(source: string, usageBounds: JsonValueBounds | null)
| 276 | } |
| 277 | |
| 278 | function 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 | |
| 314 | function extractLargeToolBlocks(source: string, contentBounds: JsonValueBounds | null): ToolUseBlock[] { |
| 315 | if (!contentBounds || contentBounds.kind !== 'array') return [] |
no test coverage detected