feat(voice): add isolated Local S2S v3 candidate and acceptance evidence

Extract the provider boundary while retaining OpenAI/Gemini contracts. Add
an opt-in isolated Local S2S adapter, pinned engine extension, bounded
component gateway and frozen effective configuration profiles.

Enforce request token limits, zero retries, local asset validation,
connection deadlines, disconnect ownership, bounded cleanup and signals.
Include regression coverage, pinned source fixtures, operator guidance,
asset fingerprints and guarded disposable PostgreSQL acceptance tooling.
Preserve immutable fixture bytes across Git line-ending conversion.

Validation recorded in the reports:
- 74 repair, 107 combined and 242 preservation checks passed.
- Fresh PostgreSQL local checks: 2 passed.
- Expanded PostgreSQL: 57 passed, 6 documented baseline failures.
- Compose configurations, staged whitespace and fixture hashes passed.

Phase 1 live listening and Phase 2 complete engine/SDK/POSIX, real component
audio and Persian browser acceptance remain pending. No operational switch,
paid call, model download or Phase 3 implementation is included.
This commit is contained in:
amirhosein mazaheri
2026-10-15 12:28:17 +03:30
parent 872e5f25cb
commit 8d348f0ba1
56 changed files with 8802 additions and 44 deletions
+74
View File
@@ -0,0 +1,74 @@
"""Private provider port; browser events and runtime safety policy stay unchanged.
Events retain their admitted native identities and replay fingerprints. A terminal
response proves generation stopped, never that unheard history was repaired.
"""
from dataclasses import dataclass
import json
from typing import Protocol
from app.modules.voice.settings import RuntimeSettings
class ProviderProtocolError(ValueError):
pass
def canonical_json(value):
return json.dumps(value, ensure_ascii=False, allow_nan=False,
separators=(",", ":"), sort_keys=True)
def strict_json(raw):
def pairs(items):
value = {}
for key, item in items:
if key in value:
raise ValueError("Duplicate JSON key")
value[key] = item
return value
return json.loads(raw, object_pairs_hook=pairs,
parse_constant=lambda _: (_ for _ in ()).throw(ValueError("Nonfinite JSON")))
@dataclass(frozen=True)
class HistoryRepair:
"""Runtime-frozen correlation, after terminal and final playback coordinates."""
session_id: str
generation: int
response_id: str
operation_id: str
item_id: str
content_index: int
played_ms: int
@dataclass(frozen=True)
class HistoryRepairReceipt:
repair: HistoryRepair
# Native provenance, not an invented provider history revision. OpenAI's
# truncate event supplies item/part/position, but no operation or revision.
native_event_id: str | None
provenance: str
class VoiceProvider(Protocol):
"""Required transport/setup/repair operations; no provider-name branching.
Native optional extensions (consumed/backlog/tool completion classification)
remain adapter-owned. Runtime owns all authority, deadlines and release gates.
"""
settings: RuntimeSettings
def setup(self) -> dict: ...
def acknowledged(self, session: dict) -> bool: ...
def serialize(self, event: dict) -> str: ...
async def send_serialized(self, wire: str) -> None: ...
async def send(self, event: dict) -> None: ...
async def receive(self) -> dict: ...
def cancellation_request(self, response_id: str, operation_id: str | None = None) -> dict: ...
def history_repair_request(self, repair: HistoryRepair) -> dict: ...
def confirm_history_repair(self, repair: HistoryRepair, event: dict) -> HistoryRepairReceipt: ...
def is_no_active(self, error: dict) -> bool: ...
def abort(self) -> bool: ...
async def close(self) -> None: ...