diff --git a/crates/assistant/src/provider.rs b/crates/assistant/src/provider.rs index 0817553e40..3b7df60eaa 100644 --- a/crates/assistant/src/provider.rs +++ b/crates/assistant/src/provider.rs @@ -356,6 +356,18 @@ pub fn first_keyed(config: impl Fn(&str) -> Config) -> Option<&'static str> { PRESETS.iter().find(|p| !p.login && p.id != "ollama-cloud" && !config(p.id).key.is_empty()).map(|p| p.id) } +/// Whether the web app can use the provider: a sign-in needs a server on this computer, and +/// ollama.com refuses requests from web pages (its CORS preflight). +pub fn works_in_browser(p: &Preset) -> bool { + !p.login && p.id != "ollama-cloud" +} + +/// Whether a saved or environment choice of provider can be used: one that exists and, in the web +/// app (`web`), [`works_in_browser`]. A choice that can't falls back to the default. +pub fn usable_choice(id: &str, web: bool) -> bool { + preset(id).is_some_and(|p| !web || works_in_browser(p)) +} + /// The provider a command-line run uses: the explicit choice, then the environment's choice, then /// the first provider with an environment key, then (only when `saved` has the desktop's /// preferences) the one the desktop app uses, else `ollama`. Environment credentials win over the diff --git a/crates/assistant/src/tests.rs b/crates/assistant/src/tests.rs index e3ad187523..20e811e291 100644 --- a/crates/assistant/src/tests.rs +++ b/crates/assistant/src/tests.rs @@ -5626,6 +5626,23 @@ fn ollama_cloud_sends_chat_and_model_requests_to_ollama_com_with_a_bearer_key() assert_eq!(parse_models(Api::OpenAi, &listed.unwrap()), Ok(vec!["gemma4:31b".to_string(), "gpt-oss:120b".to_string()])); } +#[test] +fn the_web_app_offers_only_providers_a_web_page_can_reach() { + // ollama.com refuses the browser's CORS preflight, and a ChatGPT sign-in needs the desktop. + let offered: Vec<&str> = PRESETS.iter().filter(|p| works_in_browser(p)).map(|p| p.id).collect(); + assert!(!offered.contains(&"ollama-cloud") && !offered.contains(&"chatgpt"), "{offered:?}"); + assert!(["anthropic", "openai", "gemini", "openrouter", "ollama", "custom", "mistral"].iter().all(|id| offered.contains(id))); +} + +#[test] +fn a_saved_choice_the_web_app_cannot_use_is_not_restored_there() { + // Saved before the web app stopped listing it: the web app falls back instead. + assert!(!usable_choice("ollama-cloud", true) && !usable_choice("chatgpt", true)); + assert!(usable_choice("ollama-cloud", false) && usable_choice("chatgpt", false)); + assert!(usable_choice("mistral", true) && usable_choice("ollama", true)); + assert!(!usable_choice("retired", false) && !usable_choice("retired", true)); +} + #[test] fn ollama_cloud_runs_a_tool_call_and_answers() { let mut s = sample(); diff --git a/crates/ui-egui/src/assistant.rs b/crates/ui-egui/src/assistant.rs index d312c50772..6112c44590 100644 --- a/crates/ui-egui/src/assistant.rs +++ b/crates/ui-egui/src/assistant.rs @@ -296,7 +296,8 @@ pub(crate) fn ensure_loaded(app: &mut RustGisApp, ctx: &egui::Context) { app.assistant.remember_key = provider::remembers_keys(pref(app, provider::REMEMBER_KEY_PREF).as_deref()); let provider = pref(app, provider::PROVIDER_PREF) .or_else(|| std::env::var("RUSTGIS_ASSISTANT_PROVIDER").ok()) - .filter(|p| provider::preset(p).is_some()) + // One saved before the web app stopped offering it (Ollama Cloud) falls back there. + .filter(|p| provider::usable_choice(p, cfg!(target_arch = "wasm32"))) // The first provider with a key in the environment (a ChatGPT sign-in and Ollama Cloud are // chosen, not assumed). .or_else(|| provider::first_keyed(Config::from_env).map(str::to_string)) diff --git a/crates/ui-egui/src/assistantpane.rs b/crates/ui-egui/src/assistantpane.rs index 020f426f93..2c13221779 100644 --- a/crates/ui-egui/src/assistantpane.rs +++ b/crates/ui-egui/src/assistantpane.rs @@ -143,8 +143,9 @@ fn provider_settings(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, cfg: &mut Co .width(180.0) .show_ui(ui, |ui| { for p in PRESETS { - // Signing in needs the browser and a server on this computer: the desktop app. - if p.login && cfg!(target_arch = "wasm32") { + // Signing in needs the browser and a server on this computer, and ollama.com + // refuses web pages: the desktop app. + if !provider::usable_choice(p.id, cfg!(target_arch = "wasm32")) { continue; } if ui.selectable_label(cfg.provider == p.id, tl!(p.label)).clicked() && cfg.provider != p.id { diff --git a/docs/user-guide/assistant.md b/docs/user-guide/assistant.md index 2293bd4f7a..662d184714 100644 --- a/docs/user-guide/assistant.md +++ b/docs/user-guide/assistant.md @@ -441,8 +441,8 @@ Plain HTTP is only used for servers on your computer or local network. In the web app, the browser calls the provider directly. Anthropic, OpenAI, Gemini, OpenRouter, Requesty, TrustedRouter, Opper and Mistral accept that; a local Ollama server must allow the page's origin (`OLLAMA_ORIGINS=https://web.rustgis.app ollama serve`). Ollama Cloud refuses requests from -web pages, so in the web app use its models through a local Ollama server signed in with -`ollama signin`. +web pages, so the web app doesn't list it: use its models there through a local Ollama server +signed in with `ollama signin`. ## Retries and long conversations