Initial commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import type { UIMessageChunk } from "ai";
|
||||
|
||||
export type BackendSseEvent = {
|
||||
event: string;
|
||||
data: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export function backendEventToUiChunk(
|
||||
item: BackendSseEvent,
|
||||
textId: string,
|
||||
): UIMessageChunk | null {
|
||||
if (item.event === "text_delta") {
|
||||
return { type: "text-delta", id: textId, delta: String(item.data.text || "") };
|
||||
}
|
||||
if (item.event === "progress") {
|
||||
return {
|
||||
type: "data-cad-progress",
|
||||
id: `progress_${String(item.data.step || Date.now())}`,
|
||||
data: item.data,
|
||||
};
|
||||
}
|
||||
if (item.event === "cad_result") {
|
||||
return {
|
||||
type: "data-cad-result",
|
||||
id: `result_${String(item.data.taskId || Date.now())}`,
|
||||
data: item.data,
|
||||
};
|
||||
}
|
||||
if (item.event === "cad_error") {
|
||||
return {
|
||||
type: "data-cad-error",
|
||||
id: `error_${Date.now()}`,
|
||||
data: item.data,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user