* Calculate cost based on pricing model
( pricing: ToolHostingPricing, params: Record<string, unknown>, response: Record<string, unknown> )
| 509 | * Calculate cost based on pricing model |
| 510 | */ |
| 511 | function calculateToolCost( |
| 512 | pricing: ToolHostingPricing, |
| 513 | params: Record<string, unknown>, |
| 514 | response: Record<string, unknown> |
| 515 | ): ToolCostResult { |
| 516 | switch (pricing.type) { |
| 517 | case 'per_request': |
| 518 | return { cost: pricing.cost } |
| 519 | |
| 520 | case 'custom': { |
| 521 | const result = pricing.getCost(params, response) |
| 522 | if (typeof result === 'number') { |
| 523 | return { cost: result } |
| 524 | } |
| 525 | return result |
| 526 | } |
| 527 | |
| 528 | default: { |
| 529 | const exhaustiveCheck: never = pricing |
| 530 | throw new Error(`Unknown pricing type: ${(exhaustiveCheck as ToolHostingPricing).type}`) |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | interface HostedKeyCostResult { |
| 536 | cost: number |
no outgoing calls
no test coverage detected