Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Agent chat: copy an entire sent prompt or assistant message (#10675) (#10741)

Dahak Builds6a7275a5afee
diff --git a/assets/locales/pending/agent-chat-copy-message.json b/assets/locales/pending/agent-chat-copy-message.json
new file mode 100644
index 0000000000..cb724aa67b
--- /dev/null
+++ b/assets/locales/pending/agent-chat-copy-message.json
@@ -0,0 +1,9 @@
+{
+ "en": { "ui.agent_chat_copy_message": "Copy message" },
+ "de": { "ui.agent_chat_copy_message": "Nachricht kopieren" },
+ "ar": { "ui.agent_chat_copy_message": "نسخ الرسالة" },
+ "he": { "ui.agent_chat_copy_message": "העתק הודעה" },
+ "ja": { "ui.agent_chat_copy_message": "メッセージをコピー" },
+ "vi": { "ui.agent_chat_copy_message": "Sao chép tin nhắn" },
+ "zh": { "ui.agent_chat_copy_message": "复制消息" }
+}
diff --git a/crates/ui-egui/src/agent_chat/panel.rs b/crates/ui-egui/src/agent_chat/panel.rs
index 8529dd01e9..201b2f8b8f 100644
--- a/crates/ui-egui/src/agent_chat/panel.rs
+++ b/crates/ui-egui/src/agent_chat/panel.rs
@@ -1613,6 +1613,49 @@ fn auth_box(app: &mut SolveApp, ui: &mut egui::Ui) {
});
}
+/// The visible **Copy message** button of one transcript message (#10675): copies the whole
+/// message — the prompt as entered, or the assistant's original Markdown — and nothing else.
+/// A streaming reply copies the stable text received so far, which is what `text` holds.
+#[cfg(not(target_arch = "wasm32"))]
+fn copy_message_button(ui: &mut egui::Ui, n: usize, text: &str) {
+ let b = ui_kit::button(ui, tr("ui.agent_chat_copy_message"), ui_kit::Button::Small);
+ crate::scenario::publish_handle(&format!("agent_chat:copy:{n}"), b.rect.center());
+ if b.clicked() {
+ ui.ctx().copy_text(text.to_owned());
+ }
+}
+
+/// The right-click menu of one transcript message (#10675): the same single action as the
+/// visible button, on the whole message area, beside the composer's own text menu.
+/// The area stays hover-only so partial text selection keeps working, so the menu opens on a
+/// right-click released over it rather than on a click the response itself would report.
+#[cfg(not(target_arch = "wasm32"))]
+fn copy_message_menu(ui: &egui::Ui, response: &egui::Response, n: usize, text: &str) {
+ crate::scenario::publish_rect(&format!("agent_chat:msg:{n}"), response.rect);
+ let opened = ui
+ .input(|i| i.pointer.button_released(egui::PointerButton::Secondary) && i.pointer.interact_pos().is_some_and(|p| response.rect.contains(p)));
+ let mut copy = false;
+ Container::new(ui.ctx(), Surface::Popup)
+ .menu(response)
+ .at_pointer_fixed()
+ .frame(ui_kit::Menu::frame())
+ .open_memory(if opened { Some(egui::SetOpenCommand::Bool(true)) } else { None })
+ .show(|ui| {
+ ui_kit::Menu::show(ui, crate::context_menu::LIST_W, |ui| {
+ let item = ui_kit::MenuItem::new("copy_message", tr("ui.agent_chat_copy_message"), "copy");
+ let row = item.show(ui);
+ crate::scenario::publish_handle(&format!("agent_chat:copy_menu:{n}"), row.rect.center());
+ if row.clicked() {
+ copy = true;
+ ui.close();
+ }
+ });
+ });
+ if copy {
+ ui.ctx().copy_text(text.to_owned());
+ }
+}
+
#[cfg(not(target_arch = "wasm32"))]
fn conversation(app: &mut SolveApp, ui: &mut egui::Ui) {
let t = Tokens::get();
@@ -1626,6 +1669,9 @@ fn conversation(app: &mut SolveApp, ui: &mut egui::Ui) {
for (n, item) in app.agent_chat.items.iter().enumerate() {
match item {
Item::User { text, image, pictures, context, files } => {
+ // A picture-only prompt has no text to copy: no action rather than an empty copy (#10675).
+ let copyable = !text.is_empty();
+ let before = ui.cursor();
ui_kit::assistant_bubble(ui, |ui| {
if !text.is_empty() {
ui.add(egui::Label::new(RichText::new(text).color(t.text)).selectable(true).wrap());
@@ -1640,13 +1686,28 @@ fn conversation(app: &mut SolveApp, ui: &mut egui::Ui) {
}
context_chips(ui, context, false);
files_line(ui, files.iter().map(String::as_str));
+ if copyable {
+ ui.with_layout(Layout::right_to_left(Align::Center), |ui| copy_message_button(ui, n, text));
+ }
});
+ if copyable {
+ let drawn = egui::Rect::from_x_y_ranges(before.x_range(), before.min.y..=ui.cursor().min.y);
+ let resp = ui.interact(drawn, Id::new(("agent_chat_msg", n)), Sense::hover());
+ copy_message_menu(ui, &resp, n, text);
+ }
}
Item::Agent { thought, text } => {
if *thought {
ui.add(egui::Label::new(RichText::new(text).italics().color(t.text_dim)).selectable(true).wrap());
} else {
+ let before = ui.cursor();
ui_kit::assistant_prose(ui, |ui| super::markdown_view::show(ui, n, text));
+ if !text.is_empty() {
+ copy_message_button(ui, n, text);
+ let drawn = egui::Rect::from_x_y_ranges(before.x_range(), before.min.y..=ui.cursor().min.y);
+ let resp = ui.interact(drawn, Id::new(("agent_chat_msg", n)), Sense::hover());
+ copy_message_menu(ui, &resp, n, text);
+ }
}
}
Item::Tool { .. } => {
diff --git a/crates/ui-egui/src/agent_chat/tests.rs b/crates/ui-egui/src/agent_chat/tests.rs
index 9f2054c916..7040dd8913 100644
--- a/crates/ui-egui/src/agent_chat/tests.rs
+++ b/crates/ui-egui/src/agent_chat/tests.rs
@@ -4159,3 +4159,101 @@ fn tool_room_beside_the_docked_assistant_survives_an_inside_out_view() {
assert!(free.min.x.is_finite() && free.max.x.is_finite(), "{side}: {free:?}");
}
}
+
+// ---- Copy message (#10675) ----
+
+/// A chat with a multi-paragraph prompt and a Markdown reply, both drawn.
+fn chat_with_copiable_messages() -> crate::scenario::Harness {
+ let mut h = crate::scenario::Harness::new();
+ h.call("ui.agent_chat", json!({"open": true}));
+ h.frames(3);
+ h.app.agent_chat.items.push(Item::User {
+ text: "make a plate\n\nwith two holes:\n- 6 mm\n- 8 mm".into(),
+ image: false,
+ pictures: Vec::new(),
+ files: Vec::new(),
+ context: Context::default(),
+ });
+ h.app.agent_chat.items.push(Item::Agent { thought: false, text: "# Result\n\nA plate with holes.\n\n```rust\nlet x = 1;\n```".into() });
+ h.frames(3);
+ h
+}
+
+/// The text the last frame copied to the clipboard, if any.
+fn copied_text(h: &crate::scenario::Harness) -> Option<String> {
+ h.output.commands.iter().rev().find_map(|c| match c {
+ egui::OutputCommand::CopyText(t) => Some(t.clone()),
+ _ => None,
+ })
+}
+
+fn click_at(h: &mut crate::scenario::Harness, at: egui::Pos2, button: egui::PointerButton) {
+ h.frame_with(vec![egui::Event::PointerMoved(at)]);
+ h.frame_with(vec![egui::Event::PointerButton { pos: at, button, pressed: true, modifiers: egui::Modifiers::NONE }]);
+ h.frame_with(vec![egui::Event::PointerButton { pos: at, button, pressed: false, modifiers: egui::Modifiers::NONE }]);
+}
+
+/// The visible button on a sent prompt copies the whole prompt, as entered.
+#[test]
+fn the_copy_message_button_copies_the_prompt_as_entered() {
+ let mut h = chat_with_copiable_messages();
+ let at = crate::scenario::handle_at("agent_chat:copy:0").expect("the prompt's Copy message button");
+ click_at(&mut h, at, egui::PointerButton::Primary);
+ assert_eq!(copied_text(&h).as_deref(), Some("make a plate\n\nwith two holes:\n- 6 mm\n- 8 mm"), "the whole prompt, paragraphs and list items");
+}
+
+/// The visible button on a reply copies its original Markdown: heading, paragraphs, list and
+/// fenced code, not the laid-out text.
+#[test]
+fn the_copy_message_button_copies_the_reply_as_original_markdown() {
+ let mut h = chat_with_copiable_messages();
+ let at = crate::scenario::handle_at("agent_chat:copy:1").expect("the reply's Copy message button");
+ click_at(&mut h, at, egui::PointerButton::Primary);
+ assert_eq!(copied_text(&h).as_deref(), Some("# Result\n\nA plate with holes.\n\n```rust\nlet x = 1;\n```"));
+}
+
+/// Right-clicking a message opens its menu, and its row copies the same whole reply.
+#[test]
+fn right_clicking_a_message_offers_copy_message() {
+ let mut h = chat_with_copiable_messages();
+ let msg = crate::scenario::rect_of("agent_chat:msg:1").expect("the reply's message area");
+ click_at(&mut h, msg.center(), egui::PointerButton::Secondary);
+ h.frames(1); // let the popup settle at its final place before clicking its row
+ let item = crate::scenario::handle_at("agent_chat:copy_menu:1").expect("the right-click menu's Copy message row");
+ click_at(&mut h, item, egui::PointerButton::Primary);
+ assert_eq!(copied_text(&h).as_deref(), Some("# Result\n\nA plate with holes.\n\n```rust\nlet x = 1;\n```"));
+}
+
+/// A reply that is still streaming copies the stable text received so far.
+#[test]
+fn a_streaming_reply_copies_the_text_received_so_far() {
+ let mut h = crate::scenario::Harness::new();
+ h.call("ui.agent_chat", json!({"open": true}));
+ h.frames(3);
+ h.app.agent_chat.items.push(Item::Agent { thought: false, text: "half a repl".into() });
+ h.frames(3);
+ let at = crate::scenario::handle_at("agent_chat:copy:0").expect("the streaming reply's button");
+ click_at(&mut h, at, egui::PointerButton::Primary);
+ assert_eq!(copied_text(&h).as_deref(), Some("half a repl"));
+}
+
+/// A picture-only prompt has no text to copy: no button, no menu, and a thought has none
+/// either — the clipboard is never overwritten with an empty string.
+#[test]
+fn a_picture_only_prompt_and_a_thought_have_no_copy_message_action() {
+ let mut h = crate::scenario::Harness::new();
+ h.call("ui.agent_chat", json!({"open": true}));
+ h.frames(3);
+ h.app.agent_chat.items.push(Item::User {
+ text: String::new(),
+ image: true,
+ pictures: Vec::new(),
+ files: Vec::new(),
+ context: Context::default(),
+ });
+ h.app.agent_chat.items.push(Item::Agent { thought: true, text: "pondering".into() });
+ h.frames(3);
+ assert!(crate::scenario::handle_at("agent_chat:copy:0").is_none(), "a picture-only prompt hides the text-copy action");
+ assert!(crate::scenario::handle_at("agent_chat:copy:1").is_none(), "a thought has no copy action");
+ assert!(h.widget("Copy message").is_none(), "nothing to click");
+}