Add tool call streaming and tool execution results to chat endpoint

Extend the Vercel stream listener to handle toolcall_start,
toolcall_delta, toolcall_end, and tool_execution_end events.
Maps to tool-input-start, tool-input-delta, tool-input-available,
and tool-output-available/tool-output-error Vercel SDK chunk types.
This commit is contained in:
Harivansh Rathi 2026-03-06 01:21:40 -08:00
parent f83648c5c5
commit fcd51005e2

View file

@ -95,6 +95,36 @@ export function createVercelStreamListener(
id: `text_${inner.contentIndex}`,
});
return;
case "toolcall_start": {
const content = inner.partial.content[inner.contentIndex];
if (content?.type === "toolCall") {
writeChunk(response, {
type: "tool-input-start",
toolCallId: content.id,
toolName: content.name,
});
}
return;
}
case "toolcall_delta": {
const content = inner.partial.content[inner.contentIndex];
if (content?.type === "toolCall") {
writeChunk(response, {
type: "tool-input-delta",
toolCallId: content.id,
inputTextDelta: inner.delta,
});
}
return;
}
case "toolcall_end":
writeChunk(response, {
type: "tool-input-available",
toolCallId: inner.toolCall.id,
toolName: inner.toolCall.name,
input: inner.toolCall.arguments,
});
return;
}
return;
}
@ -102,6 +132,22 @@ export function createVercelStreamListener(
case "turn_end":
writeChunk(response, { type: "finish-step" });
return;
case "tool_execution_end":
if (event.isError) {
writeChunk(response, {
type: "tool-output-error",
toolCallId: event.toolCallId,
errorText: typeof event.result === "string" ? event.result : JSON.stringify(event.result),
});
} else {
writeChunk(response, {
type: "tool-output-available",
toolCallId: event.toolCallId,
output: typeof event.result === "string" ? event.result : JSON.stringify(event.result),
});
}
return;
}
};
}