@yitom/acp-client 0.1.11 → 0.1.13
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/README.md +45 -1
- package/dist/client/acp-client.d.ts +2 -2
- package/dist/client/client-handlers.d.ts +3 -3
- package/dist/client/sdk-client.d.ts +6 -2
- package/dist/client/session-open.d.ts +16 -5
- package/dist/contracts/index.d.ts +27 -0
- package/dist/index.cjs +699 -120
- package/dist/index.js +712 -132
- package/dist/resources/app-resources.d.ts +7 -0
- package/dist/resources/runtime-bindings.d.ts +6 -1
- package/dist/runtimes/codex/index.d.ts +2 -0
- package/dist/runtimes/deepseek/deepseek-provider.d.ts +50 -0
- package/dist/runtimes/deepseek/dsh-acp-bootstrap.d.ts +65 -0
- package/dist/runtimes/deepseek/index.d.ts +51 -12
- package/dist/runtimes/deepseek/quota.d.ts +24 -0
- package/dist/runtimes/index.d.ts +22 -2
- package/dist/session/quota.d.ts +9 -0
- package/dist/sidecar.cjs +1004 -766
- package/dist/version.d.ts +1 -1
- package/docs/api-reference.md +137 -0
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -142,8 +142,8 @@ var BUILTIN_ACP_RUNTIMES = [
|
|
|
142
142
|
{
|
|
143
143
|
id: "deepseek",
|
|
144
144
|
name: "DeepSeek",
|
|
145
|
-
description: "通过
|
|
146
|
-
authHint: "无 ACP 登录,靠 harness
|
|
145
|
+
description: "通过 dsh 启动 @deepseek-ai/dsh(--profile acp);无 ACP 登录,靠 harness 自身凭证(DEEPSEEK_API_KEY 或 $DSH_HOME/.credentials.yaml);模型经 session 到达(V4.1-Flash 的 id 是 deepseek-flash)",
|
|
146
|
+
authHint: "无 ACP 登录,靠 harness 自身凭证;先导出 DEEPSEEK_API_KEY 或在 dsh 里完成登录;稳定安装可设 DSH_BIN 指向 dsh 入口(bunx 临时目录被清理会让 profile 断链);pin 包版本用 DSH_PACKAGE(如 @deepseek-ai/dsh@0.2.1-rc.2)",
|
|
147
147
|
command: "bunx",
|
|
148
148
|
args: ["-y", `${DEEPSEEK_DSH_NPM_PACKAGE}@latest`, "--profile", "acp"],
|
|
149
149
|
requiredEnvKeys: ["DEEPSEEK_API_KEY"]
|
|
@@ -162,17 +162,20 @@ function findBuiltinAcpRuntime(id) {
|
|
|
162
162
|
return BUILTIN_ACP_RUNTIMES.find((item) => item.id === id);
|
|
163
163
|
}
|
|
164
164
|
// src/version.ts
|
|
165
|
-
var ACP_CLIENT_VERSION = "0.1.
|
|
165
|
+
var ACP_CLIENT_VERSION = "0.1.13";
|
|
166
166
|
// src/client/sdk-client.ts
|
|
167
167
|
import { PassThrough, Readable, Writable } from "node:stream";
|
|
168
168
|
import {
|
|
169
169
|
client as createSdkClientApp,
|
|
170
|
-
ndJsonStream
|
|
170
|
+
ndJsonStream,
|
|
171
|
+
methods
|
|
171
172
|
} from "@agentclientprotocol/sdk";
|
|
172
173
|
var ACP_SDK_REQUEST_TIMEOUT_MS = 120000;
|
|
173
174
|
function createSdkStreamHandle(child) {
|
|
174
175
|
const stdoutBridge = new PassThrough;
|
|
175
176
|
const stdinBridge = new PassThrough;
|
|
177
|
+
stdoutBridge.on("error", () => {});
|
|
178
|
+
stdinBridge.on("error", () => {});
|
|
176
179
|
child.stdout.pipe(stdoutBridge);
|
|
177
180
|
stdinBridge.pipe(child.stdin, { end: false });
|
|
178
181
|
const output = Writable.toWeb(stdinBridge);
|
|
@@ -200,11 +203,11 @@ function createSdkStreamHandle(child) {
|
|
|
200
203
|
}
|
|
201
204
|
};
|
|
202
205
|
}
|
|
203
|
-
function connectSdkClient(child, configure, runtimeId) {
|
|
206
|
+
function connectSdkClient(child, configure, runtimeId, options = {}) {
|
|
204
207
|
if (runtimeId && true) {
|
|
205
208
|
console.info(`[acp:sdk] connect runtime=${runtimeId} pid=${child.pid ?? "?"}`);
|
|
206
209
|
}
|
|
207
|
-
const app = createSdkClientApp({ name: "inkdown" });
|
|
210
|
+
const app = createSdkClientApp({ name: options.name ?? "inkdown" });
|
|
208
211
|
configure(app);
|
|
209
212
|
const streamHandle = createSdkStreamHandle(child);
|
|
210
213
|
const connection = app.connect(streamHandle.stream);
|
|
@@ -234,7 +237,7 @@ async function closeAcpSessions(agent, sessionIds, timeoutMs = 2000) {
|
|
|
234
237
|
const failed = [];
|
|
235
238
|
await Promise.all([...new Set(sessionIds)].map(async (sessionId) => {
|
|
236
239
|
try {
|
|
237
|
-
await sdkRequest(agent,
|
|
240
|
+
await sdkRequest(agent, methods.agent.session.close, { sessionId }, timeoutMs);
|
|
238
241
|
} catch {
|
|
239
242
|
failed.push(sessionId);
|
|
240
243
|
}
|
|
@@ -676,11 +679,24 @@ function parseRateLimitsFromStatusText(text, runtimeId = "unknown") {
|
|
|
676
679
|
class QuotaCache {
|
|
677
680
|
bySession = new Map;
|
|
678
681
|
byRuntime = new Map;
|
|
682
|
+
usageBySession = new Map;
|
|
683
|
+
usageByRuntime = new Map;
|
|
679
684
|
observe(params, defaultRuntimeId = "unknown") {
|
|
680
685
|
if (!params || typeof params !== "object")
|
|
681
686
|
return null;
|
|
682
687
|
const p = params;
|
|
683
688
|
const sessionId = typeof p.sessionId === "string" ? p.sessionId : undefined;
|
|
689
|
+
if (p.update?.sessionUpdate === "usage_update") {
|
|
690
|
+
const used = Number(p.update.used);
|
|
691
|
+
const size = Number(p.update.size);
|
|
692
|
+
if (Number.isFinite(used) && Number.isFinite(size) && size > 0) {
|
|
693
|
+
const usage = { used, size, updatedAt: Date.now() };
|
|
694
|
+
if (sessionId)
|
|
695
|
+
this.usageBySession.set(sessionId, usage);
|
|
696
|
+
this.usageByRuntime.set(defaultRuntimeId, usage);
|
|
697
|
+
}
|
|
698
|
+
return null;
|
|
699
|
+
}
|
|
684
700
|
let textToParse = "";
|
|
685
701
|
if (p.update?.content && p.update.content.type === "text" && typeof p.update.content.text === "string") {
|
|
686
702
|
textToParse = p.update.content.text;
|
|
@@ -716,15 +732,35 @@ class QuotaCache {
|
|
|
716
732
|
}
|
|
717
733
|
return;
|
|
718
734
|
}
|
|
735
|
+
applyContextUsage(quota, sessionId, runtimeId = "unknown") {
|
|
736
|
+
const usage = (sessionId ? this.usageBySession.get(sessionId) : undefined) ?? this.usageByRuntime.get(runtimeId);
|
|
737
|
+
if (!usage)
|
|
738
|
+
return quota ?? null;
|
|
739
|
+
const usedPercent = usage.size > 0 ? Math.min(100, Math.round(usage.used / usage.size * 100)) : 0;
|
|
740
|
+
const window = {
|
|
741
|
+
label: "Context",
|
|
742
|
+
used: usage.used,
|
|
743
|
+
total: usage.size,
|
|
744
|
+
usedPercent,
|
|
745
|
+
percentLeft: Math.max(0, 100 - usedPercent)
|
|
746
|
+
};
|
|
747
|
+
if (!quota) {
|
|
748
|
+
return { runtimeId, primaryWindow: window, status: "ok", updatedAt: usage.updatedAt };
|
|
749
|
+
}
|
|
750
|
+
const rest = (quota.extraWindows ?? []).filter((item) => item.label !== "Context");
|
|
751
|
+
return { ...quota, extraWindows: [window, ...rest] };
|
|
752
|
+
}
|
|
719
753
|
clear() {
|
|
720
754
|
this.bySession.clear();
|
|
721
755
|
this.byRuntime.clear();
|
|
756
|
+
this.usageBySession.clear();
|
|
757
|
+
this.usageByRuntime.clear();
|
|
722
758
|
}
|
|
723
759
|
}
|
|
724
760
|
|
|
725
761
|
// src/client/acp-client.ts
|
|
726
762
|
import {
|
|
727
|
-
methods as
|
|
763
|
+
methods as methods4
|
|
728
764
|
} from "@agentclientprotocol/sdk";
|
|
729
765
|
|
|
730
766
|
// src/runtimes/codex/quota.ts
|
|
@@ -1316,7 +1352,7 @@ import { promisify } from "node:util";
|
|
|
1316
1352
|
var APP_RESOURCE_CAPABILITIES = {
|
|
1317
1353
|
"codex-acp": { entry: "CODEX_CONFIG", strategy: "native-overlay", configHome: "CODEX_HOME" },
|
|
1318
1354
|
opencode: { entry: "OPENCODE_CONFIG_CONTENT", strategy: "native-overlay", configHome: "OPENCODE_CONFIG_DIR" },
|
|
1319
|
-
"opencode-v2": { entry:
|
|
1355
|
+
"opencode-v2": { entry: "OPENCODE_CONFIG_CONTENT (questions only)", strategy: "compatibility", configHome: null },
|
|
1320
1356
|
claude: { entry: "_meta.systemPrompt + _meta.claudeCode.options.plugins", strategy: "native-session", configHome: "CLAUDE_CONFIG_DIR" },
|
|
1321
1357
|
gemini: { entry: null, strategy: "compatibility", configHome: "GEMINI_CLI_HOME" },
|
|
1322
1358
|
copilot: { entry: null, strategy: "compatibility", configHome: "COPILOT_HOME", candidateEntry: "COPILOT_CUSTOM_INSTRUCTIONS_DIRS" },
|
|
@@ -1354,18 +1390,49 @@ function mergeOpenCodeAppConfig(raw, directory) {
|
|
|
1354
1390
|
skills: { ...skills, paths: [...new Set([...skills.paths ?? [], join8(directory, "skills")])] }
|
|
1355
1391
|
});
|
|
1356
1392
|
}
|
|
1393
|
+
function resolveOpenCodeQuestionMode(version) {
|
|
1394
|
+
const normalized = version.trim().replace(/^opencode\s+v?/i, "");
|
|
1395
|
+
return ["1.18.35", "2.0.6"].includes(normalized) ? "fallback" : "unverified";
|
|
1396
|
+
}
|
|
1397
|
+
function mergeOpenCodeQuestionConfig(raw) {
|
|
1398
|
+
const value = raw?.trim() ? JSON.parse(raw) : {};
|
|
1399
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
1400
|
+
throw new Error("invalid-opencode-config");
|
|
1401
|
+
const config = value;
|
|
1402
|
+
const permission = config.permission;
|
|
1403
|
+
if (permission !== undefined && (typeof permission !== "string" || !["allow", "ask", "deny"].includes(permission)) && (!permission || typeof permission !== "object" || Array.isArray(permission)))
|
|
1404
|
+
throw new Error("invalid-opencode-permission");
|
|
1405
|
+
const rules = typeof permission === "string" ? { "*": permission } : permission ?? {};
|
|
1406
|
+
return JSON.stringify({ ...config, permission: { ...rules, question: "deny" } });
|
|
1407
|
+
}
|
|
1357
1408
|
async function prepareOpenCodeResources(input) {
|
|
1358
1409
|
const prep = prepareCompatibilityResources(input.directory, "native-entry-not-verified");
|
|
1359
|
-
|
|
1410
|
+
prep.report.openCodeQuestions = { mode: "unverified", configuration: "unchanged", reason: "version-not-verified" };
|
|
1411
|
+
if (!input.command)
|
|
1360
1412
|
return prep;
|
|
1361
1413
|
try {
|
|
1362
1414
|
const { stdout } = await promisify(execFile)(input.command, ["--version"], { env: input.env, timeout: 8000, windowsHide: true });
|
|
1363
|
-
|
|
1415
|
+
const version = stdout.trim().replace(/^opencode\s+v?/i, "");
|
|
1416
|
+
if (resolveOpenCodeQuestionMode(version) !== "fallback") {
|
|
1417
|
+
prep.report.openCodeQuestions.version = version;
|
|
1364
1418
|
return prep;
|
|
1365
|
-
|
|
1366
|
-
|
|
1419
|
+
}
|
|
1420
|
+
let json = mergeOpenCodeQuestionConfig(input.env?.OPENCODE_CONFIG_CONTENT);
|
|
1421
|
+
const hasRules = version === "1.18.35" && !!readAppRulesText(input.directory);
|
|
1422
|
+
if (hasRules)
|
|
1423
|
+
json = mergeOpenCodeAppConfig(json, input.directory);
|
|
1424
|
+
return { env: { OPENCODE_CONFIG_CONTENT: json }, report: {
|
|
1425
|
+
...prep.report,
|
|
1426
|
+
rulesPrepared: hasRules,
|
|
1427
|
+
reason: hasRules ? undefined : version === "2.0.6" ? "native-entry-not-verified" : "missing-app-rules",
|
|
1428
|
+
openCodeQuestions: { version, mode: "fallback", configuration: "prepared", reason: "acp-question-not-forwarded" }
|
|
1429
|
+
} };
|
|
1367
1430
|
} catch {
|
|
1368
|
-
return { ...prep, report: {
|
|
1431
|
+
return { ...prep, report: {
|
|
1432
|
+
...prep.report,
|
|
1433
|
+
reason: "native-config-prepare-failed",
|
|
1434
|
+
openCodeQuestions: { mode: "unverified", configuration: "unchanged", reason: "prepare-failed" }
|
|
1435
|
+
} };
|
|
1369
1436
|
}
|
|
1370
1437
|
}
|
|
1371
1438
|
function prepareClaudeResources(directory) {
|
|
@@ -1961,7 +2028,7 @@ var opencodeAdapter = {
|
|
|
1961
2028
|
// src/runtimes/opencode-v2/index.ts
|
|
1962
2029
|
var opencodeV2Adapter = {
|
|
1963
2030
|
id: "opencode-v2",
|
|
1964
|
-
prepareAppResources:
|
|
2031
|
+
prepareAppResources: prepareOpenCodeResources,
|
|
1965
2032
|
probeAuth: () => probeOpencodeAuth(),
|
|
1966
2033
|
orderAuthMethods: (methods) => methods,
|
|
1967
2034
|
canSkipInteractiveAuth: () => false,
|
|
@@ -2261,14 +2328,383 @@ function getCursorCatalogIds(execFile, overrides) {
|
|
|
2261
2328
|
}
|
|
2262
2329
|
}
|
|
2263
2330
|
|
|
2331
|
+
// src/runtimes/deepseek/index.ts
|
|
2332
|
+
import { existsSync as existsSync15, readFileSync as readFileSync10 } from "node:fs";
|
|
2333
|
+
|
|
2334
|
+
// src/runtimes/deepseek/deepseek-provider.ts
|
|
2335
|
+
import { existsSync as existsSync13, mkdirSync, readFileSync as readFileSync8, rmSync, writeFileSync } from "node:fs";
|
|
2336
|
+
import { homedir as homedir11 } from "node:os";
|
|
2337
|
+
import { dirname as dirname4, join as join16 } from "node:path";
|
|
2338
|
+
var DEEPSEEK_OFFICIAL_BASE_URL = "https://api.deepseek.com/anthropic";
|
|
2339
|
+
function resolveDshHome(env = process.env) {
|
|
2340
|
+
const override = env.DSH_HOME?.trim();
|
|
2341
|
+
return override || join16(homedir11(), ".dsh");
|
|
2342
|
+
}
|
|
2343
|
+
function resolveDshCredentialsFile(env = process.env) {
|
|
2344
|
+
return join16(resolveDshHome(env), ".credentials.yaml");
|
|
2345
|
+
}
|
|
2346
|
+
function escapeRegExp(value) {
|
|
2347
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2348
|
+
}
|
|
2349
|
+
function readHarnessCredential(name, env = process.env) {
|
|
2350
|
+
try {
|
|
2351
|
+
const text = readFileSync8(resolveDshCredentialsFile(env), "utf8");
|
|
2352
|
+
const pattern = new RegExp(`^\\s+${escapeRegExp(name)}\\s*:\\s*(.+)$`);
|
|
2353
|
+
let inRefs = false;
|
|
2354
|
+
for (const line of text.split(/\r?\n/)) {
|
|
2355
|
+
if (/^refs\s*:/.test(line)) {
|
|
2356
|
+
inRefs = true;
|
|
2357
|
+
continue;
|
|
2358
|
+
}
|
|
2359
|
+
if (!inRefs)
|
|
2360
|
+
continue;
|
|
2361
|
+
if (/^\S/.test(line))
|
|
2362
|
+
break;
|
|
2363
|
+
const match = pattern.exec(line);
|
|
2364
|
+
if (match) {
|
|
2365
|
+
const value = match[1].trim().replace(/^['"]|['"]$/g, "");
|
|
2366
|
+
return value || null;
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
return null;
|
|
2370
|
+
} catch {
|
|
2371
|
+
return null;
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
function normalizeDeepseekBaseUrl(raw) {
|
|
2375
|
+
const trimmed = (raw ?? "").trim();
|
|
2376
|
+
if (!trimmed)
|
|
2377
|
+
return DEEPSEEK_OFFICIAL_BASE_URL;
|
|
2378
|
+
const withoutSlash = trimmed.replace(/\/+$/, "");
|
|
2379
|
+
try {
|
|
2380
|
+
const url = new URL(withoutSlash);
|
|
2381
|
+
if (url.host.toLowerCase() === "api.deepseek.com" && (url.pathname === "" || url.pathname === "/")) {
|
|
2382
|
+
return DEEPSEEK_OFFICIAL_BASE_URL;
|
|
2383
|
+
}
|
|
2384
|
+
return withoutSlash;
|
|
2385
|
+
} catch {
|
|
2386
|
+
return withoutSlash;
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
function providerFilePath2(dir) {
|
|
2390
|
+
return join16(dir, "agent", "deepseek-provider.json");
|
|
2391
|
+
}
|
|
2392
|
+
function readStoredDeepseekProvider(dir = getDefaultAgentDataDir()) {
|
|
2393
|
+
const file = providerFilePath2(dir);
|
|
2394
|
+
if (!existsSync13(file))
|
|
2395
|
+
return null;
|
|
2396
|
+
try {
|
|
2397
|
+
const raw = JSON.parse(readFileSync8(file, "utf8"));
|
|
2398
|
+
if (typeof raw.baseUrl !== "string" || typeof raw.apiKey !== "string" || !raw.apiKey.trim()) {
|
|
2399
|
+
return null;
|
|
2400
|
+
}
|
|
2401
|
+
return { baseUrl: normalizeDeepseekBaseUrl(raw.baseUrl), apiKey: raw.apiKey };
|
|
2402
|
+
} catch {
|
|
2403
|
+
return null;
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
function getDeepseekProviderStatus(dir = getDefaultAgentDataDir()) {
|
|
2407
|
+
const stored = readStoredDeepseekProvider(dir);
|
|
2408
|
+
if (!stored)
|
|
2409
|
+
return { configured: false, isOfficial: true, hasApiKey: false };
|
|
2410
|
+
return {
|
|
2411
|
+
configured: true,
|
|
2412
|
+
baseUrl: stored.baseUrl,
|
|
2413
|
+
isOfficial: stored.baseUrl === DEEPSEEK_OFFICIAL_BASE_URL,
|
|
2414
|
+
hasApiKey: Boolean(stored.apiKey)
|
|
2415
|
+
};
|
|
2416
|
+
}
|
|
2417
|
+
function validateBaseUrl(baseUrl) {
|
|
2418
|
+
try {
|
|
2419
|
+
const url = new URL(baseUrl);
|
|
2420
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
2421
|
+
return "URL 必须是 http(s) 地址";
|
|
2422
|
+
if (!url.hostname)
|
|
2423
|
+
return "URL 缺少主机名";
|
|
2424
|
+
return null;
|
|
2425
|
+
} catch {
|
|
2426
|
+
return "URL 不是合法地址";
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
function saveDeepseekProvider(payload, dir = getDefaultAgentDataDir()) {
|
|
2430
|
+
const baseUrl = normalizeDeepseekBaseUrl(payload.baseUrl);
|
|
2431
|
+
const invalid = validateBaseUrl(baseUrl);
|
|
2432
|
+
if (invalid)
|
|
2433
|
+
return err({ code: "INVALID_ARGUMENT", message: invalid });
|
|
2434
|
+
const apiKey = payload.apiKey?.trim() || readStoredDeepseekProvider(dir)?.apiKey || "";
|
|
2435
|
+
if (!apiKey)
|
|
2436
|
+
return err({ code: "INVALID_ARGUMENT", message: "Token/API Key 不能为空" });
|
|
2437
|
+
const file = providerFilePath2(dir);
|
|
2438
|
+
try {
|
|
2439
|
+
mkdirSync(dirname4(file), { recursive: true });
|
|
2440
|
+
writeFileSync(file, JSON.stringify({ baseUrl, apiKey }, null, 2), "utf8");
|
|
2441
|
+
} catch (error) {
|
|
2442
|
+
return err({
|
|
2443
|
+
code: "FILE_WRITE_ERROR",
|
|
2444
|
+
message: error instanceof Error ? error.message : "写入 DeepSeek 配置失败"
|
|
2445
|
+
});
|
|
2446
|
+
}
|
|
2447
|
+
return ok(getDeepseekProviderStatus(dir));
|
|
2448
|
+
}
|
|
2449
|
+
function clearDeepseekProvider(dir = getDefaultAgentDataDir()) {
|
|
2450
|
+
try {
|
|
2451
|
+
rmSync(providerFilePath2(dir), { force: true });
|
|
2452
|
+
return ok(undefined);
|
|
2453
|
+
} catch (error) {
|
|
2454
|
+
return err({
|
|
2455
|
+
code: "FILE_WRITE_ERROR",
|
|
2456
|
+
message: error instanceof Error ? error.message : "删除 DeepSeek 配置失败"
|
|
2457
|
+
});
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
function buildDeepseekProviderEnv(stored, currentEnv = process.env) {
|
|
2461
|
+
if (!stored)
|
|
2462
|
+
return {};
|
|
2463
|
+
const env = {};
|
|
2464
|
+
if (!currentEnv.DEEPSEEK_BASE_URL?.trim())
|
|
2465
|
+
env.DEEPSEEK_BASE_URL = stored.baseUrl;
|
|
2466
|
+
if (!currentEnv.DEEPSEEK_API_KEY?.trim())
|
|
2467
|
+
env.DEEPSEEK_API_KEY = stored.apiKey;
|
|
2468
|
+
return env;
|
|
2469
|
+
}
|
|
2470
|
+
|
|
2471
|
+
// src/runtimes/deepseek/dsh-acp-bootstrap.ts
|
|
2472
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync2, readFileSync as readFileSync9, readdirSync as readdirSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
2473
|
+
import { homedir as homedir12, tmpdir as tmpdir2 } from "node:os";
|
|
2474
|
+
import { join as join17 } from "node:path";
|
|
2475
|
+
var DSH_ACP_PINNED_VERSION = "0.2.1-rc.2";
|
|
2476
|
+
var DSH_ACP_DEFAULT_MODEL = "deepseek-flash";
|
|
2477
|
+
var DSH_ACP_DEFAULT_PROVIDER = "deepseek-official";
|
|
2478
|
+
function resolveDshRuntimeRoot(env = process.env) {
|
|
2479
|
+
const override = env.DSH_RUNTIME_DIR?.trim();
|
|
2480
|
+
if (override)
|
|
2481
|
+
return override;
|
|
2482
|
+
if (process.platform === "win32") {
|
|
2483
|
+
const localAppData = env.LOCALAPPDATA?.trim() || join17(homedir12(), "AppData", "Local");
|
|
2484
|
+
return join17(localAppData, "acp-dsh");
|
|
2485
|
+
}
|
|
2486
|
+
if (process.platform === "darwin") {
|
|
2487
|
+
return join17(homedir12(), "Library", "Application Support", "acp-dsh");
|
|
2488
|
+
}
|
|
2489
|
+
const dataHome = env.XDG_DATA_HOME?.trim() || join17(homedir12(), ".local", "share");
|
|
2490
|
+
return join17(dataHome, "acp-dsh");
|
|
2491
|
+
}
|
|
2492
|
+
function resolveManagedDshEntry(env = process.env, version = resolveManagedDshVersion(env)) {
|
|
2493
|
+
return join17(resolveDshRuntimeRoot(env), version, "node_modules", "@deepseek-ai", "dsh", "lib", "bin.js");
|
|
2494
|
+
}
|
|
2495
|
+
function parseVersion(value) {
|
|
2496
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(value);
|
|
2497
|
+
if (!match)
|
|
2498
|
+
return null;
|
|
2499
|
+
return {
|
|
2500
|
+
nums: [Number(match[1]), Number(match[2]), Number(match[3])],
|
|
2501
|
+
pre: match[4] ? match[4].split(".") : []
|
|
2502
|
+
};
|
|
2503
|
+
}
|
|
2504
|
+
function compareDshVersions(a, b) {
|
|
2505
|
+
const left = parseVersion(a);
|
|
2506
|
+
const right = parseVersion(b);
|
|
2507
|
+
if (!left || !right)
|
|
2508
|
+
return a.localeCompare(b);
|
|
2509
|
+
for (let i = 0;i < 3; i += 1) {
|
|
2510
|
+
if (left.nums[i] !== right.nums[i])
|
|
2511
|
+
return left.nums[i] - right.nums[i];
|
|
2512
|
+
}
|
|
2513
|
+
if (left.pre.length === 0 && right.pre.length > 0)
|
|
2514
|
+
return 1;
|
|
2515
|
+
if (left.pre.length > 0 && right.pre.length === 0)
|
|
2516
|
+
return -1;
|
|
2517
|
+
for (let i = 0;i < Math.max(left.pre.length, right.pre.length); i += 1) {
|
|
2518
|
+
const x = left.pre[i];
|
|
2519
|
+
const y = right.pre[i];
|
|
2520
|
+
if (x === undefined)
|
|
2521
|
+
return -1;
|
|
2522
|
+
if (y === undefined)
|
|
2523
|
+
return 1;
|
|
2524
|
+
const nx = Number(x);
|
|
2525
|
+
const ny = Number(y);
|
|
2526
|
+
if (!Number.isNaN(nx) && !Number.isNaN(ny) && nx !== ny)
|
|
2527
|
+
return nx - ny;
|
|
2528
|
+
if (x !== y)
|
|
2529
|
+
return x < y ? -1 : 1;
|
|
2530
|
+
}
|
|
2531
|
+
return 0;
|
|
2532
|
+
}
|
|
2533
|
+
function hasManagedEntry(root, version) {
|
|
2534
|
+
return existsSync14(join17(root, version, "node_modules", "@deepseek-ai", "dsh", "lib", "bin.js"));
|
|
2535
|
+
}
|
|
2536
|
+
function resolveManagedDshVersion(env = process.env) {
|
|
2537
|
+
const explicit = env.DSH_RUNTIME_VERSION?.trim();
|
|
2538
|
+
if (explicit)
|
|
2539
|
+
return explicit;
|
|
2540
|
+
const root = resolveDshRuntimeRoot(env);
|
|
2541
|
+
let best = null;
|
|
2542
|
+
try {
|
|
2543
|
+
for (const name of readdirSync2(root)) {
|
|
2544
|
+
if (!parseVersion(name))
|
|
2545
|
+
continue;
|
|
2546
|
+
if (!hasManagedEntry(root, name))
|
|
2547
|
+
continue;
|
|
2548
|
+
if (best === null || compareDshVersions(name, best) > 0)
|
|
2549
|
+
best = name;
|
|
2550
|
+
}
|
|
2551
|
+
} catch {}
|
|
2552
|
+
return best ?? DSH_ACP_PINNED_VERSION;
|
|
2553
|
+
}
|
|
2554
|
+
function hasManagedDshRuntime(env = process.env) {
|
|
2555
|
+
return existsSync14(resolveManagedDshEntry(env));
|
|
2556
|
+
}
|
|
2557
|
+
function safeId(raw, fallback) {
|
|
2558
|
+
const value = raw?.trim();
|
|
2559
|
+
return value && /^[A-Za-z0-9._-]+$/.test(value) ? value : fallback;
|
|
2560
|
+
}
|
|
2561
|
+
function resolveAcpModelOverride(env = process.env) {
|
|
2562
|
+
const flag = env.DSH_ACP_MODEL_PATCH?.trim().toLowerCase();
|
|
2563
|
+
if (flag === "off" || flag === "0" || flag === "false" || flag === "none")
|
|
2564
|
+
return null;
|
|
2565
|
+
return {
|
|
2566
|
+
provider: safeId(env.DSH_PROVIDER, DSH_ACP_DEFAULT_PROVIDER),
|
|
2567
|
+
model: safeId(env.DSH_MODEL, DSH_ACP_DEFAULT_MODEL)
|
|
2568
|
+
};
|
|
2569
|
+
}
|
|
2570
|
+
function buildAcpModelPatch(override) {
|
|
2571
|
+
return [
|
|
2572
|
+
"# 由 @yitom/acp-client 生成:修正 ACP 会话默认模型。",
|
|
2573
|
+
"# dsh-acp-app 自带补丁把 model 写死为 deepseek-v4-flash,该 id 不在 provider catalog 中;",
|
|
2574
|
+
"# V4.1-Flash 的 catalog id 是 deepseek-flash(桌面端 1017 只是 UI 徽标)。",
|
|
2575
|
+
"- id: acp",
|
|
2576
|
+
" name: '@deepseek-ai/dsh-acp'",
|
|
2577
|
+
" config:",
|
|
2578
|
+
` provider: ${override.provider}`,
|
|
2579
|
+
` model: ${override.model}`,
|
|
2580
|
+
""
|
|
2581
|
+
].join(`
|
|
2582
|
+
`);
|
|
2583
|
+
}
|
|
2584
|
+
var patchFileCache = new Map;
|
|
2585
|
+
function ensureAcpModelPatchFile(env = process.env) {
|
|
2586
|
+
const override = resolveAcpModelOverride(env);
|
|
2587
|
+
if (!override)
|
|
2588
|
+
return null;
|
|
2589
|
+
const key = `${override.provider}/${override.model}`;
|
|
2590
|
+
const cached = patchFileCache.get(key);
|
|
2591
|
+
if (cached !== undefined)
|
|
2592
|
+
return cached;
|
|
2593
|
+
try {
|
|
2594
|
+
const dir = join17(tmpdir2(), "acp-dsh-runtime");
|
|
2595
|
+
mkdirSync2(dir, { recursive: true });
|
|
2596
|
+
const file = join17(dir, `acp-model-${override.provider}--${override.model}.patch.yml`);
|
|
2597
|
+
const body = buildAcpModelPatch(override);
|
|
2598
|
+
if (!existsSync14(file) || readFileSync9(file, "utf8") !== body) {
|
|
2599
|
+
writeFileSync2(file, body, "utf8");
|
|
2600
|
+
}
|
|
2601
|
+
patchFileCache.set(key, file);
|
|
2602
|
+
return file;
|
|
2603
|
+
} catch {
|
|
2604
|
+
patchFileCache.set(key, null);
|
|
2605
|
+
return null;
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
function resetAcpModelPatchCache() {
|
|
2609
|
+
patchFileCache.clear();
|
|
2610
|
+
}
|
|
2611
|
+
|
|
2612
|
+
// src/runtimes/deepseek/quota.ts
|
|
2613
|
+
var DEFAULT_TIMEOUT_MS = 4000;
|
|
2614
|
+
function resolveDeepseekQuotaKey(options = {}) {
|
|
2615
|
+
const env = options.env ?? process.env;
|
|
2616
|
+
const envKey = env.DEEPSEEK_API_KEY?.trim();
|
|
2617
|
+
if (envKey)
|
|
2618
|
+
return envKey;
|
|
2619
|
+
if (options.dataDir) {
|
|
2620
|
+
const stored = readStoredDeepseekProvider(options.dataDir);
|
|
2621
|
+
if (stored?.apiKey)
|
|
2622
|
+
return stored.apiKey;
|
|
2623
|
+
}
|
|
2624
|
+
return readHarnessCredential("DEEPSEEK_API_KEY", env);
|
|
2625
|
+
}
|
|
2626
|
+
function resolveDeepseekApiBase(options = {}) {
|
|
2627
|
+
const env = options.env ?? process.env;
|
|
2628
|
+
const raw = env.DEEPSEEK_BASE_URL?.trim() || (options.dataDir ? readStoredDeepseekProvider(options.dataDir)?.baseUrl : undefined) || DEEPSEEK_OFFICIAL_BASE_URL;
|
|
2629
|
+
const trimmed = raw.replace(/\/+$/, "").replace(/\/anthropic$/i, "");
|
|
2630
|
+
return trimmed || "https://api.deepseek.com";
|
|
2631
|
+
}
|
|
2632
|
+
function unauthorized(runtimeId, message) {
|
|
2633
|
+
return { runtimeId, provider: "DeepSeek", status: "unauthorized", message, updatedAt: Date.now() };
|
|
2634
|
+
}
|
|
2635
|
+
async function probeDeepseekQuota(options = {}) {
|
|
2636
|
+
const runtimeId = options.runtimeId ?? "deepseek";
|
|
2637
|
+
const apiKey = resolveDeepseekQuotaKey(options);
|
|
2638
|
+
if (!apiKey) {
|
|
2639
|
+
return unauthorized(runtimeId, "未配置 DEEPSEEK_API_KEY / 表单 Token,无法查询余额");
|
|
2640
|
+
}
|
|
2641
|
+
const doFetch = options.fetchImpl ?? fetch;
|
|
2642
|
+
try {
|
|
2643
|
+
const response = await doFetch(`${resolveDeepseekApiBase(options)}/user/balance`, {
|
|
2644
|
+
headers: { Authorization: `Bearer ${apiKey}`, Accept: "application/json" },
|
|
2645
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS)
|
|
2646
|
+
});
|
|
2647
|
+
if (response.status === 401 || response.status === 403) {
|
|
2648
|
+
return unauthorized(runtimeId, `余额查询被拒绝 (HTTP ${response.status})`);
|
|
2649
|
+
}
|
|
2650
|
+
if (!response.ok)
|
|
2651
|
+
return null;
|
|
2652
|
+
const data = await response.json();
|
|
2653
|
+
const infos = Array.isArray(data.balance_infos) ? data.balance_infos : [];
|
|
2654
|
+
const first = infos[0];
|
|
2655
|
+
const total = first ? Number(first.total_balance) : Number.NaN;
|
|
2656
|
+
const credits = first ? {
|
|
2657
|
+
balance: Number.isFinite(total) ? total : first.total_balance ?? "0",
|
|
2658
|
+
currency: first.currency
|
|
2659
|
+
} : undefined;
|
|
2660
|
+
const balanceText = infos.map((info) => `${info.total_balance ?? "0"} ${info.currency ?? ""}`.trim()).join(" / ");
|
|
2661
|
+
return {
|
|
2662
|
+
runtimeId,
|
|
2663
|
+
provider: "DeepSeek",
|
|
2664
|
+
account: { type: "apiKey", plan: "DeepSeek API" },
|
|
2665
|
+
credits,
|
|
2666
|
+
status: data.is_available === false ? "exhausted" : "ok",
|
|
2667
|
+
message: data.is_available === false ? "账户余额不足,API 暂不可用" : `可用余额 ${balanceText || "未知"}`,
|
|
2668
|
+
rawText: JSON.stringify(data),
|
|
2669
|
+
updatedAt: Date.now()
|
|
2670
|
+
};
|
|
2671
|
+
} catch {
|
|
2672
|
+
return null;
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
|
|
2264
2676
|
// src/runtimes/deepseek/index.ts
|
|
2265
2677
|
function buildDeepseekMissingKeyMessage() {
|
|
2266
|
-
return "未检测到 DEEPSEEK_API_KEY
|
|
2678
|
+
return "未检测到 DEEPSEEK_API_KEY,也未在 harness 凭证库中找到登录记录:请先在终端导出该变量,或先在该 harness(dsh)里完成登录后再连接";
|
|
2267
2679
|
}
|
|
2268
|
-
function
|
|
2680
|
+
function hasDshCredentials(env) {
|
|
2681
|
+
try {
|
|
2682
|
+
const text = readFileSync10(resolveDshCredentialsFile(env), "utf8");
|
|
2683
|
+
const match = /^records\s*:(.*)$/m.exec(text);
|
|
2684
|
+
if (!match)
|
|
2685
|
+
return false;
|
|
2686
|
+
if (/^\s*(\[\]|\{\}|null|~)\s*$/.test(match[1]))
|
|
2687
|
+
return false;
|
|
2688
|
+
for (const line of text.slice(match.index + match[0].length).split(/\r?\n/)) {
|
|
2689
|
+
if (!line.trim() || line.trim().startsWith("#"))
|
|
2690
|
+
continue;
|
|
2691
|
+
if (/^\s+\S/.test(line))
|
|
2692
|
+
return true;
|
|
2693
|
+
return false;
|
|
2694
|
+
}
|
|
2695
|
+
return false;
|
|
2696
|
+
} catch {
|
|
2697
|
+
return false;
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
function resolveDeepseekSpawnBlocker(env, dataDir) {
|
|
2269
2701
|
const source = env ?? process.env;
|
|
2270
2702
|
if (source.DEEPSEEK_API_KEY?.trim())
|
|
2271
2703
|
return null;
|
|
2704
|
+
if (dataDir && readStoredDeepseekProvider(dataDir))
|
|
2705
|
+
return null;
|
|
2706
|
+
if (hasDshCredentials(source))
|
|
2707
|
+
return null;
|
|
2272
2708
|
return buildDeepseekMissingKeyMessage();
|
|
2273
2709
|
}
|
|
2274
2710
|
function resolveDeepseekPackage(env) {
|
|
@@ -2284,39 +2720,86 @@ function resolveDeepseekPackage(env) {
|
|
|
2284
2720
|
}
|
|
2285
2721
|
return raw;
|
|
2286
2722
|
}
|
|
2723
|
+
var UNSAFE_BIN = /[\u0000-\u001f;&|$()`"'<>*?~#!]/;
|
|
2724
|
+
function resolveDeepseekBin(env) {
|
|
2725
|
+
const raw = (env ?? process.env).DSH_BIN?.trim();
|
|
2726
|
+
if (!raw)
|
|
2727
|
+
return null;
|
|
2728
|
+
if (UNSAFE_BIN.test(raw)) {
|
|
2729
|
+
if (true) {
|
|
2730
|
+
console.warn(`[acp:deepseek] 非法 DSH_BIN 回落包解析: ${raw}`);
|
|
2731
|
+
}
|
|
2732
|
+
return null;
|
|
2733
|
+
}
|
|
2734
|
+
return raw;
|
|
2735
|
+
}
|
|
2287
2736
|
function resolveDeepseekSpawnCommand(env) {
|
|
2288
|
-
const
|
|
2737
|
+
const source = env ?? process.env;
|
|
2738
|
+
const patchFile = ensureAcpModelPatchFile(source);
|
|
2739
|
+
const withPatch = (args) => patchFile ? [...args, "--patch", patchFile] : args;
|
|
2740
|
+
const bin = resolveDeepseekBin(source);
|
|
2741
|
+
if (bin) {
|
|
2742
|
+
const args = ["--profile", "acp"];
|
|
2743
|
+
if (/\.(c|m)?js$/i.test(bin))
|
|
2744
|
+
return { command: process.execPath, args: withPatch([bin, ...args]) };
|
|
2745
|
+
const looksAbsolute = /^([A-Za-z]:[\\/]|\\\\|\/)/.test(bin);
|
|
2746
|
+
if (/\.(cmd|bat)$/i.test(bin) && /\s/.test(bin)) {
|
|
2747
|
+
if (true) {
|
|
2748
|
+
console.warn(`[acp:deepseek] DSH_BIN 为含空格的批处理,回落包解析: ${bin}`);
|
|
2749
|
+
}
|
|
2750
|
+
} else if (!looksAbsolute || existsSync15(bin)) {
|
|
2751
|
+
return { command: bin, args: withPatch(args) };
|
|
2752
|
+
} else if (true) {
|
|
2753
|
+
console.warn(`[acp:deepseek] DSH_BIN 不存在,回落包解析: ${bin}`);
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
if (hasManagedDshRuntime(source)) {
|
|
2757
|
+
const entry = resolveManagedDshEntry(source);
|
|
2758
|
+
return { command: process.execPath, args: withPatch([entry, "--profile", "acp"]) };
|
|
2759
|
+
}
|
|
2760
|
+
const pkg = resolveDeepseekPackage(source);
|
|
2289
2761
|
const spec = pkg === DEEPSEEK_DSH_NPM_PACKAGE ? `${pkg}@latest` : pkg;
|
|
2290
|
-
return { command: "bunx", args: ["-y", spec, "--profile", "acp"] };
|
|
2762
|
+
return { command: "bunx", args: withPatch(["-y", spec, "--profile", "acp"]) };
|
|
2291
2763
|
}
|
|
2292
|
-
function probeDeepseekAuth() {
|
|
2293
|
-
const
|
|
2764
|
+
function probeDeepseekAuth(env, dataDir) {
|
|
2765
|
+
const source = env ?? process.env;
|
|
2766
|
+
const hasApiKeyEnv = Boolean(source.DEEPSEEK_API_KEY?.trim());
|
|
2767
|
+
const dshHome = resolveDshHome(source);
|
|
2768
|
+
const hasCredentialsFile = existsSync15(resolveDshCredentialsFile(source));
|
|
2769
|
+
const hasCredentialRecords = hasDshCredentials(source);
|
|
2770
|
+
const hasStoredProvider = Boolean(dataDir && readStoredDeepseekProvider(dataDir));
|
|
2294
2771
|
return {
|
|
2295
|
-
codexHome:
|
|
2296
|
-
hasCodexHome:
|
|
2297
|
-
hasAuthFile:
|
|
2298
|
-
hasApiKeyEnv,
|
|
2299
|
-
looksLoggedIn: hasApiKeyEnv
|
|
2772
|
+
codexHome: dshHome,
|
|
2773
|
+
hasCodexHome: existsSync15(dshHome),
|
|
2774
|
+
hasAuthFile: hasCredentialsFile,
|
|
2775
|
+
hasApiKeyEnv: hasApiKeyEnv || hasStoredProvider,
|
|
2776
|
+
looksLoggedIn: hasApiKeyEnv || hasStoredProvider || hasCredentialRecords
|
|
2300
2777
|
};
|
|
2301
2778
|
}
|
|
2302
2779
|
var deepseekAdapter = {
|
|
2303
2780
|
id: "deepseek",
|
|
2304
2781
|
prepareAppResources: async ({ directory }) => prepareCompatibilityResources(directory, "native-config-entry-not-verified"),
|
|
2305
|
-
probeAuth: () => probeDeepseekAuth(),
|
|
2782
|
+
probeAuth: (context) => probeDeepseekAuth(context?.env, context?.dataDir),
|
|
2306
2783
|
resolveSpawnCommand: () => resolveDeepseekSpawnCommand(),
|
|
2307
|
-
resolveSpawnBlocker: () => resolveDeepseekSpawnBlocker(),
|
|
2784
|
+
resolveSpawnBlocker: (context) => resolveDeepseekSpawnBlocker(context?.env, context?.dataDir),
|
|
2785
|
+
getProviderEnv: ({ dataDir, env }) => buildDeepseekProviderEnv(readStoredDeepseekProvider(dataDir), env),
|
|
2786
|
+
probeQuota: (options) => probeDeepseekQuota({
|
|
2787
|
+
runtimeId: "deepseek",
|
|
2788
|
+
dataDir: options?.dataDir,
|
|
2789
|
+
env: options?.env
|
|
2790
|
+
}),
|
|
2308
2791
|
orderAuthMethods: (methods) => methods,
|
|
2309
2792
|
canSkipInteractiveAuth: () => false
|
|
2310
2793
|
};
|
|
2311
2794
|
|
|
2312
2795
|
// src/runtimes/agy/quota.ts
|
|
2313
|
-
import { existsSync as
|
|
2314
|
-
import { join as
|
|
2796
|
+
import { existsSync as existsSync16, readFileSync as readFileSync11, readdirSync as readdirSync3, statSync as statSync2 } from "node:fs";
|
|
2797
|
+
import { join as join18 } from "node:path";
|
|
2315
2798
|
import { execFileSync } from "node:child_process";
|
|
2316
2799
|
import * as os2 from "node:os";
|
|
2317
2800
|
function resolveGeminiHome2() {
|
|
2318
2801
|
const home = process.env.USERPROFILE || process.env.HOME || "";
|
|
2319
|
-
return
|
|
2802
|
+
return join18(home, ".gemini");
|
|
2320
2803
|
}
|
|
2321
2804
|
function resolveAntigravityAccount() {
|
|
2322
2805
|
if (process.env.GOOGLE_ACCOUNT?.trim()) {
|
|
@@ -2329,14 +2812,14 @@ function resolveAntigravityAccount() {
|
|
|
2329
2812
|
}
|
|
2330
2813
|
const home = process.env.USERPROFILE || process.env.HOME || os2.homedir() || "";
|
|
2331
2814
|
const candidates = [
|
|
2332
|
-
process.env.APPDATA ?
|
|
2333
|
-
|
|
2334
|
-
|
|
2815
|
+
process.env.APPDATA ? join18(process.env.APPDATA, "Antigravity", "app_storage.json") : null,
|
|
2816
|
+
join18(home, ".config", "Antigravity", "app_storage.json"),
|
|
2817
|
+
join18(home, "Library", "Application Support", "Antigravity", "app_storage.json")
|
|
2335
2818
|
].filter(Boolean);
|
|
2336
2819
|
for (const file of candidates) {
|
|
2337
2820
|
try {
|
|
2338
|
-
if (
|
|
2339
|
-
const raw =
|
|
2821
|
+
if (existsSync16(file)) {
|
|
2822
|
+
const raw = readFileSync11(file, "utf8");
|
|
2340
2823
|
const json = JSON.parse(raw);
|
|
2341
2824
|
const username = json["jetski.onboarding.lastLoginUsername"];
|
|
2342
2825
|
if (username && typeof username === "string" && username.trim()) {
|
|
@@ -2357,30 +2840,30 @@ function resolveAntigravityAccount() {
|
|
|
2357
2840
|
}
|
|
2358
2841
|
function resolveAntigravityLanguageServer() {
|
|
2359
2842
|
const home = process.env.USERPROFILE || process.env.HOME || os2.homedir() || "";
|
|
2360
|
-
const appData = process.env.APPDATA || (process.platform === "win32" ?
|
|
2843
|
+
const appData = process.env.APPDATA || (process.platform === "win32" ? join18(home, "AppData", "Roaming") : "");
|
|
2361
2844
|
const baseDirs = [
|
|
2362
|
-
appData ?
|
|
2363
|
-
appData ?
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2845
|
+
appData ? join18(appData, "Antigravity IDE", "logs") : null,
|
|
2846
|
+
appData ? join18(appData, "Antigravity", "logs") : null,
|
|
2847
|
+
join18(home, ".config", "Antigravity IDE", "logs"),
|
|
2848
|
+
join18(home, ".config", "Antigravity", "logs"),
|
|
2849
|
+
join18(home, "Library", "Application Support", "Antigravity IDE", "logs"),
|
|
2850
|
+
join18(home, "Library", "Application Support", "Antigravity", "logs")
|
|
2368
2851
|
].filter(Boolean);
|
|
2369
2852
|
for (const base of baseDirs) {
|
|
2370
2853
|
try {
|
|
2371
|
-
if (!
|
|
2854
|
+
if (!existsSync16(base))
|
|
2372
2855
|
continue;
|
|
2373
|
-
const sessionDirs =
|
|
2856
|
+
const sessionDirs = readdirSync3(base).map((d) => {
|
|
2374
2857
|
try {
|
|
2375
|
-
return { name: d, time: statSync2(
|
|
2858
|
+
return { name: d, time: statSync2(join18(base, d)).mtimeMs };
|
|
2376
2859
|
} catch {
|
|
2377
2860
|
return null;
|
|
2378
2861
|
}
|
|
2379
2862
|
}).filter((d) => Boolean(d)).sort((a, b) => b.time - a.time);
|
|
2380
2863
|
for (const s of sessionDirs) {
|
|
2381
|
-
const logFile =
|
|
2382
|
-
if (
|
|
2383
|
-
const content =
|
|
2864
|
+
const logFile = join18(base, s.name, "ls-main.log");
|
|
2865
|
+
if (existsSync16(logFile)) {
|
|
2866
|
+
const content = readFileSync11(logFile, "utf8");
|
|
2384
2867
|
const csrfMatch = content.match(/--csrf_token\s+([a-f0-9\-]+)/);
|
|
2385
2868
|
const portMatch = content.match(/LS started on port\s+(\d+)/) || content.match(/--https_server_port\s+(\d+)/);
|
|
2386
2869
|
if (csrfMatch && portMatch) {
|
|
@@ -2537,7 +3020,7 @@ async function probeAgyQuota(options) {
|
|
|
2537
3020
|
} catch {}
|
|
2538
3021
|
}
|
|
2539
3022
|
const geminiHome = resolveGeminiHome2();
|
|
2540
|
-
const hasAgyDir =
|
|
3023
|
+
const hasAgyDir = existsSync16(join18(geminiHome, "antigravity")) || existsSync16(join18(geminiHome, "antigravity-cli"));
|
|
2541
3024
|
const hasApiKey = Boolean(process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY);
|
|
2542
3025
|
const isAvailable = hasAgyDir || hasApiKey || Boolean(acc.email || acc.name);
|
|
2543
3026
|
if (!isAvailable) {
|
|
@@ -2854,11 +3337,11 @@ function tryReuseLiveAcpProcess(runtimeId, query = {}) {
|
|
|
2854
3337
|
}
|
|
2855
3338
|
|
|
2856
3339
|
// src/client/client-handlers.ts
|
|
2857
|
-
import { methods, RequestError } from "@agentclientprotocol/sdk";
|
|
3340
|
+
import { methods as methods2, RequestError } from "@agentclientprotocol/sdk";
|
|
2858
3341
|
|
|
2859
3342
|
// src/client/acp-fs.ts
|
|
2860
3343
|
import { access, readFile as readFile4, writeFile as writeFile4 } from "node:fs/promises";
|
|
2861
|
-
import { dirname as
|
|
3344
|
+
import { dirname as dirname5, extname, resolve as resolve2, sep as sep2 } from "node:path";
|
|
2862
3345
|
import { mkdir as mkdir4 } from "node:fs/promises";
|
|
2863
3346
|
var MAX_READ_BYTES = 2 * 1024 * 1024;
|
|
2864
3347
|
var BINARY_DOCUMENT_EXTENSIONS = new Set([".epub", ".mobi", ".azw", ".azw3", ".pdf"]);
|
|
@@ -2899,7 +3382,7 @@ async function acpReadTextFile(params) {
|
|
|
2899
3382
|
}
|
|
2900
3383
|
async function acpWriteTextFile(params) {
|
|
2901
3384
|
const abs = assertPathInsideWorkspace(params.path, params.workspaceRoot);
|
|
2902
|
-
await mkdir4(
|
|
3385
|
+
await mkdir4(dirname5(abs), { recursive: true });
|
|
2903
3386
|
await writeFile4(abs, params.content, "utf-8");
|
|
2904
3387
|
return {};
|
|
2905
3388
|
}
|
|
@@ -2912,7 +3395,7 @@ function toServerError(error, fallback) {
|
|
|
2912
3395
|
return new RequestError(-32000, error instanceof Error ? error.message : fallback);
|
|
2913
3396
|
}
|
|
2914
3397
|
function registerAcpClientHandlers(app, deps) {
|
|
2915
|
-
app.onRequest(
|
|
3398
|
+
app.onRequest(methods2.client.session.requestPermission, async (ctx) => {
|
|
2916
3399
|
const params = ctx.params;
|
|
2917
3400
|
const toolCall = params.toolCall;
|
|
2918
3401
|
const toolHint = toolCall && typeof toolCall === "object" ? {
|
|
@@ -2937,7 +3420,7 @@ function registerAcpClientHandlers(app, deps) {
|
|
|
2937
3420
|
return { outcome: { outcome: "cancelled" } };
|
|
2938
3421
|
}
|
|
2939
3422
|
});
|
|
2940
|
-
app.onRequest(
|
|
3423
|
+
app.onRequest(methods2.client.fs.readTextFile, async (ctx) => {
|
|
2941
3424
|
const workspaceRoot = deps.getWorkspaceRoot();
|
|
2942
3425
|
const filePath = ctx.params.path;
|
|
2943
3426
|
if (!workspaceRoot || !filePath) {
|
|
@@ -2972,7 +3455,7 @@ function registerAcpClientHandlers(app, deps) {
|
|
|
2972
3455
|
throw toServerError(error, "读取文件失败");
|
|
2973
3456
|
}
|
|
2974
3457
|
});
|
|
2975
|
-
app.onRequest(
|
|
3458
|
+
app.onRequest(methods2.client.fs.writeTextFile, async (ctx) => {
|
|
2976
3459
|
const workspaceRoot = deps.getWorkspaceRoot();
|
|
2977
3460
|
const filePath = ctx.params.path;
|
|
2978
3461
|
const content = ctx.params.content;
|
|
@@ -2989,7 +3472,7 @@ function registerAcpClientHandlers(app, deps) {
|
|
|
2989
3472
|
throw toServerError(error, "写入文件失败");
|
|
2990
3473
|
}
|
|
2991
3474
|
});
|
|
2992
|
-
app.onRequest(
|
|
3475
|
+
app.onRequest(methods2.client.terminal.create, async (ctx) => {
|
|
2993
3476
|
const workspaceRoot = deps.getWorkspaceRoot();
|
|
2994
3477
|
const sessionId = ctx.params.sessionId;
|
|
2995
3478
|
const command = ctx.params.command;
|
|
@@ -3010,7 +3493,7 @@ function registerAcpClientHandlers(app, deps) {
|
|
|
3010
3493
|
throw toServerError(error, "创建终端失败");
|
|
3011
3494
|
}
|
|
3012
3495
|
});
|
|
3013
|
-
app.onRequest(
|
|
3496
|
+
app.onRequest(methods2.client.terminal.output, async (ctx) => {
|
|
3014
3497
|
const terminalId = ctx.params.terminalId;
|
|
3015
3498
|
if (!terminalId) {
|
|
3016
3499
|
throw toInvalidParams("terminal/output 需要 terminalId");
|
|
@@ -3021,7 +3504,7 @@ function registerAcpClientHandlers(app, deps) {
|
|
|
3021
3504
|
throw toServerError(error, "读取终端输出失败");
|
|
3022
3505
|
}
|
|
3023
3506
|
});
|
|
3024
|
-
app.onRequest(
|
|
3507
|
+
app.onRequest(methods2.client.terminal.waitForExit, async (ctx) => {
|
|
3025
3508
|
const terminalId = ctx.params.terminalId;
|
|
3026
3509
|
if (!terminalId) {
|
|
3027
3510
|
throw toInvalidParams("terminal/wait_for_exit 需要 terminalId");
|
|
@@ -3032,7 +3515,7 @@ function registerAcpClientHandlers(app, deps) {
|
|
|
3032
3515
|
throw toServerError(error, "等待终端退出失败");
|
|
3033
3516
|
}
|
|
3034
3517
|
});
|
|
3035
|
-
app.onRequest(
|
|
3518
|
+
app.onRequest(methods2.client.terminal.kill, async (ctx) => {
|
|
3036
3519
|
const terminalId = ctx.params.terminalId;
|
|
3037
3520
|
if (!terminalId) {
|
|
3038
3521
|
throw toInvalidParams("terminal/kill 需要 terminalId");
|
|
@@ -3043,7 +3526,7 @@ function registerAcpClientHandlers(app, deps) {
|
|
|
3043
3526
|
throw toServerError(error, "终止终端失败");
|
|
3044
3527
|
}
|
|
3045
3528
|
});
|
|
3046
|
-
app.onRequest(
|
|
3529
|
+
app.onRequest(methods2.client.terminal.release, async (ctx) => {
|
|
3047
3530
|
const terminalId = ctx.params.terminalId;
|
|
3048
3531
|
if (!terminalId) {
|
|
3049
3532
|
throw toInvalidParams("terminal/release 需要 terminalId");
|
|
@@ -3054,7 +3537,7 @@ function registerAcpClientHandlers(app, deps) {
|
|
|
3054
3537
|
throw toServerError(error, "释放终端失败");
|
|
3055
3538
|
}
|
|
3056
3539
|
});
|
|
3057
|
-
app.onNotification(
|
|
3540
|
+
app.onNotification(methods2.client.session.update, async (ctx) => {
|
|
3058
3541
|
deps.onSessionUpdate({
|
|
3059
3542
|
sessionId: ctx.params.sessionId,
|
|
3060
3543
|
update: ctx.params.update
|
|
@@ -3093,7 +3576,7 @@ function pickAllowOptionId(params) {
|
|
|
3093
3576
|
}
|
|
3094
3577
|
|
|
3095
3578
|
// src/client/session-open.ts
|
|
3096
|
-
import { RequestError as RequestError2 } from "@agentclientprotocol/sdk";
|
|
3579
|
+
import { RequestError as RequestError2, methods as methods3 } from "@agentclientprotocol/sdk";
|
|
3097
3580
|
|
|
3098
3581
|
// src/session/config-options.ts
|
|
3099
3582
|
function coerceOptionValue(raw) {
|
|
@@ -3103,6 +3586,16 @@ function coerceOptionValue(raw) {
|
|
|
3103
3586
|
return String(raw);
|
|
3104
3587
|
if (typeof raw === "boolean")
|
|
3105
3588
|
return String(raw);
|
|
3589
|
+
if (raw !== null && typeof raw === "object") {
|
|
3590
|
+
if (!Array.isArray(raw) && Object.keys(raw).length === 0)
|
|
3591
|
+
return null;
|
|
3592
|
+
try {
|
|
3593
|
+
const encoded = JSON.stringify(raw);
|
|
3594
|
+
return encoded && encoded !== "null" ? encoded : null;
|
|
3595
|
+
} catch {
|
|
3596
|
+
return null;
|
|
3597
|
+
}
|
|
3598
|
+
}
|
|
3106
3599
|
return null;
|
|
3107
3600
|
}
|
|
3108
3601
|
function coerceCurrentValue(raw) {
|
|
@@ -3112,8 +3605,41 @@ function coerceCurrentValue(raw) {
|
|
|
3112
3605
|
return raw;
|
|
3113
3606
|
if (typeof raw === "number" && Number.isFinite(raw))
|
|
3114
3607
|
return String(raw);
|
|
3608
|
+
if (raw !== null && typeof raw === "object") {
|
|
3609
|
+
if (!Array.isArray(raw) && Object.keys(raw).length === 0)
|
|
3610
|
+
return;
|
|
3611
|
+
try {
|
|
3612
|
+
const encoded = JSON.stringify(raw);
|
|
3613
|
+
return encoded && encoded !== "null" ? encoded : undefined;
|
|
3614
|
+
} catch {
|
|
3615
|
+
return;
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3115
3618
|
return;
|
|
3116
3619
|
}
|
|
3620
|
+
function collectOptionValues(rows, group, out) {
|
|
3621
|
+
for (const opt of rows) {
|
|
3622
|
+
if (!opt || typeof opt !== "object")
|
|
3623
|
+
continue;
|
|
3624
|
+
const o = opt;
|
|
3625
|
+
const nested = Array.isArray(o.options) ? o.options : null;
|
|
3626
|
+
const label = typeof o.group === "string" && o.group ? o.group : group;
|
|
3627
|
+
if (nested && nested.length > 0) {
|
|
3628
|
+
const fallbackName = typeof o.name === "string" && o.name ? o.name : undefined;
|
|
3629
|
+
collectOptionValues(nested, label ?? fallbackName, out);
|
|
3630
|
+
continue;
|
|
3631
|
+
}
|
|
3632
|
+
const value = coerceOptionValue(o.value) ?? coerceOptionValue(o.id);
|
|
3633
|
+
if (!value)
|
|
3634
|
+
continue;
|
|
3635
|
+
out.push({
|
|
3636
|
+
value,
|
|
3637
|
+
name: typeof o.name === "string" ? o.name : String(value),
|
|
3638
|
+
...typeof o.description === "string" ? { description: o.description } : {},
|
|
3639
|
+
...label ? { group: label } : {}
|
|
3640
|
+
});
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3117
3643
|
function parseAcpConfigOptions(raw) {
|
|
3118
3644
|
if (!Array.isArray(raw))
|
|
3119
3645
|
return [];
|
|
@@ -3128,21 +3654,8 @@ function parseAcpConfigOptions(raw) {
|
|
|
3128
3654
|
const name = typeof row.name === "string" ? row.name : configId;
|
|
3129
3655
|
const type = typeof row.type === "string" ? row.type : "select";
|
|
3130
3656
|
const values = [];
|
|
3131
|
-
if (Array.isArray(row.options))
|
|
3132
|
-
|
|
3133
|
-
if (!opt || typeof opt !== "object")
|
|
3134
|
-
continue;
|
|
3135
|
-
const o = opt;
|
|
3136
|
-
const value = coerceOptionValue(o.value) ?? coerceOptionValue(o.id);
|
|
3137
|
-
if (!value)
|
|
3138
|
-
continue;
|
|
3139
|
-
values.push({
|
|
3140
|
-
value,
|
|
3141
|
-
name: typeof o.name === "string" ? o.name : String(value),
|
|
3142
|
-
description: typeof o.description === "string" ? o.description : undefined
|
|
3143
|
-
});
|
|
3144
|
-
}
|
|
3145
|
-
}
|
|
3657
|
+
if (Array.isArray(row.options))
|
|
3658
|
+
collectOptionValues(row.options, undefined, values);
|
|
3146
3659
|
options.push({
|
|
3147
3660
|
configId,
|
|
3148
3661
|
name,
|
|
@@ -3239,6 +3752,9 @@ function mergeTopLevelModelsIntoConfigOptions(configOptionsRaw, response) {
|
|
|
3239
3752
|
}
|
|
3240
3753
|
|
|
3241
3754
|
// src/client/session-open.ts
|
|
3755
|
+
function isAuthenticationRequired(message) {
|
|
3756
|
+
return !/\bmcp\b/i.test(message) && /authentication required|not authenticated|please (?:log|sign) in|需要认证|尚未认证/i.test(message);
|
|
3757
|
+
}
|
|
3242
3758
|
function errorMessage(error) {
|
|
3243
3759
|
return error instanceof Error ? error.message : String(error);
|
|
3244
3760
|
}
|
|
@@ -3258,29 +3774,30 @@ function isTransientAcpTransportError(error) {
|
|
|
3258
3774
|
return /ACP connection closed|connection closed|closed|abort|超时|timeout|timed out|econnreset|epipe|stdio|stream/i.test(message);
|
|
3259
3775
|
}
|
|
3260
3776
|
async function restoreOrCreateAcpSession(input) {
|
|
3261
|
-
const resumeId = input.resumeSessionId?.trim() || null;
|
|
3262
|
-
const restoreAttempts = [];
|
|
3263
3777
|
let mcpServersAccepted = (input.mcpServers ?? []).length > 0;
|
|
3264
3778
|
let nativeSessionAccepted = false;
|
|
3779
|
+
let recoveredToolOutputs;
|
|
3265
3780
|
const request = async (method, params) => {
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3781
|
+
const opened = await requestSessionWithResources(input.request, method, params, input.sessionMeta);
|
|
3782
|
+
nativeSessionAccepted = opened.nativeSessionAccepted;
|
|
3783
|
+
const meta = opened.result._meta;
|
|
3784
|
+
const outputs = meta?.toolOutputRecovery?.outputs;
|
|
3785
|
+
let total = 0;
|
|
3786
|
+
recoveredToolOutputs = Array.isArray(outputs) ? outputs.slice(0, 20).filter((row) => {
|
|
3787
|
+
if (!row || typeof row.toolCallId !== "string" || row.toolCallId.length > 120 || typeof row.text !== "string")
|
|
3788
|
+
return false;
|
|
3789
|
+
const bytes = Buffer.byteLength(row.text);
|
|
3790
|
+
if (bytes > 128 * 1024 || total + bytes > 256 * 1024)
|
|
3791
|
+
return false;
|
|
3792
|
+
total += bytes;
|
|
3793
|
+
return true;
|
|
3794
|
+
}) : undefined;
|
|
3795
|
+
return opened.result;
|
|
3281
3796
|
};
|
|
3797
|
+
const resumeId = input.resumeSessionId?.trim() || null;
|
|
3798
|
+
const restoreAttempts = [];
|
|
3282
3799
|
const delayMs = input.retryDelayMs ?? 250;
|
|
3283
|
-
const
|
|
3800
|
+
const outputLog = input.log ?? ((level, message, data) => {
|
|
3284
3801
|
if (level === "info" && false)
|
|
3285
3802
|
;
|
|
3286
3803
|
const line = `[acp] ${message}`;
|
|
@@ -3289,6 +3806,7 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
3289
3806
|
else
|
|
3290
3807
|
console.info(line, data ?? "");
|
|
3291
3808
|
});
|
|
3809
|
+
const log = outputLog;
|
|
3292
3810
|
const tryRestoreMethod = async (method, rpcMethod) => {
|
|
3293
3811
|
const maxTries = 2;
|
|
3294
3812
|
let lastError = "";
|
|
@@ -3339,19 +3857,17 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
3339
3857
|
mcpServers: input.mcpServers ?? []
|
|
3340
3858
|
};
|
|
3341
3859
|
try {
|
|
3342
|
-
return await request(
|
|
3860
|
+
return await request(methods3.agent.session.new, baseParams);
|
|
3343
3861
|
} catch (firstError) {
|
|
3344
3862
|
if ((input.mcpServers ?? []).length === 0)
|
|
3345
3863
|
throw firstError;
|
|
3346
|
-
log("warn", "session/new failed, retry without mcpServers", {
|
|
3864
|
+
log("warn", input.preserveMcpOnRetry ? "session/new failed, retry with mcpServers" : "session/new failed, retry without mcpServers", {
|
|
3347
3865
|
error: errorMessage(firstError)
|
|
3348
3866
|
});
|
|
3349
3867
|
try {
|
|
3350
|
-
const
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
});
|
|
3354
|
-
mcpServersAccepted = false;
|
|
3868
|
+
const retryServers = input.preserveMcpOnRetry ? input.mcpServers ?? [] : [];
|
|
3869
|
+
const result = await request(methods3.agent.session.new, { cwd: input.cwd, mcpServers: retryServers });
|
|
3870
|
+
mcpServersAccepted = retryServers.length > 0;
|
|
3355
3871
|
return result;
|
|
3356
3872
|
} catch {
|
|
3357
3873
|
throw firstError;
|
|
@@ -3360,16 +3876,17 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
3360
3876
|
};
|
|
3361
3877
|
const withModelsFallback = (result) => mergeTopLevelModelsIntoConfigOptions(result.configOptions, result);
|
|
3362
3878
|
if (resumeId && input.resumeSupported) {
|
|
3363
|
-
const resumed = await tryRestoreMethod("resume",
|
|
3879
|
+
const resumed = await tryRestoreMethod("resume", methods3.agent.session.resume);
|
|
3364
3880
|
if (resumed) {
|
|
3365
3881
|
const id = typeof resumed.sessionId === "string" ? resumed.sessionId : resumeId;
|
|
3366
3882
|
return {
|
|
3367
3883
|
sessionId: id,
|
|
3884
|
+
mcpServersAccepted,
|
|
3885
|
+
recoveredToolOutputs,
|
|
3886
|
+
nativeSessionAccepted,
|
|
3368
3887
|
configOptions: withModelsFallback(resumed),
|
|
3369
3888
|
restoreMethod: "resume",
|
|
3370
3889
|
sessionRestored: true,
|
|
3371
|
-
mcpServersAccepted,
|
|
3372
|
-
nativeSessionAccepted,
|
|
3373
3890
|
requestedSessionId: resumeId,
|
|
3374
3891
|
restoreAttempts
|
|
3375
3892
|
};
|
|
@@ -3380,16 +3897,17 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
3380
3897
|
if (resumeId && input.loadSupported) {
|
|
3381
3898
|
input.onSuppressUpdates?.(true);
|
|
3382
3899
|
try {
|
|
3383
|
-
const loaded = await tryRestoreMethod("load",
|
|
3900
|
+
const loaded = await tryRestoreMethod("load", methods3.agent.session.load);
|
|
3384
3901
|
if (loaded) {
|
|
3385
3902
|
const id = typeof loaded.sessionId === "string" ? loaded.sessionId : resumeId;
|
|
3386
3903
|
return {
|
|
3387
3904
|
sessionId: id,
|
|
3905
|
+
mcpServersAccepted,
|
|
3906
|
+
recoveredToolOutputs,
|
|
3907
|
+
nativeSessionAccepted,
|
|
3388
3908
|
configOptions: withModelsFallback(loaded),
|
|
3389
3909
|
restoreMethod: "load",
|
|
3390
3910
|
sessionRestored: true,
|
|
3391
|
-
mcpServersAccepted,
|
|
3392
|
-
nativeSessionAccepted,
|
|
3393
3911
|
requestedSessionId: resumeId,
|
|
3394
3912
|
restoreAttempts
|
|
3395
3913
|
};
|
|
@@ -3408,15 +3926,27 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
3408
3926
|
}
|
|
3409
3927
|
return {
|
|
3410
3928
|
sessionId: newSessionId,
|
|
3929
|
+
mcpServersAccepted,
|
|
3930
|
+
nativeSessionAccepted,
|
|
3411
3931
|
configOptions: withModelsFallback(sessionResult),
|
|
3412
3932
|
restoreMethod: "new",
|
|
3413
3933
|
sessionRestored: false,
|
|
3414
|
-
mcpServersAccepted,
|
|
3415
|
-
nativeSessionAccepted,
|
|
3416
3934
|
requestedSessionId: resumeId ?? undefined,
|
|
3417
3935
|
restoreAttempts
|
|
3418
3936
|
};
|
|
3419
3937
|
}
|
|
3938
|
+
async function requestSessionWithResources(request, method, params, sessionMeta) {
|
|
3939
|
+
if (!sessionMeta)
|
|
3940
|
+
return { result: await request(method, params), nativeSessionAccepted: false };
|
|
3941
|
+
try {
|
|
3942
|
+
return { result: await request(method, { ...params, _meta: sessionMeta }), nativeSessionAccepted: true };
|
|
3943
|
+
} catch (error) {
|
|
3944
|
+
const rejected = error instanceof RequestError2 && error.code === -32602 || /native.*meta.*reject|unsupported.*(meta|systemPrompt)|unknown.*(meta|systemPrompt)/i.test(errorMessage(error));
|
|
3945
|
+
if (!rejected || isTransientAcpTransportError(error))
|
|
3946
|
+
throw error;
|
|
3947
|
+
return { result: await request(method, params), nativeSessionAccepted: false };
|
|
3948
|
+
}
|
|
3949
|
+
}
|
|
3420
3950
|
|
|
3421
3951
|
// src/client/acp-terminal.ts
|
|
3422
3952
|
import { spawn as spawn3 } from "node:child_process";
|
|
@@ -3604,8 +4134,8 @@ class AcpTerminalManager {
|
|
|
3604
4134
|
|
|
3605
4135
|
// src/client/acp-proxy-service.ts
|
|
3606
4136
|
import { mkdir as mkdir5, readFile as readFile5, writeFile as writeFile5 } from "node:fs/promises";
|
|
3607
|
-
import { existsSync as
|
|
3608
|
-
import { join as
|
|
4137
|
+
import { existsSync as existsSync17 } from "node:fs";
|
|
4138
|
+
import { join as join19 } from "node:path";
|
|
3609
4139
|
var DEFAULT_ACP_PROXY_SETTINGS = {
|
|
3610
4140
|
enabled: false,
|
|
3611
4141
|
host: "127.0.0.1",
|
|
@@ -3614,7 +4144,7 @@ var DEFAULT_ACP_PROXY_SETTINGS = {
|
|
|
3614
4144
|
var PROXY_ENV_KEYS = ["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY"];
|
|
3615
4145
|
var LOWERCASE_PROXY_ENV_KEYS = ["http_proxy", "https_proxy", "all_proxy", "no_proxy"];
|
|
3616
4146
|
function proxyFilePath(dir) {
|
|
3617
|
-
return
|
|
4147
|
+
return join19(dir, "agent", "proxy.json");
|
|
3618
4148
|
}
|
|
3619
4149
|
function validate2(settings) {
|
|
3620
4150
|
if (!settings.host.trim())
|
|
@@ -3626,7 +4156,7 @@ function validate2(settings) {
|
|
|
3626
4156
|
}
|
|
3627
4157
|
async function readAcpProxySettings(dir = getDefaultAgentDataDir()) {
|
|
3628
4158
|
const file = proxyFilePath(dir);
|
|
3629
|
-
if (!
|
|
4159
|
+
if (!existsSync17(file))
|
|
3630
4160
|
return { ...DEFAULT_ACP_PROXY_SETTINGS };
|
|
3631
4161
|
try {
|
|
3632
4162
|
const raw = JSON.parse(await readFile5(file, "utf8"));
|
|
@@ -3648,7 +4178,7 @@ async function saveAcpProxySettings(payload, dir = getDefaultAgentDataDir()) {
|
|
|
3648
4178
|
host: payload.host.trim() || DEFAULT_ACP_PROXY_SETTINGS.host,
|
|
3649
4179
|
port: payload.port
|
|
3650
4180
|
};
|
|
3651
|
-
await mkdir5(
|
|
4181
|
+
await mkdir5(join19(dir, "agent"), { recursive: true });
|
|
3652
4182
|
await writeFile5(proxyFilePath(dir), JSON.stringify(stored, null, 2), "utf8");
|
|
3653
4183
|
return ok(stored);
|
|
3654
4184
|
}
|
|
@@ -3704,9 +4234,9 @@ function compatDeliveryKey(sessionId, generation, digest) {
|
|
|
3704
4234
|
}
|
|
3705
4235
|
|
|
3706
4236
|
// src/mcp/app-skills-mcp.ts
|
|
3707
|
-
import { dirname as
|
|
4237
|
+
import { dirname as dirname6, join as join20 } from "node:path";
|
|
3708
4238
|
import { fileURLToPath } from "node:url";
|
|
3709
|
-
import { existsSync as
|
|
4239
|
+
import { existsSync as existsSync18, readFileSync as readFileSync12, statSync as statSync3 } from "node:fs";
|
|
3710
4240
|
var APP_SKILLS_MCP_SERVER_NAME = "app-skills";
|
|
3711
4241
|
var APP_SKILLS_TOOLS = [
|
|
3712
4242
|
{
|
|
@@ -3742,11 +4272,11 @@ function buildAppSkillsMcpServer(directory, opts) {
|
|
|
3742
4272
|
function resolveAppSkillsRunnerPath(fromFile) {
|
|
3743
4273
|
const base = fromFile ?? fileURLToPath(import.meta.url);
|
|
3744
4274
|
const candidates = [
|
|
3745
|
-
|
|
3746
|
-
|
|
4275
|
+
join20(dirname6(base), "app-skills-mcp-serve.cjs"),
|
|
4276
|
+
join20(dirname6(base), "app-skills-mcp-serve.ts")
|
|
3747
4277
|
];
|
|
3748
4278
|
for (const candidate of candidates) {
|
|
3749
|
-
if (
|
|
4279
|
+
if (existsSync18(candidate))
|
|
3750
4280
|
return candidate;
|
|
3751
4281
|
}
|
|
3752
4282
|
throw new Error(`技能 MCP 入口缺失(dist 未构建?): ${candidates[0]}`);
|
|
@@ -3926,7 +4456,10 @@ class AcpClient {
|
|
|
3926
4456
|
const connectGen = this.connectionGen;
|
|
3927
4457
|
try {
|
|
3928
4458
|
this.setStatus("connecting");
|
|
3929
|
-
const blocker = this.adapter.resolveSpawnBlocker?.(
|
|
4459
|
+
const blocker = this.adapter.resolveSpawnBlocker?.({
|
|
4460
|
+
env: { ...process.env, ...this.extraEnv },
|
|
4461
|
+
dataDir: this.dataDir
|
|
4462
|
+
});
|
|
3930
4463
|
if (blocker) {
|
|
3931
4464
|
this.setStatus("error", blocker);
|
|
3932
4465
|
return err({ code: "ACP_SPAWN_ERROR", message: blocker });
|
|
@@ -3949,6 +4482,10 @@ class AcpClient {
|
|
|
3949
4482
|
...baseEnv,
|
|
3950
4483
|
env: { ...baseEnv.env ?? {}, ...this.extraEnv ?? {} }
|
|
3951
4484
|
};
|
|
4485
|
+
const providerEnv = this.adapter.getProviderEnv?.({
|
|
4486
|
+
dataDir: this.dataDir,
|
|
4487
|
+
env: { ...process.env, ...spawnEnv.env }
|
|
4488
|
+
}) ?? {};
|
|
3952
4489
|
let resourceEnv = {};
|
|
3953
4490
|
let profileTag = null;
|
|
3954
4491
|
if (this.resourcesDir && this.configurationScope === "session") {
|
|
@@ -3959,6 +4496,13 @@ class AcpClient {
|
|
|
3959
4496
|
}
|
|
3960
4497
|
this.sessionConfig = profile;
|
|
3961
4498
|
resourceEnv = this.sessionConfig.env;
|
|
4499
|
+
const interactions = ["opencode", "opencode-v2"].includes(this.runtimeInfo.id) && this.adapter.prepareAppResources ? await this.adapter.prepareAppResources({
|
|
4500
|
+
directory: this.resourcesDir,
|
|
4501
|
+
command: effectiveRuntime.command,
|
|
4502
|
+
workspaceRoot: this.workspaceRoot,
|
|
4503
|
+
env: { ...process.env, ...spawnEnv.env, ...resourceEnv }
|
|
4504
|
+
}) : undefined;
|
|
4505
|
+
Object.assign(resourceEnv, interactions?.env);
|
|
3962
4506
|
const load = readAppResourcesDir(this.resourcesDir);
|
|
3963
4507
|
this.resourcePrep = { profileTag: null, report: {
|
|
3964
4508
|
rulesApplied: false,
|
|
@@ -3967,6 +4511,7 @@ class AcpClient {
|
|
|
3967
4511
|
rulesChars: load.rules?.chars ?? 0,
|
|
3968
4512
|
profileDigest: digestAppResources(load),
|
|
3969
4513
|
skillsFound: load.skills.map((s) => s.name),
|
|
4514
|
+
openCodeQuestions: interactions?.report.openCodeQuestions,
|
|
3970
4515
|
configurationScope: "session",
|
|
3971
4516
|
configurationDirectory: this.sessionConfig.directory,
|
|
3972
4517
|
configurationRulesFile: this.sessionConfig.rulesFile,
|
|
@@ -4015,7 +4560,7 @@ class AcpClient {
|
|
|
4015
4560
|
reason: "runtime-not-supported"
|
|
4016
4561
|
} } : null;
|
|
4017
4562
|
}
|
|
4018
|
-
const finalEnv = { ...spawnEnv.env, ...resourceEnv };
|
|
4563
|
+
const finalEnv = { ...spawnEnv.env, ...providerEnv, ...resourceEnv };
|
|
4019
4564
|
await this.adapter.beforeSpawn?.();
|
|
4020
4565
|
if (connectGen !== this.connectionGen || this.status !== "connecting")
|
|
4021
4566
|
return err({ code: "CANCELLED", message: "连接已取消" });
|
|
@@ -4086,7 +4631,7 @@ class AcpClient {
|
|
|
4086
4631
|
this.sdkApp = app;
|
|
4087
4632
|
this.sdkConnection = connection;
|
|
4088
4633
|
this.streamHandle = streamHandle;
|
|
4089
|
-
const initResp = await sdkRequest(connection.agent,
|
|
4634
|
+
const initResp = await sdkRequest(connection.agent, methods4.agent.initialize, {
|
|
4090
4635
|
protocolVersion: 1,
|
|
4091
4636
|
clientInfo: this.clientInfo,
|
|
4092
4637
|
clientCapabilities: {
|
|
@@ -4127,21 +4672,25 @@ class AcpClient {
|
|
|
4127
4672
|
}
|
|
4128
4673
|
}
|
|
4129
4674
|
getCachedQuota(sessionId) {
|
|
4130
|
-
return this.quotaCache.get(sessionId, this.runtimeInfo.id);
|
|
4675
|
+
return this.quotaCache.applyContextUsage(this.quotaCache.get(sessionId, this.runtimeInfo.id), sessionId, this.runtimeInfo.id) ?? undefined;
|
|
4131
4676
|
}
|
|
4132
4677
|
async getQuota(sessionId) {
|
|
4133
|
-
const cached = this.
|
|
4678
|
+
const cached = this.quotaCache.get(sessionId, this.runtimeInfo.id);
|
|
4134
4679
|
if (cached && Date.now() - cached.updatedAt < 30000) {
|
|
4135
|
-
return cached;
|
|
4680
|
+
return this.quotaCache.applyContextUsage(cached, sessionId, this.runtimeInfo.id);
|
|
4136
4681
|
}
|
|
4137
4682
|
if (this.adapter.probeQuota) {
|
|
4138
|
-
const probed = await this.adapter.probeQuota({
|
|
4683
|
+
const probed = await this.adapter.probeQuota({
|
|
4684
|
+
sessionId,
|
|
4685
|
+
dataDir: this.dataDir,
|
|
4686
|
+
env: { ...process.env, ...this.extraEnv }
|
|
4687
|
+
});
|
|
4139
4688
|
if (probed) {
|
|
4140
4689
|
this.quotaCache.set(probed, sessionId);
|
|
4141
|
-
return probed;
|
|
4690
|
+
return this.quotaCache.applyContextUsage(probed, sessionId, this.runtimeInfo.id);
|
|
4142
4691
|
}
|
|
4143
4692
|
}
|
|
4144
|
-
return cached ?? null;
|
|
4693
|
+
return this.quotaCache.applyContextUsage(cached ?? null, sessionId, this.runtimeInfo.id);
|
|
4145
4694
|
}
|
|
4146
4695
|
getAvailableCommands(sessionId) {
|
|
4147
4696
|
return this.commandsCache.get(sessionId);
|
|
@@ -4230,7 +4779,7 @@ class AcpClient {
|
|
|
4230
4779
|
}
|
|
4231
4780
|
const compat = this.buildCompatPrepend(sessionId);
|
|
4232
4781
|
const blocks = compat ? [{ type: "text", text: compat }, ...prompt] : prompt;
|
|
4233
|
-
const response = await sdkRequest(this.sdkConnection.agent,
|
|
4782
|
+
const response = await sdkRequest(this.sdkConnection.agent, methods4.agent.session.prompt, {
|
|
4234
4783
|
sessionId,
|
|
4235
4784
|
prompt: blocks
|
|
4236
4785
|
}, options?.timeoutMs);
|
|
@@ -4279,7 +4828,7 @@ class AcpClient {
|
|
|
4279
4828
|
return err({ code: "ACP_NOT_CONNECTED", message: "尚未连接到 Agent 服务端" });
|
|
4280
4829
|
}
|
|
4281
4830
|
try {
|
|
4282
|
-
const response = await sdkRequest(this.sdkConnection.agent,
|
|
4831
|
+
const response = await sdkRequest(this.sdkConnection.agent, methods4.agent.session.setConfigOption, {
|
|
4283
4832
|
sessionId,
|
|
4284
4833
|
configId,
|
|
4285
4834
|
value
|
|
@@ -5263,8 +5812,12 @@ export {
|
|
|
5263
5812
|
CLAUDE_ACP_NPM_PACKAGE,
|
|
5264
5813
|
CODEX_ACP_NPM_PACKAGE,
|
|
5265
5814
|
DEEPSEEK_DSH_NPM_PACKAGE,
|
|
5815
|
+
DEEPSEEK_OFFICIAL_BASE_URL,
|
|
5266
5816
|
DEFAULT_ACP_PROXY_SETTINGS,
|
|
5267
5817
|
DEFAULT_ACP_RUNTIME_ID,
|
|
5818
|
+
DSH_ACP_DEFAULT_MODEL,
|
|
5819
|
+
DSH_ACP_DEFAULT_PROVIDER,
|
|
5820
|
+
DSH_ACP_PINNED_VERSION,
|
|
5268
5821
|
INKDOWN_MCP_TOOLS,
|
|
5269
5822
|
INKDOWN_PROVIDER_API_KEY_ENV,
|
|
5270
5823
|
INKDOWN_PROVIDER_ID,
|
|
@@ -5281,19 +5834,23 @@ export {
|
|
|
5281
5834
|
agyAdapter,
|
|
5282
5835
|
appendTerminalOutput,
|
|
5283
5836
|
assertPathInsideWorkspace,
|
|
5837
|
+
buildAcpModelPatch,
|
|
5284
5838
|
buildAcpProxySpawnEnv,
|
|
5285
5839
|
buildCursorMissingCliMessage,
|
|
5286
5840
|
buildCustomProviderConfigToml,
|
|
5287
5841
|
buildCustomProviderSpawnEnv,
|
|
5288
5842
|
buildDeepseekMissingKeyMessage,
|
|
5843
|
+
buildDeepseekProviderEnv,
|
|
5289
5844
|
callInkdownMcpTool,
|
|
5290
5845
|
callInkdownTocTool,
|
|
5291
5846
|
claudeAdapter,
|
|
5292
5847
|
claudeResourceSessionMeta,
|
|
5293
5848
|
clearAcpProvider,
|
|
5294
5849
|
clearCursorCatalogCache,
|
|
5850
|
+
clearDeepseekProvider,
|
|
5295
5851
|
closeAcpSessions,
|
|
5296
5852
|
codexAdapter,
|
|
5853
|
+
compareDshVersions,
|
|
5297
5854
|
connectSdkClient,
|
|
5298
5855
|
copilotAdapter,
|
|
5299
5856
|
createSdkStreamHandle,
|
|
@@ -5304,6 +5861,7 @@ export {
|
|
|
5304
5861
|
digestAppResources,
|
|
5305
5862
|
disposeAllAcpProcesses,
|
|
5306
5863
|
emptyAcpAuthPreflight,
|
|
5864
|
+
ensureAcpModelPatchFile,
|
|
5307
5865
|
err,
|
|
5308
5866
|
extractAvailableCommands,
|
|
5309
5867
|
findBuiltinAcpRuntime,
|
|
@@ -5317,12 +5875,16 @@ export {
|
|
|
5317
5875
|
getAcpRuntimeAdapter,
|
|
5318
5876
|
getActiveAcpProcess,
|
|
5319
5877
|
getCursorCatalogIds,
|
|
5878
|
+
getDeepseekProviderStatus,
|
|
5320
5879
|
getDefaultAcpRuntime,
|
|
5321
5880
|
getDefaultAgentDataDir,
|
|
5322
5881
|
getLiveAcpProcess,
|
|
5323
5882
|
handleInkdownMcpRpc,
|
|
5883
|
+
hasDshCredentials,
|
|
5884
|
+
hasManagedDshRuntime,
|
|
5324
5885
|
isAbsolutePathLike,
|
|
5325
5886
|
isAppError,
|
|
5887
|
+
isAuthenticationRequired,
|
|
5326
5888
|
isBinaryDocumentPath,
|
|
5327
5889
|
isCancelled,
|
|
5328
5890
|
isCodexPreflightRuntime,
|
|
@@ -5340,7 +5902,9 @@ export {
|
|
|
5340
5902
|
mergeCodexConfigJson,
|
|
5341
5903
|
mergeConfigTomlPreserving,
|
|
5342
5904
|
mergeOpenCodeAppConfig,
|
|
5905
|
+
mergeOpenCodeQuestionConfig,
|
|
5343
5906
|
mergeTopLevelModelsIntoConfigOptions,
|
|
5907
|
+
normalizeDeepseekBaseUrl,
|
|
5344
5908
|
ok,
|
|
5345
5909
|
opencodeAdapter,
|
|
5346
5910
|
opencodeV2Adapter,
|
|
@@ -5367,6 +5931,7 @@ export {
|
|
|
5367
5931
|
probeCursorAuth,
|
|
5368
5932
|
probeCursorQuota,
|
|
5369
5933
|
probeDeepseekAuth,
|
|
5934
|
+
probeDeepseekQuota,
|
|
5370
5935
|
probeGeminiAuth,
|
|
5371
5936
|
probeOpencodeAuth,
|
|
5372
5937
|
probeOpencodeQuota,
|
|
@@ -5374,18 +5939,32 @@ export {
|
|
|
5374
5939
|
readAcpProxySettings,
|
|
5375
5940
|
readAppResourcesDir,
|
|
5376
5941
|
readAppRulesText,
|
|
5942
|
+
readHarnessCredential,
|
|
5377
5943
|
readStoredAcpProvider,
|
|
5944
|
+
readStoredDeepseekProvider,
|
|
5378
5945
|
registerAcpClientHandlers,
|
|
5946
|
+
requestSessionWithResources,
|
|
5947
|
+
resetAcpModelPatchCache,
|
|
5948
|
+
resolveAcpModelOverride,
|
|
5379
5949
|
resolveClaudeHome,
|
|
5380
5950
|
resolveCodexHome,
|
|
5381
5951
|
resolveCopilotHome,
|
|
5382
5952
|
resolveCursorAuthCandidates,
|
|
5383
5953
|
resolveCursorCommand,
|
|
5384
5954
|
resolveCursorSpawnCommand,
|
|
5955
|
+
resolveDeepseekApiBase,
|
|
5956
|
+
resolveDeepseekBin,
|
|
5385
5957
|
resolveDeepseekPackage,
|
|
5958
|
+
resolveDeepseekQuotaKey,
|
|
5386
5959
|
resolveDeepseekSpawnBlocker,
|
|
5387
5960
|
resolveDeepseekSpawnCommand,
|
|
5961
|
+
resolveDshCredentialsFile,
|
|
5962
|
+
resolveDshHome,
|
|
5963
|
+
resolveDshRuntimeRoot,
|
|
5388
5964
|
resolveGeminiHome,
|
|
5965
|
+
resolveManagedDshEntry,
|
|
5966
|
+
resolveManagedDshVersion,
|
|
5967
|
+
resolveOpenCodeQuestionMode,
|
|
5389
5968
|
resolveOpencodeAuthCandidates,
|
|
5390
5969
|
resolveOpencodeAuthFile,
|
|
5391
5970
|
resolveOpencodeAuthPath,
|
|
@@ -5394,6 +5973,7 @@ export {
|
|
|
5394
5973
|
runConnectAuthGate,
|
|
5395
5974
|
saveAcpProvider,
|
|
5396
5975
|
saveAcpProxySettings,
|
|
5976
|
+
saveDeepseekProvider,
|
|
5397
5977
|
sdkRequest,
|
|
5398
5978
|
shouldPromptAuthWizard,
|
|
5399
5979
|
spawnAcpProcess,
|