@workglow/task-graph 0.0.109 → 0.0.111
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 +81 -40
- package/dist/browser.js.map +11 -11
- package/dist/bun.js +81 -40
- package/dist/bun.js.map +11 -11
- package/dist/node.js +81 -40
- package/dist/node.js.map +11 -11
- package/dist/storage/TaskGraphTabularRepository.d.ts +7 -1
- package/dist/storage/TaskGraphTabularRepository.d.ts.map +1 -1
- package/dist/task/ITask.d.ts +1 -1
- package/dist/task/ITask.d.ts.map +1 -1
- package/dist/task/InputResolver.d.ts.map +1 -1
- package/dist/task/JobQueueTask.d.ts +2 -2
- package/dist/task/JobQueueTask.d.ts.map +1 -1
- package/dist/task/TaskJSON.d.ts +58 -16
- package/dist/task/TaskJSON.d.ts.map +1 -1
- package/dist/task/TaskQueueRegistry.d.ts +4 -4
- package/dist/task/TaskQueueRegistry.d.ts.map +1 -1
- package/dist/task/TaskRegistry.d.ts +24 -2
- package/dist/task/TaskRegistry.d.ts.map +1 -1
- package/dist/task-graph/TaskGraph.d.ts +5 -1
- package/dist/task-graph/TaskGraph.d.ts.map +1 -1
- package/dist/task-graph/TaskGraphRunner.d.ts +7 -3
- package/dist/task-graph/TaskGraphRunner.d.ts.map +1 -1
- package/package.json +9 -7
package/dist/browser.js
CHANGED
|
@@ -848,8 +848,8 @@ async function resolveSchemaInputs(input, schema, config) {
|
|
|
848
848
|
if (typeof value === "string") {
|
|
849
849
|
value = await resolver(value, format, config.registry);
|
|
850
850
|
resolved[key] = value;
|
|
851
|
-
} else if (Array.isArray(value) && value.
|
|
852
|
-
const results = await Promise.all(value.map((item) => resolver(item, format, config.registry)));
|
|
851
|
+
} else if (Array.isArray(value) && value.some((item) => typeof item === "string")) {
|
|
852
|
+
const results = await Promise.all(value.map((item) => typeof item === "string" ? resolver(item, format, config.registry) : item));
|
|
853
853
|
value = results.filter((result) => result !== undefined);
|
|
854
854
|
resolved[key] = value;
|
|
855
855
|
}
|
|
@@ -2199,8 +2199,8 @@ class TaskGraphRunner {
|
|
|
2199
2199
|
await this.handleComplete();
|
|
2200
2200
|
return results;
|
|
2201
2201
|
}
|
|
2202
|
-
async runGraphReactive(input = {}) {
|
|
2203
|
-
await this.handleStartReactive();
|
|
2202
|
+
async runGraphReactive(input = {}, config) {
|
|
2203
|
+
await this.handleStartReactive(config);
|
|
2204
2204
|
const results = [];
|
|
2205
2205
|
try {
|
|
2206
2206
|
for await (const task of this.reactiveScheduler.tasks()) {
|
|
@@ -2583,7 +2583,7 @@ class TaskGraphRunner {
|
|
|
2583
2583
|
async handleStart(config) {
|
|
2584
2584
|
if (config?.registry !== undefined) {
|
|
2585
2585
|
this.registry = config.registry;
|
|
2586
|
-
} else {
|
|
2586
|
+
} else if (this.registry === undefined) {
|
|
2587
2587
|
this.registry = new ServiceRegistry2(globalServiceRegistry2.container.createChildContainer());
|
|
2588
2588
|
}
|
|
2589
2589
|
this.accumulateLeafOutputs = config?.accumulateLeafOutputs !== false;
|
|
@@ -2626,10 +2626,13 @@ class TaskGraphRunner {
|
|
|
2626
2626
|
logger.time(this.timerLabel);
|
|
2627
2627
|
this.graph.emit("start");
|
|
2628
2628
|
}
|
|
2629
|
-
async handleStartReactive() {
|
|
2629
|
+
async handleStartReactive(config) {
|
|
2630
2630
|
if (this.reactiveRunning) {
|
|
2631
2631
|
throw new TaskConfigurationError("Graph is already running reactively");
|
|
2632
2632
|
}
|
|
2633
|
+
if (config?.registry !== undefined) {
|
|
2634
|
+
this.registry = config.registry;
|
|
2635
|
+
}
|
|
2633
2636
|
this.reactiveScheduler.reset();
|
|
2634
2637
|
this.reactiveRunning = true;
|
|
2635
2638
|
}
|
|
@@ -3789,11 +3792,12 @@ class TaskGraph {
|
|
|
3789
3792
|
return this.runner.runGraph(input, {
|
|
3790
3793
|
outputCache: config?.outputCache || this.outputCache,
|
|
3791
3794
|
parentSignal: config?.parentSignal || undefined,
|
|
3792
|
-
accumulateLeafOutputs: config?.accumulateLeafOutputs
|
|
3795
|
+
accumulateLeafOutputs: config?.accumulateLeafOutputs,
|
|
3796
|
+
registry: config?.registry
|
|
3793
3797
|
});
|
|
3794
3798
|
}
|
|
3795
|
-
runReactive(input = {}) {
|
|
3796
|
-
return this.runner.runGraphReactive(input);
|
|
3799
|
+
runReactive(input = {}, config = {}) {
|
|
3800
|
+
return this.runner.runGraphReactive(input, config);
|
|
3797
3801
|
}
|
|
3798
3802
|
mergeExecuteOutputsToRunOutput(results, compoundMerge) {
|
|
3799
3803
|
return this.runner.mergeExecuteOutputsToRunOutput(results, compoundMerge);
|
|
@@ -4345,7 +4349,7 @@ class IteratorTaskRunner extends GraphAsTaskRunner {
|
|
|
4345
4349
|
const clone = new TaskGraph;
|
|
4346
4350
|
for (const task of graph.getTasks()) {
|
|
4347
4351
|
const ctor = task.constructor;
|
|
4348
|
-
const newTask = new ctor(task.defaults, task.config);
|
|
4352
|
+
const newTask = new ctor(task.defaults, task.config, task.runConfig);
|
|
4349
4353
|
if (task.hasChildren()) {
|
|
4350
4354
|
newTask.subGraph = this.cloneGraph(task.subGraph);
|
|
4351
4355
|
}
|
|
@@ -5508,23 +5512,20 @@ class TaskQueueRegistry {
|
|
|
5508
5512
|
getQueue(queueName) {
|
|
5509
5513
|
return this.queues.get(queueName);
|
|
5510
5514
|
}
|
|
5511
|
-
startQueues() {
|
|
5515
|
+
async startQueues() {
|
|
5512
5516
|
for (const queue of this.queues.values()) {
|
|
5513
|
-
queue.server.start();
|
|
5517
|
+
await queue.server.start();
|
|
5514
5518
|
}
|
|
5515
|
-
return this;
|
|
5516
5519
|
}
|
|
5517
|
-
stopQueues() {
|
|
5520
|
+
async stopQueues() {
|
|
5518
5521
|
for (const queue of this.queues.values()) {
|
|
5519
|
-
queue.server.stop();
|
|
5522
|
+
await queue.server.stop();
|
|
5520
5523
|
}
|
|
5521
|
-
return this;
|
|
5522
5524
|
}
|
|
5523
|
-
clearQueues() {
|
|
5525
|
+
async clearQueues() {
|
|
5524
5526
|
for (const queue of this.queues.values()) {
|
|
5525
|
-
queue.storage.deleteAll();
|
|
5527
|
+
await queue.storage.deleteAll();
|
|
5526
5528
|
}
|
|
5527
|
-
return this;
|
|
5528
5529
|
}
|
|
5529
5530
|
}
|
|
5530
5531
|
function getTaskQueueRegistry() {
|
|
@@ -5533,10 +5534,10 @@ function getTaskQueueRegistry() {
|
|
|
5533
5534
|
}
|
|
5534
5535
|
return taskQueueRegistry;
|
|
5535
5536
|
}
|
|
5536
|
-
function setTaskQueueRegistry(registry) {
|
|
5537
|
+
async function setTaskQueueRegistry(registry) {
|
|
5537
5538
|
if (taskQueueRegistry) {
|
|
5538
|
-
taskQueueRegistry.stopQueues();
|
|
5539
|
-
taskQueueRegistry.clearQueues();
|
|
5539
|
+
await taskQueueRegistry.stopQueues();
|
|
5540
|
+
await taskQueueRegistry.clearQueues();
|
|
5540
5541
|
}
|
|
5541
5542
|
taskQueueRegistry = registry;
|
|
5542
5543
|
}
|
|
@@ -5865,6 +5866,11 @@ queueMicrotask(() => {
|
|
|
5865
5866
|
Workflow.prototype.endReduce = CreateEndLoopWorkflow("endReduce");
|
|
5866
5867
|
});
|
|
5867
5868
|
// src/task/TaskRegistry.ts
|
|
5869
|
+
import {
|
|
5870
|
+
createServiceToken as createServiceToken3,
|
|
5871
|
+
globalServiceRegistry as globalServiceRegistry4,
|
|
5872
|
+
registerInputResolver
|
|
5873
|
+
} from "@workglow/util";
|
|
5868
5874
|
var taskConstructors = new Map;
|
|
5869
5875
|
function registerTask(baseClass) {
|
|
5870
5876
|
if (taskConstructors.has(baseClass.type)) {}
|
|
@@ -5874,56 +5880,85 @@ var TaskRegistry = {
|
|
|
5874
5880
|
all: taskConstructors,
|
|
5875
5881
|
registerTask
|
|
5876
5882
|
};
|
|
5883
|
+
var TASK_CONSTRUCTORS = createServiceToken3("task.constructors");
|
|
5884
|
+
if (!globalServiceRegistry4.has(TASK_CONSTRUCTORS)) {
|
|
5885
|
+
globalServiceRegistry4.register(TASK_CONSTRUCTORS, () => TaskRegistry.all, true);
|
|
5886
|
+
}
|
|
5887
|
+
function getGlobalTaskConstructors() {
|
|
5888
|
+
return globalServiceRegistry4.get(TASK_CONSTRUCTORS);
|
|
5889
|
+
}
|
|
5890
|
+
function setGlobalTaskConstructors(map) {
|
|
5891
|
+
globalServiceRegistry4.registerInstance(TASK_CONSTRUCTORS, map);
|
|
5892
|
+
}
|
|
5893
|
+
function getTaskConstructors(registry) {
|
|
5894
|
+
if (!registry)
|
|
5895
|
+
return TaskRegistry.all;
|
|
5896
|
+
return registry.has(TASK_CONSTRUCTORS) ? registry.get(TASK_CONSTRUCTORS) : TaskRegistry.all;
|
|
5897
|
+
}
|
|
5898
|
+
function resolveTaskFromRegistry(id, _format, registry) {
|
|
5899
|
+
const constructors = getTaskConstructors(registry);
|
|
5900
|
+
const ctor = constructors.get(id);
|
|
5901
|
+
if (!ctor)
|
|
5902
|
+
return;
|
|
5903
|
+
return {
|
|
5904
|
+
name: ctor.type,
|
|
5905
|
+
description: ctor.description ?? "",
|
|
5906
|
+
inputSchema: ctor.inputSchema(),
|
|
5907
|
+
outputSchema: ctor.outputSchema()
|
|
5908
|
+
};
|
|
5909
|
+
}
|
|
5910
|
+
registerInputResolver("tasks", resolveTaskFromRegistry);
|
|
5877
5911
|
|
|
5878
5912
|
// src/task/TaskJSON.ts
|
|
5879
|
-
var createSingleTaskFromJSON = (item,
|
|
5913
|
+
var createSingleTaskFromJSON = (item, registry) => {
|
|
5880
5914
|
if (!item.id)
|
|
5881
5915
|
throw new TaskJSONError("Task id required");
|
|
5882
5916
|
if (!item.type)
|
|
5883
5917
|
throw new TaskJSONError("Task type required");
|
|
5884
5918
|
if (item.defaults && Array.isArray(item.defaults))
|
|
5885
5919
|
throw new TaskJSONError("Task defaults must be an object");
|
|
5886
|
-
const
|
|
5920
|
+
const constructors = getTaskConstructors(registry);
|
|
5921
|
+
const taskClass = constructors.get(item.type);
|
|
5887
5922
|
if (!taskClass)
|
|
5888
5923
|
throw new TaskJSONError(`Task type ${item.type} not found, perhaps not registered?`);
|
|
5889
5924
|
const taskConfig = {
|
|
5890
5925
|
...item.config,
|
|
5891
5926
|
id: item.id
|
|
5892
5927
|
};
|
|
5893
|
-
const task = new taskClass(item.defaults ?? {}, taskConfig);
|
|
5928
|
+
const task = new taskClass(item.defaults ?? {}, taskConfig, registry ? { registry } : {});
|
|
5894
5929
|
return task;
|
|
5895
5930
|
};
|
|
5896
|
-
var createTaskFromDependencyJSON = (item) => {
|
|
5897
|
-
const task = createSingleTaskFromJSON(item);
|
|
5931
|
+
var createTaskFromDependencyJSON = (item, registry) => {
|
|
5932
|
+
const task = createSingleTaskFromJSON(item, registry);
|
|
5898
5933
|
if (item.subtasks && item.subtasks.length > 0) {
|
|
5899
5934
|
if (!(task instanceof GraphAsTask)) {
|
|
5900
5935
|
throw new TaskConfigurationError("Subgraph is only supported for CompoundTasks");
|
|
5901
5936
|
}
|
|
5902
|
-
task.subGraph = createGraphFromDependencyJSON(item.subtasks);
|
|
5937
|
+
task.subGraph = createGraphFromDependencyJSON(item.subtasks, registry);
|
|
5903
5938
|
}
|
|
5904
5939
|
return task;
|
|
5905
5940
|
};
|
|
5906
|
-
var createGraphFromDependencyJSON = (jsonItems) => {
|
|
5941
|
+
var createGraphFromDependencyJSON = (jsonItems, registry) => {
|
|
5907
5942
|
const subGraph = new TaskGraph;
|
|
5908
5943
|
for (const subitem of jsonItems) {
|
|
5909
|
-
subGraph.addTask(createTaskFromDependencyJSON(subitem));
|
|
5944
|
+
subGraph.addTask(createTaskFromDependencyJSON(subitem, registry));
|
|
5910
5945
|
}
|
|
5911
5946
|
return subGraph;
|
|
5912
5947
|
};
|
|
5913
|
-
var createTaskFromGraphJSON = (item,
|
|
5914
|
-
const task = createSingleTaskFromJSON(item,
|
|
5948
|
+
var createTaskFromGraphJSON = (item, registry) => {
|
|
5949
|
+
const task = createSingleTaskFromJSON(item, registry);
|
|
5915
5950
|
if (item.subgraph) {
|
|
5916
5951
|
if (!(task instanceof GraphAsTask)) {
|
|
5917
5952
|
throw new TaskConfigurationError("Subgraph is only supported for GraphAsTask");
|
|
5918
5953
|
}
|
|
5919
|
-
task.subGraph = createGraphFromGraphJSON(item.subgraph,
|
|
5954
|
+
task.subGraph = createGraphFromGraphJSON(item.subgraph, registry);
|
|
5920
5955
|
}
|
|
5921
5956
|
return task;
|
|
5922
5957
|
};
|
|
5923
|
-
var createGraphFromGraphJSON = (graphJsonObj,
|
|
5958
|
+
var createGraphFromGraphJSON = (graphJsonObj, registry) => {
|
|
5924
5959
|
const subGraph = new TaskGraph;
|
|
5925
5960
|
for (const subitem of graphJsonObj.tasks) {
|
|
5926
|
-
subGraph.addTask(createTaskFromGraphJSON(subitem,
|
|
5961
|
+
subGraph.addTask(createTaskFromGraphJSON(subitem, registry));
|
|
5927
5962
|
}
|
|
5928
5963
|
for (const subitem of graphJsonObj.dataflows) {
|
|
5929
5964
|
subGraph.addDataflow(new Dataflow(subitem.sourceTaskId, subitem.sourceTaskPortId, subitem.targetTaskId, subitem.targetTaskPortId));
|
|
@@ -5937,8 +5972,8 @@ var registerBaseTasks = () => {
|
|
|
5937
5972
|
return tasks;
|
|
5938
5973
|
};
|
|
5939
5974
|
// src/storage/TaskGraphRepository.ts
|
|
5940
|
-
import { createServiceToken as
|
|
5941
|
-
var TASK_GRAPH_REPOSITORY =
|
|
5975
|
+
import { createServiceToken as createServiceToken4, EventEmitter as EventEmitter6 } from "@workglow/util";
|
|
5976
|
+
var TASK_GRAPH_REPOSITORY = createServiceToken4("taskgraph.taskGraphRepository");
|
|
5942
5977
|
|
|
5943
5978
|
class TaskGraphRepository {
|
|
5944
5979
|
type = "TaskGraphRepository";
|
|
@@ -5979,9 +6014,11 @@ var TaskGraphPrimaryKeyNames = ["key"];
|
|
|
5979
6014
|
class TaskGraphTabularRepository extends TaskGraphRepository {
|
|
5980
6015
|
type = "TaskGraphTabularRepository";
|
|
5981
6016
|
tabularRepository;
|
|
5982
|
-
|
|
6017
|
+
registry;
|
|
6018
|
+
constructor({ tabularRepository, registry }) {
|
|
5983
6019
|
super();
|
|
5984
6020
|
this.tabularRepository = tabularRepository;
|
|
6021
|
+
this.registry = registry;
|
|
5985
6022
|
}
|
|
5986
6023
|
async setupDatabase() {
|
|
5987
6024
|
await this.tabularRepository.setupDatabase?.();
|
|
@@ -5998,7 +6035,7 @@ class TaskGraphTabularRepository extends TaskGraphRepository {
|
|
|
5998
6035
|
return;
|
|
5999
6036
|
}
|
|
6000
6037
|
const jsonObj = JSON.parse(value);
|
|
6001
|
-
const graph = createGraphFromGraphJSON(jsonObj);
|
|
6038
|
+
const graph = createGraphFromGraphJSON(jsonObj, this.registry);
|
|
6002
6039
|
this.emit("graph_retrieved", key);
|
|
6003
6040
|
return graph;
|
|
6004
6041
|
}
|
|
@@ -6096,6 +6133,7 @@ export {
|
|
|
6096
6133
|
wrapSchemaInArray,
|
|
6097
6134
|
whileTaskConfigSchema,
|
|
6098
6135
|
setTaskQueueRegistry,
|
|
6136
|
+
setGlobalTaskConstructors,
|
|
6099
6137
|
serialGraph,
|
|
6100
6138
|
schemaAcceptsArray,
|
|
6101
6139
|
resolveSchemaInputs,
|
|
@@ -6118,6 +6156,7 @@ export {
|
|
|
6118
6156
|
hasStructuredOutput,
|
|
6119
6157
|
graphAsTaskConfigSchema,
|
|
6120
6158
|
getTaskQueueRegistry,
|
|
6159
|
+
getTaskConstructors,
|
|
6121
6160
|
getStructuredOutputSchemas,
|
|
6122
6161
|
getStreamingPorts,
|
|
6123
6162
|
getPortStreamMode,
|
|
@@ -6128,6 +6167,7 @@ export {
|
|
|
6128
6167
|
getJobQueueFactory,
|
|
6129
6168
|
getIterationContextSchemaForType,
|
|
6130
6169
|
getInputModeFromSchema,
|
|
6170
|
+
getGlobalTaskConstructors,
|
|
6131
6171
|
getAppendPortId,
|
|
6132
6172
|
findArrayPorts,
|
|
6133
6173
|
filterIterationProperties,
|
|
@@ -6182,6 +6222,7 @@ export {
|
|
|
6182
6222
|
Task,
|
|
6183
6223
|
TASK_OUTPUT_REPOSITORY,
|
|
6184
6224
|
TASK_GRAPH_REPOSITORY,
|
|
6225
|
+
TASK_CONSTRUCTORS,
|
|
6185
6226
|
ReduceTask,
|
|
6186
6227
|
PROPERTY_ARRAY,
|
|
6187
6228
|
MapTask,
|
|
@@ -6209,4 +6250,4 @@ export {
|
|
|
6209
6250
|
ConditionalTask
|
|
6210
6251
|
};
|
|
6211
6252
|
|
|
6212
|
-
//# debugId=
|
|
6253
|
+
//# debugId=5979668511C1CA3D64756E2164756E21
|