mirror of
https://github.com/agentclientprotocol/claude-agent-acp.git
synced 2026-10-27 12:40:32 +00:00
Do not send tool_call_update for TodoWrite (#10)
When we receive a `TodoWrite` tool use, we send a plan update instead of a tool call. However, we were still trying to send a tool call update when we received the `TodoWrite` tool result, which caused an ACP error. Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de>
This commit is contained in:
@@ -440,14 +440,16 @@ function promptToClaude(prompt: PromptRequest): SDKUserMessage {
|
|||||||
export function toAcpNotifications(
|
export function toAcpNotifications(
|
||||||
message: SDKAssistantMessage | SDKUserMessage,
|
message: SDKAssistantMessage | SDKUserMessage,
|
||||||
sessionId: string,
|
sessionId: string,
|
||||||
toolUseCache: { [key: string]: any },
|
toolUseCache: {
|
||||||
|
[key: string]: { type: "tool_use"; id: string; name: string; input: any };
|
||||||
|
},
|
||||||
fileContentCache: { [key: string]: string },
|
fileContentCache: { [key: string]: string },
|
||||||
): SessionNotification[] {
|
): SessionNotification[] {
|
||||||
let chunks = message.message.content as ContentChunk[];
|
let chunks = message.message.content as ContentChunk[];
|
||||||
let output = [];
|
let output = [];
|
||||||
// Only handle the first chunk for streaming; extend as needed for batching
|
// Only handle the first chunk for streaming; extend as needed for batching
|
||||||
for (const chunk of chunks) {
|
for (const chunk of chunks) {
|
||||||
let update: SessionNotification["update"];
|
let update: SessionNotification["update"] | null = null;
|
||||||
switch (chunk.type) {
|
switch (chunk.type) {
|
||||||
case "text":
|
case "text":
|
||||||
update = {
|
update = {
|
||||||
@@ -497,19 +499,32 @@ export function toAcpNotifications(
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "tool_result":
|
case "tool_result": {
|
||||||
update = {
|
const toolUse = toolUseCache[chunk.tool_use_id];
|
||||||
toolCallId: chunk.tool_use_id,
|
if (!toolUse) {
|
||||||
sessionUpdate: "tool_call_update",
|
console.error(
|
||||||
status: chunk.is_error ? "failed" : "completed",
|
`[claude-code-acp] Got a tool result for tool use that wasn't tracked: ${chunk.tool_use_id}`,
|
||||||
...toolUpdateFromToolResult(chunk, toolUseCache[chunk.tool_use_id]),
|
);
|
||||||
};
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toolUse.name !== "TodoWrite") {
|
||||||
|
update = {
|
||||||
|
toolCallId: chunk.tool_use_id,
|
||||||
|
sessionUpdate: "tool_call_update",
|
||||||
|
status: chunk.is_error ? "failed" : "completed",
|
||||||
|
...toolUpdateFromToolResult(chunk, toolUseCache[chunk.tool_use_id]),
|
||||||
|
};
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error("unhandled chunk type: " + chunk.type);
|
throw new Error("unhandled chunk type: " + chunk.type);
|
||||||
}
|
}
|
||||||
output.push({ sessionId, update });
|
if (update) {
|
||||||
|
output.push({ sessionId, update });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
|||||||
Reference in New Issue
Block a user