@adecore/agents 0.31.6 → 0.31.7
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/chat/acp-backend.js +10 -3
- package/dist/chat/acp-protocol.d.ts +3 -0
- package/dist/chat/acp-protocol.js +26 -2
- package/dist/chat/chat-session.js +5 -2
- package/dist/chat/fixtures/copilot-1.0.101-turn.json +677 -0
- package/dist/testing/fake-acp-capture.d.ts +11 -0
- package/dist/testing/fake-acp-capture.js +50 -0
- package/package.json +3 -3
- package/src/chat/acp-backend.ts +9 -3
- package/src/chat/acp-protocol.ts +30 -2
- package/src/chat/chat-session.ts +5 -2
- package/src/chat/fixtures/copilot-1.0.101-turn.json +677 -0
- package/src/testing/fake-acp-capture.ts +70 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* An ACP agent that answers with the frames a real one sent, recorded in a capture: its `initialize`, its
|
|
3
|
+
* `session/new`, and every update of one prompt before the response. Every prompt gets the same turn, except
|
|
4
|
+
* that a `session_info_update` carries the prompt's own text as its title, as Copilot CLI names a session.
|
|
5
|
+
*/
|
|
6
|
+
import type { FakeCli } from './fake-cli.ts';
|
|
7
|
+
|
|
8
|
+
type Frame = Record<string, unknown>;
|
|
9
|
+
|
|
10
|
+
export interface AcpCapture {
|
|
11
|
+
sessionId: string;
|
|
12
|
+
initialize: unknown;
|
|
13
|
+
sessionNew: unknown;
|
|
14
|
+
// The `available_commands_update` the agent sends before it answers `session/new`.
|
|
15
|
+
commands: unknown[];
|
|
16
|
+
setConfigOption: unknown;
|
|
17
|
+
promptUpdates: unknown[];
|
|
18
|
+
promptResponse: unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function fakeAcpCapture(capture: AcpCapture): FakeCli {
|
|
22
|
+
return (io) => {
|
|
23
|
+
const send = (frame: Frame): void => {
|
|
24
|
+
io.out({ jsonrpc: '2.0', ...frame });
|
|
25
|
+
};
|
|
26
|
+
const update = (fields: unknown): void => {
|
|
27
|
+
send({ method: 'session/update', params: { sessionId: capture.sessionId, update: fields } });
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
onLine: (line) => {
|
|
31
|
+
const frame = JSON.parse(line) as Frame;
|
|
32
|
+
const id = frame.id;
|
|
33
|
+
switch (frame.method) {
|
|
34
|
+
case undefined:
|
|
35
|
+
return;
|
|
36
|
+
case 'initialize':
|
|
37
|
+
send({ id, result: capture.initialize });
|
|
38
|
+
return;
|
|
39
|
+
case 'session/new':
|
|
40
|
+
update({ sessionUpdate: 'available_commands_update', availableCommands: capture.commands });
|
|
41
|
+
send({ id, result: capture.sessionNew });
|
|
42
|
+
return;
|
|
43
|
+
case 'session/set_config_option':
|
|
44
|
+
send({ id, result: capture.setConfigOption });
|
|
45
|
+
return;
|
|
46
|
+
case 'session/set_mode':
|
|
47
|
+
case 'session/close':
|
|
48
|
+
send({ id, result: {} });
|
|
49
|
+
return;
|
|
50
|
+
case 'session/prompt': {
|
|
51
|
+
const blocks = Array.isArray((frame.params as Frame | undefined)?.prompt) ? ((frame.params as Frame).prompt as Frame[]) : [];
|
|
52
|
+
const text = blocks.find((block) => block.type === 'text')?.text;
|
|
53
|
+
for (const fields of capture.promptUpdates) {
|
|
54
|
+
const named = (fields as Frame).sessionUpdate === 'session_info_update';
|
|
55
|
+
update(named ? { ...(fields as Frame), title: text } : fields);
|
|
56
|
+
}
|
|
57
|
+
send({ id, result: capture.promptResponse });
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
case 'session/cancel':
|
|
61
|
+
return;
|
|
62
|
+
default:
|
|
63
|
+
if (id !== undefined) {
|
|
64
|
+
send({ id, error: { code: -32601, message: `Method not found: ${String(frame.method)}` } });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
}
|