Engine mode is now explicit: USE_MOCK_SIP=true is the only way to get the mock engine; an unconfigured trunk fails startup with guidance instead of silently degrading. Root-caused why the engine always ran mock: nested pydantic-settings never read .env (no env_file on the sub-settings classes) — all 8 now declare it. /health stops lying: reports engine mode (sippy|mock), a live DB SELECT 1, trunk registration state with reason, and TTS/STT availability from their last real request; "healthy" now requires ready + db + sippy + registered trunk. Error policy: leaf services (tts/transcription/llm_client) raise and track availability; call-loop callers catch, publish EventType.ERROR naming the failed service, and apply an explicit fallback. Persistence writes get one bounded 3x exponential retry, then an ERROR log — no more silent data loss. Event bus: a full subscriber queue drops its oldest event (counted) instead of silently evicting the subscription; subscribe(replay_last=N) delivers the advertised history replay, used by /ws/events (25). Receptionist correctness: a matched TAKE_MESSAGE rule beats the LLM; voicemail polls for early hangup and stops/transcribes/hangs up in finally; RecordingSession finally keeps its leg_ids so taps detach. Dead code removed: models/contact.py + Contact table, dtmf_buffer, transcribe_stream stub, SMS stub in notification.py. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
165 lines
5.1 KiB
Python
165 lines
5.1 KiB
Python
"""
|
|
Hold Slayer Gateway — Configuration
|
|
|
|
All settings loaded from environment variables / .env file.
|
|
"""
|
|
|
|
from pydantic import Field, SecretStr
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class SIPTrunkSettings(BaseSettings):
|
|
"""SIP trunk provider configuration."""
|
|
|
|
model_config = SettingsConfigDict(env_prefix="SIP_TRUNK_", env_file=".env", extra="ignore")
|
|
|
|
host: str = "sip.provider.com"
|
|
port: int = 5060
|
|
username: str = ""
|
|
password: SecretStr = SecretStr("")
|
|
transport: str = "udp" # udp, tcp, tls
|
|
did: str = "" # Your phone number (E.164)
|
|
|
|
|
|
class GatewaySIPSettings(BaseSettings):
|
|
"""Gateway SIP listener for device registration."""
|
|
|
|
model_config = SettingsConfigDict(env_prefix="GATEWAY_SIP_", env_file=".env", extra="ignore")
|
|
|
|
host: str = "0.0.0.0"
|
|
port: int = 5060
|
|
domain: str = "gateway.local"
|
|
|
|
|
|
class SpeachesSettings(BaseSettings):
|
|
"""Speaches STT service configuration."""
|
|
|
|
model_config = SettingsConfigDict(env_prefix="SPEACHES_", env_file=".env", extra="ignore")
|
|
|
|
url: str = "http://localhost:22070"
|
|
model: str = "whisper-large-v3"
|
|
|
|
|
|
class ClassifierSettings(BaseSettings):
|
|
"""Audio classifier thresholds."""
|
|
|
|
model_config = SettingsConfigDict(env_prefix="CLASSIFIER_", env_file=".env", extra="ignore")
|
|
|
|
music_threshold: float = 0.7
|
|
speech_threshold: float = 0.6
|
|
silence_threshold: float = 0.85
|
|
window_seconds: float = 3.0
|
|
|
|
|
|
class LLMSettings(BaseSettings):
|
|
"""LLM service configuration (OpenAI-compatible API)."""
|
|
|
|
model_config = SettingsConfigDict(env_prefix="LLM_", env_file=".env", extra="ignore")
|
|
|
|
base_url: str = "http://localhost:11434/v1"
|
|
model: str = "llama3"
|
|
api_key: SecretStr = SecretStr("not-needed")
|
|
timeout: float = 30.0
|
|
max_tokens: int = 1024
|
|
temperature: float = 0.3
|
|
|
|
|
|
class HoldSlayerSettings(BaseSettings):
|
|
"""Hold Slayer behavior settings."""
|
|
|
|
model_config = SettingsConfigDict(env_prefix="HOLD_SLAYER_", env_prefix_allow_empty=True, env_file=".env", extra="ignore")
|
|
|
|
default_transfer_device: str = Field(
|
|
default="sip_phone", validation_alias="DEFAULT_TRANSFER_DEVICE"
|
|
)
|
|
max_hold_time: int = Field(default=7200, validation_alias="MAX_HOLD_TIME")
|
|
hold_check_interval: float = Field(default=2.0, validation_alias="HOLD_CHECK_INTERVAL")
|
|
|
|
|
|
class TTSSettings(BaseSettings):
|
|
"""Rhema TTS service configuration (OpenAI-compatible /v1/audio/speech)."""
|
|
|
|
model_config = SettingsConfigDict(env_prefix="TTS_", env_file=".env", extra="ignore")
|
|
|
|
base_url: str = "http://localhost:8000"
|
|
model: str = "speaches-ai/Kokoro-82M-v1.0-ONNX"
|
|
voice: str = "af_heart"
|
|
api_key: SecretStr = SecretStr("")
|
|
timeout: float = 30.0
|
|
sample_rate: int = 16000
|
|
|
|
|
|
class ReceptionistSettings(BaseSettings):
|
|
"""AI Receptionist behavior settings."""
|
|
|
|
model_config = SettingsConfigDict(env_prefix="RECEPTIONIST_", env_file=".env", extra="ignore")
|
|
|
|
enabled: bool = True
|
|
greeting_template: str = (
|
|
"Hi, you've reached Robert's line. Who's calling, and what's this about?"
|
|
)
|
|
message_prompt: str = "Please leave your message after the tone."
|
|
listen_timeout_s: float = 15.0
|
|
end_of_utterance_silence_s: float = 1.2
|
|
message_max_seconds: int = 90
|
|
llm_persona: str = (
|
|
"You are a helpful, concise phone receptionist. Decide whether to ring "
|
|
"the owner, take a message, or politely decline."
|
|
)
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""Root application settings."""
|
|
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env",
|
|
env_file_encoding="utf-8",
|
|
extra="ignore",
|
|
)
|
|
|
|
# Database — no default credentials; must be set in the environment
|
|
database_url: str = ""
|
|
|
|
# Server
|
|
host: str = "0.0.0.0"
|
|
port: int = 8000
|
|
debug: bool = False
|
|
log_level: str = "info"
|
|
|
|
# Auth — one static bearer token shared by REST, WebSocket, and MCP.
|
|
# Empty disables auth, which is only permitted on loopback binds.
|
|
api_token: SecretStr = SecretStr("")
|
|
|
|
# Outbound-call safety cap (REST + MCP make_call)
|
|
max_concurrent_calls: int = 4
|
|
|
|
# Explicit engine mode — the mock engine must be asked for. An
|
|
# unconfigured trunk without this flag fails startup instead of
|
|
# silently degrading to a gateway that can't place real calls.
|
|
use_mock_sip: bool = False
|
|
|
|
# Notifications
|
|
notify_sms_number: str = ""
|
|
|
|
# Sub-configs
|
|
sip_trunk: SIPTrunkSettings = Field(default_factory=SIPTrunkSettings)
|
|
gateway_sip: GatewaySIPSettings = Field(default_factory=GatewaySIPSettings)
|
|
speaches: SpeachesSettings = Field(default_factory=SpeachesSettings)
|
|
classifier: ClassifierSettings = Field(default_factory=ClassifierSettings)
|
|
llm: LLMSettings = Field(default_factory=LLMSettings)
|
|
hold_slayer: HoldSlayerSettings = Field(default_factory=HoldSlayerSettings)
|
|
tts: TTSSettings = Field(default_factory=TTSSettings)
|
|
receptionist: ReceptionistSettings = Field(default_factory=ReceptionistSettings)
|
|
|
|
|
|
# Singleton
|
|
_settings: Settings | None = None
|
|
|
|
|
|
def get_settings() -> Settings:
|
|
"""Get cached application settings."""
|
|
global _settings
|
|
if _settings is None:
|
|
_settings = Settings()
|
|
return _settings
|