@noetic-tools/acp 1.3.1 → 2.0.0-next.1

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.
Files changed (58) hide show
  1. package/dist/agents.d.ts +72 -8
  2. package/dist/agents.js +162 -58
  3. package/dist/bin.d.ts +19 -0
  4. package/dist/bin.js +99 -0
  5. package/dist/client.d.ts +14 -0
  6. package/dist/client.js +50 -0
  7. package/dist/connection.d.ts +3 -0
  8. package/dist/connection.js +26 -4
  9. package/dist/define.d.ts +21 -7
  10. package/dist/define.js +139 -15
  11. package/dist/index.d.ts +13 -3
  12. package/dist/index.js +10 -2
  13. package/dist/mcp/node.d.ts +24 -0
  14. package/dist/mcp/node.js +146 -0
  15. package/dist/mcp/server.d.ts +16 -0
  16. package/dist/mcp/server.js +104 -0
  17. package/dist/permission-channel.d.ts +2 -2
  18. package/dist/permission-channel.js +23 -12
  19. package/dist/permissions.d.ts +6 -0
  20. package/dist/permissions.js +7 -0
  21. package/dist/pi/extension.d.ts +31 -0
  22. package/dist/pi/extension.js +223 -0
  23. package/dist/pi/launch.d.ts +11 -0
  24. package/dist/pi/launch.js +35 -0
  25. package/dist/remote.d.ts +52 -0
  26. package/dist/remote.js +108 -0
  27. package/dist/runner/grants.d.ts +47 -0
  28. package/dist/runner/grants.js +127 -0
  29. package/dist/runner/host.d.ts +21 -0
  30. package/dist/runner/host.js +318 -0
  31. package/dist/runner/options.d.ts +21 -0
  32. package/dist/runner/options.js +82 -0
  33. package/dist/runner/protocol.d.ts +101 -0
  34. package/dist/runner/protocol.js +218 -0
  35. package/dist/runner/serve.d.ts +60 -0
  36. package/dist/runner/serve.js +285 -0
  37. package/dist/runner/ws-link.d.ts +6 -0
  38. package/dist/runner/ws-link.js +47 -0
  39. package/dist/serve-permissions.d.ts +8 -2
  40. package/dist/serve-permissions.js +26 -5
  41. package/dist/serve-types.d.ts +6 -5
  42. package/dist/server-env.d.ts +10 -0
  43. package/dist/server-env.js +47 -0
  44. package/dist/spawn.d.ts +12 -0
  45. package/dist/spawn.js +37 -0
  46. package/dist/stdio.d.ts +9 -1
  47. package/dist/stdio.js +97 -55
  48. package/dist/tool-bridge.d.ts +67 -0
  49. package/dist/tool-bridge.js +62 -0
  50. package/dist/tool-permissions.d.ts +46 -0
  51. package/dist/tool-permissions.js +70 -0
  52. package/dist/tool-wiring.d.ts +46 -0
  53. package/dist/tool-wiring.js +203 -0
  54. package/dist/transport-loopback.d.ts +8 -1
  55. package/dist/transport-loopback.js +22 -1
  56. package/dist/turn.d.ts +11 -5
  57. package/dist/turn.js +39 -16
  58. package/package.json +17 -4
@@ -0,0 +1,218 @@
1
+ /**
2
+ * The frames between a host and a remote runner (`noetic-acp serve`), carried
3
+ * as JSON over one WebSocket or one stdio pipe.
4
+ *
5
+ * The one channel carries everything a connection needs on the agent's
6
+ * machine: processes the host starts there (the agent, and MCP servers beside
7
+ * it), their stdio, and the tool bridge — HTTP requests the agent sends to a
8
+ * loopback port on its machine, answered by the host's bridge.
9
+ */
10
+ import { z } from 'zod';
11
+ //#region Frames
12
+ const Id = z.string().min(1);
13
+ const Bytes = z.string();
14
+ const Headers = z.array(z.tuple([
15
+ z.string(),
16
+ z.string(),
17
+ ]));
18
+ /** @public Host → runner. */
19
+ export const HostFrameSchema = z.discriminatedUnion('t', [
20
+ /** Open a loopback port that forwards to the host's bridge. */
21
+ z.object({
22
+ t: z.literal('reach'),
23
+ id: Id,
24
+ path: z.string().startsWith('/'),
25
+ }),
26
+ /**
27
+ * Start a process; its stdio becomes stream `id`. `launch` is the agent,
28
+ * `spawn` an MCP server beside it (`AcpMachine.launch` and `.spawn`).
29
+ */
30
+ z.object({
31
+ t: z.literal('start'),
32
+ id: Id,
33
+ kind: z.enum([
34
+ 'launch',
35
+ 'spawn',
36
+ ]),
37
+ command: z.string().min(1),
38
+ args: z.array(z.string()),
39
+ env: z.record(z.string(), z.string()),
40
+ cwd: z.string().optional(),
41
+ }),
42
+ z.object({
43
+ t: z.literal('stdin'),
44
+ id: Id,
45
+ data: Bytes,
46
+ }),
47
+ z.object({
48
+ t: z.literal('kill'),
49
+ id: Id,
50
+ }),
51
+ z.object({
52
+ t: z.literal('response'),
53
+ id: Id,
54
+ status: z.number().int(),
55
+ headers: Headers,
56
+ }),
57
+ z.object({
58
+ t: z.literal('body'),
59
+ id: Id,
60
+ data: Bytes,
61
+ }),
62
+ z.object({
63
+ t: z.literal('end'),
64
+ id: Id,
65
+ }),
66
+ ]);
67
+ /** @public Runner → host. */
68
+ export const RunnerFrameSchema = z.discriminatedUnion('t', [
69
+ z.object({
70
+ t: z.literal('reached'),
71
+ id: Id,
72
+ url: z.string().url(),
73
+ }),
74
+ z.object({
75
+ t: z.literal('started'),
76
+ id: Id,
77
+ }),
78
+ z.object({
79
+ t: z.literal('stdout'),
80
+ id: Id,
81
+ data: Bytes,
82
+ }),
83
+ z.object({
84
+ t: z.literal('exit'),
85
+ id: Id,
86
+ code: z.number().int().nullable(),
87
+ }),
88
+ /** A request or start the runner could not carry out. */
89
+ z.object({
90
+ t: z.literal('error'),
91
+ id: Id,
92
+ message: z.string(),
93
+ }),
94
+ /** An HTTP request the agent sent to a reached port. */
95
+ z.object({
96
+ t: z.literal('request'),
97
+ id: Id,
98
+ method: z.string(),
99
+ path: z.string(),
100
+ headers: Headers,
101
+ body: Bytes,
102
+ }),
103
+ /** The agent dropped a request before its response ended. */
104
+ z.object({
105
+ t: z.literal('abort'),
106
+ id: Id,
107
+ }),
108
+ ]);
109
+ /** Frames over a byte stream, one JSON object per line. */
110
+ export function lineFrameLink(readable, writable, close) {
111
+ const frameListeners = [];
112
+ const closeListeners = [];
113
+ const writer = writable.getWriter();
114
+ const encoder = new TextEncoder();
115
+ let closed = false;
116
+ const finish = (reason) => {
117
+ if (closed) {
118
+ return;
119
+ }
120
+ closed = true;
121
+ for (const listener of closeListeners) {
122
+ listener(reason);
123
+ }
124
+ };
125
+ void readLines(readable, (line) => {
126
+ const frame = parseLine(line);
127
+ if (frame === undefined) {
128
+ return;
129
+ }
130
+ for (const listener of frameListeners) {
131
+ listener(frame);
132
+ }
133
+ }).then(() => finish(), (e) => finish(e instanceof Error ? e : new Error(String(e))));
134
+ return {
135
+ send(frame) {
136
+ if (closed) {
137
+ return;
138
+ }
139
+ writer.write(encoder.encode(`${JSON.stringify(frame)}\n`)).catch(() => finish());
140
+ },
141
+ onFrame: (listener) => {
142
+ frameListeners.push(listener);
143
+ },
144
+ onClose: (listener) => {
145
+ closeListeners.push(listener);
146
+ },
147
+ async close() {
148
+ finish();
149
+ await writer.close().catch(() => undefined);
150
+ await close();
151
+ },
152
+ };
153
+ }
154
+ async function readLines(readable, onLine) {
155
+ const decoder = new TextDecoder();
156
+ let buffered = '';
157
+ for await (const chunk of chunksOf(readable)) {
158
+ buffered += decoder.decode(chunk, {
159
+ stream: true,
160
+ });
161
+ let newline = buffered.indexOf('\n');
162
+ while (newline >= 0) {
163
+ onLine(buffered.slice(0, newline));
164
+ buffered = buffered.slice(newline + 1);
165
+ newline = buffered.indexOf('\n');
166
+ }
167
+ }
168
+ }
169
+ /** The chunks of a byte stream, without relying on its async iterator. */
170
+ export async function* chunksOf(readable) {
171
+ const reader = readable.getReader();
172
+ try {
173
+ while (true) {
174
+ const { done, value } = await reader.read();
175
+ if (done) {
176
+ return;
177
+ }
178
+ yield value;
179
+ }
180
+ }
181
+ finally {
182
+ reader.releaseLock();
183
+ }
184
+ }
185
+ function parseLine(line) {
186
+ if (line.trim() === '') {
187
+ return undefined;
188
+ }
189
+ try {
190
+ return JSON.parse(line);
191
+ }
192
+ catch {
193
+ return undefined;
194
+ }
195
+ }
196
+ //#endregion
197
+ //#region Bytes
198
+ export function toBase64(bytes) {
199
+ let binary = '';
200
+ for (const byte of bytes) {
201
+ binary += String.fromCharCode(byte);
202
+ }
203
+ return btoa(binary);
204
+ }
205
+ export function fromBase64(text) {
206
+ const binary = atob(text);
207
+ const bytes = new Uint8Array(binary.length);
208
+ for (let i = 0; i < binary.length; i++) {
209
+ bytes[i] = binary.charCodeAt(i);
210
+ }
211
+ return bytes;
212
+ }
213
+ /** Hosts that never leave the machine, so a hop to them needs no TLS. */
214
+ export function isLoopbackHost(hostname) {
215
+ const host = hostname.replace(/^\[|\]$/g, '');
216
+ return host === 'localhost' || host === '::1' || /^127\./.test(host);
217
+ }
218
+ //#endregion
@@ -0,0 +1,60 @@
1
+ /**
2
+ * The remote runner: started on the agent's machine, it runs what a host asks
3
+ * for over one channel — the agent with its launch settings, MCP servers
4
+ * beside it — and serves the host's tool bridge to them on a loopback port.
5
+ *
6
+ * Every channel is one session: when it closes, everything it started stops.
7
+ * Over WebSocket each upgrade must carry the runner's bearer token, and a
8
+ * listener off the loopback interface must use TLS.
9
+ */
10
+ import type { AcpRunnerGrant } from './grants.js';
11
+ import type { FrameLink } from './protocol.js';
12
+ /** @public Options for {@link serveAcpRunner}. */
13
+ export interface AcpRunnerOptions {
14
+ /**
15
+ * Only these commands may be started, compared by executable and
16
+ * arguments, each with only its own environment names, in a working
17
+ * directory inside `cwd`.
18
+ */
19
+ allow?: ReadonlyArray<AcpRunnerGrant>;
20
+ /** Working directory for a start that names none. */
21
+ cwd?: string;
22
+ }
23
+ /** @public Options for {@link listenAcpRunner}. */
24
+ export interface AcpRunnerListenOptions extends AcpRunnerOptions {
25
+ host?: string;
26
+ port?: number;
27
+ /** Every WebSocket upgrade must send `Authorization: Bearer <token>`. */
28
+ token: string;
29
+ /** PEM certificate and key. Required off the loopback interface. */
30
+ tls?: {
31
+ cert: string;
32
+ key: string;
33
+ };
34
+ }
35
+ /** @public A listening runner. */
36
+ export interface AcpRunnerListener {
37
+ /** `ws://` or `wss://` URL hosts connect to. */
38
+ readonly url: string;
39
+ close(): Promise<void>;
40
+ }
41
+ /**
42
+ * Serve one host over `link` until it closes.
43
+ * @public
44
+ */
45
+ export declare function serveAcpRunner(link: FrameLink, options?: AcpRunnerOptions): Promise<void>;
46
+ /**
47
+ * Serve one host over this process's stdin and stdout — for a runner started
48
+ * by `ssh` or `docker exec`, whose own channel is already private.
49
+ * @public
50
+ */
51
+ export declare function serveAcpRunnerOverStdio(options?: AcpRunnerOptions): Promise<void>;
52
+ /**
53
+ * Listen for hosts over WebSocket. Each connection is its own session.
54
+ * @public
55
+ */
56
+ export declare function listenAcpRunner(options: AcpRunnerListenOptions): Promise<AcpRunnerListener>;
57
+ /** A token for a runner started without one. */
58
+ export declare function newRunnerToken(): string;
59
+ /** Read a PEM file for {@link AcpRunnerListenOptions.tls}. */
60
+ export declare function readPem(path: string): string;
@@ -0,0 +1,285 @@
1
+ /**
2
+ * The remote runner: started on the agent's machine, it runs what a host asks
3
+ * for over one channel — the agent with its launch settings, MCP servers
4
+ * beside it — and serves the host's tool bridge to them on a loopback port.
5
+ *
6
+ * Every channel is one session: when it closes, everything it started stops.
7
+ * Over WebSocket each upgrade must carry the runner's bearer token, and a
8
+ * listener off the loopback interface must use TLS.
9
+ */
10
+ import { spawn } from 'node:child_process';
11
+ import { randomUUID, timingSafeEqual } from 'node:crypto';
12
+ import { readFileSync } from 'node:fs';
13
+ import { createServer } from 'node:http';
14
+ import * as https from 'node:https';
15
+ import { Readable, Writable } from 'node:stream';
16
+ import { frameworkCast } from '@noetic-tools/types';
17
+ import { WebSocketServer } from 'ws';
18
+ import { serverEnv } from '../server-env.js';
19
+ import { checkStart } from './grants.js';
20
+ import { fromBase64, HostFrameSchema, isLoopbackHost, lineFrameLink, toBase64 } from './protocol.js';
21
+ import { webSocketFrameLink } from './ws-link.js';
22
+ //#endregion
23
+ //#region Public API
24
+ /**
25
+ * Serve one host over `link` until it closes.
26
+ * @public
27
+ */
28
+ export function serveAcpRunner(link, options = {}) {
29
+ const session = {
30
+ link,
31
+ options,
32
+ children: new Map(),
33
+ ports: [],
34
+ responses: new Map(),
35
+ next: 0,
36
+ };
37
+ return new Promise((resolve) => {
38
+ link.onFrame((raw) => {
39
+ void receive(session, raw);
40
+ });
41
+ link.onClose(() => {
42
+ release(session);
43
+ resolve();
44
+ });
45
+ });
46
+ }
47
+ /**
48
+ * Serve one host over this process's stdin and stdout — for a runner started
49
+ * by `ssh` or `docker exec`, whose own channel is already private.
50
+ * @public
51
+ */
52
+ export function serveAcpRunnerOverStdio(options = {}) {
53
+ return serveAcpRunner(lineFrameLink(frameworkCast(Readable.toWeb(process.stdin)), frameworkCast(Writable.toWeb(process.stdout)), async () => undefined), options);
54
+ }
55
+ /**
56
+ * Listen for hosts over WebSocket. Each connection is its own session.
57
+ * @public
58
+ */
59
+ export async function listenAcpRunner(options) {
60
+ const host = options.host ?? '127.0.0.1';
61
+ if (!options.tls && !isLoopbackHost(host)) {
62
+ throw new TypeError(`A runner listening on ${host} must use TLS: pass a certificate and key, or listen on 127.0.0.1.`);
63
+ }
64
+ if (options.token.length < 16) {
65
+ throw new TypeError('The runner token must be at least 16 characters.');
66
+ }
67
+ const server = options.tls
68
+ ? https.createServer({
69
+ cert: options.tls.cert,
70
+ key: options.tls.key,
71
+ })
72
+ : createServer();
73
+ const sockets = new WebSocketServer({
74
+ server,
75
+ verifyClient: (info) => sameSecret(info.req.headers.authorization, `Bearer ${options.token}`),
76
+ });
77
+ sockets.on('connection', (socket) => {
78
+ void serveAcpRunner(webSocketFrameLink(socket), options);
79
+ });
80
+ await new Promise((resolve, reject) => {
81
+ server.once('error', reject);
82
+ server.listen(options.port ?? 0, host, () => {
83
+ server.off('error', reject);
84
+ resolve();
85
+ });
86
+ });
87
+ const address = server.address();
88
+ if (address === null || typeof address === 'string') {
89
+ throw new Error('The runner did not bind a TCP port.');
90
+ }
91
+ const shown = host.includes(':') ? `[${host}]` : host;
92
+ return {
93
+ url: `${options.tls ? 'wss' : 'ws'}://${shown}:${address.port}`,
94
+ async close() {
95
+ for (const client of sockets.clients) {
96
+ client.terminate();
97
+ }
98
+ sockets.close();
99
+ // Under Bun a socket upgraded moments ago can hold the server's close
100
+ // callback back for good, so the wait is bounded.
101
+ await new Promise((resolve) => {
102
+ server.close(() => resolve());
103
+ server.closeAllConnections();
104
+ setTimeout(resolve, 1e3).unref();
105
+ });
106
+ },
107
+ };
108
+ }
109
+ //#endregion
110
+ //#region Handlers
111
+ const handlers = {
112
+ reach: openPort,
113
+ start: startProcess,
114
+ stdin: (session, frame) => {
115
+ session.children.get(frame.id)?.stdin?.write(fromBase64(frame.data));
116
+ },
117
+ kill: (session, frame) => {
118
+ session.children.get(frame.id)?.kill();
119
+ },
120
+ response: (session, frame) => {
121
+ const res = session.responses.get(frame.id);
122
+ if (!res || res.headersSent) {
123
+ return;
124
+ }
125
+ res.writeHead(frame.status, frame.headers.flat());
126
+ },
127
+ body: (session, frame) => {
128
+ session.responses.get(frame.id)?.write(fromBase64(frame.data));
129
+ },
130
+ end: (session, frame) => {
131
+ session.responses.get(frame.id)?.end();
132
+ session.responses.delete(frame.id);
133
+ },
134
+ };
135
+ async function receive(session, raw) {
136
+ const parsed = HostFrameSchema.safeParse(raw);
137
+ if (!parsed.success) {
138
+ return;
139
+ }
140
+ const frame = parsed.data;
141
+ const handler = frameworkCast(handlers[frame.t]);
142
+ try {
143
+ await handler(session, frame);
144
+ }
145
+ catch (e) {
146
+ session.link.send({
147
+ t: 'error',
148
+ id: frame.id,
149
+ message: e instanceof Error ? e.message : String(e),
150
+ });
151
+ }
152
+ }
153
+ /**
154
+ * A loopback port on this machine whose requests the host answers from its
155
+ * bridge. The host's bridge checks the token, host, and origin itself.
156
+ */
157
+ async function openPort(session, frame) {
158
+ const server = createServer((req, res) => {
159
+ void relay(session, req, res);
160
+ });
161
+ session.ports.push(server);
162
+ await new Promise((resolve, reject) => {
163
+ server.once('error', reject);
164
+ server.listen(0, '127.0.0.1', () => {
165
+ server.off('error', reject);
166
+ resolve();
167
+ });
168
+ });
169
+ const address = server.address();
170
+ if (address === null || typeof address === 'string') {
171
+ throw new Error('The bridge port did not bind.');
172
+ }
173
+ session.link.send({
174
+ t: 'reached',
175
+ id: frame.id,
176
+ url: `http://127.0.0.1:${address.port}${frame.path}`,
177
+ });
178
+ }
179
+ async function relay(session, req, res) {
180
+ session.next += 1;
181
+ const id = `r${session.next}`;
182
+ const chunks = [];
183
+ for await (const chunk of req) {
184
+ chunks.push(Buffer.from(chunk));
185
+ }
186
+ session.responses.set(id, res);
187
+ res.on('close', () => {
188
+ if (session.responses.delete(id)) {
189
+ session.link.send({
190
+ t: 'abort',
191
+ id,
192
+ });
193
+ }
194
+ });
195
+ const headers = [];
196
+ for (let i = 0; i < req.rawHeaders.length; i += 2) {
197
+ headers.push([
198
+ req.rawHeaders[i] ?? '',
199
+ req.rawHeaders[i + 1] ?? '',
200
+ ]);
201
+ }
202
+ session.link.send({
203
+ t: 'request',
204
+ id,
205
+ method: req.method ?? 'GET',
206
+ path: req.url ?? '/',
207
+ headers,
208
+ body: toBase64(Buffer.concat(chunks)),
209
+ });
210
+ }
211
+ async function startProcess(session, frame) {
212
+ const checked = checkStart(frame, session.options);
213
+ // An MCP server gets what the MCP SDK would give it here, the agent all of the runner's.
214
+ const env = frame.kind === 'spawn'
215
+ ? serverEnv(checked.env)
216
+ : {
217
+ ...process.env,
218
+ ...checked.env,
219
+ };
220
+ const child = spawn(frame.command, frame.args, {
221
+ cwd: checked.cwd,
222
+ env,
223
+ stdio: [
224
+ 'pipe',
225
+ 'pipe',
226
+ 'inherit',
227
+ ],
228
+ });
229
+ await new Promise((resolve, reject) => {
230
+ child.once('spawn', resolve);
231
+ child.once('error', reject);
232
+ });
233
+ session.children.set(frame.id, child);
234
+ // A write after the process exits must not take the runner down with it.
235
+ child.stdin?.on('error', () => undefined);
236
+ child.stdout?.on('data', (chunk) => {
237
+ session.link.send({
238
+ t: 'stdout',
239
+ id: frame.id,
240
+ data: toBase64(chunk),
241
+ });
242
+ });
243
+ child.once('exit', (code) => {
244
+ session.children.delete(frame.id);
245
+ session.link.send({
246
+ t: 'exit',
247
+ id: frame.id,
248
+ code,
249
+ });
250
+ });
251
+ session.link.send({
252
+ t: 'started',
253
+ id: frame.id,
254
+ });
255
+ }
256
+ //#endregion
257
+ //#region Helpers
258
+ function release(session) {
259
+ for (const child of session.children.values()) {
260
+ child.kill();
261
+ }
262
+ session.children.clear();
263
+ for (const server of session.ports) {
264
+ server.close();
265
+ server.closeAllConnections();
266
+ }
267
+ for (const res of session.responses.values()) {
268
+ res.destroy();
269
+ }
270
+ session.responses.clear();
271
+ }
272
+ function sameSecret(given, expected) {
273
+ const a = Buffer.from(given ?? '');
274
+ const b = Buffer.from(expected);
275
+ return a.length === b.length && timingSafeEqual(a, b);
276
+ }
277
+ /** A token for a runner started without one. */
278
+ export function newRunnerToken() {
279
+ return randomUUID();
280
+ }
281
+ /** Read a PEM file for {@link AcpRunnerListenOptions.tls}. */
282
+ export function readPem(path) {
283
+ return readFileSync(path, 'utf8');
284
+ }
285
+ //#endregion
@@ -0,0 +1,6 @@
1
+ /**
2
+ * A {@link FrameLink} over a `ws` WebSocket, one JSON frame per text message.
3
+ */
4
+ import type { WebSocket } from 'ws';
5
+ import type { FrameLink } from './protocol.js';
6
+ export declare function webSocketFrameLink(socket: WebSocket): FrameLink;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * A {@link FrameLink} over a `ws` WebSocket, one JSON frame per text message.
3
+ */
4
+ export function webSocketFrameLink(socket) {
5
+ const closeListeners = [];
6
+ let failure;
7
+ socket.on('error', (error) => {
8
+ failure = error;
9
+ });
10
+ socket.on('close', () => {
11
+ for (const listener of closeListeners) {
12
+ listener(failure);
13
+ }
14
+ });
15
+ return {
16
+ send(frame) {
17
+ if (socket.readyState === socket.OPEN) {
18
+ socket.send(JSON.stringify(frame));
19
+ }
20
+ },
21
+ onFrame(listener) {
22
+ socket.on('message', (data, isBinary) => {
23
+ if (isBinary) {
24
+ return;
25
+ }
26
+ try {
27
+ listener(JSON.parse(data.toString()));
28
+ }
29
+ catch {
30
+ // Not a frame.
31
+ }
32
+ });
33
+ },
34
+ onClose(listener) {
35
+ closeListeners.push(listener);
36
+ },
37
+ async close() {
38
+ if (socket.readyState === socket.CLOSED) {
39
+ return;
40
+ }
41
+ await new Promise((resolve) => {
42
+ socket.once('close', () => resolve());
43
+ socket.close();
44
+ });
45
+ },
46
+ };
47
+ }
@@ -21,6 +21,10 @@ export declare function evaluateServePolicy(params: {
21
21
  toolName: string;
22
22
  kind?: AcpToolKind;
23
23
  }): AcpServePermissionDecision;
24
+ /** A reply, and whether it is the broker's own because nobody answered in time. */
25
+ interface AskOutcome extends AcpServePermissionReply {
26
+ timedOut?: boolean;
27
+ }
24
28
  /**
25
29
  * Holds `ask` parks and routes each to its answerer. The layer registers the
26
30
  * park *before* invoking `forward`, so an answer racing back in the same tick
@@ -31,9 +35,10 @@ export declare class ServePermissionBroker {
31
35
  private readonly forward;
32
36
  private readonly pending;
33
37
  constructor(forward: (prompt: AcpServePermissionPrompt) => Promise<AcpServePermissionReply>);
34
- ask(prompt: AcpServePermissionPrompt, timeoutMs: number): Promise<AcpServePermissionReply>;
38
+ /** Ask the client. With no `timeoutMs` the ask waits for an answer or a session cancel. */
39
+ ask(prompt: AcpServePermissionPrompt, timeoutMs?: number): Promise<AskOutcome>;
35
40
  /** Resolve one park; later answers to the same request are dropped. */
36
- answer(requestId: string, reply: AcpServePermissionReply): void;
41
+ answer(requestId: string, reply: AskOutcome): void;
37
42
  /** Unwind every park belonging to a session — the `session/cancel` path. */
38
43
  cancelSession(sessionId: string): void;
39
44
  }
@@ -53,3 +58,4 @@ export declare function createServePermissionLayer(params: {
53
58
  broker: ServePermissionBroker;
54
59
  presentation: ServeToolPresentation;
55
60
  }): ContextLayer;
61
+ export {};