@workglow/task-graph 0.0.86 → 0.0.87
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.
- package/dist/browser.js +1399 -311
- package/dist/browser.js.map +16 -8
- package/dist/bun.js +1399 -311
- package/dist/bun.js.map +16 -8
- package/dist/node.js +1399 -311
- package/dist/node.js.map +16 -8
- package/dist/task/BatchTask.d.ts +154 -0
- package/dist/task/BatchTask.d.ts.map +1 -0
- package/dist/task/ForEachTask.d.ts +120 -0
- package/dist/task/ForEachTask.d.ts.map +1 -0
- package/dist/task/IteratorTask.d.ts +197 -0
- package/dist/task/IteratorTask.d.ts.map +1 -0
- package/dist/task/IteratorTaskRunner.d.ts +63 -0
- package/dist/task/IteratorTaskRunner.d.ts.map +1 -0
- package/dist/task/MapTask.d.ts +134 -0
- package/dist/task/MapTask.d.ts.map +1 -0
- package/dist/task/ReduceTask.d.ts +155 -0
- package/dist/task/ReduceTask.d.ts.map +1 -0
- package/dist/task/WhileTask.d.ts +176 -0
- package/dist/task/WhileTask.d.ts.map +1 -0
- package/dist/task/index.d.ts +13 -1
- package/dist/task/index.d.ts.map +1 -1
- package/dist/task-graph/Dataflow.d.ts.map +1 -1
- package/dist/task-graph/Workflow.d.ts +94 -8
- package/dist/task-graph/Workflow.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,154 @@
|
|
|
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 { IteratorTask, IteratorTaskConfig } from "./IteratorTask";
|
|
8
|
+
import type { TaskInput, TaskOutput, TaskTypeName } from "./TaskTypes";
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for BatchTask.
|
|
11
|
+
*/
|
|
12
|
+
export interface BatchTaskConfig extends IteratorTaskConfig {
|
|
13
|
+
/**
|
|
14
|
+
* Number of items per batch.
|
|
15
|
+
* @default 10
|
|
16
|
+
*/
|
|
17
|
+
readonly batchSize?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to flatten results from all batches into a single array.
|
|
20
|
+
* When false, results are grouped by batch.
|
|
21
|
+
* @default true
|
|
22
|
+
*/
|
|
23
|
+
readonly flattenResults?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Whether to execute batches in parallel or sequentially.
|
|
26
|
+
* @default "sequential"
|
|
27
|
+
*/
|
|
28
|
+
readonly batchExecutionMode?: "parallel" | "sequential";
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* BatchTask processes an array in configurable chunks/batches.
|
|
32
|
+
*
|
|
33
|
+
* This task is useful for:
|
|
34
|
+
* - Rate-limited API calls that accept multiple items
|
|
35
|
+
* - Memory-constrained processing
|
|
36
|
+
* - Progress tracking at batch granularity
|
|
37
|
+
*
|
|
38
|
+
* ## Features
|
|
39
|
+
*
|
|
40
|
+
* - Groups array into chunks of batchSize
|
|
41
|
+
* - Runs inner workflow per batch (receives array of items)
|
|
42
|
+
* - Configurable batch and within-batch execution
|
|
43
|
+
* - Optional result flattening
|
|
44
|
+
*
|
|
45
|
+
* ## Usage
|
|
46
|
+
*
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Process in batches of 10
|
|
49
|
+
* workflow
|
|
50
|
+
* .input({ documents: [...100 docs...] })
|
|
51
|
+
* .batch({ batchSize: 10 })
|
|
52
|
+
* .bulkEmbed()
|
|
53
|
+
* .bulkStore()
|
|
54
|
+
* .endBatch()
|
|
55
|
+
*
|
|
56
|
+
* // Sequential batches for rate limiting
|
|
57
|
+
* workflow
|
|
58
|
+
* .batch({ batchSize: 5, batchExecutionMode: "sequential" })
|
|
59
|
+
* .apiCall()
|
|
60
|
+
* .endBatch()
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @template Input - The input type containing the array to batch
|
|
64
|
+
* @template Output - The output type (collected batch results)
|
|
65
|
+
* @template Config - The configuration type
|
|
66
|
+
*/
|
|
67
|
+
export declare class BatchTask<Input extends TaskInput = TaskInput, Output extends TaskOutput = TaskOutput, Config extends BatchTaskConfig = BatchTaskConfig> extends IteratorTask<Input, Output, Config> {
|
|
68
|
+
static type: TaskTypeName;
|
|
69
|
+
static category: string;
|
|
70
|
+
static title: string;
|
|
71
|
+
static description: string;
|
|
72
|
+
/**
|
|
73
|
+
* BatchTask always uses PROPERTY_ARRAY merge strategy.
|
|
74
|
+
*/
|
|
75
|
+
static readonly compoundMerge: "PROPERTY_ARRAY";
|
|
76
|
+
/**
|
|
77
|
+
* Static input schema for BatchTask.
|
|
78
|
+
*/
|
|
79
|
+
static inputSchema(): DataPortSchema;
|
|
80
|
+
/**
|
|
81
|
+
* Static output schema for BatchTask.
|
|
82
|
+
*/
|
|
83
|
+
static outputSchema(): DataPortSchema;
|
|
84
|
+
/**
|
|
85
|
+
* Gets the batch size.
|
|
86
|
+
*/
|
|
87
|
+
get batchSize(): number;
|
|
88
|
+
/**
|
|
89
|
+
* Whether to flatten results from all batches.
|
|
90
|
+
*/
|
|
91
|
+
get flattenResults(): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Batch execution mode.
|
|
94
|
+
*/
|
|
95
|
+
get batchExecutionMode(): "parallel" | "sequential";
|
|
96
|
+
/**
|
|
97
|
+
* Override to group items into batches instead of individual items.
|
|
98
|
+
*/
|
|
99
|
+
protected getIterableItems(input: Input): unknown[];
|
|
100
|
+
/**
|
|
101
|
+
* Groups items into batches of batchSize.
|
|
102
|
+
*/
|
|
103
|
+
protected groupIntoBatches(items: unknown[]): unknown[][];
|
|
104
|
+
/**
|
|
105
|
+
* Creates iteration tasks for batches.
|
|
106
|
+
* Each batch receives the array of items for that batch.
|
|
107
|
+
*/
|
|
108
|
+
protected createIterationTasks(batches: unknown[]): void;
|
|
109
|
+
/**
|
|
110
|
+
* Returns the empty result for BatchTask.
|
|
111
|
+
*/
|
|
112
|
+
protected getEmptyResult(): Output;
|
|
113
|
+
/**
|
|
114
|
+
* Output schema for BatchTask.
|
|
115
|
+
* Similar to MapTask - wraps inner outputs in arrays.
|
|
116
|
+
*/
|
|
117
|
+
outputSchema(): DataPortSchema;
|
|
118
|
+
/**
|
|
119
|
+
* Collects and optionally flattens results from all batches.
|
|
120
|
+
*/
|
|
121
|
+
protected collectResults(results: TaskOutput[]): Output;
|
|
122
|
+
/**
|
|
123
|
+
* Regenerates the graph for batch execution.
|
|
124
|
+
*/
|
|
125
|
+
regenerateGraph(): void;
|
|
126
|
+
}
|
|
127
|
+
declare module "../task-graph/Workflow" {
|
|
128
|
+
interface Workflow {
|
|
129
|
+
/**
|
|
130
|
+
* Starts a batch loop that processes arrays in chunks.
|
|
131
|
+
* Use .endBatch() to close the loop and return to the parent workflow.
|
|
132
|
+
*
|
|
133
|
+
* @param config - Configuration for the batch loop
|
|
134
|
+
* @returns A Workflow in loop builder mode for defining the batch processing
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* workflow
|
|
139
|
+
* .batch({ batchSize: 10 })
|
|
140
|
+
* .bulkProcess()
|
|
141
|
+
* .endBatch()
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
batch: CreateLoopWorkflow<TaskInput, TaskOutput, BatchTaskConfig>;
|
|
145
|
+
/**
|
|
146
|
+
* Ends the batch loop and returns to the parent workflow.
|
|
147
|
+
* Only callable on workflows in loop builder mode.
|
|
148
|
+
*
|
|
149
|
+
* @returns The parent workflow
|
|
150
|
+
*/
|
|
151
|
+
endBatch(): Workflow;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=BatchTask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BatchTask.d.ts","sourceRoot":"","sources":["../../src/task/BatchTask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,c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K,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,EAAE;IAWzD;;;OAGG;cACgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI;IA0BjE;;OAEG;cACgB,cAAc,IAAI,MAAM;IAc3C;;;OAGG;IACa,YAAY,IAAI,cAAc;IAQ9C;;OAEG;cACgB,cAAc,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM;IAqBhE;;OAEG;IACa,eAAe,IAAI,IAAI;CAqBxC;AAMD,OAAO,QAAQ,wBAAwB,CAAC;IACtC,UAAU,QAAQ;QAChB;;;;;;;;;;;;;;WAcG;QAEH,KAAK,EAAE,kBAAkB,CAAC,SAAS,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC;QAElE;;;;;WAKG;QACH,QAAQ,IAAI,QAAQ,CAAC;KACtB;CACF"}
|
|
@@ -0,0 +1,120 @@
|
|
|
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 { IteratorTask, IteratorTaskConfig } from "./IteratorTask";
|
|
8
|
+
import type { TaskInput, TaskOutput, TaskTypeName } from "./TaskTypes";
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for ForEachTask.
|
|
11
|
+
*/
|
|
12
|
+
export interface ForEachTaskConfig extends IteratorTaskConfig {
|
|
13
|
+
/**
|
|
14
|
+
* Whether to collect and return results from each iteration.
|
|
15
|
+
* When false (default), ForEachTask is optimized for side effects.
|
|
16
|
+
* When true, results are collected but not transformed.
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
readonly shouldCollectResults?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* ForEachTask iterates over an array and runs a workflow for each element.
|
|
23
|
+
*
|
|
24
|
+
* This task is optimized for side-effect operations where the primary goal
|
|
25
|
+
* is to process each item rather than collect transformed results.
|
|
26
|
+
* For transformations that collect results, use MapTask instead.
|
|
27
|
+
*
|
|
28
|
+
* ## Features
|
|
29
|
+
*
|
|
30
|
+
* - Iterates over array input
|
|
31
|
+
* - Runs inner workflow for each element
|
|
32
|
+
* - Configurable execution modes (parallel, sequential, etc.)
|
|
33
|
+
* - Optimized for side effects (default: doesn't collect results)
|
|
34
|
+
*
|
|
35
|
+
* ## Usage
|
|
36
|
+
*
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Using Workflow API
|
|
39
|
+
* workflow
|
|
40
|
+
* .input({ items: ["a", "b", "c"] })
|
|
41
|
+
* .forEach()
|
|
42
|
+
* .processItem()
|
|
43
|
+
* .saveToDatabase()
|
|
44
|
+
* .endForEach()
|
|
45
|
+
*
|
|
46
|
+
* // With sequential execution
|
|
47
|
+
* workflow
|
|
48
|
+
* .forEach({ executionMode: "sequential" })
|
|
49
|
+
* .processItem()
|
|
50
|
+
* .endForEach()
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @template Input - The input type containing the array to iterate
|
|
54
|
+
* @template Output - The output type (typically empty for side-effect operations)
|
|
55
|
+
* @template Config - The configuration type
|
|
56
|
+
*/
|
|
57
|
+
export declare class ForEachTask<Input extends TaskInput = TaskInput, Output extends TaskOutput = TaskOutput, Config extends ForEachTaskConfig = ForEachTaskConfig> extends IteratorTask<Input, Output, Config> {
|
|
58
|
+
static type: TaskTypeName;
|
|
59
|
+
static category: string;
|
|
60
|
+
static title: string;
|
|
61
|
+
static description: string;
|
|
62
|
+
/**
|
|
63
|
+
* Static input schema for ForEachTask.
|
|
64
|
+
* Accepts any object with at least one array property.
|
|
65
|
+
*/
|
|
66
|
+
static inputSchema(): DataPortSchema;
|
|
67
|
+
/**
|
|
68
|
+
* Static output schema for ForEachTask.
|
|
69
|
+
* By default, returns an empty object (side-effect focused).
|
|
70
|
+
*/
|
|
71
|
+
static outputSchema(): DataPortSchema;
|
|
72
|
+
/**
|
|
73
|
+
* Whether to collect results from iterations.
|
|
74
|
+
*/
|
|
75
|
+
get shouldCollectResults(): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Returns the empty result for ForEachTask.
|
|
78
|
+
* Indicates completion with zero items processed.
|
|
79
|
+
*/
|
|
80
|
+
protected getEmptyResult(): Output;
|
|
81
|
+
/**
|
|
82
|
+
* Output schema for ForEachTask instance.
|
|
83
|
+
* If shouldCollectResults is enabled, wraps inner output in arrays.
|
|
84
|
+
* Otherwise, returns the simple completion status schema.
|
|
85
|
+
*/
|
|
86
|
+
outputSchema(): DataPortSchema;
|
|
87
|
+
/**
|
|
88
|
+
* Collects results from all iterations.
|
|
89
|
+
* For ForEachTask, this primarily returns completion status.
|
|
90
|
+
*/
|
|
91
|
+
protected collectResults(results: TaskOutput[]): Output;
|
|
92
|
+
}
|
|
93
|
+
declare module "../task-graph/Workflow" {
|
|
94
|
+
interface Workflow {
|
|
95
|
+
/**
|
|
96
|
+
* Starts a forEach loop that iterates over an array.
|
|
97
|
+
* Use .endForEach() to close the loop and return to the parent workflow.
|
|
98
|
+
*
|
|
99
|
+
* @param config - Configuration for the forEach loop
|
|
100
|
+
* @returns A Workflow in loop builder mode for defining the loop body
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* workflow
|
|
105
|
+
* .forEach({ executionMode: "sequential" })
|
|
106
|
+
* .processItem()
|
|
107
|
+
* .endForEach()
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
forEach: CreateLoopWorkflow<TaskInput, TaskOutput, ForEachTaskConfig>;
|
|
111
|
+
/**
|
|
112
|
+
* Ends the forEach loop and returns to the parent workflow.
|
|
113
|
+
* Only callable on workflows in loop builder mode.
|
|
114
|
+
*
|
|
115
|
+
* @returns The parent workflow
|
|
116
|
+
*/
|
|
117
|
+
endForEach(): Workflow;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL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WAcG;QACH,OAAO,EAAE,kBAAkB,CAAC,SAAS,EAAE,UAAU,EAAE,iBAAiB,CAAC,CAAC;QAEtE;;;;;WAKG;QACH,UAAU,IAAI,QAAQ,CAAC;KACxB;CACF"}
|
|
@@ -0,0 +1,197 @@
|
|
|
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 { IteratorTaskRunner } from "./IteratorTaskRunner";
|
|
11
|
+
import type { TaskInput, TaskOutput, TaskTypeName } from "./TaskTypes";
|
|
12
|
+
/**
|
|
13
|
+
* Execution mode for iterator tasks.
|
|
14
|
+
* - `parallel`: Execute all iterations concurrently (unlimited)
|
|
15
|
+
* - `parallel-limited`: Execute with a concurrency limit
|
|
16
|
+
* - `sequential`: Execute one at a time
|
|
17
|
+
* - `batched`: Execute in batches of batchSize
|
|
18
|
+
*/
|
|
19
|
+
export type ExecutionMode = "parallel" | "parallel-limited" | "sequential" | "batched";
|
|
20
|
+
/**
|
|
21
|
+
* Configuration interface for IteratorTask.
|
|
22
|
+
* Extends GraphAsTaskConfig with iterator-specific options.
|
|
23
|
+
*/
|
|
24
|
+
export interface IteratorTaskConfig extends GraphAsTaskConfig {
|
|
25
|
+
/**
|
|
26
|
+
* The execution mode for iterations.
|
|
27
|
+
* @default "parallel"
|
|
28
|
+
*/
|
|
29
|
+
readonly executionMode?: ExecutionMode;
|
|
30
|
+
/**
|
|
31
|
+
* Maximum number of concurrent iterations when executionMode is "parallel-limited".
|
|
32
|
+
* @default 5
|
|
33
|
+
*/
|
|
34
|
+
readonly concurrencyLimit?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Number of items per batch when executionMode is "batched".
|
|
37
|
+
* @default 10
|
|
38
|
+
*/
|
|
39
|
+
readonly batchSize?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Optional custom queue name for job queue integration.
|
|
42
|
+
* If not provided, a unique queue name will be generated.
|
|
43
|
+
*/
|
|
44
|
+
readonly queueName?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The name of the input port containing the array to iterate.
|
|
47
|
+
* If not provided, auto-detection will find the first array-typed port.
|
|
48
|
+
*/
|
|
49
|
+
readonly iteratorPort?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Result of detecting the iterator port from the input schema.
|
|
53
|
+
*/
|
|
54
|
+
interface IteratorPortInfo {
|
|
55
|
+
readonly portName: string;
|
|
56
|
+
readonly itemSchema: DataPortSchema;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Base class for iterator tasks that process collections of items.
|
|
60
|
+
*
|
|
61
|
+
* IteratorTask provides the foundation for loop-type tasks in the task graph.
|
|
62
|
+
* It manages a subgraph of tasks that are executed for each item in a collection,
|
|
63
|
+
* with configurable execution modes (parallel, sequential, batched, etc.).
|
|
64
|
+
*
|
|
65
|
+
* Subclasses should implement:
|
|
66
|
+
* - `getIterableItems(input)`: Extract the items to iterate over from input
|
|
67
|
+
* - Optionally override `collectResults()`: Define how to collect/merge results
|
|
68
|
+
*
|
|
69
|
+
* @template Input - The input type for the iterator task
|
|
70
|
+
* @template Output - The output type for the iterator task
|
|
71
|
+
* @template Config - The configuration type (must extend IteratorTaskConfig)
|
|
72
|
+
*/
|
|
73
|
+
export declare abstract class IteratorTask<Input extends TaskInput = TaskInput, Output extends TaskOutput = TaskOutput, Config extends IteratorTaskConfig = IteratorTaskConfig> extends GraphAsTask<Input, Output, Config> {
|
|
74
|
+
static type: TaskTypeName;
|
|
75
|
+
static category: string;
|
|
76
|
+
static title: string;
|
|
77
|
+
static description: string;
|
|
78
|
+
/** This task has dynamic schemas based on the inner workflow */
|
|
79
|
+
static hasDynamicSchemas: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* The template subgraph that will be cloned for each iteration.
|
|
82
|
+
* This is the workflow defined between forEach() and endForEach().
|
|
83
|
+
*/
|
|
84
|
+
protected _templateGraph: TaskGraph | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Cached iterator port info from schema analysis.
|
|
87
|
+
*/
|
|
88
|
+
protected _iteratorPortInfo: IteratorPortInfo | undefined;
|
|
89
|
+
constructor(input?: Partial<Input>, config?: Partial<Config>);
|
|
90
|
+
_runner: IteratorTaskRunner<Input, Output, Config>;
|
|
91
|
+
/**
|
|
92
|
+
* Gets the custom iterator task runner.
|
|
93
|
+
*/
|
|
94
|
+
get runner(): IteratorTaskRunner<Input, Output, Config>;
|
|
95
|
+
/**
|
|
96
|
+
* Gets the execution mode for this iterator.
|
|
97
|
+
*/
|
|
98
|
+
get executionMode(): ExecutionMode;
|
|
99
|
+
/**
|
|
100
|
+
* Gets the concurrency limit for parallel-limited mode.
|
|
101
|
+
*/
|
|
102
|
+
get concurrencyLimit(): number;
|
|
103
|
+
/**
|
|
104
|
+
* Gets the batch size for batched mode.
|
|
105
|
+
*/
|
|
106
|
+
get batchSize(): number;
|
|
107
|
+
/**
|
|
108
|
+
* Auto-detects the iterator port from the input schema.
|
|
109
|
+
* Finds the first property with type "array" or that has an "items" property.
|
|
110
|
+
*
|
|
111
|
+
* @returns The port info or undefined if no array port found
|
|
112
|
+
*/
|
|
113
|
+
protected detectIteratorPort(): IteratorPortInfo | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Gets the name of the port containing the iterable collection.
|
|
116
|
+
*/
|
|
117
|
+
getIteratorPortName(): string | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Gets the schema for individual items in the collection.
|
|
120
|
+
*/
|
|
121
|
+
getItemSchema(): DataPortSchema;
|
|
122
|
+
/**
|
|
123
|
+
* Extracts the items to iterate over from the input.
|
|
124
|
+
* Subclasses can override this to provide custom extraction logic.
|
|
125
|
+
*
|
|
126
|
+
* @param input - The task input
|
|
127
|
+
* @returns Array of items to iterate over
|
|
128
|
+
*/
|
|
129
|
+
protected getIterableItems(input: Input): unknown[];
|
|
130
|
+
/**
|
|
131
|
+
* Sets the template graph that defines the workflow to run for each iteration.
|
|
132
|
+
* This is called by the Workflow builder when setting up the loop.
|
|
133
|
+
*
|
|
134
|
+
* Note: This does NOT call regenerateGraph() automatically because during
|
|
135
|
+
* workflow construction, input data may not be available. The graph is
|
|
136
|
+
* regenerated at execution time when actual input data is provided.
|
|
137
|
+
*/
|
|
138
|
+
setTemplateGraph(graph: TaskGraph): void;
|
|
139
|
+
/**
|
|
140
|
+
* Gets the template graph.
|
|
141
|
+
*/
|
|
142
|
+
getTemplateGraph(): TaskGraph | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Regenerates the subgraph based on the template and current input.
|
|
145
|
+
* This creates cloned task instances for each item in the iteration.
|
|
146
|
+
*/
|
|
147
|
+
regenerateGraph(): void;
|
|
148
|
+
/**
|
|
149
|
+
* Creates task instances for each iteration item.
|
|
150
|
+
* Subclasses can override this for custom iteration behavior.
|
|
151
|
+
*
|
|
152
|
+
* @param items - The items to iterate over
|
|
153
|
+
*/
|
|
154
|
+
protected createIterationTasks(items: unknown[]): void;
|
|
155
|
+
/**
|
|
156
|
+
* Clones the template graph tasks for a single iteration.
|
|
157
|
+
*
|
|
158
|
+
* @param iterationInput - The input for this iteration
|
|
159
|
+
* @param index - The iteration index
|
|
160
|
+
*/
|
|
161
|
+
protected cloneTemplateForIteration(iterationInput: Record<string, unknown>, index: number): void;
|
|
162
|
+
/**
|
|
163
|
+
* Execute the iterator task.
|
|
164
|
+
* Sets up the iteration and delegates to the parent GraphAsTask execution.
|
|
165
|
+
*/
|
|
166
|
+
execute(input: Input, context: IExecuteContext): Promise<Output | undefined>;
|
|
167
|
+
/**
|
|
168
|
+
* Returns the result when there are no items to iterate.
|
|
169
|
+
* Subclasses should override this to return appropriate empty results.
|
|
170
|
+
*/
|
|
171
|
+
protected getEmptyResult(): Output;
|
|
172
|
+
/**
|
|
173
|
+
* Collects and merges results from all iterations.
|
|
174
|
+
* Subclasses can override this for custom result handling.
|
|
175
|
+
*
|
|
176
|
+
* @param results - Array of results from each iteration
|
|
177
|
+
* @returns Merged output
|
|
178
|
+
*/
|
|
179
|
+
protected collectResults(results: TaskOutput[]): Output;
|
|
180
|
+
/**
|
|
181
|
+
* Input schema for the iterator.
|
|
182
|
+
* Returns the static schema since the iterator accepts the full array.
|
|
183
|
+
*/
|
|
184
|
+
inputSchema(): DataPortSchema;
|
|
185
|
+
/**
|
|
186
|
+
* Output schema for the iterator.
|
|
187
|
+
* Subclasses should override to define their specific output structure.
|
|
188
|
+
*/
|
|
189
|
+
outputSchema(): DataPortSchema;
|
|
190
|
+
/**
|
|
191
|
+
* Gets the output schema with properties wrapped in arrays.
|
|
192
|
+
* Used by MapTask and similar tasks that collect results.
|
|
193
|
+
*/
|
|
194
|
+
protected getWrappedOutputSchema(): DataPortSchema;
|
|
195
|
+
}
|
|
196
|
+
export {};
|
|
197
|
+
//# sourceMappingURL=IteratorTask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IteratorTask.d.ts","sourceRoot":"","sources":["../../src/task/IteratorTask.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEvE;;;;;;GAMG;AAC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I,cAAc;IAQpC;;;OAGG;IACI,YAAY,IAAI,cAAc;IASrC;;;OAGG;IACH,SAAS,CAAC,sBAAsB,IAAI,cAAc;CAsCnD"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { GraphResultArray } from "../task-graph/TaskGraphRunner";
|
|
7
|
+
import { GraphAsTaskRunner } from "./GraphAsTaskRunner";
|
|
8
|
+
import type { ExecutionMode, IteratorTask, IteratorTaskConfig } from "./IteratorTask";
|
|
9
|
+
import { RegisteredQueue } from "./TaskQueueRegistry";
|
|
10
|
+
import type { TaskInput, TaskOutput } from "./TaskTypes";
|
|
11
|
+
/**
|
|
12
|
+
* Custom runner for IteratorTask that handles execution mode and queue integration.
|
|
13
|
+
*
|
|
14
|
+
* This runner manages:
|
|
15
|
+
* - Dynamic queue creation based on execution mode
|
|
16
|
+
* - Concurrency limiting for parallel-limited mode
|
|
17
|
+
* - Sequential execution for sequential mode
|
|
18
|
+
* - Batch grouping for batched mode
|
|
19
|
+
*/
|
|
20
|
+
export declare class IteratorTaskRunner<Input extends TaskInput = TaskInput, Output extends TaskOutput = TaskOutput, Config extends IteratorTaskConfig = IteratorTaskConfig> extends GraphAsTaskRunner<Input, Output, Config> {
|
|
21
|
+
task: IteratorTask<Input, Output, Config>;
|
|
22
|
+
/**
|
|
23
|
+
* The queue used for this iterator's executions.
|
|
24
|
+
*/
|
|
25
|
+
protected iteratorQueue?: RegisteredQueue<Input, Output>;
|
|
26
|
+
/**
|
|
27
|
+
* Generated queue name for this iterator instance.
|
|
28
|
+
*/
|
|
29
|
+
protected iteratorQueueName?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Gets or creates the queue for this iterator based on execution mode.
|
|
32
|
+
*/
|
|
33
|
+
protected getOrCreateIteratorQueue(): Promise<RegisteredQueue<Input, Output> | undefined>;
|
|
34
|
+
/**
|
|
35
|
+
* Gets the concurrency level for the given execution mode.
|
|
36
|
+
*/
|
|
37
|
+
protected getConcurrencyForMode(mode: ExecutionMode): number;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new queue for iterator execution.
|
|
40
|
+
*/
|
|
41
|
+
protected createIteratorQueue(queueName: string, concurrency: number): Promise<RegisteredQueue<Input, Output>>;
|
|
42
|
+
/**
|
|
43
|
+
* Execute the iterator's children based on execution mode.
|
|
44
|
+
*/
|
|
45
|
+
protected executeTaskChildren(input: Input): Promise<GraphResultArray<Output>>;
|
|
46
|
+
/**
|
|
47
|
+
* Execute iterations sequentially (one at a time).
|
|
48
|
+
*/
|
|
49
|
+
protected executeSequential(input: Input): Promise<GraphResultArray<Output>>;
|
|
50
|
+
/**
|
|
51
|
+
* Execute iterations with a concurrency limit.
|
|
52
|
+
*/
|
|
53
|
+
protected executeParallelLimited(input: Input): Promise<GraphResultArray<Output>>;
|
|
54
|
+
/**
|
|
55
|
+
* Execute iterations in batches.
|
|
56
|
+
*/
|
|
57
|
+
protected executeBatched(input: Input): Promise<GraphResultArray<Output>>;
|
|
58
|
+
/**
|
|
59
|
+
* Clean up the iterator queue when done.
|
|
60
|
+
*/
|
|
61
|
+
protected cleanup(): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=IteratorTaskRunner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IteratorTaskRunner.d.ts","sourceRoot":"","sources":["../../src/task/IteratorTaskRunner.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAAwB,eAAe,EAAE,M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gB,CAAC,MAAM,CAAC,CAAC;IAsC/E;;OAEG;cACa,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CASzC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
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 { IteratorTask, IteratorTaskConfig } from "./IteratorTask";
|
|
8
|
+
import type { TaskInput, TaskOutput, TaskTypeName } from "./TaskTypes";
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for MapTask.
|
|
11
|
+
*/
|
|
12
|
+
export interface MapTaskConfig extends IteratorTaskConfig {
|
|
13
|
+
/**
|
|
14
|
+
* Whether to preserve the order of results matching the input order.
|
|
15
|
+
* When false, results may be in completion order (faster for parallel).
|
|
16
|
+
* @default true
|
|
17
|
+
*/
|
|
18
|
+
readonly preserveOrder?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether to flatten array results from each iteration.
|
|
21
|
+
* When true, if each iteration returns an array, they are concatenated.
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
readonly flatten?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* MapTask transforms an array by running a workflow for each element and collecting results.
|
|
28
|
+
*
|
|
29
|
+
* This task is the functional-style map operation: it takes an array input,
|
|
30
|
+
* applies a transformation workflow to each element, and returns an array
|
|
31
|
+
* of transformed results.
|
|
32
|
+
*
|
|
33
|
+
* ## Features
|
|
34
|
+
*
|
|
35
|
+
* - Transforms each array element through inner workflow
|
|
36
|
+
* - Collects and returns array of results
|
|
37
|
+
* - Maintains result order by default
|
|
38
|
+
* - Configurable execution modes (parallel, sequential, etc.)
|
|
39
|
+
* - Optional flattening of nested arrays
|
|
40
|
+
*
|
|
41
|
+
* ## Usage
|
|
42
|
+
*
|
|
43
|
+
* ```typescript
|
|
44
|
+
* // Transform texts to embeddings
|
|
45
|
+
* workflow
|
|
46
|
+
* .input({ texts: ["hello", "world"] })
|
|
47
|
+
* .map()
|
|
48
|
+
* .textEmbedding()
|
|
49
|
+
* .endMap()
|
|
50
|
+
* // Result: { vectors: [Float32Array, Float32Array] }
|
|
51
|
+
*
|
|
52
|
+
* // With explicit port
|
|
53
|
+
* workflow
|
|
54
|
+
* .map({ iteratorPort: "documents" })
|
|
55
|
+
* .enrich()
|
|
56
|
+
* .chunk()
|
|
57
|
+
* .endMap()
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @template Input - The input type containing the array to transform
|
|
61
|
+
* @template Output - The output type (array of transformed results)
|
|
62
|
+
* @template Config - The configuration type
|
|
63
|
+
*/
|
|
64
|
+
export declare class MapTask<Input extends TaskInput = TaskInput, Output extends TaskOutput = TaskOutput, Config extends MapTaskConfig = MapTaskConfig> extends IteratorTask<Input, Output, Config> {
|
|
65
|
+
static type: TaskTypeName;
|
|
66
|
+
static category: string;
|
|
67
|
+
static title: string;
|
|
68
|
+
static description: string;
|
|
69
|
+
/**
|
|
70
|
+
* MapTask always uses PROPERTY_ARRAY merge strategy to collect results.
|
|
71
|
+
*/
|
|
72
|
+
static readonly compoundMerge: "PROPERTY_ARRAY";
|
|
73
|
+
/**
|
|
74
|
+
* Static input schema for MapTask.
|
|
75
|
+
* Accepts any object with at least one array property.
|
|
76
|
+
*/
|
|
77
|
+
static inputSchema(): DataPortSchema;
|
|
78
|
+
/**
|
|
79
|
+
* Static output schema for MapTask.
|
|
80
|
+
* Dynamic based on inner workflow outputs.
|
|
81
|
+
*/
|
|
82
|
+
static outputSchema(): DataPortSchema;
|
|
83
|
+
/**
|
|
84
|
+
* Whether to preserve order of results.
|
|
85
|
+
*/
|
|
86
|
+
get preserveOrder(): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Whether to flatten nested array results.
|
|
89
|
+
*/
|
|
90
|
+
get flatten(): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Returns the empty result for MapTask.
|
|
93
|
+
* Returns empty arrays for each output property.
|
|
94
|
+
*/
|
|
95
|
+
protected getEmptyResult(): Output;
|
|
96
|
+
/**
|
|
97
|
+
* Output schema for MapTask.
|
|
98
|
+
* Wraps inner workflow output properties in arrays.
|
|
99
|
+
*/
|
|
100
|
+
outputSchema(): DataPortSchema;
|
|
101
|
+
/**
|
|
102
|
+
* Collects and optionally flattens results from all iterations.
|
|
103
|
+
*/
|
|
104
|
+
protected collectResults(results: TaskOutput[]): Output;
|
|
105
|
+
}
|
|
106
|
+
declare module "../task-graph/Workflow" {
|
|
107
|
+
interface Workflow {
|
|
108
|
+
/**
|
|
109
|
+
* Starts a map loop that transforms each element in an array.
|
|
110
|
+
* Use .endMap() to close the loop and return to the parent workflow.
|
|
111
|
+
*
|
|
112
|
+
* @param config - Configuration for the map loop
|
|
113
|
+
* @returns A Workflow in loop builder mode for defining the transformation
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* workflow
|
|
118
|
+
* .map()
|
|
119
|
+
* .textEmbedding()
|
|
120
|
+
* .endMap()
|
|
121
|
+
* // Result: { vectors: [...] }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
map: CreateLoopWorkflow<TaskInput, TaskOutput, MapTaskConfig>;
|
|
125
|
+
/**
|
|
126
|
+
* Ends the map loop and returns to the parent workflow.
|
|
127
|
+
* Only callable on workflows in loop builder mode.
|
|
128
|
+
*
|
|
129
|
+
* @returns The parent workflow
|
|
130
|
+
*/
|
|
131
|
+
endMap(): Workflow;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=MapTask.d.ts.map
|