feat: add compact_boundary event support in web UI

https://github.com/tiann/hapi/issues/108#issuecomment-3799439152
This commit is contained in:
weishu
2026-01-27 10:04:01 +08:00
parent b63089f3f9
commit 7a8f1c3e87
3 changed files with 20 additions and 0 deletions
+16
View File
@@ -263,6 +263,22 @@ export function normalizeAgentRecord(
meta
}
}
if (data.type === 'system' && data.subtype === 'compact_boundary') {
const metadata = isObject(data.compactMetadata) ? data.compactMetadata : null
return {
id: messageId,
localId,
createdAt,
role: 'event',
content: {
type: 'compact',
trigger: asString(metadata?.trigger) ?? 'auto',
preTokens: asNumber(metadata?.preTokens) ?? 0
},
isSidechain: false,
meta
}
}
return null
}
+3
View File
@@ -63,6 +63,9 @@ export function getEventPresentation(event: AgentEvent): EventPresentation {
const formatted = saved >= 1000 ? `${Math.round(saved / 1000)}K` : String(saved)
return { icon: '📦', text: `Context compacted (saved ${formatted} tokens)` }
}
if (event.type === 'compact') {
return { icon: '📦', text: 'Conversation compacted' }
}
try {
return { icon: null, text: JSON.stringify(event) }
} catch {
+1
View File
@@ -17,6 +17,7 @@ export type AgentEvent =
| { type: 'api-error'; retryAttempt: number; maxRetries: number; error: unknown }
| { type: 'turn-duration'; durationMs: number }
| { type: 'microcompact'; trigger: string; preTokens: number; tokensSaved: number }
| { type: 'compact'; trigger: string; preTokens: number }
| ({ type: string } & Record<string, unknown>)
export type ToolResultPermission = {