import { DisposableStore } from "../../../../../base/common/lifecycle.js"; import { IReader } from "../../../../../base/common/observable.js"; import { VoiceCloseKind } from "./voiceCloseCodes.js"; import { IChatToolInvocation, type ChatVoiceProgressStage } from "../chatService/chatService.js"; import { IChatModel } from "../model/chatModel.js"; export declare function normalizeAgentsVoiceId(value: unknown): string; /** * One selectable option on a pending question, positioned in *displayed* order. * * Position is what the user hears and says back ("the second one"), so the list * is in `getOptionsWithDefaultsFirst` order and both sides number it by index. * `value` is the opaque id the chat model wants back and is never spoken. */ export interface IVoicePendingOption { label: string; value: string; } /** One question of a pending question form. */ export interface IVoicePendingQuestion { id: string; type: "text" | "singleSelect" | "multiSelect"; title: string; allow_freeform: boolean; options: IVoicePendingOption[]; } /** * What a coding session is currently waiting on, structurally. * * `agent_state_detail` describes the same thing as prose, which is enough to * *say* but not to *act on*: a spoken answer to a question form has nowhere to * land without the ids and options below. `pending_id` + `request_id` route a * response back to the exact part that raised it, with no "currently focused * session" guesswork. * * Field names are snake_case because this crosses the voice websocket verbatim. */ export interface IVoiceSessionPending { type: "questions" | "approval"; pending_id: string; request_id: string; allow_skip?: boolean; message?: string; questions?: IVoicePendingQuestion[]; } /** The command currently presented for a tool approval, if it has one. */ export declare function getVoiceToolApprovalCommand(invocation: IChatToolInvocation, includeParameters?: boolean): string | undefined; /** * Derive the id that routes a voice response back to this exact pending part. * * Call this only when publishing a part as the session's pending request; it * mints a token on first sight. Use `peekPendingId` for an id that came back * from the backend, so a part never offered cannot be matched by a stale id. */ export declare function derivePendingId(requestId: string, part: object, store?: DisposableStore): string; /** * Retire a published tool approval after the user acts on it. * * Tool providers are allowed to leave the invocation in a pending state while * they send the response to another process. Explicit retirement closes that * gap and prevents another live copy from submitting the same approval again. */ export declare function markPendingIdResolved(pendingId: string): boolean; /** Whether a published tool approval has already been acted on. */ export declare function isPendingIdResolved(pendingId: string, reader?: IReader): boolean; /** Restore the retired id for a late rehydrated copy of an already-handled tool approval. */ export declare function restoreResolvedPendingId(requestId: string, part: object, store?: DisposableStore): string | undefined; /** * Resolve the id of an already-published pending part, or `undefined`. * * Does not mint: a part the client never published as pending has no id, so an * echoed id can only match the part it was issued for. */ export declare function peekPendingId(requestId: string, part: object): string | undefined; /** * Session context sent to the voice server for grounding. */ export interface IVoiceSessionContext { sessions: { id: string; /** Human-readable name, so the backend can tell two sessions apart. */ label?: string; /** Which frontend session surface owns this conversation. */ session_type?: "agent" | "chat"; is_active: boolean; agent_state: string; agent_state_detail?: string; confirmation_type?: VoiceConfirmationType; /** The model currently selected for this session's next request. */ selected_model?: IVoiceModelReference; /** Names only: file contents remain in the frontend until a request is sent. */ attachment_names?: string[]; attachment_count?: number; last_response_summary?: string; pending?: IVoiceSessionPending; /** Bounded recent conversation, supplied only for GPT Live session awareness. */ recent_turns?: { user: string; assistant: string; }[]; }[]; display_locale: string; } export declare function getVoiceRecentTurns(model: IChatModel, lastN: number, completedResponsesOnly?: boolean): { user: string; assistant: string; }[]; export interface IVoiceModelReference { readonly identifier: string; readonly name: string; readonly vendor: string; } export type VoiceConfirmationType = "questionnaire" | "elicitation" | "plan" | "tool" | "generic"; export type VoiceCheckpointId = ChatVoiceProgressStage; export declare function isVoiceCheckpointId(value: unknown): value is VoiceCheckpointId; export interface IVoiceCheckpointNarrationMetadata { readonly requestId: string; readonly checkpointId: VoiceCheckpointId; readonly sequence: number; } /** * What a client-requested narration is speaking. Mirrors `NarrationKind` in the * voice backend. * * `'question'` is spoken verbatim by the backend rather than being paraphrased * by the narration model: the numbered options are the ordinals the user says * back, so a summary that drops them breaks answering. */ export type VoiceNarrationKind = "response" | "confirmation" | "question" | "checkpoint"; /** * Structured outcome of a dispatched voice tool call. The backend speaks an * acknowledgement only after seeing one, so a dishonest `ok` becomes the * assistant claiming something that never happened. */ export interface IVoiceDispatchResult { readonly ok: boolean; readonly reason?: "stale_pending" | "invalid_answer" | "no_session" | "unsupported"; } /** * Inbound message types emitted by the voice client service. */ export interface IVoiceTranscription { readonly text: string; readonly status?: "partial" | "final"; readonly committed?: string; /** Client capture turn identifier translated from the wire's `turn_id`. */ readonly turnId?: string; /** Monotonically increasing backend revision within a scoped turn. */ readonly revision?: number; } export interface IVoiceAudioResponse { readonly audio: string; readonly isFirstChunk: boolean; readonly isFinal: boolean; readonly codingSessionId?: string; readonly transcript?: string; /** Backend turn identifier from the wire's `turn_id`. */ readonly turnId?: string; /** * Stable id correlating all chunks of ONE narration/response stream, echoed * by the backend from the `narration_id` the client sent on * `request_narration` (or the backend's own `turn_id`). Lets playback routing * decide a response's fate once and keep every chunk on that decision, even * when responses for different sessions interleave. Absent for untagged * direct replies and for backends that don't yet echo it (legacy fallback). */ readonly responseId?: string; readonly requestId?: string; readonly checkpointId?: VoiceCheckpointId; readonly sequence?: number; readonly narrationKind?: VoiceNarrationKind; readonly playbackId?: string; } export interface IVoiceBargeIn { readonly turnId: string; readonly interruptedTurnId: string; } /** Disposition of a client `request_narration`, reported by `narration_ack`. */ export type IVoiceNarrationDisposition = "accepted" | "busy" | "invalid" | "suppressed"; /** The backend's acknowledgement of a `request_narration`. */ export interface IVoiceNarrationAck { readonly narrationId: string; readonly codingSessionId: string; readonly disposition: IVoiceNarrationDisposition; /** Present on `busy`/`invalid`: why the narration could not play. */ readonly reason?: string; } /** * A correlation-only server signal about a previously requested narration: * `narration_unblocked` (the guard cleared, you may retry) or * `narration_interrupted` (an accepted narration was cancelled by barge-in). * Carries no text — the client revalidates against current session state. */ export interface IVoiceNarrationSignal { readonly narrationId: string; readonly codingSessionId: string; readonly retryable?: boolean; readonly reason?: string; } export interface IVoiceToolCall { readonly callId: string; readonly name: string; readonly args: Record; /** Capture turn owning this call, when the transport can identify it. */ readonly turnId?: string; } export interface IVoiceSpeechStarted { readonly turnId?: string; } export interface IVoiceSessionInit { readonly sessionId: string; } /** * Client turn-endpointing configuration sent to the backend. Serialized * verbatim into the ``turn_config`` object on ``start_session`` / * ``resume_session`` and the ``set_turn_config`` live-update event, so the * field names are snake_case to match the wire contract (same convention as * ``IVoiceSessionContext``). */ export interface IVoiceTurnConfig { /** How (if at all) the backend ends a held turn on its own. */ readonly auto_end_mode: "off" | "vad" | "phrase" | "both"; /** Trailing silence (ms) before VAD ends the turn; used when mode is ``vad``/``both``. The server clamps. */ readonly silence_ms: number; /** Phrases matched at the end of the transcript; the server normalizes and strips them. */ readonly stop_phrases: readonly string[]; /** Whether the backend gates ASR on its voice-activity detector. Always ``true``: only forward audio to speech recognition when the VAD hears speech. */ readonly vad_gate_asr: boolean; } /** Why the backend ended the turn on its own. */ export type IVoiceTurnAutoEndReason = "vad_silence" | "stop_phrase"; /** * Emitted when the backend ends a held turn itself (server VAD silence or a * matched stop phrase) while the user is still "holding" push-to-talk. The * consumer must treat this like a local ``ptt_end`` — stop capturing/streaming * and clear the recording UI — but MUST NOT send its own ``ptt_end`` for the * turn. ``turnId`` guards against double-ending. */ export interface IVoiceTurnAutoEnded { readonly reason: IVoiceTurnAutoEndReason; readonly turnId: string; } /** * Payload for a terminal websocket close. Despite the name this covers every * close that will not reconnect, including an expected end of session: `kind` * distinguishes them, and an `expected` close must not paint the UI red or * raise a toast. `clientSide` marks an unconfigured backend URL, not a BYOK * session creation or connection failure. */ export interface IVoiceFatalDisconnect { readonly code: number; readonly reason: string; readonly kind?: VoiceCloseKind; readonly clientSide?: boolean; } /** A recoverable connection problem; the client keeps retrying. */ export interface IVoiceConnectionIssue { readonly code: number; readonly reason: string; } /** * One entry in the cross-session timeline the FE replays to the BE on * ``start_session``. The BE's coding_agent renders these into a * ``[PRIOR_CONTEXT]`` block on the *first* command after reconnect so the * model can answer "what were we doing?" / "remember xyz?" without any * server-side persistence. * * Kinds: * user_voice — what the user said * agent_voice — what the voice agent spoke back * agent_tool_call — a tool the voice agent dispatched (send_to_chat, etc.) * coding_event — a coding-session status transition * (e.g. ``thinking → waiting_for_confirmation``) * coding_agent_reply — first ~2 sentences of the latest Copilot Chat * response per active session (synthesized * FE-side at connect time, never persisted to disk) */ export type IVoicePriorTimelineKind = "user_voice" | "agent_voice" | "agent_tool_call" | "coding_event" | "coding_agent_reply"; export interface IVoicePriorTimelineEntry { readonly kind: IVoicePriorTimelineKind; /** ISO 8601 wall-clock time of the entry. Used for chronological ordering. */ readonly timestamp: string; /** * Human/LLM-readable one-line summary. The BE renders this directly * into the prompt without further parsing. */ readonly text: string; /** Tool name for ``agent_tool_call`` entries (also encoded inside ``text``). */ readonly toolName?: string; /** Originating coding-session id for ``coding_event`` / ``coding_agent_reply``. */ readonly codingSessionId?: string; /** Status string for ``coding_event`` (e.g. ``thinking``, ``idle``). */ readonly codingStatus?: string; } /** * Payload sent to the backend for a user-initiated feedback submission. */ export interface IVoiceFeedbackPayload { readonly feedbackText: string; readonly machineId: string; readonly userId: string; readonly sessionId: string; readonly submissionId: string; readonly transcriptHistory: readonly IVoiceFeedbackTranscriptTurn[]; readonly clientSessionState: Record; readonly clientEnvironment: Record; readonly timestamp: string; } export interface IVoiceFeedbackTranscriptTurn { readonly role: "user" | "assistant"; readonly text: string; readonly timestamp: string; } export interface IVoicePttStartOptions { readonly hasActiveSession: boolean; readonly passive?: boolean; } export declare const VOICE_AGENT_PROGRESS_SETTING = "agents.voice.agentProgress";