Files
CyberGril/deploy/voice/wss_bridge.example.py
T
hel-879-workerandmultica-agent 11fd0e2dc2 HEL-879 R5 test package v2 (materials rework per manager's 4-item list; zero execution): (1) dependencies split into two tracks - R5 voice-only chain verified present (LiveKit 7880 plain ws / FunASR / agent venv livekit-agents 1.8.8 / CosyVoice weights, GPU 30520MiB free) vs FULL unified experience honestly listed as 41-item closure truly-missing (mem0ai fixed-source wheel offline-built sha256 698284b6 352586B, greenlet/pillow/truststore cache-reusable, 37 pending download authorization, hatchling resolved; existing .12 product venvs probed have NO mem0 and are system 3.12.3 - 'zero missing' does not hold for the full experience; fastembed models actually 190.4MB+0.05MB, hel895 doc's ~92MB flagged as erratum); (2) trusted HTTPS+WSS rewritten with evidence - retracted 'one self-signed click covers LiveKit WSS 7880' (7880 is plain ws shared by generic worker and 8090 demo, 7881 is not an HTTP endpoint, the 8090 https page itself hands browsers ws:// = mixed content with no proof it ever worked); proposed dedicated 8363 TLS bridge deploy/voice/wss_bridge.example.py (asyncio+ssl stdlib, zero new deps; local smoke TLS1.3 + byte transparency pass, wss-bridge-smoke.log), livekit_url=wss://...:8363, per-device per-port trust steps, ignore-cert switches explicitly banned, iOS/Android behavior marked pending real device; (3) budget per-category - acquire() is an atomic pre-send hold so failures/retries/interrupts/background all count (LLM call count != successful chat lines); LLM+embedding = code-enforced hard gates, ASR/TTS/session-creation honestly listed as ops-only caps (window<=2h, calls<=3, TTS<=200 segments; session-cap listed as engineering follow-up); proposed caps do not self-activate, caps stay 0; (4) engineering params decided by engineering - 8360/8361/8363/8082 and /opt/voice-agent-cybergril + /opt/cybergril-voice-certs all verified conflict-free read-only; D1 rewritten to the real 11 voice IDs with zero-synthesis reference-audio audition plan (8090 panel has NO audition and mutates shared state - v1 claim retracted; generic demo 'rain' is not this user's choice). .12 facts from read-only SSH probes, evidence sheet r5-facts-20261027.md (secrets redacted); web/src and src zero changes; 4x requirements checks pass (origin/main and f92a86f, with/without handoff); handoff appended; zero real LLM/embed/ASR/TTS/mic, zero download/install/deploy/merge, real caps stay 0
Co-authored-by: multica-agent <github@multica.ai>
2026-10-27 06:44:42 +08:00

110 lines
4.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""CyberGril R5 · WSS TLS bridge (PROPOSAL — 拟议材料,未在任何服务器执行).
背景(docs/rework/hel879/unified-review/r5-facts-20261027.md E2/E4):.12 的
LiveKit 7880 是纯 HTTP/WS 且通用 worker/8090 演示都依赖它保持明文,不能改
TLS;HTTPS 页面直连 ws:// 又是混合内容。本脚本在**新端口**终结 TLS 并把字节
流透明转发给本机 7880,使浏览器可用 ``wss://192.168.200.12:<port>`` 接入
LiveKit 信令,零新依赖(asyncio + ssl 标准库),不触碰既有服务。
- 监听(拟议):0.0.0.0:8363,证书 = 与 8361 同一张自签证书
(SAN=IP:192.168.200.12,存 /opt/cybergril-voice-certs/,600)。
- 上游:127.0.0.1:7880(仅回环,不暴露第二明文入口)。
- voice.yaml:livekit_url 改 wss://192.168.200.12:8363;
livekit_internal 保持 http://127.0.0.1:7880。
- 实现为透明 TCP TLS 终结(不解析 WebSocket/HTTP),LiveKit 信令是 7880 上的
HTTP/WebSocket,字节级转发即协议无关;WebRTC 媒体面(UDP/7881)不经本桥,
由 WebRTC 自带 DTLS/SRTP 加密。
- 每设备信任:https://192.168.200.12:8363 手动接受一次证书例外(与 8361 的
例外分端口各自生效)。禁止用 --ignore-certificate-errors 冒充验收。
部署(获批后)示例:
python3 wss_bridge.example.py --listen 0.0.0.0:8363 \
--upstream 127.0.0.1:7880 \
--cert /opt/cybergril-voice-certs/cybergril-voice.pem \
--key /opt/cybergril-voice-certs/cybergril-voice.key
回滚:停本进程即可(独立进程,不影响 LiveKit/通用 worker/8090)。
本地冒烟(零网络出站):见
docs/rework/hel879/unified-review/r5-facts-20261027.md 与
docs/rework/hel879/unified-review/wss-bridge-smoke.log(一次性本地证书 +
dummy 上游回环验证字节穿透与 TLS 握手)。
"""
from __future__ import annotations
import argparse
import asyncio
import ssl
import sys
from typing import Tuple
async def _pipe(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None:
try:
while True:
data = await reader.read(65536)
if not data:
break
writer.write(data)
await writer.drain()
except (ConnectionError, asyncio.CancelledError, ssl.SSLError):
pass
finally:
try:
writer.close()
except Exception:
pass
async def _handle(
downstream: Tuple[asyncio.StreamReader, asyncio.StreamWriter],
upstream_host: str,
upstream_port: int,
) -> None:
down_reader, down_writer = downstream
try:
up_reader, up_writer = await asyncio.open_connection(upstream_host, upstream_port)
except (ConnectionError, OSError):
down_writer.close()
return
await asyncio.gather(
_pipe(down_reader, up_writer),
_pipe(up_reader, down_writer),
return_exceptions=True,
)
async def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description="TLS->plain TCP bridge (CyberGril R5 WSS proposal)")
parser.add_argument("--listen", default="0.0.0.0:8363", help="host:port to terminate TLS on")
parser.add_argument("--upstream", default="127.0.0.1:7880", help="plain upstream host:port")
parser.add_argument("--cert", required=True, help="TLS certificate PEM path")
parser.add_argument("--key", required=True, help="TLS private key path")
args = parser.parse_args(argv)
listen_host, _, listen_port = args.listen.rpartition(":")
up_host, _, up_port = args.upstream.rpartition(":")
if not listen_host or not up_host:
parser.error("listen/upstream must be host:port")
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ctx.load_cert_chain(args.cert, args.key)
async def handler(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None:
await _handle((reader, writer), up_host, int(up_port))
server = await asyncio.start_server(
handler, listen_host or "0.0.0.0", int(listen_port), ssl=ctx
)
addrs = ", ".join(str(s.getsockname()) for s in server.sockets or [])
print(f"wss-bridge(PROPOSAL) tls {addrs} -> {up_host}:{up_port}", file=sys.stderr)
async with server:
await server.serve_forever()
return 0
if __name__ == "__main__":
raise SystemExit(asyncio.run(main()))