2Branches0Tags
GL
glucryptoFix trade candle loading via gateway
typescript
import { createAIClient, type StreamTextOptions } from "opentool/ai"; export async function collectStreamText(params: { ai: ReturnType<typeof createAIClient>; options: Omit<StreamTextOptions, "handlers">; errorMessage: string; }) { let text = ""; const stream = await params.ai.streamText({ ...params.options, handlers: { onTextDelta(delta) { text += delta; }, }, }); await stream.finished; const trimmed = text.trim(); if (!trimmed) { throw new Error(params.errorMessage); } return trimmed; }