MCPcopy
hub / github.com/simstudioai/sim / calculateToolCost

Function calculateToolCost

apps/sim/tools/index.ts:511–533  ·  view source on GitHub ↗

* Calculate cost based on pricing model

(
  pricing: ToolHostingPricing,
  params: Record<string, unknown>,
  response: Record<string, unknown>
)

Source from the content-addressed store, hash-verified

509 * Calculate cost based on pricing model
510 */
511function 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
535interface HostedKeyCostResult {
536 cost: number

Callers 1

processHostedKeyCostFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected