refactor: fix architectural issues across frontend and backend
Address all architecture review findings: P0 fixes: - Add API key authentication for admin endpoints (analytics, replay, openapi) and WebSocket connections via ADMIN_API_KEY env var - Add PostgreSQL-backed PgSessionManager and PgInterruptManager for multi-worker production deployments (in-memory defaults preserved) P1 fixes: - Implement actual tool generation in OpenAPI approve_job endpoint using generate_tool_code() and generate_agent_yaml() - Add missing clarification, interrupt_expired, and tool_result message handlers in frontend ChatPage P2 fixes: - Replace monkey-patching on CompiledStateGraph with typed GraphContext - Replace 9-param dispatch_message with WebSocketContext dataclass - Extract duplicate _envelope() into shared app/api_utils.py - Replace mutable module-level counter with crypto.randomUUID() - Remove hardcoded mock data from ReviewPage, use api.ts wrappers - Remove `as any` type escape from ReplayPage All 516 tests passing, 0 TypeScript errors.
This commit is contained in:
30
backend/app/ws_context.py
Normal file
30
backend/app/ws_context.py
Normal file
@@ -0,0 +1,30 @@
|
||||
"""WebSocketContext -- bundles all dependencies needed by dispatch_message."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from app.analytics.event_recorder import AnalyticsRecorder
|
||||
from app.callbacks import TokenUsageCallbackHandler
|
||||
from app.conversation_tracker import ConversationTrackerProtocol
|
||||
from app.graph_context import GraphContext
|
||||
from app.interrupt_manager import InterruptManager
|
||||
from app.session_manager import SessionManager
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class WebSocketContext:
|
||||
"""All dependencies required for WebSocket message processing.
|
||||
|
||||
Replaces the previous 9-parameter function signature in dispatch_message.
|
||||
"""
|
||||
|
||||
graph_ctx: GraphContext
|
||||
session_manager: SessionManager
|
||||
callback_handler: TokenUsageCallbackHandler
|
||||
interrupt_manager: InterruptManager | None = None
|
||||
analytics_recorder: AnalyticsRecorder | None = None
|
||||
conversation_tracker: ConversationTrackerProtocol | None = None
|
||||
pool: Any = None
|
||||
Reference in New Issue
Block a user