import type { ConnectionStatus, TranscriptEntry, StreamCoreAIConfig, StreamCoreAIEvents } from "./types.js"; export declare class StreamCoreAIClient { private config; private events; private pc; private sessionURL; /** * Most recently used JWT (either the static `config.token` or one fetched * from `config.tokenUrl` during `connect`). `disconnect` reuses this so * the WHIP DELETE is properly authenticated; otherwise servers enforcing * Bearer auth on `/whip` reject the teardown and skip server-side * finalization (billing, transcript persistence, etc.). */ private lastToken; /** ETag of the current ICE session, sent as `If-Match` on an ICE restart. */ private etag; /** * Single-use credential that reattaches a redial to this conversation. * Re-issued by the server on every response. */ private resumeToken; /** "new", "resumed", or "expired" — the server's answer on the last POST. */ private resumeStatus; /** Set while a recovery sequence is running, so it is never doubled up. */ private recovering; /** Bumped by connect()/disconnect() so an in-flight recovery abandons itself. */ private generation; private stream; private meterStream; private _remoteStream; private remoteAudio; private audioCtx; private analyser; private animFrame; private statsInterval; private assistantBuf; private _status; private _transcript; private _audioLevel; private _isMuted; constructor(config?: StreamCoreAIConfig, events?: StreamCoreAIEvents); get status(): ConnectionStatus; get transcript(): TranscriptEntry[]; get audioLevel(): number; get isMuted(): boolean; get localStream(): MediaStream | null; get remoteStream(): MediaStream | null; connect(): Promise; /** * Builds a peer connection and completes WHIP signaling. * * With a resume token the server reattaches this new transport to the * conversation the previous one was having, so the history, the rolling * summary and the agent's memory of the call all survive. Without one it is * an ordinary first connect. * * The microphone stream is deliberately reused across calls: re-running * getUserMedia on a reconnect costs a second of device setup and, on some * browsers, risks a fresh permission prompt mid-call. */ private establish; disconnect(): void; toggleMute(): void; on(event: K, handler: StreamCoreAIEvents[K]): void; private setStatus; /** * Recovers a dropped connection, in two phases. * * **ICE restart** first, while the peer connection is merely `disconnected`. * It keeps the transport itself alive — same `PeerConnection`, same DTLS, * same tracks — so nothing above it notices. * * **Resume redial** when that is no longer possible: once the connection has * `failed` the server has closed its peer and there is nothing left to * restart. A fresh peer connection then POSTs with the session's resume * token, and the server reattaches it to the same conversation. The * transport is new; the history, the rolling summary and the agent's memory * of the call are not. * * The phases are one sequence rather than two independent ones because they * share a deadline: the server holds an abandoned conversation for * `session_grace_ms` (30s by default), and time spent on restarts is time * not available for redials. */ private recover; /** * Phase one: keep the transport alive with an ICE restart. * * Each attempt re-gathers candidates, PATCHes the resulting fragment to the * session URL, and folds the server's reply back into the remote * description. Between attempts it re-checks the connection state, because * plain ICE frequently repairs the drop unaided and a restart would then be * wasted work. * * Returns true when the drop is dealt with — recovered, or abandoned because * the client itself went away. False means phase two should take over. */ private recoverByIceRestart; /** * Phase two: rebuild the transport and reattach it to the conversation. * * This is the only recovery available once the connection has failed, and * the only one at all for a client that was suspended or offline for longer * than ICE tolerates — a backgrounded phone, a closed laptop lid. */ private recoverByResume; /** Closes the current peer connection without touching session state. */ private closePeerConnection; /** One ICE restart round-trip against the existing peer connection. */ private restartIce; /** * Resolves when ICE gathering finishes or the timeout elapses. * * `allowComplete` must be false for a restart: gathering is already * "complete" from the previous generation at the moment the restart offer is * applied, so trusting that flag would send the server the old candidates. * The end-of-candidates signal is per-generation and is the reliable one. */ private waitForIceGathering; private handleDataChannelMessage; private startAudioLevelMonitoring; private isSafari; private startStatsBasedAudioLevel; private cleanupAudioLevel; } //# sourceMappingURL=client.d.ts.map