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
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
"""Chat REST route — POST /chat fallback when WS is unavailable."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, Request
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from shared.schemas import ChatRequest
|
|
|
|
from app.deep_agent import run_home
|
|
from app.ws_context import clear_current_user, set_current_user
|
|
|
|
router = APIRouter(prefix="/chat", tags=["chat"])
|
|
|
|
|
|
@router.post("")
|
|
async def chat(body: ChatRequest, request: Request) -> JSONResponse:
|
|
"""REST fallback for home chat.
|
|
|
|
In the microservices setup, Traefik ForwardAuth has already validated
|
|
the JWT and injected X-User-Id / X-User-Email / X-User-Tier headers.
|
|
"""
|
|
user_id = request.headers.get("X-User-Id", "")
|
|
if not user_id:
|
|
return JSONResponse(status_code=401, content={"detail": "Missing X-User-Id header"})
|
|
|
|
set_current_user(user_id)
|
|
try:
|
|
response = await run_home(
|
|
user_id=user_id,
|
|
message=body.message,
|
|
context=body.context.model_dump(),
|
|
)
|
|
finally:
|
|
clear_current_user()
|
|
|
|
return JSONResponse(content={"response": response})
|