AAI SDK
    Preparing search index...

    Interface ClientSink

    Typed interface for pushing session events to a connected client.

    Events (event, playAudioDone) send JSON text frames. Audio chunks (playAudioChunk) send raw PCM16 binary frames.

    interface ClientSink {
        open: boolean;
        close?(reason?: string): void;
        event(
            e:
                | { type: "speech_started" }
                | { type: "speech_stopped" }
                | { text: string; type: "user_transcript" }
                | { text: string; type: "user_transcript_partial" }
                | { text: string; type: "agent_transcript" }
                | {
                    args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
                    toolCallId: string;
                    toolName: string;
                    type: "tool_call";
                }
                | { result: string; toolCallId: string; type: "tool_call_done" }
                | { type: "reply_done" }
                | { type: "cancelled" }
                | { type: "reset" }
                | { type: "idle_timeout" }
                | {
                    code:
                        | "audio"
                        | "connection"
                        | "internal"
                        | "llm"
                        | "protocol"
                        | "stt"
                        | "tool"
                        | "tts";
                    fatal?: boolean;
                    message: string;
                    type: "error";
                }
                | { data: unknown; event: string; type: "custom_event" }
                | { state: unknown; type: "agent_state" },
        ): void;
        playAudioChunk(chunk: Uint8Array): void;
        playAudioDone(): void;
    }
    Index
    open: boolean

    True when the underlying connection is open and will accept calls.

    • Close the underlying connection (best-effort, idempotent). Used when the server retires a session out from under a connected client — a resume takeover, or a sandbox teardown — so the client gets a real close to react to instead of a socket that silently stops answering.

      Parameters

      • Optionalreason: string

      Returns void

    • Push a session event (JSON text frame) to the client.

      Parameters

      • e:
            | { type: "speech_started" }
            | { type: "speech_stopped" }
            | { text: string; type: "user_transcript" }
            | { text: string; type: "user_transcript_partial" }
            | { text: string; type: "agent_transcript" }
            | {
                args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
                toolCallId: string;
                toolName: string;
                type: "tool_call";
            }
            | { result: string; toolCallId: string; type: "tool_call_done" }
            | { type: "reply_done" }
            | { type: "cancelled" }
            | { type: "reset" }
            | { type: "idle_timeout" }
            | {
                code:
                    | "audio"
                    | "connection"
                    | "internal"
                    | "llm"
                    | "protocol"
                    | "stt"
                    | "tool"
                    | "tts";
                fatal?: boolean;
                message: string;
                type: "error";
            }
            | { data: unknown; event: string; type: "custom_event" }
            | { state: unknown; type: "agent_state" }

      Returns void

    • Send a single PCM16 audio chunk (raw binary frame) to the client.

      Parameters

      • chunk: Uint8Array

      Returns void

    • Signal that TTS audio is complete (JSON text frame).

      Returns void