mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
feat(web): add turn-duration event display
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user