HEL-879 assembly: merge the audited HEL-877 voice backend (aba2aeb) onto the HEL-879 release-closure mainline - backend-only voice module (session/token router, chat_api_client, llm_chat_api, receipt, stt/tts adapters, worker) with zero new dependencies, provenance-preserved, e978e87 fully contained in both parents; web/ untouched by this side

This commit is contained in:
zonggong
2026-10-27 03:27:03 +08:00
24 changed files with 3153 additions and 0 deletions
+18
View File
@@ -48,6 +48,7 @@ from ..memory.semantic import build_semantic
from ..memory.store import Store
from ..think.scenes import Scene
from ..think.wiring import build_router_from_config
from ..voice import VoiceSessionService, build_voice_router, load_voice_config
HOURS = [
"子时",
@@ -180,6 +181,7 @@ def create_app(
character: CharacterConfig | None = None,
semantic_mode: str | None = None,
semantic_config: dict | None = None,
voice_service=None,
) -> FastAPI:
"""Dependencies can be injected for isolated fault/cancellation tests, never via browser flags."""
db_path = db_path or os.environ.get(
@@ -272,10 +274,26 @@ def create_app(
await app.state.semantic.aclose()
for provider in set(router.provider_for(t) for t in router.available_tiers()):
await provider.aclose()
if getattr(app.state, "voice_service", None):
await app.state.voice_service.aclose()
store.close()
app = FastAPI(lifespan=lifespan, docs_url=None, redoc_url=None)
# R5 voice session endpoint (HEL-877): independent module sharing this
# process's state/locks; unconfigured instances refuse honestly.
# voice_service injection is for isolated tests; production reads config.
if voice_service is None:
try:
voice_config = load_voice_config()
except Exception:
voice_config = None
voice_service = (
VoiceSessionService(voice_config) if voice_config is not None else None
)
app.state.voice_service = voice_service
app.include_router(build_voice_router(voice_service))
@app.exception_handler(RequestValidationError)
async def invalid(_request, exc):
fields = {}