import type { ActivityInterceptor } from '../core/interceptor.ts'; import type { WorkerManifest } from './manifest/index.ts'; import { type RegisterMessage, type RemoteWorkerCapabilities } from './protocol.ts'; import type { RemoteWorkerWorkflowDefinition } from './workflow-activity-binding.ts'; /** * Options accepted by `new RemoteWorker(...)`. * * A worker advertises its activities through `workflows`: a map of * `workflowType → { name, activities }`. The SDK builds the qualified * `${workflowType}.${activityName}` table that the protocol expects and * validates that each outer key matches the inner `workflow.name`. This is the * API the engine-side builder produces, and it is required. * * `deploymentName` and `buildId` are required — defaulting them risks a false * deployment-conflict collision between two unrelated apps that both skip the * option and happen to declare different workflows. */ export interface RemoteWorkerOptions { serverUrl: string; workerId?: string; /** * Map of workflow type → workflow definition. The SDK produces qualified * activity names from this map and validates name grammar + key/name match. * This is the single, required activity-advertisement input. */ workflows: Record; concurrency?: number; queue?: string; disconnectTimeoutMs?: number; /** Logical service this worker instance belongs to. */ deploymentName: string; /** Operator-visible release this worker instance is running. */ buildId: string; /** * Trusted digest of the executable artifact this instance loaded. When * omitted, a placeholder digest is derived from the declared workflow and * activity names — tagged `declared-shape:...` so it is never mistaken for * a real content digest. Real build tooling should supply this. Ignored * when `manifest` is supplied, which carries its own `deployment.artifactDigest`. */ artifactDigest?: string; /** * A complete, real manifest built ahead of time — typically by * `buildWorkerManifestFromRegistry` (WFT-29) from the engine's canonical * workflow registry. When supplied, it is advertised verbatim at * registration instead of the `declared-shape:` placeholder this module * otherwise derives from `workflows`, and every other manifest-shaping * option (`deploymentName`, `buildId`, `artifactDigest`, `runtimeVersion`, * `capabilities`) is ignored. * * The constructor requires `manifest.workflows` to declare exactly the * same set of workflow types as `workflows` — a manifest advertising * contracts this instance's dispatch table cannot execute (or omitting * ones it can) is rejected at construction rather than at registration. */ manifest?: WorkerManifest; /** Runtime version string. Defaults to `detectRuntimeVersion()`. */ runtimeVersion?: string; startedAt?: number; capabilities?: RemoteWorkerCapabilities; /** * Headers sent with the WebSocket upgrade request, such as `Authorization`. * When the server enforces authentication, registration requires credentials * with the `workers:write` scope; supply them here. This relies on Bun's * WebSocket constructor header extension and does not apply in browsers. */ headers?: Record; /** Activity interceptors to run around each activity execution on this worker. */ interceptors?: ActivityInterceptor[]; } /** * Construction options including internal knobs that are deliberately kept off * the public {@link RemoteWorkerOptions} surface. The `RemoteWorker` constructor * accepts this wider type; only `RemoteWorkerOptions` is exported from the * package, so consumers never see these fields. */ export interface InternalRemoteWorkerOptions extends RemoteWorkerOptions { /** * Test-only override for the unsent-task-result buffer ceiling. Defaults to * `MAX_BUFFERED_TASK_RESULTS`. Lets a test exercise the backpressure decline * branch with a small cap instead of fabricating a thousand buffered results. */ maxBufferedResults?: number; } /** A `connect()` promise's resolve/reject pair, awaiting `registerAck`. */ export type PendingRegistration = { resolve: () => void; reject: (error: Error) => void; }; /** * Copy a caller-supplied `workflows` map so later mutation of the caller's * own object cannot desync the manifest a future `connect()` advertises from * the activity dispatch table the constructor already built from the same * shape. `buildRegisterMessage` re-derives the manifest from `options.workflows` * on every `connect()`; without this copy that field stays a live reference * to the caller's object for the instance's whole lifetime. */ export declare function snapshotWorkflows(workflows: Record): Record; /** * Assert that a caller-supplied real manifest (`options.manifest`) declares * exactly the workflow types the SDK's own `workflows` dispatch table * declares — no more, no fewer. Called once, at construction, so a mismatch * between build-tool output and the live dispatch table fails fast rather * than surfacing later as a confusing registration rejection or a routed * task this instance cannot actually execute. */ export declare function assertManifestMatchesWorkflows(manifest: WorkerManifest, workflows: Record): void; /** * Build the `register` frame from the worker's resolved options. `workerId` * and `concurrency` are resolved to defaults by the constructor before this * runs; `manifest` carries every identity claim protocol v3 validates. */ export declare function buildRegisterMessage(workerId: string, options: RemoteWorkerOptions): RegisterMessage;