import EventEmitter from "eventemitter3"; import ReconnectingWebSocket from "reconnecting-websocket"; import { ITranscriptionService } from "../interfaces/ITranscriptionService"; import { TelemetryRow, TelemetrySnapshot, TranscriptionMetricsProvider } from "../metrics"; import { BatchReprocessConfig, BatchReprocessStatus, ResolvedWhisperConnectionContext } from "../batchReprocess"; import type { DebugAuditFile } from "../audit"; import { SttAuditIngestionConfig, SttAuditIngestionWarning } from "../sttAuditIngestion"; interface IConnectionResilienceConfig { connectTimeoutMs?: number; healthCheckIntervalMs?: number; maxBufferedAmountBytes?: number; drainStallTimeoutMs?: number; preRecoveryReplayMs?: number; reconnectBaseDelayMs?: number; reconnectMaxDelayMs?: number; reconnectDelayGrowFactor?: number; minConnectionUptimeMs?: number; maxReconnectAttempts?: number; } interface ITranscriptionConfig { language: string; translation_lang?: string; external_id?: string; record?: boolean; token?: string; headers?: Record; resolvedEndpointUrl?: string; resolvedConnectionContext?: ResolvedWhisperConnectionContext; ws: ReconnectingWebSocket; provider?: TranscriptionMetricsProvider; resilience?: IConnectionResilienceConfig; finalUpload?: { mode?: "stream" | "blob"; format?: "pcm" | "wav"; endpoint?: string; }; batchReprocess?: BatchReprocessConfig; auditIngestion?: SttAuditIngestionConfig; debug?: boolean | { enabled?: boolean; advancedMetrics?: boolean; }; } type ResilienceConnectionState = "connecting" | "connected" | "reconnecting" | "disconnected" | "stopped"; type ResilienceWebSocketState = "connecting" | "open" | "closing" | "closed" | "unavailable"; type FinishDeliveryState = "sent" | "skipped_socket_closed" | "timed_out"; export interface WhisperSttSessionInfo { sttSessionId: string; externalId: string | null; connectionAttempt: number; } export declare class WhisperTranscriptionAdapter extends EventEmitter implements ITranscriptionService { private static sharedAudioContext; private static sharedAudioContextLeaseCount; private static sharedAudioContextIdleCloseTimer; private static sharedWorkletModuleReadyPromise; private static sharedWorkletBlobUrl; private websocket; private readonly websocketFactoryConfig; private audioContext; private mediaStream; private input; private tempPartialTranscription; private connectionSequence; private currentSttSessionId; private sttSessionIds; private recordState; private recordingNode; private readonly resilienceConfig; private readonly finalUploadConfig?; private readonly batchReprocessConfig?; private readonly sttAuditIngestionConfig?; private readonly resolvedConnectionContext?; private readonly metricsCollector; private durableAudioSession; private replayOrchestrator; private durableReplayInFlight; private lastProducedSeq; private latestConsultationStorageStatus; private consultationStatusRefreshTimer; private consultationStatusRefreshInFlight; private consultationStatusRefreshQueued; private lastConsultationStatusRefreshAt; private healthCheckTimer; private batchReprocessExpiryTimer; private intentionalStop; private hasConnectedOnce; private awaitingReconnection; private lastReconnectAttempt; private suppressNextReconnectEvent; private pendingDisconnectDetails; private finishDeliveryState; private stopFinalizationState; private stopInFlightPromise; private connectionState; private currentReconnectAttempt; private nextReconnectDelayMs; private lastDisconnectDetails; private hasAudioContextLease; private browserOnline; private terminalCleanupPromise; private lifecyclePhase; private batchReprocessStatus; private readonly handleBrowserOnline; private readonly handleBrowserOffline; constructor(config: ITranscriptionConfig); private extractWebSocketFactoryConfig; private createLegacyResolvedConnectionContext; private createWaitingBatchReprocessStatus; private isBatchReprocessConfigured; private areBatchReprocessErrorsEqual; private areBatchReprocessStatusesEqual; private clearBatchReprocessExpiryTimer; private scheduleBatchReprocessExpiry; private setBatchReprocessStatus; private syncBatchReprocessStatus; private transitionBatchReprocessStatusAfterStop; private markBatchReprocessError; getBatchReprocessStatus(): BatchReprocessStatus; getBatchReprocessRemainingTime(): number | null; getSttSessionId(): string | null; getSttSessionIds(): string[]; private ensureWebSocketForStart; private setupDurableRuntime; private canTransitionLifecycle; private logLifecycle; private transitionLifecycle; private canProcessAudioFrames; private refreshConsultationStorageStatus; private maybeRunDurableReplay; private readableStreamToBlob; private uploadFinalArchiveIfConfigured; reprocessAudio(): Promise; private buildBatchReprocessUrl; private buildBatchReprocessHeaders; ingestSttAudit(audit: DebugAuditFile): Promise; private buildSttAuditIngestionUrl; private buildSttAuditIngestionHeaders; private buildSttAuditIngestionPayload; private resolveSttAuditThreadId; private resolveSttAuditExternalIdentifier; private getAuditMetadataString; private asNonEmptyString; private waitForSttAuditRetry; private static cancelSharedAudioContextIdleClose; private static scheduleSharedAudioContextClose; private static getSharedWorkletBlobUrl; private static releaseSharedWorkletBlobUrl; private static closeSharedAudioContextImmediately; private ensureWorkletModuleLoaded; private restartPhaseForStart; private releaseAudioContextLease; static __resetSharedAudioRuntimeForTests(): Promise; startTranscription(mediaStream: MediaStream): Promise; private ensureAudioContext; setupRecordingWorkletNode(): Promise; private postMessage; private bindWebsocket; private startHealthChecks; private stopHealthChecks; private detachAudioPipeline; private stopMediaStreamTracks; private closeAudioContext; private closeWebSocket; private releaseRuntimeResources; private scheduleTerminalCleanup; private isBrowserOffline; private bindBrowserNetworkListeners; private removeBrowserNetworkListeners; private reconnectTransport; private shouldBufferOfflineAudio; private waitForTransportDrain; private delay; private requestPersistentStorage; private getReconnectEventDetails; private handleAuthRejection; private isTerminalDisconnect; private getRetryCount; private getMaxRetries; private getWebSocketState; private getRemainingReconnectAttempts; private emitResilienceStatus; private getBufferedAudioBytes; getResilienceStatus(): { connectionState: ResilienceConnectionState; websocketState: ResilienceWebSocketState; browserOnline: boolean; hasConnectedOnce: boolean; isRecovering: boolean; isBufferingAudio: boolean; isDrainingAudio: boolean; transportBufferedAmountBytes: number; pendingBufferedAudioBytes: number; pendingBufferedAudioChunks: number; persistedBufferedAudioBytes: number; persistedBufferedAudioSegments: number; totalBufferedAudioBytes: number; bufferingStartedAt: null; drainStartedAt: null; lastDrainProgressAt: null; drainCycles: number; drainExitReason: null; reconnectAttempt: number | null; nextReconnectDelayMs: number | null; finishDeliveryState: FinishDeliveryState | null; maxReconnectAttempts: any; remainingReconnectAttempts: number | null; lastDisconnect: { code: number | undefined; reason: string | undefined; wasClean: boolean | undefined; errorMessage: string | undefined; } | null; }; getTelemetrySnapshot(): TelemetrySnapshot; getTelemetryRows(): TelemetryRow[]; clearTelemetryRows(): void; resetTelemetry(): void; private getReconnectDelay; private toError; private logStopFlow; private settleStopFinalization; private emitPartialFallbackAsFinalIfPresent; private trySendStopFinish; private maybeHandleStopFinalizationOnClose; private maybeHandleStopFinalizationOnMessage; private handleStopTerminalTranscriptPayload; private isTerminalStopMessage; private handleParsedTranscriptMessage; private trackSttSession; private languageSelector; private sendAudioConfig; private decreaseSampleRate; private convertFloat32ToInt16; private getAudioPayloadDurationMs; pauseTranscription(): void; resumeTranscription(): void; stopTranscription(): Promise; private freezeInputPhase; private finalizeServerPhase; private cleanupPhase; private performStopTranscription; } export {}; //# sourceMappingURL=WhisperTranscriptionAdapter.d.ts.map