import { WorkflowClient } from "./client.js"; import type { Workflow } from "./types.js"; /** Fired after a job completes; purely observational. */ export interface ActivityEvent { workflowId: string; type: string; jobKey: string; elementId: string; /** For an imperative orchestrator turn: the journalled step key, or "__done". */ step?: string; } /** Options common to both ways of building a `Worker`. */ interface WorkerCommon { workflows: Workflow[]; /** Worker name reported to the gateway. Default "nanobpm-workflow". */ name?: string; /** Transport for the worker's own client (used only when `client` is not * supplied): "auto" | "falcon" | "rest". Defaults to "rest" — job serving is * resilience-critical, and REST long-poll reconnects with backoff after an * engine restart (the ADR 0044 property), whereas the Falcon push transport * does not recover a mid-stream disconnect. Instance creation, by contrast, * defaults to Falcon on its own `WorkflowClient` for throughput. */ transport?: "auto" | "falcon" | "rest"; /** Long-poll timeout per activation, ms. Also bounds stop() latency. Default 10000. */ pollTimeoutMs?: number; /** Job lock timeout, ms. Default 30000. */ jobTimeoutMs?: number; /** Max jobs handled in parallel per derived job type. Default 1. */ maxParallelJobs?: number; onActivity?: (e: ActivityEvent) => void | Promise; onError?: (err: Error, context: { type: string; }) => void; } /** Build a `Worker` from **either** a `baseUrl` (a `WorkflowClient` is created) * **or** an existing `client`. The union makes TypeScript enforce that exactly * one is supplied, matching the constructor's runtime requirement. */ export type WorkerOptions = (WorkerCommon & { /** Base URL of the nanobpmn gateway; a `WorkflowClient` is created for you. */ baseUrl: string; client?: never; }) | (WorkerCommon & { /** An existing `WorkflowClient` to serve jobs through. */ client: WorkflowClient; baseUrl?: never; }); export declare class Worker { private readonly client; private readonly name; private readonly pollTimeoutMs; private readonly jobTimeoutMs; private readonly maxParallelJobs; private readonly onActivity?; private readonly onError?; /** job type → { workflowId, handle } */ private readonly routes; private running; private workers; constructor(opts: WorkerOptions); private register; /** Register a derived job type, failing fast on a collision. Two workflows can * resolve to the same job type (duplicate workflow ids, or a declarative step * name that collides with another workflow's); silently overwriting the route * would drop a handler, so we reject it at construction time. */ private addRoute; /** Invoke the onError observer hook without letting it affect the poll loop — * a throwing observer must not permanently stop a route. */ private emitError; /** Invoke the onActivity observer hook in isolation. It runs after the job has * already been completed, so a throwing observer must not fall into the * failure path and try to fail an already-completed job. */ private emitActivity; /** The derived job types this worker serves. */ get servedTypes(): string[]; /** Begin serving. Creates one nano-sdk job worker per derived job type with * `autoStart: false`, then starts each explicitly, so the poll lifecycle is * deterministic and owned here rather than left to the SDK's auto-start * default (matching the `JobWorkerConfig.autoStart` contract). Nothing polls * before `start()` is called. */ start(): void; /** Stop serving and wait for in-flight jobs to drain. Stopping is best-effort * per worker: the Falcon worker's `stop` throws if it never bound a transport * (detection still pending), which must not fail the whole shutdown. */ stop(): Promise; /** Dispatch one activated job to its route handler and acknowledge it. Returns * the nano-sdk action receipt (its `complete`/`fail` result). */ private handleJob; } export {};