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

Function reportCustomDimensionUsage

apps/sim/tools/index.ts:576–610  ·  view source on GitHub ↗

* Report custom dimension usage after successful hosted-key tool execution. * Only applies to tools with `custom` rate limit mode. Fires and logs; * failures here do not block the response since execution already succeeded.

(
  tool: ToolConfig,
  params: Record<string, unknown>,
  response: Record<string, unknown>,
  executionContext: ExecutionContext | undefined,
  requestId: string
)

Source from the content-addressed store, hash-verified

574 * failures here do not block the response since execution already succeeded.
575 */
576async function reportCustomDimensionUsage(
577 tool: ToolConfig,
578 params: Record<string, unknown>,
579 response: Record<string, unknown>,
580 executionContext: ExecutionContext | undefined,
581 requestId: string
582): Promise<void> {
583 if (tool.hosting?.rateLimit.mode !== 'custom') return
584 const { workspaceId: billingActorId } = resolveToolScope(params, executionContext)
585 if (!billingActorId) return
586
587 const rateLimiter = getHostedKeyRateLimiter()
588 const provider = tool.hosting.byokProviderId || tool.id
589
590 try {
591 const result = await rateLimiter.reportUsage(
592 provider,
593 billingActorId,
594 tool.hosting.rateLimit,
595 params,
596 response
597 )
598
599 for (const dim of result.dimensions) {
600 if (!dim.allowed) {
601 logger.warn(`[${requestId}] Dimension ${dim.name} overdrawn after ${tool.id} execution`, {
602 consumed: dim.consumed,
603 tokensRemaining: dim.tokensRemaining,
604 })
605 }
606 }
607 } catch (error) {
608 logger.error(`[${requestId}] Failed to report custom dimension usage for ${tool.id}:`, error)
609 }
610}
611
612/**
613 * Strips internal fields (keys starting with `__`) from tool output before

Callers 1

Calls 5

getHostedKeyRateLimiterFunction · 0.90
resolveToolScopeFunction · 0.85
reportUsageMethod · 0.80
errorMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected