mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-29 06:13:46 +00:00
fix: normalize cache token usage semantics (#1390)
Normalize usage input at parse time, mark inclusive producers, rebuild derived usage indexes, and preserve valid primary usage when cache partitions are malformed. Fixes #1389
This commit is contained in:
@@ -32,6 +32,27 @@ describe('convertCodexEvent', () => {
|
||||
expect(result?.userMessage).toBe('hello user');
|
||||
});
|
||||
|
||||
it('marks native token counts as inclusive of cached input', () => {
|
||||
const info = {
|
||||
total_token_usage: {
|
||||
input_tokens: 120,
|
||||
cached_input_tokens: 20,
|
||||
output_tokens: 12
|
||||
}
|
||||
};
|
||||
const result = convertCodexEvent({
|
||||
type: 'event_msg',
|
||||
payload: { type: 'token_count', info }
|
||||
});
|
||||
|
||||
expect(result?.messages?.[0]).toMatchObject({
|
||||
type: 'token_count',
|
||||
usageSchema: 'hapi.usage.v1',
|
||||
inputTokenSemantics: 'includes-cache',
|
||||
info
|
||||
});
|
||||
});
|
||||
|
||||
it('converts completed plan items into proposed plan messages', () => {
|
||||
const result = convertCodexEvent({
|
||||
type: 'event_msg',
|
||||
|
||||
Reference in New Issue
Block a user