@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/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.every((item) => typeof item === "string")) {
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
  }
@@ -5509,23 +5513,20 @@ class TaskQueueRegistry {
5509
5513
  getQueue(queueName) {
5510
5514
  return this.queues.get(queueName);
5511
5515
  }
5512
- startQueues() {
5516
+ async startQueues() {
5513
5517
  for (const queue of this.queues.values()) {
5514
- queue.server.start();
5518
+ await queue.server.start();
5515
5519
  }
5516
- return this;
5517
5520
  }
5518
- stopQueues() {
5521
+ async stopQueues() {
5519
5522
  for (const queue of this.queues.values()) {
5520
- queue.server.stop();
5523
+ await queue.server.stop();
5521
5524
  }
5522
- return this;
5523
5525
  }
5524
- clearQueues() {
5526
+ async clearQueues() {
5525
5527
  for (const queue of this.queues.values()) {
5526
- queue.storage.deleteAll();
5528
+ await queue.storage.deleteAll();
5527
5529
  }
5528
- return this;
5529
5530
  }
5530
5531
  }
5531
5532
  function getTaskQueueRegistry() {
@@ -5534,10 +5535,10 @@ function getTaskQueueRegistry() {
5534
5535
  }
5535
5536
  return taskQueueRegistry;
5536
5537
  }
5537
- function setTaskQueueRegistry(registry) {
5538
+ async function setTaskQueueRegistry(registry) {
5538
5539
  if (taskQueueRegistry) {
5539
- taskQueueRegistry.stopQueues();
5540
- taskQueueRegistry.clearQueues();
5540
+ await taskQueueRegistry.stopQueues();
5541
+ await taskQueueRegistry.clearQueues();
5541
5542
  }
5542
5543
  taskQueueRegistry = registry;
5543
5544
  }
@@ -5866,6 +5867,11 @@ queueMicrotask(() => {
5866
5867
  Workflow.prototype.endReduce = CreateEndLoopWorkflow("endReduce");
5867
5868
  });
5868
5869
  // src/task/TaskRegistry.ts
5870
+ import {
5871
+ createServiceToken as createServiceToken3,
5872
+ globalServiceRegistry as globalServiceRegistry4,
5873
+ registerInputResolver
5874
+ } from "@workglow/util";
5869
5875
  var taskConstructors = new Map;
5870
5876
  function registerTask(baseClass) {
5871
5877
  if (taskConstructors.has(baseClass.type)) {}
@@ -5875,56 +5881,85 @@ var TaskRegistry = {
5875
5881
  all: taskConstructors,
5876
5882
  registerTask
5877
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);
5878
5912
 
5879
5913
  // src/task/TaskJSON.ts
5880
- var createSingleTaskFromJSON = (item, taskRegistry) => {
5914
+ var createSingleTaskFromJSON = (item, registry) => {
5881
5915
  if (!item.id)
5882
5916
  throw new TaskJSONError("Task id required");
5883
5917
  if (!item.type)
5884
5918
  throw new TaskJSONError("Task type required");
5885
5919
  if (item.defaults && Array.isArray(item.defaults))
5886
5920
  throw new TaskJSONError("Task defaults must be an object");
5887
- const taskClass = taskRegistry?.get(item.type) ?? TaskRegistry.all.get(item.type);
5921
+ const constructors = getTaskConstructors(registry);
5922
+ const taskClass = constructors.get(item.type);
5888
5923
  if (!taskClass)
5889
5924
  throw new TaskJSONError(`Task type ${item.type} not found, perhaps not registered?`);
5890
5925
  const taskConfig = {
5891
5926
  ...item.config,
5892
5927
  id: item.id
5893
5928
  };
5894
- const task = new taskClass(item.defaults ?? {}, taskConfig);
5929
+ const task = new taskClass(item.defaults ?? {}, taskConfig, registry ? { registry } : {});
5895
5930
  return task;
5896
5931
  };
5897
- var createTaskFromDependencyJSON = (item) => {
5898
- const task = createSingleTaskFromJSON(item);
5932
+ var createTaskFromDependencyJSON = (item, registry) => {
5933
+ const task = createSingleTaskFromJSON(item, registry);
5899
5934
  if (item.subtasks && item.subtasks.length > 0) {
5900
5935
  if (!(task instanceof GraphAsTask)) {
5901
5936
  throw new TaskConfigurationError("Subgraph is only supported for CompoundTasks");
5902
5937
  }
5903
- task.subGraph = createGraphFromDependencyJSON(item.subtasks);
5938
+ task.subGraph = createGraphFromDependencyJSON(item.subtasks, registry);
5904
5939
  }
5905
5940
  return task;
5906
5941
  };
5907
- var createGraphFromDependencyJSON = (jsonItems) => {
5942
+ var createGraphFromDependencyJSON = (jsonItems, registry) => {
5908
5943
  const subGraph = new TaskGraph;
5909
5944
  for (const subitem of jsonItems) {
5910
- subGraph.addTask(createTaskFromDependencyJSON(subitem));
5945
+ subGraph.addTask(createTaskFromDependencyJSON(subitem, registry));
5911
5946
  }
5912
5947
  return subGraph;
5913
5948
  };
5914
- var createTaskFromGraphJSON = (item, taskRegistry) => {
5915
- const task = createSingleTaskFromJSON(item, taskRegistry);
5949
+ var createTaskFromGraphJSON = (item, registry) => {
5950
+ const task = createSingleTaskFromJSON(item, registry);
5916
5951
  if (item.subgraph) {
5917
5952
  if (!(task instanceof GraphAsTask)) {
5918
5953
  throw new TaskConfigurationError("Subgraph is only supported for GraphAsTask");
5919
5954
  }
5920
- task.subGraph = createGraphFromGraphJSON(item.subgraph, taskRegistry);
5955
+ task.subGraph = createGraphFromGraphJSON(item.subgraph, registry);
5921
5956
  }
5922
5957
  return task;
5923
5958
  };
5924
- var createGraphFromGraphJSON = (graphJsonObj, taskRegistry) => {
5959
+ var createGraphFromGraphJSON = (graphJsonObj, registry) => {
5925
5960
  const subGraph = new TaskGraph;
5926
5961
  for (const subitem of graphJsonObj.tasks) {
5927
- subGraph.addTask(createTaskFromGraphJSON(subitem, taskRegistry));
5962
+ subGraph.addTask(createTaskFromGraphJSON(subitem, registry));
5928
5963
  }
5929
5964
  for (const subitem of graphJsonObj.dataflows) {
5930
5965
  subGraph.addDataflow(new Dataflow(subitem.sourceTaskId, subitem.sourceTaskPortId, subitem.targetTaskId, subitem.targetTaskPortId));
@@ -5938,8 +5973,8 @@ var registerBaseTasks = () => {
5938
5973
  return tasks;
5939
5974
  };
5940
5975
  // src/storage/TaskGraphRepository.ts
5941
- import { createServiceToken as createServiceToken3, EventEmitter as EventEmitter6 } from "@workglow/util";
5942
- var TASK_GRAPH_REPOSITORY = createServiceToken3("taskgraph.taskGraphRepository");
5976
+ import { createServiceToken as createServiceToken4, EventEmitter as EventEmitter6 } from "@workglow/util";
5977
+ var TASK_GRAPH_REPOSITORY = createServiceToken4("taskgraph.taskGraphRepository");
5943
5978
 
5944
5979
  class TaskGraphRepository {
5945
5980
  type = "TaskGraphRepository";
@@ -5980,9 +6015,11 @@ var TaskGraphPrimaryKeyNames = ["key"];
5980
6015
  class TaskGraphTabularRepository extends TaskGraphRepository {
5981
6016
  type = "TaskGraphTabularRepository";
5982
6017
  tabularRepository;
5983
- constructor({ tabularRepository }) {
6018
+ registry;
6019
+ constructor({ tabularRepository, registry }) {
5984
6020
  super();
5985
6021
  this.tabularRepository = tabularRepository;
6022
+ this.registry = registry;
5986
6023
  }
5987
6024
  async setupDatabase() {
5988
6025
  await this.tabularRepository.setupDatabase?.();
@@ -5999,7 +6036,7 @@ class TaskGraphTabularRepository extends TaskGraphRepository {
5999
6036
  return;
6000
6037
  }
6001
6038
  const jsonObj = JSON.parse(value);
6002
- const graph = createGraphFromGraphJSON(jsonObj);
6039
+ const graph = createGraphFromGraphJSON(jsonObj, this.registry);
6003
6040
  this.emit("graph_retrieved", key);
6004
6041
  return graph;
6005
6042
  }
@@ -6097,6 +6134,7 @@ export {
6097
6134
  wrapSchemaInArray,
6098
6135
  whileTaskConfigSchema,
6099
6136
  setTaskQueueRegistry,
6137
+ setGlobalTaskConstructors,
6100
6138
  serialGraph,
6101
6139
  schemaAcceptsArray,
6102
6140
  resolveSchemaInputs,
@@ -6119,6 +6157,7 @@ export {
6119
6157
  hasStructuredOutput,
6120
6158
  graphAsTaskConfigSchema,
6121
6159
  getTaskQueueRegistry,
6160
+ getTaskConstructors,
6122
6161
  getStructuredOutputSchemas,
6123
6162
  getStreamingPorts,
6124
6163
  getPortStreamMode,
@@ -6129,6 +6168,7 @@ export {
6129
6168
  getJobQueueFactory,
6130
6169
  getIterationContextSchemaForType,
6131
6170
  getInputModeFromSchema,
6171
+ getGlobalTaskConstructors,
6132
6172
  getAppendPortId,
6133
6173
  findArrayPorts,
6134
6174
  filterIterationProperties,
@@ -6183,6 +6223,7 @@ export {
6183
6223
  Task,
6184
6224
  TASK_OUTPUT_REPOSITORY,
6185
6225
  TASK_GRAPH_REPOSITORY,
6226
+ TASK_CONSTRUCTORS,
6186
6227
  ReduceTask,
6187
6228
  PROPERTY_ARRAY,
6188
6229
  MapTask,
@@ -6210,4 +6251,4 @@ export {
6210
6251
  ConditionalTask
6211
6252
  };
6212
6253
 
6213
- //# debugId=D8AFA9046FA8621E64756E2164756E21
6254
+ //# debugId=4EA0BC88063B5C3D64756E2164756E21