import { Message } from "../contracts/conversation-message.type.mjs"; import { AIError } from "../errors/ai-error.mjs"; import { Usage } from "../contracts/result/usage.type.mjs"; import { ModelCallOptions, ModelContract } from "../contracts/model.contract.mjs"; import { StandardSchemaV1 } from "@standard-schema/spec"; //#region ../ai/src/object-stream/stream-object.d.ts /** * One event in a {@link streamObject} run. * * - `text-delta` — the raw token text as it streams (for a "typing" view). * - `partial` — a best-effort snapshot of the object so far, re-parsed * from the accumulated text on each delta (only emitted when it changed). * - `done` — terminal: the final text is strictly parsed and validated * against the schema. `valid` + `value` on success; `valid: false` + * `error` when the output wasn't valid JSON or failed the schema. */ type ObjectStreamEvent = { type: "text-delta"; delta: string; } | { type: "partial"; value: unknown; } | { type: "done"; valid: true; value: T; usage: Usage; } | { type: "done"; valid: false; error: AIError; usage: Usage; }; /** Parameters for {@link streamObject}. */ type StreamObjectParams = { /** The model to stream from (e.g. `sdk.model({ name })`). */model: ModelContract; /** The prompt messages. */ messages: Message[]; /** Standard Schema the final object is validated against. */ schema: StandardSchemaV1; /** Extra model call options (e.g. `responseSchema`, `temperature`). */ options?: ModelCallOptions; }; /** * Stream a structured object: emit raw token deltas, progressively-parsed * partial-object snapshots, and a final strictly-validated object — the * first-class structured-output streaming primitive (A1). Reuses the * model's existing `stream()` seam; the partial snapshots come from a * tolerant {@link parsePartialJson}, while the terminal `done` event is a * strict `JSON.parse` + schema validation, so an over-eager partial parse * never affects the authoritative result. * * Pair it with a `structuredOutput`-capable model and a `responseSchema` * (via `options`) for the cleanest JSON; otherwise prompt the model to * reply with JSON only. * * @example * for await (const event of streamObject({ model, messages, schema })) { * if (event.type === "partial") render(event.value); // live UI * if (event.type === "done" && event.valid) save(event.value); // final * } */ declare function streamObject(params: StreamObjectParams): AsyncIterable>; /** Collect a {@link streamObject} run down to just its terminal event. */ declare function collectStreamObject(stream: AsyncIterable>): Promise, { type: "done"; }>>; //#endregion export { ObjectStreamEvent, StreamObjectParams, collectStreamObject, streamObject }; //# sourceMappingURL=stream-object.d.mts.map