feat(pheby): add authenticated GPT-Live voice setup

Use Hermes to exchange WebRTC offers for the connector profile. Keep cancellation acknowledgments private and guard replacement runs against stale delivery.
This commit is contained in:
Chris Mendoza
2026-11-20 12:36:28 -05:00
parent 3bfb300a2f
commit 49b180922d
8 changed files with 462 additions and 72 deletions
+46
View File
@@ -1155,6 +1155,24 @@ class TestBridge:
ok = await hb.cancel_run("convY", "wrong-run")
assert ok is False
@pytest.mark.asyncio
async def test_cancel_ack_is_private_and_terminal_event_is_broadcast(self, tmp_path):
server = make_server(tmp_path)
caller, other = FakeClientConnection(), FakeClientConnection()
caller.authenticated = other.authenticated = True
server._clients.update(caller=caller, other=other)
server.adapter.gateway_runner = runner = FakeRunner()
runner._running_agents["agent:main:pheby:dm:voice-chat"] = FakeAgent()
from pheby import hermes_bridge as hb
hb._ACTIVE_RUNS["voice-chat"] = {"run_id": "voice-run", "started": 0}
await server._handle_run_cancel(caller, {"conversation_id": "voice-chat", "run_id": "voice-run"}, "r1")
event = {"type": "run.finished", "conversation_id": "voice-chat", "run_id": "voice-run", "status": "cancelled"}
assert caller.ws.events() == [{**event, "request_id": "r1"}, event]
assert other.ws.events() == [event]
assert hb.active_run_id("voice-chat") is None
@pytest.mark.asyncio
async def test_reasoning_set_validation(self, tmp_path):
from pheby import hermes_bridge as hb
@@ -1404,6 +1422,34 @@ class TestAdapterUnits:
assert [e["type"] for e in client.ws.events()][-2:] == [
proto.S_MESSAGE_COMPLETE, proto.S_RUN_FINISHED]
@pytest.mark.asyncio
async def test_cancelled_task_delivery_does_not_finish_successor(self, tmp_path, monkeypatch):
from gateway.config import PlatformConfig
from gateway.platforms.base import BasePlatformAdapter
from pheby import hermes_bridge as hb
server = make_server(tmp_path)
listener = FakeClientConnection()
listener.authenticated = True
server._clients["listener"] = listener
adapter = PhebyAdapter(PlatformConfig(enabled=True))
adapter._server = server
conv = "voice-replacement"
adapter._drafts[conv] = {"run_id": "new", "message_id": "draft-new", "text": ""}
monkeypatch.setitem(hb._ACTIVE_RUNS, conv, {"run_id": "new", "started": 0})
async def late_delivery(self, event, key):
await self.send(conv, "old final")
await self.edit_message(conv, "draft-old", "old edit", finalize=True)
monkeypatch.setattr(BasePlatformAdapter, "_process_message_background", late_delivery)
event = SimpleNamespace(metadata={"pheby_run_id": "old"}, source=SimpleNamespace(chat_id=conv))
await adapter._process_message_background(event, "session-key")
assert hb.active_run_id(conv) == "new"
assert adapter._drafts[conv]["message_id"] == "draft-new"
assert listener.ws.events() == []
def test_transport_auth_is_gateway_authorization(self):
from pheby.adapter import PhebyAdapter
from gateway.config import PlatformConfig