@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/node.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.every((item) => typeof item === "string")) {
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
  }
@@ -5862,6 +5866,11 @@ queueMicrotask(() => {
5862
5866
  Workflow.prototype.endReduce = CreateEndLoopWorkflow("endReduce");
5863
5867
  });
5864
5868
  // src/task/TaskRegistry.ts
5869
+ import {
5870
+ createServiceToken as createServiceToken3,
5871
+ globalServiceRegistry as globalServiceRegistry4,
5872
+ registerInputResolver
5873
+ } from "@workglow/util";
5865
5874
  var taskConstructors = new Map;
5866
5875
  function registerTask(baseClass) {
5867
5876
  if (taskConstructors.has(baseClass.type)) {}
@@ -5871,56 +5880,85 @@ var TaskRegistry = {
5871
5880
  all: taskConstructors,
5872
5881
  registerTask
5873
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);
5874
5911
 
5875
5912
  // src/task/TaskJSON.ts
5876
- var createSingleTaskFromJSON = (item, taskRegistry) => {
5913
+ var createSingleTaskFromJSON = (item, registry) => {
5877
5914
  if (!item.id)
5878
5915
  throw new TaskJSONError("Task id required");
5879
5916
  if (!item.type)
5880
5917
  throw new TaskJSONError("Task type required");
5881
5918
  if (item.defaults && Array.isArray(item.defaults))
5882
5919
  throw new TaskJSONError("Task defaults must be an object");
5883
- const taskClass = taskRegistry?.get(item.type) ?? TaskRegistry.all.get(item.type);
5920
+ const constructors = getTaskConstructors(registry);
5921
+ const taskClass = constructors.get(item.type);
5884
5922
  if (!taskClass)
5885
5923
  throw new TaskJSONError(`Task type ${item.type} not found, perhaps not registered?`);
5886
5924
  const taskConfig = {
5887
5925
  ...item.config,
5888
5926
  id: item.id
5889
5927
  };
5890
- const task = new taskClass(item.defaults ?? {}, taskConfig);
5928
+ const task = new taskClass(item.defaults ?? {}, taskConfig, registry ? { registry } : {});
5891
5929
  return task;
5892
5930
  };
5893
- var createTaskFromDependencyJSON = (item) => {
5894
- const task = createSingleTaskFromJSON(item);
5931
+ var createTaskFromDependencyJSON = (item, registry) => {
5932
+ const task = createSingleTaskFromJSON(item, registry);
5895
5933
  if (item.subtasks && item.subtasks.length > 0) {
5896
5934
  if (!(task instanceof GraphAsTask)) {
5897
5935
  throw new TaskConfigurationError("Subgraph is only supported for CompoundTasks");
5898
5936
  }
5899
- task.subGraph = createGraphFromDependencyJSON(item.subtasks);
5937
+ task.subGraph = createGraphFromDependencyJSON(item.subtasks, registry);
5900
5938
  }
5901
5939
  return task;
5902
5940
  };
5903
- var createGraphFromDependencyJSON = (jsonItems) => {
5941
+ var createGraphFromDependencyJSON = (jsonItems, registry) => {
5904
5942
  const subGraph = new TaskGraph;
5905
5943
  for (const subitem of jsonItems) {
5906
- subGraph.addTask(createTaskFromDependencyJSON(subitem));
5944
+ subGraph.addTask(createTaskFromDependencyJSON(subitem, registry));
5907
5945
  }
5908
5946
  return subGraph;
5909
5947
  };
5910
- var createTaskFromGraphJSON = (item, taskRegistry) => {
5911
- const task = createSingleTaskFromJSON(item, taskRegistry);
5948
+ var createTaskFromGraphJSON = (item, registry) => {
5949
+ const task = createSingleTaskFromJSON(item, registry);
5912
5950
  if (item.subgraph) {
5913
5951
  if (!(task instanceof GraphAsTask)) {
5914
5952
  throw new TaskConfigurationError("Subgraph is only supported for GraphAsTask");
5915
5953
  }
5916
- task.subGraph = createGraphFromGraphJSON(item.subgraph, taskRegistry);
5954
+ task.subGraph = createGraphFromGraphJSON(item.subgraph, registry);
5917
5955
  }
5918
5956
  return task;
5919
5957
  };
5920
- var createGraphFromGraphJSON = (graphJsonObj, taskRegistry) => {
5958
+ var createGraphFromGraphJSON = (graphJsonObj, registry) => {
5921
5959
  const subGraph = new TaskGraph;
5922
5960
  for (const subitem of graphJsonObj.tasks) {
5923
- subGraph.addTask(createTaskFromGraphJSON(subitem, taskRegistry));
5961
+ subGraph.addTask(createTaskFromGraphJSON(subitem, registry));
5924
5962
  }
5925
5963
  for (const subitem of graphJsonObj.dataflows) {
5926
5964
  subGraph.addDataflow(new Dataflow(subitem.sourceTaskId, subitem.sourceTaskPortId, subitem.targetTaskId, subitem.targetTaskPortId));
@@ -5934,8 +5972,8 @@ var registerBaseTasks = () => {
5934
5972
  return tasks;
5935
5973
  };
5936
5974
  // src/storage/TaskGraphRepository.ts
5937
- import { createServiceToken as createServiceToken3, EventEmitter as EventEmitter6 } from "@workglow/util";
5938
- var TASK_GRAPH_REPOSITORY = createServiceToken3("taskgraph.taskGraphRepository");
5975
+ import { createServiceToken as createServiceToken4, EventEmitter as EventEmitter6 } from "@workglow/util";
5976
+ var TASK_GRAPH_REPOSITORY = createServiceToken4("taskgraph.taskGraphRepository");
5939
5977
 
5940
5978
  class TaskGraphRepository {
5941
5979
  type = "TaskGraphRepository";
@@ -5976,9 +6014,11 @@ var TaskGraphPrimaryKeyNames = ["key"];
5976
6014
  class TaskGraphTabularRepository extends TaskGraphRepository {
5977
6015
  type = "TaskGraphTabularRepository";
5978
6016
  tabularRepository;
5979
- constructor({ tabularRepository }) {
6017
+ registry;
6018
+ constructor({ tabularRepository, registry }) {
5980
6019
  super();
5981
6020
  this.tabularRepository = tabularRepository;
6021
+ this.registry = registry;
5982
6022
  }
5983
6023
  async setupDatabase() {
5984
6024
  await this.tabularRepository.setupDatabase?.();
@@ -5995,7 +6035,7 @@ class TaskGraphTabularRepository extends TaskGraphRepository {
5995
6035
  return;
5996
6036
  }
5997
6037
  const jsonObj = JSON.parse(value);
5998
- const graph = createGraphFromGraphJSON(jsonObj);
6038
+ const graph = createGraphFromGraphJSON(jsonObj, this.registry);
5999
6039
  this.emit("graph_retrieved", key);
6000
6040
  return graph;
6001
6041
  }
@@ -6093,6 +6133,7 @@ export {
6093
6133
  wrapSchemaInArray,
6094
6134
  whileTaskConfigSchema,
6095
6135
  setTaskQueueRegistry,
6136
+ setGlobalTaskConstructors,
6096
6137
  serialGraph,
6097
6138
  schemaAcceptsArray,
6098
6139
  resolveSchemaInputs,
@@ -6115,6 +6156,7 @@ export {
6115
6156
  hasStructuredOutput,
6116
6157
  graphAsTaskConfigSchema,
6117
6158
  getTaskQueueRegistry,
6159
+ getTaskConstructors,
6118
6160
  getStructuredOutputSchemas,
6119
6161
  getStreamingPorts,
6120
6162
  getPortStreamMode,
@@ -6125,6 +6167,7 @@ export {
6125
6167
  getJobQueueFactory,
6126
6168
  getIterationContextSchemaForType,
6127
6169
  getInputModeFromSchema,
6170
+ getGlobalTaskConstructors,
6128
6171
  getAppendPortId,
6129
6172
  findArrayPorts,
6130
6173
  filterIterationProperties,
@@ -6179,6 +6222,7 @@ export {
6179
6222
  Task,
6180
6223
  TASK_OUTPUT_REPOSITORY,
6181
6224
  TASK_GRAPH_REPOSITORY,
6225
+ TASK_CONSTRUCTORS,
6182
6226
  ReduceTask,
6183
6227
  PROPERTY_ARRAY,
6184
6228
  MapTask,
@@ -6206,4 +6250,4 @@ export {
6206
6250
  ConditionalTask
6207
6251
  };
6208
6252
 
6209
- //# debugId=151B3C79E52B799864756E2164756E21
6253
+ //# debugId=20201DC9CC0358D464756E2164756E21