feat: add api-error event support with folding for retry messages

Introduces support for displaying API error system messages in the web UI with
automatic folding of consecutive retry messages to show only the latest state.
This commit is contained in:
weishu
2026-01-05 13:00:25 +08:00
parent b665e34d3c
commit f7d161e6cf
5 changed files with 62 additions and 3 deletions
+13
View File
@@ -13,6 +13,19 @@ export type EventPresentation = {
}
export function getEventPresentation(event: AgentEvent): EventPresentation {
if (event.type === 'api-error') {
const { retryAttempt, maxRetries } = event as { retryAttempt: number; maxRetries: number }
if (maxRetries > 0 && retryAttempt >= maxRetries) {
return { icon: '⚠️', text: 'API error: Max retries reached' }
}
if (maxRetries > 0) {
return { icon: '⏳', text: `API error: Retrying (${retryAttempt}/${maxRetries})` }
}
if (retryAttempt > 0) {
return { icon: '⏳', text: 'API error: Retrying...' }
}
return { icon: '⚠️', text: 'API error' }
}
if (event.type === 'switch') {
const mode = event.mode === 'local' ? 'local' : 'remote'
return { icon: '🔄', text: `Switched to ${mode}` }