* Calculate and log hosted key cost for a tool execution. * Logs to usageLog for audit trail and returns cost + metadata for output.
( tool: ToolConfig, params: Record<string, unknown>, response: Record<string, unknown>, executionContext: ExecutionContext | undefined, requestId: string )
| 542 | * Logs to usageLog for audit trail and returns cost + metadata for output. |
| 543 | */ |
| 544 | async function processHostedKeyCost( |
| 545 | tool: ToolConfig, |
| 546 | params: Record<string, unknown>, |
| 547 | response: Record<string, unknown>, |
| 548 | executionContext: ExecutionContext | undefined, |
| 549 | requestId: string |
| 550 | ): Promise<HostedKeyCostResult> { |
| 551 | if (!tool.hosting?.pricing) { |
| 552 | return { cost: 0 } |
| 553 | } |
| 554 | |
| 555 | const { cost, metadata } = calculateToolCost(tool.hosting.pricing, params, response) |
| 556 | |
| 557 | if (cost <= 0) return { cost: 0 } |
| 558 | |
| 559 | const { userId } = resolveToolScope(params, executionContext) |
| 560 | |
| 561 | if (!userId) return { cost, metadata } |
| 562 | |
| 563 | logger.debug( |
| 564 | `[${requestId}] Hosted key cost for ${tool.id}: $${cost}`, |
| 565 | metadata ? { metadata } : {} |
| 566 | ) |
| 567 | |
| 568 | return { cost, metadata } |
| 569 | } |
| 570 | |
| 571 | /** |
| 572 | * Report custom dimension usage after successful hosted-key tool execution. |
no test coverage detected