@workglow/task-graph 0.0.110 → 0.0.113
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 +72 -28
- package/dist/browser.js.map +9 -9
- package/dist/bun.js +72 -28
- package/dist/bun.js.map +9 -9
- package/dist/node.js +72 -28
- package/dist/node.js.map +9 -9
- 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/TaskJSON.d.ts +58 -16
- package/dist/task/TaskJSON.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 +7 -7
package/dist/bun.js
CHANGED
|
@@ -849,8 +849,8 @@ async function resolveSchemaInputs(input, schema, config) {
|
|
|
849
849
|
if (typeof value === "string") {
|
|
850
850
|
value = await resolver(value, format, config.registry);
|
|
851
851
|
resolved[key] = value;
|
|
852
|
-
} else if (Array.isArray(value) && value.
|
|
853
|
-
const results = await Promise.all(value.map((item) => resolver(item, format, config.registry)));
|
|
852
|
+
} else if (Array.isArray(value) && value.some((item) => typeof item === "string")) {
|
|
853
|
+
const results = await Promise.all(value.map((item) => typeof item === "string" ? resolver(item, format, config.registry) : item));
|
|
854
854
|
value = results.filter((result) => result !== undefined);
|
|
855
855
|
resolved[key] = value;
|
|
856
856
|
}
|
|
@@ -2200,8 +2200,8 @@ class TaskGraphRunner {
|
|
|
2200
2200
|
await this.handleComplete();
|
|
2201
2201
|
return results;
|
|
2202
2202
|
}
|
|
2203
|
-
async runGraphReactive(input = {}) {
|
|
2204
|
-
await this.handleStartReactive();
|
|
2203
|
+
async runGraphReactive(input = {}, config) {
|
|
2204
|
+
await this.handleStartReactive(config);
|
|
2205
2205
|
const results = [];
|
|
2206
2206
|
try {
|
|
2207
2207
|
for await (const task of this.reactiveScheduler.tasks()) {
|
|
@@ -2584,7 +2584,7 @@ class TaskGraphRunner {
|
|
|
2584
2584
|
async handleStart(config) {
|
|
2585
2585
|
if (config?.registry !== undefined) {
|
|
2586
2586
|
this.registry = config.registry;
|
|
2587
|
-
} else {
|
|
2587
|
+
} else if (this.registry === undefined) {
|
|
2588
2588
|
this.registry = new ServiceRegistry2(globalServiceRegistry2.container.createChildContainer());
|
|
2589
2589
|
}
|
|
2590
2590
|
this.accumulateLeafOutputs = config?.accumulateLeafOutputs !== false;
|
|
@@ -2627,10 +2627,13 @@ class TaskGraphRunner {
|
|
|
2627
2627
|
logger.time(this.timerLabel);
|
|
2628
2628
|
this.graph.emit("start");
|
|
2629
2629
|
}
|
|
2630
|
-
async handleStartReactive() {
|
|
2630
|
+
async handleStartReactive(config) {
|
|
2631
2631
|
if (this.reactiveRunning) {
|
|
2632
2632
|
throw new TaskConfigurationError("Graph is already running reactively");
|
|
2633
2633
|
}
|
|
2634
|
+
if (config?.registry !== undefined) {
|
|
2635
|
+
this.registry = config.registry;
|
|
2636
|
+
}
|
|
2634
2637
|
this.reactiveScheduler.reset();
|
|
2635
2638
|
this.reactiveRunning = true;
|
|
2636
2639
|
}
|
|
@@ -3790,11 +3793,12 @@ class TaskGraph {
|
|
|
3790
3793
|
return this.runner.runGraph(input, {
|
|
3791
3794
|
outputCache: config?.outputCache || this.outputCache,
|
|
3792
3795
|
parentSignal: config?.parentSignal || undefined,
|
|
3793
|
-
accumulateLeafOutputs: config?.accumulateLeafOutputs
|
|
3796
|
+
accumulateLeafOutputs: config?.accumulateLeafOutputs,
|
|
3797
|
+
registry: config?.registry
|
|
3794
3798
|
});
|
|
3795
3799
|
}
|
|
3796
|
-
runReactive(input = {}) {
|
|
3797
|
-
return this.runner.runGraphReactive(input);
|
|
3800
|
+
runReactive(input = {}, config = {}) {
|
|
3801
|
+
return this.runner.runGraphReactive(input, config);
|
|
3798
3802
|
}
|
|
3799
3803
|
mergeExecuteOutputsToRunOutput(results, compoundMerge) {
|
|
3800
3804
|
return this.runner.mergeExecuteOutputsToRunOutput(results, compoundMerge);
|
|
@@ -4346,7 +4350,7 @@ class IteratorTaskRunner extends GraphAsTaskRunner {
|
|
|
4346
4350
|
const clone = new TaskGraph;
|
|
4347
4351
|
for (const task of graph.getTasks()) {
|
|
4348
4352
|
const ctor = task.constructor;
|
|
4349
|
-
const newTask = new ctor(task.defaults, task.config);
|
|
4353
|
+
const newTask = new ctor(task.defaults, task.config, task.runConfig);
|
|
4350
4354
|
if (task.hasChildren()) {
|
|
4351
4355
|
newTask.subGraph = this.cloneGraph(task.subGraph);
|
|
4352
4356
|
}
|
|
@@ -5863,6 +5867,11 @@ queueMicrotask(() => {
|
|
|
5863
5867
|
Workflow.prototype.endReduce = CreateEndLoopWorkflow("endReduce");
|
|
5864
5868
|
});
|
|
5865
5869
|
// src/task/TaskRegistry.ts
|
|
5870
|
+
import {
|
|
5871
|
+
createServiceToken as createServiceToken3,
|
|
5872
|
+
globalServiceRegistry as globalServiceRegistry4,
|
|
5873
|
+
registerInputResolver
|
|
5874
|
+
} from "@workglow/util";
|
|
5866
5875
|
var taskConstructors = new Map;
|
|
5867
5876
|
function registerTask(baseClass) {
|
|
5868
5877
|
if (taskConstructors.has(baseClass.type)) {}
|
|
@@ -5872,56 +5881,85 @@ var TaskRegistry = {
|
|
|
5872
5881
|
all: taskConstructors,
|
|
5873
5882
|
registerTask
|
|
5874
5883
|
};
|
|
5884
|
+
var TASK_CONSTRUCTORS = createServiceToken3("task.constructors");
|
|
5885
|
+
if (!globalServiceRegistry4.has(TASK_CONSTRUCTORS)) {
|
|
5886
|
+
globalServiceRegistry4.register(TASK_CONSTRUCTORS, () => TaskRegistry.all, true);
|
|
5887
|
+
}
|
|
5888
|
+
function getGlobalTaskConstructors() {
|
|
5889
|
+
return globalServiceRegistry4.get(TASK_CONSTRUCTORS);
|
|
5890
|
+
}
|
|
5891
|
+
function setGlobalTaskConstructors(map) {
|
|
5892
|
+
globalServiceRegistry4.registerInstance(TASK_CONSTRUCTORS, map);
|
|
5893
|
+
}
|
|
5894
|
+
function getTaskConstructors(registry) {
|
|
5895
|
+
if (!registry)
|
|
5896
|
+
return TaskRegistry.all;
|
|
5897
|
+
return registry.has(TASK_CONSTRUCTORS) ? registry.get(TASK_CONSTRUCTORS) : TaskRegistry.all;
|
|
5898
|
+
}
|
|
5899
|
+
function resolveTaskFromRegistry(id, _format, registry) {
|
|
5900
|
+
const constructors = getTaskConstructors(registry);
|
|
5901
|
+
const ctor = constructors.get(id);
|
|
5902
|
+
if (!ctor)
|
|
5903
|
+
return;
|
|
5904
|
+
return {
|
|
5905
|
+
name: ctor.type,
|
|
5906
|
+
description: ctor.description ?? "",
|
|
5907
|
+
inputSchema: ctor.inputSchema(),
|
|
5908
|
+
outputSchema: ctor.outputSchema()
|
|
5909
|
+
};
|
|
5910
|
+
}
|
|
5911
|
+
registerInputResolver("tasks", resolveTaskFromRegistry);
|
|
5875
5912
|
|
|
5876
5913
|
// src/task/TaskJSON.ts
|
|
5877
|
-
var createSingleTaskFromJSON = (item,
|
|
5914
|
+
var createSingleTaskFromJSON = (item, registry) => {
|
|
5878
5915
|
if (!item.id)
|
|
5879
5916
|
throw new TaskJSONError("Task id required");
|
|
5880
5917
|
if (!item.type)
|
|
5881
5918
|
throw new TaskJSONError("Task type required");
|
|
5882
5919
|
if (item.defaults && Array.isArray(item.defaults))
|
|
5883
5920
|
throw new TaskJSONError("Task defaults must be an object");
|
|
5884
|
-
const
|
|
5921
|
+
const constructors = getTaskConstructors(registry);
|
|
5922
|
+
const taskClass = constructors.get(item.type);
|
|
5885
5923
|
if (!taskClass)
|
|
5886
5924
|
throw new TaskJSONError(`Task type ${item.type} not found, perhaps not registered?`);
|
|
5887
5925
|
const taskConfig = {
|
|
5888
5926
|
...item.config,
|
|
5889
5927
|
id: item.id
|
|
5890
5928
|
};
|
|
5891
|
-
const task = new taskClass(item.defaults ?? {}, taskConfig);
|
|
5929
|
+
const task = new taskClass(item.defaults ?? {}, taskConfig, registry ? { registry } : {});
|
|
5892
5930
|
return task;
|
|
5893
5931
|
};
|
|
5894
|
-
var createTaskFromDependencyJSON = (item) => {
|
|
5895
|
-
const task = createSingleTaskFromJSON(item);
|
|
5932
|
+
var createTaskFromDependencyJSON = (item, registry) => {
|
|
5933
|
+
const task = createSingleTaskFromJSON(item, registry);
|
|
5896
5934
|
if (item.subtasks && item.subtasks.length > 0) {
|
|
5897
5935
|
if (!(task instanceof GraphAsTask)) {
|
|
5898
5936
|
throw new TaskConfigurationError("Subgraph is only supported for CompoundTasks");
|
|
5899
5937
|
}
|
|
5900
|
-
task.subGraph = createGraphFromDependencyJSON(item.subtasks);
|
|
5938
|
+
task.subGraph = createGraphFromDependencyJSON(item.subtasks, registry);
|
|
5901
5939
|
}
|
|
5902
5940
|
return task;
|
|
5903
5941
|
};
|
|
5904
|
-
var createGraphFromDependencyJSON = (jsonItems) => {
|
|
5942
|
+
var createGraphFromDependencyJSON = (jsonItems, registry) => {
|
|
5905
5943
|
const subGraph = new TaskGraph;
|
|
5906
5944
|
for (const subitem of jsonItems) {
|
|
5907
|
-
subGraph.addTask(createTaskFromDependencyJSON(subitem));
|
|
5945
|
+
subGraph.addTask(createTaskFromDependencyJSON(subitem, registry));
|
|
5908
5946
|
}
|
|
5909
5947
|
return subGraph;
|
|
5910
5948
|
};
|
|
5911
|
-
var createTaskFromGraphJSON = (item,
|
|
5912
|
-
const task = createSingleTaskFromJSON(item,
|
|
5949
|
+
var createTaskFromGraphJSON = (item, registry) => {
|
|
5950
|
+
const task = createSingleTaskFromJSON(item, registry);
|
|
5913
5951
|
if (item.subgraph) {
|
|
5914
5952
|
if (!(task instanceof GraphAsTask)) {
|
|
5915
5953
|
throw new TaskConfigurationError("Subgraph is only supported for GraphAsTask");
|
|
5916
5954
|
}
|
|
5917
|
-
task.subGraph = createGraphFromGraphJSON(item.subgraph,
|
|
5955
|
+
task.subGraph = createGraphFromGraphJSON(item.subgraph, registry);
|
|
5918
5956
|
}
|
|
5919
5957
|
return task;
|
|
5920
5958
|
};
|
|
5921
|
-
var createGraphFromGraphJSON = (graphJsonObj,
|
|
5959
|
+
var createGraphFromGraphJSON = (graphJsonObj, registry) => {
|
|
5922
5960
|
const subGraph = new TaskGraph;
|
|
5923
5961
|
for (const subitem of graphJsonObj.tasks) {
|
|
5924
|
-
subGraph.addTask(createTaskFromGraphJSON(subitem,
|
|
5962
|
+
subGraph.addTask(createTaskFromGraphJSON(subitem, registry));
|
|
5925
5963
|
}
|
|
5926
5964
|
for (const subitem of graphJsonObj.dataflows) {
|
|
5927
5965
|
subGraph.addDataflow(new Dataflow(subitem.sourceTaskId, subitem.sourceTaskPortId, subitem.targetTaskId, subitem.targetTaskPortId));
|
|
@@ -5935,8 +5973,8 @@ var registerBaseTasks = () => {
|
|
|
5935
5973
|
return tasks;
|
|
5936
5974
|
};
|
|
5937
5975
|
// src/storage/TaskGraphRepository.ts
|
|
5938
|
-
import { createServiceToken as
|
|
5939
|
-
var TASK_GRAPH_REPOSITORY =
|
|
5976
|
+
import { createServiceToken as createServiceToken4, EventEmitter as EventEmitter6 } from "@workglow/util";
|
|
5977
|
+
var TASK_GRAPH_REPOSITORY = createServiceToken4("taskgraph.taskGraphRepository");
|
|
5940
5978
|
|
|
5941
5979
|
class TaskGraphRepository {
|
|
5942
5980
|
type = "TaskGraphRepository";
|
|
@@ -5977,9 +6015,11 @@ var TaskGraphPrimaryKeyNames = ["key"];
|
|
|
5977
6015
|
class TaskGraphTabularRepository extends TaskGraphRepository {
|
|
5978
6016
|
type = "TaskGraphTabularRepository";
|
|
5979
6017
|
tabularRepository;
|
|
5980
|
-
|
|
6018
|
+
registry;
|
|
6019
|
+
constructor({ tabularRepository, registry }) {
|
|
5981
6020
|
super();
|
|
5982
6021
|
this.tabularRepository = tabularRepository;
|
|
6022
|
+
this.registry = registry;
|
|
5983
6023
|
}
|
|
5984
6024
|
async setupDatabase() {
|
|
5985
6025
|
await this.tabularRepository.setupDatabase?.();
|
|
@@ -5996,7 +6036,7 @@ class TaskGraphTabularRepository extends TaskGraphRepository {
|
|
|
5996
6036
|
return;
|
|
5997
6037
|
}
|
|
5998
6038
|
const jsonObj = JSON.parse(value);
|
|
5999
|
-
const graph = createGraphFromGraphJSON(jsonObj);
|
|
6039
|
+
const graph = createGraphFromGraphJSON(jsonObj, this.registry);
|
|
6000
6040
|
this.emit("graph_retrieved", key);
|
|
6001
6041
|
return graph;
|
|
6002
6042
|
}
|
|
@@ -6094,6 +6134,7 @@ export {
|
|
|
6094
6134
|
wrapSchemaInArray,
|
|
6095
6135
|
whileTaskConfigSchema,
|
|
6096
6136
|
setTaskQueueRegistry,
|
|
6137
|
+
setGlobalTaskConstructors,
|
|
6097
6138
|
serialGraph,
|
|
6098
6139
|
schemaAcceptsArray,
|
|
6099
6140
|
resolveSchemaInputs,
|
|
@@ -6116,6 +6157,7 @@ export {
|
|
|
6116
6157
|
hasStructuredOutput,
|
|
6117
6158
|
graphAsTaskConfigSchema,
|
|
6118
6159
|
getTaskQueueRegistry,
|
|
6160
|
+
getTaskConstructors,
|
|
6119
6161
|
getStructuredOutputSchemas,
|
|
6120
6162
|
getStreamingPorts,
|
|
6121
6163
|
getPortStreamMode,
|
|
@@ -6126,6 +6168,7 @@ export {
|
|
|
6126
6168
|
getJobQueueFactory,
|
|
6127
6169
|
getIterationContextSchemaForType,
|
|
6128
6170
|
getInputModeFromSchema,
|
|
6171
|
+
getGlobalTaskConstructors,
|
|
6129
6172
|
getAppendPortId,
|
|
6130
6173
|
findArrayPorts,
|
|
6131
6174
|
filterIterationProperties,
|
|
@@ -6180,6 +6223,7 @@ export {
|
|
|
6180
6223
|
Task,
|
|
6181
6224
|
TASK_OUTPUT_REPOSITORY,
|
|
6182
6225
|
TASK_GRAPH_REPOSITORY,
|
|
6226
|
+
TASK_CONSTRUCTORS,
|
|
6183
6227
|
ReduceTask,
|
|
6184
6228
|
PROPERTY_ARRAY,
|
|
6185
6229
|
MapTask,
|
|
@@ -6207,4 +6251,4 @@ export {
|
|
|
6207
6251
|
ConditionalTask
|
|
6208
6252
|
};
|
|
6209
6253
|
|
|
6210
|
-
//# debugId=
|
|
6254
|
+
//# debugId=4EA0BC88063B5C3D64756E2164756E21
|