import { Actor, ActorRef } from "./actor.js"; import { ActorSystem, SpawnOptions } from "./actor_system.js"; import type { ActorDefinition, TypedActorRef } from "./types/functional.js"; /** * Configuration options for a DynamicSupervisor. */ export interface DynamicSupervisorOptions { /** Maximum number of children (default: Infinity) */ maxChildren?: number; /** Maximum restarts within period before child is permanently stopped (default: 3) */ maxRestarts?: number; /** Period in ms for counting restarts (default: 5000) */ periodMs?: number; } /** * Information about a child actor managed by a DynamicSupervisor. */ export interface ChildInfo { /** Reference to the child actor */ ref: ActorRef; /** Name of the actor class */ className: string; /** Registered name (if any) */ name?: string; } /** * Child count statistics for a DynamicSupervisor. */ export interface ChildCounts { /** Number of child specifications (including restarting children) */ specs: number; /** Number of actively running children */ active: number; } /** * DynamicSupervisor provides on-demand supervised child spawning. * * Unlike static supervision trees where children are defined at init time, * a DynamicSupervisor starts with zero children and allows adding them * at runtime via `startChild()`. All children are independent and supervised * with a one-for-one strategy. * * Follows the Agent pattern: an internal actor manages state, while this * wrapper provides a typed public API. * * @example * ```typescript * const dynSup = DynamicSupervisor.start(system, { maxChildren: 10 }); * * // Start children on demand * const ref = await dynSup.startChild(WorkerActor, { args: ['job-1'] }); * * // Works with functional actors too (returns TypedActorRef) * const counter = await dynSup.startChild(Counter, { args: [0] }); * await counter.call('get'); // fully typed! * * // Inspect children * const children = await dynSup.whichChildren(); * const counts = await dynSup.countChildren(); * * // Terminate a specific child * await dynSup.terminateChild(ref); * * // Stop the supervisor (cascades to all children) * await dynSup.stop(); * ``` */ export declare class DynamicSupervisor { private readonly actorRef; private readonly system; private constructor(); /** * Starts a new DynamicSupervisor. * * @param system The actor system * @param options Configuration (maxChildren, restarts, etc.) * @param spawnOptions Spawn options for the supervisor itself (name, etc.) * @returns A new DynamicSupervisor instance * * @example * ```typescript * // Basic * const dynSup = DynamicSupervisor.start(system); * * // With limits * const dynSup = DynamicSupervisor.start(system, { maxChildren: 100 }); * * // Named * const dynSup = DynamicSupervisor.start(system, {}, { name: 'worker-pool' }); * ``` */ static start(system: ActorSystem, options?: DynamicSupervisorOptions, spawnOptions?: SpawnOptions): DynamicSupervisor; /** * Dynamically start a child under this supervisor. * * For functional actors (created with `createActor`), returns a `TypedActorRef` * with full type inference for `call` and `cast`. * * For class-based actors, returns a plain `ActorRef`. * * @throws {MaxChildrenError} If the supervisor has reached its `maxChildren` limit * * @example * ```typescript * // Class-based * const ref = await dynSup.startChild(WorkerActor, { args: ['job-1'] }); * * // Functional (typed) * const counter = await dynSup.startChild(Counter, { args: [0] }); * await counter.call('get'); // TypeScript knows return type * ``` */ startChild any>, TCasts extends Record void>>(actorClass: ActorDefinition, options?: Omit): Promise>; startChild(actorClass: new () => T, options?: Omit): Promise; /** * Terminate a child by ref. * * @param ref The ActorRef of the child to terminate * @returns true if the child was found and stopped, false if not found */ terminateChild(ref: ActorRef): Promise; /** * List all active children with metadata. * * @returns Array of ChildInfo objects describing each active child */ whichChildren(): Promise; /** * Get child counts. * * @returns Object with `specs` and `active` counts */ countChildren(): Promise; /** * Stop the supervisor and all its children. * Children are terminated first (cascading), then the supervisor itself. */ stop(): Promise; /** * Get the supervisor's own ActorRef. * Useful for watching/linking the supervisor itself. */ getRef(): ActorRef; } //# sourceMappingURL=dynamic_supervisor.d.ts.map