* fix(server): graceful stream termination on cancellation (issue #847) * Update the code with review suggestion
This commit is contained in:
@@ -84,6 +84,7 @@ export async function* chatStream(
|
||||
});
|
||||
|
||||
for await (const event of stream) {
|
||||
if (event.data == null) continue;
|
||||
yield {
|
||||
type: event.event,
|
||||
data: JSON.parse(event.data),
|
||||
|
||||
@@ -84,10 +84,20 @@ export interface CitationsEvent {
|
||||
};
|
||||
}
|
||||
|
||||
export interface ErrorEvent {
|
||||
type: "error";
|
||||
data: {
|
||||
thread_id: string;
|
||||
error: string;
|
||||
reason?: "cancelled" | string;
|
||||
};
|
||||
}
|
||||
|
||||
export type ChatEvent =
|
||||
| MessageChunkEvent
|
||||
| ToolCallsEvent
|
||||
| ToolCallChunksEvent
|
||||
| ToolCallResultEvent
|
||||
| InterruptEvent
|
||||
| CitationsEvent;
|
||||
| CitationsEvent
|
||||
| ErrorEvent;
|
||||
|
||||
Reference in New Issue
Block a user