@workglow/task-graph 0.0.87 → 0.0.88

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,176 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import type { DataPortSchema } from "@workglow/util";
7
- import { TaskGraph } from "../task-graph/TaskGraph";
8
- import { GraphAsTask, GraphAsTaskConfig } from "./GraphAsTask";
9
- import type { IExecuteContext } from "./ITask";
10
- import type { TaskInput, TaskOutput, TaskTypeName } from "./TaskTypes";
11
- /**
12
- * Condition function type for WhileTask.
13
- * Receives the current output and iteration count, returns whether to continue looping.
14
- *
15
- * @param output - The output from the last iteration
16
- * @param iteration - The current iteration number (0-based)
17
- * @returns true to continue looping, false to stop
18
- */
19
- export type WhileConditionFn<Output> = (output: Output, iteration: number) => boolean;
20
- /**
21
- * Configuration for WhileTask.
22
- */
23
- export interface WhileTaskConfig<Output extends TaskOutput = TaskOutput> extends GraphAsTaskConfig {
24
- /**
25
- * Condition function that determines whether to continue looping.
26
- * Called after each iteration with the current output and iteration count.
27
- * Returns true to continue, false to stop.
28
- */
29
- readonly condition?: WhileConditionFn<Output>;
30
- /**
31
- * Maximum number of iterations to prevent infinite loops.
32
- * @default 100
33
- */
34
- readonly maxIterations?: number;
35
- /**
36
- * Whether to pass the output of each iteration as input to the next.
37
- * When true, output from iteration N becomes input to iteration N+1.
38
- * @default true
39
- */
40
- readonly chainIterations?: boolean;
41
- }
42
- /**
43
- * WhileTask loops until a condition function returns false.
44
- *
45
- * This task is useful for:
46
- * - Iterative refinement processes
47
- * - Polling until a condition is met
48
- * - Convergence algorithms
49
- * - Retry logic with conditions
50
- *
51
- * ## Features
52
- *
53
- * - Loops until condition returns false
54
- * - Configurable maximum iterations (safety limit)
55
- * - Passes output from each iteration to the next
56
- * - Access to iteration count in condition function
57
- *
58
- * ## Usage
59
- *
60
- * ```typescript
61
- * // Refine until quality threshold
62
- * workflow
63
- * .while({
64
- * condition: (output, iteration) => output.quality < 0.9 && iteration < 10,
65
- * maxIterations: 20
66
- * })
67
- * .refineResult()
68
- * .evaluateQuality()
69
- * .endWhile()
70
- *
71
- * // Retry until success
72
- * workflow
73
- * .while({
74
- * condition: (output) => !output.success,
75
- * maxIterations: 5
76
- * })
77
- * .attemptOperation()
78
- * .endWhile()
79
- * ```
80
- *
81
- * @template Input - The input type for the while task
82
- * @template Output - The output type for the while task
83
- * @template Config - The configuration type
84
- */
85
- export declare class WhileTask<Input extends TaskInput = TaskInput, Output extends TaskOutput = TaskOutput, Config extends WhileTaskConfig<Output> = WhileTaskConfig<Output>> extends GraphAsTask<Input, Output, Config> {
86
- static type: TaskTypeName;
87
- static category: string;
88
- static title: string;
89
- static description: string;
90
- /** This task has dynamic schemas based on the inner workflow */
91
- static hasDynamicSchemas: boolean;
92
- /**
93
- * The template subgraph that will be executed each iteration.
94
- */
95
- protected _templateGraph: TaskGraph | undefined;
96
- /**
97
- * Current iteration count during execution.
98
- */
99
- protected _currentIteration: number;
100
- constructor(input?: Partial<Input>, config?: Partial<Config>);
101
- /**
102
- * Gets the condition function.
103
- */
104
- get condition(): WhileConditionFn<Output> | undefined;
105
- /**
106
- * Gets the maximum iterations limit.
107
- */
108
- get maxIterations(): number;
109
- /**
110
- * Whether to chain iteration outputs to inputs.
111
- */
112
- get chainIterations(): boolean;
113
- /**
114
- * Gets the current iteration count.
115
- */
116
- get currentIteration(): number;
117
- /**
118
- * Sets the template graph that defines the workflow to run each iteration.
119
- */
120
- setTemplateGraph(graph: TaskGraph): void;
121
- /**
122
- * Gets the template graph.
123
- */
124
- getTemplateGraph(): TaskGraph | undefined;
125
- /**
126
- * Execute the while loop.
127
- */
128
- execute(input: Input, context: IExecuteContext): Promise<Output | undefined>;
129
- /**
130
- * Clones the template graph for a specific iteration.
131
- */
132
- protected cloneTemplateGraph(iteration: number): TaskGraph;
133
- /**
134
- * Static input schema for WhileTask.
135
- */
136
- static inputSchema(): DataPortSchema;
137
- /**
138
- * Static output schema for WhileTask.
139
- */
140
- static outputSchema(): DataPortSchema;
141
- /**
142
- * Instance output schema - returns final iteration output schema.
143
- */
144
- outputSchema(): DataPortSchema;
145
- }
146
- declare module "../task-graph/Workflow" {
147
- interface Workflow {
148
- /**
149
- * Starts a while loop that continues until a condition is false.
150
- * Use .endWhile() to close the loop and return to the parent workflow.
151
- *
152
- * @param config - Configuration for the while loop (must include condition)
153
- * @returns A Workflow in loop builder mode for defining the loop body
154
- *
155
- * @example
156
- * ```typescript
157
- * workflow
158
- * .while({
159
- * condition: (output, iteration) => output.quality < 0.9,
160
- * maxIterations: 10
161
- * })
162
- * .refineResult()
163
- * .endWhile()
164
- * ```
165
- */
166
- while: CreateLoopWorkflow<TaskInput, TaskOutput, WhileTaskConfig<any>>;
167
- /**
168
- * Ends the while loop and returns to the parent workflow.
169
- * Only callable on workflows in loop builder mode.
170
- *
171
- * @returns The parent workflow
172
- */
173
- endWhile(): Workflow;
174
- }
175
- }
176
- //# sourceMappingURL=WhileTask.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WhileTask.d.ts","sourceRoot":"","sources":["../../src/task/WhileTask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAMpD,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEvE;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAA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