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

Function parseLargeUsage

src/parser.ts:278–312  ·  view source on GitHub ↗
(source: string, usageBounds: JsonValueBounds | null)

Source from the content-addressed store, hash-verified

276}
277
278function parseLargeUsage(source: string, usageBounds: JsonValueBounds | null) {
279 const usage: AssistantMessageContent['usage'] = {
280 input_tokens: readJsonNumberField(source, usageBounds, 'input_tokens') ?? 0,
281 output_tokens: readJsonNumberField(source, usageBounds, 'output_tokens') ?? 0,
282 cache_creation_input_tokens: readJsonNumberField(source, usageBounds, 'cache_creation_input_tokens'),
283 cache_read_input_tokens: readJsonNumberField(source, usageBounds, 'cache_read_input_tokens'),
284 }
285
286 if (usageBounds?.kind === 'object') {
287 const cacheCreation = findObjectFieldValue(source, usageBounds.start, usageBounds.end, 'cache_creation')
288 const ephemeral5m = readJsonNumberField(source, cacheCreation, 'ephemeral_5m_input_tokens')
289 const ephemeral1h = readJsonNumberField(source, cacheCreation, 'ephemeral_1h_input_tokens')
290 if (ephemeral5m !== undefined || ephemeral1h !== undefined) {
291 ;(usage as AssistantMessageContent['usage']).cache_creation = {
292 ...(ephemeral5m !== undefined ? { ephemeral_5m_input_tokens: ephemeral5m } : {}),
293 ...(ephemeral1h !== undefined ? { ephemeral_1h_input_tokens: ephemeral1h } : {}),
294 }
295 }
296
297 const serverToolUse = findObjectFieldValue(source, usageBounds.start, usageBounds.end, 'server_tool_use')
298 const webSearch = readJsonNumberField(source, serverToolUse, 'web_search_requests')
299 const webFetch = readJsonNumberField(source, serverToolUse, 'web_fetch_requests')
300 if (webSearch !== undefined || webFetch !== undefined) {
301 ;(usage as AssistantMessageContent['usage']).server_tool_use = {
302 ...(webSearch !== undefined ? { web_search_requests: webSearch } : {}),
303 ...(webFetch !== undefined ? { web_fetch_requests: webFetch } : {}),
304 }
305 }
306
307 const speed = readJsonString(source, findObjectFieldValue(source, usageBounds.start, usageBounds.end, 'speed'))
308 if (speed === 'standard' || speed === 'fast') usage.speed = speed
309 }
310
311 return usage
312}
313
314function extractLargeToolBlocks(source: string, contentBounds: JsonValueBounds | null): ToolUseBlock[] {
315 if (!contentBounds || contentBounds.kind !== 'array') return []

Callers 1

parseLargeJsonlLineFunction · 0.85

Calls 3

readJsonNumberFieldFunction · 0.85
findObjectFieldValueFunction · 0.85
readJsonStringFunction · 0.85

Tested by

no test coverage detected