@cadenza.io/core 1.10.0 → 1.11.0
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 +351 -141
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +351 -141
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
// src/utils/tools.ts
|
|
2
|
+
function deepCloneFilter(input, filterOut = () => false) {
|
|
3
|
+
if (input === null || typeof input !== "object") {
|
|
4
|
+
return input;
|
|
5
|
+
}
|
|
6
|
+
const visited = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
const stack = [];
|
|
8
|
+
const output = Array.isArray(input) ? [] : {};
|
|
9
|
+
stack.push({ source: input, target: output });
|
|
10
|
+
visited.set(input, output);
|
|
11
|
+
while (stack.length) {
|
|
12
|
+
const { source, target, key } = stack.pop();
|
|
13
|
+
const currentTarget = key !== void 0 ? target[key] : target;
|
|
14
|
+
for (const [k, value] of Object.entries(source)) {
|
|
15
|
+
if (filterOut(k)) continue;
|
|
16
|
+
if (value && typeof value === "object") {
|
|
17
|
+
if (visited.has(value)) {
|
|
18
|
+
currentTarget[k] = visited.get(value);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const clonedValue = Array.isArray(value) ? [] : {};
|
|
22
|
+
currentTarget[k] = clonedValue;
|
|
23
|
+
visited.set(value, clonedValue);
|
|
24
|
+
stack.push({ source: value, target: currentTarget, key: k });
|
|
25
|
+
} else {
|
|
26
|
+
currentTarget[k] = value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return output;
|
|
31
|
+
}
|
|
32
|
+
function formatTimestamp(timestamp) {
|
|
33
|
+
return new Date(timestamp).toISOString();
|
|
34
|
+
}
|
|
35
|
+
|
|
1
36
|
// src/engine/SignalBroker.ts
|
|
2
37
|
var SignalBroker = class _SignalBroker {
|
|
3
38
|
// execId -> emitted signals
|
|
@@ -64,8 +99,11 @@ var SignalBroker = class _SignalBroker {
|
|
|
64
99
|
},
|
|
65
100
|
"Executes queued signals and clears the stack",
|
|
66
101
|
500,
|
|
67
|
-
{
|
|
68
|
-
|
|
102
|
+
{
|
|
103
|
+
maxWait: 1e4,
|
|
104
|
+
leading: true
|
|
105
|
+
}
|
|
106
|
+
).doOn("meta.process_signal_queue_requested").emitsAfter("meta.signal_broker.queue_empty");
|
|
69
107
|
this.getSignalsTask = Cadenza.createMetaTask("Get signals", (ctx) => {
|
|
70
108
|
return {
|
|
71
109
|
__signals: Array.from(this.signalObservers.keys()),
|
|
@@ -107,6 +145,7 @@ var SignalBroker = class _SignalBroker {
|
|
|
107
145
|
*/
|
|
108
146
|
emit(signal, context = {}) {
|
|
109
147
|
const execId = context.__routineExecId || "global";
|
|
148
|
+
delete context.__routineExecId;
|
|
110
149
|
if (!this.emitStacks.has(execId)) this.emitStacks.set(execId, /* @__PURE__ */ new Map());
|
|
111
150
|
const stack = this.emitStacks.get(execId);
|
|
112
151
|
stack.set(signal, context);
|
|
@@ -119,29 +158,36 @@ var SignalBroker = class _SignalBroker {
|
|
|
119
158
|
}
|
|
120
159
|
}
|
|
121
160
|
execute(signal, context) {
|
|
122
|
-
const isMeta = signal.startsWith("meta");
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
__signalEmission
|
|
161
|
+
const isMeta = signal.startsWith("meta.");
|
|
162
|
+
const isSubMeta = signal.startsWith("sub_meta.");
|
|
163
|
+
if (!isSubMeta && (!isMeta || this.debug)) {
|
|
164
|
+
const emittedAt = Date.now();
|
|
165
|
+
context.__signalEmission = {
|
|
127
166
|
...context.__signalEmission,
|
|
128
167
|
signalName: signal,
|
|
129
|
-
emittedAt,
|
|
168
|
+
emittedAt: formatTimestamp(emittedAt),
|
|
130
169
|
isMeta
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const parent = parts.slice(0, i).join(".");
|
|
138
|
-
executed = executed || this.executeListener(parent + ".*", data);
|
|
170
|
+
};
|
|
171
|
+
} else if (isSubMeta) {
|
|
172
|
+
context.__isSubMeta = true;
|
|
173
|
+
delete context.__signalEmission;
|
|
174
|
+
} else {
|
|
175
|
+
delete context.__signalEmission;
|
|
139
176
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
)
|
|
177
|
+
let executed;
|
|
178
|
+
executed = this.executeListener(signal, context);
|
|
179
|
+
if (!isSubMeta) {
|
|
180
|
+
const parts = signal.slice(0, Math.max(signal.lastIndexOf(":"), signal.lastIndexOf("."))).split(".");
|
|
181
|
+
for (let i = parts.length; i > 0; i--) {
|
|
182
|
+
const parent = parts.slice(0, i).join(".");
|
|
183
|
+
executed = executed || this.executeListener(parent + ".*", context);
|
|
184
|
+
}
|
|
185
|
+
if (this.debug) {
|
|
186
|
+
console.log(
|
|
187
|
+
`Emitted signal ${signal} with context ${JSON.stringify(context)}`,
|
|
188
|
+
executed ? "\u2705" : "\u274C"
|
|
189
|
+
);
|
|
190
|
+
}
|
|
145
191
|
}
|
|
146
192
|
return executed;
|
|
147
193
|
}
|
|
@@ -448,40 +494,6 @@ import { v4 as uuid3 } from "uuid";
|
|
|
448
494
|
|
|
449
495
|
// src/graph/context/GraphContext.ts
|
|
450
496
|
import { v4 as uuid2 } from "uuid";
|
|
451
|
-
|
|
452
|
-
// src/utils/tools.ts
|
|
453
|
-
function deepCloneFilter(input, filterOut = () => false) {
|
|
454
|
-
if (input === null || typeof input !== "object") {
|
|
455
|
-
return input;
|
|
456
|
-
}
|
|
457
|
-
const visited = /* @__PURE__ */ new WeakMap();
|
|
458
|
-
const stack = [];
|
|
459
|
-
const output = Array.isArray(input) ? [] : {};
|
|
460
|
-
stack.push({ source: input, target: output });
|
|
461
|
-
visited.set(input, output);
|
|
462
|
-
while (stack.length) {
|
|
463
|
-
const { source, target, key } = stack.pop();
|
|
464
|
-
const currentTarget = key !== void 0 ? target[key] : target;
|
|
465
|
-
for (const [k, value] of Object.entries(source)) {
|
|
466
|
-
if (filterOut(k)) continue;
|
|
467
|
-
if (value && typeof value === "object") {
|
|
468
|
-
if (visited.has(value)) {
|
|
469
|
-
currentTarget[k] = visited.get(value);
|
|
470
|
-
continue;
|
|
471
|
-
}
|
|
472
|
-
const clonedValue = Array.isArray(value) ? [] : {};
|
|
473
|
-
currentTarget[k] = clonedValue;
|
|
474
|
-
visited.set(value, clonedValue);
|
|
475
|
-
stack.push({ source: value, target: currentTarget, key: k });
|
|
476
|
-
} else {
|
|
477
|
-
currentTarget[k] = value;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
return output;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
// src/graph/context/GraphContext.ts
|
|
485
497
|
var GraphContext = class _GraphContext {
|
|
486
498
|
// __keys, frozen
|
|
487
499
|
constructor(context) {
|
|
@@ -641,7 +653,10 @@ function sleep(ms) {
|
|
|
641
653
|
// src/graph/execution/GraphNode.ts
|
|
642
654
|
var GraphNode = class _GraphNode extends SignalEmitter {
|
|
643
655
|
constructor(task, context, routineExecId, prevNodes = [], debug = false) {
|
|
644
|
-
|
|
656
|
+
var _a;
|
|
657
|
+
super(
|
|
658
|
+
task.isMeta && !debug || task.isSubMeta || ((_a = context == null ? void 0 : context.getMetaData()) == null ? void 0 : _a.__isSubMeta)
|
|
659
|
+
);
|
|
645
660
|
this.divided = false;
|
|
646
661
|
this.splitGroupId = "";
|
|
647
662
|
this.processing = false;
|
|
@@ -712,6 +727,7 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
712
727
|
return this.task.getTag(this.context);
|
|
713
728
|
}
|
|
714
729
|
scheduleOn(layer) {
|
|
730
|
+
var _a;
|
|
715
731
|
let shouldSchedule = true;
|
|
716
732
|
const nodes = layer.getNodesByRoutineExecId(this.routineExecId);
|
|
717
733
|
for (const node of nodes) {
|
|
@@ -728,23 +744,56 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
728
744
|
if (shouldSchedule) {
|
|
729
745
|
this.layer = layer;
|
|
730
746
|
layer.add(this);
|
|
747
|
+
const context = this.context.getFullContext();
|
|
731
748
|
const scheduledAt = Date.now();
|
|
732
749
|
this.emitWithMetadata("meta.node.scheduled", {
|
|
733
|
-
|
|
734
|
-
|
|
750
|
+
data: {
|
|
751
|
+
uuid: this.id,
|
|
752
|
+
routineExecutionId: this.routineExecId,
|
|
753
|
+
contractId: context.__contractId,
|
|
754
|
+
context: this.context.export(),
|
|
755
|
+
taskId: this.task.id,
|
|
756
|
+
taskName: this.task.name,
|
|
757
|
+
isMeta: this.isMeta(),
|
|
758
|
+
isScheduled: true,
|
|
759
|
+
splitGroupId: this.splitGroupId,
|
|
760
|
+
created: formatTimestamp(scheduledAt)
|
|
761
|
+
}
|
|
735
762
|
});
|
|
736
|
-
|
|
737
|
-
|
|
763
|
+
this.previousNodes.forEach((node) => {
|
|
764
|
+
this.emitWithMetadata("meta.node.mapped", {
|
|
765
|
+
data: {
|
|
766
|
+
taskExecutionId: this.id,
|
|
767
|
+
previousTaskExecutionId: node.id,
|
|
768
|
+
executionCount: "increment"
|
|
769
|
+
},
|
|
770
|
+
filter: {
|
|
771
|
+
taskId: this.task.id,
|
|
772
|
+
previousTaskId: node.task.id
|
|
773
|
+
}
|
|
774
|
+
});
|
|
775
|
+
if (node.failed || node.errored) {
|
|
776
|
+
this.emitWithMetadata("meta.node.failed_mapped", {
|
|
777
|
+
data: {
|
|
778
|
+
executionCount: "increment"
|
|
779
|
+
},
|
|
780
|
+
filter: {
|
|
781
|
+
taskId: this.task.id,
|
|
782
|
+
failTaskId: node.task.id
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
if (((_a = context.__signalEmission) == null ? void 0 : _a.signalName) && (!this.isMeta() || this.debug)) {
|
|
738
788
|
this.emitWithMetadata("meta.node.consumed_signal", {
|
|
739
|
-
|
|
789
|
+
data: {
|
|
740
790
|
signalName: context.__signalEmission.signalName,
|
|
741
791
|
taskId: this.task.id,
|
|
742
792
|
taskExecutionId: this.id,
|
|
743
|
-
consumedAt: scheduledAt
|
|
793
|
+
consumedAt: formatTimestamp(scheduledAt)
|
|
744
794
|
}
|
|
745
795
|
});
|
|
746
796
|
delete context.__signalEmission;
|
|
747
|
-
this.migrate(context);
|
|
748
797
|
}
|
|
749
798
|
}
|
|
750
799
|
}
|
|
@@ -752,14 +801,25 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
752
801
|
if (this.executionStart === 0) {
|
|
753
802
|
this.executionStart = Date.now();
|
|
754
803
|
}
|
|
755
|
-
const memento = this.lightExport();
|
|
756
804
|
if (this.previousNodes.length === 0) {
|
|
757
|
-
this.emitWithMetadata("meta.node.started_routine_execution",
|
|
805
|
+
this.emitWithMetadata("meta.node.started_routine_execution", {
|
|
806
|
+
data: {
|
|
807
|
+
isRunning: true,
|
|
808
|
+
started: formatTimestamp(this.executionStart)
|
|
809
|
+
},
|
|
810
|
+
filter: { uuid: this.routineExecId }
|
|
811
|
+
});
|
|
758
812
|
}
|
|
759
813
|
if (this.debug) {
|
|
760
814
|
this.log();
|
|
761
815
|
}
|
|
762
|
-
this.emitWithMetadata("meta.node.started",
|
|
816
|
+
this.emitWithMetadata("meta.node.started", {
|
|
817
|
+
data: {
|
|
818
|
+
isRunning: true,
|
|
819
|
+
started: formatTimestamp(this.executionStart)
|
|
820
|
+
},
|
|
821
|
+
filter: { uuid: this.id }
|
|
822
|
+
});
|
|
763
823
|
return this.executionStart;
|
|
764
824
|
}
|
|
765
825
|
end() {
|
|
@@ -769,15 +829,44 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
769
829
|
this.processing = false;
|
|
770
830
|
const end = Date.now();
|
|
771
831
|
this.executionTime = end - this.executionStart;
|
|
772
|
-
const
|
|
832
|
+
const context = this.context.getFullContext();
|
|
773
833
|
if (this.errored || this.failed) {
|
|
774
|
-
this.emitWithMetadata("meta.node.errored",
|
|
834
|
+
this.emitWithMetadata("meta.node.errored", {
|
|
835
|
+
data: {
|
|
836
|
+
isRunning: false,
|
|
837
|
+
errored: this.errored,
|
|
838
|
+
failed: this.failed,
|
|
839
|
+
errorMessage: context.__error
|
|
840
|
+
},
|
|
841
|
+
filter: { uuid: this.id }
|
|
842
|
+
});
|
|
775
843
|
}
|
|
776
|
-
this.emitWithMetadata("meta.node.ended",
|
|
844
|
+
this.emitWithMetadata("meta.node.ended", {
|
|
845
|
+
data: {
|
|
846
|
+
isRunning: false,
|
|
847
|
+
isComplete: true,
|
|
848
|
+
resultContext: this.context.export(),
|
|
849
|
+
errored: this.errored,
|
|
850
|
+
failed: this.failed,
|
|
851
|
+
errorMessage: context.__error,
|
|
852
|
+
progress: 1,
|
|
853
|
+
ended: formatTimestamp(end)
|
|
854
|
+
},
|
|
855
|
+
filter: { uuid: this.id }
|
|
856
|
+
});
|
|
777
857
|
if (this.graphDone()) {
|
|
778
858
|
this.emitWithMetadata(
|
|
779
859
|
`meta.node.ended_routine_execution:${this.routineExecId}`,
|
|
780
|
-
|
|
860
|
+
{
|
|
861
|
+
data: {
|
|
862
|
+
isRunning: false,
|
|
863
|
+
isComplete: true,
|
|
864
|
+
resultContext: this.context.export(),
|
|
865
|
+
progress: 1,
|
|
866
|
+
ended: formatTimestamp(end)
|
|
867
|
+
},
|
|
868
|
+
filter: { uuid: this.routineExecId }
|
|
869
|
+
}
|
|
781
870
|
);
|
|
782
871
|
}
|
|
783
872
|
return end;
|
|
@@ -839,23 +928,41 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
839
928
|
}
|
|
840
929
|
}
|
|
841
930
|
emitWithMetadata(signal, ctx) {
|
|
842
|
-
this.
|
|
843
|
-
|
|
844
|
-
|
|
931
|
+
if (this.silent) return;
|
|
932
|
+
const data = { ...ctx };
|
|
933
|
+
if (!this.task.isHidden) {
|
|
934
|
+
data.__signalEmission = {
|
|
845
935
|
taskId: this.task.id,
|
|
846
936
|
taskExecutionId: this.id
|
|
847
|
-
}
|
|
848
|
-
|
|
937
|
+
};
|
|
938
|
+
data.__metadata = {
|
|
939
|
+
__routineExecId: this.routineExecId
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
this.emit(signal, data);
|
|
849
943
|
}
|
|
850
944
|
onProgress(progress) {
|
|
851
|
-
var _a, _b
|
|
945
|
+
var _a, _b;
|
|
852
946
|
progress = Math.min(Math.max(0, progress), 1);
|
|
853
|
-
this.emitWithMetadata(
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
947
|
+
this.emitWithMetadata("meta.node.progress", {
|
|
948
|
+
data: {
|
|
949
|
+
progress
|
|
950
|
+
},
|
|
951
|
+
filter: {
|
|
952
|
+
uuid: this.id
|
|
953
|
+
}
|
|
858
954
|
});
|
|
955
|
+
this.emitWithMetadata(
|
|
956
|
+
`meta.node.routine_execution_progress:${this.routineExecId}`,
|
|
957
|
+
{
|
|
958
|
+
data: {
|
|
959
|
+
progress: progress * this.task.progressWeight / ((_b = (_a = this.layer) == null ? void 0 : _a.getIdenticalNodes(this).length) != null ? _b : 1)
|
|
960
|
+
},
|
|
961
|
+
filter: {
|
|
962
|
+
uuid: this.routineExecId
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
);
|
|
859
966
|
}
|
|
860
967
|
postProcess() {
|
|
861
968
|
if (typeof this.result === "string") {
|
|
@@ -872,11 +979,11 @@ var GraphNode = class _GraphNode extends SignalEmitter {
|
|
|
872
979
|
}
|
|
873
980
|
if (this.errored || this.failed) {
|
|
874
981
|
this.task.mapOnFailSignals(
|
|
875
|
-
(signal) => this.emitWithMetadata(signal, this.context)
|
|
982
|
+
(signal) => this.emitWithMetadata(signal, this.context.getFullContext())
|
|
876
983
|
);
|
|
877
984
|
} else {
|
|
878
985
|
this.task.mapSignals(
|
|
879
|
-
(signal) => this.emitWithMetadata(signal, this.context)
|
|
986
|
+
(signal) => this.emitWithMetadata(signal, this.context.getFullContext())
|
|
880
987
|
);
|
|
881
988
|
}
|
|
882
989
|
this.end();
|
|
@@ -1265,8 +1372,24 @@ var GraphRoutine = class extends SignalParticipant {
|
|
|
1265
1372
|
this.name = name;
|
|
1266
1373
|
this.description = description;
|
|
1267
1374
|
this.isMeta = isMeta;
|
|
1268
|
-
|
|
1269
|
-
|
|
1375
|
+
this.emit("meta.routine.created", {
|
|
1376
|
+
data: {
|
|
1377
|
+
uuid: this.id,
|
|
1378
|
+
name: this.name,
|
|
1379
|
+
description: this.description,
|
|
1380
|
+
isMeta: this.isMeta
|
|
1381
|
+
},
|
|
1382
|
+
__routineInstance: this
|
|
1383
|
+
});
|
|
1384
|
+
tasks.forEach((t) => {
|
|
1385
|
+
this.tasks.add(t);
|
|
1386
|
+
this.emit("meta.routine.task_added", {
|
|
1387
|
+
data: {
|
|
1388
|
+
taskId: t.id,
|
|
1389
|
+
routineId: this.id
|
|
1390
|
+
}
|
|
1391
|
+
});
|
|
1392
|
+
});
|
|
1270
1393
|
}
|
|
1271
1394
|
/**
|
|
1272
1395
|
* Applies callback to starting tasks.
|
|
@@ -1296,7 +1419,10 @@ var GraphRoutine = class extends SignalParticipant {
|
|
|
1296
1419
|
*/
|
|
1297
1420
|
destroy() {
|
|
1298
1421
|
this.tasks.clear();
|
|
1299
|
-
this.emit("meta.routine.destroyed", {
|
|
1422
|
+
this.emit("meta.routine.destroyed", {
|
|
1423
|
+
data: { deleted: true },
|
|
1424
|
+
filter: { uuid: this.id }
|
|
1425
|
+
});
|
|
1300
1426
|
}
|
|
1301
1427
|
};
|
|
1302
1428
|
|
|
@@ -1346,6 +1472,8 @@ var Task = class extends SignalParticipant {
|
|
|
1346
1472
|
* @param register Register via signal (default true).
|
|
1347
1473
|
* @param isUnique
|
|
1348
1474
|
* @param isMeta
|
|
1475
|
+
* @param isSubMeta
|
|
1476
|
+
* @param isHidden
|
|
1349
1477
|
* @param getTagCallback
|
|
1350
1478
|
* @param inputSchema
|
|
1351
1479
|
* @param validateInputContext
|
|
@@ -1357,14 +1485,17 @@ var Task = class extends SignalParticipant {
|
|
|
1357
1485
|
* @param retryDelayFactor
|
|
1358
1486
|
* @edge Emits 'meta.task.created' with { __task: this } for seed.
|
|
1359
1487
|
*/
|
|
1360
|
-
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) {
|
|
1488
|
+
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) {
|
|
1361
1489
|
super();
|
|
1362
1490
|
this.isMeta = false;
|
|
1491
|
+
this.isSubMeta = false;
|
|
1492
|
+
this.isHidden = false;
|
|
1363
1493
|
this.isUnique = false;
|
|
1364
1494
|
this.throttled = false;
|
|
1365
1495
|
this.isSignal = false;
|
|
1366
1496
|
this.isDeputy = false;
|
|
1367
1497
|
this.isEphemeral = false;
|
|
1498
|
+
this.isDebounce = false;
|
|
1368
1499
|
this.inputContextSchema = void 0;
|
|
1369
1500
|
this.validateInputContext = false;
|
|
1370
1501
|
this.outputContextSchema = void 0;
|
|
@@ -1387,6 +1518,8 @@ var Task = class extends SignalParticipant {
|
|
|
1387
1518
|
this.timeout = timeout;
|
|
1388
1519
|
this.isUnique = isUnique;
|
|
1389
1520
|
this.isMeta = isMeta;
|
|
1521
|
+
this.isSubMeta = isSubMeta;
|
|
1522
|
+
this.isHidden = isHidden;
|
|
1390
1523
|
this.inputContextSchema = inputSchema;
|
|
1391
1524
|
this.validateInputContext = validateInputContext;
|
|
1392
1525
|
this.outputContextSchema = outputSchema;
|
|
@@ -1399,8 +1532,35 @@ var Task = class extends SignalParticipant {
|
|
|
1399
1532
|
this.getTag = (context) => getTagCallback(context, this);
|
|
1400
1533
|
this.throttled = true;
|
|
1401
1534
|
}
|
|
1402
|
-
if (register) {
|
|
1403
|
-
|
|
1535
|
+
if (register && !this.isHidden && !this.isSubMeta) {
|
|
1536
|
+
const { __functionString, __getTagCallback } = this.export();
|
|
1537
|
+
this.emit("meta.task.created", {
|
|
1538
|
+
__task: {
|
|
1539
|
+
uuid: this.id,
|
|
1540
|
+
name: this.name,
|
|
1541
|
+
description: this.description,
|
|
1542
|
+
functionString: __functionString,
|
|
1543
|
+
tagIdGetter: __getTagCallback,
|
|
1544
|
+
layerIndex: this.layerIndex,
|
|
1545
|
+
concurrency: this.concurrency,
|
|
1546
|
+
retryCount: this.retryCount,
|
|
1547
|
+
retryDelay: this.retryDelay,
|
|
1548
|
+
retryDelayMax: this.retryDelayMax,
|
|
1549
|
+
retryDelayFactor: this.retryDelayFactor,
|
|
1550
|
+
timeout: this.timeout,
|
|
1551
|
+
isUnique: this.isUnique,
|
|
1552
|
+
isSignal: this.isSignal,
|
|
1553
|
+
isThrottled: this.throttled,
|
|
1554
|
+
isDebounce: this.isDebounce,
|
|
1555
|
+
isEphemeral: this.isEphemeral,
|
|
1556
|
+
isMeta: this.isMeta,
|
|
1557
|
+
validateInputContext: this.validateInputContext,
|
|
1558
|
+
validateOutputContext: this.validateOutputContext,
|
|
1559
|
+
inputContextSchemaId: this.inputContextSchema,
|
|
1560
|
+
outputContextSchemaId: this.outputContextSchema
|
|
1561
|
+
},
|
|
1562
|
+
__taskInstance: this
|
|
1563
|
+
});
|
|
1404
1564
|
}
|
|
1405
1565
|
}
|
|
1406
1566
|
getTag(context) {
|
|
@@ -1610,6 +1770,12 @@ var Task = class extends SignalParticipant {
|
|
|
1610
1770
|
this.decouple(pred);
|
|
1611
1771
|
throw new Error(`Cycle adding pred ${pred.name} to ${this.name}`);
|
|
1612
1772
|
}
|
|
1773
|
+
this.emit("meta.task.relationship_added", {
|
|
1774
|
+
data: {
|
|
1775
|
+
taskId: this.id,
|
|
1776
|
+
predecessorTaskId: pred.id
|
|
1777
|
+
}
|
|
1778
|
+
});
|
|
1613
1779
|
}
|
|
1614
1780
|
this.updateProgressWeights();
|
|
1615
1781
|
return this;
|
|
@@ -1624,6 +1790,12 @@ var Task = class extends SignalParticipant {
|
|
|
1624
1790
|
this.decouple(next);
|
|
1625
1791
|
throw new Error(`Cycle adding next ${next.name} to ${this.name}`);
|
|
1626
1792
|
}
|
|
1793
|
+
this.emit("meta.task.relationship_added", {
|
|
1794
|
+
data: {
|
|
1795
|
+
taskId: next.id,
|
|
1796
|
+
predecessorTaskId: this.id
|
|
1797
|
+
}
|
|
1798
|
+
});
|
|
1627
1799
|
}
|
|
1628
1800
|
this.updateProgressWeights();
|
|
1629
1801
|
return this;
|
|
@@ -1649,6 +1821,12 @@ var Task = class extends SignalParticipant {
|
|
|
1649
1821
|
this.decouple(task);
|
|
1650
1822
|
throw new Error(`Cycle adding onFail ${task.name} to ${this.name}`);
|
|
1651
1823
|
}
|
|
1824
|
+
this.emit("meta.task.on_fail_relationship_added", {
|
|
1825
|
+
data: {
|
|
1826
|
+
taskId: this.id,
|
|
1827
|
+
onFailTaskId: task.id
|
|
1828
|
+
}
|
|
1829
|
+
});
|
|
1652
1830
|
}
|
|
1653
1831
|
return this;
|
|
1654
1832
|
}
|
|
@@ -1680,11 +1858,20 @@ var Task = class extends SignalParticipant {
|
|
|
1680
1858
|
return layers;
|
|
1681
1859
|
}
|
|
1682
1860
|
updateLayerFromPredecessors() {
|
|
1861
|
+
const prevLayerIndex = this.layerIndex;
|
|
1683
1862
|
let maxPred = 0;
|
|
1684
1863
|
this.predecessorTasks.forEach(
|
|
1685
1864
|
(pred) => maxPred = Math.max(maxPred, pred.layerIndex)
|
|
1686
1865
|
);
|
|
1687
1866
|
this.layerIndex = maxPred + 1;
|
|
1867
|
+
if (prevLayerIndex !== this.layerIndex) {
|
|
1868
|
+
this.emit("meta.task.layer_index_changed", {
|
|
1869
|
+
data: {
|
|
1870
|
+
layerIndex: this.layerIndex
|
|
1871
|
+
},
|
|
1872
|
+
filter: { uuid: this.id }
|
|
1873
|
+
});
|
|
1874
|
+
}
|
|
1688
1875
|
const queue = Array.from(this.nextTasks);
|
|
1689
1876
|
while (queue.length) {
|
|
1690
1877
|
const next = queue.shift();
|
|
@@ -1724,7 +1911,10 @@ var Task = class extends SignalParticipant {
|
|
|
1724
1911
|
this.predecessorTasks.clear();
|
|
1725
1912
|
this.onFailTasks.clear();
|
|
1726
1913
|
this.destroyed = true;
|
|
1727
|
-
this.emit("meta.task.destroyed", {
|
|
1914
|
+
this.emit("meta.task.destroyed", {
|
|
1915
|
+
data: { deleted: true },
|
|
1916
|
+
filter: { uuid: this.id }
|
|
1917
|
+
});
|
|
1728
1918
|
}
|
|
1729
1919
|
export() {
|
|
1730
1920
|
return {
|
|
@@ -1770,13 +1960,13 @@ var GraphRegistry = class _GraphRegistry {
|
|
|
1770
1960
|
this.tasks = /* @__PURE__ */ new Map();
|
|
1771
1961
|
this.routines = /* @__PURE__ */ new Map();
|
|
1772
1962
|
this.registerTask = new Task(
|
|
1773
|
-
"
|
|
1963
|
+
"Register task",
|
|
1774
1964
|
(context) => {
|
|
1775
|
-
const {
|
|
1776
|
-
if (
|
|
1777
|
-
|
|
1778
|
-
this.tasks.set(__task.id, __task);
|
|
1965
|
+
const { __taskInstance } = context;
|
|
1966
|
+
if (__taskInstance && !this.tasks.has(__taskInstance.id)) {
|
|
1967
|
+
this.tasks.set(__taskInstance.id, __taskInstance);
|
|
1779
1968
|
}
|
|
1969
|
+
delete context.__taskInstance;
|
|
1780
1970
|
return true;
|
|
1781
1971
|
},
|
|
1782
1972
|
"Registers tasks. Seed for meta.taskCreated",
|
|
@@ -1881,10 +2071,11 @@ var GraphRegistry = class _GraphRegistry {
|
|
|
1881
2071
|
this.registerRoutine = Cadenza.createMetaTask(
|
|
1882
2072
|
"Register routine",
|
|
1883
2073
|
(context) => {
|
|
1884
|
-
const {
|
|
1885
|
-
if (
|
|
1886
|
-
this.routines.set(
|
|
2074
|
+
const { __routineInstance } = context;
|
|
2075
|
+
if (__routineInstance && !this.routines.has(__routineInstance.id)) {
|
|
2076
|
+
this.routines.set(__routineInstance.id, __routineInstance);
|
|
1887
2077
|
}
|
|
2078
|
+
delete context.__routineInstance;
|
|
1888
2079
|
return true;
|
|
1889
2080
|
},
|
|
1890
2081
|
"Registers routine."
|
|
@@ -2021,28 +2212,18 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
2021
2212
|
const ctx = new GraphContext(context || {});
|
|
2022
2213
|
const routineExecId = (_a = context.__routineExecId) != null ? _a : uuid6();
|
|
2023
2214
|
context.__routineExecId = routineExecId;
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
}
|
|
2035
|
-
|
|
2036
|
-
};
|
|
2037
|
-
this.emit("meta.runner.added_tasks", data);
|
|
2038
|
-
if (this.debug) {
|
|
2039
|
-
console.log(
|
|
2040
|
-
`${this.isMeta ? "Meta" : ""}Runner added tasks`,
|
|
2041
|
-
allTasks.map((t) => t.name),
|
|
2042
|
-
"with context",
|
|
2043
|
-
ctx.getFullContext()
|
|
2044
|
-
);
|
|
2045
|
-
}
|
|
2215
|
+
this.emit("meta.runner.added_tasks", {
|
|
2216
|
+
data: {
|
|
2217
|
+
uuid: routineExecId,
|
|
2218
|
+
name: routineName,
|
|
2219
|
+
isMeta,
|
|
2220
|
+
contractId: (_d = (_c = (_b = context.__metaData) == null ? void 0 : _b.__contractId) != null ? _c : context.__contractId) != null ? _d : null,
|
|
2221
|
+
context: ctx.export(),
|
|
2222
|
+
previousRoutineExecution: (_f = (_e = context.__metaData) == null ? void 0 : _e.__routineExecId) != null ? _f : null,
|
|
2223
|
+
// TODO: There is a chance this is not added to the database yet...
|
|
2224
|
+
created: formatTimestamp(Date.now())
|
|
2225
|
+
}
|
|
2226
|
+
});
|
|
2046
2227
|
allTasks.forEach(
|
|
2047
2228
|
(task) => this.currentRun.addNode(
|
|
2048
2229
|
new GraphNode(task, ctx, routineExecId, [], this.debug)
|
|
@@ -2113,7 +2294,7 @@ var GraphRunner = class extends SignalEmitter {
|
|
|
2113
2294
|
|
|
2114
2295
|
// src/graph/definition/DebounceTask.ts
|
|
2115
2296
|
var DebounceTask = class extends Task {
|
|
2116
|
-
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) {
|
|
2297
|
+
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) {
|
|
2117
2298
|
super(
|
|
2118
2299
|
name,
|
|
2119
2300
|
task,
|
|
@@ -2123,6 +2304,8 @@ var DebounceTask = class extends Task {
|
|
|
2123
2304
|
register,
|
|
2124
2305
|
isUnique,
|
|
2125
2306
|
isMeta,
|
|
2307
|
+
isSubMeta,
|
|
2308
|
+
isHidden,
|
|
2126
2309
|
void 0,
|
|
2127
2310
|
inputSchema,
|
|
2128
2311
|
validateInputSchema,
|
|
@@ -2232,7 +2415,7 @@ var DebounceTask = class extends Task {
|
|
|
2232
2415
|
|
|
2233
2416
|
// src/graph/definition/EphemeralTask.ts
|
|
2234
2417
|
var EphemeralTask = class extends Task {
|
|
2235
|
-
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) {
|
|
2418
|
+
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) {
|
|
2236
2419
|
super(
|
|
2237
2420
|
name,
|
|
2238
2421
|
task,
|
|
@@ -2242,6 +2425,8 @@ var EphemeralTask = class extends Task {
|
|
|
2242
2425
|
register,
|
|
2243
2426
|
isUnique,
|
|
2244
2427
|
isMeta,
|
|
2428
|
+
isSubMeta,
|
|
2429
|
+
isHidden,
|
|
2245
2430
|
getTagCallback,
|
|
2246
2431
|
inputSchema,
|
|
2247
2432
|
validateInputContext,
|
|
@@ -2258,7 +2443,7 @@ var EphemeralTask = class extends Task {
|
|
|
2258
2443
|
}
|
|
2259
2444
|
execute(context, emit, progressCallback) {
|
|
2260
2445
|
const result = super.execute(context, emit, progressCallback);
|
|
2261
|
-
if (this.once ||
|
|
2446
|
+
if (this.once || this.condition(result)) {
|
|
2262
2447
|
this.destroy();
|
|
2263
2448
|
return result;
|
|
2264
2449
|
}
|
|
@@ -2366,6 +2551,11 @@ var GraphLayer = class _GraphLayer extends ExecutionChain {
|
|
|
2366
2551
|
getNodesByRoutineExecId(routineExecId) {
|
|
2367
2552
|
return this.nodes.filter((node) => node.routineExecId === routineExecId);
|
|
2368
2553
|
}
|
|
2554
|
+
getIdenticalNodes(node) {
|
|
2555
|
+
return this.nodes.filter(
|
|
2556
|
+
(n) => node.routineExecId === n.routineExecId && node.sharesTaskWith(n)
|
|
2557
|
+
);
|
|
2558
|
+
}
|
|
2369
2559
|
isProcessed() {
|
|
2370
2560
|
for (const node of this.nodes) {
|
|
2371
2561
|
if (!node.isProcessed()) {
|
|
@@ -2839,6 +3029,8 @@ var Cadenza = class {
|
|
|
2839
3029
|
register: true,
|
|
2840
3030
|
isUnique: false,
|
|
2841
3031
|
isMeta: false,
|
|
3032
|
+
isSubMeta: false,
|
|
3033
|
+
isHidden: false,
|
|
2842
3034
|
getTagCallback: void 0,
|
|
2843
3035
|
inputSchema: void 0,
|
|
2844
3036
|
validateInputContext: false,
|
|
@@ -2860,6 +3052,8 @@ var Cadenza = class {
|
|
|
2860
3052
|
options.register,
|
|
2861
3053
|
options.isUnique,
|
|
2862
3054
|
options.isMeta,
|
|
3055
|
+
options.isSubMeta,
|
|
3056
|
+
options.isHidden,
|
|
2863
3057
|
options.getTagCallback,
|
|
2864
3058
|
options.inputSchema,
|
|
2865
3059
|
options.validateInputContext,
|
|
@@ -2887,6 +3081,8 @@ var Cadenza = class {
|
|
|
2887
3081
|
register: true,
|
|
2888
3082
|
isUnique: false,
|
|
2889
3083
|
isMeta: true,
|
|
3084
|
+
isSubMeta: false,
|
|
3085
|
+
isHidden: false,
|
|
2890
3086
|
getTagCallback: void 0,
|
|
2891
3087
|
inputSchema: void 0,
|
|
2892
3088
|
validateInputContext: false,
|
|
@@ -2916,6 +3112,8 @@ var Cadenza = class {
|
|
|
2916
3112
|
register: true,
|
|
2917
3113
|
isUnique: true,
|
|
2918
3114
|
isMeta: false,
|
|
3115
|
+
isSubMeta: false,
|
|
3116
|
+
isHidden: false,
|
|
2919
3117
|
getTagCallback: void 0,
|
|
2920
3118
|
inputSchema: void 0,
|
|
2921
3119
|
validateInputContext: false,
|
|
@@ -2943,6 +3141,8 @@ var Cadenza = class {
|
|
|
2943
3141
|
register: true,
|
|
2944
3142
|
isUnique: true,
|
|
2945
3143
|
isMeta: true,
|
|
3144
|
+
isSubMeta: false,
|
|
3145
|
+
isHidden: false,
|
|
2946
3146
|
getTagCallback: void 0,
|
|
2947
3147
|
inputSchema: void 0,
|
|
2948
3148
|
validateInputContext: false,
|
|
@@ -2972,6 +3172,8 @@ var Cadenza = class {
|
|
|
2972
3172
|
register: true,
|
|
2973
3173
|
isUnique: false,
|
|
2974
3174
|
isMeta: false,
|
|
3175
|
+
isSubMeta: false,
|
|
3176
|
+
isHidden: false,
|
|
2975
3177
|
inputSchema: void 0,
|
|
2976
3178
|
validateInputContext: false,
|
|
2977
3179
|
outputSchema: void 0,
|
|
@@ -2999,6 +3201,8 @@ var Cadenza = class {
|
|
|
2999
3201
|
register: true,
|
|
3000
3202
|
isUnique: false,
|
|
3001
3203
|
isMeta: true,
|
|
3204
|
+
isSubMeta: false,
|
|
3205
|
+
isHidden: false,
|
|
3002
3206
|
inputSchema: void 0,
|
|
3003
3207
|
validateInputContext: false,
|
|
3004
3208
|
outputSchema: void 0,
|
|
@@ -3036,6 +3240,8 @@ var Cadenza = class {
|
|
|
3036
3240
|
maxWait: 0,
|
|
3037
3241
|
isUnique: false,
|
|
3038
3242
|
isMeta: false,
|
|
3243
|
+
isSubMeta: false,
|
|
3244
|
+
isHidden: false,
|
|
3039
3245
|
inputSchema: void 0,
|
|
3040
3246
|
validateInputContext: false,
|
|
3041
3247
|
outputSchema: void 0,
|
|
@@ -3056,6 +3262,8 @@ var Cadenza = class {
|
|
|
3056
3262
|
options.register,
|
|
3057
3263
|
options.isUnique,
|
|
3058
3264
|
options.isMeta,
|
|
3265
|
+
options.isSubMeta,
|
|
3266
|
+
options.isHidden,
|
|
3059
3267
|
options.inputSchema,
|
|
3060
3268
|
options.validateInputContext,
|
|
3061
3269
|
options.outputSchema,
|
|
@@ -3080,6 +3288,8 @@ var Cadenza = class {
|
|
|
3080
3288
|
maxWait: 0,
|
|
3081
3289
|
isUnique: false,
|
|
3082
3290
|
isMeta: false,
|
|
3291
|
+
isSubMeta: false,
|
|
3292
|
+
isHidden: false,
|
|
3083
3293
|
inputSchema: void 0,
|
|
3084
3294
|
validateInputContext: false,
|
|
3085
3295
|
outputSchema: void 0,
|
|
@@ -3100,18 +3310,20 @@ var Cadenza = class {
|
|
|
3100
3310
|
* @param name Identifier (may not be unique if not registered).
|
|
3101
3311
|
* @param func Function.
|
|
3102
3312
|
* @param description Optional.
|
|
3103
|
-
* @param
|
|
3104
|
-
* @param destroyCondition Predicate for destruction (default always true).
|
|
3105
|
-
* @param options Optional task options.
|
|
3313
|
+
* @param options Optional task options plus optional "once" (true) and "destroyCondition" (ctx => boolean).
|
|
3106
3314
|
* @returns The created EphemeralTask.
|
|
3107
3315
|
* @edge Destruction triggered post-exec via Node/Builder; emits meta-signal for cleanup.
|
|
3108
3316
|
*/
|
|
3109
|
-
static createEphemeralTask(name, func, description,
|
|
3317
|
+
static createEphemeralTask(name, func, description, options = {
|
|
3110
3318
|
concurrency: 0,
|
|
3111
3319
|
timeout: 0,
|
|
3112
3320
|
register: true,
|
|
3113
3321
|
isUnique: false,
|
|
3114
3322
|
isMeta: false,
|
|
3323
|
+
isSubMeta: false,
|
|
3324
|
+
isHidden: false,
|
|
3325
|
+
once: true,
|
|
3326
|
+
destroyCondition: () => true,
|
|
3115
3327
|
getTagCallback: void 0,
|
|
3116
3328
|
inputSchema: void 0,
|
|
3117
3329
|
validateInputContext: false,
|
|
@@ -3128,13 +3340,15 @@ var Cadenza = class {
|
|
|
3128
3340
|
name,
|
|
3129
3341
|
func,
|
|
3130
3342
|
description,
|
|
3131
|
-
once,
|
|
3132
|
-
destroyCondition,
|
|
3343
|
+
options.once,
|
|
3344
|
+
options.destroyCondition,
|
|
3133
3345
|
options.concurrency,
|
|
3134
3346
|
options.timeout,
|
|
3135
3347
|
options.register,
|
|
3136
3348
|
options.isUnique,
|
|
3137
3349
|
options.isMeta,
|
|
3350
|
+
options.isSubMeta,
|
|
3351
|
+
options.isHidden,
|
|
3138
3352
|
options.getTagCallback,
|
|
3139
3353
|
options.inputSchema,
|
|
3140
3354
|
options.validateInputContext,
|
|
@@ -3151,17 +3365,19 @@ var Cadenza = class {
|
|
|
3151
3365
|
* @param name Identifier.
|
|
3152
3366
|
* @param func Function.
|
|
3153
3367
|
* @param description Optional.
|
|
3154
|
-
* @param once
|
|
3155
|
-
* @param destroyCondition Destruction predicate.
|
|
3156
|
-
* @param options Optional task options.
|
|
3368
|
+
* @param options Optional task options plus optional "once" (true) and "destroyCondition" (ctx => boolean).
|
|
3157
3369
|
* @returns The created EphemeralMetaTask.
|
|
3158
3370
|
*/
|
|
3159
|
-
static createEphemeralMetaTask(name, func, description,
|
|
3371
|
+
static createEphemeralMetaTask(name, func, description, options = {
|
|
3160
3372
|
concurrency: 0,
|
|
3161
3373
|
timeout: 0,
|
|
3162
3374
|
register: true,
|
|
3163
3375
|
isUnique: false,
|
|
3164
3376
|
isMeta: true,
|
|
3377
|
+
isSubMeta: false,
|
|
3378
|
+
isHidden: false,
|
|
3379
|
+
once: true,
|
|
3380
|
+
destroyCondition: () => true,
|
|
3165
3381
|
getTagCallback: void 0,
|
|
3166
3382
|
inputSchema: void 0,
|
|
3167
3383
|
validateInputContext: false,
|
|
@@ -3173,14 +3389,7 @@ var Cadenza = class {
|
|
|
3173
3389
|
retryDelayFactor: 1
|
|
3174
3390
|
}) {
|
|
3175
3391
|
options.isMeta = true;
|
|
3176
|
-
return this.createEphemeralTask(
|
|
3177
|
-
name,
|
|
3178
|
-
func,
|
|
3179
|
-
description,
|
|
3180
|
-
once,
|
|
3181
|
-
destroyCondition,
|
|
3182
|
-
options
|
|
3183
|
-
);
|
|
3392
|
+
return this.createEphemeralTask(name, func, description, options);
|
|
3184
3393
|
}
|
|
3185
3394
|
/**
|
|
3186
3395
|
* Creates a GraphRoutine (named entry to starting tasks) and registers it.
|
|
@@ -3217,6 +3426,7 @@ var Cadenza = class {
|
|
|
3217
3426
|
var _a, _b;
|
|
3218
3427
|
(_a = this.broker) == null ? void 0 : _a.reset();
|
|
3219
3428
|
(_b = this.registry) == null ? void 0 : _b.reset();
|
|
3429
|
+
this.isBootstrapped = false;
|
|
3220
3430
|
}
|
|
3221
3431
|
};
|
|
3222
3432
|
Cadenza.isBootstrapped = false;
|