generated from Labyricorn/labyricorn-project-template
CI / frontend-quality (push) Canceled after 0s
- All 'voicebox'/'Voicebox'/'VOICEBOX' strings replaced with 'talkbox'/'TalkBox'/'TALKBOX' - Port changed from 17493 to 17494 (avoids conflict with upstream VoiceBox) - MCP tool namespace: voicebox.* -> talkbox.* - App bundle ID: sh.voicebox.app -> com.talkbox.app - Binary names: voicebox-server -> talkbox-server, voicebox-mcp -> talkbox-mcp - Docker user/group: voicebox -> talkbox - Database: voicebox.db -> talkbox.db - Env vars: VOICEBOX_* -> TALKBOX_* - Asset files renamed: voicebox-logo.* -> talkbox-logo.*, etc. - External binaries in tauri.conf.json updated to talkbox-server/talkbox-mcp
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
"""In-memory pub/sub for speaking-pill SSE broadcasts.
|
|
|
|
MCP ``talkbox.speak`` calls and the REST ``POST /speak`` route publish
|
|
start/end events that DictateWindow subscribes to via /events/speak, so the
|
|
floating pill surfaces whenever an agent is speaking.
|
|
"""
|
|
|
|
import asyncio
|
|
from typing import Any
|
|
|
|
|
|
# Each subscriber gets its own queue. Bounded to drop oldest if a client lags.
|
|
_subscribers: set[asyncio.Queue[dict[str, Any]]] = set()
|
|
|
|
|
|
def subscribe() -> asyncio.Queue[dict[str, Any]]:
|
|
"""Register a new subscriber; caller must call unsubscribe() when done."""
|
|
queue: asyncio.Queue[dict[str, Any]] = asyncio.Queue(maxsize=64)
|
|
_subscribers.add(queue)
|
|
return queue
|
|
|
|
|
|
def unsubscribe(queue: asyncio.Queue[dict[str, Any]]) -> None:
|
|
_subscribers.discard(queue)
|
|
|
|
|
|
def publish(kind: str, payload: dict[str, Any]) -> None:
|
|
"""Fan out to all current subscribers. Non-blocking; drops on full queue.
|
|
|
|
Each subscriber gets its own dict copy — the SSE consumer calls
|
|
``event.pop("kind", ...)``, so sharing a single dict between queues
|
|
would mean the first consumer to drain its queue strips ``kind`` from
|
|
the object the next consumer later reads.
|
|
"""
|
|
for queue in list(_subscribers):
|
|
event = {"kind": kind, **payload}
|
|
try:
|
|
queue.put_nowait(event)
|
|
except asyncio.QueueFull:
|
|
# Slow subscriber — skip rather than block publishers.
|
|
pass
|