diff --git a/apps/solidcraft/src/main.rs b/apps/solidcraft/src/main.rs index 9e1ca38ac..7b5c07fb6 100644 --- a/apps/solidcraft/src/main.rs +++ b/apps/solidcraft/src/main.rs @@ -369,7 +369,7 @@ fn agent_http(r: &solidcraft_ui_egui::agent_chat::backend::HttpRequest) -> Resul let agent: ureq::Agent = ureq::Agent::config_builder() .tls_config(tls) .http_status_as_error(false) - .timeout_global(Some(Duration::from_secs(r.timeout_s.clamp(1, 900)))) + .timeout_global(Some(Duration::from_secs(r.timeout_s.clamp(1, 3600)))) .timeout_connect(Some(Duration::from_secs(10))) .user_agent("SolidCraft") .max_redirects(0) diff --git a/assets/locales/en.json b/assets/locales/en.json index b013b10da..47796f429 100644 --- a/assets/locales/en.json +++ b/assets/locales/en.json @@ -2428,6 +2428,9 @@ "ui.ai_protocol": "Protocol", "ui.ai_remove": "Remove", "ui.ai_request_limit": "stopped after 24 requests for one message; send another message to go on", + "ui.ai_request_timed_out": "The model took longer than {seconds} s. You can raise the request timeout for this endpoint in Preferences › Assistant.", + "ui.ai_request_timeout": "Request timeout", + "ui.ai_request_timeout_hint": "How long one model request to this endpoint may take, from 30 s to an hour. Raise it for a slow local model.", "ui.ai_reset": "Reset", "ui.ai_settings": "AI settings…", "ui.ai_show_features": "Show AI features", diff --git a/assets/locales/ja.json b/assets/locales/ja.json index 324bd212a..601bf3c86 100644 --- a/assets/locales/ja.json +++ b/assets/locales/ja.json @@ -2428,6 +2428,9 @@ "ui.ai_protocol": "プロトコル", "ui.ai_remove": "削除", "ui.ai_request_limit": "1メッセージあたり24リクエストで停止しました。続けるには、もう一度メッセージを送ってください", + "ui.ai_request_timed_out": "モデルの応答に {seconds} 秒以上かかりました。このエンドポイントのリクエストのタイムアウトは、環境設定 › アシスタントで長くできます。", + "ui.ai_request_timeout": "リクエストのタイムアウト", + "ui.ai_request_timeout_hint": "このエンドポイントへのモデルリクエスト1回にかけられる時間です(30秒〜1時間)。遅いローカルモデルでは長くしてください。", "ui.ai_reset": "リセット", "ui.ai_settings": "AI 設定…", "ui.ai_show_features": "AI 機能を表示", diff --git a/assets/locales/zh.json b/assets/locales/zh.json index 4b9f62811..215c64cb5 100644 --- a/assets/locales/zh.json +++ b/assets/locales/zh.json @@ -2428,6 +2428,9 @@ "ui.ai_protocol": "协议", "ui.ai_remove": "移除", "ui.ai_request_limit": "每条消息 24 次请求后已停止;再发送一条消息即可继续", + "ui.ai_request_timed_out": "模型用时超过 {seconds} 秒。可在“首选项 › 助手”中调高此端点的请求超时。", + "ui.ai_request_timeout": "请求超时", + "ui.ai_request_timeout_hint": "对此端点的一次模型请求最多可用的时间,30 秒到 1 小时。本地模型较慢时请调高。", "ui.ai_reset": "重置", "ui.ai_settings": "AI 设置…", "ui.ai_show_features": "显示 AI 功能", diff --git a/crates/ui-egui/src/agent_chat/agents.rs b/crates/ui-egui/src/agent_chat/agents.rs index 1bcb01954..6bdaab81b 100644 --- a/crates/ui-egui/src/agent_chat/agents.rs +++ b/crates/ui-egui/src/agent_chat/agents.rs @@ -95,7 +95,7 @@ impl Protocol { } /// An agent the user added. -#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(default)] pub struct AgentConfig { pub id: String, @@ -108,6 +108,41 @@ pub struct AgentConfig { pub model: String, /// API: a key is stored for it in the system keychain. pub key: bool, + /// API: how long one model request may take, in seconds (clamped to + /// [`MIN_REQUEST_TIMEOUT_S`]..=[`MAX_REQUEST_TIMEOUT_S`] where it is used). + pub request_timeout_s: u64, +} + +impl Default for AgentConfig { + fn default() -> AgentConfig { + AgentConfig { + id: String::new(), + name: String::new(), + kind: Kind::default(), + command: String::new(), + base_url: String::new(), + model: String::new(), + key: false, + request_timeout_s: DEFAULT_REQUEST_TIMEOUT_S, + } + } +} + +/// How long one model request to an endpoint may take by default, in seconds. +pub const DEFAULT_REQUEST_TIMEOUT_S: u64 = 300; +/// The shortest request timeout an endpoint can have. +pub const MIN_REQUEST_TIMEOUT_S: u64 = 30; +/// The longest request timeout an endpoint can have (an hour). +pub const MAX_REQUEST_TIMEOUT_S: u64 = 3600; + +/// A request timeout in range: seconds from a preferences file, the dialog or the control +/// channel, rounded and clamped; anything not a finite number is the default. +pub fn request_timeout_s(secs: f64) -> u64 { + if !secs.is_finite() { + return DEFAULT_REQUEST_TIMEOUT_S; + } + // Clamped first, so the cast is exact. + secs.round().clamp(MIN_REQUEST_TIMEOUT_S as f64, MAX_REQUEST_TIMEOUT_S as f64) as u64 } /// An agent as the picker and the switcher show it. @@ -126,6 +161,8 @@ pub struct Entry { pub base_url: String, pub model: String, pub key: bool, + /// API: seconds one model request may take (in range). + pub request_timeout_s: u64, } impl Entry { @@ -141,6 +178,7 @@ impl Entry { base_url: c.base_url.clone(), model: c.model.clone(), key: c.key, + request_timeout_s: c.request_timeout_s.clamp(MIN_REQUEST_TIMEOUT_S, MAX_REQUEST_TIMEOUT_S), } } /// A short line under the name: the version, the model, or the command. @@ -171,6 +209,7 @@ pub fn entries(app: &crate::SolveApp) -> Vec { base_url: String::new(), model: String::new(), key: false, + request_timeout_s: DEFAULT_REQUEST_TIMEOUT_S, })); } out.extend(app.preferences.agents.iter().map(Entry::from_config)); @@ -309,4 +348,23 @@ mod tests { assert!(presets(Protocol::OpenAi).iter().all(|p| !p.name.is_empty() && p.base_url.starts_with("http"))); assert!(presets(Protocol::Anthropic).iter().any(|p| p.base_url == "https://api.anthropic.com/v1")); } + + #[test] + fn request_timeouts_default_to_300_s_and_stay_between_30_s_and_an_hour() { + assert_eq!(AgentConfig::default().request_timeout_s, 300); + assert_eq!(request_timeout_s(600.4), 600); + assert_eq!(request_timeout_s(1.0), 30); + assert_eq!(request_timeout_s(-5.0), 30); + assert_eq!(request_timeout_s(1e300), 3600); + assert_eq!(request_timeout_s(f64::NAN), 300); + assert_eq!(request_timeout_s(f64::INFINITY), 300); + // An older preferences file has no timeout: the default; a hand-edited one is clamped where used. + let old: AgentConfig = serde_json::from_str(r#"{"id":"api-1","kind":"api","base_url":"http://localhost:11434/v1","model":"m"}"#).unwrap(); + assert_eq!(old.request_timeout_s, 300); + let wild: AgentConfig = serde_json::from_str(r#"{"id":"api-2","kind":"api","request_timeout_s":99999}"#).unwrap(); + assert_eq!(Entry::from_config(&wild).request_timeout_s, 3600); + let saved = AgentConfig { id: "api-3".into(), kind: Kind::Api, request_timeout_s: 1200, ..Default::default() }; + let back: AgentConfig = serde_json::from_value(serde_json::to_value(&saved).unwrap()).unwrap(); + assert_eq!(back, saved); + } } diff --git a/crates/ui-egui/src/agent_chat/api_client.rs b/crates/ui-egui/src/agent_chat/api_client.rs index c3d074027..d4b13678c 100644 --- a/crates/ui-egui/src/agent_chat/api_client.rs +++ b/crates/ui-egui/src/agent_chat/api_client.rs @@ -26,9 +26,10 @@ pub const MAX_REQUESTS_PER_TURN: usize = 24; const MAX_TOOL_TEXT: usize = 20_000; /// Messages kept in the conversation (the system note stays). const MAX_HISTORY: usize = 240; -/// How long one model request may take. -const REQUEST_TIMEOUT_S: u64 = 300; -/// How long one tool call may take (it may wait for the user's Allow). +/// How long one tool call may take (it may wait for the user's Allow, declined after four +/// minutes). It does not depend on the endpoint's request timeout: a tool call is SolidCraft's own +/// work and the user's answer, never a wait for the model, so a longer request timeout does not +/// need a longer tool timeout. const TOOL_TIMEOUT: Duration = Duration::from_secs(330); /// How often a waiting request or tool call looks at the cancel flag. const CANCEL_POLL: Duration = Duration::from_millis(40); @@ -51,12 +52,15 @@ pub struct ApiConfig { pub model: String, pub key: Option, pub http: HttpFn, + /// How long one model request may take, in seconds (the endpoint's setting). + pub request_timeout_s: u64, } enum Cmd { Prompt(Vec), NewChat, SetModel(String), + SetRequestTimeout(u64), } pub struct ApiBackend { @@ -122,6 +126,11 @@ impl ChatBackend for ApiBackend { let _ = c.send(Cmd::SetModel(model.to_string())); } } + fn set_request_timeout(&mut self, secs: u64) { + if let Some(c) = &self.cmds { + let _ = c.send(Cmd::SetRequestTimeout(secs)); + } + } fn new_session(&mut self) { // A running turn is cancelled; the worker resets the history once it has ended. self.cancel.store(true, Ordering::Relaxed); @@ -191,6 +200,7 @@ impl Worker { match cmd { Cmd::Prompt(parts) => self.turn(parts), Cmd::SetModel(m) => self.cfg.model = m, + Cmd::SetRequestTimeout(secs) => self.cfg.request_timeout_s = secs, Cmd::NewChat => { self.history.clear(); self.cancel.store(false, Ordering::Relaxed); @@ -431,21 +441,26 @@ impl Worker { Protocol::Anthropic => headers.push(("x-api-key".into(), k.clone())), } } - let req = HttpRequest { method: "POST", url, headers, body: Some(body.to_string().into_bytes()), timeout_s: REQUEST_TIMEOUT_S }; + let req = HttpRequest { method: "POST", url, headers, body: Some(body.to_string().into_bytes()), timeout_s: self.limit_s() }; // The request runs on a thread of its own so that Stop does not wait for the model: a // cancelled one is abandoned (the host's own timeout ends it) and its answer dropped. let (tx, rx) = channel(); let http = self.cfg.http.clone(); + let started = std::time::Instant::now(); std::thread::spawn(move || { let _ = tx.send(http(&req)); }); + // The host ends the request at the limit; a few seconds more is the backstop for one + // that does not. + let backstop = Duration::from_secs(self.limit_s().saturating_add(5)); let (status, bytes) = loop { if self.cancel.load(Ordering::Relaxed) { return Err("cancelled by the user".into()); } match rx.recv_timeout(CANCEL_POLL) { - Ok(r) => break r?, - Err(std::sync::mpsc::RecvTimeoutError::Timeout) => {} + Ok(r) => break r.map_err(|e| request_error(e, started.elapsed(), self.limit_s()))?, + Err(std::sync::mpsc::RecvTimeoutError::Timeout) if started.elapsed() < backstop => {} + Err(std::sync::mpsc::RecvTimeoutError::Timeout) => return Err(timed_out(self.limit_s())), Err(_) => return Err("the request ended without an answer".into()), } }; @@ -453,6 +468,24 @@ impl Worker { } } +impl Worker { + /// The endpoint's request timeout, in range. + fn limit_s(&self) -> u64 { + self.cfg.request_timeout_s.clamp(super::agents::MIN_REQUEST_TIMEOUT_S, super::agents::MAX_REQUEST_TIMEOUT_S) + } +} + +/// What the chat says when a request ran out of time: the limit, and where to raise it. +pub fn timed_out(limit_s: u64) -> String { + crate::i18n::format("ui.ai_request_timed_out", &[("seconds", &limit_s.to_string())]) +} + +/// A failed request as people read it: one that ran into the endpoint's request timeout (the +/// host says so, or it failed at the limit) says the limit and where to raise it. +pub fn request_error(error: String, elapsed: Duration, limit_s: u64) -> String { + if error.starts_with("timeout: global") || elapsed >= Duration::from_secs(limit_s) { timed_out(limit_s) } else { error } +} + /// An endpoint's refusal as people read it. pub fn http_error(status: u16, body: &Value) -> String { let detail = @@ -898,6 +931,7 @@ mod tests { model: "m".into(), key: None, http, + request_timeout_s: 300, }; let ctx = StartContext { cwd: std::env::temp_dir(), bridge: None, tools: None, wake: Box::new(|| {}) }; let mut b = ApiBackend::start(cfg, ctx).unwrap(); @@ -951,6 +985,7 @@ mod tests { model: "m".into(), key: None, http, + request_timeout_s: 300, }; let ctx = StartContext { cwd: std::env::temp_dir(), bridge: None, tools: None, wake: Box::new(|| {}) }; let mut b = ApiBackend::start(cfg, ctx).unwrap(); @@ -1005,6 +1040,7 @@ mod tests { model: "m".into(), key: None, http, + request_timeout_s: 300, }; let ctx = StartContext { cwd: std::env::temp_dir(), bridge: None, tools: None, wake: Box::new(|| {}) }; let mut b = ApiBackend::start(cfg, ctx).unwrap(); @@ -1050,6 +1086,7 @@ mod tests { model: "local".into(), key: None, http, + request_timeout_s: 300, }; let ctx = StartContext { cwd: std::env::temp_dir(), bridge: None, tools: None, wake: Box::new(|| {}) }; let mut b = ApiBackend::start(cfg, ctx).unwrap(); @@ -1106,6 +1143,7 @@ mod tests { model: "m".into(), key: None, http, + request_timeout_s: 300, }; let ctx = StartContext { cwd: std::env::temp_dir(), bridge: None, tools: None, wake: Box::new(|| {}) }; let mut b = ApiBackend::start(cfg, ctx).unwrap(); @@ -1139,6 +1177,7 @@ mod tests { model: "m".into(), key: Some("k".into()), http, + request_timeout_s: 300, }; let ctx = StartContext { cwd: std::env::temp_dir(), bridge: None, tools: None, wake: Box::new(|| {}) }; assert!(ApiBackend::start(cfg, ctx).is_err()); @@ -1162,6 +1201,7 @@ mod tests { model: "m".into(), key: Some("sk-secret".into()), http, + request_timeout_s: 300, }; let (events, _rx) = channel(); let w = Worker { @@ -1288,6 +1328,7 @@ mod tests { model: "m".into(), key: Some("sk-secret".into()), http, + request_timeout_s: 300, }; let ctx = StartContext { cwd: std::env::temp_dir(), bridge: None, tools: None, wake: Box::new(|| {}) }; let mut b = ApiBackend::start(cfg, ctx).unwrap(); diff --git a/crates/ui-egui/src/agent_chat/backend.rs b/crates/ui-egui/src/agent_chat/backend.rs index a470ccad9..b4d1375b1 100644 --- a/crates/ui-egui/src/agent_chat/backend.rs +++ b/crates/ui-egui/src/agent_chat/backend.rs @@ -92,6 +92,8 @@ pub trait ChatBackend { fn set_model(&mut self, _model: &str) {} /// Switch to one of the modes it reported in [`Event::Modes`]. fn set_mode(&mut self, _mode: &str) {} + /// An endpoint's new request timeout, in seconds, from the next request on. + fn set_request_timeout(&mut self, _secs: u64) {} /// Its process, for status and tests. fn pid(&self) -> Option { None diff --git a/crates/ui-egui/src/agent_chat/mod.rs b/crates/ui-egui/src/agent_chat/mod.rs index e10143513..0e36206c2 100644 --- a/crates/ui-egui/src/agent_chat/mod.rs +++ b/crates/ui-egui/src/agent_chat/mod.rs @@ -803,6 +803,7 @@ pub fn connect(app: &mut SolveApp, ctx: &egui::Context) { model: entry.model.clone(), key, http, + request_timeout_s: entry.request_timeout_s, }, start, ) @@ -1621,9 +1622,16 @@ pub fn control(app: &mut SolveApp, ctx: &egui::Context, p: &Value) -> Result Value { "features": app.preferences.ai_features, "toolbarButton": app.preferences.ai_toolbar_button, "permissions": app.preferences.ai_permissions.id(), - "agents": agents::entries(app).iter().map(|e| json!({"id": e.id, "name": e.name, "kind": e.kind.id(), "found": e.found, "version": e.version, "login": e.login})).collect::>(), + "agents": agents::entries(app).iter().map(|e| json!({"id": e.id, "name": e.name, "kind": e.kind.id(), "found": e.found, "version": e.version, "login": e.login, "request_timeout_s": e.kind.is_api().then_some(e.request_timeout_s)})).collect::>(), "currentAgent": agents::current(app).map(|e| e.id), "models": c.models.iter().map(|m| json!({"id": m.id, "name": m.name, "description": m.description})).collect::>(), "model": c.model, diff --git a/crates/ui-egui/src/agent_chat/settings.rs b/crates/ui-egui/src/agent_chat/settings.rs index 853228b54..0222734c2 100644 --- a/crates/ui-egui/src/agent_chat/settings.rs +++ b/crates/ui-egui/src/agent_chat/settings.rs @@ -27,6 +27,8 @@ pub struct AddState { pub base_url: String, pub model: String, pub key: String, + /// Seconds one model request may take. + pub request_timeout_s: u64, pub error: Option, test: Option, } @@ -60,6 +62,7 @@ pub fn open_add(app: &mut SolveApp) { app.agent_chat.settings.add = Some(AddState { base_url: preset.map(|p| p.base_url.to_string()).unwrap_or_default(), name: preset.map(|p| p.name.to_string()).unwrap_or_default(), + request_timeout_s: agents::DEFAULT_REQUEST_TIMEOUT_S, ..Default::default() }); } @@ -108,6 +111,14 @@ fn start_test(app: &SolveApp, e: &agents::Entry, key: Option) -> Test { Test::Running(rx) } +/// An endpoint's request timeout field: seconds, 30 s to an hour. +fn timeout_field(ui: &mut egui::Ui, secs: &mut u64, handle: &str) -> bool { + let r = ui_kit::number_field(ui, secs, agents::MIN_REQUEST_TIMEOUT_S..=agents::MAX_REQUEST_TIMEOUT_S, 5.0, " s") + .on_hover_text(tr("ui.ai_request_timeout_hint")); + crate::scenario::publish_target(handle, r.rect); + r.changed() +} + fn test_line(ui: &mut egui::Ui, test: &Option<&Test>) { match test { Some(Test::Running(_)) => { @@ -277,6 +288,7 @@ fn agents_section(app: &mut SolveApp, ui: &mut egui::Ui) { let default = if all.iter().any(|e| &e.id == d) { Some(d.clone()) } else { all.first().map(|e| e.id.clone()) }; let mut remove: Option = None; let mut test: Option = None; + let mut retimed: Option<(String, u64)> = None; let t = crate::theme::Tokens::get(); ui_kit::settings_section(ui, "agents", tr("ui.ai_agents"), |ui| { if app.agent_chat.detecting.is_some() { @@ -329,7 +341,9 @@ fn agents_section(app: &mut SolveApp, ui: &mut egui::Ui) { } }); ui_kit::settings_short_note(ui, &entry.detail()); - ui_kit::settings_form(ui, t.form_label_width + t.space_16, |ui| { + // Wide enough for an endpoint's "Request timeout" too, so both rows line up. + let label_w = (t.form_label_width + t.space_16).max(ui_kit::ContentWidth::label(ui, tr("ui.ai_request_timeout")) + t.space_16); + ui_kit::settings_form(ui, label_w, |ui| { ui_kit::row(ui, tr("ui.ai_permissions"), |ui| { let current = app.preferences.agent_permissions.get(&entry.id).copied(); let shown = current.map_or_else(|| tr("ui.ai_mode_global").to_owned(), |mode| mode.label().to_owned()); @@ -355,6 +369,19 @@ fn agents_section(app: &mut SolveApp, ui: &mut egui::Ui) { } }); }); + if entry.kind == Kind::Api + && let Some(c) = app.preferences.agents.iter_mut().find(|c| c.id == entry.id) + { + ui_kit::settings_form(ui, label_w, |ui| { + ui_kit::row(ui, tr("ui.ai_request_timeout"), |ui| { + let mut secs = entry.request_timeout_s; + if timeout_field(ui, &mut secs, &format!("prefs:ai_timeout:{}", entry.id)) { + c.request_timeout_s = secs; + retimed = Some((entry.id.clone(), secs)); + } + }); + }); + } if app.preferences.agent_permissions.get(&entry.id) == Some(&Mode::All) { ui_kit::text(ui, tr("ai.prefs.override_all_warning"), ui_kit::Text::Report("agent_permissions_warning", true)) .on_hover_text(tr("ui.ai_mode_all_warning")); @@ -379,6 +406,13 @@ fn agents_section(app: &mut SolveApp, ui: &mut egui::Ui) { let started = start_test(app, &e, key); app.agent_chat.settings.tests.insert(e.id.clone(), started); } + // The running conversation uses a new timeout from its next request on. + if let Some((id, secs)) = retimed + && app.agent_chat.running_id == id + && let Some(b) = app.agent_chat.backend.as_mut() + { + b.set_request_timeout(secs); + } if let Some(id) = remove { app.preferences.agents.retain(|a| a.id != id); app.preferences.agent_permissions.remove(&id); @@ -513,6 +547,9 @@ pub fn dialog(app: &mut SolveApp, ctx: &egui::Context) { ui_kit::row(ui, tr("ui.ai_model"), |ui| { ui_kit::text_field(ui, &mut s.model, tr("ui.ai_model_hint")); }); + ui_kit::row(ui, tr("ui.ai_request_timeout"), |ui| { + timeout_field(ui, &mut s.request_timeout_s, "ai_add:request_timeout"); + }); ui_kit::row(ui, tr("ui.ai_key"), |ui| { ui.add_enabled_ui(has_keychain, |ui| { let r = ui_kit::password_field(ui, egui::Id::new("sc_ai_add_key"), &mut s.key, tr("ui.ai_key_hint")); @@ -550,6 +587,7 @@ pub fn dialog(app: &mut SolveApp, ctx: &egui::Context) { base_url: url.clone().unwrap_or_default(), model: s.model.trim().to_string(), key: false, + request_timeout_s: s.request_timeout_s, }; let key = Some(s.key.trim().to_string()).filter(|k| !k.is_empty()); let result = match url { @@ -599,6 +637,7 @@ fn add_agent(app: &mut SolveApp) -> Result<(), String> { c.kind = s.protocol.kind(); c.base_url = agents::normalize_url(&s.base_url)?; c.model = s.model.trim().to_string(); + c.request_timeout_s = s.request_timeout_s.clamp(agents::MIN_REQUEST_TIMEOUT_S, agents::MAX_REQUEST_TIMEOUT_S); if c.model.is_empty() { return Err(tr("ui.ai_need_model").to_string()); } diff --git a/crates/ui-egui/src/agent_chat/tests.rs b/crates/ui-egui/src/agent_chat/tests.rs index 88e799945..3feb5dcc5 100644 --- a/crates/ui-egui/src/agent_chat/tests.rs +++ b/crates/ui-egui/src/agent_chat/tests.rs @@ -2020,3 +2020,34 @@ fn add_agent_opens_its_dialog_from_home() { assert!(h.app.agent_chat.settings.add.is_some(), "Add agent opened its dialog"); assert!(handle_at("ai_add:add").is_some(), "the dialog is drawn over Home"); } + +/// `ui.agent_chat` `add_agent` takes an endpoint's request timeout (rounded and clamped to 30 s +/// ..= 1 h, 300 s when left out) and the state reports it. +#[test] +fn add_agent_takes_a_request_timeout_and_the_state_reports_it() { + let ctx = egui::Context::default(); + let mut app = SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default()); + let timeout = |app: &mut SolveApp, id: &str| { + let state = control(app, &ctx, &json!({})).unwrap(); + state["agents"].as_array().unwrap().iter().find(|a| a["id"] == id).map(|a| a["request_timeout_s"].clone()) + }; + let add = |app: &mut SolveApp, t: Value| { + let mut a = json!({"id": "slow", "name": "Slow", "kind": "api", "base_url": "http://localhost:11434/v1", "model": "m"}); + if !t.is_null() { + a["request_timeout_s"] = t; + } + control(app, &ctx, &json!({"add_agent": a})) + }; + add(&mut app, json!(1200)).unwrap(); + assert_eq!(timeout(&mut app, "slow"), Some(json!(1200))); + assert_eq!(app.preferences.agents.iter().find(|a| a.id == "slow").unwrap().request_timeout_s, 1200); + add(&mut app, json!(99999.7)).unwrap(); + assert_eq!(timeout(&mut app, "slow"), Some(json!(3600))); + add(&mut app, json!(-3)).unwrap(); + assert_eq!(timeout(&mut app, "slow"), Some(json!(30))); + add(&mut app, Value::Null).unwrap(); + assert_eq!(timeout(&mut app, "slow"), Some(json!(300))); + assert!(add(&mut app, json!("long")).is_err()); + control(&mut app, &ctx, &json!({"add_agent": {"id": "acp", "name": "A", "command": "x --acp"}})).unwrap(); + assert_eq!(timeout(&mut app, "acp"), Some(Value::Null), "only endpoints have a request timeout"); +} diff --git a/docs/agent-chat.md b/docs/agent-chat.md index 9f01b9f42..ae68dac4c 100644 --- a/docs/agent-chat.md +++ b/docs/agent-chat.md @@ -208,7 +208,11 @@ Grok Build also supports `XAI_API_KEY` for users who choose API authentication. OpenAI-compatible endpoint for its models; an Anthropic-compatible one gets a short message, because not every such endpoint lists models (Qwen's has no model list). For these agents SolidCraft runs the conversation itself, with the same tools, limits and questions as for a - coding agent, and at most 24 model requests per message. + coding agent, and at most 24 model requests per message. **Request timeout** is how long one model request may + take: 300 s by default, from 30 s to an hour. A slow local model (a large model on modest + hardware, or a long message with many tool results) may need more; raise it here or in the + endpoint's entry under **Agents**, where a change applies from the next request. A request that + runs out of time ends the message with the limit it hit and where to raise it. ## Signing in diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 46f2085e0..987218884 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -252,7 +252,7 @@ labels; `prefs:measure_axis_distances` identifies the checkbox. | `engine.execute` → `browser.expand_all` | `path?`: occurrence ids; `component?`: id; omit both for the whole tree | Open every Browser row under that scope, including folders that start closed (Origin, Named Views, Features). Display only: not saved in the design, not an undo step. | | `engine.execute` → `browser.collapse_all` | same | Close those rows. The design row stays open when the whole tree is collapsed. | | `engine.execute` → `view.history_layout` | `width?`, `dock?`: `bottom`, `left`, `under_browser`, `collapsed?` | Resize/dock the history without opening a dialog or changing the design. Contents respond to measured width; browser-stacked history shares its width and splits height equally. One folded header gives the expanded card the rest; two folded headers stay at the top. | -| `ui.agent_chat` | `features?`, `toolbar_button?`, `permissions?` (`ask`, `edits`, `all`), `add_agent?` ({`name`, `kind`: `acp`, `api` or `anthropic` (`api` is OpenAI-compatible, `anthropic` Anthropic-compatible), `command` or `base_url` + `model`}; no keys), `add_dialog?` (`installed`, `custom`, `api`, `anthropic`, or `false` to close), `default_agent?`, `agent?` (the conversation's agent, by id), `mode?` (the agent's own mode), `model?` (one of its models), `open?`, `side?` (`left`, `right`), `minimized?`, `popped?` (in its own window), `width?`, `picker?`, `refresh?`, `connect?`, `stop?`, `attach?`: a file's path (a picture, a text file or a CAD file, for the next message; CAD files are imported at once), `remove_file?` (index of a file on the next message), `send?`: text (files alone make a message too), `attach_view?`, `attach_selection?`, `pick?` (true: open the context picker), `permission?`: an option id or `"cancel"` (the newest question of the agent's own), `approve?`: true, false or `"always"` (the oldest request held for Allow/Deny), `cancel?` (Stop: the queue stays), `send_now?` (stop the running step, then send the queued messages), `remove_pending?` (index), `new_chat?` (clear the chat, new session), `undo?` (the last message's changes) | the chat's state: `features`, `agents` (found and added), `currentAgent`, `state` (off, starting, ready, busy, auth, exited), `popped`, `window` (its place and size), `agent`, `modes`, `mode`, `models`, `model`, `authMethods`, `toolsPort`, `pid`, `waiting`, `turn`, `pending` (queued messages, with their `files`), `attachments` (the files on the next message, by name), `loading` (pictures still being read for it, by name), `stopped`, `detection` and the conversation (`items`). With `features` off only the settings apply. Desktop only; see [Agent chat](agent-chat.md) | +| `ui.agent_chat` | `features?`, `toolbar_button?`, `permissions?` (`ask`, `edits`, `all`), `add_agent?` ({`name`, `kind`: `acp`, `api` or `anthropic` (`api` is OpenAI-compatible, `anthropic` Anthropic-compatible), `command` or `base_url` + `model` + `request_timeout_s?` (seconds one model request may take, 300 by default, rounded and clamped to 30 to 3600)}; no keys), `add_dialog?` (`installed`, `custom`, `api`, `anthropic`, or `false` to close), `default_agent?`, `agent?` (the conversation's agent, by id), `mode?` (the agent's own mode), `model?` (one of its models), `open?`, `side?` (`left`, `right`), `minimized?`, `popped?` (in its own window), `width?`, `picker?`, `refresh?`, `connect?`, `stop?`, `attach?`: a file's path (a picture, a text file or a CAD file, for the next message; CAD files are imported at once), `remove_file?` (index of a file on the next message), `send?`: text (files alone make a message too), `attach_view?`, `attach_selection?`, `pick?` (true: open the context picker), `permission?`: an option id or `"cancel"` (the newest question of the agent's own), `approve?`: true, false or `"always"` (the oldest request held for Allow/Deny), `cancel?` (Stop: the queue stays), `send_now?` (stop the running step, then send the queued messages), `remove_pending?` (index), `new_chat?` (clear the chat, new session), `undo?` (the last message's changes) | the chat's state: `features`, `agents` (found and added), `currentAgent`, `state` (off, starting, ready, busy, auth, exited), `popped`, `window` (its place and size), `agent`, `modes`, `mode`, `models`, `model`, `authMethods`, `toolsPort`, `pid`, `waiting`, `turn`, `pending` (queued messages, with their `files`), `attachments` (the files on the next message, by name), `loading` (pictures still being read for it, by name), `stopped`, `detection` and the conversation (`items`). With `features` off only the settings apply. Desktop only; see [Agent chat](agent-chat.md) | | `ui.resize` | `width`, `height` | | | `app.quit` | `force?` (quit without asking about unsaved designs) | `quitting` (the window closes), `asking` (a "save changes?" prompt is open) |