feat(web): add turn-duration event display

This commit is contained in:
weishu
2026-01-17 15:00:04 +08:00
parent f33d142446
commit 940d7b8233
3 changed files with 27 additions and 0 deletions
+14
View File
@@ -232,6 +232,20 @@ export function normalizeAgentRecord(
meta
}
}
if (data.type === 'system' && data.subtype === 'turn_duration') {
return {
id: messageId,
localId,
createdAt,
role: 'event',
content: {
type: 'turn-duration',
durationMs: asNumber(data.durationMs) ?? 0
},
isSidechain: false,
meta
}
}
return null
}
+12
View File
@@ -7,6 +7,14 @@ export function formatUnixTimestamp(value: number): string {
return date.toLocaleString()
}
function formatDuration(ms: number): string {
const seconds = ms / 1000
if (seconds < 60) return `${seconds.toFixed(1)}s`
const mins = Math.floor(seconds / 60)
const secs = Math.round(seconds % 60)
return `${mins}m ${secs}s`
}
export type EventPresentation = {
icon: string | null
text: string
@@ -46,6 +54,10 @@ export function getEventPresentation(event: AgentEvent): EventPresentation {
if (event.type === 'message') {
return { icon: null, text: typeof event.message === 'string' ? event.message : 'Message' }
}
if (event.type === 'turn-duration') {
const ms = typeof event.durationMs === 'number' ? event.durationMs : 0
return { icon: '⏱️', text: `Turn: ${formatDuration(ms)}` }
}
try {
return { icon: null, text: JSON.stringify(event) }
} catch {
+1
View File
@@ -15,6 +15,7 @@ export type AgentEvent =
| { type: 'limit-reached'; endsAt: number }
| { type: 'ready' }
| { type: 'api-error'; retryAttempt: number; maxRetries: number; error: unknown }
| { type: 'turn-duration'; durationMs: number }
| ({ type: string } & Record<string, unknown>)
export type ToolResultPermission = {