@yitom/acp-client 0.1.8 → 0.1.9
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 +2 -0
- package/dist/client/sdk-client.d.ts +2 -0
- package/dist/index.cjs +84 -66
- package/dist/index.js +87 -69
- package/dist/sidecar.cjs +1117 -1098
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -149,3 +149,5 @@ bun run packages/acp/examples/standalone-acp-demo.ts
|
|
|
149
149
|
### Antigravity session resources
|
|
150
150
|
|
|
151
151
|
With `@yitom/agy-acp-map` 0.1.24, `resources.directory` is delivered through the bridge session extension `_meta.appResources.directory`. Rules, native Skills and session MCP live in a private temporary additional workspace; cwd, global configuration and authentication remain unchanged. Close/delete/orderly shutdown remove the temporary workspace. Unknown bridge versions keep compatibility guidance and the app-skills MCP fallback. This extension is bridge-specific, not a standard ACP configuration-home API. `configurationScope: "session"` also supports agy; its configuration report remains conservative until the bridge accepts the session extension.
|
|
152
|
+
|
|
153
|
+
Normal disconnect closes owned sessions on agents advertising `sessionCapabilities.close` before terminating the transport/process. Requests are bounded to two seconds; failures are logged and teardown continues. This permits session resource cleanup on Windows as well.
|
|
@@ -30,3 +30,5 @@ runtimeId?: string): {
|
|
|
30
30
|
};
|
|
31
31
|
/** 带显式超时的 agent.request:超时 abort(触发 $/cancel_request)并拒绝 */
|
|
32
32
|
export declare function sdkRequest<Response, Params>(agent: ClientContext, method: string, params: Params, timeoutMs?: number): Promise<Response>;
|
|
33
|
+
/** Close owned sessions before transport/process teardown; unsupported failures stay bounded. */
|
|
34
|
+
export declare function closeAcpSessions(agent: ClientContext, sessionIds: Iterable<string>, timeoutMs?: number): Promise<string[]>;
|
package/dist/index.cjs
CHANGED
|
@@ -111,6 +111,7 @@ __export(exports_src, {
|
|
|
111
111
|
claudeResourceSessionMeta: () => claudeResourceSessionMeta,
|
|
112
112
|
clearAcpProvider: () => clearAcpProvider,
|
|
113
113
|
clearCursorCatalogCache: () => clearCursorCatalogCache,
|
|
114
|
+
closeAcpSessions: () => closeAcpSessions,
|
|
114
115
|
codexAdapter: () => codexAdapter,
|
|
115
116
|
connectSdkClient: () => connectSdkClient,
|
|
116
117
|
copilotAdapter: () => copilotAdapter,
|
|
@@ -384,7 +385,83 @@ function findBuiltinAcpRuntime(id) {
|
|
|
384
385
|
return BUILTIN_ACP_RUNTIMES.find((item) => item.id === id);
|
|
385
386
|
}
|
|
386
387
|
// src/version.ts
|
|
387
|
-
var ACP_CLIENT_VERSION = "0.1.
|
|
388
|
+
var ACP_CLIENT_VERSION = "0.1.9";
|
|
389
|
+
// src/client/sdk-client.ts
|
|
390
|
+
var import_node_stream = require("node:stream");
|
|
391
|
+
var import_sdk = require("@agentclientprotocol/sdk");
|
|
392
|
+
var ACP_SDK_REQUEST_TIMEOUT_MS = 120000;
|
|
393
|
+
function createSdkStreamHandle(child) {
|
|
394
|
+
const stdoutBridge = new import_node_stream.PassThrough;
|
|
395
|
+
const stdinBridge = new import_node_stream.PassThrough;
|
|
396
|
+
child.stdout.pipe(stdoutBridge);
|
|
397
|
+
stdinBridge.pipe(child.stdin, { end: false });
|
|
398
|
+
const output = import_node_stream.Writable.toWeb(stdinBridge);
|
|
399
|
+
const input = import_node_stream.Readable.toWeb(stdoutBridge);
|
|
400
|
+
const stream = import_sdk.ndJsonStream(output, input);
|
|
401
|
+
let disposed = false;
|
|
402
|
+
return {
|
|
403
|
+
stream,
|
|
404
|
+
dispose: () => {
|
|
405
|
+
if (disposed)
|
|
406
|
+
return;
|
|
407
|
+
disposed = true;
|
|
408
|
+
try {
|
|
409
|
+
child.stdout.unpipe(stdoutBridge);
|
|
410
|
+
} catch {}
|
|
411
|
+
try {
|
|
412
|
+
stdinBridge.unpipe(child.stdin);
|
|
413
|
+
} catch {}
|
|
414
|
+
try {
|
|
415
|
+
stdoutBridge.destroy();
|
|
416
|
+
} catch {}
|
|
417
|
+
try {
|
|
418
|
+
stdinBridge.destroy();
|
|
419
|
+
} catch {}
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
function connectSdkClient(child, configure, runtimeId) {
|
|
424
|
+
if (runtimeId && true) {
|
|
425
|
+
console.info(`[acp:sdk] connect runtime=${runtimeId} pid=${child.pid ?? "?"}`);
|
|
426
|
+
}
|
|
427
|
+
const app = import_sdk.client({ name: "inkdown" });
|
|
428
|
+
configure(app);
|
|
429
|
+
const streamHandle = createSdkStreamHandle(child);
|
|
430
|
+
const connection = app.connect(streamHandle.stream);
|
|
431
|
+
return { app, connection, streamHandle };
|
|
432
|
+
}
|
|
433
|
+
async function sdkRequest(agent, method, params, timeoutMs = ACP_SDK_REQUEST_TIMEOUT_MS) {
|
|
434
|
+
const controller = new AbortController;
|
|
435
|
+
let timer;
|
|
436
|
+
try {
|
|
437
|
+
const pending = agent.request(method, params, {
|
|
438
|
+
cancellationSignal: controller.signal
|
|
439
|
+
});
|
|
440
|
+
const timeout = new Promise((_, reject) => {
|
|
441
|
+
timer = setTimeout(() => {
|
|
442
|
+
controller.abort();
|
|
443
|
+
reject(new Error(`请求超时: ${method}`));
|
|
444
|
+
}, timeoutMs);
|
|
445
|
+
timer.unref?.();
|
|
446
|
+
});
|
|
447
|
+
return await Promise.race([pending, timeout]);
|
|
448
|
+
} finally {
|
|
449
|
+
if (timer !== undefined)
|
|
450
|
+
clearTimeout(timer);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
async function closeAcpSessions(agent, sessionIds, timeoutMs = 2000) {
|
|
454
|
+
const failed = [];
|
|
455
|
+
await Promise.all([...new Set(sessionIds)].map(async (sessionId) => {
|
|
456
|
+
try {
|
|
457
|
+
await sdkRequest(agent, "session/close", { sessionId }, timeoutMs);
|
|
458
|
+
} catch {
|
|
459
|
+
failed.push(sessionId);
|
|
460
|
+
}
|
|
461
|
+
}));
|
|
462
|
+
return failed;
|
|
463
|
+
}
|
|
464
|
+
|
|
388
465
|
// src/resources/session-config.ts
|
|
389
466
|
var import_node_fs2 = require("node:fs");
|
|
390
467
|
var import_promises = require("node:fs/promises");
|
|
@@ -2994,71 +3071,6 @@ function tryReuseLiveAcpProcess(runtimeId, query = {}) {
|
|
|
2994
3071
|
return { status: "miss" };
|
|
2995
3072
|
}
|
|
2996
3073
|
|
|
2997
|
-
// src/client/sdk-client.ts
|
|
2998
|
-
var import_node_stream = require("node:stream");
|
|
2999
|
-
var import_sdk = require("@agentclientprotocol/sdk");
|
|
3000
|
-
var ACP_SDK_REQUEST_TIMEOUT_MS = 120000;
|
|
3001
|
-
function createSdkStreamHandle(child) {
|
|
3002
|
-
const stdoutBridge = new import_node_stream.PassThrough;
|
|
3003
|
-
const stdinBridge = new import_node_stream.PassThrough;
|
|
3004
|
-
child.stdout.pipe(stdoutBridge);
|
|
3005
|
-
stdinBridge.pipe(child.stdin, { end: false });
|
|
3006
|
-
const output = import_node_stream.Writable.toWeb(stdinBridge);
|
|
3007
|
-
const input = import_node_stream.Readable.toWeb(stdoutBridge);
|
|
3008
|
-
const stream = import_sdk.ndJsonStream(output, input);
|
|
3009
|
-
let disposed = false;
|
|
3010
|
-
return {
|
|
3011
|
-
stream,
|
|
3012
|
-
dispose: () => {
|
|
3013
|
-
if (disposed)
|
|
3014
|
-
return;
|
|
3015
|
-
disposed = true;
|
|
3016
|
-
try {
|
|
3017
|
-
child.stdout.unpipe(stdoutBridge);
|
|
3018
|
-
} catch {}
|
|
3019
|
-
try {
|
|
3020
|
-
stdinBridge.unpipe(child.stdin);
|
|
3021
|
-
} catch {}
|
|
3022
|
-
try {
|
|
3023
|
-
stdoutBridge.destroy();
|
|
3024
|
-
} catch {}
|
|
3025
|
-
try {
|
|
3026
|
-
stdinBridge.destroy();
|
|
3027
|
-
} catch {}
|
|
3028
|
-
}
|
|
3029
|
-
};
|
|
3030
|
-
}
|
|
3031
|
-
function connectSdkClient(child, configure, runtimeId) {
|
|
3032
|
-
if (runtimeId && true) {
|
|
3033
|
-
console.info(`[acp:sdk] connect runtime=${runtimeId} pid=${child.pid ?? "?"}`);
|
|
3034
|
-
}
|
|
3035
|
-
const app = import_sdk.client({ name: "inkdown" });
|
|
3036
|
-
configure(app);
|
|
3037
|
-
const streamHandle = createSdkStreamHandle(child);
|
|
3038
|
-
const connection = app.connect(streamHandle.stream);
|
|
3039
|
-
return { app, connection, streamHandle };
|
|
3040
|
-
}
|
|
3041
|
-
async function sdkRequest(agent, method, params, timeoutMs = ACP_SDK_REQUEST_TIMEOUT_MS) {
|
|
3042
|
-
const controller = new AbortController;
|
|
3043
|
-
let timer;
|
|
3044
|
-
try {
|
|
3045
|
-
const pending = agent.request(method, params, {
|
|
3046
|
-
cancellationSignal: controller.signal
|
|
3047
|
-
});
|
|
3048
|
-
const timeout = new Promise((_, reject) => {
|
|
3049
|
-
timer = setTimeout(() => {
|
|
3050
|
-
controller.abort();
|
|
3051
|
-
reject(new Error(`请求超时: ${method}`));
|
|
3052
|
-
}, timeoutMs);
|
|
3053
|
-
timer.unref?.();
|
|
3054
|
-
});
|
|
3055
|
-
return await Promise.race([pending, timeout]);
|
|
3056
|
-
} finally {
|
|
3057
|
-
if (timer !== undefined)
|
|
3058
|
-
clearTimeout(timer);
|
|
3059
|
-
}
|
|
3060
|
-
}
|
|
3061
|
-
|
|
3062
3074
|
// src/client/client-handlers.ts
|
|
3063
3075
|
var import_sdk2 = require("@agentclientprotocol/sdk");
|
|
3064
3076
|
|
|
@@ -4499,6 +4511,12 @@ class AcpClient {
|
|
|
4499
4511
|
async disconnect(reason) {
|
|
4500
4512
|
this.setStatus("disconnected", reason);
|
|
4501
4513
|
this.resourcePrep = null;
|
|
4514
|
+
const capabilities = this.initResponse?.agentCapabilities?.sessionCapabilities;
|
|
4515
|
+
if (capabilities?.close && this.sdkConnection?.agent) {
|
|
4516
|
+
const failed = await closeAcpSessions(this.sdkConnection.agent, this.sessionLedger.keys());
|
|
4517
|
+
if (failed.length)
|
|
4518
|
+
this.callbacks.onLog?.("warn", "Session close failed before process teardown", { count: failed.length });
|
|
4519
|
+
}
|
|
4502
4520
|
this.sessionLedger.clear();
|
|
4503
4521
|
this.compatSentKeys.clear();
|
|
4504
4522
|
this.compatSnapshots.clear();
|
package/dist/index.js
CHANGED
|
@@ -162,7 +162,86 @@ 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.9";
|
|
166
|
+
// src/client/sdk-client.ts
|
|
167
|
+
import { PassThrough, Readable, Writable } from "node:stream";
|
|
168
|
+
import {
|
|
169
|
+
client as createSdkClientApp,
|
|
170
|
+
ndJsonStream
|
|
171
|
+
} from "@agentclientprotocol/sdk";
|
|
172
|
+
var ACP_SDK_REQUEST_TIMEOUT_MS = 120000;
|
|
173
|
+
function createSdkStreamHandle(child) {
|
|
174
|
+
const stdoutBridge = new PassThrough;
|
|
175
|
+
const stdinBridge = new PassThrough;
|
|
176
|
+
child.stdout.pipe(stdoutBridge);
|
|
177
|
+
stdinBridge.pipe(child.stdin, { end: false });
|
|
178
|
+
const output = Writable.toWeb(stdinBridge);
|
|
179
|
+
const input = Readable.toWeb(stdoutBridge);
|
|
180
|
+
const stream = ndJsonStream(output, input);
|
|
181
|
+
let disposed = false;
|
|
182
|
+
return {
|
|
183
|
+
stream,
|
|
184
|
+
dispose: () => {
|
|
185
|
+
if (disposed)
|
|
186
|
+
return;
|
|
187
|
+
disposed = true;
|
|
188
|
+
try {
|
|
189
|
+
child.stdout.unpipe(stdoutBridge);
|
|
190
|
+
} catch {}
|
|
191
|
+
try {
|
|
192
|
+
stdinBridge.unpipe(child.stdin);
|
|
193
|
+
} catch {}
|
|
194
|
+
try {
|
|
195
|
+
stdoutBridge.destroy();
|
|
196
|
+
} catch {}
|
|
197
|
+
try {
|
|
198
|
+
stdinBridge.destroy();
|
|
199
|
+
} catch {}
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function connectSdkClient(child, configure, runtimeId) {
|
|
204
|
+
if (runtimeId && true) {
|
|
205
|
+
console.info(`[acp:sdk] connect runtime=${runtimeId} pid=${child.pid ?? "?"}`);
|
|
206
|
+
}
|
|
207
|
+
const app = createSdkClientApp({ name: "inkdown" });
|
|
208
|
+
configure(app);
|
|
209
|
+
const streamHandle = createSdkStreamHandle(child);
|
|
210
|
+
const connection = app.connect(streamHandle.stream);
|
|
211
|
+
return { app, connection, streamHandle };
|
|
212
|
+
}
|
|
213
|
+
async function sdkRequest(agent, method, params, timeoutMs = ACP_SDK_REQUEST_TIMEOUT_MS) {
|
|
214
|
+
const controller = new AbortController;
|
|
215
|
+
let timer;
|
|
216
|
+
try {
|
|
217
|
+
const pending = agent.request(method, params, {
|
|
218
|
+
cancellationSignal: controller.signal
|
|
219
|
+
});
|
|
220
|
+
const timeout = new Promise((_, reject) => {
|
|
221
|
+
timer = setTimeout(() => {
|
|
222
|
+
controller.abort();
|
|
223
|
+
reject(new Error(`请求超时: ${method}`));
|
|
224
|
+
}, timeoutMs);
|
|
225
|
+
timer.unref?.();
|
|
226
|
+
});
|
|
227
|
+
return await Promise.race([pending, timeout]);
|
|
228
|
+
} finally {
|
|
229
|
+
if (timer !== undefined)
|
|
230
|
+
clearTimeout(timer);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async function closeAcpSessions(agent, sessionIds, timeoutMs = 2000) {
|
|
234
|
+
const failed = [];
|
|
235
|
+
await Promise.all([...new Set(sessionIds)].map(async (sessionId) => {
|
|
236
|
+
try {
|
|
237
|
+
await sdkRequest(agent, "session/close", { sessionId }, timeoutMs);
|
|
238
|
+
} catch {
|
|
239
|
+
failed.push(sessionId);
|
|
240
|
+
}
|
|
241
|
+
}));
|
|
242
|
+
return failed;
|
|
243
|
+
}
|
|
244
|
+
|
|
166
245
|
// src/resources/session-config.ts
|
|
167
246
|
import { existsSync } from "node:fs";
|
|
168
247
|
import { mkdtemp, mkdir, writeFile, readdir, readFile, lstat, realpath, rm } from "node:fs/promises";
|
|
@@ -2774,74 +2853,6 @@ function tryReuseLiveAcpProcess(runtimeId, query = {}) {
|
|
|
2774
2853
|
return { status: "miss" };
|
|
2775
2854
|
}
|
|
2776
2855
|
|
|
2777
|
-
// src/client/sdk-client.ts
|
|
2778
|
-
import { PassThrough, Readable, Writable } from "node:stream";
|
|
2779
|
-
import {
|
|
2780
|
-
client as createSdkClientApp,
|
|
2781
|
-
ndJsonStream
|
|
2782
|
-
} from "@agentclientprotocol/sdk";
|
|
2783
|
-
var ACP_SDK_REQUEST_TIMEOUT_MS = 120000;
|
|
2784
|
-
function createSdkStreamHandle(child) {
|
|
2785
|
-
const stdoutBridge = new PassThrough;
|
|
2786
|
-
const stdinBridge = new PassThrough;
|
|
2787
|
-
child.stdout.pipe(stdoutBridge);
|
|
2788
|
-
stdinBridge.pipe(child.stdin, { end: false });
|
|
2789
|
-
const output = Writable.toWeb(stdinBridge);
|
|
2790
|
-
const input = Readable.toWeb(stdoutBridge);
|
|
2791
|
-
const stream = ndJsonStream(output, input);
|
|
2792
|
-
let disposed = false;
|
|
2793
|
-
return {
|
|
2794
|
-
stream,
|
|
2795
|
-
dispose: () => {
|
|
2796
|
-
if (disposed)
|
|
2797
|
-
return;
|
|
2798
|
-
disposed = true;
|
|
2799
|
-
try {
|
|
2800
|
-
child.stdout.unpipe(stdoutBridge);
|
|
2801
|
-
} catch {}
|
|
2802
|
-
try {
|
|
2803
|
-
stdinBridge.unpipe(child.stdin);
|
|
2804
|
-
} catch {}
|
|
2805
|
-
try {
|
|
2806
|
-
stdoutBridge.destroy();
|
|
2807
|
-
} catch {}
|
|
2808
|
-
try {
|
|
2809
|
-
stdinBridge.destroy();
|
|
2810
|
-
} catch {}
|
|
2811
|
-
}
|
|
2812
|
-
};
|
|
2813
|
-
}
|
|
2814
|
-
function connectSdkClient(child, configure, runtimeId) {
|
|
2815
|
-
if (runtimeId && true) {
|
|
2816
|
-
console.info(`[acp:sdk] connect runtime=${runtimeId} pid=${child.pid ?? "?"}`);
|
|
2817
|
-
}
|
|
2818
|
-
const app = createSdkClientApp({ name: "inkdown" });
|
|
2819
|
-
configure(app);
|
|
2820
|
-
const streamHandle = createSdkStreamHandle(child);
|
|
2821
|
-
const connection = app.connect(streamHandle.stream);
|
|
2822
|
-
return { app, connection, streamHandle };
|
|
2823
|
-
}
|
|
2824
|
-
async function sdkRequest(agent, method, params, timeoutMs = ACP_SDK_REQUEST_TIMEOUT_MS) {
|
|
2825
|
-
const controller = new AbortController;
|
|
2826
|
-
let timer;
|
|
2827
|
-
try {
|
|
2828
|
-
const pending = agent.request(method, params, {
|
|
2829
|
-
cancellationSignal: controller.signal
|
|
2830
|
-
});
|
|
2831
|
-
const timeout = new Promise((_, reject) => {
|
|
2832
|
-
timer = setTimeout(() => {
|
|
2833
|
-
controller.abort();
|
|
2834
|
-
reject(new Error(`请求超时: ${method}`));
|
|
2835
|
-
}, timeoutMs);
|
|
2836
|
-
timer.unref?.();
|
|
2837
|
-
});
|
|
2838
|
-
return await Promise.race([pending, timeout]);
|
|
2839
|
-
} finally {
|
|
2840
|
-
if (timer !== undefined)
|
|
2841
|
-
clearTimeout(timer);
|
|
2842
|
-
}
|
|
2843
|
-
}
|
|
2844
|
-
|
|
2845
2856
|
// src/client/client-handlers.ts
|
|
2846
2857
|
import { methods, RequestError } from "@agentclientprotocol/sdk";
|
|
2847
2858
|
|
|
@@ -4282,6 +4293,12 @@ class AcpClient {
|
|
|
4282
4293
|
async disconnect(reason) {
|
|
4283
4294
|
this.setStatus("disconnected", reason);
|
|
4284
4295
|
this.resourcePrep = null;
|
|
4296
|
+
const capabilities = this.initResponse?.agentCapabilities?.sessionCapabilities;
|
|
4297
|
+
if (capabilities?.close && this.sdkConnection?.agent) {
|
|
4298
|
+
const failed = await closeAcpSessions(this.sdkConnection.agent, this.sessionLedger.keys());
|
|
4299
|
+
if (failed.length)
|
|
4300
|
+
this.callbacks.onLog?.("warn", "Session close failed before process teardown", { count: failed.length });
|
|
4301
|
+
}
|
|
4285
4302
|
this.sessionLedger.clear();
|
|
4286
4303
|
this.compatSentKeys.clear();
|
|
4287
4304
|
this.compatSnapshots.clear();
|
|
@@ -5275,6 +5292,7 @@ export {
|
|
|
5275
5292
|
claudeResourceSessionMeta,
|
|
5276
5293
|
clearAcpProvider,
|
|
5277
5294
|
clearCursorCatalogCache,
|
|
5295
|
+
closeAcpSessions,
|
|
5278
5296
|
codexAdapter,
|
|
5279
5297
|
connectSdkClient,
|
|
5280
5298
|
copilotAdapter,
|