Add reasoning events and abort-aware finish reason to chat endpoint

Map thinking_start/delta/end to Vercel AI SDK reasoning-start/delta/end
chunk types. Derive finish reason from enqueueMessage result - aborted
sessions get a clean finish with reason "error" instead of an error chunk.
This commit is contained in:
Harivansh Rathi 2026-03-06 01:25:22 -08:00
parent fcd51005e2
commit 8a61de15fa
2 changed files with 25 additions and 1 deletions

View file

@ -637,10 +637,15 @@ export class GatewayRuntime {
unsubscribe();
if (result.ok) {
finishVercelStream(response, "stop");
} else {
const isAbort = result.error?.includes("aborted");
if (isAbort) {
finishVercelStream(response, "error");
} else {
errorVercelStream(response, result.error ?? "Unknown error");
}
}
}
} catch (error) {
if (!clientDisconnected) {
unsubscribe();

View file

@ -125,6 +125,25 @@ export function createVercelStreamListener(
input: inner.toolCall.arguments,
});
return;
case "thinking_start":
writeChunk(response, {
type: "reasoning-start",
id: `reasoning_${inner.contentIndex}`,
});
return;
case "thinking_delta":
writeChunk(response, {
type: "reasoning-delta",
id: `reasoning_${inner.contentIndex}`,
delta: inner.delta,
});
return;
case "thinking_end":
writeChunk(response, {
type: "reasoning-end",
id: `reasoning_${inner.contentIndex}`,
});
return;
}
return;
}