@exla/rudder 5.0.5 → 5.0.10
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/dist/auth.js +9 -0
- package/dist/auth.js.map +1 -1
- package/dist/cloud.js +2 -1
- package/dist/cloud.js.map +1 -1
- package/dist/codex-config.js +3 -0
- package/dist/codex-config.js.map +1 -1
- package/dist/graph.d.ts +2 -1
- package/dist/graph.js +2 -3
- package/dist/graph.js.map +1 -1
- package/dist/jj.d.ts +11 -26
- package/dist/jj.js +26 -53
- package/dist/jj.js.map +1 -1
- package/dist/main.js +31 -24
- package/dist/main.js.map +1 -1
- package/dist/models.d.ts +9 -1
- package/dist/models.js +353 -228
- package/dist/models.js.map +1 -1
- package/dist/native/darwin-arm64/native-manifest.json +3 -3
- package/dist/native/darwin-arm64/rudder-native +0 -0
- package/dist/native/linux-x64/native-manifest.json +5 -5
- package/dist/native/linux-x64/rudder-jj +0 -0
- package/dist/native/linux-x64/rudder-native +0 -0
- package/dist/onboarding.d.ts +10 -0
- package/dist/onboarding.js +29 -0
- package/dist/onboarding.js.map +1 -1
- package/dist/planner.js +8 -79
- package/dist/planner.js.map +1 -1
- package/dist/private-access/home.js +5 -0
- package/dist/private-access/home.js.map +1 -1
- package/dist/project-files/engine.d.ts +22 -3
- package/dist/project-files/engine.js +27 -11
- package/dist/project-files/engine.js.map +1 -1
- package/dist/project-files/notes.d.ts +64 -0
- package/dist/project-files/notes.js +212 -0
- package/dist/project-files/notes.js.map +1 -0
- package/dist/run-manager.js +4 -4
- package/dist/run-manager.js.map +1 -1
- package/dist/scheduler.d.ts +8 -7
- package/dist/scheduler.js +115 -157
- package/dist/scheduler.js.map +1 -1
- package/dist/state.d.ts +5 -0
- package/dist/state.js +11 -1
- package/dist/state.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.js.map +1 -1
- package/dist/util.d.ts +2 -0
- package/dist/util.js +14 -3
- package/dist/util.js.map +1 -1
- package/package.json +2 -1
package/dist/models.js
CHANGED
|
@@ -1,80 +1,39 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
1
2
|
import fsp from "node:fs/promises";
|
|
2
3
|
import fs from "node:fs";
|
|
3
4
|
import os from "node:os";
|
|
4
5
|
import path from "node:path";
|
|
5
6
|
import { loadAuthStore, loadConfig } from "./state.js";
|
|
6
|
-
import { rudderHome, writeJson } from "./util.js";
|
|
7
|
+
import { readJson, rudderHome, writeJson } from "./util.js";
|
|
7
8
|
const MODELS_DEV_URL = "https://models.dev/api.json";
|
|
8
9
|
const OPENAI_MODELS_URL = "https://api.openai.com/v1/models";
|
|
9
10
|
const ANTHROPIC_MODELS_URL = "https://api.anthropic.com/v1/models?limit=100";
|
|
10
11
|
const ANTHROPIC_VERSION = "2023-06-01";
|
|
11
12
|
const MODELS_DEV_CACHE_MAX_AGE_MS = 24 * 60 * 60 * 1000;
|
|
13
|
+
const FETCH_TIMEOUT_MS = 2500;
|
|
12
14
|
const MODEL_PICKER_LIMIT = 24;
|
|
13
15
|
let modelCatalogInFlight;
|
|
14
16
|
export async function discoverModelOptions(backend, configuredDefault) {
|
|
15
17
|
const defaultDetail = configuredDefault || "CLI default";
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
if (options.length <= 1) {
|
|
30
|
-
const fallback = backend === "claude" ? await discoverClaudeModelsLocal() : await discoverCodexModelsLocal();
|
|
31
|
-
for (const option of fallback) {
|
|
32
|
-
pushUnique(options, option);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return options;
|
|
36
|
-
}
|
|
37
|
-
export function fallbackModelOptions(backend, configuredDefault) {
|
|
38
|
-
const defaultDetail = configuredDefault || "CLI default";
|
|
39
|
-
if (backend === "claude") {
|
|
40
|
-
return [
|
|
41
|
-
{ label: "Default", value: undefined, detail: defaultDetail },
|
|
42
|
-
...claudeCodeAliasOptions(),
|
|
43
|
-
];
|
|
44
|
-
}
|
|
45
|
-
return [
|
|
46
|
-
{ label: "Default", value: undefined, detail: defaultDetail },
|
|
47
|
-
{ label: "gpt-6.1-sol", value: "gpt-6.1-sol" },
|
|
48
|
-
{ label: "gpt-5.6-sol", value: "gpt-5.6-sol" },
|
|
49
|
-
{ label: "gpt-5.6-terra", value: "gpt-5.6-terra" },
|
|
50
|
-
{ label: "gpt-5.6-luna", value: "gpt-5.6-luna" },
|
|
51
|
-
];
|
|
52
|
-
}
|
|
53
|
-
async function discoverCodexModelsDev() {
|
|
54
|
-
const data = await readModelsDev();
|
|
55
|
-
const provider = data.openai;
|
|
56
|
-
const entries = Object.entries(provider?.models ?? {})
|
|
57
|
-
.filter(([id, model]) => isUsableTextModel(id, model) && isCodexRelevantModel(id))
|
|
58
|
-
.sort(compareModelEntries("codex"));
|
|
59
|
-
return entries.map(([id, model]) => ({
|
|
60
|
-
label: id,
|
|
61
|
-
value: id,
|
|
62
|
-
detail: shortModelDetail(model),
|
|
63
|
-
}));
|
|
18
|
+
const picker = backend === "claude" ? "claude" : "codex";
|
|
19
|
+
// The catalog (models.dev, the provider APIs, local history, Claude Code's
|
|
20
|
+
// list) and the CLI's own list: Claude Code's /model list or Codex's model
|
|
21
|
+
// cache. The CLI's list names a model, its effort levels and its display
|
|
22
|
+
// name as soon as the CLI learns it.
|
|
23
|
+
const [{ data, claudeCode }, codex] = await Promise.all([
|
|
24
|
+
readModelsDev(),
|
|
25
|
+
picker === "claude" ? [] : readCodexCliModels(),
|
|
26
|
+
]);
|
|
27
|
+
const cli = picker === "claude" ? claudeCode : codex;
|
|
28
|
+
const catalog = (picker === "claude" ? data.anthropic : data.openai)?.models ?? {};
|
|
29
|
+
return [{ label: "Default", value: undefined, detail: defaultDetail }, ...pickerRows(picker, catalog, cli)];
|
|
64
30
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const entries = Object.entries(provider?.models ?? {})
|
|
69
|
-
.filter(([id, model]) => id.startsWith("claude-") && isUsableTextModel(id, model) && isClaudePickerModel(id))
|
|
70
|
-
.sort(compareModelEntries("claude"));
|
|
71
|
-
return entries.map(([id, model]) => ({
|
|
72
|
-
label: id,
|
|
73
|
-
value: id,
|
|
74
|
-
detail: modelDetail(model, prettyClaudeModel(id)),
|
|
75
|
-
}));
|
|
31
|
+
/** Refreshes the models.dev catalog the dashboard's own picker reads. */
|
|
32
|
+
export async function refreshModelCatalog() {
|
|
33
|
+
await readModelsDev();
|
|
76
34
|
}
|
|
77
|
-
|
|
35
|
+
/** The models Codex's cache (the CLI's own list) shows. */
|
|
36
|
+
async function readCodexCacheModels() {
|
|
78
37
|
const file = path.join(process.env.CODEX_HOME || path.join(os.homedir(), ".codex"), "models_cache.json");
|
|
79
38
|
const raw = await fsp.readFile(file, "utf8").catch(() => "");
|
|
80
39
|
if (!raw) {
|
|
@@ -90,29 +49,23 @@ async function discoverCodexModelsLocal() {
|
|
|
90
49
|
return [];
|
|
91
50
|
}
|
|
92
51
|
return (parsed.models ?? [])
|
|
93
|
-
.filter((model) => model.slug && model.slug !== "codex-auto-review" && model.visibility !== "hide")
|
|
94
|
-
|
|
52
|
+
.filter((model) => model.slug && model.slug !== "codex-auto-review" && model.visibility !== "hide");
|
|
53
|
+
}
|
|
54
|
+
async function discoverCodexModelsLocal() {
|
|
55
|
+
return (await readCodexCacheModels()).map((model) => ({
|
|
95
56
|
label: model.slug || model.display_name || "model",
|
|
96
57
|
value: model.slug,
|
|
97
58
|
detail: model.display_name || model.description || "local Codex cache",
|
|
98
59
|
}));
|
|
99
60
|
}
|
|
100
|
-
async function
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
.
|
|
106
|
-
|
|
107
|
-
label: model,
|
|
108
|
-
value: model,
|
|
109
|
-
detail: prettyClaudeModel(model),
|
|
61
|
+
async function readCodexCliModels() {
|
|
62
|
+
return (await readCodexCacheModels()).map((model) => ({
|
|
63
|
+
id: model.slug,
|
|
64
|
+
name: model.display_name,
|
|
65
|
+
description: model.description,
|
|
66
|
+
efforts: (model.supported_reasoning_levels ?? []).flatMap((level) => (level.effort ? [level.effort] : [])),
|
|
67
|
+
alias: false,
|
|
110
68
|
}));
|
|
111
|
-
const options = claudeCodeAliasOptions();
|
|
112
|
-
for (const option of recent) {
|
|
113
|
-
pushUnique(options, option);
|
|
114
|
-
}
|
|
115
|
-
return options;
|
|
116
69
|
}
|
|
117
70
|
async function readModelsDev() {
|
|
118
71
|
if (modelCatalogInFlight) {
|
|
@@ -125,57 +78,22 @@ async function readModelsDev() {
|
|
|
125
78
|
}
|
|
126
79
|
async function readMergedModelCatalog() {
|
|
127
80
|
const cached = await readModelsDevCache();
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (cached && Date.now() - cached.mtimeMs < MODELS_DEV_CACHE_MAX_AGE_MS) {
|
|
131
|
-
base = cached.data;
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
const fresh = await fetchModelsDev().catch(() => null);
|
|
135
|
-
if (fresh) {
|
|
136
|
-
base = fresh;
|
|
137
|
-
shouldWrite = true;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
base = cached?.data ?? {};
|
|
141
|
-
}
|
|
142
|
-
}
|
|
81
|
+
const current = cached !== null && Date.now() - cached.mtimeMs < MODELS_DEV_CACHE_MAX_AGE_MS;
|
|
82
|
+
const base = current ? cached.data : await fetchJsonWithTimeout(MODELS_DEV_URL, {});
|
|
143
83
|
const merged = cloneModelCatalog(base);
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
84
|
+
const { changed, claudeCode } = await mergeLiveAndLocalModels(merged);
|
|
85
|
+
if (!current || changed) {
|
|
146
86
|
await writeModelsDevCache(merged);
|
|
147
87
|
}
|
|
148
|
-
return merged;
|
|
149
|
-
}
|
|
150
|
-
async function fetchModelsDev() {
|
|
151
|
-
const controller = new AbortController();
|
|
152
|
-
const timer = setTimeout(() => controller.abort(), 2500);
|
|
153
|
-
try {
|
|
154
|
-
const response = await fetch(MODELS_DEV_URL, { signal: controller.signal });
|
|
155
|
-
if (!response.ok) {
|
|
156
|
-
throw new Error(`models.dev returned ${response.status}`);
|
|
157
|
-
}
|
|
158
|
-
return await response.json();
|
|
159
|
-
}
|
|
160
|
-
finally {
|
|
161
|
-
clearTimeout(timer);
|
|
162
|
-
}
|
|
88
|
+
return { data: merged, claudeCode };
|
|
163
89
|
}
|
|
90
|
+
/** The cached catalog, or null when there is none yet. A cache that does not
|
|
91
|
+
* parse is an error that names the file. */
|
|
164
92
|
async function readModelsDevCache() {
|
|
165
93
|
const file = modelsDevCachePath();
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
]);
|
|
170
|
-
if (!raw || !stat) {
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
try {
|
|
174
|
-
return { data: JSON.parse(raw), mtimeMs: stat.mtimeMs };
|
|
175
|
-
}
|
|
176
|
-
catch {
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
94
|
+
const stat = await fsp.stat(file).catch(ignoreMissing);
|
|
95
|
+
const data = stat ? await readJson(file) : null;
|
|
96
|
+
return stat && data ? { data, mtimeMs: stat.mtimeMs } : null;
|
|
179
97
|
}
|
|
180
98
|
async function writeModelsDevCache(data) {
|
|
181
99
|
const file = modelsDevCachePath();
|
|
@@ -197,14 +115,6 @@ function isUsableTextModel(id, model) {
|
|
|
197
115
|
const output = model.modalities?.output;
|
|
198
116
|
return !output || output.includes("text");
|
|
199
117
|
}
|
|
200
|
-
function claudeCodeAliasOptions() {
|
|
201
|
-
return [
|
|
202
|
-
{ label: "opus", value: "opus", detail: "1M context · complex tasks" },
|
|
203
|
-
{ label: "fable", value: "fable", detail: "hard, long-running tasks" },
|
|
204
|
-
{ label: "sonnet", value: "sonnet", detail: "efficient routine tasks" },
|
|
205
|
-
{ label: "haiku", value: "haiku", detail: "fastest quick answers" },
|
|
206
|
-
];
|
|
207
|
-
}
|
|
208
118
|
function isClaudePickerModel(id) {
|
|
209
119
|
// No family-name allowlist: a brand-new model family (fable, and whatever
|
|
210
120
|
// comes after it) must show up in the picker without a Rudder release. Only
|
|
@@ -217,54 +127,14 @@ function isCodexRelevantModel(id) {
|
|
|
217
127
|
}
|
|
218
128
|
return id.includes("codex") || isGptTextModel(id) || isOSeriesModel(id);
|
|
219
129
|
}
|
|
220
|
-
function compareModelEntries(backend) {
|
|
221
|
-
return (a, b) => {
|
|
222
|
-
const score = backend === "claude" ? scoreClaudeModel : scoreCodexModel;
|
|
223
|
-
const diff = score(b[0], b[1]) - score(a[0], a[1]);
|
|
224
|
-
if (diff !== 0) {
|
|
225
|
-
return diff;
|
|
226
|
-
}
|
|
227
|
-
return (b[1].release_date ?? "").localeCompare(a[1].release_date ?? "") || a[0].localeCompare(b[0]);
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
function scoreClaudeModel(id, model) {
|
|
231
|
-
let score = 0;
|
|
232
|
-
if (id.includes("fable"))
|
|
233
|
-
score += 50;
|
|
234
|
-
else if (id.includes("sonnet"))
|
|
235
|
-
score += 40;
|
|
236
|
-
else if (id.includes("opus"))
|
|
237
|
-
score += 35;
|
|
238
|
-
else if (id.includes("haiku"))
|
|
239
|
-
score += 20;
|
|
240
|
-
// An unknown family is likely a NEW tier; rank it above haiku rather than
|
|
241
|
-
// letting it score zero and fall off the picker cut.
|
|
242
|
-
else
|
|
243
|
-
score += 30;
|
|
244
|
-
if (model.reasoning)
|
|
245
|
-
score += 20;
|
|
246
|
-
score += recencyScore(model);
|
|
247
|
-
return score;
|
|
248
|
-
}
|
|
249
|
-
function scoreCodexModel(id, model) {
|
|
250
|
-
let score = 0;
|
|
251
|
-
if (id.includes("codex"))
|
|
252
|
-
score += 60;
|
|
253
|
-
score += gptVersionScore(id);
|
|
254
|
-
if (isOSeriesModel(id))
|
|
255
|
-
score += 25;
|
|
256
|
-
if (model.reasoning)
|
|
257
|
-
score += 20;
|
|
258
|
-
score += recencyScore(model);
|
|
259
|
-
return score;
|
|
260
|
-
}
|
|
261
130
|
async function mergeLiveAndLocalModels(data) {
|
|
262
131
|
let changed = false;
|
|
263
|
-
const [openai, anthropic, codexLocal, claudeLocal] = await Promise.all([
|
|
264
|
-
fetchOpenAIModelCatalog()
|
|
265
|
-
fetchAnthropicModelCatalog()
|
|
266
|
-
readCodexLocalModels()
|
|
267
|
-
readClaudeLocalModelIds()
|
|
132
|
+
const [openai, anthropic, codexLocal, claudeLocal, claudeCode] = await Promise.all([
|
|
133
|
+
fetchOpenAIModelCatalog(),
|
|
134
|
+
fetchAnthropicModelCatalog(),
|
|
135
|
+
readCodexLocalModels(),
|
|
136
|
+
readClaudeLocalModelIds(),
|
|
137
|
+
readClaudeCodeModels(),
|
|
268
138
|
]);
|
|
269
139
|
for (const model of openai) {
|
|
270
140
|
changed = mergeProviderModel(data, "openai", model.id, model.meta) || changed;
|
|
@@ -278,13 +148,43 @@ async function mergeLiveAndLocalModels(data) {
|
|
|
278
148
|
for (const model of claudeLocal) {
|
|
279
149
|
changed = mergeProviderModel(data, "anthropic", model.id, model.meta) || changed;
|
|
280
150
|
}
|
|
281
|
-
|
|
151
|
+
for (const model of claudeCodeCatalogModels(data, claudeCode)) {
|
|
152
|
+
changed = mergeProviderModel(data, "anthropic", model.id, model.meta) || changed;
|
|
153
|
+
}
|
|
154
|
+
return { changed, claudeCode };
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Every model and alias Claude Code lists, with exactly its effort levels, so
|
|
158
|
+
* the dashboard accepts it and offers the same levels as the picker. A model
|
|
159
|
+
* the catalog already has keeps its other fields. A dated id also gives its
|
|
160
|
+
* levels to the undated twin the pickers list in its place.
|
|
161
|
+
*/
|
|
162
|
+
function claudeCodeCatalogModels(data, listed) {
|
|
163
|
+
const known = data.anthropic?.models ?? {};
|
|
164
|
+
const efforts = new Map();
|
|
165
|
+
const names = new Map();
|
|
166
|
+
for (const model of listed) {
|
|
167
|
+
efforts.set(model.id, RUDDER_EFFORTS.claude.filter((level) => model.efforts.includes(level)));
|
|
168
|
+
names.set(model.id, model.name);
|
|
169
|
+
}
|
|
170
|
+
for (const model of listed) {
|
|
171
|
+
const base = /^(.+)-\d{8}$/.exec(model.id)?.[1];
|
|
172
|
+
if (base && known[base] && !efforts.has(base)) {
|
|
173
|
+
efforts.set(base, efforts.get(model.id));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return [...efforts].map(([id, levels]) => ({
|
|
177
|
+
id,
|
|
178
|
+
meta: known[id]
|
|
179
|
+
? { efforts: levels }
|
|
180
|
+
: { id, name: names.get(id) || prettyClaudeModel(id), tool_call: true, efforts: levels, modalities: { output: ["text"] }, source: "claude-code" },
|
|
181
|
+
}));
|
|
282
182
|
}
|
|
283
183
|
async function fetchOpenAIModelCatalog() {
|
|
284
184
|
const authHeaders = await openAIAuthHeaders();
|
|
285
185
|
for (const headers of authHeaders) {
|
|
286
|
-
const response = await fetchJsonWithTimeout(OPENAI_MODELS_URL, { headers })
|
|
287
|
-
const rows = response
|
|
186
|
+
const response = await fetchJsonWithTimeout(OPENAI_MODELS_URL, { headers });
|
|
187
|
+
const rows = response.data ?? [];
|
|
288
188
|
if (rows.length === 0) {
|
|
289
189
|
continue;
|
|
290
190
|
}
|
|
@@ -310,8 +210,8 @@ async function fetchOpenAIModelCatalog() {
|
|
|
310
210
|
async function fetchAnthropicModelCatalog() {
|
|
311
211
|
const authHeaders = await anthropicAuthHeaders();
|
|
312
212
|
for (const headers of authHeaders) {
|
|
313
|
-
const response = await fetchJsonWithTimeout(ANTHROPIC_MODELS_URL, { headers })
|
|
314
|
-
const rows = response
|
|
213
|
+
const response = await fetchJsonWithTimeout(ANTHROPIC_MODELS_URL, { headers });
|
|
214
|
+
const rows = response.data ?? [];
|
|
315
215
|
if (rows.length === 0) {
|
|
316
216
|
continue;
|
|
317
217
|
}
|
|
@@ -396,10 +296,7 @@ async function providerCredentials(provider) {
|
|
|
396
296
|
if (envKey) {
|
|
397
297
|
values.push({ kind: "api_key", value: envKey });
|
|
398
298
|
}
|
|
399
|
-
const [store, config] = await Promise.all([
|
|
400
|
-
loadAuthStore().catch(() => ({ version: 1, profiles: {} })),
|
|
401
|
-
loadConfig().catch(() => undefined),
|
|
402
|
-
]);
|
|
299
|
+
const [store, config] = await Promise.all([loadAuthStore(), loadConfig()]);
|
|
403
300
|
const ids = provider === "openai"
|
|
404
301
|
? [
|
|
405
302
|
config?.backends?.codex?.profileId,
|
|
@@ -439,23 +336,33 @@ function addCredential(values, credential) {
|
|
|
439
336
|
if (!credential) {
|
|
440
337
|
return;
|
|
441
338
|
}
|
|
339
|
+
// Rudder's copy of a CLI login stops working once the CLI refreshes it, and
|
|
340
|
+
// an expired token is only ever refused, so it is not offered at all.
|
|
341
|
+
const expired = "expires" in credential && typeof credential.expires === "number" && credential.expires <= Date.now();
|
|
442
342
|
if (credential.type === "api_key" && credential.key) {
|
|
443
343
|
values.push({ kind: "api_key", value: credential.key });
|
|
444
344
|
}
|
|
445
|
-
else if (credential.type === "token" && credential.token) {
|
|
345
|
+
else if (credential.type === "token" && credential.token && !expired) {
|
|
446
346
|
values.push({ kind: "token", value: credential.token });
|
|
447
347
|
}
|
|
448
|
-
else if (credential.type === "oauth" && credential.access) {
|
|
348
|
+
else if (credential.type === "oauth" && credential.access && !expired) {
|
|
449
349
|
values.push({ kind: "token", value: credential.access });
|
|
450
350
|
}
|
|
451
351
|
}
|
|
452
352
|
async function fetchJsonWithTimeout(url, init) {
|
|
453
353
|
const controller = new AbortController();
|
|
454
|
-
const timer = setTimeout(() => controller.abort(),
|
|
354
|
+
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
455
355
|
try {
|
|
456
|
-
const response = await fetch(url, { ...init, signal: controller.signal })
|
|
356
|
+
const response = await fetch(url, { ...init, signal: controller.signal }).catch((error) => {
|
|
357
|
+
if (controller.signal.aborted) {
|
|
358
|
+
throw new Error(`${url} did not answer within ${FETCH_TIMEOUT_MS / 1000} s`);
|
|
359
|
+
}
|
|
360
|
+
const cause = error instanceof Error && error.cause instanceof Error ? error.cause : error;
|
|
361
|
+
throw new Error(`could not reach ${url}: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
362
|
+
});
|
|
457
363
|
if (!response.ok) {
|
|
458
|
-
|
|
364
|
+
const body = (await response.text()).trim().slice(0, 200);
|
|
365
|
+
throw new Error(`${url} returned ${response.status}${body ? `: ${body}` : ""}`);
|
|
459
366
|
}
|
|
460
367
|
return await response.json();
|
|
461
368
|
}
|
|
@@ -496,48 +403,20 @@ function isOSeriesModel(id) {
|
|
|
496
403
|
}
|
|
497
404
|
function isLikelyReasoningModel(backend, id) {
|
|
498
405
|
if (backend === "claude") {
|
|
499
|
-
if (!id.startsWith("claude-") || id.includes("
|
|
406
|
+
if (!id.startsWith("claude-") || id.includes("3-")) {
|
|
500
407
|
return id.includes("opus") || id.includes("sonnet") || id.includes("fable");
|
|
501
408
|
}
|
|
502
409
|
return true;
|
|
503
410
|
}
|
|
504
411
|
return isGptTextModel(id) || id.includes("codex") || isOSeriesModel(id);
|
|
505
412
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
if (!match) {
|
|
509
|
-
return 0;
|
|
510
|
-
}
|
|
511
|
-
const major = Number(match[1]);
|
|
512
|
-
const minor = Number(match[2] ?? "0");
|
|
513
|
-
if (!Number.isFinite(major) || !Number.isFinite(minor)) {
|
|
514
|
-
return 0;
|
|
515
|
-
}
|
|
516
|
-
return 20 + major * 20 + minor;
|
|
517
|
-
}
|
|
518
|
-
function recencyScore(model) {
|
|
519
|
-
const date = model.release_date || model.last_updated;
|
|
520
|
-
if (!date) {
|
|
521
|
-
return 0;
|
|
522
|
-
}
|
|
523
|
-
const timestamp = Date.parse(date);
|
|
524
|
-
if (Number.isNaN(timestamp)) {
|
|
525
|
-
return 0;
|
|
526
|
-
}
|
|
527
|
-
return Math.min(30, Math.max(0, Math.round((timestamp - Date.parse("2024-01-01")) / (30 * 24 * 60 * 60 * 1000))));
|
|
528
|
-
}
|
|
529
|
-
function shortModelDetail(model) {
|
|
530
|
-
return modelDetail(model, "");
|
|
531
|
-
}
|
|
532
|
-
function modelDetail(model, fallbackName) {
|
|
413
|
+
/** A catalog model's context window and release date. */
|
|
414
|
+
function catalogDetail(model) {
|
|
533
415
|
const parts = [];
|
|
534
|
-
if (model
|
|
535
|
-
parts.push(model.name || fallbackName);
|
|
536
|
-
}
|
|
537
|
-
if (model.limit?.context) {
|
|
416
|
+
if (model?.limit?.context) {
|
|
538
417
|
parts.push(`${formatNumber(model.limit.context)} context`);
|
|
539
418
|
}
|
|
540
|
-
if (model
|
|
419
|
+
if (model?.release_date) {
|
|
541
420
|
parts.push(model.release_date);
|
|
542
421
|
}
|
|
543
422
|
return parts.join(" · ");
|
|
@@ -658,10 +537,256 @@ function prettyClaudeModel(model) {
|
|
|
658
537
|
function capitalize(value) {
|
|
659
538
|
return `${value.slice(0, 1).toUpperCase()}${value.slice(1)}`;
|
|
660
539
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
540
|
+
const ALIAS_GROUP = "Always the newest";
|
|
541
|
+
const CONTEXT_SUFFIX = /\[(\d+)([km])\]$/i;
|
|
542
|
+
// The levels the dashboard passes (native/src/models.rs effort_options_for):
|
|
543
|
+
// a model with an effort setting takes low to xhigh, and Claude also max.
|
|
544
|
+
const RUDDER_EFFORTS = {
|
|
545
|
+
claude: ["low", "medium", "high", "xhigh", "max"],
|
|
546
|
+
codex: ["low", "medium", "high", "xhigh"],
|
|
547
|
+
};
|
|
548
|
+
function pickerRows(backend, catalog, cli) {
|
|
549
|
+
const listed = new Map();
|
|
550
|
+
const aliases = [];
|
|
551
|
+
for (const model of cli) {
|
|
552
|
+
if (model.alias) {
|
|
553
|
+
aliases.push(model);
|
|
554
|
+
}
|
|
555
|
+
else if (!listed.has(model.id)) {
|
|
556
|
+
listed.set(model.id, model);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
const ids = new Set(Object.entries(catalog).filter(([id, model]) => isPickerModel(backend, id, model)).map(([id]) => id));
|
|
560
|
+
for (const id of listed.keys()) {
|
|
561
|
+
ids.add(id);
|
|
562
|
+
}
|
|
563
|
+
// A dated snapshot repeats its undated twin, so only the twin is listed
|
|
564
|
+
// (the dashboard's picker does the same: models.rs dated_duplicate_base).
|
|
565
|
+
for (const id of ids) {
|
|
566
|
+
const base = /^(.+)-\d{8}$/.exec(id)?.[1];
|
|
567
|
+
if (base && ids.has(base)) {
|
|
568
|
+
const twin = listed.get(id);
|
|
569
|
+
if (twin && !listed.has(base)) {
|
|
570
|
+
listed.set(base, twin);
|
|
571
|
+
}
|
|
572
|
+
ids.delete(id);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
const prices = familyPrices(backend, catalog);
|
|
576
|
+
const rows = [...ids]
|
|
577
|
+
.map((id) => ({ id, parsed: parseModelId(backend, id) }))
|
|
578
|
+
.sort((a, b) => compareModelIds(a.parsed, b.parsed, prices) || a.id.localeCompare(b.id))
|
|
579
|
+
// Older catalog models make way; every model the CLI lists stays.
|
|
580
|
+
.filter((row, index) => listed.has(row.id) || index < MODEL_PICKER_LIMIT)
|
|
581
|
+
.map(({ id, parsed }) => ({
|
|
582
|
+
label: modelLabel(backend, id, parsed, listed),
|
|
583
|
+
value: id,
|
|
584
|
+
detail: listed.get(id)?.description || catalogDetail(catalog[id]),
|
|
585
|
+
group: parsed.group,
|
|
586
|
+
efforts: modelEfforts(backend, id, catalog[id], listed.get(id)),
|
|
587
|
+
}));
|
|
588
|
+
const aliasRows = aliases
|
|
589
|
+
.map((alias) => ({ alias, family: alias.id.replace(CONTEXT_SUFFIX, "") }))
|
|
590
|
+
.sort((a, b) => (prices.get(b.family) ?? 0) - (prices.get(a.family) ?? 0) || a.alias.id.localeCompare(b.alias.id))
|
|
591
|
+
.map(({ alias }) => ({
|
|
592
|
+
label: withContext(capitalize(alias.id.replace(CONTEXT_SUFFIX, "")), alias.id),
|
|
593
|
+
value: alias.id,
|
|
594
|
+
detail: [alias.name ? `Now ${alias.name}` : "", alias.description ?? ""].filter(Boolean).join(" · "),
|
|
595
|
+
group: ALIAS_GROUP,
|
|
596
|
+
efforts: modelEfforts(backend, alias.id, catalog[alias.id], alias),
|
|
597
|
+
}));
|
|
598
|
+
return [...rows, ...aliasRows];
|
|
599
|
+
}
|
|
600
|
+
function isPickerModel(backend, id, model) {
|
|
601
|
+
if (!isUsableTextModel(id, model)) {
|
|
602
|
+
return false;
|
|
603
|
+
}
|
|
604
|
+
return backend === "claude" ? id.startsWith("claude-") && isClaudePickerModel(id) : isCodexRelevantModel(id);
|
|
605
|
+
}
|
|
606
|
+
/** "claude-opus-5-5" is Opus of Claude 5.5, "gpt-6.1-sol" Sol of GPT-6.1, "o4-mini" Mini of o4. */
|
|
607
|
+
function parseModelId(backend, id) {
|
|
608
|
+
const suffix = CONTEXT_SUFFIX.exec(id);
|
|
609
|
+
const context = suffix ? `${suffix[1]}${suffix[2].toUpperCase()}` : undefined;
|
|
610
|
+
const base = suffix ? id.slice(0, suffix.index) : id;
|
|
611
|
+
if (backend === "claude") {
|
|
612
|
+
const claude = /^claude-([a-z]+)((?:-\d{1,2})+)(?:-\d{8})?$/.exec(base);
|
|
613
|
+
if (claude) {
|
|
614
|
+
const version = claude[2].slice(1).split("-").map(Number);
|
|
615
|
+
const number = version.join(".");
|
|
616
|
+
return { group: `Claude ${number}`, series: 0, version, family: claude[1], name: `${capitalize(claude[1])} ${number}`, context };
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
const gpt = /^gpt-(\d+(?:\.\d+)?)(?:-([a-z][a-z0-9-]*))?$/.exec(base);
|
|
621
|
+
if (gpt) {
|
|
622
|
+
const variant = gpt[2] ?? "";
|
|
623
|
+
return { group: `GPT-${gpt[1]}`, series: 0, version: gpt[1].split(".").map(Number), family: variant, name: [`GPT-${gpt[1]}`, ...words(variant)].join(" "), context };
|
|
624
|
+
}
|
|
625
|
+
const oSeries = /^o(\d+)(?:-([a-z][a-z0-9-]*))?$/.exec(base);
|
|
626
|
+
if (oSeries) {
|
|
627
|
+
const variant = oSeries[2] ?? "";
|
|
628
|
+
return { group: `o${oSeries[1]}`, series: 1, version: [Number(oSeries[1])], family: `o:${variant}`, name: [`o${oSeries[1]}`, ...words(variant)].join(" "), context };
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return { group: "Other", series: 2, version: [], family: base, name: base, context };
|
|
632
|
+
}
|
|
633
|
+
function words(variant) {
|
|
634
|
+
return variant.split("-").filter(Boolean).map(capitalize);
|
|
635
|
+
}
|
|
636
|
+
/** Newest generation first; within one, the family with the highest price first. */
|
|
637
|
+
function compareModelIds(a, b, prices) {
|
|
638
|
+
if (a.series !== b.series) {
|
|
639
|
+
return a.series - b.series;
|
|
640
|
+
}
|
|
641
|
+
for (let i = 0; i < Math.max(a.version.length, b.version.length); i += 1) {
|
|
642
|
+
const diff = (b.version[i] ?? 0) - (a.version[i] ?? 0);
|
|
643
|
+
if (diff !== 0) {
|
|
644
|
+
return diff;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return (prices.get(b.family) ?? 0) - (prices.get(a.family) ?? 0) || Number(!!a.context) - Number(!!b.context);
|
|
648
|
+
}
|
|
649
|
+
/** Each family's highest output price in the catalog: Fable before Opus before Sonnet before Haiku. */
|
|
650
|
+
function familyPrices(backend, catalog) {
|
|
651
|
+
const prices = new Map();
|
|
652
|
+
for (const [id, model] of Object.entries(catalog)) {
|
|
653
|
+
const price = model.cost?.output;
|
|
654
|
+
if (typeof price === "number") {
|
|
655
|
+
const { family } = parseModelId(backend, id);
|
|
656
|
+
prices.set(family, Math.max(prices.get(family) ?? 0, price));
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
return prices;
|
|
660
|
+
}
|
|
661
|
+
/** The CLI's display name for the model ("GPT-6.2-Sol" reads "GPT-6.2 Sol"), or one read from the id. */
|
|
662
|
+
function modelLabel(backend, id, parsed, listed) {
|
|
663
|
+
const own = listed.get(id.replace(CONTEXT_SUFFIX, ""))?.name?.trim();
|
|
664
|
+
const name = own ? (backend === "codex" ? own.replace(/^(GPT-\d+(?:\.\d+)?)-/i, "$1 ") : own) : parsed.name;
|
|
665
|
+
return withContext(name, id);
|
|
666
|
+
}
|
|
667
|
+
/** "Opus 5.5" of "claude-opus-5-5[1m]" reads "Opus 5.5 · 1M". */
|
|
668
|
+
function withContext(name, id) {
|
|
669
|
+
const suffix = CONTEXT_SUFFIX.exec(id);
|
|
670
|
+
return suffix ? `${name} · ${suffix[1]}${suffix[2].toUpperCase()}` : name;
|
|
671
|
+
}
|
|
672
|
+
/** The levels both the model's CLI lists and the dashboard passes; the dashboard refuses any other. */
|
|
673
|
+
function modelEfforts(backend, id, model, listed) {
|
|
674
|
+
// Claude Code's levels, kept in the catalog: the dashboard takes exactly these.
|
|
675
|
+
if (model?.efforts) {
|
|
676
|
+
return model.efforts;
|
|
677
|
+
}
|
|
678
|
+
if (!hasEffortSetting(backend, id, model)) {
|
|
679
|
+
return [];
|
|
680
|
+
}
|
|
681
|
+
return listed ? RUDDER_EFFORTS[backend].filter((level) => listed.efforts.includes(level)) : RUDDER_EFFORTS[backend];
|
|
682
|
+
}
|
|
683
|
+
/** native/src/models.rs model_supports_reasoning: the family rule, or the catalog's word. */
|
|
684
|
+
function hasEffortSetting(backend, id, model) {
|
|
685
|
+
if (model?.reasoning === true) {
|
|
686
|
+
return true;
|
|
687
|
+
}
|
|
688
|
+
if (backend === "claude") {
|
|
689
|
+
return /opus|sonnet|fable/.test(id) || (id.startsWith("claude-") && !id.includes("3-"));
|
|
690
|
+
}
|
|
691
|
+
return isGptTextModel(id) || id.includes("codex") || isOSeriesModel(id);
|
|
692
|
+
}
|
|
693
|
+
const CLAUDE_CODE_TIMEOUT_MS = 20_000;
|
|
694
|
+
/**
|
|
695
|
+
* Claude Code's own /model list for this account, with each alias's current
|
|
696
|
+
* model, display names and the effort levels each model takes. Each alias
|
|
697
|
+
* also lists the model it stands for. Empty when Claude Code is not installed.
|
|
698
|
+
*/
|
|
699
|
+
async function readClaudeCodeModels() {
|
|
700
|
+
const answer = await claudeCodeModelList();
|
|
701
|
+
const models = [];
|
|
702
|
+
for (const row of answer ?? []) {
|
|
703
|
+
// Claude Code's "default" is what Rudder's Default row starts.
|
|
704
|
+
if (!row.value || row.value === "default") {
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
const efforts = row.supportsEffort ? row.supportedEffortLevels ?? [] : [];
|
|
708
|
+
const alias = !row.value.startsWith("claude-");
|
|
709
|
+
models.push({ id: row.value, name: row.displayName, description: row.description, efforts, alias });
|
|
710
|
+
if (alias && row.resolvedModel?.startsWith("claude-")) {
|
|
711
|
+
models.push({ id: row.resolvedModel, name: row.displayName, description: row.description, efforts, alias: false });
|
|
712
|
+
}
|
|
664
713
|
}
|
|
665
|
-
|
|
714
|
+
return models;
|
|
715
|
+
}
|
|
716
|
+
/** Claude Code's headless `initialize` answer: its model list, or null when Claude Code is not installed. */
|
|
717
|
+
function claudeCodeModelList() {
|
|
718
|
+
const bin = process.env.RUDDER_CLAUDE_BIN?.trim() || "claude";
|
|
719
|
+
const args = [
|
|
720
|
+
"-p", "--input-format", "stream-json", "--output-format", "stream-json", "--verbose",
|
|
721
|
+
// It answers and exits: no hooks or MCP servers start, and no prompt is sent.
|
|
722
|
+
"--settings", JSON.stringify({ disableAllHooks: true }),
|
|
723
|
+
"--strict-mcp-config", "--mcp-config", JSON.stringify({ mcpServers: {} }),
|
|
724
|
+
];
|
|
725
|
+
const requestId = "rudder-models";
|
|
726
|
+
return new Promise((resolve, reject) => {
|
|
727
|
+
const child = spawn(bin, args, { cwd: os.homedir(), stdio: ["pipe", "pipe", "pipe"] });
|
|
728
|
+
let stdout = "";
|
|
729
|
+
let stderr = "";
|
|
730
|
+
let settled = false;
|
|
731
|
+
const finish = (error, models) => {
|
|
732
|
+
if (settled) {
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
settled = true;
|
|
736
|
+
clearTimeout(timer);
|
|
737
|
+
// It exits once its stdin closes; nothing here waits for that.
|
|
738
|
+
child.stdin.end();
|
|
739
|
+
child.stdout.destroy();
|
|
740
|
+
child.stderr.destroy();
|
|
741
|
+
child.unref();
|
|
742
|
+
if (error) {
|
|
743
|
+
child.kill("SIGKILL");
|
|
744
|
+
reject(error);
|
|
745
|
+
}
|
|
746
|
+
else {
|
|
747
|
+
resolve(models ?? null);
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
const timer = setTimeout(() => finish(new Error(`${bin} did not answer initialize within ${CLAUDE_CODE_TIMEOUT_MS / 1000}s`)), CLAUDE_CODE_TIMEOUT_MS);
|
|
751
|
+
child.on("error", (error) => {
|
|
752
|
+
finish(error.code === "ENOENT" ? null : new Error(`could not start ${bin}: ${error.message}`), null);
|
|
753
|
+
});
|
|
754
|
+
child.stdin.on("error", (error) => finish(new Error(`could not ask ${bin} for its models: ${error.message}`)));
|
|
755
|
+
child.stderr.on("data", (data) => { stderr += data; });
|
|
756
|
+
child.stdout.on("data", (data) => {
|
|
757
|
+
stdout += data;
|
|
758
|
+
let newline;
|
|
759
|
+
while ((newline = stdout.indexOf("\n")) >= 0) {
|
|
760
|
+
const line = stdout.slice(0, newline).trim();
|
|
761
|
+
stdout = stdout.slice(newline + 1);
|
|
762
|
+
if (!line.startsWith("{")) {
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
let message;
|
|
766
|
+
try {
|
|
767
|
+
message = JSON.parse(line);
|
|
768
|
+
}
|
|
769
|
+
catch {
|
|
770
|
+
finish(new Error(`${bin} wrote a line that is not JSON: ${line.slice(0, 120)}`));
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
if (message.type !== "control_response" || message.response?.request_id !== requestId) {
|
|
774
|
+
continue;
|
|
775
|
+
}
|
|
776
|
+
if (message.response.subtype !== "success") {
|
|
777
|
+
finish(new Error(`${bin} refused initialize: ${message.response.error || "no reason given"}`));
|
|
778
|
+
}
|
|
779
|
+
else if (!Array.isArray(message.response.response?.models)) {
|
|
780
|
+
finish(new Error(`${bin} answered initialize without its model list`));
|
|
781
|
+
}
|
|
782
|
+
else {
|
|
783
|
+
finish(null, message.response.response.models);
|
|
784
|
+
}
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
});
|
|
788
|
+
child.on("close", (code) => finish(new Error(`${bin} exited (${code}) before listing its models${stderr.trim() ? `: ${stderr.trim().split("\n")[0]}` : ""}`)));
|
|
789
|
+
child.stdin.write(`${JSON.stringify({ type: "control_request", request_id: requestId, request: { subtype: "initialize" } })}\n`);
|
|
790
|
+
});
|
|
666
791
|
}
|
|
667
792
|
//# sourceMappingURL=models.js.map
|