From 9b7043e87e2290921726d0e997117747913c5f6f Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Sat, 28 Mar 2026 00:17:01 +0800 Subject: [PATCH] fix(web): display steer messages in chat immediately and persist to DB Steer messages (sent during agent execution) were not showing in the chat. Two issues: 1. Frontend: steer messages were added to pendingMessages (amber chips) instead of messages (chat history). They relied on a message_start event echo from the brain to move from chip to chat, but pi-agent may not emit this event. Fix: add steer messages directly to the messages array, same as normal sends. 2. Gateway: chat.steer RPC didn't save the user message to the database. On page refresh, steer messages were lost. Fix: appendMessage to DB before forwarding to agentbox. --- src/gateway/rpc-methods.ts | 11 +++++++++++ src/gateway/web/src/hooks/usePilot.ts | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/gateway/rpc-methods.ts b/src/gateway/rpc-methods.ts index 807308a6..4acf6264 100644 --- a/src/gateway/rpc-methods.ts +++ b/src/gateway/rpc-methods.ts @@ -2244,6 +2244,17 @@ export function createRpcMethods( } } + // Save steer message to DB (like chat.send saves the initial user message) + if (chatRepo) { + const effectiveSessionId = sessionId ?? stream.sessionId; + await chatRepo.appendMessage({ + sessionId: effectiveSessionId, + role: "user", + content: text, + }); + await chatRepo.incrementMessageCount(effectiveSessionId); + } + const client = new AgentBoxClient(stream.endpoint, 30000, agentBoxTlsOptions); await client.steerSession(stream.sessionId, text); return { status: "steered" }; diff --git a/src/gateway/web/src/hooks/usePilot.ts b/src/gateway/web/src/hooks/usePilot.ts index 423c7b3f..310941da 100644 --- a/src/gateway/web/src/hooks/usePilot.ts +++ b/src/gateway/web/src/hooks/usePilot.ts @@ -789,7 +789,13 @@ export function usePilot() { if (isLoading) { try { await sendRpc('chat.steer', { text, sessionId: currentSessionKeyRef.current }); - setPendingMessages(prev => [...prev, text]); + // Show steer message in chat immediately (same as normal send) + setMessages(prev => [...prev, { + id: `user-${Date.now()}`, + role: 'user' as const, + content: text, + timestamp: new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }), + }]); } catch (err) { console.error('Failed to steer:', err); }