import { Disposable } from "../../../../../base/common/lifecycle.js"; import { CancellationToken } from "../../../../../base/common/cancellation.js"; import { Event } from "../../../../../base/common/event.js"; import { IConfigurationService } from "../../../../../platform/configuration/common/configuration.service.js"; import { ILogService } from "../../../../../platform/log/common/log.service.js"; import { IProductService } from "../../../../../platform/product/common/productService.service.js"; import { IVoicePriorTimelineEntry, IVoicePttStartOptions, IVoiceSessionContext, IVoiceTranscription, IVoiceAudioResponse, IVoiceToolCall, IVoiceSpeechStarted, IVoiceSessionInit, IVoiceFeedbackPayload, IVoiceTurnConfig, IVoiceTurnAutoEnded, IVoiceConnectionIssue, IVoiceFatalDisconnect, IVoiceBargeIn, IVoiceNarrationAck, IVoiceNarrationSignal, IVoiceDispatchResult, IVoiceCheckpointNarrationMetadata, VoiceConfirmationType, VoiceNarrationKind } from "../../common/voiceClient/voiceClientService.js"; import { IVoiceClientService } from "../../common/voiceClient/voiceClientService.service.js"; import { IMicCaptureService } from "./micCaptureService.service.js"; import { ITtsPlaybackService } from "./ttsPlaybackService.service.js"; import { IVoiceLiveSessionResult } from "../../../speech/common/speechService.js"; import { ISpeechService } from "../../../speech/common/speechService.service.js"; export type GptLiveSessionCommandResult = IVoiceLiveSessionResult; export interface IGptLiveDataChannel { readonly readyState: RTCDataChannelState; onmessage: ((event: MessageEvent) => void) | null; onclose: ((event: globalThis.Event) => void) | null; send(data: string): void; close(): void; } export interface IGptLivePeerConnection { readonly iceGatheringState: RTCIceGatheringState; readonly connectionState: RTCPeerConnectionState; readonly localDescription: RTCSessionDescription | null; ontrack: ((event: RTCTrackEvent) => void) | null; onconnectionstatechange: ((event: globalThis.Event) => void) | null; addTrack(track: MediaStreamTrack, ...streams: MediaStream[]): RTCRtpSender; createDataChannel(label: string): IGptLiveDataChannel; createOffer(): Promise; setLocalDescription(description?: RTCLocalSessionDescriptionInit): Promise; setRemoteDescription(description: RTCSessionDescriptionInit): Promise; addEventListener(type: "icegatheringstatechange", listener: () => void): void; removeEventListener(type: "icegatheringstatechange", listener: () => void): void; close(): void; } export declare function resolveAutomaticVoiceLanguage(browserLanguage: string | undefined, displayLanguage: string | undefined): string; export declare class VoiceClientService extends Disposable implements IVoiceClientService { private readonly _configurationService; private readonly _logService; private readonly _productService; private readonly _micCaptureService; private readonly _speechService; private readonly _ttsPlaybackService; readonly _serviceBrand: undefined; private _ws; private _gptLivePeer; private _gptLiveEvents; private _gptLiveAudio; private _gptLiveRemoteStream; private readonly _gptLiveAudioFallback; private _gptLiveTurnId; private _gptLivePassiveTurn; private _gptLivePassiveSpeechStarted; private _gptLiveDelegationId; private _gptLiveInputTranscript; private _gptLiveInputContext; private _gptLiveInputContextAllowed; private readonly _gptLiveDelegations; private _gptLiveOutputTranscript; private _gptLiveOutputStarted; private _gptLiveOutputInterrupted; private _gptLiveOutputSuppressedUntilInput; private _gptLiveOutputTimer; private _usingGptLive; private _gptLiveSessionInitSent; private _gptLiveAvailability; private _gptLiveInputRouter; private _gptLiveInputTarget; private _gptLiveInputStartMs; private _gptLiveInputLastStartMs; private _gptLiveInputEndMs; private readonly _gptLiveInputs; private _gptLiveContext; private _gptLiveInstructionsSent; private _gptLiveSessionAwareness; private _gptLiveBriefing; private _gptLiveBriefingRevision; private _gptLiveAwarenessInstructionsSent; private _gptLiveAwaitingFirstInteraction; private readonly _gptLiveRequest; private readonly _gptLiveDisconnectTimer; private _connectionAttempt; private _intentionalDisconnect; private _reconnectAttempts; private _reconnectStartedAt; private _reconnectTimer; private _isConnected; private _isResuming; private _sessionStartedOnSocket; private _window; private _lastSessionId; private _pingTimer; private _pongTimer; private _contextSendTimer; private _pendingContext; private _lastSentById; private readonly _invalidatedSessionIds; private readonly _onTranscription; readonly onTranscription: Event; private readonly _onAudioResponse; readonly onAudioResponse: Event; private readonly _onBargeIn; readonly onBargeIn: Event; private readonly _onNarrationAck; readonly onNarrationAck: Event; private readonly _onNarrationUnblocked; readonly onNarrationUnblocked: Event; private readonly _onNarrationInterrupted; readonly onNarrationInterrupted: Event; private readonly _onToolCall; readonly onToolCall: Event; private readonly _onSpeechStarted; readonly onSpeechStarted: Event; private readonly _onSessionInit; readonly onSessionInit: Event; private readonly _onError; readonly onError: Event; private readonly _onDidChangeConnectionState; readonly onDidChangeConnectionState: Event; private readonly _onDidChangeRemoteAudioState; readonly onDidChangeRemoteAudioState: Event; private readonly _onFatalDisconnect; readonly onFatalDisconnect: Event; private readonly _onConnectionIssue; readonly onConnectionIssue: Event; private readonly _onTurnAutoEnded; readonly onTurnAutoEnded: Event; get isConnected(): boolean; get isResuming(): boolean; get isSessionAwarenessEnabled(): boolean; get willReconnect(): boolean; get currentSessionId(): string | undefined; private _authToken; constructor(_configurationService: IConfigurationService, _logService: ILogService, _productService: IProductService, _micCaptureService: IMicCaptureService, _speechService: ISpeechService, _ttsPlaybackService: ITtsPlaybackService); private _updateGptLiveAudioMuted; private _getVoice; private _sendSetVoice; private _getLanguage; private _sendSetLanguage; /** * Whether a configuration setting has an explicit user/workspace/application * value, as opposed to falling back to its registered default. */ private _isExplicitlyConfigured; /** * Assemble the ``turn_config`` wire object from the ``agents.voice.turn.*`` * settings, normalizing each into the shape the backend expects. The * ``auto_end_mode`` is derived from the other two settings: trailing-silence * ending is enabled unless ``silenceMs`` is ``-1`` (or otherwise non-positive), * and stop-phrase ending is enabled when at least one phrase is configured. * * When hands-free mode (``agents.voice.handsFree``) is disabled, the turn is * not sent automatically by default: trailing-silence and stop-phrase ending * are each suppressed unless the corresponding setting has been explicitly * configured, so a user who opts out of the hands-free loop keeps manual * control over when a turn is sent. */ private _getTurnConfig; private _sendSetTurnConfig; private _getWsUrl; connect(window: Window & typeof globalThis, authToken?: string): Promise; hasGptLiveByok(): Promise; private _isActiveConnectionAttempt; private _connectGptLive; private _handleGptLiveStartupFailure; protected _executeGptLiveSessionCommand(sdp?: string, token?: CancellationToken): Promise; protected _createPeerConnection(window: Window & typeof globalThis): IGptLivePeerConnection; protected _createGptLiveAudioElement(): HTMLAudioElement; private _playGptLiveAudio; protected _createGptLiveRemoteStream(window: Window & typeof globalThis, track: MediaStreamTrack): MediaStream; private _waitForIceGathering; private _handleGptLiveEvent; private _canRetainGptLiveVoiceContext; private _captureGptLiveVoiceContext; private _finalizeGptLiveInput; private _startGptLivePassiveSpeech; private _endGptLivePassiveTurn; private _finalizeGptLiveOutput; private _handleGptLiveDisconnect; private _connectWebSocket; disconnect(): void; private _cleanup; private _resetReconnectBudget; private _startPing; private _stopPing; private _clearPongTimeout; private _setConnected; sendPttStart(turnId: string, options: IVoicePttStartOptions): void; sendPttAudioChunk(audio: string): void; sendPttEnd(): void; private _setGptLiveInputEnabled; sendPttDiagnostic(turnId: string, metrics: Record): void; sendSessionContext(context: IVoiceSessionContext): void; flushSessionContext(): void; invalidateSessionCache(sessionId: string): void; private _sendDelta; private _seedTracking; sendToolResult(callId: string, result: string | IVoiceDispatchResult, toolName?: string, toolArgs?: Readonly>): void; sendNarrationPlaybackComplete(codingSessionId: string, narrationId: string, playbackId: string): void; requestNarration(codingSessionId: string, kind: VoiceNarrationKind, text: string, narrationId?: string, checkpoint?: IVoiceCheckpointNarrationMetadata, confirmationType?: VoiceConfirmationType, pending?: { pendingId: string; }): string | undefined; sendSessionStateChange(sessionId: string, newState: string, _label: string, detail?: string, lastResponseSummary?: string): void; stopSpeaking(): void; prepareForInputTargetChange(): void; private _isGptLiveInputTargetCurrent; private _sendGptLiveAppend; private _sendGptLiveEvent; /** * Send the start_session message with the given context. * Called by the consumer after connect() resolves and AudioContext is ready. * * ``priorTimeline`` carries an ordered slice of cross-session entries * (voice turns, voice tool calls, coding-session events, and a synthesized * coding-agent-reply summary per active session) from the previous voice * session. The BE consumes it once on the first command turn so the model * can answer recall questions across reconnects without backend * persistence. See ``IVoicePriorTimelineEntry``. */ sendStartSession(context: IVoiceSessionContext, machineId: string, priorTimeline?: readonly IVoicePriorTimelineEntry[], turnConfigOverride?: IVoiceTurnConfig, voiceInstructions?: string): void; sendResumeSession(context: IVoiceSessionContext, machineId: string, voiceInstructions?: string): void; submitFeedback(payload: IVoiceFeedbackPayload): Promise<{ ok: boolean; error?: string; }>; dispose(): void; }