@yitom/acp-client 0.1.14 → 0.1.15
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 +30 -12
- package/dist/client/acp-client.d.ts +7 -0
- package/dist/client/client-handlers.d.ts +4 -1
- package/dist/index.cjs +202 -55
- package/dist/index.d.ts +2 -2
- package/dist/index.js +196 -49
- package/dist/resources/runtime-bindings.d.ts +5 -0
- package/dist/runtimes/agy/index.d.ts +15 -0
- package/dist/runtimes/agy/quota.d.ts +1 -0
- package/dist/session/session-capabilities.d.ts +2 -2
- package/dist/sidecar.cjs +8797 -8967
- package/dist/version.d.ts +1 -1
- package/docs/adding-an-agent.md +1 -1
- package/docs/api-reference.md +10 -3
- package/docs/getting-started.md +15 -17
- package/docs/tauri-integration.md +4 -4
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -101,6 +101,7 @@ __export(exports_src, {
|
|
|
101
101
|
acpReadTextFile: () => acpReadTextFile,
|
|
102
102
|
acpWriteTextFile: () => acpWriteTextFile,
|
|
103
103
|
agyAdapter: () => agyAdapter,
|
|
104
|
+
antigravityCliAdapter: () => antigravityCliAdapter,
|
|
104
105
|
appendTerminalOutput: () => appendTerminalOutput,
|
|
105
106
|
assertPathInsideWorkspace: () => assertPathInsideWorkspace,
|
|
106
107
|
buildAcpProxySpawnEnv: () => buildAcpProxySpawnEnv,
|
|
@@ -146,6 +147,7 @@ __export(exports_src, {
|
|
|
146
147
|
handleInkdownMcpRpc: () => handleInkdownMcpRpc,
|
|
147
148
|
hasDeepseekHarnessCredentials: () => hasDeepseekHarnessCredentials,
|
|
148
149
|
isAbsolutePathLike: () => isAbsolutePathLike,
|
|
150
|
+
isAcpPermissionOutcome: () => isAcpPermissionOutcome,
|
|
149
151
|
isAppError: () => isAppError,
|
|
150
152
|
isAuthenticationRequired: () => isAuthenticationRequired,
|
|
151
153
|
isBinaryDocumentPath: () => isBinaryDocumentPath,
|
|
@@ -186,6 +188,7 @@ __export(exports_src, {
|
|
|
186
188
|
prepareCompatibilityResources: () => prepareCompatibilityResources,
|
|
187
189
|
prepareOpenCodeResources: () => prepareOpenCodeResources,
|
|
188
190
|
probeAgyAuth: () => probeAgyAuth,
|
|
191
|
+
probeAgyQuota: () => probeAgyQuota,
|
|
189
192
|
probeClaudeAuth: () => probeClaudeAuth,
|
|
190
193
|
probeClaudeQuota: () => probeClaudeQuota,
|
|
191
194
|
probeCodexAuth: () => probeCodexAuth,
|
|
@@ -205,6 +208,9 @@ __export(exports_src, {
|
|
|
205
208
|
readStoredAcpProvider: () => readStoredAcpProvider,
|
|
206
209
|
registerAcpClientHandlers: () => registerAcpClientHandlers,
|
|
207
210
|
requestSessionWithResources: () => requestSessionWithResources,
|
|
211
|
+
resolveAntigravityAccount: () => resolveAntigravityAccount,
|
|
212
|
+
resolveAntigravityCliCommand: () => resolveAntigravityCliCommand,
|
|
213
|
+
resolveAntigravityLanguageServer: () => resolveAntigravityLanguageServer,
|
|
208
214
|
resolveAppCodexHome: () => resolveAppCodexHome,
|
|
209
215
|
resolveClaudeHome: () => resolveClaudeHome,
|
|
210
216
|
resolveCodexHome: () => resolveCodexHome,
|
|
@@ -385,10 +391,19 @@ var BUILTIN_ACP_RUNTIMES = [
|
|
|
385
391
|
args: ["-y", `${DEEPSEEK_DSH_NPM_PACKAGE}@latest`, "--profile", "acp"],
|
|
386
392
|
requiredEnvKeys: ["DEEPSEEK_API_KEY"]
|
|
387
393
|
},
|
|
394
|
+
{
|
|
395
|
+
id: "antigravity-cli",
|
|
396
|
+
name: "Antigravity",
|
|
397
|
+
description: "启动 Google Antigravity CLI 自带的 agy acp 服务",
|
|
398
|
+
authHint: "复用 Antigravity CLI 登录。需要登录时选择 Agent 提供的方式,或在终端运行 agy acp --login",
|
|
399
|
+
command: isWindowsPlatform() ? "agy.exe" : "agy",
|
|
400
|
+
args: ["acp"],
|
|
401
|
+
requiredEnvKeys: []
|
|
402
|
+
},
|
|
388
403
|
{
|
|
389
404
|
id: "agy",
|
|
390
|
-
name: "
|
|
391
|
-
description: "
|
|
405
|
+
name: "Antigravity (legacy bridge)",
|
|
406
|
+
description: "通过 bunx 启动 @yitom/agy-acp-map,兼容旧会话 ID 和桥接扩展",
|
|
392
407
|
authHint: "复用 Antigravity CLI 本地登录态;未登录先在本机终端完成 agy 登录后再连接",
|
|
393
408
|
command: "bunx",
|
|
394
409
|
args: ["-y", `${AGY_ACP_NPM_PACKAGE}@latest`],
|
|
@@ -399,7 +414,7 @@ function findBuiltinAcpRuntime(id) {
|
|
|
399
414
|
return BUILTIN_ACP_RUNTIMES.find((item) => item.id === id);
|
|
400
415
|
}
|
|
401
416
|
// src/version.ts
|
|
402
|
-
var ACP_CLIENT_VERSION = "0.1.
|
|
417
|
+
var ACP_CLIENT_VERSION = "0.1.15";
|
|
403
418
|
// src/client/session-open.ts
|
|
404
419
|
var import_sdk = require("@agentclientprotocol/sdk");
|
|
405
420
|
|
|
@@ -632,6 +647,8 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
632
647
|
return result;
|
|
633
648
|
} catch (error) {
|
|
634
649
|
lastError = errorMessage(error);
|
|
650
|
+
if (isAuthenticationRequired(lastError))
|
|
651
|
+
throw error;
|
|
635
652
|
log("warn", "session restore failed", {
|
|
636
653
|
method: rpcMethod,
|
|
637
654
|
sessionId: resumeId,
|
|
@@ -663,7 +680,7 @@ async function restoreOrCreateAcpSession(input) {
|
|
|
663
680
|
try {
|
|
664
681
|
return await request("session/new", baseParams);
|
|
665
682
|
} catch (firstError) {
|
|
666
|
-
if (isTransientAcpTransportError(firstError))
|
|
683
|
+
if (isAuthenticationRequired(errorMessage(firstError)) || isTransientAcpTransportError(firstError))
|
|
667
684
|
throw firstError;
|
|
668
685
|
if ((input.mcpServers ?? []).length === 0)
|
|
669
686
|
throw firstError;
|
|
@@ -2207,6 +2224,7 @@ var APP_RESOURCE_CAPABILITIES = {
|
|
|
2207
2224
|
gemini: { entry: null, strategy: "compatibility", configHome: "GEMINI_CLI_HOME" },
|
|
2208
2225
|
copilot: { entry: null, strategy: "compatibility", configHome: "COPILOT_HOME", candidateEntry: "COPILOT_CUSTOM_INSTRUCTIONS_DIRS" },
|
|
2209
2226
|
"cursor-cli": { entry: null, strategy: "compatibility", configHome: "CURSOR_CONFIG_DIR" },
|
|
2227
|
+
"antigravity-cli": { entry: null, strategy: "compatibility", configHome: null },
|
|
2210
2228
|
agy: { entry: "_meta.appResources.directory", strategy: "native-session", configHome: null },
|
|
2211
2229
|
deepseek: { entry: null, strategy: "compatibility", configHome: null }
|
|
2212
2230
|
};
|
|
@@ -3495,6 +3513,11 @@ var deepseekAdapter = {
|
|
|
3495
3513
|
canSkipInteractiveAuth: () => false
|
|
3496
3514
|
};
|
|
3497
3515
|
|
|
3516
|
+
// src/runtimes/agy/index.ts
|
|
3517
|
+
var import_node_fs18 = require("node:fs");
|
|
3518
|
+
var import_node_os14 = require("node:os");
|
|
3519
|
+
var import_node_path19 = require("node:path");
|
|
3520
|
+
|
|
3498
3521
|
// src/runtimes/agy/quota.ts
|
|
3499
3522
|
var import_node_fs17 = require("node:fs");
|
|
3500
3523
|
var import_node_path18 = require("node:path");
|
|
@@ -3602,6 +3625,7 @@ function resolveAntigravityLanguageServer() {
|
|
|
3602
3625
|
return null;
|
|
3603
3626
|
}
|
|
3604
3627
|
async function probeAgyQuota(options) {
|
|
3628
|
+
const runtimeId = options?.runtimeId ?? "agy";
|
|
3605
3629
|
const acc = resolveAntigravityAccount();
|
|
3606
3630
|
const lsInfo = resolveAntigravityLanguageServer();
|
|
3607
3631
|
if (lsInfo) {
|
|
@@ -3701,7 +3725,7 @@ async function probeAgyQuota(options) {
|
|
|
3701
3725
|
toWindow(tpWeekly, "Claude and GPT models", "Weekly limit", 10080)
|
|
3702
3726
|
].filter(Boolean);
|
|
3703
3727
|
return {
|
|
3704
|
-
runtimeId
|
|
3728
|
+
runtimeId,
|
|
3705
3729
|
provider: "Google Antigravity",
|
|
3706
3730
|
account: {
|
|
3707
3731
|
email: acc.email,
|
|
@@ -3728,7 +3752,7 @@ async function probeAgyQuota(options) {
|
|
|
3728
3752
|
const isAvailable = hasAgyDir || hasApiKey || Boolean(acc.email || acc.name);
|
|
3729
3753
|
if (!isAvailable) {
|
|
3730
3754
|
return {
|
|
3731
|
-
runtimeId
|
|
3755
|
+
runtimeId,
|
|
3732
3756
|
provider: "Google Antigravity",
|
|
3733
3757
|
status: "unauthorized",
|
|
3734
3758
|
message: "未检测到 Antigravity 登录凭据",
|
|
@@ -3736,7 +3760,7 @@ async function probeAgyQuota(options) {
|
|
|
3736
3760
|
};
|
|
3737
3761
|
}
|
|
3738
3762
|
return {
|
|
3739
|
-
runtimeId
|
|
3763
|
+
runtimeId,
|
|
3740
3764
|
provider: "Google Antigravity",
|
|
3741
3765
|
account: {
|
|
3742
3766
|
email: acc.email,
|
|
@@ -3784,6 +3808,53 @@ async function probeAgyQuota(options) {
|
|
|
3784
3808
|
}
|
|
3785
3809
|
|
|
3786
3810
|
// src/runtimes/agy/index.ts
|
|
3811
|
+
function isExecutableOnPath(command, env, platform) {
|
|
3812
|
+
const pathValue = env.PATH ?? env.Path ?? "";
|
|
3813
|
+
if (!pathValue.trim())
|
|
3814
|
+
return false;
|
|
3815
|
+
const sep = platform === "win32" ? ";" : import_node_path19.delimiter;
|
|
3816
|
+
for (const dir of pathValue.split(sep)) {
|
|
3817
|
+
const trimmed = dir.trim().replace(/^"|"$/g, "");
|
|
3818
|
+
if (!trimmed)
|
|
3819
|
+
continue;
|
|
3820
|
+
try {
|
|
3821
|
+
if (import_node_fs18.existsSync(import_node_path19.join(trimmed, command)))
|
|
3822
|
+
return true;
|
|
3823
|
+
} catch {}
|
|
3824
|
+
}
|
|
3825
|
+
return false;
|
|
3826
|
+
}
|
|
3827
|
+
function resolveAntigravityCliCommand(overrides) {
|
|
3828
|
+
const args = ["acp"];
|
|
3829
|
+
const platform = overrides?.platform ?? process.platform;
|
|
3830
|
+
const env = overrides?.env ?? process.env;
|
|
3831
|
+
const home = overrides?.home ?? import_node_os14.homedir();
|
|
3832
|
+
const binaries = platform === "win32" ? ["agy.exe", "agy.cmd"] : ["agy"];
|
|
3833
|
+
for (const binary of binaries) {
|
|
3834
|
+
if (isExecutableOnPath(binary, env, platform)) {
|
|
3835
|
+
return { command: binary, args };
|
|
3836
|
+
}
|
|
3837
|
+
}
|
|
3838
|
+
const candidates = [];
|
|
3839
|
+
if (platform === "win32") {
|
|
3840
|
+
const localAppData = env.LOCALAPPDATA?.trim() || (env.USERPROFILE?.trim() ? import_node_path19.join(env.USERPROFILE.trim(), "AppData", "Local") : "");
|
|
3841
|
+
const userProfile = env.USERPROFILE?.trim() || home;
|
|
3842
|
+
if (localAppData)
|
|
3843
|
+
candidates.push(import_node_path19.join(localAppData, "antigravity", "agy.exe"));
|
|
3844
|
+
if (userProfile)
|
|
3845
|
+
candidates.push(import_node_path19.join(userProfile, ".local", "bin", "agy.exe"));
|
|
3846
|
+
} else if (home) {
|
|
3847
|
+
candidates.push(import_node_path19.join(home, ".local", "bin", "agy"));
|
|
3848
|
+
}
|
|
3849
|
+
for (const candidate of candidates) {
|
|
3850
|
+
try {
|
|
3851
|
+
if (candidate && import_node_fs18.existsSync(candidate)) {
|
|
3852
|
+
return { command: candidate, args };
|
|
3853
|
+
}
|
|
3854
|
+
} catch {}
|
|
3855
|
+
}
|
|
3856
|
+
return null;
|
|
3857
|
+
}
|
|
3787
3858
|
function probeAgyAuth() {
|
|
3788
3859
|
return {
|
|
3789
3860
|
codexHome: "",
|
|
@@ -3807,6 +3878,16 @@ var agyAdapter = {
|
|
|
3807
3878
|
canSkipInteractiveAuth: () => false,
|
|
3808
3879
|
tryDirectSessionFirst: true
|
|
3809
3880
|
};
|
|
3881
|
+
var antigravityCliAdapter = {
|
|
3882
|
+
id: "antigravity-cli",
|
|
3883
|
+
prepareAppResources: async ({ directory }) => prepareCompatibilityResources(directory, "runtime-not-supported"),
|
|
3884
|
+
probeAuth: () => probeAgyAuth(),
|
|
3885
|
+
probeQuota: (options) => probeAgyQuota({ ...options, runtimeId: "antigravity-cli" }),
|
|
3886
|
+
resolveSpawnCommand: () => resolveAntigravityCliCommand(),
|
|
3887
|
+
orderAuthMethods: (methods) => methods,
|
|
3888
|
+
canSkipInteractiveAuth: () => false,
|
|
3889
|
+
tryDirectSessionFirst: true
|
|
3890
|
+
};
|
|
3810
3891
|
|
|
3811
3892
|
// src/runtimes/index.ts
|
|
3812
3893
|
function getAcpRuntimeAdapter(runtimeId) {
|
|
@@ -3831,6 +3912,8 @@ function getAcpRuntimeAdapter(runtimeId) {
|
|
|
3831
3912
|
return deepseekAdapter;
|
|
3832
3913
|
case agyAdapter.id:
|
|
3833
3914
|
return agyAdapter;
|
|
3915
|
+
case antigravityCliAdapter.id:
|
|
3916
|
+
return antigravityCliAdapter;
|
|
3834
3917
|
default:
|
|
3835
3918
|
return {
|
|
3836
3919
|
id: runtimeId,
|
|
@@ -4044,17 +4127,17 @@ var import_sdk3 = require("@agentclientprotocol/sdk");
|
|
|
4044
4127
|
|
|
4045
4128
|
// src/client/acp-fs.ts
|
|
4046
4129
|
var import_promises5 = require("node:fs/promises");
|
|
4047
|
-
var
|
|
4130
|
+
var import_node_path20 = require("node:path");
|
|
4048
4131
|
var import_promises6 = require("node:fs/promises");
|
|
4049
4132
|
var MAX_READ_BYTES = 2 * 1024 * 1024;
|
|
4050
4133
|
var BINARY_DOCUMENT_EXTENSIONS = new Set([".epub", ".mobi", ".azw", ".azw3", ".pdf"]);
|
|
4051
4134
|
function isBinaryDocumentPath(filePath) {
|
|
4052
|
-
return BINARY_DOCUMENT_EXTENSIONS.has(
|
|
4135
|
+
return BINARY_DOCUMENT_EXTENSIONS.has(import_node_path20.extname(filePath).toLowerCase());
|
|
4053
4136
|
}
|
|
4054
4137
|
function assertPathInsideWorkspace(filePath, workspaceRoot) {
|
|
4055
|
-
const root =
|
|
4056
|
-
const target =
|
|
4057
|
-
const rootWithSep = root.endsWith(
|
|
4138
|
+
const root = import_node_path20.resolve(workspaceRoot);
|
|
4139
|
+
const target = import_node_path20.resolve(filePath);
|
|
4140
|
+
const rootWithSep = root.endsWith(import_node_path20.sep) ? root : root + import_node_path20.sep;
|
|
4058
4141
|
if (target !== root && !target.startsWith(rootWithSep)) {
|
|
4059
4142
|
throw new Error(`路径不在工作区内: ${filePath}`);
|
|
4060
4143
|
}
|
|
@@ -4085,7 +4168,7 @@ async function acpReadTextFile(params) {
|
|
|
4085
4168
|
}
|
|
4086
4169
|
async function acpWriteTextFile(params) {
|
|
4087
4170
|
const abs = assertPathInsideWorkspace(params.path, params.workspaceRoot);
|
|
4088
|
-
await import_promises6.mkdir(
|
|
4171
|
+
await import_promises6.mkdir(import_node_path20.dirname(abs), { recursive: true });
|
|
4089
4172
|
await import_promises5.writeFile(abs, params.content, "utf-8");
|
|
4090
4173
|
return {};
|
|
4091
4174
|
}
|
|
@@ -4115,9 +4198,10 @@ function registerAcpClientHandlers(app, deps) {
|
|
|
4115
4198
|
try {
|
|
4116
4199
|
const outcome = await deps.onPermission({
|
|
4117
4200
|
sessionId: typeof params.sessionId === "string" ? params.sessionId : undefined,
|
|
4118
|
-
params
|
|
4201
|
+
params,
|
|
4202
|
+
signal: ctx.signal
|
|
4119
4203
|
});
|
|
4120
|
-
return { outcome };
|
|
4204
|
+
return { outcome: !ctx.signal.aborted && isAcpPermissionOutcome(outcome, params) ? outcome : { outcome: "cancelled" } };
|
|
4121
4205
|
} catch (error) {
|
|
4122
4206
|
console.error("[acp] request_permission 失败", error);
|
|
4123
4207
|
return { outcome: { outcome: "cancelled" } };
|
|
@@ -4254,26 +4338,23 @@ function permissionOptionId(option) {
|
|
|
4254
4338
|
return option.id;
|
|
4255
4339
|
return null;
|
|
4256
4340
|
}
|
|
4341
|
+
function permissionOptions(params) {
|
|
4342
|
+
return Array.isArray(params.options) ? params.options.filter((option) => !!option && typeof option === "object") : [];
|
|
4343
|
+
}
|
|
4344
|
+
function isAcpPermissionOutcome(outcome, params) {
|
|
4345
|
+
if (!outcome || typeof outcome !== "object")
|
|
4346
|
+
return false;
|
|
4347
|
+
const value = outcome;
|
|
4348
|
+
if (value.outcome === "cancelled")
|
|
4349
|
+
return true;
|
|
4350
|
+
return value.outcome === "selected" && typeof value.optionId === "string" && value.optionId.length > 0 && permissionOptions(params).some((option) => permissionOptionId(option) === value.optionId);
|
|
4351
|
+
}
|
|
4257
4352
|
function pickAllowOptionId(params) {
|
|
4258
|
-
const options = params
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
continue;
|
|
4264
|
-
const option = item;
|
|
4265
|
-
const id = permissionOptionId(option);
|
|
4266
|
-
const kind = typeof option.kind === "string" ? option.kind : "";
|
|
4267
|
-
if (id && (kind.includes("allow") || kind === "allow_once" || kind === "allow_always")) {
|
|
4268
|
-
return id;
|
|
4269
|
-
}
|
|
4270
|
-
}
|
|
4271
|
-
for (const item of options) {
|
|
4272
|
-
if (!item || typeof item !== "object")
|
|
4273
|
-
continue;
|
|
4274
|
-
const id = permissionOptionId(item);
|
|
4275
|
-
if (id)
|
|
4276
|
-
return id;
|
|
4353
|
+
const options = permissionOptions(params);
|
|
4354
|
+
for (const kind of ["allow_once", "allow", "allow_always"]) {
|
|
4355
|
+
const option = options.find((entry) => entry.kind === kind && permissionOptionId(entry));
|
|
4356
|
+
if (option)
|
|
4357
|
+
return permissionOptionId(option);
|
|
4277
4358
|
}
|
|
4278
4359
|
return null;
|
|
4279
4360
|
}
|
|
@@ -4464,8 +4545,8 @@ class AcpTerminalManager {
|
|
|
4464
4545
|
|
|
4465
4546
|
// src/client/acp-proxy-service.ts
|
|
4466
4547
|
var import_promises7 = require("node:fs/promises");
|
|
4467
|
-
var
|
|
4468
|
-
var
|
|
4548
|
+
var import_node_fs19 = require("node:fs");
|
|
4549
|
+
var import_node_path21 = require("node:path");
|
|
4469
4550
|
var DEFAULT_ACP_PROXY_SETTINGS = {
|
|
4470
4551
|
enabled: false,
|
|
4471
4552
|
host: "127.0.0.1",
|
|
@@ -4474,7 +4555,7 @@ var DEFAULT_ACP_PROXY_SETTINGS = {
|
|
|
4474
4555
|
var PROXY_ENV_KEYS = ["HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY"];
|
|
4475
4556
|
var LOWERCASE_PROXY_ENV_KEYS = ["http_proxy", "https_proxy", "all_proxy", "no_proxy"];
|
|
4476
4557
|
function proxyFilePath(dir) {
|
|
4477
|
-
return
|
|
4558
|
+
return import_node_path21.join(dir, "agent", "proxy.json");
|
|
4478
4559
|
}
|
|
4479
4560
|
function validate2(settings) {
|
|
4480
4561
|
if (!settings.host.trim())
|
|
@@ -4486,7 +4567,7 @@ function validate2(settings) {
|
|
|
4486
4567
|
}
|
|
4487
4568
|
async function readAcpProxySettings(dir = getDefaultAgentDataDir()) {
|
|
4488
4569
|
const file = proxyFilePath(dir);
|
|
4489
|
-
if (!
|
|
4570
|
+
if (!import_node_fs19.existsSync(file))
|
|
4490
4571
|
return { ...DEFAULT_ACP_PROXY_SETTINGS };
|
|
4491
4572
|
try {
|
|
4492
4573
|
const raw = JSON.parse(await import_promises7.readFile(file, "utf8"));
|
|
@@ -4508,7 +4589,7 @@ async function saveAcpProxySettings(payload, dir = getDefaultAgentDataDir()) {
|
|
|
4508
4589
|
host: payload.host.trim() || DEFAULT_ACP_PROXY_SETTINGS.host,
|
|
4509
4590
|
port: payload.port
|
|
4510
4591
|
};
|
|
4511
|
-
await import_promises7.mkdir(
|
|
4592
|
+
await import_promises7.mkdir(import_node_path21.join(dir, "agent"), { recursive: true });
|
|
4512
4593
|
await import_promises7.writeFile(proxyFilePath(dir), JSON.stringify(stored, null, 2), "utf8");
|
|
4513
4594
|
return ok(stored);
|
|
4514
4595
|
}
|
|
@@ -4564,9 +4645,9 @@ function compatDeliveryKey(sessionId, generation, digest) {
|
|
|
4564
4645
|
}
|
|
4565
4646
|
|
|
4566
4647
|
// src/mcp/app-skills-mcp.ts
|
|
4567
|
-
var
|
|
4648
|
+
var import_node_path22 = require("node:path");
|
|
4568
4649
|
var import_node_url = require("node:url");
|
|
4569
|
-
var
|
|
4650
|
+
var import_node_fs20 = require("node:fs");
|
|
4570
4651
|
var APP_SKILLS_MCP_SERVER_NAME = "app-skills";
|
|
4571
4652
|
var APP_SKILLS_TOOLS = [
|
|
4572
4653
|
{
|
|
@@ -4602,11 +4683,11 @@ function buildAppSkillsMcpServer(directory, opts) {
|
|
|
4602
4683
|
function resolveAppSkillsRunnerPath(fromFile) {
|
|
4603
4684
|
const base = fromFile ?? import_node_url.fileURLToPath("file:///home/runner/work/acp-client/acp-client/src/mcp/app-skills-mcp.ts");
|
|
4604
4685
|
const candidates = [
|
|
4605
|
-
|
|
4606
|
-
|
|
4686
|
+
import_node_path22.join(import_node_path22.dirname(base), "app-skills-mcp-serve.cjs"),
|
|
4687
|
+
import_node_path22.join(import_node_path22.dirname(base), "app-skills-mcp-serve.ts")
|
|
4607
4688
|
];
|
|
4608
4689
|
for (const candidate of candidates) {
|
|
4609
|
-
if (
|
|
4690
|
+
if (import_node_fs20.existsSync(candidate))
|
|
4610
4691
|
return candidate;
|
|
4611
4692
|
}
|
|
4612
4693
|
throw new Error(`技能 MCP 入口缺失(dist 未构建?): ${candidates[0]}`);
|
|
@@ -4643,10 +4724,10 @@ function isSupportedBridgeVersion(runtimeId, version) {
|
|
|
4643
4724
|
|
|
4644
4725
|
// src/session/session-capabilities.ts
|
|
4645
4726
|
function parseLoadSessionSupported(caps) {
|
|
4646
|
-
return caps
|
|
4727
|
+
return caps?.loadSession === true;
|
|
4647
4728
|
}
|
|
4648
4729
|
function parseResumeSessionSupported(caps) {
|
|
4649
|
-
const sessionCaps = caps
|
|
4730
|
+
const sessionCaps = caps?.sessionCapabilities && typeof caps.sessionCapabilities === "object" ? caps.sessionCapabilities : null;
|
|
4650
4731
|
if (!sessionCaps)
|
|
4651
4732
|
return false;
|
|
4652
4733
|
const resume = sessionCaps.resume;
|
|
@@ -4712,6 +4793,7 @@ class AcpClient {
|
|
|
4712
4793
|
commandsCache = new AvailableCommandsCache;
|
|
4713
4794
|
quotaCache = new QuotaCache;
|
|
4714
4795
|
runtimeInfo;
|
|
4796
|
+
hasCustomRuntime;
|
|
4715
4797
|
adapter;
|
|
4716
4798
|
workspaceRoot;
|
|
4717
4799
|
clientInfo;
|
|
@@ -4720,6 +4802,8 @@ class AcpClient {
|
|
|
4720
4802
|
configurationScope;
|
|
4721
4803
|
sessionConfig = null;
|
|
4722
4804
|
resourcesDir;
|
|
4805
|
+
authenticatingAgent;
|
|
4806
|
+
permissionRequests = new Map;
|
|
4723
4807
|
processScopeKey = import_node_crypto4.randomUUID();
|
|
4724
4808
|
callbacks;
|
|
4725
4809
|
terminals = new AcpTerminalManager;
|
|
@@ -4776,8 +4860,10 @@ class AcpClient {
|
|
|
4776
4860
|
const runtimeId = typeof options.runtime === "string" ? options.runtime : options.runtime?.id ?? DEFAULT_ACP_RUNTIME_ID;
|
|
4777
4861
|
this.adapter = getAcpRuntimeAdapter(runtimeId);
|
|
4778
4862
|
if (typeof options.runtime === "object" && options.runtime !== null) {
|
|
4863
|
+
this.hasCustomRuntime = true;
|
|
4779
4864
|
this.runtimeInfo = options.runtime;
|
|
4780
4865
|
} else {
|
|
4866
|
+
this.hasCustomRuntime = false;
|
|
4781
4867
|
const found = findBuiltinAcpRuntime(runtimeId);
|
|
4782
4868
|
if (!found) {
|
|
4783
4869
|
throw new Error(`未知或未注册的 ACP 运行时模板: ${runtimeId}`);
|
|
@@ -4797,6 +4883,39 @@ class AcpClient {
|
|
|
4797
4883
|
get initializeResponse() {
|
|
4798
4884
|
return this.initResponse;
|
|
4799
4885
|
}
|
|
4886
|
+
async authenticate(methodId) {
|
|
4887
|
+
const agent = this.sdkConnection?.agent;
|
|
4888
|
+
if (!agent || !this.isConnected) {
|
|
4889
|
+
return err({ code: "ACP_NOT_CONNECTED", message: "尚未连接到 Agent 服务端" });
|
|
4890
|
+
}
|
|
4891
|
+
const method = this.initResponse?.authMethods?.find((entry) => entry.id === methodId);
|
|
4892
|
+
if (!method) {
|
|
4893
|
+
return err({ code: "INVALID_ARGUMENT", message: "Agent 未声明此认证方式" });
|
|
4894
|
+
}
|
|
4895
|
+
if ("type" in method && method.type === "terminal") {
|
|
4896
|
+
return err({ code: "INVALID_ARGUMENT", message: "此认证方式需要在交互式终端中运行" });
|
|
4897
|
+
}
|
|
4898
|
+
if (this.authenticatingAgent === agent) {
|
|
4899
|
+
return err({ code: "INVALID_STATE", message: "Agent 正在认证" });
|
|
4900
|
+
}
|
|
4901
|
+
this.authenticatingAgent = agent;
|
|
4902
|
+
try {
|
|
4903
|
+
await sdkRequest(agent, import_sdk4.methods.agent.authenticate, { methodId });
|
|
4904
|
+
if (this.sdkConnection?.agent !== agent) {
|
|
4905
|
+
return err({ code: "CANCELLED", message: "认证期间 Agent 连接已关闭" });
|
|
4906
|
+
}
|
|
4907
|
+
return ok(undefined);
|
|
4908
|
+
} catch (error) {
|
|
4909
|
+
if (this.sdkConnection?.agent !== agent) {
|
|
4910
|
+
return err({ code: "CANCELLED", message: "认证期间 Agent 连接已关闭" });
|
|
4911
|
+
}
|
|
4912
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4913
|
+
return err({ code: isAuthenticationRequired(message) ? "UNAUTHORIZED" : "ACP_PROTOCOL_ERROR", message });
|
|
4914
|
+
} finally {
|
|
4915
|
+
if (this.authenticatingAgent === agent)
|
|
4916
|
+
this.authenticatingAgent = undefined;
|
|
4917
|
+
}
|
|
4918
|
+
}
|
|
4800
4919
|
async connect() {
|
|
4801
4920
|
if (this.inflightPrompts.size > 0)
|
|
4802
4921
|
return err({ code: "ACP_PROTOCOL_ERROR", message: "Agent 正在回答,请结束后重新连接" });
|
|
@@ -4815,7 +4934,7 @@ class AcpClient {
|
|
|
4815
4934
|
return err({ code: "ACP_SPAWN_ERROR", message: blocker });
|
|
4816
4935
|
}
|
|
4817
4936
|
let effectiveRuntime = { ...this.runtimeInfo };
|
|
4818
|
-
if (this.adapter.resolveSpawnCommand) {
|
|
4937
|
+
if (!this.hasCustomRuntime && this.adapter.resolveSpawnCommand) {
|
|
4819
4938
|
const resolved = this.adapter.resolveSpawnCommand();
|
|
4820
4939
|
if (!resolved) {
|
|
4821
4940
|
const message = `运行时 CLI 未安装: ${this.runtimeInfo.id}`;
|
|
@@ -4948,14 +5067,31 @@ class AcpClient {
|
|
|
4948
5067
|
return this.callbacks.readSnapshot(resource);
|
|
4949
5068
|
},
|
|
4950
5069
|
onPermission: async (payload) => {
|
|
4951
|
-
|
|
4952
|
-
|
|
5070
|
+
const callback = this.callbacks.onPermissionRequest;
|
|
5071
|
+
const cancelled = { outcome: "cancelled" };
|
|
5072
|
+
if (!callback || payload.signal.aborted)
|
|
5073
|
+
return cancelled;
|
|
5074
|
+
const controller = new AbortController;
|
|
5075
|
+
const signal = AbortSignal.any([payload.signal, controller.signal]);
|
|
5076
|
+
this.permissionRequests.set(controller, payload.sessionId);
|
|
5077
|
+
let resolveCancellation;
|
|
5078
|
+
const cancellation = new Promise((resolve) => {
|
|
5079
|
+
resolveCancellation = resolve;
|
|
5080
|
+
});
|
|
5081
|
+
const onAbort = () => resolveCancellation(cancelled);
|
|
5082
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
5083
|
+
try {
|
|
5084
|
+
const outcome = await Promise.race([cancellation, callback({
|
|
4953
5085
|
sessionId: payload.sessionId,
|
|
4954
5086
|
toolCall: payload.params?.toolCall,
|
|
4955
|
-
params: payload.params
|
|
4956
|
-
|
|
5087
|
+
params: payload.params,
|
|
5088
|
+
signal
|
|
5089
|
+
})]);
|
|
5090
|
+
return signal.aborted ? cancelled : outcome;
|
|
5091
|
+
} finally {
|
|
5092
|
+
signal.removeEventListener("abort", onAbort);
|
|
5093
|
+
this.permissionRequests.delete(controller);
|
|
4957
5094
|
}
|
|
4958
|
-
return { outcome: "cancelled" };
|
|
4959
5095
|
},
|
|
4960
5096
|
onSessionUpdate: (params) => {
|
|
4961
5097
|
this.commandsCache.observe(params);
|
|
@@ -5112,7 +5248,7 @@ class AcpClient {
|
|
|
5112
5248
|
return ok(handle);
|
|
5113
5249
|
} catch (e) {
|
|
5114
5250
|
const message = e instanceof Error ? e.message : String(e);
|
|
5115
|
-
return err({ code: "ACP_PROTOCOL_ERROR", message });
|
|
5251
|
+
return err({ code: isAuthenticationRequired(message) ? "UNAUTHORIZED" : "ACP_PROTOCOL_ERROR", message });
|
|
5116
5252
|
}
|
|
5117
5253
|
}
|
|
5118
5254
|
async promptSession(sessionId, promptText, options) {
|
|
@@ -5145,7 +5281,9 @@ class AcpClient {
|
|
|
5145
5281
|
return ok(response);
|
|
5146
5282
|
} catch (e) {
|
|
5147
5283
|
const message = e instanceof Error ? e.message : String(e);
|
|
5148
|
-
|
|
5284
|
+
if (e instanceof AcpMcpRecoveryCancelledError)
|
|
5285
|
+
return err({ code: "CANCELLED", message });
|
|
5286
|
+
return err({ code: isAuthenticationRequired(message) ? "UNAUTHORIZED" : "ACP_PROTOCOL_ERROR", message });
|
|
5149
5287
|
} finally {
|
|
5150
5288
|
if (generation === this.connectionGen)
|
|
5151
5289
|
this.inflightPrompts.delete(sessionId);
|
|
@@ -5188,7 +5326,9 @@ class AcpClient {
|
|
|
5188
5326
|
if (!this.sdkConnection?.agent)
|
|
5189
5327
|
return err({ code: "ACP_NOT_CONNECTED", message: "Agent is not connected" });
|
|
5190
5328
|
try {
|
|
5191
|
-
|
|
5329
|
+
const notifying = this.sdkConnection.agent.notify(import_sdk4.methods.agent.session.cancel, { sessionId });
|
|
5330
|
+
this.cancelPermissionRequests("session_cancelled", sessionId);
|
|
5331
|
+
await notifying;
|
|
5192
5332
|
return ok(undefined);
|
|
5193
5333
|
} catch (error) {
|
|
5194
5334
|
return err({ code: "ACP_PROTOCOL_ERROR", message: error instanceof Error ? error.message : String(error) });
|
|
@@ -5214,6 +5354,7 @@ class AcpClient {
|
|
|
5214
5354
|
++this.connectionGen;
|
|
5215
5355
|
this.mcpRecovery.reset();
|
|
5216
5356
|
this.inflightPrompts.clear();
|
|
5357
|
+
this.cancelPermissionRequests("connection_closed");
|
|
5217
5358
|
this.setStatus("disconnected", reason);
|
|
5218
5359
|
this.resourcePrep = null;
|
|
5219
5360
|
const capabilities = this.initResponse?.agentCapabilities?.sessionCapabilities;
|
|
@@ -5250,6 +5391,12 @@ class AcpClient {
|
|
|
5250
5391
|
}
|
|
5251
5392
|
}
|
|
5252
5393
|
}
|
|
5394
|
+
cancelPermissionRequests(reason, sessionId) {
|
|
5395
|
+
for (const [controller, pendingSessionId] of this.permissionRequests) {
|
|
5396
|
+
if (sessionId === undefined || pendingSessionId === sessionId)
|
|
5397
|
+
controller.abort(reason);
|
|
5398
|
+
}
|
|
5399
|
+
}
|
|
5253
5400
|
setStatus(status, detail) {
|
|
5254
5401
|
this.status = status;
|
|
5255
5402
|
this.callbacks.onStatusChange?.(status, detail);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @yitom/acp-client — Headless Agent Client Protocol SDK
|
|
3
3
|
*
|
|
4
4
|
* 完整的 ACP 客户端协议栈,包含:
|
|
5
|
-
* - runtimes:
|
|
5
|
+
* - runtimes: 内置主流 Agent 运行时(Codex, Claude, Cursor, DeepSeek, Gemini, Copilot, OpenCode, Antigravity CLI, Agy)
|
|
6
6
|
* - process: 跨平台子进程生命周期、级联 kill 与温进程池复用
|
|
7
7
|
* - client: 独立的 AcpClient 客户端、会话状态机、stdio 桥接与通用回调
|
|
8
8
|
* - auth: 统一认证守门员、密钥探测与 CODEX_HOME 隔离
|