UNPKG

@cadenza.io/core

Version:

This is a framework for building asynchronous graphs and flows of tasks and signals.

955 lines (925 loc) 34.9 kB
type AnyObject = { [key: string | number]: any; }; declare class GraphContext { readonly id: string; readonly fullContext: AnyObject; readonly userData: AnyObject; readonly metadata: AnyObject; constructor(context: AnyObject); /** * Gets frozen user data (read-only, no clone). * @returns Frozen user context. */ getContext(): AnyObject; getClonedContext(): AnyObject; /** * Gets full raw context (cloned for safety). * @returns Cloned full context. */ getFullContext(): AnyObject; getClonedFullContext(): AnyObject; /** * Gets frozen metadata (read-only). * @returns Frozen metadata object. */ getMetadata(): AnyObject; /** * Clones this context (new instance). * @returns New GraphContext. */ clone(): GraphContext; /** * Creates new context from data (via registry). * @param context New data. * @returns New GraphContext. */ mutate(context: AnyObject): GraphContext; /** * Combines with another for uniques (joins userData). * @param otherContext The other. * @returns New combined GraphContext. * @edge Appends other.userData to joinedContexts in userData. */ combine(otherContext: GraphContext): GraphContext; /** * Exports the context. * @returns Exported object. */ export(): { id: string; context: AnyObject; }; } declare abstract class Iterator { abstract hasNext(): boolean; abstract hasPrevious?(): boolean; abstract next(): any; abstract previous?(): any; abstract getFirst?(): any; abstract getLast?(): any; } declare abstract class Graph { /** * Executes this graph node/task. * @param args Execution args (e.g., context). * @returns Result. */ abstract execute(...args: any[]): unknown; /** * Logs the graph node (debugging). */ abstract log(): void; /** * Destroys the graph node. */ abstract destroy(): void; /** * Exports the graph node. * @returns Exported data. */ abstract export(): any; /** * Accepts a visitor for traversal (e.g., debugging/exporters). * @param visitor The visitor. * @note Non-runtime use; pairs with iterator for data extraction. */ abstract accept(visitor: GraphVisitor): void; /** * Gets an iterator for graph traversal (e.g., BFS/DFS). * @returns Iterator. * @note For debugging/exporters. */ abstract getIterator(): Iterator; } declare class GraphNodeIterator implements Iterator { currentNode: GraphNode | undefined; currentLayer: GraphNode[]; nextLayer: GraphNode[]; index: number; constructor(node: GraphNode); hasNext(): boolean; next(): any; } declare abstract class SignalEmitter { silent: boolean; /** * Constructor for signal emitters. * @param silent If true, suppresses all emissions (e.g., for meta-runners to avoid loops; affects all emits). */ constructor(silent?: boolean); /** * Emits a signal via the broker. * @param signal The signal name. * @param data Optional payload (defaults to empty object). */ emit(signal: string, data?: AnyObject): void; /** * Emits a signal via the broker if not silent. * @param signal The signal name. * @param data Optional payload (defaults to empty object). */ emitMetrics(signal: string, data?: AnyObject): void; } declare abstract class ExecutionChain { next: ExecutionChain | undefined; previous: ExecutionChain | undefined; setNext(next: ExecutionChain): void; get hasNext(): boolean; get hasPreceding(): boolean; getNext(): ExecutionChain | undefined; getPreceding(): ExecutionChain | undefined; decouple(): void; } declare class GraphLayerIterator implements Iterator { graph: GraphLayer; currentLayer: GraphLayer | undefined; constructor(graph: GraphLayer); hasNext(): boolean; hasPrevious(): boolean; next(): GraphLayer; previous(): GraphLayer; getFirst(): GraphLayer; getLast(): GraphLayer; } declare abstract class GraphLayer extends ExecutionChain implements Graph { readonly index: number; nodes: GraphNode[]; executionTime: number; executionStart: number; debug: boolean; constructor(index: number); setDebug(value: boolean): void; abstract execute(context?: GraphContext): unknown; get hasPreceding(): boolean; getNumberOfNodes(): number; getNodesByRoutineExecId(routineExecId: string): GraphNode[]; getIdenticalNodes(node: GraphNode): GraphNode[]; isProcessed(): boolean; graphDone(): boolean; setNext(next: GraphLayer): void; add(node: GraphNode): void; start(): number; end(): number; destroy(): void; getIterator(): GraphLayerIterator; accept(visitor: GraphVisitor): void; export(): { __index: number; __executionTime: number; __numberOfNodes: number; __hasNextLayer: boolean; __hasPrecedingLayer: boolean; __nodes: string[]; }; log(): void; } declare class GraphNode extends SignalEmitter implements Graph { id: string; routineExecId: string; task: Task; context: GraphContext; layer: GraphLayer | undefined; divided: boolean; splitGroupId: string; processing: boolean; subgraphComplete: boolean; graphComplete: boolean; result: TaskResult; retryCount: number; retryDelay: number; retries: number; previousNodes: GraphNode[]; nextNodes: GraphNode[]; executionTime: number; executionStart: number; failed: boolean; errored: boolean; destroyed: boolean; debug: boolean; verbose: boolean; constructor(task: Task, context: GraphContext, routineExecId: string, prevNodes?: GraphNode[], debug?: boolean, verbose?: boolean); setDebug(value: boolean): void; isUnique(): boolean; isMeta(): boolean; isProcessed(): boolean; isProcessing(): boolean; subgraphDone(): boolean; graphDone(): boolean; isEqualTo(node: GraphNode): boolean; isPartOfSameGraph(node: GraphNode): boolean; sharesTaskWith(node: GraphNode): boolean; sharesContextWith(node: GraphNode): boolean; getLayerIndex(): number; getConcurrency(): number; getTag(): string; scheduleOn(layer: GraphLayer): void; start(): number; end(): number; execute(): GraphNode[] | Promise<GraphNode[]>; workAsync(): Promise<void>; executeAsync(): Promise<GraphNode[]>; work(): TaskResult | Promise<TaskResult>; emitWithMetadata(signal: string, ctx: AnyObject): void; emitMetricsWithMetadata(signal: string, ctx: AnyObject): void; onProgress(progress: number): void; postProcess(): GraphNode[] | Promise<GraphNode[]>; postProcessAsync(nextNodes: Promise<GraphNode[]>): Promise<GraphNode[]>; finalize(): void; onError(error: unknown, errorData?: AnyObject): void; retry(prevResult?: any): Promise<TaskResult>; retryAsync(prevResult?: any): Promise<TaskResult>; delayRetry(): Promise<void>; divide(): GraphNode[] | Promise<GraphNode[]>; divideAsync(current: Promise<IteratorResult<any>>): Promise<GraphNode[]>; generateNewNodes(result: any): GraphNode[]; differentiate(task: Task): GraphNode; migrate(ctx: any): GraphNode; split(id: string): GraphNode; clone(): GraphNode; consume(node: GraphNode): void; changeIdentity(id: string): void; completeSubgraph(): void; completeGraph(): void; destroy(): void; getIterator(): GraphNodeIterator; mapNext(callback: (node: GraphNode) => any): any[]; accept(visitor: GraphVisitor): void; export(): { __id: string; __task: AnyObject; __context: { id: string; context: AnyObject; }; __result: TaskResult; __executionTime: number; __executionStart: number; __executionEnd: number; __nextNodes: string[]; __previousNodes: string[]; __routineExecId: string; __isProcessing: boolean; __isMeta: boolean; __graphComplete: boolean; __failed: boolean; __errored: boolean; __isUnique: boolean; __splitGroupId: string; __tag: string; }; lightExport(): { __id: string; __task: { __name: string; __version: number; }; __context: { id: string; context: AnyObject; }; __executionTime: number; __executionStart: number; __nextNodes: string[]; __previousNodes: string[]; __routineExecId: string; __isProcessing: boolean; __graphComplete: boolean; __isMeta: boolean; __failed: boolean; __errored: boolean; __isUnique: boolean; __splitGroupId: string; __tag: string; }; log(): void; } declare abstract class GraphVisitor { abstract visitLayer(layer: GraphLayer): any; abstract visitNode(node: GraphNode): any; abstract visitTask(task: Task): any; } declare class TaskIterator implements Iterator { currentTask: Task | undefined; currentLayer: Set<Task>; nextLayer: Set<Task>; iterator: { next: () => { value: Task | undefined; }; }; constructor(task: Task); hasNext(): boolean; next(): Task | undefined; } type SchemaType = "string" | "number" | "boolean" | "array" | "object" | "any"; type SchemaConstraints = { min?: number; max?: number; minLength?: number; maxLength?: number; pattern?: string; enum?: any[]; multipleOf?: number; format?: "email" | "url" | "date-time" | "uuid" | "custom"; oneOf?: any[]; }; type SchemaDefinition = { type: SchemaType; required?: string[]; properties?: { [key: string]: SchemaDefinition; }; items?: SchemaDefinition; constraints?: SchemaConstraints; description?: string; strict?: boolean; }; type TaskFunction = (context: AnyObject, emit: (signal: string, context: AnyObject) => void, progressCallback: (progress: number) => void) => TaskResult; type TaskResult = boolean | AnyObject | Generator | Promise<any> | void; type ThrottleTagGetter = (context?: AnyObject, task?: Task) => string; declare class Task extends SignalEmitter implements Graph { readonly name: string; readonly description: string; version: number; concurrency: number; timeout: number; readonly isMeta: boolean; readonly isSubMeta: boolean; readonly isHidden: boolean; readonly isUnique: boolean; readonly throttled: boolean; readonly isSignal: boolean; readonly isDeputy: boolean; readonly isEphemeral: boolean; readonly isDebounce: boolean; inputContextSchema: SchemaDefinition | undefined; validateInputContext: boolean; outputContextSchema: SchemaDefinition | undefined; validateOutputContext: boolean; readonly retryCount: number; readonly retryDelay: number; readonly retryDelayMax: number; readonly retryDelayFactor: number; layerIndex: number; progressWeight: number; nextTasks: Set<Task>; onFailTasks: Set<Task>; predecessorTasks: Set<Task>; destroyed: boolean; emitsSignals: Set<string>; signalsToEmitAfter: Set<string>; signalsToEmitOnFail: Set<string>; observedSignals: Set<string>; readonly taskFunction: TaskFunction; /** * Constructs a Task (static definition). * @param name Name. * @param task Function. * @param description Description. * @param concurrency Limit. * @param timeout ms. * @param register Register via signal (default true). * @param isUnique * @param isMeta * @param isSubMeta * @param isHidden * @param getTagCallback * @param inputSchema * @param validateInputContext * @param outputSchema * @param validateOutputContext * @param retryCount * @param retryDelay * @param retryDelayMax * @param retryDelayFactor * @edge Emits 'meta.task.created' with { __task: this } for seed. */ 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?: SchemaDefinition | undefined, validateInputContext?: boolean, outputSchema?: SchemaDefinition | undefined, validateOutputContext?: boolean, retryCount?: number, retryDelay?: number, retryDelayMax?: number, retryDelayFactor?: number); getTag(context?: AnyObject): string; setVersion(version: number): void; setTimeout(timeout: number): void; setConcurrency(concurrency: number): void; setProgressWeight(weight: number): void; setInputContextSchema(schema: SchemaDefinition): void; setOutputContextSchema(schema: SchemaDefinition): void; setValidateInputContext(value: boolean): void; setValidateOutputContext(value: boolean): void; emitWithMetadata(signal: string, ctx?: AnyObject): void; emitMetricsWithMetadata(signal: string, ctx?: AnyObject): void; /** * Validates a context deeply against a schema. * @param data - The data to validate (input context or output result). * @param schema - The schema definition. * @param path - The current path for error reporting (default: 'root'). * @returns { { valid: boolean, errors: Record<string, string> } } - Validation result with detailed errors if invalid. * @description Recursively checks types, required fields, and constraints; allows extra properties not in schema. */ validateSchema(data: any, schema: SchemaDefinition | undefined, path?: string): { valid: boolean; errors: Record<string, string>; }; validateInput(context: AnyObject): true | AnyObject; validateOutput(context: AnyObject): true | AnyObject; /** * Executes the task function after optional input validation. * @param context - The GraphContext to validate and execute. * @param emit * @param progressCallback - Callback for progress updates. * @returns TaskResult from the taskFunction or error object on validation failure. * @edge If validateInputContext is true, validates context; on failure, emits 'meta.task.validationFailed' with detailed errors. * @edge If validateOutputContext is true, validates output; on failure, emits 'meta.task.outputValidationFailed' with detailed errors. */ execute(context: GraphContext, emit: (signal: string, context: AnyObject) => void, progressCallback: (progress: number) => void): TaskResult; doAfter(...tasks: Task[]): this; then(...tasks: Task[]): this; decouple(task: Task): void; updateProgressWeights(): void; getSubgraphLayers(): Map<number, Set<Task>>; updateLayerFromPredecessors(): void; hasCycle(): boolean; mapNext(callback: (task: Task) => any, failed?: boolean): any[]; mapPrevious(callback: (task: Task) => any): any[]; /** * Subscribes to signals (chainable). * @param signals The signal names. * @returns This for chaining. * @edge Duplicates ignored; assumes broker.observe binds this as handler. */ doOn(...signals: string[]): this; /** * Sets signals to emit post-execution (chainable). * @param signals The signal names. * @returns This for chaining. */ emits(...signals: string[]): this; emitsOnFail(...signals: string[]): this; /** * Unsubscribes from all observed signals. * @returns This for chaining. */ unsubscribeAll(): this; /** * Unsubscribes from specific signals. * @param signals The signals. * @returns This for chaining. * @edge No-op if not subscribed. */ unsubscribe(...signals: string[]): this; /** * Detaches specific emitted signals. * @param signals The signals. * @returns This for chaining. */ detachSignals(...signals: string[]): this; /** * Detaches all emitted signals. * @returns This for chaining. */ detachAllSignals(): this; mapSignals(callback: (signal: string) => void): void[]; mapOnFailSignals(callback: (signal: string) => void): void[]; /** * Emits attached signals. * @param context The context for emission. * @edge If isMeta (from Task), suppresses further "meta.*" to prevent loops. */ emitSignals(context: GraphContext): void; /** * Emits attached fail signals. * @param context The context for emission. * @edge If isMeta (from Task), suppresses further "meta.*" to prevent loops. */ emitOnFailSignals(context: GraphContext): void; destroy(): void; export(): AnyObject; getIterator(): TaskIterator; accept(visitor: GraphVisitor): void; log(): void; } declare class SyncGraphLayer extends GraphLayer { execute(): GraphNode[]; } declare abstract class GraphExporter { abstract exportGraph(graph: SyncGraphLayer): any; abstract exportStaticGraph(graph: Task[]): any; } declare abstract class GraphBuilder { graph: GraphLayer | undefined; topLayerIndex: number; layers: GraphLayer[]; debug: boolean; setDebug(value: boolean): void; getResult(): GraphLayer; compose(): void; addNode(node: GraphNode): void; addNodes(nodes: GraphNode[]): void; addLayer(index: number): void; createLayer(index: number): GraphLayer; getLayer(layerIndex: number): GraphLayer; reset(): void; } declare abstract class GraphRunStrategy { graphBuilder: GraphBuilder; runInstance?: GraphRun; constructor(); setRunInstance(runInstance: GraphRun): void; changeStrategy(builder: GraphBuilder): void; reset(): void; addNode(node: GraphNode): void; updateRunInstance(): void; abstract run(): void; abstract export(): any; } interface RunJson { __id: string; __label: string; __graph: any; __data: any; } declare class GraphRun { readonly id: string; graph: GraphLayer | undefined; strategy: GraphRunStrategy; exporter: GraphExporter | undefined; constructor(strategy: GraphRunStrategy); setGraph(graph: GraphLayer): void; addNode(node: GraphNode): void; run(): void | Promise<void>; destroy(): void; log(): void; export(): RunJson; setExporter(exporter: GraphExporter): void; } declare class GraphRoutine extends SignalEmitter { readonly name: string; version: number; readonly description: string; readonly isMeta: boolean; tasks: Set<Task>; observedSignals: Set<string>; constructor(name: string, tasks: Task[], description: string, isMeta?: boolean); /** * Applies callback to starting tasks. * @param callBack The callback. * @returns Promise if async. */ forEachTask(callBack: (task: Task) => any): Promise<void>; /** * Sets global Version. * @param version The Version. */ setVersion(version: number): void; /** * Subscribes to signals (chainable). * @param signals The signal names. * @returns This for chaining. * @edge Duplicates ignored; assumes broker.observe binds this as handler. */ doOn(...signals: string[]): this; /** * Unsubscribes from all observed signals. * @returns This for chaining. */ unsubscribeAll(): this; /** * Unsubscribes from specific signals. * @param signals The signals. * @returns This for chaining. * @edge No-op if not subscribed. */ unsubscribe(...signals: string[]): this; /** * Destroys the routine. */ destroy(): void; } declare class GraphRunner extends SignalEmitter { currentRun: GraphRun; debug: boolean; verbose: boolean; isRunning: boolean; readonly isMeta: boolean; strategy: GraphRunStrategy; /** * Constructs a runner. * @param isMeta Meta flag (default false). * @edge Creates 'Start run' meta-task chained to registry gets. */ constructor(isMeta?: boolean); init(): void; /** * Adds tasks/routines to current run. * @param tasks Tasks/routines. * @param context Context (defaults {}). * @edge Flattens routines to tasks; generates routineExecId if not in context. * @edge Emits 'meta.runner.added_tasks' with metadata. * @edge Empty tasks warns no-op. */ addTasks(tasks: Task | GraphRoutine | (Task | GraphRoutine)[], context?: AnyObject): void; /** * Runs tasks/routines. * @param tasks Optional tasks/routines. * @param context Optional context. * @returns Current/last run (Promise if async). * @edge If running, returns current; else runs and resets. */ run(tasks?: Task | GraphRoutine | (Task | GraphRoutine)[], context?: AnyObject): GraphRun | Promise<GraphRun>; runAsync(run: Promise<void>): Promise<GraphRun>; reset(): GraphRun; setDebug(value: boolean): void; setVerbose(value: boolean): void; destroy(): void; setStrategy(strategy: GraphRunStrategy): void; startRun(context: AnyObject): boolean; } declare class SignalBroker { static instance_: SignalBroker; /** * Singleton instance for signal management. * @returns The broker instance. */ static get instance(): SignalBroker; debug: boolean; verbose: boolean; setDebug(value: boolean): void; setVerbose(value: boolean): void; validateSignalName(signalName: string): void; runner: GraphRunner | undefined; metaRunner: GraphRunner | undefined; getSignalsTask: Task | undefined; signalObservers: Map<string, { fn: (runner: GraphRunner, tasks: (Task | GraphRoutine)[], context: AnyObject) => void; tasks: Set<Task | GraphRoutine>; }>; emitStacks: Map<string, Map<string, AnyObject>>; constructor(); /** * Initializes with runners. * @param runner Standard runner for user signals. * @param metaRunner Meta runner for 'meta.' signals (suppresses further meta-emits). */ bootstrap(runner: GraphRunner, metaRunner: GraphRunner): void; init(): void; /** * Observes a signal with a routine/task. * @param signal The signal (e.g., 'domain.action', 'domain.*' for wildcards). * @param routineOrTask The observer. * @edge Duplicates ignored; supports wildcards for broad listening. */ observe(signal: string, routineOrTask: Task | GraphRoutine): void; /** * Unsubscribes a routine/task from a signal. * @param signal The signal. * @param routineOrTask The observer. * @edge Removes all instances if duplicate; deletes if empty. */ unsubscribe(signal: string, routineOrTask: Task | GraphRoutine): void; /** * Emits a signal and bubbles to matching wildcards/parents (e.g., 'a.b.action' triggers 'a.b.action', 'a.b.*', 'a.*'). * @param signal The signal name. * @param context The payload. * @edge Fire-and-forget; guards against loops per execId (from context.__graphExecId). * @edge For distribution, SignalTask can prefix and proxy remote. */ emit(signal: string, context?: AnyObject): void; execute(signal: string, context: AnyObject): boolean; executeListener(signal: string, context: AnyObject): boolean; addSignal(signal: string): void; /** * Lists all observed signals. * @returns Array of signals. */ listObservedSignals(): string[]; reset(): void; } declare class GraphRegistry { static _instance: GraphRegistry; static get instance(): GraphRegistry; tasks: Map<string, Task>; routines: Map<string, GraphRoutine>; registerTask: Task; updateTaskInputSchema: Task; updateTaskOutputSchema: Task; getTaskByName: Task; getTasksByLayer: Task; getAllTasks: Task; doForEachTask: Task; deleteTask: Task; registerRoutine: Task; getRoutineByName: Task; getAllRoutines: Task; doForEachRoutine: Task; deleteRoutine: Task; constructor(); reset(): void; } interface DebounceOptions { leading?: boolean; trailing?: boolean; maxWait?: number; } declare class DebounceTask extends Task { readonly debounceTime: number; leading: boolean; trailing: boolean; maxWait: number; timer: NodeJS.Timeout | null; maxTimer: NodeJS.Timeout | null; hasLaterCall: boolean; lastResolve: ((value: unknown) => void) | null; lastReject: ((reason?: any) => void) | null; lastContext: GraphContext | null; lastTimeout: NodeJS.Timeout | null; lastProgressCallback: ((progress: number) => void) | null; lastEmitFunction: ((signal: string, context: any) => void) | null; constructor(name: string, task: TaskFunction, description?: string, debounceTime?: number, leading?: boolean, trailing?: boolean, maxWait?: number, concurrency?: number, timeout?: number, register?: boolean, isUnique?: boolean, isMeta?: boolean, isSubMeta?: boolean, isHidden?: boolean, inputSchema?: SchemaDefinition | undefined, validateInputSchema?: boolean, outputSchema?: SchemaDefinition | undefined, validateOutputSchema?: boolean); executeFunction(): void; debouncedTrigger(resolve: (value: unknown) => void, reject: (reason?: any) => void, context: GraphContext, timeout: NodeJS.Timeout, emit: (signal: string, context: any) => void, progressCallback: (progress: number) => void): void; execute(context: GraphContext, emit: (signal: string, context: any) => void, progressCallback: (progress: number) => void): TaskResult; } type EphemeralTaskOptions = { once?: boolean; destroyCondition?: (context: any) => boolean; }; declare class EphemeralTask extends Task { readonly once: boolean; readonly condition: (context: any) => boolean; readonly isEphemeral: boolean; constructor(name: string, task: TaskFunction, description?: string, once?: boolean, condition?: (context: any) => boolean, concurrency?: number, timeout?: number, register?: boolean, isUnique?: boolean, isMeta?: boolean, isSubMeta?: boolean, isHidden?: boolean, getTagCallback?: ThrottleTagGetter | undefined, inputSchema?: SchemaDefinition | undefined, validateInputContext?: boolean, outputSchema?: SchemaDefinition | undefined, validateOutputContext?: boolean, retryCount?: number, retryDelay?: number, retryDelayMax?: number, retryDelayFactor?: number); execute(context: any, emit: (signal: string, context: AnyObject) => void, progressCallback: (progress: number) => void): TaskResult; } declare class GraphAsyncRun extends GraphRunStrategy { constructor(); run(): Promise<void>; reset(): void; export(): any; } declare class GraphStandardRun extends GraphRunStrategy { run(): void; export(): any; } interface TaskOptions { concurrency?: number; timeout?: number; register?: boolean; isUnique?: boolean; isMeta?: boolean; isSubMeta?: boolean; isHidden?: boolean; getTagCallback?: ThrottleTagGetter; inputSchema?: SchemaDefinition; validateInputContext?: boolean; outputSchema?: SchemaDefinition; validateOutputContext?: boolean; retryCount?: number; retryDelay?: number; retryDelayMax?: number; retryDelayFactor?: number; } type CadenzaMode = "dev" | "debug" | "verbose" | "production"; declare class Cadenza { static broker: SignalBroker; static runner: GraphRunner; static metaRunner: GraphRunner; static registry: GraphRegistry; static isBootstrapped: boolean; static mode: CadenzaMode; static bootstrap(): void; static get runStrategy(): { PARALLEL: GraphAsyncRun; SEQUENTIAL: GraphStandardRun; }; static setMode(mode: CadenzaMode): void; /** * Validates a name for uniqueness and non-emptiness. * @param name The name to validate. * @throws Error if invalid. */ static validateName(name: string): void; /** * Creates a standard Task and registers it in the GraphRegistry. * @param name Unique identifier for the task. * @param func The function or async generator to execute. * @param description Optional human-readable description for introspection. * @param options Optional task options. * @returns The created Task instance. * @throws Error if name is invalid or duplicate in registry. */ static createTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions): Task; /** * Creates a MetaTask (for meta-layer graphs) and registers it. * MetaTasks suppress further meta-signal emissions to prevent loops. * @param name Unique identifier for the meta-task. * @param func The function or async generator to execute. * @param description Optional description. * @param options Optional task options. * @returns The created MetaTask instance. * @throws Error if name invalid or duplicate. */ static createMetaTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions): Task; /** * Creates a UniqueTask (executes once per execution ID, merging parents) and registers it. * Use for fan-in/joins after parallel branches. * @param name Unique identifier. * @param func Function receiving joinedContexts. * @param description Optional description. * @param options Optional task options. * @returns The created UniqueTask. * @throws Error if invalid. */ static createUniqueTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions): Task; /** * Creates a UniqueMetaTask for meta-layer joins. * @param name Unique identifier. * @param func Function. * @param description Optional. * @param options Optional task options. * @returns The created UniqueMetaTask. */ static createUniqueMetaTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions): Task; /** * Creates a ThrottledTask (rate-limited by concurrency or custom groups) and registers it. * @param name Unique identifier. * @param func Function. * @param throttledIdGetter Optional getter for dynamic grouping (e.g., per-user). * @param description Optional. * @param options Optional task options. * @returns The created ThrottledTask. * @edge If no getter, throttles per task ID; use for resource protection. */ static createThrottledTask(name: string, func: TaskFunction, throttledIdGetter?: ThrottleTagGetter, description?: string, options?: TaskOptions): Task; /** * Creates a ThrottledMetaTask for meta-layer throttling. * @param name Identifier. * @param func Function. * @param throttledIdGetter Optional getter. * @param description Optional. * @param options Optional task options. * @returns The created ThrottledMetaTask. */ static createThrottledMetaTask(name: string, func: TaskFunction, throttledIdGetter: ThrottleTagGetter, description?: string, options?: TaskOptions): Task; /** * Creates a DebounceTask (delays exec until quiet period) and registers it. * @param name Identifier. * @param func Function. * @param description Optional. * @param debounceTime Delay in ms (default 1000). * @param options Optional task options plus optional debounce config (e.g., leading/trailing). * @returns The created DebounceTask. * @edge Multiple triggers within time collapse to one exec. */ static createDebounceTask(name: string, func: TaskFunction, description?: string, debounceTime?: number, options?: TaskOptions & DebounceOptions): DebounceTask; /** * Creates a DebouncedMetaTask for meta-layer debouncing. * @param name Identifier. * @param func Function. * @param description Optional. * @param debounceTime Delay in ms. * @param options Optional task options plus optional debounce config (e.g., leading/trailing). * @returns The created DebouncedMetaTask. */ static createDebounceMetaTask(name: string, func: TaskFunction, description?: string, debounceTime?: number, options?: TaskOptions & DebounceOptions): DebounceTask; /** * Creates an EphemeralTask (self-destructs after exec or condition) without default registration. * Useful for transients; optionally register if needed. * @param name Identifier (may not be unique if not registered). * @param func Function. * @param description Optional. * @param options Optional task options plus optional "once" (true) and "destroyCondition" (ctx => boolean). * @returns The created EphemeralTask. * @edge Destruction triggered post-exec via Node/Builder; emits meta-signal for cleanup. */ static createEphemeralTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions & EphemeralTaskOptions): EphemeralTask; /** * Creates an EphemeralMetaTask for meta-layer transients. * @param name Identifier. * @param func Function. * @param description Optional. * @param options Optional task options plus optional "once" (true) and "destroyCondition" (ctx => boolean). * @returns The created EphemeralMetaTask. */ static createEphemeralMetaTask(name: string, func: TaskFunction, description?: string, options?: TaskOptions & EphemeralTaskOptions): EphemeralTask; /** * Creates a GraphRoutine (named entry to starting tasks) and registers it. * @param name Unique identifier. * @param tasks Starting tasks (can be empty, but warns as no-op). * @param description Optional. * @returns The created GraphRoutine. * @edge If tasks empty, routine is valid but inert. */ static createRoutine(name: string, tasks: Task[], description?: string): GraphRoutine; /** * Creates a MetaRoutine for meta-layer entry points. * @param name Identifier. * @param tasks Starting tasks. * @param description Optional. * @returns The created MetaRoutine. */ static createMetaRoutine(name: string, tasks: Task[], description?: string): GraphRoutine; static reset(): void; } declare class SignalTask extends Task { constructor(signal: string, description?: string); } export { type AnyObject, type CadenzaMode, type DebounceOptions, DebounceTask, EphemeralTask, type EphemeralTaskOptions, GraphContext, GraphRegistry, GraphRoutine, GraphRun, GraphRunner, type SchemaConstraints, type SchemaDefinition, type SchemaType, SignalBroker, SignalEmitter, SignalTask, Task, type TaskFunction, type TaskOptions, type TaskResult, type ThrottleTagGetter, Cadenza as default };