# Copie para .env.dev ou .env.prod antes de executar.

APP_ENV=dev
LOG_LEVEL=DEBUG
LOG_DIR=./logs
LOG_TO_FILE=1
CALL_TIMELINE_DIR=./timeline
CALL_TIMELINE_ENABLED=1
CALL_TIMELINE_CONSOLE=1
FLOW_LOG_ENABLED=1
FLOW_AUDIO_BURST_GAP_S=0.8
FLOW_LOG_AUDIO_BURST_END=1
FLOW_LOG_PREVIEW_CHARS=500
FLOW_LOG_STT_SKIPS=1
FLOW_LOG_VAD_DECISIONS=1
FLOW_LOG_VAD_ACTIVITY=1
FLOW_LOG_VAD_ACTIVITY_MIN_PROB=0.03
STRUCTURED_EVENT_LOG_ENABLED=1
EXPORT_DIR=./recordings
ENTIRE_CALL_RECORDING_ENABLED=1
ENTIRE_CALL_RECORDING_TMP_DIR=./recordings/entire_call_tmp

AGENT_BASE_NAME=ws-voice-agent
AGENT_BACKEND=remote_sse
AGENT_RECONNECT_ENABLED=1
AGENT_RECONNECT_MAX_ATTEMPTS=1
AGENT_RECONNECT_TIMEOUT_S=10

# WebSocket keepalive do Uvicorn para sessoes longas de audio.
UVICORN_WS_PING_INTERVAL_S=30
UVICORN_WS_PING_TIMEOUT_S=120

LIVEKIT_URL=ws://tim-ai-atend-agnt-integ-tia-livekit.agnt-ai-atendimento-tia.svc.cluster.local:7880
LIVEKIT_API_KEY=tia_livek_tia_api_key
LIVEKIT_API_SECRET=TiaLivekitSecret2026KeyBridgeSync01

# Providers locais para smoke test
STT_PROVIDER=internal_http
TTS_PROVIDER=xai
TTS_EMPTY_FRAME_RETRY_TIMEOUT_S=3
TTS_FIRST_FRAME_TIMEOUT_S=3
TTS_UNDERFLOW_ERROR_MS=1000
TTS_TOTAL_TIMEOUT_S=60
TTS_PLAYOUT_START_TIMEOUT_S=6

# Tuning de fala/interrupcao: permite detectar palavras curtas como "nao".
MIN_INTERRUPT_S=0.5
DISCARD_AUDIO_IF_UNINTERRUPTIBLE=0
SILENCE_CHECK_EVERY=1
# Volume da fala do agente: a correcao de nivel agora e feita na saida do TTS
# (worker), com limiter soft-knee p/ nao clipar. O ganho do bridge fica neutro.
WS_OUTPUT_GAIN=1.0
TTS_OUTPUT_GAIN=2.0
VAD_MIN_SPEECH_DURATION=0.15
VAD_ACTIVATION_THRESHOLD=0.30
VAD_DEACTIVATION_THRESHOLD=0.15
VAD_MIN_SILENCE_DURATION=1.0
VAD_PREFIX_PADDING_DURATION=1.0
VAD_PREFIX_PADDING_MIN_DURATION=1.0
AGENT_WAIT_TIMEOUT_RETRY_VAD_THRESHOLD_ENABLED=1
AGENT_WAIT_TIMEOUT_RETRY_VAD_ACTIVATION_THRESHOLD=0.20

# STT fake: usa uma frase por turno. Quando acabar, repete a ultima.
FAKE_STT_TRANSCRIPTS="alô"
FAKE_STT_MODE=repeat_last
FAKE_STT_MIN_AUDIO_MS=150

# TTS fake: gera um tom PCM local para validar o pipeline de audio.
FAKE_TTS_TONE_HZ=440
FAKE_TTS_AMPLITUDE=0.12
FAKE_TTS_MIN_DURATION_MS=320
FAKE_TTS_MAX_DURATION_MS=2200
FAKE_TTS_CHAR_DURATION_MS=35

# Azure Speech TTS opcional
AZURE_TTS_IMPLEMENTATION=plugin
AZURE_SPEECH_REGION=brazilsouth
AZURE_SPEECH_ENDPOINT=https://speech-agent-ai-atendi-fqa-01.cognitiveservices.azure.com/
AZURE_SPEECH_VOICE=pt-BR-FranciscaNeural
AZURE_SPEECH_LANGUAGE=pt-BR
AZURE_SPEECH_DEPLOYMENT_ID=

# STT opcional
STT_URL=http://10.152.95.27:8100/api/transcriber
STT_KEY=
STT_LANG=portuguese
STT_MIN_PROB_SINGLE_WORD=0.03
STT_MIN_AUDIO_MS=120
STT_MIN_DBFS=-55
VOSK_MODEL_PATH=

# Backend remoto opcional
REMOTE_AGENT_WS_URL=ws://tim-ai-contas-agnt-service.agnt-ai-atendimento-contas.svc.cluster.local:80/agent/ws
# Endpoint fake mantido apenas para testes manuais do contrato websocket.
REMOTE_AGENT_WS_FAKE_URL=ws://127.0.0.1:8000/fake-agent/ws
REMOTE_AGENT_WS_OPEN_TIMEOUT_S=10
REMOTE_AGENT_WS_READ_TIMEOUT_S=900
REMOTE_AGENT_WS_WRITE_TIMEOUT_S=10
REMOTE_AGENT_WS_CLOSE_TIMEOUT_S=10
REMOTE_AGENT_SSE_URL_CONTA=http://tim-ai-contas-agnt-service.agnt-ai-atendimento-contas.svc.cluster.local:80/agent/sse
REMOTE_AGENT_HEALTH_URL=http://tim-ai-contas-agnt-service.agnt-ai-atendimento-contas.svc.cluster.local:80/health
REMOTE_AGENT_HEALTH_URL_CONTA=http://tim-ai-contas-agnt-service.agnt-ai-atendimento-contas.svc.cluster.local:80/health
REMOTE_AGENT_SSE_DEFAULT_STAGE=PRESENTATION
REMOTE_AGENT_SSE_CONNECT_TIMEOUT_S=10
REMOTE_AGENT_SSE_READ_TIMEOUT_S=900
REMOTE_AGENT_SSE_WRITE_TIMEOUT_S=10
REMOTE_AGENT_INFLIGHT_WAIT_INTERVAL_S=12
REMOTE_AGENT_INFLIGHT_WAIT_TIMEOUT_S=180
REMOTE_AGENT_INFLIGHT_WAIT_MAX_NOTICES=0
REMOTE_AGENT_INFLIGHT_WAIT_TEXT=Um momento, ainda estou consultando para te ajudar.
PRE_BACKEND_WAIT_NOTICE_FAST_ON_VAD_PAUSE=0
REMOTE_AGENT_INFLIGHT_WAIT_SHORT_AUDIO_DIR=src/app/livekit/assets/comfort/short
REMOTE_AGENT_INFLIGHT_WAIT_LONG_AUDIO_DIR=src/app/livekit/assets/comfort/long

# Mock temporario para encerrar a chamada apos a primeira resposta de audio do agente.
MOCK_STOP_AFTER_FIRST_AUDIO_ENABLED=0
MOCK_STOP_AFTER_FIRST_AUDIO_SILENCE_S=2
MOCK_STOP_AFTER_FIRST_AUDIO_REASON=nao_resolvido

# Bridge audio tuning
HOLD_SILENCE_DBFS=-45
LK_CATCHUP_KEEP_MS=600
AUDIO_IN_BACKLOG_SHED_ENABLED=1
AUDIO_IN_BACKLOG_SHED_THRESHOLD_MS=500
AUDIO_IN_BACKLOG_SHED_KEEP_MS=300
AUDIO_IN_LATENCY_METRICS_ENABLED=1
AUDIO_IN_LATENCY_ALERT_MS=1000
AUDIO_IN_LATENCY_LOG_INTERVAL_S=15
LIVEKIT_AUDIO_SOURCE_QUEUE_SIZE_MS=500
LIVEKIT_AUDIO_SOURCE_CLEAR_ON_SHED=1

# Status terminais de finalizacao normal, resolvidos por reason no bridge.
FINAL_STOP_STATUS_RESOLVED=stop_resolvido_e_finalizado
FINAL_STOP_STATUS_UNRESOLVED=stop_nao_resolvido
FINAL_STOP_STATUS_OTHER_SUBJECT=stop_outro_assunto
FINAL_STOP_STATUS_LONG_SILENCE=stop_silencio_longo
FINAL_STOP_DEFAULT_KIND=resolved
FINAL_STOP_REASON_RESOLVED=stage_done
FINAL_STOP_REASON_UNRESOLVED=nao_resolvido
FINAL_STOP_REASON_OTHER_SUBJECT=outro_assunto
FINAL_STOP_REASON_LONG_SILENCE=no_user_response

# Readiness / capacidade do TIA
TIA_WS_MAX_CONNECTIONS=0
TIA_RESOURCE_HEALTH_TTL_S=5
TIA_RESOURCE_HEALTH_TIMEOUT_S=3
TIA_SKIP_STT_READINESS=1
STT_HEALTH_URL=http://10.152.95.27:8100/health

# Idle nudge
IDLE_NUDGE_ENABLED=0
IDLE_NUDGE_DELAY_S=60
IDLE_NUDGE_JOIN_DELAY_S=60

# Interrupcao durante processamento
DEFERRED_INTERRUPTION_ENABLED=1
DEFERRED_INTERRUPTION_MIN_AUDIO_MS=1000
DEFERRED_INTERRUPTION_STT_SETTLE_TIMEOUT_S=3.0
DEFERRED_INTERRUPTION_USER_TURN_TIMEOUT_S=10.0

# XAI
XAI_TTS_VOICE=c8x2ieiocufs
XAI_TTS_LANGUAGE=pt-BR
XAI_TTS_READINESS_MODE=connect
XAI_WEBSOCKET_URL=wss://peordagnt002prd.pe.inference.generativeai.us-chicago-1.oci.oraclecloud.com/xai/v1/tts

# PUBSUB Metrics
GCP_PROJECT_ID=tim-bigdata-dev-ca1f
AGENT_PUBSUB_TOPIC=pbs-ingest-agnt-ai-tia-events

REMOTE_AGENT_SSE_URL_OFERTA=https://agt-ai-atendimento-ofertas-dev.internal.timbrasil.com.br/agent/execute
REMOTE_AGENT_SSE_TLS_VERIFY_OFERTA=0

# OTEL
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://10.153.35.23/v1/traces
OTEL_SERVICE_NAME=ai-agent-tia-orch
OTEL_EXPORTER_OTLP_HEADERS=Host=tim-ai-atend-agnt-opentelemetry

#BUCKET OBJECT STORAGE
BUCKET_REGION=sa-saopaulo-1
BUCKET_NAME=osb-gru-agnt-ai-atendimento-dev-004
BUCKET_NAMESPACE=grfrp6rtsznm
