@yitom/acp-client 0.1.12 → 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 +25 -1
- package/dist/contracts/index.d.ts +27 -0
- package/dist/index.cjs +594 -77
- package/dist/index.js +590 -73
- 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 +509 -76
- package/dist/version.d.ts +1 -1
- package/docs/api-reference.md +137 -0
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -82,8 +82,12 @@ __export(exports_src, {
|
|
|
82
82
|
CLAUDE_ACP_NPM_PACKAGE: () => CLAUDE_ACP_NPM_PACKAGE,
|
|
83
83
|
CODEX_ACP_NPM_PACKAGE: () => CODEX_ACP_NPM_PACKAGE,
|
|
84
84
|
DEEPSEEK_DSH_NPM_PACKAGE: () => DEEPSEEK_DSH_NPM_PACKAGE,
|
|
85
|
+
DEEPSEEK_OFFICIAL_BASE_URL: () => DEEPSEEK_OFFICIAL_BASE_URL,
|
|
85
86
|
DEFAULT_ACP_PROXY_SETTINGS: () => DEFAULT_ACP_PROXY_SETTINGS,
|
|
86
87
|
DEFAULT_ACP_RUNTIME_ID: () => DEFAULT_ACP_RUNTIME_ID,
|
|
88
|
+
DSH_ACP_DEFAULT_MODEL: () => DSH_ACP_DEFAULT_MODEL,
|
|
89
|
+
DSH_ACP_DEFAULT_PROVIDER: () => DSH_ACP_DEFAULT_PROVIDER,
|
|
90
|
+
DSH_ACP_PINNED_VERSION: () => DSH_ACP_PINNED_VERSION,
|
|
87
91
|
INKDOWN_MCP_TOOLS: () => INKDOWN_MCP_TOOLS,
|
|
88
92
|
INKDOWN_PROVIDER_API_KEY_ENV: () => INKDOWN_PROVIDER_API_KEY_ENV,
|
|
89
93
|
INKDOWN_PROVIDER_ID: () => INKDOWN_PROVIDER_ID,
|
|
@@ -100,19 +104,23 @@ __export(exports_src, {
|
|
|
100
104
|
agyAdapter: () => agyAdapter,
|
|
101
105
|
appendTerminalOutput: () => appendTerminalOutput,
|
|
102
106
|
assertPathInsideWorkspace: () => assertPathInsideWorkspace,
|
|
107
|
+
buildAcpModelPatch: () => buildAcpModelPatch,
|
|
103
108
|
buildAcpProxySpawnEnv: () => buildAcpProxySpawnEnv,
|
|
104
109
|
buildCursorMissingCliMessage: () => buildCursorMissingCliMessage,
|
|
105
110
|
buildCustomProviderConfigToml: () => buildCustomProviderConfigToml,
|
|
106
111
|
buildCustomProviderSpawnEnv: () => buildCustomProviderSpawnEnv,
|
|
107
112
|
buildDeepseekMissingKeyMessage: () => buildDeepseekMissingKeyMessage,
|
|
113
|
+
buildDeepseekProviderEnv: () => buildDeepseekProviderEnv,
|
|
108
114
|
callInkdownMcpTool: () => callInkdownMcpTool,
|
|
109
115
|
callInkdownTocTool: () => callInkdownTocTool,
|
|
110
116
|
claudeAdapter: () => claudeAdapter,
|
|
111
117
|
claudeResourceSessionMeta: () => claudeResourceSessionMeta,
|
|
112
118
|
clearAcpProvider: () => clearAcpProvider,
|
|
113
119
|
clearCursorCatalogCache: () => clearCursorCatalogCache,
|
|
120
|
+
clearDeepseekProvider: () => clearDeepseekProvider,
|
|
114
121
|
closeAcpSessions: () => closeAcpSessions,
|
|
115
122
|
codexAdapter: () => codexAdapter,
|
|
123
|
+
compareDshVersions: () => compareDshVersions,
|
|
116
124
|
connectSdkClient: () => connectSdkClient,
|
|
117
125
|
copilotAdapter: () => copilotAdapter,
|
|
118
126
|
createSdkStreamHandle: () => createSdkStreamHandle,
|
|
@@ -123,6 +131,7 @@ __export(exports_src, {
|
|
|
123
131
|
digestAppResources: () => digestAppResources,
|
|
124
132
|
disposeAllAcpProcesses: () => disposeAllAcpProcesses,
|
|
125
133
|
emptyAcpAuthPreflight: () => emptyAcpAuthPreflight,
|
|
134
|
+
ensureAcpModelPatchFile: () => ensureAcpModelPatchFile,
|
|
126
135
|
err: () => err,
|
|
127
136
|
extractAvailableCommands: () => extractAvailableCommands,
|
|
128
137
|
findBuiltinAcpRuntime: () => findBuiltinAcpRuntime,
|
|
@@ -136,10 +145,13 @@ __export(exports_src, {
|
|
|
136
145
|
getAcpRuntimeAdapter: () => getAcpRuntimeAdapter,
|
|
137
146
|
getActiveAcpProcess: () => getActiveAcpProcess,
|
|
138
147
|
getCursorCatalogIds: () => getCursorCatalogIds,
|
|
148
|
+
getDeepseekProviderStatus: () => getDeepseekProviderStatus,
|
|
139
149
|
getDefaultAcpRuntime: () => getDefaultAcpRuntime,
|
|
140
150
|
getDefaultAgentDataDir: () => getDefaultAgentDataDir,
|
|
141
151
|
getLiveAcpProcess: () => getLiveAcpProcess,
|
|
142
152
|
handleInkdownMcpRpc: () => handleInkdownMcpRpc,
|
|
153
|
+
hasDshCredentials: () => hasDshCredentials,
|
|
154
|
+
hasManagedDshRuntime: () => hasManagedDshRuntime,
|
|
143
155
|
isAbsolutePathLike: () => isAbsolutePathLike,
|
|
144
156
|
isAppError: () => isAppError,
|
|
145
157
|
isAuthenticationRequired: () => isAuthenticationRequired,
|
|
@@ -162,6 +174,7 @@ __export(exports_src, {
|
|
|
162
174
|
mergeOpenCodeAppConfig: () => mergeOpenCodeAppConfig,
|
|
163
175
|
mergeOpenCodeQuestionConfig: () => mergeOpenCodeQuestionConfig,
|
|
164
176
|
mergeTopLevelModelsIntoConfigOptions: () => mergeTopLevelModelsIntoConfigOptions,
|
|
177
|
+
normalizeDeepseekBaseUrl: () => normalizeDeepseekBaseUrl,
|
|
165
178
|
ok: () => ok,
|
|
166
179
|
opencodeAdapter: () => opencodeAdapter,
|
|
167
180
|
opencodeV2Adapter: () => opencodeV2Adapter,
|
|
@@ -188,6 +201,7 @@ __export(exports_src, {
|
|
|
188
201
|
probeCursorAuth: () => probeCursorAuth,
|
|
189
202
|
probeCursorQuota: () => probeCursorQuota,
|
|
190
203
|
probeDeepseekAuth: () => probeDeepseekAuth,
|
|
204
|
+
probeDeepseekQuota: () => probeDeepseekQuota,
|
|
191
205
|
probeGeminiAuth: () => probeGeminiAuth,
|
|
192
206
|
probeOpencodeAuth: () => probeOpencodeAuth,
|
|
193
207
|
probeOpencodeQuota: () => probeOpencodeQuota,
|
|
@@ -195,19 +209,31 @@ __export(exports_src, {
|
|
|
195
209
|
readAcpProxySettings: () => readAcpProxySettings,
|
|
196
210
|
readAppResourcesDir: () => readAppResourcesDir,
|
|
197
211
|
readAppRulesText: () => readAppRulesText,
|
|
212
|
+
readHarnessCredential: () => readHarnessCredential,
|
|
198
213
|
readStoredAcpProvider: () => readStoredAcpProvider,
|
|
214
|
+
readStoredDeepseekProvider: () => readStoredDeepseekProvider,
|
|
199
215
|
registerAcpClientHandlers: () => registerAcpClientHandlers,
|
|
200
216
|
requestSessionWithResources: () => requestSessionWithResources,
|
|
217
|
+
resetAcpModelPatchCache: () => resetAcpModelPatchCache,
|
|
218
|
+
resolveAcpModelOverride: () => resolveAcpModelOverride,
|
|
201
219
|
resolveClaudeHome: () => resolveClaudeHome,
|
|
202
220
|
resolveCodexHome: () => resolveCodexHome,
|
|
203
221
|
resolveCopilotHome: () => resolveCopilotHome,
|
|
204
222
|
resolveCursorAuthCandidates: () => resolveCursorAuthCandidates,
|
|
205
223
|
resolveCursorCommand: () => resolveCursorCommand,
|
|
206
224
|
resolveCursorSpawnCommand: () => resolveCursorSpawnCommand,
|
|
225
|
+
resolveDeepseekApiBase: () => resolveDeepseekApiBase,
|
|
226
|
+
resolveDeepseekBin: () => resolveDeepseekBin,
|
|
207
227
|
resolveDeepseekPackage: () => resolveDeepseekPackage,
|
|
228
|
+
resolveDeepseekQuotaKey: () => resolveDeepseekQuotaKey,
|
|
208
229
|
resolveDeepseekSpawnBlocker: () => resolveDeepseekSpawnBlocker,
|
|
209
230
|
resolveDeepseekSpawnCommand: () => resolveDeepseekSpawnCommand,
|
|
231
|
+
resolveDshCredentialsFile: () => resolveDshCredentialsFile,
|
|
232
|
+
resolveDshHome: () => resolveDshHome,
|
|
233
|
+
resolveDshRuntimeRoot: () => resolveDshRuntimeRoot,
|
|
210
234
|
resolveGeminiHome: () => resolveGeminiHome,
|
|
235
|
+
resolveManagedDshEntry: () => resolveManagedDshEntry,
|
|
236
|
+
resolveManagedDshVersion: () => resolveManagedDshVersion,
|
|
211
237
|
resolveOpenCodeQuestionMode: () => resolveOpenCodeQuestionMode,
|
|
212
238
|
resolveOpencodeAuthCandidates: () => resolveOpencodeAuthCandidates,
|
|
213
239
|
resolveOpencodeAuthFile: () => resolveOpencodeAuthFile,
|
|
@@ -217,6 +243,7 @@ __export(exports_src, {
|
|
|
217
243
|
runConnectAuthGate: () => runConnectAuthGate,
|
|
218
244
|
saveAcpProvider: () => saveAcpProvider,
|
|
219
245
|
saveAcpProxySettings: () => saveAcpProxySettings,
|
|
246
|
+
saveDeepseekProvider: () => saveDeepseekProvider,
|
|
220
247
|
sdkRequest: () => sdkRequest,
|
|
221
248
|
shouldPromptAuthWizard: () => shouldPromptAuthWizard,
|
|
222
249
|
spawnAcpProcess: () => spawnAcpProcess,
|
|
@@ -369,8 +396,8 @@ var BUILTIN_ACP_RUNTIMES = [
|
|
|
369
396
|
{
|
|
370
397
|
id: "deepseek",
|
|
371
398
|
name: "DeepSeek",
|
|
372
|
-
description: "通过
|
|
373
|
-
authHint: "无 ACP 登录,靠 harness
|
|
399
|
+
description: "通过 dsh 启动 @deepseek-ai/dsh(--profile acp);无 ACP 登录,靠 harness 自身凭证(DEEPSEEK_API_KEY 或 $DSH_HOME/.credentials.yaml);模型经 session 到达(V4.1-Flash 的 id 是 deepseek-flash)",
|
|
400
|
+
authHint: "无 ACP 登录,靠 harness 自身凭证;先导出 DEEPSEEK_API_KEY 或在 dsh 里完成登录;稳定安装可设 DSH_BIN 指向 dsh 入口(bunx 临时目录被清理会让 profile 断链);pin 包版本用 DSH_PACKAGE(如 @deepseek-ai/dsh@0.2.1-rc.2)",
|
|
374
401
|
command: "bunx",
|
|
375
402
|
args: ["-y", `${DEEPSEEK_DSH_NPM_PACKAGE}@latest`, "--profile", "acp"],
|
|
376
403
|
requiredEnvKeys: ["DEEPSEEK_API_KEY"]
|
|
@@ -389,7 +416,7 @@ function findBuiltinAcpRuntime(id) {
|
|
|
389
416
|
return BUILTIN_ACP_RUNTIMES.find((item) => item.id === id);
|
|
390
417
|
}
|
|
391
418
|
// src/version.ts
|
|
392
|
-
var ACP_CLIENT_VERSION = "0.1.
|
|
419
|
+
var ACP_CLIENT_VERSION = "0.1.13";
|
|
393
420
|
// src/client/sdk-client.ts
|
|
394
421
|
var import_node_stream = require("node:stream");
|
|
395
422
|
var import_sdk = require("@agentclientprotocol/sdk");
|
|
@@ -902,11 +929,24 @@ function parseRateLimitsFromStatusText(text, runtimeId = "unknown") {
|
|
|
902
929
|
class QuotaCache {
|
|
903
930
|
bySession = new Map;
|
|
904
931
|
byRuntime = new Map;
|
|
932
|
+
usageBySession = new Map;
|
|
933
|
+
usageByRuntime = new Map;
|
|
905
934
|
observe(params, defaultRuntimeId = "unknown") {
|
|
906
935
|
if (!params || typeof params !== "object")
|
|
907
936
|
return null;
|
|
908
937
|
const p = params;
|
|
909
938
|
const sessionId = typeof p.sessionId === "string" ? p.sessionId : undefined;
|
|
939
|
+
if (p.update?.sessionUpdate === "usage_update") {
|
|
940
|
+
const used = Number(p.update.used);
|
|
941
|
+
const size = Number(p.update.size);
|
|
942
|
+
if (Number.isFinite(used) && Number.isFinite(size) && size > 0) {
|
|
943
|
+
const usage = { used, size, updatedAt: Date.now() };
|
|
944
|
+
if (sessionId)
|
|
945
|
+
this.usageBySession.set(sessionId, usage);
|
|
946
|
+
this.usageByRuntime.set(defaultRuntimeId, usage);
|
|
947
|
+
}
|
|
948
|
+
return null;
|
|
949
|
+
}
|
|
910
950
|
let textToParse = "";
|
|
911
951
|
if (p.update?.content && p.update.content.type === "text" && typeof p.update.content.text === "string") {
|
|
912
952
|
textToParse = p.update.content.text;
|
|
@@ -942,9 +982,29 @@ class QuotaCache {
|
|
|
942
982
|
}
|
|
943
983
|
return;
|
|
944
984
|
}
|
|
985
|
+
applyContextUsage(quota, sessionId, runtimeId = "unknown") {
|
|
986
|
+
const usage = (sessionId ? this.usageBySession.get(sessionId) : undefined) ?? this.usageByRuntime.get(runtimeId);
|
|
987
|
+
if (!usage)
|
|
988
|
+
return quota ?? null;
|
|
989
|
+
const usedPercent = usage.size > 0 ? Math.min(100, Math.round(usage.used / usage.size * 100)) : 0;
|
|
990
|
+
const window = {
|
|
991
|
+
label: "Context",
|
|
992
|
+
used: usage.used,
|
|
993
|
+
total: usage.size,
|
|
994
|
+
usedPercent,
|
|
995
|
+
percentLeft: Math.max(0, 100 - usedPercent)
|
|
996
|
+
};
|
|
997
|
+
if (!quota) {
|
|
998
|
+
return { runtimeId, primaryWindow: window, status: "ok", updatedAt: usage.updatedAt };
|
|
999
|
+
}
|
|
1000
|
+
const rest = (quota.extraWindows ?? []).filter((item) => item.label !== "Context");
|
|
1001
|
+
return { ...quota, extraWindows: [window, ...rest] };
|
|
1002
|
+
}
|
|
945
1003
|
clear() {
|
|
946
1004
|
this.bySession.clear();
|
|
947
1005
|
this.byRuntime.clear();
|
|
1006
|
+
this.usageBySession.clear();
|
|
1007
|
+
this.usageByRuntime.clear();
|
|
948
1008
|
}
|
|
949
1009
|
}
|
|
950
1010
|
|
|
@@ -2516,14 +2576,383 @@ function getCursorCatalogIds(execFile, overrides) {
|
|
|
2516
2576
|
}
|
|
2517
2577
|
}
|
|
2518
2578
|
|
|
2579
|
+
// src/runtimes/deepseek/index.ts
|
|
2580
|
+
var import_node_fs16 = require("node:fs");
|
|
2581
|
+
|
|
2582
|
+
// src/runtimes/deepseek/deepseek-provider.ts
|
|
2583
|
+
var import_node_fs14 = require("node:fs");
|
|
2584
|
+
var import_node_os11 = require("node:os");
|
|
2585
|
+
var import_node_path15 = require("node:path");
|
|
2586
|
+
var DEEPSEEK_OFFICIAL_BASE_URL = "https://api.deepseek.com/anthropic";
|
|
2587
|
+
function resolveDshHome(env = process.env) {
|
|
2588
|
+
const override = env.DSH_HOME?.trim();
|
|
2589
|
+
return override || import_node_path15.join(import_node_os11.homedir(), ".dsh");
|
|
2590
|
+
}
|
|
2591
|
+
function resolveDshCredentialsFile(env = process.env) {
|
|
2592
|
+
return import_node_path15.join(resolveDshHome(env), ".credentials.yaml");
|
|
2593
|
+
}
|
|
2594
|
+
function escapeRegExp(value) {
|
|
2595
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2596
|
+
}
|
|
2597
|
+
function readHarnessCredential(name, env = process.env) {
|
|
2598
|
+
try {
|
|
2599
|
+
const text = import_node_fs14.readFileSync(resolveDshCredentialsFile(env), "utf8");
|
|
2600
|
+
const pattern = new RegExp(`^\\s+${escapeRegExp(name)}\\s*:\\s*(.+)$`);
|
|
2601
|
+
let inRefs = false;
|
|
2602
|
+
for (const line of text.split(/\r?\n/)) {
|
|
2603
|
+
if (/^refs\s*:/.test(line)) {
|
|
2604
|
+
inRefs = true;
|
|
2605
|
+
continue;
|
|
2606
|
+
}
|
|
2607
|
+
if (!inRefs)
|
|
2608
|
+
continue;
|
|
2609
|
+
if (/^\S/.test(line))
|
|
2610
|
+
break;
|
|
2611
|
+
const match = pattern.exec(line);
|
|
2612
|
+
if (match) {
|
|
2613
|
+
const value = match[1].trim().replace(/^['"]|['"]$/g, "");
|
|
2614
|
+
return value || null;
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
return null;
|
|
2618
|
+
} catch {
|
|
2619
|
+
return null;
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
function normalizeDeepseekBaseUrl(raw) {
|
|
2623
|
+
const trimmed = (raw ?? "").trim();
|
|
2624
|
+
if (!trimmed)
|
|
2625
|
+
return DEEPSEEK_OFFICIAL_BASE_URL;
|
|
2626
|
+
const withoutSlash = trimmed.replace(/\/+$/, "");
|
|
2627
|
+
try {
|
|
2628
|
+
const url = new URL(withoutSlash);
|
|
2629
|
+
if (url.host.toLowerCase() === "api.deepseek.com" && (url.pathname === "" || url.pathname === "/")) {
|
|
2630
|
+
return DEEPSEEK_OFFICIAL_BASE_URL;
|
|
2631
|
+
}
|
|
2632
|
+
return withoutSlash;
|
|
2633
|
+
} catch {
|
|
2634
|
+
return withoutSlash;
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
function providerFilePath2(dir) {
|
|
2638
|
+
return import_node_path15.join(dir, "agent", "deepseek-provider.json");
|
|
2639
|
+
}
|
|
2640
|
+
function readStoredDeepseekProvider(dir = getDefaultAgentDataDir()) {
|
|
2641
|
+
const file = providerFilePath2(dir);
|
|
2642
|
+
if (!import_node_fs14.existsSync(file))
|
|
2643
|
+
return null;
|
|
2644
|
+
try {
|
|
2645
|
+
const raw = JSON.parse(import_node_fs14.readFileSync(file, "utf8"));
|
|
2646
|
+
if (typeof raw.baseUrl !== "string" || typeof raw.apiKey !== "string" || !raw.apiKey.trim()) {
|
|
2647
|
+
return null;
|
|
2648
|
+
}
|
|
2649
|
+
return { baseUrl: normalizeDeepseekBaseUrl(raw.baseUrl), apiKey: raw.apiKey };
|
|
2650
|
+
} catch {
|
|
2651
|
+
return null;
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
function getDeepseekProviderStatus(dir = getDefaultAgentDataDir()) {
|
|
2655
|
+
const stored = readStoredDeepseekProvider(dir);
|
|
2656
|
+
if (!stored)
|
|
2657
|
+
return { configured: false, isOfficial: true, hasApiKey: false };
|
|
2658
|
+
return {
|
|
2659
|
+
configured: true,
|
|
2660
|
+
baseUrl: stored.baseUrl,
|
|
2661
|
+
isOfficial: stored.baseUrl === DEEPSEEK_OFFICIAL_BASE_URL,
|
|
2662
|
+
hasApiKey: Boolean(stored.apiKey)
|
|
2663
|
+
};
|
|
2664
|
+
}
|
|
2665
|
+
function validateBaseUrl(baseUrl) {
|
|
2666
|
+
try {
|
|
2667
|
+
const url = new URL(baseUrl);
|
|
2668
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
2669
|
+
return "URL 必须是 http(s) 地址";
|
|
2670
|
+
if (!url.hostname)
|
|
2671
|
+
return "URL 缺少主机名";
|
|
2672
|
+
return null;
|
|
2673
|
+
} catch {
|
|
2674
|
+
return "URL 不是合法地址";
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
function saveDeepseekProvider(payload, dir = getDefaultAgentDataDir()) {
|
|
2678
|
+
const baseUrl = normalizeDeepseekBaseUrl(payload.baseUrl);
|
|
2679
|
+
const invalid = validateBaseUrl(baseUrl);
|
|
2680
|
+
if (invalid)
|
|
2681
|
+
return err({ code: "INVALID_ARGUMENT", message: invalid });
|
|
2682
|
+
const apiKey = payload.apiKey?.trim() || readStoredDeepseekProvider(dir)?.apiKey || "";
|
|
2683
|
+
if (!apiKey)
|
|
2684
|
+
return err({ code: "INVALID_ARGUMENT", message: "Token/API Key 不能为空" });
|
|
2685
|
+
const file = providerFilePath2(dir);
|
|
2686
|
+
try {
|
|
2687
|
+
import_node_fs14.mkdirSync(import_node_path15.dirname(file), { recursive: true });
|
|
2688
|
+
import_node_fs14.writeFileSync(file, JSON.stringify({ baseUrl, apiKey }, null, 2), "utf8");
|
|
2689
|
+
} catch (error) {
|
|
2690
|
+
return err({
|
|
2691
|
+
code: "FILE_WRITE_ERROR",
|
|
2692
|
+
message: error instanceof Error ? error.message : "写入 DeepSeek 配置失败"
|
|
2693
|
+
});
|
|
2694
|
+
}
|
|
2695
|
+
return ok(getDeepseekProviderStatus(dir));
|
|
2696
|
+
}
|
|
2697
|
+
function clearDeepseekProvider(dir = getDefaultAgentDataDir()) {
|
|
2698
|
+
try {
|
|
2699
|
+
import_node_fs14.rmSync(providerFilePath2(dir), { force: true });
|
|
2700
|
+
return ok(undefined);
|
|
2701
|
+
} catch (error) {
|
|
2702
|
+
return err({
|
|
2703
|
+
code: "FILE_WRITE_ERROR",
|
|
2704
|
+
message: error instanceof Error ? error.message : "删除 DeepSeek 配置失败"
|
|
2705
|
+
});
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
function buildDeepseekProviderEnv(stored, currentEnv = process.env) {
|
|
2709
|
+
if (!stored)
|
|
2710
|
+
return {};
|
|
2711
|
+
const env = {};
|
|
2712
|
+
if (!currentEnv.DEEPSEEK_BASE_URL?.trim())
|
|
2713
|
+
env.DEEPSEEK_BASE_URL = stored.baseUrl;
|
|
2714
|
+
if (!currentEnv.DEEPSEEK_API_KEY?.trim())
|
|
2715
|
+
env.DEEPSEEK_API_KEY = stored.apiKey;
|
|
2716
|
+
return env;
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
// src/runtimes/deepseek/dsh-acp-bootstrap.ts
|
|
2720
|
+
var import_node_fs15 = require("node:fs");
|
|
2721
|
+
var import_node_os12 = require("node:os");
|
|
2722
|
+
var import_node_path16 = require("node:path");
|
|
2723
|
+
var DSH_ACP_PINNED_VERSION = "0.2.1-rc.2";
|
|
2724
|
+
var DSH_ACP_DEFAULT_MODEL = "deepseek-flash";
|
|
2725
|
+
var DSH_ACP_DEFAULT_PROVIDER = "deepseek-official";
|
|
2726
|
+
function resolveDshRuntimeRoot(env = process.env) {
|
|
2727
|
+
const override = env.DSH_RUNTIME_DIR?.trim();
|
|
2728
|
+
if (override)
|
|
2729
|
+
return override;
|
|
2730
|
+
if (process.platform === "win32") {
|
|
2731
|
+
const localAppData = env.LOCALAPPDATA?.trim() || import_node_path16.join(import_node_os12.homedir(), "AppData", "Local");
|
|
2732
|
+
return import_node_path16.join(localAppData, "acp-dsh");
|
|
2733
|
+
}
|
|
2734
|
+
if (process.platform === "darwin") {
|
|
2735
|
+
return import_node_path16.join(import_node_os12.homedir(), "Library", "Application Support", "acp-dsh");
|
|
2736
|
+
}
|
|
2737
|
+
const dataHome = env.XDG_DATA_HOME?.trim() || import_node_path16.join(import_node_os12.homedir(), ".local", "share");
|
|
2738
|
+
return import_node_path16.join(dataHome, "acp-dsh");
|
|
2739
|
+
}
|
|
2740
|
+
function resolveManagedDshEntry(env = process.env, version = resolveManagedDshVersion(env)) {
|
|
2741
|
+
return import_node_path16.join(resolveDshRuntimeRoot(env), version, "node_modules", "@deepseek-ai", "dsh", "lib", "bin.js");
|
|
2742
|
+
}
|
|
2743
|
+
function parseVersion(value) {
|
|
2744
|
+
const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(value);
|
|
2745
|
+
if (!match)
|
|
2746
|
+
return null;
|
|
2747
|
+
return {
|
|
2748
|
+
nums: [Number(match[1]), Number(match[2]), Number(match[3])],
|
|
2749
|
+
pre: match[4] ? match[4].split(".") : []
|
|
2750
|
+
};
|
|
2751
|
+
}
|
|
2752
|
+
function compareDshVersions(a, b) {
|
|
2753
|
+
const left = parseVersion(a);
|
|
2754
|
+
const right = parseVersion(b);
|
|
2755
|
+
if (!left || !right)
|
|
2756
|
+
return a.localeCompare(b);
|
|
2757
|
+
for (let i = 0;i < 3; i += 1) {
|
|
2758
|
+
if (left.nums[i] !== right.nums[i])
|
|
2759
|
+
return left.nums[i] - right.nums[i];
|
|
2760
|
+
}
|
|
2761
|
+
if (left.pre.length === 0 && right.pre.length > 0)
|
|
2762
|
+
return 1;
|
|
2763
|
+
if (left.pre.length > 0 && right.pre.length === 0)
|
|
2764
|
+
return -1;
|
|
2765
|
+
for (let i = 0;i < Math.max(left.pre.length, right.pre.length); i += 1) {
|
|
2766
|
+
const x = left.pre[i];
|
|
2767
|
+
const y = right.pre[i];
|
|
2768
|
+
if (x === undefined)
|
|
2769
|
+
return -1;
|
|
2770
|
+
if (y === undefined)
|
|
2771
|
+
return 1;
|
|
2772
|
+
const nx = Number(x);
|
|
2773
|
+
const ny = Number(y);
|
|
2774
|
+
if (!Number.isNaN(nx) && !Number.isNaN(ny) && nx !== ny)
|
|
2775
|
+
return nx - ny;
|
|
2776
|
+
if (x !== y)
|
|
2777
|
+
return x < y ? -1 : 1;
|
|
2778
|
+
}
|
|
2779
|
+
return 0;
|
|
2780
|
+
}
|
|
2781
|
+
function hasManagedEntry(root, version) {
|
|
2782
|
+
return import_node_fs15.existsSync(import_node_path16.join(root, version, "node_modules", "@deepseek-ai", "dsh", "lib", "bin.js"));
|
|
2783
|
+
}
|
|
2784
|
+
function resolveManagedDshVersion(env = process.env) {
|
|
2785
|
+
const explicit = env.DSH_RUNTIME_VERSION?.trim();
|
|
2786
|
+
if (explicit)
|
|
2787
|
+
return explicit;
|
|
2788
|
+
const root = resolveDshRuntimeRoot(env);
|
|
2789
|
+
let best = null;
|
|
2790
|
+
try {
|
|
2791
|
+
for (const name of import_node_fs15.readdirSync(root)) {
|
|
2792
|
+
if (!parseVersion(name))
|
|
2793
|
+
continue;
|
|
2794
|
+
if (!hasManagedEntry(root, name))
|
|
2795
|
+
continue;
|
|
2796
|
+
if (best === null || compareDshVersions(name, best) > 0)
|
|
2797
|
+
best = name;
|
|
2798
|
+
}
|
|
2799
|
+
} catch {}
|
|
2800
|
+
return best ?? DSH_ACP_PINNED_VERSION;
|
|
2801
|
+
}
|
|
2802
|
+
function hasManagedDshRuntime(env = process.env) {
|
|
2803
|
+
return import_node_fs15.existsSync(resolveManagedDshEntry(env));
|
|
2804
|
+
}
|
|
2805
|
+
function safeId(raw, fallback) {
|
|
2806
|
+
const value = raw?.trim();
|
|
2807
|
+
return value && /^[A-Za-z0-9._-]+$/.test(value) ? value : fallback;
|
|
2808
|
+
}
|
|
2809
|
+
function resolveAcpModelOverride(env = process.env) {
|
|
2810
|
+
const flag = env.DSH_ACP_MODEL_PATCH?.trim().toLowerCase();
|
|
2811
|
+
if (flag === "off" || flag === "0" || flag === "false" || flag === "none")
|
|
2812
|
+
return null;
|
|
2813
|
+
return {
|
|
2814
|
+
provider: safeId(env.DSH_PROVIDER, DSH_ACP_DEFAULT_PROVIDER),
|
|
2815
|
+
model: safeId(env.DSH_MODEL, DSH_ACP_DEFAULT_MODEL)
|
|
2816
|
+
};
|
|
2817
|
+
}
|
|
2818
|
+
function buildAcpModelPatch(override) {
|
|
2819
|
+
return [
|
|
2820
|
+
"# 由 @yitom/acp-client 生成:修正 ACP 会话默认模型。",
|
|
2821
|
+
"# dsh-acp-app 自带补丁把 model 写死为 deepseek-v4-flash,该 id 不在 provider catalog 中;",
|
|
2822
|
+
"# V4.1-Flash 的 catalog id 是 deepseek-flash(桌面端 1017 只是 UI 徽标)。",
|
|
2823
|
+
"- id: acp",
|
|
2824
|
+
" name: '@deepseek-ai/dsh-acp'",
|
|
2825
|
+
" config:",
|
|
2826
|
+
` provider: ${override.provider}`,
|
|
2827
|
+
` model: ${override.model}`,
|
|
2828
|
+
""
|
|
2829
|
+
].join(`
|
|
2830
|
+
`);
|
|
2831
|
+
}
|
|
2832
|
+
var patchFileCache = new Map;
|
|
2833
|
+
function ensureAcpModelPatchFile(env = process.env) {
|
|
2834
|
+
const override = resolveAcpModelOverride(env);
|
|
2835
|
+
if (!override)
|
|
2836
|
+
return null;
|
|
2837
|
+
const key = `${override.provider}/${override.model}`;
|
|
2838
|
+
const cached = patchFileCache.get(key);
|
|
2839
|
+
if (cached !== undefined)
|
|
2840
|
+
return cached;
|
|
2841
|
+
try {
|
|
2842
|
+
const dir = import_node_path16.join(import_node_os12.tmpdir(), "acp-dsh-runtime");
|
|
2843
|
+
import_node_fs15.mkdirSync(dir, { recursive: true });
|
|
2844
|
+
const file = import_node_path16.join(dir, `acp-model-${override.provider}--${override.model}.patch.yml`);
|
|
2845
|
+
const body = buildAcpModelPatch(override);
|
|
2846
|
+
if (!import_node_fs15.existsSync(file) || import_node_fs15.readFileSync(file, "utf8") !== body) {
|
|
2847
|
+
import_node_fs15.writeFileSync(file, body, "utf8");
|
|
2848
|
+
}
|
|
2849
|
+
patchFileCache.set(key, file);
|
|
2850
|
+
return file;
|
|
2851
|
+
} catch {
|
|
2852
|
+
patchFileCache.set(key, null);
|
|
2853
|
+
return null;
|
|
2854
|
+
}
|
|
2855
|
+
}
|
|
2856
|
+
function resetAcpModelPatchCache() {
|
|
2857
|
+
patchFileCache.clear();
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
// src/runtimes/deepseek/quota.ts
|
|
2861
|
+
var DEFAULT_TIMEOUT_MS = 4000;
|
|
2862
|
+
function resolveDeepseekQuotaKey(options = {}) {
|
|
2863
|
+
const env = options.env ?? process.env;
|
|
2864
|
+
const envKey = env.DEEPSEEK_API_KEY?.trim();
|
|
2865
|
+
if (envKey)
|
|
2866
|
+
return envKey;
|
|
2867
|
+
if (options.dataDir) {
|
|
2868
|
+
const stored = readStoredDeepseekProvider(options.dataDir);
|
|
2869
|
+
if (stored?.apiKey)
|
|
2870
|
+
return stored.apiKey;
|
|
2871
|
+
}
|
|
2872
|
+
return readHarnessCredential("DEEPSEEK_API_KEY", env);
|
|
2873
|
+
}
|
|
2874
|
+
function resolveDeepseekApiBase(options = {}) {
|
|
2875
|
+
const env = options.env ?? process.env;
|
|
2876
|
+
const raw = env.DEEPSEEK_BASE_URL?.trim() || (options.dataDir ? readStoredDeepseekProvider(options.dataDir)?.baseUrl : undefined) || DEEPSEEK_OFFICIAL_BASE_URL;
|
|
2877
|
+
const trimmed = raw.replace(/\/+$/, "").replace(/\/anthropic$/i, "");
|
|
2878
|
+
return trimmed || "https://api.deepseek.com";
|
|
2879
|
+
}
|
|
2880
|
+
function unauthorized(runtimeId, message) {
|
|
2881
|
+
return { runtimeId, provider: "DeepSeek", status: "unauthorized", message, updatedAt: Date.now() };
|
|
2882
|
+
}
|
|
2883
|
+
async function probeDeepseekQuota(options = {}) {
|
|
2884
|
+
const runtimeId = options.runtimeId ?? "deepseek";
|
|
2885
|
+
const apiKey = resolveDeepseekQuotaKey(options);
|
|
2886
|
+
if (!apiKey) {
|
|
2887
|
+
return unauthorized(runtimeId, "未配置 DEEPSEEK_API_KEY / 表单 Token,无法查询余额");
|
|
2888
|
+
}
|
|
2889
|
+
const doFetch = options.fetchImpl ?? fetch;
|
|
2890
|
+
try {
|
|
2891
|
+
const response = await doFetch(`${resolveDeepseekApiBase(options)}/user/balance`, {
|
|
2892
|
+
headers: { Authorization: `Bearer ${apiKey}`, Accept: "application/json" },
|
|
2893
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS)
|
|
2894
|
+
});
|
|
2895
|
+
if (response.status === 401 || response.status === 403) {
|
|
2896
|
+
return unauthorized(runtimeId, `余额查询被拒绝 (HTTP ${response.status})`);
|
|
2897
|
+
}
|
|
2898
|
+
if (!response.ok)
|
|
2899
|
+
return null;
|
|
2900
|
+
const data = await response.json();
|
|
2901
|
+
const infos = Array.isArray(data.balance_infos) ? data.balance_infos : [];
|
|
2902
|
+
const first = infos[0];
|
|
2903
|
+
const total = first ? Number(first.total_balance) : Number.NaN;
|
|
2904
|
+
const credits = first ? {
|
|
2905
|
+
balance: Number.isFinite(total) ? total : first.total_balance ?? "0",
|
|
2906
|
+
currency: first.currency
|
|
2907
|
+
} : undefined;
|
|
2908
|
+
const balanceText = infos.map((info) => `${info.total_balance ?? "0"} ${info.currency ?? ""}`.trim()).join(" / ");
|
|
2909
|
+
return {
|
|
2910
|
+
runtimeId,
|
|
2911
|
+
provider: "DeepSeek",
|
|
2912
|
+
account: { type: "apiKey", plan: "DeepSeek API" },
|
|
2913
|
+
credits,
|
|
2914
|
+
status: data.is_available === false ? "exhausted" : "ok",
|
|
2915
|
+
message: data.is_available === false ? "账户余额不足,API 暂不可用" : `可用余额 ${balanceText || "未知"}`,
|
|
2916
|
+
rawText: JSON.stringify(data),
|
|
2917
|
+
updatedAt: Date.now()
|
|
2918
|
+
};
|
|
2919
|
+
} catch {
|
|
2920
|
+
return null;
|
|
2921
|
+
}
|
|
2922
|
+
}
|
|
2923
|
+
|
|
2519
2924
|
// src/runtimes/deepseek/index.ts
|
|
2520
2925
|
function buildDeepseekMissingKeyMessage() {
|
|
2521
|
-
return "未检测到 DEEPSEEK_API_KEY
|
|
2926
|
+
return "未检测到 DEEPSEEK_API_KEY,也未在 harness 凭证库中找到登录记录:请先在终端导出该变量,或先在该 harness(dsh)里完成登录后再连接";
|
|
2927
|
+
}
|
|
2928
|
+
function hasDshCredentials(env) {
|
|
2929
|
+
try {
|
|
2930
|
+
const text = import_node_fs16.readFileSync(resolveDshCredentialsFile(env), "utf8");
|
|
2931
|
+
const match = /^records\s*:(.*)$/m.exec(text);
|
|
2932
|
+
if (!match)
|
|
2933
|
+
return false;
|
|
2934
|
+
if (/^\s*(\[\]|\{\}|null|~)\s*$/.test(match[1]))
|
|
2935
|
+
return false;
|
|
2936
|
+
for (const line of text.slice(match.index + match[0].length).split(/\r?\n/)) {
|
|
2937
|
+
if (!line.trim() || line.trim().startsWith("#"))
|
|
2938
|
+
continue;
|
|
2939
|
+
if (/^\s+\S/.test(line))
|
|
2940
|
+
return true;
|
|
2941
|
+
return false;
|
|
2942
|
+
}
|
|
2943
|
+
return false;
|
|
2944
|
+
} catch {
|
|
2945
|
+
return false;
|
|
2946
|
+
}
|
|
2522
2947
|
}
|
|
2523
|
-
function resolveDeepseekSpawnBlocker(env) {
|
|
2948
|
+
function resolveDeepseekSpawnBlocker(env, dataDir) {
|
|
2524
2949
|
const source = env ?? process.env;
|
|
2525
2950
|
if (source.DEEPSEEK_API_KEY?.trim())
|
|
2526
2951
|
return null;
|
|
2952
|
+
if (dataDir && readStoredDeepseekProvider(dataDir))
|
|
2953
|
+
return null;
|
|
2954
|
+
if (hasDshCredentials(source))
|
|
2955
|
+
return null;
|
|
2527
2956
|
return buildDeepseekMissingKeyMessage();
|
|
2528
2957
|
}
|
|
2529
2958
|
function resolveDeepseekPackage(env) {
|
|
@@ -2539,39 +2968,86 @@ function resolveDeepseekPackage(env) {
|
|
|
2539
2968
|
}
|
|
2540
2969
|
return raw;
|
|
2541
2970
|
}
|
|
2971
|
+
var UNSAFE_BIN = /[\u0000-\u001f;&|$()`"'<>*?~#!]/;
|
|
2972
|
+
function resolveDeepseekBin(env) {
|
|
2973
|
+
const raw = (env ?? process.env).DSH_BIN?.trim();
|
|
2974
|
+
if (!raw)
|
|
2975
|
+
return null;
|
|
2976
|
+
if (UNSAFE_BIN.test(raw)) {
|
|
2977
|
+
if (true) {
|
|
2978
|
+
console.warn(`[acp:deepseek] 非法 DSH_BIN 回落包解析: ${raw}`);
|
|
2979
|
+
}
|
|
2980
|
+
return null;
|
|
2981
|
+
}
|
|
2982
|
+
return raw;
|
|
2983
|
+
}
|
|
2542
2984
|
function resolveDeepseekSpawnCommand(env) {
|
|
2543
|
-
const
|
|
2985
|
+
const source = env ?? process.env;
|
|
2986
|
+
const patchFile = ensureAcpModelPatchFile(source);
|
|
2987
|
+
const withPatch = (args) => patchFile ? [...args, "--patch", patchFile] : args;
|
|
2988
|
+
const bin = resolveDeepseekBin(source);
|
|
2989
|
+
if (bin) {
|
|
2990
|
+
const args = ["--profile", "acp"];
|
|
2991
|
+
if (/\.(c|m)?js$/i.test(bin))
|
|
2992
|
+
return { command: process.execPath, args: withPatch([bin, ...args]) };
|
|
2993
|
+
const looksAbsolute = /^([A-Za-z]:[\\/]|\\\\|\/)/.test(bin);
|
|
2994
|
+
if (/\.(cmd|bat)$/i.test(bin) && /\s/.test(bin)) {
|
|
2995
|
+
if (true) {
|
|
2996
|
+
console.warn(`[acp:deepseek] DSH_BIN 为含空格的批处理,回落包解析: ${bin}`);
|
|
2997
|
+
}
|
|
2998
|
+
} else if (!looksAbsolute || import_node_fs16.existsSync(bin)) {
|
|
2999
|
+
return { command: bin, args: withPatch(args) };
|
|
3000
|
+
} else if (true) {
|
|
3001
|
+
console.warn(`[acp:deepseek] DSH_BIN 不存在,回落包解析: ${bin}`);
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
if (hasManagedDshRuntime(source)) {
|
|
3005
|
+
const entry = resolveManagedDshEntry(source);
|
|
3006
|
+
return { command: process.execPath, args: withPatch([entry, "--profile", "acp"]) };
|
|
3007
|
+
}
|
|
3008
|
+
const pkg = resolveDeepseekPackage(source);
|
|
2544
3009
|
const spec = pkg === DEEPSEEK_DSH_NPM_PACKAGE ? `${pkg}@latest` : pkg;
|
|
2545
|
-
return { command: "bunx", args: ["-y", spec, "--profile", "acp"] };
|
|
3010
|
+
return { command: "bunx", args: withPatch(["-y", spec, "--profile", "acp"]) };
|
|
2546
3011
|
}
|
|
2547
|
-
function probeDeepseekAuth() {
|
|
2548
|
-
const
|
|
3012
|
+
function probeDeepseekAuth(env, dataDir) {
|
|
3013
|
+
const source = env ?? process.env;
|
|
3014
|
+
const hasApiKeyEnv = Boolean(source.DEEPSEEK_API_KEY?.trim());
|
|
3015
|
+
const dshHome = resolveDshHome(source);
|
|
3016
|
+
const hasCredentialsFile = import_node_fs16.existsSync(resolveDshCredentialsFile(source));
|
|
3017
|
+
const hasCredentialRecords = hasDshCredentials(source);
|
|
3018
|
+
const hasStoredProvider = Boolean(dataDir && readStoredDeepseekProvider(dataDir));
|
|
2549
3019
|
return {
|
|
2550
|
-
codexHome:
|
|
2551
|
-
hasCodexHome:
|
|
2552
|
-
hasAuthFile:
|
|
2553
|
-
hasApiKeyEnv,
|
|
2554
|
-
looksLoggedIn: hasApiKeyEnv
|
|
3020
|
+
codexHome: dshHome,
|
|
3021
|
+
hasCodexHome: import_node_fs16.existsSync(dshHome),
|
|
3022
|
+
hasAuthFile: hasCredentialsFile,
|
|
3023
|
+
hasApiKeyEnv: hasApiKeyEnv || hasStoredProvider,
|
|
3024
|
+
looksLoggedIn: hasApiKeyEnv || hasStoredProvider || hasCredentialRecords
|
|
2555
3025
|
};
|
|
2556
3026
|
}
|
|
2557
3027
|
var deepseekAdapter = {
|
|
2558
3028
|
id: "deepseek",
|
|
2559
3029
|
prepareAppResources: async ({ directory }) => prepareCompatibilityResources(directory, "native-config-entry-not-verified"),
|
|
2560
|
-
probeAuth: () => probeDeepseekAuth(),
|
|
3030
|
+
probeAuth: (context) => probeDeepseekAuth(context?.env, context?.dataDir),
|
|
2561
3031
|
resolveSpawnCommand: () => resolveDeepseekSpawnCommand(),
|
|
2562
|
-
resolveSpawnBlocker: () => resolveDeepseekSpawnBlocker(),
|
|
3032
|
+
resolveSpawnBlocker: (context) => resolveDeepseekSpawnBlocker(context?.env, context?.dataDir),
|
|
3033
|
+
getProviderEnv: ({ dataDir, env }) => buildDeepseekProviderEnv(readStoredDeepseekProvider(dataDir), env),
|
|
3034
|
+
probeQuota: (options) => probeDeepseekQuota({
|
|
3035
|
+
runtimeId: "deepseek",
|
|
3036
|
+
dataDir: options?.dataDir,
|
|
3037
|
+
env: options?.env
|
|
3038
|
+
}),
|
|
2563
3039
|
orderAuthMethods: (methods) => methods,
|
|
2564
3040
|
canSkipInteractiveAuth: () => false
|
|
2565
3041
|
};
|
|
2566
3042
|
|
|
2567
3043
|
// src/runtimes/agy/quota.ts
|
|
2568
|
-
var
|
|
2569
|
-
var
|
|
3044
|
+
var import_node_fs17 = require("node:fs");
|
|
3045
|
+
var import_node_path17 = require("node:path");
|
|
2570
3046
|
var import_node_child_process6 = require("node:child_process");
|
|
2571
3047
|
var os2 = __toESM(require("node:os"), 1);
|
|
2572
3048
|
function resolveGeminiHome2() {
|
|
2573
3049
|
const home = process.env.USERPROFILE || process.env.HOME || "";
|
|
2574
|
-
return
|
|
3050
|
+
return import_node_path17.join(home, ".gemini");
|
|
2575
3051
|
}
|
|
2576
3052
|
function resolveAntigravityAccount() {
|
|
2577
3053
|
if (process.env.GOOGLE_ACCOUNT?.trim()) {
|
|
@@ -2584,14 +3060,14 @@ function resolveAntigravityAccount() {
|
|
|
2584
3060
|
}
|
|
2585
3061
|
const home = process.env.USERPROFILE || process.env.HOME || os2.homedir() || "";
|
|
2586
3062
|
const candidates = [
|
|
2587
|
-
process.env.APPDATA ?
|
|
2588
|
-
|
|
2589
|
-
|
|
3063
|
+
process.env.APPDATA ? import_node_path17.join(process.env.APPDATA, "Antigravity", "app_storage.json") : null,
|
|
3064
|
+
import_node_path17.join(home, ".config", "Antigravity", "app_storage.json"),
|
|
3065
|
+
import_node_path17.join(home, "Library", "Application Support", "Antigravity", "app_storage.json")
|
|
2590
3066
|
].filter(Boolean);
|
|
2591
3067
|
for (const file of candidates) {
|
|
2592
3068
|
try {
|
|
2593
|
-
if (
|
|
2594
|
-
const raw =
|
|
3069
|
+
if (import_node_fs17.existsSync(file)) {
|
|
3070
|
+
const raw = import_node_fs17.readFileSync(file, "utf8");
|
|
2595
3071
|
const json = JSON.parse(raw);
|
|
2596
3072
|
const username = json["jetski.onboarding.lastLoginUsername"];
|
|
2597
3073
|
if (username && typeof username === "string" && username.trim()) {
|
|
@@ -2612,30 +3088,30 @@ function resolveAntigravityAccount() {
|
|
|
2612
3088
|
}
|
|
2613
3089
|
function resolveAntigravityLanguageServer() {
|
|
2614
3090
|
const home = process.env.USERPROFILE || process.env.HOME || os2.homedir() || "";
|
|
2615
|
-
const appData = process.env.APPDATA || (process.platform === "win32" ?
|
|
3091
|
+
const appData = process.env.APPDATA || (process.platform === "win32" ? import_node_path17.join(home, "AppData", "Roaming") : "");
|
|
2616
3092
|
const baseDirs = [
|
|
2617
|
-
appData ?
|
|
2618
|
-
appData ?
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
3093
|
+
appData ? import_node_path17.join(appData, "Antigravity IDE", "logs") : null,
|
|
3094
|
+
appData ? import_node_path17.join(appData, "Antigravity", "logs") : null,
|
|
3095
|
+
import_node_path17.join(home, ".config", "Antigravity IDE", "logs"),
|
|
3096
|
+
import_node_path17.join(home, ".config", "Antigravity", "logs"),
|
|
3097
|
+
import_node_path17.join(home, "Library", "Application Support", "Antigravity IDE", "logs"),
|
|
3098
|
+
import_node_path17.join(home, "Library", "Application Support", "Antigravity", "logs")
|
|
2623
3099
|
].filter(Boolean);
|
|
2624
3100
|
for (const base of baseDirs) {
|
|
2625
3101
|
try {
|
|
2626
|
-
if (!
|
|
3102
|
+
if (!import_node_fs17.existsSync(base))
|
|
2627
3103
|
continue;
|
|
2628
|
-
const sessionDirs =
|
|
3104
|
+
const sessionDirs = import_node_fs17.readdirSync(base).map((d) => {
|
|
2629
3105
|
try {
|
|
2630
|
-
return { name: d, time:
|
|
3106
|
+
return { name: d, time: import_node_fs17.statSync(import_node_path17.join(base, d)).mtimeMs };
|
|
2631
3107
|
} catch {
|
|
2632
3108
|
return null;
|
|
2633
3109
|
}
|
|
2634
3110
|
}).filter((d) => Boolean(d)).sort((a, b) => b.time - a.time);
|
|
2635
3111
|
for (const s of sessionDirs) {
|
|
2636
|
-
const logFile =
|
|
2637
|
-
if (
|
|
2638
|
-
const content =
|
|
3112
|
+
const logFile = import_node_path17.join(base, s.name, "ls-main.log");
|
|
3113
|
+
if (import_node_fs17.existsSync(logFile)) {
|
|
3114
|
+
const content = import_node_fs17.readFileSync(logFile, "utf8");
|
|
2639
3115
|
const csrfMatch = content.match(/--csrf_token\s+([a-f0-9\-]+)/);
|
|
2640
3116
|
const portMatch = content.match(/LS started on port\s+(\d+)/) || content.match(/--https_server_port\s+(\d+)/);
|
|
2641
3117
|
if (csrfMatch && portMatch) {
|
|
@@ -2792,7 +3268,7 @@ async function probeAgyQuota(options) {
|
|
|
2792
3268
|
} catch {}
|
|
2793
3269
|
}
|
|
2794
3270
|
const geminiHome = resolveGeminiHome2();
|
|
2795
|
-
const hasAgyDir =
|
|
3271
|
+
const hasAgyDir = import_node_fs17.existsSync(import_node_path17.join(geminiHome, "antigravity")) || import_node_fs17.existsSync(import_node_path17.join(geminiHome, "antigravity-cli"));
|
|
2796
3272
|
const hasApiKey = Boolean(process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY);
|
|
2797
3273
|
const isAvailable = hasAgyDir || hasApiKey || Boolean(acc.email || acc.name);
|
|
2798
3274
|
if (!isAvailable) {
|
|
@@ -3113,17 +3589,17 @@ var import_sdk2 = require("@agentclientprotocol/sdk");
|
|
|
3113
3589
|
|
|
3114
3590
|
// src/client/acp-fs.ts
|
|
3115
3591
|
var import_promises4 = require("node:fs/promises");
|
|
3116
|
-
var
|
|
3592
|
+
var import_node_path18 = require("node:path");
|
|
3117
3593
|
var import_promises5 = require("node:fs/promises");
|
|
3118
3594
|
var MAX_READ_BYTES = 2 * 1024 * 1024;
|
|
3119
3595
|
var BINARY_DOCUMENT_EXTENSIONS = new Set([".epub", ".mobi", ".azw", ".azw3", ".pdf"]);
|
|
3120
3596
|
function isBinaryDocumentPath(filePath) {
|
|
3121
|
-
return BINARY_DOCUMENT_EXTENSIONS.has(
|
|
3597
|
+
return BINARY_DOCUMENT_EXTENSIONS.has(import_node_path18.extname(filePath).toLowerCase());
|
|
3122
3598
|
}
|
|
3123
3599
|
function assertPathInsideWorkspace(filePath, workspaceRoot) {
|
|
3124
|
-
const root =
|
|
3125
|
-
const target =
|
|
3126
|
-
const rootWithSep = root.endsWith(
|
|
3600
|
+
const root = import_node_path18.resolve(workspaceRoot);
|
|
3601
|
+
const target = import_node_path18.resolve(filePath);
|
|
3602
|
+
const rootWithSep = root.endsWith(import_node_path18.sep) ? root : root + import_node_path18.sep;
|
|
3127
3603
|
if (target !== root && !target.startsWith(rootWithSep)) {
|
|
3128
3604
|
throw new Error(`路径不在工作区内: ${filePath}`);
|
|
3129
3605
|
}
|
|
@@ -3154,7 +3630,7 @@ async function acpReadTextFile(params) {
|
|
|
3154
3630
|
}
|
|
3155
3631
|
async function acpWriteTextFile(params) {
|
|
3156
3632
|
const abs = assertPathInsideWorkspace(params.path, params.workspaceRoot);
|
|
3157
|
-
await import_promises5.mkdir(
|
|
3633
|
+
await import_promises5.mkdir(import_node_path18.dirname(abs), { recursive: true });
|
|
3158
3634
|
await import_promises4.writeFile(abs, params.content, "utf-8");
|
|
3159
3635
|
return {};
|
|
3160
3636
|
}
|
|
@@ -3358,6 +3834,16 @@ function coerceOptionValue(raw) {
|
|
|
3358
3834
|
return String(raw);
|
|
3359
3835
|
if (typeof raw === "boolean")
|
|
3360
3836
|
return String(raw);
|
|
3837
|
+
if (raw !== null && typeof raw === "object") {
|
|
3838
|
+
if (!Array.isArray(raw) && Object.keys(raw).length === 0)
|
|
3839
|
+
return null;
|
|
3840
|
+
try {
|
|
3841
|
+
const encoded = JSON.stringify(raw);
|
|
3842
|
+
return encoded && encoded !== "null" ? encoded : null;
|
|
3843
|
+
} catch {
|
|
3844
|
+
return null;
|
|
3845
|
+
}
|
|
3846
|
+
}
|
|
3361
3847
|
return null;
|
|
3362
3848
|
}
|
|
3363
3849
|
function coerceCurrentValue(raw) {
|
|
@@ -3367,8 +3853,41 @@ function coerceCurrentValue(raw) {
|
|
|
3367
3853
|
return raw;
|
|
3368
3854
|
if (typeof raw === "number" && Number.isFinite(raw))
|
|
3369
3855
|
return String(raw);
|
|
3856
|
+
if (raw !== null && typeof raw === "object") {
|
|
3857
|
+
if (!Array.isArray(raw) && Object.keys(raw).length === 0)
|
|
3858
|
+
return;
|
|
3859
|
+
try {
|
|
3860
|
+
const encoded = JSON.stringify(raw);
|
|
3861
|
+
return encoded && encoded !== "null" ? encoded : undefined;
|
|
3862
|
+
} catch {
|
|
3863
|
+
return;
|
|
3864
|
+
}
|
|
3865
|
+
}
|
|
3370
3866
|
return;
|
|
3371
3867
|
}
|
|
3868
|
+
function collectOptionValues(rows, group, out) {
|
|
3869
|
+
for (const opt of rows) {
|
|
3870
|
+
if (!opt || typeof opt !== "object")
|
|
3871
|
+
continue;
|
|
3872
|
+
const o = opt;
|
|
3873
|
+
const nested = Array.isArray(o.options) ? o.options : null;
|
|
3874
|
+
const label = typeof o.group === "string" && o.group ? o.group : group;
|
|
3875
|
+
if (nested && nested.length > 0) {
|
|
3876
|
+
const fallbackName = typeof o.name === "string" && o.name ? o.name : undefined;
|
|
3877
|
+
collectOptionValues(nested, label ?? fallbackName, out);
|
|
3878
|
+
continue;
|
|
3879
|
+
}
|
|
3880
|
+
const value = coerceOptionValue(o.value) ?? coerceOptionValue(o.id);
|
|
3881
|
+
if (!value)
|
|
3882
|
+
continue;
|
|
3883
|
+
out.push({
|
|
3884
|
+
value,
|
|
3885
|
+
name: typeof o.name === "string" ? o.name : String(value),
|
|
3886
|
+
...typeof o.description === "string" ? { description: o.description } : {},
|
|
3887
|
+
...label ? { group: label } : {}
|
|
3888
|
+
});
|
|
3889
|
+
}
|
|
3890
|
+
}
|
|
3372
3891
|
function parseAcpConfigOptions(raw) {
|
|
3373
3892
|
if (!Array.isArray(raw))
|
|
3374
3893
|
return [];
|
|
@@ -3383,21 +3902,8 @@ function parseAcpConfigOptions(raw) {
|
|
|
3383
3902
|
const name = typeof row.name === "string" ? row.name : configId;
|
|
3384
3903
|
const type = typeof row.type === "string" ? row.type : "select";
|
|
3385
3904
|
const values = [];
|
|
3386
|
-
if (Array.isArray(row.options))
|
|
3387
|
-
|
|
3388
|
-
if (!opt || typeof opt !== "object")
|
|
3389
|
-
continue;
|
|
3390
|
-
const o = opt;
|
|
3391
|
-
const value = coerceOptionValue(o.value) ?? coerceOptionValue(o.id);
|
|
3392
|
-
if (!value)
|
|
3393
|
-
continue;
|
|
3394
|
-
values.push({
|
|
3395
|
-
value,
|
|
3396
|
-
name: typeof o.name === "string" ? o.name : String(value),
|
|
3397
|
-
description: typeof o.description === "string" ? o.description : undefined
|
|
3398
|
-
});
|
|
3399
|
-
}
|
|
3400
|
-
}
|
|
3905
|
+
if (Array.isArray(row.options))
|
|
3906
|
+
collectOptionValues(row.options, undefined, values);
|
|
3401
3907
|
options.push({
|
|
3402
3908
|
configId,
|
|
3403
3909
|
name,
|
|
@@ -3876,8 +4382,8 @@ class AcpTerminalManager {
|
|
|
3876
4382
|
|
|
3877
4383
|
// src/client/acp-proxy-service.ts
|
|
3878
4384
|
var import_promises6 = require("node:fs/promises");
|
|
3879
|
-
var
|
|
3880
|
-
var
|
|
4385
|
+
var import_node_fs18 = require("node:fs");
|
|
4386
|
+
var import_node_path19 = require("node:path");
|
|
3881
4387
|
var DEFAULT_ACP_PROXY_SETTINGS = {
|
|
3882
4388
|
enabled: false,
|
|
3883
4389
|
host: "127.0.0.1",
|
|
@@ -3886,7 +4392,7 @@ var DEFAULT_ACP_PROXY_SETTINGS = {
|
|
|
3886
4392
|
var PROXY_ENV_KEYS = ["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY"];
|
|
3887
4393
|
var LOWERCASE_PROXY_ENV_KEYS = ["http_proxy", "https_proxy", "all_proxy", "no_proxy"];
|
|
3888
4394
|
function proxyFilePath(dir) {
|
|
3889
|
-
return
|
|
4395
|
+
return import_node_path19.join(dir, "agent", "proxy.json");
|
|
3890
4396
|
}
|
|
3891
4397
|
function validate2(settings) {
|
|
3892
4398
|
if (!settings.host.trim())
|
|
@@ -3898,7 +4404,7 @@ function validate2(settings) {
|
|
|
3898
4404
|
}
|
|
3899
4405
|
async function readAcpProxySettings(dir = getDefaultAgentDataDir()) {
|
|
3900
4406
|
const file = proxyFilePath(dir);
|
|
3901
|
-
if (!
|
|
4407
|
+
if (!import_node_fs18.existsSync(file))
|
|
3902
4408
|
return { ...DEFAULT_ACP_PROXY_SETTINGS };
|
|
3903
4409
|
try {
|
|
3904
4410
|
const raw = JSON.parse(await import_promises6.readFile(file, "utf8"));
|
|
@@ -3920,7 +4426,7 @@ async function saveAcpProxySettings(payload, dir = getDefaultAgentDataDir()) {
|
|
|
3920
4426
|
host: payload.host.trim() || DEFAULT_ACP_PROXY_SETTINGS.host,
|
|
3921
4427
|
port: payload.port
|
|
3922
4428
|
};
|
|
3923
|
-
await import_promises6.mkdir(
|
|
4429
|
+
await import_promises6.mkdir(import_node_path19.join(dir, "agent"), { recursive: true });
|
|
3924
4430
|
await import_promises6.writeFile(proxyFilePath(dir), JSON.stringify(stored, null, 2), "utf8");
|
|
3925
4431
|
return ok(stored);
|
|
3926
4432
|
}
|
|
@@ -3976,9 +4482,9 @@ function compatDeliveryKey(sessionId, generation, digest) {
|
|
|
3976
4482
|
}
|
|
3977
4483
|
|
|
3978
4484
|
// src/mcp/app-skills-mcp.ts
|
|
3979
|
-
var
|
|
4485
|
+
var import_node_path20 = require("node:path");
|
|
3980
4486
|
var import_node_url = require("node:url");
|
|
3981
|
-
var
|
|
4487
|
+
var import_node_fs19 = require("node:fs");
|
|
3982
4488
|
var APP_SKILLS_MCP_SERVER_NAME = "app-skills";
|
|
3983
4489
|
var APP_SKILLS_TOOLS = [
|
|
3984
4490
|
{
|
|
@@ -4014,11 +4520,11 @@ function buildAppSkillsMcpServer(directory, opts) {
|
|
|
4014
4520
|
function resolveAppSkillsRunnerPath(fromFile) {
|
|
4015
4521
|
const base = fromFile ?? import_node_url.fileURLToPath("file:///home/runner/work/acp-client/acp-client/src/mcp/app-skills-mcp.ts");
|
|
4016
4522
|
const candidates = [
|
|
4017
|
-
|
|
4018
|
-
|
|
4523
|
+
import_node_path20.join(import_node_path20.dirname(base), "app-skills-mcp-serve.cjs"),
|
|
4524
|
+
import_node_path20.join(import_node_path20.dirname(base), "app-skills-mcp-serve.ts")
|
|
4019
4525
|
];
|
|
4020
4526
|
for (const candidate of candidates) {
|
|
4021
|
-
if (
|
|
4527
|
+
if (import_node_fs19.existsSync(candidate))
|
|
4022
4528
|
return candidate;
|
|
4023
4529
|
}
|
|
4024
4530
|
throw new Error(`技能 MCP 入口缺失(dist 未构建?): ${candidates[0]}`);
|
|
@@ -4198,7 +4704,10 @@ class AcpClient {
|
|
|
4198
4704
|
const connectGen = this.connectionGen;
|
|
4199
4705
|
try {
|
|
4200
4706
|
this.setStatus("connecting");
|
|
4201
|
-
const blocker = this.adapter.resolveSpawnBlocker?.(
|
|
4707
|
+
const blocker = this.adapter.resolveSpawnBlocker?.({
|
|
4708
|
+
env: { ...process.env, ...this.extraEnv },
|
|
4709
|
+
dataDir: this.dataDir
|
|
4710
|
+
});
|
|
4202
4711
|
if (blocker) {
|
|
4203
4712
|
this.setStatus("error", blocker);
|
|
4204
4713
|
return err({ code: "ACP_SPAWN_ERROR", message: blocker });
|
|
@@ -4221,6 +4730,10 @@ class AcpClient {
|
|
|
4221
4730
|
...baseEnv,
|
|
4222
4731
|
env: { ...baseEnv.env ?? {}, ...this.extraEnv ?? {} }
|
|
4223
4732
|
};
|
|
4733
|
+
const providerEnv = this.adapter.getProviderEnv?.({
|
|
4734
|
+
dataDir: this.dataDir,
|
|
4735
|
+
env: { ...process.env, ...spawnEnv.env }
|
|
4736
|
+
}) ?? {};
|
|
4224
4737
|
let resourceEnv = {};
|
|
4225
4738
|
let profileTag = null;
|
|
4226
4739
|
if (this.resourcesDir && this.configurationScope === "session") {
|
|
@@ -4295,7 +4808,7 @@ class AcpClient {
|
|
|
4295
4808
|
reason: "runtime-not-supported"
|
|
4296
4809
|
} } : null;
|
|
4297
4810
|
}
|
|
4298
|
-
const finalEnv = { ...spawnEnv.env, ...resourceEnv };
|
|
4811
|
+
const finalEnv = { ...spawnEnv.env, ...providerEnv, ...resourceEnv };
|
|
4299
4812
|
await this.adapter.beforeSpawn?.();
|
|
4300
4813
|
if (connectGen !== this.connectionGen || this.status !== "connecting")
|
|
4301
4814
|
return err({ code: "CANCELLED", message: "连接已取消" });
|
|
@@ -4407,21 +4920,25 @@ class AcpClient {
|
|
|
4407
4920
|
}
|
|
4408
4921
|
}
|
|
4409
4922
|
getCachedQuota(sessionId) {
|
|
4410
|
-
return this.quotaCache.get(sessionId, this.runtimeInfo.id);
|
|
4923
|
+
return this.quotaCache.applyContextUsage(this.quotaCache.get(sessionId, this.runtimeInfo.id), sessionId, this.runtimeInfo.id) ?? undefined;
|
|
4411
4924
|
}
|
|
4412
4925
|
async getQuota(sessionId) {
|
|
4413
|
-
const cached = this.
|
|
4926
|
+
const cached = this.quotaCache.get(sessionId, this.runtimeInfo.id);
|
|
4414
4927
|
if (cached && Date.now() - cached.updatedAt < 30000) {
|
|
4415
|
-
return cached;
|
|
4928
|
+
return this.quotaCache.applyContextUsage(cached, sessionId, this.runtimeInfo.id);
|
|
4416
4929
|
}
|
|
4417
4930
|
if (this.adapter.probeQuota) {
|
|
4418
|
-
const probed = await this.adapter.probeQuota({
|
|
4931
|
+
const probed = await this.adapter.probeQuota({
|
|
4932
|
+
sessionId,
|
|
4933
|
+
dataDir: this.dataDir,
|
|
4934
|
+
env: { ...process.env, ...this.extraEnv }
|
|
4935
|
+
});
|
|
4419
4936
|
if (probed) {
|
|
4420
4937
|
this.quotaCache.set(probed, sessionId);
|
|
4421
|
-
return probed;
|
|
4938
|
+
return this.quotaCache.applyContextUsage(probed, sessionId, this.runtimeInfo.id);
|
|
4422
4939
|
}
|
|
4423
4940
|
}
|
|
4424
|
-
return cached ?? null;
|
|
4941
|
+
return this.quotaCache.applyContextUsage(cached ?? null, sessionId, this.runtimeInfo.id);
|
|
4425
4942
|
}
|
|
4426
4943
|
getAvailableCommands(sessionId) {
|
|
4427
4944
|
return this.commandsCache.get(sessionId);
|