@prestyj/core 5.32.1 → 5.33.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/index.js CHANGED
@@ -1,19 +1,36 @@
1
1
  import {
2
2
  AuthStorage,
3
+ CLAUDE_CODE_AUTH_KEY,
4
+ CLAUDE_CODE_AUTH_MARKER,
5
+ CLAUDE_CODE_MANIFEST,
3
6
  DEFAULT_MAX_VIDEO_BYTES,
4
7
  GEMINI_API_KEY,
5
8
  GEMINI_API_KEY_BASE_URL,
9
+ HIDDEN_PROVIDERS,
6
10
  LOCAL_AUTH_KEY_PREFIX,
11
+ MINIMAX_CN_BASE_URL,
12
+ MINIMAX_GLOBAL_BASE_URL,
7
13
  MODELS,
8
14
  MOONSHOT_OAUTH_KEY,
9
15
  NotLoggedInError,
10
16
  XAI_OAUTH_KEY,
11
17
  XIAOMI_CREDITS_KEY,
18
+ XIAOMI_TOKEN_PLAN_BASE_URLS,
19
+ claudeCodeAuthStatus,
20
+ claudeCodeBinaryPath,
21
+ claudeCodeCallbackUrl,
22
+ claudeCodeConfigDir,
23
+ claudeCodeEnv,
24
+ claudeCodeHome,
25
+ claudeCodePlatformKey,
12
26
  clearRuntimeModels,
13
27
  closeLogger,
14
- compareClaudeCodeVersions,
28
+ detectMiniMaxBaseUrl,
29
+ detectXiaomiTokenPlanBaseUrl,
15
30
  dualAuthProvider,
16
31
  dualAuthProviderByOAuthKey,
32
+ ensureClaudeCodeBinary,
33
+ formatClaudeCodeInstallProgress,
17
34
  generatePKCE,
18
35
  getAllModels,
19
36
  getAuthStorageKey,
@@ -23,32 +40,39 @@ import {
23
40
  getContextWindow,
24
41
  getDefaultModel,
25
42
  getDefaultThinkingLevel,
43
+ getListedModels,
26
44
  getMaxThinkingLevel,
27
45
  getModel,
28
46
  getModelsForProvider,
47
+ getProviderCatalog,
29
48
  getSessionId,
30
49
  getSummaryModel,
31
50
  getToolResultCharLimit,
32
51
  getVideoByteLimit,
33
52
  grokCliBaseUrl,
34
53
  grokCliHeaders,
54
+ isClaudeCodeAuthMarker,
35
55
  isGrokCliEndpoint,
56
+ isHiddenProvider,
36
57
  isKimiCodingEndpoint,
58
+ isLegacyClaudeOAuth,
37
59
  isLoggerOpen,
38
60
  isPaidModel,
39
61
  kimiCodeBaseUrl,
40
62
  kimiCodingHeaders,
41
63
  log,
42
64
  loginAnthropic,
65
+ loginClaudeCode,
43
66
  loginGemini,
44
67
  loginKimi,
45
68
  loginOpenAI,
46
69
  loginXai,
70
+ logoutClaudeCode,
47
71
  oauthStorageKey,
48
72
  openLog,
73
+ pendingClaudeCodeVersionRefresh,
49
74
  providerStorageKeys,
50
75
  readStoredBaseUrlSync,
51
- recordRequiredClaudeCodeVersion,
52
76
  refreshAnthropicToken,
53
77
  refreshGeminiToken,
54
78
  refreshKimiToken,
@@ -56,13 +80,68 @@ import {
56
80
  refreshXaiToken,
57
81
  registerLogCleanup,
58
82
  registerRuntimeModels,
83
+ resolveClaudeCodeBinary,
84
+ setProviderCatalog,
59
85
  usesOpenAICodexTransport,
60
86
  withFileLock,
61
87
  withoutPaidTier
62
- } from "./chunk-XPXWXKRZ.js";
88
+ } from "./chunk-G3ZS4V2K.js";
63
89
  import {
64
90
  getAppPaths
65
- } from "./chunk-W4NHU4UL.js";
91
+ } from "./chunk-DVWS2KEW.js";
92
+
93
+ // src/openrouter-catalog.ts
94
+ var OPENROUTER_DEFAULT_BASE_URL = "https://openrouter.ai/api/v1";
95
+ var EFFORT_LADDER = ["low", "medium", "high", "xhigh", "max"];
96
+ function positiveInt(value) {
97
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
98
+ }
99
+ function strings(value) {
100
+ return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
101
+ }
102
+ function costTier(prompt) {
103
+ const perToken = typeof prompt === "string" ? Number(prompt) : NaN;
104
+ if (!Number.isFinite(perToken) || perToken < 5e-7) return "low";
105
+ return perToken < 3e-6 ? "medium" : "high";
106
+ }
107
+ function parseOpenRouterCatalog(body) {
108
+ const data = body?.data;
109
+ if (!Array.isArray(data)) return { models: [], skipped: 0 };
110
+ const models = [];
111
+ let skipped = 0;
112
+ const seen = /* @__PURE__ */ new Set();
113
+ for (const raw of data) {
114
+ const id = typeof raw?.id === "string" ? raw.id.trim() : "";
115
+ const params = strings(raw?.supported_parameters);
116
+ const contextWindow = positiveInt(raw?.top_provider?.context_length) ?? positiveInt(raw?.context_length);
117
+ if (!id || seen.has(id) || !params.includes("tools") || !contextWindow) {
118
+ skipped++;
119
+ continue;
120
+ }
121
+ seen.add(id);
122
+ const efforts = strings(raw.reasoning?.supported_efforts);
123
+ const ladder = EFFORT_LADDER.filter((rung) => efforts.includes(rung));
124
+ const supportsThinking = ladder.length > 0 || params.includes("reasoning") || params.includes("reasoning_effort");
125
+ const defaultEffort = raw.reasoning?.default_effort;
126
+ const maxOutput = positiveInt(raw.top_provider?.max_completion_tokens) ?? Math.min(contextWindow, 16384);
127
+ models.push({
128
+ id,
129
+ name: typeof raw.name === "string" && raw.name.trim() ? raw.name.trim() : id,
130
+ provider: "openrouter",
131
+ contextWindow,
132
+ maxOutputTokens: Math.min(maxOutput, contextWindow),
133
+ supportsThinking,
134
+ supportsImages: strings(raw.architecture?.input_modalities).includes("image"),
135
+ // Video needs a per-transport payload cap the catalog doesn't publish.
136
+ supportsVideo: false,
137
+ costTier: costTier(raw.pricing?.prompt),
138
+ maxThinkingLevel: ladder[ladder.length - 1] ?? "high",
139
+ ...ladder.length > 0 ? { thinkingLevels: ladder } : {},
140
+ ...typeof defaultEffort === "string" && ladder.includes(defaultEffort) ? { defaultThinkingLevel: defaultEffort } : {}
141
+ });
142
+ }
143
+ return { models, skipped };
144
+ }
66
145
 
67
146
  // src/thinking-level.ts
68
147
  var OPENAI_GPT_THINKING_LEVELS = ["medium", "high", "xhigh"];
@@ -92,6 +171,13 @@ var ANTHROPIC_ADAPTIVE_THINKING_LEVELS = [
92
171
  ];
93
172
  var MOONSHOT_K3_THINKING_LEVELS = ["low", "high", "max"];
94
173
  var GLM_THINKING_LEVELS = ["low", "medium", "high", "xhigh", "max"];
174
+ var MINIMAX_EFFORT_THINKING_LEVELS = [
175
+ "low",
176
+ "medium",
177
+ "high",
178
+ "xhigh",
179
+ "max"
180
+ ];
95
181
  var LOCAL_THINKING_LEVELS = ["low", "medium", "high", "max"];
96
182
  function isOpenAIGptModel(provider, model) {
97
183
  return provider === "openai" && model.startsWith("gpt-");
@@ -108,8 +194,11 @@ function isMoonshotK3Model(provider, model) {
108
194
  function isGlmModel(provider) {
109
195
  return provider === "glm";
110
196
  }
197
+ function isMiniMaxEffortModel(provider, model) {
198
+ return provider === "minimax" && model.startsWith("MiniMax-M3.1");
199
+ }
111
200
  function isAnthropicXhighModel(provider, model) {
112
- return provider === "anthropic" && /opus-5|opus-4[-.]8|opus-4[-.]7|sonnet-5[-.]5|haiku-5[-.]5/.test(model);
201
+ return provider === "anthropic" && /fable-5|mythos-5|opus-5|opus-4-8|opus-4-7|sonnet-5[-.]5|haiku-5[-.]5/.test(model);
113
202
  }
114
203
  function isAnthropicAdaptiveModel(provider, model) {
115
204
  return provider === "anthropic" && /opus-5|opus-4[-.]8|opus-4[-.]7|opus-4[-.]6|sonnet-5|haiku-5|fable-5|mythos-5/.test(model);
@@ -121,6 +210,8 @@ function getSupportedThinkingLevels(provider, model) {
121
210
  const maxIndex2 = LOCAL_THINKING_LEVELS.indexOf(info.maxThinkingLevel);
122
211
  return maxIndex2 === -1 ? LOCAL_THINKING_LEVELS.slice(0, 3) : LOCAL_THINKING_LEVELS.slice(0, maxIndex2 + 1);
123
212
  }
213
+ const declared = getModel(model)?.thinkingLevels;
214
+ if (declared && declared.length > 0) return declared;
124
215
  const maxLevel = getMaxThinkingLevel(model);
125
216
  if (isAnthropicAdaptiveModel(provider, model)) {
126
217
  const levels2 = isAnthropicXhighModel(provider, model) ? ANTHROPIC_XHIGH_THINKING_LEVELS : ANTHROPIC_ADAPTIVE_THINKING_LEVELS;
@@ -140,6 +231,7 @@ function getSupportedThinkingLevels(provider, model) {
140
231
  }
141
232
  if (isMoonshotK3Model(provider, model)) return MOONSHOT_K3_THINKING_LEVELS;
142
233
  if (provider === "deepseek") return DEEPSEEK_THINKING_LEVELS;
234
+ if (isMiniMaxEffortModel(provider, model)) return MINIMAX_EFFORT_THINKING_LEVELS;
143
235
  if (isGlmModel(provider)) {
144
236
  const maxIndex2 = GLM_THINKING_LEVELS.indexOf(maxLevel);
145
237
  if (maxIndex2 === -1) return GLM_THINKING_LEVELS;
@@ -160,7 +252,7 @@ function isThinkingLevelSupported(provider, model, level) {
160
252
  }
161
253
  function getNextThinkingLevel(provider, model, current) {
162
254
  const supportedLevels = getSupportedThinkingLevels(provider, model);
163
- 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
255
+ 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
164
256
  // low/medium/high on `reasoning_effort` (verified against 0.32) and the
165
257
  // other OpenAI-compatible servers use the same three. A model that can't
166
258
  // reason at all already has no supported levels, so it never gets here.
@@ -188,11 +280,12 @@ function clampThinkingForPlanMode(level) {
188
280
  }
189
281
 
190
282
  // src/local-models.ts
283
+ import { LOCAL_NO_API_KEY, localBearerKey } from "@prestyj/ai";
191
284
  var DEFAULT_LOCAL_ENDPOINTS = [
192
285
  { id: "ollama", label: "Ollama", baseUrl: "http://127.0.0.1:11434/v1", kind: "ollama" }
193
286
  ];
194
287
  var FALLBACK_CONTEXT_WINDOW = 4096;
195
- var LOCAL_API_KEY_PLACEHOLDER = "local";
288
+ var LOCAL_API_KEY_PLACEHOLDER = LOCAL_NO_API_KEY;
196
289
  var DEFAULT_PROBE_TIMEOUT_MS = 1200;
197
290
  var ENRICH_CONCURRENCY = 6;
198
291
  var CACHE_TTL_MS = 3e4;
@@ -208,6 +301,9 @@ function parseLocalModelId(id) {
208
301
  if (slash <= 0 || slash === rest.length - 1) return void 0;
209
302
  return { endpointId: rest.slice(0, slash), rawId: rest.slice(slash + 1) };
210
303
  }
304
+ function localModelShortName(rawId) {
305
+ return rawId.slice(rawId.lastIndexOf("/") + 1) || rawId;
306
+ }
211
307
  function isLocalModelId(id) {
212
308
  return parseLocalModelId(id) !== void 0;
213
309
  }
@@ -218,8 +314,9 @@ function endpointRoot(baseUrl) {
218
314
  return baseUrl.replace(/\/+$/, "").replace(/\/v1$/, "");
219
315
  }
220
316
  function authHeaders(endpoint) {
317
+ const key = localBearerKey(endpoint.apiKey);
221
318
  return {
222
- Authorization: `Bearer ${endpoint.apiKey ?? LOCAL_API_KEY_PLACEHOLDER}`,
319
+ ...key ? { Authorization: `Bearer ${key}` } : {},
223
320
  Accept: "application/json"
224
321
  };
225
322
  }
@@ -270,7 +367,9 @@ async function probeEndpoint(endpoint, { timeoutMs = DEFAULT_PROBE_TIMEOUT_MS, s
270
367
  const entries = (list.data ?? []).filter(
271
368
  (entry) => typeof entry.id === "string" && entry.id.length > 0 && !NON_CHAT_ID_PATTERN.test(entry.id)
272
369
  );
273
- const models = await enrich(endpoint, entries, { timeoutMs, signal });
370
+ const enriched = await enrich(endpoint, entries, { timeoutMs, signal });
371
+ const pinned = contextLength(endpoint.contextLength);
372
+ const models = pinned === void 0 ? enriched : enriched.map((m) => ({ ...m, contextWindow: pinned, contextWindowKnown: true }));
274
373
  log("INFO", "local-models", `Probed ${endpoint.label}`, {
275
374
  baseUrl: endpoint.baseUrl,
276
375
  models: String(models.length)
@@ -281,10 +380,22 @@ async function enrich(endpoint, entries, options) {
281
380
  if (endpoint.kind === "lmstudio") return enrichLmStudio(endpoint, entries, options);
282
381
  if (endpoint.kind === "ollama") return enrichOllama(endpoint, entries, options);
283
382
  if (endpoint.kind === "llamacpp") return enrichLlamaCpp(endpoint, entries, options);
383
+ if (endpoint.kind === "custom") return enrichCustom(endpoint, entries, options);
284
384
  return entries.map((entry) => genericModel(endpoint, entry));
285
385
  }
386
+ async function enrichCustom(endpoint, entries, options) {
387
+ const generic = entries.map((entry) => genericModel(endpoint, entry));
388
+ if (generic.every((model) => model.contextWindowKnown)) return generic;
389
+ const root = endpointRoot(endpoint.baseUrl);
390
+ const props = await fetchJson(`${root}/props`, endpoint, options);
391
+ const nCtx = contextLength(props?.default_generation_settings?.n_ctx);
392
+ if (nCtx !== void 0) return llamaCppModels(endpoint, entries, nCtx);
393
+ const lmStudio = await fetchJson(`${root}/api/v1/models`, endpoint, options);
394
+ if (Array.isArray(lmStudio?.models)) return enrichLmStudio(endpoint, entries, options, lmStudio);
395
+ return generic;
396
+ }
286
397
  function genericModel(endpoint, entry) {
287
- const declared = contextLength(entry.max_model_len);
398
+ const declared = contextLength(entry.max_model_len) ?? contextLength(entry.context_length) ?? contextLength(entry.meta?.n_ctx);
288
399
  return {
289
400
  rawId: entry.id,
290
401
  endpointId: endpoint.id,
@@ -311,9 +422,7 @@ async function enrichOllama(endpoint, entries, options) {
311
422
  });
312
423
  const caps = Array.isArray(show?.capabilities) ? show.capabilities : [];
313
424
  if (caps.includes("embedding") && !caps.includes("completion")) return void 0;
314
- const ctx = contextLength(
315
- runningModels.find((model) => model?.name === entry.id || model?.model === entry.id)?.context_length
316
- );
425
+ const ctx = runningContext(runningModels, entry.id) ?? modelfileNumCtx(show?.parameters);
317
426
  return {
318
427
  rawId: entry.id,
319
428
  endpointId: endpoint.id,
@@ -328,12 +437,41 @@ async function enrichOllama(endpoint, entries, options) {
328
437
  });
329
438
  return enriched.filter((model) => model !== void 0);
330
439
  }
440
+ function runningContext(models, rawId) {
441
+ return contextLength(
442
+ models.find((model) => model?.name === rawId || model?.model === rawId)?.context_length
443
+ );
444
+ }
445
+ function modelfileNumCtx(parameters) {
446
+ const match = /^num_ctx\s+(\d+)\s*$/m.exec(parameters ?? "");
447
+ return match ? contextLength(Number(match[1])) : void 0;
448
+ }
449
+ async function ollamaServedContext(endpoint, rawId, {
450
+ load = false,
451
+ timeoutMs = 12e4,
452
+ signal
453
+ } = {}) {
454
+ const root = endpointRoot(endpoint.baseUrl);
455
+ if (load) {
456
+ await fetchJson(`${root}/api/generate`, endpoint, {
457
+ timeoutMs,
458
+ signal,
459
+ method: "POST",
460
+ body: { model: rawId }
461
+ });
462
+ }
463
+ const running = await fetchJson(`${root}/api/ps`, endpoint, {
464
+ timeoutMs: DEFAULT_PROBE_TIMEOUT_MS,
465
+ signal
466
+ });
467
+ return runningContext(Array.isArray(running?.models) ? running.models : [], rawId);
468
+ }
331
469
  function contextLength(value) {
332
470
  return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : void 0;
333
471
  }
334
- async function enrichLmStudio(endpoint, entries, options) {
472
+ async function enrichLmStudio(endpoint, entries, options, fetched) {
335
473
  const root = endpointRoot(endpoint.baseUrl);
336
- const detail = await fetchJson(`${root}/api/v1/models`, endpoint, options);
474
+ const detail = fetched ?? await fetchJson(`${root}/api/v1/models`, endpoint, options);
337
475
  const byId = /* @__PURE__ */ new Map();
338
476
  if (Array.isArray(detail?.models)) {
339
477
  for (const model of detail.models) {
@@ -391,12 +529,17 @@ async function enrichLlamaCpp(endpoint, entries, options) {
391
529
  endpoint,
392
530
  options
393
531
  );
394
- const nCtx = contextLength(props?.default_generation_settings?.n_ctx);
395
- const known = nCtx !== void 0;
532
+ return llamaCppModels(
533
+ endpoint,
534
+ entries,
535
+ contextLength(props?.default_generation_settings?.n_ctx)
536
+ );
537
+ }
538
+ function llamaCppModels(endpoint, entries, nCtx) {
396
539
  return entries.map((entry) => ({
397
540
  ...genericModel(endpoint, entry),
398
- contextWindow: known ? nCtx : FALLBACK_CONTEXT_WINDOW,
399
- contextWindowKnown: known
541
+ contextWindow: nCtx ?? FALLBACK_CONTEXT_WINDOW,
542
+ contextWindowKnown: nCtx !== void 0
400
543
  }));
401
544
  }
402
545
  async function mapLimited(items, limit, fn) {
@@ -432,7 +575,7 @@ function toModelInfo(model, endpoint) {
432
575
  }
433
576
  var cache;
434
577
  function cacheKey(endpoints) {
435
- return endpoints.map((e) => `${e.id}@${e.baseUrl}`).join("|");
578
+ return endpoints.map((e) => `${e.id}@${e.baseUrl}#${e.contextLength ?? ""}`).join("|");
436
579
  }
437
580
  async function discoverLocalModels(endpoints = DEFAULT_LOCAL_ENDPOINTS, options = {}) {
438
581
  const key = cacheKey(endpoints);
@@ -461,18 +604,122 @@ function findProbedModel(probes, modelId) {
461
604
  return void 0;
462
605
  }
463
606
 
607
+ // src/claude-code/usage.ts
608
+ import fsp from "fs/promises";
609
+ import path from "path";
610
+ var USAGE_FILE = "usage.json";
611
+ var WINDOWS = {
612
+ five_hour: { kind: "current", label: "5-hour" },
613
+ seven_day: { kind: "weekly", label: "Weekly" }
614
+ };
615
+ function finite(value) {
616
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
617
+ }
618
+ function toWindow(key, raw) {
619
+ const shape = WINDOWS[key];
620
+ const fraction = finite(raw?.utilization);
621
+ if (!shape || fraction === void 0) return null;
622
+ const resetsAt = finite(raw?.resetsAt);
623
+ return {
624
+ ...shape,
625
+ usedPercent: Math.min(100, Math.max(0, fraction * 100)),
626
+ ...resetsAt !== void 0 ? { resetsAt: resetsAt * 1e3 } : {}
627
+ };
628
+ }
629
+ function mergeClaudeCodeRateLimit(info, previous, now = Date.now()) {
630
+ const reported = info.unifiedWindows ? Object.entries(info.unifiedWindows).map(([key, raw]) => toWindow(key, raw)) : info.rateLimitType ? [toWindow(info.rateLimitType, info)] : [];
631
+ const byKind = new Map(previous?.windows.map((w) => [w.kind, w]) ?? []);
632
+ for (const window of reported) if (window) byKind.set(window.kind, window);
633
+ const windows = [...byKind.values()].sort(
634
+ (a, b) => a.kind === b.kind ? 0 : a.kind === "current" ? -1 : 1
635
+ );
636
+ return { provider: "anthropic", displayName: "Anthropic", windows, fetchedAt: now };
637
+ }
638
+ function usagePath(opts) {
639
+ return path.join(claudeCodeHome(opts), USAGE_FILE);
640
+ }
641
+ async function readClaudeCodeUsage(opts = {}) {
642
+ let parsed;
643
+ try {
644
+ parsed = JSON.parse(await fsp.readFile(usagePath(opts), "utf8"));
645
+ } catch {
646
+ return null;
647
+ }
648
+ if (!Array.isArray(parsed?.windows) || typeof parsed.fetchedAt !== "number") return null;
649
+ const now = opts.now ?? Date.now();
650
+ const windows = parsed.windows.filter(
651
+ (w) => (w.kind === "current" || w.kind === "weekly") && typeof w.usedPercent === "number" && (w.resetsAt === void 0 || w.resetsAt > now)
652
+ );
653
+ return { provider: "anthropic", displayName: "Anthropic", windows, fetchedAt: parsed.fetchedAt };
654
+ }
655
+ var writeQueue = Promise.resolve();
656
+ function recordClaudeCodeRateLimit(info, opts = {}) {
657
+ const write = async () => {
658
+ const now = opts.now ?? Date.now();
659
+ const next = mergeClaudeCodeRateLimit(info, await readClaudeCodeUsage({ ...opts, now }), now);
660
+ if (next.windows.length === 0) return;
661
+ const file = usagePath(opts);
662
+ await fsp.mkdir(path.dirname(file), { recursive: true });
663
+ await fsp.writeFile(file, JSON.stringify(next), "utf8");
664
+ };
665
+ writeQueue = writeQueue.then(write).catch(() => {
666
+ });
667
+ return writeQueue;
668
+ }
669
+ async function clearClaudeCodeUsage(opts = {}) {
670
+ await writeQueue;
671
+ await fsp.rm(usagePath(opts), { force: true }).catch(() => {
672
+ });
673
+ }
674
+
675
+ // src/claude-code/sign-in.ts
676
+ async function signInWithClaudeCode(auth, callbacks, opts = {}) {
677
+ if (!opts.binary && !resolveClaudeCodeBinary(opts)) {
678
+ callbacks.onStatus("Downloading Claude Code (one time)\u2026");
679
+ await ensureClaudeCodeBinary({
680
+ ...opts,
681
+ onProgress: (progress) => {
682
+ callbacks.onStatus(formatClaudeCodeInstallProgress(progress));
683
+ opts.onProgress?.(progress);
684
+ }
685
+ });
686
+ }
687
+ let status = await claudeCodeAuthStatus(opts);
688
+ if (!status.loggedIn) {
689
+ callbacks.onStatus("Opening Claude sign-in\u2026");
690
+ await loginClaudeCode(callbacks, opts);
691
+ status = await claudeCodeAuthStatus(opts);
692
+ }
693
+ if (!status.loggedIn) throw new Error("Claude sign-in didn't finish. Try again.");
694
+ await auth.setClaudeCodeLogin();
695
+ return status;
696
+ }
697
+ async function signOutOfClaudeCode(auth, opts = {}) {
698
+ await auth.clearClaudeCodeLogin();
699
+ await clearClaudeCodeUsage(opts);
700
+ try {
701
+ await logoutClaudeCode(opts);
702
+ } catch (err) {
703
+ log(
704
+ "WARN",
705
+ "auth",
706
+ `claude auth logout failed: ${err instanceof Error ? err.message : String(err)}`
707
+ );
708
+ }
709
+ }
710
+
464
711
  // src/auth-providers.ts
465
- var AUTH_PROVIDERS = [
712
+ var ALL_AUTH_PROVIDERS = [
466
713
  {
467
714
  value: "anthropic",
468
715
  label: "Anthropic",
469
- description: "Claude Fable 5.1, Opus 5.5, Opus 5.5 Fast, Sonnet 5.5, Haiku 5.5",
716
+ description: "Claude Fable 5.2, Fable 5.2 Fast, Opus 5.5, Opus 5.5 Fast, Sonnet 5.5, Haiku 5.5",
470
717
  methods: ["oauth"]
471
718
  },
472
719
  {
473
720
  value: "openai",
474
721
  label: "OpenAI",
475
- description: "GPT-6 Astra, GPT-6 Astra Fast, GPT-6.1 Sol, GPT-6.1 Sol Fast, GPT-6 Luna, GPT-6 Luna Fast",
722
+ description: "GPT-6 Astra, GPT-6 Astra Fast, GPT-6.1 Sol, GPT-6.1 Sol Fast, GPT-6.1 Terra, GPT-6.1 Terra Fast, GPT-6 Luna, GPT-6 Luna Fast",
476
723
  methods: ["oauth"]
477
724
  },
478
725
  {
@@ -553,7 +800,7 @@ var AUTH_PROVIDERS = [
553
800
  {
554
801
  value: "minimax",
555
802
  label: "MiniMax",
556
- description: "MiniMax M3",
803
+ description: "MiniMax M3.1 Flash, M3",
557
804
  methods: ["apikey"],
558
805
  apiKeyLabel: "MiniMax"
559
806
  },
@@ -606,6 +853,9 @@ var AUTH_PROVIDERS = [
606
853
  apiKeyLabel: "Hugging Face"
607
854
  }
608
855
  ];
856
+ var AUTH_PROVIDERS = ALL_AUTH_PROVIDERS.filter(
857
+ (p) => !isHiddenProvider(p.value)
858
+ );
609
859
  function getAuthProvider(value) {
610
860
  return AUTH_PROVIDERS.find((p) => p.value === value);
611
861
  }
@@ -1206,7 +1456,7 @@ async function transcribeVoice(fileUrl) {
1206
1456
  // src/auto-update.ts
1207
1457
  import { spawn } from "child_process";
1208
1458
  import fs from "fs";
1209
- import path from "path";
1459
+ import path2 from "path";
1210
1460
  var CHECK_INTERVAL_MS = 60 * 60 * 1e3;
1211
1461
  var FETCH_TIMEOUT_MS = 1e4;
1212
1462
  function compareVersions(a, b) {
@@ -1248,7 +1498,7 @@ function createAutoUpdater(config) {
1248
1498
  function writeState(state) {
1249
1499
  try {
1250
1500
  const filePath = stateFilePath();
1251
- fs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 448 });
1501
+ fs.mkdirSync(path2.dirname(filePath), { recursive: true, mode: 448 });
1252
1502
  fs.writeFileSync(filePath, JSON.stringify(state));
1253
1503
  } catch {
1254
1504
  }
@@ -1374,37 +1624,56 @@ function createAutoUpdater(config) {
1374
1624
  export {
1375
1625
  AUTH_PROVIDERS,
1376
1626
  AuthStorage,
1627
+ CLAUDE_CODE_AUTH_KEY,
1628
+ CLAUDE_CODE_AUTH_MARKER,
1629
+ CLAUDE_CODE_MANIFEST,
1377
1630
  DEFAULT_LOCAL_ENDPOINTS,
1378
1631
  DEFAULT_MAX_VIDEO_BYTES,
1379
1632
  FALLBACK_CONTEXT_WINDOW,
1380
1633
  GEMINI_API_KEY,
1381
1634
  GEMINI_API_KEY_BASE_URL,
1635
+ HIDDEN_PROVIDERS,
1382
1636
  LOCAL_API_KEY_PLACEHOLDER,
1383
1637
  LOCAL_AUTH_KEY_PREFIX,
1638
+ MINIMAX_CN_BASE_URL,
1639
+ MINIMAX_GLOBAL_BASE_URL,
1384
1640
  MODELS,
1385
1641
  MOONSHOT_OAUTH_KEY,
1386
1642
  NotLoggedInError,
1643
+ OPENROUTER_DEFAULT_BASE_URL,
1387
1644
  PLAN_MODE_THINKING_CAP,
1388
1645
  SubscriptionUsageError,
1389
1646
  TelegramBot,
1390
1647
  XAI_OAUTH_KEY,
1391
1648
  XIAOMI_CREDITS_KEY,
1649
+ XIAOMI_TOKEN_PLAN_BASE_URLS,
1392
1650
  authPriorityNote,
1393
1651
  clampThinkingForPlanMode,
1652
+ claudeCodeAuthStatus,
1653
+ claudeCodeBinaryPath,
1654
+ claudeCodeCallbackUrl,
1655
+ claudeCodeConfigDir,
1656
+ claudeCodeEnv,
1657
+ claudeCodeHome,
1658
+ claudeCodePlatformKey,
1659
+ clearClaudeCodeUsage,
1394
1660
  clearLocalDiscoveryCache,
1395
1661
  clearRuntimeModels,
1396
1662
  closeLogger,
1397
- compareClaudeCodeVersions,
1398
1663
  createAutoUpdater,
1399
1664
  decodeOggOpus,
1400
1665
  describeAuthMethods,
1666
+ detectMiniMaxBaseUrl,
1667
+ detectXiaomiTokenPlanBaseUrl,
1401
1668
  discoverLocalModels,
1402
1669
  downmixToMono,
1403
1670
  dualAuthProvider,
1404
1671
  dualAuthProviderByOAuthKey,
1405
1672
  endpointRoot,
1673
+ ensureClaudeCodeBinary,
1406
1674
  fetchSubscriptionUsage,
1407
1675
  findProbedModel,
1676
+ formatClaudeCodeInstallProgress,
1408
1677
  formatLocalModelId,
1409
1678
  generatePKCE,
1410
1679
  getAllModels,
@@ -1417,11 +1686,13 @@ export {
1417
1686
  getContextWindow,
1418
1687
  getDefaultModel,
1419
1688
  getDefaultThinkingLevel,
1689
+ getListedModels,
1420
1690
  getLowestThinkingLevel,
1421
1691
  getMaxThinkingLevel,
1422
1692
  getModel,
1423
1693
  getModelsForProvider,
1424
1694
  getNextThinkingLevel,
1695
+ getProviderCatalog,
1425
1696
  getSessionId,
1426
1697
  getSummaryModel,
1427
1698
  getSupportedThinkingLevels,
@@ -1429,8 +1700,11 @@ export {
1429
1700
  getVideoByteLimit,
1430
1701
  grokCliBaseUrl,
1431
1702
  grokCliHeaders,
1703
+ isClaudeCodeAuthMarker,
1432
1704
  isGrokCliEndpoint,
1705
+ isHiddenProvider,
1433
1706
  isKimiCodingEndpoint,
1707
+ isLegacyClaudeOAuth,
1434
1708
  isLocalModelId,
1435
1709
  isLoggerOpen,
1436
1710
  isModelLoaded,
@@ -1439,19 +1713,27 @@ export {
1439
1713
  kimiCodeBaseUrl,
1440
1714
  kimiCodingHeaders,
1441
1715
  localAuthStorageKey,
1716
+ localModelShortName,
1442
1717
  log,
1443
1718
  loginAnthropic,
1719
+ loginClaudeCode,
1444
1720
  loginGemini,
1445
1721
  loginKimi,
1446
1722
  loginOpenAI,
1447
1723
  loginXai,
1724
+ logoutClaudeCode,
1725
+ mergeClaudeCodeRateLimit,
1448
1726
  oauthStorageKey,
1727
+ ollamaServedContext,
1449
1728
  openLog,
1450
1729
  parseLocalModelId,
1730
+ parseOpenRouterCatalog,
1731
+ pendingClaudeCodeVersionRefresh,
1451
1732
  probeEndpoint,
1452
1733
  providerStorageKeys,
1734
+ readClaudeCodeUsage,
1453
1735
  readStoredBaseUrlSync,
1454
- recordRequiredClaudeCodeVersion,
1736
+ recordClaudeCodeRateLimit,
1455
1737
  refreshAnthropicToken,
1456
1738
  refreshGeminiToken,
1457
1739
  refreshKimiToken,
@@ -1460,7 +1742,11 @@ export {
1460
1742
  registerLogCleanup,
1461
1743
  registerRuntimeModels,
1462
1744
  resample,
1745
+ resolveClaudeCodeBinary,
1463
1746
  setProgressCallback,
1747
+ setProviderCatalog,
1748
+ signInWithClaudeCode,
1749
+ signOutOfClaudeCode,
1464
1750
  toModelInfo,
1465
1751
  transcribeVoice,
1466
1752
  usesOpenAICodexTransport,