mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
feat: add compact_boundary event support in web UI
https://github.com/tiann/hapi/issues/108#issuecomment-3799439152
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user