( cost: number, usage: Usage, model: string, )
| 288 | } |
| 289 | |
| 290 | export function addToTotalSessionCost( |
| 291 | cost: number, |
| 292 | usage: Usage, |
| 293 | model: string, |
| 294 | ): number { |
| 295 | const modelUsage = addToTotalModelUsage(cost, usage, model) |
| 296 | addToTotalCostState(cost, modelUsage, model) |
| 297 | |
| 298 | const attrs = |
| 299 | isFastModeEnabled() && usage.speed === 'fast' |
| 300 | ? { model, speed: 'fast' } |
| 301 | : { model } |
| 302 | |
| 303 | getCostCounter()?.add(cost, attrs) |
| 304 | getTokenCounter()?.add(usage.input_tokens, { ...attrs, type: 'input' }) |
| 305 | getTokenCounter()?.add(usage.output_tokens, { ...attrs, type: 'output' }) |
| 306 | getTokenCounter()?.add(usage.cache_read_input_tokens ?? 0, { |
| 307 | ...attrs, |
| 308 | type: 'cacheRead', |
| 309 | }) |
| 310 | getTokenCounter()?.add(usage.cache_creation_input_tokens ?? 0, { |
| 311 | ...attrs, |
| 312 | type: 'cacheCreation', |
| 313 | }) |
| 314 | |
| 315 | let totalCost = cost |
| 316 | for (const advisorUsage of getAdvisorUsage(usage)) { |
| 317 | const advisorCost = calculateUSDCost(advisorUsage.model, advisorUsage) |
| 318 | logEvent('tengu_advisor_tool_token_usage', { |
| 319 | advisor_model: |
| 320 | advisorUsage.model as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 321 | input_tokens: advisorUsage.input_tokens, |
| 322 | output_tokens: advisorUsage.output_tokens, |
| 323 | cache_read_input_tokens: advisorUsage.cache_read_input_tokens ?? 0, |
| 324 | cache_creation_input_tokens: |
| 325 | advisorUsage.cache_creation_input_tokens ?? 0, |
| 326 | cost_usd_micros: Math.round(advisorCost * 1_000_000), |
| 327 | }) |
| 328 | totalCost += addToTotalSessionCost( |
| 329 | advisorCost, |
| 330 | advisorUsage, |
| 331 | advisorUsage.model, |
| 332 | ) |
| 333 | } |
| 334 | return totalCost |
| 335 | } |
| 336 |
no test coverage detected