复制可定位的小壹问题详情
This commit is contained in:
parent
d654e55032
commit
82af43b3d7
@ -3319,9 +3319,17 @@ impl Workspace {
|
||||
// Do not attribute an old in-memory error to the newly selected account.
|
||||
history.last_error = self.error.clone(); history.last_unknown = unknown;
|
||||
}
|
||||
let bound = self.owner_doc.is_some_and(|doc| self.loaded_draft == Some(doc)
|
||||
&& self.open_projects.get(&doc).is_some_and(|project| project.starts_with(&self.local_identity(""))));
|
||||
let receipts = if bound { self.messages.as_slice() } else { &[] };
|
||||
let identity_prefix = self.local_identity("");
|
||||
let project_id = self.owner_doc.filter(|doc| self.loaded_draft == Some(*doc))
|
||||
.and_then(|doc| self.open_projects.get(&doc))
|
||||
.and_then(|identity| identity.strip_prefix(&identity_prefix))
|
||||
.filter(|project| !project.is_empty());
|
||||
let receipts = if project_id.is_some() { self.messages.as_slice() } else { &[] };
|
||||
let diagnostics = super::operation_error::DiagnosticContext {
|
||||
version: &self.client_update.version,
|
||||
project_id,
|
||||
messages: receipts,
|
||||
};
|
||||
let warning = self.prompt_library.warning();
|
||||
history.observe(&self.error, unknown, warning.as_deref(), receipts);
|
||||
let visual = super::stitch_ui::overlay_transition(ui.ctx(), id.with("transition"), history.open, self.reduce_motion);
|
||||
@ -3348,7 +3356,7 @@ impl Workspace {
|
||||
self.panel_geometry["notificationCandidates"]=rect_value(button.rect);
|
||||
if button.clicked() {view_candidates=true;}
|
||||
}
|
||||
super::operation_error::details(ui,id.with(("error-details",index)),entry,self.reduce_motion);
|
||||
super::operation_error::details(ui,id.with(("error-details",index)),entry,self.reduce_motion,Some(&diagnostics));
|
||||
}
|
||||
});
|
||||
bounds = ui.min_rect();
|
||||
|
||||
@ -1035,7 +1035,7 @@ impl Workspace {
|
||||
egui::Frame::NONE.inner_margin(24).show(ui, |ui| {
|
||||
if self.creation_doc != doc {
|
||||
if self.creation_read_failed {
|
||||
super::operation_error::details(ui,egui::Id::unique("creation-read-error"),&self.error,self.reduce_motion);
|
||||
super::operation_error::details(ui,egui::Id::unique("creation-read-error"),&self.error,self.reduce_motion,None);
|
||||
if stitch_ui::action_button(ui, "重新读取", stitch_ui::ButtonRole::Secondary, true).clicked() {
|
||||
self.creation_read_failed = false;
|
||||
self.send("creation-read", json!({"doc":doc}));
|
||||
@ -1052,7 +1052,7 @@ impl Workspace {
|
||||
return;
|
||||
}
|
||||
if !self.error.is_empty() {
|
||||
super::operation_error::details(ui,egui::Id::unique("creation-operation-error"),&self.error,self.reduce_motion);
|
||||
super::operation_error::details(ui,egui::Id::unique("creation-operation-error"),&self.error,self.reduce_motion,None);
|
||||
}
|
||||
if !self.creation_progress.is_empty() {
|
||||
stitch_ui::disclosure(ui, egui::Id::unique("creation-progress"), if self.busy.is_some() { "处理中…" } else { "最近结果" }, false, self.reduce_motion, |ui| {
|
||||
|
||||
@ -4,6 +4,14 @@ use super::stitch_state::{ErrorCategory, Severity};
|
||||
use super::stitch_ui as kit;
|
||||
use crate::theme::agent_scale::{icon, Type};
|
||||
use egui::{RichText, Ui, vec2};
|
||||
use serde_json::Value;
|
||||
use std::fmt::Write as _;
|
||||
|
||||
pub(super) struct DiagnosticContext<'a> {
|
||||
pub version: &'a Value,
|
||||
pub project_id: Option<&'a str>,
|
||||
pub messages: &'a [Value],
|
||||
}
|
||||
|
||||
pub(super) struct Message<'a> {
|
||||
pub title: &'a str,
|
||||
@ -41,7 +49,7 @@ pub(super) fn inline(ui:&mut Ui,raw:&str)->egui::Response {
|
||||
}).inner
|
||||
}
|
||||
|
||||
pub(super) fn details(ui:&mut Ui,id:egui::Id,raw:&str,reduced:bool)->egui::Response {
|
||||
pub(super) fn details(ui:&mut Ui,id:egui::Id,raw:&str,reduced:bool,context:Option<&DiagnosticContext<'_>>)->egui::Response {
|
||||
let t=crate::theme::Tokens::get(ui.ctx()).agent();
|
||||
let text=message(raw);
|
||||
let title=crate::client_brand::file_diagnostic(text.title);
|
||||
@ -55,12 +63,45 @@ pub(super) fn details(ui:&mut Ui,id:egui::Id,raw:&str,reduced:bool)->egui::Respo
|
||||
let copy=kit::action_button(ui,"复制问题详情",kit::ButtonRole::Quiet,true);
|
||||
if copy.clicked() {
|
||||
let reason=text.reason.unwrap_or("");
|
||||
let body = if text.title == raw { diagnostic } else { format!("{title}\n{reason}\n\n技术详情:\n{diagnostic}") };
|
||||
let mut body = if text.title == raw { diagnostic } else { format!("{title}\n{reason}\n\n技术详情:\n{diagnostic}") };
|
||||
if let Some(context) = context { append_diagnostics(&mut body, context); }
|
||||
ui.ctx().copy_text(body);
|
||||
}
|
||||
copy
|
||||
}
|
||||
|
||||
fn append_diagnostics(body: &mut String, context: &DiagnosticContext<'_>) {
|
||||
if let Some(version) = context.version["version"].as_str() {
|
||||
let _ = write!(body, "\n\n小壹版本 {version}");
|
||||
if let Some(commit) = context.version["commit"].as_str() {
|
||||
let _ = write!(body, " · 提交 {commit}");
|
||||
}
|
||||
}
|
||||
if let Some(project) = context.project_id {
|
||||
let _ = write!(body, "\n项目 ID {project}");
|
||||
}
|
||||
|
||||
let recent = context.messages.iter().rev()
|
||||
.filter(|message| message["kind"] == "activity")
|
||||
.map(|message| &message["event"])
|
||||
.filter(|event| event["version"] == 1 && event["type"] == "tool"
|
||||
&& matches!(event["status"].as_str(), Some("failed" | "stopped")));
|
||||
for (index, event) in recent.take(12).enumerate() {
|
||||
if index == 0 { body.push_str("\n\n近期失败与已停止的工具操作"); }
|
||||
let summary = event["summary"].as_str().unwrap_or("工具未提供错误原因");
|
||||
let _ = write!(body, "\n\n{}. {}", index + 1, crate::client_brand::file_diagnostic(summary));
|
||||
for (key, label) in [("failureCategory", "错误类别"), ("toolCallId", "调用 ID"), ("run", "会话 ID")] {
|
||||
if let Some(value) = event[key].as_str() { let _ = write!(body, "\n{label} {value}"); }
|
||||
}
|
||||
if let Some(timestamp) = event["timestampMs"].as_u64() {
|
||||
let _ = write!(body, "\n时间戳 {timestamp} ms");
|
||||
}
|
||||
if let Some(duration) = event["durationMs"].as_u64() {
|
||||
let _ = write!(body, "\n耗时 {duration} ms");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@ -168,9 +209,19 @@ mod tests {
|
||||
let ctx=egui::Context::default();
|
||||
crate::PhotocraftApp::setup_context(&ctx,crate::theme::ThemeKind::ProMedium);
|
||||
let raw="can't read smart source within the preview budget: pcraft: limit exceeded: canvas 1440x35827 exceeds 8192 pixels per side";
|
||||
let version = serde_json::json!({"version":"1.2611.3004","commit":"0f4a2eb"});
|
||||
let messages = [
|
||||
serde_json::json!({"kind":"activity","event":{"version":1,"type":"tool","status":"failed",
|
||||
"summary":"失败:组合画布操作 · 画布版本已变化","toolCallId":"call-edit-3","run":"run-1",
|
||||
"failureCategory":"revision_conflict","timestampMs":1796047500000_u64,"durationMs":120,
|
||||
"args":{"text":"internal test payload"}}}),
|
||||
serde_json::json!({"kind":"activity","event":{"version":1,"type":"tool","status":"completed",
|
||||
"summary":"完成:查询原生命令","toolCallId":"call-ok"}}),
|
||||
];
|
||||
let diagnostics = DiagnosticContext { version: &version, project_id: Some("project-1"), messages: &messages };
|
||||
let mut rect=egui::Rect::NOTHING;
|
||||
let render=|time,events,rect:&mut egui::Rect|ctx.settle_ui(egui::RawInput {screen_rect:Some(egui::Rect::from_min_size(egui::Pos2::ZERO,vec2(420.,600.))),time:Some(time),events,..Default::default()},|ui| {
|
||||
kit::scope_with_motion(ui,true,|ui| {*rect=details(ui,egui::Id::unique("copy-error"),raw,true).rect;});
|
||||
kit::scope_with_motion(ui,true,|ui| {*rect=details(ui,egui::Id::unique("copy-error"),raw,true,Some(&diagnostics)).rect;});
|
||||
});
|
||||
let mut initial=render(0.,vec![],&mut rect);
|
||||
initial.textures_delta.clear();
|
||||
@ -179,7 +230,20 @@ mod tests {
|
||||
for (time,pressed) in [(0.1,true),(0.2,false)] {
|
||||
let mut out=render(time,vec![egui::Event::PointerMoved(at),egui::Event::PointerButton {pos:at,button:egui::PointerButton::Primary,pressed,modifiers:egui::Modifiers::NONE}],&mut rect);
|
||||
out.textures_delta.clear();
|
||||
if !pressed {assert!(out.platform_output.commands.iter().any(|command|matches!(command,egui::OutputCommand::CopyText(text) if text.contains("画布工程文件:limit exceeded: canvas 1440x35827 exceeds 8192 pixels per side")&&!text.contains("pcraft:")&&text.contains("图片暂时无法读取"))));}
|
||||
if !pressed {
|
||||
let text = out.platform_output.commands.iter().find_map(|command| match command {
|
||||
egui::OutputCommand::CopyText(text) => Some(text),
|
||||
_ => None,
|
||||
}).expect("click copies the diagnostics");
|
||||
for expected in ["画布工程文件:limit exceeded: canvas 1440x35827 exceeds 8192 pixels per side",
|
||||
"图片暂时无法读取", "小壹版本 1.2611.3004", "提交 0f4a2eb", "项目 ID project-1",
|
||||
"组合画布操作 · 画布版本已变化", "调用 ID call-edit-3", "错误类别 revision_conflict", "会话 ID run-1", "耗时 120 ms"] {
|
||||
assert!(text.contains(expected), "missing {expected}");
|
||||
}
|
||||
assert!(!text.contains("pcraft:"));
|
||||
assert!(!text.contains("call-ok"));
|
||||
assert!(!text.contains("internal test payload"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,7 +265,7 @@ mod tests {
|
||||
ui.label("当前问题");
|
||||
let id=egui::Id::unique("read-error-detail");
|
||||
ui.data_mut(|data|data.insert_temp(id.with("open"),self.expanded));
|
||||
details(ui,id,raw,true);
|
||||
details(ui,id,raw,true,None);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -128,6 +128,9 @@ fn tool_activity(w: &Workspace, event: &Value) -> Result<Value, String> {
|
||||
}
|
||||
let mut clean = json!({"version":1,"type":"tool","toolCallId":call,"toolName":name,"status":state,
|
||||
"timestampMs":timestamp,"summary":summary,"run":w.pi_run});
|
||||
if matches!(state, "failed" | "stopped") && let Some(category) = id(&event["failureCategory"]) {
|
||||
clean["failureCategory"] = json!(category);
|
||||
}
|
||||
if let Some(category) = event["category"].as_str().filter(|category| matches!(*category,
|
||||
"inference" | "canvas_read" | "canvas_write" | "disk_persist" | "remote_image" | "ui_ack" | "export")) {
|
||||
clean["category"] = json!(category);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user