import type { ServerWebSocket } from 'bun'; import type { Engine } from '../../core/engine.ts'; import type { WebSocketData } from '../json-rpc-websocket-runtime.ts'; import type { ServerContext } from './context.ts'; /** * Default per-workflow cap for one-way workflow WebSocket connections * (`/stream` and `/watch`). Mirrors the JSON-RPC subscription default so one * workflow cannot consume unbounded server sockets. */ export declare const DEFAULT_MAX_STREAM_CONNECTIONS_PER_WORKFLOW = 100; export type WorkflowStreamConnectionLease = { release(): void; }; export declare function sendStreamMessage(ws: ServerWebSocket, sequence: number, message: string): void; export declare function sendWatchMessage(ws: ServerWebSocket, sequence: number, message: string): void; export declare function getHighestStoredStreamSequence(engine: Engine, workflowId: string, key: string): Promise; export declare function getHighestStoredWatchSequence(engine: Engine, workflowId: string): Promise; export declare function addStreamSocket(context: ServerContext, workflowId: string, ws: ServerWebSocket): boolean; export declare function addWatchSocket(context: ServerContext, workflowId: string, ws: ServerWebSocket): boolean; export declare function removeStreamSocket(context: ServerContext, ws: ServerWebSocket): void; export declare function removeWatchSocket(context: ServerContext, ws: ServerWebSocket): void; export declare function removeWorkflowStreamConnection(context: ServerContext, ws: ServerWebSocket): void; export declare function acquireWorkflowStreamConnection(context: ServerContext, workflowId: string): WorkflowStreamConnectionLease | null; export declare function flushPendingStreamMessages(_context: ServerContext, ws: ServerWebSocket): void; export declare function flushPendingWatchMessages(_context: ServerContext, ws: ServerWebSocket): void; export declare function publishTokenMessage(context: ServerContext, workflowId: string, sequence: number, message: string): void; export declare function publishWatchMessage(context: ServerContext, workflowId: string, sequence: number, message: string): void; /** * Send existing token chunks from storage to a newly connected stream client, * so it can catch up on tokens emitted before the connection was established. */ export declare function replayTokenStream(context: ServerContext, engine: Engine, ws: ServerWebSocket, workflowId: string): Promise; /** * Send stored raw watch events to a newly connected watch client. The raw * watch transport keeps its historical frame shape but now honors the same * `resumeFrom` cursor query parameter used by token streams. */ export declare function replayWatchEvents(context: ServerContext, engine: Engine, ws: ServerWebSocket, workflowId: string): Promise;