/** * @license * Copyright 2025 Steven Roussey * SPDX-License-Identifier: Apache-2.0 */ import type { IExecuteContext, IRunConfig, StreamEvent, TaskConfig } from "@workglow/task-graph"; import { CreateWorkflow, TaskError } from "@workglow/task-graph"; import type { DataPortSchema } from "@workglow/util/schema"; import type { ModelConfig } from "../model/ModelSchema"; import { StreamingAiTask } from "./base/StreamingAiTask"; export declare const StructuredGenerationInputSchema: { readonly type: "object"; readonly properties: { readonly model: { readonly oneOf: readonly [{ readonly title: "Model"; readonly description: `The model ${string}`; } & Record & { readonly format: import(".").TypeModelSemantic; readonly type: "string"; }, { readonly type: "object"; readonly properties: { readonly model_id: { readonly type: "string"; }; readonly capabilities: { readonly type: "array"; readonly items: { readonly type: "string"; }; readonly "x-ui-editor": "multiselect"; }; readonly title: { readonly type: "string"; }; readonly description: { readonly type: "string"; readonly "x-ui-editor": "textarea"; }; readonly provider: { readonly type: "string"; }; readonly provider_config: { readonly type: "object"; readonly properties: { readonly credential_key: { readonly type: "string"; readonly format: "credential"; readonly "x-ui-hidden": true; }; readonly native_dimensions: { readonly type: "integer"; readonly description: "Native output vector dimensions for embedding models"; }; readonly mrl: { readonly type: "boolean"; readonly description: "Whether the model supports Matryoshka Representation Learning"; }; }; readonly additionalProperties: true; readonly default: {}; }; readonly metadata: { readonly type: "object"; readonly default: {}; readonly "x-ui-hidden": true; }; }; readonly required: readonly ["provider", "provider_config"]; readonly format: "model"; readonly additionalProperties: true; } & Record & { readonly format: import(".").TypeModelSemantic; }]; } & Record & { readonly format: import(".").TypeModelSemantic; }; readonly prompt: { readonly type: "string"; readonly title: "Prompt"; readonly description: "The prompt to generate structured output from"; }; readonly outputSchema: { readonly type: "object"; readonly title: "Output Schema"; readonly description: "JSON Schema describing the desired output structure"; readonly additionalProperties: true; }; readonly maxTokens: { readonly type: "number"; readonly title: "Max Tokens"; readonly description: "The maximum number of tokens to generate"; readonly minimum: 1; readonly maximum: 4096; readonly "x-ui-group": "Configuration"; }; readonly temperature: { readonly type: "number"; readonly title: "Temperature"; readonly description: "The temperature to use for sampling"; readonly minimum: 0; readonly maximum: 2; readonly "x-ui-group": "Configuration"; }; readonly maxRetries: { readonly type: "integer"; readonly title: "Max Retries"; readonly description: "Number of times to re-prompt the model with validation errors when its output doesn't match the schema. 0 disables retries (fail on first mismatch)."; readonly minimum: 0; readonly maximum: 10; readonly default: 2; readonly "x-ui-group": "Configuration"; }; }; readonly required: readonly ["model", "prompt", "outputSchema"]; readonly additionalProperties: false; }; export declare const StructuredGenerationOutputSchema: { readonly type: "object"; readonly properties: { readonly object: { readonly type: "object"; readonly title: "Structured Output"; readonly description: "The generated structured object conforming to the provided schema"; readonly "x-stream": "object"; readonly "x-structured-output": true; readonly additionalProperties: true; }; }; readonly required: readonly ["object"]; readonly additionalProperties: false; }; export type StructuredGenerationTaskInput = { maxTokens?: number | undefined; temperature?: number | undefined; maxRetries?: number | undefined; model: string | ModelConfig; prompt: string; outputSchema: { [x: string]: unknown; }; }; export type StructuredGenerationTaskOutput = { object: { [x: string]: unknown; }; }; export type StructuredGenerationTaskConfig = TaskConfig; /** * One round of validation errors from a failed attempt. */ export interface StructuredOutputValidationAttempt { readonly attempt: number; readonly errors: ReadonlyArray<{ readonly path: string; readonly message: string; }>; /** The invalid object the model produced on this attempt. */ readonly object: Record | undefined; } /** * Thrown when the model's output fails schema validation on every attempt * (including retries). */ export declare class StructuredOutputValidationError extends TaskError { static readonly type: string; readonly attempts: ReadonlyArray; constructor(attempts: ReadonlyArray); } export declare class StructuredGenerationTask extends StreamingAiTask { static type: string; /** Capabilities required of the model; gated in {@link StreamingAiTask.executeStream}. */ static readonly requires: ["json-mode"]; protected static readonly streamingPhaseLabel = "Generating"; static category: string; static title: string; static description: string; static inputSchema(): DataPortSchema; static outputSchema(): DataPortSchema; /** * Runs the provider, validates the resulting object against `input.outputSchema`, * and retries with validation-error feedback up to `input.maxRetries` times if * the model's output doesn't match. Between attempts, emits an empty * object-delta so downstream accumulators reset. * * Throws: * - `TaskConfigurationError` if `input.outputSchema` isn't a compilable JSON Schema. * - `StructuredOutputValidationError` if every attempt fails validation. */ executeStream(input: StructuredGenerationTaskInput, context: IExecuteContext): AsyncIterable>; /** * Drains executeStream so non-streaming callers get the validated output. * Without this override, `execute()` would route through the base class's * non-streaming path and bypass validation + retry entirely. */ execute(input: StructuredGenerationTaskInput, context: IExecuteContext): Promise; } export declare const structuredGeneration: (input: StructuredGenerationTaskInput, config?: StructuredGenerationTaskConfig, runConfig?: Partial) => Promise; declare module "@workglow/task-graph" { interface Workflow { structuredGeneration: CreateWorkflow; } } //# sourceMappingURL=StructuredGenerationTask.d.ts.map