@cadenza.io/core 1.10.1 → 1.11.1
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/index.d.mts +20 -12
- package/dist/index.d.ts +20 -12
- package/dist/index.js +346 -136
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +346 -136
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -36,6 +36,41 @@ __export(index_exports, {
|
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(index_exports);
|
|
38
38
|
|
|
39
|
+
// src/utils/tools.ts
|
|
40
|
+
function deepCloneFilter(input, filterOut = () => false) {
|
|
41
|
+
if (input === null || typeof input !== "object") {
|
|
42
|
+
return input;
|
|
43
|
+
}
|
|
44
|
+
const visited = /* @__PURE__ */ new WeakMap();
|
|
45
|
+
const stack = [];
|
|
46
|
+
const output = Array.isArray(input) ? [] : {};
|
|
47
|
+
stack.push({ source: input, target: output });
|
|
48
|
+
visited.set(input, output);
|
|
49
|
+
while (stack.length) {
|
|
50
|
+
const { source, target, key } = stack.pop();
|
|
51
|
+
const currentTarget = key !== void 0 ? target[key] : target;
|
|
52
|
+
for (const [k, value] of Object.entries(source)) {
|
|
53
|
+
if (filterOut(k)) continue;
|
|
54
|
+
if (value && typeof value === "object") {
|
|
55
|
+
if (visited.has(value)) {
|
|
56
|
+
currentTarget[k] = visited.get(value);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const clonedValue = Array.isArray(value) ? [] : {};
|
|
60
|
+
currentTarget[k] = clonedValue;
|
|
61
|
+
visited.set(value, clonedValue);
|
|
62
|
+
stack.push({ source: value, target: currentTarget, key: k });
|
|
63
|
+
} else {
|
|
64
|
+
currentTarget[k] = value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return output;
|
|
69
|
+
}
|
|
70
|
+
function formatTimestamp(timestamp) {
|
|
71
|
+
return new Date(timestamp).toISOString();
|
|
72
|
+
}
|
|
73
|
+
|
|
39
74
|
// src/engine/SignalBroker.ts
|
|
40
75
|
var SignalBroker = class _SignalBroker {
|
|
41
76
|
// execId -> emitted signals
|
|
@@ -102,8 +137,11 @@ var SignalBroker = class _SignalBroker {
|
|
|
102
137
|
},
|
|
103
138
|
"Executes queued signals and clears the stack",
|
|
104
139
|
500,
|
|
105
|
-
{
|
|
106
|
-
|
|
140
|
+
{
|
|
141
|
+
maxWait: 1e4,
|
|
142
|
+
leading: true
|
|
143
|
+
}
|
|
144
|
+
).doOn("meta.process_signal_queue_requested").emitsAfter("meta.signal_broker.queue_empty");
|
|
107
145
|
this.getSignalsTask = Cadenza.createMetaTask("Get signals", (ctx) => {
|
|
108
146
|
return {
|
|
109
147
|
__signals: Array.from(this.signalObservers.keys()),
|
|
@@ -145,6 +183,7 @@ var SignalBroker = class _SignalBroker {
|
|
|
145
183
|
*/
|
|
146
184
|
emit(signal, context = {}) {
|
|
147
185
|
const execId = context.__routineExecId || "global";
|
|
186
|
+
delete context.__routineExecId;
|
|
148
187
|
if (!this.emitStacks.has(execId)) this.emitStacks.set(execId, /* @__PURE__ */ new Map());
|
|
149
188
|
const stack = this.emitStacks.get(execId);
|
|
150
189
|
stack.set(signal, context);
|
|
@@ -157,30 +196,36 @@ var SignalBroker = class _SignalBroker {
|
|
|
157
196
|
}
|
|
158
197
|
}
|
|
159
198
|
execute(signal, context) {
|
|
160
|
-
const isMeta = signal.startsWith("meta");
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
__signalEmission
|
|
199
|
+
const isMeta = signal.startsWith("meta.");
|
|
200
|
+
const isSubMeta = signal.startsWith("sub_meta.");
|
|
201
|
+
if (!isSubMeta && (!isMeta || this.debug)) {
|
|
202
|
+
const emittedAt = Date.now();
|
|
203
|
+
context.__signalEmission = {
|
|
165
204
|
...context.__signalEmission,
|
|
166
205
|
signalName: signal,
|
|
167
|
-
emittedAt,
|
|
206
|
+
emittedAt: formatTimestamp(emittedAt),
|
|
168
207
|
isMeta
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const parent = parts.slice(0, i).join(".");
|
|
176
|
-
executed = executed || this.executeListener(parent + ".*", data);
|
|
208
|
+
};
|
|
209
|
+
} else if (isSubMeta) {
|
|
210
|
+
context.__isSubMeta = true;
|
|
211
|
+
delete context.__signalEmission;
|
|
212
|
+
} else {
|
|
213
|
+
delete context.__signalEmission;
|
|
177
214
|
}
|
|
178
215
|
if (this.debug) {
|
|
179
216
|
console.log(
|
|
180
|
-
`
|
|
181
|
-
executed ? "\u2705" : "\u274C"
|
|
217
|
+
`Emitting signal ${signal} with context ${JSON.stringify(context)}`
|
|
182
218
|
);
|
|
183
219
|
}
|
|
220
|
+
let executed;
|
|
221
|
+
executed = this.executeListener(signal, context);
|
|
222
|
+
if (!isSubMeta) {
|
|
223
|
+
const parts = signal.slice(0, Math.max(signal.lastIndexOf(":"), signal.lastIndexOf("."))).split(".");
|
|
224
|
+
for (let i = parts.length; i > 0; i--) {
|
|
225
|
+
const parent = parts.slice(0, i).join(".");
|
|
226
|
+
executed = executed || this.executeListener(parent + ".*", context);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
184
229
|
return executed;
|
|
185
230
|
}
|
|
186
231
|
executeListener(signal, context) {
|
|
@@ -486,40 +531,6 @@ var import_uuid3 = require("uuid");
|
|
|
486
531
|
|
|
487
532
|
// src/graph/context/GraphContext.ts
|
|
488
533
|
var import_uuid2 = require("uuid");
|
|
489
|
-
|
|
490
|
-
// src/utils/tools.ts
|
|
491
|
-
function deepCloneFilter(input, filterOut = () => false) {
|
|
492
|
-
if (input === null || typeof input !== "object") {
|
|
493
|
-
return input;
|
|
494
|
-
}
|
|
495
|
-
const visited = /* @__PURE__ */ new WeakMap();
|
|
496
|
-
const stack = [];
|
|
497
|
-
const output = Array.isArray(input) ? [] : {};
|
|
498
|
-
stack.push({ source: input, target: output });
|
|
499
|
-
visited.set(input, output);
|
|
500
|
-
while (stack.length) {
|
|
501
|
-
const { source, target, key } = stack.pop();
|
|
502
|
-
const currentTarget = key !== void 0 ? target[key] : target;
|
|
503
|
-
for (const [k, value] of Object.entries(source)) {
|
|
504
|
-
if (filterOut(k)) continue;
|
|
505
|
-
if (value && typeof value === "object") {
|
|
506
|
-
if (visited.has(value)) {
|
|
507
|
-
currentTarget[k] = visited.get(value);
|
|
508
|
-
continue;
|
|
509
|
-
}
|
|
510
|
-
const clonedValue = Array.isArray(value) ? [] : {};
|
|
511
|
-
currentTarget[k] = clonedValue;
|
|
512
|
-
visited.set(value, clonedValue);
|
|
513
|
-
stack.push({ source: value, target: currentTarget, key: k });
|
|
514
|
-
} else {
|
|
515
|
-
currentTarget[k] = value;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
return output;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
// src/graph/context/GraphContext.ts
|
|
523
534
|
var GraphContext = class _GraphContext {
|
|
524
535
|
// __keys, frozen
|
|
525
536
|
constructor(context) {
|
|
@@ -679,7 +690,10 @@ function sleep(ms) {
|
|
|
679
690
|
// src/graph/execution/GraphNode.ts
|
|
680
691
|
var GraphNode = class _GraphNode extends SignalEmitter {
|
|
681
692
|
constructor(task, context, routineExecId, prevNodes = [], debug = false) {
|
|
682
|
-
|
|
693
|
+
var _a;
|
|
694
|
+
super(
|
|
695
|
+
task.isMeta && !debug || task.isSubMeta || ((_a = context == null ? void 0 : context.getMetaData()) == null ? void 0 : _a.__isSubMeta)
|
|
696
|
+
);
|
|
683
697
|
this.divided = false;
|
|
684
698
|
this.splitGroupId = "";
|
|
685
699
|
this.processing = false;
|
|
@@ -750,6 +764,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
750
764
|
return this.task.getTag(this.context);
|
|
751
765
|
}
|
|
752
766
|
scheduleOn(layer) {
|
|
767
|
+
var _a;
|
|
753
768
|
let shouldSchedule = true;
|
|
754
769
|
const nodes = layer.getNodesByRoutineExecId(this.routineExecId);
|
|
755
770
|
for (const node of nodes) {
|
|
@@ -766,23 +781,56 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
766
781
|
if (shouldSchedule) {
|
|
767
782
|
this.layer = layer;
|
|
768
783
|
layer.add(this);
|
|
784
|
+
const context = this.context.getFullContext();
|
|
769
785
|
const scheduledAt = Date.now();
|
|
770
786
|
this.emitWithMetadata("meta.node.scheduled", {
|
|
771
|
-
|
|
772
|
-
|
|
787
|
+
data: {
|
|
788
|
+
uuid: this.id,
|
|
789
|
+
routineExecutionId: this.routineExecId,
|
|
790
|
+
contractId: context.__contractId,
|
|
791
|
+
context: this.context.export(),
|
|
792
|
+
taskId: this.task.id,
|
|
793
|
+
taskName: this.task.name,
|
|
794
|
+
isMeta: this.isMeta(),
|
|
795
|
+
isScheduled: true,
|
|
796
|
+
splitGroupId: this.splitGroupId,
|
|
797
|
+
created: formatTimestamp(scheduledAt)
|
|
798
|
+
}
|
|
773
799
|
});
|
|
774
|
-
|
|
775
|
-
|
|
800
|
+
this.previousNodes.forEach((node) => {
|
|
801
|
+
this.emitWithMetadata("meta.node.mapped", {
|
|
802
|
+
data: {
|
|
803
|
+
taskExecutionId: this.id,
|
|
804
|
+
previousTaskExecutionId: node.id,
|
|
805
|
+
executionCount: "increment"
|
|
806
|
+
},
|
|
807
|
+
filter: {
|
|
808
|
+
taskId: this.task.id,
|
|
809
|
+
previousTaskId: node.task.id
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
if (node.failed || node.errored) {
|
|
813
|
+
this.emitWithMetadata("meta.node.failed_mapped", {
|
|
814
|
+
data: {
|
|
815
|
+
executionCount: "increment"
|
|
816
|
+
},
|
|
817
|
+
filter: {
|
|
818
|
+
taskId: this.task.id,
|
|
819
|
+
failTaskId: node.task.id
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
if (((_a = context.__signalEmission) == null ? void 0 : _a.signalName) && (!this.isMeta() || this.debug)) {
|
|
776
825
|
this.emitWithMetadata("meta.node.consumed_signal", {
|
|
777
|
-
|
|
826
|
+
data: {
|
|
778
827
|
signalName: context.__signalEmission.signalName,
|
|
779
828
|
taskId: this.task.id,
|
|
780
829
|
taskExecutionId: this.id,
|
|
781
|
-
consumedAt: scheduledAt
|
|
830
|
+
consumedAt: formatTimestamp(scheduledAt)
|
|
782
831
|
}
|
|
783
832
|
});
|
|
784
833
|
delete context.__signalEmission;
|
|
785
|
-
this.migrate(context);
|
|
786
834
|
}
|
|
787
835
|
}
|
|
788
836
|
}
|
|
@@ -790,14 +838,25 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
790
838
|
if (this.executionStart === 0) {
|
|
791
839
|
this.executionStart = Date.now();
|
|
792
840
|
}
|
|
793
|
-
const memento = this.lightExport();
|
|
794
841
|
if (this.previousNodes.length === 0) {
|
|
795
|
-
this.emitWithMetadata("meta.node.started_routine_execution",
|
|
842
|
+
this.emitWithMetadata("meta.node.started_routine_execution", {
|
|
843
|
+
data: {
|
|
844
|
+
isRunning: true,
|
|
845
|
+
started: formatTimestamp(this.executionStart)
|
|
846
|
+
},
|
|
847
|
+
filter: { uuid: this.routineExecId }
|
|
848
|
+
});
|
|
796
849
|
}
|
|
797
850
|
if (this.debug) {
|
|
798
851
|
this.log();
|
|
799
852
|
}
|
|
800
|
-
this.emitWithMetadata("meta.node.started",
|
|
853
|
+
this.emitWithMetadata("meta.node.started", {
|
|
854
|
+
data: {
|
|
855
|
+
isRunning: true,
|
|
856
|
+
started: formatTimestamp(this.executionStart)
|
|
857
|
+
},
|
|
858
|
+
filter: { uuid: this.id }
|
|
859
|
+
});
|
|
801
860
|
return this.executionStart;
|
|
802
861
|
}
|
|
803
862
|
end() {
|
|
@@ -807,15 +866,44 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
807
866
|
this.processing = false;
|
|
808
867
|
const end = Date.now();
|
|
809
868
|
this.executionTime = end - this.executionStart;
|
|
810
|
-
const
|
|
869
|
+
const context = this.context.getFullContext();
|
|
811
870
|
if (this.errored || this.failed) {
|
|
812
|
-
this.emitWithMetadata("meta.node.errored",
|
|
871
|
+
this.emitWithMetadata("meta.node.errored", {
|
|
872
|
+
data: {
|
|
873
|
+
isRunning: false,
|
|
874
|
+
errored: this.errored,
|
|
875
|
+
failed: this.failed,
|
|
876
|
+
errorMessage: context.__error
|
|
877
|
+
},
|
|
878
|
+
filter: { uuid: this.id }
|
|
879
|
+
});
|
|
813
880
|
}
|
|
814
|
-
this.emitWithMetadata("meta.node.ended",
|
|
881
|
+
this.emitWithMetadata("meta.node.ended", {
|
|
882
|
+
data: {
|
|
883
|
+
isRunning: false,
|
|
884
|
+
isComplete: true,
|
|
885
|
+
resultContext: this.context.export(),
|
|
886
|
+
errored: this.errored,
|
|
887
|
+
failed: this.failed,
|
|
888
|
+
errorMessage: context.__error,
|
|
889
|
+
progress: 1,
|
|
890
|
+
ended: formatTimestamp(end)
|
|
891
|
+
},
|
|
892
|
+
filter: { uuid: this.id }
|
|
893
|
+
});
|
|
815
894
|
if (this.graphDone()) {
|
|
816
895
|
this.emitWithMetadata(
|
|
817
896
|
`meta.node.ended_routine_execution:${this.routineExecId}`,
|
|
818
|
-
|
|
897
|
+
{
|
|
898
|
+
data: {
|
|
899
|
+
isRunning: false,
|
|
900
|
+
isComplete: true,
|
|
901
|
+
resultContext: this.context.export(),
|
|
902
|
+
progress: 1,
|
|
903
|
+
ended: formatTimestamp(end)
|
|
904
|
+
},
|
|
905
|
+
filter: { uuid: this.routineExecId }
|
|
906
|
+
}
|
|
819
907
|
);
|
|
820
908
|
}
|
|
821
909
|
return end;
|
|
@@ -877,23 +965,41 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
877
965
|
}
|
|
878
966
|
}
|
|
879
967
|
emitWithMetadata(signal, ctx) {
|
|
880
|
-
this.
|
|
881
|
-
|
|
882
|
-
|
|
968
|
+
if (this.silent) return;
|
|
969
|
+
const data = { ...ctx };
|
|
970
|
+
if (!this.task.isHidden) {
|
|
971
|
+
data.__signalEmission = {
|
|
883
972
|
taskId: this.task.id,
|
|
884
973
|
taskExecutionId: this.id
|
|
885
|
-
}
|
|
886
|
-
|
|
974
|
+
};
|
|
975
|
+
data.__metadata = {
|
|
976
|
+
__routineExecId: this.routineExecId
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
this.emit(signal, data);
|
|
887
980
|
}
|
|
888
981
|
onProgress(progress) {
|
|
889
|
-
var _a, _b
|
|
982
|
+
var _a, _b;
|
|
890
983
|
progress = Math.min(Math.max(0, progress), 1);
|
|
891
|
-
this.emitWithMetadata(
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
984
|
+
this.emitWithMetadata("meta.node.progress", {
|
|
985
|
+
data: {
|
|
986
|
+
progress
|
|
987
|
+
},
|
|
988
|
+
filter: {
|
|
989
|
+
uuid: this.id
|
|
990
|
+
}
|
|
896
991
|
});
|
|
992
|
+
this.emitWithMetadata(
|
|
993
|
+
`meta.node.routine_execution_progress:${this.routineExecId}`,
|
|
994
|
+
{
|
|
995
|
+
data: {
|
|
996
|
+
progress: progress * this.task.progressWeight / ((_b = (_a = this.layer) == null ? void 0 : _a.getIdenticalNodes(this).length) != null ? _b : 1)
|
|
997
|
+
},
|
|
998
|
+
filter: {
|
|
999
|
+
uuid: this.routineExecId
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
);
|
|
897
1003
|
}
|
|
898
1004
|
postProcess() {
|
|
899
1005
|
if (typeof this.result === "string") {
|
|
@@ -910,11 +1016,11 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
910
1016
|
}
|
|
911
1017
|
if (this.errored || this.failed) {
|
|
912
1018
|
this.task.mapOnFailSignals(
|
|
913
|
-
(signal) => this.emitWithMetadata(signal, this.context)
|
|
1019
|
+
(signal) => this.emitWithMetadata(signal, this.context.getFullContext())
|
|
914
1020
|
);
|
|
915
1021
|
} else {
|
|
916
1022
|
this.task.mapSignals(
|
|
917
|
-
(signal) => this.emitWithMetadata(signal, this.context)
|
|
1023
|
+
(signal) => this.emitWithMetadata(signal, this.context.getFullContext())
|
|
918
1024
|
);
|
|
919
1025
|
}
|
|
920
1026
|
this.end();
|
|
@@ -1303,8 +1409,24 @@ var GraphRoutine = class extends SignalParticipant {
|
|
|
1303
1409
|
this.name = name;
|
|
1304
1410
|
this.description = description;
|
|
1305
1411
|
this.isMeta = isMeta;
|
|
1306
|
-
|
|
1307
|
-
|
|
1412
|
+
this.emit("meta.routine.created", {
|
|
1413
|
+
data: {
|
|
1414
|
+
uuid: this.id,
|
|
1415
|
+
name: this.name,
|
|
1416
|
+
description: this.description,
|
|
1417
|
+
isMeta: this.isMeta
|
|
1418
|
+
},
|
|
1419
|
+
__routineInstance: this
|
|
1420
|
+
});
|
|
1421
|
+
tasks.forEach((t) => {
|
|
1422
|
+
this.tasks.add(t);
|
|
1423
|
+
this.emit("meta.routine.task_added", {
|
|
1424
|
+
data: {
|
|
1425
|
+
taskId: t.id,
|
|
1426
|
+
routineId: this.id
|
|
1427
|
+
}
|
|
1428
|
+
});
|
|
1429
|
+
});
|
|
1308
1430
|
}
|
|
1309
1431
|
/**
|
|
1310
1432
|
* Applies callback to starting tasks.
|
|
@@ -1334,7 +1456,10 @@ var GraphRoutine = class extends SignalParticipant {
|
|
|
1334
1456
|
*/
|
|
1335
1457
|
destroy() {
|
|
1336
1458
|
this.tasks.clear();
|
|
1337
|
-
this.emit("meta.routine.destroyed", {
|
|
1459
|
+
this.emit("meta.routine.destroyed", {
|
|
1460
|
+
data: { deleted: true },
|
|
1461
|
+
filter: { uuid: this.id }
|
|
1462
|
+
});
|
|
1338
1463
|
}
|
|
1339
1464
|
};
|
|
1340
1465
|
|
|
@@ -1384,6 +1509,8 @@ var Task = class extends SignalParticipant {
|
|
|
1384
1509
|
* @param register Register via signal (default true).
|
|
1385
1510
|
* @param isUnique
|
|
1386
1511
|
* @param isMeta
|
|
1512
|
+
* @param isSubMeta
|
|
1513
|
+
* @param isHidden
|
|
1387
1514
|
* @param getTagCallback
|
|
1388
1515
|
* @param inputSchema
|
|
1389
1516
|
* @param validateInputContext
|
|
@@ -1395,14 +1522,17 @@ var Task = class extends SignalParticipant {
|
|
|
1395
1522
|
* @param retryDelayFactor
|
|
1396
1523
|
* @edge Emits 'meta.task.created' with { __task: this } for seed.
|
|
1397
1524
|
*/
|
|
1398
|
-
constructor(name, task, description = "", concurrency = 0, timeout = 0, register = true, isUnique = false, isMeta = false, getTagCallback = void 0, inputSchema = void 0, validateInputContext = false, outputSchema = void 0, validateOutputContext = false, retryCount = 0, retryDelay = 0, retryDelayMax = 0, retryDelayFactor = 1) {
|
|
1525
|
+
constructor(name, task, description = "", concurrency = 0, timeout = 0, register = true, isUnique = false, isMeta = false, isSubMeta = false, isHidden = false, getTagCallback = void 0, inputSchema = void 0, validateInputContext = false, outputSchema = void 0, validateOutputContext = false, retryCount = 0, retryDelay = 0, retryDelayMax = 0, retryDelayFactor = 1) {
|
|
1399
1526
|
super();
|
|
1400
1527
|
this.isMeta = false;
|
|
1528
|
+
this.isSubMeta = false;
|
|
1529
|
+
this.isHidden = false;
|
|
1401
1530
|
this.isUnique = false;
|
|
1402
1531
|
this.throttled = false;
|
|
1403
1532
|
this.isSignal = false;
|
|
1404
1533
|
this.isDeputy = false;
|
|
1405
1534
|
this.isEphemeral = false;
|
|
1535
|
+
this.isDebounce = false;
|
|
1406
1536
|
this.inputContextSchema = void 0;
|
|
1407
1537
|
this.validateInputContext = false;
|
|
1408
1538
|
this.outputContextSchema = void 0;
|
|
@@ -1425,6 +1555,8 @@ var Task = class extends SignalParticipant {
|
|
|
1425
1555
|
this.timeout = timeout;
|
|
1426
1556
|
this.isUnique = isUnique;
|
|
1427
1557
|
this.isMeta = isMeta;
|
|
1558
|
+
this.isSubMeta = isSubMeta;
|
|
1559
|
+
this.isHidden = isHidden;
|
|
1428
1560
|
this.inputContextSchema = inputSchema;
|
|
1429
1561
|
this.validateInputContext = validateInputContext;
|
|
1430
1562
|
this.outputContextSchema = outputSchema;
|
|
@@ -1437,8 +1569,35 @@ var Task = class extends SignalParticipant {
|
|
|
1437
1569
|
this.getTag = (context) => getTagCallback(context, this);
|
|
1438
1570
|
this.throttled = true;
|
|
1439
1571
|
}
|
|
1440
|
-
if (register) {
|
|
1441
|
-
|
|
1572
|
+
if (register && !this.isHidden && !this.isSubMeta) {
|
|
1573
|
+
const { __functionString, __getTagCallback } = this.export();
|
|
1574
|
+
this.emit("meta.task.created", {
|
|
1575
|
+
__task: {
|
|
1576
|
+
uuid: this.id,
|
|
1577
|
+
name: this.name,
|
|
1578
|
+
description: this.description,
|
|
1579
|
+
functionString: __functionString,
|
|
1580
|
+
tagIdGetter: __getTagCallback,
|
|
1581
|
+
layerIndex: this.layerIndex,
|
|
1582
|
+
concurrency: this.concurrency,
|
|
1583
|
+
retryCount: this.retryCount,
|
|
1584
|
+
retryDelay: this.retryDelay,
|
|
1585
|
+
retryDelayMax: this.retryDelayMax,
|
|
1586
|
+
retryDelayFactor: this.retryDelayFactor,
|
|
1587
|
+
timeout: this.timeout,
|
|
1588
|
+
isUnique: this.isUnique,
|
|
1589
|
+
isSignal: this.isSignal,
|
|
1590
|
+
isThrottled: this.throttled,
|
|
1591
|
+
isDebounce: this.isDebounce,
|
|
1592
|
+
isEphemeral: this.isEphemeral,
|
|
1593
|
+
isMeta: this.isMeta,
|
|
1594
|
+
validateInputContext: this.validateInputContext,
|
|
1595
|
+
validateOutputContext: this.validateOutputContext,
|
|
1596
|
+
inputContextSchemaId: this.inputContextSchema,
|
|
1597
|
+
outputContextSchemaId: this.outputContextSchema
|
|
1598
|
+
},
|
|
1599
|
+
__taskInstance: this
|
|
1600
|
+
});
|
|
1442
1601
|
}
|
|
1443
1602
|
}
|
|
1444
1603
|
getTag(context) {
|
|
@@ -1648,6 +1807,12 @@ var Task = class extends SignalParticipant {
|
|
|
1648
1807
|
this.decouple(pred);
|
|
1649
1808
|
throw new Error(`Cycle adding pred ${pred.name} to ${this.name}`);
|
|
1650
1809
|
}
|
|
1810
|
+
this.emit("meta.task.relationship_added", {
|
|
1811
|
+
data: {
|
|
1812
|
+
taskId: this.id,
|
|
1813
|
+
predecessorTaskId: pred.id
|
|
1814
|
+
}
|
|
1815
|
+
});
|
|
1651
1816
|
}
|
|
1652
1817
|
this.updateProgressWeights();
|
|
1653
1818
|
return this;
|
|
@@ -1662,6 +1827,12 @@ var Task = class extends SignalParticipant {
|
|
|
1662
1827
|
this.decouple(next);
|
|
1663
1828
|
throw new Error(`Cycle adding next ${next.name} to ${this.name}`);
|
|
1664
1829
|
}
|
|
1830
|
+
this.emit("meta.task.relationship_added", {
|
|
1831
|
+
data: {
|
|
1832
|
+
taskId: next.id,
|
|
1833
|
+
predecessorTaskId: this.id
|
|
1834
|
+
}
|
|
1835
|
+
});
|
|
1665
1836
|
}
|
|
1666
1837
|
this.updateProgressWeights();
|
|
1667
1838
|
return this;
|
|
@@ -1687,6 +1858,12 @@ var Task = class extends SignalParticipant {
|
|
|
1687
1858
|
this.decouple(task);
|
|
1688
1859
|
throw new Error(`Cycle adding onFail ${task.name} to ${this.name}`);
|
|
1689
1860
|
}
|
|
1861
|
+
this.emit("meta.task.on_fail_relationship_added", {
|
|
1862
|
+
data: {
|
|
1863
|
+
taskId: this.id,
|
|
1864
|
+
onFailTaskId: task.id
|
|
1865
|
+
}
|
|
1866
|
+
});
|
|
1690
1867
|
}
|
|
1691
1868
|
return this;
|
|
1692
1869
|
}
|
|
@@ -1718,11 +1895,20 @@ var Task = class extends SignalParticipant {
|
|
|
1718
1895
|
return layers;
|
|
1719
1896
|
}
|
|
1720
1897
|
updateLayerFromPredecessors() {
|
|
1898
|
+
const prevLayerIndex = this.layerIndex;
|
|
1721
1899
|
let maxPred = 0;
|
|
1722
1900
|
this.predecessorTasks.forEach(
|
|
1723
1901
|
(pred) => maxPred = Math.max(maxPred, pred.layerIndex)
|
|
1724
1902
|
);
|
|
1725
1903
|
this.layerIndex = maxPred + 1;
|
|
1904
|
+
if (prevLayerIndex !== this.layerIndex) {
|
|
1905
|
+
this.emit("meta.task.layer_index_changed", {
|
|
1906
|
+
data: {
|
|
1907
|
+
layerIndex: this.layerIndex
|
|
1908
|
+
},
|
|
1909
|
+
filter: { uuid: this.id }
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1726
1912
|
const queue = Array.from(this.nextTasks);
|
|
1727
1913
|
while (queue.length) {
|
|
1728
1914
|
const next = queue.shift();
|
|
@@ -1762,7 +1948,10 @@ var Task = class extends SignalParticipant {
|
|
|
1762
1948
|
this.predecessorTasks.clear();
|
|
1763
1949
|
this.onFailTasks.clear();
|
|
1764
1950
|
this.destroyed = true;
|
|
1765
|
-
this.emit("meta.task.destroyed", {
|
|
1951
|
+
this.emit("meta.task.destroyed", {
|
|
1952
|
+
data: { deleted: true },
|
|
1953
|
+
filter: { uuid: this.id }
|
|
1954
|
+
});
|
|
1766
1955
|
}
|
|
1767
1956
|
export() {
|
|
1768
1957
|
return {
|
|
@@ -1810,10 +1999,11 @@ var GraphRegistry = class _GraphRegistry {
|
|
|
1810
1999
|
this.registerTask = new Task(
|
|
1811
2000
|
"Register task",
|
|
1812
2001
|
(context) => {
|
|
1813
|
-
const {
|
|
1814
|
-
if (
|
|
1815
|
-
this.tasks.set(
|
|
2002
|
+
const { __taskInstance } = context;
|
|
2003
|
+
if (__taskInstance && !this.tasks.has(__taskInstance.id)) {
|
|
2004
|
+
this.tasks.set(__taskInstance.id, __taskInstance);
|
|
1816
2005
|
}
|
|
2006
|
+
delete context.__taskInstance;
|
|
1817
2007
|
return true;
|
|
1818
2008
|
},
|
|
1819
2009
|
"Registers tasks. Seed for meta.taskCreated",
|
|
@@ -1918,10 +2108,11 @@ var GraphRegistry = class _GraphRegistry {
|
|
|
1918
2108
|
this.registerRoutine = Cadenza.createMetaTask(
|
|
1919
2109
|
"Register routine",
|
|
1920
2110
|
(context) => {
|
|
1921
|
-
const {
|
|
1922
|
-
if (
|
|
1923
|
-
this.routines.set(
|
|
2111
|
+
const { __routineInstance } = context;
|
|
2112
|
+
if (__routineInstance && !this.routines.has(__routineInstance.id)) {
|
|
2113
|
+
this.routines.set(__routineInstance.id, __routineInstance);
|
|
1924
2114
|
}
|
|
2115
|
+
delete context.__routineInstance;
|
|
1925
2116
|
return true;
|
|
1926
2117
|
},
|
|
1927
2118
|
"Registers routine."
|
|
@@ -2058,28 +2249,18 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
2058
2249
|
const ctx = new GraphContext(context || {});
|
|
2059
2250
|
const routineExecId = (_a = context.__routineExecId) != null ? _a : (0, import_uuid6.v4)();
|
|
2060
2251
|
context.__routineExecId = routineExecId;
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
}
|
|
2072
|
-
|
|
2073
|
-
};
|
|
2074
|
-
this.emit("meta.runner.added_tasks", data);
|
|
2075
|
-
if (this.debug) {
|
|
2076
|
-
console.log(
|
|
2077
|
-
`${this.isMeta ? "Meta" : ""}Runner added tasks`,
|
|
2078
|
-
allTasks.map((t) => t.name),
|
|
2079
|
-
"with context",
|
|
2080
|
-
ctx.getFullContext()
|
|
2081
|
-
);
|
|
2082
|
-
}
|
|
2252
|
+
this.emit("meta.runner.added_tasks", {
|
|
2253
|
+
data: {
|
|
2254
|
+
uuid: routineExecId,
|
|
2255
|
+
name: routineName,
|
|
2256
|
+
isMeta,
|
|
2257
|
+
contractId: (_d = (_c = (_b = context.__metaData) == null ? void 0 : _b.__contractId) != null ? _c : context.__contractId) != null ? _d : null,
|
|
2258
|
+
context: ctx.export(),
|
|
2259
|
+
previousRoutineExecution: (_f = (_e = context.__metaData) == null ? void 0 : _e.__routineExecId) != null ? _f : null,
|
|
2260
|
+
// TODO: There is a chance this is not added to the database yet...
|
|
2261
|
+
created: formatTimestamp(Date.now())
|
|
2262
|
+
}
|
|
2263
|
+
});
|
|
2083
2264
|
allTasks.forEach(
|
|
2084
2265
|
(task) => this.currentRun.addNode(
|
|
2085
2266
|
new GraphNode(task, ctx, routineExecId, [], this.debug)
|
|
@@ -2150,7 +2331,7 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
2150
2331
|
|
|
2151
2332
|
// src/graph/definition/DebounceTask.ts
|
|
2152
2333
|
var DebounceTask = class extends Task {
|
|
2153
|
-
constructor(name, task, description = "", debounceTime = 1e3, leading = false, trailing = true, maxWait = 0, concurrency = 0, timeout = 0, register = true, isUnique = false, isMeta = false, inputSchema = void 0, validateInputSchema = false, outputSchema = void 0, validateOutputSchema = false) {
|
|
2334
|
+
constructor(name, task, description = "", debounceTime = 1e3, leading = false, trailing = true, maxWait = 0, concurrency = 0, timeout = 0, register = true, isUnique = false, isMeta = false, isSubMeta = false, isHidden = false, inputSchema = void 0, validateInputSchema = false, outputSchema = void 0, validateOutputSchema = false) {
|
|
2154
2335
|
super(
|
|
2155
2336
|
name,
|
|
2156
2337
|
task,
|
|
@@ -2160,6 +2341,8 @@ var DebounceTask = class extends Task {
|
|
|
2160
2341
|
register,
|
|
2161
2342
|
isUnique,
|
|
2162
2343
|
isMeta,
|
|
2344
|
+
isSubMeta,
|
|
2345
|
+
isHidden,
|
|
2163
2346
|
void 0,
|
|
2164
2347
|
inputSchema,
|
|
2165
2348
|
validateInputSchema,
|
|
@@ -2269,7 +2452,7 @@ var DebounceTask = class extends Task {
|
|
|
2269
2452
|
|
|
2270
2453
|
// src/graph/definition/EphemeralTask.ts
|
|
2271
2454
|
var EphemeralTask = class extends Task {
|
|
2272
|
-
constructor(name, task, description = "", once = true, condition = () => true, concurrency = 0, timeout = 0, register = false, isUnique = false, isMeta = false, getTagCallback = void 0, inputSchema = void 0, validateInputContext = false, outputSchema = void 0, validateOutputContext = false, retryCount = 0, retryDelay = 0, retryDelayMax = 0, retryDelayFactor = 1) {
|
|
2455
|
+
constructor(name, task, description = "", once = true, condition = () => true, concurrency = 0, timeout = 0, register = false, isUnique = false, isMeta = false, isSubMeta = false, isHidden = false, getTagCallback = void 0, inputSchema = void 0, validateInputContext = false, outputSchema = void 0, validateOutputContext = false, retryCount = 0, retryDelay = 0, retryDelayMax = 0, retryDelayFactor = 1) {
|
|
2273
2456
|
super(
|
|
2274
2457
|
name,
|
|
2275
2458
|
task,
|
|
@@ -2279,6 +2462,8 @@ var EphemeralTask = class extends Task {
|
|
|
2279
2462
|
register,
|
|
2280
2463
|
isUnique,
|
|
2281
2464
|
isMeta,
|
|
2465
|
+
isSubMeta,
|
|
2466
|
+
isHidden,
|
|
2282
2467
|
getTagCallback,
|
|
2283
2468
|
inputSchema,
|
|
2284
2469
|
validateInputContext,
|
|
@@ -2295,7 +2480,7 @@ var EphemeralTask = class extends Task {
|
|
|
2295
2480
|
}
|
|
2296
2481
|
execute(context, emit, progressCallback) {
|
|
2297
2482
|
const result = super.execute(context, emit, progressCallback);
|
|
2298
|
-
if (this.once ||
|
|
2483
|
+
if (this.once || this.condition(result)) {
|
|
2299
2484
|
this.destroy();
|
|
2300
2485
|
return result;
|
|
2301
2486
|
}
|
|
@@ -2403,6 +2588,11 @@ var GraphLayer = class _GraphLayer extends ExecutionChain {
|
|
|
2403
2588
|
getNodesByRoutineExecId(routineExecId) {
|
|
2404
2589
|
return this.nodes.filter((node) => node.routineExecId === routineExecId);
|
|
2405
2590
|
}
|
|
2591
|
+
getIdenticalNodes(node) {
|
|
2592
|
+
return this.nodes.filter(
|
|
2593
|
+
(n) => node.routineExecId === n.routineExecId && node.sharesTaskWith(n)
|
|
2594
|
+
);
|
|
2595
|
+
}
|
|
2406
2596
|
isProcessed() {
|
|
2407
2597
|
for (const node of this.nodes) {
|
|
2408
2598
|
if (!node.isProcessed()) {
|
|
@@ -2876,6 +3066,8 @@ var Cadenza = class {
|
|
|
2876
3066
|
register: true,
|
|
2877
3067
|
isUnique: false,
|
|
2878
3068
|
isMeta: false,
|
|
3069
|
+
isSubMeta: false,
|
|
3070
|
+
isHidden: false,
|
|
2879
3071
|
getTagCallback: void 0,
|
|
2880
3072
|
inputSchema: void 0,
|
|
2881
3073
|
validateInputContext: false,
|
|
@@ -2897,6 +3089,8 @@ var Cadenza = class {
|
|
|
2897
3089
|
options.register,
|
|
2898
3090
|
options.isUnique,
|
|
2899
3091
|
options.isMeta,
|
|
3092
|
+
options.isSubMeta,
|
|
3093
|
+
options.isHidden,
|
|
2900
3094
|
options.getTagCallback,
|
|
2901
3095
|
options.inputSchema,
|
|
2902
3096
|
options.validateInputContext,
|
|
@@ -2924,6 +3118,8 @@ var Cadenza = class {
|
|
|
2924
3118
|
register: true,
|
|
2925
3119
|
isUnique: false,
|
|
2926
3120
|
isMeta: true,
|
|
3121
|
+
isSubMeta: false,
|
|
3122
|
+
isHidden: false,
|
|
2927
3123
|
getTagCallback: void 0,
|
|
2928
3124
|
inputSchema: void 0,
|
|
2929
3125
|
validateInputContext: false,
|
|
@@ -2953,6 +3149,8 @@ var Cadenza = class {
|
|
|
2953
3149
|
register: true,
|
|
2954
3150
|
isUnique: true,
|
|
2955
3151
|
isMeta: false,
|
|
3152
|
+
isSubMeta: false,
|
|
3153
|
+
isHidden: false,
|
|
2956
3154
|
getTagCallback: void 0,
|
|
2957
3155
|
inputSchema: void 0,
|
|
2958
3156
|
validateInputContext: false,
|
|
@@ -2980,6 +3178,8 @@ var Cadenza = class {
|
|
|
2980
3178
|
register: true,
|
|
2981
3179
|
isUnique: true,
|
|
2982
3180
|
isMeta: true,
|
|
3181
|
+
isSubMeta: false,
|
|
3182
|
+
isHidden: false,
|
|
2983
3183
|
getTagCallback: void 0,
|
|
2984
3184
|
inputSchema: void 0,
|
|
2985
3185
|
validateInputContext: false,
|
|
@@ -3009,6 +3209,8 @@ var Cadenza = class {
|
|
|
3009
3209
|
register: true,
|
|
3010
3210
|
isUnique: false,
|
|
3011
3211
|
isMeta: false,
|
|
3212
|
+
isSubMeta: false,
|
|
3213
|
+
isHidden: false,
|
|
3012
3214
|
inputSchema: void 0,
|
|
3013
3215
|
validateInputContext: false,
|
|
3014
3216
|
outputSchema: void 0,
|
|
@@ -3036,6 +3238,8 @@ var Cadenza = class {
|
|
|
3036
3238
|
register: true,
|
|
3037
3239
|
isUnique: false,
|
|
3038
3240
|
isMeta: true,
|
|
3241
|
+
isSubMeta: false,
|
|
3242
|
+
isHidden: false,
|
|
3039
3243
|
inputSchema: void 0,
|
|
3040
3244
|
validateInputContext: false,
|
|
3041
3245
|
outputSchema: void 0,
|
|
@@ -3073,6 +3277,8 @@ var Cadenza = class {
|
|
|
3073
3277
|
maxWait: 0,
|
|
3074
3278
|
isUnique: false,
|
|
3075
3279
|
isMeta: false,
|
|
3280
|
+
isSubMeta: false,
|
|
3281
|
+
isHidden: false,
|
|
3076
3282
|
inputSchema: void 0,
|
|
3077
3283
|
validateInputContext: false,
|
|
3078
3284
|
outputSchema: void 0,
|
|
@@ -3093,6 +3299,8 @@ var Cadenza = class {
|
|
|
3093
3299
|
options.register,
|
|
3094
3300
|
options.isUnique,
|
|
3095
3301
|
options.isMeta,
|
|
3302
|
+
options.isSubMeta,
|
|
3303
|
+
options.isHidden,
|
|
3096
3304
|
options.inputSchema,
|
|
3097
3305
|
options.validateInputContext,
|
|
3098
3306
|
options.outputSchema,
|
|
@@ -3117,6 +3325,8 @@ var Cadenza = class {
|
|
|
3117
3325
|
maxWait: 0,
|
|
3118
3326
|
isUnique: false,
|
|
3119
3327
|
isMeta: false,
|
|
3328
|
+
isSubMeta: false,
|
|
3329
|
+
isHidden: false,
|
|
3120
3330
|
inputSchema: void 0,
|
|
3121
3331
|
validateInputContext: false,
|
|
3122
3332
|
outputSchema: void 0,
|
|
@@ -3137,18 +3347,20 @@ var Cadenza = class {
|
|
|
3137
3347
|
* @param name Identifier (may not be unique if not registered).
|
|
3138
3348
|
* @param func Function.
|
|
3139
3349
|
* @param description Optional.
|
|
3140
|
-
* @param
|
|
3141
|
-
* @param destroyCondition Predicate for destruction (default always true).
|
|
3142
|
-
* @param options Optional task options.
|
|
3350
|
+
* @param options Optional task options plus optional "once" (true) and "destroyCondition" (ctx => boolean).
|
|
3143
3351
|
* @returns The created EphemeralTask.
|
|
3144
3352
|
* @edge Destruction triggered post-exec via Node/Builder; emits meta-signal for cleanup.
|
|
3145
3353
|
*/
|
|
3146
|
-
static createEphemeralTask(name, func, description,
|
|
3354
|
+
static createEphemeralTask(name, func, description, options = {
|
|
3147
3355
|
concurrency: 0,
|
|
3148
3356
|
timeout: 0,
|
|
3149
3357
|
register: true,
|
|
3150
3358
|
isUnique: false,
|
|
3151
3359
|
isMeta: false,
|
|
3360
|
+
isSubMeta: false,
|
|
3361
|
+
isHidden: false,
|
|
3362
|
+
once: true,
|
|
3363
|
+
destroyCondition: () => true,
|
|
3152
3364
|
getTagCallback: void 0,
|
|
3153
3365
|
inputSchema: void 0,
|
|
3154
3366
|
validateInputContext: false,
|
|
@@ -3165,13 +3377,15 @@ var Cadenza = class {
|
|
|
3165
3377
|
name,
|
|
3166
3378
|
func,
|
|
3167
3379
|
description,
|
|
3168
|
-
once,
|
|
3169
|
-
destroyCondition,
|
|
3380
|
+
options.once,
|
|
3381
|
+
options.destroyCondition,
|
|
3170
3382
|
options.concurrency,
|
|
3171
3383
|
options.timeout,
|
|
3172
3384
|
options.register,
|
|
3173
3385
|
options.isUnique,
|
|
3174
3386
|
options.isMeta,
|
|
3387
|
+
options.isSubMeta,
|
|
3388
|
+
options.isHidden,
|
|
3175
3389
|
options.getTagCallback,
|
|
3176
3390
|
options.inputSchema,
|
|
3177
3391
|
options.validateInputContext,
|
|
@@ -3188,17 +3402,19 @@ var Cadenza = class {
|
|
|
3188
3402
|
* @param name Identifier.
|
|
3189
3403
|
* @param func Function.
|
|
3190
3404
|
* @param description Optional.
|
|
3191
|
-
* @param once
|
|
3192
|
-
* @param destroyCondition Destruction predicate.
|
|
3193
|
-
* @param options Optional task options.
|
|
3405
|
+
* @param options Optional task options plus optional "once" (true) and "destroyCondition" (ctx => boolean).
|
|
3194
3406
|
* @returns The created EphemeralMetaTask.
|
|
3195
3407
|
*/
|
|
3196
|
-
static createEphemeralMetaTask(name, func, description,
|
|
3408
|
+
static createEphemeralMetaTask(name, func, description, options = {
|
|
3197
3409
|
concurrency: 0,
|
|
3198
3410
|
timeout: 0,
|
|
3199
3411
|
register: true,
|
|
3200
3412
|
isUnique: false,
|
|
3201
3413
|
isMeta: true,
|
|
3414
|
+
isSubMeta: false,
|
|
3415
|
+
isHidden: false,
|
|
3416
|
+
once: true,
|
|
3417
|
+
destroyCondition: () => true,
|
|
3202
3418
|
getTagCallback: void 0,
|
|
3203
3419
|
inputSchema: void 0,
|
|
3204
3420
|
validateInputContext: false,
|
|
@@ -3210,14 +3426,7 @@ var Cadenza = class {
|
|
|
3210
3426
|
retryDelayFactor: 1
|
|
3211
3427
|
}) {
|
|
3212
3428
|
options.isMeta = true;
|
|
3213
|
-
return this.createEphemeralTask(
|
|
3214
|
-
name,
|
|
3215
|
-
func,
|
|
3216
|
-
description,
|
|
3217
|
-
once,
|
|
3218
|
-
destroyCondition,
|
|
3219
|
-
options
|
|
3220
|
-
);
|
|
3429
|
+
return this.createEphemeralTask(name, func, description, options);
|
|
3221
3430
|
}
|
|
3222
3431
|
/**
|
|
3223
3432
|
* Creates a GraphRoutine (named entry to starting tasks) and registers it.
|
|
@@ -3254,6 +3463,7 @@ var Cadenza = class {
|
|
|
3254
3463
|
var _a, _b;
|
|
3255
3464
|
(_a = this.broker) == null ? void 0 : _a.reset();
|
|
3256
3465
|
(_b = this.registry) == null ? void 0 : _b.reset();
|
|
3466
|
+
this.isBootstrapped = false;
|
|
3257
3467
|
}
|
|
3258
3468
|
};
|
|
3259
3469
|
Cadenza.isBootstrapped = false;
|