mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-08 07:17:39 +00:00
feat: add microcompact_boundary event handling in web UI
Adds support for Claude Code's microcompact_boundary system message type to display context microcompaction events with token savings information in the chat UI. Shows a package icon with formatted token count (e.g., "Context compacted (saved 32K tokens)"). close #108
This commit is contained in:
@@ -246,6 +246,23 @@ export function normalizeAgentRecord(
|
|||||||
meta
|
meta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (data.type === 'system' && data.subtype === 'microcompact_boundary') {
|
||||||
|
const metadata = isObject(data.microcompactMetadata) ? data.microcompactMetadata : null
|
||||||
|
return {
|
||||||
|
id: messageId,
|
||||||
|
localId,
|
||||||
|
createdAt,
|
||||||
|
role: 'event',
|
||||||
|
content: {
|
||||||
|
type: 'microcompact',
|
||||||
|
trigger: asString(metadata?.trigger) ?? 'auto',
|
||||||
|
preTokens: asNumber(metadata?.preTokens) ?? 0,
|
||||||
|
tokensSaved: asNumber(metadata?.tokensSaved) ?? 0
|
||||||
|
},
|
||||||
|
isSidechain: false,
|
||||||
|
meta
|
||||||
|
}
|
||||||
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,11 @@ export function getEventPresentation(event: AgentEvent): EventPresentation {
|
|||||||
const ms = typeof event.durationMs === 'number' ? event.durationMs : 0
|
const ms = typeof event.durationMs === 'number' ? event.durationMs : 0
|
||||||
return { icon: '⏱️', text: `Turn: ${formatDuration(ms)}` }
|
return { icon: '⏱️', text: `Turn: ${formatDuration(ms)}` }
|
||||||
}
|
}
|
||||||
|
if (event.type === 'microcompact') {
|
||||||
|
const saved = typeof event.tokensSaved === 'number' ? event.tokensSaved : 0
|
||||||
|
const formatted = saved >= 1000 ? `${Math.round(saved / 1000)}K` : String(saved)
|
||||||
|
return { icon: '📦', text: `Context compacted (saved ${formatted} tokens)` }
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return { icon: null, text: JSON.stringify(event) }
|
return { icon: null, text: JSON.stringify(event) }
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export type AgentEvent =
|
|||||||
| { type: 'ready' }
|
| { type: 'ready' }
|
||||||
| { type: 'api-error'; retryAttempt: number; maxRetries: number; error: unknown }
|
| { type: 'api-error'; retryAttempt: number; maxRetries: number; error: unknown }
|
||||||
| { type: 'turn-duration'; durationMs: number }
|
| { type: 'turn-duration'; durationMs: number }
|
||||||
|
| { type: 'microcompact'; trigger: string; preTokens: number; tokensSaved: number }
|
||||||
| ({ type: string } & Record<string, unknown>)
|
| ({ type: string } & Record<string, unknown>)
|
||||||
|
|
||||||
export type ToolResultPermission = {
|
export type ToolResultPermission = {
|
||||||
|
|||||||
Reference in New Issue
Block a user