/** * @license * Copyright 2025 Steven Roussey * SPDX-License-Identifier: Apache-2.0 */ import type { IExecuteContext, StreamEvent, TaskConfig, TaskOutput } from "@workglow/task-graph"; import type { AiTaskInput } from "./AiTask"; import { AiTask } from "./AiTask"; /** * A base class for streaming AI tasks. * Extends AiTask to provide streaming output via executeStream(). * * Subclasses set `streamMode` to control streaming behavior: * - 'append': each chunk is a delta (e.g., a new token). Default for text generation. * - 'object': each chunk is a progressively more complete partial object. * - 'replace': each chunk is a revised full snapshot of the output. * * The standard execute() method is preserved as a fallback that internally * consumes the stream to completion (so non-streaming callers get the same result). * * Port annotation: providers yield raw events without a `port` field. * This class wraps text-delta events with the correct port from the task's * output schema before they reach the TaskRunner. * * @cancel The `context.signal` is forwarded to the resolved execution strategy * (direct or queued), which in turn forwards it to the provider stream function. * When the signal fires, the underlying provider SDK tears down its connection * and the inner `for await` exits; this generator then returns or throws * promptly. Consumer-driven cancellation (an early `break` from the * `for await` consuming this generator) is also propagated: see * {@link runWithIterable} for the mechanism that converts a closed * consumer into an aborted provider signal. Partial accumulated text / * object state may still remain in task or runner state after abort (the * runner does not clear `runOutputData`) and MUST be treated as invalid * unless the final run status is `COMPLETED`. Subclasses overriding * `executeStream()` MUST preserve this contract: forward `context.signal`, * and either return or throw promptly after abort. */ export declare class StreamingAiTask = TaskConfig> extends AiTask { static type: string; /** * Phase label emitted before the underlying provider stream begins * producing data events. Override in subclasses for task-specific * pre-stream phases (e.g. "Uploading" for tasks that prepare large * inputs). */ protected static readonly preparingPhaseLabel: string; /** * Phase label emitted on the first data event from the underlying * provider stream (text-delta / object-delta / snapshot). Override in * subclasses to reflect what the task is producing — "Generating", * "Summarizing", "Translating", "Rendering", etc. */ protected static readonly streamingPhaseLabel: string; /** * Streaming execution: resolves the provider strategy and yields StreamEvents from it. * Routes through the same strategy as execute() (queued vs direct) so GPU * serialization is respected even for streaming tasks. * * Wraps port-less text-delta and object-delta events from providers with * the port determined by the task's output schema `x-stream` annotations. */ executeStream(input: Input, context: IExecuteContext): AsyncIterable>; } //# sourceMappingURL=StreamingAiTask.d.ts.map