/** * Canonical RemoteWorker WebSocket protocol contract. * * This module owns the parser trust boundary: every guard below maps to one * documented schema field. Wire-shape types live in `./protocol-messages.ts`, * JSON Schema documents in `./protocol-schemas.ts`, the `taskResult` variant * parser in `./protocol-task-result.ts`, and internal helpers in * `./protocol-internals.ts`. All are re-exported so the public surface * `@lostgradient/weft/worker-protocol` stays a single import path. * * @module worker/protocol */ import type { RemoteWorkerProtocolFailure, RemoteWorkerProtocolParseResult } from './protocol-internals.ts'; import { isRemoteWorkerJsonValue } from './protocol-internals.ts'; import type { CancelMessage, CancelledTaskResultMessage, CompletedTaskResultMessage, FailedTaskResultMessage, HeartbeatMessage, ProtocolErrorMessage, RegisterAckMessage, RegisterErrorMessage, RegisterMessage, RemoteWorkerCapabilities, RemoteWorkerJsonValue, ShutdownMessage, TaskMessage } from './protocol-messages.ts'; import { REMOTE_WORKER_MESSAGE_SCHEMAS, REMOTE_WORKER_PROTOCOL_JSON_SCHEMA } from './protocol-schemas.ts'; import type { TaskResultMessage } from './protocol-task-result.ts'; import type { RemoteWorkerProtocolVersion } from './protocol-version.ts'; import { REMOTE_WORKER_MAX_PROTOCOL_VERSION, REMOTE_WORKER_MIN_PROTOCOL_VERSION, REMOTE_WORKER_PROTOCOL_VERSION, REMOTE_WORKER_SUPPORTED_PROTOCOL_VERSIONS } from './protocol-version.ts'; export { REMOTE_WORKER_MAX_PROTOCOL_VERSION, REMOTE_WORKER_MESSAGE_SCHEMAS, REMOTE_WORKER_MIN_PROTOCOL_VERSION, REMOTE_WORKER_PROTOCOL_JSON_SCHEMA, REMOTE_WORKER_PROTOCOL_VERSION, REMOTE_WORKER_SUPPORTED_PROTOCOL_VERSIONS, isRemoteWorkerJsonValue, }; export type { CancelMessage, CancelledTaskResultMessage, CompletedTaskResultMessage, FailedTaskResultMessage, HeartbeatMessage, ProtocolErrorMessage, RegisterAckMessage, RegisterErrorMessage, RegisterMessage, RemoteWorkerCapabilities, RemoteWorkerJsonValue, RemoteWorkerProtocolFailure, RemoteWorkerProtocolParseResult, RemoteWorkerProtocolVersion, ShutdownMessage, TaskMessage, TaskResultMessage, }; /** * Messages accepted from a worker stream client. * * @example * ```ts * import type { WorkerToServerMessage } from '@lostgradient/weft/worker-protocol'; * * const message: WorkerToServerMessage = { type: 'heartbeat', workerId: 'worker-1' }; * ``` */ export type WorkerToServerMessage = RegisterMessage | HeartbeatMessage | TaskResultMessage; /** * Messages the server may send to a worker stream client. * * @example * ```ts * import type { ServerToWorkerMessage } from '@lostgradient/weft/worker-protocol'; * * const message: ServerToWorkerMessage = { type: 'shutdown' }; * ``` */ export type ServerToWorkerMessage = RegisterAckMessage | RegisterErrorMessage | ProtocolErrorMessage | TaskMessage | CancelMessage | ShutdownMessage; /** * Parse and validate a worker-to-server protocol message. * @example * ```ts * import { parseWorkerToServerMessage } from '@lostgradient/weft/worker-protocol'; * const result = parseWorkerToServerMessage({ type: 'heartbeat', workerId: 'worker-1' }); * ``` */ export declare function parseWorkerToServerMessage(value: unknown): RemoteWorkerProtocolParseResult; /** * Parse and validate a server-to-worker protocol message. * @example * ```ts * import { parseServerToWorkerMessage } from '@lostgradient/weft/worker-protocol'; * const result = parseServerToWorkerMessage({ type: 'shutdown' }); * ``` */ export declare function parseServerToWorkerMessage(value: unknown): RemoteWorkerProtocolParseResult;