@agentclientprotocol/claude-agent-acp 0.85.2-preview.9 → 0.86.1-preview.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.
- package/dist/acp-agent.d.ts +67 -21
- package/dist/acp-agent.d.ts.map +1 -1
- package/dist/acp-agent.js +264 -68
- package/dist/async-tasks.d.ts +52 -3
- package/dist/async-tasks.d.ts.map +1 -1
- package/dist/async-tasks.js +185 -42
- package/dist/clear-context-coordinator.d.ts +1 -0
- package/dist/clear-context-coordinator.d.ts.map +1 -1
- package/dist/clear-context-coordinator.js +2 -1
- package/dist/diff.d.ts +45 -8
- package/dist/diff.d.ts.map +1 -1
- package/dist/diff.js +111 -30
- package/dist/native-subagents.d.ts +7 -4
- package/dist/native-subagents.d.ts.map +1 -1
- package/dist/native-subagents.js +22 -5
- package/dist/permissions/presentation.d.ts +17 -2
- package/dist/permissions/presentation.d.ts.map +1 -1
- package/dist/permissions/presentation.js +4 -0
- package/dist/session-config-ids.d.ts +1 -0
- package/dist/session-config-ids.d.ts.map +1 -1
- package/dist/session-config-ids.js +1 -0
- package/dist/tool-calls/background.d.ts +5 -2
- package/dist/tool-calls/background.d.ts.map +1 -1
- package/dist/tool-calls/background.js +6 -11
- package/dist/tool-calls/client-capabilities.d.ts +20 -2
- package/dist/tool-calls/client-capabilities.d.ts.map +1 -1
- package/dist/tool-calls/client-capabilities.js +14 -4
- package/dist/tool-calls/facts.d.ts +8 -1
- package/dist/tool-calls/facts.d.ts.map +1 -1
- package/dist/tool-calls/renderer.d.ts +5 -1
- package/dist/tool-calls/renderer.d.ts.map +1 -1
- package/dist/tool-calls/renderer.js +14 -3
- package/dist/tool-calls/reporters/bash.d.ts.map +1 -1
- package/dist/tool-calls/reporters/bash.js +32 -5
- package/dist/tool-calls/reporters/file-edit.d.ts +1 -1
- package/dist/tool-calls/reporters/file-edit.d.ts.map +1 -1
- package/dist/tool-calls/reporters/file-edit.js +20 -14
- package/dist/v2/agent.d.ts +2 -0
- package/dist/v2/agent.d.ts.map +1 -1
- package/dist/v2/agent.js +109 -14
- package/dist/v2/initialize.d.ts +2 -5
- package/dist/v2/initialize.d.ts.map +1 -1
- package/dist/v2/initialize.js +42 -11
- package/dist/v2/permission.d.ts +25 -0
- package/dist/v2/permission.d.ts.map +1 -0
- package/dist/v2/permission.js +38 -0
- package/dist/v2/session-update.d.ts +6 -0
- package/dist/v2/session-update.d.ts.map +1 -1
- package/dist/v2/session-update.js +19 -0
- package/dist/v2/session.d.ts +29 -4
- package/dist/v2/session.d.ts.map +1 -1
- package/dist/v2/session.js +41 -6
- package/dist/v2/terminal.d.ts +42 -0
- package/dist/v2/terminal.d.ts.map +1 -0
- package/dist/v2/terminal.js +95 -0
- package/dist/v2/tool-call.d.ts +38 -0
- package/dist/v2/tool-call.d.ts.map +1 -0
- package/dist/v2/tool-call.js +49 -0
- package/package.json +1 -1
package/dist/v2/session.d.ts
CHANGED
|
@@ -3,14 +3,39 @@
|
|
|
3
3
|
* `ClaudeAcpAgent`: v2 requests become the v1 requests that the agent serves,
|
|
4
4
|
* and its v1 responses become v2 responses.
|
|
5
5
|
*/
|
|
6
|
-
import { type AvailableCommand, type NewSessionRequest, type NewSessionResponse, type ResumeSessionRequest, type ResumeSessionResponse, type SessionConfigOption, type SetSessionConfigOptionRequest } from "@agentclientprotocol/sdk";
|
|
6
|
+
import { type AvailableCommand, type ForkSessionRequest, type LoadSessionRequest, type NewSessionRequest, type NewSessionResponse, type ResumeSessionRequest, type ResumeSessionResponse, type SessionConfigOption, type SetSessionConfigOptionRequest } from "@agentclientprotocol/sdk";
|
|
7
7
|
import * as v2 from "@agentclientprotocol/sdk/experimental/v2";
|
|
8
8
|
export declare function v1NewSessionRequest(params: v2.NewSessionRequest): NewSessionRequest;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* The v1 request that a v2 `session/resume` means.
|
|
11
|
+
*
|
|
12
|
+
* v2 restores a session with `session/resume` and replays its history only
|
|
13
|
+
* when `replayFrom` asks for it. v1 has two methods: `session/resume`, which
|
|
14
|
+
* never replays, and `session/load`, which replays the whole history before it
|
|
15
|
+
* responds. `replayFrom: { type: "start" }` is the second; a cursor that
|
|
16
|
+
* starts elsewhere is rejected.
|
|
12
17
|
*/
|
|
13
|
-
export declare function
|
|
18
|
+
export declare function v1RestoreSessionRequest(params: v2.ResumeSessionRequest): {
|
|
19
|
+
method: "resume";
|
|
20
|
+
request: ResumeSessionRequest;
|
|
21
|
+
} | {
|
|
22
|
+
method: "load";
|
|
23
|
+
request: LoadSessionRequest;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The v1 requests that a v2 `session/fork` means.
|
|
27
|
+
*
|
|
28
|
+
* The agent's v1 fork copies the transcript into a new session and returns
|
|
29
|
+
* only its id; a v1 client then resumes or loads it. A v2 fork returns the new
|
|
30
|
+
* session with its config options, like `session/new`, so the client can
|
|
31
|
+
* prompt it. The v2 surface therefore forks, then resumes the fork without
|
|
32
|
+
* replay, with the request's `cwd`, `additionalDirectories`, and
|
|
33
|
+
* `mcpServers`. The request's `_meta` goes to the fork alone.
|
|
34
|
+
*/
|
|
35
|
+
export declare function v1ForkSessionRequests(params: v2.ForkSessionRequest): {
|
|
36
|
+
fork: ForkSessionRequest;
|
|
37
|
+
resume: (sessionId: string) => ResumeSessionRequest;
|
|
38
|
+
};
|
|
14
39
|
/** v2 drops `modes`: the session mode is the `mode` config option, which the agent always lists. */
|
|
15
40
|
export declare function v2NewSessionResponse(response: NewSessionResponse): v2.NewSessionResponse;
|
|
16
41
|
export declare function v2ResumeSessionResponse(response: ResumeSessionResponse): v2.ResumeSessionResponse;
|
package/dist/v2/session.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/v2/session.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAEL,KAAK,gBAAgB,
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/v2/session.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EAEvB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EAGxB,KAAK,6BAA6B,EACnC,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,0CAA0C,CAAC;AAE/D,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,EAAE,CAAC,iBAAiB,GAAG,iBAAiB,CAInF;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,EAAE,CAAC,oBAAoB,GAE7B;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,oBAAoB,CAAA;CAAE,GACnD;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,kBAAkB,CAAA;CAAE,CAkBlD;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,EAAE,CAAC,kBAAkB,GAAG;IACpE,IAAI,EAAE,kBAAkB,CAAC;IACzB,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,oBAAoB,CAAC;CACrD,CAUA;AAED,oGAAoG;AACpG,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,EAAE,CAAC,kBAAkB,CAExF;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,EAAE,CAAC,qBAAqB,CAKjG;AAED,uEAAuE;AACvE,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,EAAE,CAAC,6BAA6B,GACvC,6BAA6B,CAgB/B;AAED,sFAAsF;AACtF,wBAAgB,eAAe,CAAC,OAAO,EAAE,mBAAmB,EAAE,GAAG,EAAE,CAAC,mBAAmB,EAAE,CAQxF;AAWD,oEAAoE;AACpE,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,EAAE,CAAC,gBAAgB,EAAE,CAKvF"}
|
package/dist/v2/session.js
CHANGED
|
@@ -11,15 +11,50 @@ export function v1NewSessionRequest(params) {
|
|
|
11
11
|
return { ...request, mcpServers: (mcpServers ?? []).map(v1McpServer) };
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* The v1 request that a v2 `session/resume` means.
|
|
15
|
+
*
|
|
16
|
+
* v2 restores a session with `session/resume` and replays its history only
|
|
17
|
+
* when `replayFrom` asks for it. v1 has two methods: `session/resume`, which
|
|
18
|
+
* never replays, and `session/load`, which replays the whole history before it
|
|
19
|
+
* responds. `replayFrom: { type: "start" }` is the second; a cursor that
|
|
20
|
+
* starts elsewhere is rejected.
|
|
16
21
|
*/
|
|
17
|
-
export function
|
|
22
|
+
export function v1RestoreSessionRequest(params) {
|
|
18
23
|
const { replayFrom, mcpServers, ...request } = params;
|
|
19
|
-
if (replayFrom
|
|
20
|
-
|
|
24
|
+
if (replayFrom == null) {
|
|
25
|
+
return {
|
|
26
|
+
method: "resume",
|
|
27
|
+
request: { ...request, ...(mcpServers ? { mcpServers: mcpServers.map(v1McpServer) } : {}) },
|
|
28
|
+
};
|
|
21
29
|
}
|
|
22
|
-
|
|
30
|
+
if (replayFrom.type !== "start") {
|
|
31
|
+
throw RequestError.invalidParams({ replayFrom }, `Replaying from a ${replayFrom.type} cursor is not supported`);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
method: "load",
|
|
35
|
+
request: { ...request, mcpServers: (mcpServers ?? []).map(v1McpServer) },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The v1 requests that a v2 `session/fork` means.
|
|
40
|
+
*
|
|
41
|
+
* The agent's v1 fork copies the transcript into a new session and returns
|
|
42
|
+
* only its id; a v1 client then resumes or loads it. A v2 fork returns the new
|
|
43
|
+
* session with its config options, like `session/new`, so the client can
|
|
44
|
+
* prompt it. The v2 surface therefore forks, then resumes the fork without
|
|
45
|
+
* replay, with the request's `cwd`, `additionalDirectories`, and
|
|
46
|
+
* `mcpServers`. The request's `_meta` goes to the fork alone.
|
|
47
|
+
*/
|
|
48
|
+
export function v1ForkSessionRequests(params) {
|
|
49
|
+
const { mcpServers, _meta, ...request } = params;
|
|
50
|
+
const session = {
|
|
51
|
+
...request,
|
|
52
|
+
...(mcpServers ? { mcpServers: mcpServers.map(v1McpServer) } : {}),
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
fork: { ...session, ...(_meta != null ? { _meta } : {}) },
|
|
56
|
+
resume: (sessionId) => ({ ...session, sessionId }),
|
|
57
|
+
};
|
|
23
58
|
}
|
|
24
59
|
/** v2 drops `modes`: the session mode is the `mode` config option, which the agent always lists. */
|
|
25
60
|
export function v2NewSessionResponse(response) {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent-owned display terminals for the commands that the agent runs.
|
|
3
|
+
*
|
|
4
|
+
* The agent reports a command through the terminal extension of ACP v1
|
|
5
|
+
* clients, as codex-acp does: `_meta.terminal_info` names the terminal of a
|
|
6
|
+
* tool call, whose content references it; `terminal_output` (a snapshot) or
|
|
7
|
+
* `terminal_output_delta` (a chunk) carries the output, and `terminal_exit` the
|
|
8
|
+
* exit. ACP v2 standardizes this as display-only terminals: the same content
|
|
9
|
+
* reference, and `terminal_update` and `terminal_output_chunk` for the
|
|
10
|
+
* terminal's state. The agent reports to a v2 client as to a client of the
|
|
11
|
+
* extension (`ToolCallClientCapabilities.from`), and {@link V2Terminals} turns
|
|
12
|
+
* the extension's keys into those updates.
|
|
13
|
+
*/
|
|
14
|
+
import type { ToolCall, ToolCallUpdate } from "@agentclientprotocol/sdk";
|
|
15
|
+
import type * as v2 from "@agentclientprotocol/sdk/experimental/v2";
|
|
16
|
+
type V1ToolCallReport = (ToolCall & {
|
|
17
|
+
sessionUpdate: "tool_call";
|
|
18
|
+
}) | (ToolCallUpdate & {
|
|
19
|
+
sessionUpdate: "tool_call_update";
|
|
20
|
+
});
|
|
21
|
+
/** The terminal updates of the tool call reports of one v2 connection. */
|
|
22
|
+
export declare class V2Terminals {
|
|
23
|
+
/** The terminal and the last reported command of each running command, by session and tool call. */
|
|
24
|
+
private readonly running;
|
|
25
|
+
/**
|
|
26
|
+
* The terminal updates that a tool call report carries in the extension's
|
|
27
|
+
* keys, and the report without them, or undefined when nothing else is left
|
|
28
|
+
* in it.
|
|
29
|
+
*
|
|
30
|
+
* The extension names no command, so the terminal gets the command of the
|
|
31
|
+
* tool call's `rawInput` once a report carries it: the first report of a
|
|
32
|
+
* streamed tool use has no input yet.
|
|
33
|
+
*/
|
|
34
|
+
split(sessionId: string, report: V1ToolCallReport): {
|
|
35
|
+
terminal: v2.SessionUpdate[];
|
|
36
|
+
report: V1ToolCallReport | undefined;
|
|
37
|
+
};
|
|
38
|
+
/** Forgets the terminals of a session. */
|
|
39
|
+
forget(sessionId: string): void;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=terminal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../src/v2/terminal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,KAAK,EAAE,MAAM,0CAA0C,CAAC;AAEpE,KAAK,gBAAgB,GACjB,CAAC,QAAQ,GAAG;IAAE,aAAa,EAAE,WAAW,CAAA;CAAE,CAAC,GAC3C,CAAC,cAAc,GAAG;IAAE,aAAa,EAAE,kBAAkB,CAAA;CAAE,CAAC,CAAC;AAiB7D,0EAA0E;AAC1E,qBAAa,WAAW;IACtB,oGAAoG;IACpG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA+D;IAEvF;;;;;;;;OAQG;IACH,KAAK,CACH,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,gBAAgB,GACvB;QAAE,QAAQ,EAAE,EAAE,CAAC,aAAa,EAAE,CAAC;QAAC,MAAM,EAAE,gBAAgB,GAAG,SAAS,CAAA;KAAE;IAuCzE,0CAA0C;IAC1C,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;CAKhC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const TERMINAL_KEYS = [
|
|
2
|
+
"terminal_info",
|
|
3
|
+
"terminal_output",
|
|
4
|
+
"terminal_output_delta",
|
|
5
|
+
"terminal_exit",
|
|
6
|
+
];
|
|
7
|
+
/** The terminal updates of the tool call reports of one v2 connection. */
|
|
8
|
+
export class V2Terminals {
|
|
9
|
+
/** The terminal and the last reported command of each running command, by session and tool call. */
|
|
10
|
+
running = new Map();
|
|
11
|
+
/**
|
|
12
|
+
* The terminal updates that a tool call report carries in the extension's
|
|
13
|
+
* keys, and the report without them, or undefined when nothing else is left
|
|
14
|
+
* in it.
|
|
15
|
+
*
|
|
16
|
+
* The extension names no command, so the terminal gets the command of the
|
|
17
|
+
* tool call's `rawInput` once a report carries it: the first report of a
|
|
18
|
+
* streamed tool use has no input yet.
|
|
19
|
+
*/
|
|
20
|
+
split(sessionId, report) {
|
|
21
|
+
const meta = (report._meta ?? {});
|
|
22
|
+
const key = `${sessionId} ${report.toolCallId}`;
|
|
23
|
+
if (meta.terminal_info)
|
|
24
|
+
this.running.set(key, { terminalId: meta.terminal_info.terminal_id });
|
|
25
|
+
const terminal = [];
|
|
26
|
+
const running = this.running.get(key);
|
|
27
|
+
if (running) {
|
|
28
|
+
const command = commandOf(report.rawInput);
|
|
29
|
+
const newCommand = command !== undefined && command !== running.command;
|
|
30
|
+
if (newCommand)
|
|
31
|
+
running.command = command;
|
|
32
|
+
const { terminal_output: output, terminal_output_delta: delta, terminal_exit: exit } = meta;
|
|
33
|
+
if (meta.terminal_info || newCommand || output || exit) {
|
|
34
|
+
terminal.push({
|
|
35
|
+
sessionUpdate: "terminal_update",
|
|
36
|
+
terminalId: running.terminalId,
|
|
37
|
+
...(newCommand ? { command } : {}),
|
|
38
|
+
...(output ? { output: { data: base64(output.data) } } : {}),
|
|
39
|
+
...(exit
|
|
40
|
+
? {
|
|
41
|
+
exitStatus: {
|
|
42
|
+
...(exit.exit_code != null ? { exitCode: exit.exit_code } : {}),
|
|
43
|
+
...(exit.signal != null ? { signal: exit.signal } : {}),
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
: {}),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (delta) {
|
|
50
|
+
terminal.push({
|
|
51
|
+
sessionUpdate: "terminal_output_chunk",
|
|
52
|
+
terminalId: running.terminalId,
|
|
53
|
+
data: base64(delta.data),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (exit)
|
|
57
|
+
this.running.delete(key);
|
|
58
|
+
}
|
|
59
|
+
return { terminal, report: withoutTerminalKeys(report) };
|
|
60
|
+
}
|
|
61
|
+
/** Forgets the terminals of a session. */
|
|
62
|
+
forget(sessionId) {
|
|
63
|
+
for (const key of this.running.keys()) {
|
|
64
|
+
if (key.startsWith(`${sessionId} `))
|
|
65
|
+
this.running.delete(key);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The report without the extension's keys, or undefined when it carried
|
|
71
|
+
* nothing else but `_meta`: the output report of a command carries the output
|
|
72
|
+
* alone, and only the stamps that every report of the tool call repeats. In v2
|
|
73
|
+
* a concrete `_meta` replaces the stored one, so sending them would drop the
|
|
74
|
+
* other keys that the tool call holds.
|
|
75
|
+
*/
|
|
76
|
+
function withoutTerminalKeys(report) {
|
|
77
|
+
if (!report._meta || !TERMINAL_KEYS.some((key) => key in report._meta))
|
|
78
|
+
return report;
|
|
79
|
+
const meta = Object.fromEntries(Object.entries(report._meta).filter(([key]) => !TERMINAL_KEYS.includes(key)));
|
|
80
|
+
const stripped = { ...report };
|
|
81
|
+
if (Object.keys(meta).length > 0)
|
|
82
|
+
stripped._meta = meta;
|
|
83
|
+
else
|
|
84
|
+
delete stripped._meta;
|
|
85
|
+
const fields = Object.keys(stripped).filter((key) => key !== "sessionUpdate" && key !== "toolCallId" && key !== "_meta");
|
|
86
|
+
return fields.length > 0 || report.sessionUpdate === "tool_call" ? stripped : undefined;
|
|
87
|
+
}
|
|
88
|
+
function commandOf(rawInput) {
|
|
89
|
+
const command = rawInput?.command;
|
|
90
|
+
return typeof command === "string" && command.length > 0 ? command : undefined;
|
|
91
|
+
}
|
|
92
|
+
/** The output bytes, base64-encoded as a v2 terminal carries them. */
|
|
93
|
+
function base64(text) {
|
|
94
|
+
return Buffer.from(text, "utf8").toString("base64");
|
|
95
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The v2 form of the tool call reports that `ClaudeAcpAgent` sends as v1
|
|
3
|
+
* `tool_call` and `tool_call_update` updates, and in permission requests.
|
|
4
|
+
*/
|
|
5
|
+
import type { ToolCall, ToolCallUpdate } from "@agentclientprotocol/sdk";
|
|
6
|
+
import type * as v2 from "@agentclientprotocol/sdk/experimental/v2";
|
|
7
|
+
type V1ToolCallReport = (ToolCall & {
|
|
8
|
+
sessionUpdate: "tool_call";
|
|
9
|
+
}) | (ToolCallUpdate & {
|
|
10
|
+
sessionUpdate: "tool_call_update";
|
|
11
|
+
});
|
|
12
|
+
type V2ToolCallUpdate = v2.ToolCallUpdate & {
|
|
13
|
+
sessionUpdate: "tool_call_update";
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The v2 form of a v1 tool call report.
|
|
17
|
+
*
|
|
18
|
+
* v1 reports a new tool call with `tool_call` and changes it with
|
|
19
|
+
* `tool_call_update`; v2 has one `tool_call_update` that upserts by
|
|
20
|
+
* `toolCallId`. Both leave a field that a report omits unchanged, and both
|
|
21
|
+
* replace `content` and `locations` as whole arrays. They differ on `null`:
|
|
22
|
+
* in v1 it leaves the field unchanged too, in v2 it clears the field, so `null`
|
|
23
|
+
* fields are left out.
|
|
24
|
+
*
|
|
25
|
+
* Diffs need what a v1 diff does not say, so the agent builds them in v2 form
|
|
26
|
+
* for a v2 client (`v2DiffContent`), and they pass as they are. Terminal
|
|
27
|
+
* content references a display terminal, as in v2: a v2 client has no client
|
|
28
|
+
* terminals, so the agent's only terminals are those of its terminal extension
|
|
29
|
+
* (see `terminal.ts`).
|
|
30
|
+
*/
|
|
31
|
+
export declare function v2ToolCallUpdate(report: V1ToolCallReport): V2ToolCallUpdate;
|
|
32
|
+
/**
|
|
33
|
+
* The v2 form of the fields of a v1 tool call report, which a session update
|
|
34
|
+
* and the subject of a permission request carry. See {@link v2ToolCallUpdate}.
|
|
35
|
+
*/
|
|
36
|
+
export declare function v2ToolCallPatch(toolCall: ToolCall | ToolCallUpdate): v2.ToolCallUpdate;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=tool-call.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-call.d.ts","sourceRoot":"","sources":["../../src/v2/tool-call.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAmB,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1F,OAAO,KAAK,KAAK,EAAE,MAAM,0CAA0C,CAAC;AAEpE,KAAK,gBAAgB,GACjB,CAAC,QAAQ,GAAG;IAAE,aAAa,EAAE,WAAW,CAAA;CAAE,CAAC,GAC3C,CAAC,cAAc,GAAG;IAAE,aAAa,EAAE,kBAAkB,CAAA;CAAE,CAAC,CAAC;AAE7D,KAAK,gBAAgB,GAAG,EAAE,CAAC,cAAc,GAAG;IAAE,aAAa,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAElF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAE3E;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,cAAc,GAAG,EAAE,CAAC,cAAc,CAUtF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The v2 form of a v1 tool call report.
|
|
3
|
+
*
|
|
4
|
+
* v1 reports a new tool call with `tool_call` and changes it with
|
|
5
|
+
* `tool_call_update`; v2 has one `tool_call_update` that upserts by
|
|
6
|
+
* `toolCallId`. Both leave a field that a report omits unchanged, and both
|
|
7
|
+
* replace `content` and `locations` as whole arrays. They differ on `null`:
|
|
8
|
+
* in v1 it leaves the field unchanged too, in v2 it clears the field, so `null`
|
|
9
|
+
* fields are left out.
|
|
10
|
+
*
|
|
11
|
+
* Diffs need what a v1 diff does not say, so the agent builds them in v2 form
|
|
12
|
+
* for a v2 client (`v2DiffContent`), and they pass as they are. Terminal
|
|
13
|
+
* content references a display terminal, as in v2: a v2 client has no client
|
|
14
|
+
* terminals, so the agent's only terminals are those of its terminal extension
|
|
15
|
+
* (see `terminal.ts`).
|
|
16
|
+
*/
|
|
17
|
+
export function v2ToolCallUpdate(report) {
|
|
18
|
+
return { ...v2ToolCallPatch(report), sessionUpdate: "tool_call_update" };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The v2 form of the fields of a v1 tool call report, which a session update
|
|
22
|
+
* and the subject of a permission request carry. See {@link v2ToolCallUpdate}.
|
|
23
|
+
*/
|
|
24
|
+
export function v2ToolCallPatch(toolCall) {
|
|
25
|
+
const patch = Object.fromEntries(Object.entries(toolCall).filter(([key, value]) => value !== null && key !== "sessionUpdate" && key !== "content"));
|
|
26
|
+
return {
|
|
27
|
+
...patch,
|
|
28
|
+
...(toolCall.content != null ? { content: toolCall.content.map(v2ToolCallContent) } : {}),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function v2ToolCallContent(item) {
|
|
32
|
+
switch (item.type) {
|
|
33
|
+
case "content":
|
|
34
|
+
// v2 content blocks are a superset of the v1 blocks.
|
|
35
|
+
return item;
|
|
36
|
+
case "terminal":
|
|
37
|
+
return item;
|
|
38
|
+
default:
|
|
39
|
+
if (isV2Diff(item))
|
|
40
|
+
return item;
|
|
41
|
+
// A v1 diff names one path, with old and new texts that can be a
|
|
42
|
+
// snippet: v2 cannot say which operation it is, nor give its patch.
|
|
43
|
+
throw new Error("An ACP v2 client cannot take a v1 diff");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** A diff that the agent built in v2 form, which travels as v1 content. */
|
|
47
|
+
function isV2Diff(item) {
|
|
48
|
+
return "changes" in item;
|
|
49
|
+
}
|
package/package.json
CHANGED