@workglow/task-graph 0.1.0 → 0.1.2
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 +96 -5
- package/dist/browser.js.map +20 -19
- package/dist/bun.js +96 -5
- package/dist/bun.js.map +20 -19
- package/dist/node.js +96 -5
- package/dist/node.js.map +20 -19
- package/dist/storage/TaskGraphRepository.d.ts.map +1 -1
- package/dist/storage/TaskGraphTabularRepository.d.ts.map +1 -1
- package/dist/storage/TaskOutputRepository.d.ts.map +1 -1
- package/dist/storage/TaskOutputTabularRepository.d.ts.map +1 -1
- package/dist/task/ConditionalTask.d.ts.map +1 -1
- package/dist/task/FallbackTask.d.ts +20 -20
- package/dist/task/FallbackTask.d.ts.map +1 -1
- package/dist/task/GraphAsTask.d.ts.map +1 -1
- package/dist/task/GraphAsTaskRunner.d.ts.map +1 -1
- package/dist/task/InputCompactor.d.ts +37 -0
- package/dist/task/InputCompactor.d.ts.map +1 -0
- package/dist/task/InputResolver.d.ts +18 -0
- package/dist/task/InputResolver.d.ts.map +1 -1
- package/dist/task/IteratorTask.d.ts.map +1 -1
- package/dist/task/MapTask.d.ts.map +1 -1
- package/dist/task/ReduceTask.d.ts.map +1 -1
- package/dist/task/TaskError.d.ts.map +1 -1
- package/dist/task/TaskJSON.d.ts +4 -4
- package/dist/task/TaskJSON.d.ts.map +1 -1
- package/dist/task/TaskRegistry.d.ts.map +1 -1
- package/dist/task/TaskTypes.d.ts.map +1 -1
- package/dist/task/WhileTask.d.ts.map +1 -1
- package/dist/task/index.d.ts +1 -0
- package/dist/task/index.d.ts.map +1 -1
- package/dist/task-graph/GraphToWorkflowCode.d.ts.map +1 -1
- package/dist/task-graph/TaskGraphEvents.d.ts.map +1 -1
- package/dist/task-graph/TaskGraphRunner.d.ts.map +1 -1
- package/dist/task-graph/Workflow.d.ts +5 -2
- package/dist/task-graph/Workflow.d.ts.map +1 -1
- package/package.json +7 -7
package/dist/bun.js
CHANGED
|
@@ -3659,10 +3659,11 @@ class WorkflowTask extends GraphAsTask {
|
|
|
3659
3659
|
}
|
|
3660
3660
|
|
|
3661
3661
|
class Workflow {
|
|
3662
|
-
constructor(cache, parent, iteratorTask) {
|
|
3662
|
+
constructor(cache, parent, iteratorTask, registry) {
|
|
3663
3663
|
this._outputCache = cache;
|
|
3664
3664
|
this._parentWorkflow = parent;
|
|
3665
3665
|
this._iteratorTask = iteratorTask;
|
|
3666
|
+
this._registry = registry ?? parent?._registry;
|
|
3666
3667
|
this._graph = new TaskGraph({ outputCache: this._outputCache });
|
|
3667
3668
|
if (!parent) {
|
|
3668
3669
|
this._onChanged = this._onChanged.bind(this);
|
|
@@ -3673,6 +3674,7 @@ class Workflow {
|
|
|
3673
3674
|
_dataFlows = [];
|
|
3674
3675
|
_error = "";
|
|
3675
3676
|
_outputCache;
|
|
3677
|
+
_registry;
|
|
3676
3678
|
_abortController;
|
|
3677
3679
|
_parentWorkflow;
|
|
3678
3680
|
_iteratorTask;
|
|
@@ -3786,7 +3788,7 @@ class Workflow {
|
|
|
3786
3788
|
const output = await this.graph.run(input, {
|
|
3787
3789
|
parentSignal: this._abortController.signal,
|
|
3788
3790
|
outputCache: this._outputCache,
|
|
3789
|
-
registry: config?.registry
|
|
3791
|
+
registry: config?.registry ?? this._registry
|
|
3790
3792
|
});
|
|
3791
3793
|
const results = this.graph.mergeExecuteOutputsToRunOutput(output, PROPERTY_ARRAY);
|
|
3792
3794
|
this.events.emit("complete");
|
|
@@ -3947,7 +3949,7 @@ class Workflow {
|
|
|
3947
3949
|
return this;
|
|
3948
3950
|
}
|
|
3949
3951
|
addTaskToGraph(taskClass, input, config) {
|
|
3950
|
-
const task = new taskClass(input, config);
|
|
3952
|
+
const task = new taskClass(input, config, this._registry ? { registry: this._registry } : undefined);
|
|
3951
3953
|
const id = this.graph.addTask(task);
|
|
3952
3954
|
this.events.emit("changed", id);
|
|
3953
3955
|
return task;
|
|
@@ -3973,7 +3975,7 @@ class Workflow {
|
|
|
3973
3975
|
});
|
|
3974
3976
|
this._dataFlows = [];
|
|
3975
3977
|
}
|
|
3976
|
-
const loopBuilder = new Workflow(this.outputCache(), this, task);
|
|
3978
|
+
const loopBuilder = new Workflow(this.outputCache(), this, task, this._registry);
|
|
3977
3979
|
if (parent) {
|
|
3978
3980
|
loopBuilder._pendingLoopConnect = { parent, iteratorTask: task };
|
|
3979
3981
|
}
|
|
@@ -4559,7 +4561,18 @@ function extractLoopConfig(task) {
|
|
|
4559
4561
|
}
|
|
4560
4562
|
return config;
|
|
4561
4563
|
}
|
|
4564
|
+
function stripUndefined(obj) {
|
|
4565
|
+
if (!obj)
|
|
4566
|
+
return obj;
|
|
4567
|
+
const result = {};
|
|
4568
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
4569
|
+
if (v !== undefined)
|
|
4570
|
+
result[k] = v;
|
|
4571
|
+
}
|
|
4572
|
+
return Object.keys(result).length > 0 ? result : undefined;
|
|
4573
|
+
}
|
|
4562
4574
|
function buildMethodArgs(defaults, config, baseIndent = "", columnOffset = 0) {
|
|
4575
|
+
defaults = stripUndefined(defaults);
|
|
4563
4576
|
const hasDefaults = defaults && Object.keys(defaults).length > 0;
|
|
4564
4577
|
const hasConfig = Object.keys(config).length > 0;
|
|
4565
4578
|
if (!hasDefaults && !hasConfig)
|
|
@@ -4834,6 +4847,68 @@ queueMicrotask(() => {
|
|
|
4834
4847
|
};
|
|
4835
4848
|
Workflow.prototype.endFallbackWith = CreateEndLoopWorkflow("endFallbackWith");
|
|
4836
4849
|
});
|
|
4850
|
+
// src/task/InputCompactor.ts
|
|
4851
|
+
import { getInputCompactors } from "@workglow/util";
|
|
4852
|
+
function schemaAllowsString(schema) {
|
|
4853
|
+
if (typeof schema !== "object" || schema === null)
|
|
4854
|
+
return false;
|
|
4855
|
+
const s = schema;
|
|
4856
|
+
if (s.type === "string")
|
|
4857
|
+
return true;
|
|
4858
|
+
const variants = s.oneOf ?? s.anyOf;
|
|
4859
|
+
if (Array.isArray(variants)) {
|
|
4860
|
+
for (const variant of variants) {
|
|
4861
|
+
if (schemaAllowsString(variant))
|
|
4862
|
+
return true;
|
|
4863
|
+
}
|
|
4864
|
+
}
|
|
4865
|
+
return false;
|
|
4866
|
+
}
|
|
4867
|
+
async function compactSchemaInputs(input, schema, config) {
|
|
4868
|
+
if (typeof schema === "boolean")
|
|
4869
|
+
return input;
|
|
4870
|
+
const properties = schema.properties;
|
|
4871
|
+
if (!properties || typeof properties !== "object")
|
|
4872
|
+
return input;
|
|
4873
|
+
const compactors = getInputCompactors();
|
|
4874
|
+
const compacted = { ...input };
|
|
4875
|
+
for (const [key, propSchema] of Object.entries(properties)) {
|
|
4876
|
+
let value = compacted[key];
|
|
4877
|
+
const format = getSchemaFormat(propSchema);
|
|
4878
|
+
if (format) {
|
|
4879
|
+
let compactor = compactors.get(format);
|
|
4880
|
+
if (!compactor) {
|
|
4881
|
+
const prefix = getFormatPrefix(format);
|
|
4882
|
+
compactor = compactors.get(prefix);
|
|
4883
|
+
}
|
|
4884
|
+
if (compactor) {
|
|
4885
|
+
if (value !== null && value !== undefined && typeof value === "object" && !Array.isArray(value) && schemaAllowsString(propSchema)) {
|
|
4886
|
+
const id = await compactor(value, format, config.registry);
|
|
4887
|
+
if (id !== undefined) {
|
|
4888
|
+
compacted[key] = id;
|
|
4889
|
+
continue;
|
|
4890
|
+
}
|
|
4891
|
+
} else if (Array.isArray(value)) {
|
|
4892
|
+
compacted[key] = await Promise.all(value.map(async (item) => {
|
|
4893
|
+
if (item !== null && item !== undefined && typeof item === "object" && !Array.isArray(item)) {
|
|
4894
|
+
const id = await compactor(item, format, config.registry);
|
|
4895
|
+
return id !== undefined ? id : item;
|
|
4896
|
+
}
|
|
4897
|
+
return item;
|
|
4898
|
+
}));
|
|
4899
|
+
continue;
|
|
4900
|
+
}
|
|
4901
|
+
}
|
|
4902
|
+
}
|
|
4903
|
+
if (value !== null && value !== undefined && typeof value === "object" && !Array.isArray(value)) {
|
|
4904
|
+
const objectSchema = getObjectSchema(propSchema);
|
|
4905
|
+
if (objectSchema) {
|
|
4906
|
+
compacted[key] = await compactSchemaInputs(value, objectSchema, config);
|
|
4907
|
+
}
|
|
4908
|
+
}
|
|
4909
|
+
}
|
|
4910
|
+
return compacted;
|
|
4911
|
+
}
|
|
4837
4912
|
// src/task/IteratorTaskRunner.ts
|
|
4838
4913
|
import { uuid4 as uuid46 } from "@workglow/util";
|
|
4839
4914
|
class IteratorTaskRunner extends GraphAsTaskRunner {
|
|
@@ -6335,6 +6410,7 @@ queueMicrotask(() => {
|
|
|
6335
6410
|
import {
|
|
6336
6411
|
createServiceToken as createServiceToken3,
|
|
6337
6412
|
globalServiceRegistry as globalServiceRegistry4,
|
|
6413
|
+
registerInputCompactor,
|
|
6338
6414
|
registerInputResolver
|
|
6339
6415
|
} from "@workglow/util";
|
|
6340
6416
|
var taskConstructors = new Map;
|
|
@@ -6377,6 +6453,17 @@ function resolveTaskFromRegistry(id, _format, registry) {
|
|
|
6377
6453
|
};
|
|
6378
6454
|
}
|
|
6379
6455
|
registerInputResolver("tasks", resolveTaskFromRegistry);
|
|
6456
|
+
registerInputCompactor("tasks", (value, _format, registry) => {
|
|
6457
|
+
if (typeof value === "object" && value !== null && "name" in value) {
|
|
6458
|
+
const name = value.name;
|
|
6459
|
+
if (typeof name !== "string")
|
|
6460
|
+
return;
|
|
6461
|
+
const constructors = getTaskConstructors(registry);
|
|
6462
|
+
const ctor = constructors.get(name);
|
|
6463
|
+
return ctor ? name : undefined;
|
|
6464
|
+
}
|
|
6465
|
+
return;
|
|
6466
|
+
});
|
|
6380
6467
|
|
|
6381
6468
|
// src/task/TaskJSON.ts
|
|
6382
6469
|
var createSingleTaskFromJSON = (item, registry, options) => {
|
|
@@ -6685,8 +6772,10 @@ export {
|
|
|
6685
6772
|
getTaskConstructors,
|
|
6686
6773
|
getStructuredOutputSchemas,
|
|
6687
6774
|
getStreamingPorts,
|
|
6775
|
+
getSchemaFormat,
|
|
6688
6776
|
getPortStreamMode,
|
|
6689
6777
|
getOutputStreamMode,
|
|
6778
|
+
getObjectSchema,
|
|
6690
6779
|
getObjectPortId,
|
|
6691
6780
|
getNestedValue,
|
|
6692
6781
|
getLastTask,
|
|
@@ -6694,6 +6783,7 @@ export {
|
|
|
6694
6783
|
getIterationContextSchemaForType,
|
|
6695
6784
|
getInputModeFromSchema,
|
|
6696
6785
|
getGlobalTaskConstructors,
|
|
6786
|
+
getFormatPrefix,
|
|
6697
6787
|
getAppendPortId,
|
|
6698
6788
|
formatValue,
|
|
6699
6789
|
findArrayPorts,
|
|
@@ -6715,6 +6805,7 @@ export {
|
|
|
6715
6805
|
conditionalTaskConfigSchema,
|
|
6716
6806
|
computeGraphOutputSchema,
|
|
6717
6807
|
computeGraphInputSchema,
|
|
6808
|
+
compactSchemaInputs,
|
|
6718
6809
|
calculateNodeDepths,
|
|
6719
6810
|
buildIterationInputSchema,
|
|
6720
6811
|
addIterationContextToSchema,
|
|
@@ -6778,4 +6869,4 @@ export {
|
|
|
6778
6869
|
ConditionalTask
|
|
6779
6870
|
};
|
|
6780
6871
|
|
|
6781
|
-
//# debugId=
|
|
6872
|
+
//# debugId=BDC0F4EAE393712864756E2164756E21
|