diff --git a/assets/locales/pending/agent-chat-tool-summaries.json b/assets/locales/pending/agent-chat-tool-summaries.json new file mode 100644 index 000000000..b025a6a0f --- /dev/null +++ b/assets/locales/pending/agent-chat-tool-summaries.json @@ -0,0 +1,62 @@ +{ + "en": { + "ui.ai_tool_arguments": "Arguments", + "ui.ai_tool_details": "Details", + "ui.ai_tool_result": "Result", + "ui.ai_tool_sum_bodies_one": "{count} body", + "ui.ai_tool_sum_bodies_other": "{count} bodies", + "ui.ai_tool_sum_by": "by {value}", + "ui.ai_tool_sum_edges_one": "{count} edge", + "ui.ai_tool_sum_edges_other": "{count} edges", + "ui.ai_tool_sum_faces_one": "{count} face", + "ui.ai_tool_sum_faces_other": "{count} faces", + "ui.ai_tool_sum_features_one": "{count} feature", + "ui.ai_tool_sum_features_other": "{count} features", + "ui.ai_tool_sum_measured": "Measured {what}", + "ui.ai_tool_sum_more": "{steps}, and {count} more", + "ui.ai_tool_sum_radius": "r {value}", + "ui.ai_tool_sum_saved": "Saved {file}", + "ui.ai_tool_sum_screenshot": "Screenshot", + "ui.ai_tool_sum_then": "{first}, then {next}" + }, + "ja": { + "ui.ai_tool_arguments": "引数", + "ui.ai_tool_details": "詳細", + "ui.ai_tool_result": "結果", + "ui.ai_tool_sum_bodies_one": "{count} ボディ", + "ui.ai_tool_sum_bodies_other": "{count} ボディ", + "ui.ai_tool_sum_by": "距離 {value}", + "ui.ai_tool_sum_edges_one": "{count} エッジ", + "ui.ai_tool_sum_edges_other": "{count} エッジ", + "ui.ai_tool_sum_faces_one": "{count} 面", + "ui.ai_tool_sum_faces_other": "{count} 面", + "ui.ai_tool_sum_features_one": "{count} フィーチャー", + "ui.ai_tool_sum_features_other": "{count} フィーチャー", + "ui.ai_tool_sum_measured": "測定: {what}", + "ui.ai_tool_sum_more": "{steps}、ほか {count} 件", + "ui.ai_tool_sum_radius": "R {value}", + "ui.ai_tool_sum_saved": "{file} を保存しました", + "ui.ai_tool_sum_screenshot": "スクリーンショット", + "ui.ai_tool_sum_then": "{first}、続いて {next}" + }, + "zh": { + "ui.ai_tool_arguments": "参数", + "ui.ai_tool_details": "详细信息", + "ui.ai_tool_result": "结果", + "ui.ai_tool_sum_bodies_one": "{count} 个实体", + "ui.ai_tool_sum_bodies_other": "{count} 个实体", + "ui.ai_tool_sum_by": "距离 {value}", + "ui.ai_tool_sum_edges_one": "{count} 条边", + "ui.ai_tool_sum_edges_other": "{count} 条边", + "ui.ai_tool_sum_faces_one": "{count} 个面", + "ui.ai_tool_sum_faces_other": "{count} 个面", + "ui.ai_tool_sum_features_one": "{count} 个特征", + "ui.ai_tool_sum_features_other": "{count} 个特征", + "ui.ai_tool_sum_measured": "已测量 {what}", + "ui.ai_tool_sum_more": "{steps},另有 {count} 项", + "ui.ai_tool_sum_radius": "R {value}", + "ui.ai_tool_sum_saved": "已保存 {file}", + "ui.ai_tool_sum_screenshot": "截图", + "ui.ai_tool_sum_then": "{first},然后 {next}" + } +} diff --git a/crates/ui-egui/src/agent_chat/acp.rs b/crates/ui-egui/src/agent_chat/acp.rs index fc8c0cb0e..092c36616 100644 --- a/crates/ui-egui/src/agent_chat/acp.rs +++ b/crates/ui-egui/src/agent_chat/acp.rs @@ -311,7 +311,7 @@ pub enum Incoming { /// Text the agent streams (`thought`: its reasoning, shown dimmed). Text { thought: bool, text: String }, /// A new tool call, or news about one (`title`/`status` when they changed). - Tool { id: String, title: Option, kind: Option, status: Option, output: Option }, + Tool { id: String, title: Option, kind: Option, status: Option, input: Option, output: Option }, /// The agent's plan: each entry with its status. Plan(Vec<(String, String)>), /// The agent asks before running a tool call; answered with [`permission_reply`]. @@ -420,6 +420,8 @@ fn update(u: &Value) -> Incoming { title: s("title"), kind: s("kind"), status: u.get("status").and_then(Value::as_str).and_then(ToolStatus::parse), + // ACP's `rawInput`: the arguments the tool was called with. + input: u.get("rawInput").filter(|v| v.is_object()).cloned(), output: tool_output(u), }, None => Incoming::Ignored, @@ -598,7 +600,14 @@ mod tests { let tool = r#"{"jsonrpc":"2.0","method":"session/update","params":{"sessionId":"s","update":{"sessionUpdate":"tool_call_update","toolCallId":"t1","status":"completed","content":[{"type":"content","content":{"type":"text","text":"ok"}}]}}}"#; assert_eq!( parse(tool), - Some(Incoming::Tool { id: "t1".into(), title: None, kind: None, status: Some(ToolStatus::Completed), output: Some("ok".into()) }) + Some(Incoming::Tool { + id: "t1".into(), + title: None, + kind: None, + status: Some(ToolStatus::Completed), + input: None, + output: Some("ok".into()) + }) ); let perm = r#"{"jsonrpc":"2.0","id":7,"method":"session/request_permission","params":{"sessionId":"s","toolCall":{"toolCallId":"t1","title":"batch"},"options":[{"optionId":"allow","name":"Allow","kind":"allow_once"},{"optionId":"reject","name":"Reject","kind":"reject_once"}]}}"#; let Some(Incoming::Permission { rpc, title, options }) = parse(perm) else { panic!() }; diff --git a/crates/ui-egui/src/agent_chat/acp_client.rs b/crates/ui-egui/src/agent_chat/acp_client.rs index bf1e37e5f..d1c91ae1a 100644 --- a/crates/ui-egui/src/agent_chat/acp_client.rs +++ b/crates/ui-egui/src/agent_chat/acp_client.rs @@ -130,7 +130,7 @@ impl AcpBackend { } } Incoming::Text { thought, text } => out.push(Event::Text { thought, text }), - Incoming::Tool { id, title, kind, status, output } => out.push(Event::Tool { id, title, kind, status, output }), + Incoming::Tool { id, title, kind, status, input, output } => out.push(Event::Tool { id, title, kind, status, input, output }), Incoming::Plan(p) => out.push(Event::Plan(p)), Incoming::Permission { rpc, title, options } => { self.next_key += 1; diff --git a/crates/ui-egui/src/agent_chat/api_client.rs b/crates/ui-egui/src/agent_chat/api_client.rs index 6eef97597..47fa43bc1 100644 --- a/crates/ui-egui/src/agent_chat/api_client.rs +++ b/crates/ui-egui/src/agent_chat/api_client.rs @@ -329,6 +329,7 @@ impl Worker { title: Some(title), kind: Some(String::new()), status: Some(ToolStatus::InProgress), + input: c.arguments.as_ref().ok().filter(|a| a.is_object()).cloned(), output: None, }); let (text, failed) = if self.cancel.load(Ordering::Relaxed) { @@ -350,6 +351,7 @@ impl Worker { title: None, kind: None, status: Some(if failed { ToolStatus::Failed } else { ToolStatus::Completed }), + input: None, output: Some(shown), }); match self.cfg.protocol { diff --git a/crates/ui-egui/src/agent_chat/backend.rs b/crates/ui-egui/src/agent_chat/backend.rs index b74d33cbe..98f5ad246 100644 --- a/crates/ui-egui/src/agent_chat/backend.rs +++ b/crates/ui-egui/src/agent_chat/backend.rs @@ -56,8 +56,8 @@ pub enum Event { Ready { agent: String, images: bool }, /// Text it streams (`thought`: its reasoning, shown dimmed). Text { thought: bool, text: String }, - /// A new tool call, or news about one. - Tool { id: String, title: Option, kind: Option, status: Option, output: Option }, + /// A new tool call, or news about one (`input`: its arguments, when the agent says). + Tool { id: String, title: Option, kind: Option, status: Option, input: Option, output: Option }, /// Its plan, replaced whole: each entry with its status. Plan(Vec<(String, String)>), /// It asks before running something of its own; answered with [`ChatBackend::answer_permission`]. diff --git a/crates/ui-egui/src/agent_chat/mod.rs b/crates/ui-egui/src/agent_chat/mod.rs index 8648874c4..47d316d9c 100644 --- a/crates/ui-egui/src/agent_chat/mod.rs +++ b/crates/ui-egui/src/agent_chat/mod.rs @@ -36,6 +36,7 @@ pub mod paste; #[cfg(not(target_arch = "wasm32"))] mod process; pub mod settings; +pub mod summary; use std::sync::Arc; use std::sync::mpsc::{Receiver, Sender}; @@ -64,6 +65,8 @@ const APPROVAL_TIMEOUT_MS: f64 = 240_000.0; const VIEW_IMAGE: (u32, u32) = (960, 600); /// A picture kept for the user to open later, at most this big. const MAX_PICTURE_BYTES: usize = 4 << 20; +/// A tool call's arguments kept for its card, at most this big (as JSON text). +const MAX_TOOL_INPUT: usize = 64 << 10; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum State { @@ -212,6 +215,9 @@ pub enum Item { title: String, kind: String, status: Option, + /// The arguments it was called with, when the agent says (shown under Details, and read + /// for the card's summary, #1457). + input: Option, output: Option, }, Plan(Vec<(String, String)>), @@ -615,12 +621,14 @@ impl AgentChat { self.push(Item::Agent { thought, text }); } } - Event::Tool { id, title, kind, status, output } => { + Event::Tool { id, title, kind, status, input, output } => { if let Some(turn) = self.turn.as_mut() { turn.tool_called = true; } + // Arguments too large to show or read are left with the agent. + let input = input.filter(|v| serde_json::to_string(v).is_ok_and(|s| s.len() <= MAX_TOOL_INPUT)); let existing = self.items.iter_mut().rev().find(|i| matches!(i, Item::Tool { id: x, .. } if *x == id)); - if let Some(Item::Tool { title: t, kind: k, status: s, output: o, .. }) = existing { + if let Some(Item::Tool { title: t, kind: k, status: s, input: i, output: o, .. }) = existing { if let Some(v) = title { *t = v; } @@ -630,11 +638,14 @@ impl AgentChat { if status.is_some() { *s = status; } + if input.is_some() { + *i = input; + } if output.is_some() { *o = output; } } else { - self.push(Item::Tool { id, title: title.unwrap_or_default(), kind: kind.unwrap_or_default(), status, output }); + self.push(Item::Tool { id, title: title.unwrap_or_default(), kind: kind.unwrap_or_default(), status, input, output }); } } Event::Plan(entries) => { @@ -2008,8 +2019,8 @@ pub fn status(app: &SolveApp) -> Value { .map(|i| match i { Item::User { text, image, pictures, context, files } => json!({"user": text, "image": image, "pictures": pictures.len(), "files": files, "context": context.items.iter().map(|i| json!({"label": i.label, "detail": i.detail})).collect::>(), "context_omitted": context.omitted}), Item::Agent { thought, text } => json!({"agent": text, "thought": thought}), - Item::Tool { id, title, kind, status, output } => { - json!({"tool": id, "title": title, "kind": kind, "status": status.map(|s| format!("{s:?}")), "output": output}) + Item::Tool { id, title, kind, status, input, output } => { + json!({"tool": id, "title": title, "kind": kind, "status": status.map(|s| format!("{s:?}")), "input": input, "output": output}) } Item::Plan(p) => json!({"plan": p}), Item::Permission { title, options, answer, .. } => { diff --git a/crates/ui-egui/src/agent_chat/panel.rs b/crates/ui-egui/src/agent_chat/panel.rs index d1998b33b..2f2724a66 100644 --- a/crates/ui-egui/src/agent_chat/panel.rs +++ b/crates/ui-egui/src/agent_chat/panel.rs @@ -1333,6 +1333,7 @@ fn conversation(app: &mut SolveApp, ui: &mut egui::Ui) { let mut undo: Option = None; let mut open_gallery: Option = None; let current_doc = app.session.doc.clone(); + let units = summary::Units { units: &app.session.doc.units, decimals: app.preferences.length_decimals }; for (n, item) in app.agent_chat.items.iter().enumerate() { match item { Item::User { text, image, pictures, context, files } => { @@ -1366,8 +1367,17 @@ fn conversation(app: &mut SolveApp, ui: &mut egui::Ui) { ui_kit::assistant_tool_frame(ui, false, |ui| { ui.spacing_mut().item_spacing.y = Tokens::get().space_2; for (offset, next) in app.agent_chat.items.iter().skip(n).take_while(|next| matches!(next, Item::Tool { .. })).enumerate() { - if let Item::Tool { title, kind, status, output, .. } = next { - tool_card(ui, n + offset, title, kind, *status, output.as_deref()); + if let Item::Tool { title, kind, status, input, output, .. } = next { + let words = summary::summary(title, input.as_ref(), output.as_deref(), *status == Some(ToolStatus::Completed), units); + let call = ToolCall { + title, + summary: words.as_deref(), + kind, + status: *status, + input: input.as_ref(), + output: output.as_deref(), + }; + tool_card(ui, n + offset, &call); } } }); @@ -1799,16 +1809,37 @@ fn add_menu(app: &mut SolveApp, ui: &mut egui::Ui) { } } -/// A tool call as a card: its state, name and kind on one line; a click unfolds what it returned. +/// A tool call as its card shows it. #[cfg(not(target_arch = "wasm32"))] -fn tool_card(ui: &mut egui::Ui, n: usize, title: &str, kind: &str, status: Option, output: Option<&str>) { +struct ToolCall<'a> { + /// The agent's title, shown when there are no words for the call. + title: &'a str, + /// What it did in words (#1457). + summary: Option<&'a str>, + kind: &'a str, + status: Option, + input: Option<&'a Value>, + output: Option<&'a str>, +} + +/// Longest raw text shown under a card's Details (characters). +#[cfg(not(target_arch = "wasm32"))] +const MAX_DETAIL: usize = 8000; + +/// A tool call as a card: its state and what it did in words on one line (the agent's own title +/// when there are none); a click on the line unfolds Details, the raw arguments and what it +/// returned. +#[cfg(not(target_arch = "wasm32"))] +fn tool_card(ui: &mut egui::Ui, n: usize, call: &ToolCall) { let t = Tokens::get(); + let status = call.status; let (color, mark, state) = match status { Some(ToolStatus::Completed) => (t.form_success, ui_kit::AssistantToolState::Done, "ui.ai_tool_done"), Some(ToolStatus::Failed) => (t.error, ui_kit::AssistantToolState::Failed, "ui.ai_tool_failed"), Some(ToolStatus::InProgress) => (t.accent, ui_kit::AssistantToolState::Running, "ui.ai_tool_running"), _ => (t.text_dim, ui_kit::AssistantToolState::Pending, "ui.ai_tool_waiting"), }; + let details = call.input.is_some() || call.output.is_some(); ui_kit::assistant_tool_row(ui, status == Some(ToolStatus::Failed), |ui| { ui.set_width(ui.available_width()); let id = ui.make_persistent_id(("sc_agent_tool", n)); @@ -1817,37 +1848,57 @@ fn tool_card(ui: &mut egui::Ui, n: usize, title: &str, kind: &str, status: Optio ui.spacing_mut().item_spacing.x = t.space_8; ui_kit::assistant_tool_status(ui, mark); ui.with_layout(Layout::right_to_left(Align::Center), |ui| { - if output.is_some() { + if details { let (rect, _) = ui.allocate_exact_size(vec2(t.space_14, t.space_14), Sense::hover()); ui_kit::disclosure(ui.painter(), rect.center(), state_.is_open(), t.text_dim); + ui.label(RichText::new(tr("ui.ai_tool_details")).size(t.font_small).color(t.text_dim)); } ui.label(RichText::new(tr(state)).size(t.font_small).color(color)); - if !kind.is_empty() && kind != "other" { - ui.label(RichText::new(kind).size(t.font_small).color(t.text_dim)); + if !call.kind.is_empty() && call.kind != "other" { + ui.label(RichText::new(call.kind).size(t.font_small).color(t.text_dim)); } ui.with_layout(Layout::left_to_right(Align::Center), |ui| { - ui.add(egui::Label::new(RichText::new(title).monospace().size(t.font_caption).color(t.text)).truncate()).on_hover_text(title); + let text = match call.summary { + Some(words) => RichText::new(words).size(t.font_caption).color(t.text), + None => RichText::new(summary::plain_title(call.title)).monospace().size(t.font_caption).color(t.text), + }; + ui.add(egui::Label::new(text).truncate().selectable(false)).on_hover_text(call.title); }); }); }); let click = ui.interact(head.response.rect, id.with("head"), Sense::click()); crate::scenario::publish_handle(&format!("agent_chat:tool:{n}"), head.response.rect.center()); - if output.is_some() && click.clicked() { + if details && click.clicked() { state_.toggle(ui); } - if output.is_some() { + if details { click.on_hover_text(tr("ui.ai_tool_unfold")); } state_.show_body_unindented(ui, |ui| { - if let Some(o) = output { - ui.indent(id.with("detail"), |ui| { - ui_kit::assistant_tool_detail(ui, |ui| { - egui::ScrollArea::vertical().id_salt(("sc_agent_tool_out", n)).max_height(180.0).show(ui, |ui| { - ui.add(egui::Label::new(RichText::new(o).monospace().size(t.font_small)).selectable(true).wrap()); - }); - }); - }); - } + ui.indent(id.with("detail"), |ui| { + if let Some(input) = call.input { + let text = serde_json::to_string_pretty(input).unwrap_or_default(); + tool_detail(ui, tr("ui.ai_tool_arguments"), &text, id.with("in")); + } + if let Some(o) = call.output { + tool_detail(ui, tr("ui.ai_tool_result"), o, id.with("out")); + } + }); + }); + }); +} + +/// One part of a card's Details: its heading and the raw text, cut short and scrolling. +#[cfg(not(target_arch = "wasm32"))] +fn tool_detail(ui: &mut egui::Ui, heading: &str, text: &str, id: Id) { + let t = Tokens::get(); + ui.label(RichText::new(heading).size(t.font_small).color(t.text_dim)); + let shown: String = + if text.chars().count() > MAX_DETAIL { text.chars().take(MAX_DETAIL).chain(std::iter::once('…')).collect() } else { text.to_string() }; + ui_kit::assistant_tool_detail(ui, |ui| { + ui.set_min_width(ui.available_width()); + egui::ScrollArea::vertical().id_salt(id).max_height(180.0).show(ui, |ui| { + ui.add(egui::Label::new(RichText::new(shown).monospace().size(t.font_small)).selectable(true).wrap()); }); }); } diff --git a/crates/ui-egui/src/agent_chat/summary.rs b/crates/ui-egui/src/agent_chat/summary.rs new file mode 100644 index 000000000..9d72b2840 --- /dev/null +++ b/crates/ui-egui/src/agent_chat/summary.rs @@ -0,0 +1,360 @@ +//! A tool call in words, for its card (#1457): "Extrude Sketch1 by 10 mm", "Box 40 × 30 × 20 mm, +//! then Fillet 4 edges (r 4 mm)", "Saved block.solidcraft". +//! +//! A first pass built from the command's translated label, its main parameters (lengths in the +//! design's units) and the bodies the result names. Anything it doesn't know (another agent's own +//! tools, a call too large or malformed to read) gives `None`, and the card keeps its title. +//! The arguments and the result are the agent's: read with `get`, quoted short, never trusted. + +use serde_json::{Map, Value}; + +use crate::i18n::{format as trf, tr, tr_label}; + +/// Steps of a batch named before "and N more". +const MAX_STEPS: usize = 4; +/// Created bodies named after the arrow. +const MAX_BODIES: usize = 3; +/// Longest name, path or expression quoted from a call (characters). +const MAX_WORD: usize = 40; +/// Longest summary (characters). +const MAX_SUMMARY: usize = 240; +/// Largest result read for its bodies or measurements (bytes). +const MAX_RESULT: usize = 64 * 1024; + +/// How lengths are shown: the design's units and the length precision. +#[derive(Clone, Copy, Debug)] +pub struct Units<'a> { + pub units: &'a str, + pub decimals: u8, +} + +/// The call in words, or `None` when it is not one of SolidCraft's tools or says too little. +/// `title`: the call's title as the agent gave it; `input`: its arguments; `output`: what it +/// returned (text); `done`: it completed (a finished save reads "Saved …", one still running +/// or failed "Save …"). +pub fn summary(title: &str, input: Option<&Value>, output: Option<&str>, done: bool, u: Units) -> Option { + let tool = tool_name(title)?; + let result = output.filter(|o| o.len() <= MAX_RESULT).and_then(|o| serde_json::from_str::(o).ok()); + let text = tool_summary(tool, input.and_then(Value::as_object), result.as_ref(), done, u, true)?; + Some(clip(&text, MAX_SUMMARY)) +} + +/// SolidCraft's tool a title names: `mcp____` (an agent names MCP tools after their +/// server, which for SolidCraft's has `solidcraft` in it), or the in-app client's own `measure`, +/// `execute: solid.box`, `batch: …`. +pub fn tool_name(title: &str) -> Option<&str> { + let head = title.trim(); + let name = head.split(|c: char| c == ':' || c.is_whitespace()).next()?; + let parts: Vec<&str> = name.split("__").take(4).collect(); + match parts.as_slice() { + ["mcp", server, tool] if server.to_ascii_lowercase().contains("solidcraft") && !tool.is_empty() => Some(*tool), + [bare] if !bare.is_empty() && head.strip_prefix(*bare).is_some_and(|rest| rest.is_empty() || rest.starts_with(':')) => Some(*bare), + _ => None, + } +} + +/// One tool's words. `nest`: a batch may hold steps (batches don't nest). +fn tool_summary(tool: &str, a: Option<&Map>, result: Option<&Value>, done: bool, u: Units, nest: bool) -> Option { + let s = |k: &str| a.and_then(|a| a.get(k)).and_then(Value::as_str); + match tool { + "execute" => command(s("command")?, a.and_then(|a| a.get("params")).and_then(Value::as_object), result, u), + "batch" if nest => batch(a?.get("commands")?.as_array()?, done, u), + "measure" => measure(s("body"), result, done, u), + "save" => { + let file = s("path").or_else(|| result.and_then(|r| r.get("path")).and_then(Value::as_str)).and_then(file_name); + match file { + Some(f) if done => Some(trf("ui.ai_tool_sum_saved", &[("file", &f)])), + f => Some(words([Some(label("file.save")?.to_string()), f])), + } + } + "export" => Some(words([Some(label("file.export")?.to_string()), s("path").and_then(file_name)])), + "open" => Some(words([Some(label("doc.open")?.to_string()), s("path").and_then(file_name)])), + // The control channel's own calls: the picture is the point, never where it was left. + "ui.screenshot" | "ui_screenshot" | "screenshot" => Some(tr("ui.ai_tool_sum_screenshot").to_string()), + "new_design" => Some(words([Some(label("file.new")?.to_string()), s("name").map(word)])), + "set_parameter" => { + let value = a.and_then(|a| a.get("value").or_else(|| a.get("expression"))).and_then(|v| length(v, u)); + let what = s("name").map(word).map(|n| match value { + Some(v) => format!("{n} = {v}"), + None => n, + }); + Some(words([Some(label("parameters.change")?.to_string()), what])) + } + "inspect_design" => label("document.inspect").map(str::to_string), + "undo" => label("edit.undo").map(str::to_string), + "redo" => label("edit.redo").map(str::to_string), + "crash_reports" => label("diagnostics.crash_reports").map(str::to_string), + _ => None, + } +} + +/// An engine command: its label, what it works on, its sizes, and the bodies it made. +fn command(id: &str, p: Option<&Map>, result: Option<&Value>, u: Units) -> Option { + let mut text = label(id)?.to_string(); + if let Some(p) = p { + let size = size(p, u).or_else(|| p.get("distance").and_then(|v| length(v, u)).map(|d| trf("ui.ai_tool_sum_by", &[("value", &d)]))); + text = words([Some(text), subject(p), size]); + let mut extras = Vec::new(); + if let Some(r) = p.get("radius").and_then(|v| length(v, u)) { + extras.push(trf("ui.ai_tool_sum_radius", &[("value", &r)])); + } + if let Some(d) = p.get("diameter").and_then(|v| length(v, u)) { + extras.push(format!("⌀ {d}")); + } + if let Some(a) = p.get("angle").and_then(angle) { + extras.push(a); + } + if !extras.is_empty() { + text = format!("{text} ({})", extras.join(", ")); + } + } + let created: Vec = result + .and_then(|r| r.get("created_bodies")) + .and_then(Value::as_array) + .map(|b| b.iter().filter_map(Value::as_str).take(MAX_BODIES + 1).map(word).collect()) + .unwrap_or_default(); + if !created.is_empty() { + let shown: Vec<&str> = created.iter().take(MAX_BODIES).map(String::as_str).collect(); + let more = if created.len() > MAX_BODIES { ", …" } else { "" }; + text = format!("{text} → {}{more}", shown.join(", ")); + } + Some(text) +} + +/// A batch: its first steps in order, "A, then B", and how many more. +fn batch(steps: &[Value], done: bool, u: Units) -> Option { + let mut parts = steps.iter().take(MAX_STEPS).filter_map(|step| { + let id = step.get("command").or_else(|| step.get("id")).and_then(Value::as_str)?; + let params = step.get("params").and_then(Value::as_object); + let text = if id.contains('.') { command(id, params, None, u) } else { tool_summary(id, params, None, done, u, false) }; + Some(text.unwrap_or_else(|| word(id))) + }); + let mut text = parts.next()?; + for next in parts { + text = trf("ui.ai_tool_sum_then", &[("first", &text), ("next", &next)]); + } + if steps.len() > MAX_STEPS { + text = trf("ui.ai_tool_sum_more", &[("steps", &text), ("count", &(steps.len() - MAX_STEPS).to_string())]); + } + Some(text) +} + +/// `measure`: once done, the body's size and volume, or the bodies' total volume. +fn measure(body: Option<&str>, result: Option<&Value>, done: bool, u: Units) -> Option { + let plain = || Some(words([Some(label("inspect.measure")?.to_string()), body.map(word)])); + if !done { + return plain(); + } + let bodies = result.and_then(|r| r.get("bodies")).and_then(Value::as_array); + let what = match bodies.map(Vec::as_slice) { + Some([one]) => { + let name = one.get("name").and_then(Value::as_str).or(body).map(word)?; + let facts: Vec = + [bbox_size(one, u), one.get("volume_mm3").and_then(Value::as_f64).and_then(|v| volume(v, u))].into_iter().flatten().collect(); + if facts.is_empty() { name } else { format!("{name}: {}", facts.join(", ")) } + } + Some(many) if !many.is_empty() => { + let count = plural(BODIES, many.len()); + match result.and_then(|r| r.get("total")).and_then(|t| t.get("volume_mm3")).and_then(Value::as_f64).and_then(|v| volume(v, u)) { + Some(v) => format!("{count}: {v}"), + None => count, + } + } + _ => match body { + Some(b) => word(b), + None => return plain(), + }, + }; + Some(trf("ui.ai_tool_sum_measured", &[("what", &what)])) +} + +/// What a command works on: a sketch, body or target by name, or how many edges, faces or bodies. +fn subject(p: &Map) -> Option { + for k in ["sketch", "body", "target"] { + if let Some(name) = p.get(k).and_then(Value::as_str) { + return Some(word(name)); + } + } + for (k, key) in [("edges", EDGES), ("faces", FACES), ("bodies", BODIES), ("features", FEATURES)] { + match p.get(k).and_then(Value::as_array).map(Vec::as_slice) { + Some([one]) if one.is_string() => return one.as_str().map(word), + Some(list) if !list.is_empty() => return Some(plural(key, list.len())), + _ => {} + } + } + None +} + +/// "40 × 30 × 20 mm" from two or more of length, width and height. +fn size(p: &Map, u: Units) -> Option { + let given: Vec<&Value> = ["length", "width", "height"].iter().filter_map(|k| p.get(*k)).collect(); + if given.len() < 2 { + return None; + } + if let Some(mm) = given.iter().map(|v| v.as_f64().filter(|x| x.is_finite())).collect::>>() { + return Some(lengths(&mm, u)); + } + let each: Vec = given.iter().filter_map(|v| length(v, u)).collect(); + (each.len() == given.len()).then(|| each.join(" × ")) +} + +/// A body's size along X, Y and Z from its bounding box. +fn bbox_size(body: &Value, u: Units) -> Option { + let corner = |k: &str| -> Option> { + let a = body.get("bbox")?.get(k)?.as_array()?; + let v: Vec = a.iter().take(3).filter_map(Value::as_f64).filter(|x| x.is_finite()).collect(); + (v.len() == 3).then_some(v) + }; + let (min, max) = (corner("min")?, corner("max")?); + Some(lengths(&min.iter().zip(&max).map(|(a, b)| (b - a).abs()).collect::>(), u)) +} + +/// Millimetre lengths as "40 × 30 × 20 mm" in the design's units. +fn lengths(mm: &[f64], u: Units) -> String { + let unit = crate::prefs::unit_scale(u.units).1; + let numbers: Vec = mm.iter().map(|v| compact(&crate::prefs::length_number(*v, u.units, u.decimals))).collect(); + format!("{} {unit}", numbers.join(" × ")) +} + +/// A length parameter: a number (mm) in the design's units, or the expression as written. +fn length(v: &Value, u: Units) -> Option { + match v { + Value::Number(n) => n.as_f64().filter(|x| x.is_finite()).map(|mm| lengths(&[mm], u)), + Value::String(s) if !s.trim().is_empty() => Some(word(s)), + _ => None, + } +} + +/// An angle parameter: a number (degrees), or the expression as written. +fn angle(v: &Value) -> Option { + match v { + Value::Number(n) => n.as_f64().filter(|x| x.is_finite()).map(|d| format!("{}°", compact(&format!("{d:.2}")))), + Value::String(s) if !s.trim().is_empty() => Some(word(s)), + _ => None, + } +} + +/// A volume in mm³: cm³ for a millimetre design (as people read a part's size), otherwise the +/// design's unit cubed; three significant figures. +fn volume(mm3: f64, u: Units) -> Option { + if !mm3.is_finite() { + return None; + } + let (scale, unit) = crate::prefs::unit_scale(u.units); + let (v, unit) = if unit == "mm" { (mm3 / 1000.0, "cm") } else { (mm3 * scale.powi(3), unit) }; + let places = match v.abs() { + a if a >= 100.0 => 0, + a if a >= 10.0 => 1, + a if a >= 1.0 => 2, + _ => 3, + }; + Some(format!("{} {unit}³", compact(&format!("{v:.places$}")))) +} + +/// "10.00" → "10", "2.50" → "2.5", "-0.00" → "0". +fn compact(number: &str) -> String { + let s = if number.contains('.') { number.trim_end_matches('0').trim_end_matches('.') } else { number }; + if s == "-0" { "0".to_string() } else { s.to_string() } +} + +/// A count's messages: one, and more. +const EDGES: (&str, &str) = ("ui.ai_tool_sum_edges_one", "ui.ai_tool_sum_edges_other"); +const FACES: (&str, &str) = ("ui.ai_tool_sum_faces_one", "ui.ai_tool_sum_faces_other"); +const BODIES: (&str, &str) = ("ui.ai_tool_sum_bodies_one", "ui.ai_tool_sum_bodies_other"); +const FEATURES: (&str, &str) = ("ui.ai_tool_sum_features_one", "ui.ai_tool_sum_features_other"); + +/// "1 edge", "4 edges". +fn plural((one, other): (&str, &str), count: usize) -> String { + trf(if count == 1 { one } else { other }, &[("count", &count.to_string())]) +} + +/// A command's label in the interface language. +fn label(id: &str) -> Option<&'static str> { + solidcraft_engine::find_command(id).map(|c| tr_label(c.label)) +} + +/// A file's name without its folders; `None` for a temporary file (the agent's scratch, not +/// something to name). +fn file_name(path: &str) -> Option { + if is_temp(path) { + return None; + } + Some(word(path.rsplit(['/', '\\']).find(|p| !p.is_empty()).unwrap_or(path))) +} + +/// A path in a temporary folder (`/tmp`, `%TEMP%`, macOS `/var/folders`) or one of SolidCraft's +/// own scratch folders. +fn is_temp(path: &str) -> bool { + let p = path.replace('\\', "/").to_ascii_lowercase(); + ["/tmp/", "/temp/", "/var/folders/", "/appdata/local/temp", "solidcraft-mcp-", "/dev/shm/"].iter().any(|m| p.contains(m)) + || p.ends_with("/tmp") + || p.ends_with("/temp") +} + +/// Whether a word starts an absolute path: a Windows drive (`C:\`, `C:/`), a UNC share (`\\server`), +/// `~` or a Unix path with a folder (`/home/x`, not a lone `/`). +fn path_start(w: &str) -> bool { + let b = w.as_bytes(); + let drive = b.len() >= 3 && b[0].is_ascii_alphabetic() && b[1] == b':' && (b[2] == b'\\' || b[2] == b'/'); + let windows = drive || w.starts_with("\\\\"); + windows || w == "~" || w.starts_with("~/") || (w.starts_with('/') && w[1..].contains(|c: char| c != '/')) +} + +/// A card's title with every path cut to its file name and temporary files left out: +/// "ui.screenshot: C:\\Users\\me\\Temp\\shot-0.png" reads "ui.screenshot", "Read /home/me/a.step" +/// "Read a.step". The full title stays in the card's tooltip. +pub fn plain_title(title: &str) -> String { + let mut out: Vec = Vec::new(); + let mut words = title.split_whitespace().peekable(); + while let Some(first) = words.next() { + // Quotes and brackets around a path stay out of it. + let lead = first.len() - first.trim_start_matches(['"', '\'', '(', '[', '`']).len(); + let core = &first[lead..]; + if !path_start(core) { + out.push(first.to_string()); + continue; + } + let mut path = core.to_string(); + let windows = !core.starts_with('/') && !core.starts_with('~'); + // A Windows folder may hold spaces ("Jane Doe"): carry on while the last part has no extension. + while windows && words.peek().is_some() { + let last = path.rsplit(['/', '\\']).next().unwrap_or(""); + if last.contains('.') { + break; + } + path.push(' '); + path.push_str(words.next().unwrap_or_default()); + } + let trail_at = path.trim_end_matches(['"', '\'', ')', ']', '`', ',', ';', '.', ':']).len(); + let (body, trail) = path.split_at(trail_at); + let trail = trail.trim_start_matches(['"', '\'', ')', ']', '`']); + match file_name(body) { + Some(name) => out.push(format!("{}{name}{trail}", &first[..lead])), + None => { + if let Some(prev) = out.last_mut() { + // The colon or "to" that led to the path leads nowhere now. + if prev.ends_with(':') { + prev.pop(); + } + } + } + } + } + let text = out.join(" "); + clip(&text, MAX_SUMMARY) +} + +/// A name or expression from the call on one line, cut short. +fn word(s: &str) -> String { + let line: String = s.chars().take(MAX_WORD * 4).map(|c| if c.is_control() { ' ' } else { c }).collect(); + clip(line.trim(), MAX_WORD) +} + +fn clip(s: &str, max: usize) -> String { + if s.chars().count() <= max { s.to_string() } else { s.chars().take(max.saturating_sub(1)).collect::() + "…" } +} + +/// The parts that are there, with spaces between. +fn words(parts: [Option; N]) -> String { + parts.into_iter().flatten().filter(|p| !p.is_empty()).collect::>().join(" ") +} diff --git a/crates/ui-egui/src/agent_chat/tests.rs b/crates/ui-egui/src/agent_chat/tests.rs index 3c84e2421..cad57919c 100644 --- a/crates/ui-egui/src/agent_chat/tests.rs +++ b/crates/ui-egui/src/agent_chat/tests.rs @@ -104,8 +104,15 @@ fn streamed_text_joins_and_tool_updates_change_their_call() { for e in [ Event::Text { thought: false, text: "Mak".into() }, Event::Text { thought: false, text: "ing a box".into() }, - Event::Tool { id: "t".into(), title: Some("batch".into()), kind: Some("other".into()), status: Some(ToolStatus::Pending), output: None }, - Event::Tool { id: "t".into(), title: None, kind: None, status: Some(ToolStatus::Completed), output: Some("ok".into()) }, + Event::Tool { + id: "t".into(), + title: Some("batch".into()), + kind: Some("other".into()), + status: Some(ToolStatus::Pending), + input: None, + output: None, + }, + Event::Tool { id: "t".into(), title: None, kind: None, status: Some(ToolStatus::Completed), input: None, output: Some("ok".into()) }, ] { c.on_event(e); } @@ -2510,7 +2517,14 @@ fn no_tool_turn_warning_does_not_follow_a_tool_call() { let (mut app, _, _) = app_with_script(); app.agent_chat.tools_port = Some(12345); start_turn(&mut app, "Make a box".into(), false, None, vec![]); - app.agent_chat.on_event(Event::Tool { id: "t".into(), title: Some("batch".into()), kind: None, status: Some(ToolStatus::Failed), output: None }); + app.agent_chat.on_event(Event::Tool { + id: "t".into(), + title: Some("batch".into()), + kind: None, + status: Some(ToolStatus::Failed), + input: None, + output: None, + }); app.agent_chat.on_event(Event::TurnEnded { reason: String::new() }); end_turn(&mut app); assert!(status(&app).get("turnWarning").is_some()); @@ -2538,3 +2552,191 @@ fn no_tool_turn_warning_leaves_answers_and_incomplete_turns_quiet() { assert!(!app.agent_chat.items.iter().any(|i| matches!(i, Item::Notice { text, .. } if text == tr("ui.agent_chat_no_tool_call")))); } } + +// ---- Tool calls in words (#1457) ---- + +fn in_mm() -> summary::Units<'static> { + summary::Units { units: "mm", decimals: 2 } +} + +fn said(title: &str, input: Value, output: Option<&str>) -> Option { + summary::summary(title, Some(&input), output, true, in_mm()) +} + +/// The issue's examples: a card says what the call did, from the command's label, its main +/// parameters and what it returned. +#[test] +fn tool_calls_read_as_what_they_did() { + let extrude = json!({"command": "solid.extrude", "params": {"sketch": "Sketch1", "distance": 10}}); + assert_eq!(said("execute: solid.extrude", extrude.clone(), None).as_deref(), Some("Extrude Sketch1 by 10 mm")); + // As an ACP agent names the bridged tool, with the body the result made. + let made = r#"{"feature": 4, "name": "Extrude1", "created_bodies": ["Body2"], "changed_bodies": []}"#; + assert_eq!(said("mcp__solidcraft-app__execute", extrude, Some(made)).as_deref(), Some("Extrude Sketch1 by 10 mm → Body2")); + let edges = json!([[20, 0, 20], [20, 30, 20], [0, 15, 20], [40, 15, 20]]); + let batch = json!({"commands": [ + {"command": "solid.box", "params": {"length": 40, "width": 30, "height": 20}}, + {"command": "solid.fillet", "params": {"edges": edges, "radius": 4}}, + ]}); + assert_eq!(said("batch: solid.box, solid.fillet", batch, None).as_deref(), Some("Box 40 × 30 × 20 mm, then Fillet 4 edges (r 4 mm)")); + let measured = r#"{"body_count": 1, "bodies": [{"name": "Block", "volume_mm3": 23620.4, "bbox": {"min": [0, 0, 0], "max": [40, 30, 20]}}]}"#; + assert_eq!(said("measure", json!({"body": "Block"}), Some(measured)).as_deref(), Some("Measured Block: 40 × 30 × 20 mm, 23.6 cm³")); + assert_eq!(said("save", json!({"path": "C:\\designs\\block.solidcraft"}), None).as_deref(), Some("Saved block.solidcraft")); + // Still running, or failed: what it does, not what it did. + let running = summary::summary("save", Some(&json!({"path": "/home/me/block.solidcraft"})), None, false, in_mm()); + assert_eq!(running.as_deref(), Some("Save block.solidcraft")); + // Lengths in the design's units; an expression as written; one edge is one. + let inches = summary::Units { units: "in", decimals: 3 }; + let one = json!({"command": "solid.fillet", "params": {"edges": [[0, 0, 0]], "radius": 2.54}}); + assert_eq!(summary::summary("execute: solid.fillet", Some(&one), None, true, inches).as_deref(), Some("Fillet 1 edge (r 0.1 in)")); + let expr = json!({"command": "solid.extrude", "params": {"sketch": "Sketch1", "distance": "2 * depth"}}); + assert_eq!(said("execute: solid.extrude", expr, None).as_deref(), Some("Extrude Sketch1 by 2 * depth")); + // A long batch names its first steps and counts the rest. + let steps: Vec = (0..6).map(|_| json!({"command": "edit.undo"})).collect(); + assert_eq!(said("batch: edit.undo", json!({"commands": steps}), None).as_deref(), Some("Undo, then Undo, then Undo, then Undo, and 2 more")); +} + +/// Paths in a card never show their folders (the owner's "way too much"): the screenshot is just +/// "Screenshot", files are their names, temporary files are not named, and the full text stays in +/// Details and the tooltip. +#[test] +fn tool_cards_show_file_names_never_paths() { + let shot = r"ui.screenshot: C:\Users\bherbruck\AppData\Local\Temp\solidcraft-mcp-8608-b4c7b64\shot-0.png"; + assert_eq!(said(shot, json!({}), None).as_deref(), Some("Screenshot")); + assert_eq!(said("mcp__solidcraft-app__ui.screenshot", json!({}), None).as_deref(), Some("Screenshot")); + // The fallback title (another agent's tools) is cut to file names; temp files drop out. + assert_eq!(summary::plain_title(shot), "ui.screenshot"); + assert_eq!(summary::plain_title(r"Read C:\Users\Jane Doe\Documents\part.step"), "Read part.step"); + assert_eq!(summary::plain_title(r"Write D:/work/out/block.solidcraft now"), "Write block.solidcraft now"); + assert_eq!(summary::plain_title(r"Open \\nas\share\parts\bracket.step"), "Open bracket.step"); + assert_eq!(summary::plain_title("Read /home/bherbruck/designs/part.step"), "Read part.step"); + assert_eq!(summary::plain_title("Edit ~/designs/part.step."), "Edit part.step."); + assert_eq!(summary::plain_title("cat \"/home/me/a b.txt\" | head"), "cat \"a b.txt\" | head"); + assert_eq!(summary::plain_title("Read /tmp/claude-1000/scratch/out.txt"), "Read"); + assert_eq!(summary::plain_title("ui.render: /var/folders/xy/T/shot.png"), "ui.render"); + assert_eq!(summary::plain_title("Run mcp__x__y with a/b and /"), "Run mcp__x__y with a/b and /"); + // SolidCraft's own file tools: the name alone; a temp file has none. + assert_eq!( + said("export", json!({"path": "/home/me/cad/part.step"}), None).as_deref().map(|s| s.ends_with("part.step") && !s.contains('/')), + Some(true) + ); + assert_eq!( + said("open", json!({"path": r"C:\cad\block.solidcraft"}), None).as_deref().map(|s| s.ends_with(" block.solidcraft") && !s.contains('\\')), + Some(true) + ); + assert_eq!(said("save", json!({"path": "/tmp/x/block.solidcraft"}), None).as_deref(), Some("Save")); + assert_eq!(said("save", json!({"path": r"C:\Users\me\AppData\Local\Temp\a.solidcraft"}), Some("")).as_deref(), Some("Save")); +} + +/// Another agent's own tools, an unknown command and malformed or hostile calls keep the card's +/// title (no words), and nothing panics or grows without bound. +#[test] +fn unknown_or_malformed_tool_calls_keep_their_title_and_never_panic() { + for title in ["Read /etc/hosts", "mcp__github__create_issue", "mcp__github__save", "save /tmp/x.txt", "", " ", "__", "mcp____"] { + assert_eq!(said(title, json!({"path": "x.solidcraft", "command": "solid.box"}), None), None, "{title}"); + } + assert_eq!(said("execute: solid.nope", json!({"command": "solid.nope"}), None), None, "an unknown command"); + assert_eq!(summary::summary("execute: solid.box", None, None, true, in_mm()), None, "arguments that did not parse"); + let long = "x".repeat(100_000); + let many: Vec = (0..10_000).map(|i| json!({"command": format!("solid.{i}"), "params": {"distance": i}})).collect(); + let hostile = [ + json!(null), + json!([1, 2, 3]), + json!("text"), + json!({"command": 5, "params": "x"}), + json!({"command": "solid.box", "params": {"length": "", "width": [], "height": {"a": 1}}}), + json!({"command": "solid.box", "params": {"length": 1e308, "width": -1e308, "height": 0}}), + json!({"command": "solid.extrude", "params": {"sketch": long, "distance": long, "edges": [long], "angle": 1e300}}), + json!({"command": "solid.extrude", "params": {"sketch": "a\nb\u{0}\u{202e}c", "distance": -0.0}}), + json!({"commands": many}), + json!({"commands": [null, 1, {"command": "batch", "params": {"commands": [{"command": "solid.box"}]}}, {"id": "save"}]}), + json!({"body": ["Block"], "path": {"x": 1}, "name": 3, "value": null}), + ]; + let outputs = [ + None, + Some(""), + Some("{"), + Some("[]"), + Some(r#"{"bodies": [{"bbox": {"min": [1], "max": "x"}}]}"#), + Some(r#"{"created_bodies": [1, null, "B"]}"#), + ]; + for tool in ["execute", "batch", "measure", "save", "export", "open", "new_design", "set_parameter", "mcp__solidcraft__batch"] { + for input in &hostile { + for output in outputs { + for done in [true, false] { + if let Some(s) = summary::summary(tool, Some(input), output, done, in_mm()) { + assert!(s.chars().count() <= 240 && !s.contains('\n'), "{tool}: {s}"); + } + } + } + } + } + let huge = format!("{{\"bodies\": [{}]}}", "{\"name\": \"B\"},".repeat(20_000)); + assert_eq!(said("measure", json!({}), Some(&huge)).as_deref(), Some("Measure"), "a result too large is not read"); +} + +/// The card's title is the summary; the raw arguments and result wait behind Details until it is +/// opened. A call with no words keeps its title. +#[test] +fn a_tool_card_shows_its_summary_and_keeps_the_json_behind_details() { + use crate::scenario::handle_at; + let mut h = crate::scenario::Harness::new(); + h.call("ui.agent_chat", json!({"open": true})); + h.frames(3); + let input = json!({"command": "solid.extrude", "params": {"sketch": "Sketch1", "distance": 10}}); + let output = r#"{"feature": 4, "name": "Extrude1", "created_bodies": []}"#; + let n = h.app.agent_chat.items.len(); + h.app.agent_chat.items.push(Item::Tool { + id: "t".into(), + title: "execute: solid.extrude".into(), + kind: String::new(), + status: Some(ToolStatus::Completed), + input: Some(input.clone()), + output: Some(output.into()), + }); + h.app.agent_chat.items.push(Item::Tool { + id: "u".into(), + title: "mcp__github__create_issue".into(), + kind: String::new(), + status: Some(ToolStatus::InProgress), + input: None, + output: None, + }); + h.frames(3); + assert!(h.widget("Extrude Sketch1 by 10 mm").is_some(), "the summary is the card's title"); + assert!(h.widget("execute: solid.extrude").is_none(), "the raw title is not shown"); + assert!(h.widget("mcp__github__create_issue").is_some(), "a call with no words keeps its title"); + assert!(h.widget("Details").is_some(), "the expander is named"); + let pretty = serde_json::to_string_pretty(&input).unwrap(); + assert!(h.widget("Arguments").is_none() && h.widget(&pretty).is_none() && h.widget(output).is_none(), "the JSON waits behind Details"); + let card = handle_at(&format!("agent_chat:tool:{n}")).expect("the card"); + h.call("ui.click", json!({"x": card.x, "y": card.y})); + h.frames(3); + assert!(h.widget("Arguments").is_some() && h.widget(&pretty).is_some(), "the arguments unfold"); + assert!(h.widget("Result").is_some() && h.widget(output).is_some(), "and what it returned"); +} + +/// The card says "Screenshot"; the full temp path is only under Details. +#[test] +fn a_screenshot_card_hides_the_path_until_details() { + use crate::scenario::handle_at; + let mut h = crate::scenario::Harness::new(); + h.call("ui.agent_chat", json!({"open": true})); + h.frames(3); + let path = r"C:\Users\bherbruck\AppData\Local\Temp\solidcraft-mcp-8608-b4c7b64\shot-0.png"; + let n = h.app.agent_chat.items.len(); + h.app.agent_chat.items.push(Item::Tool { + id: "s".into(), + title: format!("ui.screenshot: {path}"), + kind: String::new(), + status: Some(ToolStatus::Completed), + input: Some(json!({"path": path})), + output: Some(path.into()), + }); + h.frames(3); + assert!(h.widget("Screenshot").is_some(), "the card says what it did"); + assert!(h.widget(path).is_none() && h.widget(&format!("ui.screenshot: {path}")).is_none(), "no path in the card"); + let card = handle_at(&format!("agent_chat:tool:{n}")).expect("the card"); + h.call("ui.click", json!({"x": card.x, "y": card.y})); + h.frames(3); + assert!(h.widget("Result").is_some() && h.widget(path).is_some(), "Details holds the full path"); +} diff --git a/crates/ui-egui/tests/assistant_render.rs b/crates/ui-egui/tests/assistant_render.rs index 746e8b8eb..be029d069 100644 --- a/crates/ui-egui/tests/assistant_render.rs +++ b/crates/ui-egui/tests/assistant_render.rs @@ -39,6 +39,7 @@ fn assistant_transcript_tools_and_approvals_fit_in_both_themes() { title: "parameters.set".into(), kind: "other".into(), status: Some(ToolStatus::Completed), + input: None, output: Some("plate_width = 80 mm".into()), }, Item::Tool { @@ -46,6 +47,7 @@ fn assistant_transcript_tools_and_approvals_fit_in_both_themes() { title: "solid.fillet".into(), kind: "other".into(), status: Some(ToolStatus::Failed), + input: None, output: Some("The requested radius is too large. Try a smaller radius.".into()), }, Item::Agent { diff --git a/crates/ui-egui/tests/icon_audit.rs b/crates/ui-egui/tests/icon_audit.rs index 70333d23b..b05896d18 100644 --- a/crates/ui-egui/tests/icon_audit.rs +++ b/crates/ui-egui/tests/icon_audit.rs @@ -107,6 +107,7 @@ fn assistant(h: &mut Harness, requested: &mut BTreeMap) { title: "solid.fillet".into(), kind: "other".into(), status: Some(ToolStatus::Failed), + input: None, output: Some("Use a smaller radius".into()), }, Item::Approval { id: 1, title: "Export plate.step".into(), tool: "export".into(), answer: None },