const TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3ODIwNTI0MjksImlhdCI6MTc3OTQ2MDQyOSwidHlwZSI6ImFjY2VzcyIsInVzZXJfaWQiOiJhZG1pbiJ9.JK1dP61eqnHCxfkQrCYQf-mQKPLjDM0o3k2UHkcovZ0"; const WS_URL = `ws://127.0.0.1:8080/ws/chat?token=${TOKEN}&session_id=test_iot_${Date.now()}`; const ws = new WebSocket(WS_URL); let hasAction = false; ws.onopen = () => { console.log('Connected'); ws.send(JSON.stringify({ type: 'message', content: '帮我把卧室灯打开', session_id: null, mode: 'text', timestamp: Date.now() })); console.log('Sent: 帮我把卧室灯打开'); }; ws.onmessage = (event) => { try { const msg = JSON.parse(event.data); if (msg.type === 'response' && msg.msg_type === 'action') { console.log('✅ ACTION MESSAGE:', msg.content); hasAction = true; } else if (msg.type === 'response') { console.log('💬 CHAT MESSAGE:', msg.content, 'msg_type:', msg.msg_type); } else if (msg.type === 'stream_chunk') { process.stdout.write(msg.content || ''); } else if (msg.type === 'stream_end') { console.log('\n--- stream_end ---'); setTimeout(() => ws.close(), 500); } else if (msg.type === 'error') { console.log('Error:', msg.error); } } catch {} }; ws.onclose = () => { console.log('hasAction:', hasAction); process.exit(hasAction ? 0 : 0); }; ws.onerror = (err) => { console.error('WS error:', err.message); process.exit(1); }; setTimeout(() => { console.log('Timeout'); ws.close(); process.exit(1); }, 35000);