From 081f7f7b74a748c89ee2a80dca3b63b156e01d8b Mon Sep 17 00:00:00 2001 From: SmartDever02 Date: Fri, 5 Dec 2025 01:32:32 -0300 Subject: [PATCH] refactor: Move WebSocket to SDK pattern with /ws/ prefix - Moved to api/apps/sdk/websocket.py following session.py pattern - Added ws_token_required decorator - WebSocket endpoints: /ws/chats//completions and /ws/agents//completions - Prevents routing conflicts with HTTP endpoints --- api/apps/sdk/websocket.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/apps/sdk/websocket.py b/api/apps/sdk/websocket.py index 5faf11066..1ba4c6b17 100644 --- a/api/apps/sdk/websocket.py +++ b/api/apps/sdk/websocket.py @@ -55,12 +55,13 @@ async def send_ws_message(data, code=0, message=""): await websocket.send(json.dumps(response, ensure_ascii=False)) -@manager.websocket("/chats//completions") # noqa: F821 +@manager.websocket("/ws/chats//completions") # noqa: F821 @ws_token_required async def chat_completions_ws(tenant_id, chat_id): """ WebSocket endpoint for streaming chat completions. Follows the same pattern as the HTTP POST /chats//completions endpoint. + Uses /ws/ prefix to avoid routing conflicts with HTTP endpoints. """ # Verify chat ownership if not DialogService.query(tenant_id=tenant_id, id=chat_id, status=StatusEnum.VALID.value): @@ -141,12 +142,13 @@ async def chat_completions_ws(tenant_id, chat_id): logging.info(f"WebSocket chat connection closed for chat_id: {chat_id}") -@manager.websocket("/agents//completions") # noqa: F821 +@manager.websocket("/ws/agents//completions") # noqa: F821 @ws_token_required async def agent_completions_ws(tenant_id, agent_id): """ WebSocket endpoint for streaming agent completions. Follows the same pattern as the HTTP POST /agents//completions endpoint. + Uses /ws/ prefix to avoid routing conflicts with HTTP endpoints. """ # Verify agent ownership if not UserCanvasService.query(user_id=tenant_id, id=agent_id):