import type { DeliveredMessage } from "./delivered-message.js"; import type { CreatedAgent } from "./persistent-agent.js"; import type { FabricActor, JsonValue } from "./types.js"; /** Async delivery request to a persistent agent instance + session. */ export interface AgentDispatchRequest { /** Instance id of the target persistent agent. */ id: string; /** Named session within the instance. Defaults to `"default"`. */ session?: string; /** The typed message delivered to the session. */ message: DeliveredMessage; /** Immutable instance creation data. Only the first accepted value is retained. */ initialData?: JsonValue; /** Incarnation precondition: string continues only that instance; null creates only. */ uid?: string | null; /** * Stable identity for idempotent admission. Reusing it with the same * request coalesces delivery in durable stores. */ dispatchId?: string; /** Tenant owning the target session. Hosts may override this at admission. */ tenantId?: string; /** Actor responsible for the dispatch. Hosts may override this at admission. */ actor?: FabricActor; } /** A dispatch request that names its target agent. */ export interface NamedAgentDispatchRequest extends AgentDispatchRequest { agent: string; } /** Acceptance confirmation for an enqueued dispatch. */ export interface DispatchReceipt { dispatchId: string; acceptedAt: string; uid?: string; } /** Internal enqueued form, carrying correlation + isolation metadata. */ export interface DispatchInput { dispatchId: string; agent: string; id: string; session: string; /** The normalized message delivered to the session. */ message: DeliveredMessage; initialData?: JsonValue; uid?: string | null; /** Resolved instance generation stamped by trusted admission. */ instanceUid?: string; acceptedAt: string; tenantId?: string; actor?: FabricActor; /** Admission-resolved static agent durability, persisted for recovery. */ durability?: { maxRetry: number; timeoutAt: number; }; /** Absolute timestamp (ms) after which the dispatch should be aborted. */ timeoutAt?: number; /** Absolute timestamp (ms) after which the dispatch lease expires and may be reclaimed. */ leaseExpiresAt?: number; } /** Consumes enqueued dispatches and applies them to an instance session. */ export interface DispatchProcessor { process(input: DispatchInput): Promise | void; } /** Admission queue for dispatches. The default is in-process; durable backends implement the same shape. */ export interface DispatchQueue { enqueue(input: DispatchInput): Promise; } export interface InMemoryDispatchQueueOptions { /** Lease duration in milliseconds. Default: 5 minutes. */ leaseTimeoutMs?: number; /** Maximum number of concurrent dispatches. Default: Infinity. */ maxConcurrent?: number; } /** * In-process dispatch queue: microtask-drained, concurrent across sessions, * serialized within a single session. Suitable for the `inline`/`stateless` * runtimes and dev. Durable delivery (surviving restarts) is provided by the * Temporal-backed queue, which implements this same interface. */ export declare class InMemoryDispatchQueue implements DispatchQueue { private readonly processor; private readonly leaseTimeoutMs; private readonly maxConcurrent; private readonly pending; private readonly inFlight; private concurrency; private shuttingDown; private drainPromise; private scheduled; constructor(processor: DispatchProcessor, options?: InMemoryDispatchQueueOptions); enqueue(input: DispatchInput): Promise; /** Signal the queue to stop accepting new work. */ shutdown(): void; /** Resolve once the queue has drained all pending and in-flight work. */ whenIdle(): Promise; private sessionKey; private scheduleDrain; private attemptStartDispatches; private runDispatch; } interface DispatchRuntime { queue: DispatchQueue; } /** Configure the ambient dispatch queue used by {@link dispatch}. */ export declare function configureDispatchRuntime(runtime: DispatchRuntime): void; /** Clear the ambient dispatch runtime (tests/teardown). */ export declare function resetDispatchRuntime(): void; /** Register a name for a {@link CreatedAgent} so `dispatch(agent, ...)` can resolve it. */ export declare function registerCreatedAgentName(agent: CreatedAgent, name: string): void; export declare function dispatch(agent: CreatedAgent, request: AgentDispatchRequest): Promise; export declare function dispatch(request: NamedAgentDispatchRequest): Promise; /** Validate + normalize a named request and enqueue it, generating the dispatch id. */ export declare function enqueueDispatch(queue: DispatchQueue, request: NamedAgentDispatchRequest, extra?: { tenantId?: string; actor?: FabricActor; dispatchId?: string; }): Promise; export {}; //# sourceMappingURL=dispatch.d.ts.map