mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-16 13:20:39 -07:00
Mounts FastMCP at /mcp (Streamable HTTP) so Claude Code, Cursor, Windsurf, and the VS Code MCP extensions can call voicebox.speak, voicebox.transcribe, voicebox.list_captures, and voicebox.list_profiles against the running Voicebox server. Backend - new backend/mcp_server package (tools, middleware, profile resolve, pub/sub events); named mcp_server to avoid shadowing the installed mcp PyPI package FastMCP imports internally - app.py migrated from @app.on_event to lifespan= so FastMCP's session manager cohabits with Voicebox's startup/shutdown - new MCPClientBinding table + /mcp/bindings CRUD; ClientIdMiddleware reads X-Voicebox-Client-Id into a ContextVar and stamps last_seen_at - profile resolution precedence: explicit -> per-client binding -> capture_settings.default_playback_voice_id - POST /speak REST wrapper for non-MCP callers (shell, ACP, A2A) - GET /events/speak SSE broadcasts speak-start / speak-end so the pill surfaces agent-initiated speech - backend/mcp_shim proxy (plain httpx) for stdio-only MCP clients - PyInstaller spec updates + new --shim build target (~18 MB) Frontend - Settings -> MCP page with HTTP / stdio / claude-mcp-add copy snippets, default voice picker, per-client bindings table, connection status - useMCPBindings, useSpeakEvents hooks - CapturePill gains 'speaking' state; DictateWindow subscribes to SSE and emits dictate:show so the Rust side surfaces the pill window Native - tauri.conf.json externalBin now includes voicebox-mcp - show_dictate_window helper + dictate:show listener in main.rs - (also in this commit: InputMonitoringGate UX, hotkey_monitor tweaks, landing footer/navbar updates, new overview docs for captures / dictation / mcp-server / voice-personalities) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
"""Server-Sent-Event streams the frontend subscribes to.
|
|
|
|
``GET /events/speak`` — broadcasts ``speak-start`` / ``speak-end`` events
|
|
whenever an agent-initiated speak (MCP tool or POST /speak) runs. The
|
|
DictateWindow uses them to show the floating pill in a `speaking` state.
|
|
"""
|
|
|
|
import asyncio
|
|
import json
|
|
import logging
|
|
|
|
from fastapi import APIRouter, Request
|
|
from sse_starlette.sse import EventSourceResponse
|
|
|
|
from ..mcp_server import events as mcp_events
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/events/speak")
|
|
async def speak_events(request: Request):
|
|
"""SSE stream of speak-start / speak-end events."""
|
|
|
|
async def event_stream():
|
|
queue = mcp_events.subscribe()
|
|
try:
|
|
# Immediate hello so EventSource knows the connection is live.
|
|
yield {"event": "ready", "data": "{}"}
|
|
while True:
|
|
if await request.is_disconnected():
|
|
return
|
|
try:
|
|
event = await asyncio.wait_for(queue.get(), timeout=15.0)
|
|
except asyncio.TimeoutError:
|
|
# Heartbeat so proxies don't reap idle streams.
|
|
yield {"event": "ping", "data": "{}"}
|
|
continue
|
|
kind = event.pop("kind", "message")
|
|
yield {"event": kind, "data": json.dumps(event)}
|
|
finally:
|
|
mcp_events.unsubscribe(queue)
|
|
|
|
return EventSourceResponse(event_stream())
|