fix: expand switch cases
Some checks failed
Deploy Admin Frontend / build-and-deploy (push) Failing after 4s

This commit is contained in:
WangDL 2026-05-22 19:13:22 +08:00
parent 0efc78c656
commit 62b4963bb8

View File

@ -82,14 +82,31 @@ function ChatPage() {
try { try {
await streamChat(prevMessages.map(m => ({ role: m.role, content: m.content })), activeId, (event: StreamEvent) => { await streamChat(prevMessages.map(m => ({ role: m.role, content: m.content })), activeId, (event: StreamEvent) => {
switch (event.event) { switch (event.event) {
case 'meta': completedConvId = event.conversationId; if (event.conversationId && event.conversationId !== activeId) { setActiveId(event.conversationId); loadConversations() } break case 'meta': completedConvId = event.conversationId
case 'tool.started': currentTools.push({ tool: event.tool, preview: event.preview, done: false }); update({ toolCalls: [...currentTools] }) break if (event.conversationId && event.conversationId !== activeId) { setActiveId(event.conversationId); loadConversations() } break
case 'tool.completed': { const i = currentTools.findIndex((t: any) => t.tool === event.tool && !t.done); if (i >= 0) { currentTools[i] = { ...currentTools[i], done: true, duration: event.duration, error: event.error }; update({ toolCalls: [...currentTools] }) } } break case 'tool.started':
case 'approval.request': setWaitingApproval(true); update({ approval: { command: event.command, description: event.description, choices: event.choices, runId: event.runId } }) break currentTools.push({ tool: event.tool, preview: event.preview, done: false });
case 'message.delta': currentContent += event.delta || ''; update({ content: currentContent, streaming: true }) break update({ toolCalls: [...currentTools] })
case 'run.completed': if (event.output) currentContent = event.output; update({ content: currentContent, streaming: false }) break break
case 'done': completedConvId = event.conversationId || completedConvId; update({ streaming: false }) break case 'tool.completed': {
case 'error': update({ content: 'Error: ' + event.error, streaming: false }) break const i = currentTools.findIndex((t: any) => t.tool === event.tool && !t.done); if (i >= 0) { currentTools[i] = { ...currentTools[i], done: true, duration: event.duration, error: event.error }; update({ toolCalls: [...currentTools] })
}
break
case 'approval.request':
setWaitingApproval(true); update({ approval: { command: event.command, description: event.description, choices: event.choices, runId: event.runId } })
break
case 'message.delta':
currentContent += event.delta || ''; update({ content: currentContent, streaming: true })
break
case 'run.completed':
if (event.output) currentContent = event.output; update({ content: currentContent, streaming: false })
break
case 'done':
completedConvId = event.conversationId || completedConvId; update({ streaming: false })
break
case 'error':
update({ content: 'Error: ' + event.error, streaming: false })
break
} }
}, controller.signal) }, controller.signal)
if (completedConvId) loadConversations() if (completedConvId) loadConversations()