// Quick WebSocket test for review pipeline const WebSocket = require('ws'); const TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3ODIwNTIwNDYsImlhdCI6MTc3OTQ2MDA0NiwidHlwZSI6ImFjY2VzcyIsInVzZXJfaWQiOiJhZG1pbiJ9.dmNrCJsz576eEvNWlXVNP7BdZDEpijJ73pSrcqmTJdE'; const WS_URL = `ws://127.0.0.1:8080/ws/chat?token=${TOKEN}&session_id=test_review_${Date.now()}`; const ws = new WebSocket(WS_URL); ws.on('open', () => { console.log('Connected to WebSocket'); // Send a message that should trigger IoT action response with parenthetical format ws.send(JSON.stringify({ type: 'message', content: '帮我把客厅灯打开', session_id: null, mode: 'text', timestamp: Date.now() })); console.log('Sent: 帮我把客厅灯打开'); }); ws.on('message', (data) => { try { const msg = JSON.parse(data.toString()); console.log(`\n[${msg.type}]`, JSON.stringify(msg, null, 2).substring(0, 500)); if (msg.type === 'response' || msg.type === 'review') { console.log('✅ Got response/review message!'); } if (msg.type === 'stream_end') { console.log('Stream ended, closing...'); setTimeout(() => ws.close(), 1000); } if (msg.type === 'error') { console.log('❌ Error:', msg.error); ws.close(); } } catch (e) { console.log('Raw:', data.toString().substring(0, 200)); } }); ws.on('close', () => { console.log('Connection closed'); process.exit(0); }); ws.on('error', (err) => { console.error('WebSocket error:', err.message); process.exit(1); }); setTimeout(() => { console.log('Timeout - closing'); ws.close(); process.exit(1); }, 30000);