@prestyj/core 5.32.2 → 5.34.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/dist/{chunk-6I3APHDP.js → chunk-7IHCMEIY.js} +1237 -484
- package/dist/chunk-7IHCMEIY.js.map +1 -0
- package/dist/{chunk-W4NHU4UL.js → chunk-DVWS2KEW.js} +4 -2
- package/dist/chunk-DVWS2KEW.js.map +1 -0
- package/dist/index.cjs +1615 -480
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +301 -95
- package/dist/index.d.ts +301 -95
- package/dist/index.js +423 -28
- package/dist/index.js.map +1 -1
- package/dist/model-registry.cjs +299 -81
- package/dist/model-registry.cjs.map +1 -1
- package/dist/model-registry.d.cts +43 -5
- package/dist/model-registry.d.ts +43 -5
- package/dist/model-registry.js +12 -2
- package/dist/paths.cjs +3 -1
- package/dist/paths.cjs.map +1 -1
- package/dist/paths.d.cts +4 -0
- package/dist/paths.d.ts +4 -0
- package/dist/paths.js +1 -1
- package/package.json +16 -3
- package/dist/chunk-6I3APHDP.js.map +0 -1
- package/dist/chunk-W4NHU4UL.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -32,54 +32,78 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
AUTH_PROVIDERS: () => AUTH_PROVIDERS,
|
|
34
34
|
AuthStorage: () => AuthStorage,
|
|
35
|
+
CLAUDE_CODE_AUTH_KEY: () => CLAUDE_CODE_AUTH_KEY,
|
|
36
|
+
CLAUDE_CODE_AUTH_MARKER: () => CLAUDE_CODE_AUTH_MARKER,
|
|
37
|
+
CLAUDE_CODE_MANIFEST: () => CLAUDE_CODE_MANIFEST,
|
|
35
38
|
DEFAULT_LOCAL_ENDPOINTS: () => DEFAULT_LOCAL_ENDPOINTS,
|
|
36
39
|
DEFAULT_MAX_VIDEO_BYTES: () => DEFAULT_MAX_VIDEO_BYTES,
|
|
37
40
|
FALLBACK_CONTEXT_WINDOW: () => FALLBACK_CONTEXT_WINDOW,
|
|
38
41
|
GEMINI_API_KEY: () => GEMINI_API_KEY,
|
|
39
42
|
GEMINI_API_KEY_BASE_URL: () => GEMINI_API_KEY_BASE_URL,
|
|
43
|
+
HIDDEN_PROVIDERS: () => HIDDEN_PROVIDERS,
|
|
40
44
|
LOCAL_API_KEY_PLACEHOLDER: () => LOCAL_API_KEY_PLACEHOLDER,
|
|
41
45
|
LOCAL_AUTH_KEY_PREFIX: () => LOCAL_AUTH_KEY_PREFIX,
|
|
46
|
+
MINIMAX_CN_BASE_URL: () => MINIMAX_CN_BASE_URL,
|
|
47
|
+
MINIMAX_GLOBAL_BASE_URL: () => MINIMAX_GLOBAL_BASE_URL,
|
|
42
48
|
MODELS: () => MODELS,
|
|
43
49
|
MOONSHOT_OAUTH_KEY: () => MOONSHOT_OAUTH_KEY,
|
|
44
50
|
NotLoggedInError: () => NotLoggedInError,
|
|
51
|
+
OPENCODE_CATALOG_URLS: () => OPENCODE_CATALOG_URLS,
|
|
52
|
+
OPENCODE_PROVIDERS: () => OPENCODE_PROVIDERS,
|
|
53
|
+
OPENROUTER_DEFAULT_BASE_URL: () => OPENROUTER_DEFAULT_BASE_URL,
|
|
45
54
|
PLAN_MODE_THINKING_CAP: () => PLAN_MODE_THINKING_CAP,
|
|
46
55
|
SubscriptionUsageError: () => SubscriptionUsageError,
|
|
47
56
|
TelegramBot: () => TelegramBot,
|
|
48
57
|
XAI_OAUTH_KEY: () => XAI_OAUTH_KEY,
|
|
49
58
|
XIAOMI_CREDITS_KEY: () => XIAOMI_CREDITS_KEY,
|
|
59
|
+
XIAOMI_TOKEN_PLAN_BASE_URLS: () => XIAOMI_TOKEN_PLAN_BASE_URLS,
|
|
50
60
|
authPriorityNote: () => authPriorityNote,
|
|
51
61
|
clampThinkingForPlanMode: () => clampThinkingForPlanMode,
|
|
62
|
+
claudeCodeAuthStatus: () => claudeCodeAuthStatus,
|
|
63
|
+
claudeCodeBinaryPath: () => claudeCodeBinaryPath,
|
|
64
|
+
claudeCodeCallbackUrl: () => claudeCodeCallbackUrl,
|
|
65
|
+
claudeCodeConfigDir: () => claudeCodeConfigDir,
|
|
66
|
+
claudeCodeEnv: () => claudeCodeEnv,
|
|
67
|
+
claudeCodeHome: () => claudeCodeHome,
|
|
68
|
+
claudeCodePlatformKey: () => claudeCodePlatformKey,
|
|
69
|
+
clearClaudeCodeUsage: () => clearClaudeCodeUsage,
|
|
52
70
|
clearLocalDiscoveryCache: () => clearLocalDiscoveryCache,
|
|
53
71
|
clearRuntimeModels: () => clearRuntimeModels,
|
|
54
72
|
closeLogger: () => closeLogger,
|
|
55
|
-
compareClaudeCodeVersions: () => compareClaudeCodeVersions,
|
|
56
73
|
createAutoUpdater: () => createAutoUpdater,
|
|
57
74
|
decodeOggOpus: () => decodeOggOpus,
|
|
58
75
|
describeAuthMethods: () => describeAuthMethods,
|
|
76
|
+
detectMiniMaxBaseUrl: () => detectMiniMaxBaseUrl,
|
|
77
|
+
detectXiaomiTokenPlanBaseUrl: () => detectXiaomiTokenPlanBaseUrl,
|
|
59
78
|
discoverLocalModels: () => discoverLocalModels,
|
|
60
79
|
downmixToMono: () => downmixToMono,
|
|
61
80
|
dualAuthProvider: () => dualAuthProvider,
|
|
62
81
|
dualAuthProviderByOAuthKey: () => dualAuthProviderByOAuthKey,
|
|
63
82
|
endpointRoot: () => endpointRoot,
|
|
83
|
+
ensureClaudeCodeBinary: () => ensureClaudeCodeBinary,
|
|
64
84
|
fetchSubscriptionUsage: () => fetchSubscriptionUsage,
|
|
65
85
|
findProbedModel: () => findProbedModel,
|
|
86
|
+
formatClaudeCodeInstallProgress: () => formatClaudeCodeInstallProgress,
|
|
66
87
|
formatLocalModelId: () => formatLocalModelId,
|
|
88
|
+
formatOpenCodeModelId: () => formatOpenCodeModelId,
|
|
67
89
|
generatePKCE: () => generatePKCE,
|
|
68
90
|
getAllModels: () => getAllModels,
|
|
69
91
|
getAppPaths: () => getAppPaths,
|
|
70
92
|
getAuthProvider: () => getAuthProvider,
|
|
71
93
|
getAuthStorageKey: () => getAuthStorageKey,
|
|
72
94
|
getAuthStorageKeys: () => getAuthStorageKeys,
|
|
73
|
-
getClaudeCliUserAgent: () => getClaudeCliUserAgent,
|
|
74
|
-
getClaudeCodeVersion: () => getClaudeCodeVersion,
|
|
95
|
+
getClaudeCliUserAgent: () => import_ai.getClaudeCliUserAgent,
|
|
96
|
+
getClaudeCodeVersion: () => import_ai.getClaudeCodeVersion,
|
|
75
97
|
getContextWindow: () => getContextWindow,
|
|
76
98
|
getDefaultModel: () => getDefaultModel,
|
|
77
99
|
getDefaultThinkingLevel: () => getDefaultThinkingLevel,
|
|
100
|
+
getListedModels: () => getListedModels,
|
|
78
101
|
getLowestThinkingLevel: () => getLowestThinkingLevel,
|
|
79
102
|
getMaxThinkingLevel: () => getMaxThinkingLevel,
|
|
80
103
|
getModel: () => getModel,
|
|
81
104
|
getModelsForProvider: () => getModelsForProvider,
|
|
82
105
|
getNextThinkingLevel: () => getNextThinkingLevel,
|
|
106
|
+
getProviderCatalog: () => getProviderCatalog,
|
|
83
107
|
getSessionId: () => getSessionId,
|
|
84
108
|
getSummaryModel: () => getSummaryModel,
|
|
85
109
|
getSupportedThinkingLevels: () => getSupportedThinkingLevels,
|
|
@@ -87,8 +111,11 @@ __export(index_exports, {
|
|
|
87
111
|
getVideoByteLimit: () => getVideoByteLimit,
|
|
88
112
|
grokCliBaseUrl: () => grokCliBaseUrl,
|
|
89
113
|
grokCliHeaders: () => grokCliHeaders,
|
|
114
|
+
isClaudeCodeAuthMarker: () => isClaudeCodeAuthMarker,
|
|
90
115
|
isGrokCliEndpoint: () => isGrokCliEndpoint,
|
|
116
|
+
isHiddenProvider: () => isHiddenProvider,
|
|
91
117
|
isKimiCodingEndpoint: () => isKimiCodingEndpoint,
|
|
118
|
+
isLegacyClaudeOAuth: () => isLegacyClaudeOAuth,
|
|
92
119
|
isLocalModelId: () => isLocalModelId,
|
|
93
120
|
isLoggerOpen: () => isLoggerOpen,
|
|
94
121
|
isModelLoaded: () => isModelLoaded,
|
|
@@ -97,19 +124,29 @@ __export(index_exports, {
|
|
|
97
124
|
kimiCodeBaseUrl: () => kimiCodeBaseUrl,
|
|
98
125
|
kimiCodingHeaders: () => kimiCodingHeaders,
|
|
99
126
|
localAuthStorageKey: () => localAuthStorageKey,
|
|
127
|
+
localModelShortName: () => localModelShortName,
|
|
100
128
|
log: () => log,
|
|
101
129
|
loginAnthropic: () => loginAnthropic,
|
|
130
|
+
loginClaudeCode: () => loginClaudeCode,
|
|
102
131
|
loginGemini: () => loginGemini,
|
|
103
132
|
loginKimi: () => loginKimi,
|
|
104
133
|
loginOpenAI: () => loginOpenAI,
|
|
105
134
|
loginXai: () => loginXai,
|
|
135
|
+
logoutClaudeCode: () => logoutClaudeCode,
|
|
136
|
+
mergeClaudeCodeRateLimit: () => mergeClaudeCodeRateLimit,
|
|
106
137
|
oauthStorageKey: () => oauthStorageKey,
|
|
138
|
+
ollamaServedContext: () => ollamaServedContext,
|
|
107
139
|
openLog: () => openLog,
|
|
108
140
|
parseLocalModelId: () => parseLocalModelId,
|
|
141
|
+
parseOpenCodeCatalog: () => parseOpenCodeCatalog,
|
|
142
|
+
parseOpenRouterCatalog: () => parseOpenRouterCatalog,
|
|
143
|
+
pendingClaudeCodeVersionRefresh: () => import_ai.pendingClaudeCodeVersionRefresh,
|
|
144
|
+
pointScale: () => pointScale,
|
|
109
145
|
probeEndpoint: () => probeEndpoint,
|
|
110
146
|
providerStorageKeys: () => providerStorageKeys,
|
|
147
|
+
readClaudeCodeUsage: () => readClaudeCodeUsage,
|
|
111
148
|
readStoredBaseUrlSync: () => readStoredBaseUrlSync,
|
|
112
|
-
|
|
149
|
+
recordClaudeCodeRateLimit: () => recordClaudeCodeRateLimit,
|
|
113
150
|
refreshAnthropicToken: () => refreshAnthropicToken,
|
|
114
151
|
refreshGeminiToken: () => refreshGeminiToken,
|
|
115
152
|
refreshKimiToken: () => refreshKimiToken,
|
|
@@ -118,7 +155,11 @@ __export(index_exports, {
|
|
|
118
155
|
registerLogCleanup: () => registerLogCleanup,
|
|
119
156
|
registerRuntimeModels: () => registerRuntimeModels,
|
|
120
157
|
resample: () => resample,
|
|
158
|
+
resolveClaudeCodeBinary: () => resolveClaudeCodeBinary,
|
|
121
159
|
setProgressCallback: () => setProgressCallback,
|
|
160
|
+
setProviderCatalog: () => setProviderCatalog,
|
|
161
|
+
signInWithClaudeCode: () => signInWithClaudeCode,
|
|
162
|
+
signOutOfClaudeCode: () => signOutOfClaudeCode,
|
|
122
163
|
toModelInfo: () => toModelInfo,
|
|
123
164
|
transcribeVoice: () => transcribeVoice,
|
|
124
165
|
usesOpenAICodexTransport: () => usesOpenAICodexTransport,
|
|
@@ -157,7 +198,9 @@ function getAppPaths() {
|
|
|
157
198
|
agentsDir: import_node_path.default.join(agentDir, "agents"),
|
|
158
199
|
progressFile: import_node_path.default.join(agentDir, "progress.json"),
|
|
159
200
|
progressBackupFile: import_node_path.default.join(agentDir, "progress.backup.json"),
|
|
160
|
-
trophiesFile: import_node_path.default.join(agentDir, "trophies.json")
|
|
201
|
+
trophiesFile: import_node_path.default.join(agentDir, "trophies.json"),
|
|
202
|
+
claudeCodeDir: import_node_path.default.join(agentDir, "claude-code"),
|
|
203
|
+
claudeCodeConfigDir: import_node_path.default.join(agentDir, "claude-code", "config")
|
|
161
204
|
};
|
|
162
205
|
}
|
|
163
206
|
|
|
@@ -382,12 +425,12 @@ async function refreshKimiToken(refreshToken) {
|
|
|
382
425
|
}
|
|
383
426
|
|
|
384
427
|
// src/auth-storage.ts
|
|
385
|
-
var
|
|
386
|
-
var
|
|
387
|
-
var
|
|
428
|
+
var import_promises5 = __toESM(require("fs/promises"), 1);
|
|
429
|
+
var import_node_fs5 = require("fs");
|
|
430
|
+
var import_node_crypto7 = __toESM(require("crypto"), 1);
|
|
388
431
|
|
|
389
432
|
// src/oauth/anthropic.ts
|
|
390
|
-
var
|
|
433
|
+
var import_node_crypto2 = __toESM(require("crypto"), 1);
|
|
391
434
|
|
|
392
435
|
// src/oauth/pkce.ts
|
|
393
436
|
function base64urlEncode(bytes) {
|
|
@@ -408,347 +451,7 @@ async function generatePKCE() {
|
|
|
408
451
|
}
|
|
409
452
|
|
|
410
453
|
// src/claude-code-version.ts
|
|
411
|
-
var import_promises = __toESM(require("fs/promises"), 1);
|
|
412
|
-
var import_node_fs3 = require("fs");
|
|
413
|
-
var import_node_path4 = __toESM(require("path"), 1);
|
|
414
|
-
|
|
415
|
-
// src/logger.ts
|
|
416
|
-
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
417
|
-
var import_node_path3 = __toESM(require("path"), 1);
|
|
418
|
-
var import_node_crypto2 = require("crypto");
|
|
419
454
|
var import_ai = require("@prestyj/ai");
|
|
420
|
-
var MAX_BYTES = 10 * 1024 * 1024;
|
|
421
|
-
var MIN_HEADROOM_BYTES = 64 * 1024;
|
|
422
|
-
var fd = null;
|
|
423
|
-
var logPath = null;
|
|
424
|
-
var fileBytes = 0;
|
|
425
|
-
var processBytes = 0;
|
|
426
|
-
var rotationFailed = false;
|
|
427
|
-
var capped = false;
|
|
428
|
-
var sessionId = "";
|
|
429
|
-
var appName = "app";
|
|
430
|
-
var cleanups = [];
|
|
431
|
-
var exactSecrets = [];
|
|
432
|
-
function rotateIfNeeded(filePath, force = false) {
|
|
433
|
-
try {
|
|
434
|
-
const st = import_node_fs2.default.statSync(filePath);
|
|
435
|
-
if (!force && st.size <= MAX_BYTES - MIN_HEADROOM_BYTES) return;
|
|
436
|
-
const rotated = `${filePath}.1`;
|
|
437
|
-
try {
|
|
438
|
-
import_node_fs2.default.unlinkSync(rotated);
|
|
439
|
-
} catch {
|
|
440
|
-
}
|
|
441
|
-
import_node_fs2.default.renameSync(filePath, rotated);
|
|
442
|
-
} catch {
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
function rotateOpenLog() {
|
|
446
|
-
if (fd === null || logPath === null) return false;
|
|
447
|
-
const sizeBefore = fileBytes;
|
|
448
|
-
try {
|
|
449
|
-
import_node_fs2.default.closeSync(fd);
|
|
450
|
-
} catch {
|
|
451
|
-
}
|
|
452
|
-
fd = null;
|
|
453
|
-
rotateIfNeeded(logPath, true);
|
|
454
|
-
try {
|
|
455
|
-
fd = import_node_fs2.default.openSync(logPath, "a");
|
|
456
|
-
fileBytes = import_node_fs2.default.fstatSync(fd).size;
|
|
457
|
-
} catch {
|
|
458
|
-
if (fd !== null) {
|
|
459
|
-
try {
|
|
460
|
-
import_node_fs2.default.closeSync(fd);
|
|
461
|
-
} catch {
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
fd = null;
|
|
465
|
-
capped = true;
|
|
466
|
-
return false;
|
|
467
|
-
}
|
|
468
|
-
if (fileBytes >= sizeBefore) rotationFailed = true;
|
|
469
|
-
return true;
|
|
470
|
-
}
|
|
471
|
-
function openLog(filePath, name) {
|
|
472
|
-
if (fd !== null || capped) return false;
|
|
473
|
-
appName = name;
|
|
474
|
-
exactSecrets = (0, import_ai.environmentSecrets)(process.env);
|
|
475
|
-
try {
|
|
476
|
-
import_node_fs2.default.mkdirSync(import_node_path3.default.dirname(filePath), { recursive: true, mode: 448 });
|
|
477
|
-
} catch {
|
|
478
|
-
}
|
|
479
|
-
rotateIfNeeded(filePath);
|
|
480
|
-
try {
|
|
481
|
-
fd = import_node_fs2.default.openSync(filePath, "a");
|
|
482
|
-
} catch {
|
|
483
|
-
fd = null;
|
|
484
|
-
fileBytes = 0;
|
|
485
|
-
return false;
|
|
486
|
-
}
|
|
487
|
-
try {
|
|
488
|
-
fileBytes = import_node_fs2.default.fstatSync(fd).size;
|
|
489
|
-
} catch {
|
|
490
|
-
try {
|
|
491
|
-
import_node_fs2.default.closeSync(fd);
|
|
492
|
-
} catch {
|
|
493
|
-
}
|
|
494
|
-
fd = null;
|
|
495
|
-
fileBytes = 0;
|
|
496
|
-
return false;
|
|
497
|
-
}
|
|
498
|
-
logPath = filePath;
|
|
499
|
-
processBytes = 0;
|
|
500
|
-
rotationFailed = false;
|
|
501
|
-
sessionId = (0, import_node_crypto2.randomBytes)(4).toString("hex");
|
|
502
|
-
try {
|
|
503
|
-
if (fileBytes < MAX_BYTES) {
|
|
504
|
-
const written = import_node_fs2.default.writeSync(fd, "\n");
|
|
505
|
-
fileBytes += written;
|
|
506
|
-
processBytes += written;
|
|
507
|
-
}
|
|
508
|
-
} catch {
|
|
509
|
-
}
|
|
510
|
-
return true;
|
|
511
|
-
}
|
|
512
|
-
function getSessionId() {
|
|
513
|
-
return sessionId;
|
|
514
|
-
}
|
|
515
|
-
function isLoggerOpen() {
|
|
516
|
-
return fd !== null;
|
|
517
|
-
}
|
|
518
|
-
function log(level, category, message, data) {
|
|
519
|
-
if (fd === null) return;
|
|
520
|
-
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
521
|
-
const safeMessage = (0, import_ai.redactText)(message, { secrets: exactSecrets });
|
|
522
|
-
let line = `[${ts}] [sid=${sessionId}] [${level}] [${category}] ${safeMessage}`;
|
|
523
|
-
if (data) {
|
|
524
|
-
const safeData = (0, import_ai.redactValue)(data, { secrets: exactSecrets });
|
|
525
|
-
const pairs = Object.entries(safeData).map(([k, v]) => {
|
|
526
|
-
if (typeof v === "string") return `${k}=${v}`;
|
|
527
|
-
if (typeof v === "bigint") return `${k}=${String(v)}`;
|
|
528
|
-
return `${k}=${JSON.stringify(v)}`;
|
|
529
|
-
}).join(" ");
|
|
530
|
-
if (pairs) line += ` ${pairs}`;
|
|
531
|
-
}
|
|
532
|
-
line += "\n";
|
|
533
|
-
const lineBytes = Buffer.byteLength(line);
|
|
534
|
-
if (processBytes + lineBytes > MAX_BYTES) {
|
|
535
|
-
const capLine = `[${ts}] [sid=${sessionId}] [WARN] [logger] Log cap reached; file logging disabled until restart
|
|
536
|
-
`;
|
|
537
|
-
try {
|
|
538
|
-
if (fileBytes + Buffer.byteLength(capLine) <= MAX_BYTES) {
|
|
539
|
-
fileBytes += import_node_fs2.default.writeSync(fd, capLine);
|
|
540
|
-
}
|
|
541
|
-
import_node_fs2.default.closeSync(fd);
|
|
542
|
-
} catch {
|
|
543
|
-
}
|
|
544
|
-
fd = null;
|
|
545
|
-
capped = true;
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
if (fileBytes + lineBytes > MAX_BYTES && !rotationFailed && !rotateOpenLog()) return;
|
|
549
|
-
if (fd === null) return;
|
|
550
|
-
try {
|
|
551
|
-
const written = import_node_fs2.default.writeSync(fd, line);
|
|
552
|
-
fileBytes += written;
|
|
553
|
-
processBytes += written;
|
|
554
|
-
} catch {
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
function registerLogCleanup(fn) {
|
|
558
|
-
cleanups.push(fn);
|
|
559
|
-
}
|
|
560
|
-
function closeLogger(opts) {
|
|
561
|
-
if (fd !== null) {
|
|
562
|
-
if (opts?.shutdownLine !== false) log("INFO", "shutdown", `${appName} shutting down`);
|
|
563
|
-
try {
|
|
564
|
-
if (fd !== null) import_node_fs2.default.closeSync(fd);
|
|
565
|
-
} catch {
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
fd = null;
|
|
569
|
-
logPath = null;
|
|
570
|
-
fileBytes = 0;
|
|
571
|
-
processBytes = 0;
|
|
572
|
-
rotationFailed = false;
|
|
573
|
-
capped = false;
|
|
574
|
-
exactSecrets = [];
|
|
575
|
-
for (const unsub of cleanups) unsub();
|
|
576
|
-
cleanups = [];
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
// src/claude-code-version.ts
|
|
580
|
-
var NPM_LATEST_URL = "https://registry.npmjs.org/@anthropic-ai/claude-code/latest";
|
|
581
|
-
var CACHE_FRESH_MS = 60 * 60 * 1e3;
|
|
582
|
-
var CACHE_HARD_MS = 24 * 60 * 60 * 1e3;
|
|
583
|
-
var FETCH_TIMEOUT_MS = 3e3;
|
|
584
|
-
var FALLBACK_VERSION = "2.1.280";
|
|
585
|
-
var memoryCache = null;
|
|
586
|
-
var inflight = null;
|
|
587
|
-
var backgroundRefresh = null;
|
|
588
|
-
var versionFloor = null;
|
|
589
|
-
function cachePath() {
|
|
590
|
-
return import_node_path4.default.join(getAppPaths().agentDir, "claude-code-version.json");
|
|
591
|
-
}
|
|
592
|
-
function compareClaudeCodeVersions(a, b) {
|
|
593
|
-
const parse = (v) => v.split(".").map((part) => Number.parseInt(part, 10)).map((n) => Number.isFinite(n) ? n : 0);
|
|
594
|
-
const left = parse(a);
|
|
595
|
-
const right = parse(b);
|
|
596
|
-
for (let i = 0; i < Math.max(left.length, right.length); i += 1) {
|
|
597
|
-
const diff = (left[i] ?? 0) - (right[i] ?? 0);
|
|
598
|
-
if (diff !== 0) return diff;
|
|
599
|
-
}
|
|
600
|
-
return 0;
|
|
601
|
-
}
|
|
602
|
-
function applyFloor(version) {
|
|
603
|
-
if (!versionFloor) return version;
|
|
604
|
-
return compareClaudeCodeVersions(versionFloor, version) > 0 ? versionFloor : version;
|
|
605
|
-
}
|
|
606
|
-
async function readDiskCache() {
|
|
607
|
-
try {
|
|
608
|
-
const raw = await import_promises.default.readFile(cachePath(), "utf-8");
|
|
609
|
-
const parsed = JSON.parse(raw);
|
|
610
|
-
if (typeof parsed.version === "string" && typeof parsed.fetchedAt === "number") {
|
|
611
|
-
if (typeof parsed.minVersion === "string") {
|
|
612
|
-
if (!versionFloor || compareClaudeCodeVersions(parsed.minVersion, versionFloor) > 0) {
|
|
613
|
-
versionFloor = parsed.minVersion;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
return parsed;
|
|
617
|
-
}
|
|
618
|
-
return null;
|
|
619
|
-
} catch {
|
|
620
|
-
return null;
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
async function writeDiskCache(data) {
|
|
624
|
-
try {
|
|
625
|
-
await import_promises.default.mkdir(getAppPaths().agentDir, { recursive: true, mode: 448 });
|
|
626
|
-
await import_promises.default.writeFile(
|
|
627
|
-
cachePath(),
|
|
628
|
-
JSON.stringify({ ...data, ...versionFloor ? { minVersion: versionFloor } : {} }),
|
|
629
|
-
{ mode: 384 }
|
|
630
|
-
);
|
|
631
|
-
} catch (err) {
|
|
632
|
-
log(
|
|
633
|
-
"WARN",
|
|
634
|
-
"claude-code-version",
|
|
635
|
-
`Failed to write cache: ${err instanceof Error ? err.message : String(err)}`
|
|
636
|
-
);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
async function fetchLatest() {
|
|
640
|
-
const controller = new AbortController();
|
|
641
|
-
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
642
|
-
try {
|
|
643
|
-
const response = await fetch(NPM_LATEST_URL, { signal: controller.signal });
|
|
644
|
-
if (!response.ok) return null;
|
|
645
|
-
const data = await response.json();
|
|
646
|
-
if (typeof data.version === "string" && /^\d/.test(data.version)) {
|
|
647
|
-
return data.version;
|
|
648
|
-
}
|
|
649
|
-
return null;
|
|
650
|
-
} catch {
|
|
651
|
-
return null;
|
|
652
|
-
} finally {
|
|
653
|
-
clearTimeout(timer);
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
function refreshInBackground() {
|
|
657
|
-
if (backgroundRefresh) return;
|
|
658
|
-
backgroundRefresh = (async () => {
|
|
659
|
-
const fetched = await fetchLatest();
|
|
660
|
-
if (fetched) {
|
|
661
|
-
await writeDiskCache({ version: fetched, fetchedAt: Date.now() });
|
|
662
|
-
memoryCache = { version: applyFloor(fetched), expiresAt: Date.now() + CACHE_FRESH_MS };
|
|
663
|
-
}
|
|
664
|
-
})().catch(() => {
|
|
665
|
-
}).finally(() => {
|
|
666
|
-
backgroundRefresh = null;
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
async function getClaudeCodeVersion() {
|
|
670
|
-
if (memoryCache && Date.now() < memoryCache.expiresAt) {
|
|
671
|
-
return memoryCache.version;
|
|
672
|
-
}
|
|
673
|
-
if (inflight) return inflight;
|
|
674
|
-
inflight = (async () => {
|
|
675
|
-
const disk = await readDiskCache();
|
|
676
|
-
const age = disk ? Date.now() - disk.fetchedAt : Infinity;
|
|
677
|
-
if (disk && age < CACHE_FRESH_MS) {
|
|
678
|
-
const version = applyFloor(disk.version);
|
|
679
|
-
memoryCache = { version, expiresAt: Date.now() + CACHE_FRESH_MS };
|
|
680
|
-
return version;
|
|
681
|
-
}
|
|
682
|
-
if (disk && age < CACHE_HARD_MS) {
|
|
683
|
-
const version = applyFloor(disk.version);
|
|
684
|
-
memoryCache = { version, expiresAt: Date.now() + 5 * 60 * 1e3 };
|
|
685
|
-
refreshInBackground();
|
|
686
|
-
return version;
|
|
687
|
-
}
|
|
688
|
-
const fetched = await fetchLatest();
|
|
689
|
-
if (fetched) {
|
|
690
|
-
await writeDiskCache({ version: fetched, fetchedAt: Date.now() });
|
|
691
|
-
const version = applyFloor(fetched);
|
|
692
|
-
memoryCache = { version, expiresAt: Date.now() + CACHE_FRESH_MS };
|
|
693
|
-
return version;
|
|
694
|
-
}
|
|
695
|
-
const resolved = applyFloor(disk?.version ?? FALLBACK_VERSION);
|
|
696
|
-
memoryCache = { version: resolved, expiresAt: Date.now() + 5 * 60 * 1e3 };
|
|
697
|
-
log(
|
|
698
|
-
"WARN",
|
|
699
|
-
"claude-code-version",
|
|
700
|
-
`Failed to fetch latest Claude Code version; using ${resolved}`
|
|
701
|
-
);
|
|
702
|
-
return resolved;
|
|
703
|
-
})();
|
|
704
|
-
try {
|
|
705
|
-
return await inflight;
|
|
706
|
-
} finally {
|
|
707
|
-
inflight = null;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
var REQUIRED_VERSION_PATTERN = /version\s+(\d+(?:\.\d+)+)\s+or\s+newer\s+is\s+required/i;
|
|
711
|
-
function recordRequiredClaudeCodeVersion(message) {
|
|
712
|
-
const required = REQUIRED_VERSION_PATTERN.exec(message ?? "")?.[1];
|
|
713
|
-
if (!required) return null;
|
|
714
|
-
if (versionFloor && compareClaudeCodeVersions(required, versionFloor) <= 0) return versionFloor;
|
|
715
|
-
versionFloor = required;
|
|
716
|
-
memoryCache = null;
|
|
717
|
-
log(
|
|
718
|
-
"WARN",
|
|
719
|
-
"claude-code-version",
|
|
720
|
-
`Provider requires Claude Code >= ${required}; pinning User-Agent floor`
|
|
721
|
-
);
|
|
722
|
-
try {
|
|
723
|
-
const dir = getAppPaths().agentDir;
|
|
724
|
-
(0, import_node_fs3.mkdirSync)(dir, { recursive: true, mode: 448 });
|
|
725
|
-
let existing = {};
|
|
726
|
-
try {
|
|
727
|
-
existing = JSON.parse((0, import_node_fs3.readFileSync)(cachePath(), "utf-8"));
|
|
728
|
-
} catch {
|
|
729
|
-
}
|
|
730
|
-
(0, import_node_fs3.writeFileSync)(
|
|
731
|
-
cachePath(),
|
|
732
|
-
JSON.stringify({
|
|
733
|
-
version: existing.version ?? required,
|
|
734
|
-
fetchedAt: existing.fetchedAt ?? 0,
|
|
735
|
-
minVersion: required
|
|
736
|
-
}),
|
|
737
|
-
{ mode: 384 }
|
|
738
|
-
);
|
|
739
|
-
} catch (err) {
|
|
740
|
-
log(
|
|
741
|
-
"WARN",
|
|
742
|
-
"claude-code-version",
|
|
743
|
-
`Failed to persist required version: ${err instanceof Error ? err.message : String(err)}`
|
|
744
|
-
);
|
|
745
|
-
}
|
|
746
|
-
return required;
|
|
747
|
-
}
|
|
748
|
-
async function getClaudeCliUserAgent() {
|
|
749
|
-
const version = await getClaudeCodeVersion();
|
|
750
|
-
return `claude-cli/${version} (external, cli)`;
|
|
751
|
-
}
|
|
752
455
|
|
|
753
456
|
// src/oauth/anthropic.ts
|
|
754
457
|
var CLIENT_ID2 = atob("OWQxYzI1MGEtZTYxYi00NGQ5LTg4ZWQtNTk0NGQxOTYyZjVl");
|
|
@@ -763,7 +466,7 @@ async function postTokenRequest(body, label) {
|
|
|
763
466
|
const encoded = JSON.stringify(body);
|
|
764
467
|
const headers = {
|
|
765
468
|
"Content-Type": "application/json",
|
|
766
|
-
"User-Agent": await getClaudeCliUserAgent(),
|
|
469
|
+
"User-Agent": await (0, import_ai.getClaudeCliUserAgent)(),
|
|
767
470
|
"anthropic-beta": "oauth-2025-04-20"
|
|
768
471
|
};
|
|
769
472
|
let lastError = null;
|
|
@@ -800,7 +503,7 @@ function toCredentials(data) {
|
|
|
800
503
|
}
|
|
801
504
|
async function loginAnthropic(callbacks) {
|
|
802
505
|
const { verifier, challenge } = await generatePKCE();
|
|
803
|
-
const state =
|
|
506
|
+
const state = import_node_crypto2.default.randomBytes(16).toString("hex");
|
|
804
507
|
const params = new URLSearchParams({
|
|
805
508
|
code: "true",
|
|
806
509
|
client_id: CLIENT_ID2,
|
|
@@ -848,7 +551,7 @@ async function refreshAnthropicToken(refreshToken) {
|
|
|
848
551
|
|
|
849
552
|
// src/oauth/openai.ts
|
|
850
553
|
var import_node_http = __toESM(require("http"), 1);
|
|
851
|
-
var
|
|
554
|
+
var import_node_crypto3 = __toESM(require("crypto"), 1);
|
|
852
555
|
var CLIENT_ID3 = "app_EMoamEEZ73f0CkXaXp7hrann";
|
|
853
556
|
var AUTHORIZE_URL2 = "https://auth.openai.com/oauth/authorize";
|
|
854
557
|
var TOKEN_URL = "https://auth.openai.com/oauth/token";
|
|
@@ -860,7 +563,7 @@ var MAX_PASTE_ATTEMPTS = 3;
|
|
|
860
563
|
var MIN_RAW_CODE_LENGTH = 10;
|
|
861
564
|
async function loginOpenAI(callbacks) {
|
|
862
565
|
const { verifier, challenge } = await generatePKCE();
|
|
863
|
-
const state =
|
|
566
|
+
const state = import_node_crypto3.default.randomBytes(16).toString("hex");
|
|
864
567
|
const url = new URL(AUTHORIZE_URL2);
|
|
865
568
|
url.searchParams.set("response_type", "code");
|
|
866
569
|
url.searchParams.set("client_id", CLIENT_ID3);
|
|
@@ -1068,7 +771,7 @@ async function refreshOpenAIToken(refreshToken) {
|
|
|
1068
771
|
|
|
1069
772
|
// src/oauth/gemini.ts
|
|
1070
773
|
var import_node_http2 = __toESM(require("http"), 1);
|
|
1071
|
-
var
|
|
774
|
+
var import_node_crypto4 = __toESM(require("crypto"), 1);
|
|
1072
775
|
var CLIENT_ID_ENV = "EZCODER_GEMINI_OAUTH_CLIENT_ID";
|
|
1073
776
|
var CLIENT_SECRET_ENV = "EZCODER_GEMINI_OAUTH_CLIENT_SECRET";
|
|
1074
777
|
var DEFAULT_CLIENT_ID = "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com";
|
|
@@ -1102,7 +805,7 @@ var CodeAssistHttpError = class extends Error {
|
|
|
1102
805
|
async function loginGemini(callbacks) {
|
|
1103
806
|
const { clientId: clientId2, clientSecret } = getGeminiOAuthClientCredentials();
|
|
1104
807
|
const { verifier, challenge } = await generatePKCE();
|
|
1105
|
-
const state =
|
|
808
|
+
const state = import_node_crypto4.default.randomBytes(32).toString("hex");
|
|
1106
809
|
const redirectUri = await getLoopbackRedirectUri();
|
|
1107
810
|
const url = new URL(AUTHORIZE_URL3);
|
|
1108
811
|
url.searchParams.set("response_type", "code");
|
|
@@ -1631,11 +1334,12 @@ async function refreshXaiToken(refreshToken) {
|
|
|
1631
1334
|
}
|
|
1632
1335
|
|
|
1633
1336
|
// src/file-lock.ts
|
|
1634
|
-
var
|
|
1635
|
-
var
|
|
1337
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
1338
|
+
var import_promises2 = require("timers/promises");
|
|
1636
1339
|
var STALE_TIMEOUT_MS = 1e4;
|
|
1637
1340
|
var RETRY_INTERVAL_MS = 50;
|
|
1638
1341
|
var MAX_WAIT_MS = 5e3;
|
|
1342
|
+
var PENDING_DELETE_CODES = /* @__PURE__ */ new Set(["EACCES", "EBUSY", "EPERM"]);
|
|
1639
1343
|
async function withFileLock(filePath, fn) {
|
|
1640
1344
|
const lockPath = filePath + ".lock";
|
|
1641
1345
|
await acquireLock(lockPath);
|
|
@@ -1647,49 +1351,839 @@ async function withFileLock(filePath, fn) {
|
|
|
1647
1351
|
}
|
|
1648
1352
|
async function acquireLock(lockPath) {
|
|
1649
1353
|
const startTime = Date.now();
|
|
1354
|
+
let refusedWithoutLock = 0;
|
|
1650
1355
|
while (true) {
|
|
1651
1356
|
try {
|
|
1652
1357
|
const info = { pid: process.pid, timestamp: Date.now() };
|
|
1653
|
-
await
|
|
1358
|
+
await import_promises.default.writeFile(lockPath, JSON.stringify(info), { flag: "wx" });
|
|
1654
1359
|
return;
|
|
1655
1360
|
} catch (err) {
|
|
1656
|
-
|
|
1361
|
+
const code = err.code;
|
|
1362
|
+
if (code !== "EEXIST") {
|
|
1363
|
+
if (process.platform !== "win32" || !code || !PENDING_DELETE_CODES.has(code)) throw err;
|
|
1364
|
+
const lockPresent = await lockFileExists(lockPath);
|
|
1365
|
+
if (!lockPresent && ++refusedWithoutLock > 3) throw err;
|
|
1366
|
+
if (Date.now() - startTime > MAX_WAIT_MS) throw err;
|
|
1367
|
+
await (0, import_promises2.setTimeout)(RETRY_INTERVAL_MS);
|
|
1368
|
+
continue;
|
|
1369
|
+
}
|
|
1657
1370
|
try {
|
|
1658
|
-
const content = await
|
|
1371
|
+
const content = await import_promises.default.readFile(lockPath, "utf-8");
|
|
1659
1372
|
const info = JSON.parse(content);
|
|
1660
1373
|
const isProcessAlive = isAlive(info.pid);
|
|
1661
1374
|
const isStale = Date.now() - info.timestamp > STALE_TIMEOUT_MS;
|
|
1662
1375
|
if (!isProcessAlive || isStale) {
|
|
1663
|
-
await
|
|
1376
|
+
await import_promises.default.unlink(lockPath).catch(() => {
|
|
1664
1377
|
});
|
|
1665
1378
|
continue;
|
|
1666
1379
|
}
|
|
1667
1380
|
} catch {
|
|
1668
|
-
await
|
|
1381
|
+
const stat = await import_promises.default.stat(lockPath).catch(() => null);
|
|
1382
|
+
if (!stat) continue;
|
|
1383
|
+
if (Date.now() - stat.mtimeMs > STALE_TIMEOUT_MS) {
|
|
1384
|
+
await import_promises.default.unlink(lockPath).catch(() => {
|
|
1385
|
+
});
|
|
1386
|
+
continue;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
if (Date.now() - startTime > MAX_WAIT_MS) {
|
|
1390
|
+
await import_promises.default.unlink(lockPath).catch(() => {
|
|
1669
1391
|
});
|
|
1670
1392
|
continue;
|
|
1671
1393
|
}
|
|
1672
|
-
|
|
1673
|
-
|
|
1394
|
+
await (0, import_promises2.setTimeout)(RETRY_INTERVAL_MS);
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
async function lockFileExists(lockPath) {
|
|
1399
|
+
try {
|
|
1400
|
+
await import_promises.default.stat(lockPath);
|
|
1401
|
+
return true;
|
|
1402
|
+
} catch (err) {
|
|
1403
|
+
return err.code !== "ENOENT";
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
async function releaseLock(lockPath) {
|
|
1407
|
+
await import_promises.default.unlink(lockPath).catch(() => {
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
function isAlive(pid) {
|
|
1411
|
+
try {
|
|
1412
|
+
process.kill(pid, 0);
|
|
1413
|
+
return true;
|
|
1414
|
+
} catch (err) {
|
|
1415
|
+
if (err.code === "EPERM") return true;
|
|
1416
|
+
return false;
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
// src/logger.ts
|
|
1421
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
1422
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
1423
|
+
var import_node_crypto5 = require("crypto");
|
|
1424
|
+
var import_ai2 = require("@prestyj/ai");
|
|
1425
|
+
var MAX_BYTES = 10 * 1024 * 1024;
|
|
1426
|
+
var ROTATED_GENERATIONS = 3;
|
|
1427
|
+
var MIN_HEADROOM_BYTES = 64 * 1024;
|
|
1428
|
+
var fd = null;
|
|
1429
|
+
var logPath = null;
|
|
1430
|
+
var fileBytes = 0;
|
|
1431
|
+
var processBytes = 0;
|
|
1432
|
+
var rotationFailed = false;
|
|
1433
|
+
var capped = false;
|
|
1434
|
+
var sessionId = "";
|
|
1435
|
+
var appName = "app";
|
|
1436
|
+
var cleanups = [];
|
|
1437
|
+
var exactSecrets = [];
|
|
1438
|
+
function rotateIfNeeded(filePath, force = false) {
|
|
1439
|
+
try {
|
|
1440
|
+
const st = import_node_fs2.default.statSync(filePath);
|
|
1441
|
+
if (!force && st.size <= MAX_BYTES - MIN_HEADROOM_BYTES) return;
|
|
1442
|
+
const rotated = `${filePath}.1`;
|
|
1443
|
+
for (let generation = ROTATED_GENERATIONS - 1; generation >= 1; generation--) {
|
|
1444
|
+
const older = `${filePath}.${generation + 1}`;
|
|
1445
|
+
try {
|
|
1446
|
+
import_node_fs2.default.unlinkSync(older);
|
|
1447
|
+
} catch {
|
|
1448
|
+
}
|
|
1449
|
+
try {
|
|
1450
|
+
import_node_fs2.default.renameSync(`${filePath}.${generation}`, older);
|
|
1451
|
+
} catch {
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
try {
|
|
1455
|
+
import_node_fs2.default.unlinkSync(rotated);
|
|
1456
|
+
} catch {
|
|
1457
|
+
}
|
|
1458
|
+
import_node_fs2.default.renameSync(filePath, rotated);
|
|
1459
|
+
} catch {
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
function rotateOpenLog() {
|
|
1463
|
+
if (fd === null || logPath === null) return false;
|
|
1464
|
+
const sizeBefore = fileBytes;
|
|
1465
|
+
try {
|
|
1466
|
+
import_node_fs2.default.closeSync(fd);
|
|
1467
|
+
} catch {
|
|
1468
|
+
}
|
|
1469
|
+
fd = null;
|
|
1470
|
+
rotateIfNeeded(logPath, true);
|
|
1471
|
+
try {
|
|
1472
|
+
fd = import_node_fs2.default.openSync(logPath, "a");
|
|
1473
|
+
fileBytes = import_node_fs2.default.fstatSync(fd).size;
|
|
1474
|
+
} catch {
|
|
1475
|
+
if (fd !== null) {
|
|
1476
|
+
try {
|
|
1477
|
+
import_node_fs2.default.closeSync(fd);
|
|
1478
|
+
} catch {
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
fd = null;
|
|
1482
|
+
capped = true;
|
|
1483
|
+
return false;
|
|
1484
|
+
}
|
|
1485
|
+
if (fileBytes >= sizeBefore) rotationFailed = true;
|
|
1486
|
+
return true;
|
|
1487
|
+
}
|
|
1488
|
+
function openLog(filePath, name) {
|
|
1489
|
+
if (fd !== null || capped) return false;
|
|
1490
|
+
appName = name;
|
|
1491
|
+
exactSecrets = (0, import_ai2.environmentSecrets)(process.env);
|
|
1492
|
+
try {
|
|
1493
|
+
import_node_fs2.default.mkdirSync(import_node_path3.default.dirname(filePath), { recursive: true, mode: 448 });
|
|
1494
|
+
} catch {
|
|
1495
|
+
}
|
|
1496
|
+
rotateIfNeeded(filePath);
|
|
1497
|
+
try {
|
|
1498
|
+
fd = import_node_fs2.default.openSync(filePath, "a");
|
|
1499
|
+
} catch {
|
|
1500
|
+
fd = null;
|
|
1501
|
+
fileBytes = 0;
|
|
1502
|
+
return false;
|
|
1503
|
+
}
|
|
1504
|
+
try {
|
|
1505
|
+
fileBytes = import_node_fs2.default.fstatSync(fd).size;
|
|
1506
|
+
} catch {
|
|
1507
|
+
try {
|
|
1508
|
+
import_node_fs2.default.closeSync(fd);
|
|
1509
|
+
} catch {
|
|
1510
|
+
}
|
|
1511
|
+
fd = null;
|
|
1512
|
+
fileBytes = 0;
|
|
1513
|
+
return false;
|
|
1514
|
+
}
|
|
1515
|
+
logPath = filePath;
|
|
1516
|
+
processBytes = 0;
|
|
1517
|
+
rotationFailed = false;
|
|
1518
|
+
sessionId = (0, import_node_crypto5.randomBytes)(4).toString("hex");
|
|
1519
|
+
try {
|
|
1520
|
+
if (fileBytes < MAX_BYTES) {
|
|
1521
|
+
const written = import_node_fs2.default.writeSync(fd, "\n");
|
|
1522
|
+
fileBytes += written;
|
|
1523
|
+
processBytes += written;
|
|
1524
|
+
}
|
|
1525
|
+
} catch {
|
|
1526
|
+
}
|
|
1527
|
+
return true;
|
|
1528
|
+
}
|
|
1529
|
+
function getSessionId() {
|
|
1530
|
+
return sessionId;
|
|
1531
|
+
}
|
|
1532
|
+
function isLoggerOpen() {
|
|
1533
|
+
return fd !== null;
|
|
1534
|
+
}
|
|
1535
|
+
function log(level, category, message, data) {
|
|
1536
|
+
if (fd === null) return;
|
|
1537
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
1538
|
+
const safeMessage = (0, import_ai2.redactText)(message, { secrets: exactSecrets });
|
|
1539
|
+
let line = `[${ts}] [sid=${sessionId}] [${level}] [${category}] ${safeMessage}`;
|
|
1540
|
+
if (data) {
|
|
1541
|
+
const safeData = (0, import_ai2.redactValue)(data, { secrets: exactSecrets });
|
|
1542
|
+
const pairs = Object.entries(safeData).map(([k, v]) => {
|
|
1543
|
+
if (typeof v === "string") return `${k}=${v}`;
|
|
1544
|
+
if (typeof v === "bigint") return `${k}=${String(v)}`;
|
|
1545
|
+
return `${k}=${JSON.stringify(v)}`;
|
|
1546
|
+
}).join(" ");
|
|
1547
|
+
if (pairs) line += ` ${pairs}`;
|
|
1548
|
+
}
|
|
1549
|
+
line += "\n";
|
|
1550
|
+
const lineBytes = Buffer.byteLength(line);
|
|
1551
|
+
if (processBytes + lineBytes > MAX_BYTES) {
|
|
1552
|
+
const capLine = `[${ts}] [sid=${sessionId}] [WARN] [logger] Log cap reached; file logging disabled until restart
|
|
1553
|
+
`;
|
|
1554
|
+
try {
|
|
1555
|
+
if (fileBytes + Buffer.byteLength(capLine) <= MAX_BYTES) {
|
|
1556
|
+
fileBytes += import_node_fs2.default.writeSync(fd, capLine);
|
|
1557
|
+
}
|
|
1558
|
+
import_node_fs2.default.closeSync(fd);
|
|
1559
|
+
} catch {
|
|
1560
|
+
}
|
|
1561
|
+
fd = null;
|
|
1562
|
+
capped = true;
|
|
1563
|
+
return;
|
|
1564
|
+
}
|
|
1565
|
+
if (fileBytes + lineBytes > MAX_BYTES && !rotationFailed && !rotateOpenLog()) return;
|
|
1566
|
+
if (fd === null) return;
|
|
1567
|
+
try {
|
|
1568
|
+
const written = import_node_fs2.default.writeSync(fd, line);
|
|
1569
|
+
fileBytes += written;
|
|
1570
|
+
processBytes += written;
|
|
1571
|
+
} catch {
|
|
1572
|
+
}
|
|
1573
|
+
}
|
|
1574
|
+
function registerLogCleanup(fn) {
|
|
1575
|
+
cleanups.push(fn);
|
|
1576
|
+
}
|
|
1577
|
+
function closeLogger(opts) {
|
|
1578
|
+
if (fd !== null) {
|
|
1579
|
+
if (opts?.shutdownLine !== false) log("INFO", "shutdown", `${appName} shutting down`);
|
|
1580
|
+
try {
|
|
1581
|
+
if (fd !== null) import_node_fs2.default.closeSync(fd);
|
|
1582
|
+
} catch {
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
fd = null;
|
|
1586
|
+
logPath = null;
|
|
1587
|
+
fileBytes = 0;
|
|
1588
|
+
processBytes = 0;
|
|
1589
|
+
rotationFailed = false;
|
|
1590
|
+
capped = false;
|
|
1591
|
+
exactSecrets = [];
|
|
1592
|
+
for (const unsub of cleanups) unsub();
|
|
1593
|
+
cleanups = [];
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
// src/hidden-providers.ts
|
|
1597
|
+
var HIDDEN_PROVIDERS = ["gemini"];
|
|
1598
|
+
function isHiddenProvider(provider) {
|
|
1599
|
+
return HIDDEN_PROVIDERS.includes(provider);
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
// src/claude-code/runtime.ts
|
|
1603
|
+
var import_node_child_process2 = require("child_process");
|
|
1604
|
+
var import_node_crypto6 = __toESM(require("crypto"), 1);
|
|
1605
|
+
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
1606
|
+
var import_promises4 = __toESM(require("fs/promises"), 1);
|
|
1607
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
1608
|
+
|
|
1609
|
+
// src/claude-code/tar.ts
|
|
1610
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
1611
|
+
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
1612
|
+
var import_node_zlib = __toESM(require("zlib"), 1);
|
|
1613
|
+
var BLOCK = 512;
|
|
1614
|
+
function readString(buf, offset, length) {
|
|
1615
|
+
const end = buf.indexOf(0, offset);
|
|
1616
|
+
return buf.toString("utf8", offset, end === -1 || end > offset + length ? offset + length : end);
|
|
1617
|
+
}
|
|
1618
|
+
function readSize(buf, offset) {
|
|
1619
|
+
if (buf[offset] & 128) {
|
|
1620
|
+
let value = buf[offset] & 127;
|
|
1621
|
+
for (let i = 1; i < 12; i++) value = value * 256 + buf[offset + i];
|
|
1622
|
+
return value;
|
|
1623
|
+
}
|
|
1624
|
+
const text = readString(buf, offset, 12).trim();
|
|
1625
|
+
return text ? parseInt(text, 8) : 0;
|
|
1626
|
+
}
|
|
1627
|
+
function paxPath(data) {
|
|
1628
|
+
let pos = 0;
|
|
1629
|
+
while (pos < data.length) {
|
|
1630
|
+
const space = data.indexOf(32, pos);
|
|
1631
|
+
if (space === -1) break;
|
|
1632
|
+
const len = parseInt(data.toString("utf8", pos, space), 10);
|
|
1633
|
+
if (!Number.isFinite(len) || len <= 0) break;
|
|
1634
|
+
const record = data.toString("utf8", space + 1, pos + len - 1);
|
|
1635
|
+
const eq = record.indexOf("=");
|
|
1636
|
+
if (eq !== -1 && record.slice(0, eq) === "path") return record.slice(eq + 1);
|
|
1637
|
+
pos += len;
|
|
1638
|
+
}
|
|
1639
|
+
return void 0;
|
|
1640
|
+
}
|
|
1641
|
+
async function extractFileFromTarGz(tgzPath, entryName, destPath) {
|
|
1642
|
+
const input = import_node_fs3.default.createReadStream(tgzPath).pipe(import_node_zlib.default.createGunzip());
|
|
1643
|
+
let pending = Buffer.alloc(0);
|
|
1644
|
+
let remaining = 0;
|
|
1645
|
+
let padding = 0;
|
|
1646
|
+
let kind = "skip";
|
|
1647
|
+
let meta = [];
|
|
1648
|
+
let overridePath;
|
|
1649
|
+
let out;
|
|
1650
|
+
let found = false;
|
|
1651
|
+
try {
|
|
1652
|
+
for await (const chunk of input) {
|
|
1653
|
+
pending = pending.length ? Buffer.concat([pending, chunk]) : chunk;
|
|
1654
|
+
let pos = 0;
|
|
1655
|
+
while (pos < pending.length) {
|
|
1656
|
+
if (remaining > 0) {
|
|
1657
|
+
const take = Math.min(remaining, pending.length - pos);
|
|
1658
|
+
const slice = pending.subarray(pos, pos + take);
|
|
1659
|
+
if (kind === "target") await out.write(slice);
|
|
1660
|
+
else if (kind === "pax" || kind === "longname") meta.push(Buffer.from(slice));
|
|
1661
|
+
pos += take;
|
|
1662
|
+
remaining -= take;
|
|
1663
|
+
if (remaining === 0) {
|
|
1664
|
+
if (kind === "target") {
|
|
1665
|
+
await out.close();
|
|
1666
|
+
out = void 0;
|
|
1667
|
+
found = true;
|
|
1668
|
+
} else if (kind === "pax") {
|
|
1669
|
+
overridePath = paxPath(Buffer.concat(meta)) ?? overridePath;
|
|
1670
|
+
} else if (kind === "longname") {
|
|
1671
|
+
overridePath = readString(Buffer.concat(meta), 0, Number.MAX_SAFE_INTEGER);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
continue;
|
|
1675
|
+
}
|
|
1676
|
+
if (padding > 0) {
|
|
1677
|
+
const skip = Math.min(padding, pending.length - pos);
|
|
1678
|
+
pos += skip;
|
|
1679
|
+
padding -= skip;
|
|
1680
|
+
continue;
|
|
1681
|
+
}
|
|
1682
|
+
if (found) break;
|
|
1683
|
+
if (pending.length - pos < BLOCK) break;
|
|
1684
|
+
const header = pending.subarray(pos, pos + BLOCK);
|
|
1685
|
+
pos += BLOCK;
|
|
1686
|
+
if (header.every((b) => b === 0)) continue;
|
|
1687
|
+
const size = readSize(header, 124);
|
|
1688
|
+
const type2 = String.fromCharCode(header[156] || 48);
|
|
1689
|
+
let name = readString(header, 0, 100);
|
|
1690
|
+
if (readString(header, 257, 6) === "ustar") {
|
|
1691
|
+
const prefix = readString(header, 345, 155);
|
|
1692
|
+
if (prefix) name = `${prefix}/${name}`;
|
|
1693
|
+
}
|
|
1694
|
+
remaining = size;
|
|
1695
|
+
padding = (BLOCK - size % BLOCK) % BLOCK;
|
|
1696
|
+
meta = [];
|
|
1697
|
+
if (type2 === "x") kind = "pax";
|
|
1698
|
+
else if (type2 === "L") kind = "longname";
|
|
1699
|
+
else {
|
|
1700
|
+
const path7 = overridePath ?? name;
|
|
1701
|
+
overridePath = void 0;
|
|
1702
|
+
if ((type2 === "0" || type2 === "\0" || type2 === "7") && path7 === entryName) {
|
|
1703
|
+
kind = "target";
|
|
1704
|
+
out = await import_promises3.default.open(destPath, "w", 493);
|
|
1705
|
+
if (size === 0) {
|
|
1706
|
+
await out.close();
|
|
1707
|
+
out = void 0;
|
|
1708
|
+
found = true;
|
|
1709
|
+
}
|
|
1710
|
+
} else {
|
|
1711
|
+
kind = "skip";
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
pending = pos < pending.length ? Buffer.from(pending.subarray(pos)) : Buffer.alloc(0);
|
|
1716
|
+
if (found) break;
|
|
1717
|
+
}
|
|
1718
|
+
if (!found && out) throw new Error(`Archive ended inside ${entryName}`);
|
|
1719
|
+
return found;
|
|
1720
|
+
} finally {
|
|
1721
|
+
if (out) await out.close().catch(() => {
|
|
1722
|
+
});
|
|
1723
|
+
input.destroy();
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
// src/claude-code/manifest.json
|
|
1728
|
+
var manifest_default = {
|
|
1729
|
+
sdkVersion: "0.3.318",
|
|
1730
|
+
claudeCodeVersion: "2.1.318",
|
|
1731
|
+
platforms: {
|
|
1732
|
+
"darwin-arm64": {
|
|
1733
|
+
url: "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-darwin-arm64/-/claude-agent-sdk-darwin-arm64-0.3.318.tgz",
|
|
1734
|
+
integrity: "sha512-AWoXeDXzAMD3RaA21lWuHvCrKd8xmbTTmKjovninn4j07jheoVSMzFbCFjpp4kk5TdhT36JtWPkAxvjNMbcO8w==",
|
|
1735
|
+
bin: "claude"
|
|
1736
|
+
},
|
|
1737
|
+
"darwin-x64": {
|
|
1738
|
+
url: "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-darwin-x64/-/claude-agent-sdk-darwin-x64-0.3.318.tgz",
|
|
1739
|
+
integrity: "sha512-6CkZ5PCdebSY/LePp16sf/HYRtM6zVuxtn8qYICFS5KUZFsjccJJ9swVsOdHXNHi4SWZcSmIFTwoUbfFCzisRw==",
|
|
1740
|
+
bin: "claude"
|
|
1741
|
+
},
|
|
1742
|
+
"linux-arm64": {
|
|
1743
|
+
url: "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-arm64/-/claude-agent-sdk-linux-arm64-0.3.318.tgz",
|
|
1744
|
+
integrity: "sha512-mBm4su17aMitLBBCQj3bHdejyUDY6z/ormGih+HG24N689RSbdKECjGjkT87tDBIR/4jyoqmuSeHqM1DI8TJlg==",
|
|
1745
|
+
bin: "claude"
|
|
1746
|
+
},
|
|
1747
|
+
"linux-arm64-musl": {
|
|
1748
|
+
url: "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-arm64-musl/-/claude-agent-sdk-linux-arm64-musl-0.3.318.tgz",
|
|
1749
|
+
integrity: "sha512-l4LSYFOrvlYCrUImGfxMTQ0wg+T3s9CBhrBvPF/0oJGKZg+QnxHHU8jUVm9e9/xYmDRTtqFIrr4id/5AfH4XGw==",
|
|
1750
|
+
bin: "claude"
|
|
1751
|
+
},
|
|
1752
|
+
"linux-x64": {
|
|
1753
|
+
url: "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-x64/-/claude-agent-sdk-linux-x64-0.3.318.tgz",
|
|
1754
|
+
integrity: "sha512-+mE+ueBD3oRFdaG16rd0h+LMjdeivGxL0pr/+FZK7JeLWVu+yPSw/f/X02b9oK36/DWykiFTu2G6HnJ9/+YO6w==",
|
|
1755
|
+
bin: "claude"
|
|
1756
|
+
},
|
|
1757
|
+
"linux-x64-musl": {
|
|
1758
|
+
url: "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-linux-x64-musl/-/claude-agent-sdk-linux-x64-musl-0.3.318.tgz",
|
|
1759
|
+
integrity: "sha512-SAF3lj/2OzTU84p+OOA13QEKA9+5fYAw0M9E7AJjdnRmVFGqQfbV7Do1i1f9Sj0mIubB3rLTRphGRw8O4HZjgA==",
|
|
1760
|
+
bin: "claude"
|
|
1761
|
+
},
|
|
1762
|
+
"win32-arm64": {
|
|
1763
|
+
url: "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-win32-arm64/-/claude-agent-sdk-win32-arm64-0.3.318.tgz",
|
|
1764
|
+
integrity: "sha512-19iVSZ4379QbZU1XnGUtfFvhKS1WzS8H1sbU/DbrzqbJ5Kq1eB1drj+obB1fCxTh6m26tRPj0zMJmdeu/jk3Gw==",
|
|
1765
|
+
bin: "claude.exe"
|
|
1766
|
+
},
|
|
1767
|
+
"win32-x64": {
|
|
1768
|
+
url: "https://registry.npmjs.org/@anthropic-ai/claude-agent-sdk-win32-x64/-/claude-agent-sdk-win32-x64-0.3.318.tgz",
|
|
1769
|
+
integrity: "sha512-ZdKVWpyVNVt0cXrOf8sUBaxcxLEAP+oGMdQDLBWr/BqOxTWLy7TBWOj1kzw+wVg/9WIkjkgQWeJzGXPWulR1sA==",
|
|
1770
|
+
bin: "claude.exe"
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
};
|
|
1774
|
+
|
|
1775
|
+
// src/claude-code/runtime.ts
|
|
1776
|
+
var CLAUDE_CODE_MANIFEST = manifest_default;
|
|
1777
|
+
var CLAUDE_CODE_AUTH_KEY = "anthropic-claude-code";
|
|
1778
|
+
var CLAUDE_CODE_AUTH_MARKER = { via: "claude-code" };
|
|
1779
|
+
function isClaudeCodeAuthMarker(value) {
|
|
1780
|
+
return value?.via === CLAUDE_CODE_AUTH_MARKER.via;
|
|
1781
|
+
}
|
|
1782
|
+
function isLegacyClaudeOAuth(value) {
|
|
1783
|
+
const token = value?.accessToken;
|
|
1784
|
+
return typeof token === "string" && token.startsWith("sk-ant-oat");
|
|
1785
|
+
}
|
|
1786
|
+
function isMusl() {
|
|
1787
|
+
if (process.platform !== "linux") return false;
|
|
1788
|
+
const report = typeof process.report?.getReport === "function" ? process.report.getReport() : null;
|
|
1789
|
+
return report != null && report.header?.glibcVersionRuntime === void 0;
|
|
1790
|
+
}
|
|
1791
|
+
function claudeCodePlatformKey(info = { platform: process.platform, arch: process.arch, musl: isMusl() }) {
|
|
1792
|
+
const arch2 = info.arch === "arm64" || info.arch === "x64" ? info.arch : null;
|
|
1793
|
+
if (!arch2) return null;
|
|
1794
|
+
if (info.platform === "darwin" || info.platform === "win32") return `${info.platform}-${arch2}`;
|
|
1795
|
+
if (info.platform === "linux") return `linux-${arch2}${info.musl ? "-musl" : ""}`;
|
|
1796
|
+
return null;
|
|
1797
|
+
}
|
|
1798
|
+
function resolveAsset(opts) {
|
|
1799
|
+
const manifest = opts.manifest ?? CLAUDE_CODE_MANIFEST;
|
|
1800
|
+
const key = opts.platformKey ?? claudeCodePlatformKey();
|
|
1801
|
+
const asset = key ? manifest.platforms[key] : void 0;
|
|
1802
|
+
if (!asset) {
|
|
1803
|
+
throw new Error(
|
|
1804
|
+
`Claude Code isn't available for ${process.platform}-${process.arch}. Use an Anthropic API key instead.`
|
|
1805
|
+
);
|
|
1806
|
+
}
|
|
1807
|
+
return { manifest, asset };
|
|
1808
|
+
}
|
|
1809
|
+
function claudeCodeHome(opts = {}) {
|
|
1810
|
+
return opts.home ?? getAppPaths().claudeCodeDir;
|
|
1811
|
+
}
|
|
1812
|
+
function claudeCodeConfigDir(opts = {}) {
|
|
1813
|
+
return opts.home ? import_node_path4.default.join(opts.home, "config") : getAppPaths().claudeCodeConfigDir;
|
|
1814
|
+
}
|
|
1815
|
+
function claudeCodeBinaryPath(opts = {}) {
|
|
1816
|
+
const { manifest, asset } = resolveAsset(opts);
|
|
1817
|
+
return import_node_path4.default.join(claudeCodeHome(opts), manifest.claudeCodeVersion, asset.bin);
|
|
1818
|
+
}
|
|
1819
|
+
function resolveClaudeCodeBinary(opts = {}) {
|
|
1820
|
+
let binary;
|
|
1821
|
+
try {
|
|
1822
|
+
binary = claudeCodeBinaryPath(opts);
|
|
1823
|
+
} catch {
|
|
1824
|
+
return null;
|
|
1825
|
+
}
|
|
1826
|
+
try {
|
|
1827
|
+
return import_node_fs4.default.statSync(binary).isFile() ? binary : null;
|
|
1828
|
+
} catch {
|
|
1829
|
+
return null;
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
var installs = /* @__PURE__ */ new Map();
|
|
1833
|
+
async function ensureClaudeCodeBinary(opts = {}) {
|
|
1834
|
+
const existing = resolveClaudeCodeBinary(opts);
|
|
1835
|
+
if (existing) return existing;
|
|
1836
|
+
const target = claudeCodeBinaryPath(opts);
|
|
1837
|
+
let install = installs.get(target);
|
|
1838
|
+
if (!install) {
|
|
1839
|
+
install = installClaudeCode(opts).finally(() => installs.delete(target));
|
|
1840
|
+
installs.set(target, install);
|
|
1841
|
+
}
|
|
1842
|
+
return install;
|
|
1843
|
+
}
|
|
1844
|
+
async function installClaudeCode(opts) {
|
|
1845
|
+
const { manifest, asset } = resolveAsset(opts);
|
|
1846
|
+
const home = claudeCodeHome(opts);
|
|
1847
|
+
const versionDir = import_node_path4.default.join(home, manifest.claudeCodeVersion);
|
|
1848
|
+
const binary = import_node_path4.default.join(versionDir, asset.bin);
|
|
1849
|
+
await import_promises4.default.mkdir(home, { recursive: true });
|
|
1850
|
+
const tag = `${process.pid}-${import_node_crypto6.default.randomBytes(4).toString("hex")}`;
|
|
1851
|
+
const tarball = import_node_path4.default.join(home, `.download-${tag}.tgz`);
|
|
1852
|
+
const staging = import_node_path4.default.join(home, `.staging-${tag}`);
|
|
1853
|
+
try {
|
|
1854
|
+
await download(asset, tarball, opts);
|
|
1855
|
+
opts.onProgress?.({ phase: "extract" });
|
|
1856
|
+
await import_promises4.default.mkdir(staging, { recursive: true });
|
|
1857
|
+
const found = await extractFileFromTarGz(
|
|
1858
|
+
tarball,
|
|
1859
|
+
`package/${asset.bin}`,
|
|
1860
|
+
import_node_path4.default.join(staging, asset.bin)
|
|
1861
|
+
);
|
|
1862
|
+
if (!found) throw new Error(`The Claude Code download has no ${asset.bin} binary.`);
|
|
1863
|
+
await import_promises4.default.chmod(import_node_path4.default.join(staging, asset.bin), 493);
|
|
1864
|
+
try {
|
|
1865
|
+
await import_promises4.default.rename(staging, versionDir);
|
|
1866
|
+
} catch (err) {
|
|
1867
|
+
if (!import_node_fs4.default.existsSync(binary)) throw err;
|
|
1868
|
+
}
|
|
1869
|
+
await removeOldVersions(home, manifest.claudeCodeVersion);
|
|
1870
|
+
return binary;
|
|
1871
|
+
} finally {
|
|
1872
|
+
await import_promises4.default.rm(tarball, { force: true }).catch(() => {
|
|
1873
|
+
});
|
|
1874
|
+
await import_promises4.default.rm(staging, { recursive: true, force: true }).catch(() => {
|
|
1875
|
+
});
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
async function download(asset, dest, opts) {
|
|
1879
|
+
const doFetch = opts.fetch ?? fetch;
|
|
1880
|
+
const res = await doFetch(asset.url, { signal: opts.signal });
|
|
1881
|
+
if (!res.ok || !res.body) {
|
|
1882
|
+
throw new Error(`Claude Code download failed (HTTP ${res.status}).`);
|
|
1883
|
+
}
|
|
1884
|
+
const totalBytes = Number(res.headers.get("content-length")) || void 0;
|
|
1885
|
+
const hash = import_node_crypto6.default.createHash("sha512");
|
|
1886
|
+
const out = await import_promises4.default.open(dest, "w");
|
|
1887
|
+
let receivedBytes = 0;
|
|
1888
|
+
let lastReported = -1;
|
|
1889
|
+
try {
|
|
1890
|
+
opts.onProgress?.({ phase: "download", receivedBytes, totalBytes });
|
|
1891
|
+
for await (const chunk of res.body) {
|
|
1892
|
+
if (opts.signal?.aborted) throw opts.signal.reason ?? new Error("Download cancelled.");
|
|
1893
|
+
hash.update(chunk);
|
|
1894
|
+
await out.write(chunk);
|
|
1895
|
+
receivedBytes += chunk.byteLength;
|
|
1896
|
+
const step = totalBytes ? Math.floor(receivedBytes / totalBytes * 100) : Math.floor(receivedBytes / 4194304);
|
|
1897
|
+
if (step !== lastReported) {
|
|
1898
|
+
lastReported = step;
|
|
1899
|
+
opts.onProgress?.({ phase: "download", receivedBytes, totalBytes });
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
} finally {
|
|
1903
|
+
await out.close();
|
|
1904
|
+
}
|
|
1905
|
+
opts.onProgress?.({ phase: "verify" });
|
|
1906
|
+
const expected = asset.integrity.replace(/^sha512-/, "");
|
|
1907
|
+
if (hash.digest("base64") !== expected) {
|
|
1908
|
+
throw new Error(
|
|
1909
|
+
"The Claude Code download didn't match its pinned checksum, so it was discarded."
|
|
1910
|
+
);
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
async function removeOldVersions(home, keep) {
|
|
1914
|
+
let entries;
|
|
1915
|
+
try {
|
|
1916
|
+
entries = await import_promises4.default.readdir(home, { withFileTypes: true });
|
|
1917
|
+
} catch {
|
|
1918
|
+
return;
|
|
1919
|
+
}
|
|
1920
|
+
for (const entry of entries) {
|
|
1921
|
+
if (!entry.isDirectory() || entry.name === keep || entry.name === "config") continue;
|
|
1922
|
+
if (!/^\d+\.\d+\.\d+/.test(entry.name)) continue;
|
|
1923
|
+
await import_promises4.default.rm(import_node_path4.default.join(home, entry.name), { recursive: true, force: true }).catch(() => {
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
function formatClaudeCodeInstallProgress(progress) {
|
|
1928
|
+
if (progress.phase === "verify") return "Checking the Claude Code download\u2026";
|
|
1929
|
+
if (progress.phase === "extract") return "Unpacking Claude Code\u2026";
|
|
1930
|
+
const mb = (bytes) => Math.round(bytes / 1048576);
|
|
1931
|
+
if (!progress.totalBytes) return `Downloading Claude Code\u2026 ${mb(progress.receivedBytes)} MB`;
|
|
1932
|
+
const pct = Math.floor(progress.receivedBytes / progress.totalBytes * 100);
|
|
1933
|
+
return `Downloading Claude Code\u2026 ${pct}% (${mb(progress.receivedBytes)} of ${mb(progress.totalBytes)} MB)`;
|
|
1934
|
+
}
|
|
1935
|
+
var STRIPPED_ENV = [
|
|
1936
|
+
"ANTHROPIC_API_KEY",
|
|
1937
|
+
"ANTHROPIC_AUTH_TOKEN",
|
|
1938
|
+
"ANTHROPIC_BASE_URL",
|
|
1939
|
+
"CLAUDE_CODE_OAUTH_TOKEN",
|
|
1940
|
+
"CLAUDE_CODE_OAUTH_REFRESH_TOKEN",
|
|
1941
|
+
"CLAUDE_CODE_USE_BEDROCK",
|
|
1942
|
+
"CLAUDE_CODE_USE_VERTEX",
|
|
1943
|
+
"CLAUDE_CODE_USE_FOUNDRY",
|
|
1944
|
+
"NODE_OPTIONS"
|
|
1945
|
+
];
|
|
1946
|
+
function claudeCodeEnv(opts = {}, base = process.env) {
|
|
1947
|
+
const env = {};
|
|
1948
|
+
for (const [key, value] of Object.entries(base)) {
|
|
1949
|
+
if (value !== void 0 && !STRIPPED_ENV.includes(key)) env[key] = value;
|
|
1950
|
+
}
|
|
1951
|
+
env.CLAUDE_CONFIG_DIR = claudeCodeConfigDir(opts);
|
|
1952
|
+
env.DISABLE_AUTOUPDATER = "1";
|
|
1953
|
+
return env;
|
|
1954
|
+
}
|
|
1955
|
+
function runCommand(opts) {
|
|
1956
|
+
if (opts.binary) return { command: opts.binary, prefix: opts.binaryArgs ?? [] };
|
|
1957
|
+
const binary = resolveClaudeCodeBinary(opts);
|
|
1958
|
+
if (!binary) throw new Error("Claude Code isn't installed yet. Sign in with Claude first.");
|
|
1959
|
+
return { command: binary, prefix: [] };
|
|
1960
|
+
}
|
|
1961
|
+
function runClaude(args, opts) {
|
|
1962
|
+
const { command, prefix } = runCommand(opts);
|
|
1963
|
+
return new Promise((resolve, reject) => {
|
|
1964
|
+
const child = (0, import_node_child_process2.spawn)(command, [...prefix, ...args], {
|
|
1965
|
+
env: claudeCodeEnv(opts),
|
|
1966
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
1967
|
+
windowsHide: true,
|
|
1968
|
+
signal: opts.signal
|
|
1969
|
+
});
|
|
1970
|
+
let stdout = "";
|
|
1971
|
+
let stderr = "";
|
|
1972
|
+
child.stdout.on("data", (d) => stdout += d.toString());
|
|
1973
|
+
child.stderr.on("data", (d) => stderr += d.toString());
|
|
1974
|
+
child.on("error", reject);
|
|
1975
|
+
child.on("close", (code) => resolve({ code, stdout, stderr }));
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
async function claudeCodeAuthStatus(opts = {}) {
|
|
1979
|
+
if (!opts.binary && !resolveClaudeCodeBinary(opts)) return { loggedIn: false };
|
|
1980
|
+
const { stdout } = await runClaude(["auth", "status", "--json"], opts);
|
|
1981
|
+
try {
|
|
1982
|
+
const parsed = JSON.parse(stdout);
|
|
1983
|
+
return {
|
|
1984
|
+
loggedIn: parsed.loggedIn === true,
|
|
1985
|
+
...typeof parsed.authMethod === "string" ? { authMethod: parsed.authMethod } : {},
|
|
1986
|
+
...typeof parsed.email === "string" ? { email: parsed.email } : {},
|
|
1987
|
+
...typeof parsed.subscriptionType === "string" ? { subscriptionType: parsed.subscriptionType } : {}
|
|
1988
|
+
};
|
|
1989
|
+
} catch {
|
|
1990
|
+
return { loggedIn: false };
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
async function logoutClaudeCode(opts = {}) {
|
|
1994
|
+
if (!opts.binary && !resolveClaudeCodeBinary(opts)) return;
|
|
1995
|
+
const { code, stderr } = await runClaude(["auth", "logout"], opts);
|
|
1996
|
+
if (code !== 0) throw new Error(stderr.trim() || `claude auth logout exited with ${code}`);
|
|
1997
|
+
}
|
|
1998
|
+
var OPEN_URL_HOOK = `const arg = String(process.argv[1] || "");
|
|
1999
|
+
const file = process.env.EZ_CLAUDE_CODE_URL_FILE;
|
|
2000
|
+
if (file && /https?:/.test(arg)) {
|
|
2001
|
+
require("node:fs").appendFileSync(file, arg + "\\n");
|
|
2002
|
+
process.exit(0);
|
|
2003
|
+
}
|
|
2004
|
+
`;
|
|
2005
|
+
var CAPTURE_WAIT_MS = 3e3;
|
|
2006
|
+
function stripAnsi(text) {
|
|
2007
|
+
return text.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b\[[0-9;?]*[A-Za-z]/g, "");
|
|
2008
|
+
}
|
|
2009
|
+
function claudeCodeCallbackUrl(manualUrl, captured) {
|
|
2010
|
+
const port = /localhost(?::|%3A)(\d{2,5})(?:\/|%2F)callback/i.exec(captured)?.[1];
|
|
2011
|
+
if (!port) return null;
|
|
2012
|
+
try {
|
|
2013
|
+
const url = new URL(manualUrl);
|
|
2014
|
+
url.searchParams.set("redirect_uri", `http://localhost:${port}/callback`);
|
|
2015
|
+
return url.toString();
|
|
2016
|
+
} catch {
|
|
2017
|
+
return null;
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
async function loginClaudeCode(callbacks, opts = {}) {
|
|
2021
|
+
const { command, prefix } = runCommand(opts);
|
|
2022
|
+
const home = claudeCodeHome(opts);
|
|
2023
|
+
await import_promises4.default.mkdir(claudeCodeConfigDir(opts), { recursive: true });
|
|
2024
|
+
const tag = `${process.pid}-${import_node_crypto6.default.randomBytes(4).toString("hex")}`;
|
|
2025
|
+
const hookFile = import_node_path4.default.join(home, `.open-url-${tag}.cjs`);
|
|
2026
|
+
const urlFile = import_node_path4.default.join(home, `.open-url-${tag}.txt`);
|
|
2027
|
+
await import_promises4.default.writeFile(hookFile, OPEN_URL_HOOK);
|
|
2028
|
+
const env = {
|
|
2029
|
+
...claudeCodeEnv(opts),
|
|
2030
|
+
BROWSER: process.execPath,
|
|
2031
|
+
NODE_OPTIONS: `--require ${JSON.stringify(hookFile)}`,
|
|
2032
|
+
EZ_CLAUDE_CODE_URL_FILE: urlFile
|
|
2033
|
+
};
|
|
2034
|
+
const promptAbort = new AbortController();
|
|
2035
|
+
let timer;
|
|
2036
|
+
try {
|
|
2037
|
+
await new Promise((resolve, reject) => {
|
|
2038
|
+
const child = (0, import_node_child_process2.spawn)(command, [...prefix, "auth", "login", "--claudeai"], {
|
|
2039
|
+
env,
|
|
2040
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
2041
|
+
windowsHide: true
|
|
2042
|
+
});
|
|
2043
|
+
let stdout = "";
|
|
2044
|
+
let stderr = "";
|
|
2045
|
+
let manualUrl = null;
|
|
2046
|
+
let opened = false;
|
|
2047
|
+
const onAbort = () => child.kill();
|
|
2048
|
+
opts.signal?.addEventListener("abort", onAbort, { once: true });
|
|
2049
|
+
const open = (url, needsCode) => {
|
|
2050
|
+
if (opened) return;
|
|
2051
|
+
opened = true;
|
|
2052
|
+
clearInterval(timer);
|
|
2053
|
+
callbacks.onOpenUrl(url);
|
|
2054
|
+
callbacks.onStatus("Finish signing in to Claude in your browser\u2026");
|
|
2055
|
+
if (!needsCode) return;
|
|
2056
|
+
void callbacks.onPromptCode("Paste the code shown after signing in to Claude:", promptAbort.signal).then((code) => {
|
|
2057
|
+
const trimmed = code.trim();
|
|
2058
|
+
if (trimmed && !child.stdin.destroyed) child.stdin.write(`${trimmed}
|
|
2059
|
+
`);
|
|
2060
|
+
}).catch(() => {
|
|
2061
|
+
});
|
|
2062
|
+
};
|
|
2063
|
+
child.stdout.on("data", (d) => {
|
|
2064
|
+
stdout += d.toString();
|
|
2065
|
+
if (manualUrl) return;
|
|
2066
|
+
const match = /visit:\s*(https:\/\/\S+)/.exec(stripAnsi(stdout));
|
|
2067
|
+
if (!match) return;
|
|
2068
|
+
manualUrl = match[1];
|
|
2069
|
+
const started = Date.now();
|
|
2070
|
+
timer = setInterval(() => {
|
|
2071
|
+
let captured = "";
|
|
2072
|
+
try {
|
|
2073
|
+
captured = import_node_fs4.default.readFileSync(urlFile, "utf8");
|
|
2074
|
+
} catch {
|
|
2075
|
+
}
|
|
2076
|
+
const callbackUrl = captured ? claudeCodeCallbackUrl(manualUrl, captured) : null;
|
|
2077
|
+
if (callbackUrl) open(callbackUrl, false);
|
|
2078
|
+
else if (Date.now() - started > (opts.browserWaitMs ?? CAPTURE_WAIT_MS))
|
|
2079
|
+
open(manualUrl, true);
|
|
2080
|
+
}, 100);
|
|
2081
|
+
});
|
|
2082
|
+
child.stderr.on("data", (d) => stderr += d.toString());
|
|
2083
|
+
child.on("error", reject);
|
|
2084
|
+
child.on("close", (code) => {
|
|
2085
|
+
opts.signal?.removeEventListener("abort", onAbort);
|
|
2086
|
+
if (opts.signal?.aborted) reject(new Error("Sign-in cancelled."));
|
|
2087
|
+
else if (code === 0) resolve();
|
|
2088
|
+
else {
|
|
2089
|
+
const detail = stripAnsi(stderr).trim().split("\n").pop()?.trim();
|
|
2090
|
+
reject(new Error(detail || `Claude sign-in failed (exit ${code}).`));
|
|
2091
|
+
}
|
|
2092
|
+
});
|
|
2093
|
+
});
|
|
2094
|
+
} finally {
|
|
2095
|
+
clearInterval(timer);
|
|
2096
|
+
promptAbort.abort();
|
|
2097
|
+
await import_promises4.default.rm(hookFile, { force: true }).catch(() => {
|
|
2098
|
+
});
|
|
2099
|
+
await import_promises4.default.rm(urlFile, { force: true }).catch(() => {
|
|
2100
|
+
});
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
// src/auth-storage.ts
|
|
2105
|
+
var import_ai3 = require("@prestyj/ai");
|
|
2106
|
+
|
|
2107
|
+
// src/minimax-region.ts
|
|
2108
|
+
var MINIMAX_GLOBAL_BASE_URL = "https://api.minimax.io/anthropic";
|
|
2109
|
+
var MINIMAX_CN_BASE_URL = "https://api.minimax.cn/anthropic";
|
|
2110
|
+
var REGION_HOSTS = [
|
|
2111
|
+
{ host: "https://api.minimax.io", baseUrl: MINIMAX_GLOBAL_BASE_URL },
|
|
2112
|
+
{ host: "https://api.minimax.cn", baseUrl: MINIMAX_CN_BASE_URL }
|
|
2113
|
+
];
|
|
2114
|
+
var KEY_KNOWN_CODES = /* @__PURE__ */ new Set([0, 2062]);
|
|
2115
|
+
var KEY_REJECTED_CODES = /* @__PURE__ */ new Set([1004, 2049]);
|
|
2116
|
+
async function probeRegion(host, apiKey, fetchImpl, timeoutMs) {
|
|
2117
|
+
const url = apiKey.startsWith("sk-api-") ? `${host}/account/query_balance` : `${host}/v1/token_plan/remains`;
|
|
2118
|
+
let sawRejection = false;
|
|
2119
|
+
const authHeaders2 = [
|
|
2120
|
+
{ Authorization: `Bearer ${apiKey}` },
|
|
2121
|
+
{ "x-api-key": apiKey }
|
|
2122
|
+
];
|
|
2123
|
+
for (const auth of authHeaders2) {
|
|
2124
|
+
let res;
|
|
2125
|
+
try {
|
|
2126
|
+
res = await fetchImpl(url, {
|
|
2127
|
+
headers: { ...auth, "Content-Type": "application/json" },
|
|
2128
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
2129
|
+
});
|
|
2130
|
+
} catch {
|
|
2131
|
+
return "inconclusive";
|
|
2132
|
+
}
|
|
2133
|
+
if (res.status === 401 || res.status === 403) {
|
|
2134
|
+
sawRejection = true;
|
|
2135
|
+
continue;
|
|
2136
|
+
}
|
|
2137
|
+
if (!res.ok) return "inconclusive";
|
|
2138
|
+
let code;
|
|
2139
|
+
try {
|
|
2140
|
+
code = (await res.json()).base_resp?.status_code;
|
|
2141
|
+
} catch {
|
|
2142
|
+
return "inconclusive";
|
|
2143
|
+
}
|
|
2144
|
+
if (typeof code === "number" && KEY_KNOWN_CODES.has(code)) return "authorized";
|
|
2145
|
+
if (typeof code === "number" && KEY_REJECTED_CODES.has(code)) {
|
|
2146
|
+
sawRejection = true;
|
|
2147
|
+
continue;
|
|
2148
|
+
}
|
|
2149
|
+
return "inconclusive";
|
|
2150
|
+
}
|
|
2151
|
+
return sawRejection ? "unauthorized" : "inconclusive";
|
|
2152
|
+
}
|
|
2153
|
+
async function detectMiniMaxBaseUrl(apiKey, options = {}) {
|
|
2154
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
2155
|
+
const timeoutMs = options.timeoutMs ?? 5e3;
|
|
2156
|
+
const results = await Promise.all(
|
|
2157
|
+
REGION_HOSTS.map((r) => probeRegion(r.host, apiKey, fetchImpl, timeoutMs))
|
|
2158
|
+
);
|
|
2159
|
+
const index = results.indexOf("authorized");
|
|
2160
|
+
return index === -1 ? void 0 : REGION_HOSTS[index].baseUrl;
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2163
|
+
// src/xiaomi-region.ts
|
|
2164
|
+
var XIAOMI_TOKEN_PLAN_BASE_URLS = [
|
|
2165
|
+
"https://token-plan-sgp.xiaomimimo.com/v1",
|
|
2166
|
+
"https://token-plan-ams.xiaomimimo.com/v1",
|
|
2167
|
+
"https://token-plan-cn.xiaomimimo.com/v1"
|
|
2168
|
+
];
|
|
2169
|
+
async function detectXiaomiTokenPlanBaseUrl(apiKey, options = {}) {
|
|
2170
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
2171
|
+
const timeoutMs = options.timeoutMs ?? 5e3;
|
|
2172
|
+
const accepted = await Promise.all(
|
|
2173
|
+
XIAOMI_TOKEN_PLAN_BASE_URLS.map(async (baseUrl) => {
|
|
2174
|
+
try {
|
|
2175
|
+
const res = await fetchImpl(`${baseUrl}/models`, {
|
|
2176
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
2177
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
1674
2178
|
});
|
|
1675
|
-
|
|
2179
|
+
return res.ok;
|
|
2180
|
+
} catch {
|
|
2181
|
+
return false;
|
|
1676
2182
|
}
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
async function releaseLock(lockPath) {
|
|
1682
|
-
await import_promises2.default.unlink(lockPath).catch(() => {
|
|
1683
|
-
});
|
|
1684
|
-
}
|
|
1685
|
-
function isAlive(pid) {
|
|
1686
|
-
try {
|
|
1687
|
-
process.kill(pid, 0);
|
|
1688
|
-
return true;
|
|
1689
|
-
} catch (err) {
|
|
1690
|
-
if (err.code === "EPERM") return true;
|
|
1691
|
-
return false;
|
|
1692
|
-
}
|
|
2183
|
+
})
|
|
2184
|
+
);
|
|
2185
|
+
const index = accepted.indexOf(true);
|
|
2186
|
+
return index === -1 ? void 0 : XIAOMI_TOKEN_PLAN_BASE_URLS[index];
|
|
1693
2187
|
}
|
|
1694
2188
|
|
|
1695
2189
|
// src/auth-storage.ts
|
|
@@ -1742,9 +2236,18 @@ function activeBaseUrlEntry(data, provider) {
|
|
|
1742
2236
|
}
|
|
1743
2237
|
return data[provider];
|
|
1744
2238
|
}
|
|
2239
|
+
var MINIMAX_REGION_RETRY_MS = 5 * 60 * 1e3;
|
|
2240
|
+
var miniMaxRegionProbes = /* @__PURE__ */ new Map();
|
|
2241
|
+
function cachedMiniMaxRegion(apiKey) {
|
|
2242
|
+
const cached = miniMaxRegionProbes.get(apiKey);
|
|
2243
|
+
if (cached && Date.now() - cached.at < MINIMAX_REGION_RETRY_MS) return cached.result;
|
|
2244
|
+
const result = detectMiniMaxBaseUrl(apiKey).catch(() => void 0);
|
|
2245
|
+
miniMaxRegionProbes.set(apiKey, { at: Date.now(), result });
|
|
2246
|
+
return result;
|
|
2247
|
+
}
|
|
1745
2248
|
function readStoredBaseUrlSync(authFile, provider) {
|
|
1746
2249
|
try {
|
|
1747
|
-
const data = JSON.parse((0,
|
|
2250
|
+
const data = JSON.parse((0, import_node_fs5.readFileSync)(authFile, "utf-8"));
|
|
1748
2251
|
return activeBaseUrlEntry(data, provider)?.baseUrl;
|
|
1749
2252
|
} catch {
|
|
1750
2253
|
return void 0;
|
|
@@ -1788,8 +2291,12 @@ var AuthStorage = class {
|
|
|
1788
2291
|
snapshotIno = 0;
|
|
1789
2292
|
/** Per-provider lock to serialize concurrent refresh calls. */
|
|
1790
2293
|
refreshLocks = /* @__PURE__ */ new Map();
|
|
1791
|
-
|
|
2294
|
+
detectMiniMaxRegion;
|
|
2295
|
+
detectXiaomiCluster;
|
|
2296
|
+
constructor(filePath, options) {
|
|
1792
2297
|
this.filePath = filePath ?? getAppPaths().authFile;
|
|
2298
|
+
this.detectMiniMaxRegion = options?.detectMiniMaxBaseUrl ?? cachedMiniMaxRegion;
|
|
2299
|
+
this.detectXiaomiCluster = options?.detectXiaomiTokenPlanBaseUrl ?? detectXiaomiTokenPlanBaseUrl;
|
|
1793
2300
|
}
|
|
1794
2301
|
/** Path to the on-disk auth file. Useful for status output. */
|
|
1795
2302
|
get path() {
|
|
@@ -1822,6 +2329,7 @@ var AuthStorage = class {
|
|
|
1822
2329
|
* satisfies it.
|
|
1823
2330
|
*/
|
|
1824
2331
|
async hasProviderAuth(provider) {
|
|
2332
|
+
if (isHiddenProvider(provider)) return false;
|
|
1825
2333
|
await this.ensureFresh();
|
|
1826
2334
|
const dual = dualAuthProvider(provider);
|
|
1827
2335
|
if (dual) {
|
|
@@ -1833,11 +2341,28 @@ var AuthStorage = class {
|
|
|
1833
2341
|
if (provider === "gemini") {
|
|
1834
2342
|
return Boolean(this.data["gemini"] || this.data[GEMINI_API_KEY]);
|
|
1835
2343
|
}
|
|
2344
|
+
if (provider === "anthropic" && isClaudeCodeAuthMarker(this.data[CLAUDE_CODE_AUTH_KEY])) {
|
|
2345
|
+
return true;
|
|
2346
|
+
}
|
|
1836
2347
|
if (provider === "local") {
|
|
1837
2348
|
return Object.keys(this.data).some((key) => key.startsWith(LOCAL_AUTH_KEY_PREFIX));
|
|
1838
2349
|
}
|
|
1839
2350
|
return Boolean(this.data[provider]);
|
|
1840
2351
|
}
|
|
2352
|
+
/** True when the user signed in with Claude through Claude Code (marker only, no token). */
|
|
2353
|
+
async hasClaudeCodeLogin() {
|
|
2354
|
+
await this.ensureFresh();
|
|
2355
|
+
return isClaudeCodeAuthMarker(this.data[CLAUDE_CODE_AUTH_KEY]);
|
|
2356
|
+
}
|
|
2357
|
+
/** Record a Claude Code sign-in. Claude Code keeps the token; auth.json gets only the marker. */
|
|
2358
|
+
async setClaudeCodeLogin() {
|
|
2359
|
+
await this.mutateLatest((latest) => {
|
|
2360
|
+
latest[CLAUDE_CODE_AUTH_KEY] = { ...CLAUDE_CODE_AUTH_MARKER };
|
|
2361
|
+
});
|
|
2362
|
+
}
|
|
2363
|
+
async clearClaudeCodeLogin() {
|
|
2364
|
+
await this.clearCredentials(CLAUDE_CODE_AUTH_KEY);
|
|
2365
|
+
}
|
|
1841
2366
|
/** Endpoint ids that currently have a `local:<id>` credential stored. */
|
|
1842
2367
|
async listLocalEndpointIds() {
|
|
1843
2368
|
await this.ensureLoaded();
|
|
@@ -1850,7 +2375,7 @@ var AuthStorage = class {
|
|
|
1850
2375
|
*/
|
|
1851
2376
|
async setLocalEndpoint(endpointId, baseUrl, apiKey) {
|
|
1852
2377
|
await this.setCredentials(`${LOCAL_AUTH_KEY_PREFIX}${endpointId}`, {
|
|
1853
|
-
accessToken: apiKey && apiKey.length > 0 ? apiKey :
|
|
2378
|
+
accessToken: apiKey && apiKey.length > 0 ? apiKey : import_ai3.LOCAL_NO_API_KEY,
|
|
1854
2379
|
refreshToken: "",
|
|
1855
2380
|
expiresAt: Date.now() + LOCAL_CREDENTIAL_LIFETIME_MS,
|
|
1856
2381
|
baseUrl
|
|
@@ -1891,7 +2416,7 @@ var AuthStorage = class {
|
|
|
1891
2416
|
const first = !this.loaded;
|
|
1892
2417
|
await withFileLock(this.filePath, async () => {
|
|
1893
2418
|
try {
|
|
1894
|
-
const content = await
|
|
2419
|
+
const content = await import_promises5.default.readFile(this.filePath, "utf-8");
|
|
1895
2420
|
this.data = JSON.parse(content);
|
|
1896
2421
|
if (first) {
|
|
1897
2422
|
log("INFO", "auth", `Loaded credentials from ${this.filePath}`, {
|
|
@@ -1946,7 +2471,7 @@ var AuthStorage = class {
|
|
|
1946
2471
|
}
|
|
1947
2472
|
let changed;
|
|
1948
2473
|
try {
|
|
1949
|
-
const stat = await
|
|
2474
|
+
const stat = await import_promises5.default.stat(this.filePath);
|
|
1950
2475
|
changed = stat.ino !== this.snapshotIno || stat.mtimeMs !== this.snapshotMtimeMs || stat.size !== this.snapshotSize;
|
|
1951
2476
|
} catch {
|
|
1952
2477
|
changed = this.snapshotSize !== -1;
|
|
@@ -1956,7 +2481,7 @@ var AuthStorage = class {
|
|
|
1956
2481
|
/** Record the file identity behind the current snapshot. */
|
|
1957
2482
|
async rememberSnapshot() {
|
|
1958
2483
|
try {
|
|
1959
|
-
const stat = await
|
|
2484
|
+
const stat = await import_promises5.default.stat(this.filePath);
|
|
1960
2485
|
this.snapshotMtimeMs = stat.mtimeMs;
|
|
1961
2486
|
this.snapshotSize = stat.size;
|
|
1962
2487
|
this.snapshotIno = stat.ino;
|
|
@@ -1993,11 +2518,54 @@ var AuthStorage = class {
|
|
|
1993
2518
|
await this.ensureFresh();
|
|
1994
2519
|
return this.data[provider];
|
|
1995
2520
|
}
|
|
2521
|
+
/**
|
|
2522
|
+
* A MiniMax key saved without an endpoint (every key, until its first use)
|
|
2523
|
+
* gets the endpoint of the region that issued it, saved so the check runs
|
|
2524
|
+
* once. Without this a Mainland China key went to the Global API, got a 401,
|
|
2525
|
+
* and was deleted as invalid.
|
|
2526
|
+
*/
|
|
2527
|
+
async withMiniMaxRegion(creds) {
|
|
2528
|
+
const baseUrl = await this.detectMiniMaxRegion(creds.accessToken);
|
|
2529
|
+
if (!baseUrl) return creds;
|
|
2530
|
+
log("INFO", "auth", `MiniMax key belongs to ${baseUrl} \u2014 saved for future requests`);
|
|
2531
|
+
await this.mutateLatest((latest) => {
|
|
2532
|
+
const current = latest["minimax"];
|
|
2533
|
+
if (current?.accessToken === creds.accessToken && !current.baseUrl) {
|
|
2534
|
+
current.baseUrl = baseUrl;
|
|
2535
|
+
}
|
|
2536
|
+
});
|
|
2537
|
+
return { ...creds, baseUrl };
|
|
2538
|
+
}
|
|
1996
2539
|
async setCredentials(provider, creds) {
|
|
1997
2540
|
await this.mutateLatest((latest) => {
|
|
1998
2541
|
latest[provider] = creds;
|
|
1999
2542
|
});
|
|
2000
2543
|
}
|
|
2544
|
+
/**
|
|
2545
|
+
* After a 401, move a regional key to the cluster that issued it instead of
|
|
2546
|
+
* treating it as invalid. Only the Xiaomi Token Plan is regional: every key
|
|
2547
|
+
* used to go to Singapore, so Europe and China keys were rejected and deleted.
|
|
2548
|
+
* Returns the new base URL, or undefined when no other cluster accepts the key.
|
|
2549
|
+
*/
|
|
2550
|
+
async relocateRegionalApiKey(storageKeys) {
|
|
2551
|
+
const key = await this.pickStorageKey(storageKeys);
|
|
2552
|
+
const creds = key === "xiaomi" ? this.data[key] : void 0;
|
|
2553
|
+
if (!creds) return void 0;
|
|
2554
|
+
const baseUrl = await this.detectXiaomiCluster(creds.accessToken);
|
|
2555
|
+
if (!baseUrl || baseUrl === creds.baseUrl) return void 0;
|
|
2556
|
+
await this.mutateLatest((latest) => {
|
|
2557
|
+
const current = latest["xiaomi"];
|
|
2558
|
+
if (current?.accessToken === creds.accessToken) current.baseUrl = baseUrl;
|
|
2559
|
+
});
|
|
2560
|
+
log("INFO", "auth", `Xiaomi Token Plan key belongs to ${baseUrl} \u2014 saved for future requests`);
|
|
2561
|
+
return baseUrl;
|
|
2562
|
+
}
|
|
2563
|
+
// Keeps local-endpoint keys: they're the user's own config, and a 401 there is often a busy gateway.
|
|
2564
|
+
async clearRejectedApiKey(storageKey) {
|
|
2565
|
+
if (storageKey.startsWith(LOCAL_AUTH_KEY_PREFIX)) return false;
|
|
2566
|
+
await this.clearCredentials(storageKey);
|
|
2567
|
+
return true;
|
|
2568
|
+
}
|
|
2001
2569
|
async clearCredentials(provider) {
|
|
2002
2570
|
await this.mutateLatest((latest) => {
|
|
2003
2571
|
delete latest[provider];
|
|
@@ -2077,6 +2645,9 @@ var AuthStorage = class {
|
|
|
2077
2645
|
}
|
|
2078
2646
|
throw new NotLoggedInError(provider);
|
|
2079
2647
|
}
|
|
2648
|
+
if (provider === "anthropic" && !this.data.anthropic && isClaudeCodeAuthMarker(this.data[CLAUDE_CODE_AUTH_KEY])) {
|
|
2649
|
+
return { accessToken: "", refreshToken: "", expiresAt: Number.MAX_SAFE_INTEGER };
|
|
2650
|
+
}
|
|
2080
2651
|
const dual = dualAuthProvider(provider);
|
|
2081
2652
|
const dualOAuthCreds = dual ? this.data[dual.oauthKey] : void 0;
|
|
2082
2653
|
if (dual && dualOAuthCreds) {
|
|
@@ -2111,6 +2682,7 @@ var AuthStorage = class {
|
|
|
2111
2682
|
throw new NotLoggedInError(provider);
|
|
2112
2683
|
}
|
|
2113
2684
|
if (STATIC_API_KEY_PROVIDERS.has(provider)) {
|
|
2685
|
+
if (provider === "minimax" && !creds.baseUrl) return await this.withMiniMaxRegion(creds);
|
|
2114
2686
|
return creds;
|
|
2115
2687
|
}
|
|
2116
2688
|
if (!opts?.forceRefresh && Date.now() < creds.expiresAt - refreshThresholdMs(creds)) {
|
|
@@ -2197,7 +2769,7 @@ var AuthStorage = class {
|
|
|
2197
2769
|
};
|
|
2198
2770
|
async function readAuthData(filePath) {
|
|
2199
2771
|
try {
|
|
2200
|
-
const content = await
|
|
2772
|
+
const content = await import_promises5.default.readFile(filePath, "utf-8");
|
|
2201
2773
|
return JSON.parse(content);
|
|
2202
2774
|
} catch (error) {
|
|
2203
2775
|
if (error.code === "ENOENT") return {};
|
|
@@ -2205,12 +2777,12 @@ async function readAuthData(filePath) {
|
|
|
2205
2777
|
}
|
|
2206
2778
|
}
|
|
2207
2779
|
async function atomicWriteFile(filePath, content) {
|
|
2208
|
-
const tmpPath = `${filePath}.${process.pid}.${Date.now()}.${
|
|
2780
|
+
const tmpPath = `${filePath}.${process.pid}.${Date.now()}.${import_node_crypto7.default.randomUUID().slice(0, 8)}.tmp`;
|
|
2209
2781
|
try {
|
|
2210
|
-
await
|
|
2211
|
-
await
|
|
2782
|
+
await import_promises5.default.writeFile(tmpPath, content, { encoding: "utf-8", mode: 384 });
|
|
2783
|
+
await import_promises5.default.rename(tmpPath, filePath);
|
|
2212
2784
|
} catch (err) {
|
|
2213
|
-
await
|
|
2785
|
+
await import_promises5.default.unlink(tmpPath).catch(() => {
|
|
2214
2786
|
});
|
|
2215
2787
|
throw err;
|
|
2216
2788
|
}
|
|
@@ -2231,6 +2803,12 @@ var CLAUDE_FAST_BILLING = {
|
|
|
2231
2803
|
paid: true,
|
|
2232
2804
|
standardModel: "claude-opus-5-5"
|
|
2233
2805
|
};
|
|
2806
|
+
var CLAUDE_FABLE_FAST_BILLING = {
|
|
2807
|
+
label: "bills usage credits",
|
|
2808
|
+
detail: "Fast mode bills your Claude usage credits ($16 in / $80 out per million tokens) from the first token, never your plan's included usage.",
|
|
2809
|
+
paid: true,
|
|
2810
|
+
standardModel: "claude-fable-5-2"
|
|
2811
|
+
};
|
|
2234
2812
|
var XIAOMI_ULTRASPEED_BILLING = {
|
|
2235
2813
|
label: "bills API Credits",
|
|
2236
2814
|
detail: "UltraSpeed runs only on your Xiaomi API Credits, billed per token at a higher rate than MiMo-V2.6-Pro, never on the Token Plan.",
|
|
@@ -2245,18 +2823,18 @@ var CODEX_FAST_BILLING = {
|
|
|
2245
2823
|
var GEMINI_AUTH_KEYS = [GEMINI_API_KEY, "gemini"];
|
|
2246
2824
|
var MODELS = [
|
|
2247
2825
|
// ── Anthropic ──────────────────────────────────────────
|
|
2248
|
-
// NOTE: Claude Mythos 5.
|
|
2249
|
-
// out — it's
|
|
2250
|
-
//
|
|
2251
|
-
//
|
|
2826
|
+
// NOTE: Claude Mythos 5.2 (`claude-mythos-5-2`, 2026-11-09) is kept commented
|
|
2827
|
+
// out — it's only for organizations verified through Anthropic's verification
|
|
2828
|
+
// programs and unavailable to most users. Re-enable once it's generally
|
|
2829
|
+
// available.
|
|
2252
2830
|
{
|
|
2253
|
-
// Released 2026-09
|
|
2254
|
-
//
|
|
2255
|
-
// forced tool use
|
|
2256
|
-
// Anthropic path. Fable 5 is retired here — a
|
|
2257
|
-
// saved falls back to the provider default
|
|
2258
|
-
id: "claude-fable-5-
|
|
2259
|
-
name: "Claude Fable 5.
|
|
2831
|
+
// Released 2026-11-09 — replaces Fable 5.1 at $8/$40 MTok (down from
|
|
2832
|
+
// $10/$50; cache reads $0.20). Same API surface as 5.1: always-on adaptive
|
|
2833
|
+
// thinking steered by effort, forced tool use rejected with a 400 (@prestyj/ai
|
|
2834
|
+
// never sends it on the Anthropic path). Fable 5.1 is retired here — a
|
|
2835
|
+
// session that still has it saved falls back to the provider default.
|
|
2836
|
+
id: "claude-fable-5-2",
|
|
2837
|
+
name: "Claude Fable 5.2",
|
|
2260
2838
|
provider: "anthropic",
|
|
2261
2839
|
contextWindow: 1e6,
|
|
2262
2840
|
maxOutputTokens: 128e3,
|
|
@@ -2266,12 +2844,28 @@ var MODELS = [
|
|
|
2266
2844
|
costTier: "high",
|
|
2267
2845
|
maxThinkingLevel: "max"
|
|
2268
2846
|
},
|
|
2847
|
+
{
|
|
2848
|
+
// Fable 5.2 in fast mode: the same model at up to 2.5x output tokens/sec,
|
|
2849
|
+
// $16/$80 MTok. Sent as `claude-fable-5-2` + `speed: "fast"`; on a Claude
|
|
2850
|
+
// subscription it bills usage credits only, like Opus 5.5 Fast.
|
|
2851
|
+
id: "claude-fable-5-2-fast",
|
|
2852
|
+
name: "Claude Fable 5.2 Fast",
|
|
2853
|
+
provider: "anthropic",
|
|
2854
|
+
contextWindow: 1e6,
|
|
2855
|
+
maxOutputTokens: 128e3,
|
|
2856
|
+
supportsThinking: true,
|
|
2857
|
+
supportsImages: true,
|
|
2858
|
+
supportsVideo: false,
|
|
2859
|
+
costTier: "high",
|
|
2860
|
+
maxThinkingLevel: "max",
|
|
2861
|
+
billing: CLAUDE_FABLE_FAST_BILLING
|
|
2862
|
+
},
|
|
2269
2863
|
// {
|
|
2270
2864
|
// // Mythos-class model offered through Project Glasswing (limited
|
|
2271
|
-
// // availability,
|
|
2272
|
-
// //
|
|
2273
|
-
// id: "claude-mythos-5-
|
|
2274
|
-
// name: "Claude Mythos 5.
|
|
2865
|
+
// // availability, verified organizations only). Same specs and pricing as
|
|
2866
|
+
// // Fable 5.2; kept here so approved accounts can select it.
|
|
2867
|
+
// id: "claude-mythos-5-2",
|
|
2868
|
+
// name: "Claude Mythos 5.2",
|
|
2275
2869
|
// provider: "anthropic",
|
|
2276
2870
|
// contextWindow: 1_000_000,
|
|
2277
2871
|
// maxOutputTokens: 128_000,
|
|
@@ -2370,18 +2964,13 @@ var MODELS = [
|
|
|
2370
2964
|
},
|
|
2371
2965
|
// ── OpenAI (Codex) ─────────────────────────────────────
|
|
2372
2966
|
{
|
|
2373
|
-
// GPT-6 Astra — "Our most capable model for
|
|
2374
|
-
// (Codex catalog priority 2,
|
|
2375
|
-
//
|
|
2376
|
-
//
|
|
2377
|
-
//
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
// Note: through a plain API key OpenAI requires the Responses API for tool
|
|
2381
|
-
// calling on Astra, so the Chat Completions path is text-only; the OAuth
|
|
2382
|
-
// Codex route is the supported way to use it as an agent.
|
|
2383
|
-
id: "gpt-6-astra",
|
|
2384
|
-
name: "GPT-6 Astra",
|
|
2967
|
+
// GPT-6.2 Astra — released 2026-11-17, "Our most capable model for your
|
|
2968
|
+
// hardest projects." (Codex catalog priority 2, default low, client >=
|
|
2969
|
+
// 0.166.0). $8/$40 MTok, cached input $0.40. 1.05M on the public Responses
|
|
2970
|
+
// API, 272K on the Codex route; 128K output, text+image input. Same ladder
|
|
2971
|
+
// and Ultra preset as GPT-6 Astra, which it retires; the API rejects reasoning effort `none`.
|
|
2972
|
+
id: "gpt-6.2-astra",
|
|
2973
|
+
name: "GPT-6.2 Astra",
|
|
2385
2974
|
provider: "openai",
|
|
2386
2975
|
contextWindow: 105e4,
|
|
2387
2976
|
codexContextWindow: 272e3,
|
|
@@ -2394,12 +2983,12 @@ var MODELS = [
|
|
|
2394
2983
|
maxThinkingLevel: "ultra"
|
|
2395
2984
|
},
|
|
2396
2985
|
{
|
|
2397
|
-
// Codex Fast mode for Astra (
|
|
2398
|
-
//
|
|
2399
|
-
//
|
|
2400
|
-
//
|
|
2401
|
-
id: "gpt-6-astra-fast",
|
|
2402
|
-
name: "GPT-6 Astra Fast",
|
|
2986
|
+
// Codex Fast mode for 6.2 Astra ("2x speed, increased usage"). @prestyj/ai's
|
|
2987
|
+
// `stream()` sends it as `gpt-6.2-astra` + `service_tier: "priority"`,
|
|
2988
|
+
// exactly what the Codex CLI sends. On a ChatGPT plan it draws included
|
|
2989
|
+
// limits at 2.5x the standard rate.
|
|
2990
|
+
id: "gpt-6.2-astra-fast",
|
|
2991
|
+
name: "GPT-6.2 Astra Fast",
|
|
2403
2992
|
provider: "openai",
|
|
2404
2993
|
contextWindow: 105e4,
|
|
2405
2994
|
codexContextWindow: 272e3,
|
|
@@ -2413,25 +3002,26 @@ var MODELS = [
|
|
|
2413
3002
|
billing: CODEX_FAST_BILLING
|
|
2414
3003
|
},
|
|
2415
3004
|
// GPT-6 Sol + Luna — released 2026-09-22 below Astra, replacing the whole
|
|
2416
|
-
// GPT-5.6 family (Sol/Terra/Luna; there
|
|
2417
|
-
// catalog upgrades 5.6 Terra to 6 Sol). GPT-6.1 Sol (2026-09-29)
|
|
2418
|
-
// GPT-6 Sol.
|
|
2419
|
-
//
|
|
2420
|
-
//
|
|
2421
|
-
//
|
|
2422
|
-
//
|
|
3005
|
+
// GPT-5.6 family (Sol/Terra/Luna; there was no GPT-6 Terra — OpenAI's Codex
|
|
3006
|
+
// catalog upgrades 5.6 Terra to 6 Sol). GPT-6.1 Sol (2026-09-29) replaced
|
|
3007
|
+
// GPT-6 Sol, GPT-6.1 Terra (2026-10-26) sits between Sol and Luna, and
|
|
3008
|
+
// GPT-6.2 Sol (2026-11-17) replaced GPT-6.1 Sol. 1.05M on the public
|
|
3009
|
+
// Responses API; 128K output, text+image input, freeform apply_patch,
|
|
3010
|
+
// responses-lite transport. The GPT-5.6 ids, `gpt-6-sol` and `gpt-6.1-sol`
|
|
3011
|
+
// are retired — a saved session on one falls back to the provider default
|
|
3012
|
+
// on next start.
|
|
2423
3013
|
{
|
|
2424
|
-
// GPT-6.
|
|
2425
|
-
// (Codex priority 1, default low
|
|
2426
|
-
//
|
|
2427
|
-
//
|
|
3014
|
+
// GPT-6.2 Sol — "Our go-to model for everyday work, from coding to
|
|
3015
|
+
// powering agents at scale." (Codex priority 1, default low, client >=
|
|
3016
|
+
// 0.166.0). $2/$10 MTok, cached input $0.10. Like Terra, the Codex route
|
|
3017
|
+
// gets a 500K window (catalog `context_window`). Ladder low →
|
|
2428
3018
|
// medium → high → xhigh → max → ultra; ultra is the Codex orchestration
|
|
2429
3019
|
// preset (xhigh effort on the wire + proactive local subagent delegation).
|
|
2430
|
-
id: "gpt-6.
|
|
2431
|
-
name: "GPT-6.
|
|
3020
|
+
id: "gpt-6.2-sol",
|
|
3021
|
+
name: "GPT-6.2 Sol",
|
|
2432
3022
|
provider: "openai",
|
|
2433
3023
|
contextWindow: 105e4,
|
|
2434
|
-
codexContextWindow:
|
|
3024
|
+
codexContextWindow: 5e5,
|
|
2435
3025
|
maxOutputTokens: 128e3,
|
|
2436
3026
|
supportsThinking: true,
|
|
2437
3027
|
defaultThinkingLevel: "low",
|
|
@@ -2441,13 +3031,47 @@ var MODELS = [
|
|
|
2441
3031
|
maxThinkingLevel: "ultra"
|
|
2442
3032
|
},
|
|
2443
3033
|
{
|
|
2444
|
-
// Codex Fast mode for 6.
|
|
2445
|
-
// `gpt-6-astra-fast` for the wire mapping and billing.
|
|
2446
|
-
id: "gpt-6.
|
|
2447
|
-
name: "GPT-6.
|
|
3034
|
+
// Codex Fast mode for 6.2 Sol ("2x speed, increased usage") — see
|
|
3035
|
+
// `gpt-6.2-astra-fast` for the wire mapping and billing.
|
|
3036
|
+
id: "gpt-6.2-sol-fast",
|
|
3037
|
+
name: "GPT-6.2 Sol Fast",
|
|
2448
3038
|
provider: "openai",
|
|
2449
3039
|
contextWindow: 105e4,
|
|
2450
|
-
codexContextWindow:
|
|
3040
|
+
codexContextWindow: 5e5,
|
|
3041
|
+
maxOutputTokens: 128e3,
|
|
3042
|
+
supportsThinking: true,
|
|
3043
|
+
defaultThinkingLevel: "low",
|
|
3044
|
+
supportsImages: true,
|
|
3045
|
+
supportsVideo: false,
|
|
3046
|
+
costTier: "medium",
|
|
3047
|
+
maxThinkingLevel: "ultra",
|
|
3048
|
+
billing: CODEX_FAST_BILLING
|
|
3049
|
+
},
|
|
3050
|
+
{
|
|
3051
|
+
// GPT-6.1 Terra (Codex priority 7, default low, client >= 0.153.0). $1/$5
|
|
3052
|
+
// MTok, cached input $0.05. Unlike Sol/Astra the Codex route gets a 500K
|
|
3053
|
+
// window (catalog `context_window`). Same ladder and Ultra preset as Sol.
|
|
3054
|
+
id: "gpt-6.1-terra",
|
|
3055
|
+
name: "GPT-6.1 Terra",
|
|
3056
|
+
provider: "openai",
|
|
3057
|
+
contextWindow: 105e4,
|
|
3058
|
+
codexContextWindow: 5e5,
|
|
3059
|
+
maxOutputTokens: 128e3,
|
|
3060
|
+
supportsThinking: true,
|
|
3061
|
+
defaultThinkingLevel: "low",
|
|
3062
|
+
supportsImages: true,
|
|
3063
|
+
supportsVideo: false,
|
|
3064
|
+
costTier: "medium",
|
|
3065
|
+
maxThinkingLevel: "ultra"
|
|
3066
|
+
},
|
|
3067
|
+
{
|
|
3068
|
+
// Codex Fast mode for 6.1 Terra ("1.5x speed") — see `gpt-6.2-astra-fast`
|
|
3069
|
+
// for the wire mapping and billing.
|
|
3070
|
+
id: "gpt-6.1-terra-fast",
|
|
3071
|
+
name: "GPT-6.1 Terra Fast",
|
|
3072
|
+
provider: "openai",
|
|
3073
|
+
contextWindow: 105e4,
|
|
3074
|
+
codexContextWindow: 5e5,
|
|
2451
3075
|
maxOutputTokens: 128e3,
|
|
2452
3076
|
supportsThinking: true,
|
|
2453
3077
|
defaultThinkingLevel: "low",
|
|
@@ -2475,7 +3099,7 @@ var MODELS = [
|
|
|
2475
3099
|
maxThinkingLevel: "max"
|
|
2476
3100
|
},
|
|
2477
3101
|
{
|
|
2478
|
-
// Codex Fast mode for Luna ("1.5x speed") — see `gpt-6-astra-fast` for the
|
|
3102
|
+
// Codex Fast mode for Luna ("1.5x speed") — see `gpt-6.2-astra-fast` for the
|
|
2479
3103
|
// wire mapping and billing. Listed after Luna so compaction summaries
|
|
2480
3104
|
// (first `low` OpenAI model) stay on standard-speed Luna.
|
|
2481
3105
|
id: "gpt-6-luna-fast",
|
|
@@ -2761,6 +3385,23 @@ var MODELS = [
|
|
|
2761
3385
|
maxThinkingLevel: "max"
|
|
2762
3386
|
},
|
|
2763
3387
|
// ── MiniMax ────────────────────────────────────────────
|
|
3388
|
+
{
|
|
3389
|
+
// The only text model M Plan / Token Plan keys cover; MiniMax-M3 on those
|
|
3390
|
+
// keys fails with "insufficient balance (1008)". Pay-as-you-go serves both.
|
|
3391
|
+
// Always thinks (`thinking: disabled` 400s; omitted = on) with a real
|
|
3392
|
+
// low→max effort ladder on output_config.effort, API default max.
|
|
3393
|
+
id: "MiniMax-M3.1-Flash",
|
|
3394
|
+
name: "MiniMax M3.1 Flash",
|
|
3395
|
+
provider: "minimax",
|
|
3396
|
+
contextWindow: 1e6,
|
|
3397
|
+
maxOutputTokens: 131072,
|
|
3398
|
+
supportsThinking: true,
|
|
3399
|
+
supportsImages: true,
|
|
3400
|
+
supportsVideo: true,
|
|
3401
|
+
maxVideoBytes: 50 * 1024 * 1024,
|
|
3402
|
+
costTier: "low",
|
|
3403
|
+
maxThinkingLevel: "max"
|
|
3404
|
+
},
|
|
2764
3405
|
{
|
|
2765
3406
|
id: "MiniMax-M3",
|
|
2766
3407
|
name: "MiniMax M3",
|
|
@@ -2906,6 +3547,93 @@ var MODELS = [
|
|
|
2906
3547
|
costTier: "medium",
|
|
2907
3548
|
maxThinkingLevel: "high"
|
|
2908
3549
|
},
|
|
3550
|
+
// ── OpenCode Console (Go subscription, then pay-as-you-go) ────────
|
|
3551
|
+
// One Console API key reaches many labs' models through opencode.ai. Ids
|
|
3552
|
+
// carry the plan prefix (`opencode-go/kimi-k3`) because the gateway reuses
|
|
3553
|
+
// the vendors' own ids; @prestyj/ai strips it at the wire. These rows are only the
|
|
3554
|
+
// offline fallback: the desktop app replaces them with each plan's live,
|
|
3555
|
+
// public model list (core/opencode-catalog-store.ts). Limits, image input
|
|
3556
|
+
// and effort ladders are from GET /inference[/go]/v1/models (2026-11-11);
|
|
3557
|
+
// all three speak Chat Completions natively.
|
|
3558
|
+
{
|
|
3559
|
+
// Go declares `max` as K3's only effort; pay-as-you-go adds low and high.
|
|
3560
|
+
id: "opencode-go/kimi-k3",
|
|
3561
|
+
name: "Kimi K3",
|
|
3562
|
+
provider: "opencode-go",
|
|
3563
|
+
contextWindow: 1048576,
|
|
3564
|
+
maxOutputTokens: 131072,
|
|
3565
|
+
supportsThinking: true,
|
|
3566
|
+
supportsImages: true,
|
|
3567
|
+
supportsVideo: false,
|
|
3568
|
+
costTier: "high",
|
|
3569
|
+
maxThinkingLevel: "max",
|
|
3570
|
+
thinkingLevels: ["max"]
|
|
3571
|
+
},
|
|
3572
|
+
{
|
|
3573
|
+
id: "opencode-go/glm-5.3",
|
|
3574
|
+
name: "GLM-5.3",
|
|
3575
|
+
provider: "opencode-go",
|
|
3576
|
+
contextWindow: 1e6,
|
|
3577
|
+
maxOutputTokens: 131072,
|
|
3578
|
+
supportsThinking: true,
|
|
3579
|
+
supportsImages: false,
|
|
3580
|
+
supportsVideo: false,
|
|
3581
|
+
costTier: "medium",
|
|
3582
|
+
maxThinkingLevel: "max",
|
|
3583
|
+
thinkingLevels: ["low", "high", "max"]
|
|
3584
|
+
},
|
|
3585
|
+
{
|
|
3586
|
+
id: "opencode-go/glm-5.3-flash",
|
|
3587
|
+
name: "GLM-5.3-Flash",
|
|
3588
|
+
provider: "opencode-go",
|
|
3589
|
+
contextWindow: 1e6,
|
|
3590
|
+
maxOutputTokens: 131072,
|
|
3591
|
+
supportsThinking: true,
|
|
3592
|
+
supportsImages: true,
|
|
3593
|
+
supportsVideo: false,
|
|
3594
|
+
costTier: "low",
|
|
3595
|
+
maxThinkingLevel: "max",
|
|
3596
|
+
thinkingLevels: ["low", "high", "max"]
|
|
3597
|
+
},
|
|
3598
|
+
{
|
|
3599
|
+
id: "opencode/kimi-k3",
|
|
3600
|
+
name: "Kimi K3",
|
|
3601
|
+
provider: "opencode",
|
|
3602
|
+
contextWindow: 1048576,
|
|
3603
|
+
maxOutputTokens: 131072,
|
|
3604
|
+
supportsThinking: true,
|
|
3605
|
+
supportsImages: true,
|
|
3606
|
+
supportsVideo: false,
|
|
3607
|
+
costTier: "high",
|
|
3608
|
+
maxThinkingLevel: "max",
|
|
3609
|
+
thinkingLevels: ["low", "high", "max"]
|
|
3610
|
+
},
|
|
3611
|
+
{
|
|
3612
|
+
id: "opencode/glm-5.3",
|
|
3613
|
+
name: "GLM-5.3",
|
|
3614
|
+
provider: "opencode",
|
|
3615
|
+
contextWindow: 1e6,
|
|
3616
|
+
maxOutputTokens: 131072,
|
|
3617
|
+
supportsThinking: true,
|
|
3618
|
+
supportsImages: false,
|
|
3619
|
+
supportsVideo: false,
|
|
3620
|
+
costTier: "medium",
|
|
3621
|
+
maxThinkingLevel: "max",
|
|
3622
|
+
thinkingLevels: ["low", "high", "max"]
|
|
3623
|
+
},
|
|
3624
|
+
{
|
|
3625
|
+
id: "opencode/glm-5.3-flash",
|
|
3626
|
+
name: "GLM-5.3-Flash",
|
|
3627
|
+
provider: "opencode",
|
|
3628
|
+
contextWindow: 1e6,
|
|
3629
|
+
maxOutputTokens: 131072,
|
|
3630
|
+
supportsThinking: true,
|
|
3631
|
+
supportsImages: true,
|
|
3632
|
+
supportsVideo: false,
|
|
3633
|
+
costTier: "low",
|
|
3634
|
+
maxThinkingLevel: "max",
|
|
3635
|
+
thinkingLevels: ["low", "high", "max"]
|
|
3636
|
+
},
|
|
2909
3637
|
// ── Hugging Face (Inference Providers router) ────────
|
|
2910
3638
|
// One HF token (hf.co/settings/tokens, "Make calls to Inference Providers"
|
|
2911
3639
|
// permission) routes to whichever hosted backend serves each open model;
|
|
@@ -2983,15 +3711,51 @@ function clearRuntimeModels(predicate) {
|
|
|
2983
3711
|
if (predicate(model)) runtimeModels.delete(id);
|
|
2984
3712
|
}
|
|
2985
3713
|
}
|
|
3714
|
+
var providerCatalogs = /* @__PURE__ */ new Map();
|
|
3715
|
+
function setProviderCatalog(provider, models) {
|
|
3716
|
+
if (!models) {
|
|
3717
|
+
providerCatalogs.delete(provider);
|
|
3718
|
+
return [];
|
|
3719
|
+
}
|
|
3720
|
+
const installed = /* @__PURE__ */ new Map();
|
|
3721
|
+
for (const model of models) {
|
|
3722
|
+
if (model.provider !== provider) continue;
|
|
3723
|
+
if (MODELS.some((m) => m.id === model.id && m.provider !== provider)) continue;
|
|
3724
|
+
installed.set(model.id, model);
|
|
3725
|
+
}
|
|
3726
|
+
providerCatalogs.set(provider, installed);
|
|
3727
|
+
return [...installed.values()];
|
|
3728
|
+
}
|
|
3729
|
+
function getProviderCatalog(provider) {
|
|
3730
|
+
const catalog = providerCatalogs.get(provider);
|
|
3731
|
+
return catalog ? [...catalog.values()] : void 0;
|
|
3732
|
+
}
|
|
2986
3733
|
function getAllModels() {
|
|
2987
|
-
|
|
3734
|
+
const synced = [...providerCatalogs.values()].flatMap((c) => [...c.values()]);
|
|
3735
|
+
return [
|
|
3736
|
+
...MODELS.filter((m) => !providerCatalogs.has(m.provider)),
|
|
3737
|
+
...synced,
|
|
3738
|
+
...runtimeModels.values()
|
|
3739
|
+
];
|
|
2988
3740
|
}
|
|
2989
3741
|
function getModel(id) {
|
|
2990
|
-
|
|
3742
|
+
const fixed = MODELS.find((m) => m.id === id);
|
|
3743
|
+
if (fixed && !providerCatalogs.has(fixed.provider)) return fixed;
|
|
3744
|
+
return findSynced(id) ?? fixed ?? runtimeModels.get(id);
|
|
3745
|
+
}
|
|
3746
|
+
function findSynced(id) {
|
|
3747
|
+
for (const catalog of providerCatalogs.values()) {
|
|
3748
|
+
const hit = catalog.get(id);
|
|
3749
|
+
if (hit) return hit;
|
|
3750
|
+
}
|
|
3751
|
+
return void 0;
|
|
2991
3752
|
}
|
|
2992
3753
|
function getModelsForProvider(provider) {
|
|
2993
3754
|
return getAllModels().filter((m) => m.provider === provider);
|
|
2994
3755
|
}
|
|
3756
|
+
function getListedModels() {
|
|
3757
|
+
return getAllModels().filter((m) => !isHiddenProvider(m.provider));
|
|
3758
|
+
}
|
|
2995
3759
|
function isPaidModel(modelId) {
|
|
2996
3760
|
return getModel(modelId)?.billing?.paid === true;
|
|
2997
3761
|
}
|
|
@@ -3020,13 +3784,15 @@ function getVideoByteLimit(modelId) {
|
|
|
3020
3784
|
}
|
|
3021
3785
|
var DEFAULT_MODEL_IDS = {
|
|
3022
3786
|
xiaomi: "mimo-v2.6-pro",
|
|
3023
|
-
openai: "gpt-6.
|
|
3787
|
+
openai: "gpt-6.2-sol",
|
|
3024
3788
|
gemini: "gemini-3.1-flash-lite",
|
|
3025
3789
|
glm: "glm-5.3",
|
|
3026
3790
|
moonshot: "kimi-k3",
|
|
3027
|
-
minimax: "MiniMax-M3",
|
|
3791
|
+
minimax: "MiniMax-M3.1-Flash",
|
|
3028
3792
|
deepseek: "deepseek-v4-pro",
|
|
3029
3793
|
huggingface: "moonshotai/Kimi-K2.7-Code",
|
|
3794
|
+
opencode: "opencode/kimi-k3",
|
|
3795
|
+
"opencode-go": "opencode-go/kimi-k3",
|
|
3030
3796
|
openrouter: "qwen/qwen3.8-max",
|
|
3031
3797
|
sakana: "fugu",
|
|
3032
3798
|
xai: "grok-4.7"
|
|
@@ -3090,6 +3856,123 @@ function getSummaryModel(provider, currentModelId) {
|
|
|
3090
3856
|
return tagged ?? getModel(currentModelId) ?? getDefaultModel(provider);
|
|
3091
3857
|
}
|
|
3092
3858
|
|
|
3859
|
+
// src/openrouter-catalog.ts
|
|
3860
|
+
var OPENROUTER_DEFAULT_BASE_URL = "https://openrouter.ai/api/v1";
|
|
3861
|
+
var EFFORT_LADDER = ["low", "medium", "high", "xhigh", "max"];
|
|
3862
|
+
function positiveInt(value) {
|
|
3863
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
|
|
3864
|
+
}
|
|
3865
|
+
function strings(value) {
|
|
3866
|
+
return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
3867
|
+
}
|
|
3868
|
+
function costTier(prompt) {
|
|
3869
|
+
const perToken = typeof prompt === "string" ? Number(prompt) : NaN;
|
|
3870
|
+
if (!Number.isFinite(perToken) || perToken < 5e-7) return "low";
|
|
3871
|
+
return perToken < 3e-6 ? "medium" : "high";
|
|
3872
|
+
}
|
|
3873
|
+
function parseOpenRouterCatalog(body) {
|
|
3874
|
+
const data = body?.data;
|
|
3875
|
+
if (!Array.isArray(data)) return { models: [], skipped: 0 };
|
|
3876
|
+
const models = [];
|
|
3877
|
+
let skipped = 0;
|
|
3878
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3879
|
+
for (const raw of data) {
|
|
3880
|
+
const id = typeof raw?.id === "string" ? raw.id.trim() : "";
|
|
3881
|
+
const params = strings(raw?.supported_parameters);
|
|
3882
|
+
const contextWindow = positiveInt(raw?.top_provider?.context_length) ?? positiveInt(raw?.context_length);
|
|
3883
|
+
if (!id || seen.has(id) || !params.includes("tools") || !contextWindow) {
|
|
3884
|
+
skipped++;
|
|
3885
|
+
continue;
|
|
3886
|
+
}
|
|
3887
|
+
seen.add(id);
|
|
3888
|
+
const efforts = strings(raw.reasoning?.supported_efforts);
|
|
3889
|
+
const ladder = EFFORT_LADDER.filter((rung) => efforts.includes(rung));
|
|
3890
|
+
const supportsThinking = ladder.length > 0 || params.includes("reasoning") || params.includes("reasoning_effort");
|
|
3891
|
+
const defaultEffort = raw.reasoning?.default_effort;
|
|
3892
|
+
const maxOutput = positiveInt(raw.top_provider?.max_completion_tokens) ?? Math.min(contextWindow, 16384);
|
|
3893
|
+
models.push({
|
|
3894
|
+
id,
|
|
3895
|
+
name: typeof raw.name === "string" && raw.name.trim() ? raw.name.trim() : id,
|
|
3896
|
+
provider: "openrouter",
|
|
3897
|
+
contextWindow,
|
|
3898
|
+
maxOutputTokens: Math.min(maxOutput, contextWindow),
|
|
3899
|
+
supportsThinking,
|
|
3900
|
+
supportsImages: strings(raw.architecture?.input_modalities).includes("image"),
|
|
3901
|
+
// Video needs a per-transport payload cap the catalog doesn't publish.
|
|
3902
|
+
supportsVideo: false,
|
|
3903
|
+
costTier: costTier(raw.pricing?.prompt),
|
|
3904
|
+
maxThinkingLevel: ladder[ladder.length - 1] ?? "high",
|
|
3905
|
+
...ladder.length > 0 ? { thinkingLevels: ladder } : {},
|
|
3906
|
+
...typeof defaultEffort === "string" && ladder.includes(defaultEffort) ? { defaultThinkingLevel: defaultEffort } : {}
|
|
3907
|
+
});
|
|
3908
|
+
}
|
|
3909
|
+
return { models, skipped };
|
|
3910
|
+
}
|
|
3911
|
+
|
|
3912
|
+
// src/opencode-catalog.ts
|
|
3913
|
+
var OPENCODE_PROVIDERS = ["opencode-go", "opencode"];
|
|
3914
|
+
var OPENCODE_CATALOG_URLS = {
|
|
3915
|
+
opencode: "https://opencode.ai/inference/v1/models",
|
|
3916
|
+
"opencode-go": "https://opencode.ai/inference/go/v1/models"
|
|
3917
|
+
};
|
|
3918
|
+
var EFFORT_LADDER2 = ["low", "medium", "high", "xhigh", "max"];
|
|
3919
|
+
function positiveInt2(value) {
|
|
3920
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
|
|
3921
|
+
}
|
|
3922
|
+
function strings2(value) {
|
|
3923
|
+
return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
3924
|
+
}
|
|
3925
|
+
function costTier2(price) {
|
|
3926
|
+
if (typeof price !== "number" || !Number.isFinite(price) || price < 0.5) return "low";
|
|
3927
|
+
return price < 3 ? "medium" : "high";
|
|
3928
|
+
}
|
|
3929
|
+
function formatOpenCodeModelId(provider, rawId) {
|
|
3930
|
+
return `${provider}/${rawId}`;
|
|
3931
|
+
}
|
|
3932
|
+
function parseOpenCodeCatalog(provider, body) {
|
|
3933
|
+
const data = body?.data;
|
|
3934
|
+
if (!Array.isArray(data)) return { models: [], skipped: 0 };
|
|
3935
|
+
const models = [];
|
|
3936
|
+
let skipped = 0;
|
|
3937
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3938
|
+
for (const raw of data) {
|
|
3939
|
+
const rawId = typeof raw?.id === "string" ? raw.id.trim() : "";
|
|
3940
|
+
const contextWindow = positiveInt2(raw?.limit?.context);
|
|
3941
|
+
const price = raw?.cost?.text?.input?.price;
|
|
3942
|
+
if (!/^[\w.:-]+$/.test(rawId) || seen.has(rawId) || raw.type !== "chat" || !raw.api?.["chat-completions"] || raw.capabilities?.tools?.supported !== true || !contextWindow || provider === "opencode" && price === 0) {
|
|
3943
|
+
skipped++;
|
|
3944
|
+
continue;
|
|
3945
|
+
}
|
|
3946
|
+
seen.add(rawId);
|
|
3947
|
+
const reasoning = raw.capabilities.reasoning;
|
|
3948
|
+
const efforts = strings2(reasoning?.effort);
|
|
3949
|
+
const ladder = EFFORT_LADDER2.filter((rung) => efforts.includes(rung));
|
|
3950
|
+
const defaultEffort = reasoning?.default?.type === "effort" ? reasoning.default.value : null;
|
|
3951
|
+
const maxOutput = Math.min(
|
|
3952
|
+
positiveInt2(raw.limit?.output) ?? 16384,
|
|
3953
|
+
Math.floor(contextWindow / 2)
|
|
3954
|
+
);
|
|
3955
|
+
models.push({
|
|
3956
|
+
id: formatOpenCodeModelId(provider, rawId),
|
|
3957
|
+
name: typeof raw.name === "string" && raw.name.trim() ? raw.name.trim() : rawId,
|
|
3958
|
+
provider,
|
|
3959
|
+
contextWindow,
|
|
3960
|
+
maxOutputTokens: Math.max(1, maxOutput),
|
|
3961
|
+
// Only a declared effort ladder counts: a model without one is never sent
|
|
3962
|
+
// a reasoning_effort it might reject.
|
|
3963
|
+
supportsThinking: ladder.length > 0,
|
|
3964
|
+
supportsImages: strings2(raw.modalities?.input).some((m) => m.startsWith("image")),
|
|
3965
|
+
// Video needs a per-transport payload cap the catalog doesn't publish.
|
|
3966
|
+
supportsVideo: false,
|
|
3967
|
+
costTier: costTier2(price),
|
|
3968
|
+
maxThinkingLevel: ladder[ladder.length - 1] ?? "low",
|
|
3969
|
+
...ladder.length > 0 ? { thinkingLevels: ladder } : {},
|
|
3970
|
+
...typeof defaultEffort === "string" && ladder.includes(defaultEffort) ? { defaultThinkingLevel: defaultEffort } : {}
|
|
3971
|
+
});
|
|
3972
|
+
}
|
|
3973
|
+
return { models, skipped };
|
|
3974
|
+
}
|
|
3975
|
+
|
|
3093
3976
|
// src/thinking-level.ts
|
|
3094
3977
|
var OPENAI_GPT_THINKING_LEVELS = ["medium", "high", "xhigh"];
|
|
3095
3978
|
var OPENAI_GPT_56_THINKING_LEVELS = [
|
|
@@ -3118,6 +4001,13 @@ var ANTHROPIC_ADAPTIVE_THINKING_LEVELS = [
|
|
|
3118
4001
|
];
|
|
3119
4002
|
var MOONSHOT_K3_THINKING_LEVELS = ["low", "high", "max"];
|
|
3120
4003
|
var GLM_THINKING_LEVELS = ["low", "medium", "high", "xhigh", "max"];
|
|
4004
|
+
var MINIMAX_EFFORT_THINKING_LEVELS = [
|
|
4005
|
+
"low",
|
|
4006
|
+
"medium",
|
|
4007
|
+
"high",
|
|
4008
|
+
"xhigh",
|
|
4009
|
+
"max"
|
|
4010
|
+
];
|
|
3121
4011
|
var LOCAL_THINKING_LEVELS = ["low", "medium", "high", "max"];
|
|
3122
4012
|
function isOpenAIGptModel(provider, model) {
|
|
3123
4013
|
return provider === "openai" && model.startsWith("gpt-");
|
|
@@ -3134,8 +4024,11 @@ function isMoonshotK3Model(provider, model) {
|
|
|
3134
4024
|
function isGlmModel(provider) {
|
|
3135
4025
|
return provider === "glm";
|
|
3136
4026
|
}
|
|
4027
|
+
function isMiniMaxEffortModel(provider, model) {
|
|
4028
|
+
return provider === "minimax" && model.startsWith("MiniMax-M3.1");
|
|
4029
|
+
}
|
|
3137
4030
|
function isAnthropicXhighModel(provider, model) {
|
|
3138
|
-
return provider === "anthropic" && /opus-5|opus-4
|
|
4031
|
+
return provider === "anthropic" && /fable-5|mythos-5|opus-5|opus-4-8|opus-4-7|sonnet-5[-.]5|haiku-5[-.]5/.test(model);
|
|
3139
4032
|
}
|
|
3140
4033
|
function isAnthropicAdaptiveModel(provider, model) {
|
|
3141
4034
|
return provider === "anthropic" && /opus-5|opus-4[-.]8|opus-4[-.]7|opus-4[-.]6|sonnet-5|haiku-5|fable-5|mythos-5/.test(model);
|
|
@@ -3147,6 +4040,8 @@ function getSupportedThinkingLevels(provider, model) {
|
|
|
3147
4040
|
const maxIndex2 = LOCAL_THINKING_LEVELS.indexOf(info.maxThinkingLevel);
|
|
3148
4041
|
return maxIndex2 === -1 ? LOCAL_THINKING_LEVELS.slice(0, 3) : LOCAL_THINKING_LEVELS.slice(0, maxIndex2 + 1);
|
|
3149
4042
|
}
|
|
4043
|
+
const declared = getModel(model)?.thinkingLevels;
|
|
4044
|
+
if (declared && declared.length > 0) return declared;
|
|
3150
4045
|
const maxLevel = getMaxThinkingLevel(model);
|
|
3151
4046
|
if (isAnthropicAdaptiveModel(provider, model)) {
|
|
3152
4047
|
const levels2 = isAnthropicXhighModel(provider, model) ? ANTHROPIC_XHIGH_THINKING_LEVELS : ANTHROPIC_ADAPTIVE_THINKING_LEVELS;
|
|
@@ -3166,6 +4061,7 @@ function getSupportedThinkingLevels(provider, model) {
|
|
|
3166
4061
|
}
|
|
3167
4062
|
if (isMoonshotK3Model(provider, model)) return MOONSHOT_K3_THINKING_LEVELS;
|
|
3168
4063
|
if (provider === "deepseek") return DEEPSEEK_THINKING_LEVELS;
|
|
4064
|
+
if (isMiniMaxEffortModel(provider, model)) return MINIMAX_EFFORT_THINKING_LEVELS;
|
|
3169
4065
|
if (isGlmModel(provider)) {
|
|
3170
4066
|
const maxIndex2 = GLM_THINKING_LEVELS.indexOf(maxLevel);
|
|
3171
4067
|
if (maxIndex2 === -1) return GLM_THINKING_LEVELS;
|
|
@@ -3186,7 +4082,7 @@ function isThinkingLevelSupported(provider, model, level) {
|
|
|
3186
4082
|
}
|
|
3187
4083
|
function getNextThinkingLevel(provider, model, current) {
|
|
3188
4084
|
const supportedLevels = getSupportedThinkingLevels(provider, model);
|
|
3189
|
-
const shouldCycleLevels = isOpenAIGptModel(provider, model) || isAnthropicAdaptiveModel(provider, model) || isSakanaModel(provider) || isXaiModel(provider) || isMoonshotK3Model(provider, model) || isGlmModel(provider) || provider === "deepseek" || // Local servers take a real effort level, not just on/off: Ollama accepts
|
|
4085
|
+
const shouldCycleLevels = isOpenAIGptModel(provider, model) || isAnthropicAdaptiveModel(provider, model) || isSakanaModel(provider) || isXaiModel(provider) || isMoonshotK3Model(provider, model) || isGlmModel(provider) || isMiniMaxEffortModel(provider, model) || provider === "deepseek" || // Local servers take a real effort level, not just on/off: Ollama accepts
|
|
3190
4086
|
// low/medium/high on `reasoning_effort` (verified against 0.32) and the
|
|
3191
4087
|
// other OpenAI-compatible servers use the same three. A model that can't
|
|
3192
4088
|
// reason at all already has no supported levels, so it never gets here.
|
|
@@ -3214,11 +4110,12 @@ function clampThinkingForPlanMode(level) {
|
|
|
3214
4110
|
}
|
|
3215
4111
|
|
|
3216
4112
|
// src/local-models.ts
|
|
4113
|
+
var import_ai4 = require("@prestyj/ai");
|
|
3217
4114
|
var DEFAULT_LOCAL_ENDPOINTS = [
|
|
3218
4115
|
{ id: "ollama", label: "Ollama", baseUrl: "http://127.0.0.1:11434/v1", kind: "ollama" }
|
|
3219
4116
|
];
|
|
3220
4117
|
var FALLBACK_CONTEXT_WINDOW = 4096;
|
|
3221
|
-
var LOCAL_API_KEY_PLACEHOLDER =
|
|
4118
|
+
var LOCAL_API_KEY_PLACEHOLDER = import_ai4.LOCAL_NO_API_KEY;
|
|
3222
4119
|
var DEFAULT_PROBE_TIMEOUT_MS = 1200;
|
|
3223
4120
|
var ENRICH_CONCURRENCY = 6;
|
|
3224
4121
|
var CACHE_TTL_MS = 3e4;
|
|
@@ -3234,6 +4131,9 @@ function parseLocalModelId(id) {
|
|
|
3234
4131
|
if (slash <= 0 || slash === rest.length - 1) return void 0;
|
|
3235
4132
|
return { endpointId: rest.slice(0, slash), rawId: rest.slice(slash + 1) };
|
|
3236
4133
|
}
|
|
4134
|
+
function localModelShortName(rawId) {
|
|
4135
|
+
return rawId.slice(rawId.lastIndexOf("/") + 1) || rawId;
|
|
4136
|
+
}
|
|
3237
4137
|
function isLocalModelId(id) {
|
|
3238
4138
|
return parseLocalModelId(id) !== void 0;
|
|
3239
4139
|
}
|
|
@@ -3244,8 +4144,9 @@ function endpointRoot(baseUrl) {
|
|
|
3244
4144
|
return baseUrl.replace(/\/+$/, "").replace(/\/v1$/, "");
|
|
3245
4145
|
}
|
|
3246
4146
|
function authHeaders(endpoint) {
|
|
4147
|
+
const key = (0, import_ai4.localBearerKey)(endpoint.apiKey);
|
|
3247
4148
|
return {
|
|
3248
|
-
Authorization: `Bearer ${
|
|
4149
|
+
...key ? { Authorization: `Bearer ${key}` } : {},
|
|
3249
4150
|
Accept: "application/json"
|
|
3250
4151
|
};
|
|
3251
4152
|
}
|
|
@@ -3296,7 +4197,14 @@ async function probeEndpoint(endpoint, { timeoutMs = DEFAULT_PROBE_TIMEOUT_MS, s
|
|
|
3296
4197
|
const entries = (list.data ?? []).filter(
|
|
3297
4198
|
(entry) => typeof entry.id === "string" && entry.id.length > 0 && !NON_CHAT_ID_PATTERN.test(entry.id)
|
|
3298
4199
|
);
|
|
3299
|
-
const
|
|
4200
|
+
const enriched = await enrich(endpoint, entries, { timeoutMs, signal });
|
|
4201
|
+
const pinned = contextLength(endpoint.contextLength);
|
|
4202
|
+
const images = typeof endpoint.supportsImages === "boolean" ? endpoint.supportsImages : void 0;
|
|
4203
|
+
const models = enriched.map((m) => ({
|
|
4204
|
+
...m,
|
|
4205
|
+
...pinned === void 0 ? {} : { contextWindow: pinned, contextWindowKnown: true },
|
|
4206
|
+
...images === void 0 ? {} : { supportsImages: images }
|
|
4207
|
+
}));
|
|
3300
4208
|
log("INFO", "local-models", `Probed ${endpoint.label}`, {
|
|
3301
4209
|
baseUrl: endpoint.baseUrl,
|
|
3302
4210
|
models: String(models.length)
|
|
@@ -3307,10 +4215,22 @@ async function enrich(endpoint, entries, options) {
|
|
|
3307
4215
|
if (endpoint.kind === "lmstudio") return enrichLmStudio(endpoint, entries, options);
|
|
3308
4216
|
if (endpoint.kind === "ollama") return enrichOllama(endpoint, entries, options);
|
|
3309
4217
|
if (endpoint.kind === "llamacpp") return enrichLlamaCpp(endpoint, entries, options);
|
|
4218
|
+
if (endpoint.kind === "custom") return enrichCustom(endpoint, entries, options);
|
|
3310
4219
|
return entries.map((entry) => genericModel(endpoint, entry));
|
|
3311
4220
|
}
|
|
4221
|
+
async function enrichCustom(endpoint, entries, options) {
|
|
4222
|
+
const generic = entries.map((entry) => genericModel(endpoint, entry));
|
|
4223
|
+
if (generic.every((model) => model.contextWindowKnown)) return generic;
|
|
4224
|
+
const root = endpointRoot(endpoint.baseUrl);
|
|
4225
|
+
const props = await fetchJson(`${root}/props`, endpoint, options);
|
|
4226
|
+
const nCtx = contextLength(props?.default_generation_settings?.n_ctx);
|
|
4227
|
+
if (nCtx !== void 0) return llamaCppModels(endpoint, entries, nCtx, props);
|
|
4228
|
+
const lmStudio = await fetchJson(`${root}/api/v1/models`, endpoint, options);
|
|
4229
|
+
if (Array.isArray(lmStudio?.models)) return enrichLmStudio(endpoint, entries, options, lmStudio);
|
|
4230
|
+
return generic;
|
|
4231
|
+
}
|
|
3312
4232
|
function genericModel(endpoint, entry) {
|
|
3313
|
-
const declared = contextLength(entry.max_model_len);
|
|
4233
|
+
const declared = contextLength(entry.max_model_len) ?? contextLength(entry.context_length) ?? contextLength(entry.meta?.n_ctx);
|
|
3314
4234
|
return {
|
|
3315
4235
|
rawId: entry.id,
|
|
3316
4236
|
endpointId: endpoint.id,
|
|
@@ -3337,9 +4257,7 @@ async function enrichOllama(endpoint, entries, options) {
|
|
|
3337
4257
|
});
|
|
3338
4258
|
const caps = Array.isArray(show?.capabilities) ? show.capabilities : [];
|
|
3339
4259
|
if (caps.includes("embedding") && !caps.includes("completion")) return void 0;
|
|
3340
|
-
const ctx =
|
|
3341
|
-
runningModels.find((model) => model?.name === entry.id || model?.model === entry.id)?.context_length
|
|
3342
|
-
);
|
|
4260
|
+
const ctx = runningContext(runningModels, entry.id) ?? modelfileNumCtx(show?.parameters);
|
|
3343
4261
|
return {
|
|
3344
4262
|
rawId: entry.id,
|
|
3345
4263
|
endpointId: endpoint.id,
|
|
@@ -3354,12 +4272,41 @@ async function enrichOllama(endpoint, entries, options) {
|
|
|
3354
4272
|
});
|
|
3355
4273
|
return enriched.filter((model) => model !== void 0);
|
|
3356
4274
|
}
|
|
4275
|
+
function runningContext(models, rawId) {
|
|
4276
|
+
return contextLength(
|
|
4277
|
+
models.find((model) => model?.name === rawId || model?.model === rawId)?.context_length
|
|
4278
|
+
);
|
|
4279
|
+
}
|
|
4280
|
+
function modelfileNumCtx(parameters) {
|
|
4281
|
+
const match = /^num_ctx\s+(\d+)\s*$/m.exec(parameters ?? "");
|
|
4282
|
+
return match ? contextLength(Number(match[1])) : void 0;
|
|
4283
|
+
}
|
|
4284
|
+
async function ollamaServedContext(endpoint, rawId, {
|
|
4285
|
+
load = false,
|
|
4286
|
+
timeoutMs = 12e4,
|
|
4287
|
+
signal
|
|
4288
|
+
} = {}) {
|
|
4289
|
+
const root = endpointRoot(endpoint.baseUrl);
|
|
4290
|
+
if (load) {
|
|
4291
|
+
await fetchJson(`${root}/api/generate`, endpoint, {
|
|
4292
|
+
timeoutMs,
|
|
4293
|
+
signal,
|
|
4294
|
+
method: "POST",
|
|
4295
|
+
body: { model: rawId }
|
|
4296
|
+
});
|
|
4297
|
+
}
|
|
4298
|
+
const running = await fetchJson(`${root}/api/ps`, endpoint, {
|
|
4299
|
+
timeoutMs: DEFAULT_PROBE_TIMEOUT_MS,
|
|
4300
|
+
signal
|
|
4301
|
+
});
|
|
4302
|
+
return runningContext(Array.isArray(running?.models) ? running.models : [], rawId);
|
|
4303
|
+
}
|
|
3357
4304
|
function contextLength(value) {
|
|
3358
4305
|
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
|
|
3359
4306
|
}
|
|
3360
|
-
async function enrichLmStudio(endpoint, entries, options) {
|
|
4307
|
+
async function enrichLmStudio(endpoint, entries, options, fetched) {
|
|
3361
4308
|
const root = endpointRoot(endpoint.baseUrl);
|
|
3362
|
-
const detail = await fetchJson(`${root}/api/v1/models`, endpoint, options);
|
|
4309
|
+
const detail = fetched ?? await fetchJson(`${root}/api/v1/models`, endpoint, options);
|
|
3363
4310
|
const byId = /* @__PURE__ */ new Map();
|
|
3364
4311
|
if (Array.isArray(detail?.models)) {
|
|
3365
4312
|
for (const model of detail.models) {
|
|
@@ -3417,12 +4364,19 @@ async function enrichLlamaCpp(endpoint, entries, options) {
|
|
|
3417
4364
|
endpoint,
|
|
3418
4365
|
options
|
|
3419
4366
|
);
|
|
3420
|
-
|
|
3421
|
-
|
|
4367
|
+
return llamaCppModels(
|
|
4368
|
+
endpoint,
|
|
4369
|
+
entries,
|
|
4370
|
+
contextLength(props?.default_generation_settings?.n_ctx),
|
|
4371
|
+
props
|
|
4372
|
+
);
|
|
4373
|
+
}
|
|
4374
|
+
function llamaCppModels(endpoint, entries, nCtx, props) {
|
|
3422
4375
|
return entries.map((entry) => ({
|
|
3423
4376
|
...genericModel(endpoint, entry),
|
|
3424
|
-
contextWindow:
|
|
3425
|
-
contextWindowKnown:
|
|
4377
|
+
contextWindow: nCtx ?? FALLBACK_CONTEXT_WINDOW,
|
|
4378
|
+
contextWindowKnown: nCtx !== void 0,
|
|
4379
|
+
supportsImages: props?.modalities?.vision === true
|
|
3426
4380
|
}));
|
|
3427
4381
|
}
|
|
3428
4382
|
async function mapLimited(items, limit, fn) {
|
|
@@ -3458,7 +4412,7 @@ function toModelInfo(model, endpoint) {
|
|
|
3458
4412
|
}
|
|
3459
4413
|
var cache;
|
|
3460
4414
|
function cacheKey(endpoints) {
|
|
3461
|
-
return endpoints.map((e) => `${e.id}@${e.baseUrl}`).join("|");
|
|
4415
|
+
return endpoints.map((e) => `${e.id}@${e.baseUrl}#${e.contextLength ?? ""}#${e.supportsImages ?? ""}`).join("|");
|
|
3462
4416
|
}
|
|
3463
4417
|
async function discoverLocalModels(endpoints = DEFAULT_LOCAL_ENDPOINTS, options = {}) {
|
|
3464
4418
|
const key = cacheKey(endpoints);
|
|
@@ -3487,18 +4441,131 @@ function findProbedModel(probes, modelId) {
|
|
|
3487
4441
|
return void 0;
|
|
3488
4442
|
}
|
|
3489
4443
|
|
|
4444
|
+
// src/point-scale.ts
|
|
4445
|
+
var NORM1000_PATTERN = /qwen3[-_.]?vl|qwen3[._]?[56](?![\d])/i;
|
|
4446
|
+
function pointScale(modelId) {
|
|
4447
|
+
return NORM1000_PATTERN.test(modelId) ? "norm1000" : "pixels";
|
|
4448
|
+
}
|
|
4449
|
+
|
|
4450
|
+
// src/claude-code/usage.ts
|
|
4451
|
+
var import_promises6 = __toESM(require("fs/promises"), 1);
|
|
4452
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
4453
|
+
var USAGE_FILE = "usage.json";
|
|
4454
|
+
var WINDOWS = {
|
|
4455
|
+
five_hour: { kind: "current", label: "5-hour" },
|
|
4456
|
+
seven_day: { kind: "weekly", label: "Weekly" }
|
|
4457
|
+
};
|
|
4458
|
+
function finite(value) {
|
|
4459
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
4460
|
+
}
|
|
4461
|
+
function toWindow(key, raw) {
|
|
4462
|
+
const shape = WINDOWS[key];
|
|
4463
|
+
const fraction = finite(raw?.utilization);
|
|
4464
|
+
if (!shape || fraction === void 0) return null;
|
|
4465
|
+
const resetsAt = finite(raw?.resetsAt);
|
|
4466
|
+
return {
|
|
4467
|
+
...shape,
|
|
4468
|
+
usedPercent: Math.min(100, Math.max(0, fraction * 100)),
|
|
4469
|
+
...resetsAt !== void 0 ? { resetsAt: resetsAt * 1e3 } : {}
|
|
4470
|
+
};
|
|
4471
|
+
}
|
|
4472
|
+
function mergeClaudeCodeRateLimit(info, previous, now = Date.now()) {
|
|
4473
|
+
const reported = info.unifiedWindows ? Object.entries(info.unifiedWindows).map(([key, raw]) => toWindow(key, raw)) : info.rateLimitType ? [toWindow(info.rateLimitType, info)] : [];
|
|
4474
|
+
const byKind = new Map(previous?.windows.map((w) => [w.kind, w]) ?? []);
|
|
4475
|
+
for (const window of reported) if (window) byKind.set(window.kind, window);
|
|
4476
|
+
const windows = [...byKind.values()].sort(
|
|
4477
|
+
(a, b) => a.kind === b.kind ? 0 : a.kind === "current" ? -1 : 1
|
|
4478
|
+
);
|
|
4479
|
+
return { provider: "anthropic", displayName: "Anthropic", windows, fetchedAt: now };
|
|
4480
|
+
}
|
|
4481
|
+
function usagePath(opts) {
|
|
4482
|
+
return import_node_path5.default.join(claudeCodeHome(opts), USAGE_FILE);
|
|
4483
|
+
}
|
|
4484
|
+
async function readClaudeCodeUsage(opts = {}) {
|
|
4485
|
+
let parsed;
|
|
4486
|
+
try {
|
|
4487
|
+
parsed = JSON.parse(await import_promises6.default.readFile(usagePath(opts), "utf8"));
|
|
4488
|
+
} catch {
|
|
4489
|
+
return null;
|
|
4490
|
+
}
|
|
4491
|
+
if (!Array.isArray(parsed?.windows) || typeof parsed.fetchedAt !== "number") return null;
|
|
4492
|
+
const now = opts.now ?? Date.now();
|
|
4493
|
+
const windows = parsed.windows.filter(
|
|
4494
|
+
(w) => (w.kind === "current" || w.kind === "weekly") && typeof w.usedPercent === "number" && (w.resetsAt === void 0 || w.resetsAt > now)
|
|
4495
|
+
);
|
|
4496
|
+
return { provider: "anthropic", displayName: "Anthropic", windows, fetchedAt: parsed.fetchedAt };
|
|
4497
|
+
}
|
|
4498
|
+
var writeQueue = Promise.resolve();
|
|
4499
|
+
function recordClaudeCodeRateLimit(info, opts = {}) {
|
|
4500
|
+
const write = async () => {
|
|
4501
|
+
const now = opts.now ?? Date.now();
|
|
4502
|
+
const next = mergeClaudeCodeRateLimit(info, await readClaudeCodeUsage({ ...opts, now }), now);
|
|
4503
|
+
if (next.windows.length === 0) return;
|
|
4504
|
+
const file = usagePath(opts);
|
|
4505
|
+
await import_promises6.default.mkdir(import_node_path5.default.dirname(file), { recursive: true });
|
|
4506
|
+
await import_promises6.default.writeFile(file, JSON.stringify(next), "utf8");
|
|
4507
|
+
};
|
|
4508
|
+
writeQueue = writeQueue.then(write).catch(() => {
|
|
4509
|
+
});
|
|
4510
|
+
return writeQueue;
|
|
4511
|
+
}
|
|
4512
|
+
async function clearClaudeCodeUsage(opts = {}) {
|
|
4513
|
+
await writeQueue;
|
|
4514
|
+
await import_promises6.default.rm(usagePath(opts), { force: true }).catch(() => {
|
|
4515
|
+
});
|
|
4516
|
+
}
|
|
4517
|
+
|
|
4518
|
+
// src/claude-code/sign-in.ts
|
|
4519
|
+
async function signInWithClaudeCode(auth, callbacks, opts = {}) {
|
|
4520
|
+
if (!opts.binary && !resolveClaudeCodeBinary(opts)) {
|
|
4521
|
+
callbacks.onStatus("Downloading Claude Code (one time)\u2026");
|
|
4522
|
+
await ensureClaudeCodeBinary({
|
|
4523
|
+
...opts,
|
|
4524
|
+
onProgress: (progress) => {
|
|
4525
|
+
callbacks.onStatus(formatClaudeCodeInstallProgress(progress));
|
|
4526
|
+
opts.onProgress?.(progress);
|
|
4527
|
+
}
|
|
4528
|
+
});
|
|
4529
|
+
}
|
|
4530
|
+
let status = await claudeCodeAuthStatus(opts);
|
|
4531
|
+
if (!status.loggedIn) {
|
|
4532
|
+
callbacks.onStatus("Opening Claude sign-in\u2026");
|
|
4533
|
+
await loginClaudeCode(callbacks, opts);
|
|
4534
|
+
status = await claudeCodeAuthStatus(opts);
|
|
4535
|
+
}
|
|
4536
|
+
if (!status.loggedIn) throw new Error("Claude sign-in didn't finish. Try again.");
|
|
4537
|
+
await auth.setClaudeCodeLogin();
|
|
4538
|
+
return status;
|
|
4539
|
+
}
|
|
4540
|
+
async function signOutOfClaudeCode(auth, opts = {}) {
|
|
4541
|
+
await auth.clearClaudeCodeLogin();
|
|
4542
|
+
await clearClaudeCodeUsage(opts);
|
|
4543
|
+
try {
|
|
4544
|
+
await logoutClaudeCode(opts);
|
|
4545
|
+
} catch (err) {
|
|
4546
|
+
log(
|
|
4547
|
+
"WARN",
|
|
4548
|
+
"auth",
|
|
4549
|
+
`claude auth logout failed: ${err instanceof Error ? err.message : String(err)}`
|
|
4550
|
+
);
|
|
4551
|
+
}
|
|
4552
|
+
}
|
|
4553
|
+
|
|
3490
4554
|
// src/auth-providers.ts
|
|
3491
|
-
|
|
4555
|
+
function apiKeyDetails(label, billing, when = "") {
|
|
4556
|
+
return { apikey: { method: "apikey", label, billing, when } };
|
|
4557
|
+
}
|
|
4558
|
+
var ALL_AUTH_PROVIDERS = [
|
|
3492
4559
|
{
|
|
3493
4560
|
value: "anthropic",
|
|
3494
4561
|
label: "Anthropic",
|
|
3495
|
-
description: "Claude Fable 5.
|
|
4562
|
+
description: "Claude Fable 5.2, Fable 5.2 Fast, Opus 5.5, Opus 5.5 Fast, Sonnet 5.5, Haiku 5.5",
|
|
3496
4563
|
methods: ["oauth"]
|
|
3497
4564
|
},
|
|
3498
4565
|
{
|
|
3499
4566
|
value: "openai",
|
|
3500
4567
|
label: "OpenAI",
|
|
3501
|
-
description: "GPT-6 Astra, GPT-6 Astra Fast, GPT-6.
|
|
4568
|
+
description: "GPT-6.2 Astra, GPT-6.2 Astra Fast, GPT-6.2 Sol, GPT-6.2 Sol Fast, GPT-6.1 Terra, GPT-6.1 Terra Fast, GPT-6 Luna, GPT-6 Luna Fast",
|
|
3502
4569
|
methods: ["oauth"]
|
|
3503
4570
|
},
|
|
3504
4571
|
{
|
|
@@ -3579,7 +4646,7 @@ var AUTH_PROVIDERS = [
|
|
|
3579
4646
|
{
|
|
3580
4647
|
value: "minimax",
|
|
3581
4648
|
label: "MiniMax",
|
|
3582
|
-
description: "MiniMax M3",
|
|
4649
|
+
description: "MiniMax M3.1 Flash, M3",
|
|
3583
4650
|
methods: ["apikey"],
|
|
3584
4651
|
apiKeyLabel: "MiniMax"
|
|
3585
4652
|
},
|
|
@@ -3617,6 +4684,30 @@ var AUTH_PROVIDERS = [
|
|
|
3617
4684
|
methods: ["apikey"],
|
|
3618
4685
|
apiKeyLabel: "Sakana"
|
|
3619
4686
|
},
|
|
4687
|
+
{
|
|
4688
|
+
value: "opencode-go",
|
|
4689
|
+
label: "OpenCode Go",
|
|
4690
|
+
description: "Kimi K3, GLM-5.3, GLM-5.3-Flash and more Go models",
|
|
4691
|
+
methods: ["apikey"],
|
|
4692
|
+
apiKeyLabel: "OpenCode",
|
|
4693
|
+
methodDetails: apiKeyDetails(
|
|
4694
|
+
"OpenCode API key",
|
|
4695
|
+
"Uses your OpenCode Go subscription.",
|
|
4696
|
+
"Create a personal API key in the OpenCode Console, in a workspace subscribed to Go."
|
|
4697
|
+
)
|
|
4698
|
+
},
|
|
4699
|
+
{
|
|
4700
|
+
value: "opencode",
|
|
4701
|
+
label: "OpenCode",
|
|
4702
|
+
description: "Kimi K3, GLM-5.3, GLM-5.3-Flash and more paid Console models",
|
|
4703
|
+
methods: ["apikey"],
|
|
4704
|
+
apiKeyLabel: "OpenCode",
|
|
4705
|
+
methodDetails: apiKeyDetails(
|
|
4706
|
+
"OpenCode API key",
|
|
4707
|
+
"Pay-per-token from your OpenCode Console credits.",
|
|
4708
|
+
"Free-tier models only run inside OpenCode, so they are not listed here."
|
|
4709
|
+
)
|
|
4710
|
+
},
|
|
3620
4711
|
{
|
|
3621
4712
|
value: "openrouter",
|
|
3622
4713
|
label: "OpenRouter",
|
|
@@ -3632,6 +4723,9 @@ var AUTH_PROVIDERS = [
|
|
|
3632
4723
|
apiKeyLabel: "Hugging Face"
|
|
3633
4724
|
}
|
|
3634
4725
|
];
|
|
4726
|
+
var AUTH_PROVIDERS = ALL_AUTH_PROVIDERS.filter(
|
|
4727
|
+
(p) => !isHiddenProvider(p.value)
|
|
4728
|
+
);
|
|
3635
4729
|
function getAuthProvider(value) {
|
|
3636
4730
|
return AUTH_PROVIDERS.find((p) => p.value === value);
|
|
3637
4731
|
}
|
|
@@ -4230,11 +5324,11 @@ async function transcribeVoice(fileUrl) {
|
|
|
4230
5324
|
}
|
|
4231
5325
|
|
|
4232
5326
|
// src/auto-update.ts
|
|
4233
|
-
var
|
|
4234
|
-
var
|
|
4235
|
-
var
|
|
5327
|
+
var import_node_child_process3 = require("child_process");
|
|
5328
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
5329
|
+
var import_node_path6 = __toESM(require("path"), 1);
|
|
4236
5330
|
var CHECK_INTERVAL_MS = 60 * 60 * 1e3;
|
|
4237
|
-
var
|
|
5331
|
+
var FETCH_TIMEOUT_MS = 1e4;
|
|
4238
5332
|
function compareVersions(a, b) {
|
|
4239
5333
|
const pa = a.split(".").map(Number);
|
|
4240
5334
|
const pb = b.split(".").map(Number);
|
|
@@ -4247,7 +5341,7 @@ function compareVersions(a, b) {
|
|
|
4247
5341
|
function performUpdateInBackground(command) {
|
|
4248
5342
|
try {
|
|
4249
5343
|
const parts = command.split(" ");
|
|
4250
|
-
const child = (0,
|
|
5344
|
+
const child = (0, import_node_child_process3.spawn)(parts[0], parts.slice(1), {
|
|
4251
5345
|
detached: true,
|
|
4252
5346
|
stdio: "ignore",
|
|
4253
5347
|
env: { ...process.env, npm_config_loglevel: "silent" }
|
|
@@ -4265,7 +5359,7 @@ function createAutoUpdater(config) {
|
|
|
4265
5359
|
}
|
|
4266
5360
|
function readState() {
|
|
4267
5361
|
try {
|
|
4268
|
-
const raw =
|
|
5362
|
+
const raw = import_node_fs6.default.readFileSync(stateFilePath(), "utf-8");
|
|
4269
5363
|
return JSON.parse(raw);
|
|
4270
5364
|
} catch {
|
|
4271
5365
|
return null;
|
|
@@ -4274,8 +5368,8 @@ function createAutoUpdater(config) {
|
|
|
4274
5368
|
function writeState(state) {
|
|
4275
5369
|
try {
|
|
4276
5370
|
const filePath = stateFilePath();
|
|
4277
|
-
|
|
4278
|
-
|
|
5371
|
+
import_node_fs6.default.mkdirSync(import_node_path6.default.dirname(filePath), { recursive: true, mode: 448 });
|
|
5372
|
+
import_node_fs6.default.writeFileSync(filePath, JSON.stringify(state));
|
|
4279
5373
|
} catch {
|
|
4280
5374
|
}
|
|
4281
5375
|
}
|
|
@@ -4304,7 +5398,7 @@ function createAutoUpdater(config) {
|
|
|
4304
5398
|
async function fetchLatestVersion() {
|
|
4305
5399
|
try {
|
|
4306
5400
|
const controller = new AbortController();
|
|
4307
|
-
const timeout = setTimeout(() => controller.abort(),
|
|
5401
|
+
const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
4308
5402
|
const response = await fetch(REGISTRY_URL, { signal: controller.signal });
|
|
4309
5403
|
clearTimeout(timeout);
|
|
4310
5404
|
const data = await response.json();
|
|
@@ -4401,38 +5495,60 @@ function createAutoUpdater(config) {
|
|
|
4401
5495
|
0 && (module.exports = {
|
|
4402
5496
|
AUTH_PROVIDERS,
|
|
4403
5497
|
AuthStorage,
|
|
5498
|
+
CLAUDE_CODE_AUTH_KEY,
|
|
5499
|
+
CLAUDE_CODE_AUTH_MARKER,
|
|
5500
|
+
CLAUDE_CODE_MANIFEST,
|
|
4404
5501
|
DEFAULT_LOCAL_ENDPOINTS,
|
|
4405
5502
|
DEFAULT_MAX_VIDEO_BYTES,
|
|
4406
5503
|
FALLBACK_CONTEXT_WINDOW,
|
|
4407
5504
|
GEMINI_API_KEY,
|
|
4408
5505
|
GEMINI_API_KEY_BASE_URL,
|
|
5506
|
+
HIDDEN_PROVIDERS,
|
|
4409
5507
|
LOCAL_API_KEY_PLACEHOLDER,
|
|
4410
5508
|
LOCAL_AUTH_KEY_PREFIX,
|
|
5509
|
+
MINIMAX_CN_BASE_URL,
|
|
5510
|
+
MINIMAX_GLOBAL_BASE_URL,
|
|
4411
5511
|
MODELS,
|
|
4412
5512
|
MOONSHOT_OAUTH_KEY,
|
|
4413
5513
|
NotLoggedInError,
|
|
5514
|
+
OPENCODE_CATALOG_URLS,
|
|
5515
|
+
OPENCODE_PROVIDERS,
|
|
5516
|
+
OPENROUTER_DEFAULT_BASE_URL,
|
|
4414
5517
|
PLAN_MODE_THINKING_CAP,
|
|
4415
5518
|
SubscriptionUsageError,
|
|
4416
5519
|
TelegramBot,
|
|
4417
5520
|
XAI_OAUTH_KEY,
|
|
4418
5521
|
XIAOMI_CREDITS_KEY,
|
|
5522
|
+
XIAOMI_TOKEN_PLAN_BASE_URLS,
|
|
4419
5523
|
authPriorityNote,
|
|
4420
5524
|
clampThinkingForPlanMode,
|
|
5525
|
+
claudeCodeAuthStatus,
|
|
5526
|
+
claudeCodeBinaryPath,
|
|
5527
|
+
claudeCodeCallbackUrl,
|
|
5528
|
+
claudeCodeConfigDir,
|
|
5529
|
+
claudeCodeEnv,
|
|
5530
|
+
claudeCodeHome,
|
|
5531
|
+
claudeCodePlatformKey,
|
|
5532
|
+
clearClaudeCodeUsage,
|
|
4421
5533
|
clearLocalDiscoveryCache,
|
|
4422
5534
|
clearRuntimeModels,
|
|
4423
5535
|
closeLogger,
|
|
4424
|
-
compareClaudeCodeVersions,
|
|
4425
5536
|
createAutoUpdater,
|
|
4426
5537
|
decodeOggOpus,
|
|
4427
5538
|
describeAuthMethods,
|
|
5539
|
+
detectMiniMaxBaseUrl,
|
|
5540
|
+
detectXiaomiTokenPlanBaseUrl,
|
|
4428
5541
|
discoverLocalModels,
|
|
4429
5542
|
downmixToMono,
|
|
4430
5543
|
dualAuthProvider,
|
|
4431
5544
|
dualAuthProviderByOAuthKey,
|
|
4432
5545
|
endpointRoot,
|
|
5546
|
+
ensureClaudeCodeBinary,
|
|
4433
5547
|
fetchSubscriptionUsage,
|
|
4434
5548
|
findProbedModel,
|
|
5549
|
+
formatClaudeCodeInstallProgress,
|
|
4435
5550
|
formatLocalModelId,
|
|
5551
|
+
formatOpenCodeModelId,
|
|
4436
5552
|
generatePKCE,
|
|
4437
5553
|
getAllModels,
|
|
4438
5554
|
getAppPaths,
|
|
@@ -4444,11 +5560,13 @@ function createAutoUpdater(config) {
|
|
|
4444
5560
|
getContextWindow,
|
|
4445
5561
|
getDefaultModel,
|
|
4446
5562
|
getDefaultThinkingLevel,
|
|
5563
|
+
getListedModels,
|
|
4447
5564
|
getLowestThinkingLevel,
|
|
4448
5565
|
getMaxThinkingLevel,
|
|
4449
5566
|
getModel,
|
|
4450
5567
|
getModelsForProvider,
|
|
4451
5568
|
getNextThinkingLevel,
|
|
5569
|
+
getProviderCatalog,
|
|
4452
5570
|
getSessionId,
|
|
4453
5571
|
getSummaryModel,
|
|
4454
5572
|
getSupportedThinkingLevels,
|
|
@@ -4456,8 +5574,11 @@ function createAutoUpdater(config) {
|
|
|
4456
5574
|
getVideoByteLimit,
|
|
4457
5575
|
grokCliBaseUrl,
|
|
4458
5576
|
grokCliHeaders,
|
|
5577
|
+
isClaudeCodeAuthMarker,
|
|
4459
5578
|
isGrokCliEndpoint,
|
|
5579
|
+
isHiddenProvider,
|
|
4460
5580
|
isKimiCodingEndpoint,
|
|
5581
|
+
isLegacyClaudeOAuth,
|
|
4461
5582
|
isLocalModelId,
|
|
4462
5583
|
isLoggerOpen,
|
|
4463
5584
|
isModelLoaded,
|
|
@@ -4466,19 +5587,29 @@ function createAutoUpdater(config) {
|
|
|
4466
5587
|
kimiCodeBaseUrl,
|
|
4467
5588
|
kimiCodingHeaders,
|
|
4468
5589
|
localAuthStorageKey,
|
|
5590
|
+
localModelShortName,
|
|
4469
5591
|
log,
|
|
4470
5592
|
loginAnthropic,
|
|
5593
|
+
loginClaudeCode,
|
|
4471
5594
|
loginGemini,
|
|
4472
5595
|
loginKimi,
|
|
4473
5596
|
loginOpenAI,
|
|
4474
5597
|
loginXai,
|
|
5598
|
+
logoutClaudeCode,
|
|
5599
|
+
mergeClaudeCodeRateLimit,
|
|
4475
5600
|
oauthStorageKey,
|
|
5601
|
+
ollamaServedContext,
|
|
4476
5602
|
openLog,
|
|
4477
5603
|
parseLocalModelId,
|
|
5604
|
+
parseOpenCodeCatalog,
|
|
5605
|
+
parseOpenRouterCatalog,
|
|
5606
|
+
pendingClaudeCodeVersionRefresh,
|
|
5607
|
+
pointScale,
|
|
4478
5608
|
probeEndpoint,
|
|
4479
5609
|
providerStorageKeys,
|
|
5610
|
+
readClaudeCodeUsage,
|
|
4480
5611
|
readStoredBaseUrlSync,
|
|
4481
|
-
|
|
5612
|
+
recordClaudeCodeRateLimit,
|
|
4482
5613
|
refreshAnthropicToken,
|
|
4483
5614
|
refreshGeminiToken,
|
|
4484
5615
|
refreshKimiToken,
|
|
@@ -4487,7 +5618,11 @@ function createAutoUpdater(config) {
|
|
|
4487
5618
|
registerLogCleanup,
|
|
4488
5619
|
registerRuntimeModels,
|
|
4489
5620
|
resample,
|
|
5621
|
+
resolveClaudeCodeBinary,
|
|
4490
5622
|
setProgressCallback,
|
|
5623
|
+
setProviderCatalog,
|
|
5624
|
+
signInWithClaudeCode,
|
|
5625
|
+
signOutOfClaudeCode,
|
|
4491
5626
|
toModelInfo,
|
|
4492
5627
|
transcribeVoice,
|
|
4493
5628
|
usesOpenAICodexTransport,
|