File size: 3,666 Bytes
71c3187
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# SPEC-DRIVERS — backend interface specs

Every layer is a driver with a common interface, chosen per run. A driver
never prints; it raises typed errors and the CLI maps them to exit codes.

## Error contract

| Exception | Exit | Meaning |
|---|---|---|
| `ValidationError` | 2 | bad input (URL, missing image, unknown driver) |
| `DriverError` | 3 | transport failure (HTTP, WebSocket, track error) |
| `SessionError` | 4 | session refused/failed/closed by remote |
| `CapabilityShortfall` | 6 | driver deps/config missing on this host; carries `capability` + `remediation` |

## PresenceDriver

```python
class PresenceDriver:
    name: str          # registry key: "browser" | "livekit" | "sip"
    audio: bool        # owns a mic track?
    video: bool        # owns a camera track?

    join(meet_url, platform, bot_name, image, voice,
         system_prompt, meeting_password) -> session_id
    status(session_id) -> "joining" | "ready" | "error" | "closed"
    video_connected(session_id) -> bool
    bot_connected(session_id)  -> bool
    leave(session_id) -> None
```

Contract rules:

1. `join` returns a driver-global session id stable across CLI invocations
   (leave is a separate process).
2. Sessions must survive the joining process — state lives in a driver
   registry on disk (`.freestream/sessions/<id>/driver.json`), not in memory.
3. `join` must emit event-log entries (`driver.join_attempted`,
   `session.created`, `session.status`, …) when a log is attached.
4. Missing host capabilities are `CapabilityShortfall`, never crashes.
5. Sessions must survive process teardown — state lives in a driver
   registry on disk (`.freestream/sessions/<id>/driver.json`), not in memory.

## livekit driver (MVP target)

- Joins a LiveKit room via `livekit-rtc` with a local track: mic-in fed by
  the persona TTS output, camera-in fed by the avatar frame sink.
- ASR subscribes to remote audio tracks; faster-whisper consumes them.
- Lowest jitter of the free drivers; requires the meeting to run on
  LiveKit/Jitsi (self-hosted or open instance).
- Config: `LIVEKIT_URL`, `LIVEKIT_TOKEN` (room-local token minted by
  `freestream` for bot-name).

## browser driver (post-MVP)

- Playwright/Chromium joins as a guest; virtual camera (v4l2loopback on
  Linux, BlackHole + AVFoundation on macOS) supplies avatar frames; virtual
  mic supplies TTS audio.
- Needs per-platform **join packs**: URL validation, guest-button selectors,
  permission-grant selectors, pre-admit waiting-room handling. Selector
  drift is the maintenance hotspot; packs are versioned and pinned per
  platform build (see docs/PLATFORMS.md).
- Commercial platforms (Meet/Zoom) are ToS gray zones — shipped last.

## sip driver (audio-only)

- Dials a conferencing bridge via SIP; near-zero cost, no video.
- Fidelity rung caps at AUDIO_REACTIVE_WAVE (no camera track).
- Config: `FREESTREAM_SIP_URI`, trunk credentials.

## Persona drivers

- `VoiceBackend`: `piper` (default, CPU real-time) → `xtts-local` (cloning).
  `clone()` returns the Pika-compatible dict and writes `life/voice_id.txt`
  + `life/voice_config.json`. Clones are local files, never uploaded.
- `AvatarBackend`: selected by `select_rung()` from the fidelity ladder
  (FULL_PORTRAIT 4 → STATIC_CARD 1). Rung degrades downward at runtime if
  measured FPS < target for 5s; every downgrade is an event-log entry.

## Cognition

- MCP server (`freestream/mcp_server.py`): stdio JSON-RPC by default,
  HTTP when `FREESTREAM_MCP_HTTP=host:port`. Tools: `session.observe`,
  `session.speak`, `session.listen`, `session.leave`. The agent is the
  participant; FREESTREAM owns presence and persona only.