@yitom/acp-client 0.1.4 → 0.1.5
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/client/acp-client.d.ts +8 -0
- package/dist/contracts/index.d.ts +2 -0
- package/dist/contracts/quota.d.ts +61 -0
- package/dist/index.cjs +591 -116
- package/dist/index.d.ts +1 -0
- package/dist/index.js +582 -107
- package/dist/runtimes/agy/index.d.ts +1 -16
- package/dist/runtimes/agy/quota.d.ts +5 -0
- package/dist/runtimes/claude/index.d.ts +1 -0
- package/dist/runtimes/claude/quota.d.ts +4 -0
- package/dist/runtimes/codex/index.d.ts +7 -2
- package/dist/runtimes/codex/quota.d.ts +4 -0
- package/dist/runtimes/cursor/index.d.ts +1 -0
- package/dist/runtimes/cursor/quota.d.ts +2 -0
- package/dist/runtimes/index.d.ts +6 -1
- package/dist/runtimes/opencode/index.d.ts +1 -0
- package/dist/runtimes/opencode/quota.d.ts +3 -0
- package/dist/runtimes/opencode-v2/index.d.ts +10 -0
- package/dist/session/quota.d.ts +16 -0
- package/dist/sidecar.cjs +590 -112
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/sidecar.cjs
CHANGED
|
@@ -36,8 +36,7 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
36
36
|
var readline = __toESM(require("node:readline"), 1);
|
|
37
37
|
|
|
38
38
|
// src/version.ts
|
|
39
|
-
var ACP_CLIENT_VERSION = "0.1.
|
|
40
|
-
|
|
39
|
+
var ACP_CLIENT_VERSION = "0.1.5";
|
|
41
40
|
// src/contracts/index.ts
|
|
42
41
|
function ok(value) {
|
|
43
42
|
return { ok: true, value };
|
|
@@ -84,6 +83,7 @@ var CODEX_ACP_NPM_PACKAGE = "@agentclientprotocol/codex-acp";
|
|
|
84
83
|
var CLAUDE_ACP_NPM_PACKAGE = "@agentclientprotocol/claude-agent-acp";
|
|
85
84
|
var DEEPSEEK_DSH_NPM_PACKAGE = "@deepseek-ai/dsh";
|
|
86
85
|
var AGY_ACP_NPM_PACKAGE = "@yitom/agy-acp-map";
|
|
86
|
+
var OPENCODE_CLI_NPM_PACKAGE = "@opencode/cli";
|
|
87
87
|
var DEFAULT_ACP_RUNTIME_ID = "codex-acp";
|
|
88
88
|
function isWindowsPlatform() {
|
|
89
89
|
const proc = globalThis.process;
|
|
@@ -135,6 +135,15 @@ var BUILTIN_ACP_RUNTIMES = [
|
|
|
135
135
|
args: ["acp"],
|
|
136
136
|
requiredEnvKeys: []
|
|
137
137
|
},
|
|
138
|
+
{
|
|
139
|
+
id: "opencode-v2",
|
|
140
|
+
name: "OpenCode v2",
|
|
141
|
+
description: "通过 npx 启动独立产品线 @opencode/cli v2(acp);与 1.x 共存,复用 v2 SQLite 登录态",
|
|
142
|
+
authHint: "v2 登录态在 SQLite(auth.json 仅兼容残留);未登录先用 v2 二进制跑 opencode auth login",
|
|
143
|
+
command: "npx",
|
|
144
|
+
args: ["-y", OPENCODE_CLI_NPM_PACKAGE, "acp"],
|
|
145
|
+
requiredEnvKeys: []
|
|
146
|
+
},
|
|
138
147
|
{
|
|
139
148
|
id: "cursor-cli",
|
|
140
149
|
name: "Cursor",
|
|
@@ -248,6 +257,161 @@ class AvailableCommandsCache {
|
|
|
248
257
|
}
|
|
249
258
|
}
|
|
250
259
|
|
|
260
|
+
// src/session/quota.ts
|
|
261
|
+
function parseRateLimitsFromStatusText(text, runtimeId = "unknown") {
|
|
262
|
+
if (!text || typeof text !== "string")
|
|
263
|
+
return null;
|
|
264
|
+
const lines = text.split(/\r?\n/);
|
|
265
|
+
let account;
|
|
266
|
+
const windows = [];
|
|
267
|
+
let credits;
|
|
268
|
+
let status = "ok";
|
|
269
|
+
let message;
|
|
270
|
+
if (/account (?:disabled|banned|suspended)|suspended|banned/i.test(text)) {
|
|
271
|
+
status = "banned";
|
|
272
|
+
message = "账号已封禁或暂停使用 (Account banned / suspended)";
|
|
273
|
+
} else if (/RESOURCE_EXHAUSTED|quota reached|rate limit exceeded|429/i.test(text)) {
|
|
274
|
+
status = "exhausted";
|
|
275
|
+
message = "额度已用尽 (Quota / Rate limit reached)";
|
|
276
|
+
} else if (/unauthorized|authentication failed|invalid api key/i.test(text)) {
|
|
277
|
+
status = "unauthorized";
|
|
278
|
+
message = "认证失效 (Unauthorized / Invalid credentials)";
|
|
279
|
+
}
|
|
280
|
+
for (const rawLine of lines) {
|
|
281
|
+
const line = rawLine.replace(/\*\*/g, "").trim();
|
|
282
|
+
if (!line)
|
|
283
|
+
continue;
|
|
284
|
+
const accMatch = line.match(/^Account\s*[::]\s*([^()]+?)(?:\s*\(([^)]+)\))?$/i);
|
|
285
|
+
if (accMatch) {
|
|
286
|
+
account = {
|
|
287
|
+
plan: accMatch[1].trim(),
|
|
288
|
+
email: accMatch[2]?.trim()
|
|
289
|
+
};
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
const credMatch = line.match(/(?:\b|^)(?:[\w\s-]*?credits?)\s*[::]\s*(unlimited|[\d.]+)/i);
|
|
293
|
+
if (credMatch) {
|
|
294
|
+
const val = credMatch[1].trim();
|
|
295
|
+
credits = val.toLowerCase() === "unlimited" ? { unlimited: true, balance: "unlimited" } : { balance: Number(val) || val, unlimited: false };
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
const winMatch = line.match(/(?:(?:[\w-]+\s+)?([\w\s-]+?(?:limit|spend limit|window)))\s*[::]\s*(\d+(?:\.\d+)?)%\s*(?:left|remaining)(?:\s*\((?:resets\s*(?:at\s*)?([^)]+)|([^)]+))\))?/i);
|
|
299
|
+
if (winMatch) {
|
|
300
|
+
const label = winMatch[1].trim();
|
|
301
|
+
const pct = parseFloat(winMatch[2]);
|
|
302
|
+
const resetsAt = (winMatch[3] || winMatch[4] || "").trim() || undefined;
|
|
303
|
+
let windowDurationMins;
|
|
304
|
+
const lower = label.toLowerCase();
|
|
305
|
+
if (/5h|5-hour/i.test(lower))
|
|
306
|
+
windowDurationMins = 300;
|
|
307
|
+
else if (/week/i.test(lower))
|
|
308
|
+
windowDurationMins = 10080;
|
|
309
|
+
else if (/month/i.test(lower))
|
|
310
|
+
windowDurationMins = 43200;
|
|
311
|
+
else if (/day|24h/i.test(lower))
|
|
312
|
+
windowDurationMins = 1440;
|
|
313
|
+
else if (/(\d+)\s*h/i.test(lower)) {
|
|
314
|
+
const m = lower.match(/(\d+)\s*h/);
|
|
315
|
+
if (m)
|
|
316
|
+
windowDurationMins = parseInt(m[1], 10) * 60;
|
|
317
|
+
}
|
|
318
|
+
windows.push({
|
|
319
|
+
label,
|
|
320
|
+
percentLeft: pct,
|
|
321
|
+
usedPercent: Math.max(0, 100 - pct),
|
|
322
|
+
resetsAt,
|
|
323
|
+
windowDurationMins
|
|
324
|
+
});
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
const fastMatch = line.match(/(?:fast requests?|requests?)\s*[::]\s*(\d+)\s*\/\s*(\d+)/i);
|
|
328
|
+
if (fastMatch) {
|
|
329
|
+
const used = parseInt(fastMatch[1], 10);
|
|
330
|
+
const total = parseInt(fastMatch[2], 10);
|
|
331
|
+
const left = Math.max(0, total - used);
|
|
332
|
+
const pct = total > 0 ? Math.round(left / total * 100) : 0;
|
|
333
|
+
windows.push({
|
|
334
|
+
label: "Fast requests",
|
|
335
|
+
percentLeft: pct,
|
|
336
|
+
usedPercent: total > 0 ? Math.round(used / total * 100) : 0,
|
|
337
|
+
used,
|
|
338
|
+
total
|
|
339
|
+
});
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (!windows.length && !credits && !account && status === "ok") {
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
const primary = windows.find((w) => /5h|5-hour|hour|primary|fast/i.test(w.label)) || windows[0];
|
|
347
|
+
const secondary = windows.find((w) => w !== primary && /week|month|secondary/i.test(w.label)) || windows.find((w) => w !== primary);
|
|
348
|
+
const extraWindows = windows.filter((w) => w !== primary && w !== secondary);
|
|
349
|
+
if (primary && primary.percentLeft <= 10 && status === "ok") {
|
|
350
|
+
status = "warning";
|
|
351
|
+
}
|
|
352
|
+
return {
|
|
353
|
+
runtimeId,
|
|
354
|
+
account,
|
|
355
|
+
primaryWindow: primary,
|
|
356
|
+
secondaryWindow: secondary,
|
|
357
|
+
extraWindows: extraWindows.length ? extraWindows : undefined,
|
|
358
|
+
credits,
|
|
359
|
+
status,
|
|
360
|
+
message,
|
|
361
|
+
rawText: text,
|
|
362
|
+
updatedAt: Date.now()
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
class QuotaCache {
|
|
367
|
+
bySession = new Map;
|
|
368
|
+
byRuntime = new Map;
|
|
369
|
+
observe(params, defaultRuntimeId = "unknown") {
|
|
370
|
+
if (!params || typeof params !== "object")
|
|
371
|
+
return null;
|
|
372
|
+
const p = params;
|
|
373
|
+
const sessionId = typeof p.sessionId === "string" ? p.sessionId : undefined;
|
|
374
|
+
let textToParse = "";
|
|
375
|
+
if (p.update?.content && p.update.content.type === "text" && typeof p.update.content.text === "string") {
|
|
376
|
+
textToParse = p.update.content.text;
|
|
377
|
+
} else if (p.update?.message?.content && Array.isArray(p.update.message.content)) {
|
|
378
|
+
textToParse = p.update.message.content.filter((c) => c && c.type === "text" && typeof c.text === "string").map((c) => c.text).join(`
|
|
379
|
+
`);
|
|
380
|
+
}
|
|
381
|
+
if (!textToParse)
|
|
382
|
+
return null;
|
|
383
|
+
if (!/(?:limit|credits?|Account:|5h|resets|banned|suspended|quota)/i.test(textToParse)) {
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
const quota = parseRateLimitsFromStatusText(textToParse, defaultRuntimeId);
|
|
387
|
+
if (quota) {
|
|
388
|
+
if (sessionId)
|
|
389
|
+
this.bySession.set(sessionId, quota);
|
|
390
|
+
this.byRuntime.set(defaultRuntimeId, quota);
|
|
391
|
+
return quota;
|
|
392
|
+
}
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
set(quota, sessionId) {
|
|
396
|
+
if (sessionId)
|
|
397
|
+
this.bySession.set(sessionId, quota);
|
|
398
|
+
this.byRuntime.set(quota.runtimeId, quota);
|
|
399
|
+
}
|
|
400
|
+
get(sessionId, runtimeId) {
|
|
401
|
+
if (sessionId && this.bySession.has(sessionId)) {
|
|
402
|
+
return this.bySession.get(sessionId);
|
|
403
|
+
}
|
|
404
|
+
if (runtimeId && this.byRuntime.has(runtimeId)) {
|
|
405
|
+
return this.byRuntime.get(runtimeId);
|
|
406
|
+
}
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
clear() {
|
|
410
|
+
this.bySession.clear();
|
|
411
|
+
this.byRuntime.clear();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
251
415
|
// node_modules/@agentclientprotocol/sdk/dist/schema/index.js
|
|
252
416
|
var AGENT_METHODS = {
|
|
253
417
|
initialize: "initialize",
|
|
@@ -10133,38 +10297,9 @@ var legacyClientNotificationMethods = new Set([
|
|
|
10133
10297
|
CLIENT_METHODS.elicitation_complete
|
|
10134
10298
|
]);
|
|
10135
10299
|
|
|
10136
|
-
// src/runtimes/codex/
|
|
10137
|
-
var
|
|
10138
|
-
var
|
|
10139
|
-
|
|
10140
|
-
// src/runtimes/codex/codex-provider-home.ts
|
|
10141
|
-
var INKDOWN_PROVIDER_ID = "inkdown-custom";
|
|
10142
|
-
var INKDOWN_PROVIDER_API_KEY_ENV = "INKDOWN_PROVIDER_API_KEY";
|
|
10143
|
-
function tomlEscape(value) {
|
|
10144
|
-
return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
10145
|
-
}
|
|
10146
|
-
function buildCustomProviderConfigToml(config) {
|
|
10147
|
-
const name = config.name?.trim() || "自定义 API";
|
|
10148
|
-
const wireApi = config.wireApi === "responses" ? "responses" : "chat";
|
|
10149
|
-
return [
|
|
10150
|
-
`model_provider = "${INKDOWN_PROVIDER_ID}"`,
|
|
10151
|
-
`model = "${tomlEscape(config.model.trim())}"`,
|
|
10152
|
-
"",
|
|
10153
|
-
`[model_providers.${INKDOWN_PROVIDER_ID}]`,
|
|
10154
|
-
`name = "${tomlEscape(name)}"`,
|
|
10155
|
-
`base_url = "${tomlEscape(config.baseUrl.trim())}"`,
|
|
10156
|
-
`env_key = "${INKDOWN_PROVIDER_API_KEY_ENV}"`,
|
|
10157
|
-
`wire_api = "${wireApi}"`,
|
|
10158
|
-
""
|
|
10159
|
-
].join(`
|
|
10160
|
-
`);
|
|
10161
|
-
}
|
|
10162
|
-
function buildCustomProviderSpawnEnv(config, apiKey, codexHome) {
|
|
10163
|
-
return {
|
|
10164
|
-
CODEX_HOME: codexHome,
|
|
10165
|
-
[INKDOWN_PROVIDER_API_KEY_ENV]: apiKey
|
|
10166
|
-
};
|
|
10167
|
-
}
|
|
10300
|
+
// src/runtimes/codex/quota.ts
|
|
10301
|
+
var import_node_fs2 = require("node:fs");
|
|
10302
|
+
var import_node_path2 = require("node:path");
|
|
10168
10303
|
|
|
10169
10304
|
// src/runtimes/codex/codex-auth-preflight.ts
|
|
10170
10305
|
var import_node_fs = require("node:fs");
|
|
@@ -10199,14 +10334,114 @@ function probeCodexAuth() {
|
|
|
10199
10334
|
};
|
|
10200
10335
|
}
|
|
10201
10336
|
|
|
10337
|
+
// src/runtimes/codex/quota.ts
|
|
10338
|
+
function decodeJwtPayload(token) {
|
|
10339
|
+
try {
|
|
10340
|
+
const parts = token.split(".");
|
|
10341
|
+
if (parts.length < 2)
|
|
10342
|
+
return null;
|
|
10343
|
+
const json = Buffer.from(parts[1], "base64").toString("utf8");
|
|
10344
|
+
return JSON.parse(json);
|
|
10345
|
+
} catch {
|
|
10346
|
+
return null;
|
|
10347
|
+
}
|
|
10348
|
+
}
|
|
10349
|
+
async function probeCodexQuota(options) {
|
|
10350
|
+
const codexHome = resolveCodexHome();
|
|
10351
|
+
const authPath = import_node_path2.join(codexHome, "auth.json");
|
|
10352
|
+
let accountEmail;
|
|
10353
|
+
let accountPlan = "Codex Free / Local";
|
|
10354
|
+
let isLoggedIn = false;
|
|
10355
|
+
if (import_node_fs2.existsSync(authPath)) {
|
|
10356
|
+
try {
|
|
10357
|
+
const authData = JSON.parse(import_node_fs2.readFileSync(authPath, "utf8"));
|
|
10358
|
+
if (authData.OPENAI_API_KEY) {
|
|
10359
|
+
isLoggedIn = true;
|
|
10360
|
+
accountPlan = "OpenAI API Key";
|
|
10361
|
+
}
|
|
10362
|
+
if (authData.tokens?.id_token) {
|
|
10363
|
+
isLoggedIn = true;
|
|
10364
|
+
const payload = decodeJwtPayload(authData.tokens.id_token);
|
|
10365
|
+
if (payload) {
|
|
10366
|
+
if (typeof payload.email === "string")
|
|
10367
|
+
accountEmail = payload.email;
|
|
10368
|
+
const authObj = payload["https://api.openai.com/auth"];
|
|
10369
|
+
if (authObj && typeof authObj.chatgpt_plan_type === "string") {
|
|
10370
|
+
accountPlan = `ChatGPT ${authObj.chatgpt_plan_type}`;
|
|
10371
|
+
}
|
|
10372
|
+
}
|
|
10373
|
+
} else if (authData.tokens?.access_token) {
|
|
10374
|
+
isLoggedIn = true;
|
|
10375
|
+
}
|
|
10376
|
+
} catch {}
|
|
10377
|
+
}
|
|
10378
|
+
if (process.env.CODEX_API_KEY || process.env.OPENAI_API_KEY) {
|
|
10379
|
+
isLoggedIn = true;
|
|
10380
|
+
accountPlan = "API Key (Env)";
|
|
10381
|
+
}
|
|
10382
|
+
if (!isLoggedIn) {
|
|
10383
|
+
return {
|
|
10384
|
+
runtimeId: "codex-acp",
|
|
10385
|
+
provider: "OpenAI / Codex",
|
|
10386
|
+
status: "unauthorized",
|
|
10387
|
+
message: "未登录 Codex (Not logged in)",
|
|
10388
|
+
updatedAt: Date.now()
|
|
10389
|
+
};
|
|
10390
|
+
}
|
|
10391
|
+
return {
|
|
10392
|
+
runtimeId: "codex-acp",
|
|
10393
|
+
provider: "OpenAI / Codex",
|
|
10394
|
+
account: {
|
|
10395
|
+
email: accountEmail,
|
|
10396
|
+
plan: accountPlan,
|
|
10397
|
+
type: "chatgpt"
|
|
10398
|
+
},
|
|
10399
|
+
status: "ok",
|
|
10400
|
+
updatedAt: Date.now()
|
|
10401
|
+
};
|
|
10402
|
+
}
|
|
10403
|
+
|
|
10404
|
+
// src/runtimes/codex/index.ts
|
|
10405
|
+
var import_promises2 = require("node:fs/promises");
|
|
10406
|
+
var import_node_path5 = require("node:path");
|
|
10407
|
+
|
|
10408
|
+
// src/runtimes/codex/codex-provider-home.ts
|
|
10409
|
+
var INKDOWN_PROVIDER_ID = "inkdown-custom";
|
|
10410
|
+
var INKDOWN_PROVIDER_API_KEY_ENV = "INKDOWN_PROVIDER_API_KEY";
|
|
10411
|
+
function tomlEscape(value) {
|
|
10412
|
+
return value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
|
|
10413
|
+
}
|
|
10414
|
+
function buildCustomProviderConfigToml(config) {
|
|
10415
|
+
const name = config.name?.trim() || "自定义 API";
|
|
10416
|
+
const wireApi = config.wireApi === "responses" ? "responses" : "chat";
|
|
10417
|
+
return [
|
|
10418
|
+
`model_provider = "${INKDOWN_PROVIDER_ID}"`,
|
|
10419
|
+
`model = "${tomlEscape(config.model.trim())}"`,
|
|
10420
|
+
"",
|
|
10421
|
+
`[model_providers.${INKDOWN_PROVIDER_ID}]`,
|
|
10422
|
+
`name = "${tomlEscape(name)}"`,
|
|
10423
|
+
`base_url = "${tomlEscape(config.baseUrl.trim())}"`,
|
|
10424
|
+
`env_key = "${INKDOWN_PROVIDER_API_KEY_ENV}"`,
|
|
10425
|
+
`wire_api = "${wireApi}"`,
|
|
10426
|
+
""
|
|
10427
|
+
].join(`
|
|
10428
|
+
`);
|
|
10429
|
+
}
|
|
10430
|
+
function buildCustomProviderSpawnEnv(config, apiKey, codexHome) {
|
|
10431
|
+
return {
|
|
10432
|
+
CODEX_HOME: codexHome,
|
|
10433
|
+
[INKDOWN_PROVIDER_API_KEY_ENV]: apiKey
|
|
10434
|
+
};
|
|
10435
|
+
}
|
|
10436
|
+
|
|
10202
10437
|
// src/runtimes/codex/codex-provider.ts
|
|
10203
10438
|
var import_promises = require("node:fs/promises");
|
|
10204
|
-
var
|
|
10205
|
-
var
|
|
10439
|
+
var import_node_fs3 = require("node:fs");
|
|
10440
|
+
var import_node_path4 = require("node:path");
|
|
10206
10441
|
|
|
10207
10442
|
// src/client/acp-paths.ts
|
|
10208
10443
|
var import_node_os2 = require("node:os");
|
|
10209
|
-
var
|
|
10444
|
+
var import_node_path3 = require("node:path");
|
|
10210
10445
|
function getDefaultAgentDataDir() {
|
|
10211
10446
|
if (process.env.INKDOWN_DATA_DIR) {
|
|
10212
10447
|
return process.env.INKDOWN_DATA_DIR;
|
|
@@ -10215,24 +10450,24 @@ function getDefaultAgentDataDir() {
|
|
|
10215
10450
|
return process.env.ACP_DATA_DIR;
|
|
10216
10451
|
}
|
|
10217
10452
|
if (process.platform === "win32") {
|
|
10218
|
-
return process.env.LOCALAPPDATA || process.env.APPDATA ||
|
|
10453
|
+
return process.env.LOCALAPPDATA || process.env.APPDATA || import_node_path3.join(import_node_os2.homedir(), "AppData", "Local", "inkdown");
|
|
10219
10454
|
}
|
|
10220
10455
|
if (process.platform === "darwin") {
|
|
10221
|
-
return
|
|
10456
|
+
return import_node_path3.join(import_node_os2.homedir(), "Library", "Application Support", "inkdown");
|
|
10222
10457
|
}
|
|
10223
|
-
return process.env.XDG_DATA_HOME ||
|
|
10458
|
+
return process.env.XDG_DATA_HOME || import_node_path3.join(import_node_os2.homedir(), ".local", "share", "inkdown");
|
|
10224
10459
|
}
|
|
10225
10460
|
|
|
10226
10461
|
// src/runtimes/codex/codex-provider.ts
|
|
10227
10462
|
function providerFilePath(dir) {
|
|
10228
|
-
return
|
|
10463
|
+
return import_node_path4.join(dir, "agent", "provider.json");
|
|
10229
10464
|
}
|
|
10230
10465
|
function providerHomePath(dir) {
|
|
10231
|
-
return
|
|
10466
|
+
return import_node_path4.join(dir, "agent", "codex-home");
|
|
10232
10467
|
}
|
|
10233
10468
|
async function readStoredAcpProvider(dir = getDefaultAgentDataDir()) {
|
|
10234
10469
|
const file = providerFilePath(dir);
|
|
10235
|
-
if (!
|
|
10470
|
+
if (!import_node_fs3.existsSync(file))
|
|
10236
10471
|
return null;
|
|
10237
10472
|
try {
|
|
10238
10473
|
const raw = JSON.parse(await import_promises.readFile(file, "utf8"));
|
|
@@ -10258,7 +10493,7 @@ function getAcpProviderCodexHome(dir = getDefaultAgentDataDir()) {
|
|
|
10258
10493
|
async function provisionCustomProviderCodexHome(provider, codexHome) {
|
|
10259
10494
|
try {
|
|
10260
10495
|
await import_promises2.mkdir(codexHome, { recursive: true });
|
|
10261
|
-
await import_promises2.writeFile(
|
|
10496
|
+
await import_promises2.writeFile(import_node_path5.join(codexHome, "config.toml"), buildCustomProviderConfigToml(provider), "utf8");
|
|
10262
10497
|
return true;
|
|
10263
10498
|
} catch (error) {
|
|
10264
10499
|
console.error("[acp] 自定义供应商 config.toml 写入失败,回落本机登录", error);
|
|
@@ -10267,6 +10502,7 @@ async function provisionCustomProviderCodexHome(provider, codexHome) {
|
|
|
10267
10502
|
}
|
|
10268
10503
|
var codexAdapter = {
|
|
10269
10504
|
id: "codex-acp",
|
|
10505
|
+
probeQuota: async (options) => probeCodexQuota(options),
|
|
10270
10506
|
probeAuth: () => {
|
|
10271
10507
|
return probeCodexAuth();
|
|
10272
10508
|
},
|
|
@@ -10283,20 +10519,86 @@ var codexAdapter = {
|
|
|
10283
10519
|
}
|
|
10284
10520
|
};
|
|
10285
10521
|
|
|
10286
|
-
// src/runtimes/claude/
|
|
10287
|
-
var
|
|
10522
|
+
// src/runtimes/claude/quota.ts
|
|
10523
|
+
var import_node_fs4 = require("node:fs");
|
|
10288
10524
|
var import_node_os3 = require("node:os");
|
|
10289
|
-
var
|
|
10525
|
+
var import_node_path6 = require("node:path");
|
|
10526
|
+
async function probeClaudeQuota(options) {
|
|
10527
|
+
const claudeHome = resolveClaudeHome();
|
|
10528
|
+
const claudeJsonPath = import_node_path6.join(import_node_os3.homedir(), ".claude.json");
|
|
10529
|
+
const credsPath = import_node_path6.join(claudeHome, ".credentials.json");
|
|
10530
|
+
let isLoggedIn = false;
|
|
10531
|
+
let isBanned = false;
|
|
10532
|
+
let accountEmail;
|
|
10533
|
+
let plan = "Claude Free / Default";
|
|
10534
|
+
if (import_node_fs4.existsSync(claudeJsonPath)) {
|
|
10535
|
+
try {
|
|
10536
|
+
const data = JSON.parse(import_node_fs4.readFileSync(claudeJsonPath, "utf8"));
|
|
10537
|
+
if (data.oauthAccount) {
|
|
10538
|
+
isLoggedIn = true;
|
|
10539
|
+
accountEmail = data.oauthAccount.emailAddress;
|
|
10540
|
+
plan = data.oauthAccount.subscriptionTier || "Claude Pro";
|
|
10541
|
+
}
|
|
10542
|
+
if (data.isBanned || data.accountSuspended || data.status === "banned") {
|
|
10543
|
+
isBanned = true;
|
|
10544
|
+
}
|
|
10545
|
+
} catch {}
|
|
10546
|
+
}
|
|
10547
|
+
if (import_node_fs4.existsSync(credsPath)) {
|
|
10548
|
+
try {
|
|
10549
|
+
const creds = JSON.parse(import_node_fs4.readFileSync(credsPath, "utf8"));
|
|
10550
|
+
if (creds.accessToken || creds.sessionKey)
|
|
10551
|
+
isLoggedIn = true;
|
|
10552
|
+
} catch {}
|
|
10553
|
+
}
|
|
10554
|
+
if (process.env.ANTHROPIC_API_KEY || process.env.CLAUDE_CODE_OAUTH_TOKEN) {
|
|
10555
|
+
isLoggedIn = true;
|
|
10556
|
+
plan = "API Key (Env)";
|
|
10557
|
+
}
|
|
10558
|
+
if (isBanned) {
|
|
10559
|
+
return {
|
|
10560
|
+
runtimeId: "claude",
|
|
10561
|
+
provider: "Anthropic / Claude Code",
|
|
10562
|
+
status: "banned",
|
|
10563
|
+
message: "账号已被封禁或暂停使用 (Account suspended / banned)",
|
|
10564
|
+
updatedAt: Date.now()
|
|
10565
|
+
};
|
|
10566
|
+
}
|
|
10567
|
+
if (!isLoggedIn) {
|
|
10568
|
+
return {
|
|
10569
|
+
runtimeId: "claude",
|
|
10570
|
+
provider: "Anthropic / Claude Code",
|
|
10571
|
+
status: "unauthorized",
|
|
10572
|
+
message: "未登录 Claude Code 或凭据无效 (Unauthorized)",
|
|
10573
|
+
updatedAt: Date.now()
|
|
10574
|
+
};
|
|
10575
|
+
}
|
|
10576
|
+
return {
|
|
10577
|
+
runtimeId: "claude",
|
|
10578
|
+
provider: "Anthropic / Claude Code",
|
|
10579
|
+
account: {
|
|
10580
|
+
email: accountEmail,
|
|
10581
|
+
plan
|
|
10582
|
+
},
|
|
10583
|
+
status: "ok",
|
|
10584
|
+
updatedAt: Date.now()
|
|
10585
|
+
};
|
|
10586
|
+
}
|
|
10587
|
+
|
|
10588
|
+
// src/runtimes/claude/index.ts
|
|
10589
|
+
var import_node_fs5 = require("node:fs");
|
|
10590
|
+
var import_node_os4 = require("node:os");
|
|
10591
|
+
var import_node_path7 = require("node:path");
|
|
10290
10592
|
function resolveClaudeHome() {
|
|
10291
10593
|
const fromEnv = process.env.CLAUDE_CONFIG_DIR?.trim();
|
|
10292
10594
|
if (fromEnv)
|
|
10293
10595
|
return fromEnv;
|
|
10294
|
-
return
|
|
10596
|
+
return import_node_path7.join(import_node_os4.homedir(), ".claude");
|
|
10295
10597
|
}
|
|
10296
10598
|
function probeClaudeAuth() {
|
|
10297
10599
|
const claudeHome = resolveClaudeHome();
|
|
10298
|
-
const hasCodexHome =
|
|
10299
|
-
const hasAuthFile =
|
|
10600
|
+
const hasCodexHome = import_node_fs5.existsSync(claudeHome);
|
|
10601
|
+
const hasAuthFile = import_node_fs5.existsSync(import_node_path7.join(import_node_os4.homedir(), ".claude.json")) || import_node_fs5.existsSync(import_node_path7.join(claudeHome, ".credentials.json"));
|
|
10300
10602
|
const hasApiKeyEnv = Boolean(process.env.ANTHROPIC_API_KEY?.trim() || process.env.CLAUDE_CODE_OAUTH_TOKEN?.trim());
|
|
10301
10603
|
return {
|
|
10302
10604
|
codexHome: claudeHome,
|
|
@@ -10309,21 +10611,22 @@ function probeClaudeAuth() {
|
|
|
10309
10611
|
var claudeAdapter = {
|
|
10310
10612
|
id: "claude",
|
|
10311
10613
|
probeAuth: () => probeClaudeAuth(),
|
|
10614
|
+
probeQuota: async (options) => probeClaudeQuota(options),
|
|
10312
10615
|
orderAuthMethods: (methods) => methods,
|
|
10313
10616
|
canSkipInteractiveAuth: () => false
|
|
10314
10617
|
};
|
|
10315
10618
|
|
|
10316
10619
|
// src/runtimes/gemini/index.ts
|
|
10317
|
-
var
|
|
10318
|
-
var
|
|
10319
|
-
var
|
|
10620
|
+
var import_node_fs6 = require("node:fs");
|
|
10621
|
+
var import_node_os5 = require("node:os");
|
|
10622
|
+
var import_node_path8 = require("node:path");
|
|
10320
10623
|
function resolveGeminiHome() {
|
|
10321
|
-
return
|
|
10624
|
+
return import_node_path8.join(import_node_os5.homedir(), ".gemini");
|
|
10322
10625
|
}
|
|
10323
10626
|
function probeGeminiAuth() {
|
|
10324
10627
|
const geminiHome = resolveGeminiHome();
|
|
10325
|
-
const hasCodexHome =
|
|
10326
|
-
const hasAuthFile =
|
|
10628
|
+
const hasCodexHome = import_node_fs6.existsSync(geminiHome);
|
|
10629
|
+
const hasAuthFile = import_node_fs6.existsSync(import_node_path8.join(geminiHome, "oauth_creds.json")) || Boolean(process.env.GOOGLE_APPLICATION_CREDENTIALS?.trim());
|
|
10327
10630
|
const hasApiKeyEnv = Boolean(process.env.GEMINI_API_KEY?.trim() || process.env.GOOGLE_API_KEY?.trim());
|
|
10328
10631
|
return {
|
|
10329
10632
|
codexHome: geminiHome,
|
|
@@ -10341,18 +10644,18 @@ var geminiAdapter = {
|
|
|
10341
10644
|
};
|
|
10342
10645
|
|
|
10343
10646
|
// src/runtimes/copilot/index.ts
|
|
10344
|
-
var
|
|
10345
|
-
var
|
|
10346
|
-
var
|
|
10647
|
+
var import_node_fs7 = require("node:fs");
|
|
10648
|
+
var import_node_os6 = require("node:os");
|
|
10649
|
+
var import_node_path9 = require("node:path");
|
|
10347
10650
|
function resolveCopilotHome() {
|
|
10348
10651
|
const fromEnv = process.env.COPILOT_HOME?.trim();
|
|
10349
10652
|
if (fromEnv)
|
|
10350
10653
|
return fromEnv;
|
|
10351
|
-
return
|
|
10654
|
+
return import_node_path9.join(import_node_os6.homedir(), ".copilot");
|
|
10352
10655
|
}
|
|
10353
10656
|
function hasCopilotLogin(home) {
|
|
10354
10657
|
try {
|
|
10355
|
-
const raw =
|
|
10658
|
+
const raw = import_node_fs7.readFileSync(import_node_path9.join(home, "config.json"), "utf8");
|
|
10356
10659
|
const parsed = JSON.parse(raw);
|
|
10357
10660
|
return Array.isArray(parsed.loggedInUsers) && parsed.loggedInUsers.length > 0;
|
|
10358
10661
|
} catch {
|
|
@@ -10361,7 +10664,7 @@ function hasCopilotLogin(home) {
|
|
|
10361
10664
|
}
|
|
10362
10665
|
function probeCopilotAuth() {
|
|
10363
10666
|
const copilotHome = resolveCopilotHome();
|
|
10364
|
-
const hasCodexHome =
|
|
10667
|
+
const hasCodexHome = import_node_fs7.existsSync(copilotHome);
|
|
10365
10668
|
const hasAuthFile = hasCopilotLogin(copilotHome);
|
|
10366
10669
|
const hasApiKeyEnv = Boolean(process.env.COPILOT_GITHUB_TOKEN?.trim() || process.env.GH_TOKEN?.trim() || process.env.GITHUB_TOKEN?.trim());
|
|
10367
10670
|
return {
|
|
@@ -10379,17 +10682,68 @@ var copilotAdapter = {
|
|
|
10379
10682
|
canSkipInteractiveAuth: () => false
|
|
10380
10683
|
};
|
|
10381
10684
|
|
|
10685
|
+
// src/runtimes/opencode/quota.ts
|
|
10686
|
+
var import_node_fs8 = require("node:fs");
|
|
10687
|
+
function resolveOpencodeAuthPath() {
|
|
10688
|
+
const candidates = resolveOpencodeAuthCandidates();
|
|
10689
|
+
for (const c of candidates) {
|
|
10690
|
+
if (import_node_fs8.existsSync(c))
|
|
10691
|
+
return c;
|
|
10692
|
+
}
|
|
10693
|
+
return candidates[0] ?? null;
|
|
10694
|
+
}
|
|
10695
|
+
async function probeOpencodeQuota(runtimeId = "opencode") {
|
|
10696
|
+
const authPath = resolveOpencodeAuthPath();
|
|
10697
|
+
let isLoggedIn = false;
|
|
10698
|
+
let accountEmail;
|
|
10699
|
+
let plan = "OpenCode Community";
|
|
10700
|
+
if (authPath && import_node_fs8.existsSync(authPath)) {
|
|
10701
|
+
try {
|
|
10702
|
+
const data = JSON.parse(import_node_fs8.readFileSync(authPath, "utf8"));
|
|
10703
|
+
if (data && typeof data === "object") {
|
|
10704
|
+
const keys = Object.keys(data);
|
|
10705
|
+
if (keys.length > 0) {
|
|
10706
|
+
isLoggedIn = true;
|
|
10707
|
+
if (data.email)
|
|
10708
|
+
accountEmail = String(data.email);
|
|
10709
|
+
if (data.plan)
|
|
10710
|
+
plan = String(data.plan);
|
|
10711
|
+
}
|
|
10712
|
+
}
|
|
10713
|
+
} catch {}
|
|
10714
|
+
}
|
|
10715
|
+
if (!isLoggedIn) {
|
|
10716
|
+
return {
|
|
10717
|
+
runtimeId,
|
|
10718
|
+
provider: "OpenCode",
|
|
10719
|
+
status: "unauthorized",
|
|
10720
|
+
message: "未检测到 OpenCode 登录凭证 (auth.json / SQLite)",
|
|
10721
|
+
updatedAt: Date.now()
|
|
10722
|
+
};
|
|
10723
|
+
}
|
|
10724
|
+
return {
|
|
10725
|
+
runtimeId,
|
|
10726
|
+
provider: "OpenCode",
|
|
10727
|
+
account: {
|
|
10728
|
+
email: accountEmail,
|
|
10729
|
+
plan
|
|
10730
|
+
},
|
|
10731
|
+
status: "ok",
|
|
10732
|
+
updatedAt: Date.now()
|
|
10733
|
+
};
|
|
10734
|
+
}
|
|
10735
|
+
|
|
10382
10736
|
// src/runtimes/opencode/index.ts
|
|
10383
|
-
var
|
|
10384
|
-
var
|
|
10385
|
-
var
|
|
10737
|
+
var import_node_fs9 = require("node:fs");
|
|
10738
|
+
var import_node_os7 = require("node:os");
|
|
10739
|
+
var import_node_path10 = require("node:path");
|
|
10386
10740
|
function pickEnv(env, key) {
|
|
10387
10741
|
return env?.[key]?.trim() ?? "";
|
|
10388
10742
|
}
|
|
10389
10743
|
function resolveOpencodeAuthCandidates(overrides) {
|
|
10390
10744
|
const platform = overrides?.platform ?? process.platform;
|
|
10391
10745
|
const env = overrides?.env ?? process.env;
|
|
10392
|
-
const home = overrides?.home ??
|
|
10746
|
+
const home = overrides?.home ?? import_node_os7.homedir();
|
|
10393
10747
|
const seen = new Set;
|
|
10394
10748
|
const out = [];
|
|
10395
10749
|
const push = (p) => {
|
|
@@ -10400,27 +10754,27 @@ function resolveOpencodeAuthCandidates(overrides) {
|
|
|
10400
10754
|
};
|
|
10401
10755
|
const xdg = pickEnv(env, "XDG_DATA_HOME");
|
|
10402
10756
|
if (xdg)
|
|
10403
|
-
push(
|
|
10757
|
+
push(import_node_path10.join(xdg, "opencode", "auth.json"));
|
|
10404
10758
|
if (platform === "win32") {
|
|
10405
|
-
const localAppData = pickEnv(env, "LOCALAPPDATA") || (pickEnv(env, "USERPROFILE") ?
|
|
10759
|
+
const localAppData = pickEnv(env, "LOCALAPPDATA") || (pickEnv(env, "USERPROFILE") ? import_node_path10.join(pickEnv(env, "USERPROFILE"), "AppData", "Local") : "");
|
|
10406
10760
|
if (localAppData)
|
|
10407
|
-
push(
|
|
10761
|
+
push(import_node_path10.join(localAppData, "opencode", "auth.json"));
|
|
10408
10762
|
const userProfile = pickEnv(env, "USERPROFILE") || home;
|
|
10409
10763
|
if (userProfile)
|
|
10410
|
-
push(
|
|
10764
|
+
push(import_node_path10.join(userProfile, ".local", "share", "opencode", "auth.json"));
|
|
10411
10765
|
} else if (home) {
|
|
10412
|
-
push(
|
|
10766
|
+
push(import_node_path10.join(home, ".local", "share", "opencode", "auth.json"));
|
|
10413
10767
|
}
|
|
10414
10768
|
return out;
|
|
10415
10769
|
}
|
|
10416
10770
|
function resolveOpencodeAuthFile() {
|
|
10417
|
-
return resolveOpencodeAuthCandidates()[0] ??
|
|
10771
|
+
return resolveOpencodeAuthCandidates()[0] ?? import_node_path10.join(import_node_os7.homedir(), ".local", "share", "opencode", "auth.json");
|
|
10418
10772
|
}
|
|
10419
10773
|
function isValidOpencodeAuthFile(authFile) {
|
|
10420
10774
|
try {
|
|
10421
|
-
if (!authFile || !
|
|
10775
|
+
if (!authFile || !import_node_fs9.existsSync(authFile))
|
|
10422
10776
|
return false;
|
|
10423
|
-
const raw =
|
|
10777
|
+
const raw = import_node_fs9.readFileSync(authFile, "utf8").trim();
|
|
10424
10778
|
if (!raw)
|
|
10425
10779
|
return false;
|
|
10426
10780
|
const parsed = JSON.parse(raw);
|
|
@@ -10438,7 +10792,7 @@ function probeOpencodeAuth(overrides) {
|
|
|
10438
10792
|
for (const candidate of candidates) {
|
|
10439
10793
|
let exists = false;
|
|
10440
10794
|
try {
|
|
10441
|
-
exists =
|
|
10795
|
+
exists = import_node_fs9.existsSync(candidate);
|
|
10442
10796
|
} catch {
|
|
10443
10797
|
exists = false;
|
|
10444
10798
|
}
|
|
@@ -10451,10 +10805,10 @@ function probeOpencodeAuth(overrides) {
|
|
|
10451
10805
|
validFile = candidate;
|
|
10452
10806
|
}
|
|
10453
10807
|
const authFile = validFile ?? firstExisting ?? candidates[0] ?? resolveOpencodeAuthFile();
|
|
10454
|
-
const authDir =
|
|
10808
|
+
const authDir = import_node_path10.dirname(authFile);
|
|
10455
10809
|
let hasCodexHome = false;
|
|
10456
10810
|
try {
|
|
10457
|
-
hasCodexHome =
|
|
10811
|
+
hasCodexHome = import_node_fs9.existsSync(authDir);
|
|
10458
10812
|
} catch {
|
|
10459
10813
|
hasCodexHome = false;
|
|
10460
10814
|
}
|
|
@@ -10470,33 +10824,65 @@ function probeOpencodeAuth(overrides) {
|
|
|
10470
10824
|
var opencodeAdapter = {
|
|
10471
10825
|
id: "opencode",
|
|
10472
10826
|
probeAuth: () => probeOpencodeAuth(),
|
|
10827
|
+
probeQuota: async () => probeOpencodeQuota(),
|
|
10828
|
+
orderAuthMethods: (methods) => methods,
|
|
10829
|
+
canSkipInteractiveAuth: () => false,
|
|
10830
|
+
tryDirectSessionFirst: true
|
|
10831
|
+
};
|
|
10832
|
+
|
|
10833
|
+
// src/runtimes/opencode-v2/index.ts
|
|
10834
|
+
var opencodeV2Adapter = {
|
|
10835
|
+
id: "opencode-v2",
|
|
10836
|
+
probeAuth: () => probeOpencodeAuth(),
|
|
10473
10837
|
orderAuthMethods: (methods) => methods,
|
|
10474
10838
|
canSkipInteractiveAuth: () => false,
|
|
10475
10839
|
tryDirectSessionFirst: true
|
|
10476
10840
|
};
|
|
10477
10841
|
|
|
10842
|
+
// src/runtimes/cursor/quota.ts
|
|
10843
|
+
async function probeCursorQuota() {
|
|
10844
|
+
const auth = probeCursorAuth();
|
|
10845
|
+
if (!auth.looksLoggedIn) {
|
|
10846
|
+
return {
|
|
10847
|
+
runtimeId: "cursor-cli",
|
|
10848
|
+
provider: "Cursor",
|
|
10849
|
+
status: "unauthorized",
|
|
10850
|
+
message: "未检测到 Cursor CLI 登录凭证",
|
|
10851
|
+
updatedAt: Date.now()
|
|
10852
|
+
};
|
|
10853
|
+
}
|
|
10854
|
+
return {
|
|
10855
|
+
runtimeId: "cursor-cli",
|
|
10856
|
+
provider: "Cursor",
|
|
10857
|
+
account: {
|
|
10858
|
+
plan: "Cursor Pro / Fast Requests"
|
|
10859
|
+
},
|
|
10860
|
+
status: "ok",
|
|
10861
|
+
updatedAt: Date.now()
|
|
10862
|
+
};
|
|
10863
|
+
}
|
|
10478
10864
|
// src/runtimes/cursor/index.ts
|
|
10479
|
-
var
|
|
10480
|
-
var
|
|
10481
|
-
var
|
|
10865
|
+
var import_node_fs10 = require("node:fs");
|
|
10866
|
+
var import_node_os8 = require("node:os");
|
|
10867
|
+
var import_node_path11 = require("node:path");
|
|
10482
10868
|
function cursorLocalAppData(env) {
|
|
10483
10869
|
const local = env.LOCALAPPDATA?.trim();
|
|
10484
10870
|
if (local)
|
|
10485
10871
|
return local;
|
|
10486
10872
|
const profile = env.USERPROFILE?.trim();
|
|
10487
|
-
return profile ?
|
|
10873
|
+
return profile ? import_node_path11.join(profile, "AppData", "Local") : "";
|
|
10488
10874
|
}
|
|
10489
10875
|
function isOnPath(command, env, platform) {
|
|
10490
10876
|
const pathValue = env.PATH ?? env.Path ?? "";
|
|
10491
10877
|
if (!pathValue.trim())
|
|
10492
10878
|
return false;
|
|
10493
|
-
const sep = platform === "win32" ? ";" :
|
|
10879
|
+
const sep = platform === "win32" ? ";" : import_node_path11.delimiter;
|
|
10494
10880
|
for (const dir of pathValue.split(sep)) {
|
|
10495
10881
|
const trimmed = dir.trim().replace(/^"|"$/g, "");
|
|
10496
10882
|
if (!trimmed)
|
|
10497
10883
|
continue;
|
|
10498
10884
|
try {
|
|
10499
|
-
if (
|
|
10885
|
+
if (import_node_fs10.existsSync(import_node_path11.join(trimmed, command)))
|
|
10500
10886
|
return true;
|
|
10501
10887
|
} catch {}
|
|
10502
10888
|
}
|
|
@@ -10505,19 +10891,19 @@ function isOnPath(command, env, platform) {
|
|
|
10505
10891
|
function resolveDirectCursorCommand(platform, env, home) {
|
|
10506
10892
|
if (platform === "win32") {
|
|
10507
10893
|
const localAppData = cursorLocalAppData(env);
|
|
10508
|
-
return localAppData ?
|
|
10894
|
+
return localAppData ? import_node_path11.join(localAppData, "cursor-agent", "agent.cmd") : "";
|
|
10509
10895
|
}
|
|
10510
|
-
return home ?
|
|
10896
|
+
return home ? import_node_path11.join(home, ".local", "bin", "agent") : "";
|
|
10511
10897
|
}
|
|
10512
10898
|
function resolveCursorSpawnCommand(overrides) {
|
|
10513
10899
|
const args = ["acp"];
|
|
10514
10900
|
const platform = overrides?.platform ?? process.platform;
|
|
10515
10901
|
const env = overrides?.env ?? process.env;
|
|
10516
|
-
const home = overrides?.home ??
|
|
10902
|
+
const home = overrides?.home ?? import_node_os8.homedir();
|
|
10517
10903
|
const binary = platform === "win32" ? "agent.cmd" : "agent";
|
|
10518
10904
|
const direct = resolveDirectCursorCommand(platform, env, home);
|
|
10519
10905
|
try {
|
|
10520
|
-
if (direct &&
|
|
10906
|
+
if (direct && import_node_fs10.existsSync(direct))
|
|
10521
10907
|
return { command: direct, args };
|
|
10522
10908
|
} catch {}
|
|
10523
10909
|
if (isOnPath(binary, env, platform))
|
|
@@ -10532,12 +10918,12 @@ function cursorRoamingAppData(env, home) {
|
|
|
10532
10918
|
if (roaming)
|
|
10533
10919
|
return roaming;
|
|
10534
10920
|
const profile = pickEnv2(env, "USERPROFILE") || home;
|
|
10535
|
-
return profile ?
|
|
10921
|
+
return profile ? import_node_path11.join(profile, "AppData", "Roaming") : "";
|
|
10536
10922
|
}
|
|
10537
10923
|
function resolveCursorAuthCandidates(overrides) {
|
|
10538
10924
|
const platform = overrides?.platform ?? process.platform;
|
|
10539
10925
|
const env = overrides?.env ?? process.env;
|
|
10540
|
-
const home = overrides?.home ??
|
|
10926
|
+
const home = overrides?.home ?? import_node_os8.homedir();
|
|
10541
10927
|
const seen = new Set;
|
|
10542
10928
|
const out = [];
|
|
10543
10929
|
const push = (p) => {
|
|
@@ -10548,16 +10934,16 @@ function resolveCursorAuthCandidates(overrides) {
|
|
|
10548
10934
|
};
|
|
10549
10935
|
const xdg = pickEnv2(env, "XDG_CONFIG_HOME");
|
|
10550
10936
|
if (xdg)
|
|
10551
|
-
push(
|
|
10937
|
+
push(import_node_path11.join(xdg, "cursor", "auth.json"));
|
|
10552
10938
|
if (platform === "win32") {
|
|
10553
10939
|
const profile = pickEnv2(env, "USERPROFILE") || home;
|
|
10554
10940
|
if (profile)
|
|
10555
|
-
push(
|
|
10941
|
+
push(import_node_path11.join(profile, ".config", "cursor", "auth.json"));
|
|
10556
10942
|
const roaming = cursorRoamingAppData(env, home);
|
|
10557
10943
|
if (roaming)
|
|
10558
|
-
push(
|
|
10944
|
+
push(import_node_path11.join(roaming, "Cursor", "User", "globalStorage", "storage.json"));
|
|
10559
10945
|
} else if (home) {
|
|
10560
|
-
push(
|
|
10946
|
+
push(import_node_path11.join(home, ".config", "cursor", "auth.json"));
|
|
10561
10947
|
}
|
|
10562
10948
|
return out;
|
|
10563
10949
|
}
|
|
@@ -10568,9 +10954,9 @@ function isValidCursorAuthFile(authFile) {
|
|
|
10568
10954
|
try {
|
|
10569
10955
|
if (!authFile || isStorageHintPath(authFile))
|
|
10570
10956
|
return false;
|
|
10571
|
-
if (!
|
|
10957
|
+
if (!import_node_fs10.existsSync(authFile))
|
|
10572
10958
|
return false;
|
|
10573
|
-
const raw =
|
|
10959
|
+
const raw = import_node_fs10.readFileSync(authFile, "utf8").trim();
|
|
10574
10960
|
if (!raw)
|
|
10575
10961
|
return false;
|
|
10576
10962
|
const parsed = JSON.parse(raw);
|
|
@@ -10588,9 +10974,9 @@ function isHintCursorStorageFile(authFile) {
|
|
|
10588
10974
|
try {
|
|
10589
10975
|
if (!authFile || !isStorageHintPath(authFile))
|
|
10590
10976
|
return false;
|
|
10591
|
-
if (!
|
|
10977
|
+
if (!import_node_fs10.existsSync(authFile))
|
|
10592
10978
|
return false;
|
|
10593
|
-
const raw =
|
|
10979
|
+
const raw = import_node_fs10.readFileSync(authFile, "utf8").trim();
|
|
10594
10980
|
if (!raw)
|
|
10595
10981
|
return false;
|
|
10596
10982
|
const parsed = JSON.parse(raw);
|
|
@@ -10606,7 +10992,7 @@ function isValidCursorCandidate(authFile) {
|
|
|
10606
10992
|
}
|
|
10607
10993
|
function probeCursorAuth(overrides) {
|
|
10608
10994
|
const env = overrides?.env ?? process.env;
|
|
10609
|
-
const home = overrides?.home ??
|
|
10995
|
+
const home = overrides?.home ?? import_node_os8.homedir();
|
|
10610
10996
|
const hasApiKeyEnv = Boolean(env.CURSOR_API_KEY?.trim() || env.CURSOR_AUTH_TOKEN?.trim());
|
|
10611
10997
|
const candidates = resolveCursorAuthCandidates(overrides);
|
|
10612
10998
|
let firstExisting = null;
|
|
@@ -10614,7 +11000,7 @@ function probeCursorAuth(overrides) {
|
|
|
10614
11000
|
for (const candidate of candidates) {
|
|
10615
11001
|
let exists = false;
|
|
10616
11002
|
try {
|
|
10617
|
-
exists =
|
|
11003
|
+
exists = import_node_fs10.existsSync(candidate);
|
|
10618
11004
|
} catch {
|
|
10619
11005
|
exists = false;
|
|
10620
11006
|
}
|
|
@@ -10626,12 +11012,12 @@ function probeCursorAuth(overrides) {
|
|
|
10626
11012
|
if (isValidCursorCandidate(candidate))
|
|
10627
11013
|
validFile = candidate;
|
|
10628
11014
|
}
|
|
10629
|
-
const fallback = home ?
|
|
11015
|
+
const fallback = home ? import_node_path11.join(home, ".config", "cursor", "auth.json") : "";
|
|
10630
11016
|
const authFile = validFile ?? firstExisting ?? candidates[0] ?? fallback;
|
|
10631
|
-
const authDir = authFile ?
|
|
11017
|
+
const authDir = authFile ? import_node_path11.dirname(authFile) : "";
|
|
10632
11018
|
let hasCodexHome = false;
|
|
10633
11019
|
try {
|
|
10634
|
-
hasCodexHome = authDir ?
|
|
11020
|
+
hasCodexHome = authDir ? import_node_fs10.existsSync(authDir) : false;
|
|
10635
11021
|
} catch {
|
|
10636
11022
|
hasCodexHome = false;
|
|
10637
11023
|
}
|
|
@@ -10646,6 +11032,7 @@ function probeCursorAuth(overrides) {
|
|
|
10646
11032
|
var cursorAdapter = {
|
|
10647
11033
|
id: "cursor-cli",
|
|
10648
11034
|
probeAuth: () => probeCursorAuth(),
|
|
11035
|
+
probeQuota: async () => probeCursorQuota(),
|
|
10649
11036
|
resolveSpawnCommand: () => resolveCursorSpawnCommand(),
|
|
10650
11037
|
orderAuthMethods: (methods) => methods,
|
|
10651
11038
|
canSkipInteractiveAuth: () => false,
|
|
@@ -10699,6 +11086,55 @@ var deepseekAdapter = {
|
|
|
10699
11086
|
canSkipInteractiveAuth: () => false
|
|
10700
11087
|
};
|
|
10701
11088
|
|
|
11089
|
+
// src/runtimes/agy/quota.ts
|
|
11090
|
+
var import_node_fs11 = require("node:fs");
|
|
11091
|
+
var import_node_path12 = require("node:path");
|
|
11092
|
+
function resolveGeminiHome2() {
|
|
11093
|
+
const home = process.env.USERPROFILE || process.env.HOME || "";
|
|
11094
|
+
return import_node_path12.join(home, ".gemini");
|
|
11095
|
+
}
|
|
11096
|
+
async function probeAgyQuota(options) {
|
|
11097
|
+
const geminiHome = resolveGeminiHome2();
|
|
11098
|
+
const hasAgyDir = import_node_fs11.existsSync(import_node_path12.join(geminiHome, "antigravity")) || import_node_fs11.existsSync(import_node_path12.join(geminiHome, "antigravity-cli"));
|
|
11099
|
+
const hasApiKey = Boolean(process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY);
|
|
11100
|
+
const isAvailable = hasAgyDir || hasApiKey;
|
|
11101
|
+
if (!isAvailable) {
|
|
11102
|
+
return {
|
|
11103
|
+
runtimeId: "agy",
|
|
11104
|
+
provider: "Google Antigravity",
|
|
11105
|
+
status: "unauthorized",
|
|
11106
|
+
message: "wenjianlingu antigravity cli",
|
|
11107
|
+
updatedAt: Date.now()
|
|
11108
|
+
};
|
|
11109
|
+
}
|
|
11110
|
+
return {
|
|
11111
|
+
runtimeId: "agy",
|
|
11112
|
+
provider: "Google Antigravity",
|
|
11113
|
+
account: {
|
|
11114
|
+
plan: "Antigravity / Gemini",
|
|
11115
|
+
type: "gemini"
|
|
11116
|
+
},
|
|
11117
|
+
primaryWindow: {
|
|
11118
|
+
label: "5-Hour limit",
|
|
11119
|
+
percentLeft: 100,
|
|
11120
|
+
usedPercent: 0,
|
|
11121
|
+
windowDurationMins: 300
|
|
11122
|
+
},
|
|
11123
|
+
secondaryWindow: {
|
|
11124
|
+
label: "Weekly limit",
|
|
11125
|
+
percentLeft: 100,
|
|
11126
|
+
usedPercent: 0,
|
|
11127
|
+
windowDurationMins: 10080
|
|
11128
|
+
},
|
|
11129
|
+
credits: {
|
|
11130
|
+
unlimited: true,
|
|
11131
|
+
balance: "unlimited"
|
|
11132
|
+
},
|
|
11133
|
+
status: "ok",
|
|
11134
|
+
updatedAt: Date.now()
|
|
11135
|
+
};
|
|
11136
|
+
}
|
|
11137
|
+
|
|
10702
11138
|
// src/runtimes/agy/index.ts
|
|
10703
11139
|
function probeAgyAuth() {
|
|
10704
11140
|
return {
|
|
@@ -10712,6 +11148,7 @@ function probeAgyAuth() {
|
|
|
10712
11148
|
var agyAdapter = {
|
|
10713
11149
|
id: "agy",
|
|
10714
11150
|
probeAuth: () => probeAgyAuth(),
|
|
11151
|
+
probeQuota: (options) => probeAgyQuota(options),
|
|
10715
11152
|
orderAuthMethods: (methods) => methods,
|
|
10716
11153
|
canSkipInteractiveAuth: () => false,
|
|
10717
11154
|
tryDirectSessionFirst: true
|
|
@@ -10731,6 +11168,8 @@ function getAcpRuntimeAdapter(runtimeId) {
|
|
|
10731
11168
|
return copilotAdapter;
|
|
10732
11169
|
case opencodeAdapter.id:
|
|
10733
11170
|
return opencodeAdapter;
|
|
11171
|
+
case opencodeV2Adapter.id:
|
|
11172
|
+
return opencodeV2Adapter;
|
|
10734
11173
|
case cursorAdapter.id:
|
|
10735
11174
|
case "cursor":
|
|
10736
11175
|
return cursorAdapter;
|
|
@@ -10937,17 +11376,17 @@ async function sdkRequest(agent, method, params, timeoutMs = ACP_SDK_REQUEST_TIM
|
|
|
10937
11376
|
|
|
10938
11377
|
// src/client/acp-fs.ts
|
|
10939
11378
|
var import_promises3 = require("node:fs/promises");
|
|
10940
|
-
var
|
|
11379
|
+
var import_node_path13 = require("node:path");
|
|
10941
11380
|
var import_promises4 = require("node:fs/promises");
|
|
10942
11381
|
var MAX_READ_BYTES = 2 * 1024 * 1024;
|
|
10943
11382
|
var BINARY_DOCUMENT_EXTENSIONS = new Set([".epub", ".mobi", ".azw", ".azw3", ".pdf"]);
|
|
10944
11383
|
function isBinaryDocumentPath(filePath) {
|
|
10945
|
-
return BINARY_DOCUMENT_EXTENSIONS.has(
|
|
11384
|
+
return BINARY_DOCUMENT_EXTENSIONS.has(import_node_path13.extname(filePath).toLowerCase());
|
|
10946
11385
|
}
|
|
10947
11386
|
function assertPathInsideWorkspace(filePath, workspaceRoot) {
|
|
10948
|
-
const root =
|
|
10949
|
-
const target =
|
|
10950
|
-
const rootWithSep = root.endsWith(
|
|
11387
|
+
const root = import_node_path13.resolve(workspaceRoot);
|
|
11388
|
+
const target = import_node_path13.resolve(filePath);
|
|
11389
|
+
const rootWithSep = root.endsWith(import_node_path13.sep) ? root : root + import_node_path13.sep;
|
|
10951
11390
|
if (target !== root && !target.startsWith(rootWithSep)) {
|
|
10952
11391
|
throw new Error(`路径不在工作区内: ${filePath}`);
|
|
10953
11392
|
}
|
|
@@ -10978,7 +11417,7 @@ async function acpReadTextFile(params) {
|
|
|
10978
11417
|
}
|
|
10979
11418
|
async function acpWriteTextFile(params) {
|
|
10980
11419
|
const abs = assertPathInsideWorkspace(params.path, params.workspaceRoot);
|
|
10981
|
-
await import_promises4.mkdir(
|
|
11420
|
+
await import_promises4.mkdir(import_node_path13.dirname(abs), { recursive: true });
|
|
10982
11421
|
await import_promises3.writeFile(abs, params.content, "utf-8");
|
|
10983
11422
|
return {};
|
|
10984
11423
|
}
|
|
@@ -11623,8 +12062,8 @@ class AcpTerminalManager {
|
|
|
11623
12062
|
|
|
11624
12063
|
// src/client/acp-proxy-service.ts
|
|
11625
12064
|
var import_promises5 = require("node:fs/promises");
|
|
11626
|
-
var
|
|
11627
|
-
var
|
|
12065
|
+
var import_node_fs12 = require("node:fs");
|
|
12066
|
+
var import_node_path14 = require("node:path");
|
|
11628
12067
|
var DEFAULT_ACP_PROXY_SETTINGS = {
|
|
11629
12068
|
enabled: false,
|
|
11630
12069
|
host: "127.0.0.1",
|
|
@@ -11633,11 +12072,11 @@ var DEFAULT_ACP_PROXY_SETTINGS = {
|
|
|
11633
12072
|
var PROXY_ENV_KEYS = ["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY"];
|
|
11634
12073
|
var LOWERCASE_PROXY_ENV_KEYS = ["http_proxy", "https_proxy", "all_proxy", "no_proxy"];
|
|
11635
12074
|
function proxyFilePath(dir) {
|
|
11636
|
-
return
|
|
12075
|
+
return import_node_path14.join(dir, "agent", "proxy.json");
|
|
11637
12076
|
}
|
|
11638
12077
|
async function readAcpProxySettings(dir = getDefaultAgentDataDir()) {
|
|
11639
12078
|
const file = proxyFilePath(dir);
|
|
11640
|
-
if (!
|
|
12079
|
+
if (!import_node_fs12.existsSync(file))
|
|
11641
12080
|
return { ...DEFAULT_ACP_PROXY_SETTINGS };
|
|
11642
12081
|
try {
|
|
11643
12082
|
const raw = JSON.parse(await import_promises5.readFile(file, "utf8"));
|
|
@@ -11700,6 +12139,12 @@ class AcpSessionHandle {
|
|
|
11700
12139
|
async prompt(promptText, options) {
|
|
11701
12140
|
return this.client.promptSession(this.sessionId, promptText, options);
|
|
11702
12141
|
}
|
|
12142
|
+
get quota() {
|
|
12143
|
+
return this.client.getCachedQuota(this.sessionId);
|
|
12144
|
+
}
|
|
12145
|
+
async getQuota() {
|
|
12146
|
+
return this.client.getQuota(this.sessionId);
|
|
12147
|
+
}
|
|
11703
12148
|
get availableCommands() {
|
|
11704
12149
|
return this.client.getAvailableCommands(this.sessionId);
|
|
11705
12150
|
}
|
|
@@ -11711,6 +12156,7 @@ class AcpSessionHandle {
|
|
|
11711
12156
|
class AcpClient {
|
|
11712
12157
|
status = "disconnected";
|
|
11713
12158
|
commandsCache = new AvailableCommandsCache;
|
|
12159
|
+
quotaCache = new QuotaCache;
|
|
11714
12160
|
runtimeInfo;
|
|
11715
12161
|
adapter;
|
|
11716
12162
|
workspaceRoot;
|
|
@@ -11821,6 +12267,7 @@ class AcpClient {
|
|
|
11821
12267
|
},
|
|
11822
12268
|
onSessionUpdate: (params) => {
|
|
11823
12269
|
this.commandsCache.observe(params);
|
|
12270
|
+
this.quotaCache.observe(params, this.runtimeInfo.id);
|
|
11824
12271
|
this.callbacks.onSessionUpdate?.(params);
|
|
11825
12272
|
}
|
|
11826
12273
|
};
|
|
@@ -11851,6 +12298,23 @@ class AcpClient {
|
|
|
11851
12298
|
return err({ code: "ACP_PROTOCOL_ERROR", message });
|
|
11852
12299
|
}
|
|
11853
12300
|
}
|
|
12301
|
+
getCachedQuota(sessionId) {
|
|
12302
|
+
return this.quotaCache.get(sessionId, this.runtimeInfo.id);
|
|
12303
|
+
}
|
|
12304
|
+
async getQuota(sessionId) {
|
|
12305
|
+
const cached = this.getCachedQuota(sessionId);
|
|
12306
|
+
if (cached && Date.now() - cached.updatedAt < 30000) {
|
|
12307
|
+
return cached;
|
|
12308
|
+
}
|
|
12309
|
+
if (this.adapter.probeQuota) {
|
|
12310
|
+
const probed = await this.adapter.probeQuota({ sessionId });
|
|
12311
|
+
if (probed) {
|
|
12312
|
+
this.quotaCache.set(probed, sessionId);
|
|
12313
|
+
return probed;
|
|
12314
|
+
}
|
|
12315
|
+
}
|
|
12316
|
+
return cached ?? null;
|
|
12317
|
+
}
|
|
11854
12318
|
getAvailableCommands(sessionId) {
|
|
11855
12319
|
return this.commandsCache.get(sessionId);
|
|
11856
12320
|
}
|
|
@@ -12678,6 +13142,20 @@ async function handleRpcRequest(id, method, params) {
|
|
|
12678
13142
|
}
|
|
12679
13143
|
break;
|
|
12680
13144
|
}
|
|
13145
|
+
case "session/quota": {
|
|
13146
|
+
const { sessionId } = params ?? {};
|
|
13147
|
+
if (!client2) {
|
|
13148
|
+
sendError(id, -32002, "Client not connected");
|
|
13149
|
+
return;
|
|
13150
|
+
}
|
|
13151
|
+
try {
|
|
13152
|
+
const quota = await client2.getQuota(sessionId ? String(sessionId) : undefined);
|
|
13153
|
+
sendResponse(id, { sessionId, quota });
|
|
13154
|
+
} catch (err) {
|
|
13155
|
+
sendError(id, -32000, err instanceof Error ? err.message : String(err));
|
|
13156
|
+
}
|
|
13157
|
+
break;
|
|
13158
|
+
}
|
|
12681
13159
|
case "session/commands": {
|
|
12682
13160
|
const { sessionId } = params ?? {};
|
|
12683
13161
|
if (!client2) {
|