@cadenza.io/core 3.14.0 → 3.15.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 CHANGED
@@ -1000,6 +1000,7 @@ declare class Task extends SignalEmitter implements Graph {
1000
1000
  * @return {any[]} An array containing the results of applying the callback function to each predecessor task.
1001
1001
  */
1002
1002
  mapPrevious(callback: (task: Task) => any): any[];
1003
+ makeRoutine(name: string, description: string): this;
1003
1004
  /**
1004
1005
  * Adds the specified signals to the current instance, making it observe them.
1005
1006
  * If the instance is already observing a signal, it will be skipped.
@@ -1027,11 +1028,10 @@ declare class Task extends SignalEmitter implements Graph {
1027
1028
  /**
1028
1029
  * Attaches a signal to the current context and emits metadata if the register flag is set.
1029
1030
  *
1030
- * @param {string} signal - The name of the signal to attach.
1031
- * @param {boolean} [isOnFail=false] - Indicates if the signal should be marked as "on fail".
1031
+ * @param {...string} signals - The names of the signals to attach.
1032
1032
  * @return {void} This method does not return a value.
1033
1033
  */
1034
- attachSignal(signal: string, isOnFail?: boolean): void;
1034
+ attachSignal(...signals: string[]): Task;
1035
1035
  /**
1036
1036
  * Unsubscribes the current instance from the specified signals.
1037
1037
  * This method removes the signals from the observedSignals set, unsubscribes
@@ -1358,7 +1358,6 @@ declare class GraphRunner extends SignalEmitter {
1358
1358
  * @edge Creates 'Start run' meta-task chained to registry gets.
1359
1359
  */
1360
1360
  constructor(isMeta?: boolean);
1361
- init(): void;
1362
1361
  /**
1363
1362
  * Adds tasks or routines to the current execution pipeline. Supports both individual tasks,
1364
1363
  * routines, or arrays of tasks and routines. Handles metadata and execution context management.
@@ -1405,7 +1404,6 @@ declare class GraphRunner extends SignalEmitter {
1405
1404
  * @return {void}
1406
1405
  */
1407
1406
  setStrategy(strategy: GraphRunStrategy): void;
1408
- startRun(context: AnyObject, emit: (signal: string, ctx: AnyObject) => void): boolean;
1409
1407
  }
1410
1408
 
1411
1409
  /**
@@ -1440,6 +1438,7 @@ declare class SignalBroker {
1440
1438
  tasks: Set<Task | GraphRoutine>;
1441
1439
  registered: boolean;
1442
1440
  }>;
1441
+ emittedSignalsRegistry: Set<string>;
1443
1442
  emitStacks: Map<string, Map<string, AnyObject>>;
1444
1443
  constructor();
1445
1444
  /**
@@ -1461,6 +1460,7 @@ declare class SignalBroker {
1461
1460
  * @edge Duplicates ignored; supports wildcards for broad listening.
1462
1461
  */
1463
1462
  observe(signal: string, routineOrTask: Task | GraphRoutine): void;
1463
+ registerEmittedSignal(signal: string): void;
1464
1464
  /**
1465
1465
  * Unsubscribes a routine/task from a signal.
1466
1466
  * @param signal The signal.
@@ -1534,6 +1534,7 @@ declare class SignalBroker {
1534
1534
  * @returns Array of signals.
1535
1535
  */
1536
1536
  listObservedSignals(): string[];
1537
+ listEmittedSignals(): string[];
1537
1538
  reset(): void;
1538
1539
  }
1539
1540
 
package/dist/index.d.ts CHANGED
@@ -1000,6 +1000,7 @@ declare class Task extends SignalEmitter implements Graph {
1000
1000
  * @return {any[]} An array containing the results of applying the callback function to each predecessor task.
1001
1001
  */
1002
1002
  mapPrevious(callback: (task: Task) => any): any[];
1003
+ makeRoutine(name: string, description: string): this;
1003
1004
  /**
1004
1005
  * Adds the specified signals to the current instance, making it observe them.
1005
1006
  * If the instance is already observing a signal, it will be skipped.
@@ -1027,11 +1028,10 @@ declare class Task extends SignalEmitter implements Graph {
1027
1028
  /**
1028
1029
  * Attaches a signal to the current context and emits metadata if the register flag is set.
1029
1030
  *
1030
- * @param {string} signal - The name of the signal to attach.
1031
- * @param {boolean} [isOnFail=false] - Indicates if the signal should be marked as "on fail".
1031
+ * @param {...string} signals - The names of the signals to attach.
1032
1032
  * @return {void} This method does not return a value.
1033
1033
  */
1034
- attachSignal(signal: string, isOnFail?: boolean): void;
1034
+ attachSignal(...signals: string[]): Task;
1035
1035
  /**
1036
1036
  * Unsubscribes the current instance from the specified signals.
1037
1037
  * This method removes the signals from the observedSignals set, unsubscribes
@@ -1358,7 +1358,6 @@ declare class GraphRunner extends SignalEmitter {
1358
1358
  * @edge Creates 'Start run' meta-task chained to registry gets.
1359
1359
  */
1360
1360
  constructor(isMeta?: boolean);
1361
- init(): void;
1362
1361
  /**
1363
1362
  * Adds tasks or routines to the current execution pipeline. Supports both individual tasks,
1364
1363
  * routines, or arrays of tasks and routines. Handles metadata and execution context management.
@@ -1405,7 +1404,6 @@ declare class GraphRunner extends SignalEmitter {
1405
1404
  * @return {void}
1406
1405
  */
1407
1406
  setStrategy(strategy: GraphRunStrategy): void;
1408
- startRun(context: AnyObject, emit: (signal: string, ctx: AnyObject) => void): boolean;
1409
1407
  }
1410
1408
 
1411
1409
  /**
@@ -1440,6 +1438,7 @@ declare class SignalBroker {
1440
1438
  tasks: Set<Task | GraphRoutine>;
1441
1439
  registered: boolean;
1442
1440
  }>;
1441
+ emittedSignalsRegistry: Set<string>;
1443
1442
  emitStacks: Map<string, Map<string, AnyObject>>;
1444
1443
  constructor();
1445
1444
  /**
@@ -1461,6 +1460,7 @@ declare class SignalBroker {
1461
1460
  * @edge Duplicates ignored; supports wildcards for broad listening.
1462
1461
  */
1463
1462
  observe(signal: string, routineOrTask: Task | GraphRoutine): void;
1463
+ registerEmittedSignal(signal: string): void;
1464
1464
  /**
1465
1465
  * Unsubscribes a routine/task from a signal.
1466
1466
  * @param signal The signal.
@@ -1534,6 +1534,7 @@ declare class SignalBroker {
1534
1534
  * @returns Array of signals.
1535
1535
  */
1536
1536
  listObservedSignals(): string[];
1537
+ listEmittedSignals(): string[];
1537
1538
  reset(): void;
1538
1539
  }
1539
1540
 
package/dist/index.js CHANGED
@@ -302,6 +302,7 @@ var SignalBroker = class _SignalBroker {
302
302
  this.debouncedEmitters = /* @__PURE__ */ new Map();
303
303
  // TODO: Signals should be a class with a the observers, registered flag and other data.
304
304
  this.signalObservers = /* @__PURE__ */ new Map();
305
+ this.emittedSignalsRegistry = /* @__PURE__ */ new Set();
305
306
  this.emitStacks = /* @__PURE__ */ new Map();
306
307
  this.addSignal("meta.signal_broker.added");
307
308
  }
@@ -408,6 +409,9 @@ var SignalBroker = class _SignalBroker {
408
409
  this.addSignal(signal);
409
410
  this.signalObservers.get(signal).tasks.add(routineOrTask);
410
411
  }
412
+ registerEmittedSignal(signal) {
413
+ this.emittedSignalsRegistry.add(signal);
414
+ }
411
415
  /**
412
416
  * Unsubscribes a routine/task from a signal.
413
417
  * @param signal The signal.
@@ -683,14 +687,18 @@ var SignalBroker = class _SignalBroker {
683
687
  listObservedSignals() {
684
688
  return Array.from(this.signalObservers.keys());
685
689
  }
690
+ listEmittedSignals() {
691
+ return Array.from(this.emittedSignalsRegistry);
692
+ }
686
693
  reset() {
687
694
  this.emitStacks.clear();
688
695
  this.signalObservers.clear();
696
+ this.emittedSignalsRegistry.clear();
689
697
  }
690
698
  };
691
699
 
692
700
  // src/engine/GraphRunner.ts
693
- var import_uuid6 = require("uuid");
701
+ var import_uuid5 = require("uuid");
694
702
 
695
703
  // src/engine/GraphRun.ts
696
704
  var import_uuid2 = require("uuid");
@@ -2195,8 +2203,178 @@ var GraphRoutine = class extends SignalEmitter {
2195
2203
  }
2196
2204
  };
2197
2205
 
2206
+ // src/engine/GraphRunner.ts
2207
+ var GraphRunner = class extends SignalEmitter {
2208
+ /**
2209
+ * Constructs a runner.
2210
+ * @param isMeta Meta flag (default false).
2211
+ * @edge Creates 'Start run' meta-task chained to registry gets.
2212
+ */
2213
+ constructor(isMeta = false) {
2214
+ super(isMeta);
2215
+ this.debug = false;
2216
+ this.verbose = false;
2217
+ this.isRunning = false;
2218
+ this.isMeta = false;
2219
+ this.isMeta = isMeta;
2220
+ this.strategy = Cadenza.runStrategy.PARALLEL;
2221
+ this.currentRun = new GraphRun(this.strategy);
2222
+ }
2223
+ /**
2224
+ * Adds tasks or routines to the current execution pipeline. Supports both individual tasks,
2225
+ * routines, or arrays of tasks and routines. Handles metadata and execution context management.
2226
+ *
2227
+ * @param {Task|GraphRoutine|(Task|GraphRoutine)[]} tasks - The task(s) or routine(s) to be added.
2228
+ * It can be a single task, a single routine, or an array of tasks and routines.
2229
+ * @param {AnyObject} [context={}] - Optional context object to provide execution trace and metadata.
2230
+ * Used to propagate information across task or routine executions.
2231
+ * @return {void} - This method does not return a value.
2232
+ */
2233
+ addTasks(tasks, context = {}) {
2234
+ let _tasks = Array.isArray(tasks) ? tasks : [tasks];
2235
+ if (_tasks.length === 0) {
2236
+ console.warn("No tasks/routines to add.");
2237
+ return;
2238
+ }
2239
+ let routineName = _tasks.map((t) => t.name).join(" | ");
2240
+ let routineVersion = null;
2241
+ let isMeta = _tasks.every((t) => t.isMeta);
2242
+ const allTasks = _tasks.flatMap((t) => {
2243
+ if (t instanceof GraphRoutine) {
2244
+ routineName = t.name;
2245
+ routineVersion = t.version;
2246
+ isMeta = t.isMeta;
2247
+ const routineTasks = [];
2248
+ t.forEachTask((task) => routineTasks.push(task));
2249
+ return routineTasks;
2250
+ }
2251
+ return t;
2252
+ });
2253
+ const isSubMeta = allTasks.some((t) => t.isSubMeta) || !!context.__isSubMeta;
2254
+ context.__isSubMeta = isSubMeta;
2255
+ const isNewTrace = !context.__routineExecId && !context.__metadata?.__executionTraceId && !context.__executionTraceId;
2256
+ const executionTraceId = context.__metadata?.__executionTraceId ?? context.__executionTraceId ?? (0, import_uuid5.v4)();
2257
+ context.__executionTraceId = executionTraceId;
2258
+ const routineExecId = context.__routineExecId ?? (0, import_uuid5.v4)();
2259
+ context.__routineExecId = routineExecId;
2260
+ const ctx = new GraphContext(context || {});
2261
+ if (!isSubMeta) {
2262
+ const contextData = ctx.export();
2263
+ if (isNewTrace) {
2264
+ this.emitMetrics("meta.runner.new_trace", {
2265
+ data: {
2266
+ uuid: executionTraceId,
2267
+ issuer_type: "service",
2268
+ // TODO: Add issuer type
2269
+ issuer_id: context.__metadata?.__issuerId ?? context.__issuerId ?? null,
2270
+ issued_at: formatTimestamp(Date.now()),
2271
+ intent: context.__metadata?.__intent ?? context.__intent ?? null,
2272
+ context: contextData,
2273
+ is_meta: isMeta
2274
+ },
2275
+ __metadata: {
2276
+ __executionTraceId: executionTraceId
2277
+ }
2278
+ });
2279
+ }
2280
+ this.emitMetrics("meta.runner.added_tasks", {
2281
+ data: {
2282
+ uuid: routineExecId,
2283
+ name: routineName,
2284
+ routineVersion,
2285
+ isMeta,
2286
+ executionTraceId,
2287
+ context: isNewTrace ? contextData.id : contextData,
2288
+ previousRoutineExecution: context.__localRoutineExecId ?? context.__metadata?.__routineExecId ?? null,
2289
+ created: formatTimestamp(Date.now())
2290
+ },
2291
+ __metadata: {
2292
+ __executionTraceId: executionTraceId
2293
+ }
2294
+ });
2295
+ }
2296
+ allTasks.forEach(
2297
+ (task) => this.currentRun.addNode(
2298
+ new GraphNode(task, ctx, routineExecId, [], this.debug, this.verbose)
2299
+ )
2300
+ );
2301
+ }
2302
+ /**
2303
+ * Executes the provided tasks or routines. Maintains the execution state
2304
+ * and handles synchronous or asynchronous processing.
2305
+ *
2306
+ * @param {Task|GraphRoutine|(Task|GraphRoutine)[]} [tasks] - A single task, a single routine, or an array of tasks or routines to execute. Optional.
2307
+ * @param {AnyObject} [context] - An optional context object to be used during task execution.
2308
+ * @return {GraphRun|Promise<GraphRun>} - Returns a `GraphRun` instance if the execution is synchronous, or a `Promise` resolving to a `GraphRun` for asynchronous execution.
2309
+ */
2310
+ run(tasks, context) {
2311
+ if (tasks) {
2312
+ this.addTasks(tasks, context ?? {});
2313
+ }
2314
+ if (this.isRunning) {
2315
+ return this.currentRun;
2316
+ }
2317
+ if (this.currentRun) {
2318
+ this.isRunning = true;
2319
+ const runResult = this.currentRun.run();
2320
+ if (runResult instanceof Promise) {
2321
+ return this.runAsync(runResult);
2322
+ }
2323
+ }
2324
+ return this.reset();
2325
+ }
2326
+ /**
2327
+ * Executes the provided asynchronous operation and resets the state afterwards.
2328
+ *
2329
+ * @param {Promise<void>} run - A promise representing the asynchronous operation to execute.
2330
+ * @return {Promise<GraphRun>} A promise that resolves to the result of the reset operation after the asynchronous operation completes.
2331
+ */
2332
+ async runAsync(run) {
2333
+ await run;
2334
+ return this.reset();
2335
+ }
2336
+ /**
2337
+ * Resets the current state of the graph, creating a new GraphRun instance
2338
+ * and returning the previous run instance.
2339
+ * If the debug mode is not enabled, it will destroy the existing resources.
2340
+ *
2341
+ * @return {GraphRun} The last GraphRun instance before the reset.
2342
+ */
2343
+ reset() {
2344
+ this.isRunning = false;
2345
+ const lastRun = this.currentRun;
2346
+ if (!this.debug) {
2347
+ this.destroy();
2348
+ }
2349
+ this.currentRun = new GraphRun(this.strategy);
2350
+ return lastRun;
2351
+ }
2352
+ setDebug(value) {
2353
+ this.debug = value;
2354
+ }
2355
+ setVerbose(value) {
2356
+ this.verbose = value;
2357
+ }
2358
+ destroy() {
2359
+ this.currentRun.destroy();
2360
+ }
2361
+ /**
2362
+ * Sets the strategy to be used for running the graph and initializes
2363
+ * the current run with the provided strategy if no process is currently running.
2364
+ *
2365
+ * @param {GraphRunStrategy} strategy - The strategy to use for running the graph.
2366
+ * @return {void}
2367
+ */
2368
+ setStrategy(strategy) {
2369
+ this.strategy = strategy;
2370
+ if (!this.isRunning) {
2371
+ this.currentRun = new GraphRun(this.strategy);
2372
+ }
2373
+ }
2374
+ };
2375
+
2198
2376
  // src/graph/definition/Task.ts
2199
- var import_uuid5 = require("uuid");
2377
+ var import_uuid6 = require("uuid");
2200
2378
 
2201
2379
  // src/graph/iterators/TaskIterator.ts
2202
2380
  var TaskIterator = class {
@@ -2345,7 +2523,7 @@ var Task = class _Task extends SignalEmitter {
2345
2523
  }
2346
2524
  clone(traverse = false, includeSignals = false) {
2347
2525
  const clonedTask = new _Task(
2348
- `${this.name} (clone ${(0, import_uuid5.v4)().slice(0, 8)})`,
2526
+ `${this.name} (clone ${(0, import_uuid6.v4)().slice(0, 8)})`,
2349
2527
  this.taskFunction,
2350
2528
  this.description,
2351
2529
  this.concurrency,
@@ -2830,6 +3008,14 @@ var Task = class _Task extends SignalEmitter {
2830
3008
  mapPrevious(callback) {
2831
3009
  return Array.from(this.predecessorTasks).map(callback);
2832
3010
  }
3011
+ makeRoutine(name, description) {
3012
+ if (this.isMeta) {
3013
+ Cadenza.createMetaRoutine(name, [this], description);
3014
+ } else {
3015
+ Cadenza.createRoutine(name, [this], description);
3016
+ }
3017
+ return this;
3018
+ }
2833
3019
  /**
2834
3020
  * Adds the specified signals to the current instance, making it observe them.
2835
3021
  * If the instance is already observing a signal, it will be skipped.
@@ -2886,29 +3072,33 @@ var Task = class _Task extends SignalEmitter {
2886
3072
  emitsOnFail(...signals) {
2887
3073
  signals.forEach((signal) => {
2888
3074
  this.signalsToEmitOnFail.add(signal);
2889
- this.attachSignal(signal, true);
3075
+ this.attachSignal(signal);
2890
3076
  });
2891
3077
  return this;
2892
3078
  }
2893
3079
  /**
2894
3080
  * Attaches a signal to the current context and emits metadata if the register flag is set.
2895
3081
  *
2896
- * @param {string} signal - The name of the signal to attach.
2897
- * @param {boolean} [isOnFail=false] - Indicates if the signal should be marked as "on fail".
3082
+ * @param {...string} signals - The names of the signals to attach.
2898
3083
  * @return {void} This method does not return a value.
2899
3084
  */
2900
- attachSignal(signal, isOnFail = false) {
2901
- this.emitsSignals.add(signal);
2902
- if (this.register) {
2903
- this.emitWithMetadata("meta.task.attached_signal", {
2904
- data: {
2905
- signalName: signal.split(":")[0],
2906
- taskName: this.name,
2907
- taskVersion: this.version,
2908
- isOnFail
2909
- }
2910
- });
2911
- }
3085
+ attachSignal(...signals) {
3086
+ signals.forEach((signal) => {
3087
+ this.emitsSignals.add(signal);
3088
+ Cadenza.broker.registerEmittedSignal(signal);
3089
+ if (this.register) {
3090
+ const isOnFail = this.signalsToEmitOnFail.has(signal);
3091
+ this.emitWithMetadata("meta.task.attached_signal", {
3092
+ data: {
3093
+ signalName: signal.split(":")[0],
3094
+ taskName: this.name,
3095
+ taskVersion: this.version,
3096
+ isOnFail
3097
+ }
3098
+ });
3099
+ }
3100
+ });
3101
+ return this;
2912
3102
  }
2913
3103
  /**
2914
3104
  * Unsubscribes the current instance from the specified signals.
@@ -3288,205 +3478,6 @@ var GraphRegistry = class _GraphRegistry {
3288
3478
  }
3289
3479
  };
3290
3480
 
3291
- // src/engine/GraphRunner.ts
3292
- var GraphRunner = class extends SignalEmitter {
3293
- /**
3294
- * Constructs a runner.
3295
- * @param isMeta Meta flag (default false).
3296
- * @edge Creates 'Start run' meta-task chained to registry gets.
3297
- */
3298
- constructor(isMeta = false) {
3299
- super(isMeta);
3300
- this.debug = false;
3301
- this.verbose = false;
3302
- this.isRunning = false;
3303
- this.isMeta = false;
3304
- this.isMeta = isMeta;
3305
- this.strategy = Cadenza.runStrategy.PARALLEL;
3306
- this.currentRun = new GraphRun(this.strategy);
3307
- }
3308
- init() {
3309
- if (this.isMeta) return;
3310
- Cadenza.createMetaTask(
3311
- "Start run",
3312
- this.startRun.bind(this),
3313
- "Starts a run"
3314
- ).doAfter(
3315
- GraphRegistry.instance.getTaskByName,
3316
- GraphRegistry.instance.getRoutineByName
3317
- );
3318
- }
3319
- /**
3320
- * Adds tasks or routines to the current execution pipeline. Supports both individual tasks,
3321
- * routines, or arrays of tasks and routines. Handles metadata and execution context management.
3322
- *
3323
- * @param {Task|GraphRoutine|(Task|GraphRoutine)[]} tasks - The task(s) or routine(s) to be added.
3324
- * It can be a single task, a single routine, or an array of tasks and routines.
3325
- * @param {AnyObject} [context={}] - Optional context object to provide execution trace and metadata.
3326
- * Used to propagate information across task or routine executions.
3327
- * @return {void} - This method does not return a value.
3328
- */
3329
- addTasks(tasks, context = {}) {
3330
- let _tasks = Array.isArray(tasks) ? tasks : [tasks];
3331
- if (_tasks.length === 0) {
3332
- console.warn("No tasks/routines to add.");
3333
- return;
3334
- }
3335
- let routineName = _tasks.map((t) => t.name).join(" | ");
3336
- let routineVersion = null;
3337
- let isMeta = _tasks.every((t) => t.isMeta);
3338
- const allTasks = _tasks.flatMap((t) => {
3339
- if (t instanceof GraphRoutine) {
3340
- routineName = t.name;
3341
- routineVersion = t.version;
3342
- isMeta = t.isMeta;
3343
- const routineTasks = [];
3344
- t.forEachTask((task) => routineTasks.push(task));
3345
- return routineTasks;
3346
- }
3347
- return t;
3348
- });
3349
- const isSubMeta = allTasks.some((t) => t.isSubMeta) || !!context.__isSubMeta;
3350
- context.__isSubMeta = isSubMeta;
3351
- const isNewTrace = !context.__routineExecId && !context.__metadata?.__executionTraceId && !context.__executionTraceId;
3352
- const executionTraceId = context.__metadata?.__executionTraceId ?? context.__executionTraceId ?? (0, import_uuid6.v4)();
3353
- context.__executionTraceId = executionTraceId;
3354
- const routineExecId = context.__routineExecId ?? (0, import_uuid6.v4)();
3355
- context.__routineExecId = routineExecId;
3356
- const ctx = new GraphContext(context || {});
3357
- if (!isSubMeta) {
3358
- const contextData = ctx.export();
3359
- if (isNewTrace) {
3360
- this.emitMetrics("meta.runner.new_trace", {
3361
- data: {
3362
- uuid: executionTraceId,
3363
- issuer_type: "service",
3364
- // TODO: Add issuer type
3365
- issuer_id: context.__metadata?.__issuerId ?? context.__issuerId ?? null,
3366
- issued_at: formatTimestamp(Date.now()),
3367
- intent: context.__metadata?.__intent ?? context.__intent ?? null,
3368
- context: contextData,
3369
- is_meta: isMeta
3370
- },
3371
- __metadata: {
3372
- __executionTraceId: executionTraceId
3373
- }
3374
- });
3375
- }
3376
- this.emitMetrics("meta.runner.added_tasks", {
3377
- data: {
3378
- uuid: routineExecId,
3379
- name: routineName,
3380
- routineVersion,
3381
- isMeta,
3382
- executionTraceId,
3383
- context: isNewTrace ? contextData.id : contextData,
3384
- previousRoutineExecution: context.__localRoutineExecId ?? context.__metadata?.__routineExecId ?? null,
3385
- // TODO: There is a chance this is not added to the database yet...
3386
- created: formatTimestamp(Date.now())
3387
- },
3388
- __metadata: {
3389
- __executionTraceId: executionTraceId
3390
- }
3391
- });
3392
- }
3393
- allTasks.forEach(
3394
- (task) => this.currentRun.addNode(
3395
- new GraphNode(task, ctx, routineExecId, [], this.debug, this.verbose)
3396
- )
3397
- );
3398
- }
3399
- /**
3400
- * Executes the provided tasks or routines. Maintains the execution state
3401
- * and handles synchronous or asynchronous processing.
3402
- *
3403
- * @param {Task|GraphRoutine|(Task|GraphRoutine)[]} [tasks] - A single task, a single routine, or an array of tasks or routines to execute. Optional.
3404
- * @param {AnyObject} [context] - An optional context object to be used during task execution.
3405
- * @return {GraphRun|Promise<GraphRun>} - Returns a `GraphRun` instance if the execution is synchronous, or a `Promise` resolving to a `GraphRun` for asynchronous execution.
3406
- */
3407
- run(tasks, context) {
3408
- if (tasks) {
3409
- this.addTasks(tasks, context ?? {});
3410
- }
3411
- if (this.isRunning) {
3412
- return this.currentRun;
3413
- }
3414
- if (this.currentRun) {
3415
- this.isRunning = true;
3416
- const runResult = this.currentRun.run();
3417
- if (runResult instanceof Promise) {
3418
- return this.runAsync(runResult);
3419
- }
3420
- }
3421
- return this.reset();
3422
- }
3423
- /**
3424
- * Executes the provided asynchronous operation and resets the state afterwards.
3425
- *
3426
- * @param {Promise<void>} run - A promise representing the asynchronous operation to execute.
3427
- * @return {Promise<GraphRun>} A promise that resolves to the result of the reset operation after the asynchronous operation completes.
3428
- */
3429
- async runAsync(run) {
3430
- await run;
3431
- return this.reset();
3432
- }
3433
- /**
3434
- * Resets the current state of the graph, creating a new GraphRun instance
3435
- * and returning the previous run instance.
3436
- * If the debug mode is not enabled, it will destroy the existing resources.
3437
- *
3438
- * @return {GraphRun} The last GraphRun instance before the reset.
3439
- */
3440
- reset() {
3441
- this.isRunning = false;
3442
- const lastRun = this.currentRun;
3443
- if (!this.debug) {
3444
- this.destroy();
3445
- }
3446
- this.currentRun = new GraphRun(this.strategy);
3447
- return lastRun;
3448
- }
3449
- setDebug(value) {
3450
- this.debug = value;
3451
- }
3452
- setVerbose(value) {
3453
- this.verbose = value;
3454
- }
3455
- destroy() {
3456
- this.currentRun.destroy();
3457
- }
3458
- /**
3459
- * Sets the strategy to be used for running the graph and initializes
3460
- * the current run with the provided strategy if no process is currently running.
3461
- *
3462
- * @param {GraphRunStrategy} strategy - The strategy to use for running the graph.
3463
- * @return {void}
3464
- */
3465
- setStrategy(strategy) {
3466
- this.strategy = strategy;
3467
- if (!this.isRunning) {
3468
- this.currentRun = new GraphRun(this.strategy);
3469
- }
3470
- }
3471
- // TODO This should not live here. This is deputy related.
3472
- startRun(context, emit) {
3473
- if (context.task || context.routine) {
3474
- const routine = context.task ?? context.routine;
3475
- delete context.task;
3476
- delete context.routine;
3477
- context.__routineExecId = context.__metadata?.__deputyExecId ?? null;
3478
- context.__isDeputy = true;
3479
- this.run(routine, context);
3480
- return true;
3481
- } else {
3482
- context.errored = true;
3483
- context.__error = "No routine or task defined.";
3484
- emit("meta.runner.failed", context);
3485
- return false;
3486
- }
3487
- }
3488
- };
3489
-
3490
3481
  // src/graph/definition/DebounceTask.ts
3491
3482
  var DebounceTask = class extends Task {
3492
3483
  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) {
@@ -4445,8 +4436,6 @@ var Cadenza = class {
4445
4436
  }
4446
4437
  this.registry = GraphRegistry.instance;
4447
4438
  this.broker.init();
4448
- this.runner.init();
4449
- this.metaRunner.init();
4450
4439
  }
4451
4440
  /**
4452
4441
  * Retrieves the available strategies for running graphs.