@cadenza.io/core 3.27.0 → 3.28.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.ts CHANGED
@@ -130,33 +130,6 @@ declare class GraphNodeIterator implements Iterator {
130
130
  next(): any;
131
131
  }
132
132
 
133
- /**
134
- * Abstract class representing a signal emitter.
135
- * Allows emitting events or signals, with the option to suppress emissions if desired.
136
- */
137
- declare abstract class SignalEmitter {
138
- silent: boolean;
139
- /**
140
- * Constructor for signal emitters.
141
- * @param silent If true, suppresses all emissions (e.g., for meta-runners to avoid loops; affects all emits).
142
- */
143
- constructor(silent?: boolean);
144
- /**
145
- * Emits a signal via the broker.
146
- * @param signal The signal name.
147
- * @param data Optional payload (defaults to empty object).
148
- * @param options
149
- */
150
- emit(signal: string, data?: AnyObject, options?: EmitOptions): void;
151
- /**
152
- * Emits a signal via the broker if not silent.
153
- * @param signal The signal name.
154
- * @param data Optional payload (defaults to empty object).
155
- * @param options
156
- */
157
- emitMetrics(signal: string, data?: AnyObject, options?: EmitOptions): void;
158
- }
159
-
160
133
  /**
161
134
  * Represents an abstract chain of execution, where each instance can be
162
135
  * connected to a succeeding or preceding instance to form a chain of steps.
@@ -319,1350 +292,1427 @@ declare abstract class GraphLayer extends ExecutionChain implements Graph {
319
292
  log(): void;
320
293
  }
321
294
 
322
- type SchemaType = "string" | "number" | "boolean" | "array" | "object" | "any";
323
- type SchemaConstraints = {
324
- min?: number;
325
- max?: number;
326
- minLength?: number;
327
- maxLength?: number;
328
- pattern?: string;
329
- enum?: any[];
330
- multipleOf?: number;
331
- format?: "email" | "url" | "date-time" | "uuid" | "custom";
332
- oneOf?: any[];
333
- };
334
- type SchemaDefinition = {
335
- type: SchemaType;
336
- required?: string[];
337
- properties?: {
338
- [key: string]: Schema;
339
- };
340
- items?: Schema;
341
- constraints?: SchemaConstraints;
342
- description?: string;
343
- strict?: boolean;
344
- };
345
- type SchemaMap = Record<string, SchemaDefinition>;
346
- type Schema = SchemaDefinition | SchemaMap;
347
-
348
- interface Intent {
349
- name: string;
350
- description?: string;
351
- input?: SchemaDefinition;
352
- output?: SchemaDefinition;
353
- }
354
- interface InquiryOptions {
355
- timeout?: number;
356
- rejectOnTimeout?: boolean;
357
- includePendingTasks?: boolean;
358
- requireComplete?: boolean;
359
- }
360
- declare class InquiryBroker extends SignalEmitter {
361
- static instance_: InquiryBroker;
362
- static get instance(): InquiryBroker;
363
- debug: boolean;
364
- verbose: boolean;
365
- setDebug(value: boolean): void;
366
- setVerbose(value: boolean): void;
367
- validateInquiryName(inquiryName: string): void;
368
- runner: GraphRunner | undefined;
369
- metaRunner: GraphRunner | undefined;
370
- inquiryObservers: Map<string, {
371
- fn: (runner: GraphRunner, tasks: Task[], context: AnyObject) => void;
372
- tasks: Set<Task>;
373
- registered: boolean;
374
- }>;
375
- intents: Map<string, Intent>;
376
- /**
377
- * Initializes with runners.
378
- * @param runner Standard runner for user signals.
379
- * @param metaRunner Meta runner for 'meta.' signals (suppresses further meta-emits).
380
- */
381
- bootstrap(runner: GraphRunner, metaRunner: GraphRunner): void;
382
- init(): void;
383
- /**
384
- * Observes an inquiry with a routine/task.
385
- * @param inquiry The inquiry (e.g., 'domain.action', 'domain.*' for wildcards).
386
- * @param task The observer.
387
- * @edge Duplicates ignored; supports wildcards for broad listening.
388
- */
389
- observe(inquiry: string, task: Task): void;
295
+ /**
296
+ * Represents a synchronous graph layer derived from the GraphLayer base class.
297
+ * This class is designed to execute graph nodes in a strictly synchronous manner.
298
+ * Asynchronous functions are explicitly disallowed, ensuring consistency and predictability.
299
+ */
300
+ declare class SyncGraphLayer extends GraphLayer {
390
301
  /**
391
- * Unsubscribes a routine/task from an inquiry.
392
- * @param inquiry The inquiry.
393
- * @param task The observer.
394
- * @edge Removes all instances if duplicate; deletes if empty.
302
+ * Executes the processing logic of the current set of graph nodes. Iterates through all
303
+ * nodes, skipping any that have already been processed, and executes their respective
304
+ * logic to generate new nodes. Asynchronous functions are not supported and will
305
+ * trigger an error log.
306
+ *
307
+ * @return {GraphNode[]} An array of newly generated graph nodes after executing the logic of each unprocessed node.
395
308
  */
396
- unsubscribe(inquiry: string, task: Task): void;
397
- addInquiry(inquiry: string): void;
398
- addIntent(intent: Intent): void;
399
- inquire(inquiry: string, context: AnyObject, options?: InquiryOptions): Promise<AnyObject>;
400
- reset(): void;
309
+ execute(): GraphNode[];
401
310
  }
402
311
 
403
312
  /**
404
- * Represents a node in a graph structure used for executing tasks.
405
- * A Node is a container for a task and its associated context, providing
406
- * methods for executing the task and managing its lifecycle.
407
- *
408
- * It extends the SignalEmitter class to emit and handle signals related to
409
- * the node's lifecycle, such as "meta.node.started" and "meta.node.completed".
410
- *
411
- * It also implements the Graph interface, allowing it to be used as a part of
412
- * a graph structure, such as a GraphLayer or GraphRoutine.
313
+ * An abstract class representing a GraphExporter.
314
+ * This class defines a structure for exporting graph data in different formats,
315
+ * depending on the implementations provided by subclasses.
316
+ */
317
+ declare abstract class GraphExporter {
318
+ abstract exportGraph(graph: SyncGraphLayer): any;
319
+ abstract exportStaticGraph(graph: Task[]): any;
320
+ }
321
+
322
+ /**
323
+ * GraphBuilder is an abstract base class designed to construct and manage a graph structure
324
+ * composed of multiple layers. Subclasses are expected to implement the `compose` method
325
+ * based on specific requirements. This class provides methods for adding nodes, managing
326
+ * layers, and resetting the graph construction process.
413
327
  *
414
- * @extends SignalEmitter
415
- * @implements Graph
328
+ * This class supports creating layered graph structures, dynamically adding layers and nodes,
329
+ * and debugging graph-building operations.
416
330
  */
417
- declare class GraphNode extends SignalEmitter implements Graph {
418
- id: string;
419
- routineExecId: string;
420
- executionTraceId: string;
421
- task: Task;
422
- context: GraphContext;
423
- layer: GraphLayer | undefined;
424
- divided: boolean;
425
- splitGroupId: string;
426
- processing: boolean;
427
- subgraphComplete: boolean;
428
- graphComplete: boolean;
429
- result: TaskResult;
430
- retryCount: number;
431
- retryDelay: number;
432
- retries: number;
433
- previousNodes: GraphNode[];
434
- nextNodes: GraphNode[];
435
- executionTime: number;
436
- executionStart: number;
437
- failed: boolean;
438
- errored: boolean;
439
- destroyed: boolean;
331
+ declare abstract class GraphBuilder {
332
+ graph: GraphLayer | undefined;
333
+ topLayerIndex: number;
334
+ layers: GraphLayer[];
440
335
  debug: boolean;
441
- verbose: boolean;
442
- constructor(task: Task, context: GraphContext, routineExecId: string, prevNodes?: GraphNode[], debug?: boolean, verbose?: boolean);
443
336
  setDebug(value: boolean): void;
444
- isUnique(): boolean;
445
- isMeta(): boolean;
446
- isProcessed(): boolean;
447
- isProcessing(): boolean;
448
- subgraphDone(): boolean;
449
- graphDone(): boolean;
450
- /**
451
- * Compares the current GraphNode instance with another GraphNode to determine if they are considered equal.
452
- *
453
- * @param {GraphNode} node - The GraphNode object to compare with the current instance.
454
- * @return {boolean} Returns true if the nodes share the same task, context, and belong to the same graph; otherwise, false.
455
- */
456
- isEqualTo(node: GraphNode): boolean;
337
+ getResult(): GraphLayer;
457
338
  /**
458
- * Determines if the given node is part of the same graph as the current node.
339
+ * Composes a series of functions or operations.
340
+ * This method should be implemented in the child class
341
+ * to define custom composition logic.
459
342
  *
460
- * @param {GraphNode} node - The node to compare with the current node.
461
- * @return {boolean} Returns true if the provided node is part of the same graph
462
- * (i.e., has the same routineExecId), otherwise false.
343
+ * @return {any} The result of the composed operations or functions
344
+ * when implemented in the child class.
463
345
  */
464
- isPartOfSameGraph(node: GraphNode): boolean;
346
+ compose(): void;
465
347
  /**
466
- * Determines whether the current instance shares a task with the provided node.
348
+ * Adds a node to the appropriate layer of the graph.
467
349
  *
468
- * @param {GraphNode} node - The graph node to compare with the current instance.
469
- * @return {boolean} Returns true if the task names of both nodes match, otherwise false.
350
+ * @param {GraphNode} node - The node to be added to the graph. The node contains
351
+ * layer information that determines which layer it belongs to.
352
+ * @return {void} Does not return a value.
470
353
  */
471
- sharesTaskWith(node: GraphNode): boolean;
354
+ addNode(node: GraphNode): void;
472
355
  /**
473
- * Determines whether the current node shares the same context as the specified node.
356
+ * Adds multiple nodes to the graph.
474
357
  *
475
- * @param {GraphNode} node - The graph node to compare with the current node's context.
476
- * @return {boolean} True if both nodes share the same context; otherwise, false.
358
+ * @param {GraphNode[]} nodes - An array of nodes to be added to the graph.
359
+ * @return {void} This method does not return a value.
477
360
  */
478
- sharesContextWith(node: GraphNode): boolean;
479
- getLayerIndex(): number;
480
- getConcurrency(): number;
361
+ addNodes(nodes: GraphNode[]): void;
481
362
  /**
482
- * Retrieves the tag associated with the current task and context.
363
+ * Adds a new layer to the graph at the specified index. If the graph does not exist,
364
+ * it creates the graph using the specified index. Updates the graph's top layer index
365
+ * and maintains the order of layers.
483
366
  *
484
- * @return {string} The tag retrieved from the task within the given context.
367
+ * @param {number} index - The index at which the new layer should be added to the graph.
368
+ * @return {void} This method does not return a value.
485
369
  */
486
- getTag(): string;
370
+ addLayer(index: number): void;
487
371
  /**
488
- * Schedules the current node/task on the specified graph layer if applicable.
489
- *
490
- * This method assesses whether the current node/task should be scheduled
491
- * on the given graph layer. It ensures that tasks are only scheduled
492
- * under certain conditions, such as checking if the task shares
493
- * execution contexts or dependencies with other nodes, and handles
494
- * various metadata emissions and context updates during the scheduling process.
372
+ * Creates a new layer for the graph at the specified index.
495
373
  *
496
- * @param {GraphLayer} layer - The graph layer on which the current task should be scheduled.
497
- * @returns {void} Does not return a value.
374
+ * @param {number} index - The index of the layer to be created.
375
+ * @return {GraphLayer} A new instance of the graph layer corresponding to the provided index.
498
376
  */
499
- scheduleOn(layer: GraphLayer): void;
377
+ createLayer(index: number): GraphLayer;
500
378
  /**
501
- * Starts the execution process by initializing the execution start timestamp,
502
- * emitting relevant metadata, and logging debug information if applicable.
503
- *
504
- * The method performs the following actions:
505
- * 1. Sets the execution start timestamp if it's not already initialized.
506
- * 2. Emits metrics with metadata about the routine execution starting, including additional data if there are no previous nodes.
507
- * 3. Optionally logs debug or verbose information based on the current settings.
508
- * 4. Emits additional metrics to indicate that the execution has started.
379
+ * Retrieves a specific layer from the current set of layers.
509
380
  *
510
- * @return {number} The timestamp indicating when the execution started.
381
+ * @param {number} layerIndex - The index of the layer to retrieve.
382
+ * @return {*} The layer corresponding to the given index.
511
383
  */
512
- start(): number;
513
- /**
514
- * Marks the end of an execution process, performs necessary cleanup, emits
515
- * metrics with associated metadata, and signals the completion of execution.
516
- * Also handles specific cases when the graph completes.
517
- *
518
- * @return {number} The timestamp corresponding to the end of execution. If execution
519
- * was not started, it returns 0.
520
- */
521
- end(): number;
522
- /**
523
- * Executes the main logic of the task, including input validation, processing, and post-processing.
524
- * Handles both synchronous and asynchronous workflows.
525
- *
526
- * @return {Array|Promise|undefined} Returns the next nodes to process if available.
527
- * If asynchronous processing is required, it returns a Promise that resolves to the next nodes.
528
- * Returns undefined in case of an error during input validation or preconditions that prevent processing.
529
- */
530
- execute(): GraphNode[] | Promise<GraphNode[]>;
531
- /**
532
- * Executes an asynchronous workflow that processes a result and retries on errors.
533
- * The method handles different result states, checks for error properties, and invokes
534
- * error handling when necessary.
535
- *
536
- * @return {Promise<void>} A promise that resolves when the operation completes successfully,
537
- * or rejects if an unhandled error occurs.
538
- */
539
- workAsync(): Promise<void>;
540
- /**
541
- * Executes an asynchronous operation, processes the result, and determines the next nodes to execute.
542
- * This method will manage asynchronous work, handle post-processing of results, and ensure proper handling of both synchronous and asynchronous next node configurations.
543
- *
544
- * @return {Promise<any>} A promise resolving to the next nodes to be executed. Can be the result of post-processing or a directly resolved next nodes object.
545
- */
546
- executeAsync(): Promise<GraphNode[]>;
384
+ getLayer(layerIndex: number): GraphLayer;
385
+ reset(): void;
386
+ }
387
+
388
+ /**
389
+ * Abstract class representing a strategy for configuring and executing graph operations.
390
+ * Provides a structure for managing graph builders, altering strategies, and updating the execution context.
391
+ *
392
+ * This class cannot be instantiated directly and must be extended by concrete implementations.
393
+ */
394
+ declare abstract class GraphRunStrategy {
395
+ graphBuilder: GraphBuilder;
396
+ runInstance?: GraphRun;
397
+ constructor();
398
+ setRunInstance(runInstance: GraphRun): void;
399
+ changeStrategy(builder: GraphBuilder): void;
400
+ reset(): void;
401
+ addNode(node: GraphNode): void;
402
+ updateRunInstance(): void;
403
+ abstract run(): void;
404
+ abstract export(): any;
405
+ }
406
+
407
+ interface RunJson {
408
+ __id: string;
409
+ __label: string;
410
+ __graph: any;
411
+ __data: any;
412
+ }
413
+ /**
414
+ * Represents a GraphRun instance which manages the execution of a graph-based workflow.
415
+ * It utilizes a specific strategy and export mechanism to manage, execute, and export the graph data.
416
+ */
417
+ declare class GraphRun {
418
+ readonly id: string;
419
+ graph: GraphLayer | undefined;
420
+ strategy: GraphRunStrategy;
421
+ exporter: GraphExporter | undefined;
422
+ constructor(strategy: GraphRunStrategy);
423
+ setGraph(graph: GraphLayer): void;
424
+ addNode(node: GraphNode): void;
425
+ run(): void | Promise<void>;
426
+ destroy(): void;
427
+ log(): void;
428
+ export(): RunJson;
429
+ setExporter(exporter: GraphExporter): void;
430
+ }
431
+
432
+ /**
433
+ * Represents a routine in a graph structure with tasks and signal observation capabilities.
434
+ * Routines are named entrypoint for a sub-graph, describing the purpose for the subsequent flow.
435
+ * Since Task names are specific to the task it performs, it doesn't describe the overall flow.
436
+ * Routines, therefore are used to assign names to sub-flows that can be referenced using that name instead of the name of the task(s).
437
+ * Extends SignalEmitter to emit and handle signals related to the routine's lifecycle and tasks.
438
+ */
439
+ declare class GraphRoutine extends SignalEmitter {
440
+ readonly name: string;
441
+ version: number;
442
+ readonly description: string;
443
+ readonly isMeta: boolean;
444
+ tasks: Set<Task>;
445
+ registered: boolean;
446
+ registeredTasks: Set<Task>;
447
+ observedSignals: Set<string>;
448
+ constructor(name: string, tasks: Task[], description: string, isMeta?: boolean);
547
449
  /**
548
- * Executes the task associated with the current instance, using the given context,
549
- * progress callback, and metadata. If the task fails or an error occurs, it attempts
550
- * to retry the execution. If the retry is not successful, it propagates the error and
551
- * returns the result.
450
+ * Iterates over each task in the `tasks` collection and applies the provided callback function.
451
+ * If the callback returns a Promise, resolves all Promises concurrently.
552
452
  *
553
- * @return {TaskResult | Promise<TaskResult>} The result of the task execution, or a
554
- * promise that resolves to the task result. This includes handling for retries on
555
- * failure and error propagation.
453
+ * @param {function} callBack - A function to be executed on each task from the `tasks` collection.
454
+ * The callback receives the current task as its argument.
455
+ * @return {Promise<void>} A Promise that resolves once all callback executions, including asynchronous ones, are complete.
556
456
  */
557
- work(): TaskResult | Promise<TaskResult>;
558
- inquire(inquiry: string, context: AnyObject, options: InquiryOptions): Promise<any>;
457
+ forEachTask(callBack: (task: Task) => any): Promise<void>;
559
458
  /**
560
- * Emits a signal along with its associated metadata. The metadata includes
561
- * task-specific information such as task name, version, execution ID, and
562
- * additional context metadata like routine execution ID and execution trace ID.
563
- * This method is designed to enrich emitted signals with relevant details
564
- * before broadcasting them.
565
- *
566
- * @param {string} signal - The name of the signal to be emitted.
567
- * @param {AnyObject} data - The data object to be sent along with the signal. Metadata
568
- * will be injected into this object before being emitted.
569
- * @param options
570
- * @return {void} No return value.
459
+ * Sets global Version.
460
+ * @param version The Version.
571
461
  */
572
- emitWithMetadata(signal: string, data: AnyObject, options?: EmitOptions): void;
462
+ setVersion(version: number): void;
573
463
  /**
574
- * Emits metrics with additional metadata describing the task execution and context.
464
+ * Subscribes the current instance to the specified signals, enabling it to observe them.
575
465
  *
576
- * @param {string} signal - The signal name being emitted.
577
- * @param {AnyObject} data - The data associated with the signal emission, enriched with metadata.
578
- * @param options
579
- * @return {void} Emits the signal with enriched data and does not return a value.
466
+ * @param {...string} signals - The names of the signals to observe.
467
+ * @return {this} Returns the instance to allow for method chaining.
580
468
  */
581
- emitMetricsWithMetadata(signal: string, data: AnyObject, options?: EmitOptions): void;
469
+ doOn(...signals: string[]): this;
582
470
  /**
583
- * Updates the progress of a task and emits metrics with associated metadata.
471
+ * Unsubscribes from all observed signals and clears the internal collection
472
+ * of observed signals. This ensures that the instance is no longer listening
473
+ * or reacting to any previously subscribed signals.
584
474
  *
585
- * @param {number} progress - A number representing the progress value, which will be clamped between 0 and 1.
586
- * @return {void} This method does not return a value.
475
+ * @return {this} Returns the current instance for chaining purposes.
587
476
  */
588
- onProgress(progress: number): void;
477
+ unsubscribeAll(): this;
589
478
  /**
590
- * Processes the result of the current operation, validates it, and determines the next set of nodes.
591
- *
592
- * This method ensures that results of certain types such as strings or arrays
593
- * are flagged as errors. It divides the current context into subsequent nodes
594
- * for further processing. If the division returns a promise, it delegates the
595
- * processing to `postProcessAsync`. For synchronous division, it sets the
596
- * `nextNodes` and finalizes the operation.
479
+ * Unsubscribes the current instance from the specified signals.
597
480
  *
598
- * @return {(Array|undefined)} Returns an array of next nodes for further processing,
599
- * or undefined if no further processing is required.
481
+ * @param {...string} signals - The signals to unsubscribe from.
482
+ * @return {this} The current instance for method chaining.
600
483
  */
601
- postProcess(): GraphNode[] | Promise<GraphNode[]>;
484
+ unsubscribe(...signals: string[]): this;
602
485
  /**
603
- * Asynchronously processes and finalizes the provided graph nodes.
486
+ * Cleans up resources and emits an event indicating the destruction of the routine.
604
487
  *
605
- * @param {Promise<GraphNode[]>} nextNodes A promise that resolves to an array of graph nodes to be processed.
606
- * @return {Promise<GraphNode[]>} A promise that resolves to the processed array of graph nodes.
607
- */
608
- postProcessAsync(nextNodes: Promise<GraphNode[]>): Promise<GraphNode[]>;
609
- /**
610
- * Finalizes the current task execution by determining if the task is complete, handles any errors or failures,
611
- * emits relevant signals based on the task outcomes, and ensures proper end of the task lifecycle.
488
+ * This method unsubscribes from all events, clears the tasks list,
489
+ * and emits a "meta.routine.destroyed" event with details of the destruction.
612
490
  *
613
- * @return {void} Does not return a value.
491
+ * @return {void}
614
492
  */
615
- finalize(): void;
493
+ destroy(): void;
494
+ }
495
+
496
+ /**
497
+ * Represents a runner for managing and executing tasks or routines within a graph.
498
+ * The `GraphRunner` extends `SignalEmitter` to include signal-based event-driven mechanisms.
499
+ */
500
+ declare class GraphRunner extends SignalEmitter {
501
+ currentRun: GraphRun;
502
+ debug: boolean;
503
+ verbose: boolean;
504
+ isRunning: boolean;
505
+ readonly isMeta: boolean;
506
+ strategy: GraphRunStrategy;
616
507
  /**
617
- * Handles an error event, processes the error, and updates the state accordingly.
618
- *
619
- * @param {unknown} error - The error object or message that occurred.
620
- * @param {AnyObject} [errorData={}] - Additional error data to include in the result.
621
- * @return {void} This method does not return any value.
508
+ * Constructs a runner.
509
+ * @param isMeta Meta flag (default false).
510
+ * @edge Creates 'Start run' meta-task chained to registry gets.
622
511
  */
623
- onError(error: unknown, errorData?: AnyObject): void;
512
+ constructor(isMeta?: boolean);
624
513
  /**
625
- * Retries a task based on the defined retry count and delay time. If the retry count is 0, it immediately resolves with the provided previous result.
514
+ * Adds tasks or routines to the current execution pipeline. Supports both individual tasks,
515
+ * routines, or arrays of tasks and routines. Handles metadata and execution context management.
626
516
  *
627
- * @param {any} [prevResult] - The result from a previous attempt, if any, to return when no retries are performed.
628
- * @return {Promise<TaskResult>} - A promise that resolves with the result of the retried task or the previous result if no retries occur.
517
+ * @param {Task|GraphRoutine|(Task|GraphRoutine)[]} tasks - The task(s) or routine(s) to be added.
518
+ * It can be a single task, a single routine, or an array of tasks and routines.
519
+ * @param {AnyObject} [context={}] - Optional context object to provide execution trace and metadata.
520
+ * Used to propagate information across task or routine executions.
521
+ * @return {void} - This method does not return a value.
629
522
  */
630
- retry(prevResult?: any): Promise<TaskResult>;
523
+ addTasks(tasks: Task | GraphRoutine | (Task | GraphRoutine)[], context?: AnyObject): void;
631
524
  /**
632
- * Retries an asynchronous operation and returns its result.
633
- * If the retry count is zero, the method immediately returns the provided previous result.
525
+ * Executes the provided tasks or routines. Maintains the execution state
526
+ * and handles synchronous or asynchronous processing.
634
527
  *
635
- * @param {any} [prevResult] - The optional result from a previous operation attempt, if applicable.
636
- * @return {Promise<TaskResult>} A promise that resolves to the result of the retried operation.
528
+ * @param {Task|GraphRoutine|(Task|GraphRoutine)[]} [tasks] - A single task, a single routine, or an array of tasks or routines to execute. Optional.
529
+ * @param {AnyObject} [context] - An optional context object to be used during task execution.
530
+ * @return {GraphRun|Promise<GraphRun>} - Returns a `GraphRun` instance if the execution is synchronous, or a `Promise` resolving to a `GraphRun` for asynchronous execution.
637
531
  */
638
- retryAsync(prevResult?: any): Promise<TaskResult>;
639
- delayRetry(): Promise<void>;
532
+ run(tasks?: Task | GraphRoutine | (Task | GraphRoutine)[], context?: AnyObject): GraphRun | Promise<GraphRun>;
640
533
  /**
641
- * Processes the result of a task by generating new nodes based on the task output.
642
- * The method handles synchronous and asynchronous generators, validates task output,
643
- * and creates new nodes accordingly. If errors occur, the method attempts to handle them
644
- * by generating alternative task nodes.
534
+ * Executes the provided asynchronous operation and resets the state afterwards.
645
535
  *
646
- * @return {GraphNode[] | Promise<GraphNode[]>} Returns an array of generated GraphNode objects
647
- * (synchronously or wrapped in a Promise) based on the task result, or propagates errors if validation fails.
536
+ * @param {Promise<void>} run - A promise representing the asynchronous operation to execute.
537
+ * @return {Promise<GraphRun>} A promise that resolves to the result of the reset operation after the asynchronous operation completes.
648
538
  */
649
- divide(): GraphNode[] | Promise<GraphNode[]>;
539
+ runAsync(run: Promise<void>): Promise<GraphRun>;
650
540
  /**
651
- * Processes an asynchronous iterator result, validates its output, and generates new graph nodes accordingly.
652
- * Additionally, continues to process and validate results from an asynchronous generator.
541
+ * Resets the current state of the graph, creating a new GraphRun instance
542
+ * and returning the previous run instance.
543
+ * If the debug mode is not enabled, it will destroy the existing resources.
653
544
  *
654
- * @param {Promise<IteratorResult<any>>} current - A promise resolving to the current step result from an asynchronous iterator.
655
- * @return {Promise<GraphNode[]>} A promise resolving to an array of generated GraphNode objects based on validated outputs.
545
+ * @return {GraphRun} The last GraphRun instance before the reset.
656
546
  */
657
- divideAsync(current: Promise<IteratorResult<any>>): Promise<GraphNode[]>;
547
+ reset(): GraphRun;
548
+ setDebug(value: boolean): void;
549
+ setVerbose(value: boolean): void;
550
+ destroy(): void;
658
551
  /**
659
- * Generates new nodes based on the provided result and task configuration.
552
+ * Sets the strategy to be used for running the graph and initializes
553
+ * the current run with the provided strategy if no process is currently running.
660
554
  *
661
- * @param {any} result - The result of the previous operation, which determines the configuration and context for new nodes. It can be a boolean or an object containing details like failure, errors, or metadata.
662
- * @return {GraphNode[]} An array of newly generated graph nodes configured based on the task and context.
555
+ * @param {GraphRunStrategy} strategy - The strategy to use for running the graph.
556
+ * @return {void}
663
557
  */
664
- generateNewNodes(result: any): GraphNode[];
665
- /**
666
- * Executes the differentiation process based on a given task and updates the instance properties accordingly.
667
- *
668
- * @param {Task} task - The task object containing information such as retry count, retry delay, and metadata status.
669
- * @return {GraphNode} The updated instance after processing the task.
670
- */
671
- differentiate(task: Task): GraphNode;
558
+ setStrategy(strategy: GraphRunStrategy): void;
559
+ }
560
+
561
+ interface EmitOptions {
562
+ squash?: boolean;
563
+ squashId?: string | null;
564
+ groupId?: string | null;
565
+ mergeFunction?: ((oldContext: AnyObject, ...newContext: AnyObject[]) => AnyObject) | null;
566
+ debounce?: boolean;
567
+ throttle?: boolean;
568
+ delayMs?: number;
569
+ schedule?: boolean;
570
+ exactDateTime?: Date | null;
571
+ throttleBatch?: number;
572
+ flushStrategy?: string;
573
+ }
574
+ type SignalDeliveryMode = "single" | "broadcast";
575
+ type SignalReceiverFilter = {
576
+ serviceNames?: string[];
577
+ serviceInstanceIds?: string[];
578
+ origins?: string[];
579
+ roles?: string[];
580
+ protocols?: string[];
581
+ runtimeStates?: string[];
582
+ };
583
+ type SignalMetadata = {
584
+ deliveryMode?: SignalDeliveryMode;
585
+ broadcastFilter?: SignalReceiverFilter | null;
586
+ };
587
+ type PassiveSignalListener = (signal: string, context: AnyObject, metadata: SignalMetadata | null) => void;
588
+ type SignalDefinitionInput = string | ({
589
+ name: string;
590
+ } & SignalMetadata);
591
+ type FlushStrategyName = string;
592
+ interface FlushStrategy {
593
+ intervalMs: number;
594
+ maxBatchSize: number;
595
+ }
596
+ /**
597
+ * This class manages signals and observers, enabling communication across different parts of an application.
598
+ * It follows a singleton design pattern, allowing for centralized signal management.
599
+ */
600
+ declare class SignalBroker {
601
+ static instance_: SignalBroker;
602
+ static get instance(): SignalBroker;
603
+ debug: boolean;
604
+ verbose: boolean;
605
+ setDebug(value: boolean): void;
606
+ setVerbose(value: boolean): void;
607
+ runner: GraphRunner | undefined;
608
+ metaRunner: GraphRunner | undefined;
609
+ throttleEmitters: Map<string, any>;
610
+ throttleQueues: Map<string, any>;
611
+ getSignalsTask: Task | undefined;
612
+ registerSignalTask: Task | undefined;
613
+ signalObservers: Map<string, {
614
+ fn: (runner: GraphRunner, tasks: (Task | GraphRoutine)[], context: AnyObject) => void;
615
+ tasks: Set<Task | GraphRoutine>;
616
+ registered: boolean;
617
+ }>;
618
+ emittedSignalsRegistry: Set<string>;
619
+ signalMetadataRegistry: Map<string, SignalMetadata>;
620
+ passiveSignalListeners: Map<string, PassiveSignalListener>;
621
+ private flushStrategies;
622
+ private strategyData;
623
+ private strategyTimers;
624
+ private isStrategyFlushing;
625
+ private readonly defaultStrategyName;
626
+ constructor();
627
+ private resolveSignalMetadataKey;
628
+ private normalizeSignalMetadata;
629
+ setSignalMetadata(signal: string, metadata?: SignalMetadata | null): void;
630
+ getSignalMetadata(signal: string): SignalMetadata | undefined;
631
+ logMemoryFootprint(label?: string): void;
672
632
  /**
673
- * Migrates the current instance to a new context and returns the updated instance.
633
+ * Validates the provided signal name string to ensure it adheres to specific formatting rules.
634
+ * Throws an error if any of the validation checks fail.
674
635
  *
675
- * @param {any} ctx - The context data to be used for migration.
676
- * @return {GraphNode} The updated instance after migration.
636
+ * @param {string} signalName - The signal name to be validated.
637
+ * @return {void} - Returns nothing if the signal name is valid.
638
+ * @throws {Error} - Throws an error if the signal name is longer than 100 characters, contains spaces,
639
+ * contains backslashes, or contains uppercase letters in restricted parts of the name.
677
640
  */
678
- migrate(ctx: any): GraphNode;
641
+ validateSignalName(signalName: string): void;
679
642
  /**
680
- * Splits the current node into a new group identified by the provided ID.
643
+ * Initializes with runners.
644
+ * @param runner Standard runner for user signals.
645
+ * @param metaRunner Meta runner for 'meta.' signals (suppresses further meta-emits).
646
+ */
647
+ bootstrap(runner: GraphRunner, metaRunner: GraphRunner): void;
648
+ /**
649
+ * Initializes and sets up the various tasks for managing and processing signals.
681
650
  *
682
- * @param {string} id - The unique identifier for the new split group.
683
- * @return {GraphNode} The current instance of the GraphNode with the updated split group ID.
651
+ * @return {void} This method does not return a value.
684
652
  */
685
- split(id: string): GraphNode;
653
+ init(): void;
654
+ setFlushStrategy(name: FlushStrategyName, config: {
655
+ intervalMs: number;
656
+ maxBatchSize?: number;
657
+ }): void;
658
+ updateFlushStrategy(name: FlushStrategyName, config: FlushStrategy): void;
659
+ removeFlushStrategy(name: FlushStrategyName): void;
660
+ getFlushStrategies(): Record<FlushStrategyName, FlushStrategy>;
661
+ private readonly MAX_FLUSH_DURATION_MS;
662
+ squash(signal: string, context: AnyObject, options?: EmitOptions): void;
663
+ private flushGroup;
664
+ private flushStrategy;
665
+ clearSquashState(): void;
666
+ private clearScheduledState;
667
+ private scheduledBuckets;
668
+ private scheduleTimer;
669
+ schedule(signal: string, context: AnyObject, options?: EmitOptions): AbortController;
670
+ private flushScheduled;
671
+ private debouncedEmitters;
672
+ private readonly MAX_DEBOUNCERS;
673
+ private clearDebounceState;
674
+ private clearThrottleState;
675
+ debounce(signal: string, context: any, options?: {
676
+ delayMs: number;
677
+ }): void;
678
+ throttle(signal: string, context: any, options?: EmitOptions): void;
686
679
  /**
687
- * Creates a new instance of the GraphNode with the current node's properties.
688
- * This method allows for duplicating the existing graph node.
680
+ * Emits `signal` repeatedly with a fixed interval.
689
681
  *
690
- * @return {GraphNode} A new instance of GraphNode that is a copy of the current node.
682
+ * @param signal
683
+ * @param context
684
+ * @param intervalMs
685
+ * @param leading If true, emits immediately (unless a startDateTime is given and we are before it).
686
+ * @param startDateTime Optional absolute Date when the *first* emission after `leading` should occur.
687
+ * @returns a handle with `clear()` to stop the loop.
691
688
  */
692
- clone(): GraphNode;
689
+ interval(signal: string, context: AnyObject, intervalMs?: number, leading?: boolean, startDateTime?: Date): ThrottleHandle;
693
690
  /**
694
- * Consumes the given graph node by combining contexts, merging previous nodes,
695
- * and performing associated operations on the provided node.
691
+ * Emits a signal with the specified context, triggering any associated handlers for that signal.
696
692
  *
697
- * @param {GraphNode} node - The graph node to be consumed.
693
+ * @param {string} signal - The name of the signal to emit.
694
+ * @param {AnyObject} [context={}] - An optional context object containing additional information or metadata
695
+ * associated with the signal. If the context includes a `__routineExecId`, it will be handled accordingly.
696
+ * @param options
698
697
  * @return {void} This method does not return a value.
699
698
  */
700
- consume(node: GraphNode): void;
699
+ emit(signal: string, context?: AnyObject, options?: EmitOptions): void;
701
700
  /**
702
- * Changes the identity of the current instance by updating the `id` property.
701
+ * Executes a signal by emitting events, updating context, and invoking listeners.
702
+ * Creates a new execution trace if necessary and updates the context with relevant metadata.
703
+ * Handles specific, hierarchy-based, and wildcard signals.
703
704
  *
704
- * @param {string} id - The new identity value to be assigned.
705
- * @return {void} Does not return a value.
705
+ * @param {string} signal - The signal name to be executed, potentially including namespaces or tags (e.g., "meta.*" or "signal:type").
706
+ * @param {AnyObject} context - An object containing relevant metadata and execution details used for handling the signal.
707
+ * @return {boolean} Returns true if any listeners were successfully executed, otherwise false.
706
708
  */
707
- changeIdentity(id: string): void;
709
+ execute(signal: string, context: AnyObject): boolean;
708
710
  /**
709
- * Completes the subgraph for the current node and recursively for its previous nodes
710
- * once all next nodes have their subgraphs marked as done. If there are no previous nodes,
711
- * it completes the entire graph.
711
+ * Executes the tasks associated with a given signal and context.
712
+ * It processes both normal and meta tasks depending on the signal type
713
+ * and the availability of the appropriate runner.
712
714
  *
713
- * @return {void} Does not return a value.
715
+ * @param {string} signal - The signal identifier that determines which tasks to execute.
716
+ * @param {AnyObject} context - The context object passed to the task execution function.
717
+ * @return {boolean} - Returns true if tasks were executed; otherwise, false.
714
718
  */
715
- completeSubgraph(): void;
719
+ executeListener(signal: string, context: AnyObject): boolean;
716
720
  /**
717
- * Completes the current graph by setting a flag indicating the graph has been completed
718
- * and recursively completes all subsequent nodes in the graph.
721
+ * Adds a signal to the signalObservers for tracking and execution.
722
+ * Performs validation on the signal name and emits a meta signal event when added.
723
+ * If the signal contains a namespace (denoted by a colon ":"), its base signal is
724
+ * also added if it doesn't already exist.
719
725
  *
720
- * @return {void} Does not return a value.
726
+ * @param {string} signal - The name of the signal to be added.
727
+ * @return {void} This method does not return any value.
721
728
  */
722
- completeGraph(): void;
729
+ addSignal(signal: string, metadata?: SignalMetadata | null): void;
723
730
  /**
724
- * Destroys the current instance by releasing resources, breaking references,
725
- * and resetting properties to ensure proper cleanup.
726
- *
727
- * @return {void} No return value.
731
+ * Observes a signal with a routine/task.
732
+ * @param signal The signal (e.g., 'domain.action', 'domain.*' for wildcards).
733
+ * @param routineOrTask The observer.
734
+ * @edge Duplicates ignored; supports wildcards for broad listening.
728
735
  */
729
- destroy(): void;
736
+ observe(signal: string, routineOrTask: Task | GraphRoutine, metadata?: SignalMetadata | null): void;
737
+ addPassiveSignalListener(listener: PassiveSignalListener): () => void;
738
+ private notifyPassiveSignalListeners;
739
+ registerEmittedSignal(signal: string, metadata?: SignalMetadata | null): void;
730
740
  /**
731
- * Retrieves an iterator for traversing through the graph nodes.
732
- *
733
- * @return {GraphNodeIterator} An iterator instance specific to this graph node.
741
+ * Unsubscribes a routine/task from a signal.
742
+ * @param signal The signal.
743
+ * @param routineOrTask The observer.
744
+ * @edge Removes all instances if duplicate; deletes if empty.
734
745
  */
735
- getIterator(): GraphNodeIterator;
746
+ unsubscribe(signal: string, routineOrTask: Task | GraphRoutine): void;
736
747
  /**
737
- * Applies a callback function to each node in the `nextNodes` array and returns
738
- * the resulting array from the map operation.
739
- *
740
- * @param {function} callback - A function to execute on each `GraphNode` in the `nextNodes` array.
741
- * The function receives a `GraphNode` as its argument.
742
- * @return {Array} The resulting array after applying the callback function to each node in `nextNodes`.
748
+ * Lists all observed signals.
749
+ * @returns Array of signals.
743
750
  */
744
- mapNext(callback: (node: GraphNode) => any): any[];
751
+ listObservedSignals(): string[];
752
+ listEmittedSignals(): string[];
753
+ reset(): void;
754
+ shutdown(): void;
755
+ }
756
+
757
+ /**
758
+ * Abstract class representing a signal emitter.
759
+ * Allows emitting events or signals, with the option to suppress emissions if desired.
760
+ */
761
+ declare abstract class SignalEmitter {
762
+ silent: boolean;
745
763
  /**
746
- * Accepts a visitor object and calls its visitNode method with the current instance.
747
- *
748
- * @param {GraphVisitor} visitor - The visitor instance implementing the GraphVisitor interface.
749
- * @return {void} This method does not return a value.
764
+ * Constructor for signal emitters.
765
+ * @param silent If true, suppresses all emissions (e.g., for meta-runners to avoid loops; affects all emits).
750
766
  */
751
- accept(visitor: GraphVisitor): void;
767
+ constructor(silent?: boolean);
752
768
  /**
753
- * Exports the current object's state and returns it in a serialized format.
754
- * The exported object contains metadata, task details, context information, execution times, node relationships, routine execution status, and other state information.
755
- *
756
- * @return {Object} An object representing the current state.
769
+ * Emits a signal via the broker.
770
+ * @param signal The signal name.
771
+ * @param data Optional payload (defaults to empty object).
772
+ * @param options
757
773
  */
758
- export(): {
759
- __id: string;
760
- __task: AnyObject;
761
- __context: {
762
- id: string;
763
- context: AnyObject;
764
- };
765
- __result: TaskResult;
766
- __executionTime: number;
767
- __executionStart: number;
768
- __executionEnd: number;
769
- __nextNodes: string[];
770
- __previousNodes: string[];
771
- __routineExecId: string;
772
- __isProcessing: boolean;
773
- __isMeta: boolean;
774
- __graphComplete: boolean;
775
- __failed: boolean;
776
- __errored: boolean;
777
- __isUnique: boolean;
778
- __splitGroupId: string;
779
- __tag: string;
780
- };
781
- lightExport(): {
782
- __id: string;
783
- __task: {
784
- __name: string;
785
- __version: number;
786
- };
787
- __context: {
788
- id: string;
789
- context: AnyObject;
790
- };
791
- __executionTime: number;
792
- __executionStart: number;
793
- __nextNodes: string[];
794
- __previousNodes: string[];
795
- __routineExecId: string;
796
- __isProcessing: boolean;
797
- __graphComplete: boolean;
798
- __isMeta: boolean;
799
- __failed: boolean;
800
- __errored: boolean;
801
- __isUnique: boolean;
802
- __splitGroupId: string;
803
- __tag: string;
804
- };
805
- log(): void;
806
- }
807
-
808
- declare abstract class GraphVisitor {
809
- abstract visitLayer(layer: GraphLayer): any;
810
- abstract visitNode(node: GraphNode): any;
811
- abstract visitTask(task: Task): any;
774
+ emit(signal: string, data?: AnyObject, options?: EmitOptions): void;
775
+ /**
776
+ * Emits a signal via the broker if not silent.
777
+ * @param signal The signal name.
778
+ * @param data Optional payload (defaults to empty object).
779
+ * @param options
780
+ */
781
+ emitMetrics(signal: string, data?: AnyObject, options?: EmitOptions): void;
812
782
  }
813
783
 
814
- /**
815
- * TaskIterator is a custom iterator for traversing over a set of tasks.
816
- * It provides mechanisms to iterate through tasks in a layered manner,
817
- * where each task can branch out to other tasks forming multiple layers.
818
- */
819
- declare class TaskIterator implements Iterator {
820
- currentTask: Task | undefined;
821
- currentLayer: Set<Task>;
822
- nextLayer: Set<Task>;
823
- iterator: {
824
- next: () => {
825
- value: Task | undefined;
826
- };
784
+ type SchemaType = "string" | "number" | "boolean" | "array" | "object" | "any";
785
+ type SchemaConstraints = {
786
+ min?: number;
787
+ max?: number;
788
+ minLength?: number;
789
+ maxLength?: number;
790
+ pattern?: string;
791
+ enum?: any[];
792
+ multipleOf?: number;
793
+ format?: "email" | "url" | "date-time" | "uuid" | "custom";
794
+ oneOf?: any[];
795
+ };
796
+ type SchemaDefinition = {
797
+ type: SchemaType;
798
+ required?: string[];
799
+ properties?: {
800
+ [key: string]: Schema;
827
801
  };
828
- constructor(task: Task);
829
- hasNext(): boolean;
830
- next(): Task | undefined;
831
- }
802
+ items?: Schema;
803
+ constraints?: SchemaConstraints;
804
+ description?: string;
805
+ strict?: boolean;
806
+ };
807
+ type SchemaMap = Record<string, SchemaDefinition>;
808
+ type Schema = SchemaDefinition | SchemaMap;
832
809
 
833
- type TaskFunction = (context: AnyObject, emit: (signal: string, context: AnyObject) => void, inquire: (inquiry: string, context: AnyObject, options: InquiryOptions) => Promise<AnyObject>, progressCallback: (progress: number) => void) => TaskResult;
834
- type TaskResult = boolean | AnyObject | Generator | Promise<any> | void;
835
- type ThrottleTagGetter = (context?: AnyObject, task?: Task) => string;
836
- /**
837
- * Represents a task with a specific behavior, configuration, and lifecycle management.
838
- * Tasks are used to define units of work that can be executed and orchestrated.
839
- * Tasks can specify input/output validation, concurrency, retry policies, and more.
840
- * This class extends SignalEmitter and implements Graph, allowing tasks to emit and observe signals.
841
- */
842
- declare class Task extends SignalEmitter implements Graph {
843
- readonly name: string;
844
- readonly description: string;
845
- version: number;
846
- concurrency: number;
847
- timeout: number;
848
- readonly isMeta: boolean;
849
- readonly isSubMeta: boolean;
850
- readonly isHidden: boolean;
851
- readonly isUnique: boolean;
852
- readonly throttled: boolean;
853
- readonly isSignal: boolean;
854
- readonly isDeputy: boolean;
855
- readonly isEphemeral: boolean;
856
- readonly isDebounce: boolean;
857
- inputContextSchema: Schema;
858
- hasExplicitInputContextSchema: boolean;
859
- validateInputContext: boolean;
860
- outputContextSchema: Schema;
861
- hasExplicitOutputContextSchema: boolean;
862
- validateOutputContext: boolean;
863
- readonly retryCount: number;
864
- readonly retryDelay: number;
865
- readonly retryDelayMax: number;
866
- readonly retryDelayFactor: number;
867
- layerIndex: number;
868
- progressWeight: number;
869
- nextTasks: Set<Task>;
870
- predecessorTasks: Set<Task>;
871
- destroyed: boolean;
872
- register: boolean;
873
- registered: boolean;
874
- registeredSignals: Set<string>;
875
- taskMapRegistration: Set<string>;
876
- emitsSignals: Set<string>;
877
- signalsToEmitAfter: Set<string>;
878
- signalsToEmitOnFail: Set<string>;
879
- observedSignals: Set<string>;
880
- handlesIntents: Set<string>;
881
- inquiresIntents: Set<string>;
882
- readonly taskFunction: TaskFunction;
883
- /**
884
- * Constructs an instance of the task with the specified properties and configuration options.
885
- *
886
- * @param {string} name - The name of the task.
887
- * @param {TaskFunction} task - The function that represents the task logic.
888
- * @param {string} [description=""] - A description of the task.
889
- * @param {number} [concurrency=0] - The number of concurrent executions allowed for the task.
890
- * @param {number} [timeout=0] - The maximum execution time for the task in milliseconds.
891
- * @param {boolean} [register=true] - Indicates if the task should be registered or not.
892
- * @param {boolean} [isUnique=false] - Specifies if the task should only allow one instance to exist at any time.
893
- * @param {boolean} [isMeta=false] - Indicates if the task is a meta-task.
894
- * @param {boolean} [isSubMeta=false] - Indicates if the task is a sub-meta-task.
895
- * @param {boolean} [isHidden=false] - Determines if the task is hidden and not exposed publicly.
896
- * @param {ThrottleTagGetter} [getTagCallback=undefined] - A callback to generate a throttle tag for the task.
897
- * @param {Schema} [inputSchema=undefined] - The input schema for validating the task's input context.
898
- * @param {boolean} [validateInputContext=false] - Specifies if the input context should be validated against the input schema.
899
- * @param {Schema} [outputSchema=undefined] - The output schema for validating the task's output context.
900
- * @param {boolean} [validateOutputContext=false] - Specifies if the output context should be validated against the output schema.
901
- * @param {number} [retryCount=0] - The number of retry attempts allowed for the task in case of failure.
902
- * @param {number} [retryDelay=0] - The initial delay (in milliseconds) between retry attempts.
903
- * @param {number} [retryDelayMax=0] - The maximum delay (in milliseconds) allowed between retries.
904
- * @param {number} [retryDelayFactor=1] - The factor by which the retry delay increases after each attempt.
905
- */
906
- constructor(name: string, task: TaskFunction, description?: string, concurrency?: number, timeout?: number, register?: boolean, isUnique?: boolean, isMeta?: boolean, isSubMeta?: boolean, isHidden?: boolean, getTagCallback?: ThrottleTagGetter | undefined, inputSchema?: Schema, validateInputContext?: boolean, outputSchema?: Schema, validateOutputContext?: boolean, retryCount?: number, retryDelay?: number, retryDelayMax?: number, retryDelayFactor?: number);
907
- clone(traverse?: boolean, includeSignals?: boolean): Task;
810
+ interface Intent {
811
+ name: string;
812
+ description?: string;
813
+ input?: SchemaDefinition;
814
+ output?: SchemaDefinition;
815
+ }
816
+ interface InquiryOptions {
817
+ timeout?: number;
818
+ rejectOnTimeout?: boolean;
819
+ includePendingTasks?: boolean;
820
+ requireComplete?: boolean;
821
+ }
822
+ declare class InquiryBroker extends SignalEmitter {
823
+ static instance_: InquiryBroker;
824
+ static get instance(): InquiryBroker;
825
+ debug: boolean;
826
+ verbose: boolean;
827
+ setDebug(value: boolean): void;
828
+ setVerbose(value: boolean): void;
829
+ validateInquiryName(inquiryName: string): void;
830
+ runner: GraphRunner | undefined;
831
+ metaRunner: GraphRunner | undefined;
832
+ inquiryObservers: Map<string, {
833
+ fn: (runner: GraphRunner, tasks: Task[], context: AnyObject) => void;
834
+ tasks: Set<Task>;
835
+ registered: boolean;
836
+ }>;
837
+ intents: Map<string, Intent>;
908
838
  /**
909
- * Retrieves the tag associated with the instance.
910
- * Can be overridden by subclasses.
911
- *
912
- * @param {AnyObject} [context] - Optional context parameter that can be provided.
913
- * @return {string} The tag value of the instance.
839
+ * Initializes with runners.
840
+ * @param runner Standard runner for user signals.
841
+ * @param metaRunner Meta runner for 'meta.' signals (suppresses further meta-emits).
914
842
  */
915
- getTag(context?: AnyObject): string;
916
- setVersion(version: number): void;
917
- setTimeout(timeout: number): void;
918
- setConcurrency(concurrency: number): void;
919
- setProgressWeight(weight: number): void;
920
- setInputContextSchema(schema: Schema): void;
921
- setOutputContextSchema(schema: Schema): void;
922
- setValidateInputContext(value: boolean): void;
923
- setValidateOutputContext(value: boolean): void;
843
+ bootstrap(runner: GraphRunner, metaRunner: GraphRunner): void;
844
+ init(): void;
924
845
  /**
925
- * Emits a signal along with metadata if certain conditions are met.
926
- *
927
- * This method sends a signal with optional context data and adds metadata
928
- * to the emitted data if the instance is not hidden and not a subordinate metadata object.
929
- *
930
- * @param {string} signal - The name of the signal to emit.
931
- * @param {AnyObject} [ctx={}] - Additional context data to include with the emitted signal.
932
- * @return {void} Does not return a value.
846
+ * Observes an inquiry with a routine/task.
847
+ * @param inquiry The inquiry (e.g., 'domain.action', 'domain.*' for wildcards).
848
+ * @param task The observer.
849
+ * @edge Duplicates ignored; supports wildcards for broad listening.
933
850
  */
934
- emitWithMetadata(signal: string, ctx?: AnyObject): void;
851
+ observe(inquiry: string, task: Task): void;
935
852
  /**
936
- * Emits metrics with additional metadata enhancement based on the context and the state of the instance.
937
- * This is used to prevent loops on the meta layer in debug mode.
938
- *
939
- * @param {string} signal - The signal identifier for the metric being emitted.
940
- * @param {AnyObject} [ctx={}] - Optional context object to provide additional information with the metric.
941
- * @return {void} This method does not return any value.
853
+ * Unsubscribes a routine/task from an inquiry.
854
+ * @param inquiry The inquiry.
855
+ * @param task The observer.
856
+ * @edge Removes all instances if duplicate; deletes if empty.
942
857
  */
943
- emitMetricsWithMetadata(signal: string, ctx?: AnyObject): void;
944
- private isSchemaDefinition;
945
- private isDefaultAnyObjectSchema;
946
- private mergeSchemaVariant;
947
- private validateValueAgainstSchema;
858
+ unsubscribe(inquiry: string, task: Task): void;
859
+ addInquiry(inquiry: string): void;
860
+ addIntent(intent: Intent): void;
861
+ inquire(inquiry: string, context: AnyObject, options?: InquiryOptions): Promise<AnyObject>;
862
+ reset(): void;
863
+ }
864
+
865
+ /**
866
+ * Represents a node in a graph structure used for executing tasks.
867
+ * A Node is a container for a task and its associated context, providing
868
+ * methods for executing the task and managing its lifecycle.
869
+ *
870
+ * It extends the SignalEmitter class to emit and handle signals related to
871
+ * the node's lifecycle, such as "meta.node.started" and "meta.node.completed".
872
+ *
873
+ * It also implements the Graph interface, allowing it to be used as a part of
874
+ * a graph structure, such as a GraphLayer or GraphRoutine.
875
+ *
876
+ * @extends SignalEmitter
877
+ * @implements Graph
878
+ */
879
+ declare class GraphNode extends SignalEmitter implements Graph {
880
+ id: string;
881
+ routineExecId: string;
882
+ executionTraceId: string;
883
+ task: Task;
884
+ context: GraphContext;
885
+ layer: GraphLayer | undefined;
886
+ divided: boolean;
887
+ splitGroupId: string;
888
+ processing: boolean;
889
+ subgraphComplete: boolean;
890
+ graphComplete: boolean;
891
+ result: TaskResult;
892
+ retryCount: number;
893
+ retryDelay: number;
894
+ retries: number;
895
+ previousNodes: GraphNode[];
896
+ nextNodes: GraphNode[];
897
+ executionTime: number;
898
+ executionStart: number;
899
+ failed: boolean;
900
+ errored: boolean;
901
+ destroyed: boolean;
902
+ debug: boolean;
903
+ verbose: boolean;
904
+ constructor(task: Task, context: GraphContext, routineExecId: string, prevNodes?: GraphNode[], debug?: boolean, verbose?: boolean);
905
+ setDebug(value: boolean): void;
906
+ isUnique(): boolean;
907
+ isMeta(): boolean;
908
+ isProcessed(): boolean;
909
+ isProcessing(): boolean;
910
+ subgraphDone(): boolean;
911
+ graphDone(): boolean;
948
912
  /**
949
- * Validates a data object against a specified schema definition and returns validation results.
913
+ * Compares the current GraphNode instance with another GraphNode to determine if they are considered equal.
950
914
  *
951
- * @param {any} data - The target object to validate against the schema.
952
- * @param {Schema | undefined} schema - The schema definition describing the expected structure and constraints of the data.
953
- * @param {string} [path="context"] - The base path or context for traversing the data, used in generating error messages.
954
- * @return {{ valid: boolean, errors: Record<string, string> }} - An object containing a validity flag (`valid`)
955
- * and a map (`errors`) of validation error messages keyed by property paths.
915
+ * @param {GraphNode} node - The GraphNode object to compare with the current instance.
916
+ * @return {boolean} Returns true if the nodes share the same task, context, and belong to the same graph; otherwise, false.
956
917
  */
957
- validateSchema(data: any, schema: Schema | undefined, path?: string): {
958
- valid: boolean;
959
- errors: Record<string, string>;
960
- };
961
- validateProp(prop: SchemaDefinition, key: string, value?: any, path?: string): Record<string, string>;
918
+ isEqualTo(node: GraphNode): boolean;
962
919
  /**
963
- * Validates the input context against the predefined schema and emits metadata if validation fails.
920
+ * Determines if the given node is part of the same graph as the current node.
964
921
  *
965
- * @param {AnyObject} context - The input context to validate.
966
- * @return {true | AnyObject} - Returns `true` if validation succeeds, otherwise returns an error object containing details of the validation failure.
922
+ * @param {GraphNode} node - The node to compare with the current node.
923
+ * @return {boolean} Returns true if the provided node is part of the same graph
924
+ * (i.e., has the same routineExecId), otherwise false.
967
925
  */
968
- private getEffectiveValidationMode;
969
- private warnMissingSchema;
970
- private logValidationFailure;
971
- validateInput(context: AnyObject, metadata?: AnyObject): true | AnyObject;
926
+ isPartOfSameGraph(node: GraphNode): boolean;
972
927
  /**
973
- * Validates the output context using the provided schema and emits metadata if validation fails.
928
+ * Determines whether the current instance shares a task with the provided node.
974
929
  *
975
- * @param {AnyObject} context - The output context to validate.
976
- * @return {true | AnyObject} Returns `true` if the output context is valid; otherwise, returns an object
977
- * containing error information when validation fails.
930
+ * @param {GraphNode} node - The graph node to compare with the current instance.
931
+ * @return {boolean} Returns true if the task names of both nodes match, otherwise false.
978
932
  */
979
- validateOutput(context: AnyObject, metadata?: AnyObject): true | AnyObject;
933
+ sharesTaskWith(node: GraphNode): boolean;
980
934
  /**
981
- * Executes a task within a given context, optionally emitting signals and reporting progress.
935
+ * Determines whether the current node shares the same context as the specified node.
982
936
  *
983
- * @param {GraphContext} context The execution context which provides data and functions necessary for the task.
984
- * @param {function(string, AnyObject): void} emit A function to emit signals and communicate intermediate results or states.
985
- * @param {function(string, AnyObject, InquiryOptions): Promise<AnyObject>} inquire A function to inquire something from another task.
986
- * @param {function(number): void} progressCallback A callback function used to report task progress as a percentage (0 to 100).
987
- * @param {{ nodeId: string; routineExecId: string }} nodeData An object containing identifiers related to the node and execution routine.
988
- * @return {TaskResult} The result of the executed task.
937
+ * @param {GraphNode} node - The graph node to compare with the current node's context.
938
+ * @return {boolean} True if both nodes share the same context; otherwise, false.
989
939
  */
990
- execute(context: GraphContext, emit: (signal: string, context: AnyObject) => void, inquire: (inquiry: string, context: AnyObject, options: InquiryOptions) => Promise<AnyObject>, progressCallback: (progress: number) => void, nodeData: {
991
- nodeId: string;
992
- routineExecId: string;
993
- }): TaskResult;
940
+ sharesContextWith(node: GraphNode): boolean;
941
+ getLayerIndex(): number;
942
+ getConcurrency(): number;
994
943
  /**
995
- * Adds tasks as predecessors to the current task and establishes dependencies between them.
996
- * Ensures that adding predecessors does not create cyclic dependencies.
997
- * Updates task relationships, progress weights, and emits relevant metrics after operations.
944
+ * Retrieves the tag associated with the current task and context.
998
945
  *
999
- * @param {Task[]} tasks - An array of tasks to be added as predecessors to the current task.
1000
- * @return {this} The current task instance for method chaining.
1001
- * @throws {Error} Throws an error if adding a predecessor creates a cycle in the task structure.
946
+ * @return {string} The tag retrieved from the task within the given context.
1002
947
  */
1003
- doAfter(...tasks: (Task | undefined)[]): this;
948
+ getTag(): string;
949
+ private classifyBusinessRoutineLifecycle;
950
+ private getBusinessRoutineLifecycleDecision;
951
+ private rememberBusinessRoutineLifecycleDecision;
1004
952
  /**
1005
- * Adds a sequence of tasks as successors to the current task, ensuring no cyclic dependencies are introduced.
1006
- * Metrics are emitted when a relationship is successfully added.
953
+ * Schedules the current node/task on the specified graph layer if applicable.
1007
954
  *
1008
- * @param {...Task} tasks - The tasks to be added as successors to the current task.
1009
- * @return {this} Returns the current task instance for method chaining.
1010
- * @throws {Error} Throws an error if adding a task causes a cyclic dependency.
1011
- */
1012
- then(...tasks: (Task | undefined)[]): this;
1013
- /**
1014
- * Decouples the current task from the provided task by removing mutual references.
955
+ * This method assesses whether the current node/task should be scheduled
956
+ * on the given graph layer. It ensures that tasks are only scheduled
957
+ * under certain conditions, such as checking if the task shares
958
+ * execution contexts or dependencies with other nodes, and handles
959
+ * various metadata emissions and context updates during the scheduling process.
1015
960
  *
1016
- * @param {Task} task - The task to decouple from the current task.
1017
- * @return {void} This method does not return a value.
961
+ * @param {GraphLayer} layer - The graph layer on which the current task should be scheduled.
962
+ * @returns {void} Does not return a value.
1018
963
  */
1019
- decouple(task: Task): void;
964
+ scheduleOn(layer: GraphLayer): void;
1020
965
  /**
1021
- * Updates the progress weights for tasks within each layer of the subgraph.
1022
- * The progress weight for each task is calculated based on the inverse proportion
1023
- * of the number of layers and the number of tasks in each layer. This ensures an
1024
- * even distribution of progress weight across the tasks in the layers.
966
+ * Starts the execution process by initializing the execution start timestamp,
967
+ * emitting relevant metadata, and logging debug information if applicable.
1025
968
  *
1026
- * @return {void} Does not return a value.
1027
- */
1028
- updateProgressWeights(): void;
1029
- /**
1030
- * Retrieves a mapping of layer indices to sets of tasks within each layer of a subgraph.
1031
- * This method traverses the task dependencies and organizes tasks by their respective layer indices.
969
+ * The method performs the following actions:
970
+ * 1. Sets the execution start timestamp if it's not already initialized.
971
+ * 2. Emits metrics with metadata about the routine execution starting, including additional data if there are no previous nodes.
972
+ * 3. Optionally logs debug or verbose information based on the current settings.
973
+ * 4. Emits additional metrics to indicate that the execution has started.
1032
974
  *
1033
- * @return {Map<number, Set<Task>>} A map where the key is the layer index (number) and the value is a set of tasks (Set<Task>) belonging to that layer.
975
+ * @return {number} The timestamp indicating when the execution started.
1034
976
  */
1035
- getSubgraphLayers(): Map<number, Set<Task>>;
977
+ start(): number;
1036
978
  /**
1037
- * Updates the `layerIndex` of the current task based on the maximum layer index of its predecessors
1038
- * and propagates the update recursively to all subsequent tasks. If the `layerIndex` changes,
1039
- * emits a metric event with metadata about the change.
979
+ * Marks the end of an execution process, performs necessary cleanup, emits
980
+ * metrics with associated metadata, and signals the completion of execution.
981
+ * Also handles specific cases when the graph completes.
1040
982
  *
1041
- * @return {void} This method does not return a value.
983
+ * @return {number} The timestamp corresponding to the end of execution. If execution
984
+ * was not started, it returns 0.
1042
985
  */
1043
- updateLayerFromPredecessors(): void;
986
+ end(): number;
1044
987
  /**
1045
- * Determines whether there is a cycle in the tasks graph.
1046
- * This method performs a depth-first search (DFS) to detect cycles.
988
+ * Executes the main logic of the task, including input validation, processing, and post-processing.
989
+ * Handles both synchronous and asynchronous workflows.
1047
990
  *
1048
- * @return {boolean} - Returns true if a cycle is found in the graph, otherwise false.
991
+ * @return {Array|Promise|undefined} Returns the next nodes to process if available.
992
+ * If asynchronous processing is required, it returns a Promise that resolves to the next nodes.
993
+ * Returns undefined in case of an error during input validation or preconditions that prevent processing.
1049
994
  */
1050
- hasCycle(): boolean;
995
+ execute(): GraphNode[] | Promise<GraphNode[]>;
1051
996
  /**
1052
- * Maps over the next set of tasks or failed tasks if specified, applying the provided callback function.
997
+ * Executes an asynchronous workflow that processes a result and retries on errors.
998
+ * The method handles different result states, checks for error properties, and invokes
999
+ * error handling when necessary.
1053
1000
  *
1054
- * @param {Function} callback A function that will be called with each task, transforming the task as needed. It receives a single parameter of type Task.
1055
- * @return {any[]} An array of transformed tasks resulting from applying the callback function.
1001
+ * @return {Promise<void>} A promise that resolves when the operation completes successfully,
1002
+ * or rejects if an unhandled error occurs.
1056
1003
  */
1057
- mapNext(callback: (task: Task) => any): any[];
1004
+ workAsync(): Promise<void>;
1058
1005
  /**
1059
- * Maps through each task in the set of predecessor tasks and applies the provided callback function.
1006
+ * Executes an asynchronous operation, processes the result, and determines the next nodes to execute.
1007
+ * This method will manage asynchronous work, handle post-processing of results, and ensure proper handling of both synchronous and asynchronous next node configurations.
1060
1008
  *
1061
- * @param {function} callback - A function to execute on each task in the predecessor tasks. The function receives a `Task` object as its argument and returns any value.
1062
- * @return {any[]} An array containing the results of applying the callback function to each predecessor task.
1009
+ * @return {Promise<any>} A promise resolving to the next nodes to be executed. Can be the result of post-processing or a directly resolved next nodes object.
1063
1010
  */
1064
- mapPrevious(callback: (task: Task) => any): any[];
1065
- makeRoutine(name: string, description: string): this;
1011
+ executeAsync(): Promise<GraphNode[]>;
1066
1012
  /**
1067
- * Adds the specified signals to the current instance, making it observe them.
1068
- * If the instance is already observing a signal, it will be skipped.
1069
- * The method also emits metadata information if the `register` property is set.
1013
+ * Executes the task associated with the current instance, using the given context,
1014
+ * progress callback, and metadata. If the task fails or an error occurs, it attempts
1015
+ * to retry the execution. If the retry is not successful, it propagates the error and
1016
+ * returns the result.
1070
1017
  *
1071
- * @param {...string[]} signals - The array of signal names to observe.
1072
- * @return {this} The current instance after adding the specified signals.
1018
+ * @return {TaskResult | Promise<TaskResult>} The result of the task execution, or a
1019
+ * promise that resolves to the task result. This includes handling for retries on
1020
+ * failure and error propagation.
1073
1021
  */
1074
- doOn(...signals: SignalDefinitionInput[]): this;
1022
+ work(): TaskResult | Promise<TaskResult>;
1023
+ inquire(inquiry: string, context: AnyObject, options: InquiryOptions): Promise<any>;
1075
1024
  /**
1076
- * Registers the specified signals to be emitted after the Task executes successfully and attaches them for further processing.
1025
+ * Emits a signal along with its associated metadata. The metadata includes
1026
+ * task-specific information such as task name, version, execution ID, and
1027
+ * additional context metadata like routine execution ID and execution trace ID.
1028
+ * This method is designed to enrich emitted signals with relevant details
1029
+ * before broadcasting them.
1077
1030
  *
1078
- * @param {...string} signals - The list of signals to be registered for emission.
1079
- * @return {this} The current instance for method chaining.
1031
+ * @param {string} signal - The name of the signal to be emitted.
1032
+ * @param {AnyObject} data - The data object to be sent along with the signal. Metadata
1033
+ * will be injected into this object before being emitted.
1034
+ * @param options
1035
+ * @return {void} No return value.
1080
1036
  */
1081
- emits(...signals: SignalDefinitionInput[]): this;
1037
+ emitWithMetadata(signal: string, data: AnyObject, options?: EmitOptions): void;
1082
1038
  /**
1083
- * Configures the instance to emit specified signals when the task execution fails.
1084
- * A failure is defined as anything that does not return a successful result.
1039
+ * Emits metrics with additional metadata describing the task execution and context.
1085
1040
  *
1086
- * @param {...string} signals - The names of the signals to emit upon failure.
1087
- * @return {this} Returns the current instance for chaining.
1041
+ * @param {string} signal - The signal name being emitted.
1042
+ * @param {AnyObject} data - The data associated with the signal emission, enriched with metadata.
1043
+ * @param options
1044
+ * @return {void} Emits the signal with enriched data and does not return a value.
1088
1045
  */
1089
- emitsOnFail(...signals: SignalDefinitionInput[]): this;
1046
+ emitMetricsWithMetadata(signal: string, data: AnyObject, options?: EmitOptions): void;
1090
1047
  /**
1091
- * Attaches a signal to the current context and emits metadata if the register flag is set.
1048
+ * Updates the progress of a task and emits metrics with associated metadata.
1092
1049
  *
1093
- * @param {...string} signals - The names of the signals to attach.
1050
+ * @param {number} progress - A number representing the progress value, which will be clamped between 0 and 1.
1094
1051
  * @return {void} This method does not return a value.
1095
1052
  */
1096
- attachSignal(...signals: SignalDefinitionInput[]): Task;
1053
+ onProgress(progress: number): void;
1097
1054
  /**
1098
- * Unsubscribes the current instance from the specified signals.
1099
- * This method removes the signals from the observedSignals set, unsubscribes
1100
- * from the underlying broker, and emits metadata for the unsubscription if applicable.
1055
+ * Processes the result of the current operation, validates it, and determines the next set of nodes.
1101
1056
  *
1102
- * @param {string[]} signals - The list of signal names to unsubscribe from.
1103
- * @return {this} Returns the current instance for method chaining.
1057
+ * This method ensures that results of certain types such as strings or arrays
1058
+ * are flagged as errors. It divides the current context into subsequent nodes
1059
+ * for further processing. If the division returns a promise, it delegates the
1060
+ * processing to `postProcessAsync`. For synchronous division, it sets the
1061
+ * `nextNodes` and finalizes the operation.
1062
+ *
1063
+ * @return {(Array|undefined)} Returns an array of next nodes for further processing,
1064
+ * or undefined if no further processing is required.
1104
1065
  */
1105
- unsubscribe(...signals: string[]): this;
1066
+ postProcess(): GraphNode[] | Promise<GraphNode[]>;
1106
1067
  /**
1107
- * Unsubscribes from all currently observed signals and clears the list of observed signals.
1068
+ * Asynchronously processes and finalizes the provided graph nodes.
1108
1069
  *
1109
- * @return {this} The instance of the class to allow method chaining.
1070
+ * @param {Promise<GraphNode[]>} nextNodes A promise that resolves to an array of graph nodes to be processed.
1071
+ * @return {Promise<GraphNode[]>} A promise that resolves to the processed array of graph nodes.
1110
1072
  */
1111
- unsubscribeAll(): this;
1073
+ postProcessAsync(nextNodes: Promise<GraphNode[]>): Promise<GraphNode[]>;
1112
1074
  /**
1113
- * Detaches the specified signals from being emitted after execution and optionally emits metadata for each detached signal.
1075
+ * Finalizes the current task execution by determining if the task is complete, handles any errors or failures,
1076
+ * emits relevant signals based on the task outcomes, and ensures proper end of the task lifecycle.
1114
1077
  *
1115
- * @param {...string} signals - The list of signal names to be detached. Signals can be in the format "namespace:signalName".
1116
- * @return {this} Returns the current instance of the object for method chaining.
1078
+ * @return {void} Does not return a value.
1117
1079
  */
1118
- detachSignals(...signals: string[]): this;
1080
+ finalize(): void;
1119
1081
  /**
1120
- * Detaches all signals associated with the object by invoking the `detachSignals` method
1121
- * and clearing the `signalsToEmitAfter` collection.
1082
+ * Handles an error event, processes the error, and updates the state accordingly.
1122
1083
  *
1123
- * @return {this} Returns the current instance to allow method chaining.
1084
+ * @param {unknown} error - The error object or message that occurred.
1085
+ * @param {AnyObject} [errorData={}] - Additional error data to include in the result.
1086
+ * @return {void} This method does not return any value.
1124
1087
  */
1125
- detachAllSignals(): this;
1126
- respondsTo(...inquires: string[]): this;
1127
- attachIntents(...intentNames: string[]): this;
1128
- detachIntents(...intentNames: string[]): this;
1129
- detachAllIntents(): this;
1088
+ onError(error: unknown, errorData?: AnyObject): void;
1130
1089
  /**
1131
- * Maps over the signals in the `signalsToEmitAfter` set and applies a callback function to each signal.
1090
+ * Retries a task based on the defined retry count and delay time. If the retry count is 0, it immediately resolves with the provided previous result.
1132
1091
  *
1133
- * @param {function(string): void} callback - A function that is called with each signal
1134
- * in the `signalsToEmitAfter` set, providing the signal as an argument.
1135
- * @return {Array<any>} An array containing the results of applying the callback
1136
- * function to each signal.
1092
+ * @param {any} [prevResult] - The result from a previous attempt, if any, to return when no retries are performed.
1093
+ * @return {Promise<TaskResult>} - A promise that resolves with the result of the retried task or the previous result if no retries occur.
1137
1094
  */
1138
- mapSignals(callback: (signal: string) => void): void[];
1095
+ retry(prevResult?: any): Promise<TaskResult>;
1139
1096
  /**
1140
- * Maps over the signals in `signalsToEmitOnFail` and applies the provided callback to each signal.
1097
+ * Retries an asynchronous operation and returns its result.
1098
+ * If the retry count is zero, the method immediately returns the provided previous result.
1141
1099
  *
1142
- * @param {function(string): void} callback - A function that receives each signal as a string and performs an operation or transformation on it.
1143
- * @return {Array} The array resulting from applying the callback to each signal in `signalsToEmitOnFail`.
1100
+ * @param {any} [prevResult] - The optional result from a previous operation attempt, if applicable.
1101
+ * @return {Promise<TaskResult>} A promise that resolves to the result of the retried operation.
1144
1102
  */
1145
- mapOnFailSignals(callback: (signal: string) => void): void[];
1103
+ retryAsync(prevResult?: any): Promise<TaskResult>;
1104
+ delayRetry(): Promise<void>;
1146
1105
  /**
1147
- * Maps over the observed signals with the provided callback function.
1106
+ * Processes the result of a task by generating new nodes based on the task output.
1107
+ * The method handles synchronous and asynchronous generators, validates task output,
1108
+ * and creates new nodes accordingly. If errors occur, the method attempts to handle them
1109
+ * by generating alternative task nodes.
1148
1110
  *
1149
- * @param {function(string): void} callback - A function to execute on each signal in the observed signals array.
1150
- * @return {Array} A new array containing the results of calling the callback function on each observed signal.
1111
+ * @return {GraphNode[] | Promise<GraphNode[]>} Returns an array of generated GraphNode objects
1112
+ * (synchronously or wrapped in a Promise) based on the task result, or propagates errors if validation fails.
1151
1113
  */
1152
- mapObservedSignals(callback: (signal: string) => void): void[];
1114
+ divide(): GraphNode[] | Promise<GraphNode[]>;
1153
1115
  /**
1154
- * Emits a collection of signals stored in the `signalsToEmitAfter` array.
1116
+ * Processes an asynchronous iterator result, validates its output, and generates new graph nodes accordingly.
1117
+ * Additionally, continues to process and validate results from an asynchronous generator.
1155
1118
  *
1156
- * @param {GraphContext} context - The context object containing data or state to be passed to the emitted signals.
1157
- * @return {void} This method does not return a value.
1119
+ * @param {Promise<IteratorResult<any>>} current - A promise resolving to the current step result from an asynchronous iterator.
1120
+ * @return {Promise<GraphNode[]>} A promise resolving to an array of generated GraphNode objects based on validated outputs.
1158
1121
  */
1159
- emitSignals(context: GraphContext): void;
1122
+ divideAsync(current: Promise<IteratorResult<any>>): Promise<GraphNode[]>;
1160
1123
  /**
1161
- * Emits registered signals when an operation fails.
1124
+ * Generates new nodes based on the provided result and task configuration.
1162
1125
  *
1163
- * @param {GraphContext} context - The context from which the full context is derived and passed to the signals being emitted.
1164
- * @return {void} This method does not return any value.
1126
+ * @param {any} result - The result of the previous operation, which determines the configuration and context for new nodes. It can be a boolean or an object containing details like failure, errors, or metadata.
1127
+ * @return {GraphNode[]} An array of newly generated graph nodes configured based on the task and context.
1165
1128
  */
1166
- emitOnFailSignals(context: GraphContext): void;
1129
+ generateNewNodes(result: any): GraphNode[];
1167
1130
  /**
1168
- * Cleans up and destroys the task instance, detaching it from other tasks and
1169
- * performing necessary cleanup operations.
1131
+ * Executes the differentiation process based on a given task and updates the instance properties accordingly.
1170
1132
  *
1171
- * This method:
1172
- * - Unsubscribes from all signals and events.
1173
- * - Detaches all associated signal handlers.
1174
- * - Removes the task from successor and predecessor task mappings.
1175
- * - Clears all task relationships and marks the task as destroyed.
1176
- * - Emits destruction metrics, if applicable.
1133
+ * @param {Task} task - The task object containing information such as retry count, retry delay, and metadata status.
1134
+ * @return {GraphNode} The updated instance after processing the task.
1135
+ */
1136
+ differentiate(task: Task): GraphNode;
1137
+ /**
1138
+ * Migrates the current instance to a new context and returns the updated instance.
1177
1139
  *
1178
- * @return {void} No value is returned because the function performs clean-up operations.
1140
+ * @param {any} ctx - The context data to be used for migration.
1141
+ * @return {GraphNode} The updated instance after migration.
1179
1142
  */
1180
- destroy(): void;
1143
+ migrate(ctx: any): GraphNode;
1181
1144
  /**
1182
- * Exports the current state of the object as a structured plain object.
1145
+ * Splits the current node into a new group identified by the provided ID.
1183
1146
  *
1184
- * @return {AnyObject} An object containing the serialized properties of the current instance. The exported object includes various metadata, schema information, task attributes, and related tasks, such as:
1185
- * - Name and description of the task.
1186
- * - Layer index, uniqueness, meta, and signal-related flags.
1187
- * - Event triggers and attached signals.
1188
- * - Throttling, concurrency, timeout settings, and ephemeral flag.
1189
- * - Task function as a string.
1190
- * - Serialization of getter callbacks and schemas for input/output validation.
1191
- * - Relationships such as next tasks, failure tasks, and predecessor tasks.
1147
+ * @param {string} id - The unique identifier for the new split group.
1148
+ * @return {GraphNode} The current instance of the GraphNode with the updated split group ID.
1192
1149
  */
1193
- export(): AnyObject;
1150
+ split(id: string): GraphNode;
1194
1151
  /**
1195
- * Returns an iterator for iterating over tasks associated with this instance.
1152
+ * Creates a new instance of the GraphNode with the current node's properties.
1153
+ * This method allows for duplicating the existing graph node.
1196
1154
  *
1197
- * @return {TaskIterator} An iterator instance for tasks.
1155
+ * @return {GraphNode} A new instance of GraphNode that is a copy of the current node.
1198
1156
  */
1199
- getIterator(): TaskIterator;
1157
+ clone(): GraphNode;
1200
1158
  /**
1201
- * Accepts a visitor object to perform operations on the current instance.
1159
+ * Consumes the given graph node by combining contexts, merging previous nodes,
1160
+ * and performing associated operations on the provided node.
1202
1161
  *
1203
- * @param {GraphVisitor} visitor - The visitor object implementing operations for this instance.
1162
+ * @param {GraphNode} node - The graph node to be consumed.
1204
1163
  * @return {void} This method does not return a value.
1205
1164
  */
1206
- accept(visitor: GraphVisitor): void;
1207
- log(): void;
1208
- }
1209
-
1210
- /**
1211
- * Represents a synchronous graph layer derived from the GraphLayer base class.
1212
- * This class is designed to execute graph nodes in a strictly synchronous manner.
1213
- * Asynchronous functions are explicitly disallowed, ensuring consistency and predictability.
1214
- */
1215
- declare class SyncGraphLayer extends GraphLayer {
1165
+ consume(node: GraphNode): void;
1216
1166
  /**
1217
- * Executes the processing logic of the current set of graph nodes. Iterates through all
1218
- * nodes, skipping any that have already been processed, and executes their respective
1219
- * logic to generate new nodes. Asynchronous functions are not supported and will
1220
- * trigger an error log.
1167
+ * Changes the identity of the current instance by updating the `id` property.
1221
1168
  *
1222
- * @return {GraphNode[]} An array of newly generated graph nodes after executing the logic of each unprocessed node.
1169
+ * @param {string} id - The new identity value to be assigned.
1170
+ * @return {void} Does not return a value.
1223
1171
  */
1224
- execute(): GraphNode[];
1225
- }
1226
-
1227
- /**
1228
- * An abstract class representing a GraphExporter.
1229
- * This class defines a structure for exporting graph data in different formats,
1230
- * depending on the implementations provided by subclasses.
1231
- */
1232
- declare abstract class GraphExporter {
1233
- abstract exportGraph(graph: SyncGraphLayer): any;
1234
- abstract exportStaticGraph(graph: Task[]): any;
1235
- }
1236
-
1237
- /**
1238
- * GraphBuilder is an abstract base class designed to construct and manage a graph structure
1239
- * composed of multiple layers. Subclasses are expected to implement the `compose` method
1240
- * based on specific requirements. This class provides methods for adding nodes, managing
1241
- * layers, and resetting the graph construction process.
1242
- *
1243
- * This class supports creating layered graph structures, dynamically adding layers and nodes,
1244
- * and debugging graph-building operations.
1245
- */
1246
- declare abstract class GraphBuilder {
1247
- graph: GraphLayer | undefined;
1248
- topLayerIndex: number;
1249
- layers: GraphLayer[];
1250
- debug: boolean;
1251
- setDebug(value: boolean): void;
1252
- getResult(): GraphLayer;
1172
+ changeIdentity(id: string): void;
1253
1173
  /**
1254
- * Composes a series of functions or operations.
1255
- * This method should be implemented in the child class
1256
- * to define custom composition logic.
1174
+ * Completes the subgraph for the current node and recursively for its previous nodes
1175
+ * once all next nodes have their subgraphs marked as done. If there are no previous nodes,
1176
+ * it completes the entire graph.
1257
1177
  *
1258
- * @return {any} The result of the composed operations or functions
1259
- * when implemented in the child class.
1178
+ * @return {void} Does not return a value.
1260
1179
  */
1261
- compose(): void;
1180
+ completeSubgraph(): void;
1262
1181
  /**
1263
- * Adds a node to the appropriate layer of the graph.
1182
+ * Completes the current graph by setting a flag indicating the graph has been completed
1183
+ * and recursively completes all subsequent nodes in the graph.
1264
1184
  *
1265
- * @param {GraphNode} node - The node to be added to the graph. The node contains
1266
- * layer information that determines which layer it belongs to.
1267
1185
  * @return {void} Does not return a value.
1268
1186
  */
1269
- addNode(node: GraphNode): void;
1187
+ completeGraph(): void;
1270
1188
  /**
1271
- * Adds multiple nodes to the graph.
1189
+ * Destroys the current instance by releasing resources, breaking references,
1190
+ * and resetting properties to ensure proper cleanup.
1272
1191
  *
1273
- * @param {GraphNode[]} nodes - An array of nodes to be added to the graph.
1274
- * @return {void} This method does not return a value.
1192
+ * @return {void} No return value.
1275
1193
  */
1276
- addNodes(nodes: GraphNode[]): void;
1194
+ destroy(): void;
1277
1195
  /**
1278
- * Adds a new layer to the graph at the specified index. If the graph does not exist,
1279
- * it creates the graph using the specified index. Updates the graph's top layer index
1280
- * and maintains the order of layers.
1196
+ * Retrieves an iterator for traversing through the graph nodes.
1197
+ *
1198
+ * @return {GraphNodeIterator} An iterator instance specific to this graph node.
1199
+ */
1200
+ getIterator(): GraphNodeIterator;
1201
+ /**
1202
+ * Applies a callback function to each node in the `nextNodes` array and returns
1203
+ * the resulting array from the map operation.
1281
1204
  *
1282
- * @param {number} index - The index at which the new layer should be added to the graph.
1283
- * @return {void} This method does not return a value.
1205
+ * @param {function} callback - A function to execute on each `GraphNode` in the `nextNodes` array.
1206
+ * The function receives a `GraphNode` as its argument.
1207
+ * @return {Array} The resulting array after applying the callback function to each node in `nextNodes`.
1284
1208
  */
1285
- addLayer(index: number): void;
1209
+ mapNext(callback: (node: GraphNode) => any): any[];
1286
1210
  /**
1287
- * Creates a new layer for the graph at the specified index.
1211
+ * Accepts a visitor object and calls its visitNode method with the current instance.
1288
1212
  *
1289
- * @param {number} index - The index of the layer to be created.
1290
- * @return {GraphLayer} A new instance of the graph layer corresponding to the provided index.
1213
+ * @param {GraphVisitor} visitor - The visitor instance implementing the GraphVisitor interface.
1214
+ * @return {void} This method does not return a value.
1291
1215
  */
1292
- createLayer(index: number): GraphLayer;
1216
+ accept(visitor: GraphVisitor): void;
1293
1217
  /**
1294
- * Retrieves a specific layer from the current set of layers.
1218
+ * Exports the current object's state and returns it in a serialized format.
1219
+ * The exported object contains metadata, task details, context information, execution times, node relationships, routine execution status, and other state information.
1295
1220
  *
1296
- * @param {number} layerIndex - The index of the layer to retrieve.
1297
- * @return {*} The layer corresponding to the given index.
1221
+ * @return {Object} An object representing the current state.
1298
1222
  */
1299
- getLayer(layerIndex: number): GraphLayer;
1300
- reset(): void;
1223
+ export(): {
1224
+ __id: string;
1225
+ __task: AnyObject;
1226
+ __context: {
1227
+ id: string;
1228
+ context: AnyObject;
1229
+ };
1230
+ __result: TaskResult;
1231
+ __executionTime: number;
1232
+ __executionStart: number;
1233
+ __executionEnd: number;
1234
+ __nextNodes: string[];
1235
+ __previousNodes: string[];
1236
+ __routineExecId: string;
1237
+ __isProcessing: boolean;
1238
+ __isMeta: boolean;
1239
+ __graphComplete: boolean;
1240
+ __failed: boolean;
1241
+ __errored: boolean;
1242
+ __isUnique: boolean;
1243
+ __splitGroupId: string;
1244
+ __tag: string;
1245
+ };
1246
+ lightExport(): {
1247
+ __id: string;
1248
+ __task: {
1249
+ __name: string;
1250
+ __version: number;
1251
+ };
1252
+ __context: {
1253
+ id: string;
1254
+ context: AnyObject;
1255
+ };
1256
+ __executionTime: number;
1257
+ __executionStart: number;
1258
+ __nextNodes: string[];
1259
+ __previousNodes: string[];
1260
+ __routineExecId: string;
1261
+ __isProcessing: boolean;
1262
+ __graphComplete: boolean;
1263
+ __isMeta: boolean;
1264
+ __failed: boolean;
1265
+ __errored: boolean;
1266
+ __isUnique: boolean;
1267
+ __splitGroupId: string;
1268
+ __tag: string;
1269
+ };
1270
+ log(): void;
1271
+ }
1272
+
1273
+ declare abstract class GraphVisitor {
1274
+ abstract visitLayer(layer: GraphLayer): any;
1275
+ abstract visitNode(node: GraphNode): any;
1276
+ abstract visitTask(task: Task): any;
1301
1277
  }
1302
1278
 
1303
1279
  /**
1304
- * Abstract class representing a strategy for configuring and executing graph operations.
1305
- * Provides a structure for managing graph builders, altering strategies, and updating the execution context.
1306
- *
1307
- * This class cannot be instantiated directly and must be extended by concrete implementations.
1280
+ * TaskIterator is a custom iterator for traversing over a set of tasks.
1281
+ * It provides mechanisms to iterate through tasks in a layered manner,
1282
+ * where each task can branch out to other tasks forming multiple layers.
1308
1283
  */
1309
- declare abstract class GraphRunStrategy {
1310
- graphBuilder: GraphBuilder;
1311
- runInstance?: GraphRun;
1312
- constructor();
1313
- setRunInstance(runInstance: GraphRun): void;
1314
- changeStrategy(builder: GraphBuilder): void;
1315
- reset(): void;
1316
- addNode(node: GraphNode): void;
1317
- updateRunInstance(): void;
1318
- abstract run(): void;
1319
- abstract export(): any;
1284
+ declare class TaskIterator implements Iterator {
1285
+ currentTask: Task | undefined;
1286
+ currentLayer: Set<Task>;
1287
+ nextLayer: Set<Task>;
1288
+ iterator: {
1289
+ next: () => {
1290
+ value: Task | undefined;
1291
+ };
1292
+ };
1293
+ constructor(task: Task);
1294
+ hasNext(): boolean;
1295
+ next(): Task | undefined;
1320
1296
  }
1321
1297
 
1322
- interface RunJson {
1323
- __id: string;
1324
- __label: string;
1325
- __graph: any;
1326
- __data: any;
1298
+ interface RuntimeTools {
1299
+ helpers: Record<string, HelperInvoker>;
1300
+ globals: Record<string, unknown>;
1327
1301
  }
1328
- /**
1329
- * Represents a GraphRun instance which manages the execution of a graph-based workflow.
1330
- * It utilizes a specific strategy and export mechanism to manage, execute, and export the graph data.
1331
- */
1332
- declare class GraphRun {
1333
- readonly id: string;
1334
- graph: GraphLayer | undefined;
1335
- strategy: GraphRunStrategy;
1336
- exporter: GraphExporter | undefined;
1337
- constructor(strategy: GraphRunStrategy);
1338
- setGraph(graph: GraphLayer): void;
1339
- addNode(node: GraphNode): void;
1340
- run(): void | Promise<void>;
1302
+ type HelperFunction = (context: AnyObject, emit: (signal: string, context: AnyObject) => void, inquire: (inquiry: string, context: AnyObject, options: InquiryOptions) => Promise<AnyObject>, tools: RuntimeTools, progressCallback: (progress: number) => void) => TaskResult;
1303
+ type HelperInvoker = (context?: AnyObject) => TaskResult | Promise<TaskResult>;
1304
+ interface ToolDependencyOwner {
1305
+ readonly isMeta: boolean;
1306
+ helperAliases: Map<string, string>;
1307
+ globalAliases: Map<string, string>;
1308
+ }
1309
+ declare class GlobalDefinition {
1310
+ readonly name: string;
1311
+ readonly description: string;
1312
+ readonly version: number;
1313
+ readonly isMeta: boolean;
1314
+ readonly value: unknown;
1315
+ destroyed: boolean;
1316
+ constructor(name: string, value: unknown, description?: string, isMeta?: boolean);
1341
1317
  destroy(): void;
1342
- log(): void;
1343
- export(): RunJson;
1344
- setExporter(exporter: GraphExporter): void;
1318
+ export(): Record<string, unknown>;
1319
+ }
1320
+ declare class HelperDefinition implements ToolDependencyOwner {
1321
+ readonly name: string;
1322
+ readonly description: string;
1323
+ readonly version: number;
1324
+ readonly isMeta: boolean;
1325
+ readonly helperFunction: HelperFunction;
1326
+ readonly helperAliases: Map<string, string>;
1327
+ readonly globalAliases: Map<string, string>;
1328
+ destroyed: boolean;
1329
+ constructor(name: string, helperFunction: HelperFunction, description?: string, isMeta?: boolean);
1330
+ usesHelpers(helpers: Record<string, HelperDefinition | undefined>): this;
1331
+ usesGlobals(globals: Record<string, GlobalDefinition | undefined>): this;
1332
+ execute(context: AnyObject, emit: (signal: string, context: AnyObject) => void, inquire: (inquiry: string, context: AnyObject, options: InquiryOptions) => Promise<AnyObject>, progressCallback: (progress: number) => void): TaskResult;
1333
+ destroy(): void;
1334
+ export(): Record<string, unknown>;
1345
1335
  }
1346
1336
 
1337
+ type TaskFunction = (context: AnyObject, emit: (signal: string, context: AnyObject) => void, inquire: (inquiry: string, context: AnyObject, options: InquiryOptions) => Promise<AnyObject>, tools: RuntimeTools, progressCallback: (progress: number) => void) => TaskResult;
1338
+ type TaskResult = boolean | AnyObject | Generator | Promise<any> | void;
1339
+ type ThrottleTagGetter = (context?: AnyObject, task?: Task) => string;
1347
1340
  /**
1348
- * Represents a routine in a graph structure with tasks and signal observation capabilities.
1349
- * Routines are named entrypoint for a sub-graph, describing the purpose for the subsequent flow.
1350
- * Since Task names are specific to the task it performs, it doesn't describe the overall flow.
1351
- * Routines, therefore are used to assign names to sub-flows that can be referenced using that name instead of the name of the task(s).
1352
- * Extends SignalEmitter to emit and handle signals related to the routine's lifecycle and tasks.
1341
+ * Represents a task with a specific behavior, configuration, and lifecycle management.
1342
+ * Tasks are used to define units of work that can be executed and orchestrated.
1343
+ * Tasks can specify input/output validation, concurrency, retry policies, and more.
1344
+ * This class extends SignalEmitter and implements Graph, allowing tasks to emit and observe signals.
1353
1345
  */
1354
- declare class GraphRoutine extends SignalEmitter {
1346
+ declare class Task extends SignalEmitter implements Graph, ToolDependencyOwner {
1355
1347
  readonly name: string;
1356
- version: number;
1357
1348
  readonly description: string;
1349
+ version: number;
1350
+ concurrency: number;
1351
+ timeout: number;
1358
1352
  readonly isMeta: boolean;
1359
- tasks: Set<Task>;
1353
+ readonly isSubMeta: boolean;
1354
+ readonly isHidden: boolean;
1355
+ readonly isUnique: boolean;
1356
+ readonly throttled: boolean;
1357
+ readonly isSignal: boolean;
1358
+ readonly isDeputy: boolean;
1359
+ readonly isEphemeral: boolean;
1360
+ readonly isDebounce: boolean;
1361
+ inputContextSchema: Schema;
1362
+ hasExplicitInputContextSchema: boolean;
1363
+ validateInputContext: boolean;
1364
+ outputContextSchema: Schema;
1365
+ hasExplicitOutputContextSchema: boolean;
1366
+ validateOutputContext: boolean;
1367
+ readonly retryCount: number;
1368
+ readonly retryDelay: number;
1369
+ readonly retryDelayMax: number;
1370
+ readonly retryDelayFactor: number;
1371
+ layerIndex: number;
1372
+ progressWeight: number;
1373
+ nextTasks: Set<Task>;
1374
+ predecessorTasks: Set<Task>;
1375
+ destroyed: boolean;
1376
+ register: boolean;
1360
1377
  registered: boolean;
1361
- registeredTasks: Set<Task>;
1378
+ registeredSignals: Set<string>;
1379
+ taskMapRegistration: Set<string>;
1380
+ emitsSignals: Set<string>;
1381
+ signalsToEmitAfter: Set<string>;
1382
+ signalsToEmitOnFail: Set<string>;
1362
1383
  observedSignals: Set<string>;
1363
- constructor(name: string, tasks: Task[], description: string, isMeta?: boolean);
1384
+ handlesIntents: Set<string>;
1385
+ inquiresIntents: Set<string>;
1386
+ helperAliases: Map<string, string>;
1387
+ globalAliases: Map<string, string>;
1388
+ readonly taskFunction: TaskFunction;
1389
+ /**
1390
+ * Constructs an instance of the task with the specified properties and configuration options.
1391
+ *
1392
+ * @param {string} name - The name of the task.
1393
+ * @param {TaskFunction} task - The function that represents the task logic.
1394
+ * @param {string} [description=""] - A description of the task.
1395
+ * @param {number} [concurrency=0] - The number of concurrent executions allowed for the task.
1396
+ * @param {number} [timeout=0] - The maximum execution time for the task in milliseconds.
1397
+ * @param {boolean} [register=true] - Indicates if the task should be registered or not.
1398
+ * @param {boolean} [isUnique=false] - Specifies if the task should only allow one instance to exist at any time.
1399
+ * @param {boolean} [isMeta=false] - Indicates if the task is a meta-task.
1400
+ * @param {boolean} [isSubMeta=false] - Indicates if the task is a sub-meta-task.
1401
+ * @param {boolean} [isHidden=false] - Determines if the task is hidden and not exposed publicly.
1402
+ * @param {ThrottleTagGetter} [getTagCallback=undefined] - A callback to generate a throttle tag for the task.
1403
+ * @param {Schema} [inputSchema=undefined] - The input schema for validating the task's input context.
1404
+ * @param {boolean} [validateInputContext=false] - Specifies if the input context should be validated against the input schema.
1405
+ * @param {Schema} [outputSchema=undefined] - The output schema for validating the task's output context.
1406
+ * @param {boolean} [validateOutputContext=false] - Specifies if the output context should be validated against the output schema.
1407
+ * @param {number} [retryCount=0] - The number of retry attempts allowed for the task in case of failure.
1408
+ * @param {number} [retryDelay=0] - The initial delay (in milliseconds) between retry attempts.
1409
+ * @param {number} [retryDelayMax=0] - The maximum delay (in milliseconds) allowed between retries.
1410
+ * @param {number} [retryDelayFactor=1] - The factor by which the retry delay increases after each attempt.
1411
+ */
1412
+ constructor(name: string, task: TaskFunction, description?: string, concurrency?: number, timeout?: number, register?: boolean, isUnique?: boolean, isMeta?: boolean, isSubMeta?: boolean, isHidden?: boolean, getTagCallback?: ThrottleTagGetter | undefined, inputSchema?: Schema, validateInputContext?: boolean, outputSchema?: Schema, validateOutputContext?: boolean, retryCount?: number, retryDelay?: number, retryDelayMax?: number, retryDelayFactor?: number);
1413
+ clone(traverse?: boolean, includeSignals?: boolean): Task;
1414
+ /**
1415
+ * Retrieves the tag associated with the instance.
1416
+ * Can be overridden by subclasses.
1417
+ *
1418
+ * @param {AnyObject} [context] - Optional context parameter that can be provided.
1419
+ * @return {string} The tag value of the instance.
1420
+ */
1421
+ getTag(context?: AnyObject): string;
1422
+ setVersion(version: number): void;
1423
+ setTimeout(timeout: number): void;
1424
+ setConcurrency(concurrency: number): void;
1425
+ setProgressWeight(weight: number): void;
1426
+ setInputContextSchema(schema: Schema): void;
1427
+ setOutputContextSchema(schema: Schema): void;
1428
+ setValidateInputContext(value: boolean): void;
1429
+ setValidateOutputContext(value: boolean): void;
1430
+ /**
1431
+ * Emits a signal along with metadata if certain conditions are met.
1432
+ *
1433
+ * This method sends a signal with optional context data and adds metadata
1434
+ * to the emitted data if the instance is not hidden and not a subordinate metadata object.
1435
+ *
1436
+ * @param {string} signal - The name of the signal to emit.
1437
+ * @param {AnyObject} [ctx={}] - Additional context data to include with the emitted signal.
1438
+ * @return {void} Does not return a value.
1439
+ */
1440
+ emitWithMetadata(signal: string, ctx?: AnyObject): void;
1441
+ /**
1442
+ * Emits metrics with additional metadata enhancement based on the context and the state of the instance.
1443
+ * This is used to prevent loops on the meta layer in debug mode.
1444
+ *
1445
+ * @param {string} signal - The signal identifier for the metric being emitted.
1446
+ * @param {AnyObject} [ctx={}] - Optional context object to provide additional information with the metric.
1447
+ * @return {void} This method does not return any value.
1448
+ */
1449
+ emitMetricsWithMetadata(signal: string, ctx?: AnyObject): void;
1450
+ private isSchemaDefinition;
1451
+ private isDefaultAnyObjectSchema;
1452
+ private mergeSchemaVariant;
1453
+ private validateValueAgainstSchema;
1364
1454
  /**
1365
- * Iterates over each task in the `tasks` collection and applies the provided callback function.
1366
- * If the callback returns a Promise, resolves all Promises concurrently.
1455
+ * Validates a data object against a specified schema definition and returns validation results.
1367
1456
  *
1368
- * @param {function} callBack - A function to be executed on each task from the `tasks` collection.
1369
- * The callback receives the current task as its argument.
1370
- * @return {Promise<void>} A Promise that resolves once all callback executions, including asynchronous ones, are complete.
1457
+ * @param {any} data - The target object to validate against the schema.
1458
+ * @param {Schema | undefined} schema - The schema definition describing the expected structure and constraints of the data.
1459
+ * @param {string} [path="context"] - The base path or context for traversing the data, used in generating error messages.
1460
+ * @return {{ valid: boolean, errors: Record<string, string> }} - An object containing a validity flag (`valid`)
1461
+ * and a map (`errors`) of validation error messages keyed by property paths.
1371
1462
  */
1372
- forEachTask(callBack: (task: Task) => any): Promise<void>;
1463
+ validateSchema(data: any, schema: Schema | undefined, path?: string): {
1464
+ valid: boolean;
1465
+ errors: Record<string, string>;
1466
+ };
1467
+ validateProp(prop: SchemaDefinition, key: string, value?: any, path?: string): Record<string, string>;
1373
1468
  /**
1374
- * Sets global Version.
1375
- * @param version The Version.
1469
+ * Validates the input context against the predefined schema and emits metadata if validation fails.
1470
+ *
1471
+ * @param {AnyObject} context - The input context to validate.
1472
+ * @return {true | AnyObject} - Returns `true` if validation succeeds, otherwise returns an error object containing details of the validation failure.
1376
1473
  */
1377
- setVersion(version: number): void;
1474
+ private getEffectiveValidationMode;
1475
+ private warnMissingSchema;
1476
+ private logValidationFailure;
1477
+ validateInput(context: AnyObject, metadata?: AnyObject): true | AnyObject;
1378
1478
  /**
1379
- * Subscribes the current instance to the specified signals, enabling it to observe them.
1479
+ * Validates the output context using the provided schema and emits metadata if validation fails.
1380
1480
  *
1381
- * @param {...string} signals - The names of the signals to observe.
1382
- * @return {this} Returns the instance to allow for method chaining.
1481
+ * @param {AnyObject} context - The output context to validate.
1482
+ * @return {true | AnyObject} Returns `true` if the output context is valid; otherwise, returns an object
1483
+ * containing error information when validation fails.
1383
1484
  */
1384
- doOn(...signals: string[]): this;
1485
+ validateOutput(context: AnyObject, metadata?: AnyObject): true | AnyObject;
1385
1486
  /**
1386
- * Unsubscribes from all observed signals and clears the internal collection
1387
- * of observed signals. This ensures that the instance is no longer listening
1388
- * or reacting to any previously subscribed signals.
1487
+ * Executes a task within a given context, optionally emitting signals and reporting progress.
1389
1488
  *
1390
- * @return {this} Returns the current instance for chaining purposes.
1489
+ * @param {GraphContext} context The execution context which provides data and functions necessary for the task.
1490
+ * @param {function(string, AnyObject): void} emit A function to emit signals and communicate intermediate results or states.
1491
+ * @param {function(string, AnyObject, InquiryOptions): Promise<AnyObject>} inquire A function to inquire something from another task.
1492
+ * @param {function(number): void} progressCallback A callback function used to report task progress as a percentage (0 to 100).
1493
+ * @param {{ nodeId: string; routineExecId: string }} nodeData An object containing identifiers related to the node and execution routine.
1494
+ * @return {TaskResult} The result of the executed task.
1391
1495
  */
1392
- unsubscribeAll(): this;
1496
+ execute(context: GraphContext, emit: (signal: string, context: AnyObject) => void, inquire: (inquiry: string, context: AnyObject, options: InquiryOptions) => Promise<AnyObject>, progressCallback: (progress: number) => void, nodeData: {
1497
+ nodeId: string;
1498
+ routineExecId: string;
1499
+ }): TaskResult;
1393
1500
  /**
1394
- * Unsubscribes the current instance from the specified signals.
1501
+ * Adds tasks as predecessors to the current task and establishes dependencies between them.
1502
+ * Ensures that adding predecessors does not create cyclic dependencies.
1503
+ * Updates task relationships, progress weights, and emits relevant metrics after operations.
1395
1504
  *
1396
- * @param {...string} signals - The signals to unsubscribe from.
1397
- * @return {this} The current instance for method chaining.
1505
+ * @param {Task[]} tasks - An array of tasks to be added as predecessors to the current task.
1506
+ * @return {this} The current task instance for method chaining.
1507
+ * @throws {Error} Throws an error if adding a predecessor creates a cycle in the task structure.
1398
1508
  */
1399
- unsubscribe(...signals: string[]): this;
1509
+ doAfter(...tasks: (Task | undefined)[]): this;
1400
1510
  /**
1401
- * Cleans up resources and emits an event indicating the destruction of the routine.
1511
+ * Adds a sequence of tasks as successors to the current task, ensuring no cyclic dependencies are introduced.
1512
+ * Metrics are emitted when a relationship is successfully added.
1402
1513
  *
1403
- * This method unsubscribes from all events, clears the tasks list,
1404
- * and emits a "meta.routine.destroyed" event with details of the destruction.
1514
+ * @param {...Task} tasks - The tasks to be added as successors to the current task.
1515
+ * @return {this} Returns the current task instance for method chaining.
1516
+ * @throws {Error} Throws an error if adding a task causes a cyclic dependency.
1517
+ */
1518
+ then(...tasks: (Task | undefined)[]): this;
1519
+ /**
1520
+ * Decouples the current task from the provided task by removing mutual references.
1405
1521
  *
1406
- * @return {void}
1522
+ * @param {Task} task - The task to decouple from the current task.
1523
+ * @return {void} This method does not return a value.
1407
1524
  */
1408
- destroy(): void;
1409
- }
1410
-
1411
- /**
1412
- * Represents a runner for managing and executing tasks or routines within a graph.
1413
- * The `GraphRunner` extends `SignalEmitter` to include signal-based event-driven mechanisms.
1414
- */
1415
- declare class GraphRunner extends SignalEmitter {
1416
- currentRun: GraphRun;
1417
- debug: boolean;
1418
- verbose: boolean;
1419
- isRunning: boolean;
1420
- readonly isMeta: boolean;
1421
- strategy: GraphRunStrategy;
1525
+ decouple(task: Task): void;
1422
1526
  /**
1423
- * Constructs a runner.
1424
- * @param isMeta Meta flag (default false).
1425
- * @edge Creates 'Start run' meta-task chained to registry gets.
1527
+ * Updates the progress weights for tasks within each layer of the subgraph.
1528
+ * The progress weight for each task is calculated based on the inverse proportion
1529
+ * of the number of layers and the number of tasks in each layer. This ensures an
1530
+ * even distribution of progress weight across the tasks in the layers.
1531
+ *
1532
+ * @return {void} Does not return a value.
1426
1533
  */
1427
- constructor(isMeta?: boolean);
1534
+ updateProgressWeights(): void;
1428
1535
  /**
1429
- * Adds tasks or routines to the current execution pipeline. Supports both individual tasks,
1430
- * routines, or arrays of tasks and routines. Handles metadata and execution context management.
1536
+ * Retrieves a mapping of layer indices to sets of tasks within each layer of a subgraph.
1537
+ * This method traverses the task dependencies and organizes tasks by their respective layer indices.
1431
1538
  *
1432
- * @param {Task|GraphRoutine|(Task|GraphRoutine)[]} tasks - The task(s) or routine(s) to be added.
1433
- * It can be a single task, a single routine, or an array of tasks and routines.
1434
- * @param {AnyObject} [context={}] - Optional context object to provide execution trace and metadata.
1435
- * Used to propagate information across task or routine executions.
1436
- * @return {void} - This method does not return a value.
1539
+ * @return {Map<number, Set<Task>>} A map where the key is the layer index (number) and the value is a set of tasks (Set<Task>) belonging to that layer.
1437
1540
  */
1438
- addTasks(tasks: Task | GraphRoutine | (Task | GraphRoutine)[], context?: AnyObject): void;
1541
+ getSubgraphLayers(): Map<number, Set<Task>>;
1439
1542
  /**
1440
- * Executes the provided tasks or routines. Maintains the execution state
1441
- * and handles synchronous or asynchronous processing.
1543
+ * Updates the `layerIndex` of the current task based on the maximum layer index of its predecessors
1544
+ * and propagates the update recursively to all subsequent tasks. If the `layerIndex` changes,
1545
+ * emits a metric event with metadata about the change.
1442
1546
  *
1443
- * @param {Task|GraphRoutine|(Task|GraphRoutine)[]} [tasks] - A single task, a single routine, or an array of tasks or routines to execute. Optional.
1444
- * @param {AnyObject} [context] - An optional context object to be used during task execution.
1445
- * @return {GraphRun|Promise<GraphRun>} - Returns a `GraphRun` instance if the execution is synchronous, or a `Promise` resolving to a `GraphRun` for asynchronous execution.
1547
+ * @return {void} This method does not return a value.
1446
1548
  */
1447
- run(tasks?: Task | GraphRoutine | (Task | GraphRoutine)[], context?: AnyObject): GraphRun | Promise<GraphRun>;
1549
+ updateLayerFromPredecessors(): void;
1448
1550
  /**
1449
- * Executes the provided asynchronous operation and resets the state afterwards.
1551
+ * Determines whether there is a cycle in the tasks graph.
1552
+ * This method performs a depth-first search (DFS) to detect cycles.
1450
1553
  *
1451
- * @param {Promise<void>} run - A promise representing the asynchronous operation to execute.
1452
- * @return {Promise<GraphRun>} A promise that resolves to the result of the reset operation after the asynchronous operation completes.
1554
+ * @return {boolean} - Returns true if a cycle is found in the graph, otherwise false.
1453
1555
  */
1454
- runAsync(run: Promise<void>): Promise<GraphRun>;
1556
+ hasCycle(): boolean;
1455
1557
  /**
1456
- * Resets the current state of the graph, creating a new GraphRun instance
1457
- * and returning the previous run instance.
1458
- * If the debug mode is not enabled, it will destroy the existing resources.
1558
+ * Maps over the next set of tasks or failed tasks if specified, applying the provided callback function.
1459
1559
  *
1460
- * @return {GraphRun} The last GraphRun instance before the reset.
1560
+ * @param {Function} callback A function that will be called with each task, transforming the task as needed. It receives a single parameter of type Task.
1561
+ * @return {any[]} An array of transformed tasks resulting from applying the callback function.
1461
1562
  */
1462
- reset(): GraphRun;
1463
- setDebug(value: boolean): void;
1464
- setVerbose(value: boolean): void;
1465
- destroy(): void;
1563
+ mapNext(callback: (task: Task) => any): any[];
1466
1564
  /**
1467
- * Sets the strategy to be used for running the graph and initializes
1468
- * the current run with the provided strategy if no process is currently running.
1565
+ * Maps through each task in the set of predecessor tasks and applies the provided callback function.
1469
1566
  *
1470
- * @param {GraphRunStrategy} strategy - The strategy to use for running the graph.
1471
- * @return {void}
1567
+ * @param {function} callback - A function to execute on each task in the predecessor tasks. The function receives a `Task` object as its argument and returns any value.
1568
+ * @return {any[]} An array containing the results of applying the callback function to each predecessor task.
1472
1569
  */
1473
- setStrategy(strategy: GraphRunStrategy): void;
1474
- }
1475
-
1476
- interface EmitOptions {
1477
- squash?: boolean;
1478
- squashId?: string | null;
1479
- groupId?: string | null;
1480
- mergeFunction?: ((oldContext: AnyObject, ...newContext: AnyObject[]) => AnyObject) | null;
1481
- debounce?: boolean;
1482
- throttle?: boolean;
1483
- delayMs?: number;
1484
- schedule?: boolean;
1485
- exactDateTime?: Date | null;
1486
- throttleBatch?: number;
1487
- flushStrategy?: string;
1488
- }
1489
- type SignalDeliveryMode = "single" | "broadcast";
1490
- type SignalReceiverFilter = {
1491
- serviceNames?: string[];
1492
- serviceInstanceIds?: string[];
1493
- origins?: string[];
1494
- roles?: string[];
1495
- protocols?: string[];
1496
- runtimeStates?: string[];
1497
- };
1498
- type SignalMetadata = {
1499
- deliveryMode?: SignalDeliveryMode;
1500
- broadcastFilter?: SignalReceiverFilter | null;
1501
- };
1502
- type SignalDefinitionInput = string | ({
1503
- name: string;
1504
- } & SignalMetadata);
1505
- type FlushStrategyName = string;
1506
- interface FlushStrategy {
1507
- intervalMs: number;
1508
- maxBatchSize: number;
1509
- }
1510
- /**
1511
- * This class manages signals and observers, enabling communication across different parts of an application.
1512
- * It follows a singleton design pattern, allowing for centralized signal management.
1513
- */
1514
- declare class SignalBroker {
1515
- static instance_: SignalBroker;
1516
- static get instance(): SignalBroker;
1517
- debug: boolean;
1518
- verbose: boolean;
1519
- setDebug(value: boolean): void;
1520
- setVerbose(value: boolean): void;
1521
- runner: GraphRunner | undefined;
1522
- metaRunner: GraphRunner | undefined;
1523
- throttleEmitters: Map<string, any>;
1524
- throttleQueues: Map<string, any>;
1525
- getSignalsTask: Task | undefined;
1526
- registerSignalTask: Task | undefined;
1527
- signalObservers: Map<string, {
1528
- fn: (runner: GraphRunner, tasks: (Task | GraphRoutine)[], context: AnyObject) => void;
1529
- tasks: Set<Task | GraphRoutine>;
1530
- registered: boolean;
1531
- }>;
1532
- emittedSignalsRegistry: Set<string>;
1533
- signalMetadataRegistry: Map<string, SignalMetadata>;
1534
- private flushStrategies;
1535
- private strategyData;
1536
- private strategyTimers;
1537
- private isStrategyFlushing;
1538
- private readonly defaultStrategyName;
1539
- constructor();
1540
- private resolveSignalMetadataKey;
1541
- private normalizeSignalMetadata;
1542
- setSignalMetadata(signal: string, metadata?: SignalMetadata | null): void;
1543
- getSignalMetadata(signal: string): SignalMetadata | undefined;
1544
- logMemoryFootprint(label?: string): void;
1570
+ mapPrevious(callback: (task: Task) => any): any[];
1571
+ makeRoutine(name: string, description: string): this;
1572
+ /**
1573
+ * Adds the specified signals to the current instance, making it observe them.
1574
+ * If the instance is already observing a signal, it will be skipped.
1575
+ * The method also emits metadata information if the `register` property is set.
1576
+ *
1577
+ * @param {...string[]} signals - The array of signal names to observe.
1578
+ * @return {this} The current instance after adding the specified signals.
1579
+ */
1580
+ doOn(...signals: SignalDefinitionInput[]): this;
1581
+ /**
1582
+ * Registers the specified signals to be emitted after the Task executes successfully and attaches them for further processing.
1583
+ *
1584
+ * @param {...string} signals - The list of signals to be registered for emission.
1585
+ * @return {this} The current instance for method chaining.
1586
+ */
1587
+ emits(...signals: SignalDefinitionInput[]): this;
1588
+ /**
1589
+ * Configures the instance to emit specified signals when the task execution fails.
1590
+ * A failure is defined as anything that does not return a successful result.
1591
+ *
1592
+ * @param {...string} signals - The names of the signals to emit upon failure.
1593
+ * @return {this} Returns the current instance for chaining.
1594
+ */
1595
+ emitsOnFail(...signals: SignalDefinitionInput[]): this;
1596
+ /**
1597
+ * Attaches a signal to the current context and emits metadata if the register flag is set.
1598
+ *
1599
+ * @param {...string} signals - The names of the signals to attach.
1600
+ * @return {void} This method does not return a value.
1601
+ */
1602
+ attachSignal(...signals: SignalDefinitionInput[]): Task;
1545
1603
  /**
1546
- * Validates the provided signal name string to ensure it adheres to specific formatting rules.
1547
- * Throws an error if any of the validation checks fail.
1604
+ * Unsubscribes the current instance from the specified signals.
1605
+ * This method removes the signals from the observedSignals set, unsubscribes
1606
+ * from the underlying broker, and emits metadata for the unsubscription if applicable.
1548
1607
  *
1549
- * @param {string} signalName - The signal name to be validated.
1550
- * @return {void} - Returns nothing if the signal name is valid.
1551
- * @throws {Error} - Throws an error if the signal name is longer than 100 characters, contains spaces,
1552
- * contains backslashes, or contains uppercase letters in restricted parts of the name.
1608
+ * @param {string[]} signals - The list of signal names to unsubscribe from.
1609
+ * @return {this} Returns the current instance for method chaining.
1553
1610
  */
1554
- validateSignalName(signalName: string): void;
1611
+ unsubscribe(...signals: string[]): this;
1555
1612
  /**
1556
- * Initializes with runners.
1557
- * @param runner Standard runner for user signals.
1558
- * @param metaRunner Meta runner for 'meta.' signals (suppresses further meta-emits).
1613
+ * Unsubscribes from all currently observed signals and clears the list of observed signals.
1614
+ *
1615
+ * @return {this} The instance of the class to allow method chaining.
1559
1616
  */
1560
- bootstrap(runner: GraphRunner, metaRunner: GraphRunner): void;
1617
+ unsubscribeAll(): this;
1561
1618
  /**
1562
- * Initializes and sets up the various tasks for managing and processing signals.
1619
+ * Detaches the specified signals from being emitted after execution and optionally emits metadata for each detached signal.
1563
1620
  *
1564
- * @return {void} This method does not return a value.
1621
+ * @param {...string} signals - The list of signal names to be detached. Signals can be in the format "namespace:signalName".
1622
+ * @return {this} Returns the current instance of the object for method chaining.
1565
1623
  */
1566
- init(): void;
1567
- setFlushStrategy(name: FlushStrategyName, config: {
1568
- intervalMs: number;
1569
- maxBatchSize?: number;
1570
- }): void;
1571
- updateFlushStrategy(name: FlushStrategyName, config: FlushStrategy): void;
1572
- removeFlushStrategy(name: FlushStrategyName): void;
1573
- getFlushStrategies(): Record<FlushStrategyName, FlushStrategy>;
1574
- private readonly MAX_FLUSH_DURATION_MS;
1575
- squash(signal: string, context: AnyObject, options?: EmitOptions): void;
1576
- private flushGroup;
1577
- private flushStrategy;
1578
- clearSquashState(): void;
1579
- private clearScheduledState;
1580
- private scheduledBuckets;
1581
- private scheduleTimer;
1582
- schedule(signal: string, context: AnyObject, options?: EmitOptions): AbortController;
1583
- private flushScheduled;
1584
- private debouncedEmitters;
1585
- private readonly MAX_DEBOUNCERS;
1586
- private clearDebounceState;
1587
- private clearThrottleState;
1588
- debounce(signal: string, context: any, options?: {
1589
- delayMs: number;
1590
- }): void;
1591
- throttle(signal: string, context: any, options?: EmitOptions): void;
1624
+ detachSignals(...signals: string[]): this;
1592
1625
  /**
1593
- * Emits `signal` repeatedly with a fixed interval.
1626
+ * Detaches all signals associated with the object by invoking the `detachSignals` method
1627
+ * and clearing the `signalsToEmitAfter` collection.
1594
1628
  *
1595
- * @param signal
1596
- * @param context
1597
- * @param intervalMs
1598
- * @param leading If true, emits immediately (unless a startDateTime is given and we are before it).
1599
- * @param startDateTime Optional absolute Date when the *first* emission after `leading` should occur.
1600
- * @returns a handle with `clear()` to stop the loop.
1629
+ * @return {this} Returns the current instance to allow method chaining.
1601
1630
  */
1602
- interval(signal: string, context: AnyObject, intervalMs?: number, leading?: boolean, startDateTime?: Date): ThrottleHandle;
1631
+ detachAllSignals(): this;
1632
+ respondsTo(...inquires: string[]): this;
1633
+ usesHelpers(helpers: Record<string, HelperDefinition | undefined>): this;
1634
+ usesGlobals(globals: Record<string, GlobalDefinition | undefined>): this;
1635
+ attachIntents(...intentNames: string[]): this;
1636
+ detachIntents(...intentNames: string[]): this;
1637
+ detachAllIntents(): this;
1603
1638
  /**
1604
- * Emits a signal with the specified context, triggering any associated handlers for that signal.
1639
+ * Maps over the signals in the `signalsToEmitAfter` set and applies a callback function to each signal.
1605
1640
  *
1606
- * @param {string} signal - The name of the signal to emit.
1607
- * @param {AnyObject} [context={}] - An optional context object containing additional information or metadata
1608
- * associated with the signal. If the context includes a `__routineExecId`, it will be handled accordingly.
1609
- * @param options
1610
- * @return {void} This method does not return a value.
1641
+ * @param {function(string): void} callback - A function that is called with each signal
1642
+ * in the `signalsToEmitAfter` set, providing the signal as an argument.
1643
+ * @return {Array<any>} An array containing the results of applying the callback
1644
+ * function to each signal.
1611
1645
  */
1612
- emit(signal: string, context?: AnyObject, options?: EmitOptions): void;
1646
+ mapSignals(callback: (signal: string) => void): void[];
1613
1647
  /**
1614
- * Executes a signal by emitting events, updating context, and invoking listeners.
1615
- * Creates a new execution trace if necessary and updates the context with relevant metadata.
1616
- * Handles specific, hierarchy-based, and wildcard signals.
1648
+ * Maps over the signals in `signalsToEmitOnFail` and applies the provided callback to each signal.
1617
1649
  *
1618
- * @param {string} signal - The signal name to be executed, potentially including namespaces or tags (e.g., "meta.*" or "signal:type").
1619
- * @param {AnyObject} context - An object containing relevant metadata and execution details used for handling the signal.
1620
- * @return {boolean} Returns true if any listeners were successfully executed, otherwise false.
1650
+ * @param {function(string): void} callback - A function that receives each signal as a string and performs an operation or transformation on it.
1651
+ * @return {Array} The array resulting from applying the callback to each signal in `signalsToEmitOnFail`.
1621
1652
  */
1622
- execute(signal: string, context: AnyObject): boolean;
1653
+ mapOnFailSignals(callback: (signal: string) => void): void[];
1623
1654
  /**
1624
- * Executes the tasks associated with a given signal and context.
1625
- * It processes both normal and meta tasks depending on the signal type
1626
- * and the availability of the appropriate runner.
1655
+ * Maps over the observed signals with the provided callback function.
1627
1656
  *
1628
- * @param {string} signal - The signal identifier that determines which tasks to execute.
1629
- * @param {AnyObject} context - The context object passed to the task execution function.
1630
- * @return {boolean} - Returns true if tasks were executed; otherwise, false.
1657
+ * @param {function(string): void} callback - A function to execute on each signal in the observed signals array.
1658
+ * @return {Array} A new array containing the results of calling the callback function on each observed signal.
1631
1659
  */
1632
- executeListener(signal: string, context: AnyObject): boolean;
1660
+ mapObservedSignals(callback: (signal: string) => void): void[];
1633
1661
  /**
1634
- * Adds a signal to the signalObservers for tracking and execution.
1635
- * Performs validation on the signal name and emits a meta signal event when added.
1636
- * If the signal contains a namespace (denoted by a colon ":"), its base signal is
1637
- * also added if it doesn't already exist.
1662
+ * Emits a collection of signals stored in the `signalsToEmitAfter` array.
1638
1663
  *
1639
- * @param {string} signal - The name of the signal to be added.
1664
+ * @param {GraphContext} context - The context object containing data or state to be passed to the emitted signals.
1665
+ * @return {void} This method does not return a value.
1666
+ */
1667
+ emitSignals(context: GraphContext): void;
1668
+ /**
1669
+ * Emits registered signals when an operation fails.
1670
+ *
1671
+ * @param {GraphContext} context - The context from which the full context is derived and passed to the signals being emitted.
1640
1672
  * @return {void} This method does not return any value.
1641
1673
  */
1642
- addSignal(signal: string, metadata?: SignalMetadata | null): void;
1674
+ emitOnFailSignals(context: GraphContext): void;
1643
1675
  /**
1644
- * Observes a signal with a routine/task.
1645
- * @param signal The signal (e.g., 'domain.action', 'domain.*' for wildcards).
1646
- * @param routineOrTask The observer.
1647
- * @edge Duplicates ignored; supports wildcards for broad listening.
1676
+ * Cleans up and destroys the task instance, detaching it from other tasks and
1677
+ * performing necessary cleanup operations.
1678
+ *
1679
+ * This method:
1680
+ * - Unsubscribes from all signals and events.
1681
+ * - Detaches all associated signal handlers.
1682
+ * - Removes the task from successor and predecessor task mappings.
1683
+ * - Clears all task relationships and marks the task as destroyed.
1684
+ * - Emits destruction metrics, if applicable.
1685
+ *
1686
+ * @return {void} No value is returned because the function performs clean-up operations.
1648
1687
  */
1649
- observe(signal: string, routineOrTask: Task | GraphRoutine, metadata?: SignalMetadata | null): void;
1650
- registerEmittedSignal(signal: string, metadata?: SignalMetadata | null): void;
1688
+ destroy(): void;
1651
1689
  /**
1652
- * Unsubscribes a routine/task from a signal.
1653
- * @param signal The signal.
1654
- * @param routineOrTask The observer.
1655
- * @edge Removes all instances if duplicate; deletes if empty.
1690
+ * Exports the current state of the object as a structured plain object.
1691
+ *
1692
+ * @return {AnyObject} An object containing the serialized properties of the current instance. The exported object includes various metadata, schema information, task attributes, and related tasks, such as:
1693
+ * - Name and description of the task.
1694
+ * - Layer index, uniqueness, meta, and signal-related flags.
1695
+ * - Event triggers and attached signals.
1696
+ * - Throttling, concurrency, timeout settings, and ephemeral flag.
1697
+ * - Task function as a string.
1698
+ * - Serialization of getter callbacks and schemas for input/output validation.
1699
+ * - Relationships such as next tasks, failure tasks, and predecessor tasks.
1656
1700
  */
1657
- unsubscribe(signal: string, routineOrTask: Task | GraphRoutine): void;
1701
+ export(): AnyObject;
1658
1702
  /**
1659
- * Lists all observed signals.
1660
- * @returns Array of signals.
1703
+ * Returns an iterator for iterating over tasks associated with this instance.
1704
+ *
1705
+ * @return {TaskIterator} An iterator instance for tasks.
1661
1706
  */
1662
- listObservedSignals(): string[];
1663
- listEmittedSignals(): string[];
1664
- reset(): void;
1665
- shutdown(): void;
1707
+ getIterator(): TaskIterator;
1708
+ /**
1709
+ * Accepts a visitor object to perform operations on the current instance.
1710
+ *
1711
+ * @param {GraphVisitor} visitor - The visitor object implementing operations for this instance.
1712
+ * @return {void} This method does not return a value.
1713
+ */
1714
+ accept(visitor: GraphVisitor): void;
1715
+ log(): void;
1666
1716
  }
1667
1717
 
1668
1718
  /**
@@ -1794,7 +1844,7 @@ declare class EphemeralTask extends Task {
1794
1844
  execute(context: any, emit: (signal: string, context: AnyObject) => void, inquire: (inquiry: string, context: AnyObject, options: InquiryOptions) => Promise<AnyObject>, progressCallback: (progress: number) => void, nodeData: {
1795
1845
  nodeId: string;
1796
1846
  routineExecId: string;
1797
- }): TaskResult;
1847
+ }): boolean | void | AnyObject | Generator<unknown, any, any> | Promise<any>;
1798
1848
  }
1799
1849
 
1800
1850
  /**
@@ -2071,11 +2121,12 @@ interface ActorTaskContext<D extends Record<string, any>, R = AnyObject> {
2071
2121
  reduceRuntimeState: (reducer: ActorStateReducer<R>) => void;
2072
2122
  emit: (signal: string, payload?: AnyObject) => void;
2073
2123
  inquire: (inquiry: string, context?: AnyObject, options?: InquiryOptions) => Promise<AnyObject>;
2124
+ tools: RuntimeTools;
2074
2125
  }
2075
2126
  /**
2076
2127
  * Handler signature used by `actor.task(...)`.
2077
2128
  */
2078
- type ActorTaskHandler<D extends Record<string, any>, R = AnyObject> = (context: ActorTaskContext<D, R>) => TaskResult | ActorStateReducer<D> | Promise<TaskResult | ActorStateReducer<D>>;
2129
+ type ActorTaskHandler<D extends Record<string, any>, R = AnyObject> = (context: ActorTaskContext<D, R>, emit: (signal: string, payload?: AnyObject) => void, inquire: (inquiry: string, context?: AnyObject, options?: InquiryOptions) => Promise<AnyObject>, tools: RuntimeTools, progressCallback: (progress: number) => void) => TaskResult | ActorStateReducer<D> | Promise<TaskResult | ActorStateReducer<D>>;
2079
2130
  interface ActorDurableStateHydration<D extends Record<string, any>> {
2080
2131
  durableState: D;
2081
2132
  durableVersion: number;
@@ -2133,6 +2184,10 @@ declare class Actor<D extends Record<string, any> = AnyObject, R = AnyObject> {
2133
2184
  * Returns runtime state reference for the resolved key.
2134
2185
  */
2135
2186
  getRuntimeState(actorKey?: string): R;
2187
+ /**
2188
+ * Lists all currently materialized actor keys.
2189
+ */
2190
+ listActorKeys(): string[];
2136
2191
  /**
2137
2192
  * Alias of `getDurableVersion`.
2138
2193
  */
@@ -2172,6 +2227,250 @@ declare class Actor<D extends Record<string, any> = AnyObject, R = AnyObject> {
2172
2227
  private emitActorCreatedSignal;
2173
2228
  }
2174
2229
 
2230
+ type RuntimeHandlerLanguage = "js" | "ts";
2231
+ type RuntimeTaskDefinitionKind = "task" | "metaTask";
2232
+ type RuntimeHelperDefinitionKind = "helper" | "metaHelper";
2233
+ type RuntimeGlobalDefinitionKind = "global" | "metaGlobal";
2234
+ type RuntimeSignalEmissionMode = "attach" | "after" | "onFail";
2235
+ type RuntimeSharingMode = "isolated" | "shared";
2236
+ type RuntimeSessionRole = "owner" | "writer" | "observer";
2237
+ type RuntimeTaskOptions = Omit<TaskOptions, "getTagCallback">;
2238
+ interface RuntimeTaskDefinition {
2239
+ name: string;
2240
+ description?: string;
2241
+ handlerSource: string;
2242
+ language: RuntimeHandlerLanguage;
2243
+ kind?: RuntimeTaskDefinitionKind;
2244
+ options?: RuntimeTaskOptions;
2245
+ }
2246
+ interface RuntimeHelperDefinition {
2247
+ name: string;
2248
+ description?: string;
2249
+ handlerSource: string;
2250
+ language: RuntimeHandlerLanguage;
2251
+ kind?: RuntimeHelperDefinitionKind;
2252
+ }
2253
+ interface RuntimeGlobalDefinition {
2254
+ name: string;
2255
+ description?: string;
2256
+ value: unknown;
2257
+ kind?: RuntimeGlobalDefinitionKind;
2258
+ }
2259
+ interface RuntimeRoutineDefinition {
2260
+ name: string;
2261
+ description?: string;
2262
+ startTaskNames: string[];
2263
+ isMeta?: boolean;
2264
+ }
2265
+ interface RuntimeActorTaskDefinition {
2266
+ actorName: string;
2267
+ taskName: string;
2268
+ description?: string;
2269
+ mode?: ActorTaskMode;
2270
+ handlerSource: string;
2271
+ language: RuntimeHandlerLanguage;
2272
+ options?: RuntimeTaskOptions;
2273
+ }
2274
+ interface RuntimeTaskLinkDefinition {
2275
+ predecessorTaskName: string;
2276
+ successorTaskName: string;
2277
+ }
2278
+ interface RuntimeSnapshotTask {
2279
+ name: string;
2280
+ version: number;
2281
+ description: string;
2282
+ kind: "task" | "metaTask" | "actorTask";
2283
+ runtimeOwned: boolean;
2284
+ language: RuntimeHandlerLanguage | null;
2285
+ handlerSource: string | null;
2286
+ concurrency: number;
2287
+ timeout: number;
2288
+ retryCount: number;
2289
+ retryDelay: number;
2290
+ retryDelayMax: number;
2291
+ retryDelayFactor: number;
2292
+ validateInputContext: boolean;
2293
+ validateOutputContext: boolean;
2294
+ inputContextSchema: Record<string, unknown>;
2295
+ outputContextSchema: Record<string, unknown>;
2296
+ nextTaskNames: string[];
2297
+ predecessorTaskNames: string[];
2298
+ signals: {
2299
+ emits: string[];
2300
+ emitsAfter: string[];
2301
+ emitsOnFail: string[];
2302
+ observed: string[];
2303
+ };
2304
+ intents: {
2305
+ handles: string[];
2306
+ inquires: string[];
2307
+ };
2308
+ tools: {
2309
+ helpers: Record<string, string>;
2310
+ globals: Record<string, string>;
2311
+ };
2312
+ actorName: string | null;
2313
+ actorMode: ActorTaskMode | null;
2314
+ }
2315
+ interface RuntimeSnapshotHelper {
2316
+ name: string;
2317
+ version: number;
2318
+ description: string;
2319
+ kind: "helper" | "metaHelper";
2320
+ runtimeOwned: boolean;
2321
+ language: RuntimeHandlerLanguage | null;
2322
+ handlerSource: string | null;
2323
+ tools: {
2324
+ helpers: Record<string, string>;
2325
+ globals: Record<string, string>;
2326
+ };
2327
+ }
2328
+ interface RuntimeSnapshotGlobal {
2329
+ name: string;
2330
+ version: number;
2331
+ description: string;
2332
+ kind: "global" | "metaGlobal";
2333
+ runtimeOwned: boolean;
2334
+ value: unknown;
2335
+ }
2336
+ interface RuntimeSnapshotRoutine {
2337
+ name: string;
2338
+ version: number;
2339
+ description: string;
2340
+ isMeta: boolean;
2341
+ runtimeOwned: boolean;
2342
+ startTaskNames: string[];
2343
+ observedSignals: string[];
2344
+ }
2345
+ interface RuntimeSnapshotIntent extends Intent {
2346
+ runtimeOwned: boolean;
2347
+ }
2348
+ interface RuntimeSnapshotSignal {
2349
+ name: string;
2350
+ metadata: SignalMetadata | null;
2351
+ }
2352
+ interface RuntimeSnapshotActorKeyState {
2353
+ actorKey: string;
2354
+ durableState: unknown;
2355
+ runtimeState: unknown;
2356
+ durableVersion: number;
2357
+ runtimeVersion: number;
2358
+ }
2359
+ interface RuntimeSnapshotActor {
2360
+ name: string;
2361
+ description: string;
2362
+ runtimeOwned: boolean;
2363
+ definition: ActorDefinition<Record<string, any>, AnyObject>;
2364
+ actorKeys: RuntimeSnapshotActorKeyState[];
2365
+ }
2366
+ interface RuntimeSnapshotActorTask {
2367
+ actorName: string;
2368
+ taskName: string;
2369
+ description: string;
2370
+ mode: ActorTaskMode;
2371
+ language: RuntimeHandlerLanguage;
2372
+ handlerSource: string;
2373
+ runtimeOwned: boolean;
2374
+ }
2375
+ interface RuntimeSnapshot {
2376
+ runtimeMode: "core";
2377
+ bootstrapped: boolean;
2378
+ mode: string;
2379
+ tasks: RuntimeSnapshotTask[];
2380
+ helpers: RuntimeSnapshotHelper[];
2381
+ globals: RuntimeSnapshotGlobal[];
2382
+ routines: RuntimeSnapshotRoutine[];
2383
+ intents: RuntimeSnapshotIntent[];
2384
+ signals: RuntimeSnapshotSignal[];
2385
+ actors: RuntimeSnapshotActor[];
2386
+ actorTasks: RuntimeSnapshotActorTask[];
2387
+ links: RuntimeTaskLinkDefinition[];
2388
+ }
2389
+ interface RuntimeSubscription {
2390
+ subscriptionId: string;
2391
+ signalPatterns: string[];
2392
+ maxQueueSize: number;
2393
+ createdAt: string;
2394
+ pendingEvents: number;
2395
+ }
2396
+ interface RuntimeSignalEventSource {
2397
+ taskName: string | null;
2398
+ taskVersion: number | null;
2399
+ taskExecutionId: string | null;
2400
+ routineName: string | null;
2401
+ routineVersion: number | null;
2402
+ routineExecutionId: string | null;
2403
+ executionTraceId: string | null;
2404
+ consumed: boolean;
2405
+ consumedBy: string | null;
2406
+ }
2407
+ interface RuntimeSignalEvent {
2408
+ id: string;
2409
+ subscriptionId: string;
2410
+ sequence: number;
2411
+ type: "signal";
2412
+ signal: string;
2413
+ signalName: string;
2414
+ signalTag: string | null;
2415
+ emittedAt: string | null;
2416
+ isMeta: boolean;
2417
+ isSubMeta: boolean;
2418
+ metadata: SignalMetadata | null;
2419
+ source: RuntimeSignalEventSource;
2420
+ context: Record<string, unknown>;
2421
+ }
2422
+ interface RuntimeNextEventResult {
2423
+ subscriptionId: string;
2424
+ event: RuntimeSignalEvent | null;
2425
+ timedOut: boolean;
2426
+ pendingEvents: number;
2427
+ }
2428
+ interface RuntimePollEventsResult {
2429
+ subscriptionId: string;
2430
+ events: RuntimeSignalEvent[];
2431
+ pendingEvents: number;
2432
+ }
2433
+ interface RuntimeInfo {
2434
+ runtimeMode: "core";
2435
+ runtimeSharing: RuntimeSharingMode;
2436
+ runtimeName: string | null;
2437
+ sessionId: string | null;
2438
+ sessionRole: RuntimeSessionRole | null;
2439
+ activeSessionCount: number;
2440
+ daemonProcessId: number | null;
2441
+ bootstrapped: boolean;
2442
+ mode: string;
2443
+ }
2444
+ type RuntimeProtocolOperation = "runtime.bootstrap" | "runtime.info" | "runtime.detach" | "runtime.shutdown" | "runtime.reset" | "runtime.snapshot" | "runtime.subscribe" | "runtime.unsubscribe" | "runtime.nextEvent" | "runtime.pollEvents" | "task.upsert" | "helper.upsert" | "global.upsert" | "task.link" | "task.observeSignal" | "task.emitSignal" | "task.respondToIntent" | "task.useHelper" | "task.useGlobal" | "helper.useHelper" | "helper.useGlobal" | "routine.upsert" | "routine.observeSignal" | "intent.upsert" | "actor.upsert" | "actorTask.upsert" | "run" | "emit" | "inquire";
2445
+ interface RuntimeProtocolRequest<TPayload = AnyObject> {
2446
+ id?: string | number;
2447
+ operation: RuntimeProtocolOperation;
2448
+ payload?: TPayload;
2449
+ }
2450
+ interface RuntimeProtocolError {
2451
+ code: string;
2452
+ message: string;
2453
+ details?: AnyObject;
2454
+ }
2455
+ interface RuntimeProtocolResponse<TResult = unknown> {
2456
+ id?: string | number;
2457
+ operation: RuntimeProtocolOperation;
2458
+ ok: boolean;
2459
+ result?: TResult;
2460
+ error?: RuntimeProtocolError;
2461
+ }
2462
+ interface RuntimeProtocolHandshake {
2463
+ ready: true;
2464
+ protocol: "cadenza-runtime-jsonl";
2465
+ protocolVersion: "1";
2466
+ runtimeMode: "core";
2467
+ runtimeSharing: RuntimeSharingMode;
2468
+ runtimeName: string | null;
2469
+ sessionId: string | null;
2470
+ sessionRole: RuntimeSessionRole | null;
2471
+ supportedOperations: RuntimeProtocolOperation[];
2472
+ }
2473
+
2175
2474
  interface TaskOptions {
2176
2475
  concurrency?: number;
2177
2476
  timeout?: number;
@@ -2230,11 +2529,15 @@ declare class Cadenza {
2230
2529
  static metaRunner: GraphRunner;
2231
2530
  static registry: GraphRegistry;
2232
2531
  private static taskCache;
2532
+ private static routineCache;
2233
2533
  private static actorCache;
2534
+ private static helperCache;
2535
+ private static globalCache;
2234
2536
  private static runtimeInquiryDelegate;
2235
2537
  private static runtimeValidationPolicy;
2236
2538
  private static runtimeValidationScopes;
2237
2539
  private static emittedMissingSchemaWarnings;
2540
+ private static helperExecutionDepth;
2238
2541
  static isBootstrapped: boolean;
2239
2542
  static mode: CadenzaMode;
2240
2543
  /**
@@ -2274,8 +2577,15 @@ declare class Cadenza {
2274
2577
  * @throws {Error} If the name is not a non-empty string.
2275
2578
  */
2276
2579
  static validateName(name: string): void;
2580
+ static assertGraphMutationAllowed(operationName: string): void;
2581
+ static executeHelper(helper: HelperDefinition, context: AnyObject, emit: (signal: string, context: AnyObject) => void, inquire: (inquiry: string, context: AnyObject, options: InquiryOptions) => Promise<AnyObject>, progressCallback: (progress: number) => void): TaskResult;
2582
+ static resolveToolsForOwner(owner: ToolDependencyOwner, context: AnyObject, emit: (signal: string, context: AnyObject) => void, inquire: (inquiry: string, context: AnyObject, options: InquiryOptions) => Promise<AnyObject>, progressCallback: (progress: number) => void): RuntimeTools;
2277
2583
  private static resolveTaskOptionsForActorTask;
2278
2584
  private static registerActor;
2585
+ static getHelper(name: string): HelperDefinition | undefined;
2586
+ static getAllHelpers(): HelperDefinition[];
2587
+ static getGlobal(name: string): GlobalDefinition | undefined;
2588
+ static getAllGlobals(): GlobalDefinition[];
2279
2589
  /**
2280
2590
  * Executes the specified task or GraphRoutine with the given context using an internal runner.
2281
2591
  *
@@ -2317,6 +2627,7 @@ declare class Cadenza {
2317
2627
  static interval(taskName: string, context: AnyObject, intervalMs: number, leading?: boolean, startDateTime?: Date): void;
2318
2628
  static debounce(signalName: string, context: any, delayMs: number): void;
2319
2629
  static get(taskName: string): Task | undefined;
2630
+ static forgetTask(taskName: string): void;
2320
2631
  static getActor<D extends Record<string, any> = AnyObject, R = AnyObject>(actorName: string): Actor<D, R> | undefined;
2321
2632
  static getAllActors<D extends Record<string, any> = AnyObject, R = AnyObject>(): Actor<D, R>[];
2322
2633
  static getRoutine(routineName: string): GraphRoutine | undefined;
@@ -2422,6 +2733,13 @@ declare class Cadenza {
2422
2733
  * ```
2423
2734
  */
2424
2735
  static createTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions): Task;
2736
+ static createTaskFromDefinition(definition: RuntimeTaskDefinition): Task;
2737
+ static createHelper(name: string, func: HelperFunction, description?: string): HelperDefinition;
2738
+ static createMetaHelper(name: string, func: HelperFunction, description?: string): HelperDefinition;
2739
+ static createHelperFromDefinition(definition: RuntimeHelperDefinition): HelperDefinition;
2740
+ static createGlobal(name: string, value: unknown, description?: string): GlobalDefinition;
2741
+ static createMetaGlobal(name: string, value: unknown, description?: string): GlobalDefinition;
2742
+ static createGlobalFromDefinition(definition: RuntimeGlobalDefinition): GlobalDefinition;
2425
2743
  /**
2426
2744
  * Creates a meta task with the specified name, functionality, description, and options.
2427
2745
  * This is used for creating tasks that lives on the meta layer.
@@ -2684,6 +3002,7 @@ declare class Cadenza {
2684
3002
  * ```
2685
3003
  */
2686
3004
  static createRoutine(name: string, tasks: Task[], description?: string): GraphRoutine;
3005
+ static createRoutineFromDefinition(definition: RuntimeRoutineDefinition): GraphRoutine;
2687
3006
  /**
2688
3007
  * Creates a meta routine with a given name, tasks, and optional description.
2689
3008
  * Routines are named entry points to starting tasks and are registered in the GraphRegistry.
@@ -2697,7 +3016,83 @@ declare class Cadenza {
2697
3016
  * @throws {Error} If no starting tasks are provided.
2698
3017
  */
2699
3018
  static createMetaRoutine(name: string, tasks: Task[], description?: string): GraphRoutine;
3019
+ static snapshotRuntime(): RuntimeSnapshot;
2700
3020
  static reset(): void;
2701
3021
  }
2702
3022
 
2703
- export { Actor, type ActorConsistencyProfileName, type ActorDefinition, type ActorFactoryOptions, type ActorInvocationOptions, type ActorKeyDefinition, type ActorKind, type ActorLoadPolicy, type ActorRuntimeReadGuard, type ActorSpec, type ActorStateDefinition, type ActorStateReducer, type ActorStateStore, type ActorTaskBindingDefinition, type ActorTaskBindingOptions, type ActorTaskContext, type ActorTaskHandler, type ActorTaskMode, type ActorTaskRuntimeMetadata, type ActorWriteContract, type AnyObject, type CadenzaMode, type DebounceOptions, DebounceTask, type EmitOptions, EphemeralTask, type EphemeralTaskOptions, GraphContext, GraphRegistry, GraphRoutine, GraphRun, GraphRunner, type IdempotencyPolicy, InquiryBroker, type InquiryOptions, type Intent, META_ACTOR_SESSION_STATE_PERSIST_INTENT, type ResolvedRuntimeValidationPolicy, type RetryPolicy, type RuntimeValidationMode, type RuntimeValidationPolicy, type RuntimeValidationScope, type Schema, type SchemaConstraints, type SchemaDefinition, type SchemaType, type SessionPolicy, SignalBroker, type SignalDefinitionInput, type SignalDeliveryMode, SignalEmitter, type SignalMetadata, type SignalReceiverFilter, Task, type TaskFunction, type TaskOptions, type TaskResult, type ThrottleTagGetter, Cadenza as default, getActorTaskRuntimeMetadata };
3023
+ type RuntimeControlAction = "detach" | "shutdown";
3024
+ interface RuntimeHostOptions {
3025
+ runtimeSharing?: RuntimeSharingMode;
3026
+ runtimeName?: string | null;
3027
+ sessionId?: string | null;
3028
+ sessionRole?: RuntimeSessionRole | null;
3029
+ activeSessionCountProvider?: () => number;
3030
+ daemonProcessId?: number | null;
3031
+ onResetRuntime?: () => void;
3032
+ }
3033
+ declare class RuntimeHost {
3034
+ private readonly subscriptionManager;
3035
+ private readonly runtimeSharing;
3036
+ private readonly runtimeName;
3037
+ private readonly sessionId;
3038
+ private readonly sessionRole;
3039
+ private readonly activeSessionCountProvider;
3040
+ private readonly daemonProcessId;
3041
+ private readonly onResetRuntime;
3042
+ private pendingControlAction;
3043
+ constructor(options?: RuntimeHostOptions);
3044
+ dispose(): void;
3045
+ resetSubscriptions(): void;
3046
+ consumeControlAction(): RuntimeControlAction | null;
3047
+ handshake(): RuntimeProtocolHandshake;
3048
+ handle(request: RuntimeProtocolRequest): Promise<RuntimeProtocolResponse>;
3049
+ private normalizeError;
3050
+ private dispatch;
3051
+ private assertOperationAllowed;
3052
+ private bootstrapRuntime;
3053
+ private runtimeInfo;
3054
+ private detachRuntime;
3055
+ private shutdownRuntime;
3056
+ private resetRuntime;
3057
+ private subscribe;
3058
+ private unsubscribe;
3059
+ private nextEvent;
3060
+ private pollEvents;
3061
+ private upsertTask;
3062
+ private upsertHelper;
3063
+ private upsertGlobal;
3064
+ private linkTasks;
3065
+ private observeTaskSignal;
3066
+ private emitTaskSignal;
3067
+ private bindTaskIntent;
3068
+ private bindTaskHelper;
3069
+ private bindTaskGlobal;
3070
+ private bindHelperHelper;
3071
+ private bindHelperGlobal;
3072
+ private upsertRoutine;
3073
+ private observeRoutineSignal;
3074
+ private upsertIntent;
3075
+ private upsertActor;
3076
+ private upsertActorTask;
3077
+ private runTarget;
3078
+ private emitSignal;
3079
+ private inquireIntent;
3080
+ private requireTask;
3081
+ private requireRoutine;
3082
+ private applyTaskDecorations;
3083
+ private applyHelperDecorations;
3084
+ private applyAllTaskLinks;
3085
+ private applyRoutineDecorations;
3086
+ private rematerializeRoutinesStartingWith;
3087
+ private rematerializeActorTasksFor;
3088
+ private materializeActorTask;
3089
+ private snapshotTask;
3090
+ private snapshotHelper;
3091
+ private snapshotGlobal;
3092
+ private snapshotRoutine;
3093
+ private parseSignalPatterns;
3094
+ private parsePositiveInteger;
3095
+ private parseNonNegativeInteger;
3096
+ }
3097
+
3098
+ export { Actor, type ActorConsistencyProfileName, type ActorDefinition, type ActorFactoryOptions, type ActorInvocationOptions, type ActorKeyDefinition, type ActorKind, type ActorLoadPolicy, type ActorRuntimeReadGuard, type ActorSpec, type ActorStateDefinition, type ActorStateReducer, type ActorStateStore, type ActorTaskBindingDefinition, type ActorTaskBindingOptions, type ActorTaskContext, type ActorTaskHandler, type ActorTaskMode, type ActorTaskRuntimeMetadata, type ActorWriteContract, type AnyObject, type CadenzaMode, type DebounceOptions, DebounceTask, type EmitOptions, EphemeralTask, type EphemeralTaskOptions, GlobalDefinition, GraphContext, GraphRegistry, GraphRoutine, GraphRun, GraphRunner, HelperDefinition, type HelperFunction, type IdempotencyPolicy, InquiryBroker, type InquiryOptions, type Intent, META_ACTOR_SESSION_STATE_PERSIST_INTENT, type ResolvedRuntimeValidationPolicy, type RetryPolicy, type RuntimeActorTaskDefinition, type RuntimeGlobalDefinition, type RuntimeHandlerLanguage, type RuntimeHelperDefinition, RuntimeHost, type RuntimeInfo, type RuntimeNextEventResult, type RuntimePollEventsResult, type RuntimeProtocolError, type RuntimeProtocolHandshake, type RuntimeProtocolOperation, type RuntimeProtocolRequest, type RuntimeProtocolResponse, type RuntimeRoutineDefinition, type RuntimeSessionRole, type RuntimeSharingMode, type RuntimeSignalEmissionMode, type RuntimeSignalEvent, type RuntimeSnapshot, type RuntimeSubscription, type RuntimeTaskDefinition, type RuntimeTaskOptions, type RuntimeTools, type RuntimeValidationMode, type RuntimeValidationPolicy, type RuntimeValidationScope, type Schema, type SchemaConstraints, type SchemaDefinition, type SchemaType, type SessionPolicy, SignalBroker, type SignalDefinitionInput, type SignalDeliveryMode, SignalEmitter, type SignalMetadata, type SignalReceiverFilter, Task, type TaskFunction, type TaskOptions, type TaskResult, type ThrottleTagGetter, Cadenza as default, getActorTaskRuntimeMetadata };