Fix empty content_block_stop handler to finalize tool input and emit item.updated
The content_block_stop handler retrieved the in-flight tool but did nothing with it — no event emission, no state update. This was dead code. content_block_stop signals that a content block's streaming is complete. For tool_use blocks, this means the input JSON is fully streamed. The handler now: 1. Finalizes the accumulated partial JSON input 2. Updates the tool in inFlightTools with the parsed input 3. Emits an item.updated event with the complete tool state This ensures the UI always receives the final, complete tool input even if the last input_json_delta didn't trigger an update due to fingerprint deduplication. Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
1 parent
fdcb05d3f6
commit
f5a4bbcb1c
1 file changed
+46
@@ -1148,6 +1148,52 @@ function makeClaudeCodeAdapter(options?: ClaudeCodeAdapterLiveOptions) {
|
||||
if (!tool) {
|
||||
return;
|
||||
}
|
||||
|
||||
let finalTool = tool;
|
||||
if (tool.partialInputJson.length > 0) {
|
||||
const parsedInput = tryParseJsonRecord(tool.partialInputJson);
|
||||
if (parsedInput) {
|
||||
const detail = summarizeToolRequest(tool.toolName, parsedInput);
|
||||
finalTool = {
|
||||
...tool,
|
||||
input: parsedInput,
|
||||
...(detail ? { detail } : {}),
|
||||
};
|
||||
context.inFlightTools.set(index, finalTool);
|
||||
}
|
||||
}
|
||||
|
||||
const stamp = yield* makeEventStamp();
|
||||
yield* offerRuntimeEvent({
|
||||
type: "item.updated",
|
||||
eventId: stamp.eventId,
|
||||
provider: PROVIDER,
|
||||
createdAt: stamp.createdAt,
|
||||
threadId: context.session.threadId,
|
||||
...(context.turnState ? { turnId: asCanonicalTurnId(context.turnState.turnId) } : {}),
|
||||
itemId: asRuntimeItemId(finalTool.itemId),
|
||||
payload: {
|
||||
itemType: finalTool.itemType,
|
||||
status: "inProgress",
|
||||
title: finalTool.title,
|
||||
...(finalTool.detail ? { detail: finalTool.detail } : {}),
|
||||
data: {
|
||||
toolName: finalTool.toolName,
|
||||
input: finalTool.input,
|
||||
},
|
||||
},
|
||||
providerRefs: {
|
||||
...providerThreadRef(context),
|
||||
...(context.turnState ? { providerTurnId: String(context.turnState.turnId) } : {}),
|
||||
providerItemId: ProviderItemId.makeUnsafe(finalTool.itemId),
|
||||
},
|
||||
raw: {
|
||||
source: "claude.sdk.message",
|
||||
method: "claude/stream_event/content_block_stop",
|
||||
payload: message,
|
||||
},
|
||||
});
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user