MCPcopy Create free account
hub / github.com/getagentseal/codeburn / parseLargeUsageBuffer

Function parseLargeUsageBuffer

src/parser.ts:623–657  ·  view source on GitHub ↗
(source: Buffer, usageBounds: BufferJsonValueBounds | null)

Source from the content-addressed store, hash-verified

621}
622
623function parseLargeUsageBuffer(source: Buffer, usageBounds: BufferJsonValueBounds | null) {
624 const usage: AssistantMessageContent['usage'] = {
625 input_tokens: readJsonNumberFieldBuffer(source, usageBounds, 'input_tokens') ?? 0,
626 output_tokens: readJsonNumberFieldBuffer(source, usageBounds, 'output_tokens') ?? 0,
627 cache_creation_input_tokens: readJsonNumberFieldBuffer(source, usageBounds, 'cache_creation_input_tokens'),
628 cache_read_input_tokens: readJsonNumberFieldBuffer(source, usageBounds, 'cache_read_input_tokens'),
629 }
630
631 if (usageBounds?.kind === 'object') {
632 const cacheCreation = findObjectFieldValueBuffer(source, usageBounds.start, usageBounds.end, 'cache_creation')
633 const ephemeral5m = readJsonNumberFieldBuffer(source, cacheCreation, 'ephemeral_5m_input_tokens')
634 const ephemeral1h = readJsonNumberFieldBuffer(source, cacheCreation, 'ephemeral_1h_input_tokens')
635 if (ephemeral5m !== undefined || ephemeral1h !== undefined) {
636 ;(usage as AssistantMessageContent['usage']).cache_creation = {
637 ...(ephemeral5m !== undefined ? { ephemeral_5m_input_tokens: ephemeral5m } : {}),
638 ...(ephemeral1h !== undefined ? { ephemeral_1h_input_tokens: ephemeral1h } : {}),
639 }
640 }
641
642 const serverToolUse = findObjectFieldValueBuffer(source, usageBounds.start, usageBounds.end, 'server_tool_use')
643 const webSearch = readJsonNumberFieldBuffer(source, serverToolUse, 'web_search_requests')
644 const webFetch = readJsonNumberFieldBuffer(source, serverToolUse, 'web_fetch_requests')
645 if (webSearch !== undefined || webFetch !== undefined) {
646 ;(usage as AssistantMessageContent['usage']).server_tool_use = {
647 ...(webSearch !== undefined ? { web_search_requests: webSearch } : {}),
648 ...(webFetch !== undefined ? { web_fetch_requests: webFetch } : {}),
649 }
650 }
651
652 const speed = readJsonStringBuffer(source, findObjectFieldValueBuffer(source, usageBounds.start, usageBounds.end, 'speed'))
653 if (speed === 'standard' || speed === 'fast') usage.speed = speed
654 }
655
656 return usage
657}
658
659function extractLargeToolBlocksBuffer(source: Buffer, contentBounds: BufferJsonValueBounds | null): ToolUseBlock[] {
660 if (!contentBounds || contentBounds.kind !== 'array') return []

Callers 1

parseLargeJsonlBufferFunction · 0.85

Calls 3

readJsonStringBufferFunction · 0.85

Tested by

no test coverage detected