@autonome-research/thread-phase-agents 3.0.0
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/LICENSE +21 -0
- package/README.md +207 -0
- package/dist/acp/adapter.d.ts +89 -0
- package/dist/acp/adapter.d.ts.map +1 -0
- package/dist/acp/adapter.js +461 -0
- package/dist/acp/adapter.js.map +1 -0
- package/dist/acp/index.d.ts +12 -0
- package/dist/acp/index.d.ts.map +1 -0
- package/dist/acp/index.js +10 -0
- package/dist/acp/index.js.map +1 -0
- package/dist/acp/transport.d.ts +82 -0
- package/dist/acp/transport.d.ts.map +1 -0
- package/dist/acp/transport.js +199 -0
- package/dist/acp/transport.js.map +1 -0
- package/dist/acp/types.d.ts +157 -0
- package/dist/acp/types.d.ts.map +1 -0
- package/dist/acp/types.js +34 -0
- package/dist/acp/types.js.map +1 -0
- package/dist/anthropic/adapter.d.ts +55 -0
- package/dist/anthropic/adapter.d.ts.map +1 -0
- package/dist/anthropic/adapter.js +259 -0
- package/dist/anthropic/adapter.js.map +1 -0
- package/dist/anthropic/index.d.ts +8 -0
- package/dist/anthropic/index.d.ts.map +1 -0
- package/dist/anthropic/index.js +8 -0
- package/dist/anthropic/index.js.map +1 -0
- package/dist/claude-code/adapter.d.ts +56 -0
- package/dist/claude-code/adapter.d.ts.map +1 -0
- package/dist/claude-code/adapter.js +319 -0
- package/dist/claude-code/adapter.js.map +1 -0
- package/dist/claude-code/index.d.ts +8 -0
- package/dist/claude-code/index.d.ts.map +1 -0
- package/dist/claude-code/index.js +8 -0
- package/dist/claude-code/index.js.map +1 -0
- package/dist/codex/adapter.d.ts +62 -0
- package/dist/codex/adapter.d.ts.map +1 -0
- package/dist/codex/adapter.js +258 -0
- package/dist/codex/adapter.js.map +1 -0
- package/dist/codex/index.d.ts +9 -0
- package/dist/codex/index.d.ts.map +1 -0
- package/dist/codex/index.js +9 -0
- package/dist/codex/index.js.map +1 -0
- package/dist/codex-cli/adapter.d.ts +70 -0
- package/dist/codex-cli/adapter.d.ts.map +1 -0
- package/dist/codex-cli/adapter.js +368 -0
- package/dist/codex-cli/adapter.js.map +1 -0
- package/dist/codex-cli/index.d.ts +10 -0
- package/dist/codex-cli/index.d.ts.map +1 -0
- package/dist/codex-cli/index.js +10 -0
- package/dist/codex-cli/index.js.map +1 -0
- package/dist/hermes/index.d.ts +50 -0
- package/dist/hermes/index.d.ts.map +1 -0
- package/dist/hermes/index.js +43 -0
- package/dist/hermes/index.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/injectors.d.ts +104 -0
- package/dist/injectors.d.ts.map +1 -0
- package/dist/injectors.js +219 -0
- package/dist/injectors.js.map +1 -0
- package/dist/openclaw/index.d.ts +54 -0
- package/dist/openclaw/index.d.ts.map +1 -0
- package/dist/openclaw/index.js +61 -0
- package/dist/openclaw/index.js.map +1 -0
- package/dist/pi/adapter.d.ts +79 -0
- package/dist/pi/adapter.d.ts.map +1 -0
- package/dist/pi/adapter.js +396 -0
- package/dist/pi/adapter.js.map +1 -0
- package/dist/pi/index.d.ts +14 -0
- package/dist/pi/index.d.ts.map +1 -0
- package/dist/pi/index.js +14 -0
- package/dist/pi/index.js.map +1 -0
- package/dist/thread-bridge.d.ts +83 -0
- package/dist/thread-bridge.d.ts.map +1 -0
- package/dist/thread-bridge.js +143 -0
- package/dist/thread-bridge.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP chassis — `AgentAdapter` that consumes any ACP-speaking subprocess.
|
|
3
|
+
*
|
|
4
|
+
* Lifecycle: spawn → initialize → session/new (or session/load on resume)
|
|
5
|
+
* → session/prompt → stream session/update notifications → await
|
|
6
|
+
* stopReason → emit agent_end → dispose.
|
|
7
|
+
*
|
|
8
|
+
* Translation table:
|
|
9
|
+
* session/update { sessionUpdate: 'agent_message_chunk' } → text event
|
|
10
|
+
* session/update { sessionUpdate: 'agent_thought_chunk' } → thinking event
|
|
11
|
+
* session/update { sessionUpdate: 'tool_call' } → tool_call event
|
|
12
|
+
* session/update { sessionUpdate: 'tool_call_update', status: 'completed' }
|
|
13
|
+
* → tool_result event
|
|
14
|
+
* everything else → native event
|
|
15
|
+
*
|
|
16
|
+
* Cancellation: forceful. abort() sends session/cancel as a notification,
|
|
17
|
+
* then SIGTERM after a short grace window, then SIGKILL. Subprocess
|
|
18
|
+
* cleanup is unconditional on result resolution.
|
|
19
|
+
*
|
|
20
|
+
* Resumption: 'opaque' — the ACP session id is wrapped in a
|
|
21
|
+
* `ResumeToken{ kind: 'opaque', data: sessionId }` and emitted on
|
|
22
|
+
* agent_start (when input resume) and agent_end (always).
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
import { spawn } from 'node:child_process';
|
|
27
|
+
import { composeAbort, createEventQueue, defineAgentAdapter, lazyEvents, serializeError, TurnAccumulator, } from '@autonome-research/thread-phase/agents';
|
|
28
|
+
import { ACP_METHODS, ACP_PROTOCOL_VERSION, contentBlockToText, } from './types.js';
|
|
29
|
+
import { createAcpTransport, JsonRpcCallError } from './transport.js';
|
|
30
|
+
/**
|
|
31
|
+
* Build an ACP-speaking adapter with the given id. The chassis itself
|
|
32
|
+
* is exported as `acpAgent` (id 'acp'); wrappers like `hermesAgent` and
|
|
33
|
+
* `openClawAgent` are produced by calling this with their own id.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export function createAcpAdapter(opts = {}) {
|
|
38
|
+
const id = opts.id ?? 'acp';
|
|
39
|
+
return defineAgentAdapter({
|
|
40
|
+
id,
|
|
41
|
+
capabilities: {
|
|
42
|
+
streaming: 'text',
|
|
43
|
+
cancellation: 'forceful',
|
|
44
|
+
resumption: 'opaque',
|
|
45
|
+
structuredOutput: 'prompted',
|
|
46
|
+
},
|
|
47
|
+
adapter: (config, options) => makeAcpRun(id, config, options ?? {}),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/** The unparameterized chassis adapter. @internal */
|
|
51
|
+
export const acpAgent = createAcpAdapter({ id: 'acp' });
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
// run construction
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
function makeAcpRun(source, config, options) {
|
|
56
|
+
const traceId = options.traceId;
|
|
57
|
+
const cancelGraceMs = config.cancelGraceMs ?? 2000;
|
|
58
|
+
const killGraceMs = config.killGraceMs ?? 3000;
|
|
59
|
+
const { signal: compositeSignal, controller } = composeAbort(options.signal);
|
|
60
|
+
const queue = createEventQueue(options.eventBus);
|
|
61
|
+
const pushEvent = queue.push;
|
|
62
|
+
const closeStream = queue.close;
|
|
63
|
+
const turns = new TurnAccumulator(pushEvent, source, traceId);
|
|
64
|
+
// Follow-up queue: messages to send as additional session/prompt requests
|
|
65
|
+
// after the current prompt completes. Synchronously drained between turns
|
|
66
|
+
// (the loop checks for new messages each iteration; no callback timing).
|
|
67
|
+
const followUpQueue = [];
|
|
68
|
+
let hasEnded = false;
|
|
69
|
+
// Lazy start.
|
|
70
|
+
let started = false;
|
|
71
|
+
let runPromise = null;
|
|
72
|
+
const startIfNeeded = () => {
|
|
73
|
+
if (runPromise)
|
|
74
|
+
return runPromise;
|
|
75
|
+
started = true;
|
|
76
|
+
runPromise = runOnce();
|
|
77
|
+
return runPromise;
|
|
78
|
+
};
|
|
79
|
+
async function runOnce() {
|
|
80
|
+
let resumeToken = config.resumeSessionId
|
|
81
|
+
? { kind: 'opaque', data: config.resumeSessionId }
|
|
82
|
+
: undefined;
|
|
83
|
+
pushEvent({ type: 'agent_start', source, traceId, resumeToken });
|
|
84
|
+
let child = null;
|
|
85
|
+
let transport = null;
|
|
86
|
+
let stderrBuf = '';
|
|
87
|
+
const collectedText = [];
|
|
88
|
+
let activeSessionId;
|
|
89
|
+
const cleanup = async () => {
|
|
90
|
+
transport?.dispose();
|
|
91
|
+
if (child && child.exitCode === null && child.signalCode === null) {
|
|
92
|
+
try {
|
|
93
|
+
child.kill('SIGTERM');
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
// already gone
|
|
97
|
+
}
|
|
98
|
+
await waitForExit(child, killGraceMs).catch(() => {
|
|
99
|
+
try {
|
|
100
|
+
child.kill('SIGKILL');
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// already gone
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const fail = async (err, reason) => {
|
|
109
|
+
turns.close();
|
|
110
|
+
pushEvent({
|
|
111
|
+
type: 'error',
|
|
112
|
+
source,
|
|
113
|
+
traceId,
|
|
114
|
+
error: serializeError(err),
|
|
115
|
+
transient: false,
|
|
116
|
+
});
|
|
117
|
+
pushEvent({ type: 'agent_end', source, traceId, reason, resumeToken });
|
|
118
|
+
closeStream();
|
|
119
|
+
hasEnded = true;
|
|
120
|
+
await cleanup();
|
|
121
|
+
return {
|
|
122
|
+
text: collectedText.join(''),
|
|
123
|
+
finishReason: reason,
|
|
124
|
+
usage: { promptTokens: 0, completionTokens: 0, totalTokens: 0 },
|
|
125
|
+
executedToolCalls: [],
|
|
126
|
+
resumeToken,
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
try {
|
|
130
|
+
// 1. Spawn subprocess.
|
|
131
|
+
child = spawnAgent(config);
|
|
132
|
+
child.on('error', (err) => {
|
|
133
|
+
pushEvent({
|
|
134
|
+
type: 'error',
|
|
135
|
+
source,
|
|
136
|
+
traceId,
|
|
137
|
+
error: serializeError(err),
|
|
138
|
+
transient: false,
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
child.stderr.setEncoding('utf8');
|
|
142
|
+
child.stderr.on('data', (chunk) => {
|
|
143
|
+
stderrBuf += chunk;
|
|
144
|
+
// Cap to avoid unbounded growth on noisy agents.
|
|
145
|
+
if (stderrBuf.length > 16_384) {
|
|
146
|
+
stderrBuf = stderrBuf.slice(-16_384);
|
|
147
|
+
}
|
|
148
|
+
pushEvent({
|
|
149
|
+
type: 'native',
|
|
150
|
+
source,
|
|
151
|
+
traceId,
|
|
152
|
+
kind: 'acp:stderr',
|
|
153
|
+
payload: chunk,
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
// 2. Build transport.
|
|
157
|
+
transport = createAcpTransport({
|
|
158
|
+
child,
|
|
159
|
+
onNotification: (method, params) => {
|
|
160
|
+
if (method === ACP_METHODS.sessionUpdate) {
|
|
161
|
+
handleSessionUpdate(params);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
pushEvent({
|
|
165
|
+
type: 'native',
|
|
166
|
+
source,
|
|
167
|
+
traceId,
|
|
168
|
+
kind: `acp:notification:${method}`,
|
|
169
|
+
payload: params,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
onRequest: async (method, params) => {
|
|
174
|
+
if (method === ACP_METHODS.requestPermission) {
|
|
175
|
+
pushEvent({
|
|
176
|
+
type: 'native',
|
|
177
|
+
source,
|
|
178
|
+
traceId,
|
|
179
|
+
kind: 'acp:request_permission',
|
|
180
|
+
payload: params,
|
|
181
|
+
});
|
|
182
|
+
// v1: respond per permissionMode. Real shape per the ACP spec
|
|
183
|
+
// varies by agent; we return a best-effort approval/rejection
|
|
184
|
+
// shape. Adapters that need finer control can wrap this
|
|
185
|
+
// chassis with their own onRequest before we land it as a
|
|
186
|
+
// first-class option.
|
|
187
|
+
return config.permissionMode === 'allow'
|
|
188
|
+
? { outcome: { outcome: 'selected', optionId: 'allow' } }
|
|
189
|
+
: { outcome: { outcome: 'cancelled' } };
|
|
190
|
+
}
|
|
191
|
+
pushEvent({
|
|
192
|
+
type: 'native',
|
|
193
|
+
source,
|
|
194
|
+
traceId,
|
|
195
|
+
kind: `acp:request:${method}`,
|
|
196
|
+
payload: params,
|
|
197
|
+
});
|
|
198
|
+
throw new Error(`unsupported ACP request: ${method}`);
|
|
199
|
+
},
|
|
200
|
+
onTransportError: (err) => {
|
|
201
|
+
pushEvent({
|
|
202
|
+
type: 'error',
|
|
203
|
+
source,
|
|
204
|
+
traceId,
|
|
205
|
+
error: serializeError(err),
|
|
206
|
+
transient: true,
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
// 3. Initialize handshake.
|
|
211
|
+
const initReq = {
|
|
212
|
+
protocolVersion: ACP_PROTOCOL_VERSION,
|
|
213
|
+
clientInfo: config.clientInfo,
|
|
214
|
+
clientCapabilities: config.clientCapabilities,
|
|
215
|
+
};
|
|
216
|
+
const initRes = await transport.request(ACP_METHODS.initialize, initReq);
|
|
217
|
+
pushEvent({
|
|
218
|
+
type: 'native',
|
|
219
|
+
source,
|
|
220
|
+
traceId,
|
|
221
|
+
kind: 'acp:initialized',
|
|
222
|
+
payload: initRes,
|
|
223
|
+
});
|
|
224
|
+
if (compositeSignal.aborted) {
|
|
225
|
+
return await fail(new Error('aborted before session creation'), 'aborted');
|
|
226
|
+
}
|
|
227
|
+
// 4. Session creation or resumption.
|
|
228
|
+
const mcpServers = config.mcpServers ?? [];
|
|
229
|
+
if (config.resumeSessionId) {
|
|
230
|
+
if (initRes.agentCapabilities?.loadSession !== true) {
|
|
231
|
+
throw new Error('agent does not declare loadSession capability; cannot resume');
|
|
232
|
+
}
|
|
233
|
+
const loadReq = {
|
|
234
|
+
sessionId: config.resumeSessionId,
|
|
235
|
+
cwd: config.cwd,
|
|
236
|
+
mcpServers,
|
|
237
|
+
};
|
|
238
|
+
await transport.request(ACP_METHODS.loadSession, loadReq);
|
|
239
|
+
activeSessionId = config.resumeSessionId;
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
const newReq = {
|
|
243
|
+
cwd: config.cwd,
|
|
244
|
+
mcpServers,
|
|
245
|
+
};
|
|
246
|
+
const newRes = await transport.request(ACP_METHODS.newSession, newReq);
|
|
247
|
+
activeSessionId = newRes.sessionId;
|
|
248
|
+
}
|
|
249
|
+
resumeToken = { kind: 'opaque', data: activeSessionId };
|
|
250
|
+
if (compositeSignal.aborted) {
|
|
251
|
+
return await fail(new Error('aborted before prompt'), 'aborted');
|
|
252
|
+
}
|
|
253
|
+
// 5. Wire cancel — send session/cancel when the composite aborts.
|
|
254
|
+
let cancelSent = false;
|
|
255
|
+
const sendCancel = () => {
|
|
256
|
+
if (cancelSent || !activeSessionId || !transport)
|
|
257
|
+
return;
|
|
258
|
+
cancelSent = true;
|
|
259
|
+
const params = { sessionId: activeSessionId };
|
|
260
|
+
try {
|
|
261
|
+
transport.notify(ACP_METHODS.cancel, params);
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
// transport may already be down; cleanup handles it
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
if (compositeSignal.aborted) {
|
|
268
|
+
sendCancel();
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
compositeSignal.addEventListener('abort', sendCancel, { once: true });
|
|
272
|
+
}
|
|
273
|
+
// 6. Prompt loop. The first iteration uses config.prompt; subsequent
|
|
274
|
+
// iterations drain followUpQueue (populated by SteerableAgentRun.followUp).
|
|
275
|
+
// Loop exits when the queue is empty after a response, or on abort/error.
|
|
276
|
+
let firstIteration = true;
|
|
277
|
+
let lastFinishReason = 'unknown';
|
|
278
|
+
while (true) {
|
|
279
|
+
let currentPrompt;
|
|
280
|
+
if (firstIteration) {
|
|
281
|
+
currentPrompt = config.prompt;
|
|
282
|
+
firstIteration = false;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
currentPrompt = followUpQueue.shift();
|
|
286
|
+
}
|
|
287
|
+
if (currentPrompt === undefined)
|
|
288
|
+
break;
|
|
289
|
+
const promptBlocks = Array.isArray(currentPrompt)
|
|
290
|
+
? currentPrompt
|
|
291
|
+
: [{ type: 'text', text: currentPrompt }];
|
|
292
|
+
const promptReq = {
|
|
293
|
+
sessionId: activeSessionId,
|
|
294
|
+
prompt: promptBlocks,
|
|
295
|
+
};
|
|
296
|
+
let promptRes;
|
|
297
|
+
try {
|
|
298
|
+
promptRes = await transport.request(ACP_METHODS.prompt, promptReq);
|
|
299
|
+
}
|
|
300
|
+
catch (err) {
|
|
301
|
+
const aborted = compositeSignal.aborted || cancelSent;
|
|
302
|
+
return await fail(err, aborted ? 'aborted' : 'error');
|
|
303
|
+
}
|
|
304
|
+
// Emit canonical turn_end for this prompt cycle. Natural ordering:
|
|
305
|
+
// text + tool_call events already arrived during the response, so
|
|
306
|
+
// endTurn() emits a turn_end with the accumulated counts immediately.
|
|
307
|
+
turns.endTurn();
|
|
308
|
+
lastFinishReason = mapStopReason(promptRes.stopReason, compositeSignal.aborted);
|
|
309
|
+
if (lastFinishReason === 'aborted')
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
// 7. Synthesize result. resumeToken at this point points at the
|
|
313
|
+
// (potentially updated) session id.
|
|
314
|
+
turns.close();
|
|
315
|
+
pushEvent({ type: 'agent_end', source, traceId, reason: lastFinishReason, resumeToken });
|
|
316
|
+
closeStream();
|
|
317
|
+
hasEnded = true;
|
|
318
|
+
await cleanup();
|
|
319
|
+
return {
|
|
320
|
+
text: collectedText.join(''),
|
|
321
|
+
finishReason: lastFinishReason,
|
|
322
|
+
usage: { promptTokens: 0, completionTokens: 0, totalTokens: 0 },
|
|
323
|
+
executedToolCalls: [],
|
|
324
|
+
resumeToken,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
catch (err) {
|
|
328
|
+
const aborted = compositeSignal.aborted;
|
|
329
|
+
return await fail(err, aborted ? 'aborted' : 'error');
|
|
330
|
+
}
|
|
331
|
+
function handleSessionUpdate(params) {
|
|
332
|
+
if (!params || typeof params !== 'object' || !('update' in params)) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
// params.update is typed as SessionUpdate for known variants. Future
|
|
336
|
+
// or vendor variants arrive with an unrecognized `sessionUpdate` —
|
|
337
|
+
// they hit the `default` branch via a wider runtime check.
|
|
338
|
+
const update = params.update;
|
|
339
|
+
switch (update.sessionUpdate) {
|
|
340
|
+
case 'agent_message_chunk': {
|
|
341
|
+
const text = contentBlockToText(update.content);
|
|
342
|
+
collectedText.push(text);
|
|
343
|
+
turns.text(text);
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
case 'agent_thought_chunk': {
|
|
347
|
+
turns.thinking(contentBlockToText(update.content));
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
case 'tool_call': {
|
|
351
|
+
turns.toolCall(update.toolCallId, update.title ?? update.kind ?? 'tool', update.rawInput ?? update.content ?? null);
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
case 'tool_call_update': {
|
|
355
|
+
if (update.status === 'completed') {
|
|
356
|
+
turns.toolResult(update.toolCallId, update.title ?? 'tool', update.rawOutput ?? update.content ?? null, false);
|
|
357
|
+
}
|
|
358
|
+
else if (update.status === 'failed' || update.status === 'cancelled') {
|
|
359
|
+
turns.toolResult(update.toolCallId, update.title ?? 'tool', update.rawOutput ?? update.content ?? null, true);
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
// 'in_progress' / 'pending' — informational; surface as native.
|
|
363
|
+
turns.native(`acp:tool_status:${update.status}`, update);
|
|
364
|
+
}
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
case 'user_message_chunk': {
|
|
368
|
+
// Echo of the client's own prompt; surface as native rather than
|
|
369
|
+
// as a canonical text event (which is reserved for the agent).
|
|
370
|
+
turns.native('acp:user_chunk', update);
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
default: {
|
|
374
|
+
turns.native(`acp:${update.sessionUpdate}`, update);
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
events: lazyEvents(queue.events, startIfNeeded),
|
|
382
|
+
get result() {
|
|
383
|
+
return startIfNeeded();
|
|
384
|
+
},
|
|
385
|
+
abort(reason) {
|
|
386
|
+
controller.abort(reason);
|
|
387
|
+
if (!started)
|
|
388
|
+
startIfNeeded();
|
|
389
|
+
},
|
|
390
|
+
/**
|
|
391
|
+
* Queue an additional prompt to send on the same ACP session after
|
|
392
|
+
* the current prompt response completes. Calls before the run starts
|
|
393
|
+
* are honored — the loop drains the queue before exiting. After
|
|
394
|
+
* agent_end the call rejects.
|
|
395
|
+
*/
|
|
396
|
+
followUp(message) {
|
|
397
|
+
if (hasEnded) {
|
|
398
|
+
return Promise.reject(new Error('cannot followUp after agent_end'));
|
|
399
|
+
}
|
|
400
|
+
followUpQueue.push(message);
|
|
401
|
+
return Promise.resolve();
|
|
402
|
+
},
|
|
403
|
+
/**
|
|
404
|
+
* Mid-stream steering. ACP's `session/prompt` is a discrete request —
|
|
405
|
+
* the protocol doesn't expose mid-generation injection. Callers that
|
|
406
|
+
* need to add a message after the current response should use
|
|
407
|
+
* `followUp()` instead.
|
|
408
|
+
*/
|
|
409
|
+
steer(_message) {
|
|
410
|
+
return Promise.reject(new Error(`${source} does not support mid-stream steering; use followUp() to send a message after the current prompt response completes`));
|
|
411
|
+
},
|
|
412
|
+
}; // SteerableAgentRun at runtime; narrowed via isSteerable() at the call site.
|
|
413
|
+
}
|
|
414
|
+
// ---------------------------------------------------------------------------
|
|
415
|
+
// helpers
|
|
416
|
+
// ---------------------------------------------------------------------------
|
|
417
|
+
function spawnAgent(config) {
|
|
418
|
+
const env = config.env ? { ...process.env, ...config.env } : process.env;
|
|
419
|
+
const child = spawn(config.command, config.args ?? [], {
|
|
420
|
+
cwd: config.subprocessCwd ?? config.cwd,
|
|
421
|
+
env,
|
|
422
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
423
|
+
});
|
|
424
|
+
return child;
|
|
425
|
+
}
|
|
426
|
+
function waitForExit(child, graceMs) {
|
|
427
|
+
return new Promise((resolve, reject) => {
|
|
428
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
429
|
+
resolve();
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
const t = setTimeout(() => {
|
|
433
|
+
child.removeListener('exit', onExit);
|
|
434
|
+
reject(new Error('exit timeout'));
|
|
435
|
+
}, graceMs);
|
|
436
|
+
const onExit = () => {
|
|
437
|
+
clearTimeout(t);
|
|
438
|
+
resolve();
|
|
439
|
+
};
|
|
440
|
+
child.once('exit', onExit);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
function mapStopReason(reason, aborted) {
|
|
444
|
+
if (aborted || reason === 'cancelled')
|
|
445
|
+
return 'aborted';
|
|
446
|
+
switch (reason) {
|
|
447
|
+
case 'end_turn':
|
|
448
|
+
return 'stop';
|
|
449
|
+
case 'max_tokens':
|
|
450
|
+
return 'length';
|
|
451
|
+
case 'max_turn_requests':
|
|
452
|
+
return 'tool_calls';
|
|
453
|
+
case 'refusal':
|
|
454
|
+
return 'content_filter';
|
|
455
|
+
default:
|
|
456
|
+
return 'unknown';
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
// Re-export the JsonRpcCallError class for callers that catch it.
|
|
460
|
+
export { JsonRpcCallError };
|
|
461
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/acp/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,KAAK,EAA4B,MAAM,oBAAoB,CAAC;AAGrE,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,UAAU,EACV,cAAc,EACd,eAAe,GAOhB,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,kBAAkB,GAgBnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAqB,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAqDzF;;;;;;GAMG;AACH,MAA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S,aAAa,CAAC,MAAkB,EAAE,OAAgB;IACzD,IAAI,OAAO,IAAI,MAAM,KAAK,WAAW;QAAE,OAAO,SAAS,CAAC;IACxD,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,UAAU;YACb,OAAO,MAAM,CAAC;QAChB,KAAK,YAAY;YACf,OAAO,QAAQ,CAAC;QAClB,KAAK,mBAAmB;YACtB,OAAO,YAAY,CAAC;QACtB,KAAK,SAAS;YACZ,OAAO,gBAAgB,CAAC;QAC1B;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC;AAED,kEAAkE;AAClE,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Client Protocol chassis. Public entry for the ACP-speaking adapter
|
|
3
|
+
* surface. Sibling adapters in this package (hermes, openclaw) call
|
|
4
|
+
* `createAcpAdapter({ id })` to mint their own AgentAdapterMeta with the
|
|
5
|
+
* right `source` field on every event.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export { acpAgent, createAcpAdapter, JsonRpcCallError } from './adapter.js';
|
|
10
|
+
export type { AcpAgentConfig, CreateAcpAdapterOptions } from './adapter.js';
|
|
11
|
+
export type { AgentCapabilities as AcpAgentCapabilities, AuthMethod, ClientCapabilities, ContentBlock, Implementation, McpServer, SessionId, StopReason, ToolCallStatus, } from './types.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/acp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC5E,YAAY,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAG5E,YAAY,EACV,iBAAiB,IAAI,oBAAoB,EACzC,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,SAAS,EACT,SAAS,EACT,UAAU,EACV,cAAc,GACf,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Client Protocol chassis. Public entry for the ACP-speaking adapter
|
|
3
|
+
* surface. Sibling adapters in this package (hermes, openclaw) call
|
|
4
|
+
* `createAcpAdapter({ id })` to mint their own AgentAdapterMeta with the
|
|
5
|
+
* right `source` field on every event.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export { acpAgent, createAcpAdapter, JsonRpcCallError } from './adapter.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/acp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NDJSON JSON-RPC 2.0 transport over a child-process stdio pair.
|
|
3
|
+
*
|
|
4
|
+
* ACP frames messages as newline-delimited JSON — one JSON-RPC envelope
|
|
5
|
+
* per line, no Content-Length headers. The transport owns the byte-level
|
|
6
|
+
* framing, request/response correlation, and notification dispatch. The
|
|
7
|
+
* adapter layer above translates ACP-specific messages into canonical
|
|
8
|
+
* `AgentEvent`s.
|
|
9
|
+
*
|
|
10
|
+
* Single-process scope: each transport instance binds to one subprocess.
|
|
11
|
+
* Disposing it ends the child's stdin and (optionally) signals the child.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
import type { ChildProcessByStdio } from 'node:child_process';
|
|
16
|
+
import type { Readable, Writable } from 'node:stream';
|
|
17
|
+
/** A JSON-RPC 2.0 request, response, or notification. @internal */
|
|
18
|
+
export type JsonRpcMessage = {
|
|
19
|
+
jsonrpc: '2.0';
|
|
20
|
+
id: number | string;
|
|
21
|
+
method: string;
|
|
22
|
+
params?: unknown;
|
|
23
|
+
} | {
|
|
24
|
+
jsonrpc: '2.0';
|
|
25
|
+
id: number | string;
|
|
26
|
+
result: unknown;
|
|
27
|
+
} | {
|
|
28
|
+
jsonrpc: '2.0';
|
|
29
|
+
id: number | string;
|
|
30
|
+
error: JsonRpcError;
|
|
31
|
+
} | {
|
|
32
|
+
jsonrpc: '2.0';
|
|
33
|
+
method: string;
|
|
34
|
+
params?: unknown;
|
|
35
|
+
};
|
|
36
|
+
/** JSON-RPC 2.0 error object. @internal */
|
|
37
|
+
export interface JsonRpcError {
|
|
38
|
+
code: number;
|
|
39
|
+
message: string;
|
|
40
|
+
data?: unknown;
|
|
41
|
+
}
|
|
42
|
+
/** @internal */
|
|
43
|
+
export declare class JsonRpcCallError extends Error {
|
|
44
|
+
method: string;
|
|
45
|
+
rpcError: JsonRpcError;
|
|
46
|
+
constructor(method: string, rpcError: JsonRpcError);
|
|
47
|
+
}
|
|
48
|
+
/** @internal */
|
|
49
|
+
export interface AcpTransportOptions {
|
|
50
|
+
/** The spawned child whose stdio we'll speak over. */
|
|
51
|
+
child: ChildProcessByStdio<Writable, Readable, Readable | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Called on every notification received from the agent. Notifications
|
|
54
|
+
* are method calls without an `id` — the transport routes them here.
|
|
55
|
+
*/
|
|
56
|
+
onNotification?: (method: string, params: unknown) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Called on every request the agent makes back at the client (e.g.
|
|
59
|
+
* session/request_permission). The handler returns the response value
|
|
60
|
+
* which the transport replies with. If no handler is set or the
|
|
61
|
+
* handler throws, the transport responds with a JSON-RPC method-not-
|
|
62
|
+
* found error.
|
|
63
|
+
*/
|
|
64
|
+
onRequest?: (method: string, params: unknown) => Promise<unknown>;
|
|
65
|
+
/** Called when the underlying stream emits a parse error or closes unexpectedly. */
|
|
66
|
+
onTransportError?: (err: Error) => void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Build a transport bound to the given child's stdio. The transport
|
|
70
|
+
* starts reading immediately. Call `dispose()` to release listeners and
|
|
71
|
+
* close stdin.
|
|
72
|
+
*
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
export declare function createAcpTransport(opts: AcpTransportOptions): AcpTransport;
|
|
76
|
+
/** @internal */
|
|
77
|
+
export interface AcpTransport {
|
|
78
|
+
request<T>(method: string, params?: unknown): Promise<T>;
|
|
79
|
+
notify(method: string, params?: unknown): void;
|
|
80
|
+
dispose(): void;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/acp/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEtD,mEAAmE;AACnE,MAAM,MAAM,cAAc,GACtB;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GACzE;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GACxD;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,KAAK,EAAE,YAAY,CAAA;CAAE,GAC5D;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE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