import type { AnyTrace } from '@voiceflow/dtos-interact'; import { FetchClient } from '@voiceflow/fetch'; import type { RuntimeClientOptions, RuntimeInteractStreamRequest, RuntimeLog, RuntimeRequestFileStorageRequest, RuntimeRequestFileStorageResponse, RuntimeUploadFileRequest, RuntimeUploadUserFileRequest, RuntimeUserFileStorageRequest, RuntimeUserFileStorageResponse } from '../runtime.interface'; import { TraceService } from '../trace.service'; import type { ConnectionRequest, WebSocketMessageEvents } from './websocket-runtime.interface'; import { ConnectionState } from './websocket-runtime.interface'; export declare class WebSocketRuntimeClient { protected readonly options: RuntimeClientOptions; protected readonly trace: TraceService; protected readonly fetch: FetchClient; constructor(options: RuntimeClientOptions, trace?: TraceService, fetch?: FetchClient); private state; private socket; private connectionState; /** every interaction whose stream is still open, by `messageID`, in the order they were sent */ private readonly interactions; /** * Traces and states of every interaction, handled one at a time in the order they arrived: * handlers share state across turns, so an old turn's trace must not run alongside a newer one's. */ private traceQueue; private interactionCount; /** the `messageID` of the turn the server last accepted, until its terminal status */ private runningMessageID; /** settles once a newer interaction starts or the client disconnects */ private interactionSuperseded; readonly emitter: import("nanoevents").Emitter; private lastRequest; private newSessionRequired; /** * The session key we last handed to the host app. Only used to keep the persistent * `session-key-update` listener from re-applying a key we already applied. */ private appliedSessionKey; /** * The in-flight `ensureSessionKey()` waiter. Settled by whichever comes first: the persistent * `session-key-update` listener, the timeout, or `disconnect()`. */ private sessionKeyWaiter; versionID: string | null; private unsubscribeStack; private initPromise; setState: (context: T, state: Record) => void; patchState: (state: Record) => void; resetState: (newState?: Record | null) => Promise; init: (request: ConnectionRequest) => Promise; private ensureConnection; /** * Applies a `session-key-update` payload no matter when it lands. Registered persistently for the * lifetime of the socket (see `connect()`) rather than as a one-shot tied to `ensureSessionKey()`, * so a reply that misses that 10s window is still captured instead of leaving the client keyless * on a socket whose server-side session is live. * * Re-requesting the key is NOT an option: `session-key-update` is a *create* - the server runs * `SessionExecutor.createNewSession()`, ending the live session and opening a new transcript. The * retryable half is the listen, not the emit. */ private handleSessionKeyUpdate; private settleSessionKeyWaiter; private ensureSessionKey; private connect; private startSession; interactStream(createContext: () => T, request: RuntimeInteractStreamRequest): Promise>; private sendInteraction; private closeInteraction; /** one turn runs at a time, so a turn starting means every turn sent before it is over */ private closeInteractionsBefore; private getInteraction; private supersedeInteractions; private queueTraceTask; private readonly routeTrace; private handleTrace; private readonly routeState; private readonly routeActionStatus; private hasWaitingInteraction; private sendNextWaitingInteraction; processAsyncTrace(context: T, trace: AnyTrace): Promise; disconnect: () => Promise; getConnectionState(): ConnectionState; isReady(): boolean; interactAsync(request: RuntimeInteractStreamRequest): Promise; keepAlive: () => void; /** * Ask the runtime to start listening. An empty payload takes the DTO defaults — PCM 16kHz, client * turns, stop when idle — which is what the recorder produces. */ startASR: () => boolean; stopASR: () => void; /** 16kHz linear16, binary — socket.io sends it as its own frame rather than inside the envelope */ sendASRAudio: (chunk: Blob | ArrayBuffer) => void; onASR: (event: K, listener: WebSocketMessageEvents[K]) => (() => void); interrupt(): Promise; log: ({ error, status, source, message, version, projectID, additionalProperties }: RuntimeLog) => void; requestHandoffFileStorage(request: RuntimeRequestFileStorageRequest): Promise; requestUserFileStorage(request: RuntimeUserFileStorageRequest): Promise; private uploadFileToStorage; uploadUserFile(request: RuntimeUploadUserFileRequest): Promise; uploadHandoffFile(request: RuntimeUploadFileRequest): Promise; } //# sourceMappingURL=websocket-runtime.client.d.ts.map