feat(gateway): add WebSocket gateway with JSON-RPC protocol and auth

Phase 2 of the Flynn roadmap. Adds a WebSocket gateway server that
starts alongside the Telegram bot, providing real-time API access to
the agent, sessions, and tools.

Protocol: JSON-RPC-like (request/response/event) over WebSocket.
8 methods: agent.send, agent.cancel, sessions.list, sessions.history,
sessions.create, tools.list, tools.invoke, system.health.

Auth: Bearer token + Tailscale identity header support.
Session bridge: per-connection agent instances with shared model router.

New files: src/gateway/ (protocol, router, server, auth, session-bridge,
handlers for agent/sessions/tools/system).
57 new tests (181 total), typecheck clean.
This commit is contained in:
William Valentin
2026-02-05 19:11:25 -08:00
parent ad7fc241f1
commit f30a8bc318
21 changed files with 1878 additions and 2 deletions
+13
View File
@@ -41,6 +41,9 @@ importers:
react:
specifier: ^19.0.0
version: 19.2.4
ws:
specifier: ^8.19.0
version: 8.19.0
yaml:
specifier: ^2.7.0
version: 2.8.2
@@ -60,6 +63,9 @@ importers:
'@types/react':
specifier: ^19.0.0
version: 19.2.11
'@types/ws':
specifier: ^8.18.1
version: 8.18.1
eslint:
specifier: ^9.0.0
version: 9.39.2
@@ -477,6 +483,9 @@ packages:
'@types/react@19.2.11':
resolution: {integrity: sha512-tORuanb01iEzWvMGVGv2ZDhYZVeRMrw453DCSAIn/5yvcSVnMoUMTyf33nQJLahYEnv9xqrTNbgz4qY5EfSh0g==}
'@types/ws@8.18.1':
resolution: {integrity: sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==}
'@vitest/expect@3.2.4':
resolution: {integrity: sha512-Io0yyORnB6sikFlt8QW5K7slY4OjqNX9jmJQ02QDda8lyM6B5oNgVWoSoKPac8/kgnCUzuHQKrSLtu/uOqqrig==}
@@ -1867,6 +1876,10 @@ snapshots:
dependencies:
csstype: 3.2.3
'@types/ws@8.18.1':
dependencies:
'@types/node': 22.19.7
'@vitest/expect@3.2.4':
dependencies:
'@types/chai': 5.2.3