/** * @license * Copyright 2026 Steven Roussey * SPDX-License-Identifier: Apache-2.0 */ import type { StreamEvent, TaskOutput } from "@workglow/task-graph"; /** * Stateful accumulator that materialises a single output `T` from a sequence * of {@link StreamEvent}s. * * - `text-delta` per port → concatenated per port (`Map`). * - `object-delta` non-array → replace semantics (each delta is a more * complete partial snapshot — last wins per port). * - `object-delta` array → upsert by `id` per port. * - `snapshot` → replace running state (last snapshot wins). * - `phase` → ignored (metadata only). * - `error` → throws immediately at observe time. * - `finish` → captured separately via {@link observeFinish}; mandatory before * {@link materialize}. * * Mixed-mode (both text-delta and object-delta on the same stream) is * rejected at materialise time. * * This accumulator is **only** instantiated at explicit terminal-consumer * sites (AiTask.execute, StreamProcessor `ctx.shouldAccumulate` branch). Do * not use it inside run-fns, workers, AiJob, strategies, or dataflow nodes — * streams in this codebase can be conceptually unbounded. */ /** * Discriminating tag attached to the error thrown by * {@link StreamEventAccumulator.materialize} when the underlying stream * ended (cleanly or otherwise) without ever emitting a `finish` event. * Callers (notably `AiTask.execute`) re-throw with this code preserved so * upstream code can distinguish "provider produced no terminal event" from * other provider failures. */ export declare const ACCUMULATOR_NO_FINISH: "ACCUMULATOR_NO_FINISH"; export declare class StreamEventAccumulator { private readonly textAccumulator; private readonly objectAccumulator; private hasTextDeltas; private hasObjectDeltas; private hasSnapshots; private snapshotAccumulator; private finished; private finishData; /** * The `type` of the most recent observed event. Surfaced in the * no-finish materialise error so operators can see what the stream * trailed off with (e.g. `text-delta`, `phase`, `undefined`). */ private lastEventType; observe(event: StreamEvent): void; observeFinish(event: Extract, { type: "finish"; }>): void; materialize(): T; } //# sourceMappingURL=StreamEventAccumulator.d.ts.map