import type { AssistantMessage } from "@oh-my-pi/pi-ai"; import type { AgentSession } from "../session/agent-session.js"; import type { LivePhase } from "@oh-my-pi/pi-tui/apps/live-visualizer"; /** Incremental or final transcript for one realtime conversational turn. */ export interface LiveTranscript { role: "user" | "assistant"; text: string; /** Monotonic role-local turn number used to coalesce streaming updates. */ turn: number; final: boolean; } /** UI notifications emitted during a live session. */ export interface LiveSessionCallbacks { /** Reports connection and activity phase changes. */ onPhase(phase: LivePhase): void; /** Reports clamped microphone and speaker RMS levels. */ onLevels(input: number, output: number): void; /** Reports the latest available conversational transcript. */ onTranscript(transcript: LiveTranscript | undefined): void; /** Reports one terminal stop, optionally carrying its cause. */ onTerminal(error?: Error): void; } /** Dependencies and presentation callbacks for a live session. */ export interface LiveSessionControllerOptions { /** Agent session that performs all delegated coding work. */ session: AgentSession; /** UI callbacks for live session state. */ callbacks: LiveSessionCallbacks; /** Extracts visible assistant text using the caller's normal UI rules. */ extractAssistantText(message: AssistantMessage): string; /** Realtime output voice, defaulting to sol. */ voice?: string; /** * Handlebars template replacing the bundled live instructions; rendered with * `{ username, firstName }` like the bundled prompt. */ instructions?: string; /** * SDP offer from a caller-owned WebRTC peer that carries the microphone and speaker audio * (see `LiveTransportOptions.sdpOffer`). When set, no host microphone or speaker is opened; * the caller applies {@link LiveSessionController.sdpAnswer} to its peer after `start()` * and handles echo cancellation itself. There is no host track to mute: `toggleMute` only * moves the phase to `muted`, and the caller must silence its own microphone track while the * phase is `muted`. Levels are not reported in this mode. */ sdpOffer?: string; } /** Coordinates the realtime conversational surface with normal AgentSession turns. */ export declare class LiveSessionController { #private; constructor(options: LiveSessionControllerOptions); /** Current realtime call phase. */ get phase(): LivePhase; /** Whether microphone input is currently muted. */ get muted(): boolean; /** * SDP answer for the caller's peer in an `sdpOffer` session. It exists as soon as the offer is * signaled, before the control socket connects, so apply it only after `start()` resolves. */ get sdpAnswer(): string | undefined; /** Connects the realtime surface and starts microphone streaming (or, with `sdpOffer`, only signaling). */ start(): Promise; /** Toggles microphone capture while leaving output and the session connected. */ toggleMute(): void; /** Stops recording, closes the live session, and emits one terminal callback. */ stop(): Promise; }