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.
- package/CHANGELOG.md +8 -0
- package/README.md +13 -9
- package/dist/chunks/{chunk-H2FAKNUI.js → chunk-4QQKAYXY.js} +2 -2
- package/dist/chunks/{chunk-2GDAWRT7.js → chunk-5CZK76GD.js} +168 -3
- package/dist/chunks/{chunk-XT5WAZRV.js → chunk-5J4EZHBC.js} +5 -5
- package/dist/chunks/{chunk-SYH37PL6.js → chunk-5TGJUVF3.js} +5 -5
- package/dist/chunks/{chunk-KAWTUWO2.js → chunk-D3EGRS3I.js} +4 -4
- package/dist/chunks/{chunk-N33J57DT.js → chunk-FCUOVDGP.js} +6 -6
- package/dist/chunks/{chunk-HFMRQTXE.js → chunk-HAXIR2UL.js} +1 -1
- package/dist/chunks/{chunk-33MUQ6E5.js → chunk-IJH424FN.js} +1 -1
- package/dist/chunks/{chunk-XATEICDJ.js → chunk-PKKPIADV.js} +4 -4
- package/dist/chunks/{chunk-R4PMMMD5.js → chunk-QVXNGO7V.js} +53 -26
- package/dist/chunks/{chunk-OF5PQQQ4.js → chunk-UQLWSQM7.js} +4 -4
- package/dist/chunks/{chunk-CGJ4VEUD.js → chunk-Y5KHLA3U.js} +1 -1
- package/dist/chunks/{chunk-S6YZ2A73.js → chunk-ZNW5U3O5.js} +3 -3
- package/dist/chunks/{client-TI5W2YDP.js → client-ZC4NAQXK.js} +3 -3
- package/dist/chunks/{config-PA5NJ37O.js → config-IC2NOB3E.js} +1 -1
- package/dist/chunks/{context-RKFGCGP7.js → context-QVV5J6E6.js} +5 -5
- package/dist/chunks/{doctor-ZQICU2F4.js → doctor-ZKLHHV6B.js} +11 -8
- package/dist/chunks/{errors-OJZTUG74.js → errors-EOWKXBLQ.js} +2 -2
- package/dist/chunks/{init-5ENYFSX2.js → init-GVUB76FT.js} +96 -22
- package/dist/chunks/orchestrator-256I33EZ.js +22 -0
- package/dist/chunks/{orchestrator-XLVMKC4V.js → orchestrator-7PHH2BFH.js} +10 -10
- package/dist/chunks/{orchestrator-NJ7US5XC.js → orchestrator-MJZMWRN6.js} +9 -9
- package/dist/chunks/{session-ZC5D2O77.js → session-4F3Y36PA.js} +4 -4
- package/dist/chunks/{store-JG5OKLEO.js → store-V3BGNZAC.js} +3 -3
- package/dist/chunks/{sync-ESB3YWI2.js → sync-TOXUX5TK.js} +7 -7
- package/dist/chunks/{team-PFETXIEC.js → team-Z3LGTAVW.js} +9 -9
- package/dist/chunks/{telegram-IMADPCKR.js → telegram-Y5YBM5OM.js} +12 -12
- package/dist/chunks/{wakeup-UX6AM7M6.js → wakeup-TCMBEW2F.js} +15 -15
- package/dist/chunks/{workspace-XERWEYJB.js → workspace-435F7NMP.js} +4 -4
- package/dist/index.js +22 -22
- package/package.json +6 -1
- package/dist/chunks/orchestrator-ATA2LHPJ.js +0 -22
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ConfigError,
|
|
3
3
|
DEFAULT_MODEL,
|
|
4
|
+
PROVIDERS,
|
|
5
|
+
guessProvider,
|
|
4
6
|
loadConfig
|
|
5
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-5CZK76GD.js";
|
|
6
8
|
import {
|
|
7
9
|
findWorkspaceRoot
|
|
8
10
|
} from "./chunk-MMIJKDOU.js";
|
|
@@ -19,7 +21,7 @@ import { createOpenRouter } from "@openrouter/ai-sdk-provider";
|
|
|
19
21
|
// ai/errors.ts
|
|
20
22
|
var MissingApiKeyError = class extends Error {
|
|
21
23
|
constructor() {
|
|
22
|
-
super("
|
|
24
|
+
super("No AI API key is set");
|
|
23
25
|
this.name = "MissingApiKeyError";
|
|
24
26
|
}
|
|
25
27
|
};
|
|
@@ -65,13 +67,25 @@ function findCode(e) {
|
|
|
65
67
|
}
|
|
66
68
|
return void 0;
|
|
67
69
|
}
|
|
70
|
+
function serviceName(e) {
|
|
71
|
+
const host = (() => {
|
|
72
|
+
try {
|
|
73
|
+
return new URL(String(e?.url ?? "")).hostname;
|
|
74
|
+
} catch {
|
|
75
|
+
return "";
|
|
76
|
+
}
|
|
77
|
+
})();
|
|
78
|
+
const map = [[/openrouter/, "OpenRouter"], [/openai\.com/, "OpenAI"], [/anthropic/, "Anthropic"], [/googleapis|google/, "Google Gemini"], [/groq/, "Groq"], [/x\.ai/, "xAI"], [/deepseek/, "DeepSeek"], [/mistral/, "Mistral"], [/cerebras/, "Cerebras"], [/together/, "Together AI"], [/localhost|127\.0\.0\.1/, "Your local AI server"]];
|
|
79
|
+
for (const [re, name] of map) if (re.test(host)) return name;
|
|
80
|
+
return host ? `The AI service (${host})` : "The AI service";
|
|
81
|
+
}
|
|
68
82
|
function mapAiError(error) {
|
|
69
83
|
const outer = asErrorLike(error);
|
|
70
84
|
if (error instanceof MissingApiKeyError || outer.name === "MissingApiKeyError" || outer.name === "AI_LoadAPIKeyError") {
|
|
71
85
|
return {
|
|
72
86
|
kind: "missing_key",
|
|
73
|
-
title: "No
|
|
74
|
-
hint: "Run `saarthiclaw init`
|
|
87
|
+
title: "No AI API key configured.",
|
|
88
|
+
hint: "Run `saarthiclaw init` and paste any AI key (OpenAI, Claude, Gemini, Groq, OpenRouter…). Free keys: https://openrouter.ai/keys or https://aistudio.google.com/apikey"
|
|
75
89
|
};
|
|
76
90
|
}
|
|
77
91
|
if (outer.name === "AI_NoOutputGeneratedError") {
|
|
@@ -93,6 +107,8 @@ function mapAiError(error) {
|
|
|
93
107
|
}
|
|
94
108
|
const e = unwrap(error);
|
|
95
109
|
const status = e.statusCode ?? e.status;
|
|
110
|
+
const who = serviceName(e);
|
|
111
|
+
const isOr = who === "OpenRouter";
|
|
96
112
|
const body = `${e.message ?? ""} ${e.responseBody ?? ""}`.toLowerCase();
|
|
97
113
|
if (/team ai key/.test(body)) {
|
|
98
114
|
return {
|
|
@@ -120,23 +136,23 @@ function mapAiError(error) {
|
|
|
120
136
|
if (status === 401) {
|
|
121
137
|
return {
|
|
122
138
|
kind: "invalid_key",
|
|
123
|
-
title:
|
|
124
|
-
hint: "
|
|
139
|
+
title: `${who} rejected the API key (401).`,
|
|
140
|
+
hint: "Run `saarthiclaw init` to check or replace the key (it detects the provider automatically).",
|
|
125
141
|
status
|
|
126
142
|
};
|
|
127
143
|
}
|
|
128
144
|
if (status === 402) {
|
|
129
145
|
return {
|
|
130
146
|
kind: "payment",
|
|
131
|
-
title:
|
|
132
|
-
hint: "Use a `:free` model (e.g. qwen/qwen3-coder:free) or add credits at https://openrouter.ai/credits",
|
|
147
|
+
title: `${who} says this request needs credits (402).`,
|
|
148
|
+
hint: isOr ? "Use a `:free` model (e.g. qwen/qwen3-coder:free) or add credits at https://openrouter.ai/credits" : "Add credits/billing for this key with the provider, or switch to a free key (e.g. Google Gemini or OpenRouter :free models).",
|
|
133
149
|
status
|
|
134
150
|
};
|
|
135
151
|
}
|
|
136
152
|
if (status === 403) {
|
|
137
153
|
return {
|
|
138
154
|
kind: "forbidden",
|
|
139
|
-
title:
|
|
155
|
+
title: `${who} refused the request (403).`,
|
|
140
156
|
hint: "Your key may lack permission for this model, or the input was flagged by moderation. Try another model.",
|
|
141
157
|
status
|
|
142
158
|
};
|
|
@@ -144,16 +160,16 @@ function mapAiError(error) {
|
|
|
144
160
|
if (status === 429) {
|
|
145
161
|
return {
|
|
146
162
|
kind: "rate_limit",
|
|
147
|
-
title:
|
|
148
|
-
hint: FREE_TIER_NOTE,
|
|
163
|
+
title: `Rate limited by ${who} (429), even after retrying with backoff.`,
|
|
164
|
+
hint: isOr ? FREE_TIER_NOTE : "Wait a minute and try again, or switch model with `--model <id>`.",
|
|
149
165
|
status
|
|
150
166
|
};
|
|
151
167
|
}
|
|
152
168
|
if (status === 404 || status === 400 && /(not a valid model|no endpoints found|model .*not (found|exist)|unknown model)/.test(body)) {
|
|
153
169
|
return {
|
|
154
170
|
kind: "model_not_found",
|
|
155
|
-
title:
|
|
156
|
-
hint: "Free model lineups rotate. Pick another with `saarthiclaw init` or `--model <id>` (see https://openrouter.ai/models?q=free).",
|
|
171
|
+
title: `That model is not available on ${who}.`,
|
|
172
|
+
hint: isOr ? "Free model lineups rotate. Pick another with `saarthiclaw init` or `--model <id>` (see https://openrouter.ai/models?q=free)." : "Run `saarthiclaw init` to see the models your key can use, or pass `--model <id>`.",
|
|
157
173
|
status
|
|
158
174
|
};
|
|
159
175
|
}
|
|
@@ -161,14 +177,14 @@ function mapAiError(error) {
|
|
|
161
177
|
if (code && NETWORK_CODES.has(code) || /fetch failed|network|socket hang up|getaddrinfo/.test(body)) {
|
|
162
178
|
return {
|
|
163
179
|
kind: "network",
|
|
164
|
-
title:
|
|
180
|
+
title: `Could not reach ${who} (network error).`,
|
|
165
181
|
hint: "Check your internet connection, proxy or firewall, then try again."
|
|
166
182
|
};
|
|
167
183
|
}
|
|
168
184
|
if (status !== void 0 && status >= 500) {
|
|
169
185
|
return {
|
|
170
186
|
kind: "unknown",
|
|
171
|
-
title:
|
|
187
|
+
title: `${who} had a server error (${status}).`,
|
|
172
188
|
hint: "This is usually temporary — try again in a moment or switch model.",
|
|
173
189
|
status
|
|
174
190
|
};
|
|
@@ -183,6 +199,16 @@ function mapAiError(error) {
|
|
|
183
199
|
var AI_MAX_RETRIES = 3;
|
|
184
200
|
|
|
185
201
|
// ai/ai.config.ts
|
|
202
|
+
function createAiClient(opts) {
|
|
203
|
+
const info = PROVIDERS[opts.provider];
|
|
204
|
+
return createOpenRouter({
|
|
205
|
+
apiKey: opts.apiKey || "none",
|
|
206
|
+
baseURL: (opts.baseURL || info.baseURL).replace(/\/+$/, ""),
|
|
207
|
+
headers: opts.provider === "openrouter" ? { "HTTP-Referer": "https://github.com/hritik0447/SaarthiClaw", "X-Title": "SaarthiClaw" } : {},
|
|
208
|
+
// Claude's API needs max_tokens on every request.
|
|
209
|
+
...opts.provider === "anthropic" ? { extraBody: { max_tokens: 8192 } } : {}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
186
212
|
function getTeamModel(server, accessKey, modelId) {
|
|
187
213
|
const provider = createOpenRouter({
|
|
188
214
|
apiKey: accessKey,
|
|
@@ -194,20 +220,21 @@ function getTeamModel(server, accessKey, modelId) {
|
|
|
194
220
|
function getAgentModel(options = {}) {
|
|
195
221
|
let apiKey = options.apiKey?.trim();
|
|
196
222
|
let modelId = options.model?.trim();
|
|
197
|
-
|
|
223
|
+
let provider = options.provider;
|
|
224
|
+
let baseURL = options.baseURL;
|
|
225
|
+
if (!apiKey || !modelId || !provider) {
|
|
198
226
|
const cfg = loadConfig({ root: findWorkspaceRoot() });
|
|
199
|
-
apiKey
|
|
227
|
+
if (!apiKey) {
|
|
228
|
+
apiKey = cfg.openrouterApiKey;
|
|
229
|
+
provider ||= cfg.provider;
|
|
230
|
+
baseURL ||= cfg.aiBaseUrl;
|
|
231
|
+
}
|
|
200
232
|
modelId ||= cfg.model;
|
|
201
233
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
"HTTP-Referer": "https://github.com/hritik0447/SaarthiClaw",
|
|
207
|
-
"X-Title": "SaarthiClaw"
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
return provider(modelId || DEFAULT_MODEL);
|
|
234
|
+
provider ||= guessProvider(apiKey).id;
|
|
235
|
+
if (!apiKey && provider !== "custom") throw new MissingApiKeyError();
|
|
236
|
+
const client = createAiClient({ apiKey: apiKey ?? "", provider, baseURL });
|
|
237
|
+
return client(modelId || (provider === "openrouter" ? DEFAULT_MODEL : PROVIDERS[provider].defaultModel));
|
|
211
238
|
}
|
|
212
239
|
|
|
213
240
|
// modes/agent/path-safety.ts
|
|
@@ -8,17 +8,17 @@ import {
|
|
|
8
8
|
} from "./chunk-QRAFFI5V.js";
|
|
9
9
|
import {
|
|
10
10
|
getTeamContext
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-ZNW5U3O5.js";
|
|
12
12
|
import {
|
|
13
13
|
RunCancelledError,
|
|
14
14
|
runCancellable
|
|
15
15
|
} from "./chunk-HGBZ55ND.js";
|
|
16
16
|
import {
|
|
17
17
|
sha256Hex
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-4QQKAYXY.js";
|
|
19
19
|
import {
|
|
20
20
|
resolveInsideRoot
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-QVXNGO7V.js";
|
|
22
22
|
|
|
23
23
|
// modes/agent/agent-tools.ts
|
|
24
24
|
import { tool } from "ai";
|
|
@@ -361,7 +361,7 @@ async function sendForApproval(session, tracker, info, team) {
|
|
|
361
361
|
📨 Sent ${res.ids.length} change${res.ids.length === 1 ? "" : "s"} to the Admin for approval.`) + chalk2.dim(" Nothing was written yet.\n"));
|
|
362
362
|
const wait = session.prompter.interactive ? await session.prompter.confirm({ message: "Wait here for the Admin's decision? (approved changes are applied here right after)", initialValue: true }) : false;
|
|
363
363
|
if (wait) {
|
|
364
|
-
const { runTeamSync } = await import("./sync-
|
|
364
|
+
const { runTeamSync } = await import("./sync-TOXUX5TK.js");
|
|
365
365
|
const summary = await runTeamSync(session, { wait: true });
|
|
366
366
|
return { approved: summary.applied > 0, sent: res.ids.length };
|
|
367
367
|
}
|
|
@@ -2,15 +2,15 @@ import {
|
|
|
2
2
|
LEVEL_LABEL,
|
|
3
3
|
TeamClient,
|
|
4
4
|
TeamNetworkError
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-IJH424FN.js";
|
|
6
6
|
import {
|
|
7
7
|
readKey,
|
|
8
8
|
readTeamLink,
|
|
9
9
|
writeTeamLink
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-4QQKAYXY.js";
|
|
11
11
|
import {
|
|
12
12
|
UserFacingError
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-QVXNGO7V.js";
|
|
14
14
|
|
|
15
15
|
// team/context.ts
|
|
16
16
|
import chalk from "chalk";
|
|
@@ -3,9 +3,9 @@ import {
|
|
|
3
3
|
TeamApiError,
|
|
4
4
|
TeamClient,
|
|
5
5
|
TeamNetworkError
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-IJH424FN.js";
|
|
7
|
+
import "./chunk-QVXNGO7V.js";
|
|
8
|
+
import "./chunk-5CZK76GD.js";
|
|
9
9
|
import "./chunk-MMIJKDOU.js";
|
|
10
10
|
import "./chunk-IT46XDPQ.js";
|
|
11
11
|
export {
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
describeTeamMode,
|
|
4
4
|
getTeamContext,
|
|
5
5
|
teamClientFor
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-ZNW5U3O5.js";
|
|
7
|
+
import "./chunk-IJH424FN.js";
|
|
8
|
+
import "./chunk-4QQKAYXY.js";
|
|
9
|
+
import "./chunk-QVXNGO7V.js";
|
|
10
|
+
import "./chunk-5CZK76GD.js";
|
|
11
11
|
import "./chunk-MMIJKDOU.js";
|
|
12
12
|
import "./chunk-IT46XDPQ.js";
|
|
13
13
|
export {
|
|
@@ -7,11 +7,13 @@ import {
|
|
|
7
7
|
} from "./chunk-SANS45ER.js";
|
|
8
8
|
import {
|
|
9
9
|
teamAiFor
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-4QQKAYXY.js";
|
|
11
11
|
import {
|
|
12
12
|
mapAiError
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import
|
|
13
|
+
} from "./chunk-QVXNGO7V.js";
|
|
14
|
+
import {
|
|
15
|
+
PROVIDERS
|
|
16
|
+
} from "./chunk-5CZK76GD.js";
|
|
15
17
|
import {
|
|
16
18
|
projectStateDir
|
|
17
19
|
} from "./chunk-MMIJKDOU.js";
|
|
@@ -68,11 +70,12 @@ function staticChecks(cfg) {
|
|
|
68
70
|
});
|
|
69
71
|
const teamAi = teamAiFor(cfg.root);
|
|
70
72
|
checks.push({
|
|
71
|
-
name: "
|
|
72
|
-
status: cfg.openrouterApiKey || teamAi ? "pass" : "fail",
|
|
73
|
-
detail: teamAi ? `not needed — using the team's AI key through ${teamAi.server}` : cfg.openrouterApiKey ? `${maskSecret(cfg.openrouterApiKey)}${src(cfg, "openrouterApiKey")}` : "missing — run `saarthiclaw init` (
|
|
73
|
+
name: "AI API key",
|
|
74
|
+
status: cfg.openrouterApiKey || teamAi || cfg.provider === "custom" ? "pass" : "fail",
|
|
75
|
+
detail: teamAi ? `not needed — using the team's AI key through ${teamAi.server}` : cfg.openrouterApiKey ? `${maskSecret(cfg.openrouterApiKey)}${src(cfg, "openrouterApiKey")}` : "missing — run `saarthiclaw init` and paste any AI key (OpenAI, Claude, Gemini, Groq, OpenRouter…), or ask your team Admin for a Team AI key",
|
|
74
76
|
required: true
|
|
75
77
|
});
|
|
78
|
+
checks.push({ name: "AI provider", status: "info", detail: teamAi ? "team dashboard" : `${PROVIDERS[cfg.provider].name}${cfg.provider === "custom" ? ` (${cfg.aiBaseUrl})` : ""}`, required: false });
|
|
76
79
|
checks.push({ name: "Model", status: "info", detail: `${cfg.model}${src(cfg, "model")}`, required: false });
|
|
77
80
|
checks.push({
|
|
78
81
|
name: "Firecrawl (web search)",
|
|
@@ -123,14 +126,14 @@ function printChecks(checks) {
|
|
|
123
126
|
for (const c of checks) console.log(` ${ICON[c.status]} ${c.name.padEnd(width)} ${c.detail}`);
|
|
124
127
|
}
|
|
125
128
|
async function checkTeam(session, live) {
|
|
126
|
-
const { readTeamLink, readKey } = await import("./store-
|
|
129
|
+
const { readTeamLink, readKey } = await import("./store-V3BGNZAC.js");
|
|
127
130
|
const env = session.env ?? process.env;
|
|
128
131
|
const link = readTeamLink(session.root, env);
|
|
129
132
|
if (!link) return { name: "Team dashboard", status: "info", detail: "solo mode (not connected)", required: false };
|
|
130
133
|
if (!readKey(link.server, session.root, env)) return { name: "Team dashboard", status: "warn", detail: `no key saved for ${link.server} — run \`saarthiclaw team connect\``, required: false };
|
|
131
134
|
if (!live) return { name: "Team dashboard", status: "info", detail: `${link.server} (not contacted: --offline)`, required: false };
|
|
132
135
|
try {
|
|
133
|
-
const { TeamClient } = await import("./client-
|
|
136
|
+
const { TeamClient } = await import("./client-ZC4NAQXK.js");
|
|
134
137
|
const me = await new TeamClient(link.server, readKey(link.server, session.root, env), session.teamFetch, 8e3).whoami();
|
|
135
138
|
return { name: "Team dashboard", status: "pass", detail: `${me.name} (${me.permissionLevel.replace("_", " ")}) at ${link.server}`, required: false };
|
|
136
139
|
} catch (e) {
|
|
@@ -6,12 +6,16 @@ import {
|
|
|
6
6
|
} from "./chunk-2OOG5CBM.js";
|
|
7
7
|
import {
|
|
8
8
|
DEFAULT_MODEL,
|
|
9
|
+
DetectError,
|
|
9
10
|
MODEL_PRESETS,
|
|
11
|
+
PROVIDERS,
|
|
12
|
+
PROVIDER_IDS,
|
|
13
|
+
detectAi,
|
|
10
14
|
loadConfig,
|
|
11
15
|
projectConfigPath,
|
|
12
16
|
writeDotenvFile,
|
|
13
17
|
writeProjectConfig
|
|
14
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-5CZK76GD.js";
|
|
15
19
|
import "./chunk-MMIJKDOU.js";
|
|
16
20
|
|
|
17
21
|
// cli/init.ts
|
|
@@ -94,35 +98,105 @@ async function runInit(opts) {
|
|
|
94
98
|
].join("\n")
|
|
95
99
|
);
|
|
96
100
|
const envUpdates = {};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
const clearOldKey = () => {
|
|
102
|
+
const raw = fs.existsSync(envFile) ? fs.readFileSync(envFile, "utf8") : "";
|
|
103
|
+
if (/^\s*(export\s+)?OPENROUTER_API_KEY\s*=/m.test(raw)) envUpdates.OPENROUTER_API_KEY = "";
|
|
104
|
+
};
|
|
105
|
+
const detect = opts.detect ?? detectAi;
|
|
106
|
+
console.log(chalk.dim("Use any AI: OpenAI, Anthropic (Claude), Google Gemini, Groq, xAI, DeepSeek, Mistral, OpenRouter (free models: https://openrouter.ai/keys)…"));
|
|
107
|
+
const source = await prompter.select({
|
|
108
|
+
message: "How do you want to connect an AI?",
|
|
109
|
+
options: [
|
|
110
|
+
{ value: "key", label: "Paste an API key", hint: "the provider and models are detected automatically" },
|
|
111
|
+
{ value: "custom", label: "Local / custom server", hint: "Ollama, LM Studio, vLLM or any OpenAI-compatible URL" }
|
|
112
|
+
],
|
|
113
|
+
initialValue: current.provider === "custom" ? "custom" : "key"
|
|
101
114
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
115
|
+
let provider = current.provider;
|
|
116
|
+
let aiBaseUrl = current.provider === "custom" ? current.aiBaseUrl : void 0;
|
|
117
|
+
let detected;
|
|
118
|
+
let keyToUse = current.openrouterApiKey;
|
|
119
|
+
if (source === "custom") {
|
|
120
|
+
provider = "custom";
|
|
121
|
+
aiBaseUrl = (await prompter.text({
|
|
122
|
+
message: "Server URL (OpenAI-compatible, ends with /v1)",
|
|
123
|
+
initialValue: aiBaseUrl || PROVIDERS.custom.baseURL,
|
|
124
|
+
validate: (v) => /^https?:\/\/\S+$/.test(v.trim()) ? void 0 : "Enter a URL like http://localhost:11434/v1"
|
|
125
|
+
})).trim().replace(/\/+$/, "");
|
|
126
|
+
const k = await askSecret(prompter, "API key for that server", current.provider === "custom" ? current.openrouterApiKey : void 0, { required: false, hint: "leave empty if it needs none" });
|
|
127
|
+
if (k.action === "set") {
|
|
128
|
+
keyToUse = k.value;
|
|
129
|
+
envUpdates.SAARTHICLAW_API_KEY = k.value;
|
|
130
|
+
}
|
|
131
|
+
if (k.action === "remove") {
|
|
132
|
+
keyToUse = void 0;
|
|
133
|
+
envUpdates.SAARTHICLAW_API_KEY = "";
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
detected = await detect(keyToUse ?? "", { provider: "custom", baseURL: aiBaseUrl });
|
|
137
|
+
} catch {
|
|
138
|
+
detected = void 0;
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
142
|
+
const k = await askSecret(prompter, "AI API key" + sourceNote(current, "openrouterApiKey"), attempt === 0 ? current.openrouterApiKey : void 0, {
|
|
143
|
+
required: true,
|
|
144
|
+
hint: "sk-…, sk-ant-…, AIza…, gsk_…, sk-or-…"
|
|
145
|
+
});
|
|
146
|
+
if (k.action === "set") keyToUse = k.value;
|
|
147
|
+
if (!keyToUse) break;
|
|
148
|
+
console.log(chalk.dim("Checking the key and loading its models…"));
|
|
149
|
+
try {
|
|
150
|
+
detected = await detect(keyToUse);
|
|
151
|
+
provider = detected.provider.id;
|
|
152
|
+
if (k.action === "set") {
|
|
153
|
+
envUpdates.SAARTHICLAW_API_KEY = keyToUse;
|
|
154
|
+
clearOldKey();
|
|
155
|
+
}
|
|
156
|
+
console.log(chalk.green(`✓ ${detected.provider.name} key — ${detected.models.length} model${detected.models.length === 1 ? "" : "s"} available.`));
|
|
157
|
+
break;
|
|
158
|
+
} catch (e) {
|
|
159
|
+
const rejected = e instanceof DetectError && e.code === "KEY_REJECTED";
|
|
160
|
+
console.log(chalk.yellow(`⚠ ${e.message}${rejected ? " Check it and paste it again." : ""}`));
|
|
161
|
+
if (rejected) {
|
|
162
|
+
keyToUse = current.openrouterApiKey;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
provider = await prompter.select({
|
|
166
|
+
message: "Which provider is this key from?",
|
|
167
|
+
options: PROVIDER_IDS.filter((p) => p !== "custom").map((p) => ({ value: p, label: PROVIDERS[p].name })),
|
|
168
|
+
initialValue: provider === "custom" ? "openrouter" : provider
|
|
169
|
+
});
|
|
170
|
+
if (k.action === "set") {
|
|
171
|
+
envUpdates.SAARTHICLAW_API_KEY = keyToUse;
|
|
172
|
+
clearOldKey();
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
aiBaseUrl = void 0;
|
|
178
|
+
}
|
|
179
|
+
const providerDefault = provider === "openrouter" ? DEFAULT_MODEL : PROVIDERS[provider].defaultModel;
|
|
180
|
+
const currentModel = current.provider === provider && current.model ? current.model : detected?.model ?? providerDefault;
|
|
181
|
+
const suggestions = detected?.models.length ? detected.models.slice(0, 10) : provider === "openrouter" ? [...MODEL_PRESETS] : [providerDefault];
|
|
110
182
|
const modelChoice = await prompter.select({
|
|
111
|
-
message:
|
|
183
|
+
message: `Which ${PROVIDERS[provider].name} model?`,
|
|
112
184
|
options: [
|
|
113
|
-
...
|
|
114
|
-
...
|
|
115
|
-
{ value: "__custom__", label: "
|
|
185
|
+
...suggestions.map((m, i) => ({ value: m, label: m, hint: i === 0 && detected ? "recommended" : m === currentModel ? "current" : void 0 })),
|
|
186
|
+
...suggestions.includes(currentModel) ? [] : [{ value: currentModel, label: currentModel, hint: "current" }],
|
|
187
|
+
{ value: "__custom__", label: "Type another model id…" }
|
|
116
188
|
],
|
|
117
|
-
initialValue: currentModel
|
|
189
|
+
initialValue: suggestions.includes(currentModel) ? currentModel : suggestions[0]
|
|
118
190
|
});
|
|
119
191
|
let model = modelChoice;
|
|
120
192
|
if (modelChoice === "__custom__") {
|
|
121
193
|
model = (await prompter.text({
|
|
122
|
-
message: "
|
|
123
|
-
|
|
194
|
+
message: "Model id",
|
|
195
|
+
placeholder: providerDefault,
|
|
196
|
+
validate: (v) => /^[\w./:@-]{2,120}$/.test(v.trim()) ? void 0 : "Letters, numbers and . / : @ - only"
|
|
124
197
|
})).trim();
|
|
125
198
|
}
|
|
199
|
+
if (provider === "openrouter") console.log(chalk.dim("Tip: OpenRouter's free models (:free) rotate and are rate-limited; pick another any time with saarthiclaw init."));
|
|
126
200
|
const wantsWeb = current.firecrawlApiKey ? true : await prompter.confirm({ message: "Enable web search with Firecrawl? (optional)", initialValue: false });
|
|
127
201
|
if (wantsWeb) {
|
|
128
202
|
const fc = await askSecret(prompter, "Firecrawl API key", current.firecrawlApiKey, {
|
|
@@ -169,7 +243,7 @@ async function runInit(opts) {
|
|
|
169
243
|
"",
|
|
170
244
|
chalk.bold("About to write:"),
|
|
171
245
|
` .env: ${changedKeys.length ? changedKeys.map((k) => `${k}=${envUpdates[k] ? maskSecret(envUpdates[k]) : "(removed)"}`).join(", ") : chalk.dim("no changes")}`,
|
|
172
|
-
` .saarthiclaw/config.json: model=${model}, allowShellExecution=${allowShell}`,
|
|
246
|
+
` .saarthiclaw/config.json: provider=${provider}${aiBaseUrl ? ` (${aiBaseUrl})` : ""}, model=${model}, allowShellExecution=${allowShell}`,
|
|
173
247
|
` .gitignore: ensure ${GITIGNORE_ENTRIES.join(", ")}`,
|
|
174
248
|
...wantsScript ? [` package.json: scripts.${SCRIPT_NAME}`] : [],
|
|
175
249
|
""
|
|
@@ -181,7 +255,7 @@ async function runInit(opts) {
|
|
|
181
255
|
return { wroteEnvKeys: [], configFile: cfgFile, gitignoreChanged: false, scriptAdded: false, cancelled: true };
|
|
182
256
|
}
|
|
183
257
|
if (changedKeys.length || !fs.existsSync(envFile)) writeDotenvFile(envFile, envUpdates);
|
|
184
|
-
const configFile = writeProjectConfig(root, { model, allowShellExecution: allowShell });
|
|
258
|
+
const configFile = writeProjectConfig(root, { provider, aiBaseUrl, model, allowShellExecution: allowShell });
|
|
185
259
|
const gitignoreChanged = ensureGitignore(root, GITIGNORE_ENTRIES);
|
|
186
260
|
if (wantsScript) scriptAdded = addPackageScript(root);
|
|
187
261
|
const runHint = scriptAdded || scriptState === true ? "npm run saarthiclaw" : "npx saarthiclaw wakeup";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
runPlanMode,
|
|
3
|
+
stepPrompt
|
|
4
|
+
} from "./chunk-FCUOVDGP.js";
|
|
5
|
+
import "./chunk-HAXIR2UL.js";
|
|
6
|
+
import "./chunk-UQLWSQM7.js";
|
|
7
|
+
import "./chunk-Y5KHLA3U.js";
|
|
8
|
+
import "./chunk-QRAFFI5V.js";
|
|
9
|
+
import "./chunk-ZNW5U3O5.js";
|
|
10
|
+
import "./chunk-IJH424FN.js";
|
|
11
|
+
import "./chunk-HGBZ55ND.js";
|
|
12
|
+
import "./chunk-D3EGRS3I.js";
|
|
13
|
+
import "./chunk-5WH3FNFK.js";
|
|
14
|
+
import "./chunk-4QQKAYXY.js";
|
|
15
|
+
import "./chunk-QVXNGO7V.js";
|
|
16
|
+
import "./chunk-5CZK76GD.js";
|
|
17
|
+
import "./chunk-MMIJKDOU.js";
|
|
18
|
+
import "./chunk-IT46XDPQ.js";
|
|
19
|
+
export {
|
|
20
|
+
runPlanMode,
|
|
21
|
+
stepPrompt
|
|
22
|
+
};
|
|
@@ -5,19 +5,19 @@ import {
|
|
|
5
5
|
runAskOnce,
|
|
6
6
|
saveAnswer,
|
|
7
7
|
validateMdFilename
|
|
8
|
-
} from "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-
|
|
8
|
+
} from "./chunk-5TGJUVF3.js";
|
|
9
|
+
import "./chunk-HAXIR2UL.js";
|
|
10
|
+
import "./chunk-UQLWSQM7.js";
|
|
11
|
+
import "./chunk-Y5KHLA3U.js";
|
|
12
12
|
import "./chunk-QRAFFI5V.js";
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
13
|
+
import "./chunk-ZNW5U3O5.js";
|
|
14
|
+
import "./chunk-IJH424FN.js";
|
|
15
15
|
import "./chunk-HGBZ55ND.js";
|
|
16
|
-
import "./chunk-
|
|
16
|
+
import "./chunk-D3EGRS3I.js";
|
|
17
17
|
import "./chunk-5WH3FNFK.js";
|
|
18
|
-
import "./chunk-
|
|
19
|
-
import "./chunk-
|
|
20
|
-
import "./chunk-
|
|
18
|
+
import "./chunk-4QQKAYXY.js";
|
|
19
|
+
import "./chunk-QVXNGO7V.js";
|
|
20
|
+
import "./chunk-5CZK76GD.js";
|
|
21
21
|
import "./chunk-MMIJKDOU.js";
|
|
22
22
|
import "./chunk-IT46XDPQ.js";
|
|
23
23
|
export {
|
|
@@ -2,18 +2,18 @@ import {
|
|
|
2
2
|
onlyDescribedTheChange,
|
|
3
3
|
runAgentMode,
|
|
4
4
|
runAgentTask
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-5J4EZHBC.js";
|
|
6
|
+
import "./chunk-UQLWSQM7.js";
|
|
7
|
+
import "./chunk-Y5KHLA3U.js";
|
|
8
8
|
import "./chunk-QRAFFI5V.js";
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
import "./chunk-ZNW5U3O5.js";
|
|
10
|
+
import "./chunk-IJH424FN.js";
|
|
11
11
|
import "./chunk-HGBZ55ND.js";
|
|
12
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-D3EGRS3I.js";
|
|
13
13
|
import "./chunk-5WH3FNFK.js";
|
|
14
|
-
import "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
14
|
+
import "./chunk-4QQKAYXY.js";
|
|
15
|
+
import "./chunk-QVXNGO7V.js";
|
|
16
|
+
import "./chunk-5CZK76GD.js";
|
|
17
17
|
import "./chunk-MMIJKDOU.js";
|
|
18
18
|
import "./chunk-IT46XDPQ.js";
|
|
19
19
|
export {
|
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
hasWebTools,
|
|
6
6
|
instructionsFor,
|
|
7
7
|
reportAiError
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-D3EGRS3I.js";
|
|
9
9
|
import "./chunk-5WH3FNFK.js";
|
|
10
|
-
import "./chunk-
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-4QQKAYXY.js";
|
|
11
|
+
import "./chunk-QVXNGO7V.js";
|
|
12
|
+
import "./chunk-5CZK76GD.js";
|
|
13
13
|
import "./chunk-MMIJKDOU.js";
|
|
14
14
|
import "./chunk-IT46XDPQ.js";
|
|
15
15
|
export {
|
|
@@ -15,9 +15,9 @@ import {
|
|
|
15
15
|
teamFile,
|
|
16
16
|
writeSyncState,
|
|
17
17
|
writeTeamLink
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
import "./chunk-
|
|
20
|
-
import "./chunk-
|
|
18
|
+
} from "./chunk-4QQKAYXY.js";
|
|
19
|
+
import "./chunk-QVXNGO7V.js";
|
|
20
|
+
import "./chunk-5CZK76GD.js";
|
|
21
21
|
import "./chunk-MMIJKDOU.js";
|
|
22
22
|
import "./chunk-IT46XDPQ.js";
|
|
23
23
|
export {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
applyRemoteAction,
|
|
3
3
|
runTeamSync
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-PKKPIADV.js";
|
|
5
|
+
import "./chunk-Y5KHLA3U.js";
|
|
6
6
|
import "./chunk-QRAFFI5V.js";
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-ZNW5U3O5.js";
|
|
8
|
+
import "./chunk-IJH424FN.js";
|
|
9
9
|
import "./chunk-HGBZ55ND.js";
|
|
10
10
|
import "./chunk-5WH3FNFK.js";
|
|
11
|
-
import "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-4QQKAYXY.js";
|
|
12
|
+
import "./chunk-QVXNGO7V.js";
|
|
13
|
+
import "./chunk-5CZK76GD.js";
|
|
14
14
|
import "./chunk-MMIJKDOU.js";
|
|
15
15
|
import "./chunk-IT46XDPQ.js";
|
|
16
16
|
export {
|