feat(desktop): handle agent_error events and clearLastRoute in IPC
Forward agent_error as passthrough event to renderer. Add clearLastRoute() calls in hub:sendMessage and localChat:send handlers so channel replies stop when desktop sends a message. Handle agent_error in use-local-chat to show error UI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4a503ecf4c
commit
72598322d1
2 changed files with 15 additions and 5 deletions
|
|
@ -236,6 +236,7 @@ export function registerHubIpcHandlers(): void {
|
|||
if (agent.closed) {
|
||||
return { error: `Agent is closed: ${agentId}` }
|
||||
}
|
||||
h.channelManager.clearLastRoute()
|
||||
agent.write(content)
|
||||
return { ok: true }
|
||||
})
|
||||
|
|
@ -268,11 +269,11 @@ export function registerHubIpcHandlers(): void {
|
|||
return
|
||||
}
|
||||
|
||||
// Compaction events: forward with no stream tracking
|
||||
const isCompactionEvent =
|
||||
event.type === 'compaction_start' || event.type === 'compaction_end'
|
||||
if (isCompactionEvent) {
|
||||
safeLog(`[IPC] Sending compaction event to renderer: ${event.type}`)
|
||||
// Compaction and error events: forward with no stream tracking
|
||||
const isPassthroughEvent =
|
||||
event.type === 'compaction_start' || event.type === 'compaction_end' || event.type === 'agent_error'
|
||||
if (isPassthroughEvent) {
|
||||
safeLog(`[IPC] Sending ${event.type} event to renderer`)
|
||||
mainWindowRef.webContents.send('localChat:event', {
|
||||
agentId,
|
||||
streamId: null,
|
||||
|
|
@ -384,6 +385,7 @@ export function registerHubIpcHandlers(): void {
|
|||
return { error: 'Not subscribed to agent events. Call subscribe first.' }
|
||||
}
|
||||
|
||||
h.channelManager.clearLastRoute()
|
||||
agent.write(content)
|
||||
safeLog(`[IPC] Local chat message sent to agent: ${agentId}`)
|
||||
return { ok: true }
|
||||
|
|
|
|||
|
|
@ -56,6 +56,14 @@ export function useLocalChat() {
|
|||
const payload = data as unknown as StreamPayload
|
||||
if (!payload.event) return
|
||||
|
||||
// Handle agent errors as transient UI feedback (not persisted to history)
|
||||
if (payload.event.type === 'agent_error') {
|
||||
const errorMsg = (payload.event as { error?: string }).error ?? 'Unknown error'
|
||||
chatRef.current.setError({ code: 'AGENT_ERROR', message: errorMsg })
|
||||
setIsLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
chatRef.current.handleStream(payload)
|
||||
if (payload.event.type === 'message_start') setIsLoading(true)
|
||||
if (payload.event.type === 'message_end') setIsLoading(false)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue