import { Effect, Stream } from "effect" import { LLMClient } from "../../src/route.js" import type { StreamOptions } from "../../src/route/client.js" import { LLMResponse, type LLMRequest } from "../../src/schema/index.js" /** Run one call like `LLMClient.generate`, keeping its events for tests that assert what a protocol emitted. */ export const generateResponse = (request: LLMRequest, options?: StreamOptions) => Effect.gen(function* () { const response = LLMResponse.fromEvents( Array.from(yield* LLMClient.stream(request, options).pipe(Stream.runCollect)), ) if (response) return response return yield* Effect.die(new Error("The stream ended without a finish event")) })