@workglow/task-graph 0.1.1 → 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 +9 -8
- package/dist/bun.js +96 -5
- package/dist/bun.js.map +9 -8
- package/dist/node.js +96 -5
- package/dist/node.js.map +9 -8
- 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/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/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/browser.js
CHANGED
|
@@ -3658,10 +3658,11 @@ class WorkflowTask extends GraphAsTask {
|
|
|
3658
3658
|
}
|
|
3659
3659
|
|
|
3660
3660
|
class Workflow {
|
|
3661
|
-
constructor(cache, parent, iteratorTask) {
|
|
3661
|
+
constructor(cache, parent, iteratorTask, registry) {
|
|
3662
3662
|
this._outputCache = cache;
|
|
3663
3663
|
this._parentWorkflow = parent;
|
|
3664
3664
|
this._iteratorTask = iteratorTask;
|
|
3665
|
+
this._registry = registry ?? parent?._registry;
|
|
3665
3666
|
this._graph = new TaskGraph({ outputCache: this._outputCache });
|
|
3666
3667
|
if (!parent) {
|
|
3667
3668
|
this._onChanged = this._onChanged.bind(this);
|
|
@@ -3672,6 +3673,7 @@ class Workflow {
|
|
|
3672
3673
|
_dataFlows = [];
|
|
3673
3674
|
_error = "";
|
|
3674
3675
|
_outputCache;
|
|
3676
|
+
_registry;
|
|
3675
3677
|
_abortController;
|
|
3676
3678
|
_parentWorkflow;
|
|
3677
3679
|
_iteratorTask;
|
|
@@ -3785,7 +3787,7 @@ class Workflow {
|
|
|
3785
3787
|
const output = await this.graph.run(input, {
|
|
3786
3788
|
parentSignal: this._abortController.signal,
|
|
3787
3789
|
outputCache: this._outputCache,
|
|
3788
|
-
registry: config?.registry
|
|
3790
|
+
registry: config?.registry ?? this._registry
|
|
3789
3791
|
});
|
|
3790
3792
|
const results = this.graph.mergeExecuteOutputsToRunOutput(output, PROPERTY_ARRAY);
|
|
3791
3793
|
this.events.emit("complete");
|
|
@@ -3946,7 +3948,7 @@ class Workflow {
|
|
|
3946
3948
|
return this;
|
|
3947
3949
|
}
|
|
3948
3950
|
addTaskToGraph(taskClass, input, config) {
|
|
3949
|
-
const task = new taskClass(input, config);
|
|
3951
|
+
const task = new taskClass(input, config, this._registry ? { registry: this._registry } : undefined);
|
|
3950
3952
|
const id = this.graph.addTask(task);
|
|
3951
3953
|
this.events.emit("changed", id);
|
|
3952
3954
|
return task;
|
|
@@ -3972,7 +3974,7 @@ class Workflow {
|
|
|
3972
3974
|
});
|
|
3973
3975
|
this._dataFlows = [];
|
|
3974
3976
|
}
|
|
3975
|
-
const loopBuilder = new Workflow(this.outputCache(), this, task);
|
|
3977
|
+
const loopBuilder = new Workflow(this.outputCache(), this, task, this._registry);
|
|
3976
3978
|
if (parent) {
|
|
3977
3979
|
loopBuilder._pendingLoopConnect = { parent, iteratorTask: task };
|
|
3978
3980
|
}
|
|
@@ -4558,7 +4560,18 @@ function extractLoopConfig(task) {
|
|
|
4558
4560
|
}
|
|
4559
4561
|
return config;
|
|
4560
4562
|
}
|
|
4563
|
+
function stripUndefined(obj) {
|
|
4564
|
+
if (!obj)
|
|
4565
|
+
return obj;
|
|
4566
|
+
const result = {};
|
|
4567
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
4568
|
+
if (v !== undefined)
|
|
4569
|
+
result[k] = v;
|
|
4570
|
+
}
|
|
4571
|
+
return Object.keys(result).length > 0 ? result : undefined;
|
|
4572
|
+
}
|
|
4561
4573
|
function buildMethodArgs(defaults, config, baseIndent = "", columnOffset = 0) {
|
|
4574
|
+
defaults = stripUndefined(defaults);
|
|
4562
4575
|
const hasDefaults = defaults && Object.keys(defaults).length > 0;
|
|
4563
4576
|
const hasConfig = Object.keys(config).length > 0;
|
|
4564
4577
|
if (!hasDefaults && !hasConfig)
|
|
@@ -4833,6 +4846,68 @@ queueMicrotask(() => {
|
|
|
4833
4846
|
};
|
|
4834
4847
|
Workflow.prototype.endFallbackWith = CreateEndLoopWorkflow("endFallbackWith");
|
|
4835
4848
|
});
|
|
4849
|
+
// src/task/InputCompactor.ts
|
|
4850
|
+
import { getInputCompactors } from "@workglow/util";
|
|
4851
|
+
function schemaAllowsString(schema) {
|
|
4852
|
+
if (typeof schema !== "object" || schema === null)
|
|
4853
|
+
return false;
|
|
4854
|
+
const s = schema;
|
|
4855
|
+
if (s.type === "string")
|
|
4856
|
+
return true;
|
|
4857
|
+
const variants = s.oneOf ?? s.anyOf;
|
|
4858
|
+
if (Array.isArray(variants)) {
|
|
4859
|
+
for (const variant of variants) {
|
|
4860
|
+
if (schemaAllowsString(variant))
|
|
4861
|
+
return true;
|
|
4862
|
+
}
|
|
4863
|
+
}
|
|
4864
|
+
return false;
|
|
4865
|
+
}
|
|
4866
|
+
async function compactSchemaInputs(input, schema, config) {
|
|
4867
|
+
if (typeof schema === "boolean")
|
|
4868
|
+
return input;
|
|
4869
|
+
const properties = schema.properties;
|
|
4870
|
+
if (!properties || typeof properties !== "object")
|
|
4871
|
+
return input;
|
|
4872
|
+
const compactors = getInputCompactors();
|
|
4873
|
+
const compacted = { ...input };
|
|
4874
|
+
for (const [key, propSchema] of Object.entries(properties)) {
|
|
4875
|
+
let value = compacted[key];
|
|
4876
|
+
const format = getSchemaFormat(propSchema);
|
|
4877
|
+
if (format) {
|
|
4878
|
+
let compactor = compactors.get(format);
|
|
4879
|
+
if (!compactor) {
|
|
4880
|
+
const prefix = getFormatPrefix(format);
|
|
4881
|
+
compactor = compactors.get(prefix);
|
|
4882
|
+
}
|
|
4883
|
+
if (compactor) {
|
|
4884
|
+
if (value !== null && value !== undefined && typeof value === "object" && !Array.isArray(value) && schemaAllowsString(propSchema)) {
|
|
4885
|
+
const id = await compactor(value, format, config.registry);
|
|
4886
|
+
if (id !== undefined) {
|
|
4887
|
+
compacted[key] = id;
|
|
4888
|
+
continue;
|
|
4889
|
+
}
|
|
4890
|
+
} else if (Array.isArray(value)) {
|
|
4891
|
+
compacted[key] = await Promise.all(value.map(async (item) => {
|
|
4892
|
+
if (item !== null && item !== undefined && typeof item === "object" && !Array.isArray(item)) {
|
|
4893
|
+
const id = await compactor(item, format, config.registry);
|
|
4894
|
+
return id !== undefined ? id : item;
|
|
4895
|
+
}
|
|
4896
|
+
return item;
|
|
4897
|
+
}));
|
|
4898
|
+
continue;
|
|
4899
|
+
}
|
|
4900
|
+
}
|
|
4901
|
+
}
|
|
4902
|
+
if (value !== null && value !== undefined && typeof value === "object" && !Array.isArray(value)) {
|
|
4903
|
+
const objectSchema = getObjectSchema(propSchema);
|
|
4904
|
+
if (objectSchema) {
|
|
4905
|
+
compacted[key] = await compactSchemaInputs(value, objectSchema, config);
|
|
4906
|
+
}
|
|
4907
|
+
}
|
|
4908
|
+
}
|
|
4909
|
+
return compacted;
|
|
4910
|
+
}
|
|
4836
4911
|
// src/task/IteratorTaskRunner.ts
|
|
4837
4912
|
import { uuid4 as uuid46 } from "@workglow/util";
|
|
4838
4913
|
class IteratorTaskRunner extends GraphAsTaskRunner {
|
|
@@ -6334,6 +6409,7 @@ queueMicrotask(() => {
|
|
|
6334
6409
|
import {
|
|
6335
6410
|
createServiceToken as createServiceToken3,
|
|
6336
6411
|
globalServiceRegistry as globalServiceRegistry4,
|
|
6412
|
+
registerInputCompactor,
|
|
6337
6413
|
registerInputResolver
|
|
6338
6414
|
} from "@workglow/util";
|
|
6339
6415
|
var taskConstructors = new Map;
|
|
@@ -6376,6 +6452,17 @@ function resolveTaskFromRegistry(id, _format, registry) {
|
|
|
6376
6452
|
};
|
|
6377
6453
|
}
|
|
6378
6454
|
registerInputResolver("tasks", resolveTaskFromRegistry);
|
|
6455
|
+
registerInputCompactor("tasks", (value, _format, registry) => {
|
|
6456
|
+
if (typeof value === "object" && value !== null && "name" in value) {
|
|
6457
|
+
const name = value.name;
|
|
6458
|
+
if (typeof name !== "string")
|
|
6459
|
+
return;
|
|
6460
|
+
const constructors = getTaskConstructors(registry);
|
|
6461
|
+
const ctor = constructors.get(name);
|
|
6462
|
+
return ctor ? name : undefined;
|
|
6463
|
+
}
|
|
6464
|
+
return;
|
|
6465
|
+
});
|
|
6379
6466
|
|
|
6380
6467
|
// src/task/TaskJSON.ts
|
|
6381
6468
|
var createSingleTaskFromJSON = (item, registry, options) => {
|
|
@@ -7321,8 +7408,10 @@ export {
|
|
|
7321
7408
|
getTaskConstructors,
|
|
7322
7409
|
getStructuredOutputSchemas,
|
|
7323
7410
|
getStreamingPorts,
|
|
7411
|
+
getSchemaFormat,
|
|
7324
7412
|
getPortStreamMode,
|
|
7325
7413
|
getOutputStreamMode,
|
|
7414
|
+
getObjectSchema,
|
|
7326
7415
|
getObjectPortId,
|
|
7327
7416
|
getNestedValue,
|
|
7328
7417
|
getLastTask,
|
|
@@ -7330,6 +7419,7 @@ export {
|
|
|
7330
7419
|
getIterationContextSchemaForType,
|
|
7331
7420
|
getInputModeFromSchema,
|
|
7332
7421
|
getGlobalTaskConstructors,
|
|
7422
|
+
getFormatPrefix,
|
|
7333
7423
|
getAppendPortId,
|
|
7334
7424
|
formatValue,
|
|
7335
7425
|
findArrayPorts,
|
|
@@ -7351,6 +7441,7 @@ export {
|
|
|
7351
7441
|
conditionalTaskConfigSchema,
|
|
7352
7442
|
computeGraphOutputSchema,
|
|
7353
7443
|
computeGraphInputSchema,
|
|
7444
|
+
compactSchemaInputs,
|
|
7354
7445
|
calculateNodeDepths,
|
|
7355
7446
|
buildIterationInputSchema,
|
|
7356
7447
|
addIterationContextToSchema,
|
|
@@ -7414,4 +7505,4 @@ export {
|
|
|
7414
7505
|
ConditionalTask
|
|
7415
7506
|
};
|
|
7416
7507
|
|
|
7417
|
-
//# debugId=
|
|
7508
|
+
//# debugId=20FE63BF106AB62F64756E2164756E21
|