@agentclientprotocol/claude-agent-acp 0.85.2-preview.19 → 0.85.2-preview.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/README.md +0 -1
- package/dist/acp-agent.d.ts +18 -81
- package/dist/acp-agent.d.ts.map +1 -1
- package/dist/acp-agent.js +170 -435
- package/dist/air-extension.d.ts +0 -2
- package/dist/air-extension.d.ts.map +1 -1
- package/dist/air-extension.js +0 -2
- package/dist/diff.d.ts +8 -45
- package/dist/diff.d.ts.map +1 -1
- package/dist/diff.js +30 -111
- package/dist/permissions/presentation.d.ts +2 -17
- package/dist/permissions/presentation.d.ts.map +1 -1
- package/dist/permissions/presentation.js +0 -4
- package/dist/resumed-session.d.ts +6 -16
- package/dist/resumed-session.d.ts.map +1 -1
- package/dist/resumed-session.js +25 -91
- package/dist/session-mode.d.ts +0 -14
- package/dist/session-mode.d.ts.map +1 -1
- package/dist/session-mode.js +0 -22
- package/dist/tool-calls/client-capabilities.d.ts +2 -20
- package/dist/tool-calls/client-capabilities.d.ts.map +1 -1
- package/dist/tool-calls/client-capabilities.js +4 -14
- package/dist/tool-calls/renderer.d.ts.map +1 -1
- package/dist/tool-calls/renderer.js +2 -3
- 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 +14 -20
- package/dist/turn-events.d.ts +5 -11
- package/dist/turn-events.d.ts.map +1 -1
- package/dist/usage-markdown.d.ts +0 -2
- package/dist/usage-markdown.d.ts.map +1 -1
- package/dist/usage-markdown.js +1 -2
- package/dist/utils.d.ts +0 -12
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +0 -28
- package/dist/v2/agent.d.ts.map +1 -1
- package/dist/v2/agent.js +17 -121
- package/dist/v2/initialize.d.ts +5 -2
- package/dist/v2/initialize.d.ts.map +1 -1
- package/dist/v2/initialize.js +6 -23
- package/dist/v2/session-update.d.ts +0 -6
- package/dist/v2/session-update.d.ts.map +1 -1
- package/dist/v2/session-update.js +0 -27
- package/dist/v2/session.d.ts +4 -15
- package/dist/v2/session.d.ts.map +1 -1
- package/dist/v2/session.js +6 -20
- package/package.json +2 -2
- package/dist/mcp-command.d.ts +0 -51
- package/dist/mcp-command.d.ts.map +0 -1
- package/dist/mcp-command.js +0 -321
- package/dist/v2/permission.d.ts +0 -25
- package/dist/v2/permission.d.ts.map +0 -1
- package/dist/v2/permission.js +0 -38
- package/dist/v2/prompt.d.ts +0 -47
- package/dist/v2/prompt.d.ts.map +0 -1
- package/dist/v2/prompt.js +0 -153
- package/dist/v2/terminal.d.ts +0 -42
- package/dist/v2/terminal.d.ts.map +0 -1
- package/dist/v2/terminal.js +0 -95
- package/dist/v2/tool-call.d.ts +0 -38
- package/dist/v2/tool-call.d.ts.map +0 -1
- package/dist/v2/tool-call.js +0 -49
package/dist/v2/prompt.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ACP v2 `session/prompt`, served through the turn events of `ClaudeAcpAgent`.
|
|
3
|
-
*
|
|
4
|
-
* v2 answers the prompt once Claude Code takes it in, with the id of the user
|
|
5
|
-
* message it became, and reports the rest of the turn as `state_update`s.
|
|
6
|
-
*/
|
|
7
|
-
import { type PromptRequest } from "@agentclientprotocol/sdk";
|
|
8
|
-
import * as v2 from "@agentclientprotocol/sdk/experimental/v2";
|
|
9
|
-
import type { ClaudeAcpAgent } from "../acp-agent.js";
|
|
10
|
-
/**
|
|
11
|
-
* Starts a turn for `params`, and answers when Claude Code takes the prompt
|
|
12
|
-
* in. `send` delivers a session update of the prompt's session; it must not
|
|
13
|
-
* throw, and must deliver updates in the order it is called, also relative to
|
|
14
|
-
* the agent's own updates.
|
|
15
|
-
*
|
|
16
|
-
* - Taken in: the prompt's `user_message`, then `running`, then the answer.
|
|
17
|
-
* - Waiting on a permission request or a question: `requires_action`, and
|
|
18
|
-
* `running` once none is open.
|
|
19
|
-
* - Ended: `idle` with the stop reason, usage, and `_meta` of the turn.
|
|
20
|
-
* - Failed after it was taken in: `idle` with {@link FAILED_STOP_REASON} and
|
|
21
|
-
* the JSON-RPC error that v1 answers with in `_meta.claudeCode.error`, and
|
|
22
|
-
* an error `notice` before it that shows the failure. v2 has no error on
|
|
23
|
-
* `idle`, and a notice must not be the only report of a failure.
|
|
24
|
-
* - Ended or failed before it was taken in: the answer is a JSON-RPC error,
|
|
25
|
-
* `-32800` for a prompt that a cancel ended in the queue.
|
|
26
|
-
*
|
|
27
|
-
* Deferred decision: a turn whose background subagents still run ends only
|
|
28
|
-
* when they finish (`Turn.deferredSettle`), so `idle` waits for them too. The
|
|
29
|
-
* hold exists for v1, whose clients stop listening at the prompt response.
|
|
30
|
-
* v2 allows background updates while idle, so it could report `idle` at the
|
|
31
|
-
* turn's result instead, with a turn event for the hold. To be decided with
|
|
32
|
-
* async tasks (step 6 in `docs/acp-v2.md`).
|
|
33
|
-
*/
|
|
34
|
-
export declare function v2Prompt(agent: ClaudeAcpAgent, params: v2.PromptRequest, send: (update: v2.SessionUpdate) => void): Promise<v2.PromptResponse>;
|
|
35
|
-
/**
|
|
36
|
-
* The stop reason of a turn that failed after it was taken in. v2's stop
|
|
37
|
-
* reasons all describe work that ended without an error, and a custom one
|
|
38
|
-
* starts with `_`; clients show it as a generic stop.
|
|
39
|
-
*/
|
|
40
|
-
export declare const FAILED_STOP_REASON = "_error";
|
|
41
|
-
/**
|
|
42
|
-
* A v2 prompt may hold content blocks that v1 cannot express: a custom one,
|
|
43
|
-
* or one from a newer ACP version. Clients send only the kinds the agent
|
|
44
|
-
* advertised, so such a block is rejected rather than silently dropped.
|
|
45
|
-
*/
|
|
46
|
-
export declare function v1PromptRequest({ prompt, ...request }: v2.PromptRequest): PromptRequest;
|
|
47
|
-
//# sourceMappingURL=prompt.d.ts.map
|
package/dist/v2/prompt.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/v2/prompt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAIL,KAAK,aAAa,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,0CAA0C,CAAC;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAItD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,EAAE,CAAC,aAAa,EACxB,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,aAAa,KAAK,IAAI,GACvC,OAAO,CAAC,EAAE,CAAC,cAAc,CAAC,CA0D5B;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,WAAW,CAAC;AA2B3C;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,EAAE,EAAE,CAAC,aAAa,GAAG,aAAa,CAEvF"}
|
package/dist/v2/prompt.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ACP v2 `session/prompt`, served through the turn events of `ClaudeAcpAgent`.
|
|
3
|
-
*
|
|
4
|
-
* v2 answers the prompt once Claude Code takes it in, with the id of the user
|
|
5
|
-
* message it became, and reports the rest of the turn as `state_update`s.
|
|
6
|
-
*/
|
|
7
|
-
import { RequestError, } from "@agentclientprotocol/sdk";
|
|
8
|
-
import * as v2 from "@agentclientprotocol/sdk/experimental/v2";
|
|
9
|
-
import { splitNoticeText } from "../session-notices.js";
|
|
10
|
-
/**
|
|
11
|
-
* Starts a turn for `params`, and answers when Claude Code takes the prompt
|
|
12
|
-
* in. `send` delivers a session update of the prompt's session; it must not
|
|
13
|
-
* throw, and must deliver updates in the order it is called, also relative to
|
|
14
|
-
* the agent's own updates.
|
|
15
|
-
*
|
|
16
|
-
* - Taken in: the prompt's `user_message`, then `running`, then the answer.
|
|
17
|
-
* - Waiting on a permission request or a question: `requires_action`, and
|
|
18
|
-
* `running` once none is open.
|
|
19
|
-
* - Ended: `idle` with the stop reason, usage, and `_meta` of the turn.
|
|
20
|
-
* - Failed after it was taken in: `idle` with {@link FAILED_STOP_REASON} and
|
|
21
|
-
* the JSON-RPC error that v1 answers with in `_meta.claudeCode.error`, and
|
|
22
|
-
* an error `notice` before it that shows the failure. v2 has no error on
|
|
23
|
-
* `idle`, and a notice must not be the only report of a failure.
|
|
24
|
-
* - Ended or failed before it was taken in: the answer is a JSON-RPC error,
|
|
25
|
-
* `-32800` for a prompt that a cancel ended in the queue.
|
|
26
|
-
*
|
|
27
|
-
* Deferred decision: a turn whose background subagents still run ends only
|
|
28
|
-
* when they finish (`Turn.deferredSettle`), so `idle` waits for them too. The
|
|
29
|
-
* hold exists for v1, whose clients stop listening at the prompt response.
|
|
30
|
-
* v2 allows background updates while idle, so it could report `idle` at the
|
|
31
|
-
* turn's result instead, with a turn event for the hold. To be decided with
|
|
32
|
-
* async tasks (step 6 in `docs/acp-v2.md`).
|
|
33
|
-
*/
|
|
34
|
-
export function v2Prompt(agent, params, send) {
|
|
35
|
-
return new Promise((resolve, reject) => {
|
|
36
|
-
let inserted = false;
|
|
37
|
-
const events = {
|
|
38
|
-
inserted(messageId) {
|
|
39
|
-
inserted = true;
|
|
40
|
-
send({ sessionUpdate: "user_message", messageId, content: params.prompt });
|
|
41
|
-
send({ sessionUpdate: "state_update", state: "running" });
|
|
42
|
-
resolve({ messageId });
|
|
43
|
-
},
|
|
44
|
-
awaitingUser() {
|
|
45
|
-
send({ sessionUpdate: "state_update", state: "requires_action" });
|
|
46
|
-
},
|
|
47
|
-
resumed() {
|
|
48
|
-
send({ sessionUpdate: "state_update", state: "running" });
|
|
49
|
-
},
|
|
50
|
-
ended(outcome) {
|
|
51
|
-
if (inserted) {
|
|
52
|
-
send(idle(outcome));
|
|
53
|
-
}
|
|
54
|
-
else if (outcome.stopReason === "cancelled") {
|
|
55
|
-
reject(RequestError.requestCancelled());
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
reject(RequestError.internalError({ stopReason: outcome.stopReason }, "The turn ended before Claude Code took the prompt in"));
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
failed(error, title) {
|
|
62
|
-
if (!inserted) {
|
|
63
|
-
reject(error);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const failure = jsonRpcError(error);
|
|
67
|
-
send({
|
|
68
|
-
sessionUpdate: "notice",
|
|
69
|
-
severity: "error",
|
|
70
|
-
...splitNoticeText(title ?? failure.message, "The turn failed"),
|
|
71
|
-
});
|
|
72
|
-
send({
|
|
73
|
-
sessionUpdate: "state_update",
|
|
74
|
-
state: "idle",
|
|
75
|
-
stopReason: FAILED_STOP_REASON,
|
|
76
|
-
_meta: { claudeCode: { error: failure } },
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
let request;
|
|
81
|
-
try {
|
|
82
|
-
request = v1PromptRequest(params);
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
reject(error);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
agent.startTurn(request, events).catch(reject);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* The stop reason of a turn that failed after it was taken in. v2's stop
|
|
93
|
-
* reasons all describe work that ended without an error, and a custom one
|
|
94
|
-
* starts with `_`; clients show it as a generic stop.
|
|
95
|
-
*/
|
|
96
|
-
export const FAILED_STOP_REASON = "_error";
|
|
97
|
-
/** The JSON-RPC error that v1 answers a failed prompt with. */
|
|
98
|
-
function jsonRpcError(error) {
|
|
99
|
-
if (error instanceof RequestError) {
|
|
100
|
-
return {
|
|
101
|
-
code: error.code,
|
|
102
|
-
message: error.message,
|
|
103
|
-
...(error.data !== undefined ? { data: error.data } : {}),
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
code: RequestError.internalError().code,
|
|
108
|
-
message: error instanceof Error ? error.message : String(error),
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function idle({ stopReason, usage, _meta }) {
|
|
112
|
-
return {
|
|
113
|
-
sessionUpdate: "state_update",
|
|
114
|
-
state: "idle",
|
|
115
|
-
stopReason,
|
|
116
|
-
...(usage ? { usage } : {}),
|
|
117
|
-
...(_meta ? { _meta } : {}),
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* A v2 prompt may hold content blocks that v1 cannot express: a custom one,
|
|
122
|
-
* or one from a newer ACP version. Clients send only the kinds the agent
|
|
123
|
-
* advertised, so such a block is rejected rather than silently dropped.
|
|
124
|
-
*/
|
|
125
|
-
export function v1PromptRequest({ prompt, ...request }) {
|
|
126
|
-
return { ...request, prompt: prompt.map(v1ContentBlock) };
|
|
127
|
-
}
|
|
128
|
-
function v1ContentBlock(block) {
|
|
129
|
-
if (v2.ContentBlock.isText(block) ||
|
|
130
|
-
v2.ContentBlock.isImage(block) ||
|
|
131
|
-
v2.ContentBlock.isAudio(block) ||
|
|
132
|
-
v2.ContentBlock.isResourceLink(block) ||
|
|
133
|
-
v2.ContentBlock.isResource(block)) {
|
|
134
|
-
const { annotations, ...rest } = block;
|
|
135
|
-
return annotations != null ? { ...rest, annotations: v1Annotations(annotations) } : rest;
|
|
136
|
-
}
|
|
137
|
-
throw RequestError.invalidParams({ type: block.type }, `Content blocks of type ${block.type} are not supported`);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* v2 also accepts audiences of a newer ACP version; v1 knows two. An audience
|
|
141
|
-
* of only unknown roles is dropped rather than narrowed to nobody.
|
|
142
|
-
*/
|
|
143
|
-
function v1Annotations({ audience, ...annotations }) {
|
|
144
|
-
if (audience == null)
|
|
145
|
-
return annotations;
|
|
146
|
-
const known = audience.filter(isV1Role);
|
|
147
|
-
return known.length > 0 || audience.length === 0
|
|
148
|
-
? { ...annotations, audience: known }
|
|
149
|
-
: annotations;
|
|
150
|
-
}
|
|
151
|
-
function isV1Role(role) {
|
|
152
|
-
return role === "assistant" || role === "user";
|
|
153
|
-
}
|
package/dist/v2/terminal.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/v2/terminal.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
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
|
-
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
|
-
}
|
package/dist/v2/tool-call.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/v2/tool-call.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
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
|
-
}
|