@cadenza.io/core 3.26.1 → 3.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -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,1424 @@ 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;
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>;
883
838
  /**
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.
839
+ * Initializes with runners.
840
+ * @param runner Standard runner for user signals.
841
+ * @param metaRunner Meta runner for 'meta.' signals (suppresses further meta-emits).
905
842
  */
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;
843
+ bootstrap(runner: GraphRunner, metaRunner: GraphRunner): void;
844
+ init(): void;
908
845
  /**
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.
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.
914
850
  */
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;
851
+ observe(inquiry: string, task: Task): void;
924
852
  /**
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.
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.
933
857
  */
934
- emitWithMetadata(signal: string, ctx?: AnyObject): void;
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;
935
912
  /**
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.
913
+ * Compares the current GraphNode instance with another GraphNode to determine if they are considered equal.
938
914
  *
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.
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.
942
917
  */
943
- emitMetricsWithMetadata(signal: string, ctx?: AnyObject): void;
944
- private isSchemaDefinition;
945
- private isDefaultAnyObjectSchema;
946
- private mergeSchemaVariant;
947
- private validateValueAgainstSchema;
918
+ isEqualTo(node: GraphNode): boolean;
948
919
  /**
949
- * Validates a data object against a specified schema definition and returns validation results.
920
+ * Determines if the given node is part of the same graph as the current node.
950
921
  *
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.
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.
956
925
  */
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>;
926
+ isPartOfSameGraph(node: GraphNode): boolean;
962
927
  /**
963
- * Validates the input context against the predefined schema and emits metadata if validation fails.
928
+ * Determines whether the current instance shares a task with the provided node.
964
929
  *
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.
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.
967
932
  */
968
- private getEffectiveValidationMode;
969
- private warnMissingSchema;
970
- private logValidationFailure;
971
- validateInput(context: AnyObject, metadata?: AnyObject): true | AnyObject;
933
+ sharesTaskWith(node: GraphNode): boolean;
972
934
  /**
973
- * Validates the output context using the provided schema and emits metadata if validation fails.
935
+ * Determines whether the current node shares the same context as the specified node.
974
936
  *
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.
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.
978
939
  */
979
- validateOutput(context: AnyObject, metadata?: AnyObject): true | AnyObject;
940
+ sharesContextWith(node: GraphNode): boolean;
941
+ getLayerIndex(): number;
942
+ getConcurrency(): number;
980
943
  /**
981
- * Executes a task within a given context, optionally emitting signals and reporting progress.
944
+ * Retrieves the tag associated with the current task and context.
982
945
  *
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.
946
+ * @return {string} The tag retrieved from the task within the given context.
989
947
  */
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;
948
+ getTag(): string;
994
949
  /**
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.
950
+ * Schedules the current node/task on the specified graph layer if applicable.
998
951
  *
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.
1002
- */
1003
- doAfter(...tasks: (Task | undefined)[]): this;
1004
- /**
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.
952
+ * This method assesses whether the current node/task should be scheduled
953
+ * on the given graph layer. It ensures that tasks are only scheduled
954
+ * under certain conditions, such as checking if the task shares
955
+ * execution contexts or dependencies with other nodes, and handles
956
+ * various metadata emissions and context updates during the scheduling process.
1007
957
  *
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.
958
+ * @param {GraphLayer} layer - The graph layer on which the current task should be scheduled.
959
+ * @returns {void} Does not return a value.
1011
960
  */
1012
- then(...tasks: (Task | undefined)[]): this;
961
+ scheduleOn(layer: GraphLayer): void;
1013
962
  /**
1014
- * Decouples the current task from the provided task by removing mutual references.
963
+ * Starts the execution process by initializing the execution start timestamp,
964
+ * emitting relevant metadata, and logging debug information if applicable.
1015
965
  *
1016
- * @param {Task} task - The task to decouple from the current task.
1017
- * @return {void} This method does not return a value.
1018
- */
1019
- decouple(task: Task): void;
1020
- /**
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
+ * The method performs the following actions:
967
+ * 1. Sets the execution start timestamp if it's not already initialized.
968
+ * 2. Emits metrics with metadata about the routine execution starting, including additional data if there are no previous nodes.
969
+ * 3. Optionally logs debug or verbose information based on the current settings.
970
+ * 4. Emits additional metrics to indicate that the execution has started.
1025
971
  *
1026
- * @return {void} Does not return a value.
972
+ * @return {number} The timestamp indicating when the execution started.
1027
973
  */
1028
- updateProgressWeights(): void;
974
+ start(): number;
1029
975
  /**
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.
976
+ * Marks the end of an execution process, performs necessary cleanup, emits
977
+ * metrics with associated metadata, and signals the completion of execution.
978
+ * Also handles specific cases when the graph completes.
1032
979
  *
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.
980
+ * @return {number} The timestamp corresponding to the end of execution. If execution
981
+ * was not started, it returns 0.
1034
982
  */
1035
- getSubgraphLayers(): Map<number, Set<Task>>;
983
+ end(): number;
1036
984
  /**
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.
985
+ * Executes the main logic of the task, including input validation, processing, and post-processing.
986
+ * Handles both synchronous and asynchronous workflows.
1040
987
  *
1041
- * @return {void} This method does not return a value.
988
+ * @return {Array|Promise|undefined} Returns the next nodes to process if available.
989
+ * If asynchronous processing is required, it returns a Promise that resolves to the next nodes.
990
+ * Returns undefined in case of an error during input validation or preconditions that prevent processing.
1042
991
  */
1043
- updateLayerFromPredecessors(): void;
992
+ execute(): GraphNode[] | Promise<GraphNode[]>;
1044
993
  /**
1045
- * Determines whether there is a cycle in the tasks graph.
1046
- * This method performs a depth-first search (DFS) to detect cycles.
994
+ * Executes an asynchronous workflow that processes a result and retries on errors.
995
+ * The method handles different result states, checks for error properties, and invokes
996
+ * error handling when necessary.
1047
997
  *
1048
- * @return {boolean} - Returns true if a cycle is found in the graph, otherwise false.
998
+ * @return {Promise<void>} A promise that resolves when the operation completes successfully,
999
+ * or rejects if an unhandled error occurs.
1049
1000
  */
1050
- hasCycle(): boolean;
1001
+ workAsync(): Promise<void>;
1051
1002
  /**
1052
- * Maps over the next set of tasks or failed tasks if specified, applying the provided callback function.
1003
+ * Executes an asynchronous operation, processes the result, and determines the next nodes to execute.
1004
+ * This method will manage asynchronous work, handle post-processing of results, and ensure proper handling of both synchronous and asynchronous next node configurations.
1053
1005
  *
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.
1006
+ * @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.
1056
1007
  */
1057
- mapNext(callback: (task: Task) => any): any[];
1008
+ executeAsync(): Promise<GraphNode[]>;
1058
1009
  /**
1059
- * Maps through each task in the set of predecessor tasks and applies the provided callback function.
1010
+ * Executes the task associated with the current instance, using the given context,
1011
+ * progress callback, and metadata. If the task fails or an error occurs, it attempts
1012
+ * to retry the execution. If the retry is not successful, it propagates the error and
1013
+ * returns the result.
1060
1014
  *
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.
1015
+ * @return {TaskResult | Promise<TaskResult>} The result of the task execution, or a
1016
+ * promise that resolves to the task result. This includes handling for retries on
1017
+ * failure and error propagation.
1063
1018
  */
1064
- mapPrevious(callback: (task: Task) => any): any[];
1065
- makeRoutine(name: string, description: string): this;
1019
+ work(): TaskResult | Promise<TaskResult>;
1020
+ inquire(inquiry: string, context: AnyObject, options: InquiryOptions): Promise<any>;
1066
1021
  /**
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.
1022
+ * Emits a signal along with its associated metadata. The metadata includes
1023
+ * task-specific information such as task name, version, execution ID, and
1024
+ * additional context metadata like routine execution ID and execution trace ID.
1025
+ * This method is designed to enrich emitted signals with relevant details
1026
+ * before broadcasting them.
1070
1027
  *
1071
- * @param {...string[]} signals - The array of signal names to observe.
1072
- * @return {this} The current instance after adding the specified signals.
1028
+ * @param {string} signal - The name of the signal to be emitted.
1029
+ * @param {AnyObject} data - The data object to be sent along with the signal. Metadata
1030
+ * will be injected into this object before being emitted.
1031
+ * @param options
1032
+ * @return {void} No return value.
1073
1033
  */
1074
- doOn(...signals: SignalDefinitionInput[]): this;
1034
+ emitWithMetadata(signal: string, data: AnyObject, options?: EmitOptions): void;
1075
1035
  /**
1076
- * Registers the specified signals to be emitted after the Task executes successfully and attaches them for further processing.
1036
+ * Emits metrics with additional metadata describing the task execution and context.
1077
1037
  *
1078
- * @param {...string} signals - The list of signals to be registered for emission.
1079
- * @return {this} The current instance for method chaining.
1038
+ * @param {string} signal - The signal name being emitted.
1039
+ * @param {AnyObject} data - The data associated with the signal emission, enriched with metadata.
1040
+ * @param options
1041
+ * @return {void} Emits the signal with enriched data and does not return a value.
1080
1042
  */
1081
- emits(...signals: SignalDefinitionInput[]): this;
1043
+ emitMetricsWithMetadata(signal: string, data: AnyObject, options?: EmitOptions): void;
1082
1044
  /**
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.
1045
+ * Updates the progress of a task and emits metrics with associated metadata.
1085
1046
  *
1086
- * @param {...string} signals - The names of the signals to emit upon failure.
1087
- * @return {this} Returns the current instance for chaining.
1047
+ * @param {number} progress - A number representing the progress value, which will be clamped between 0 and 1.
1048
+ * @return {void} This method does not return a value.
1088
1049
  */
1089
- emitsOnFail(...signals: SignalDefinitionInput[]): this;
1050
+ onProgress(progress: number): void;
1090
1051
  /**
1091
- * Attaches a signal to the current context and emits metadata if the register flag is set.
1052
+ * Processes the result of the current operation, validates it, and determines the next set of nodes.
1092
1053
  *
1093
- * @param {...string} signals - The names of the signals to attach.
1094
- * @return {void} This method does not return a value.
1054
+ * This method ensures that results of certain types such as strings or arrays
1055
+ * are flagged as errors. It divides the current context into subsequent nodes
1056
+ * for further processing. If the division returns a promise, it delegates the
1057
+ * processing to `postProcessAsync`. For synchronous division, it sets the
1058
+ * `nextNodes` and finalizes the operation.
1059
+ *
1060
+ * @return {(Array|undefined)} Returns an array of next nodes for further processing,
1061
+ * or undefined if no further processing is required.
1095
1062
  */
1096
- attachSignal(...signals: SignalDefinitionInput[]): Task;
1063
+ postProcess(): GraphNode[] | Promise<GraphNode[]>;
1097
1064
  /**
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.
1065
+ * Asynchronously processes and finalizes the provided graph nodes.
1101
1066
  *
1102
- * @param {string[]} signals - The list of signal names to unsubscribe from.
1103
- * @return {this} Returns the current instance for method chaining.
1067
+ * @param {Promise<GraphNode[]>} nextNodes A promise that resolves to an array of graph nodes to be processed.
1068
+ * @return {Promise<GraphNode[]>} A promise that resolves to the processed array of graph nodes.
1104
1069
  */
1105
- unsubscribe(...signals: string[]): this;
1070
+ postProcessAsync(nextNodes: Promise<GraphNode[]>): Promise<GraphNode[]>;
1106
1071
  /**
1107
- * Unsubscribes from all currently observed signals and clears the list of observed signals.
1072
+ * Finalizes the current task execution by determining if the task is complete, handles any errors or failures,
1073
+ * emits relevant signals based on the task outcomes, and ensures proper end of the task lifecycle.
1108
1074
  *
1109
- * @return {this} The instance of the class to allow method chaining.
1075
+ * @return {void} Does not return a value.
1110
1076
  */
1111
- unsubscribeAll(): this;
1077
+ finalize(): void;
1112
1078
  /**
1113
- * Detaches the specified signals from being emitted after execution and optionally emits metadata for each detached signal.
1079
+ * Handles an error event, processes the error, and updates the state accordingly.
1114
1080
  *
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.
1081
+ * @param {unknown} error - The error object or message that occurred.
1082
+ * @param {AnyObject} [errorData={}] - Additional error data to include in the result.
1083
+ * @return {void} This method does not return any value.
1117
1084
  */
1118
- detachSignals(...signals: string[]): this;
1085
+ onError(error: unknown, errorData?: AnyObject): void;
1119
1086
  /**
1120
- * Detaches all signals associated with the object by invoking the `detachSignals` method
1121
- * and clearing the `signalsToEmitAfter` collection.
1087
+ * 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.
1122
1088
  *
1123
- * @return {this} Returns the current instance to allow method chaining.
1089
+ * @param {any} [prevResult] - The result from a previous attempt, if any, to return when no retries are performed.
1090
+ * @return {Promise<TaskResult>} - A promise that resolves with the result of the retried task or the previous result if no retries occur.
1124
1091
  */
1125
- detachAllSignals(): this;
1126
- respondsTo(...inquires: string[]): this;
1127
- attachIntents(...intentNames: string[]): this;
1128
- detachIntents(...intentNames: string[]): this;
1129
- detachAllIntents(): this;
1092
+ retry(prevResult?: any): Promise<TaskResult>;
1130
1093
  /**
1131
- * Maps over the signals in the `signalsToEmitAfter` set and applies a callback function to each signal.
1094
+ * Retries an asynchronous operation and returns its result.
1095
+ * If the retry count is zero, the method immediately returns the provided previous result.
1132
1096
  *
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.
1097
+ * @param {any} [prevResult] - The optional result from a previous operation attempt, if applicable.
1098
+ * @return {Promise<TaskResult>} A promise that resolves to the result of the retried operation.
1137
1099
  */
1138
- mapSignals(callback: (signal: string) => void): void[];
1100
+ retryAsync(prevResult?: any): Promise<TaskResult>;
1101
+ delayRetry(): Promise<void>;
1139
1102
  /**
1140
- * Maps over the signals in `signalsToEmitOnFail` and applies the provided callback to each signal.
1103
+ * Processes the result of a task by generating new nodes based on the task output.
1104
+ * The method handles synchronous and asynchronous generators, validates task output,
1105
+ * and creates new nodes accordingly. If errors occur, the method attempts to handle them
1106
+ * by generating alternative task nodes.
1141
1107
  *
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`.
1108
+ * @return {GraphNode[] | Promise<GraphNode[]>} Returns an array of generated GraphNode objects
1109
+ * (synchronously or wrapped in a Promise) based on the task result, or propagates errors if validation fails.
1144
1110
  */
1145
- mapOnFailSignals(callback: (signal: string) => void): void[];
1111
+ divide(): GraphNode[] | Promise<GraphNode[]>;
1146
1112
  /**
1147
- * Maps over the observed signals with the provided callback function.
1113
+ * Processes an asynchronous iterator result, validates its output, and generates new graph nodes accordingly.
1114
+ * Additionally, continues to process and validate results from an asynchronous generator.
1148
1115
  *
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.
1116
+ * @param {Promise<IteratorResult<any>>} current - A promise resolving to the current step result from an asynchronous iterator.
1117
+ * @return {Promise<GraphNode[]>} A promise resolving to an array of generated GraphNode objects based on validated outputs.
1151
1118
  */
1152
- mapObservedSignals(callback: (signal: string) => void): void[];
1119
+ divideAsync(current: Promise<IteratorResult<any>>): Promise<GraphNode[]>;
1153
1120
  /**
1154
- * Emits a collection of signals stored in the `signalsToEmitAfter` array.
1121
+ * Generates new nodes based on the provided result and task configuration.
1155
1122
  *
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.
1123
+ * @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.
1124
+ * @return {GraphNode[]} An array of newly generated graph nodes configured based on the task and context.
1158
1125
  */
1159
- emitSignals(context: GraphContext): void;
1126
+ generateNewNodes(result: any): GraphNode[];
1160
1127
  /**
1161
- * Emits registered signals when an operation fails.
1128
+ * Executes the differentiation process based on a given task and updates the instance properties accordingly.
1162
1129
  *
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.
1130
+ * @param {Task} task - The task object containing information such as retry count, retry delay, and metadata status.
1131
+ * @return {GraphNode} The updated instance after processing the task.
1165
1132
  */
1166
- emitOnFailSignals(context: GraphContext): void;
1133
+ differentiate(task: Task): GraphNode;
1167
1134
  /**
1168
- * Cleans up and destroys the task instance, detaching it from other tasks and
1169
- * performing necessary cleanup operations.
1170
- *
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.
1135
+ * Migrates the current instance to a new context and returns the updated instance.
1177
1136
  *
1178
- * @return {void} No value is returned because the function performs clean-up operations.
1137
+ * @param {any} ctx - The context data to be used for migration.
1138
+ * @return {GraphNode} The updated instance after migration.
1179
1139
  */
1180
- destroy(): void;
1140
+ migrate(ctx: any): GraphNode;
1181
1141
  /**
1182
- * Exports the current state of the object as a structured plain object.
1142
+ * Splits the current node into a new group identified by the provided ID.
1183
1143
  *
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.
1144
+ * @param {string} id - The unique identifier for the new split group.
1145
+ * @return {GraphNode} The current instance of the GraphNode with the updated split group ID.
1192
1146
  */
1193
- export(): AnyObject;
1147
+ split(id: string): GraphNode;
1194
1148
  /**
1195
- * Returns an iterator for iterating over tasks associated with this instance.
1149
+ * Creates a new instance of the GraphNode with the current node's properties.
1150
+ * This method allows for duplicating the existing graph node.
1196
1151
  *
1197
- * @return {TaskIterator} An iterator instance for tasks.
1152
+ * @return {GraphNode} A new instance of GraphNode that is a copy of the current node.
1198
1153
  */
1199
- getIterator(): TaskIterator;
1154
+ clone(): GraphNode;
1200
1155
  /**
1201
- * Accepts a visitor object to perform operations on the current instance.
1156
+ * Consumes the given graph node by combining contexts, merging previous nodes,
1157
+ * and performing associated operations on the provided node.
1202
1158
  *
1203
- * @param {GraphVisitor} visitor - The visitor object implementing operations for this instance.
1159
+ * @param {GraphNode} node - The graph node to be consumed.
1204
1160
  * @return {void} This method does not return a value.
1205
1161
  */
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 {
1162
+ consume(node: GraphNode): void;
1216
1163
  /**
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.
1164
+ * Changes the identity of the current instance by updating the `id` property.
1221
1165
  *
1222
- * @return {GraphNode[]} An array of newly generated graph nodes after executing the logic of each unprocessed node.
1166
+ * @param {string} id - The new identity value to be assigned.
1167
+ * @return {void} Does not return a value.
1223
1168
  */
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;
1169
+ changeIdentity(id: string): void;
1253
1170
  /**
1254
- * Composes a series of functions or operations.
1255
- * This method should be implemented in the child class
1256
- * to define custom composition logic.
1171
+ * Completes the subgraph for the current node and recursively for its previous nodes
1172
+ * once all next nodes have their subgraphs marked as done. If there are no previous nodes,
1173
+ * it completes the entire graph.
1257
1174
  *
1258
- * @return {any} The result of the composed operations or functions
1259
- * when implemented in the child class.
1175
+ * @return {void} Does not return a value.
1260
1176
  */
1261
- compose(): void;
1177
+ completeSubgraph(): void;
1262
1178
  /**
1263
- * Adds a node to the appropriate layer of the graph.
1179
+ * Completes the current graph by setting a flag indicating the graph has been completed
1180
+ * and recursively completes all subsequent nodes in the graph.
1264
1181
  *
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
1182
  * @return {void} Does not return a value.
1268
1183
  */
1269
- addNode(node: GraphNode): void;
1184
+ completeGraph(): void;
1270
1185
  /**
1271
- * Adds multiple nodes to the graph.
1186
+ * Destroys the current instance by releasing resources, breaking references,
1187
+ * and resetting properties to ensure proper cleanup.
1272
1188
  *
1273
- * @param {GraphNode[]} nodes - An array of nodes to be added to the graph.
1274
- * @return {void} This method does not return a value.
1189
+ * @return {void} No return value.
1275
1190
  */
1276
- addNodes(nodes: GraphNode[]): void;
1191
+ destroy(): void;
1277
1192
  /**
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.
1193
+ * Retrieves an iterator for traversing through the graph nodes.
1281
1194
  *
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.
1195
+ * @return {GraphNodeIterator} An iterator instance specific to this graph node.
1196
+ */
1197
+ getIterator(): GraphNodeIterator;
1198
+ /**
1199
+ * Applies a callback function to each node in the `nextNodes` array and returns
1200
+ * the resulting array from the map operation.
1201
+ *
1202
+ * @param {function} callback - A function to execute on each `GraphNode` in the `nextNodes` array.
1203
+ * The function receives a `GraphNode` as its argument.
1204
+ * @return {Array} The resulting array after applying the callback function to each node in `nextNodes`.
1284
1205
  */
1285
- addLayer(index: number): void;
1206
+ mapNext(callback: (node: GraphNode) => any): any[];
1286
1207
  /**
1287
- * Creates a new layer for the graph at the specified index.
1208
+ * Accepts a visitor object and calls its visitNode method with the current instance.
1288
1209
  *
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.
1210
+ * @param {GraphVisitor} visitor - The visitor instance implementing the GraphVisitor interface.
1211
+ * @return {void} This method does not return a value.
1291
1212
  */
1292
- createLayer(index: number): GraphLayer;
1213
+ accept(visitor: GraphVisitor): void;
1293
1214
  /**
1294
- * Retrieves a specific layer from the current set of layers.
1215
+ * Exports the current object's state and returns it in a serialized format.
1216
+ * The exported object contains metadata, task details, context information, execution times, node relationships, routine execution status, and other state information.
1295
1217
  *
1296
- * @param {number} layerIndex - The index of the layer to retrieve.
1297
- * @return {*} The layer corresponding to the given index.
1218
+ * @return {Object} An object representing the current state.
1298
1219
  */
1299
- getLayer(layerIndex: number): GraphLayer;
1300
- reset(): void;
1220
+ export(): {
1221
+ __id: string;
1222
+ __task: AnyObject;
1223
+ __context: {
1224
+ id: string;
1225
+ context: AnyObject;
1226
+ };
1227
+ __result: TaskResult;
1228
+ __executionTime: number;
1229
+ __executionStart: number;
1230
+ __executionEnd: number;
1231
+ __nextNodes: string[];
1232
+ __previousNodes: string[];
1233
+ __routineExecId: string;
1234
+ __isProcessing: boolean;
1235
+ __isMeta: boolean;
1236
+ __graphComplete: boolean;
1237
+ __failed: boolean;
1238
+ __errored: boolean;
1239
+ __isUnique: boolean;
1240
+ __splitGroupId: string;
1241
+ __tag: string;
1242
+ };
1243
+ lightExport(): {
1244
+ __id: string;
1245
+ __task: {
1246
+ __name: string;
1247
+ __version: number;
1248
+ };
1249
+ __context: {
1250
+ id: string;
1251
+ context: AnyObject;
1252
+ };
1253
+ __executionTime: number;
1254
+ __executionStart: number;
1255
+ __nextNodes: string[];
1256
+ __previousNodes: string[];
1257
+ __routineExecId: string;
1258
+ __isProcessing: boolean;
1259
+ __graphComplete: boolean;
1260
+ __isMeta: boolean;
1261
+ __failed: boolean;
1262
+ __errored: boolean;
1263
+ __isUnique: boolean;
1264
+ __splitGroupId: string;
1265
+ __tag: string;
1266
+ };
1267
+ log(): void;
1268
+ }
1269
+
1270
+ declare abstract class GraphVisitor {
1271
+ abstract visitLayer(layer: GraphLayer): any;
1272
+ abstract visitNode(node: GraphNode): any;
1273
+ abstract visitTask(task: Task): any;
1301
1274
  }
1302
1275
 
1303
1276
  /**
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.
1277
+ * TaskIterator is a custom iterator for traversing over a set of tasks.
1278
+ * It provides mechanisms to iterate through tasks in a layered manner,
1279
+ * where each task can branch out to other tasks forming multiple layers.
1308
1280
  */
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;
1281
+ declare class TaskIterator implements Iterator {
1282
+ currentTask: Task | undefined;
1283
+ currentLayer: Set<Task>;
1284
+ nextLayer: Set<Task>;
1285
+ iterator: {
1286
+ next: () => {
1287
+ value: Task | undefined;
1288
+ };
1289
+ };
1290
+ constructor(task: Task);
1291
+ hasNext(): boolean;
1292
+ next(): Task | undefined;
1320
1293
  }
1321
1294
 
1322
- interface RunJson {
1323
- __id: string;
1324
- __label: string;
1325
- __graph: any;
1326
- __data: any;
1295
+ interface RuntimeTools {
1296
+ helpers: Record<string, HelperInvoker>;
1297
+ globals: Record<string, unknown>;
1327
1298
  }
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>;
1299
+ 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;
1300
+ type HelperInvoker = (context?: AnyObject) => TaskResult | Promise<TaskResult>;
1301
+ interface ToolDependencyOwner {
1302
+ readonly isMeta: boolean;
1303
+ helperAliases: Map<string, string>;
1304
+ globalAliases: Map<string, string>;
1305
+ }
1306
+ declare class GlobalDefinition {
1307
+ readonly name: string;
1308
+ readonly description: string;
1309
+ readonly version: number;
1310
+ readonly isMeta: boolean;
1311
+ readonly value: unknown;
1312
+ destroyed: boolean;
1313
+ constructor(name: string, value: unknown, description?: string, isMeta?: boolean);
1341
1314
  destroy(): void;
1342
- log(): void;
1343
- export(): RunJson;
1344
- setExporter(exporter: GraphExporter): void;
1315
+ export(): Record<string, unknown>;
1316
+ }
1317
+ declare class HelperDefinition implements ToolDependencyOwner {
1318
+ readonly name: string;
1319
+ readonly description: string;
1320
+ readonly version: number;
1321
+ readonly isMeta: boolean;
1322
+ readonly helperFunction: HelperFunction;
1323
+ readonly helperAliases: Map<string, string>;
1324
+ readonly globalAliases: Map<string, string>;
1325
+ destroyed: boolean;
1326
+ constructor(name: string, helperFunction: HelperFunction, description?: string, isMeta?: boolean);
1327
+ usesHelpers(helpers: Record<string, HelperDefinition | undefined>): this;
1328
+ usesGlobals(globals: Record<string, GlobalDefinition | undefined>): this;
1329
+ execute(context: AnyObject, emit: (signal: string, context: AnyObject) => void, inquire: (inquiry: string, context: AnyObject, options: InquiryOptions) => Promise<AnyObject>, progressCallback: (progress: number) => void): TaskResult;
1330
+ destroy(): void;
1331
+ export(): Record<string, unknown>;
1345
1332
  }
1346
1333
 
1334
+ 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;
1335
+ type TaskResult = boolean | AnyObject | Generator | Promise<any> | void;
1336
+ type ThrottleTagGetter = (context?: AnyObject, task?: Task) => string;
1347
1337
  /**
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.
1338
+ * Represents a task with a specific behavior, configuration, and lifecycle management.
1339
+ * Tasks are used to define units of work that can be executed and orchestrated.
1340
+ * Tasks can specify input/output validation, concurrency, retry policies, and more.
1341
+ * This class extends SignalEmitter and implements Graph, allowing tasks to emit and observe signals.
1353
1342
  */
1354
- declare class GraphRoutine extends SignalEmitter {
1343
+ declare class Task extends SignalEmitter implements Graph, ToolDependencyOwner {
1355
1344
  readonly name: string;
1356
- version: number;
1357
1345
  readonly description: string;
1346
+ version: number;
1347
+ concurrency: number;
1348
+ timeout: number;
1358
1349
  readonly isMeta: boolean;
1359
- tasks: Set<Task>;
1350
+ readonly isSubMeta: boolean;
1351
+ readonly isHidden: boolean;
1352
+ readonly isUnique: boolean;
1353
+ readonly throttled: boolean;
1354
+ readonly isSignal: boolean;
1355
+ readonly isDeputy: boolean;
1356
+ readonly isEphemeral: boolean;
1357
+ readonly isDebounce: boolean;
1358
+ inputContextSchema: Schema;
1359
+ hasExplicitInputContextSchema: boolean;
1360
+ validateInputContext: boolean;
1361
+ outputContextSchema: Schema;
1362
+ hasExplicitOutputContextSchema: boolean;
1363
+ validateOutputContext: boolean;
1364
+ readonly retryCount: number;
1365
+ readonly retryDelay: number;
1366
+ readonly retryDelayMax: number;
1367
+ readonly retryDelayFactor: number;
1368
+ layerIndex: number;
1369
+ progressWeight: number;
1370
+ nextTasks: Set<Task>;
1371
+ predecessorTasks: Set<Task>;
1372
+ destroyed: boolean;
1373
+ register: boolean;
1360
1374
  registered: boolean;
1361
- registeredTasks: Set<Task>;
1375
+ registeredSignals: Set<string>;
1376
+ taskMapRegistration: Set<string>;
1377
+ emitsSignals: Set<string>;
1378
+ signalsToEmitAfter: Set<string>;
1379
+ signalsToEmitOnFail: Set<string>;
1362
1380
  observedSignals: Set<string>;
1363
- constructor(name: string, tasks: Task[], description: string, isMeta?: boolean);
1381
+ handlesIntents: Set<string>;
1382
+ inquiresIntents: Set<string>;
1383
+ helperAliases: Map<string, string>;
1384
+ globalAliases: Map<string, string>;
1385
+ readonly taskFunction: TaskFunction;
1386
+ /**
1387
+ * Constructs an instance of the task with the specified properties and configuration options.
1388
+ *
1389
+ * @param {string} name - The name of the task.
1390
+ * @param {TaskFunction} task - The function that represents the task logic.
1391
+ * @param {string} [description=""] - A description of the task.
1392
+ * @param {number} [concurrency=0] - The number of concurrent executions allowed for the task.
1393
+ * @param {number} [timeout=0] - The maximum execution time for the task in milliseconds.
1394
+ * @param {boolean} [register=true] - Indicates if the task should be registered or not.
1395
+ * @param {boolean} [isUnique=false] - Specifies if the task should only allow one instance to exist at any time.
1396
+ * @param {boolean} [isMeta=false] - Indicates if the task is a meta-task.
1397
+ * @param {boolean} [isSubMeta=false] - Indicates if the task is a sub-meta-task.
1398
+ * @param {boolean} [isHidden=false] - Determines if the task is hidden and not exposed publicly.
1399
+ * @param {ThrottleTagGetter} [getTagCallback=undefined] - A callback to generate a throttle tag for the task.
1400
+ * @param {Schema} [inputSchema=undefined] - The input schema for validating the task's input context.
1401
+ * @param {boolean} [validateInputContext=false] - Specifies if the input context should be validated against the input schema.
1402
+ * @param {Schema} [outputSchema=undefined] - The output schema for validating the task's output context.
1403
+ * @param {boolean} [validateOutputContext=false] - Specifies if the output context should be validated against the output schema.
1404
+ * @param {number} [retryCount=0] - The number of retry attempts allowed for the task in case of failure.
1405
+ * @param {number} [retryDelay=0] - The initial delay (in milliseconds) between retry attempts.
1406
+ * @param {number} [retryDelayMax=0] - The maximum delay (in milliseconds) allowed between retries.
1407
+ * @param {number} [retryDelayFactor=1] - The factor by which the retry delay increases after each attempt.
1408
+ */
1409
+ 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);
1410
+ clone(traverse?: boolean, includeSignals?: boolean): Task;
1411
+ /**
1412
+ * Retrieves the tag associated with the instance.
1413
+ * Can be overridden by subclasses.
1414
+ *
1415
+ * @param {AnyObject} [context] - Optional context parameter that can be provided.
1416
+ * @return {string} The tag value of the instance.
1417
+ */
1418
+ getTag(context?: AnyObject): string;
1419
+ setVersion(version: number): void;
1420
+ setTimeout(timeout: number): void;
1421
+ setConcurrency(concurrency: number): void;
1422
+ setProgressWeight(weight: number): void;
1423
+ setInputContextSchema(schema: Schema): void;
1424
+ setOutputContextSchema(schema: Schema): void;
1425
+ setValidateInputContext(value: boolean): void;
1426
+ setValidateOutputContext(value: boolean): void;
1427
+ /**
1428
+ * Emits a signal along with metadata if certain conditions are met.
1429
+ *
1430
+ * This method sends a signal with optional context data and adds metadata
1431
+ * to the emitted data if the instance is not hidden and not a subordinate metadata object.
1432
+ *
1433
+ * @param {string} signal - The name of the signal to emit.
1434
+ * @param {AnyObject} [ctx={}] - Additional context data to include with the emitted signal.
1435
+ * @return {void} Does not return a value.
1436
+ */
1437
+ emitWithMetadata(signal: string, ctx?: AnyObject): void;
1438
+ /**
1439
+ * Emits metrics with additional metadata enhancement based on the context and the state of the instance.
1440
+ * This is used to prevent loops on the meta layer in debug mode.
1441
+ *
1442
+ * @param {string} signal - The signal identifier for the metric being emitted.
1443
+ * @param {AnyObject} [ctx={}] - Optional context object to provide additional information with the metric.
1444
+ * @return {void} This method does not return any value.
1445
+ */
1446
+ emitMetricsWithMetadata(signal: string, ctx?: AnyObject): void;
1447
+ private isSchemaDefinition;
1448
+ private isDefaultAnyObjectSchema;
1449
+ private mergeSchemaVariant;
1450
+ private validateValueAgainstSchema;
1451
+ /**
1452
+ * Validates a data object against a specified schema definition and returns validation results.
1453
+ *
1454
+ * @param {any} data - The target object to validate against the schema.
1455
+ * @param {Schema | undefined} schema - The schema definition describing the expected structure and constraints of the data.
1456
+ * @param {string} [path="context"] - The base path or context for traversing the data, used in generating error messages.
1457
+ * @return {{ valid: boolean, errors: Record<string, string> }} - An object containing a validity flag (`valid`)
1458
+ * and a map (`errors`) of validation error messages keyed by property paths.
1459
+ */
1460
+ validateSchema(data: any, schema: Schema | undefined, path?: string): {
1461
+ valid: boolean;
1462
+ errors: Record<string, string>;
1463
+ };
1464
+ validateProp(prop: SchemaDefinition, key: string, value?: any, path?: string): Record<string, string>;
1364
1465
  /**
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.
1466
+ * Validates the input context against the predefined schema and emits metadata if validation fails.
1367
1467
  *
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.
1468
+ * @param {AnyObject} context - The input context to validate.
1469
+ * @return {true | AnyObject} - Returns `true` if validation succeeds, otherwise returns an error object containing details of the validation failure.
1371
1470
  */
1372
- forEachTask(callBack: (task: Task) => any): Promise<void>;
1471
+ private getEffectiveValidationMode;
1472
+ private warnMissingSchema;
1473
+ private logValidationFailure;
1474
+ validateInput(context: AnyObject, metadata?: AnyObject): true | AnyObject;
1373
1475
  /**
1374
- * Sets global Version.
1375
- * @param version The Version.
1476
+ * Validates the output context using the provided schema and emits metadata if validation fails.
1477
+ *
1478
+ * @param {AnyObject} context - The output context to validate.
1479
+ * @return {true | AnyObject} Returns `true` if the output context is valid; otherwise, returns an object
1480
+ * containing error information when validation fails.
1376
1481
  */
1377
- setVersion(version: number): void;
1482
+ validateOutput(context: AnyObject, metadata?: AnyObject): true | AnyObject;
1378
1483
  /**
1379
- * Subscribes the current instance to the specified signals, enabling it to observe them.
1484
+ * Executes a task within a given context, optionally emitting signals and reporting progress.
1380
1485
  *
1381
- * @param {...string} signals - The names of the signals to observe.
1382
- * @return {this} Returns the instance to allow for method chaining.
1486
+ * @param {GraphContext} context The execution context which provides data and functions necessary for the task.
1487
+ * @param {function(string, AnyObject): void} emit A function to emit signals and communicate intermediate results or states.
1488
+ * @param {function(string, AnyObject, InquiryOptions): Promise<AnyObject>} inquire A function to inquire something from another task.
1489
+ * @param {function(number): void} progressCallback A callback function used to report task progress as a percentage (0 to 100).
1490
+ * @param {{ nodeId: string; routineExecId: string }} nodeData An object containing identifiers related to the node and execution routine.
1491
+ * @return {TaskResult} The result of the executed task.
1383
1492
  */
1384
- doOn(...signals: string[]): this;
1493
+ execute(context: GraphContext, emit: (signal: string, context: AnyObject) => void, inquire: (inquiry: string, context: AnyObject, options: InquiryOptions) => Promise<AnyObject>, progressCallback: (progress: number) => void, nodeData: {
1494
+ nodeId: string;
1495
+ routineExecId: string;
1496
+ }): TaskResult;
1385
1497
  /**
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.
1498
+ * Adds tasks as predecessors to the current task and establishes dependencies between them.
1499
+ * Ensures that adding predecessors does not create cyclic dependencies.
1500
+ * Updates task relationships, progress weights, and emits relevant metrics after operations.
1389
1501
  *
1390
- * @return {this} Returns the current instance for chaining purposes.
1502
+ * @param {Task[]} tasks - An array of tasks to be added as predecessors to the current task.
1503
+ * @return {this} The current task instance for method chaining.
1504
+ * @throws {Error} Throws an error if adding a predecessor creates a cycle in the task structure.
1391
1505
  */
1392
- unsubscribeAll(): this;
1506
+ doAfter(...tasks: (Task | undefined)[]): this;
1393
1507
  /**
1394
- * Unsubscribes the current instance from the specified signals.
1508
+ * Adds a sequence of tasks as successors to the current task, ensuring no cyclic dependencies are introduced.
1509
+ * Metrics are emitted when a relationship is successfully added.
1395
1510
  *
1396
- * @param {...string} signals - The signals to unsubscribe from.
1397
- * @return {this} The current instance for method chaining.
1511
+ * @param {...Task} tasks - The tasks to be added as successors to the current task.
1512
+ * @return {this} Returns the current task instance for method chaining.
1513
+ * @throws {Error} Throws an error if adding a task causes a cyclic dependency.
1398
1514
  */
1399
- unsubscribe(...signals: string[]): this;
1515
+ then(...tasks: (Task | undefined)[]): this;
1400
1516
  /**
1401
- * Cleans up resources and emits an event indicating the destruction of the routine.
1517
+ * Decouples the current task from the provided task by removing mutual references.
1402
1518
  *
1403
- * This method unsubscribes from all events, clears the tasks list,
1404
- * and emits a "meta.routine.destroyed" event with details of the destruction.
1519
+ * @param {Task} task - The task to decouple from the current task.
1520
+ * @return {void} This method does not return a value.
1521
+ */
1522
+ decouple(task: Task): void;
1523
+ /**
1524
+ * Updates the progress weights for tasks within each layer of the subgraph.
1525
+ * The progress weight for each task is calculated based on the inverse proportion
1526
+ * of the number of layers and the number of tasks in each layer. This ensures an
1527
+ * even distribution of progress weight across the tasks in the layers.
1405
1528
  *
1406
- * @return {void}
1529
+ * @return {void} Does not return a value.
1407
1530
  */
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;
1531
+ updateProgressWeights(): void;
1422
1532
  /**
1423
- * Constructs a runner.
1424
- * @param isMeta Meta flag (default false).
1425
- * @edge Creates 'Start run' meta-task chained to registry gets.
1533
+ * Retrieves a mapping of layer indices to sets of tasks within each layer of a subgraph.
1534
+ * This method traverses the task dependencies and organizes tasks by their respective layer indices.
1535
+ *
1536
+ * @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.
1426
1537
  */
1427
- constructor(isMeta?: boolean);
1538
+ getSubgraphLayers(): Map<number, Set<Task>>;
1428
1539
  /**
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.
1540
+ * Updates the `layerIndex` of the current task based on the maximum layer index of its predecessors
1541
+ * and propagates the update recursively to all subsequent tasks. If the `layerIndex` changes,
1542
+ * emits a metric event with metadata about the change.
1431
1543
  *
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.
1544
+ * @return {void} This method does not return a value.
1437
1545
  */
1438
- addTasks(tasks: Task | GraphRoutine | (Task | GraphRoutine)[], context?: AnyObject): void;
1546
+ updateLayerFromPredecessors(): void;
1439
1547
  /**
1440
- * Executes the provided tasks or routines. Maintains the execution state
1441
- * and handles synchronous or asynchronous processing.
1548
+ * Determines whether there is a cycle in the tasks graph.
1549
+ * This method performs a depth-first search (DFS) to detect cycles.
1442
1550
  *
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.
1551
+ * @return {boolean} - Returns true if a cycle is found in the graph, otherwise false.
1446
1552
  */
1447
- run(tasks?: Task | GraphRoutine | (Task | GraphRoutine)[], context?: AnyObject): GraphRun | Promise<GraphRun>;
1553
+ hasCycle(): boolean;
1448
1554
  /**
1449
- * Executes the provided asynchronous operation and resets the state afterwards.
1555
+ * Maps over the next set of tasks or failed tasks if specified, applying the provided callback function.
1450
1556
  *
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.
1557
+ * @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.
1558
+ * @return {any[]} An array of transformed tasks resulting from applying the callback function.
1453
1559
  */
1454
- runAsync(run: Promise<void>): Promise<GraphRun>;
1560
+ mapNext(callback: (task: Task) => any): any[];
1455
1561
  /**
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.
1562
+ * Maps through each task in the set of predecessor tasks and applies the provided callback function.
1459
1563
  *
1460
- * @return {GraphRun} The last GraphRun instance before the reset.
1564
+ * @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.
1565
+ * @return {any[]} An array containing the results of applying the callback function to each predecessor task.
1461
1566
  */
1462
- reset(): GraphRun;
1463
- setDebug(value: boolean): void;
1464
- setVerbose(value: boolean): void;
1465
- destroy(): void;
1567
+ mapPrevious(callback: (task: Task) => any): any[];
1568
+ makeRoutine(name: string, description: string): this;
1466
1569
  /**
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.
1570
+ * Adds the specified signals to the current instance, making it observe them.
1571
+ * If the instance is already observing a signal, it will be skipped.
1572
+ * The method also emits metadata information if the `register` property is set.
1469
1573
  *
1470
- * @param {GraphRunStrategy} strategy - The strategy to use for running the graph.
1471
- * @return {void}
1574
+ * @param {...string[]} signals - The array of signal names to observe.
1575
+ * @return {this} The current instance after adding the specified signals.
1472
1576
  */
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;
1577
+ doOn(...signals: SignalDefinitionInput[]): this;
1578
+ /**
1579
+ * Registers the specified signals to be emitted after the Task executes successfully and attaches them for further processing.
1580
+ *
1581
+ * @param {...string} signals - The list of signals to be registered for emission.
1582
+ * @return {this} The current instance for method chaining.
1583
+ */
1584
+ emits(...signals: SignalDefinitionInput[]): this;
1585
+ /**
1586
+ * Configures the instance to emit specified signals when the task execution fails.
1587
+ * A failure is defined as anything that does not return a successful result.
1588
+ *
1589
+ * @param {...string} signals - The names of the signals to emit upon failure.
1590
+ * @return {this} Returns the current instance for chaining.
1591
+ */
1592
+ emitsOnFail(...signals: SignalDefinitionInput[]): this;
1593
+ /**
1594
+ * Attaches a signal to the current context and emits metadata if the register flag is set.
1595
+ *
1596
+ * @param {...string} signals - The names of the signals to attach.
1597
+ * @return {void} This method does not return a value.
1598
+ */
1599
+ attachSignal(...signals: SignalDefinitionInput[]): Task;
1545
1600
  /**
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.
1601
+ * Unsubscribes the current instance from the specified signals.
1602
+ * This method removes the signals from the observedSignals set, unsubscribes
1603
+ * from the underlying broker, and emits metadata for the unsubscription if applicable.
1548
1604
  *
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.
1605
+ * @param {string[]} signals - The list of signal names to unsubscribe from.
1606
+ * @return {this} Returns the current instance for method chaining.
1553
1607
  */
1554
- validateSignalName(signalName: string): void;
1608
+ unsubscribe(...signals: string[]): this;
1555
1609
  /**
1556
- * Initializes with runners.
1557
- * @param runner Standard runner for user signals.
1558
- * @param metaRunner Meta runner for 'meta.' signals (suppresses further meta-emits).
1610
+ * Unsubscribes from all currently observed signals and clears the list of observed signals.
1611
+ *
1612
+ * @return {this} The instance of the class to allow method chaining.
1559
1613
  */
1560
- bootstrap(runner: GraphRunner, metaRunner: GraphRunner): void;
1614
+ unsubscribeAll(): this;
1561
1615
  /**
1562
- * Initializes and sets up the various tasks for managing and processing signals.
1616
+ * Detaches the specified signals from being emitted after execution and optionally emits metadata for each detached signal.
1563
1617
  *
1564
- * @return {void} This method does not return a value.
1618
+ * @param {...string} signals - The list of signal names to be detached. Signals can be in the format "namespace:signalName".
1619
+ * @return {this} Returns the current instance of the object for method chaining.
1565
1620
  */
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;
1621
+ detachSignals(...signals: string[]): this;
1592
1622
  /**
1593
- * Emits `signal` repeatedly with a fixed interval.
1623
+ * Detaches all signals associated with the object by invoking the `detachSignals` method
1624
+ * and clearing the `signalsToEmitAfter` collection.
1594
1625
  *
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.
1626
+ * @return {this} Returns the current instance to allow method chaining.
1601
1627
  */
1602
- interval(signal: string, context: AnyObject, intervalMs?: number, leading?: boolean, startDateTime?: Date): ThrottleHandle;
1628
+ detachAllSignals(): this;
1629
+ respondsTo(...inquires: string[]): this;
1630
+ usesHelpers(helpers: Record<string, HelperDefinition | undefined>): this;
1631
+ usesGlobals(globals: Record<string, GlobalDefinition | undefined>): this;
1632
+ attachIntents(...intentNames: string[]): this;
1633
+ detachIntents(...intentNames: string[]): this;
1634
+ detachAllIntents(): this;
1603
1635
  /**
1604
- * Emits a signal with the specified context, triggering any associated handlers for that signal.
1636
+ * Maps over the signals in the `signalsToEmitAfter` set and applies a callback function to each signal.
1605
1637
  *
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.
1638
+ * @param {function(string): void} callback - A function that is called with each signal
1639
+ * in the `signalsToEmitAfter` set, providing the signal as an argument.
1640
+ * @return {Array<any>} An array containing the results of applying the callback
1641
+ * function to each signal.
1611
1642
  */
1612
- emit(signal: string, context?: AnyObject, options?: EmitOptions): void;
1643
+ mapSignals(callback: (signal: string) => void): void[];
1613
1644
  /**
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.
1645
+ * Maps over the signals in `signalsToEmitOnFail` and applies the provided callback to each signal.
1617
1646
  *
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.
1647
+ * @param {function(string): void} callback - A function that receives each signal as a string and performs an operation or transformation on it.
1648
+ * @return {Array} The array resulting from applying the callback to each signal in `signalsToEmitOnFail`.
1621
1649
  */
1622
- execute(signal: string, context: AnyObject): boolean;
1650
+ mapOnFailSignals(callback: (signal: string) => void): void[];
1623
1651
  /**
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.
1652
+ * Maps over the observed signals with the provided callback function.
1627
1653
  *
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.
1654
+ * @param {function(string): void} callback - A function to execute on each signal in the observed signals array.
1655
+ * @return {Array} A new array containing the results of calling the callback function on each observed signal.
1631
1656
  */
1632
- executeListener(signal: string, context: AnyObject): boolean;
1657
+ mapObservedSignals(callback: (signal: string) => void): void[];
1633
1658
  /**
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.
1659
+ * Emits a collection of signals stored in the `signalsToEmitAfter` array.
1638
1660
  *
1639
- * @param {string} signal - The name of the signal to be added.
1661
+ * @param {GraphContext} context - The context object containing data or state to be passed to the emitted signals.
1662
+ * @return {void} This method does not return a value.
1663
+ */
1664
+ emitSignals(context: GraphContext): void;
1665
+ /**
1666
+ * Emits registered signals when an operation fails.
1667
+ *
1668
+ * @param {GraphContext} context - The context from which the full context is derived and passed to the signals being emitted.
1640
1669
  * @return {void} This method does not return any value.
1641
1670
  */
1642
- addSignal(signal: string, metadata?: SignalMetadata | null): void;
1671
+ emitOnFailSignals(context: GraphContext): void;
1643
1672
  /**
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.
1673
+ * Cleans up and destroys the task instance, detaching it from other tasks and
1674
+ * performing necessary cleanup operations.
1675
+ *
1676
+ * This method:
1677
+ * - Unsubscribes from all signals and events.
1678
+ * - Detaches all associated signal handlers.
1679
+ * - Removes the task from successor and predecessor task mappings.
1680
+ * - Clears all task relationships and marks the task as destroyed.
1681
+ * - Emits destruction metrics, if applicable.
1682
+ *
1683
+ * @return {void} No value is returned because the function performs clean-up operations.
1648
1684
  */
1649
- observe(signal: string, routineOrTask: Task | GraphRoutine, metadata?: SignalMetadata | null): void;
1650
- registerEmittedSignal(signal: string, metadata?: SignalMetadata | null): void;
1685
+ destroy(): void;
1651
1686
  /**
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.
1687
+ * Exports the current state of the object as a structured plain object.
1688
+ *
1689
+ * @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:
1690
+ * - Name and description of the task.
1691
+ * - Layer index, uniqueness, meta, and signal-related flags.
1692
+ * - Event triggers and attached signals.
1693
+ * - Throttling, concurrency, timeout settings, and ephemeral flag.
1694
+ * - Task function as a string.
1695
+ * - Serialization of getter callbacks and schemas for input/output validation.
1696
+ * - Relationships such as next tasks, failure tasks, and predecessor tasks.
1656
1697
  */
1657
- unsubscribe(signal: string, routineOrTask: Task | GraphRoutine): void;
1698
+ export(): AnyObject;
1658
1699
  /**
1659
- * Lists all observed signals.
1660
- * @returns Array of signals.
1700
+ * Returns an iterator for iterating over tasks associated with this instance.
1701
+ *
1702
+ * @return {TaskIterator} An iterator instance for tasks.
1661
1703
  */
1662
- listObservedSignals(): string[];
1663
- listEmittedSignals(): string[];
1664
- reset(): void;
1665
- shutdown(): void;
1704
+ getIterator(): TaskIterator;
1705
+ /**
1706
+ * Accepts a visitor object to perform operations on the current instance.
1707
+ *
1708
+ * @param {GraphVisitor} visitor - The visitor object implementing operations for this instance.
1709
+ * @return {void} This method does not return a value.
1710
+ */
1711
+ accept(visitor: GraphVisitor): void;
1712
+ log(): void;
1666
1713
  }
1667
1714
 
1668
1715
  /**
@@ -1794,7 +1841,7 @@ declare class EphemeralTask extends Task {
1794
1841
  execute(context: any, emit: (signal: string, context: AnyObject) => void, inquire: (inquiry: string, context: AnyObject, options: InquiryOptions) => Promise<AnyObject>, progressCallback: (progress: number) => void, nodeData: {
1795
1842
  nodeId: string;
1796
1843
  routineExecId: string;
1797
- }): TaskResult;
1844
+ }): boolean | void | AnyObject | Generator<unknown, any, any> | Promise<any>;
1798
1845
  }
1799
1846
 
1800
1847
  /**
@@ -1993,6 +2040,7 @@ interface ActorSpec<D extends Record<string, any>, R = AnyObject> {
1993
2040
  interface ActorFactoryOptions<D extends Record<string, any> = Record<string, any>, R = AnyObject> {
1994
2041
  isMeta?: boolean;
1995
2042
  definitionSource?: ActorDefinition<D, R>;
2043
+ hydrateDurableState?: (actorKey: string) => Promise<ActorDurableStateHydration<D> | null>;
1996
2044
  }
1997
2045
  /**
1998
2046
  * Optional per-binding behavior when wrapping actor handlers.
@@ -2070,11 +2118,16 @@ interface ActorTaskContext<D extends Record<string, any>, R = AnyObject> {
2070
2118
  reduceRuntimeState: (reducer: ActorStateReducer<R>) => void;
2071
2119
  emit: (signal: string, payload?: AnyObject) => void;
2072
2120
  inquire: (inquiry: string, context?: AnyObject, options?: InquiryOptions) => Promise<AnyObject>;
2121
+ tools: RuntimeTools;
2073
2122
  }
2074
2123
  /**
2075
2124
  * Handler signature used by `actor.task(...)`.
2076
2125
  */
2077
2126
  type ActorTaskHandler<D extends Record<string, any>, R = AnyObject> = (context: ActorTaskContext<D, R>) => TaskResult | ActorStateReducer<D> | Promise<TaskResult | ActorStateReducer<D>>;
2127
+ interface ActorDurableStateHydration<D extends Record<string, any>> {
2128
+ durableState: D;
2129
+ durableVersion: number;
2130
+ }
2078
2131
  /**
2079
2132
  * Metadata attached to wrapped actor task functions.
2080
2133
  */
@@ -2101,9 +2154,11 @@ declare class Actor<D extends Record<string, any> = AnyObject, R = AnyObject> {
2101
2154
  readonly spec: ActorSpec<D, R>;
2102
2155
  readonly kind: ActorKind;
2103
2156
  private readonly sourceDefinition?;
2157
+ private readonly hydrateDurableState?;
2104
2158
  private readonly stateByKey;
2105
2159
  private readonly sessionByKey;
2106
2160
  private readonly idempotencyByKey;
2161
+ private readonly pendingHydrationByKey;
2107
2162
  private readonly writeQueueByKey;
2108
2163
  private nextTaskBindingIndex;
2109
2164
  /**
@@ -2126,6 +2181,10 @@ declare class Actor<D extends Record<string, any> = AnyObject, R = AnyObject> {
2126
2181
  * Returns runtime state reference for the resolved key.
2127
2182
  */
2128
2183
  getRuntimeState(actorKey?: string): R;
2184
+ /**
2185
+ * Lists all currently materialized actor keys.
2186
+ */
2187
+ listActorKeys(): string[];
2129
2188
  /**
2130
2189
  * Alias of `getDurableVersion`.
2131
2190
  */
@@ -2154,6 +2213,7 @@ declare class Actor<D extends Record<string, any> = AnyObject, R = AnyObject> {
2154
2213
  private resolveInitialDurableState;
2155
2214
  private resolveInitialRuntimeState;
2156
2215
  private ensureStateRecord;
2216
+ private maybeHydrateStateRecord;
2157
2217
  private touchSession;
2158
2218
  private pruneExpiredActorKeys;
2159
2219
  private isSessionExpired;
@@ -2164,6 +2224,250 @@ declare class Actor<D extends Record<string, any> = AnyObject, R = AnyObject> {
2164
2224
  private emitActorCreatedSignal;
2165
2225
  }
2166
2226
 
2227
+ type RuntimeHandlerLanguage = "js" | "ts";
2228
+ type RuntimeTaskDefinitionKind = "task" | "metaTask";
2229
+ type RuntimeHelperDefinitionKind = "helper" | "metaHelper";
2230
+ type RuntimeGlobalDefinitionKind = "global" | "metaGlobal";
2231
+ type RuntimeSignalEmissionMode = "attach" | "after" | "onFail";
2232
+ type RuntimeSharingMode = "isolated" | "shared";
2233
+ type RuntimeSessionRole = "owner" | "writer" | "observer";
2234
+ type RuntimeTaskOptions = Omit<TaskOptions, "getTagCallback">;
2235
+ interface RuntimeTaskDefinition {
2236
+ name: string;
2237
+ description?: string;
2238
+ handlerSource: string;
2239
+ language: RuntimeHandlerLanguage;
2240
+ kind?: RuntimeTaskDefinitionKind;
2241
+ options?: RuntimeTaskOptions;
2242
+ }
2243
+ interface RuntimeHelperDefinition {
2244
+ name: string;
2245
+ description?: string;
2246
+ handlerSource: string;
2247
+ language: RuntimeHandlerLanguage;
2248
+ kind?: RuntimeHelperDefinitionKind;
2249
+ }
2250
+ interface RuntimeGlobalDefinition {
2251
+ name: string;
2252
+ description?: string;
2253
+ value: unknown;
2254
+ kind?: RuntimeGlobalDefinitionKind;
2255
+ }
2256
+ interface RuntimeRoutineDefinition {
2257
+ name: string;
2258
+ description?: string;
2259
+ startTaskNames: string[];
2260
+ isMeta?: boolean;
2261
+ }
2262
+ interface RuntimeActorTaskDefinition {
2263
+ actorName: string;
2264
+ taskName: string;
2265
+ description?: string;
2266
+ mode?: ActorTaskMode;
2267
+ handlerSource: string;
2268
+ language: RuntimeHandlerLanguage;
2269
+ options?: RuntimeTaskOptions;
2270
+ }
2271
+ interface RuntimeTaskLinkDefinition {
2272
+ predecessorTaskName: string;
2273
+ successorTaskName: string;
2274
+ }
2275
+ interface RuntimeSnapshotTask {
2276
+ name: string;
2277
+ version: number;
2278
+ description: string;
2279
+ kind: "task" | "metaTask" | "actorTask";
2280
+ runtimeOwned: boolean;
2281
+ language: RuntimeHandlerLanguage | null;
2282
+ handlerSource: string | null;
2283
+ concurrency: number;
2284
+ timeout: number;
2285
+ retryCount: number;
2286
+ retryDelay: number;
2287
+ retryDelayMax: number;
2288
+ retryDelayFactor: number;
2289
+ validateInputContext: boolean;
2290
+ validateOutputContext: boolean;
2291
+ inputContextSchema: Record<string, unknown>;
2292
+ outputContextSchema: Record<string, unknown>;
2293
+ nextTaskNames: string[];
2294
+ predecessorTaskNames: string[];
2295
+ signals: {
2296
+ emits: string[];
2297
+ emitsAfter: string[];
2298
+ emitsOnFail: string[];
2299
+ observed: string[];
2300
+ };
2301
+ intents: {
2302
+ handles: string[];
2303
+ inquires: string[];
2304
+ };
2305
+ tools: {
2306
+ helpers: Record<string, string>;
2307
+ globals: Record<string, string>;
2308
+ };
2309
+ actorName: string | null;
2310
+ actorMode: ActorTaskMode | null;
2311
+ }
2312
+ interface RuntimeSnapshotHelper {
2313
+ name: string;
2314
+ version: number;
2315
+ description: string;
2316
+ kind: "helper" | "metaHelper";
2317
+ runtimeOwned: boolean;
2318
+ language: RuntimeHandlerLanguage | null;
2319
+ handlerSource: string | null;
2320
+ tools: {
2321
+ helpers: Record<string, string>;
2322
+ globals: Record<string, string>;
2323
+ };
2324
+ }
2325
+ interface RuntimeSnapshotGlobal {
2326
+ name: string;
2327
+ version: number;
2328
+ description: string;
2329
+ kind: "global" | "metaGlobal";
2330
+ runtimeOwned: boolean;
2331
+ value: unknown;
2332
+ }
2333
+ interface RuntimeSnapshotRoutine {
2334
+ name: string;
2335
+ version: number;
2336
+ description: string;
2337
+ isMeta: boolean;
2338
+ runtimeOwned: boolean;
2339
+ startTaskNames: string[];
2340
+ observedSignals: string[];
2341
+ }
2342
+ interface RuntimeSnapshotIntent extends Intent {
2343
+ runtimeOwned: boolean;
2344
+ }
2345
+ interface RuntimeSnapshotSignal {
2346
+ name: string;
2347
+ metadata: SignalMetadata | null;
2348
+ }
2349
+ interface RuntimeSnapshotActorKeyState {
2350
+ actorKey: string;
2351
+ durableState: unknown;
2352
+ runtimeState: unknown;
2353
+ durableVersion: number;
2354
+ runtimeVersion: number;
2355
+ }
2356
+ interface RuntimeSnapshotActor {
2357
+ name: string;
2358
+ description: string;
2359
+ runtimeOwned: boolean;
2360
+ definition: ActorDefinition<Record<string, any>, AnyObject>;
2361
+ actorKeys: RuntimeSnapshotActorKeyState[];
2362
+ }
2363
+ interface RuntimeSnapshotActorTask {
2364
+ actorName: string;
2365
+ taskName: string;
2366
+ description: string;
2367
+ mode: ActorTaskMode;
2368
+ language: RuntimeHandlerLanguage;
2369
+ handlerSource: string;
2370
+ runtimeOwned: boolean;
2371
+ }
2372
+ interface RuntimeSnapshot {
2373
+ runtimeMode: "core";
2374
+ bootstrapped: boolean;
2375
+ mode: string;
2376
+ tasks: RuntimeSnapshotTask[];
2377
+ helpers: RuntimeSnapshotHelper[];
2378
+ globals: RuntimeSnapshotGlobal[];
2379
+ routines: RuntimeSnapshotRoutine[];
2380
+ intents: RuntimeSnapshotIntent[];
2381
+ signals: RuntimeSnapshotSignal[];
2382
+ actors: RuntimeSnapshotActor[];
2383
+ actorTasks: RuntimeSnapshotActorTask[];
2384
+ links: RuntimeTaskLinkDefinition[];
2385
+ }
2386
+ interface RuntimeSubscription {
2387
+ subscriptionId: string;
2388
+ signalPatterns: string[];
2389
+ maxQueueSize: number;
2390
+ createdAt: string;
2391
+ pendingEvents: number;
2392
+ }
2393
+ interface RuntimeSignalEventSource {
2394
+ taskName: string | null;
2395
+ taskVersion: number | null;
2396
+ taskExecutionId: string | null;
2397
+ routineName: string | null;
2398
+ routineVersion: number | null;
2399
+ routineExecutionId: string | null;
2400
+ executionTraceId: string | null;
2401
+ consumed: boolean;
2402
+ consumedBy: string | null;
2403
+ }
2404
+ interface RuntimeSignalEvent {
2405
+ id: string;
2406
+ subscriptionId: string;
2407
+ sequence: number;
2408
+ type: "signal";
2409
+ signal: string;
2410
+ signalName: string;
2411
+ signalTag: string | null;
2412
+ emittedAt: string | null;
2413
+ isMeta: boolean;
2414
+ isSubMeta: boolean;
2415
+ metadata: SignalMetadata | null;
2416
+ source: RuntimeSignalEventSource;
2417
+ context: Record<string, unknown>;
2418
+ }
2419
+ interface RuntimeNextEventResult {
2420
+ subscriptionId: string;
2421
+ event: RuntimeSignalEvent | null;
2422
+ timedOut: boolean;
2423
+ pendingEvents: number;
2424
+ }
2425
+ interface RuntimePollEventsResult {
2426
+ subscriptionId: string;
2427
+ events: RuntimeSignalEvent[];
2428
+ pendingEvents: number;
2429
+ }
2430
+ interface RuntimeInfo {
2431
+ runtimeMode: "core";
2432
+ runtimeSharing: RuntimeSharingMode;
2433
+ runtimeName: string | null;
2434
+ sessionId: string | null;
2435
+ sessionRole: RuntimeSessionRole | null;
2436
+ activeSessionCount: number;
2437
+ daemonProcessId: number | null;
2438
+ bootstrapped: boolean;
2439
+ mode: string;
2440
+ }
2441
+ 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";
2442
+ interface RuntimeProtocolRequest<TPayload = AnyObject> {
2443
+ id?: string | number;
2444
+ operation: RuntimeProtocolOperation;
2445
+ payload?: TPayload;
2446
+ }
2447
+ interface RuntimeProtocolError {
2448
+ code: string;
2449
+ message: string;
2450
+ details?: AnyObject;
2451
+ }
2452
+ interface RuntimeProtocolResponse<TResult = unknown> {
2453
+ id?: string | number;
2454
+ operation: RuntimeProtocolOperation;
2455
+ ok: boolean;
2456
+ result?: TResult;
2457
+ error?: RuntimeProtocolError;
2458
+ }
2459
+ interface RuntimeProtocolHandshake {
2460
+ ready: true;
2461
+ protocol: "cadenza-runtime-jsonl";
2462
+ protocolVersion: "1";
2463
+ runtimeMode: "core";
2464
+ runtimeSharing: RuntimeSharingMode;
2465
+ runtimeName: string | null;
2466
+ sessionId: string | null;
2467
+ sessionRole: RuntimeSessionRole | null;
2468
+ supportedOperations: RuntimeProtocolOperation[];
2469
+ }
2470
+
2167
2471
  interface TaskOptions {
2168
2472
  concurrency?: number;
2169
2473
  timeout?: number;
@@ -2222,11 +2526,15 @@ declare class Cadenza {
2222
2526
  static metaRunner: GraphRunner;
2223
2527
  static registry: GraphRegistry;
2224
2528
  private static taskCache;
2529
+ private static routineCache;
2225
2530
  private static actorCache;
2531
+ private static helperCache;
2532
+ private static globalCache;
2226
2533
  private static runtimeInquiryDelegate;
2227
2534
  private static runtimeValidationPolicy;
2228
2535
  private static runtimeValidationScopes;
2229
2536
  private static emittedMissingSchemaWarnings;
2537
+ private static helperExecutionDepth;
2230
2538
  static isBootstrapped: boolean;
2231
2539
  static mode: CadenzaMode;
2232
2540
  /**
@@ -2266,8 +2574,15 @@ declare class Cadenza {
2266
2574
  * @throws {Error} If the name is not a non-empty string.
2267
2575
  */
2268
2576
  static validateName(name: string): void;
2577
+ static assertGraphMutationAllowed(operationName: string): void;
2578
+ 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;
2579
+ 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;
2269
2580
  private static resolveTaskOptionsForActorTask;
2270
2581
  private static registerActor;
2582
+ static getHelper(name: string): HelperDefinition | undefined;
2583
+ static getAllHelpers(): HelperDefinition[];
2584
+ static getGlobal(name: string): GlobalDefinition | undefined;
2585
+ static getAllGlobals(): GlobalDefinition[];
2271
2586
  /**
2272
2587
  * Executes the specified task or GraphRoutine with the given context using an internal runner.
2273
2588
  *
@@ -2309,6 +2624,7 @@ declare class Cadenza {
2309
2624
  static interval(taskName: string, context: AnyObject, intervalMs: number, leading?: boolean, startDateTime?: Date): void;
2310
2625
  static debounce(signalName: string, context: any, delayMs: number): void;
2311
2626
  static get(taskName: string): Task | undefined;
2627
+ static forgetTask(taskName: string): void;
2312
2628
  static getActor<D extends Record<string, any> = AnyObject, R = AnyObject>(actorName: string): Actor<D, R> | undefined;
2313
2629
  static getAllActors<D extends Record<string, any> = AnyObject, R = AnyObject>(): Actor<D, R>[];
2314
2630
  static getRoutine(routineName: string): GraphRoutine | undefined;
@@ -2414,6 +2730,13 @@ declare class Cadenza {
2414
2730
  * ```
2415
2731
  */
2416
2732
  static createTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions): Task;
2733
+ static createTaskFromDefinition(definition: RuntimeTaskDefinition): Task;
2734
+ static createHelper(name: string, func: HelperFunction, description?: string): HelperDefinition;
2735
+ static createMetaHelper(name: string, func: HelperFunction, description?: string): HelperDefinition;
2736
+ static createHelperFromDefinition(definition: RuntimeHelperDefinition): HelperDefinition;
2737
+ static createGlobal(name: string, value: unknown, description?: string): GlobalDefinition;
2738
+ static createMetaGlobal(name: string, value: unknown, description?: string): GlobalDefinition;
2739
+ static createGlobalFromDefinition(definition: RuntimeGlobalDefinition): GlobalDefinition;
2417
2740
  /**
2418
2741
  * Creates a meta task with the specified name, functionality, description, and options.
2419
2742
  * This is used for creating tasks that lives on the meta layer.
@@ -2676,6 +2999,7 @@ declare class Cadenza {
2676
2999
  * ```
2677
3000
  */
2678
3001
  static createRoutine(name: string, tasks: Task[], description?: string): GraphRoutine;
3002
+ static createRoutineFromDefinition(definition: RuntimeRoutineDefinition): GraphRoutine;
2679
3003
  /**
2680
3004
  * Creates a meta routine with a given name, tasks, and optional description.
2681
3005
  * Routines are named entry points to starting tasks and are registered in the GraphRegistry.
@@ -2689,7 +3013,83 @@ declare class Cadenza {
2689
3013
  * @throws {Error} If no starting tasks are provided.
2690
3014
  */
2691
3015
  static createMetaRoutine(name: string, tasks: Task[], description?: string): GraphRoutine;
3016
+ static snapshotRuntime(): RuntimeSnapshot;
2692
3017
  static reset(): void;
2693
3018
  }
2694
3019
 
2695
- 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 };
3020
+ type RuntimeControlAction = "detach" | "shutdown";
3021
+ interface RuntimeHostOptions {
3022
+ runtimeSharing?: RuntimeSharingMode;
3023
+ runtimeName?: string | null;
3024
+ sessionId?: string | null;
3025
+ sessionRole?: RuntimeSessionRole | null;
3026
+ activeSessionCountProvider?: () => number;
3027
+ daemonProcessId?: number | null;
3028
+ onResetRuntime?: () => void;
3029
+ }
3030
+ declare class RuntimeHost {
3031
+ private readonly subscriptionManager;
3032
+ private readonly runtimeSharing;
3033
+ private readonly runtimeName;
3034
+ private readonly sessionId;
3035
+ private readonly sessionRole;
3036
+ private readonly activeSessionCountProvider;
3037
+ private readonly daemonProcessId;
3038
+ private readonly onResetRuntime;
3039
+ private pendingControlAction;
3040
+ constructor(options?: RuntimeHostOptions);
3041
+ dispose(): void;
3042
+ resetSubscriptions(): void;
3043
+ consumeControlAction(): RuntimeControlAction | null;
3044
+ handshake(): RuntimeProtocolHandshake;
3045
+ handle(request: RuntimeProtocolRequest): Promise<RuntimeProtocolResponse>;
3046
+ private normalizeError;
3047
+ private dispatch;
3048
+ private assertOperationAllowed;
3049
+ private bootstrapRuntime;
3050
+ private runtimeInfo;
3051
+ private detachRuntime;
3052
+ private shutdownRuntime;
3053
+ private resetRuntime;
3054
+ private subscribe;
3055
+ private unsubscribe;
3056
+ private nextEvent;
3057
+ private pollEvents;
3058
+ private upsertTask;
3059
+ private upsertHelper;
3060
+ private upsertGlobal;
3061
+ private linkTasks;
3062
+ private observeTaskSignal;
3063
+ private emitTaskSignal;
3064
+ private bindTaskIntent;
3065
+ private bindTaskHelper;
3066
+ private bindTaskGlobal;
3067
+ private bindHelperHelper;
3068
+ private bindHelperGlobal;
3069
+ private upsertRoutine;
3070
+ private observeRoutineSignal;
3071
+ private upsertIntent;
3072
+ private upsertActor;
3073
+ private upsertActorTask;
3074
+ private runTarget;
3075
+ private emitSignal;
3076
+ private inquireIntent;
3077
+ private requireTask;
3078
+ private requireRoutine;
3079
+ private applyTaskDecorations;
3080
+ private applyHelperDecorations;
3081
+ private applyAllTaskLinks;
3082
+ private applyRoutineDecorations;
3083
+ private rematerializeRoutinesStartingWith;
3084
+ private rematerializeActorTasksFor;
3085
+ private materializeActorTask;
3086
+ private snapshotTask;
3087
+ private snapshotHelper;
3088
+ private snapshotGlobal;
3089
+ private snapshotRoutine;
3090
+ private parseSignalPatterns;
3091
+ private parsePositiveInteger;
3092
+ private parseNonNegativeInteger;
3093
+ }
3094
+
3095
+ 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 };