WS Gateway:
- WebSocket lifecycle handler with RS256 JWT auth
- Redis bridge: device registry, frame publishing, tool_result routing
- Inbound routing: tool_result→LPUSH, home/floating→chat pub/sub
- Outbound: subscribes to ws:out:{user_id}, forwards to Electron
- Single-worker Dockerfile (long-lived WS connections)
Chat Service:
- Redis consumer: subscribes to chat:request:* pattern
- Redis-based ws_context: tool_call→publish, BRPOP tool_result (30s timeout)
- deep_agent: single-agent runner with home/floating/stream variants
- memory_middleware: core/associative/episodic/proactive memory with Fernet
- Domain agents: task (8 tools), note (5), project (6), timeline (4)
- LLM factory via LiteLLM (100+ providers)
- Output formatter (StreamFormatter)
- POST /chat REST fallback with Traefik header auth
- Multi-worker Dockerfile with 120s timeout for LLM calls
50 lines
1.1 KiB
Python
50 lines
1.1 KiB
Python
"""WS Gateway — stateless WebSocket proxy.
|
|
|
|
Accepts Electron device connections, authenticates JWT (RS256 public key),
|
|
and routes frames between Electron and downstream services via Redis pub/sub.
|
|
|
|
This service has NO business logic — it only routes JSON frames.
|
|
"""
|
|
|
|
from contextlib import asynccontextmanager
|
|
import logging
|
|
|
|
from fastapi import FastAPI
|
|
from shared.config import settings
|
|
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
|
|
)
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
yield
|
|
from shared.redis import redis_client
|
|
|
|
await redis_client.aclose()
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
app = FastAPI(
|
|
title="Adiuva WS Gateway",
|
|
version="0.1.0",
|
|
docs_url="/docs" if settings.ENV == "dev" else None,
|
|
redoc_url=None,
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
from app.handler import router
|
|
|
|
app.include_router(router, prefix="/api/v1")
|
|
|
|
@app.get("/api/v1/health", tags=["health"])
|
|
async def health() -> dict:
|
|
return {"status": "ok", "service": "ws-gateway", "version": app.version}
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|