import { Request, Response } from "express"; import WebSocket from "ws"; import z from "zod"; //#region ../shared/dist/index.d.mts //#region src/model/elevenlabs.voices.model.d.ts type ElevenLabsVoiceId = "dSu12TX3MEDQXAarG4s6" | "pJsNpJRIjvv0gEQf9pTf" | "21m00Tcm4TlvDq8ikWAM" | "29vD33N1CtxCmqQRPOHJ" | "2EiwWnXFnvU5JabPnv8n" | "5Q0t7uMcjvnagumLfvZi" | "9BWtsMINqrJLrRacOk9x" | "AZnzlk1XvdvUeBnXmlld" | "CYw3kZ02Hs0563khs1Fj" | "CwhRBWXzGAHq8TQ4Fs17" | "D38z5RcWu1voky8WS1ja" | "EXAVITQu4vr4xnSDxMaL" | "ErXwobaYiN019PkySvjV" | "FGY2WhTYpPnrIDTdsKH5" | "GBv7mTt0atIp3Br8iCZE" | "IKne3meq5aSn9XLyUdCD" | "JBFqnCBsd6RMkjVDRZzb" | "LcfcDJNUP1GQjkzn1xUU" | "MF3mGyEYCl7XYWbV9V6O" | "N2lVS1w4EtoT3dr4eOWO" | "ODq5zmih8GrVes37Dizd" | "SAz9YHcvj6GT2YYXdXww" | "SOYHLrjzK2X1ezoPC6cr" | "TX3LPaxmHKxFdv7VOQHJ" | "ThT5KcBeYPX3keUQqHPh" | "TxGEqnHWrfWFTfGW9XjX" | "VR6AewLTigWG4xSOukaG" | "XB0fDUnXU5powFXDhCwa" | "Xb7hH8MSUJpSbSDYk0k2" | "XrExE9yKIg1WjnnlVkGX" | "ZQe5CZNOzWyzPSCn5a3c" | "Zlb1dXrM653N07WRdFW3" | "bIHbv24MWmeRgasZH58o" | "bVMeCyTHy58xNoL34h3p" | "cgSgspJ2msm6clMCkdW9" | "cjVigY5qzO86Huf0OWal" | "flq6f7yk4E4fJM5XTYuZ" | "g5CIjZEefAph4nQFvHAz" | "iP95p4xoKVk53GoZ742B" | "jBpfuIE2acCO8z3wKNLl" | "jsCqWAovK2LkecY7zXl4" | "nPczCjzI2devNBz1zQrb" | "oWAxZDx7w5VEj9dCyTzz" | "onwK4e9ZLuTAKqWW03F9" | "pFZP5JQG7iQjIQuC4Bku" | "pMsXgVXv3BLzUgSXRplE" | "pNInz6obpgDQGcFmaJgB" | "piTKgcLEGmPE4e6mEKli" | "pqHfZKP75CvOlQylNhV4" | "t0jbNlBVZ17f02VDIeMI" | "yoZ06aMxZJJ28mfd3POQ" | "z9fAnlkpzviPz146aGWa" | "zcAOhNBS3c14rBihAFp1" | "zrHiDhphv9ZnVXBqCLjz"; /** * Legacy voice IDs that are still accepted and remapped to their current equivalents. * Applied server-side before any ElevenLabs API call. */ declare const ELEVENLABS_VOICE_ID_ALIASES: Partial>; declare const ELEVENLABS_VOICES: ({ id: string; name: string; description: string; verifiedLocales: string[]; } | { id: string; name: string; description: null; verifiedLocales: never[]; })[]; //#endregion //#region src/model/tts.model.d.ts declare enum TtsProvider { AZURE = "azure", ELEVEN_LABS = "eleven_labs", OPENAI = "openai", KUGELAUDIO = "kugelaudio", } declare const TtsConfigAzureSchema: z.ZodObject<{ provider: z.ZodLiteral; language: z.ZodOptional; voice: z.ZodOptional; }, z.core.$strict>; declare const TtsConfigElevenLabsSchema: z.ZodObject<{ provider: z.ZodLiteral; voice: z.ZodOptional>; }, z.core.$strict>; declare const TtsConfigOpenAiSchema: z.ZodObject<{ provider: z.ZodLiteral; voice: z.ZodOptional>; }, z.core.$strict>; declare const TtsConfigKugelaudioSchema: z.ZodObject<{ provider: z.ZodLiteral; voice: z.ZodOptional; language: z.ZodOptional; speed: z.ZodOptional; }, z.core.$strict>; declare const TtsConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{ provider: z.ZodLiteral; language: z.ZodOptional; voice: z.ZodOptional; }, z.core.$strict>, z.ZodObject<{ provider: z.ZodLiteral; voice: z.ZodOptional>; }, z.core.$strict>, z.ZodObject<{ provider: z.ZodLiteral; voice: z.ZodOptional>; }, z.core.$strict>, z.ZodObject<{ provider: z.ZodLiteral; voice: z.ZodOptional; language: z.ZodOptional; speed: z.ZodOptional; }, z.core.$strict>], "provider">; type TtsConfigAzure = z.infer; type TtsConfigElevenLabs = z.infer; type TtsConfigOpenAi = z.infer; type TtsConfigKugelaudio = z.infer; type TtsConfig = TtsConfigAzure | TtsConfigElevenLabs | TtsConfigOpenAi | TtsConfigKugelaudio; //#endregion //#region src/model/barge-in.model.d.ts declare enum BargeInStrategy { /** * No barge-in, play the audio fully and directly */ NONE = "none", /** * No auto barge-in, only manual barge-in via API */ MANUAL = "manual", /** * Barge in if user words exceed 3 characters or the configured minimum_characters */ MINIMUM_CHARACTERS = "minimum_characters", /** * Barge in immediately when first word is detected (uses partial/recognizing transcripts) * Stops assistant speech as soon as any speech is detected, before full sentence recognition */ IMMEDIATE = "immediate", } declare const BargeInConfigSchema: z.ZodObject<{ strategy: z.ZodEnum; minimum_characters: z.ZodOptional; allow_after_ms: z.ZodOptional; }, z.core.$strip>; type BargeInConfig = z.infer; //#endregion //#region src/model/types.d.ts declare enum TranscriptionProvider { AZURE = "AZURE", AZURE_VOICE_LIVE = "AZURE_VOICE_LIVE", ELEVEN_LABS = "ELEVEN_LABS", DEEPGRAM = "DEEPGRAM", OPENAI = "OPENAI", SIPGATE_QWEN = "SIPGATE_QWEN", SIPGATE_PARAKEET = "SIPGATE_PARAKEET", UNKNOWN = "UNKNOWN", } //#endregion //#region src/model/actions.model.d.ts declare enum AiFlowActionType { SPEAK = "speak", AUDIO = "audio", HANGUP = "hangup", BARGE_IN = "barge_in", TRANSFER = "transfer", CONFIGURE_TRANSCRIPTION = "configure_transcription", SEND_SMS = "send_sms", MIX_AUDIO = "mix_audio", } declare const AiFlowBaseActionSchema: z.ZodObject<{ session_id: z.ZodUUID; }, z.core.$strip>; declare const AiFlowActionSpeakSchema: z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; text: z.ZodOptional; ssml: z.ZodOptional; tts: z.ZodOptional; language: z.ZodOptional; voice: z.ZodOptional; }, z.core.$strict>, z.ZodObject<{ provider: z.ZodLiteral; voice: z.ZodOptional>; }, z.core.$strict>, z.ZodObject<{ provider: z.ZodLiteral; voice: z.ZodOptional>; }, z.core.$strict>, z.ZodObject<{ provider: z.ZodLiteral; voice: z.ZodOptional; language: z.ZodOptional; speed: z.ZodOptional; }, z.core.$strict>], "provider">>; barge_in: z.ZodOptional; minimum_characters: z.ZodOptional; allow_after_ms: z.ZodOptional; }, z.core.$strip>>; user_input_timeout_seconds: z.ZodOptional; vad: z.ZodOptional>; }, z.core.$strip>>; }, z.core.$strip>; declare const AiFlowActionAudioSchema: z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; audio: z.ZodString; barge_in: z.ZodOptional; minimum_characters: z.ZodOptional; allow_after_ms: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>; declare const AiFlowActionHangupSchema: z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; }, z.core.$strip>; declare const AiFlowActionBargeInSchema: z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; }, z.core.$strip>; declare const AiFlowActionTransferSchema: z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; target_phone_number: z.ZodString; caller_id_name: z.ZodString; caller_id_number: z.ZodString; timeout: z.ZodOptional; }, z.core.$strip>; declare const AiFlowActionConfigureTranscriptionSchema: z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; provider: z.ZodOptional & z.ZodType>>; languages: z.ZodDefault>>, z.ZodTransform>, z.ZodPipe, z.ZodTransform>>>; custom_vocabulary: z.ZodOptional>; vad: z.ZodOptional>; }, z.core.$strip>>; }, z.core.$strip>; declare const AiFlowActionSendSmsSchema: z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; phone_number: z.ZodString; message: z.ZodString; }, z.core.$strip>; declare const AiFlowActionMixAudioSchema: z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; audio: z.ZodOptional; volume: z.ZodOptional; stop: z.ZodOptional; }, z.core.$strip>; declare const AiFlowActionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; text: z.ZodOptional; ssml: z.ZodOptional; tts: z.ZodOptional; language: z.ZodOptional; voice: z.ZodOptional; }, z.core.$strict>, z.ZodObject<{ provider: z.ZodLiteral; voice: z.ZodOptional>; }, z.core.$strict>, z.ZodObject<{ provider: z.ZodLiteral; voice: z.ZodOptional>; }, z.core.$strict>, z.ZodObject<{ provider: z.ZodLiteral; voice: z.ZodOptional; language: z.ZodOptional; speed: z.ZodOptional; }, z.core.$strict>], "provider">>; barge_in: z.ZodOptional; minimum_characters: z.ZodOptional; allow_after_ms: z.ZodOptional; }, z.core.$strip>>; user_input_timeout_seconds: z.ZodOptional; vad: z.ZodOptional>; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; audio: z.ZodString; barge_in: z.ZodOptional; minimum_characters: z.ZodOptional; allow_after_ms: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; }, z.core.$strip>, z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; }, z.core.$strip>, z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; target_phone_number: z.ZodString; caller_id_name: z.ZodString; caller_id_number: z.ZodString; timeout: z.ZodOptional; }, z.core.$strip>, z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; provider: z.ZodOptional & z.ZodType>>; languages: z.ZodDefault>>, z.ZodTransform>, z.ZodPipe, z.ZodTransform>>>; custom_vocabulary: z.ZodOptional>; vad: z.ZodOptional>; }, z.core.$strip>>; }, z.core.$strip>, z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; phone_number: z.ZodString; message: z.ZodString; }, z.core.$strip>, z.ZodObject<{ session_id: z.ZodUUID; type: z.ZodLiteral; audio: z.ZodOptional; volume: z.ZodOptional; stop: z.ZodOptional; }, z.core.$strip>], "type">; type AiFlowBaseAction = z.infer; type AiFlowActionSpeak = z.infer; type AiFlowActionAudio = z.infer; type AiFlowActionHangup = z.infer; type AiFlowActionBargeIn = z.infer; type AiFlowActionTransfer = z.infer; type AiFlowActionConfigureTranscription = z.infer; type AiFlowActionSendSms = z.infer; type AiFlowActionMixAudio = z.infer; type AiFlowAction = z.infer; //#endregion //#region src/model/sessions.model.d.ts declare enum SessionDirection { INBOUND = "inbound", OUTBOUND = "outbound", } type SessionsRow = { id: string; client_id: string; call_sid: string; tracing_id: string; account_id?: string | null; phone_number?: string | null; direction?: SessionDirection | null; transcription_provider?: TranscriptionProvider | null; stt_custom_vocabulary?: string[] | null; provider_base_url?: string | null; to_account_id?: string | null; to_phone_number?: string | null; from_phone_number?: string | null; from_account_id?: string | null; stream_started_at?: Date | null; ended_at?: Date | null; websocket_connected_at?: Date | null; last_activity_at?: Date | null; /** * Set while a transfer with timeout is in flight. closeSession() defers * cleanup as long as this is non-null and in the future, so the row * survives until PBXCore's transfer-result Redirect lands. */ transfer_pending_until?: Date | null; created_at: Date; updated_at: Date; }; //#endregion //#region src/model/aiflow-events.model.d.ts declare enum AiFlowEventType { ASSISTANT_SPEAK = "assistant_speak", ASSISTANT_SPEECH_ENDED = "assistant_speech_ended", USER_SPEAK = "user_speak", USER_SPEECH_STARTED = "user_speech_started", USER_BARGE_IN = "user_barge_in", USER_INPUT_TIMEOUT = "user_input_timeout", DTMF_RECEIVED = "dtmf_received", SESSION_START = "session_start", SESSION_END = "session_end", SMS_FAILED = "sms_failed", ERROR = "error", } /** * Stable, low-cardinality error codes reported on the `error` event. This is * the field your application branches on — the `message` is for humans, not * for control flow. New codes are added over time; treat an unknown code the * way you would treat `internal_error`. */ declare enum AiFlowErrorCode { /** A sent action could not be parsed or failed schema validation. */ ACTION_INVALID = "action_invalid", /** An action referenced a `session_id` that matches no running session. */ ACTION_UNKNOWN_SESSION = "action_unknown_session", /** The speech-recognition provider could not be reached; the call continues degraded. */ TRANSCRIPTION_UNAVAILABLE = "transcription_unavailable", /** A requested transcription switch (`configure_transcription`) could not be applied. */ TRANSCRIPTION_SWITCH_FAILED = "transcription_switch_failed", /** Speech synthesis failed and the spoken output was dropped. */ SYNTHESIS_UNAVAILABLE = "synthesis_unavailable", /** A transfer target was rejected or could not be resolved. */ TRANSFER_TARGET_INVALID = "transfer_target_invalid", /** Catch-all for an unexpected internal failure while handling the call. */ INTERNAL_ERROR = "internal_error", } /** * How much the reported error affects the call. * * `warning` — the call continues, possibly degraded (e.g. on the previous * transcription provider). You may ignore it or react. * * `error` — something the customer likely needs to act on; the intended * effect did not happen. Lets you filter noise without knowing every code. */ declare enum AiFlowErrorSeverity { WARNING = "warning", ERROR = "error", } declare enum SmsFailedReason { SENDER_NOT_ALLOWED = "sender_not_allowed", INSUFFICIENT_BALANCE = "insufficient_balance", SMSC_UNAVAILABLE = "smsc_unavailable", NO_SMS_EXTENSION = "no_sms_extension", UNKNOWN = "unknown", } /** * Why a `transfer` did not connect. * * Reported on the `session_start` event that returns the caller to the agent, * and therefore only available for transfers that set a `timeout` (transfer * fallback). A transfer that connects never returns the caller, so there is no * success counterpart. * * `busy`, `rejected` and `no_answer` mean the target was reachable but did not * take the call; `number_not_found` and `technical_error` indicate the call * could not be delivered at all. */ declare enum TransferFailedReason { BUSY = "busy", REJECTED = "rejected", NO_ANSWER = "no_answer", NUMBER_NOT_FOUND = "number_not_found", TECHNICAL_ERROR = "technical_error", UNKNOWN = "unknown", } declare const AiFlowEventSessionInfoSchema: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; declare const AiFlowBaseEventSchema: z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; }, z.core.$strip>; declare const AiFlowEventUserSpeakSchema: z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; text: z.ZodString; barged_in: z.ZodOptional; }, z.core.$strip>; declare const AiFlowEventSessionStartSchema: z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; transfer_failed_reason: z.ZodOptional>; }, z.core.$strip>; declare const AiFlowEventUserBargeInSchema: z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; text: z.ZodString; }, z.core.$strip>; declare const AiFlowEventUserSpeechStartedSchema: z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; }, z.core.$strip>; declare const AiFlowEventAssistantSpeakSchema: z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; text: z.ZodOptional; ssml: z.ZodOptional; duration_ms: z.ZodNumber; speech_started_at: z.ZodNumber; }, z.core.$strip>; declare const AiFlowEventAssistantSpeechEndedSchema: z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; }, z.core.$strip>; declare const AiFlowEventUserInputTimeoutSchema: z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; }, z.core.$strip>; declare const AiFlowEventDtmfReceivedSchema: z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; digit: z.ZodString; }, z.core.$strip>; declare const AiFlowEventSessionEndSchema: z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; }, z.core.$strip>; declare const AiFlowEventSmsFailedSchema: z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; recipient: z.ZodString; reason: z.ZodEnum; message: z.ZodOptional; }, z.core.$strip>; /** * Generic error event. Reported additively alongside the call whenever * something the customer should know about goes wrong — an invalid action, an * unreachable speech provider, a failed synthesis. Purely diagnostic in * spirit, but over HTTP transport (where every event is a request) you may * respond with action(s) — e.g. answer `synthesis_unavailable` with a * `transfer`. * * The pre-existing `sms_failed` event and the `transfer_failed_reason` field * on `session_start` remain unchanged; this event does not replace them. */ declare const AiFlowEventErrorSchema: z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; code: z.ZodEnum; severity: z.ZodEnum; message: z.ZodString; action_type: z.ZodOptional>; }, z.core.$strip>; declare const AiFlowEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; text: z.ZodString; barged_in: z.ZodOptional; }, z.core.$strip>, z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; }, z.core.$strip>, z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; transfer_failed_reason: z.ZodOptional>; }, z.core.$strip>, z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; text: z.ZodString; }, z.core.$strip>, z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; text: z.ZodOptional; ssml: z.ZodOptional; duration_ms: z.ZodNumber; speech_started_at: z.ZodNumber; }, z.core.$strip>, z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; }, z.core.$strip>, z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; }, z.core.$strip>, z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; digit: z.ZodString; }, z.core.$strip>, z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; }, z.core.$strip>, z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; recipient: z.ZodString; reason: z.ZodEnum; message: z.ZodOptional; }, z.core.$strip>, z.ZodObject<{ session: z.ZodObject<{ id: z.ZodUUID; account_id: z.ZodString; phone_number: z.ZodString; direction: z.ZodOptional>; from_phone_number: z.ZodString; to_phone_number: z.ZodString; }, z.core.$strip>; type: z.ZodLiteral; code: z.ZodEnum; severity: z.ZodEnum; message: z.ZodString; action_type: z.ZodOptional>; }, z.core.$strip>], "type">; type AiFlowEventSessionInfo = z.infer; type AiFlowEventUserSpeak = z.infer; type AiFlowEventUserSpeechStarted = z.infer; type AiFlowEventUserBargeIn = z.infer; type AiFlowEventAssistantSpeak = z.infer; type AiFlowEventAssistantSpeechEnded = z.infer; type AiFlowEventSessionStart = z.infer; type AiFlowEventUserInputTimeout = z.infer; type AiFlowEventDtmfReceived = z.infer; type AiFlowEventSessionEnd = z.infer; type AiFlowEventSmsFailed = z.infer; type AiFlowEventError = z.infer; type AiFlowEvent = z.infer; //#endregion //#region src/model/clients.model.d.ts type ClientsRow = { id: string; name?: string | null; account_id?: string | null; phone_number?: string | null; webhook_url?: string | null; api_token?: string | null; enable_logging?: boolean; answer_after_seconds?: number; transcription_provider?: TranscriptionProvider | null; stt_languages?: string[] | null; stt_custom_vocabulary?: string[] | null; provider_base_url?: string | null; is_dev_instance?: boolean | null; created_at: Date; updated_at: Date; }; //#endregion //#region src/model/monthly-usage.model.d.ts /** * Database row type for monthly_usage table * * Pre-aggregated call-minute totals per client per calendar month (UTC). * Upserted each time a session closes. */ type MonthlyUsageRow = { /** Client that owns this usage data */ client_id: string; /** Calendar year (UTC), e.g. 2026 */ year: number; /** Calendar month (UTC), 1–12 */ month: number; /** Total number of completed sessions in this month */ total_sessions: number; /** * Total call minutes in this month (ceiling-rounded: 10s = 1 min, 118s = 2 min). * BIGINT in DB — use number in TS. */ total_minutes: number; }; //#endregion //#region src/model/session-background-audio.model.d.ts /** * Database row type for session_background_audio table. * * Holds the looping PCM payload for the mix_audio action so the * AudioMixerService can recover the loop in memory after a service restart. * Stored separately from session_state because PCM payloads can be large * (≥ 100 KB) and we don't want them on the cached hot path. * * Audio format: 16 kHz, 16-bit signed little-endian, mono, raw PCM * (WAV header stripped before storage). */ type SessionBackgroundAudioRow = { /** Session ID (foreign key to sessions.id, ON DELETE CASCADE). */ session_id: string; /** Raw PCM bytes (16 kHz, 16-bit, mono — WAV header stripped). */ audio_pcm: Buffer; /** Mix volume for the background loop, 0.0–1.0. */ volume: number; /** Row creation timestamp. */ created_at: Date; /** Row last update timestamp. */ updated_at: Date; }; //#endregion //#region src/model/session-events.model.d.ts declare enum SessionEventType { HTTP_MESSAGE = "http:message", HTTP_MESSAGE_ERROR = "http:message:error", WEBSOCKET_MESSAGE = "websocket:message", WEBSOCKET_MESSAGE_ERROR = "websocket:message:error", WEBSOCKET_ERROR = "websocket:error", WEBSOCKET_CLOSED = "websocket:closed", TRANSCRIBER_CLOSE = "transcriber:close", TRANSCRIBER_CREATE = "transcriber:create", TRANSCRIBER_STARTED = "transcriber:started", TRANSCRIBER_STOPPED = "transcriber:stopped", TRANSCRIBER_CANCELED = "transcriber:canceled", TRANSCRIBER_SPEECH_START = "transcriber:speech:start", TRANSCRIBER_SPEECH_END = "transcriber:speech:end", TRANSCRIBER_CONTINUOUS_RECOGNITION_STARTED = "transcriber:continuous-recognition:started", TRANSCRIBER_CONTINUOUS_RECOGNITION_FAILED = "transcriber:continuous-recognition:failed", SYNTHESIS_CREATED = "synthesis:created", SYNTHESIS_FAILED = "synthesis:failed", BARGE_IN = "barge_in", CALL_HANGUP = "call:hangup", CALL_TRANSFER = "call:transfer", CALL_TRANSFER_FAILED = "call:transfer:failed", CALL_ERROR = "call:error", SMS_SENT = "sms:sent", SMS_FAILED = "sms:failed", } type SessionEventBaseData = { timestamp: number; cluster_location?: string; hostname?: string; error?: unknown; }; type SessionEventData = { [SessionEventType.HTTP_MESSAGE]: SessionEventBaseData & { type: SessionEventType.HTTP_MESSAGE; url: string; enabledLogging: boolean; http_request: unknown; http_response_status: number; http_response_message: unknown; }; [SessionEventType.HTTP_MESSAGE_ERROR]: SessionEventBaseData & { type: SessionEventType.HTTP_MESSAGE_ERROR; url: string; enabledLogging: boolean; error?: unknown; }; [SessionEventType.WEBSOCKET_MESSAGE_ERROR]: SessionEventBaseData & { type: SessionEventType.WEBSOCKET_MESSAGE_ERROR; direction: "sent" | "received"; url: string; enabledLogging: boolean; error?: unknown; }; [SessionEventType.WEBSOCKET_MESSAGE]: SessionEventBaseData & { type: SessionEventType.WEBSOCKET_MESSAGE; direction: "sent" | "received"; url: string; enabledLogging: boolean; event: unknown; }; [SessionEventType.WEBSOCKET_ERROR]: SessionEventBaseData & { type: SessionEventType.WEBSOCKET_ERROR; direction: "sent" | "received"; url: string; enabledLogging: boolean; error?: unknown; }; [SessionEventType.WEBSOCKET_CLOSED]: SessionEventBaseData & { type: SessionEventType.WEBSOCKET_CLOSED; url: string; enabledLogging: boolean; code?: string; reason?: string; }; [SessionEventType.TRANSCRIBER_CLOSE]: SessionEventBaseData & { type: SessionEventType.TRANSCRIBER_CLOSE; provider: string; }; [SessionEventType.TRANSCRIBER_CREATE]: SessionEventBaseData & { type: SessionEventType.TRANSCRIBER_CREATE; provider: string; }; [SessionEventType.TRANSCRIBER_STARTED]: SessionEventBaseData & { type: SessionEventType.TRANSCRIBER_STARTED; provider: string; error?: unknown; }; [SessionEventType.TRANSCRIBER_STOPPED]: SessionEventBaseData & { type: SessionEventType.TRANSCRIBER_STOPPED; provider: string; }; [SessionEventType.TRANSCRIBER_CANCELED]: SessionEventBaseData & { type: SessionEventType.TRANSCRIBER_CANCELED; provider: string; }; [SessionEventType.TRANSCRIBER_SPEECH_START]: SessionEventBaseData & { type: SessionEventType.TRANSCRIBER_SPEECH_START; provider: string; }; [SessionEventType.TRANSCRIBER_CONTINUOUS_RECOGNITION_STARTED]: SessionEventBaseData & { type: SessionEventType.TRANSCRIBER_CONTINUOUS_RECOGNITION_STARTED; provider: string; }; [SessionEventType.TRANSCRIBER_CONTINUOUS_RECOGNITION_FAILED]: SessionEventBaseData & { type: SessionEventType.TRANSCRIBER_CONTINUOUS_RECOGNITION_FAILED; provider: string; }; [SessionEventType.TRANSCRIBER_SPEECH_END]: SessionEventBaseData & { type: SessionEventType.TRANSCRIBER_SPEECH_END; provider: string; }; [SessionEventType.SYNTHESIS_CREATED]: SessionEventBaseData & { type: SessionEventType.SYNTHESIS_CREATED; provider: string; durationMs: number; byteLength: number; text?: string; ssml?: string; }; [SessionEventType.SYNTHESIS_FAILED]: SessionEventBaseData & { type: SessionEventType.SYNTHESIS_FAILED; provider: string; text?: string; ssml?: string; }; [SessionEventType.CALL_HANGUP]: SessionEventBaseData & { type: SessionEventType.CALL_HANGUP; call_sid: string; }; [SessionEventType.CALL_TRANSFER]: SessionEventBaseData & { type: SessionEventType.CALL_TRANSFER; call_sid: string; target_number: string; caller_id_number: string; caller_id_name: string; }; [SessionEventType.CALL_TRANSFER_FAILED]: SessionEventBaseData & { type: SessionEventType.CALL_TRANSFER_FAILED; call_sid: string; target_number?: string; reason: TransferFailedReason; }; [SessionEventType.BARGE_IN]: SessionEventBaseData & { type: SessionEventType.BARGE_IN; userSpeech: string; bargeInConfig?: object; }; [SessionEventType.CALL_ERROR]: SessionEventBaseData & { type: SessionEventType.CALL_ERROR; action: "hangup" | "transfer"; call_sid: string; }; [SessionEventType.SMS_SENT]: SessionEventBaseData & { type: SessionEventType.SMS_SENT; call_sid: string; recipient: string; }; [SessionEventType.SMS_FAILED]: SessionEventBaseData & { type: SessionEventType.SMS_FAILED; call_sid: string; recipient: string; fault_code?: number; reason: string; }; }; type SessionEvent = SessionEventData[keyof SessionEventData]; type EventsRow = { id: string; session_id: string; type: string; data: SessionEvent; created_at: Date; updated_at: Date; }; //#endregion //#region src/model/vad.model.d.ts declare const VAD_END_OF_TURN_SILENCE_MS_MIN = 150; declare const VAD_END_OF_TURN_SILENCE_MS_MAX = 2000; declare const VadConfigSchema: z.ZodObject<{ end_of_turn_silence_ms: z.ZodCatch>; }, z.core.$strip>; type VadConfig = z.infer; //#endregion //#region src/model/session-state.model.d.ts /** * Database row type for session_state table * * Stores volatile session state that needs to survive service restarts: * - WebSocket identifiers (stream_id) * - Barge-in configuration and state * - User input timeout configuration * - Speech end detection state * - Voice-activity detection configuration */ type SessionStateRow = { /** Session ID (foreign key to sessions.id) */ session_id: string; /** Stream ID from WebSocket connection (for audio routing) */ stream_id?: string | null; /** Barge-in configuration (JSONB) */ barge_in_config?: BargeInConfig | null; /** Timestamp when barge-in config was set (Unix milliseconds) */ barge_in_configured_at?: number | null; /** Flag indicating if session is currently barged-in */ is_barged_in: boolean; /** User input timeout duration in seconds */ user_input_timeout_seconds?: number | null; /** Timestamp when timeout was scheduled (Unix milliseconds) */ user_input_timeout_scheduled_at?: number | null; /** Estimated timestamp when audio playback ends (Unix milliseconds) */ estimated_end_of_audio?: number | null; /** Voice-activity detection configuration (JSONB) */ vad_config?: VadConfig | null; /** Row creation timestamp */ created_at: Date; /** Row last update timestamp */ updated_at: Date; }; /** * Insertable type for session_state (omits auto-generated fields) */ type SessionStateInsert = Omit; /** * Updatable type for session_state (all fields optional except session_id) */ type SessionStateUpdate = Partial>; //#endregion //#region src/model/session-usage.model.d.ts /** * Database row type for session_usage table * * Persists completed session durations for historical usage tracking. * Written once when a session closes; never updated. */ type SessionUsageRow = { /** Client that owns this session */ client_id: string; /** Session ID (no FK to sessions — runtime table is cleaned up) */ session_id: string; /** When the audio stream started (stream_started_at from sessions) */ started_at: Date; /** When the session ended (ended_at from sessions) */ ended_at: Date; /** Duration in whole seconds: FLOOR(EXTRACT(EPOCH FROM (ended_at - started_at))) */ duration_seconds: number; /** Whether this session counts toward billing. False for dev instances. */ is_billable: boolean; }; //#endregion //#region src/model/stt-languages.model.d.ts /** * Zod schema for the `sttLanguages` client configuration field. * * Normalization pipeline (in order): * 1. `null` / `undefined` → `[]` (PUT replace semantics) * 2. Per-code validation via `Intl.Locale` dual-gate (format + semantic) * 3. Normalize + deduplicate via `Intl.Locale.maximize()` * 4. Max-4 check AFTER deduplication */ declare const SttLanguagesSchema: z.ZodPipe>>, z.ZodTransform>, z.ZodPipe, z.ZodTransform>>; type SttLanguages = z.infer; //#endregion //#region src/util/filter.util.d.ts declare function onlyUnique(value: T, index: number, self: T[]): boolean; declare function notEmpty(value: T | null | undefined): value is T; //#endregion //#region src/util/sleep.util.d.ts declare function sleep(ms: number): Promise; //#endregion //#endregion //#region src/sdk/assistant/assistant.d.ts type InvocationResponseType = AiFlowAction | AiFlowAction[] | string | null | undefined; type AiFlowAssistantOptions = { apiKey?: string; debug?: boolean; baseUrl?: string; token?: string; onUserSpeak?: (event: AiFlowEventUserSpeak, ws?: WebSocket) => Promise | Promise; onUserSpeechStarted?: (event: AiFlowEventUserSpeechStarted, ws?: WebSocket) => Promise; onUserInputTimeout?: (event: AiFlowEventUserInputTimeout, ws?: WebSocket) => Promise | Promise; onDtmfReceived?: (event: AiFlowEventDtmfReceived, ws?: WebSocket) => Promise | Promise; onAssistantSpeak?: (event: AiFlowEventAssistantSpeak, ws?: WebSocket) => Promise | Promise; onAssistantSpeechEnded?: (event: AiFlowEventAssistantSpeechEnded, ws?: WebSocket) => Promise | Promise; onSessionStart?: (event: AiFlowEventSessionStart, ws?: WebSocket) => Promise | Promise; onSessionEnd?: (event: AiFlowEventSessionEnd, ws?: WebSocket) => Promise | Promise; onUserBargeIn?: (event: AiFlowEventUserBargeIn, ws?: WebSocket) => Promise | Promise; /** * Called when the service reports an `error` event (invalid action, * unreachable speech provider, failed synthesis, …). Primarily diagnostic: * inspect `event.code` to branch and `event.severity` to filter noise. * * Over HTTP transport you MAY return action(s) — e.g. answer * `synthesis_unavailable` with a `transfer` — and they will be executed. * Over WebSocket transport the return value is ignored (there is no * per-event response channel). */ onError?: (event: AiFlowEventError, ws?: WebSocket) => Promise | Promise; }; declare class AiFlowAssistant { private options; constructor(options: AiFlowAssistantOptions); static create(options: AiFlowAssistantOptions): AiFlowAssistant; private log; private onResult; private onSessionStartEvent; private onUserSpeakEvent; private onUserSpeechStartedEvent; private onUserInputTimeoutEvent; private onDtmfReceivedEvent; private onAssistantSpeakEvent; private onAssistantSpeechEndedEvent; private onSessionEndEvent; private onUserBargeInEvent; private onErrorEvent; onEvent(event: AiFlowEvent, ws?: WebSocket): Promise; express(): (req: Request, res: Response) => Promise>>; ws(ws: WebSocket): (message: WebSocket.RawData) => Promise; call(params: { aiFlowId: string; billingDevice: string; toPhoneNumber: string; }): Promise; } //#endregion export { AiFlowAction, AiFlowActionAudio, AiFlowActionAudioSchema, AiFlowActionBargeIn, AiFlowActionBargeInSchema, AiFlowActionConfigureTranscription, AiFlowActionConfigureTranscriptionSchema, AiFlowActionHangup, AiFlowActionHangupSchema, AiFlowActionMixAudio, AiFlowActionMixAudioSchema, AiFlowActionSchema, AiFlowActionSendSms, AiFlowActionSendSmsSchema, AiFlowActionSpeak, AiFlowActionSpeakSchema, AiFlowActionTransfer, AiFlowActionTransferSchema, AiFlowActionType, AiFlowAssistant, AiFlowAssistantOptions, AiFlowBaseAction, AiFlowBaseActionSchema, AiFlowBaseEventSchema, AiFlowErrorCode, AiFlowErrorSeverity, AiFlowEvent, AiFlowEventAssistantSpeak, AiFlowEventAssistantSpeakSchema, AiFlowEventAssistantSpeechEnded, AiFlowEventAssistantSpeechEndedSchema, AiFlowEventDtmfReceived, AiFlowEventDtmfReceivedSchema, AiFlowEventError, AiFlowEventErrorSchema, AiFlowEventSchema, AiFlowEventSessionEnd, AiFlowEventSessionEndSchema, AiFlowEventSessionInfo, AiFlowEventSessionInfoSchema, AiFlowEventSessionStart, AiFlowEventSessionStartSchema, AiFlowEventSmsFailed, AiFlowEventSmsFailedSchema, AiFlowEventType, AiFlowEventUserBargeIn, AiFlowEventUserBargeInSchema, AiFlowEventUserInputTimeout, AiFlowEventUserInputTimeoutSchema, AiFlowEventUserSpeak, AiFlowEventUserSpeakSchema, AiFlowEventUserSpeechStarted, AiFlowEventUserSpeechStartedSchema, BargeInConfig, BargeInConfigSchema, BargeInStrategy, ClientsRow, ELEVENLABS_VOICES, ELEVENLABS_VOICE_ID_ALIASES, ElevenLabsVoiceId, EventsRow, MonthlyUsageRow, SessionBackgroundAudioRow, SessionDirection, SessionEvent, SessionEventData, SessionEventType, SessionStateInsert, SessionStateRow, SessionStateUpdate, SessionUsageRow, SessionsRow, SmsFailedReason, SttLanguages, SttLanguagesSchema, TranscriptionProvider, TransferFailedReason, TtsConfig, TtsConfigAzure, TtsConfigAzureSchema, TtsConfigElevenLabs, TtsConfigElevenLabsSchema, TtsConfigKugelaudio, TtsConfigKugelaudioSchema, TtsConfigOpenAi, TtsConfigOpenAiSchema, TtsConfigSchema, TtsProvider, VAD_END_OF_TURN_SILENCE_MS_MAX, VAD_END_OF_TURN_SILENCE_MS_MIN, VadConfig, VadConfigSchema, notEmpty, onlyUnique, sleep }; //# sourceMappingURL=index.d.cts.map