Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Choose the model an AI uses in Settings → AI (#145)

BFlate4d43abe148b
diff --git a/apps/craft-anything-cli/src/ai_cmd.rs b/apps/craft-anything-cli/src/ai_cmd.rs
index 59c43e65..b5433c2b 100644
--- a/apps/craft-anything-cli/src/ai_cmd.rs
+++ b/apps/craft-anything-cli/src/ai_cmd.rs
@@ -59,6 +59,9 @@ pub enum AiCommand {
/// Set the program an agent app runs, when it's installed where it isn't found (leave the
/// path out to find it by its usual name again).
Program { name: String, path: Option<String> },
+ /// Set the model an AI uses (Claude Code: the model it's asked for); leave it out to list the
+ /// ones it can use.
+ Model { name: String, model: Option<String> },
/// Send a tiny request and report latency.
Test { name: String },
/// Choose the backend that builds (leave the name out to go back to automatic).
@@ -252,6 +255,20 @@ pub fn ai(cli: &Cli, c: &AiCommand, f: Format) -> u8 {
Err(e) => fail(&e, f),
}
}
+ AiCommand::Model { name, model: None } => match hub.model_choices(name) {
+ Ok(models) => {
+ emit(&json!({"name": name, "models": models}), f);
+ 0
+ }
+ Err(e) => fail(&e, f),
+ },
+ AiCommand::Model { name, model: Some(model) } => match hub.set_model(name, model) {
+ Ok(found) => {
+ emit(&json!({"name": name, "model": model.trim(), "found": found}), f);
+ if found { 0 } else { 1 }
+ }
+ Err(e) => fail(&e, f),
+ },
AiCommand::Program { name, path } => match hub.set_command(name, path.as_deref()) {
Ok(found) => {
emit(&json!({"name": name, "program": path, "found": found}), f);
diff --git a/crates/ai/src/lib.rs b/crates/ai/src/lib.rs
index 7a99604c..d496a86e 100644
--- a/crates/ai/src/lib.rs
+++ b/crates/ai/src/lib.rs
@@ -98,6 +98,18 @@ fn yes() -> bool {
true
}
+/// The model an AI uses, when it can be chosen (Settings → AI, #123): an API's own, or the one
+/// Claude Code is asked for. `None` for an agent app that picks its own.
+pub fn model_in_use(config: &BackendConfig, options: Option<&BackendOptions>) -> Option<String> {
+ match config.kind {
+ BackendKind::AgentCli if config.model == "claude-code" => {
+ Some(options.and_then(|o| o.cli_model.clone()).unwrap_or_else(|| anthropic::DEFAULT_MODEL.to_string()))
+ }
+ BackendKind::AgentCli => None,
+ _ => Some(config.model.clone()),
+ }
+}
+
/// The backend that builds when none is named: the Builder role's choice while it's on, else an
/// agent app, else an API backend. The same rule as [`AiConfig::backend_for`] for
/// [`Role::Builder`], for a client that holds only the list (the app decides "can it build?"
@@ -408,9 +420,37 @@ impl AiHub {
Ok(true)
}
- /// The program each agent app set to one runs, by backend name.
- pub fn commands(&self) -> std::collections::BTreeMap<String, String> {
- self.config().backends.into_iter().filter_map(|b| Some((b.config.name, b.options.command?))).collect()
+ /// Each backend's options (an agent app's program and model…), by name.
+ pub fn options(&self) -> std::collections::BTreeMap<String, BackendOptions> {
+ self.config().backends.into_iter().map(|b| (b.config.name, b.options)).collect()
+ }
+
+ /// The model a backend uses: an API's model, or the one Claude Code is asked for. Returns
+ /// false when there was no such backend.
+ pub fn set_model(&self, name: &str, model: &str) -> Result<bool, ToolError> {
+ let model = model.trim();
+ if model.is_empty() {
+ return Err(ToolError::invalid("Name a model."));
+ }
+ let mut cfg = self.config();
+ let Some(b) = cfg.backends.iter_mut().find(|b| b.config.name == name) else { return Ok(false) };
+ match b.config.kind {
+ BackendKind::AgentCli => b.options.cli_model = Some(model.to_string()),
+ _ => b.config.model = model.to_string(),
+ }
+ self.save_config(&cfg)?;
+ Ok(true)
+ }
+
+ /// The models a backend can be set to (#123): the API's own list, or Claude's models for Claude
+ /// Code. Empty for an agent app that picks its own. Blocking (bounded); run it off the UI thread.
+ pub fn model_choices(&self, name: &str) -> Result<Vec<String>, ToolError> {
+ let e = self.entry(name)?;
+ match (e.config.kind, model_in_use(&e.config, Some(&e.options))) {
+ (_, None) => Ok(Vec::new()),
+ (BackendKind::AgentCli, Some(_)) => Ok(anthropic::MODELS.iter().map(|m| m.to_string()).collect()),
+ _ => self.list_models(name),
+ }
}
/// Remove a backend and its stored key. Returns false when there was no such backend.
diff --git a/crates/ai/src/tests.rs b/crates/ai/src/tests.rs
index 23950c89..c586e915 100644
--- a/crates/ai/src/tests.rs
+++ b/crates/ai/src/tests.rs
@@ -164,12 +164,34 @@ fn the_person_chooses_who_builds() {
fn an_agent_apps_program_is_set_and_cleared() {
let (h, _d) = hub();
add(&h, "OpenCode", BackendKind::AgentCli, "http://127.0.0.1:9", None);
- assert!(h.commands().is_empty());
+ let program = |h: &AiHub| h.options().get("OpenCode").and_then(|o| o.command.clone());
+ assert_eq!(program(&h), None);
assert!(h.set_command("OpenCode", Some(" /opt/oc/bin/opencode ")).unwrap());
- assert_eq!(h.commands().get("OpenCode").map(String::as_str), Some("/opt/oc/bin/opencode"));
+ assert_eq!(program(&h).as_deref(), Some("/opt/oc/bin/opencode"));
assert!(!h.set_command("Nobody", Some("/x")).unwrap(), "only a configured backend");
assert!(h.set_command("OpenCode", Some(" ")).unwrap());
- assert!(h.commands().is_empty(), "blank finds it by its usual name again");
+ assert_eq!(program(&h), None, "blank finds it by its usual name again");
+}
+
+/// #123, #127: the model an AI uses is changed; Claude Code is offered Claude's models.
+#[test]
+fn an_ais_model_is_changed() {
+ let (h, _d) = hub();
+ let url = serve("200 OK", r#"{"object":"list","data":[{"id":"nomic-embed-text"},{"id":"qwen3:8b"}]}"#);
+ h.add_server("Box", &url, Some("nomic-embed-text"), None).unwrap();
+ assert_eq!(h.model_choices("Box").unwrap(), ["nomic-embed-text", "qwen3:8b"], "the server's own list");
+ assert!(h.set_model("Box", " qwen3:8b ").unwrap());
+ assert_eq!(h.backends().into_iter().find(|b| b.name == "Box").unwrap().model, "qwen3:8b");
+ let claude =
+ BackendConfig { name: "Claude Code".into(), kind: BackendKind::AgentCli, model: "claude-code".into(), base_url: None, ssh_host: None, enabled: true };
+ h.add_backend(claude, None).unwrap();
+ assert_eq!(h.model_choices("Claude Code").unwrap(), crate::anthropic::MODELS);
+ assert!(h.set_model("Claude Code", "claude-sonnet-5-5").unwrap());
+ let claude = h.options().get("Claude Code").and_then(|o| o.cli_model.clone());
+ assert_eq!(claude.as_deref(), Some("claude-sonnet-5-5"), "the CLI is asked for it; the agent stays Claude Code");
+ assert_eq!(h.backends().into_iter().find(|b| b.name == "Claude Code").unwrap().model, "claude-code");
+ assert!(!h.set_model("Nobody", "m").unwrap());
+ assert!(h.set_model("Box", " ").is_err());
}
/// #54, #98: a server on another computer is added by its address, with a model that can chat
diff --git a/crates/ui-egui/src/builders.rs b/crates/ui-egui/src/builders.rs
index 0448f29e..def1b404 100644
--- a/crates/ui-egui/src/builders.rs
+++ b/crates/ui-egui/src/builders.rs
@@ -83,6 +83,26 @@ impl CraftApp {
});
}
+ /// Ask an AI which models it can use, for Settings → AI's model picker.
+ pub fn pick_model(&mut self, name: &str) {
+ let (hub, name) = (self.hub.clone(), name.to_string());
+ self.model_picker = Some((name.clone(), None));
+ self.jobs.spawn(tr("List an AI's models"), false, move |_| {
+ let result = hub.model_choices(&name);
+ Ok(crate::Done::ModelChoices { name, result })
+ });
+ }
+
+ /// Use `model` for an AI from now on.
+ pub fn set_model(&mut self, name: &str, model: &str) {
+ self.model_picker = None;
+ let (hub, name, model) = (self.hub.clone(), name.to_string(), model.to_string());
+ self.jobs.spawn(tr("Change an AI's model"), false, move |_| {
+ hub.set_model(&name, &model).map_err(|e| e.message)?;
+ Ok(crate::backends(&hub))
+ });
+ }
+
/// Connect the server in Settings → AI's address form. Its key goes to the keychain; the form
/// keeps what was typed until it's added, so a mistake can be fixed.
pub fn add_server(&mut self) {
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index 3804ef3b..d89be5b9 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -156,6 +156,7 @@ Ask the person 询问用户
Ask: "How does the % key work?" 提问:“% 键是如何工作的?”
Ask: "Is it safe to run?" 试着问:“运行它安全吗?”
Ask: "What does it send over the internet?" 提问:“它会通过互联网发送什么?”
+Asking for its models… 正在获取可用模型…
Asset catalog 资源目录
At most this many rounds of fixes after the first build. 首次构建后,最多进行这么多轮修正。
Attach pictures 附上图片
@@ -200,6 +201,7 @@ Capture inventories 采集清单
Capture menus, dialogs and tabs 采集菜单、对话框和标签页
Change 更改
Change a setting 更改设置
+Change an AI's model 更改 AI 的模型
Change it 更改
Change… 更改…
Check 检查
@@ -587,6 +589,7 @@ List a Unity assets file 列出 Unity assets 文件内容
List a Unity bundle 列出 Unity 资源包内容
List a game's archives 列出游戏归档文件
List a node's event listeners 列出节点的事件监听器
+List an AI's models 列出 AI 的模型
List an Unreal IoStore container 列出 Unreal IoStore 容器内容
List an Unreal pak 列出 Unreal pak 内容
List bookmarks 列出书签
@@ -654,6 +657,7 @@ Memory for Ghidra Ghidra 内存用量
Minimise 最小化
Mode 模式
Model 模型
+Model: {model} 模型:{model}
Modules 模块
More detail 更多详情
More makes a big program's first look faster. 分配更多内存可加快大型程序的首次分析。
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index 81102d48..3e6c06b5 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -156,6 +156,7 @@ Ask the person 詢問使用者
Ask: "How does the % key work?" 提問:「% 鍵是如何運作的?」
Ask: "Is it safe to run?" 試著問:「執行它安全嗎?」
Ask: "What does it send over the internet?" 提問:「它會透過網際網路傳送什麼?」
+Asking for its models… 正在取得可用模型…
Asset catalog 資源目錄
At most this many rounds of fixes after the first build. 首次建置後,最多進行這麼多輪修正。
Attach pictures 附上圖片
@@ -200,6 +201,7 @@ Capture inventories 擷取清單
Capture menus, dialogs and tabs 擷取選單、對話方塊和分頁
Change 變更
Change a setting 變更設定
+Change an AI's model 變更 AI 的模型
Change it 變更
Change… 變更…
Check 檢查
@@ -587,6 +589,7 @@ List a Unity assets file 列出 Unity assets 檔案內容
List a Unity bundle 列出 Unity 資源套件內容
List a game's archives 列出遊戲封存檔
List a node's event listeners 列出節點的事件監聽器
+List an AI's models 列出 AI 的模型
List an Unreal IoStore container 列出 Unreal IoStore 容器內容
List an Unreal pak 列出 Unreal pak 內容
List bookmarks 列出書籤
@@ -654,6 +657,7 @@ Memory for Ghidra Ghidra 記憶體用量
Minimise 最小化
Mode 模式
Model 模型
+Model: {model} 模型:{model}
Modules 模組
More detail 更多詳細資訊
More makes a big program's first look faster. 分配更多記憶體可加快大型程式的首次分析。
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index c852e58f..50d0d172 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -151,9 +151,14 @@ pub enum Done {
result: Result<Value, ToolError>,
},
Detected(Vec<Detected>),
- /// The configured backends, the ones chosen to build with and to extract with, and the
- /// program each agent app set to one runs.
- Backends(Vec<BackendConfig>, Option<String>, Option<String>, std::collections::BTreeMap<String, String>),
+ /// The configured backends, the ones chosen to build with and to extract with, and each one's
+ /// options.
+ Backends(Vec<BackendConfig>, Option<String>, Option<String>, std::collections::BTreeMap<String, craft_anything_ai::BackendOptions>),
+ /// The models an AI can be set to (Settings → AI's model picker).
+ ModelChoices {
+ name: String,
+ result: Result<Vec<String>, ToolError>,
+ },
Picked {
pick: Pick,
path: Option<PathBuf>,
@@ -340,8 +345,11 @@ pub struct CraftApp {
pub jobs: jobs::Jobs<Done>,
pub conversation: Option<Box<dyn Conversation>>,
pub backends: Vec<BackendConfig>,
- /// The program each agent app set to one runs, by backend name (Settings → AI).
- pub agent_programs: std::collections::BTreeMap<String, String>,
+ /// Each backend's options (an agent app's program and model), by name (Settings → AI).
+ pub backend_options: std::collections::BTreeMap<String, craft_anything_ai::BackendOptions>,
+ /// The AI whose model is being chosen in Settings → AI, and the models it offers once they've
+ /// come (`None`: still asking).
+ pub model_picker: Option<(String, Option<Vec<String>>)>,
/// The agent app whose program the file dialog is choosing.
pub picking_program_for: Option<String>,
/// The backend the person chose to build with (Settings → AI), if any.
@@ -437,7 +445,8 @@ impl CraftApp {
jobs: jobs::Jobs::default(),
conversation: None,
backends: Vec::new(),
- agent_programs: Default::default(),
+ backend_options: Default::default(),
+ model_picker: None,
picking_program_for: None,
builder: None,
extractor: None,
@@ -1277,15 +1286,24 @@ impl CraftApp {
self.log(false, format!("Found {} AI option(s) on this computer", d.len()));
self.detected = Some(d);
}
- Done::Backends(b, builder, extractor, programs) => {
+ Done::Backends(b, builder, extractor, options) => {
if self.state.backend.as_ref().is_some_and(|n| !b.iter().any(|c| &c.name == n)) {
self.state.backend = None;
}
self.backends = b;
self.builder = builder;
self.extractor = extractor;
- self.agent_programs = programs;
+ self.backend_options = options;
}
+ Done::ModelChoices { name, result } => match result {
+ // Kept only while the picker is still open for that AI.
+ Ok(models) if self.model_picker.as_ref().is_some_and(|(n, _)| *n == name) => self.model_picker = Some((name, Some(models))),
+ Ok(_) => {}
+ Err(e) => {
+ self.model_picker = None;
+ self.toast(e.for_people(), true);
+ }
+ },
Done::BackendAdded { name, result } => match result {
Ok(()) => {
if self.server_form.name.trim() == name {
@@ -1638,7 +1656,7 @@ pub fn app_icon(size: f32) -> egui::Image<'static> {
/// Run an action; a panic is logged and swallowed so one bad action never takes the app down.
/// The configured backends and the ones chosen to build and to extract (read off the UI thread).
pub(crate) fn backends(hub: &AiHub) -> Done {
- Done::Backends(hub.backends(), hub.chosen(craft_anything_ai::Role::Builder), hub.chosen(craft_anything_ai::Role::Extractor), hub.commands())
+ Done::Backends(hub.backends(), hub.chosen(craft_anything_ai::Role::Builder), hub.chosen(craft_anything_ai::Role::Extractor), hub.options())
}
pub fn guard<R>(what: &str, f: impl FnOnce() -> R) -> Option<R> {
diff --git a/crates/ui-egui/src/settings_ui.rs b/crates/ui-egui/src/settings_ui.rs
index f7f85581..0f5b55c6 100644
--- a/crates/ui-egui/src/settings_ui.rs
+++ b/crates/ui-egui/src/settings_ui.rs
@@ -307,6 +307,7 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
}
let (mut pick, mut builds, mut extracts, mut toggle, mut remove) = (None, None, None, None, None);
let (mut choose_program, mut usual_program) = (None, None);
+ let (mut pick_model, mut chosen_model, mut close_picker) = (None, None, false);
// The AI whose Remove was pressed once: asked again before its key is deleted.
let confirm_id = egui::Id::new("remove-ai");
let confirming: Option<String> = ui.data(|d| d.get_temp(confirm_id));
@@ -319,18 +320,15 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
icons::show(ui, "bot", 18.0, if b.enabled { t.accent } else { t.text_faint });
ui.vertical(|ui| {
ui.add(egui::Label::new(RichText::new(&b.name).font(theme::semibold(theme::SMALL))).truncate());
- ui.add(
- egui::Label::new(
- RichText::new(format!("{:?} · {}{}", b.kind, b.model, b.ssh_host.as_ref().map(|h| format!(" · ssh {h}")).unwrap_or_default()))
- .color(t.text_faint)
- .size(theme::CAPTION),
- )
- .truncate(),
- );
+ let model_in_use = craft_anything_ai::model_in_use(b, app.backend_options.get(&b.name));
+ // An API's model has its own line below; an agent app is named by its `model`.
+ let what = if model_in_use.is_some() && b.kind != BackendKind::AgentCli { String::new() } else { format!(" · {}", b.model) };
+ let ssh = b.ssh_host.as_ref().map(|h| format!(" · ssh {h}")).unwrap_or_default();
+ ui.add(egui::Label::new(RichText::new(format!("{:?}{what}{ssh}", b.kind)).color(t.text_faint).size(theme::CAPTION)).truncate());
// An agent app on this computer: which program runs it, for one installed
// where it isn't looked for (#53).
if b.kind == BackendKind::AgentCli && b.ssh_host.as_deref().is_none_or(|h| h.trim().is_empty()) {
- let program = app.agent_programs.get(&b.name);
+ let program = app.backend_options.get(&b.name).and_then(|o| o.command.as_ref());
ui.horizontal_wrapped(|ui| {
// The links at the caption's size, so the line reads as one.
ui.style_mut().override_font_id = Some(egui::FontId::proportional(theme::CAPTION));
@@ -344,6 +342,39 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
}
});
}
+ // Which model it uses, and the ones it can be set to (#123).
+ if let Some(current) = model_in_use {
+ ui.horizontal_wrapped(|ui| {
+ ui.style_mut().override_font_id = Some(egui::FontId::proportional(theme::CAPTION));
+ ui.add(
+ egui::Label::new(RichText::new(trf("Model: {model}", &[("model", &current)])).color(t.text_faint).size(theme::CAPTION))
+ .truncate(),
+ );
+ match app.model_picker.as_ref().filter(|(n, _)| *n == b.name) {
+ None => {
+ if widgets::link(ui, "Change…").clicked() {
+ pick_model = Some(b.name.clone());
+ }
+ }
+ Some((_, None)) => {
+ ui.add(egui::Spinner::new().size(theme::CAPTION).color(t.accent));
+ ui.label(RichText::new(tr("Asking for its models…")).color(t.text_faint).size(theme::CAPTION));
+ }
+ Some((_, Some(models))) => {
+ egui::ComboBox::from_id_salt(("model", &b.name)).icon(widgets::combo_icon).selected_text(&current).show_ui(ui, |ui| {
+ for m in models {
+ if ui.selectable_label(*m == current, m).clicked() && *m != current {
+ chosen_model = Some((b.name.clone(), m.clone()));
+ }
+ }
+ });
+ if widgets::link(ui, "Cancel").clicked() {
+ close_picker = true;
+ }
+ }
+ }
+ });
+ }
});
});
ui.add_space(6.0);
@@ -412,6 +443,15 @@ fn ai(app: &mut CraftApp, ui: &mut Ui) {
if let Some(name) = usual_program {
app.set_agent_program(&name, None);
}
+ if let Some(name) = pick_model {
+ app.pick_model(&name);
+ }
+ if let Some((name, model)) = chosen_model {
+ app.set_model(&name, &model);
+ }
+ if close_picker {
+ app.model_picker = None;
+ }
if let Some(name) = remove {
ui.data_mut(|d| d.remove::<String>(confirm_id));
app.remove_backend(&name);
diff --git a/crates/ui-egui/tests/headless_parity.rs b/crates/ui-egui/tests/headless_parity.rs
index 1e5e9b3e..6fc1214a 100644
--- a/crates/ui-egui/tests/headless_parity.rs
+++ b/crates/ui-egui/tests/headless_parity.rs
@@ -107,6 +107,8 @@ const ACTIONS: &[Action] = &[
a("detect_backends", "find AI on this computer", Cli("ai detect")),
a("add_backend", "connect an AI brain", Cli("ai add <name> --kind --model --base-url --ssh-host --key-env --key-stdin")),
a("add_server", "connect an AI server by its address", Cli("ai add <name> --kind --base-url --key-env --key-stdin")),
+ a("pick_model", "list the models an AI can use", Cli("ai model <name>")),
+ a("set_model", "change the model an AI uses", Cli("ai model <name> <model>")),
a("choose_backend", "pick the AI brain", Cli("chat <question> --backend")),
a("set_role", "choose which AI builds or extracts", Cli("ai extractor <name>")),
diff --git a/crates/ui-egui/tests/smoke.rs b/crates/ui-egui/tests/smoke.rs
index a8889f71..3bb153ed 100644
--- a/crates/ui-egui/tests/smoke.rs
+++ b/crates/ui-egui/tests/smoke.rs
@@ -918,11 +918,9 @@ fn command_palette_opens_and_lists_tools() {
assert!(!h.state().state.palette.open);
}
-/// #54, #98: an AI server on another computer is added by its address in Settings → AI, with a
-/// model that can chat, and the form empties once it's added.
-#[test]
-fn an_ai_server_is_added_by_its_address() {
- // A stand-in model server: every request gets the same model list.
+/// A stand-in model server whose every answer lists an embedding model, then `qwen3:8b`. Its
+/// OpenAI-style address.
+fn model_server() -> String {
let listener = std::net::TcpListener::bind(("127.0.0.1", 0)).unwrap();
let url = format!("http://{}/v1", listener.local_addr().unwrap());
std::thread::spawn(move || {
@@ -934,6 +932,39 @@ fn an_ai_server_is_added_by_its_address() {
let _ = write!(s, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}", body.len());
}
});
+ url
+}
+
+/// #123, #127: the model an AI uses is changed in Settings → AI from the ones it lists.
+#[test]
+fn an_ais_model_is_changed_in_settings() {
+ let url = model_server();
+ let mut h = harness(move || {
+ let mut a = demo::app(demo::engine(Mode::Experienced, true));
+ a.hub.add_server("Box", &url, Some("nomic-embed-text"), None).unwrap();
+ a.state.settings_open = true;
+ a.state.settings_tab = craft_anything_ui_egui::state::SettingsTab::Ai;
+ a
+ });
+ h.state_mut().refresh_backends();
+ assert!(wait(&mut h, |a| a.backends.iter().any(|b| b.name == "Box")));
+ h.run_steps(2);
+ h.get_by_label("Model: nomic-embed-text");
+ h.get_by_label("Change…").click();
+ assert!(wait(&mut h, |a| a.model_picker.as_ref().is_some_and(|(_, m)| m.as_deref() == Some(&["nomic-embed-text".to_string(), "qwen3:8b".into()][..]))));
+ h.run_steps(2);
+ h.state_mut().set_model("Box", "qwen3:8b");
+ assert!(wait(&mut h, |a| a.backends.iter().any(|b| b.name == "Box" && b.model == "qwen3:8b")));
+ h.run_steps(2);
+ h.get_by_label("Model: qwen3:8b");
+ assert!(h.state().model_picker.is_none(), "the picker closes once a model is chosen");
+}
+
+/// #54, #98: an AI server on another computer is added by its address in Settings → AI, with a
+/// model that can chat, and the form empties once it's added.
+#[test]
+fn an_ai_server_is_added_by_its_address() {
+ let url = model_server();
let mut h = harness(|| {
let mut a = demo::app(demo::engine(Mode::Experienced, true));
a.state.settings_open = true;
@@ -968,11 +999,12 @@ fn an_agent_apps_program_is_set_in_settings() {
h.run_steps(2);
h.get_by_label("Program: found automatically");
h.state_mut().set_agent_program("OpenCode", Some("/opt/oc/opencode".into()));
- assert!(wait(&mut h, |a| a.agent_programs.get("OpenCode").map(String::as_str) == Some("/opt/oc/opencode")));
+ let program = |a: &CraftApp| a.backend_options.get("OpenCode").and_then(|o| o.command.clone());
+ assert!(wait(&mut h, |a| program(a).as_deref() == Some("/opt/oc/opencode")));
h.run_steps(2);
h.get_by_label("Program: /opt/oc/opencode");
h.get_by_label("Find it automatically").click();
- assert!(wait(&mut h, |a| a.agent_programs.is_empty()));
+ assert!(wait(&mut h, |a| program(a).is_none()));
}
#[test]