export type WorkflowJSONPrimitive = string | number | boolean | null; export type WorkflowJSONValue = | WorkflowJSONPrimitive | { readonly [key: string]: WorkflowJSONValue } | readonly WorkflowJSONValue[]; export type WorkflowJSONSchemaType = | "object" | "array" | "string" | "number" | "integer" | "boolean" | "null"; /** Plain JSON Schema subset validated by the workflow runtime. */ export interface WorkflowJSONSchema { readonly type?: WorkflowJSONSchemaType | readonly WorkflowJSONSchemaType[]; readonly enum?: readonly WorkflowJSONValue[]; readonly properties?: Readonly>; readonly required?: readonly string[]; readonly additionalProperties?: boolean; readonly items?: WorkflowJSONSchema; readonly minItems?: number; readonly maxItems?: number; } export interface WorkflowPhase { readonly title: string; readonly detail?: string; readonly [key: string]: WorkflowJSONValue | undefined; } export interface WorkflowMeta { readonly name: string; readonly description: string; readonly whenToUse?: string; readonly phases?: readonly WorkflowPhase[]; readonly [key: string]: | WorkflowJSONValue | readonly WorkflowPhase[] | undefined; } export type WorkflowThinkingLevel = | "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max"; export interface WorkflowAgentOptions { readonly schema?: WorkflowJSONSchema; readonly label?: string; readonly phase?: string; readonly model?: string; readonly persona?: string; readonly isolation?: "process" | "in-process"; /** Accepted for compatibility with callers; the workflow runtime ignores it. */ readonly agentType?: string; readonly thinkingLevel?: WorkflowThinkingLevel; } export type WorkflowThunk = () => T | PromiseLike; export type WorkflowPipelineStage = ( previous: TPrevious, item: TItem, index: number, ) => TResult | PromiseLike; export type WorkflowPipelineFunction = (...args: never[]) => unknown; export type WorkflowPipelineStages< TItem, TPrevious, TStages extends readonly WorkflowPipelineFunction[], > = TStages extends readonly [ infer THead extends WorkflowPipelineFunction, ...infer TTail extends readonly WorkflowPipelineFunction[], ] ? readonly [ (previous: TPrevious, item: TItem, index: number) => ReturnType, ...WorkflowPipelineStages>, TTail>, ] : readonly []; export type WorkflowPipelineResult< TStages extends readonly WorkflowPipelineFunction[], > = TStages extends readonly [ ...WorkflowPipelineFunction[], infer TLast extends WorkflowPipelineFunction, ] ? Awaited> : never; export interface WorkflowBudget { readonly total: number | null; spent(): number; remaining(): number; } declare global { function agent( prompt: string, options?: WorkflowAgentOptions & { readonly schema?: undefined }, ): Promise; function agent( prompt: string, options: WorkflowAgentOptions & { readonly schema: WorkflowJSONSchema }, ): Promise; function parallel( thunks: readonly WorkflowThunk[], ): Promise | null>>; function pipeline( items: readonly TItem[], ): Promise | null>>; function pipeline( items: readonly TItem[], stage: WorkflowPipelineStage, ): Promise | null>>; function pipeline( items: readonly TItem[], stage1: WorkflowPipelineStage, stage2: WorkflowPipelineStage, TResult2>, ): Promise | null>>; function pipeline( items: readonly TItem[], stage1: WorkflowPipelineStage, stage2: WorkflowPipelineStage, TResult2>, stage3: WorkflowPipelineStage, TResult3>, ): Promise | null>>; // Contextual overloads keep inline callbacks ergonomic. The variadic overload // below also validates longer, explicitly typed stage tuples. function pipeline( items: readonly TItem[], stage1: WorkflowPipelineStage, stage2: WorkflowPipelineStage, TResult2>, stage3: WorkflowPipelineStage, TResult3>, stage4: WorkflowPipelineStage, TResult4>, ): Promise | null>>; function pipeline( items: readonly TItem[], stage1: WorkflowPipelineStage, stage2: WorkflowPipelineStage, TResult2>, stage3: WorkflowPipelineStage, TResult3>, stage4: WorkflowPipelineStage, TResult4>, stage5: WorkflowPipelineStage, TResult5>, ): Promise | null>>; function pipeline< TItem, TResult1, TResult2, TResult3, TResult4, TResult5, TResult6, >( items: readonly TItem[], stage1: WorkflowPipelineStage, stage2: WorkflowPipelineStage, TResult2>, stage3: WorkflowPipelineStage, TResult3>, stage4: WorkflowPipelineStage, TResult4>, stage5: WorkflowPipelineStage, TResult5>, stage6: WorkflowPipelineStage, TResult6>, ): Promise | null>>; function pipeline< TItem, const TStages extends readonly WorkflowPipelineFunction[], >( items: readonly TItem[], ...stages: TStages & WorkflowPipelineStages ): Promise | null>>; function workflow( name: string, childArgs?: WorkflowJSONValue, ): Promise; function phase(title: string): void; function log(message: unknown): void; const args: WorkflowJSONValue | undefined; const cwd: string; const budget: WorkflowBudget; }