saarthiclaw 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +13 -9
  3. package/dist/chunks/{chunk-H2FAKNUI.js → chunk-4QQKAYXY.js} +2 -2
  4. package/dist/chunks/{chunk-2GDAWRT7.js → chunk-5CZK76GD.js} +168 -3
  5. package/dist/chunks/{chunk-XT5WAZRV.js → chunk-5J4EZHBC.js} +5 -5
  6. package/dist/chunks/{chunk-SYH37PL6.js → chunk-5TGJUVF3.js} +5 -5
  7. package/dist/chunks/{chunk-KAWTUWO2.js → chunk-D3EGRS3I.js} +4 -4
  8. package/dist/chunks/{chunk-N33J57DT.js → chunk-FCUOVDGP.js} +6 -6
  9. package/dist/chunks/{chunk-HFMRQTXE.js → chunk-HAXIR2UL.js} +1 -1
  10. package/dist/chunks/{chunk-33MUQ6E5.js → chunk-IJH424FN.js} +1 -1
  11. package/dist/chunks/{chunk-XATEICDJ.js → chunk-PKKPIADV.js} +4 -4
  12. package/dist/chunks/{chunk-R4PMMMD5.js → chunk-QVXNGO7V.js} +53 -26
  13. package/dist/chunks/{chunk-OF5PQQQ4.js → chunk-UQLWSQM7.js} +4 -4
  14. package/dist/chunks/{chunk-CGJ4VEUD.js → chunk-Y5KHLA3U.js} +1 -1
  15. package/dist/chunks/{chunk-S6YZ2A73.js → chunk-ZNW5U3O5.js} +3 -3
  16. package/dist/chunks/{client-TI5W2YDP.js → client-ZC4NAQXK.js} +3 -3
  17. package/dist/chunks/{config-PA5NJ37O.js → config-IC2NOB3E.js} +1 -1
  18. package/dist/chunks/{context-RKFGCGP7.js → context-QVV5J6E6.js} +5 -5
  19. package/dist/chunks/{doctor-ZQICU2F4.js → doctor-ZKLHHV6B.js} +11 -8
  20. package/dist/chunks/{errors-OJZTUG74.js → errors-EOWKXBLQ.js} +2 -2
  21. package/dist/chunks/{init-5ENYFSX2.js → init-GVUB76FT.js} +96 -22
  22. package/dist/chunks/orchestrator-256I33EZ.js +22 -0
  23. package/dist/chunks/{orchestrator-XLVMKC4V.js → orchestrator-7PHH2BFH.js} +10 -10
  24. package/dist/chunks/{orchestrator-NJ7US5XC.js → orchestrator-MJZMWRN6.js} +9 -9
  25. package/dist/chunks/{session-ZC5D2O77.js → session-4F3Y36PA.js} +4 -4
  26. package/dist/chunks/{store-JG5OKLEO.js → store-V3BGNZAC.js} +3 -3
  27. package/dist/chunks/{sync-ESB3YWI2.js → sync-TOXUX5TK.js} +7 -7
  28. package/dist/chunks/{team-PFETXIEC.js → team-Z3LGTAVW.js} +9 -9
  29. package/dist/chunks/{telegram-IMADPCKR.js → telegram-Y5YBM5OM.js} +12 -12
  30. package/dist/chunks/{wakeup-UX6AM7M6.js → wakeup-TCMBEW2F.js} +15 -15
  31. package/dist/chunks/{workspace-XERWEYJB.js → workspace-435F7NMP.js} +4 -4
  32. package/dist/index.js +22 -22
  33. package/package.json +6 -1
  34. package/dist/chunks/orchestrator-ATA2LHPJ.js +0 -22
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to this project are documented here. This project follows [Semantic Versioning](https://semver.org/).
4
4
 
5
+ ## 0.4.0 — 2026-11-29
6
+
7
+ - **Any AI provider.** Paste a key from OpenAI, Anthropic (Claude), Google Gemini, Groq, xAI, DeepSeek, Mistral, Cerebras, Together or OpenRouter — or point SaarthiClaw at a local OpenAI-compatible server (Ollama, LM Studio, vLLM).
8
+ - `saarthiclaw init` recognises the provider from the key (`sk-ant-…` → Claude, `AIza…` → Gemini, `gsk_…` → Groq, `sk-or-…` → OpenRouter, …), asks the provider for the models the key can use, filters out embedding/audio/image models and recommends a good one. Ambiguous `sk-…` keys are checked against each candidate provider.
9
+ - One OpenAI-compatible client for all providers (Claude gets the `max_tokens` it requires).
10
+ - New settings: `SAARTHICLAW_API_KEY`, `SAARTHICLAW_PROVIDER`, `SAARTHICLAW_BASE_URL`, `SAARTHICLAW_MODEL` (and `provider` / `aiBaseUrl` in `.saarthiclaw/config.json`). Provider-specific variables like `ANTHROPIC_API_KEY` or `GEMINI_API_KEY` also work. Existing OpenRouter setups keep working unchanged.
11
+ - Error messages name the real provider (e.g. “Anthropic rejected the API key”). `doctor` shows the provider.
12
+
5
13
  ## 0.3.0 — 2026-11-29
6
14
 
7
15
  - **`saarthiclaw team watch`** keeps a project folder and the team website (dashboard → Code) in step.
package/README.md CHANGED
@@ -49,12 +49,12 @@ Or globally:
49
49
  npm install -g saarthiclaw
50
50
  ```
51
51
 
52
- You also need an [OpenRouter API key](https://openrouter.ai/keys) (free models are available).
52
+ You also need an API key from **any** AI provider — OpenAI, Anthropic (Claude), Google Gemini, Groq, xAI, DeepSeek, Mistral, Cerebras, Together or [OpenRouter](https://openrouter.ai/keys) (free models) — or a local OpenAI-compatible server such as Ollama. `init` detects the provider from the key and lists the models it can use.
53
53
 
54
54
  ## 60-second quick start
55
55
 
56
56
  ```bash
57
- npx saarthiclaw init # paste your OpenRouter key, pick a model, choose safety options
57
+ npx saarthiclaw init # paste any AI key (provider + models detected), pick a model, choose safety options
58
58
  npx saarthiclaw wakeup # banner → pick CLI (Ask / Plan / Agent) or Telegram
59
59
  ```
60
60
 
@@ -183,7 +183,7 @@ npx saarthiclaw team watch
183
183
 
184
184
  Leave it running. Changes made on the website (web editor, approved requests, AI changes, reverts) appear in this folder within seconds. For the Admin and Trusted members it also works the other way: edit files in your folder and they become a new version on the website. If a file was changed on both sides it is left alone and reported; run with `--prefer website` or `--prefer laptop` to settle it. Only text files are synced — `node_modules`, images and secrets such as `.env` never leave your computer.
185
185
 
186
- **AI for the whole team (one key):** the Admin adds an OpenRouter key on the dashboard under **Settings → Team AI**. From then on every teammate's `ask`, `plan` and `agent` use it through the dashboard, so teammates need **no AI key of their own**. The key never leaves the dashboard, and everyone uses the model the Admin chose. (`SAARTHICLAW_OWN_AI_KEY=1` makes a terminal use its own key instead.)
186
+ **AI for the whole team (one key):** the Admin adds one AI key (any provider) on the dashboard under **Settings → Team AI**. From then on every teammate's `ask`, `plan` and `agent` use it through the dashboard, so teammates need **no AI key of their own**. The key never leaves the dashboard, and everyone uses the model the Admin chose. (`SAARTHICLAW_OWN_AI_KEY=1` makes a terminal use its own key instead.)
187
187
 
188
188
  How it stays safe:
189
189
  - **The dashboard never touches files.** It stores the proposal and the decision; your own terminal applies it.
@@ -206,8 +206,10 @@ Resolution order, first match wins per key:
206
206
 
207
207
  | Variable | Required | Default | Purpose |
208
208
  | --- | --- | --- | --- |
209
- | `OPENROUTER_API_KEY` | yes | — | Your OpenRouter key |
210
- | `OPENROUTER_DEFAULT_MODEL` | no | `qwen/qwen3-coder:free` | Model id |
209
+ | `SAARTHICLAW_API_KEY` | yes* | — | Your AI key from any provider (written by `init`). `OPENROUTER_API_KEY`, `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GEMINI_API_KEY`/`GOOGLE_API_KEY`, `GROQ_API_KEY`, `XAI_API_KEY`, `DEEPSEEK_API_KEY`, `MISTRAL_API_KEY`, `CEREBRAS_API_KEY`, `TOGETHER_API_KEY` also work. *Not needed for a local server. |
210
+ | `SAARTHICLAW_PROVIDER` | no | detected from the key | `openrouter`, `openai`, `anthropic`, `google`, `groq`, `xai`, `deepseek`, `mistral`, `cerebras`, `together` or `custom` |
211
+ | `SAARTHICLAW_BASE_URL` | no | provider default | Server URL for `custom` (e.g. `http://localhost:11434/v1` for Ollama) |
212
+ | `SAARTHICLAW_MODEL` | no | provider default | Model id (`OPENROUTER_DEFAULT_MODEL` still works) |
211
213
  | `FIRECRAWL_API_KEY` | no | — | Enables `web_search`, `web_crawl`, `fetch_url` tools |
212
214
  | `TELEGRAM_BOT_TOKEN` | Telegram only | — | Bot token from @BotFather |
213
215
  | `TELEGRAM_OWNER_ID` | Telegram only | — | Your numeric Telegram user id (legacy `TELEGRAM_BOT_ID` still works, with a deprecation note) |
@@ -218,7 +220,9 @@ Resolution order, first match wins per key:
218
220
 
219
221
  | Key | Default | Notes |
220
222
  | --- | --- | --- |
221
- | `model` | `qwen/qwen3-coder:free` | Same as `OPENROUTER_DEFAULT_MODEL` |
223
+ | `model` | provider default | Same as `SAARTHICLAW_MODEL` |
224
+ | `provider` | detected | Same as `SAARTHICLAW_PROVIDER` |
225
+ | `aiBaseUrl` | provider default | Same as `SAARTHICLAW_BASE_URL` |
222
226
  | `allowShellExecution` | `false` | Offer the shell tool by default |
223
227
  | `maxSteps.ask` / `.plan` / `.agent` | `20` / `30` / `40` | Max tool-loop steps per run (plan = per step) |
224
228
  | `excludePatterns` | `[]` | **Added** to the defaults `node_modules .git dist build .next .cache coverage *.log` |
@@ -286,9 +290,9 @@ Every update from anyone other than the owner is dropped before any handler runs
286
290
 
287
291
  | Symptom | Fix |
288
292
  | --- | --- |
289
- | "No OpenRouter API key configured" | Run `npx saarthiclaw init`, or add `OPENROUTER_API_KEY=…` to the project `.env` |
290
- | "Rate limited by OpenRouter (429)" | Wait a minute, use a different free model, or add credits |
291
- | "OpenRouter rejected the API key (401)" | The key is wrong or revoked — create a new one and re-run `init` |
293
+ | "No AI API key configured" | Run `npx saarthiclaw init` and paste any AI key, or add `SAARTHICLAW_API_KEY=…` to the project `.env` |
294
+ | "Rate limited by … (429)" | Wait a minute, use a different free model, or add credits |
295
+ | "… rejected the API key (401)" | The key is wrong or revoked — create a new one and re-run `init` |
292
296
  | "needs an interactive terminal (TTY)" | Run in a real terminal, or use `saarthiclaw ask "<question>"` in scripts/CI |
293
297
  | Windows: arrow keys or colours look odd | Use Windows Terminal or PowerShell 7; set `NO_COLOR=1` to disable colours |
294
298
  | Windows: shell commands | Commands run through the platform shell (`cmd.exe` on Windows), so write them for that shell |
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  UserFacingError
3
- } from "./chunk-R4PMMMD5.js";
3
+ } from "./chunk-QVXNGO7V.js";
4
4
  import {
5
5
  userConfigDir
6
- } from "./chunk-2GDAWRT7.js";
6
+ } from "./chunk-5CZK76GD.js";
7
7
  import {
8
8
  projectStateDir
9
9
  } from "./chunk-MMIJKDOU.js";
@@ -2,6 +2,151 @@ import {
2
2
  projectStateDir
3
3
  } from "./chunk-MMIJKDOU.js";
4
4
 
5
+ // ai/providers.ts
6
+ var PROVIDERS = {
7
+ openrouter: { id: "openrouter", name: "OpenRouter", baseURL: "https://openrouter.ai/api/v1", defaultModel: "qwen/qwen3-coder:free", keysUrl: "https://openrouter.ai/keys", models: "openrouter", keyPattern: /^sk-or-/ },
8
+ anthropic: { id: "anthropic", name: "Anthropic (Claude)", baseURL: "https://api.anthropic.com/v1", defaultModel: "claude-sonnet-4-5", keysUrl: "https://console.anthropic.com/settings/keys", models: "anthropic", keyPattern: /^sk-ant-/ },
9
+ google: { id: "google", name: "Google Gemini", baseURL: "https://generativelanguage.googleapis.com/v1beta/openai", defaultModel: "gemini-2.5-flash", keysUrl: "https://aistudio.google.com/apikey", models: "openai", keyPattern: /^AIza[0-9A-Za-z_-]{30,}$/ },
10
+ groq: { id: "groq", name: "Groq", baseURL: "https://api.groq.com/openai/v1", defaultModel: "llama-3.3-70b-versatile", keysUrl: "https://console.groq.com/keys", models: "openai", keyPattern: /^gsk_/ },
11
+ xai: { id: "xai", name: "xAI (Grok)", baseURL: "https://api.x.ai/v1", defaultModel: "grok-3-mini", keysUrl: "https://console.x.ai", models: "openai", keyPattern: /^xai-/ },
12
+ cerebras: { id: "cerebras", name: "Cerebras", baseURL: "https://api.cerebras.ai/v1", defaultModel: "llama-3.3-70b", keysUrl: "https://cloud.cerebras.ai", models: "openai", keyPattern: /^csk-/ },
13
+ together: { id: "together", name: "Together AI", baseURL: "https://api.together.xyz/v1", defaultModel: "meta-llama/Llama-3.3-70B-Instruct-Turbo", keysUrl: "https://api.together.ai/settings/api-keys", models: "openai", keyPattern: /^tgp_/ },
14
+ openai: { id: "openai", name: "OpenAI", baseURL: "https://api.openai.com/v1", defaultModel: "gpt-4o-mini", keysUrl: "https://platform.openai.com/api-keys", models: "openai", keyPattern: /^sk-(proj-|svcacct-|admin-|None-)/ },
15
+ deepseek: { id: "deepseek", name: "DeepSeek", baseURL: "https://api.deepseek.com/v1", defaultModel: "deepseek-chat", keysUrl: "https://platform.deepseek.com/api_keys", models: "openai" },
16
+ mistral: { id: "mistral", name: "Mistral", baseURL: "https://api.mistral.ai/v1", defaultModel: "mistral-small-latest", keysUrl: "https://console.mistral.ai/api-keys", models: "openai" },
17
+ custom: { id: "custom", name: "Custom (OpenAI-compatible)", baseURL: "http://localhost:11434/v1", defaultModel: "llama3.1", keysUrl: "", models: "openai" }
18
+ };
19
+ var PROVIDER_IDS = Object.keys(PROVIDERS);
20
+ function isProviderId(v) {
21
+ return typeof v === "string" && PROVIDER_IDS.includes(v);
22
+ }
23
+ function detectProviders(key) {
24
+ const k = key.trim();
25
+ for (const p of Object.values(PROVIDERS)) if (p.keyPattern?.test(k)) return [p];
26
+ if (/^sk-[A-Za-z0-9]{32}$/.test(k) || /^sk-[a-f0-9]{32}$/.test(k)) return [PROVIDERS.deepseek, PROVIDERS.openai];
27
+ if (/^sk-/.test(k)) return [PROVIDERS.openai, PROVIDERS.deepseek];
28
+ if (/^[A-Za-z0-9]{32}$/.test(k)) return [PROVIDERS.mistral];
29
+ return [PROVIDERS.openai, PROVIDERS.mistral];
30
+ }
31
+ function guessProvider(key) {
32
+ return key ? detectProviders(key)[0] ?? PROVIDERS.openai : PROVIDERS.openrouter;
33
+ }
34
+ var NOT_CHAT = /(embed|embedding|whisper|tts|transcribe|dall-e|image|imagen|veo|sora|audio|realtime|moderation|omni-moderation|search|similarity|babbage|davinci|guard|aqa|computer-use|learnlm|native-audio|live|-tts|speech|rerank)/i;
35
+ function score(provider, id) {
36
+ const m = id.toLowerCase();
37
+ let s = 0;
38
+ const ver = /(\d+)(?:[.-](\d))?/.exec(m.replace(/^[^/]*\//, ""));
39
+ if (ver) s += Number(ver[1]) * 10 + (ver[2] ? Number(ver[2]) : 0);
40
+ if (/preview|exp|experimental|beta|-\d{4}-\d{2}-\d{2}|\d{8}/.test(m)) s -= 6;
41
+ if (/nano|lite|tiny|-1b|-3b|8b|mini-high/.test(m)) s -= 8;
42
+ switch (provider) {
43
+ case "anthropic":
44
+ if (/sonnet/.test(m)) s += 30;
45
+ if (/opus/.test(m)) s += 20;
46
+ if (/haiku/.test(m)) s += 12;
47
+ break;
48
+ case "openai":
49
+ if (/^gpt-/.test(m)) s += 25;
50
+ if (/mini/.test(m)) s += 8;
51
+ if (/^o\d/.test(m)) s += 5;
52
+ if (/chat-latest|codex|oss|instruct|turbo|3\.5/.test(m)) s -= 15;
53
+ break;
54
+ case "google":
55
+ if (/gemini/.test(m)) s += 25;
56
+ if (/flash/.test(m)) s += 10;
57
+ if (/pro/.test(m)) s += 6;
58
+ if (/gemma/.test(m)) s -= 20;
59
+ break;
60
+ case "openrouter":
61
+ if (/:free$/.test(m)) s += 40;
62
+ if (/coder|code/.test(m)) s += 15;
63
+ if (/qwen|deepseek|llama|gemini|gpt|claude|nemotron|mistral|glm|kimi/.test(m)) s += 5;
64
+ break;
65
+ case "groq":
66
+ case "cerebras":
67
+ case "together":
68
+ if (/70b|405b|qwen|deepseek|coder|gpt-oss/.test(m)) s += 15;
69
+ if (/versatile|instruct/.test(m)) s += 5;
70
+ break;
71
+ case "deepseek":
72
+ if (/deepseek-chat/.test(m)) s += 30;
73
+ break;
74
+ case "mistral":
75
+ if (/latest/.test(m)) s += 10;
76
+ if (/small|medium|codestral/.test(m)) s += 10;
77
+ break;
78
+ case "xai":
79
+ if (/grok/.test(m)) s += 20;
80
+ if (/mini|fast/.test(m)) s += 6;
81
+ if (/image|vision/.test(m)) s -= 30;
82
+ break;
83
+ }
84
+ return s;
85
+ }
86
+ function rankModels(provider, ids) {
87
+ const clean = [...new Set(ids.map((i) => i.replace(/^models\//, "")).filter((i) => i && !NOT_CHAT.test(i)))];
88
+ return clean.sort((a, b) => score(provider, b) - score(provider, a) || a.localeCompare(b));
89
+ }
90
+ var DetectError = class extends Error {
91
+ constructor(message, code) {
92
+ super(message);
93
+ this.code = code;
94
+ this.name = "DetectError";
95
+ }
96
+ code;
97
+ };
98
+ async function listModels(provider, key, opts = {}) {
99
+ const f = opts.fetchImpl ?? fetch;
100
+ const base = (opts.baseURL || provider.baseURL).replace(/\/+$/, "");
101
+ let res;
102
+ try {
103
+ if (provider.models === "anthropic") {
104
+ res = await f(`${base}/models?limit=100`, { headers: { "x-api-key": key, "anthropic-version": "2023-06-01" }, signal: opts.signal });
105
+ } else {
106
+ res = await f(`${base}/models`, { headers: key ? { Authorization: `Bearer ${key}` } : {}, signal: opts.signal });
107
+ }
108
+ } catch {
109
+ throw new DetectError(`Could not reach ${provider.name} (${base}).`, "UNREACHABLE");
110
+ }
111
+ if (res.status === 401 || res.status === 403) throw new DetectError(`${provider.name} rejected this key.`, "KEY_REJECTED");
112
+ if (!res.ok) throw new DetectError(`${provider.name} answered ${res.status} when listing models.`, "UNKNOWN");
113
+ const body = await res.json().catch(() => ({}));
114
+ let rows = body.data ?? body.models ?? [];
115
+ if (provider.models === "openrouter") rows = rows.filter((r) => !Array.isArray(r.supported_parameters) || r.supported_parameters.includes("tools"));
116
+ return rows.map((r) => String(r.id ?? r.name ?? "")).filter(Boolean);
117
+ }
118
+ async function detectAi(key, opts = {}) {
119
+ const candidates = opts.provider ? [PROVIDERS[opts.provider]] : detectProviders(key);
120
+ const controller = new AbortController();
121
+ const timer = setTimeout(() => controller.abort(), opts.timeoutMs ?? 15e3);
122
+ let lastErr;
123
+ try {
124
+ for (const p of candidates) {
125
+ try {
126
+ const ids = await listModels(p, key, { baseURL: opts.baseURL, fetchImpl: opts.fetchImpl, signal: controller.signal });
127
+ if (p.id === "openrouter") {
128
+ const f = opts.fetchImpl ?? fetch;
129
+ const r = await f(`${(opts.baseURL || p.baseURL).replace(/\/+$/, "")}/key`, { headers: { Authorization: `Bearer ${key}` }, signal: controller.signal }).catch(() => null);
130
+ if (r && (r.status === 401 || r.status === 403)) throw new DetectError("OpenRouter rejected this key.", "KEY_REJECTED");
131
+ }
132
+ const models = rankModels(p.id, ids);
133
+ return { provider: p, baseURL: (opts.baseURL || p.baseURL).replace(/\/+$/, ""), models, model: models[0] ?? p.defaultModel };
134
+ } catch (e) {
135
+ lastErr = e;
136
+ }
137
+ }
138
+ } finally {
139
+ clearTimeout(timer);
140
+ }
141
+ if (lastErr instanceof DetectError) throw lastErr;
142
+ throw new DetectError("Could not recognise this key.", "UNKNOWN");
143
+ }
144
+ var AI_KEY_ENV = ["SAARTHICLAW_API_KEY", "OPENROUTER_API_KEY", "OPENAI_API_KEY", "ANTHROPIC_API_KEY", "GEMINI_API_KEY", "GOOGLE_API_KEY", "GROQ_API_KEY", "XAI_API_KEY", "DEEPSEEK_API_KEY", "MISTRAL_API_KEY", "CEREBRAS_API_KEY", "TOGETHER_API_KEY"];
145
+ function providerFromEnvName(name) {
146
+ const map = { OPENROUTER_API_KEY: "openrouter", OPENAI_API_KEY: "openai", ANTHROPIC_API_KEY: "anthropic", GEMINI_API_KEY: "google", GOOGLE_API_KEY: "google", GROQ_API_KEY: "groq", XAI_API_KEY: "xai", DEEPSEEK_API_KEY: "deepseek", MISTRAL_API_KEY: "mistral", CEREBRAS_API_KEY: "cerebras", TOGETHER_API_KEY: "together" };
147
+ return map[name];
148
+ }
149
+
5
150
  // config/index.ts
6
151
  import fs2 from "node:fs";
7
152
  import os from "node:os";
@@ -117,6 +262,10 @@ var DEFAULTS = {
117
262
  var configFileSchema = z.object({
118
263
  model: z.string().min(1),
119
264
  openrouterApiKey: z.string().min(1),
265
+ /** AI provider id (openrouter, openai, anthropic, google, groq, …). Detected from the key when missing. */
266
+ provider: z.enum(["openrouter", "openai", "anthropic", "google", "groq", "xai", "deepseek", "mistral", "cerebras", "together", "custom"]),
267
+ /** Base URL for the "custom" provider (any OpenAI-compatible server, e.g. Ollama http://localhost:11434/v1). */
268
+ aiBaseUrl: z.string().url(),
120
269
  firecrawlApiKey: z.string().min(1),
121
270
  telegramBotToken: z.string().min(1),
122
271
  telegramOwnerId: z.union([z.string().min(1), z.number().int()]),
@@ -167,8 +316,10 @@ ${issues}`);
167
316
  return parsed.data;
168
317
  }
169
318
  var ENV_KEYS = {
170
- openrouterApiKey: ["OPENROUTER_API_KEY"],
171
- model: ["OPENROUTER_DEFAULT_MODEL"],
319
+ openrouterApiKey: AI_KEY_ENV,
320
+ model: ["SAARTHICLAW_MODEL", "OPENROUTER_DEFAULT_MODEL"],
321
+ provider: ["SAARTHICLAW_PROVIDER"],
322
+ aiBaseUrl: ["SAARTHICLAW_BASE_URL"],
172
323
  firecrawlApiKey: ["FIRECRAWL_API_KEY"],
173
324
  telegramBotToken: ["TELEGRAM_BOT_TOKEN"],
174
325
  telegramOwnerId: ["TELEGRAM_OWNER_ID", "TELEGRAM_BOT_ID"],
@@ -198,12 +349,14 @@ function loadConfig(opts) {
198
349
  if (dotenv) files.dotenv = dotenvPath;
199
350
  if (project) files.project = projectPath;
200
351
  if (user) files.user = userPath;
352
+ let keyEnvName;
201
353
  const fromEnvLike = (key, bag, label) => {
202
354
  if (!bag) return void 0;
203
355
  const names = ENV_KEYS[key];
204
356
  for (const name of names) {
205
357
  const v = nonEmpty(bag[name]);
206
358
  if (v !== void 0) {
359
+ if (key === "openrouterApiKey") keyEnvName = name;
207
360
  if (name === "TELEGRAM_BOT_ID") {
208
361
  warnings.push(
209
362
  `TELEGRAM_BOT_ID (from ${label}) is deprecated — rename it to TELEGRAM_OWNER_ID.`
@@ -244,9 +397,14 @@ function loadConfig(opts) {
244
397
  return void 0;
245
398
  };
246
399
  const openrouterApiKey = pickString("openrouterApiKey");
400
+ const providerRaw = pickString("provider");
401
+ if (providerRaw && !isProviderId(providerRaw)) warnings.push(`Unknown AI provider "${providerRaw}" — detecting it from the key instead.`);
402
+ const provider = isProviderId(providerRaw) ? providerRaw : keyEnvName && providerFromEnvName(keyEnvName) || guessProvider(openrouterApiKey).id;
403
+ if (!isProviderId(providerRaw)) sources.provider = providerRaw ? "default" : sources.openrouterApiKey ?? "default";
404
+ const aiBaseUrl = (pickString("aiBaseUrl") || PROVIDERS[provider].baseURL).replace(/\/+$/, "");
247
405
  let model = pickString("model", flags.model);
248
406
  if (!model) {
249
- model = DEFAULTS.model;
407
+ model = provider === "openrouter" ? DEFAULTS.model : PROVIDERS[provider].defaultModel;
250
408
  sources.model = "default";
251
409
  }
252
410
  const firecrawlApiKey = pickString("firecrawlApiKey");
@@ -298,6 +456,8 @@ function loadConfig(opts) {
298
456
  return {
299
457
  root,
300
458
  openrouterApiKey,
459
+ provider,
460
+ aiBaseUrl,
301
461
  model,
302
462
  firecrawlApiKey,
303
463
  telegramBotToken,
@@ -324,6 +484,11 @@ function writeProjectConfig(root, patch) {
324
484
  }
325
485
 
326
486
  export {
487
+ PROVIDERS,
488
+ PROVIDER_IDS,
489
+ guessProvider,
490
+ DetectError,
491
+ detectAi,
327
492
  writeDotenvFile,
328
493
  DEFAULT_MODEL,
329
494
  MODEL_PRESETS,
@@ -4,15 +4,15 @@ import {
4
4
  finishOnLastStep,
5
5
  generateWithProgress,
6
6
  renderTerminalMarkdown
7
- } from "./chunk-OF5PQQQ4.js";
7
+ } from "./chunk-UQLWSQM7.js";
8
8
  import {
9
9
  ToolExecutor
10
- } from "./chunk-CGJ4VEUD.js";
10
+ } from "./chunk-Y5KHLA3U.js";
11
11
  import {
12
12
  assertProjectOpen,
13
13
  describeTeamMode,
14
14
  getTeamContext
15
- } from "./chunk-S6YZ2A73.js";
15
+ } from "./chunk-ZNW5U3O5.js";
16
16
  import {
17
17
  RunCancelledError
18
18
  } from "./chunk-HGBZ55ND.js";
@@ -20,10 +20,10 @@ import {
20
20
  agentConfigFrom,
21
21
  createTracker,
22
22
  instructionsFor
23
- } from "./chunk-KAWTUWO2.js";
23
+ } from "./chunk-D3EGRS3I.js";
24
24
  import {
25
25
  AI_MAX_RETRIES
26
- } from "./chunk-R4PMMMD5.js";
26
+ } from "./chunk-QVXNGO7V.js";
27
27
 
28
28
  // modes/agent/orchestrator.ts
29
29
  import chalk from "chalk";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createWebTools
3
- } from "./chunk-HFMRQTXE.js";
3
+ } from "./chunk-HAXIR2UL.js";
4
4
  import {
5
5
  createReadOnlyTools,
6
6
  dedupeReadOnlyTools,
@@ -8,19 +8,19 @@ import {
8
8
  finishOnLastStep,
9
9
  generateWithProgress,
10
10
  renderTerminalMarkdown
11
- } from "./chunk-OF5PQQQ4.js";
11
+ } from "./chunk-UQLWSQM7.js";
12
12
  import {
13
13
  ToolExecutor
14
- } from "./chunk-CGJ4VEUD.js";
14
+ } from "./chunk-Y5KHLA3U.js";
15
15
  import {
16
16
  agentConfigFrom,
17
17
  createTracker,
18
18
  instructionsFor,
19
19
  readOnlyAgentConfig
20
- } from "./chunk-KAWTUWO2.js";
20
+ } from "./chunk-D3EGRS3I.js";
21
21
  import {
22
22
  AI_MAX_RETRIES
23
- } from "./chunk-R4PMMMD5.js";
23
+ } from "./chunk-QVXNGO7V.js";
24
24
 
25
25
  // modes/ask/orchestrator.ts
26
26
  import fs from "node:fs";
@@ -3,13 +3,13 @@ import {
3
3
  } from "./chunk-5WH3FNFK.js";
4
4
  import {
5
5
  teamAiFor
6
- } from "./chunk-H2FAKNUI.js";
6
+ } from "./chunk-4QQKAYXY.js";
7
7
  import {
8
8
  getAgentModel,
9
9
  getTeamModel,
10
10
  isSecretPath,
11
11
  mapAiError
12
- } from "./chunk-R4PMMMD5.js";
12
+ } from "./chunk-QVXNGO7V.js";
13
13
 
14
14
  // modes/session.ts
15
15
  import chalk from "chalk";
@@ -357,7 +357,7 @@ function createSession(opts) {
357
357
  model: opts.model ?? (() => {
358
358
  const team = teamAiFor(config.root, opts.env ?? process.env);
359
359
  if (team) return getTeamModel(team.server, team.key, config.model);
360
- return getAgentModel({ apiKey: config.openrouterApiKey, model: config.model });
360
+ return getAgentModel({ apiKey: config.openrouterApiKey, model: config.model, provider: config.provider, baseURL: config.aiBaseUrl });
361
361
  }),
362
362
  teamFetch: opts.teamFetch,
363
363
  env: opts.env,
@@ -392,7 +392,7 @@ ${chalk.red("✖")} ${chalk.bold(f.title)}`);
392
392
  console.error("");
393
393
  }
394
394
  function hasAiAccess(session) {
395
- return Boolean(session.config.openrouterApiKey) || Boolean(teamAiFor(session.root, session.env ?? process.env));
395
+ return Boolean(session.config.openrouterApiKey) || session.config.provider === "custom" || Boolean(teamAiFor(session.root, session.env ?? process.env));
396
396
  }
397
397
 
398
398
  export {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createWebTools
3
- } from "./chunk-HFMRQTXE.js";
3
+ } from "./chunk-HAXIR2UL.js";
4
4
  import {
5
5
  REPEAT_NOTE,
6
6
  createAgentTools,
@@ -10,18 +10,18 @@ import {
10
10
  finishOnLastStep,
11
11
  generateWithProgress,
12
12
  renderTerminalMarkdown
13
- } from "./chunk-OF5PQQQ4.js";
13
+ } from "./chunk-UQLWSQM7.js";
14
14
  import {
15
15
  ToolExecutor,
16
16
  clipOutput
17
- } from "./chunk-CGJ4VEUD.js";
17
+ } from "./chunk-Y5KHLA3U.js";
18
18
  import {
19
19
  Activity
20
20
  } from "./chunk-QRAFFI5V.js";
21
21
  import {
22
22
  describeTeamMode,
23
23
  getTeamContext
24
- } from "./chunk-S6YZ2A73.js";
24
+ } from "./chunk-ZNW5U3O5.js";
25
25
  import {
26
26
  RunCancelledError,
27
27
  runCancellable
@@ -31,10 +31,10 @@ import {
31
31
  createTracker,
32
32
  instructionsFor,
33
33
  readOnlyAgentConfig
34
- } from "./chunk-KAWTUWO2.js";
34
+ } from "./chunk-D3EGRS3I.js";
35
35
  import {
36
36
  AI_MAX_RETRIES
37
- } from "./chunk-R4PMMMD5.js";
37
+ } from "./chunk-QVXNGO7V.js";
38
38
 
39
39
  // modes/plan/orchestrator.ts
40
40
  import fs from "node:fs";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  clipOutput
3
- } from "./chunk-CGJ4VEUD.js";
3
+ } from "./chunk-Y5KHLA3U.js";
4
4
 
5
5
  // modes/plan/web-tools.ts
6
6
  import { tool } from "ai";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  UserFacingError
3
- } from "./chunk-R4PMMMD5.js";
3
+ } from "./chunk-QVXNGO7V.js";
4
4
 
5
5
  // team/client.ts
6
6
  var LEVEL_LABEL = {
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  clipOutput
3
- } from "./chunk-CGJ4VEUD.js";
3
+ } from "./chunk-Y5KHLA3U.js";
4
4
  import {
5
5
  colorizePatch,
6
6
  riskBadge
7
7
  } from "./chunk-QRAFFI5V.js";
8
8
  import {
9
9
  getTeamContext
10
- } from "./chunk-S6YZ2A73.js";
10
+ } from "./chunk-ZNW5U3O5.js";
11
11
  import {
12
12
  RunCancelledError,
13
13
  runCancellable
@@ -19,13 +19,13 @@ import {
19
19
  readSyncState,
20
20
  sha256Hex,
21
21
  writeSyncState
22
- } from "./chunk-H2FAKNUI.js";
22
+ } from "./chunk-4QQKAYXY.js";
23
23
  import {
24
24
  UserFacingError,
25
25
  isSecretPath,
26
26
  relativePosix,
27
27
  resolveInsideRoot
28
- } from "./chunk-R4PMMMD5.js";
28
+ } from "./chunk-QVXNGO7V.js";
29
29
  import {
30
30
  NonInteractiveError
31
31
  } from "./chunk-IT46XDPQ.js";