Skip to content

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

Settings: edit an added AI agent (#9619) (#9653)

PaddleStroke0067dcab28a5
diff --git a/assets/locales/pending/agent-settings-edit.json b/assets/locales/pending/agent-settings-edit.json
new file mode 100644
index 0000000000..df28be5762
--- /dev/null
+++ b/assets/locales/pending/agent-settings-edit.json
@@ -0,0 +1,82 @@
+{
+ "en": {
+ "ui.ai_edit": "Edit",
+ "ui.ai_edit_agent_title": "Edit agent",
+ "ui.ai_edit_gone": "This agent was removed, so there is nothing to save.",
+ "ui.ai_edit_tip": "Change this agent's name, command or endpoint. A saved key stays hidden.",
+ "ui.ai_key_keep_hint": "leave empty to keep the saved key",
+ "ui.ai_save": "Save"
+ },
+ "ar": {
+ "ui.ai_edit": "تعديل",
+ "ui.ai_edit_agent_title": "تعديل الوكيل",
+ "ui.ai_edit_gone": "أُزيل هذا الوكيل، لذا لا يوجد ما يُحفظ.",
+ "ui.ai_edit_tip": "غيّر اسم هذا الوكيل أو أمره أو نقطة الاتصال الخاصة به. يبقى المفتاح المحفوظ مخفيًا.",
+ "ui.ai_key_keep_hint": "اتركه فارغًا للإبقاء على المفتاح المحفوظ",
+ "ui.ai_save": "حفظ"
+ },
+ "de": {
+ "ui.ai_edit": "Bearbeiten",
+ "ui.ai_edit_agent_title": "Agent bearbeiten",
+ "ui.ai_edit_gone": "Dieser Agent wurde entfernt, es gibt also nichts zu speichern.",
+ "ui.ai_edit_tip": "Name, Befehl oder Endpunkt dieses Agenten ändern. Ein gespeicherter Schlüssel bleibt verborgen.",
+ "ui.ai_key_keep_hint": "leer lassen, um den gespeicherten Schlüssel zu behalten",
+ "ui.ai_save": "Speichern"
+ },
+ "es": {
+ "ui.ai_edit": "Editar",
+ "ui.ai_edit_agent_title": "Editar agente",
+ "ui.ai_edit_gone": "Este agente se eliminó, así que no hay nada que guardar.",
+ "ui.ai_edit_tip": "Cambia el nombre, el comando o el endpoint de este agente. La clave guardada sigue oculta.",
+ "ui.ai_key_keep_hint": "déjalo vacío para conservar la clave guardada",
+ "ui.ai_save": "Guardar"
+ },
+ "fr": {
+ "ui.ai_edit": "Modifier",
+ "ui.ai_edit_agent_title": "Modifier l'agent",
+ "ui.ai_edit_gone": "Cet agent a été retiré : il n'y a rien à enregistrer.",
+ "ui.ai_edit_tip": "Modifier le nom, la commande ou le point d'accès de cet agent. La clé enregistrée reste masquée.",
+ "ui.ai_key_keep_hint": "laisser vide pour garder la clé enregistrée",
+ "ui.ai_save": "Enregistrer"
+ },
+ "he": {
+ "ui.ai_edit": "עריכה",
+ "ui.ai_edit_agent_title": "עריכת סוכן",
+ "ui.ai_edit_gone": "הסוכן הזה הוסר, ולכן אין מה לשמור.",
+ "ui.ai_edit_tip": "שינוי השם, הפקודה או נקודת הקצה של סוכן זה. מפתח שמור נשאר מוסתר.",
+ "ui.ai_key_keep_hint": "יש להשאיר ריק כדי לשמור על המפתח השמור",
+ "ui.ai_save": "שמירה"
+ },
+ "ja": {
+ "ui.ai_edit": "編集",
+ "ui.ai_edit_agent_title": "エージェントを編集",
+ "ui.ai_edit_gone": "このエージェントは削除されたため、保存するものはありません。",
+ "ui.ai_edit_tip": "このエージェントの名前、コマンド、エンドポイントを変更します。保存済みのキーは表示されません。",
+ "ui.ai_key_keep_hint": "空のままにすると保存済みのキーを使い続けます",
+ "ui.ai_save": "保存"
+ },
+ "ko": {
+ "ui.ai_edit": "편집",
+ "ui.ai_edit_agent_title": "에이전트 편집",
+ "ui.ai_edit_gone": "이 에이전트는 제거되었으므로 저장할 내용이 없습니다.",
+ "ui.ai_edit_tip": "이 에이전트의 이름, 명령 또는 엔드포인트를 변경합니다. 저장된 키는 표시되지 않습니다.",
+ "ui.ai_key_keep_hint": "저장된 키를 유지하려면 비워 두세요",
+ "ui.ai_save": "저장"
+ },
+ "vi": {
+ "ui.ai_edit": "Sửa",
+ "ui.ai_edit_agent_title": "Sửa AI Agent",
+ "ui.ai_edit_gone": "AI Agent này đã bị xóa nên không có gì để lưu.",
+ "ui.ai_edit_tip": "Đổi tên, lệnh hoặc endpoint của AI Agent này. Khóa đã lưu vẫn được ẩn.",
+ "ui.ai_key_keep_hint": "để trống để giữ khóa đã lưu",
+ "ui.ai_save": "Lưu"
+ },
+ "zh": {
+ "ui.ai_edit": "编辑",
+ "ui.ai_edit_agent_title": "编辑智能体",
+ "ui.ai_edit_gone": "此智能体已被移除,没有可保存的内容。",
+ "ui.ai_edit_tip": "更改此智能体的名称、命令或端点。已保存的密钥保持隐藏。",
+ "ui.ai_key_keep_hint": "留空以保留已保存的密钥",
+ "ui.ai_save": "保存"
+ }
+}
diff --git a/crates/ui-egui/src/agent_chat/mod.rs b/crates/ui-egui/src/agent_chat/mod.rs
index 0cfa52e5f8..cfd1074802 100644
--- a/crates/ui-egui/src/agent_chat/mod.rs
+++ b/crates/ui-egui/src/agent_chat/mod.rs
@@ -2104,6 +2104,13 @@ pub fn control(app: &mut SolveApp, ctx: &egui::Context, p: &Value) -> Result<Val
None => app.agent_chat.settings.add = None,
}
}
+ // The same dialog on an agent you added (by id), filled with what it holds; its key stays hidden.
+ if let Some(id) = p.get("edit_dialog") {
+ let id = id.as_str().ok_or("edit_dialog must be the id of an agent you added")?;
+ if !settings::open_edit(app, id) {
+ return Err(format!("edit_dialog: no added agent `{id}`"));
+ }
+ }
if let Some(id) = p.get("default_agent").and_then(Value::as_str) {
app.preferences.agent_default = id.to_string();
}
diff --git a/crates/ui-egui/src/agent_chat/settings.rs b/crates/ui-egui/src/agent_chat/settings.rs
index 92d3b3bc77..1dd6b99540 100644
--- a/crates/ui-egui/src/agent_chat/settings.rs
+++ b/crates/ui-egui/src/agent_chat/settings.rs
@@ -31,6 +31,10 @@ pub struct AddState {
/// Seconds one model request may take.
pub request_timeout_s: u64,
pub error: Option<String>,
+ /// Editing this added agent (its id) instead of adding a new one.
+ pub editing: Option<String>,
+ /// Editing an endpoint whose key is in the keychain: an empty key field keeps it.
+ pub saved_key: bool,
test: Option<Test>,
}
@@ -169,6 +173,40 @@ pub fn open_add(app: &mut SolveApp) {
});
}
+/// Open the agent dialog on an agent you added, filled with what it holds. The key is never read
+/// back: its field stays empty, and saving with it empty keeps the stored key. Returns false when
+/// `id` is not an added agent (found agents have nothing of yours to edit).
+pub fn open_edit(app: &mut SolveApp, id: &str) -> bool {
+ let Some(c) = app.preferences.agents.iter().find(|c| c.id == id) else { return false };
+ let mut s = AddState {
+ name: c.name.clone(),
+ request_timeout_s: c.request_timeout_s.clamp(agents::MIN_REQUEST_TIMEOUT_S, agents::MAX_REQUEST_TIMEOUT_S),
+ editing: Some(c.id.clone()),
+ ..Default::default()
+ };
+ if c.kind.is_api() {
+ let protocol = if c.kind == Kind::Anthropic { Protocol::Anthropic } else { Protocol::OpenAi };
+ let presets = agents::presets(protocol);
+ // The Ollama preset stays chosen even if its URL was changed, as `ollama` records.
+ let preset = if protocol == Protocol::OpenAi && c.ollama {
+ Some(0)
+ } else {
+ presets.iter().position(|p| agents::normalize_url(p.base_url).ok().as_deref() == Some(c.base_url.as_str()))
+ };
+ s.kind = AddKind::Api;
+ s.protocol = protocol;
+ s.preset = preset.unwrap_or(presets.len());
+ s.base_url = c.base_url.clone();
+ s.model = c.model.clone();
+ s.saved_key = c.key;
+ } else {
+ s.kind = AddKind::Custom;
+ s.command = c.command.clone();
+ }
+ app.agent_chat.settings.add = Some(s);
+ true
+}
+
/// Take `index` from the protocol's presets, or make the URL empty for a custom endpoint.
pub(super) fn choose_preset(s: &mut AddState, protocol: Protocol, index: usize) {
s.protocol = protocol;
@@ -404,6 +442,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<String> = None;
let mut test: Option<agents::Entry> = None;
+ let mut edit: Option<String> = 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| {
@@ -443,6 +482,13 @@ fn agents_section(app: &mut SolveApp, ui: &mut egui::Ui) {
if test_button.on_hover_text(tr(tip)).clicked() {
test = Some(entry.clone());
}
+ if !entry.found {
+ let edit_button = ui_kit::button(ui, tr("ui.ai_edit"), ui_kit::Button::Small);
+ crate::scenario::publish_handle(&format!("prefs:ai_edit:{}", entry.id), edit_button.rect.center());
+ if edit_button.on_hover_text(tr("ui.ai_edit_tip")).clicked() {
+ edit = Some(entry.id.clone());
+ }
+ }
if !entry.found && ui_kit::button(ui, tr("ui.ai_remove"), ui_kit::Button::Ghost).clicked() {
remove = Some(entry.id.clone());
}
@@ -523,6 +569,9 @@ 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);
}
+ if let Some(id) = edit {
+ open_edit(app, &id);
+ }
// The running conversation uses a new timeout from its next request on.
if let Some((id, secs)) = retimed
&& app.agent_chat.running_id == id
@@ -565,32 +614,37 @@ pub fn dialog(app: &mut SolveApp, ctx: &egui::Context) {
let mut open = true;
let mut add = false;
let mut test = false;
- let (closed, action) = ui_kit::Window::new(egui::Id::new("sc_ai_add"), "settings", tr("ui.ai_add_agent_title"))
+ // Editing keeps the agent's kind: the kind switch is for adding only.
+ let editing = app.agent_chat.settings.add.as_ref().is_some_and(|s| s.editing.is_some());
+ let (title, ok) = if editing { ("ui.ai_edit_agent_title", "ui.ai_save") } else { ("ui.ai_add_agent_title", "ui.ai_add") };
+ let (closed, action) = ui_kit::Window::new(egui::Id::new("sc_ai_add"), "settings", tr(title))
.cards(2.0)
.fields()
- .actions(tr("ui.ai_add"), "Cancel", None)
+ .actions(tr(ok), "Cancel", None)
.show(ctx, true, |ui| {
let Some(s) = app.agent_chat.settings.add.as_mut() else { return };
if let Some(test) = s.test.as_mut() {
let _ = test.poll();
}
let kinds = [(AddKind::Installed, "ui.ai_add_installed"), (AddKind::Custom, "ui.ai_add_custom"), (AddKind::Api, "ui.ai_add_endpoint")];
- ui_kit::row(ui, tr("ui.ai_kind"), |ui| {
- let mut selected = kinds.iter().position(|(k, _)| *k == s.kind).unwrap_or(0);
- let labels = kinds.map(|(_, key)| tr(key));
- if ui_kit::segmented(ui, &mut selected, &labels, ui_kit::Segments { compact: true, ..Default::default() })
- && let Some((kind, _)) = kinds.get(selected)
- {
- s.kind = *kind;
- s.error = None;
- s.test = None;
- }
- for (_, key) in kinds {
- if let Some(at) = crate::scenario::handle_at(&format!("dialog:{}:{}", tr("ui.ai_kind"), tr(key))) {
- crate::scenario::publish_handle(&format!("ai_add:{key}"), at);
+ if !editing {
+ ui_kit::row(ui, tr("ui.ai_kind"), |ui| {
+ let mut selected = kinds.iter().position(|(k, _)| *k == s.kind).unwrap_or(0);
+ let labels = kinds.map(|(_, key)| tr(key));
+ if ui_kit::segmented(ui, &mut selected, &labels, ui_kit::Segments { compact: true, ..Default::default() })
+ && let Some((kind, _)) = kinds.get(selected)
+ {
+ s.kind = *kind;
+ s.error = None;
+ s.test = None;
}
- }
- });
+ for (_, key) in kinds {
+ if let Some(at) = crate::scenario::handle_at(&format!("dialog:{}:{}", tr("ui.ai_kind"), tr(key))) {
+ crate::scenario::publish_handle(&format!("ai_add:{key}"), at);
+ }
+ }
+ });
+ }
match s.kind {
AddKind::Installed => {
ui_kit::row(ui, tr("ui.agent_chat_pick"), |ui| {
@@ -675,7 +729,8 @@ pub fn dialog(app: &mut SolveApp, ctx: &egui::Context) {
});
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"));
+ let hint = tr(if s.saved_key { "ui.ai_key_keep_hint" } else { "ui.ai_key_hint" });
+ let r = ui_kit::password_field(ui, egui::Id::new("sc_ai_add_key"), &mut s.key, hint);
crate::scenario::publish_target("ai_add:key", r.rect);
});
});
@@ -714,7 +769,12 @@ pub fn dialog(app: &mut SolveApp, ctx: &egui::Context) {
problem: None,
install: "",
};
- let key = Some(s.key.trim().to_string()).filter(|k| !k.is_empty());
+ // Editing with the key field left empty tests with the stored key, which is only ever
+ // sent where a saved key may go (HTTPS or this computer).
+ let key = Some(s.key.trim().to_string()).filter(|k| !k.is_empty()).or_else(|| {
+ let id = s.editing.as_deref().filter(|_| s.saved_key && url.as_deref().is_ok_and(agents::key_safe_for))?;
+ app.services.secrets.as_ref().and_then(|store| store.get(id).ok().flatten())
+ });
let result = match url {
Ok(_) => start_test(app, &e, key),
Err(err) => Test::Done(Err(TestError::Other(err))),
@@ -742,9 +802,14 @@ pub fn dialog(app: &mut SolveApp, ctx: &egui::Context) {
}
}
-/// Add what the dialog holds; its key goes to the keychain.
+/// Add what the dialog holds, or save it over the agent being edited; its key goes to the keychain.
fn add_agent(app: &mut SolveApp) -> Result<(), String> {
let Some(s) = app.agent_chat.settings.add.as_ref() else { return Ok(()) };
+ // The agent being edited must still be there (it may have been removed meanwhile).
+ let editing = match &s.editing {
+ Some(id) => Some(app.preferences.agents.iter().position(|c| &c.id == id).ok_or_else(|| tr("ui.ai_edit_gone").to_string())?),
+ None => None,
+ };
let name = s.name.trim().chars().take(80).collect::<String>();
let mut c = AgentConfig { name, ..Default::default() };
let mut key: Option<String> = None;
@@ -768,12 +833,18 @@ fn add_agent(app: &mut SolveApp) -> Result<(), String> {
return Err(tr("ui.ai_need_model").to_string());
}
key = Some(s.key.trim().to_string()).filter(|k| !k.is_empty());
- if key.is_some() && !agents::key_safe_for(&c.base_url) {
+ // Editing with the key field left empty keeps the stored key.
+ let kept = key.is_none() && editing.is_some() && s.saved_key;
+ if (key.is_some() || kept) && !agents::key_safe_for(&c.base_url) {
return Err(tr("ui.ai_key_needs_https").to_string());
}
+ c.key = kept;
c.id = agents::new_id(&app.preferences, c.kind.id());
}
}
+ if let Some(id) = &s.editing {
+ c.id = id.clone();
+ }
if c.name.is_empty() {
c.name = c.id.clone();
}
@@ -782,12 +853,41 @@ fn add_agent(app: &mut SolveApp) -> Result<(), String> {
store.set(&c.id, &k).map_err(|e| trf("ui.ai_keychain_error", &[("error", &e)]))?;
c.key = true;
}
- app.preferences.agents.push(c);
+ let Some(at) = editing else {
+ app.preferences.agents.push(c);
+ return Ok(());
+ };
+ match app.preferences.agents.get_mut(at) {
+ None => return Err(tr("ui.ai_edit_gone").to_string()),
+ Some(old) => {
+ // An endpoint edited into a program (or one whose key was dropped) leaves no key behind.
+ if old.key
+ && !c.key
+ && let Some(store) = &app.services.secrets
+ {
+ let _ = store.delete(&c.id);
+ }
+ *old = c;
+ let id = old.id.clone();
+ let secs = old.request_timeout_s;
+ // A new command, endpoint or key has not been tested or signed in yet.
+ app.agent_chat.settings.tests.remove(&id);
+ app.agent_chat.login_results.remove(&id);
+ // The running conversation takes a new timeout from its next request on; the rest
+ // applies the next time the agent connects.
+ if app.agent_chat.running_id == id
+ && let Some(b) = app.agent_chat.backend.as_mut()
+ {
+ b.set_request_timeout(secs);
+ }
+ }
+ }
Ok(())
}
#[cfg(all(test, not(target_arch = "wasm32")))]
mod card_tests {
+ use super::super::backend::Secrets;
use super::*;
use crate::scenario::{self, Harness};
use serde_json::json;
@@ -887,4 +987,157 @@ mod card_tests {
assert_eq!(saved.base_url, "https://api.anthropic.com/v1");
assert_eq!(saved.model, "claude-opus-5-5");
}
+
+ /// A keychain in memory, for tests.
+ #[derive(Default)]
+ struct MemoryKeys(std::sync::Mutex<std::collections::HashMap<String, String>>);
+
+ impl Secrets for MemoryKeys {
+ fn get(&self, id: &str) -> Result<Option<String>, String> {
+ Ok(self.0.lock().map_err(|e| e.to_string())?.get(id).cloned())
+ }
+ fn set(&self, id: &str, secret: &str) -> Result<(), String> {
+ self.0.lock().map_err(|e| e.to_string())?.insert(id.into(), secret.into());
+ Ok(())
+ }
+ fn delete(&self, id: &str) -> Result<(), String> {
+ self.0.lock().map_err(|e| e.to_string())?.remove(id);
+ Ok(())
+ }
+ }
+
+ /// Edit on an added agent reopens the dialog filled in; Save changes it in place, keeping its
+ /// id, its permission override and its always-allowed tools (#9619).
+ #[test]
+ fn edit_reopens_an_added_agent_and_saves_it_in_place() {
+ let mut h = Harness::new();
+ h.call("ui.resize", json!({"width": 1600.0, "height": 1000.0}));
+ h.app.home.open = false;
+ h.app.preferences.ai_features = true;
+ h.app.agent_chat.detection = Some(Default::default());
+ h.app.preferences.agents.push(AgentConfig {
+ id: "custom-1".into(),
+ name: "Mine".into(),
+ command: "my-agent --acp".into(),
+ ..Default::default()
+ });
+ h.app.preferences.agent_permissions.insert("custom-1".into(), Mode::Edits);
+ h.app.preferences.agent_always_allow.insert("custom-1".into(), vec!["read".into()]);
+ h.call("ui.prefs", json!({"open": "AI"}));
+ h.frames(4);
+ let edit = scenario::handle_at("prefs:ai_edit:custom-1").expect("an added agent has Edit");
+ h.call("ui.click", json!({"x": edit.x, "y": edit.y}));
+ h.frames(4);
+ {
+ let s = h.app.agent_chat.settings.add.as_ref().expect("Edit opened the dialog");
+ assert_eq!(s.editing.as_deref(), Some("custom-1"));
+ assert_eq!(s.kind, AddKind::Custom);
+ assert_eq!((s.name.as_str(), s.command.as_str()), ("Mine", "my-agent --acp"));
+ }
+ assert!(scenario::handle_at("ai_add:ui.ai_add_custom").is_none(), "editing keeps the agent's kind");
+ let s = h.app.agent_chat.settings.add.as_mut().unwrap();
+ s.name = "Mine, verbose".into();
+ s.command = "my-agent --acp --verbose".into();
+ h.frames(3);
+ h.step(&json!({"click":{"handle":"ai_add:add"}})).unwrap();
+ assert!(h.app.agent_chat.settings.add.is_none(), "Save closed the dialog");
+ assert_eq!(h.app.preferences.agents.len(), 1, "saved in place, not added");
+ let saved = &h.app.preferences.agents[0];
+ assert_eq!((saved.id.as_str(), saved.name.as_str(), saved.command.as_str()), ("custom-1", "Mine, verbose", "my-agent --acp --verbose"));
+ assert_eq!(h.app.preferences.agent_permissions.get("custom-1"), Some(&Mode::Edits));
+ assert!(h.app.preferences.agent_always_allow.contains_key("custom-1"));
+ // An empty command is refused as when adding.
+ assert!(open_edit(&mut h.app, "custom-1"));
+ h.app.agent_chat.settings.add.as_mut().unwrap().command = " ".into();
+ assert_eq!(add_agent(&mut h.app), Err(tr("ui.ai_need_command").to_string()));
+ assert_eq!(h.app.preferences.agents[0].command, "my-agent --acp --verbose");
+ }
+
+ /// Editing an endpoint never shows its stored key: an empty key field keeps it, a new one
+ /// replaces it, and a kept key still only goes to HTTPS or this computer (#9619).
+ #[test]
+ fn edit_keeps_or_replaces_a_stored_key_without_showing_it() {
+ let mut h = Harness::new();
+ let keys = std::sync::Arc::new(MemoryKeys::default());
+ h.app.services.secrets = Some(keys.clone());
+ keys.set("api-1", "test-key-1").unwrap();
+ h.app.preferences.agents.push(AgentConfig {
+ id: "api-1".into(),
+ name: "OpenAI".into(),
+ kind: Kind::Api,
+ base_url: "https://api.openai.com/v1".into(),
+ model: "model-a".into(),
+ key: true,
+ request_timeout_s: 600,
+ ..Default::default()
+ });
+ assert!(open_edit(&mut h.app, "api-1"));
+ {
+ let s = h.app.agent_chat.settings.add.as_ref().unwrap();
+ assert!(s.key.is_empty(), "the stored key is never read back into the dialog");
+ assert!(s.saved_key);
+ assert_eq!((s.kind, s.protocol), (AddKind::Api, Protocol::OpenAi));
+ assert_eq!(agents::presets(Protocol::OpenAi).get(s.preset).map(|p| p.name), Some("OpenAI"));
+ assert_eq!((s.base_url.as_str(), s.model.as_str(), s.request_timeout_s), ("https://api.openai.com/v1", "model-a", 600));
+ }
+ h.app.agent_chat.settings.add.as_mut().unwrap().model = "model-b".into();
+ add_agent(&mut h.app).unwrap();
+ let saved = &h.app.preferences.agents[0];
+ assert_eq!((saved.id.as_str(), saved.model.as_str(), saved.key, saved.request_timeout_s), ("api-1", "model-b", true, 600));
+ assert_eq!(keys.get("api-1").unwrap().as_deref(), Some("test-key-1"), "an empty field keeps the key");
+ // A kept key does not go to a plain-HTTP address elsewhere.
+ assert!(open_edit(&mut h.app, "api-1"));
+ h.app.agent_chat.settings.add.as_mut().unwrap().base_url = "http://example.com/v1".into();
+ assert_eq!(add_agent(&mut h.app), Err(tr("ui.ai_key_needs_https").to_string()));
+ assert_eq!(h.app.preferences.agents[0].base_url, "https://api.openai.com/v1");
+ // A new key replaces the stored one.
+ assert!(open_edit(&mut h.app, "api-1"));
+ h.app.agent_chat.settings.add.as_mut().unwrap().key = "test-key-2".into();
+ add_agent(&mut h.app).unwrap();
+ assert_eq!(keys.get("api-1").unwrap().as_deref(), Some("test-key-2"));
+ assert_eq!(h.app.preferences.agents.len(), 1);
+ // Custom URLs and the Ollama preset come back as they were chosen.
+ h.app.preferences.agents.push(AgentConfig {
+ id: "api-2".into(),
+ kind: Kind::Api,
+ base_url: "http://192.168.1.20:11434/v1".into(),
+ model: "m".into(),
+ ollama: true,
+ ..Default::default()
+ });
+ h.app.preferences.agents.push(AgentConfig {
+ id: "anthropic-1".into(),
+ kind: Kind::Anthropic,
+ base_url: "https://example.com/anthropic/v1".into(),
+ model: "m".into(),
+ ..Default::default()
+ });
+ assert!(open_edit(&mut h.app, "api-2"));
+ assert_eq!(h.app.agent_chat.settings.add.as_ref().map(|s| (s.preset, s.saved_key)), Some((0, false)));
+ add_agent(&mut h.app).unwrap();
+ assert!(h.app.preferences.agents.iter().any(|c| c.id == "api-2" && c.ollama && c.base_url == "http://192.168.1.20:11434/v1"));
+ assert!(open_edit(&mut h.app, "anthropic-1"));
+ let s = h.app.agent_chat.settings.add.as_ref().unwrap();
+ assert_eq!((s.protocol, s.preset), (Protocol::Anthropic, agents::ANTHROPIC_PRESETS.len()), "a custom URL");
+ add_agent(&mut h.app).unwrap();
+ assert!(h.app.preferences.agents.iter().any(|c| c.id == "anthropic-1" && c.kind == Kind::Anthropic));
+ assert_eq!(h.app.preferences.agents.len(), 3);
+ }
+
+ /// Only added agents can be edited, and an agent removed while its dialog is open is not
+ /// brought back by Save; the control channel opens the same dialog (#9619).
+ #[test]
+ fn edit_only_for_added_agents_and_not_after_removal() {
+ let mut h = Harness::new();
+ assert!(!open_edit(&mut h.app, "claude"), "a found agent has nothing of yours to edit");
+ assert!(h.app.agent_chat.settings.add.is_none());
+ h.app.preferences.agents.push(AgentConfig { id: "custom-1".into(), command: "a --acp".into(), ..Default::default() });
+ let err = control(&mut h.app, &h.ctx, &json!({"edit_dialog": "nope"})).unwrap_err();
+ assert!(err.contains("nope"), "{err}");
+ control(&mut h.app, &h.ctx, &json!({"edit_dialog": "custom-1"})).unwrap();
+ assert_eq!(h.app.agent_chat.settings.add.as_ref().and_then(|s| s.editing.as_deref()), Some("custom-1"));
+ h.app.preferences.agents.clear();
+ assert_eq!(add_agent(&mut h.app), Err(tr("ui.ai_edit_gone").to_string()));
+ assert!(h.app.preferences.agents.is_empty());
+ }
}
diff --git a/docs/agent-chat.md b/docs/agent-chat.md
index e2e85672b0..310fa757eb 100644
--- a/docs/agent-chat.md
+++ b/docs/agent-chat.md
@@ -158,7 +158,7 @@ messages go as one prompt, in order, when the turn ends normally.
Preferences → AI → **Agents** lists every agent the chat can use, each with its kind (a program or
an endpoint), version or model, whether it looks signed in, **Test**, **Default** (the one a new
-conversation starts with), its own permission setting, and **Remove** for the ones you added.
+conversation starts with), its own permission setting, and **Edit** and **Remove** for the ones you added.
### Found by themselves
@@ -260,6 +260,14 @@ Grok Build also supports `XAI_API_KEY` for users who choose API authentication.
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.
+**Edit** on an agent you added opens the same dialog filled with its name and command, or its
+protocol, endpoint, model and request timeout, and **Save** changes it in place: it keeps its id,
+its permission setting and the tools you always allow for it. A stored key is never shown: leave
+the key field empty to keep it, or type a new one to replace it. A saved key still only goes to
+HTTPS or this computer, so moving an endpoint with a key to a plain `http://` address elsewhere is
+refused. The running conversation takes a new request timeout at once; a new command, endpoint
+or model applies the next time the agent connects.
+
For Ollama, choosing a model checks its reported capabilities in the background. If its
capabilities list lacks `tools`, a warning below the model picker explains that the model can
only chat and suggests choosing one with tool support. Results are cached in memory per base URL and
diff --git a/docs/control-protocol.md b/docs/control-protocol.md
index 0a73170529..1bfd207716 100644
--- a/docs/control-protocol.md
+++ b/docs/control-protocol.md
@@ -405,7 +405,7 @@ no box selection.
| `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 the height at the remembered share (`browser_share`, half until the seam between the two cards is dragged). One folded header gives the expanded card the rest; two folded headers stay at the top. |
-| `ui.agent_chat` | `features?`, `toolbar_button?`, `connect_at_start?` and `open_at_start?` (connect the agent started last, and open the panel, when SolidCraft starts; both off by default, never with `--control`), `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), `provider?` (which provider's models the model picker lists, when they come from several), `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, failed: the agent never got ready, and Connect reads Retry), `connectAtStart`, `openAtStart`, `lastAgent` (the agent started last), `popped`, `window` (its place and size), `agent`, `modes`, `mode`, `models`, `model`, `modelWarning` (the model capability warning text, or `null` when unknown or tool support is reported; checked asynchronously and never blocks sending), `turnWarning` (the latest completed turn's no-tool notice, otherwise `null`; cleared on the next turn or new chat), `providers` (`name` and `count` of each, empty with one provider), `provider` (the one listed), `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?`, `connect_at_start?` and `open_at_start?` (connect the agent started last, and open the panel, when SolidCraft starts; both off by default, never with `--control`), `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), `edit_dialog?` (the id of an agent you added: the same dialog filled with what it holds, as its **Edit** button opens it; the key is never shown), `default_agent?`, `agent?` (the conversation's agent, by id), `mode?` (the agent's own mode), `provider?` (which provider's models the model picker lists, when they come from several), `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, failed: the agent never got ready, and Connect reads Retry), `connectAtStart`, `openAtStart`, `lastAgent` (the agent started last), `popped`, `window` (its place and size), `agent`, `modes`, `mode`, `models`, `model`, `modelWarning` (the model capability warning text, or `null` when unknown or tool support is reported; checked asynchronously and never blocks sending), `turnWarning` (the latest completed turn's no-tool notice, otherwise `null`; cleared on the next turn or new chat), `providers` (`name` and `count` of each, empty with one provider), `provider` (the one listed), `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) |