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:
@@ -1,5 +1,4 @@
|
||||
"""Private OpenAI Realtime wire adapter; no application/provider IDs cross to clients."""
|
||||
import json
|
||||
from urllib.parse import quote
|
||||
|
||||
from app.modules.knowledge.service import SearchInput
|
||||
@@ -8,8 +7,9 @@ from app.modules.voice.configuration import OpenAIInputSettings
|
||||
from app.modules.voice.serialization import bounded_json
|
||||
from app.modules.voice.openai_style import effective_instructions
|
||||
|
||||
class ProviderProtocolError(ValueError):
|
||||
pass
|
||||
from app.modules.voice.provider import (
|
||||
ProviderProtocolError, canonical_json, strict_json, HistoryRepair, HistoryRepairReceipt,
|
||||
)
|
||||
|
||||
POLICY = """You are the official voice assistant for «شرکت شهرکهای صنعتی اصفهان».
|
||||
Your scope is strictly limited to answering questions regarding «شرکت شهرکهای صنعتی اصفهان», including its regulations, industrial parks in Isfahan province, land allocations, contracts, permits, circulars, and official procedures.
|
||||
@@ -52,21 +52,6 @@ When calling search_knowledge:
|
||||
- Preserve the user's explicitly stated place names, person names, document titles and identifiers in query. Shortening the question must not replace them with different entities. If a name is unclear, ask for clarification rather than guessing.
|
||||
- Set 'context' to null. Never write explanations or user intent in 'context'."""
|
||||
|
||||
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")))
|
||||
|
||||
class RealtimeAdapter:
|
||||
# Argument-done can precede a cut-off tool call: wait for terminal success.
|
||||
defer_tool_execution = True
|
||||
@@ -146,6 +131,30 @@ class RealtimeAdapter:
|
||||
for key in empty_defaults
|
||||
if key not in expected['audio']['input']['transcription'])
|
||||
|
||||
def cancellation_request(self, response_id, operation_id=None):
|
||||
event = dict(type="response.cancel", response_id=response_id)
|
||||
if operation_id is not None:
|
||||
event["event_id"] = operation_id
|
||||
return event
|
||||
|
||||
def history_repair_request(self, repair: HistoryRepair):
|
||||
return dict(type="conversation.item.truncate", event_id=repair.operation_id,
|
||||
item_id=repair.item_id, content_index=repair.content_index,
|
||||
audio_end_ms=repair.played_ms)
|
||||
|
||||
def confirm_history_repair(self, repair: HistoryRepair, event):
|
||||
# Native OpenAI ack has no request event_id/response_id. Runtime first
|
||||
# matches exactly one dispatched item/part in this session; never invent
|
||||
# additional upstream confirmation or infer a heard transcript prefix.
|
||||
if (event.get("type") != "conversation.item.truncated"
|
||||
or event.get("item_id") != repair.item_id
|
||||
or type(event.get("content_index")) is not int
|
||||
or event["content_index"] != repair.content_index
|
||||
or type(event.get("audio_end_ms")) is not int
|
||||
or event["audio_end_ms"] != repair.played_ms):
|
||||
raise ProviderProtocolError("History repair acknowledgement mismatch")
|
||||
return HistoryRepairReceipt(repair, event.get("event_id"), "openai.item_truncated")
|
||||
|
||||
def interrupted_tool_output(self, call_id):
|
||||
# Resolve abandoned private tool calls without publishing stale evidence.
|
||||
return dict(type="conversation.item.create", item=dict(
|
||||
|
||||
Reference in New Issue
Block a user