Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

Chat: Google AI, OpenAI and OpenRouter as chat providers

Claudecab5e744f707
diff --git a/windows/src-tauri/src/chat.rs b/windows/src-tauri/src/chat.rs
index 9f1be2b7..f9a918c4 100644
--- a/windows/src-tauri/src/chat.rs
+++ b/windows/src-tauri/src/chat.rs
@@ -1,6 +1,6 @@
// The chat, whoever answers it: the conversation, the system prompt, and which
-// provider a turn goes to. Each provider's own wire format lives in its module
-// (claude.rs for Anthropic).
+// provider a turn goes to. Each provider's own wire format lives in its module:
+// claude.rs (Anthropic) and openai_compat.rs (OpenAI, Google AI, OpenRouter).
//
// API keys never leave the credential store and file bytes never cross the IPC
// boundary: the island sends the question and gets the answer's text back.
@@ -12,7 +12,7 @@ use serde_json::{json, Value};
use tauri::AppHandle;
use crate::settings::Settings;
-use crate::{claude, secrets};
+use crate::{claude, openai_compat, secrets};
pub const ANTHROPIC: &str = "anthropic";
@@ -157,9 +157,18 @@ pub fn plain_question(first: bool, context: Option<&ChatContext>, query: &str) -
// ── Which provider ────────────────────────────────────────────────────────────
/// The model chosen for `provider`, or its default.
-pub fn model_for(settings: &Settings, _provider: &str) -> String {
- let m = settings.model.trim();
- if m.is_empty() { claude::DEFAULT_MODEL.to_string() } else { m.to_string() }
+pub fn model_for(settings: &Settings, provider: &str) -> String {
+ if provider == ANTHROPIC {
+ let m = settings.model.trim();
+ return if m.is_empty() { claude::DEFAULT_MODEL.to_string() } else { m.to_string() };
+ }
+ settings
+ .chat_models
+ .get(provider)
+ .map(|m| m.trim().to_string())
+ .filter(|m| !m.is_empty())
+ .or_else(|| openai_compat::provider(provider).map(|p| p.default_model.to_string()))
+ .unwrap_or_default()
}
/// One chat turn with the provider chosen in the settings.
@@ -170,21 +179,31 @@ pub async fn send(
query: String,
context: Option<ChatContext>,
) -> Result<ChatReply, String> {
+ let provider = settings.chat_provider.as_str();
+ let model = model_for(settings, provider);
+ if provider == ANTHROPIC || provider.is_empty() {
+ return claude::send(chat, &model, query, context).await;
+ }
+ if let Some(p) = openai_compat::provider(provider) {
+ return openai_compat::send(chat, p, &model, query, context).await;
+ }
let _ = app;
- let model = model_for(settings, ANTHROPIC);
- claude::send(chat, &model, query, context).await
+ Err(format!("Unknown chat provider: {provider}"))
}
/// The models `provider` offers. Asked only when the user opens the picker on
-/// that provider, and only once it has a key (or, for a local server, an
-/// address): nothing is sent anywhere before that.
+/// that provider, and only once it has a key: nothing is sent anywhere before that.
pub async fn models(settings: &Settings, provider: &str) -> Result<Vec<ModelInfo>, String> {
const NO_KEY: &str = "No API key — add it in Settings.";
- let _ = settings;
if provider == ANTHROPIC {
let key = secrets::get(claude::KEY).ok_or(NO_KEY)?;
return claude::models(&key).await;
}
+ if let Some(p) = openai_compat::provider(provider) {
+ let key = secrets::get(p.key).ok_or(NO_KEY)?;
+ return openai_compat::models(p, &key).await;
+ }
+ let _ = settings;
Err(format!("Unknown chat provider: {provider}"))
}
@@ -280,10 +299,13 @@ mod tests {
}
#[test]
- fn the_model_comes_from_the_settings_or_the_default() {
+ fn the_model_comes_from_the_settings_or_the_provider_default() {
let mut s = Settings::default();
assert_eq!(model_for(&s, "anthropic"), claude::DEFAULT_MODEL);
+ assert_eq!(model_for(&s, "openai"), openai_compat::provider("openai").unwrap().default_model);
+ s.chat_models.insert("openai".into(), " gpt-x ".into());
s.model = "claude-haiku-4-5".into();
+ assert_eq!(model_for(&s, "openai"), "gpt-x");
assert_eq!(model_for(&s, "anthropic"), "claude-haiku-4-5");
}
}
diff --git a/windows/src-tauri/src/lib.rs b/windows/src-tauri/src/lib.rs
index eec354d0..bb261466 100644
--- a/windows/src-tauri/src/lib.rs
+++ b/windows/src-tauri/src/lib.rs
@@ -9,6 +9,7 @@ mod integrations;
mod island;
mod log;
mod net;
+mod openai_compat;
mod pipe;
mod platform;
mod secrets;
@@ -238,7 +239,8 @@ fn approval_decline(app: AppHandle, request_id: String) {
// ── Chat, files and secrets ───────────────────────────────────────────────────
-/// One chat turn. The API key and any file bytes stay on the Rust side.
+/// One chat turn with the provider picked in the chat view. API keys and any
+/// file bytes stay on the Rust side.
#[tauri::command]
async fn chat_send(
app: AppHandle,
@@ -251,7 +253,8 @@ async fn chat_send(
chat::send(&app, &chat, &settings, query, context).await
}
-/// The models a provider offers. Only asked with the provider's key.
+/// The models a provider offers, for the picker in the chat view. Only asked
+/// once the user picked that provider, and only with its key.
#[tauri::command]
async fn chat_models(shared: State<'_, Shared>, provider: String) -> Result<Vec<ModelInfo>, String> {
let settings = shared.settings.lock().unwrap().clone();
diff --git a/windows/src-tauri/src/openai_compat.rs b/windows/src-tauri/src/openai_compat.rs
new file mode 100644
index 00000000..02a49d96
--- /dev/null
+++ b/windows/src-tauri/src/openai_compat.rs
@@ -0,0 +1,413 @@
+// Cloud providers that speak the OpenAI chat completions API: OpenAI, Google AI
+// (Gemini's OpenAI-compatible endpoint, as ClaudeService.swift uses it) and
+// OpenRouter. One table describes them; one client talks to all three.
+//
+// Same contract as claude.rs: the key never leaves the credential store and
+// file bytes never cross the IPC boundary. Chat only — no tools are sent, so
+// the model can answer but never act on the machine.
+
+use std::time::Duration;
+
+use reqwest::Url;
+use serde_json::{json, Value};
+
+use crate::chat::{self, Chat, ChatContext, ChatReply, ModelInfo};
+use crate::{net, secrets};
+
+pub struct Provider {
+ pub id: &'static str,
+ pub name: &'static str,
+ pub base_url: &'static str,
+ /// Credential store entry of its API key.
+ pub key: &'static str,
+ /// Relative to `base_url`.
+ pub models_path: &'static str,
+ pub default_model: &'static str,
+ /// Model ids containing any of these are not chat models.
+ pub not_chat: &'static [&'static str],
+ /// OpenAI's reasoning models refuse `max_tokens` and want
+ /// `max_completion_tokens`; the compatible APIs take the older name.
+ pub max_tokens_field: &'static str,
+}
+
+pub const PROVIDERS: &[Provider] = &[
+ Provider {
+ id: "openai",
+ name: "OpenAI",
+ base_url: "https://api.openai.com/v1",
+ key: "openai-api-key",
+ models_path: "models",
+ default_model: "gpt-4o",
+ not_chat: &[
+ "embed", "tts", "whisper", "dall-e", "audio", "realtime", "moderat", "codex",
+ "computer-use", "transcribe", "image", "sora", "babbage", "davinci", "instruct",
+ ],
+ max_tokens_field: "max_completion_tokens",
+ },
+ Provider {
+ id: "google",
+ name: "Google AI",
+ base_url: "https://generativelanguage.googleapis.com/v1beta/openai",
+ key: "google-api-key",
+ models_path: "models",
+ default_model: "gemini-2.0-flash",
+ not_chat: &["embed", "imagen", "veo", "aqa", "tts", "audio", "live"],
+ max_tokens_field: "max_tokens",
+ },
+ Provider {
+ id: "openrouter",
+ name: "OpenRouter",
+ base_url: "https://openrouter.ai/api/v1",
+ key: "openrouter-api-key",
+ models_path: "models",
+ default_model: "openrouter/auto",
+ not_chat: &[],
+ max_tokens_field: "max_tokens",
+ },
+];
+
+pub fn provider(id: &str) -> Option<&'static Provider> {
+ PROVIDERS.iter().find(|p| p.id == id)
+}
+
+const MAX_TOKENS: u32 = 4096;
+/// Text and code files are inlined; anything larger is skipped.
+const MAX_INLINE_TEXT: u64 = 200_000;
+/// Images are sent inline as data URLs; past this size they are skipped.
+const MAX_IMAGE: u64 = 5_000_000;
+
+fn url(p: &Provider, tail: &str) -> Result<Url, String> {
+ let base = Url::parse(p.base_url).map_err(|e| e.to_string())?;
+ Url::parse(&net::join(&base, tail)).map_err(|e| e.to_string())
+}
+
+/// The user's message for one turn: plain text, or text and an image part
+/// when the first turn carries a dropped picture.
+fn user_message(first: bool, context: Option<&ChatContext>, query: &str) -> Value {
+ let mut prefix = String::new();
+ let mut image = None;
+ match context.filter(|_| first) {
+ Some(ChatContext::File { name, path }) => match file_part(path) {
+ Some(FilePart::Image(part)) => {
+ image = Some(part);
+ prefix = format!("File: {name}\n\n");
+ }
+ Some(FilePart::Text(body)) => prefix = format!("File: {name}\nFile contents:\n{body}\n\n"),
+ None => prefix = format!("File: {name}\n\n"),
+ },
+ Some(ChatContext::Window { app_name, title, url }) => {
+ prefix = format!("{}\n\n", chat::window_line(app_name, title, url.as_deref()));
+ }
+ None => {}
+ }
+ let text = format!("{prefix}{query}");
+ match image {
+ None => json!({ "role": "user", "content": text }),
+ Some(part) => json!({ "role": "user", "content": [part, { "type": "text", "text": text }] }),
+ }
+}
+
+fn request_body(p: &Provider, model: &str, system: &str, history: &[Value], user: &Value) -> Value {
+ let mut messages = vec![json!({ "role": "system", "content": system })];
+ messages.extend(history.iter().cloned());
+ messages.push(user.clone());
+ let mut body = json!({ "model": model, "messages": messages });
+ body[p.max_tokens_field] = json!(MAX_TOKENS);
+ body
+}
+
+/// The answer's text, or the error the provider put in a 200 reply
+/// (OpenRouter does when the upstream model fails).
+fn reply_text(p: &Provider, response: &Value) -> Result<String, String> {
+ let text = response
+ .pointer("/choices/0/message/content")
+ .and_then(Value::as_str)
+ .unwrap_or("")
+ .trim()
+ .to_string();
+ if !text.is_empty() {
+ return Ok(text);
+ }
+ if let Some(msg) = response.pointer("/error/message").and_then(Value::as_str) {
+ return Err(format!("{}: {msg}", p.name));
+ }
+ Err("No response text.".into())
+}
+
+fn status_error(p: &Provider, status: u16, detail: &str) -> String {
+ match status {
+ 401 | 403 => format!("{} rejected the API key ({status}). Check it in Settings.", p.name),
+ 402 => format!("{}: not enough credits (402). {detail}", p.name),
+ 404 => format!("{}: model not found (404). Pick another one above the chat box. {detail}", p.name),
+ 429 => format!("{} rate limit reached (429): {detail}", p.name),
+ _ => format!("{} {status}: {detail}", p.name),
+ }
+}
+
+/// One chat turn with a cloud provider.
+pub async fn send(
+ chat: &Chat,
+ p: &'static Provider,
+ model: &str,
+ query: String,
+ context: Option<ChatContext>,
+) -> Result<ChatReply, String> {
+ let key = secrets::get(p.key).ok_or_else(|| format!("{} API key missing. Add it in Settings.", p.name))?;
+ if model.is_empty() {
+ return Err(format!("Pick a {} model above the chat box.", p.name));
+ }
+ let turn = chat.begin(p.id);
+ let user = user_message(turn.first, context.as_ref(), &query);
+ let body = request_body(p, model, &chat::system_prompt(false), &turn.history, &user);
+
+ let endpoint = url(p, "chat/completions")?;
+ let response = net::client(&endpoint, Duration::from_secs(90))?
+ .post(endpoint)
+ .bearer_auth(&key)
+ .json(&body)
+ .send()
+ .await
+ .map_err(|e| format!("Network error: {e}"))?;
+ let status = response.status();
+ if !status.is_success() {
+ let body = net::read_capped(response, net::MAX_ERROR_BODY).await.unwrap_or_default();
+ return Err(status_error(p, status.as_u16(), &net::error_detail(&body)));
+ }
+ let bytes = net::read_capped(response, net::MAX_BODY).await?;
+ let json: Value = serde_json::from_slice(&bytes).map_err(|e| format!("Bad API response: {e}"))?;
+ let text = reply_text(p, &json)?;
+
+ let plain = chat::plain_question(turn.first, context.as_ref(), &query);
+ chat.commit(&turn, user, json!({ "role": "assistant", "content": text }), &plain, &text);
+ Ok(ChatReply { text })
+}
+
+/// The provider's chat models. Only ever asked with the user's key, once they
+/// picked this provider in the chat.
+pub async fn models(p: &Provider, key: &str) -> Result<Vec<ModelInfo>, String> {
+ let endpoint = url(p, p.models_path)?;
+ let response = net::client(&endpoint, Duration::from_secs(15))?
+ .get(endpoint)
+ .bearer_auth(key)
+ .send()
+ .await
+ .map_err(|e| format!("Network error: {e}"))?;
+ let status = response.status();
+ if !status.is_success() {
+ let body = net::read_capped(response, net::MAX_ERROR_BODY).await.unwrap_or_default();
+ return Err(status_error(p, status.as_u16(), &net::error_detail(&body)));
+ }
+ let bytes = net::read_capped(response, net::MAX_BODY).await?;
+ let json: Value = serde_json::from_slice(&bytes).map_err(|_| "Unexpected API response.".to_string())?;
+ Ok(parse_models(p, &json))
+}
+
+fn parse_models(p: &Provider, json: &Value) -> Vec<ModelInfo> {
+ let items = json.get("data").and_then(Value::as_array).cloned().unwrap_or_default();
+ let mut models: Vec<(ModelInfo, i64, bool)> = items
+ .iter()
+ .filter(|m| {
+ // OpenRouter lists image and audio generators too.
+ m.pointer("/architecture/output_modalities")
+ .and_then(Value::as_array)
+ .is_none_or(|mods| mods.iter().any(|x| x.as_str() == Some("text")))
+ })
+ .filter_map(|m| {
+ let raw = m.get("id")?.as_str()?;
+ // Gemini sometimes answers "models/gemini-…".
+ let id = raw.strip_prefix("models/").unwrap_or(raw).to_string();
+ let lower = id.to_lowercase();
+ if id.is_empty() || p.not_chat.iter().any(|x| lower.contains(x)) {
+ return None;
+ }
+ let created = m.get("created").and_then(Value::as_i64).unwrap_or(0);
+ let free = p.id == "openrouter" && is_free(m, &id);
+ let name = m.get("name").and_then(Value::as_str).unwrap_or(&id);
+ let label = if free && !name.to_lowercase().contains("(free)") { format!("{name} (free)") } else { name.to_string() };
+ Some((ModelInfo { id, label }, created, free))
+ })
+ .collect();
+ match p.id {
+ // Newest first, as on the Mac.
+ "openai" => models.sort_by_key(|m| std::cmp::Reverse(m.1)),
+ // Free models first, then by name.
+ "openrouter" => models.sort_by(|a, b| {
+ b.2.cmp(&a.2).then_with(|| a.0.label.to_lowercase().cmp(&b.0.label.to_lowercase()))
+ }),
+ _ => {}
+ }
+ models.into_iter().map(|(m, _, _)| m).collect()
+}
+
+fn is_free(m: &Value, id: &str) -> bool {
+ let zero = |ptr: &str| {
+ m.pointer(ptr)
+ .and_then(Value::as_str)
+ .is_some_and(|v| v.parse::<f64>().ok() == Some(0.0))
+ };
+ id.ends_with(":free") || (zero("/pricing/prompt") && zero("/pricing/completion"))
+}
+
+enum FilePart {
+ Image(Value),
+ Text(String),
+}
+
+/// Images → image_url data URL, text/code → inline text. PDFs and other binary
+/// files go by name only (there is no portable document part).
+fn file_part(path: &str) -> Option<FilePart> {
+ let ext = std::path::Path::new(path)
+ .extension()
+ .and_then(|e| e.to_str())
+ .unwrap_or("")
+ .to_lowercase();
+ let len = std::fs::metadata(path).ok()?.len();
+ let image = match ext.as_str() {
+ "jpg" | "jpeg" => Some("image/jpeg"),
+ "png" => Some("image/png"),
+ "gif" => Some("image/gif"),
+ "webp" => Some("image/webp"),
+ _ => None,
+ };
+ if let Some(media) = image {
+ if len > MAX_IMAGE {
+ return None;
+ }
+ let bytes = std::fs::read(path).ok()?;
+ let url = format!("data:{media};base64,{}", crate::claude::base64_for(&bytes));
+ return Some(FilePart::Image(json!({ "type": "image_url", "image_url": { "url": url } })));
+ }
+ if ext == "pdf" || len > MAX_INLINE_TEXT {
+ return None;
+ }
+ std::fs::read_to_string(path).ok().map(FilePart::Text)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn p(id: &str) -> &'static Provider {
+ provider(id).unwrap()
+ }
+
+ #[test]
+ fn the_table_points_at_each_providers_own_api_and_key() {
+ assert_eq!(url(p("openai"), "chat/completions").unwrap().as_str(), "https://api.openai.com/v1/chat/completions");
+ assert_eq!(
+ url(p("google"), "chat/completions").unwrap().as_str(),
+ "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions"
+ );
+ assert_eq!(url(p("openrouter"), "models").unwrap().as_str(), "https://openrouter.ai/api/v1/models");
+ for prov in PROVIDERS {
+ assert!(crate::secrets::KNOWN_KEYS.contains(&prov.key), "{}", prov.key);
+ assert!(prov.base_url.starts_with("https://"));
+ }
+ assert!(provider("anthropic").is_none());
+ assert!(provider("ollama").is_none());
+ }
+
+ #[test]
+ fn the_request_is_system_then_history_then_the_new_turn() {
+ let history = vec![json!({"role":"user","content":"a"}), json!({"role":"assistant","content":"b"})];
+ let user = user_message(false, None, "c");
+ assert_eq!(user, json!({"role":"user","content":"c"}));
+ let body = request_body(p("google"), "gemini-x", "sys", &history, &user);
+ assert_eq!(body["model"], "gemini-x");
+ assert_eq!(body["max_tokens"], MAX_TOKENS);
+ let msgs = body["messages"].as_array().unwrap();
+ assert_eq!(msgs.len(), 4);
+ assert_eq!(msgs[0], json!({"role":"system","content":"sys"}));
+ assert_eq!(msgs[3], user);
+ assert!(body.get("tools").is_none(), "chat only: no tools");
+ // OpenAI's reasoning models refuse the old field name.
+ let body = request_body(p("openai"), "gpt-5", "sys", &[], &user);
+ assert_eq!(body["max_completion_tokens"], MAX_TOKENS);
+ assert!(body.get("max_tokens").is_none());
+ }
+
+ #[test]
+ fn context_rides_with_the_first_turn_as_text_or_an_image() {
+ let dir = std::env::temp_dir().join(format!("coucou-oai-{}", std::process::id()));
+ std::fs::create_dir_all(&dir).unwrap();
+ let txt = dir.join("notes.txt");
+ std::fs::write(&txt, "hello").unwrap();
+ let ctx = ChatContext::File { name: "notes.txt".into(), path: txt.to_string_lossy().into() };
+ assert_eq!(
+ user_message(true, Some(&ctx), "sum up")["content"],
+ "File: notes.txt\nFile contents:\nhello\n\nsum up"
+ );
+ assert_eq!(user_message(false, Some(&ctx), "more")["content"], "more");
+
+ let png = dir.join("pic.png");
+ std::fs::write(&png, [0x89, b'P', b'N', b'G']).unwrap();
+ let ctx = ChatContext::File { name: "pic.png".into(), path: png.to_string_lossy().into() };
+ let msg = user_message(true, Some(&ctx), "what is it?");
+ let parts = msg["content"].as_array().unwrap();
+ assert_eq!(parts[0]["type"], "image_url");
+ assert!(parts[0]["image_url"]["url"].as_str().unwrap().starts_with("data:image/png;base64,"));
+ assert_eq!(parts[1], json!({"type":"text","text":"File: pic.png\n\nwhat is it?"}));
+
+ let pdf = dir.join("doc.pdf");
+ std::fs::write(&pdf, "%PDF").unwrap();
+ let ctx = ChatContext::File { name: "doc.pdf".into(), path: pdf.to_string_lossy().into() };
+ assert_eq!(user_message(true, Some(&ctx), "q")["content"], "File: doc.pdf\n\nq");
+ let _ = std::fs::remove_dir_all(dir);
+
+ let ctx = ChatContext::Window { app_name: "Code".into(), title: "x".into(), url: None };
+ assert_eq!(user_message(true, Some(&ctx), "q")["content"], "Context — App: Code, Window: x\n\nq");
+ }
+
+ #[test]
+ fn the_reply_text_or_the_error_inside_a_200_is_read() {
+ let ok = json!({"choices":[{"message":{"role":"assistant","content":" Hi! "}}]});
+ assert_eq!(reply_text(p("openai"), &ok).unwrap(), "Hi!");
+ let failed = json!({"error":{"message":"upstream down"}});
+ assert_eq!(reply_text(p("openrouter"), &failed).unwrap_err(), "OpenRouter: upstream down");
+ assert_eq!(reply_text(p("google"), &json!({"choices":[]})).unwrap_err(), "No response text.");
+ }
+
+ #[test]
+ fn status_errors_say_what_to_do() {
+ assert!(status_error(p("openai"), 401, "x").contains("rejected the API key"));
+ assert!(status_error(p("openrouter"), 402, "x").contains("credits"));
+ assert_eq!(status_error(p("google"), 500, "boom"), "Google AI 500: boom");
+ }
+
+ #[test]
+ fn model_lists_keep_chat_models_only() {
+ let openai = json!({"data":[
+ {"id":"gpt-4o","created":100},
+ {"id":"text-embedding-3-small","created":300},
+ {"id":"gpt-5-mini","created":200},
+ {"id":"whisper-1","created":400},
+ {"id":"dall-e-3","created":500}
+ ]});
+ let ids: Vec<_> = parse_models(p("openai"), &openai).into_iter().map(|m| m.id).collect();
+ assert_eq!(ids, vec!["gpt-5-mini", "gpt-4o"]);
+
+ let google = json!({"data":[
+ {"id":"models/gemini-2.0-flash"},
+ {"id":"models/text-embedding-004"},
+ {"id":"gemini-2.5-pro"},
+ {"id":"models/imagen-3.0"}
+ ]});
+ let ids: Vec<_> = parse_models(p("google"), &google).into_iter().map(|m| m.id).collect();
+ assert_eq!(ids, vec!["gemini-2.0-flash", "gemini-2.5-pro"]);
+
+ let openrouter = json!({"data":[
+ {"id":"b/paid","name":"B Paid","pricing":{"prompt":"0.000001","completion":"0.000002"}},
+ {"id":"a/free:free","name":"A (free)"},
+ {"id":"c/zero","name":"C Zero","pricing":{"prompt":"0","completion":"0"}},
+ {"id":"d/image","name":"D Image","architecture":{"output_modalities":["image"]}}
+ ]});
+ let models = parse_models(p("openrouter"), &openrouter);
+ let labels: Vec<_> = models.iter().map(|m| m.label.as_str()).collect();
+ assert_eq!(labels, vec!["A (free)", "C Zero (free)", "B Paid"]);
+ }
+
+ #[test]
+ fn an_unknown_answer_gives_an_empty_list() {
+ assert!(parse_models(p("openai"), &json!({"nope":true})).is_empty());
+ }
+}
diff --git a/windows/src-tauri/src/secrets.rs b/windows/src-tauri/src/secrets.rs
index 5c37b652..46b94b09 100644
--- a/windows/src-tauri/src/secrets.rs
+++ b/windows/src-tauri/src/secrets.rs
@@ -8,6 +8,9 @@ const SERVICE: &str = "fr.louisraille.coucou";
/// Every key Coucou may store. Anything outside this list is refused.
pub const KNOWN_KEYS: &[&str] = &[
"anthropic-api-key",
+ "openai-api-key",
+ "google-api-key",
+ "openrouter-api-key",
"n8n-url",
"n8n-api-key",
"vercel-token",
diff --git a/windows/src-tauri/src/settings.rs b/windows/src-tauri/src/settings.rs
index 17f63e1c..6abe0948 100644
--- a/windows/src-tauri/src/settings.rs
+++ b/windows/src-tauri/src/settings.rs
@@ -3,6 +3,7 @@
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
+use std::collections::BTreeMap;
use std::io::ErrorKind;
use std::path::{Path, PathBuf};
use std::sync::{Mutex, MutexGuard, PoisonError};
@@ -23,6 +24,12 @@ pub struct Settings {
pub hooks_installed: bool,
/// Claude model used by the chat. Changeable in the settings window.
pub model: String,
+ /// Who the chat talks to: "anthropic", or a cloud provider of
+ /// openai_compat.rs ("openai", "google", "openrouter"). Picked in the chat view.
+ pub chat_provider: String,
+ /// The model picked for each provider other than Anthropic (whose model is
+ /// `model`), by provider id.
+ pub chat_models: BTreeMap<String, String>,
}
fn default_model() -> String {
@@ -46,6 +53,8 @@ impl Default for Settings {
autostart: false,
hooks_installed: false,
model: default_model(),
+ chat_provider: crate::chat::ANTHROPIC.into(),
+ chat_models: BTreeMap::new(),
}
}
}
@@ -306,7 +315,9 @@ mod tests {
"screen": "cursor",
"autostart": true,
"hooksInstalled": true,
- "model": "some-model"
+ "model": "some-model",
+ "chatProvider": "openai",
+ "chatModels": { "openai": "gpt-x" }
}"#;
fn custom() -> Value {
@@ -632,6 +643,8 @@ mod tests {
"autostart",
"hooksInstalled",
"model",
+ "chatProvider",
+ "chatModels",
]
);
let _ = std::fs::remove_dir_all(&dir);