diff --git a/crates/assistant/src/agent.rs b/crates/assistant/src/agent.rs index 6ad83ad696..d73a994f53 100644 --- a/crates/assistant/src/agent.rs +++ b/crates/assistant/src/agent.rs @@ -39,6 +39,10 @@ all the main assistant sees. Don't ask questions; where something is unclear, ma /// This is not a whole-conversation/run allowance; [`Config::pause_after`] separately pauses a user run. pub const MAX_RETRIES: u32 = 3; +/// What an [`Entry::Tool`] holds as its result when the user declined the call: it is marked as +/// failed, and this tells it from one that was tried. +pub const DECLINED: &str = "Declined"; + /// What the caller does next. #[derive(Debug, PartialEq)] pub enum Step { @@ -1095,7 +1099,7 @@ impl Agent { } else { ("The user declined this action. Don't retry it; ask what they'd like instead.".to_string(), true, Vec::new()) }; - let shown = if allow { content.clone() } else { "Declined".to_string() }; + let shown = if allow { content.clone() } else { DECLINED.to_string() }; let key = (call.name.clone(), call.args.to_string()); self.record(call, content, shown, error, images); // The user declining it isn't the call failing. diff --git a/crates/assistant/src/lib.rs b/crates/assistant/src/lib.rs index f4f530598b..8b300c2b54 100644 --- a/crates/assistant/src/lib.rs +++ b/crates/assistant/src/lib.rs @@ -37,5 +37,5 @@ pub mod skills; mod tests; pub mod tools; -pub use agent::{Agent, Asking, Entry, Step}; +pub use agent::{Agent, Asking, DECLINED, Entry, Step}; pub use provider::{Api, Config, HttpRequest, HttpResponse, Note, PRESETS, Preset}; diff --git a/crates/ui-egui/src/assistant.rs b/crates/ui-egui/src/assistant.rs index e0adf767df..17f896b02f 100644 --- a/crates/ui-egui/src/assistant.rs +++ b/crates/ui-egui/src/assistant.rs @@ -112,6 +112,8 @@ pub struct AssistantState { pub(crate) local_agents: bool, /// The tokens a message took are left out of the conversation (shown unless the user says). pub(crate) hide_tokens: bool, + /// Each call has a line of its own instead of sharing one ([`lines`]). + pub(crate) every_step: bool, /// Agent threads on this computer: their processes, windows and requests (desktop). #[cfg(not(target_arch = "wasm32"))] pub(crate) threads: crate::agentthreads::Threads, @@ -291,6 +293,20 @@ pub fn showing_tokens(app: &RustGisApp) -> bool { !app.assistant.hide_tokens } +/// The preference that gives each call the assistant makes a line of its own ("on"). +const EVERY_STEP_PREF: &str = "assistant_show_every_step"; + +/// Gives each call a line of its own, or groups them ([`lines`]), and remembers it. +pub fn show_every_step(app: &mut RustGisApp, every: bool) { + app.assistant.every_step = every; + save_pref(app, EVERY_STEP_PREF, if every { "on" } else { "off" }); +} + +/// Whether each call the assistant makes has a line of its own. +pub fn showing_every_step(app: &RustGisApp) -> bool { + app.assistant.every_step +} + /// Saves a preference through the platform hook. pub(crate) fn save_pref(app: &RustGisApp, key: &str, value: &str) { if let Some(s) = &app.services.save_pref { @@ -380,6 +396,7 @@ pub(crate) fn ensure_loaded(app: &mut RustGisApp, ctx: &egui::Context) { let mut agent = Agent::new(cfg, &app.session); app.assistant.local_agents = pref(app, "assistant_local_agents").as_deref() == Some("on"); app.assistant.hide_tokens = pref(app, TOKENS_PREF).as_deref() == Some("off"); + app.assistant.every_step = pref(app, EVERY_STEP_PREF).as_deref() == Some("on"); // A pause set in the environment that isn't one is said, as the command line says it. if let Ok(asked) = std::env::var(provider::PAUSE_ENV) && !asked.trim().is_empty() @@ -1237,6 +1254,99 @@ pub fn plain_call(app: &RustGisApp, name: &str, summary: &str) -> String { } } +/// A line of the conversation as it is drawn ([`lines`]), each entry with its place in +/// [`AssistantState::messages`]. +pub enum Line<'a> { + /// A message, a note, an error, or a call on a line of its own. + Entry(usize, &'a Entry), + /// Calls that share a line. + Steps(Steps<'a>), +} + +/// Two or more calls that share a line, which opens to show each. +pub struct Steps<'a> { + /// The calls ([`Entry::Tool`]), oldest first. + pub calls: Vec<(usize, &'a Entry)>, + /// More may still join them: the run they are part of goes on. + pub running: bool, +} + +/// The conversation as it is drawn. Unless every step is asked for ([`showing_every_step`]), the +/// calls between one message, note or error and the next share a line, which stands where the +/// latest of them was made: what the model said between them comes before it, and what it said +/// after them (its reply) comes after. Messages, notes (a pause, a stop, a retry) and errors are +/// never part of it. +pub fn lines(app: &RustGisApp) -> Vec> { + let entries = app.assistant.messages(); + if app.assistant.every_step { + return entries.iter().enumerate().map(|(i, e)| Line::Entry(i, e)).collect(); + } + let mut lines = Vec::new(); + let mut calls = Vec::new(); + // What the model said since the last call: before the calls' line if another call follows. + let mut said = Vec::new(); + for (i, e) in entries.iter().enumerate() { + match e { + Entry::Tool { .. } => { + lines.append(&mut said); + calls.push((i, e)); + } + Entry::Assistant(_) if !calls.is_empty() => said.push(Line::Entry(i, e)), + Entry::Assistant(_) => lines.push(Line::Entry(i, e)), + Entry::User(_) | Entry::Note(_) | Entry::Error(_) => { + share_line(&mut lines, &mut calls, false); + lines.append(&mut said); + lines.push(Line::Entry(i, e)); + } + } + } + share_line(&mut lines, &mut calls, app.assistant.busy()); + lines.append(&mut said); + lines +} + +/// Puts the calls gathered on one line of [`lines`]; one call alone keeps its own. +fn share_line<'a>(lines: &mut Vec>, calls: &mut Vec<(usize, &'a Entry)>, running: bool) { + if calls.len() > 1 { + lines.push(Line::Steps(Steps { calls: std::mem::take(calls), running })); + } else { + lines.extend(calls.drain(..).map(|(i, e)| Line::Entry(i, e))); + } +} + +/// What the line of calls that share one says: how many, how many of them failed or were +/// declined, and while the run goes on, the latest in words ([`plain_call`]). In display form. +pub fn steps_line(app: &RustGisApp, steps: &Steps<'_>) -> String { + use crate::i18n::fmt_raw; + let (mut failed, mut declined) = (0, 0); + for (_, e) in &steps.calls { + if let Entry::Tool { result, error: true, .. } = e { + if result == rustgis_assistant::DECLINED { + declined += 1; + } else { + failed += 1; + } + } + } + let count = steps.calls.len().to_string(); + let count = [("count", count.as_str())]; + // "Actions", not "steps": a step, as the pause settings count them, may make several. + let mut parts = + vec![if steps.running { fmt_raw("{count} actions so far", &count) } else { fmt_raw("Worked through {count} actions", &count) }]; + if failed > 0 { + parts.push(fmt_raw("{count} failed", &[("count", &failed.to_string())])); + } + if declined > 0 { + parts.push(fmt_raw("{count} declined", &[("count", &declined.to_string())])); + } + if steps.running + && let Some((_, Entry::Tool { name, summary, error, .. })) = steps.calls.last() + { + parts.push(format!("{} {}", if *error { "✗" } else { "✓" }, plain_call(app, name, summary))); + } + crate::i18n::display(&parts.join(" · ")) +} + /// An action waiting for the user's approval. #[derive(Clone)] pub struct Approval { diff --git a/crates/ui-egui/src/assistantpane.rs b/crates/ui-egui/src/assistantpane.rs index 35491b3ff8..644543fa28 100644 --- a/crates/ui-egui/src/assistantpane.rs +++ b/crates/ui-egui/src/assistantpane.rs @@ -133,6 +133,14 @@ fn settings(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { { assistant::show_tokens(app, tokens); } + let mut every = assistant::showing_every_step(app); + if ui + .checkbox(&mut every, tl!("Show every step")) + .on_hover_text(tl!("Give each action of the assistant's a line of its own, instead of one line for those it takes in a row.")) + .changed() + { + assistant::show_every_step(app, every); + } #[cfg(not(target_arch = "wasm32"))] local_agents_setting(app, ui, t); #[cfg(not(target_arch = "wasm32"))] @@ -867,6 +875,63 @@ pub fn error(ui: &mut Ui, e: &rustgis_assistant::Error, t: &Tokens) { show_error(ui, e, t); } +/// One entry of the conversation, `i` its place in it. +fn entry(app: &RustGisApp, ui: &mut Ui, t: &Tokens, i: usize, e: &Entry) { + match e { + // A message of pictures alone: its notes say them. + Entry::User(text) if text.is_empty() => {} + Entry::User(text) => { + ui.add_space(6.0); + ui.with_layout(Layout::right_to_left(Align::Min), |ui| { + egui::Frame::NONE.fill(t.selection).corner_radius(8).inner_margin(egui::Margin::symmetric(10, 6)).show(ui, |ui| { + ui.set_max_width(ui.available_width() * 0.85); + ui.add(egui::Label::new(RichText::new(text).color(t.text)).halign(Align::LEFT)); + }); + }); + ui.add_space(4.0); + } + Entry::Assistant(text) => { + markdown(ui, text, t); + ui.add_space(4.0); + } + Entry::Tool { name, summary, result, error } => { + let (mark, col) = if *error { ("✗", t.red) } else { ("✓", t.green) }; + let head = format!("{mark} {}", assistant::plain_call(app, name, summary)); + // A call's header never wraps: it is cut to the room there is. Opened, it shows the whole call. + let head = header(ui, &crate::i18n::display(&head), col, egui::TextWrapMode::Truncate); + egui::CollapsingHeader::new(head).id_salt(("assistant_tool", i, name, summary.as_str())).show(ui, |ui| { + ui.label(RichText::new(summary).monospace().small()); + ui.label(RichText::new(result.chars().take(2000).collect::()).monospace().small().color(t.text_dim)); + }); + } + Entry::Error(e) => show_error(ui, e, t), + Entry::Note(n) => { + ui.label(RichText::new(crate::i18n::note(n)).small().italics().color(t.text_dim)); + } + } +} + +/// The line calls share, which opens to a line for each. +fn shared_steps(app: &RustGisApp, ui: &mut Ui, t: &Tokens, steps: &assistant::Steps<'_>) { + // Wrapped, so the counts are never cut off. + let head = header(ui, &assistant::steps_line(app, steps), t.text_dim, egui::TextWrapMode::Wrap); + // By the first call's place, which stays as more join. + let first = steps.calls.first().map(|(i, _)| *i); + egui::CollapsingHeader::new(head).id_salt(("assistant_steps", first)).show(ui, |ui| { + for (i, e) in &steps.calls { + entry(app, ui, t, *i, e); + } + }); +} + +/// A collapsing header's text, laid out in the room the header has. +fn header(ui: &Ui, text: &str, color: egui::Color32, wrap: egui::TextWrapMode) -> std::sync::Arc { + let room = (ui.available_width() - ui.spacing().indent - ui.spacing().button_padding.x).max(0.0); + egui::WidgetText::from(RichText::new(text).small().color(color)).into_galley(ui, Some(wrap), room, egui::TextStyle::Button) +} + +/// Suggestions while the conversation is empty; else its lines, the tokens line, the way on from a +/// pause and the reply on its way. fn transcript(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, ctx: &egui::Context) { if app.assistant.config().is_none() { return; @@ -887,46 +952,10 @@ fn transcript(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, ctx: &egui::Context } return; } - for e in app.assistant.messages() { - match e { - // A message of pictures alone: its notes say them. - Entry::User(text) if text.is_empty() => {} - Entry::User(text) => { - ui.add_space(6.0); - ui.with_layout(Layout::right_to_left(Align::Min), |ui| { - egui::Frame::NONE.fill(t.selection).corner_radius(8).inner_margin(egui::Margin::symmetric(10, 6)).show(ui, |ui| { - ui.set_max_width(ui.available_width() * 0.85); - ui.add(egui::Label::new(RichText::new(text).color(t.text)).halign(Align::LEFT)); - }); - }); - ui.add_space(4.0); - } - Entry::Assistant(text) => { - markdown(ui, text, t); - ui.add_space(4.0); - } - Entry::Tool { name, summary, result, error } => { - let (mark, col) = if *error { ("✗", t.red) } else { ("✓", t.green) }; - let head = format!("{mark} {}", assistant::plain_call(app, name, summary)); - // A header never wraps: it is cut to the room there is. Opened, it shows the whole call. - let room = (ui.available_width() - ui.spacing().indent - ui.spacing().button_padding.x).max(0.0); - let head = egui::WidgetText::from(RichText::new(crate::i18n::display(&head)).small().color(col)).into_galley( - ui, - Some(egui::TextWrapMode::Truncate), - room, - egui::TextStyle::Button, - ); - egui::CollapsingHeader::new(head).id_salt(("assistant_tool", name, summary.as_str(), result.len())).show(ui, |ui| { - ui.label(RichText::new(summary).monospace().small()); - ui.label(RichText::new(result.chars().take(2000).collect::()).monospace().small().color(t.text_dim)); - }); - } - Entry::Error(e) => { - show_error(ui, e, t); - } - Entry::Note(n) => { - ui.label(RichText::new(crate::i18n::note(n)).small().italics().color(t.text_dim)); - } + for line in assistant::lines(app) { + match line { + assistant::Line::Entry(i, e) => entry(app, ui, t, i, e), + assistant::Line::Steps(steps) => shared_steps(app, ui, t, &steps), } } if !app.assistant.busy() @@ -1497,6 +1526,107 @@ pub(crate) mod tests { assert!(saved.lock().unwrap().contains(&("assistant_show_tokens".into(), "off".into()))); } + /// Calls made in a row share a line saying how many, how many failed or were declined and, + /// while the run goes on, the latest. A request for approval and the reply stay outside it, and + /// the setting, which is kept, gives each call a line of its own. + #[test] + fn calls_in_a_row_share_a_line_until_every_step_is_asked_for() { + use egui_kittest::kittest::Queryable; + use serde_json::json; + use std::sync::{Arc, Mutex}; + let mut app = plan_app(); + let saved = Arc::new(Mutex::new(Vec::new())); + let keep = saved.clone(); + app.services.save_pref = Some(Box::new(move |k, v| keep.lock().unwrap().push((k.to_string(), v.to_string())))); + // Requests after the first are held back. + app.services.http = Some(Box::new(|_, _| {})); + let config = + Config { provider: "custom".into(), base_url: "http://localhost:1/v1".into(), model: "m".into(), ..Config::from_env("custom") }; + let mut agent = Agent::new(config, &app.session); + agent.ask("hi", &app.session); + let call = |id: &str, name: &str, args: serde_json::Value| json!({"id": id, "type": "function", "function": {"name": name, "arguments": args.to_string()}}); + let answer = |message: serde_json::Value| { + let body = json!({"choices": [{"message": message, "finish_reason": "stop"}]}).to_string().into_bytes(); + Ok(HttpResponse { status: 200, body, headers: vec![] }) + }; + let calls = [ + call("1", "list_layers", json!({})), + call("2", "run_command", json!({"command": "no.such", "params": {}})), + call("3", "run_command", json!({"command": "sql.query", "params": {"sql": "SELECT 1"}})), + ]; + agent.receive(agent.generation(), answer(json!({"role": "assistant", "content": null, "tool_calls": calls})), &mut app.session); + app.assistant.agent = Some(agent); + // Open settings would leave the conversation no room to be clicked in. + app.assistant.settings = false; + let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 860.0)).build_ui_state( + |ui, app: &mut RustGisApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + app, + ); + h.run_steps(4); + // Waiting for approval: the card is outside the line. + h.get_by_label("2 actions so far · 1 failed · ✗ no.such"); + h.get_by_label("Allow this action?"); + assert!(h.query_by_label("✓ Looked at the layers").is_none()); + h.get_by_label("Decline").click(); + h.run_steps(4); + h.get_by_label_contains("3 actions so far · 1 failed · 1 declined · ✗ "); + let app = h.state_mut(); + let agent = app.assistant.agent.as_mut().unwrap(); + agent.receive(agent.generation(), answer(json!({"role": "assistant", "content": "All checked."})), &mut app.session); + h.run_steps(4); + h.get_by_label("All checked."); + h.get_by_label("Worked through 3 actions · 1 failed · 1 declined").click(); + h.run_steps(8); + h.get_by_label("✓ Looked at the layers"); + h.get_by_label("✗ no.such"); + toggle_settings(h.state_mut()); + h.run_steps(4); + // Folded, the provider's settings leave the checkboxes below them in sight. + h.get_by_label("AI provider").click(); + h.run_steps(4); + h.get_by_label("Show every step").click(); + h.run_steps(4); + assert!(h.query_by_label_contains("Worked through").is_none()); + h.get_by_label("✓ Looked at the layers"); + assert!(saved.lock().unwrap().contains(&("assistant_show_every_step".into(), "on".into()))); + } + + /// A line of calls ends at a message, a note (a pause, a retry) and an error, and takes in + /// calls made either side of what the model said between them; one call alone keeps its own. + #[test] + fn a_line_of_calls_ends_at_messages_notes_and_errors() { + let mut app = plan_app(); + let tool = || Entry::Tool { name: "list_layers".into(), summary: "list_layers {}".into(), result: "[]".into(), error: false }; + app.assistant.agent.as_mut().unwrap().transcript = vec![ + Entry::User("go".into()), + tool(), + Entry::Assistant("Now the rest.".into()), + tool(), + Entry::Note(rustgis_assistant::Note::new("Stopped.")), + tool(), + Entry::Error(String::from("no").into()), + tool(), + tool(), + Entry::Assistant("Done.".into()), + ]; + let shape = |app: &RustGisApp| -> Vec { + assistant::lines(app) + .iter() + .map(|line| match line { + assistant::Line::Entry(i, _) => i.to_string(), + assistant::Line::Steps(s) => format!("{:?}", s.calls.iter().map(|(i, _)| *i).collect::>()), + }) + .collect() + }; + assert_eq!(shape(&app), ["0", "2", "[1, 3]", "4", "5", "6", "[7, 8]", "9"]); + app.assistant.every_step = true; + assert_eq!(shape(&app), ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]); + } + /// Steps in words: the command's name and its layer, what a search was for, a subagent's /// mark, and the call itself where its parameters were cut. #[test] diff --git a/crates/ui-touch/src/assistant.rs b/crates/ui-touch/src/assistant.rs index 910a97bdd3..2be3f4fda2 100644 --- a/crates/ui-touch/src/assistant.rs +++ b/crates/ui-touch/src/assistant.rs @@ -382,43 +382,10 @@ fn messages(app: &RustGisApp, ui: &mut Ui, t: &Tokens) { ui.label(RichText::new(hint).size(15.0).color(t.text_dim)); return; } - for (i, e) in app.assistant.messages().iter().enumerate() { - match e { - // A message of pictures alone: its notes say them. - Entry::User(text) if text.is_empty() => {} - Entry::User(text) => { - ui.add_space(6.0); - ui.with_layout(Layout::right_to_left(Align::Min), |ui| { - egui::Frame::NONE.fill(t.selection).corner_radius(8).inner_margin(egui::Margin::symmetric(12, 8)).show(ui, |ui| { - ui.set_max_width(ui.available_width() * 0.85); - ui.add(egui::Label::new(RichText::new(text).size(15.0).color(t.text)).halign(Align::LEFT)); - }); - }); - ui.add_space(4.0); - } - Entry::Assistant(text) => { - assistant::reply(ui, text, t); - ui.add_space(4.0); - } - Entry::Tool { name, summary, result, error } => { - let (mark, ink) = if *error { ("✗", t.red) } else { ("✓", t.green) }; - let head = - RichText::new(i18n::display(&format!("{mark} {}", assistant::plain_call(app, name, summary)))).size(14.0).color(ink); - egui::CollapsingHeader::new(head).id_salt(("touch_assistant_tool", i)).show(ui, |ui| { - ui.label(RichText::new(summary).monospace().small()); - let shown: String = result.chars().take(2000).collect(); - ui.label(RichText::new(&shown).monospace().small().color(t.text_dim)); - let left = result.chars().count().saturating_sub(2000); - if left > 0 { - let more = i18n::fmt("… and {n} more characters.", &[("n", &left.to_string())]); - ui.label(RichText::new(more).small().italics().color(t.text_dim)); - } - }); - } - Entry::Error(e) => assistant::error(ui, e, t), - Entry::Note(n) => { - ui.label(RichText::new(i18n::note(n)).size(13.0).italics().color(t.text_dim)); - } + for line in assistant::lines(app) { + match line { + assistant::Line::Entry(i, e) => entry(app, ui, t, i, e), + assistant::Line::Steps(steps) => shared_steps(app, ui, t, &steps), } } if !app.assistant.busy() @@ -442,6 +409,65 @@ fn messages(app: &RustGisApp, ui: &mut Ui, t: &Tokens) { } } +/// One entry of the conversation, `i` its place in it. +fn entry(app: &RustGisApp, ui: &mut Ui, t: &Tokens, i: usize, e: &Entry) { + match e { + // A message of pictures alone: its notes say them. + Entry::User(text) if text.is_empty() => {} + Entry::User(text) => { + ui.add_space(6.0); + ui.with_layout(Layout::right_to_left(Align::Min), |ui| { + egui::Frame::NONE.fill(t.selection).corner_radius(8).inner_margin(egui::Margin::symmetric(12, 8)).show(ui, |ui| { + ui.set_max_width(ui.available_width() * 0.85); + ui.add(egui::Label::new(RichText::new(text).size(15.0).color(t.text)).halign(Align::LEFT)); + }); + }); + ui.add_space(4.0); + } + Entry::Assistant(text) => { + assistant::reply(ui, text, t); + ui.add_space(4.0); + } + Entry::Tool { name, summary, result, error } => { + let (mark, ink) = if *error { ("✗", t.red) } else { ("✓", t.green) }; + let head = RichText::new(i18n::display(&format!("{mark} {}", assistant::plain_call(app, name, summary)))).size(14.0).color(ink); + egui::CollapsingHeader::new(head).id_salt(("touch_assistant_tool", i)).show(ui, |ui| { + ui.label(RichText::new(summary).monospace().small()); + let shown: String = result.chars().take(2000).collect(); + ui.label(RichText::new(&shown).monospace().small().color(t.text_dim)); + let left = result.chars().count().saturating_sub(2000); + if left > 0 { + let more = i18n::fmt("… and {n} more characters.", &[("n", &left.to_string())]); + ui.label(RichText::new(more).small().italics().color(t.text_dim)); + } + }); + } + Entry::Error(e) => assistant::error(ui, e, t), + Entry::Note(n) => { + ui.label(RichText::new(i18n::note(n)).size(13.0).italics().color(t.text_dim)); + } + } +} + +/// The line calls share, which opens to a line for each. +fn shared_steps(app: &RustGisApp, ui: &mut Ui, t: &Tokens, steps: &assistant::Steps<'_>) { + // Wrapped, so the counts are never cut off. + let room = (ui.available_width() - ui.spacing().indent - ui.spacing().button_padding.x).max(0.0); + let head = egui::WidgetText::from(RichText::new(assistant::steps_line(app, steps)).size(14.0).color(t.text_dim)).into_galley( + ui, + Some(egui::TextWrapMode::Wrap), + room, + egui::TextStyle::Button, + ); + // By the first call's place, which stays as more join. + let first = steps.calls.first().map(|(i, _)| *i); + egui::CollapsingHeader::new(head).id_salt(("touch_assistant_steps", first)).show(ui, |ui| { + for (i, e) in &steps.calls { + entry(app, ui, t, *i, e); + } + }); +} + /// The approval waiting, as a card: what would run, Stop, Decline and Allow a finger's height, /// and "Don't ask again for exactly this action" where the action may be. `room` is the sheet's /// body: the details scroll in what the card's other rows leave of it. @@ -651,6 +677,10 @@ fn settings_form(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, state: &mut Chat if toggle_chip(ui, t, tl!("Show the tokens each message uses"), ui.available_width(), tokens) { assistant::show_tokens(app, !tokens); } + let every = assistant::showing_every_step(app); + if toggle_chip(ui, t, tl!("Show every step"), ui.available_width(), every) { + assistant::show_every_step(app, !every); + } label(ui, t, tl!("Pause long runs after this many steps")); let after = cfg.pause_after(); // A number set elsewhere is offered among the usual ones. @@ -1088,6 +1118,36 @@ mod tests { assert_eq!(held.app.assistant.input, "", "Enter sent it, adding no line"); } + /// The sheet's calls made in a row share a line, as the desktop's do, until every step is + /// asked for. + #[test] + fn calls_in_a_row_share_a_line_on_the_sheet() { + let mut held = Held::new(); + provider(&mut held, "custom", "test"); + let step = |id| command(id, "map.zoomIn", json!({})); + answering(&mut held, vec![step("a"), step("b"), say("Done zooming.")]); + raise(&held.ctx, Height::Full); + held.app.assistant.input = "Zoom in".into(); + let send = held.find("Send").unwrap().center(); + held.touch(&[send]); + for _ in 0..3 { + held.frame(Vec::new()); + } + assert!(held.find("Done zooming.").is_some()); + assert!(held.find("✓ Fixed Zoom In").is_none()); + let line = held.find("Worked through 2 actions").expect("one line for both").center(); + held.touch(&[line]); + // Opening it takes a few frames. + for _ in 0..6 { + held.frame(Vec::new()); + } + assert!(held.find("✓ Fixed Zoom In").is_some()); + assistant::show_every_step(&mut held.app, true); + held.frame(Vec::new()); + assert!(held.find("Worked through 2 actions").is_none()); + assert!(held.find("✓ Fixed Zoom In").is_some()); + } + #[test] fn a_paused_run_goes_on_from_the_sheet() { let mut held = Held::new(); diff --git a/docs/user-guide/assistant.md b/docs/user-guide/assistant.md index 558fc17200..f04c1dd650 100644 --- a/docs/user-guide/assistant.md +++ b/docs/user-guide/assistant.md @@ -141,6 +141,15 @@ field changes the endpoint for providers other than ChatGPT; use the OpenAI-comp path (usually `/v1`) for local servers. Models that call tools well give the best results; small local models may stop early or skip steps. +### Steps + +When the assistant takes several actions in a row, the conversation shows one line for them, such +as **Worked through 16 actions · 2 failed**, with declined ones counted too. While it works, the +line says how many so far and what the latest was. Select the line to see each action, and one of +those to see the call and what came back. Messages, requests for approval, pauses, errors and notes +are never inside it, so a retry or a pause partway through starts a new line. **Show every step** +in the settings gives each action a line of its own. + ### Long runs A step is one reply of the model's that uses tools. Where the provider bills each request, a run