From 1bc30542890f58dcb207e4a1708523e89922d83d Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 27 Nov 2026 18:13:11 -0600 Subject: [PATCH 1/3] feat(assistant): describe provider privacy and contribution criteria --- CONTRIBUTING.md | 21 ++++++++++++++++++ README.md | 2 +- crates/assistant/src/provider.rs | 12 ++++++++++ crates/ui-egui/src/assistantpane.rs | 5 +++++ docs/user-guide/assistant.md | 34 +++++++++++++++++++---------- 5 files changed, 61 insertions(+), 13 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fdaede175f..7b4fbd180a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -57,6 +57,27 @@ from the roadmap, or narrows it to what is left; one that lands an item of the [GeoLibre parity checklist](docs/geolibre-parity.md) updates that file. Either change goes in the same pull request. +## Adding an AI provider + +A preset in the Assistant's list reads as RustGIS recommending a service. Requests can carry +layer names, rows the assistant reads and pictures of the user's map. A preset needs: + +1. **A named operator and a published data policy.** Its site names the legal entity, country + and contact address, and explains retention and training for request and reply content, + including services it forwards to. +2. **No training by default, or a plain warning.** Where the API provides a per-request control, + the preset uses it by default. Otherwise its description says when training can happen and + how users can turn it off. Check the account reached through the preset's key link. +3. **Known upstreams.** A gateway names the services it forwards to. Requests must not pass + through anonymous resellers' accounts. +4. **Affiliation disclosed** in the pull request. + +Link the evidence in the pull request, and add the same short description of the operator and +privacy considerations to the preset and the [user guide](docs/user-guide/assistant.md#choosing-a-model). +Keep setup instructions in the guide's Key column. Other services can use the OpenAI-compatible +provider and its **Address**. A preset that stops meeting these criteria may be removed; +removal must tell affected users before requests go to a different provider. + ## AI-assisted contributions Code written with AI tools is welcome, from anyone, whatever their programming experience diff --git a/README.md b/README.md index 858bcb1c68..e49bfbf95c 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ Every screenshot is RustGIS itself, rendered offscreen by `cargo run -p rustgis- | **Imagery** | Ortho and reality mapping, pixel classification (k-means, minimum distance, a trainable neural network), mensuration, hosted imagery tiles | | **Layouts and reports** | Page layouts with map frames, legends, scale bars, grids, bar and column charts and map series; publication sheets and figures in one command, format panes, guides, snapping and element locks; reports with groups, statistics, charts and subreports; vector PDF and SVG, and GeoPDF with [supported map frames](docs/user-guide/layouts.md#layouts) georeferenced; presentations (HTML slideshow, PDF); notebooks (Jupyter in and out) | | **Sharing** | PNG export at up to 600 DPI; PDF; web map pages, OGC API Features collections, MapLibre styles, glTF and STL scenes, vector and raster PMTiles, the map view as a GeoTIFF placed on the ground (desktop), locators; the web app embedded in a page (`?embed`); project, map and mobile map packages; offline areas with sync | -| **AI Assistant** | Ask about your data or tell the map what to do in plain language, attaching pictures and letting it look at the map and layouts, with Anthropic, OpenAI (a key, or your ChatGPT plan by signing in on the desktop or command line), Gemini, OpenRouter, Requesty, TrustedRouter, Opper, Ollama or any OpenAI-compatible model; also `rustgis-cli ask`, and an [MCP server](docs/mcp.md) (`rustgis-cli mcp`) for Claude Code, Cursor, VS Code and other agents; skills; on the desktop, agents such as Claude Code and Codex started from the app, and external AI clients driving the open app; keys optionally remembered in the system keychain on the desktop (in the web app, unencrypted in the browser's storage) | +| **AI Assistant** | Ask about your data or tell the map what to do in plain language, attaching pictures and letting it look at the map and layouts, with Anthropic, OpenAI (a key, or your ChatGPT plan by signing in on the desktop or command line), Gemini, OpenRouter and other gateways, Ollama or any OpenAI-compatible model; also `rustgis-cli ask`, and an [MCP server](docs/mcp.md) (`rustgis-cli mcp`) for Claude Code, Cursor, VS Code and other agents; skills; on the desktop, agents such as Claude Code and Codex started from the app, and external AI clients driving the open app; keys optionally remembered in the system keychain on the desktop (in the web app, unencrypted in the browser's storage) | | **Plugins** | Sandboxed WebAssembly [plugins](docs/plugins.md) add commands, tools and ribbon tabs; install them from [plugins.rustgis.app](https://plugins.rustgis.app) on the desktop, command line and web. Process plugins (desktop and command line) run as programs (with Python environments RustGIS makes), in the background or for the whole session; panels offer trees, dropdowns, date pickers and sliders | | **Python** | The [`rustgis` package](docs/python.md) on PyPI: the engine in-process, `rustgis.Map` in Jupyter and `rustgis.qt.MapWidget` in Qt applications | | **Interface** | Layers, Browser and Data Sources panes as tabs, command search (Ctrl+K), keyboard shortcuts, dark mode, custom themes (desktop) and an interface scale, a customizable ribbon and Quick Access Toolbar, linked side-by-side maps, a History pane of tool runs and the session log, autosave and crash recovery (desktop), Check for Updates (desktop), 22 languages | diff --git a/crates/assistant/src/provider.rs b/crates/assistant/src/provider.rs index 1946a8a3a6..768f044801 100644 --- a/crates/assistant/src/provider.rs +++ b/crates/assistant/src/provider.rs @@ -27,6 +27,8 @@ pub enum Api { /// A provider the settings offer, with its defaults. pub struct Preset { pub id: &'static str, + /// Who operates the service and the privacy considerations for its default account. + pub description: &'static str, pub label: &'static str, pub api: Api, pub base_url: &'static str, @@ -47,6 +49,7 @@ pub struct Preset { pub const PRESETS: &[Preset] = &[ Preset { id: "anthropic", + description: "Anthropic's own API, from the makers of Claude. API requests aren't used for training; content may be kept for safety checks, with exceptions to the standard 30-day deletion period.", label: "Anthropic", api: Api::Anthropic, base_url: "https://api.anthropic.com", @@ -59,6 +62,7 @@ pub const PRESETS: &[Preset] = &[ }, Preset { id: "openai", + description: "OpenAI's own API, from the makers of GPT. API requests aren't used for training by default; abuse monitoring logs may be kept up to 30 days, with legal and safety exceptions.", label: "OpenAI", api: Api::OpenAi, base_url: "https://api.openai.com/v1", @@ -71,6 +75,7 @@ pub const PRESETS: &[Preset] = &[ }, Preset { id: "chatgpt", + description: "OpenAI's models, billed to your ChatGPT plan. On a personal plan, ChatGPT's \"Improve the model\" setting decides whether requests are used for training; Business, Enterprise and Edu plans aren't trained on by default.", label: "ChatGPT (sign in)", api: Api::Responses, base_url: crate::chatgpt::API, @@ -85,6 +90,7 @@ pub const PRESETS: &[Preset] = &[ }, Preset { id: "gemini", + description: "Google's own API. With a free key, Google may use requests to improve its products and people may read them; a Cloud project with billing turns that off. In the EEA, Switzerland and the UK, paid-service data terms also cover free use.", label: "Google Gemini", api: Api::Gemini, base_url: "https://generativelanguage.googleapis.com/v1beta", @@ -97,6 +103,7 @@ pub const PRESETS: &[Preset] = &[ }, Preset { id: "openrouter", + description: "A US gateway to hundreds of models from many services. OpenRouter doesn't keep request content by default; each service behind it follows its own policy, and some train on requests.", label: "OpenRouter", api: Api::OpenAi, base_url: "https://openrouter.ai/api/v1", @@ -109,6 +116,7 @@ pub const PRESETS: &[Preset] = &[ }, Preset { id: "ollama", + description: "Models you run with Ollama on this computer or a server of your own. Requests go to the server at the chosen address; its models and configuration determine any onward use.", label: "Ollama (local)", api: Api::OpenAi, base_url: "http://localhost:11434/v1", @@ -121,6 +129,7 @@ pub const PRESETS: &[Preset] = &[ }, Preset { id: "custom", + description: "Any service or local server that speaks OpenAI's API. What happens to requests is up to the service at the chosen address.", label: "OpenAI-compatible", api: Api::OpenAi, base_url: "http://localhost:1234/v1", @@ -133,6 +142,7 @@ pub const PRESETS: &[Preset] = &[ }, Preset { id: "requesty", + description: "A UK gateway to hundreds of models, which can move to another service when one fails. It logs requests up to 30 days by default; you can turn that off for each key. Upstream policies also apply; on the free plan, some models permit training.", label: "Requesty", api: Api::OpenAi, base_url: "https://router.requesty.ai/v1", @@ -145,6 +155,7 @@ pub const PRESETS: &[Preset] = &[ }, Preset { id: "trustedrouter", + description: "A US gateway to models from many services, run on servers whose software can be checked independently. The gateway doesn't keep request content; each service behind it follows its own policy and may keep or train on requests.", label: "TrustedRouter", api: Api::OpenAi, base_url: "https://api.trustedrouter.com/v1", @@ -157,6 +168,7 @@ pub const PRESETS: &[Preset] = &[ }, Preset { id: "opper", + description: "A Swedish gateway to hundreds of models, built for keeping data in the EU. It doesn't store request content by default, but a model name without a route prefix may run outside the EU.", label: "Opper", api: Api::OpenAi, base_url: "https://api.opper.ai/v3/compat", diff --git a/crates/ui-egui/src/assistantpane.rs b/crates/ui-egui/src/assistantpane.rs index 52070d9f4c..8fc8c37698 100644 --- a/crates/ui-egui/src/assistantpane.rs +++ b/crates/ui-egui/src/assistantpane.rs @@ -155,6 +155,11 @@ fn provider_settings(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, cfg: &mut Co .response .labelled_by(provider_label.id); ui.end_row(); + if let Some(p) = provider::preset(&cfg.provider) { + ui.label(""); + ui.add(egui::Label::new(RichText::new(tl!(p.description)).small().color(t.text_dim)).wrap()); + ui.end_row(); + } if cfg.login() { ui.label(tl!("Account")); ui.vertical(|ui| account_row(app, ui, t, cfg)); diff --git a/docs/user-guide/assistant.md b/docs/user-guide/assistant.md index eb1f418920..6764e7f57f 100644 --- a/docs/user-guide/assistant.md +++ b/docs/user-guide/assistant.md @@ -90,18 +90,28 @@ georeferencing with control points rather than asking the model where things are Click the model name or the gear to open the settings. The assistant works with: -| Provider | Default model | Key | -| --- | --- | --- | -| Anthropic | `claude-opus-5-5` | [console.anthropic.com](https://console.anthropic.com/settings/keys), or `ANTHROPIC_API_KEY` | -| OpenAI | `gpt-5.5` | [platform.openai.com](https://platform.openai.com/api-keys), or `OPENAI_API_KEY` | -| ChatGPT (sign in) | the first model in your account’s current catalog | none: **Continue with ChatGPT** to use your ChatGPT plan (desktop app and command line) | -| Google Gemini | `gemini-3.8-flash` | [aistudio.google.com](https://aistudio.google.com/apikey), or `GEMINI_API_KEY` / `GOOGLE_API_KEY` | -| OpenRouter | `openrouter/auto` | [openrouter.ai](https://openrouter.ai/keys), or `OPENROUTER_API_KEY` | -| Ollama (local) | `qwen3` | none; the server from `OLLAMA_BASE_URL` (default `http://localhost:11434`) | -| OpenAI-compatible | — | LM Studio, vLLM, llama.cpp…: `OPENAI_COMPATIBLE_BASE_URL` (default `http://localhost:1234/v1`), with an optional `OPENAI_COMPATIBLE_API_KEY` | -| Requesty | `anthropic/claude-sonnet-5-5` | [app.requesty.ai](https://app.requesty.ai/api-keys), or `REQUESTY_API_KEY`; for the EU, set the **Address** to `https://router.eu.requesty.ai/v1` | -| TrustedRouter | `trustedrouter/auto` | [trustedrouter.com](https://trustedrouter.com), or `TRUSTEDROUTER_API_KEY` | -| Opper | `claude-sonnet-5-5` | [platform.opper.ai](https://platform.opper.ai), or `OPPER_API_KEY` | +| Provider | Description | Default model | Key | +| --- | --- | --- | --- | +| Anthropic | Anthropic's own API, from the makers of Claude. API requests aren't used for training; content may be kept for safety checks, with exceptions to the standard 30-day deletion period. | `claude-opus-5-5` | [console.anthropic.com](https://console.anthropic.com/settings/keys), or `ANTHROPIC_API_KEY` | +| OpenAI | OpenAI's own API, from the makers of GPT. API requests aren't used for training by default; abuse monitoring logs may be kept up to 30 days, with legal and safety exceptions. | `gpt-5.5` | [platform.openai.com](https://platform.openai.com/api-keys), or `OPENAI_API_KEY` | +| ChatGPT (sign in) | OpenAI's models, billed to your ChatGPT plan. On a personal plan, ChatGPT's "Improve the model" setting decides whether requests are used for training; Business, Enterprise and Edu plans aren't trained on by default. | the first model in your account’s current catalog | none: **Continue with ChatGPT** to use your ChatGPT plan (desktop app and command line) | +| Google Gemini | Google's own API. With a free key, Google may use requests to improve its products and people may read them; a Cloud project with billing turns that off. In the EEA, Switzerland and the UK, paid-service data terms also cover free use. | `gemini-3.8-flash` | [aistudio.google.com](https://aistudio.google.com/apikey), or `GEMINI_API_KEY` / `GOOGLE_API_KEY` | +| OpenRouter | A US gateway to hundreds of models from many services. OpenRouter doesn't keep request content by default; each service behind it follows its own policy, and some train on requests. | `openrouter/auto` | [openrouter.ai](https://openrouter.ai/keys), or `OPENROUTER_API_KEY` | +| Ollama (local) | Models you run with Ollama on this computer or a server of your own. Requests go to the server at the chosen address; its models and configuration determine any onward use. | `qwen3` | none; the server from `OLLAMA_BASE_URL` (default `http://localhost:11434`) | +| OpenAI-compatible | Any service or local server that speaks OpenAI's API. What happens to requests is up to the service at the chosen address. | — | LM Studio, vLLM, llama.cpp…: `OPENAI_COMPATIBLE_BASE_URL` (default `http://localhost:1234/v1`), with an optional `OPENAI_COMPATIBLE_API_KEY` | +| Requesty | A UK gateway to hundreds of models, which can move to another service when one fails. It logs requests up to 30 days by default; you can turn that off for each key. Upstream policies also apply; on the free plan, some models permit training. | `anthropic/claude-sonnet-5-5` | [app.requesty.ai](https://app.requesty.ai/api-keys), or `REQUESTY_API_KEY`; for the EU, set the **Address** to `https://router.eu.requesty.ai/v1` | +| TrustedRouter | A US gateway to models from many services, run on servers whose software can be checked independently. The gateway doesn't keep request content; each service behind it follows its own policy and may keep or train on requests. | `trustedrouter/auto` | [trustedrouter.com](https://trustedrouter.com), or `TRUSTEDROUTER_API_KEY` | +| Opper | A Swedish gateway to hundreds of models, built for keeping data in the EU. It doesn't store request content by default, but a model name without a route prefix may run outside the EU. | `claude-sonnet-5-5` | [platform.opper.ai](https://platform.opper.ai), or `OPPER_API_KEY` | + +These descriptions summarize default policies, checked in November 2026; they aren't guarantees +against retention required by law or safety investigations. Your account settings and upstream +services can change them. Requests billed to a ChatGPT plan are assumed to follow ChatGPT's data controls, +as OpenAI documents for Codex. See the providers' own policies: [Anthropic](https://privacy.claude.com/en/articles/7996866-how-long-do-you-store-my-organization-s-data), +[OpenAI API](https://developers.openai.com/api/docs/guides/your-data), +[ChatGPT/Codex](https://developers.openai.com/codex/security/), +[Gemini](https://ai.google.dev/gemini-api/terms), [OpenRouter](https://openrouter.ai/privacy), +[Requesty](https://www.requesty.ai/privacy), [TrustedRouter](https://trustedrouter.com/privacy), +and [Opper](https://opper.ai/security-overview). The ↻ button lists the provider's models. The provider and model you last chose in the settings are used at start. Until you choose one, `RUSTGIS_ASSISTANT_PROVIDER` and From bea8b3d7fed324d24127a87d4a8adcc13509a84d Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 27 Nov 2026 18:24:15 -0600 Subject: [PATCH 2/3] feat(assistant): default OpenRouter to private routing --- crates/assistant/src/agent.rs | 11 ++++++++++ crates/assistant/src/provider.rs | 11 ++++++++++ crates/assistant/src/tests.rs | 29 +++++++++++++++++++++++++ crates/ui-egui/src/assistant.rs | 17 ++++++++++----- crates/ui-egui/src/assistantpane.rs | 25 +++++++++++++++++++++ crates/ui-egui/src/assistantpictures.rs | 1 + crates/ui-egui/src/localagents.rs | 1 + docs/user-guide/assistant.md | 16 ++++++++++++++ 8 files changed, 106 insertions(+), 5 deletions(-) diff --git a/crates/assistant/src/agent.rs b/crates/assistant/src/agent.rs index 91bb464feb..3694c6a6da 100644 --- a/crates/assistant/src/agent.rs +++ b/crates/assistant/src/agent.rs @@ -755,6 +755,7 @@ impl Agent { self.guard(|a| a.receive_unguarded(generation, resp, s)) } + /// Discards stale generations, applies provider recovery and records privacy-policy refusals. fn receive_unguarded(&mut self, generation: u64, resp: Result, s: &mut Session) -> Step { if generation != self.generation || !self.waiting() { return Step::Done; @@ -766,6 +767,16 @@ impl Agent { } self.preview = None; let parsed = resp.as_ref().map_err(Clone::clone).and_then(|r| provider::parse_reply(self.config.api(), r)); + if self.config.provider == "openrouter" + && matches!(&parsed, Err(e) if e.status == Some(404) && { + let detail = e.detail.to_ascii_lowercase(); + detail.contains("data policy") || detail.contains("data collection") || detail.contains("privacy") + }) + { + self.transcript.push(Entry::Note(Note::new( + "OpenRouter found no endpoint matching your data policy. Check Private routing in the Assistant settings or your OpenRouter privacy settings.", + ))); + } // A model that doesn't read images refuses them every time (some servers with a 500): // asked again at once without them, not retried as an outage. let images_refused = matches!(&parsed, Err(e) if self.sent_images_to.as_ref().is_some_and(|to| !self.no_images.contains(to)) diff --git a/crates/assistant/src/provider.rs b/crates/assistant/src/provider.rs index 1946a8a3a6..dc7ee3875c 100644 --- a/crates/assistant/src/provider.rs +++ b/crates/assistant/src/provider.rs @@ -192,6 +192,8 @@ pub struct Config { /// Whether the catalog offers reasoning for the selected model (`Some(false)` also turns it off /// for a Chat Completions model that refused it alongside tools: see [`refuses_reasoning_with_tools`]). pub reasoning: Option, + /// OpenRouter routing excludes endpoints that collect request data by default. + pub openrouter_private: bool, /// Requested tool output token estimate (default 10,000); the 24,000-token hard limit still applies. pub tool_output_token_limit: usize, } @@ -224,6 +226,7 @@ impl Config { client_id: String::new(), session: String::new(), reasoning: None, + openrouter_private: env("RUSTGIS_OPENROUTER_DATA_COLLECTION").as_deref() != Some("allow"), tool_output_token_limit: env("RUSTGIS_ASSISTANT_TOOL_OUTPUT_TOKEN_LIMIT") .and_then(|s| s.parse().ok()) .filter(|n| *n > 0) @@ -276,6 +279,9 @@ impl Config { } } +/// OpenRouter-only routing preference; missing values keep the privacy filter enabled. +pub const OPENROUTER_PRIVATE_PREF: &str = "assistant_openrouter_private"; + /// The desktop preference naming the provider it uses (`prefs.json`). pub const PROVIDER_PREF: &str = "assistant_provider"; @@ -678,6 +684,7 @@ impl Note { /// Every [`Note`] template RustGIS writes (the interface's catalogs translate each). pub const NOTE_TEMPLATES: &[&str] = &[ + "OpenRouter found no endpoint matching your data policy. Check Private routing in the Assistant settings or your OpenRouter privacy settings.", "The reply reached its length limit.", "The provider's content filter stopped the reply.", "The reply stopped early ({reason}).", @@ -1103,6 +1110,7 @@ fn header(k: &str, v: &str) -> (String, String) { // --------------------------------------------------------------------------------------------- // OpenAI Chat Completions +/// Builds the OpenAI-shaped request; the OpenRouter privacy filter travels with every turn. fn openai_request(cfg: &Config, system: &str, turns: &[Turn], tools: &[ToolDef]) -> HttpRequest { let mut messages = vec![json!({"role": "system", "content": system})]; for t in turns { @@ -1138,6 +1146,9 @@ fn openai_request(cfg: &Config, system: &str, turns: &[Turn], tools: &[ToolDef]) .map(|t| json!({"type": "function", "function": {"name": t.name, "description": t.description, "parameters": t.schema}})) .collect(); let mut body = json!({"model": cfg.model.trim(), "messages": messages, "stream": true}); + if cfg.provider == "openrouter" && cfg.openrouter_private { + body["provider"] = json!({"data_collection": "deny"}); + } // Some servers refuse an empty tool list. if !tools.is_empty() { body["tools"] = json!(tools); diff --git a/crates/assistant/src/tests.rs b/crates/assistant/src/tests.rs index d5839e6cef..22676c9263 100644 --- a/crates/assistant/src/tests.rs +++ b/crates/assistant/src/tests.rs @@ -36,6 +36,7 @@ fn sample() -> Session { s } +/// Deterministic provider defaults with a synthetic key and private routing enabled. fn cfg(provider: &str) -> Config { let p = preset(provider).unwrap_or(&PRESETS[0]); Config { @@ -47,6 +48,7 @@ fn cfg(provider: &str) -> Config { client_id: String::new(), session: String::new(), reasoning: None, + openrouter_private: true, tool_output_token_limit: crate::tools::DEFAULT_OUTPUT_TOKENS, } } @@ -5428,3 +5430,30 @@ fn a_message_joining_one_left_unanswered_takes_no_more_than_four_pictures() { let said = "A message takes at most 4 pictures: a1.jpg, a2.jpg, a3.jpg, a4.jpg left out."; assert!(a.transcript.iter().any(|e| matches!(e, Entry::Note(n) if n.to_string() == said))); } + +#[test] +fn openrouter_private_routing_filters_only_openrouter_and_can_be_disabled() { + let mut c = cfg("openrouter"); + let body = |c: &Config| -> Value { serde_json::from_str(&chat_request(c, "system", &[], &[]).body.unwrap()).unwrap() }; + assert_eq!(body(&c)["provider"], json!({"data_collection":"deny"})); + c.openrouter_private = false; + assert!(body(&c).get("provider").is_none()); + for p in PRESETS.iter().filter(|p| p.api == Api::OpenAi && p.id != "openrouter") { + assert!(body(&cfg(p.id)).get("provider").is_none(), "{}", p.id); + } +} + +#[test] +fn openrouter_data_policy_refusal_names_the_privacy_checkbox() { + let mut session = sample(); + let mut a = Agent::new(cfg("openrouter"), &session); + assert!(matches!(a.ask("hello", &session), Step::Send(_))); + let response = HttpResponse { + status: 404, + headers: vec![], + body: br#"{"error":{"message":"No endpoints found matching your data policy"}}"#.to_vec(), + }; + let generation = a.generation(); + assert!(matches!(a.receive(generation, Ok(response), &mut session), Step::Done)); + assert!(a.transcript.iter().any(|e| matches!(e, Entry::Note(n) if n.template.contains("Check Private routing")))); +} diff --git a/crates/ui-egui/src/assistant.rs b/crates/ui-egui/src/assistant.rs index 13864c37ff..4b003c8244 100644 --- a/crates/ui-egui/src/assistant.rs +++ b/crates/ui-egui/src/assistant.rs @@ -181,6 +181,9 @@ fn load_config(app: &mut RustGisApp, provider: &str, ctx: &egui::Context) -> Con if let Some(u) = pref(app, &provider::url_pref(provider)).filter(|_| !c.login()) { c.base_url = u; } + if provider == "openrouter" { + c.openrouter_private = pref(app, provider::OPENROUTER_PRIVATE_PREF).as_deref() != Some("off"); + } if !c.login() { let legacy = pref(app, &format!("assistant_key_{provider}")); #[cfg(not(target_arch = "wasm32"))] @@ -416,6 +419,9 @@ pub(crate) fn save_config(app: &mut RustGisApp, c: &Config, ctx: &egui::Context) save_pref(app, provider::PROVIDER_PREF, &c.provider); save_pref(app, &format!("assistant_model_{}", c.provider), c.model.trim()); save_pref(app, &provider::url_pref(&c.provider), c.base_url.trim()); + if c.provider == "openrouter" { + save_pref(app, provider::OPENROUTER_PRIVATE_PREF, provider::remember_key_value(c.openrouter_private)); + } // A key from the environment stays there; a sign-in's tokens live in their own file. let from_env = Config::from_env(&c.provider).key; if c.login() { @@ -552,12 +558,13 @@ pub(crate) fn list_models(app: &mut RustGisApp, cfg: &Config, ctx: &egui::Contex app.assistant.models_slot = Some(dispatch(app, req, cfg.login().then(|| cfg.binding()), None, ctx)); } -/// Replaces provider settings and stops work bound to a different provider or sign-in. +/// Replaces settings, stopping work when its provider, sign-in or OpenRouter privacy policy changes. pub(crate) fn apply_config(app: &mut RustGisApp, cfg: Config) { - let another = app - .assistant - .config() - .is_some_and(|c| c.provider != cfg.provider || (c.login() && (c.binding() != cfg.binding() || c.key != cfg.key))); + let another = app.assistant.config().is_some_and(|c| { + c.provider != cfg.provider + || (c.provider == "openrouter" && c.openrouter_private != cfg.openrouter_private) + || (c.login() && (c.binding() != cfg.binding() || c.key != cfg.key)) + }); if another { stop(app); } diff --git a/crates/ui-egui/src/assistantpane.rs b/crates/ui-egui/src/assistantpane.rs index 52070d9f4c..2bf1a2ad39 100644 --- a/crates/ui-egui/src/assistantpane.rs +++ b/crates/ui-egui/src/assistantpane.rs @@ -234,6 +234,10 @@ fn provider_settings(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens, cfg: &mut Co ui.end_row(); }); let preset = provider::preset(&cfg.provider); + if cfg.provider == "openrouter" { + ui.checkbox(&mut cfg.openrouter_private, tl!("Private routing")) + .on_hover_text(tl!("Ask OpenRouter to exclude endpoints that collect request data. Turning this off permits more endpoints, subject to your OpenRouter account settings.")); + } let mut notes = Vec::new(); if cfg.login() { notes.push(sign_in_storage_note(app.assistant.account.as_ref().filter(|_| !cfg.key.is_empty()))); @@ -1630,6 +1634,7 @@ pub(crate) mod tests { client_id: String::new(), session: String::new(), reasoning: None, + openrouter_private: true, tool_output_token_limit: rustgis_assistant::tools::DEFAULT_OUTPUT_TOKENS, }; let mut agent = Agent::new(config, &app.session); @@ -2112,6 +2117,7 @@ pub(crate) mod tests { client_id: String::new(), session: String::new(), reasoning: None, + openrouter_private: true, tool_output_token_limit: rustgis_assistant::tools::DEFAULT_OUTPUT_TOKENS, }; app.assistant.agent = Some(Agent::new(cfg.clone(), &app.session)); @@ -2133,6 +2139,7 @@ pub(crate) mod tests { client_id: String::new(), session: String::new(), reasoning: None, + openrouter_private: true, tool_output_token_limit: rustgis_assistant::tools::DEFAULT_OUTPUT_TOKENS, }; let mut agent = Agent::new(cfg.clone(), &app.session); @@ -2147,6 +2154,24 @@ pub(crate) mod tests { assert!(app.assistant.inflight.is_none()); } + #[test] + fn openrouter_privacy_change_stops_the_previous_request() { + let mut app = RustGisApp::with_sample(); + let mut cfg = Config::from_env("openrouter"); + cfg.openrouter_private = false; + let mut agent = Agent::new(cfg.clone(), &app.session); + assert!(matches!(agent.ask("hello", &app.session), Step::Send(_))); + let generation = agent.generation(); + app.assistant.agent = Some(agent); + app.assistant.inflight = Some((generation, Slot::default())); + cfg.openrouter_private = true; + apply_config(&mut app, cfg); + let agent = app.assistant.agent.as_ref().unwrap(); + assert!(!agent.busy()); + assert_ne!(agent.generation(), generation); + assert!(app.assistant.inflight.is_none()); + } + /// The right pane's width with `entries` in the conversation and `model` as the model's name. fn pane_width(entries: Vec, model: &str) -> f32 { let h = chat(entries, model); diff --git a/crates/ui-egui/src/assistantpictures.rs b/crates/ui-egui/src/assistantpictures.rs index e9369060f9..d87965ad5b 100644 --- a/crates/ui-egui/src/assistantpictures.rs +++ b/crates/ui-egui/src/assistantpictures.rs @@ -439,6 +439,7 @@ mod tests { client_id: String::new(), session: String::new(), reasoning: None, + openrouter_private: true, tool_output_token_limit: rustgis_assistant::tools::DEFAULT_OUTPUT_TOKENS, }; app.assistant.agent = Some(rustgis_assistant::Agent::new(cfg, &app.session)); diff --git a/crates/ui-egui/src/localagents.rs b/crates/ui-egui/src/localagents.rs index c27c09a02d..54e4508886 100644 --- a/crates/ui-egui/src/localagents.rs +++ b/crates/ui-egui/src/localagents.rs @@ -683,6 +683,7 @@ mod tests { client_id: String::new(), session: String::new(), reasoning: None, + openrouter_private: true, tool_output_token_limit: rustgis_assistant::tools::DEFAULT_OUTPUT_TOKENS, }; let app = h.state_mut(); diff --git a/docs/user-guide/assistant.md b/docs/user-guide/assistant.md index eb1f418920..57bd0fa8a8 100644 --- a/docs/user-guide/assistant.md +++ b/docs/user-guide/assistant.md @@ -112,6 +112,22 @@ 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. +### OpenRouter private routing + +**Private routing** is on by default for OpenRouter. Every chat request, including summaries +and subagent requests, sends `provider: {"data_collection": "deny"}` to exclude endpoints that +collect request data. This uses [OpenRouter's routing policy](https://openrouter.ai/docs/guides/routing/provider-selection); +it isn't a guarantee of upstream compliance or the separate zero data retention option. +If no endpoint satisfies the policy, the refusal points to this checkbox. Turning it off +allows more endpoints under your OpenRouter account settings; some may keep or train on requests. +The model list is unchanged, so a listed model may have no eligible endpoint. + +Changing this setting stops the current run, including a delegated subagent, so subsequent +requests use the new policy. A request already sent may still finish at the provider. +The setting is saved for OpenRouter alone. On the command line, set +`RUSTGIS_OPENROUTER_DATA_COLLECTION=allow` to turn the filter off; other values keep it on. +Other providers' requests are unaffected. + ### Signing in with ChatGPT With a ChatGPT plan you can use the assistant without an API key, through OpenAI's From 0d2fe035380e8c4236e9d1058f2eb525c934132b Mon Sep 17 00:00:00 2001 From: mavrick Date: Fri, 27 Nov 2026 19:14:53 -0600 Subject: [PATCH 3/3] test(assistant): supply a key for privacy cancellation fixture --- crates/ui-egui/src/assistantpane.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/ui-egui/src/assistantpane.rs b/crates/ui-egui/src/assistantpane.rs index 2bf1a2ad39..b45f35ed4f 100644 --- a/crates/ui-egui/src/assistantpane.rs +++ b/crates/ui-egui/src/assistantpane.rs @@ -2158,6 +2158,7 @@ pub(crate) mod tests { fn openrouter_privacy_change_stops_the_previous_request() { let mut app = RustGisApp::with_sample(); let mut cfg = Config::from_env("openrouter"); + cfg.key = "k".into(); cfg.openrouter_private = false; let mut agent = Agent::new(cfg.clone(), &app.session); assert!(matches!(agent.ask("hello", &app.session), Step::Send(_)));