UNPKG

@tanstack/ai

Version:

Core TanStack AI library - Open source AI SDK

49 lines (48 loc) 1.16 kB
import { EventType } from "@ag-ui/core"; function createId(prefix) { return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`; } async function* streamGenerationResult(generator, options) { const runId = createId("run"); const threadId = createId("thread"); yield { type: EventType.RUN_STARTED, runId, threadId, timestamp: Date.now() }; try { const result = await generator(); yield { type: EventType.CUSTOM, name: "generation:result", value: result, timestamp: Date.now() }; yield { type: EventType.RUN_FINISHED, runId, threadId, finishReason: "stop", timestamp: Date.now() }; } catch (error) { yield { type: EventType.RUN_ERROR, runId, threadId, message: error.message || "Generation failed", code: error.code, // Deprecated nested form for backward compatibility error: { message: error.message || "Generation failed", code: error.code }, timestamp: Date.now() }; } } export { streamGenerationResult }; //# sourceMappingURL=stream-generation-result.js.map