toc-ocra 0.3.19 → 0.3.20
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/cli/cli.mjs +198 -65
- package/dist/service/agent.mjs +190 -57
- package/dist/src/providers/claude-quota.d.ts +4 -0
- package/dist/src/providers/claude-quota.js +92 -0
- package/dist/src/providers/claude-quota.js.map +1 -0
- package/dist/src/providers/model-catalog.d.ts +9 -2
- package/dist/src/providers/model-catalog.js +85 -9
- package/dist/src/providers/model-catalog.js.map +1 -1
- package/dist/src/providers/registry.js +2 -1
- package/dist/src/providers/registry.js.map +1 -1
- package/package.json +1 -1
package/dist/service/agent.mjs
CHANGED
|
@@ -7,7 +7,7 @@ var __export = (target, all) => {
|
|
|
7
7
|
|
|
8
8
|
// src/plugin-service.ts
|
|
9
9
|
import { existsSync as existsSync8 } from "node:fs";
|
|
10
|
-
import { delimiter as delimiter5, join as
|
|
10
|
+
import { delimiter as delimiter5, join as join24 } from "node:path";
|
|
11
11
|
|
|
12
12
|
// src/config.ts
|
|
13
13
|
import { randomUUID } from "node:crypto";
|
|
@@ -21172,7 +21172,7 @@ function codexCatalogArgs() {
|
|
|
21172
21172
|
|
|
21173
21173
|
// src/providers/model-catalog.ts
|
|
21174
21174
|
import { spawn as spawn5 } from "node:child_process";
|
|
21175
|
-
import { readFile as readFile4 } from "node:fs/promises";
|
|
21175
|
+
import { readdir, readFile as readFile4 } from "node:fs/promises";
|
|
21176
21176
|
import { homedir as homedir7 } from "node:os";
|
|
21177
21177
|
import { isAbsolute as isAbsolute2, join as join10, resolve as resolve3 } from "node:path";
|
|
21178
21178
|
|
|
@@ -21305,9 +21305,40 @@ var CLAUDE_REASONING_EFFORTS = ["low", "medium", "high", "xhigh", "max"];
|
|
|
21305
21305
|
var CLAUDE_BUILTIN_MODELS = [
|
|
21306
21306
|
{ id: "opus", name: "Opus" },
|
|
21307
21307
|
{ id: "sonnet", name: "Sonnet" },
|
|
21308
|
-
{ id: "haiku", name: "Haiku" }
|
|
21308
|
+
{ id: "haiku", name: "Haiku" },
|
|
21309
|
+
{ id: "fable", name: "Fable" }
|
|
21309
21310
|
];
|
|
21310
|
-
function
|
|
21311
|
+
function parseClaudeCachedModels(cache) {
|
|
21312
|
+
const listed = objectValue(objectValue(objectValue(cache).catalog).config).models;
|
|
21313
|
+
if (!Array.isArray(listed)) return [];
|
|
21314
|
+
const entries = [];
|
|
21315
|
+
const seen = /* @__PURE__ */ new Set();
|
|
21316
|
+
for (const raw of listed) {
|
|
21317
|
+
const model = objectValue(raw);
|
|
21318
|
+
const id = stringValue(model.id);
|
|
21319
|
+
if (!id || model.disabled === true || seen.has(id)) continue;
|
|
21320
|
+
seen.add(id);
|
|
21321
|
+
const runtime = objectValue(model.runtime);
|
|
21322
|
+
const efforts = Array.isArray(runtime.effort_levels) ? runtime.effort_levels.filter((value) => typeof value === "string" && value.trim() !== "") : [];
|
|
21323
|
+
const name = stringValue(model.name);
|
|
21324
|
+
const description = stringValue(model.description);
|
|
21325
|
+
const defaultEffort = stringValue(runtime.default_effort);
|
|
21326
|
+
const section = stringValue(model.section);
|
|
21327
|
+
entries.push({
|
|
21328
|
+
...section && { section },
|
|
21329
|
+
entry: {
|
|
21330
|
+
id,
|
|
21331
|
+
name: name ?? id,
|
|
21332
|
+
...description && { description },
|
|
21333
|
+
...defaultEffort && efforts.includes(defaultEffort) && { default_reasoning_effort: defaultEffort },
|
|
21334
|
+
supported_reasoning_efforts: efforts
|
|
21335
|
+
}
|
|
21336
|
+
});
|
|
21337
|
+
}
|
|
21338
|
+
const main2 = entries.filter((item) => item.section === "main");
|
|
21339
|
+
return (main2.length ? main2 : entries).map((item) => item.entry);
|
|
21340
|
+
}
|
|
21341
|
+
function parseClaudeModelCatalog(settings, environment = process.env, fetchedAt = (/* @__PURE__ */ new Date()).toISOString(), cachedModels = []) {
|
|
21311
21342
|
const source = objectValue(settings);
|
|
21312
21343
|
const mergedEnv = { ...objectValue(source.env), ...environment };
|
|
21313
21344
|
const models2 = /* @__PURE__ */ new Map();
|
|
@@ -21331,8 +21362,18 @@ function parseClaudeModelCatalog(settings, environment = process.env, fetchedAt
|
|
|
21331
21362
|
}
|
|
21332
21363
|
const defaultModel = stringValue(mergedEnv.ANTHROPIC_MODEL) ?? stringValue(source.model);
|
|
21333
21364
|
if (models2.size === 0) {
|
|
21334
|
-
if (
|
|
21335
|
-
|
|
21365
|
+
if (cachedModels.length) {
|
|
21366
|
+
for (const model of cachedModels) if (!models2.has(model.id)) models2.set(model.id, model);
|
|
21367
|
+
if (defaultModel && !models2.has(defaultModel)) {
|
|
21368
|
+
const rest = [...models2.values()];
|
|
21369
|
+
models2.clear();
|
|
21370
|
+
addModel(defaultModel);
|
|
21371
|
+
for (const model of rest) models2.set(model.id, model);
|
|
21372
|
+
}
|
|
21373
|
+
} else {
|
|
21374
|
+
if (defaultModel) addModel(defaultModel);
|
|
21375
|
+
for (const model of CLAUDE_BUILTIN_MODELS) addModel(model.id, model.name);
|
|
21376
|
+
}
|
|
21336
21377
|
}
|
|
21337
21378
|
return {
|
|
21338
21379
|
agent_type: "claude",
|
|
@@ -21358,7 +21399,23 @@ async function readClaudeModelCatalog() {
|
|
|
21358
21399
|
throw new Error("Claude \u672C\u673A settings.json \u4E0D\u662F\u6709\u6548 JSON");
|
|
21359
21400
|
}
|
|
21360
21401
|
}
|
|
21361
|
-
return parseClaudeModelCatalog(settings);
|
|
21402
|
+
return parseClaudeModelCatalog(settings, process.env, (/* @__PURE__ */ new Date()).toISOString(), await readClaudeCachedModels(home));
|
|
21403
|
+
}
|
|
21404
|
+
async function readClaudeCachedModels(home) {
|
|
21405
|
+
const dir = join10(home, "cache", "model-catalog");
|
|
21406
|
+
const names = await readdir(dir).catch(() => []);
|
|
21407
|
+
let newest;
|
|
21408
|
+
for (const name of names) {
|
|
21409
|
+
if (!name.endsWith(".json")) continue;
|
|
21410
|
+
try {
|
|
21411
|
+
const cache = JSON.parse(await readFile4(join10(dir, name), "utf8"));
|
|
21412
|
+
const models2 = parseClaudeCachedModels(cache);
|
|
21413
|
+
const fetchedAt = Number(objectValue(cache).fetchedAt) || 0;
|
|
21414
|
+
if (models2.length && (!newest || fetchedAt > newest.fetchedAt)) newest = { fetchedAt, models: models2 };
|
|
21415
|
+
} catch {
|
|
21416
|
+
}
|
|
21417
|
+
}
|
|
21418
|
+
return newest?.models ?? [];
|
|
21362
21419
|
}
|
|
21363
21420
|
function configValue(content, key) {
|
|
21364
21421
|
const match = content.match(new RegExp(`^\\s*${key}\\s*=\\s*["']([^"']+)["']\\s*(?:#.*)?$`, "m"));
|
|
@@ -21665,7 +21722,7 @@ async function readOpencodeModelCatalog() {
|
|
|
21665
21722
|
}
|
|
21666
21723
|
var TEN_MINUTES = 10 * 60 * 1e3;
|
|
21667
21724
|
var MODEL_SOURCES = {
|
|
21668
|
-
claude: { read: readClaudeModelCatalog, watchFiles: () => [join10(claudeHome(), "settings.json")] },
|
|
21725
|
+
claude: { read: readClaudeModelCatalog, watchFiles: () => [join10(claudeHome(), "settings.json"), join10(claudeHome(), "cache", "model-catalog")] },
|
|
21669
21726
|
codex: {
|
|
21670
21727
|
read: readCodexModelCatalog,
|
|
21671
21728
|
watchFiles: () => {
|
|
@@ -21793,7 +21850,7 @@ function classifySpawnError(error62, context) {
|
|
|
21793
21850
|
}
|
|
21794
21851
|
|
|
21795
21852
|
// src/providers/cli/kiro-session-log.ts
|
|
21796
|
-
import { open as open2, readdir, readFile as readFile5, stat as stat2 } from "node:fs/promises";
|
|
21853
|
+
import { open as open2, readdir as readdir2, readFile as readFile5, stat as stat2 } from "node:fs/promises";
|
|
21797
21854
|
import { homedir as homedir8 } from "node:os";
|
|
21798
21855
|
import { join as join11 } from "node:path";
|
|
21799
21856
|
var SHELL_TOOLS = /* @__PURE__ */ new Set(["shell", "execute_bash", "bash"]);
|
|
@@ -21826,7 +21883,7 @@ var KiroSessionLog = class {
|
|
|
21826
21883
|
* in the same folder) leave it unknown.
|
|
21827
21884
|
*/
|
|
21828
21885
|
async findFreshLog() {
|
|
21829
|
-
const names = await
|
|
21886
|
+
const names = await readdir2(this.directory).catch(() => []);
|
|
21830
21887
|
const found = [];
|
|
21831
21888
|
for (const name of names) {
|
|
21832
21889
|
if (!name.endsWith(".json")) continue;
|
|
@@ -24666,6 +24723,82 @@ var opencodeProvider = {
|
|
|
24666
24723
|
}
|
|
24667
24724
|
};
|
|
24668
24725
|
|
|
24726
|
+
// src/providers/claude-quota.ts
|
|
24727
|
+
import { execFile as execFile5 } from "node:child_process";
|
|
24728
|
+
import { readFile as readFile6 } from "node:fs/promises";
|
|
24729
|
+
import { homedir as homedir10 } from "node:os";
|
|
24730
|
+
import { join as join16 } from "node:path";
|
|
24731
|
+
import { promisify as promisify3 } from "node:util";
|
|
24732
|
+
var execFileAsync3 = promisify3(execFile5);
|
|
24733
|
+
var CLAUDE_USAGE_URL = "https://api.anthropic.com/api/oauth/usage";
|
|
24734
|
+
var WINDOWS = [
|
|
24735
|
+
{ key: "five_hour", label: "5 \u5C0F\u65F6\u989D\u5EA6", seconds: 5 * 3600 },
|
|
24736
|
+
{ key: "seven_day", label: "\u6BCF\u5468\u989D\u5EA6", seconds: 7 * 86400 },
|
|
24737
|
+
{ key: "seven_day_opus", label: "Opus \xB7 \u6BCF\u5468\u989D\u5EA6", seconds: 7 * 86400 },
|
|
24738
|
+
{ key: "seven_day_sonnet", label: "Sonnet \xB7 \u6BCF\u5468\u989D\u5EA6", seconds: 7 * 86400 }
|
|
24739
|
+
];
|
|
24740
|
+
function objectValue2(value) {
|
|
24741
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
24742
|
+
}
|
|
24743
|
+
function resetSeconds(value) {
|
|
24744
|
+
if (typeof value === "number" && Number.isFinite(value) && value > 0) return Math.floor(value > 1e10 ? value / 1e3 : value);
|
|
24745
|
+
if (typeof value === "string" && value.trim()) {
|
|
24746
|
+
const parsed = Date.parse(value);
|
|
24747
|
+
if (Number.isFinite(parsed)) return Math.floor(parsed / 1e3);
|
|
24748
|
+
}
|
|
24749
|
+
return 0;
|
|
24750
|
+
}
|
|
24751
|
+
function parseClaudeQuota(body) {
|
|
24752
|
+
const source = objectValue2(body);
|
|
24753
|
+
const windows = [];
|
|
24754
|
+
for (const { key, label, seconds } of WINDOWS) {
|
|
24755
|
+
const raw = source[key];
|
|
24756
|
+
if (!raw || typeof raw !== "object") continue;
|
|
24757
|
+
const window = objectValue2(raw);
|
|
24758
|
+
const utilization = Number(window.utilization);
|
|
24759
|
+
windows.push({
|
|
24760
|
+
key: `claude:${key}`,
|
|
24761
|
+
label,
|
|
24762
|
+
resets_at: resetSeconds(window.resets_at),
|
|
24763
|
+
window_seconds: seconds,
|
|
24764
|
+
...window.utilization !== null && Number.isFinite(utilization) && utilization >= 0 ? { used_percent: Math.min(100, Math.round(utilization * 100) / 100) } : {}
|
|
24765
|
+
});
|
|
24766
|
+
}
|
|
24767
|
+
return windows;
|
|
24768
|
+
}
|
|
24769
|
+
var claudeHome2 = () => process.env.CLAUDE_CONFIG_DIR?.trim() || join16(homedir10(), ".claude");
|
|
24770
|
+
function tokenFrom(content) {
|
|
24771
|
+
try {
|
|
24772
|
+
const token = objectValue2(objectValue2(JSON.parse(content)).claudeAiOauth).accessToken;
|
|
24773
|
+
return typeof token === "string" && token.trim() ? token.trim() : void 0;
|
|
24774
|
+
} catch {
|
|
24775
|
+
return void 0;
|
|
24776
|
+
}
|
|
24777
|
+
}
|
|
24778
|
+
async function readClaudeAccessToken() {
|
|
24779
|
+
const fromEnv = process.env.CLAUDE_CODE_OAUTH_TOKEN?.trim();
|
|
24780
|
+
if (fromEnv) return fromEnv;
|
|
24781
|
+
const fromFile = tokenFrom(await readFile6(join16(claudeHome2(), ".credentials.json"), "utf8").catch(() => ""));
|
|
24782
|
+
if (fromFile) return fromFile;
|
|
24783
|
+
if (process.platform !== "darwin") return void 0;
|
|
24784
|
+
const { stdout } = await execFileAsync3("security", ["find-generic-password", "-s", "Claude Code-credentials", "-w"], { timeout: 1e4 }).catch(() => ({ stdout: "" }));
|
|
24785
|
+
return tokenFrom(String(stdout).trim());
|
|
24786
|
+
}
|
|
24787
|
+
async function readClaudeQuotaWindows() {
|
|
24788
|
+
const token = await readClaudeAccessToken();
|
|
24789
|
+
if (!token) throw new Error("Claude Code \u672A\u4F7F\u7528 Claude \u8D26\u53F7\u767B\u5F55\uFF08API Key \u65B9\u5F0F\u6CA1\u6709\u5957\u9910\u989D\u5EA6\uFF09\uFF0C\u8BF7\u5728\u672C\u673A\u8FD0\u884C claude \u5E76 /login");
|
|
24790
|
+
const response = await fetch(CLAUDE_USAGE_URL, {
|
|
24791
|
+
headers: { authorization: `Bearer ${token}`, "anthropic-beta": "oauth-2025-04-20", accept: "application/json" },
|
|
24792
|
+
redirect: "error",
|
|
24793
|
+
signal: AbortSignal.timeout(15e3)
|
|
24794
|
+
});
|
|
24795
|
+
if (response.status === 401 || response.status === 403) throw new Error("Claude Code \u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u5728\u672C\u673A\u8FD0\u884C\u4E00\u6B21 claude \u5237\u65B0\u767B\u5F55\u540E\u518D\u8BD5");
|
|
24796
|
+
if (!response.ok) throw new Error(`Claude \u989D\u5EA6\u63A5\u53E3\u8BF7\u6C42\u5931\u8D25 (${response.status})`);
|
|
24797
|
+
const windows = parseClaudeQuota(await response.json());
|
|
24798
|
+
if (!windows.length) throw new Error("Claude \u6CA1\u6709\u8FD4\u56DE\u6709\u6548\u7684\u989D\u5EA6\u7A97\u53E3");
|
|
24799
|
+
return windows;
|
|
24800
|
+
}
|
|
24801
|
+
|
|
24669
24802
|
// src/providers/codex-quota.ts
|
|
24670
24803
|
import { spawn as spawn8 } from "node:child_process";
|
|
24671
24804
|
import { createInterface as createInterface3 } from "node:readline";
|
|
@@ -24764,10 +24897,10 @@ async function readCodexQuotaWindows() {
|
|
|
24764
24897
|
}
|
|
24765
24898
|
|
|
24766
24899
|
// src/providers/kiro-quota.ts
|
|
24767
|
-
import { execFile as
|
|
24900
|
+
import { execFile as execFile6 } from "node:child_process";
|
|
24768
24901
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24769
|
-
import { promisify as
|
|
24770
|
-
var
|
|
24902
|
+
import { promisify as promisify4, stripVTControlCharacters } from "node:util";
|
|
24903
|
+
var execFileAsync4 = promisify4(execFile6);
|
|
24771
24904
|
var amount = (value) => Number(value.replace(/,/g, ""));
|
|
24772
24905
|
var rounded = (value) => Math.round(value * 100) / 100;
|
|
24773
24906
|
function parseKiroQuota(stdout, now = /* @__PURE__ */ new Date()) {
|
|
@@ -24827,7 +24960,7 @@ async function readKiroQuotaWindows() {
|
|
|
24827
24960
|
const launch = launchCli({ spec: requireCliSpec("kiro"), args: ["chat", "--no-interactive", "/usage"] });
|
|
24828
24961
|
await requireKiroAuthentication(launch.env);
|
|
24829
24962
|
try {
|
|
24830
|
-
const { stdout, stderr } = await
|
|
24963
|
+
const { stdout, stderr } = await execFileAsync4(launch.executable, launch.args, { env: launch.env, cwd: tmpdir2(), timeout: 3e4, maxBuffer: 1024 * 1024, windowsHide: true });
|
|
24831
24964
|
return parseKiroQuota(`${stdout}
|
|
24832
24965
|
${stderr}`);
|
|
24833
24966
|
} catch (error62) {
|
|
@@ -24840,7 +24973,7 @@ ${stderr}`);
|
|
|
24840
24973
|
var ALL_LEVELS = ["read-only", "acceptEdits", "bypassPermissions"];
|
|
24841
24974
|
var NATIVE = {
|
|
24842
24975
|
codex: { headless: codexProvider, chat: codexChatProvider, models: MODEL_SOURCES.codex, quota: readCodexQuotaWindows, runSettings: { permissionModes: ALL_LEVELS, plan: "prompt", fast: true } },
|
|
24843
|
-
claude: { headless: claudeProvider, chat: (_request, attachments) => claudeChatProvider(attachments), models: MODEL_SOURCES.claude, runSettings: { permissionModes: ALL_LEVELS, plan: "native", fast: true } }
|
|
24976
|
+
claude: { headless: claudeProvider, chat: (_request, attachments) => claudeChatProvider(attachments), models: MODEL_SOURCES.claude, quota: readClaudeQuotaWindows, runSettings: { permissionModes: ALL_LEVELS, plan: "native", fast: true } }
|
|
24844
24977
|
};
|
|
24845
24978
|
var ACP_EXTRAS = {
|
|
24846
24979
|
kiro: { quota: readKiroQuotaWindows, legacy: { headless: kiroProvider, restrictedPermission: true, runSettings: { permissionModes: ["read-only", "bypassPermissions"], plan: "prompt" } } },
|
|
@@ -25026,7 +25159,7 @@ var cliDetection = new CliDetectionService();
|
|
|
25026
25159
|
|
|
25027
25160
|
// src/runtime/agent-runtime.ts
|
|
25028
25161
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
25029
|
-
import { join as
|
|
25162
|
+
import { join as join23 } from "node:path";
|
|
25030
25163
|
|
|
25031
25164
|
// src/exec/script-runner.ts
|
|
25032
25165
|
import { spawn as spawn10 } from "node:child_process";
|
|
@@ -25137,7 +25270,7 @@ function resolveChatProvider(type, request, attachments) {
|
|
|
25137
25270
|
}
|
|
25138
25271
|
|
|
25139
25272
|
// src/memory/providers.ts
|
|
25140
|
-
import { execFile as
|
|
25273
|
+
import { execFile as execFile7 } from "node:child_process";
|
|
25141
25274
|
var MemoryCreateInputSchema = external_exports.object({
|
|
25142
25275
|
id: external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,127}$/),
|
|
25143
25276
|
name: external_exports.string().trim().min(1).max(200),
|
|
@@ -25159,7 +25292,7 @@ var runNmem = (args) => {
|
|
|
25159
25292
|
const env = providerEnvironment();
|
|
25160
25293
|
const launch = resolveExecutable("nmem", args, env, process.env.TOC_OCRA_NMEM_PATH);
|
|
25161
25294
|
return new Promise((resolve9) => {
|
|
25162
|
-
|
|
25295
|
+
execFile7(launch.executable, launch.args, { env: launch.env, timeout: COMMAND_TIMEOUT_MS, maxBuffer: MAX_OUTPUT_BYTES, windowsHide: true }, (error62, stdout) => {
|
|
25163
25296
|
if (!error62) {
|
|
25164
25297
|
resolve9({ stdout: String(stdout) });
|
|
25165
25298
|
return;
|
|
@@ -25314,16 +25447,16 @@ async function readCLIQuotaReport(agentType) {
|
|
|
25314
25447
|
}
|
|
25315
25448
|
|
|
25316
25449
|
// src/providers/tb-switch-control.ts
|
|
25317
|
-
import { readFile as
|
|
25318
|
-
import { homedir as
|
|
25319
|
-
import { join as
|
|
25450
|
+
import { readFile as readFile7 } from "node:fs/promises";
|
|
25451
|
+
import { homedir as homedir11 } from "node:os";
|
|
25452
|
+
import { join as join17 } from "node:path";
|
|
25320
25453
|
function dataDir() {
|
|
25321
|
-
return process.env.TB_SWITCH_HOME?.trim() ||
|
|
25454
|
+
return process.env.TB_SWITCH_HOME?.trim() || join17(homedir11(), ".tb-switch");
|
|
25322
25455
|
}
|
|
25323
25456
|
async function readLocalService() {
|
|
25324
25457
|
let discovery;
|
|
25325
25458
|
try {
|
|
25326
|
-
discovery = JSON.parse(await
|
|
25459
|
+
discovery = JSON.parse(await readFile7(join17(dataDir(), "api.json"), "utf8"));
|
|
25327
25460
|
} catch {
|
|
25328
25461
|
throw new Error("\u8FD9\u53F0\u8BBE\u5907\u4E0A\u7684 TB Switch \u670D\u52A1\u672A\u8FD0\u884C\uFF0C\u8BF7\u6253\u5F00\u684C\u9762\u7AEF\u63D2\u4EF6\u540E\u91CD\u8BD5\u3002");
|
|
25329
25462
|
}
|
|
@@ -25339,7 +25472,7 @@ async function readLocalService() {
|
|
|
25339
25472
|
}
|
|
25340
25473
|
let token = process.env.TB_SWITCH_API_TOKEN?.trim() ?? "";
|
|
25341
25474
|
try {
|
|
25342
|
-
token = (await
|
|
25475
|
+
token = (await readFile7(join17(dataDir(), "api-token"), "utf8")).trim();
|
|
25343
25476
|
} catch {
|
|
25344
25477
|
}
|
|
25345
25478
|
if (!token) throw new Error("\u65E0\u6CD5\u8BFB\u53D6 TB Switch \u672C\u673A\u670D\u52A1\u51ED\u636E\uFF0C\u8BF7\u91CD\u542F\u684C\u9762\u7AEF\u63D2\u4EF6\u540E\u91CD\u8BD5\u3002");
|
|
@@ -25429,7 +25562,7 @@ async function controlTbSwitch(payload) {
|
|
|
25429
25562
|
}
|
|
25430
25563
|
|
|
25431
25564
|
// src/runs/orphan-registry.ts
|
|
25432
|
-
import { mkdir as mkdir5, readFile as
|
|
25565
|
+
import { mkdir as mkdir5, readFile as readFile8, rename as rename5, writeFile as writeFile5 } from "node:fs/promises";
|
|
25433
25566
|
import { basename, dirname as dirname8 } from "node:path";
|
|
25434
25567
|
var OrphanRegistry = class {
|
|
25435
25568
|
constructor(file2) {
|
|
@@ -25458,7 +25591,7 @@ var OrphanRegistry = class {
|
|
|
25458
25591
|
async reapPrevious() {
|
|
25459
25592
|
let previous = [];
|
|
25460
25593
|
try {
|
|
25461
|
-
previous = JSON.parse(await
|
|
25594
|
+
previous = JSON.parse(await readFile8(this.file, "utf8"));
|
|
25462
25595
|
} catch {
|
|
25463
25596
|
return [];
|
|
25464
25597
|
}
|
|
@@ -25484,7 +25617,7 @@ function commandOf(pid) {
|
|
|
25484
25617
|
// src/runs/run-supervisor.ts
|
|
25485
25618
|
import { spawn as spawn12 } from "node:child_process";
|
|
25486
25619
|
import { mkdir as mkdir8, realpath as realpath2, stat as stat6, writeFile as writeFile8 } from "node:fs/promises";
|
|
25487
|
-
import { basename as basename3, isAbsolute as isAbsolute4, join as
|
|
25620
|
+
import { basename as basename3, isAbsolute as isAbsolute4, join as join21, relative as relative2, resolve as resolve5 } from "node:path";
|
|
25488
25621
|
import { createInterface as createInterface5 } from "node:readline";
|
|
25489
25622
|
|
|
25490
25623
|
// src/session/terminal-tail-buffer.ts
|
|
@@ -25846,19 +25979,19 @@ async function forkCodexThread(options) {
|
|
|
25846
25979
|
|
|
25847
25980
|
// src/runs/run-recorder.ts
|
|
25848
25981
|
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3 } from "node:fs";
|
|
25849
|
-
import { homedir as
|
|
25850
|
-
import { join as
|
|
25982
|
+
import { homedir as homedir12 } from "node:os";
|
|
25983
|
+
import { join as join18 } from "node:path";
|
|
25851
25984
|
var RunRecorder = class _RunRecorder {
|
|
25852
25985
|
constructor(path) {
|
|
25853
25986
|
this.path = path;
|
|
25854
25987
|
}
|
|
25855
25988
|
path;
|
|
25856
|
-
home =
|
|
25989
|
+
home = homedir12();
|
|
25857
25990
|
static fromEnvironment(runId, meta3) {
|
|
25858
25991
|
const directory = process.env.TOC_OCRA_RECORD_DIR?.trim();
|
|
25859
25992
|
if (!directory) return void 0;
|
|
25860
25993
|
mkdirSync3(directory, { recursive: true });
|
|
25861
|
-
const recorder = new _RunRecorder(
|
|
25994
|
+
const recorder = new _RunRecorder(join18(directory, `${String(meta3.agent ?? "cli")}-${runId}.jsonl`));
|
|
25862
25995
|
recorder.write({ meta: meta3 });
|
|
25863
25996
|
return recorder;
|
|
25864
25997
|
}
|
|
@@ -25873,8 +26006,8 @@ var RunRecorder = class _RunRecorder {
|
|
|
25873
26006
|
};
|
|
25874
26007
|
|
|
25875
26008
|
// src/runs/run-transcript.ts
|
|
25876
|
-
import { chmod as chmod4, mkdir as mkdir6, readdir as
|
|
25877
|
-
import { join as
|
|
26009
|
+
import { chmod as chmod4, mkdir as mkdir6, readdir as readdir3, readFile as readFile9, rename as rename6, stat as stat4, unlink, writeFile as writeFile6 } from "node:fs/promises";
|
|
26010
|
+
import { join as join19 } from "node:path";
|
|
25878
26011
|
var MAX_TRANSCRIPT_ITEMS = 5e3;
|
|
25879
26012
|
var MAX_TRANSCRIPT_TEXT = 2e5;
|
|
25880
26013
|
var MAX_TRANSCRIPT_LINES = 2e4;
|
|
@@ -26139,7 +26272,7 @@ function transcriptFileName(runId) {
|
|
|
26139
26272
|
var TranscriptStore = class {
|
|
26140
26273
|
constructor(dataDir2, logger, env = process.env) {
|
|
26141
26274
|
this.logger = logger;
|
|
26142
|
-
this.directory = dataDir2 ?
|
|
26275
|
+
this.directory = dataDir2 ? join19(dataDir2, "transcripts") : "";
|
|
26143
26276
|
this.enabled = Boolean(dataDir2) && transcriptsOnDisk(env);
|
|
26144
26277
|
}
|
|
26145
26278
|
logger;
|
|
@@ -26194,7 +26327,7 @@ var TranscriptStore = class {
|
|
|
26194
26327
|
await this.writes.get(runId);
|
|
26195
26328
|
let text3;
|
|
26196
26329
|
try {
|
|
26197
|
-
text3 = await
|
|
26330
|
+
text3 = await readFile9(join19(this.directory, name), "utf8");
|
|
26198
26331
|
} catch (error62) {
|
|
26199
26332
|
if (errorCode(error62) !== "ENOENT") this.logger.warn("run-transcript-read-failed", { runId, error: errorMessage(error62) });
|
|
26200
26333
|
return void 0;
|
|
@@ -26259,7 +26392,7 @@ var TranscriptStore = class {
|
|
|
26259
26392
|
transcript.dirty = false;
|
|
26260
26393
|
const body = JSON.stringify(transcript.toFile());
|
|
26261
26394
|
await this.ensureDirectory();
|
|
26262
|
-
const file2 =
|
|
26395
|
+
const file2 = join19(this.directory, name);
|
|
26263
26396
|
const temporary = `${file2}.${process.pid}.tmp`;
|
|
26264
26397
|
await writeFile6(temporary, body, { mode: 384 });
|
|
26265
26398
|
await rename6(temporary, file2);
|
|
@@ -26288,7 +26421,7 @@ var TranscriptStore = class {
|
|
|
26288
26421
|
async pruneOnce() {
|
|
26289
26422
|
let names;
|
|
26290
26423
|
try {
|
|
26291
|
-
names = await
|
|
26424
|
+
names = await readdir3(this.directory);
|
|
26292
26425
|
} catch (error62) {
|
|
26293
26426
|
if (errorCode(error62) === "ENOENT") return;
|
|
26294
26427
|
throw error62;
|
|
@@ -26296,7 +26429,7 @@ var TranscriptStore = class {
|
|
|
26296
26429
|
const now = Date.now();
|
|
26297
26430
|
const files = [];
|
|
26298
26431
|
for (const name of names) {
|
|
26299
|
-
const path =
|
|
26432
|
+
const path = join19(this.directory, name);
|
|
26300
26433
|
if (name.endsWith(".tmp")) {
|
|
26301
26434
|
const info2 = await stat4(path).catch(() => void 0);
|
|
26302
26435
|
if (info2?.isFile() && now - info2.mtimeMs > STALE_TEMPORARY_MS) await unlink(path).catch(() => void 0);
|
|
@@ -26346,7 +26479,7 @@ function errorMessage(error62) {
|
|
|
26346
26479
|
import { createHash as createHash3, randomUUID as randomUUID2 } from "node:crypto";
|
|
26347
26480
|
import { constants as constants2 } from "node:fs";
|
|
26348
26481
|
import { lstat, mkdir as mkdir7, open as open3, realpath, rename as rename7, rm as rm4, writeFile as writeFile7 } from "node:fs/promises";
|
|
26349
|
-
import { basename as basename2, isAbsolute as isAbsolute3, join as
|
|
26482
|
+
import { basename as basename2, isAbsolute as isAbsolute3, join as join20, relative } from "node:path";
|
|
26350
26483
|
function within(root2, path) {
|
|
26351
26484
|
const segment = relative(root2, path);
|
|
26352
26485
|
return segment === "" || !segment.startsWith("..") && !isAbsolute3(segment);
|
|
@@ -26354,7 +26487,7 @@ function within(root2, path) {
|
|
|
26354
26487
|
async function attachmentDirectory(workdir, messageId) {
|
|
26355
26488
|
let directory = workdir;
|
|
26356
26489
|
for (const segment of [".echo", "attachments", `message-${encodeURIComponent(messageId).slice(0, 180)}`]) {
|
|
26357
|
-
directory =
|
|
26490
|
+
directory = join20(directory, segment);
|
|
26358
26491
|
await mkdir7(directory, { mode: 448 }).catch((error62) => {
|
|
26359
26492
|
if (error62.code !== "EEXIST") throw error62;
|
|
26360
26493
|
});
|
|
@@ -26362,7 +26495,7 @@ async function attachmentDirectory(workdir, messageId) {
|
|
|
26362
26495
|
if (metadata.isSymbolicLink() || !metadata.isDirectory() || !within(workdir, await realpath(directory))) {
|
|
26363
26496
|
throw new Error("\u9644\u4EF6\u76EE\u5F55\u5FC5\u987B\u4F4D\u4E8E CLI \u5DE5\u4F5C\u76EE\u5F55\u5185\uFF0C\u4E14\u4E0D\u80FD\u662F\u7B26\u53F7\u94FE\u63A5");
|
|
26364
26497
|
}
|
|
26365
|
-
if (segment === ".echo") await writeFile7(
|
|
26498
|
+
if (segment === ".echo") await writeFile7(join20(directory, ".gitignore"), "*\n", { flag: "wx", mode: 384 }).catch((error62) => {
|
|
26366
26499
|
if (error62.code !== "EEXIST") throw error62;
|
|
26367
26500
|
});
|
|
26368
26501
|
}
|
|
@@ -26399,9 +26532,9 @@ async function prepareTaskAttachments(payload, workdir, download, signal2) {
|
|
|
26399
26532
|
const characters = Array.from(basename2(file2.name.replace(/\\/g, "/")).replace(/[^\p{L}\p{N}._-]/gu, "_").replace(/\.+$/u, ""));
|
|
26400
26533
|
while (Buffer.byteLength(characters.join("")) > 160) characters.shift();
|
|
26401
26534
|
const name = characters.join("") || "attachment";
|
|
26402
|
-
const path =
|
|
26535
|
+
const path = join20(directory, `${file2.file_id}-${name}`);
|
|
26403
26536
|
if (!await matches(path, file2.size, file2.sha256, signal2)) {
|
|
26404
|
-
const temporary =
|
|
26537
|
+
const temporary = join20(directory, `.download-${file2.file_id}-${randomUUID2()}.part`);
|
|
26405
26538
|
try {
|
|
26406
26539
|
await download(payload.run_id, file2.file_id, temporary, file2.size, file2.sha256, signal2);
|
|
26407
26540
|
signal2.throwIfAborted();
|
|
@@ -26516,7 +26649,7 @@ var ChatEventForwarder = class {
|
|
|
26516
26649
|
|
|
26517
26650
|
// src/acp/chat-session.ts
|
|
26518
26651
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
26519
|
-
import { readFile as
|
|
26652
|
+
import { readFile as readFile10, stat as stat5 } from "node:fs/promises";
|
|
26520
26653
|
import { extname } from "node:path";
|
|
26521
26654
|
import { pathToFileURL } from "node:url";
|
|
26522
26655
|
|
|
@@ -27124,7 +27257,7 @@ var AcpChatSession = class {
|
|
|
27124
27257
|
if (file2.kind === "image" && mimeType && connection.imagePrompts) {
|
|
27125
27258
|
const size = await stat5(file2.path).then((info) => info.size).catch(() => 0);
|
|
27126
27259
|
if (size > 0 && size <= MAX_IMAGE_BYTES) {
|
|
27127
|
-
blocks.push({ type: "image", mimeType, data: (await
|
|
27260
|
+
blocks.push({ type: "image", mimeType, data: (await readFile10(file2.path)).toString("base64") });
|
|
27128
27261
|
continue;
|
|
27129
27262
|
}
|
|
27130
27263
|
}
|
|
@@ -28356,12 +28489,12 @@ ${PLAN_MODE_PREFIX}` : payload.prompt;
|
|
|
28356
28489
|
async prepareChatAttachments(payload) {
|
|
28357
28490
|
if (!payload.attachments?.length) return [];
|
|
28358
28491
|
if (!this.reporter.chatMedia) throw new Error("\u9644\u4EF6\u8F6C\u53D1\u672A\u914D\u7F6E");
|
|
28359
|
-
const directory =
|
|
28492
|
+
const directory = join21(this.config.dataDir, "chat-media", encodeURIComponent(payload.chat_session_id ?? payload.run_id));
|
|
28360
28493
|
await mkdir8(directory, { recursive: true, mode: 448 });
|
|
28361
28494
|
const files = [];
|
|
28362
28495
|
for (const attachment of payload.attachments) {
|
|
28363
28496
|
const name = basename3(attachment.name).replace(/[^\p{L}\p{N}._-]/gu, "_").slice(-120) || "attachment";
|
|
28364
|
-
const path =
|
|
28497
|
+
const path = join21(directory, `${encodeURIComponent(attachment.media_id)}-${name}`);
|
|
28365
28498
|
const existing = await stat6(path).catch(() => void 0);
|
|
28366
28499
|
if (!existing?.isFile()) {
|
|
28367
28500
|
const data = await this.reporter.chatMedia(payload.run_id, attachment.media_id);
|
|
@@ -28674,17 +28807,17 @@ var GatewayClient = class {
|
|
|
28674
28807
|
};
|
|
28675
28808
|
|
|
28676
28809
|
// src/workspace/directory-browser.ts
|
|
28677
|
-
import { mkdir as mkdir9, readdir as
|
|
28678
|
-
import { homedir as
|
|
28810
|
+
import { mkdir as mkdir9, readdir as readdir4, realpath as realpath3, stat as stat7 } from "node:fs/promises";
|
|
28811
|
+
import { homedir as homedir13 } from "node:os";
|
|
28679
28812
|
import { dirname as dirname9, isAbsolute as isAbsolute5, parse as parse3, resolve as resolve6 } from "node:path";
|
|
28680
28813
|
var MAX_ENTRIES = 1e3;
|
|
28681
28814
|
async function listDirectory(requested, allowedRoots) {
|
|
28682
|
-
const raw = requested.trim().replace(/^~(?=$|[\\/])/,
|
|
28815
|
+
const raw = requested.trim().replace(/^~(?=$|[\\/])/, homedir13()) || homedir13();
|
|
28683
28816
|
const directory = await realpath3(resolve6(raw)).catch(() => {
|
|
28684
28817
|
throw new Error(`\u76EE\u5F55\u4E0D\u5B58\u5728\uFF1A${requested}`);
|
|
28685
28818
|
});
|
|
28686
28819
|
if (!(await stat7(directory)).isDirectory()) throw new Error("\u8FD9\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
|
|
28687
|
-
const entries = await
|
|
28820
|
+
const entries = await readdir4(directory, { withFileTypes: true }).catch((error62) => {
|
|
28688
28821
|
throw new Error(error62.code === "EACCES" || error62.code === "EPERM" ? "\u6CA1\u6709\u6743\u9650\u8BFB\u53D6\u8FD9\u4E2A\u76EE\u5F55" : error62.message);
|
|
28689
28822
|
});
|
|
28690
28823
|
const byName = (a, b) => a.name.localeCompare(b.name, void 0, { sensitivity: "base", numeric: true });
|
|
@@ -28697,8 +28830,8 @@ async function listDirectory(requested, allowedRoots) {
|
|
|
28697
28830
|
else if (entry.isFile()) files.push(item);
|
|
28698
28831
|
}
|
|
28699
28832
|
const parent = dirname9(directory);
|
|
28700
|
-
const places = [{ label: "\u4E3B\u76EE\u5F55", path:
|
|
28701
|
-
for (const root2 of allowedRoots) if (root2 !==
|
|
28833
|
+
const places = [{ label: "\u4E3B\u76EE\u5F55", path: homedir13() }];
|
|
28834
|
+
for (const root2 of allowedRoots) if (root2 !== homedir13()) places.push({ label: "\u5141\u8BB8\u7684\u76EE\u5F55", path: root2 });
|
|
28702
28835
|
places.push({ label: "\u6839\u76EE\u5F55", path: process.platform === "win32" ? parse3(directory).root : "/" });
|
|
28703
28836
|
return {
|
|
28704
28837
|
path: directory,
|
|
@@ -28736,7 +28869,7 @@ async function createDirectory(parentRequested, name) {
|
|
|
28736
28869
|
// src/workspace/workspace-manager.ts
|
|
28737
28870
|
import { spawn as spawn13 } from "node:child_process";
|
|
28738
28871
|
import { opendir, realpath as realpath4, stat as stat8 } from "node:fs/promises";
|
|
28739
|
-
import { homedir as
|
|
28872
|
+
import { homedir as homedir14 } from "node:os";
|
|
28740
28873
|
import { isAbsolute as isAbsolute6, relative as relative3, resolve as resolve7 } from "node:path";
|
|
28741
28874
|
var MAX_NODES = 2e3;
|
|
28742
28875
|
var MAX_DIRECTORY_ENTRIES = 12e3;
|
|
@@ -28772,7 +28905,7 @@ var WorkspaceManager = class {
|
|
|
28772
28905
|
return { root_path: rootPath, nodes, truncated: nodes.length >= MAX_NODES, duration_ms: Date.now() - startedAt };
|
|
28773
28906
|
}
|
|
28774
28907
|
validateRootPath(value) {
|
|
28775
|
-
const raw = value.trim().replace(/^~(?=$|[\\/])/,
|
|
28908
|
+
const raw = value.trim().replace(/^~(?=$|[\\/])/, homedir14());
|
|
28776
28909
|
const root2 = resolve7(raw);
|
|
28777
28910
|
if (!isAbsolute6(raw)) throw new Error("\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");
|
|
28778
28911
|
if (relative3(root2, resolve7(root2, "..")) === "") throw new Error("\u4E0D\u80FD\u628A\u6587\u4EF6\u7CFB\u7EDF\u6839\u76EE\u5F55\u4F5C\u4E3A\u76EE\u5F55\u6839");
|
|
@@ -29112,7 +29245,7 @@ var AgentRuntime = class {
|
|
|
29112
29245
|
}
|
|
29113
29246
|
};
|
|
29114
29247
|
this.workspaces = new WorkspaceManager(config2, this.logger);
|
|
29115
|
-
this.orphans = new OrphanRegistry(
|
|
29248
|
+
this.orphans = new OrphanRegistry(join23(config2.dataDir, "active-runs.json"));
|
|
29116
29249
|
this.runs = new RunSupervisor(config2, this.logger, reporter, this.orphans);
|
|
29117
29250
|
}
|
|
29118
29251
|
config;
|
|
@@ -29895,7 +30028,7 @@ function preferSystemNode() {
|
|
|
29895
30028
|
const names = process.platform === "win32" ? ["node.exe"] : ["node"];
|
|
29896
30029
|
for (const directory of (process.env.PATH ?? "").split(delimiter5)) {
|
|
29897
30030
|
for (const name of names) {
|
|
29898
|
-
const candidate = directory &&
|
|
30031
|
+
const candidate = directory && join24(directory, name);
|
|
29899
30032
|
if (candidate && existsSync8(candidate)) {
|
|
29900
30033
|
process.env.TOC_OCRA_NODE_PATH = candidate;
|
|
29901
30034
|
return;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CLIQuotaWindow } from './quota-types.js';
|
|
2
|
+
/** Map the usage response; windows the account does not have (null) are skipped. */
|
|
3
|
+
export declare function parseClaudeQuota(body: unknown): CLIQuotaWindow[];
|
|
4
|
+
export declare function readClaudeQuotaWindows(): Promise<CLIQuotaWindow[]>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
const execFileAsync = promisify(execFile);
|
|
7
|
+
/** Claude Code's own usage endpoint (what `/usage` shows), signed in with the CLI's OAuth token. */
|
|
8
|
+
const CLAUDE_USAGE_URL = 'https://api.anthropic.com/api/oauth/usage';
|
|
9
|
+
const WINDOWS = [
|
|
10
|
+
{ key: 'five_hour', label: '5 小时额度', seconds: 5 * 3600 },
|
|
11
|
+
{ key: 'seven_day', label: '每周额度', seconds: 7 * 86400 },
|
|
12
|
+
{ key: 'seven_day_opus', label: 'Opus · 每周额度', seconds: 7 * 86400 },
|
|
13
|
+
{ key: 'seven_day_sonnet', label: 'Sonnet · 每周额度', seconds: 7 * 86400 }
|
|
14
|
+
];
|
|
15
|
+
function objectValue(value) {
|
|
16
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
17
|
+
}
|
|
18
|
+
function resetSeconds(value) {
|
|
19
|
+
if (typeof value === 'number' && Number.isFinite(value) && value > 0)
|
|
20
|
+
return Math.floor(value > 10_000_000_000 ? value / 1000 : value);
|
|
21
|
+
if (typeof value === 'string' && value.trim()) {
|
|
22
|
+
const parsed = Date.parse(value);
|
|
23
|
+
if (Number.isFinite(parsed))
|
|
24
|
+
return Math.floor(parsed / 1000);
|
|
25
|
+
}
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
/** Map the usage response; windows the account does not have (null) are skipped. */
|
|
29
|
+
export function parseClaudeQuota(body) {
|
|
30
|
+
const source = objectValue(body);
|
|
31
|
+
const windows = [];
|
|
32
|
+
for (const { key, label, seconds } of WINDOWS) {
|
|
33
|
+
const raw = source[key];
|
|
34
|
+
if (!raw || typeof raw !== 'object')
|
|
35
|
+
continue;
|
|
36
|
+
const window = objectValue(raw);
|
|
37
|
+
const utilization = Number(window.utilization);
|
|
38
|
+
windows.push({
|
|
39
|
+
key: `claude:${key}`,
|
|
40
|
+
label,
|
|
41
|
+
resets_at: resetSeconds(window.resets_at),
|
|
42
|
+
window_seconds: seconds,
|
|
43
|
+
...(window.utilization !== null && Number.isFinite(utilization) && utilization >= 0
|
|
44
|
+
? { used_percent: Math.min(100, Math.round(utilization * 100) / 100) }
|
|
45
|
+
: {})
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return windows;
|
|
49
|
+
}
|
|
50
|
+
const claudeHome = () => process.env.CLAUDE_CONFIG_DIR?.trim() || join(homedir(), '.claude');
|
|
51
|
+
function tokenFrom(content) {
|
|
52
|
+
try {
|
|
53
|
+
const token = objectValue(objectValue(JSON.parse(content)).claudeAiOauth).accessToken;
|
|
54
|
+
return typeof token === 'string' && token.trim() ? token.trim() : undefined;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** The signed-in Claude Code OAuth token: env, credentials file, then the macOS keychain. */
|
|
61
|
+
async function readClaudeAccessToken() {
|
|
62
|
+
const fromEnv = process.env.CLAUDE_CODE_OAUTH_TOKEN?.trim();
|
|
63
|
+
if (fromEnv)
|
|
64
|
+
return fromEnv;
|
|
65
|
+
const fromFile = tokenFrom(await readFile(join(claudeHome(), '.credentials.json'), 'utf8').catch(() => ''));
|
|
66
|
+
if (fromFile)
|
|
67
|
+
return fromFile;
|
|
68
|
+
if (process.platform !== 'darwin')
|
|
69
|
+
return undefined;
|
|
70
|
+
const { stdout } = await execFileAsync('security', ['find-generic-password', '-s', 'Claude Code-credentials', '-w'], { timeout: 10_000 })
|
|
71
|
+
.catch(() => ({ stdout: '' }));
|
|
72
|
+
return tokenFrom(String(stdout).trim());
|
|
73
|
+
}
|
|
74
|
+
export async function readClaudeQuotaWindows() {
|
|
75
|
+
const token = await readClaudeAccessToken();
|
|
76
|
+
if (!token)
|
|
77
|
+
throw new Error('Claude Code 未使用 Claude 账号登录(API Key 方式没有套餐额度),请在本机运行 claude 并 /login');
|
|
78
|
+
const response = await fetch(CLAUDE_USAGE_URL, {
|
|
79
|
+
headers: { authorization: `Bearer ${token}`, 'anthropic-beta': 'oauth-2025-04-20', accept: 'application/json' },
|
|
80
|
+
redirect: 'error',
|
|
81
|
+
signal: AbortSignal.timeout(15_000)
|
|
82
|
+
});
|
|
83
|
+
if (response.status === 401 || response.status === 403)
|
|
84
|
+
throw new Error('Claude Code 登录已过期,请在本机运行一次 claude 刷新登录后再试');
|
|
85
|
+
if (!response.ok)
|
|
86
|
+
throw new Error(`Claude 额度接口请求失败 (${response.status})`);
|
|
87
|
+
const windows = parseClaudeQuota(await response.json());
|
|
88
|
+
if (!windows.length)
|
|
89
|
+
throw new Error('Claude 没有返回有效的额度窗口');
|
|
90
|
+
return windows;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=claude-quota.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-quota.js","sourceRoot":"","sources":["../../../src/providers/claude-quota.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAIrC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAA;AAEzC,oGAAoG;AACpG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