mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 05:02:07 +00:00
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:
parent
f83648c5c5
commit
fcd51005e2
1 changed files with 46 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue