@noetic-tools/acp 2.0.0-next.1 → 2.0.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents.d.ts +5 -0
- package/dist/agents.js +13 -1
- package/dist/bin.js +19 -2
- package/dist/client-adapters.d.ts +2 -2
- package/dist/client.d.ts +9 -2
- package/dist/client.js +40 -1
- package/dist/connection.d.ts +25 -2
- package/dist/connection.js +455 -36
- package/dist/define.d.ts +13 -0
- package/dist/define.js +122 -4
- package/dist/index.d.ts +1 -1
- package/dist/items.d.ts +1 -1
- package/dist/keeper/client.d.ts +93 -0
- package/dist/keeper/client.js +468 -0
- package/dist/keeper/main.d.ts +6 -0
- package/dist/keeper/main.js +31 -0
- package/dist/keeper/process.d.ts +24 -0
- package/dist/keeper/process.js +425 -0
- package/dist/keeper/protocol.d.ts +74 -0
- package/dist/keeper/protocol.js +108 -0
- package/dist/keeper/relay.d.ts +88 -0
- package/dist/keeper/relay.js +420 -0
- package/dist/mcp/node.d.ts +6 -1
- package/dist/mcp/node.js +4 -4
- package/dist/permission-channel.d.ts +5 -0
- package/dist/permission-channel.js +16 -1
- package/dist/runner/host.js +74 -16
- package/dist/runner/options.d.ts +2 -0
- package/dist/runner/options.js +2 -0
- package/dist/runner/protocol.d.ts +12 -0
- package/dist/runner/protocol.js +24 -0
- package/dist/runner/serve.d.ts +5 -0
- package/dist/runner/serve.js +93 -3
- package/dist/serve-events.d.ts +2 -0
- package/dist/serve-events.js +1 -0
- package/dist/serve-questions.d.ts +26 -0
- package/dist/serve-questions.js +105 -0
- package/dist/serve-types.d.ts +1 -1
- package/dist/serve.d.ts +2 -2
- package/dist/serve.js +10 -1
- package/dist/server.js +1 -1
- package/dist/stdio-process.d.ts +38 -0
- package/dist/stdio-process.js +214 -0
- package/dist/stdio.d.ts +50 -7
- package/dist/stdio.js +192 -52
- package/dist/tool-bridge.d.ts +9 -0
- package/dist/tool-bridge.js +5 -1
- package/dist/transport-loopback.d.ts +2 -2
- package/dist/transport-loopback.js +1 -1
- package/dist/turn.d.ts +3 -2
- package/dist/turn.js +22 -2
- package/dist/update-filter.d.ts +38 -0
- package/dist/update-filter.js +193 -0
- package/package.json +3 -3
package/dist/stdio.d.ts
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* lazy dynamic import, so `claudeCode()` works with no extra wiring while
|
|
8
8
|
* keeping the dependency off the main graph.
|
|
9
9
|
*/
|
|
10
|
-
import type { AcpMachineFactory, AcpTransportFactory } from '@noetic-tools/types';
|
|
10
|
+
import type { AcpMachineFactory, AcpTransportFactory, SpawnCommand, ToolBridgeAddress } from '@noetic-tools/types';
|
|
11
|
+
export type { StopProcessTreeOptions } from './stdio-process.js';
|
|
12
|
+
export { stopProcessTree, TERM_GRACE_MS } from './stdio-process.js';
|
|
11
13
|
/** @public How to launch an ACP agent as a child process. */
|
|
12
14
|
export interface StdioAgentSpec {
|
|
13
15
|
/** Identifier used in error messages. */
|
|
@@ -21,15 +23,56 @@ export interface StdioAgentSpec {
|
|
|
21
23
|
/**
|
|
22
24
|
* Build a transport factory that spawns `spec.command` and speaks ACP over its
|
|
23
25
|
* stdin/stdout. The child's stderr is inherited so agent diagnostics reach the
|
|
24
|
-
* host's logs instead of vanishing.
|
|
26
|
+
* host's logs instead of vanishing. Closing the transport (or aborting its
|
|
27
|
+
* signal) closes the pipes and stops the agent's whole process group —
|
|
28
|
+
* SIGTERM, a grace period, then SIGKILL; on Windows, its process tree. Close
|
|
29
|
+
* is idempotent: every call shares one shutdown.
|
|
25
30
|
* @public
|
|
26
31
|
*/
|
|
27
32
|
export declare function stdioAcpTransport(spec: StdioAgentSpec): AcpTransportFactory;
|
|
33
|
+
/** @public Options for {@link localMachine}. */
|
|
34
|
+
export interface LocalMachineOptions {
|
|
35
|
+
/**
|
|
36
|
+
* Run the agent through a keeper, so it can outlive this host and a later
|
|
37
|
+
* host can reattach to it (`AcpTransport.reattach`). Default `true`. Without
|
|
38
|
+
* one — or where no keeper script is on disk, as in a single-file bundle —
|
|
39
|
+
* the agent is a child process that ends with its host.
|
|
40
|
+
*/
|
|
41
|
+
keeper?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* How long a kept agent may run with no host attached before its keeper
|
|
44
|
+
* stops it. Default `0`: no limit — it runs until a host reattaches and
|
|
45
|
+
* closes it, or it exits.
|
|
46
|
+
*/
|
|
47
|
+
detachedTimeoutMs?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Rewrite the agent's command just before it starts — wrap it in a sandbox
|
|
50
|
+
* (`sandbox-exec`, `bwrap`), swap in a binary the host ships. `command.env`
|
|
51
|
+
* is the complete environment the agent would get; `bridges` are the tool
|
|
52
|
+
* bridge addresses this machine handed out, so a sandbox can let their
|
|
53
|
+
* ports through. The returned command runs with exactly its own `args`,
|
|
54
|
+
* `env` (the given one when it names none) and `cwd`, as the leader of its
|
|
55
|
+
* own process group, with or without a keeper.
|
|
56
|
+
*/
|
|
57
|
+
wrap?: (command: LocalAgentCommand, info: LocalWrapInfo) => SpawnCommand | Promise<SpawnCommand>;
|
|
58
|
+
/** The agent's stderr. Default: this process's stderr. */
|
|
59
|
+
onStderr?: (chunk: string) => void;
|
|
60
|
+
}
|
|
61
|
+
/** @public The command {@link LocalMachineOptions.wrap} receives: `env` is complete. */
|
|
62
|
+
export interface LocalAgentCommand extends SpawnCommand {
|
|
63
|
+
readonly env: Readonly<Record<string, string>>;
|
|
64
|
+
}
|
|
65
|
+
/** @public What {@link LocalMachineOptions.wrap} is told besides the command. */
|
|
66
|
+
export interface LocalWrapInfo {
|
|
67
|
+
/** Every tool bridge address `reach` handed out on this machine, in order. */
|
|
68
|
+
readonly bridges: ReadonlyArray<ToolBridgeAddress>;
|
|
69
|
+
}
|
|
28
70
|
/**
|
|
29
|
-
* This machine: the
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
71
|
+
* This machine: the agent runs through a keeper (see
|
|
72
|
+
* {@link LocalMachineOptions.keeper}), which also serves the tool bridge to it
|
|
73
|
+
* on a port that outlives the host; an MCP server beside it is a child
|
|
74
|
+
* process. The agent gets this process's environment; an MCP server, as the
|
|
75
|
+
* MCP SDK starts one, only `serverEnv`'s short list.
|
|
33
76
|
* @public
|
|
34
77
|
*/
|
|
35
|
-
export declare function localMachine(agentId?: string): AcpMachineFactory;
|
|
78
|
+
export declare function localMachine(agentId?: string, options?: LocalMachineOptions): AcpMachineFactory;
|
package/dist/stdio.js
CHANGED
|
@@ -10,11 +10,17 @@
|
|
|
10
10
|
import { spawn } from 'node:child_process';
|
|
11
11
|
import { Readable, Writable } from 'node:stream';
|
|
12
12
|
import { AcpConnectError, frameworkCast } from '@noetic-tools/types';
|
|
13
|
+
import { attachKeeper, keeperHandleOf, startKeeper } from './keeper/client.js';
|
|
13
14
|
import { serverEnv } from './server-env.js';
|
|
15
|
+
import { stopProcessTree, stopWithHost } from './stdio-process.js';
|
|
16
|
+
export { stopProcessTree, TERM_GRACE_MS } from './stdio-process.js';
|
|
14
17
|
/**
|
|
15
18
|
* Build a transport factory that spawns `spec.command` and speaks ACP over its
|
|
16
19
|
* stdin/stdout. The child's stderr is inherited so agent diagnostics reach the
|
|
17
|
-
* host's logs instead of vanishing.
|
|
20
|
+
* host's logs instead of vanishing. Closing the transport (or aborting its
|
|
21
|
+
* signal) closes the pipes and stops the agent's whole process group —
|
|
22
|
+
* SIGTERM, a grace period, then SIGKILL; on Windows, its process tree. Close
|
|
23
|
+
* is idempotent: every call shares one shutdown.
|
|
18
24
|
* @public
|
|
19
25
|
*/
|
|
20
26
|
export function stdioAcpTransport(spec) {
|
|
@@ -27,44 +33,163 @@ export function stdioAcpTransport(spec) {
|
|
|
27
33
|
...opts.env,
|
|
28
34
|
},
|
|
29
35
|
cwd: opts.cwd,
|
|
30
|
-
},
|
|
36
|
+
}, {
|
|
37
|
+
signal: opts.signal,
|
|
38
|
+
whenHostExits: opts.whenHostExits,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** The variables that are set, so a wrapper sees plain strings. */
|
|
42
|
+
function definedEnv(env) {
|
|
43
|
+
const out = {};
|
|
44
|
+
for (const [name, value] of Object.entries(env)) {
|
|
45
|
+
if (value !== undefined) {
|
|
46
|
+
out[name] = value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
31
50
|
}
|
|
32
51
|
/**
|
|
33
|
-
* This machine: the
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
52
|
+
* This machine: the agent runs through a keeper (see
|
|
53
|
+
* {@link LocalMachineOptions.keeper}), which also serves the tool bridge to it
|
|
54
|
+
* on a port that outlives the host; an MCP server beside it is a child
|
|
55
|
+
* process. The agent gets this process's environment; an MCP server, as the
|
|
56
|
+
* MCP SDK starts one, only `serverEnv`'s short list.
|
|
37
57
|
* @public
|
|
38
58
|
*/
|
|
39
|
-
export function localMachine(agentId = 'local') {
|
|
40
|
-
return async ({ signal }) => {
|
|
59
|
+
export function localMachine(agentId = 'local', options = {}) {
|
|
60
|
+
return async ({ signal, whenHostExits = 'keep' }) => {
|
|
41
61
|
const started = new Set();
|
|
62
|
+
const bridges = [];
|
|
63
|
+
const useKeeper = options.keeper !== false;
|
|
64
|
+
let keeper;
|
|
65
|
+
const keeperOptions = {
|
|
66
|
+
whenHostExits,
|
|
67
|
+
detachedTimeoutMs: options.detachedTimeoutMs ?? 0,
|
|
68
|
+
};
|
|
69
|
+
const withStderr = (link) => {
|
|
70
|
+
if (link && options.onStderr) {
|
|
71
|
+
link.onStderr = options.onStderr;
|
|
72
|
+
}
|
|
73
|
+
return link;
|
|
74
|
+
};
|
|
75
|
+
const openKeeper = () => {
|
|
76
|
+
keeper ??= useKeeper
|
|
77
|
+
? startKeeper(agentId, keeperOptions).then(withStderr)
|
|
78
|
+
: Promise.resolve(undefined);
|
|
79
|
+
return keeper;
|
|
80
|
+
};
|
|
81
|
+
/** The command as it will run: the host's wrapper applied, env complete. */
|
|
82
|
+
const prepare = async (command) => {
|
|
83
|
+
const env = definedEnv({
|
|
84
|
+
...process.env,
|
|
85
|
+
...command.env,
|
|
86
|
+
});
|
|
87
|
+
if (!options.wrap) {
|
|
88
|
+
return {
|
|
89
|
+
...command,
|
|
90
|
+
env,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const wrapped = await options.wrap({
|
|
94
|
+
...command,
|
|
95
|
+
env,
|
|
96
|
+
}, {
|
|
97
|
+
bridges: [
|
|
98
|
+
...bridges,
|
|
99
|
+
],
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
...wrapped,
|
|
103
|
+
env: wrapped.env ?? env,
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
signal?.addEventListener('abort', () => {
|
|
107
|
+
void keeper?.then((link) => link?.stop());
|
|
108
|
+
}, {
|
|
109
|
+
once: true,
|
|
110
|
+
});
|
|
42
111
|
const start = async (command, env) => {
|
|
43
112
|
const transport = await spawnStdio(agentId, {
|
|
44
113
|
...command,
|
|
45
114
|
env,
|
|
46
|
-
},
|
|
115
|
+
}, {
|
|
116
|
+
signal,
|
|
117
|
+
whenHostExits,
|
|
118
|
+
onStderr: options.onStderr,
|
|
119
|
+
});
|
|
47
120
|
started.add(transport);
|
|
48
121
|
return transport;
|
|
49
122
|
};
|
|
50
123
|
return {
|
|
51
|
-
reach: async (bridge) =>
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
124
|
+
reach: async (bridge) => {
|
|
125
|
+
const link = await openKeeper();
|
|
126
|
+
if (!link) {
|
|
127
|
+
bridges.push(bridge);
|
|
128
|
+
return bridge;
|
|
129
|
+
}
|
|
130
|
+
const url = await link.reach(new URL(bridge.url).pathname, bridge.url);
|
|
131
|
+
const reached = {
|
|
132
|
+
...bridge,
|
|
133
|
+
url,
|
|
134
|
+
};
|
|
135
|
+
bridges.push(reached);
|
|
136
|
+
return reached;
|
|
137
|
+
},
|
|
138
|
+
launch: async (command) => {
|
|
139
|
+
const prepared = await prepare(command);
|
|
140
|
+
const link = await openKeeper();
|
|
141
|
+
if (!link) {
|
|
142
|
+
return await start(prepared, prepared.env ?? {});
|
|
143
|
+
}
|
|
144
|
+
const transport = await link.launch(prepared);
|
|
145
|
+
started.add(transport);
|
|
146
|
+
return transport;
|
|
147
|
+
},
|
|
148
|
+
attach: async (handle) => {
|
|
149
|
+
const named = keeperHandleOf(handle);
|
|
150
|
+
if (!named) {
|
|
151
|
+
throw new AcpConnectError({
|
|
152
|
+
agentId,
|
|
153
|
+
message: `ACP agent '${agentId}' cannot be reattached: its handle names no keeper.`,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const link = attachKeeper(agentId, named, whenHostExits);
|
|
157
|
+
keeper = link.then(withStderr);
|
|
158
|
+
const transport = (await link).transport();
|
|
159
|
+
started.add(transport);
|
|
160
|
+
return transport;
|
|
161
|
+
},
|
|
56
162
|
spawn: (command) => start(command, serverEnv(command.env)),
|
|
57
163
|
async close() {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
164
|
+
// In parallel: each stop may take its whole grace period.
|
|
165
|
+
const closing = [
|
|
166
|
+
...started,
|
|
167
|
+
].map((transport) => transport.close().catch(() => undefined));
|
|
61
168
|
started.clear();
|
|
169
|
+
closing.push((keeper ?? Promise.resolve(undefined))
|
|
170
|
+
.then((link) => link?.stop())
|
|
171
|
+
.catch(() => undefined));
|
|
172
|
+
await Promise.all(closing);
|
|
62
173
|
},
|
|
63
174
|
};
|
|
64
175
|
};
|
|
65
176
|
}
|
|
66
|
-
/**
|
|
67
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Spawn `command` with exactly its `env` and carry its stdin/stdout as a byte
|
|
179
|
+
* stream. The child leads its own process group (POSIX), so closing or
|
|
180
|
+
* aborting stops everything it started — a wrapper's native grandchild
|
|
181
|
+
* included — and releases the pipes; see `stopProcessTree`. A missing binary
|
|
182
|
+
* or a signal that is already aborted rejects here, not at `close()`.
|
|
183
|
+
*/
|
|
184
|
+
async function spawnStdio(agentId, command, { signal, whenHostExits = 'keep', onStderr, }) {
|
|
185
|
+
const fail = (message, cause) => new AcpConnectError({
|
|
186
|
+
agentId,
|
|
187
|
+
message: `ACP agent '${agentId}' (${command.command}) ${message}.`,
|
|
188
|
+
cause,
|
|
189
|
+
});
|
|
190
|
+
if (signal?.aborted) {
|
|
191
|
+
throw fail('was not started: the launch was already aborted', signal.reason);
|
|
192
|
+
}
|
|
68
193
|
const child = spawn(command.command, [
|
|
69
194
|
...(command.args ?? []),
|
|
70
195
|
], {
|
|
@@ -73,52 +198,67 @@ async function spawnStdio(agentId, command, signal) {
|
|
|
73
198
|
stdio: [
|
|
74
199
|
'pipe',
|
|
75
200
|
'pipe',
|
|
76
|
-
'inherit',
|
|
201
|
+
onStderr ? 'pipe' : 'inherit',
|
|
77
202
|
],
|
|
203
|
+
// Its own process group, so shutdown can signal the whole tree without
|
|
204
|
+
// ever signalling the host's group. Windows stops the tree by pid.
|
|
205
|
+
detached: process.platform !== 'win32',
|
|
206
|
+
windowsHide: true,
|
|
78
207
|
});
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
208
|
+
const forgetOnExit = whenHostExits === 'stop' ? stopWithHost(child) : () => undefined;
|
|
209
|
+
let closing;
|
|
210
|
+
const close = () => {
|
|
211
|
+
signal?.removeEventListener('abort', onAbort);
|
|
212
|
+
forgetOnExit();
|
|
213
|
+
closing ??= stopProcessTree(child).catch((error) => {
|
|
214
|
+
throw fail('could not be stopped', error);
|
|
86
215
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// returned. Capture it so the failure is reported against the agent rather
|
|
90
|
-
// than escaping as an unhandled 'error' event.
|
|
91
|
-
let spawnError;
|
|
92
|
-
child.once('error', (error) => {
|
|
93
|
-
spawnError = error;
|
|
94
|
-
});
|
|
216
|
+
return closing;
|
|
217
|
+
};
|
|
95
218
|
const onAbort = () => {
|
|
96
|
-
|
|
219
|
+
// An explicit close() still observes a failure; this only keeps it handled.
|
|
220
|
+
void close().catch(() => undefined);
|
|
97
221
|
};
|
|
98
222
|
signal?.addEventListener('abort', onAbort, {
|
|
99
223
|
once: true,
|
|
100
224
|
});
|
|
101
|
-
|
|
225
|
+
try {
|
|
226
|
+
await new Promise((resolve, reject) => {
|
|
227
|
+
child.once('spawn', resolve);
|
|
228
|
+
child.once('error', reject);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
await close().catch(() => undefined);
|
|
233
|
+
throw fail('failed to start', error);
|
|
234
|
+
}
|
|
235
|
+
// A late error (a broken pipe after spawn) must not escape as an unhandled
|
|
236
|
+
// 'error' event; the stream ending reports it to the connection.
|
|
237
|
+
child.on('error', () => undefined);
|
|
238
|
+
// Shutdown destroys our ends of the pipes, possibly mid-read; the web
|
|
239
|
+
// streams report that to their reader, so the Node-side error is handled.
|
|
240
|
+
child.stdin?.on('error', () => undefined);
|
|
241
|
+
child.stdout?.on('error', () => undefined);
|
|
242
|
+
if (onStderr) {
|
|
243
|
+
child.stderr?.on('error', () => undefined);
|
|
244
|
+
child.stderr?.on('data', (chunk) => onStderr(chunk.toString('utf8')));
|
|
245
|
+
}
|
|
246
|
+
if (signal?.aborted) {
|
|
247
|
+
await close().catch(() => undefined);
|
|
248
|
+
throw fail('was aborted while starting', signal.reason);
|
|
249
|
+
}
|
|
250
|
+
const stdin = child.stdin;
|
|
251
|
+
const stdout = child.stdout;
|
|
252
|
+
if (!stdin || !stdout) {
|
|
253
|
+
await close().catch(() => undefined);
|
|
254
|
+
throw fail('was spawned without usable stdio pipes', undefined);
|
|
255
|
+
}
|
|
102
256
|
return {
|
|
103
257
|
// `node:stream`'s web-stream types are structurally the same as the
|
|
104
258
|
// global ones but nominally distinct, so the bridge is cast once here
|
|
105
259
|
// rather than leaking a Node-specific type through the transport contract.
|
|
106
260
|
readable: frameworkCast(Readable.toWeb(stdout)),
|
|
107
261
|
writable: frameworkCast(Writable.toWeb(stdin)),
|
|
108
|
-
|
|
109
|
-
if (closed) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
closed = true;
|
|
113
|
-
signal?.removeEventListener('abort', onAbort);
|
|
114
|
-
child.kill();
|
|
115
|
-
if (spawnError) {
|
|
116
|
-
throw new AcpConnectError({
|
|
117
|
-
agentId,
|
|
118
|
-
message: `ACP agent '${agentId}' (${command.command}) failed to start.`,
|
|
119
|
-
cause: spawnError,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
},
|
|
262
|
+
close,
|
|
123
263
|
};
|
|
124
264
|
}
|
package/dist/tool-bridge.d.ts
CHANGED
|
@@ -47,8 +47,15 @@ export interface ToolBridge {
|
|
|
47
47
|
readonly server: AcpMcpServer;
|
|
48
48
|
readonly env: Record<string, string>;
|
|
49
49
|
readonly permits?: BridgedPermissionCheck;
|
|
50
|
+
/** What a later host needs to serve this bridge to the same agent. */
|
|
51
|
+
readonly credentials: ToolBridgeCredentials;
|
|
50
52
|
close(): Promise<void>;
|
|
51
53
|
}
|
|
54
|
+
/** The path and token a bridge serves under. */
|
|
55
|
+
export interface ToolBridgeCredentials {
|
|
56
|
+
readonly path: string;
|
|
57
|
+
readonly token: string;
|
|
58
|
+
}
|
|
52
59
|
/**
|
|
53
60
|
* Start the loopback MCP server, carry it to the agent's machine, and work
|
|
54
61
|
* out the agent's launch settings from the address it reaches there. The
|
|
@@ -64,4 +71,6 @@ export declare function startToolBridge(opts: {
|
|
|
64
71
|
env?: Record<string, string | undefined>;
|
|
65
72
|
/** Carries the bridge to the agent's machine; this machine's loopback by default. */
|
|
66
73
|
reach?: (bridge: ToolBridgeAddress) => Promise<ToolBridgeAddress>;
|
|
74
|
+
/** Serve under the path and token an earlier host gave a reattached agent. */
|
|
75
|
+
reuse?: ToolBridgeCredentials;
|
|
67
76
|
}): Promise<ToolBridge>;
|
package/dist/tool-bridge.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
export async function startToolBridge(opts) {
|
|
19
19
|
const { serveToolsOverHttp } = await import('./mcp/node.js');
|
|
20
|
-
const http = await serveToolsOverHttp(opts.getHost);
|
|
20
|
+
const http = await serveToolsOverHttp(opts.getHost, opts.reuse);
|
|
21
21
|
const local = {
|
|
22
22
|
serverName: opts.serverName,
|
|
23
23
|
url: http.url,
|
|
@@ -56,6 +56,10 @@ export async function startToolBridge(opts) {
|
|
|
56
56
|
},
|
|
57
57
|
env,
|
|
58
58
|
permits: opts.wiring.permits,
|
|
59
|
+
credentials: {
|
|
60
|
+
path: new URL(http.url).pathname,
|
|
61
|
+
token: http.token,
|
|
62
|
+
},
|
|
59
63
|
close: () => http.close(),
|
|
60
64
|
};
|
|
61
65
|
}
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* both directions — capability negotiation, session updates, permission
|
|
7
7
|
* round-trips, `fs/*` and `terminal/*` callbacks — without spawning a process.
|
|
8
8
|
*/
|
|
9
|
+
import type * as acp from '@agentclientprotocol/sdk';
|
|
10
|
+
import { AgentSideConnection } from '@agentclientprotocol/sdk';
|
|
9
11
|
import type { AcpMachineFactory, AcpTransport, AcpTransportFactory, SpawnCommand } from '@noetic-tools/types';
|
|
10
|
-
import type * as acp from '@zed-industries/agent-client-protocol';
|
|
11
|
-
import { AgentSideConnection } from '@zed-industries/agent-client-protocol';
|
|
12
12
|
/** @public The two ends of a loopback connection. */
|
|
13
13
|
export interface AcpLoopbackPair {
|
|
14
14
|
/** Give this to `openAcpConnection`. */
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* both directions — capability negotiation, session updates, permission
|
|
7
7
|
* round-trips, `fs/*` and `terminal/*` callbacks — without spawning a process.
|
|
8
8
|
*/
|
|
9
|
+
import { AgentSideConnection, ndJsonStream } from '@agentclientprotocol/sdk';
|
|
9
10
|
import { AcpConnectError, frameworkCast } from '@noetic-tools/types';
|
|
10
|
-
import { AgentSideConnection, ndJsonStream } from '@zed-industries/agent-client-protocol';
|
|
11
11
|
function endpoint(readable, writable) {
|
|
12
12
|
let closed = false;
|
|
13
13
|
return {
|
package/dist/turn.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* {@link AcpTurnResult}: Noetic conversation items, the assistant text, the
|
|
4
4
|
* agent's plan, its slash commands, and its final mode.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* Transcript updates are folded here; every update also reaches the host. See `user_message_chunk`
|
|
7
7
|
* below for the one whose payload is deliberately not turned into an item.
|
|
8
8
|
*/
|
|
9
9
|
import type { AcpPlanEntry, AcpSessionNotification, AcpStopReason, AcpToolCallContent, AcpTurnResult, TokenUsage } from '@noetic-tools/types';
|
|
@@ -12,7 +12,7 @@ import type { AcpPlanEntry, AcpSessionNotification, AcpStopReason, AcpToolCallCo
|
|
|
12
12
|
* carries. Diff and terminal content are rendered structurally rather than
|
|
13
13
|
* discarded, so the transcript keeps what the agent actually did.
|
|
14
14
|
*/
|
|
15
|
-
export declare function renderToolCallContent(content: ReadonlyArray<AcpToolCallContent>, rawOutput?:
|
|
15
|
+
export declare function renderToolCallContent(content: ReadonlyArray<AcpToolCallContent>, rawOutput?: unknown): string;
|
|
16
16
|
/** @public Folds a turn's session updates into a result. */
|
|
17
17
|
export declare class AcpTurnAccumulator {
|
|
18
18
|
private reasoning;
|
|
@@ -36,6 +36,7 @@ export declare class AcpTurnAccumulator {
|
|
|
36
36
|
stopReason: AcpStopReason;
|
|
37
37
|
usage?: TokenUsage;
|
|
38
38
|
cost?: number;
|
|
39
|
+
reportedUsage?: AcpTurnResult['reportedUsage'];
|
|
39
40
|
}): AcpTurnResult;
|
|
40
41
|
/**
|
|
41
42
|
* The agent's last message — the text after its final tool call — as a
|
package/dist/turn.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* {@link AcpTurnResult}: Noetic conversation items, the assistant text, the
|
|
4
4
|
* agent's plan, its slash commands, and its final mode.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* Transcript updates are folded here; every update also reaches the host. See `user_message_chunk`
|
|
7
7
|
* below for the one whose payload is deliberately not turned into an item.
|
|
8
8
|
*/
|
|
9
9
|
import { assistantMessageItem, contentBlockText, functionCallItem, functionCallOutputItem, } from './items.js';
|
|
@@ -100,6 +100,7 @@ export class AcpTurnAccumulator {
|
|
|
100
100
|
text: this.finalText(),
|
|
101
101
|
usage: opts.usage,
|
|
102
102
|
cost: opts.cost,
|
|
103
|
+
reportedUsage: opts.reportedUsage,
|
|
103
104
|
plan: this.plan,
|
|
104
105
|
availableCommands: this.availableCommands,
|
|
105
106
|
currentModeId: this.currentModeId,
|
|
@@ -157,13 +158,32 @@ export class AcpTurnAccumulator {
|
|
|
157
158
|
];
|
|
158
159
|
return;
|
|
159
160
|
}
|
|
161
|
+
if (update.sessionUpdate === 'plan_update') {
|
|
162
|
+
// The draft plan protocol: an item plan replaces the snapshot; a file or
|
|
163
|
+
// markdown plan has no entries to fold, and stays on the event stream.
|
|
164
|
+
if (update.plan.type === 'items') {
|
|
165
|
+
this.plan = [
|
|
166
|
+
...update.plan.entries,
|
|
167
|
+
];
|
|
168
|
+
}
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (update.sessionUpdate === 'plan_removed') {
|
|
172
|
+
this.plan = [];
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
160
175
|
if (update.sessionUpdate === 'available_commands_update') {
|
|
161
176
|
this.availableCommands = [
|
|
162
177
|
...update.availableCommands,
|
|
163
178
|
];
|
|
164
179
|
return;
|
|
165
180
|
}
|
|
166
|
-
|
|
181
|
+
if (update.sessionUpdate === 'current_mode_update') {
|
|
182
|
+
this.currentModeId = update.currentModeId;
|
|
183
|
+
}
|
|
184
|
+
// Every other update (`usage_update`, `config_option_update`,
|
|
185
|
+
// `session_info_update`, …) carries no transcript content; it still reaches
|
|
186
|
+
// the host through `onSessionUpdate`.
|
|
167
187
|
}
|
|
168
188
|
trackToolCall(update) {
|
|
169
189
|
if (!this.toolCalls.has(update.toolCallId)) {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session updates newer than the protocol library.
|
|
3
|
+
*
|
|
4
|
+
* The SDK validates every `session/update` notification against the variants
|
|
5
|
+
* it knows and answers any other with `-32602 Invalid params`, dropping it. An
|
|
6
|
+
* agent built on a newer protocol revision would then lose data and log an
|
|
7
|
+
* error for normal traffic. This filter sits on the agent's byte stream before
|
|
8
|
+
* the SDK: a `session/update` whose variant the SDK does not know is handed to
|
|
9
|
+
* the host as it is and kept from the SDK. Every other line passes through
|
|
10
|
+
* byte-identical.
|
|
11
|
+
*/
|
|
12
|
+
import type { AcpSessionNotification } from '@noetic-tools/types';
|
|
13
|
+
/**
|
|
14
|
+
* The notification when `line` is a `session/update` with a variant the SDK
|
|
15
|
+
* does not know; otherwise undefined.
|
|
16
|
+
*/
|
|
17
|
+
export declare function newerSessionUpdate(line: string): AcpSessionNotification | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* An agent's `elicitation/create` line with its JSON-RPC id copied into the
|
|
20
|
+
* params' `_meta`, or undefined for any other line. The SDK hands the client a
|
|
21
|
+
* request's params only; the id is what identifies the request across hosts,
|
|
22
|
+
* since a keeper asks a reattached host again with the agent's own id. Riding
|
|
23
|
+
* in the request itself, it cannot drift onto another request.
|
|
24
|
+
*/
|
|
25
|
+
export declare function tagElicitationRequest(line: string): string | undefined;
|
|
26
|
+
/** A request's params as the agent sent them, and the JSON-RPC id the stream tagged them with. */
|
|
27
|
+
export declare function untagElicitation<T extends {
|
|
28
|
+
_meta?: Record<string, unknown> | null;
|
|
29
|
+
}>(params: T): {
|
|
30
|
+
request: T;
|
|
31
|
+
requestId?: string | number;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Pass the agent's stream through, handing `deliver` each `session/update`
|
|
35
|
+
* the SDK would reject for its variant instead of passing it on, and tagging
|
|
36
|
+
* each `elicitation/create` with its JSON-RPC id.
|
|
37
|
+
*/
|
|
38
|
+
export declare function divertNewerUpdates(readable: ReadableStream<Uint8Array>, deliver: (notification: AcpSessionNotification) => void): ReadableStream<Uint8Array>;
|