From a507001aa47d3e08affbe616c4590f5cc2b23bad Mon Sep 17 00:00:00 2001 From: ViperEkura <3081035982@qq.com> Date: Thu, 23 Apr 2026 19:01:32 +0800 Subject: [PATCH] debug --- dashboard/src/api/index.js | 100 +++++- dashboard/src/components/ListItem.vue | 8 +- dashboard/src/components/MessageBubble.vue | 23 +- dashboard/src/views/RoomView.vue | 175 +++++++++-- luxx/api/rooms.py | 63 ++-- luxx/models/__init__.py | 4 +- luxx/models/chat.py | 69 +++-- luxx/models/room.py | 36 ++- luxx/services/participant.py | 58 +++- luxx/services/room.py | 344 ++++++++++++++++++--- luxx/services/room_ws.py | 185 +++++++++-- 11 files changed, 886 insertions(+), 179 deletions(-) diff --git a/dashboard/src/api/index.js b/dashboard/src/api/index.js index 15f3a2e..777660e 100644 --- a/dashboard/src/api/index.js +++ b/dashboard/src/api/index.js @@ -218,6 +218,25 @@ export const roomsAPI = { } // ============ WebSocket ============ + +/** + * Create a WebSocket connection for chat room + * + * Event Types: + * - connected: Connection established + * - room_info: Room details with agents + * - history: Message history + * - agents: Agent list update + * - message: New message + * - typing: Typing indicator + * - stream_start: Streaming response started + * - stream_step: Streaming response chunk + * - stream_end: Streaming response completed + * - stream_error: Streaming error + * - system: System message (join/leave) + * - error: Generic error + * - pong: Heartbeat response + */ export function createRoomWS(roomId, callbacks = {}) { const token = localStorage.getItem('access_token') const wsUrl = `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/ws/chat-room/${roomId}${token ? '?token=' + token : ''}` @@ -233,31 +252,76 @@ export function createRoomWS(roomId, callbacks = {}) { try { const msg = JSON.parse(event.data) const eventName = msg.event + const data = msg.data || {} switch (eventName) { + // Connection events case 'connected': - callbacks.onConnected?.(msg.data) + callbacks.onConnected?.(data) break + + case 'room_info': + callbacks.onRoomInfo?.(data.room) + break + + // History and messages case 'history': - callbacks.onHistory?.(msg.data.messages) - break - case 'agents': - callbacks.onAgentsUpdate?.(msg.data.agents) + callbacks.onHistory?.(data.messages, data.has_more) break + case 'message': - callbacks.onMessage?.(msg.data) + // New message received + callbacks.onMessage?.(data.message) break + + // Agent events + case 'agents': + callbacks.onAgentsUpdate?.(data.agents, data.count) + break + + // Typing indicator case 'typing': - callbacks.onTyping?.(msg.data) + callbacks.onTyping?.({ + sender_id: data.sender_id, + sender_type: data.sender_type, + agent_name: data.agent_name, + is_typing: data.is_typing + }) break + + // Streaming events (new format) + case 'stream_start': + callbacks.onStreamStart?.(data) + break + + case 'stream_step': + callbacks.onStreamStep?.(data) + break + + case 'stream_end': + callbacks.onStreamEnd?.(data) + break + + case 'stream_error': + callbacks.onStreamError?.(data) + break + + // Legacy streaming events (for backward compatibility) case 'process_step': case 'done': case 'error': - callbacks.onStream?.(eventName, msg.data, msg.agent_id, msg.agent_name) + callbacks.onStream?.(eventName, data, data.agent_id, data.agent_name) break + + // System events case 'system': - callbacks.onSystem?.(msg.data) + callbacks.onSystem?.(data) break + + case 'pong': + callbacks.onPong?.() + break + default: console.log('Unknown event:', eventName, msg) } @@ -282,24 +346,34 @@ export function createRoomWS(roomId, callbacks = {}) { ws.send(JSON.stringify({ action, ...data })) } }, - sendMessage: (content, userId = 'user', userName = 'User') => { + + sendMessage: (content, userId = 'user', userName = 'User', options = {}) => { + const payload = { + action: 'send_message', + content, + user_id: userId, + user_name: userName, + ...options // Support: reply_to, mentions + } + const send = () => { if (ws.readyState === WebSocket.OPEN) { - ws.send(JSON.stringify({ action: 'send_message', content, user_id: userId, user_name: userName })) + ws.send(JSON.stringify(payload)) } else if (ws.readyState === WebSocket.CONNECTING) { - // Wait for connection then retry ws.addEventListener('open', () => { - ws.send(JSON.stringify({ action: 'send_message', content, user_id: userId, user_name: userName })) + ws.send(JSON.stringify(payload)) }, { once: true }) } } send() }, + ping: () => { if (ws.readyState === WebSocket.OPEN) { ws.send(JSON.stringify({ action: 'ping' })) } }, + close: () => ws.close() } } diff --git a/dashboard/src/components/ListItem.vue b/dashboard/src/components/ListItem.vue index 9b24061..7b1b86c 100644 --- a/dashboard/src/components/ListItem.vue +++ b/dashboard/src/components/ListItem.vue @@ -17,13 +17,13 @@
- -