Skip to content

Commit dc4c611

Browse files
author
Theodore Li
committed
Fix lint
1 parent fbd1cdf commit dc4c611

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
lines changed

apps/sim/tools/index.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ describe('Rate Limiting and Retry Logic', () => {
12301230
vi.resetAllMocks()
12311231
cleanupEnvVars()
12321232
mockIsHosted.value = false
1233-
delete mockEnv.TEST_HOSTED_KEY
1233+
mockEnv.TEST_HOSTED_KEY = undefined
12341234
})
12351235

12361236
it('should retry on 429 rate limit errors with exponential backoff', async () => {
@@ -1428,7 +1428,7 @@ describe('Cost Field Handling', () => {
14281428
vi.resetAllMocks()
14291429
cleanupEnvVars()
14301430
mockIsHosted.value = false
1431-
delete mockEnv.TEST_HOSTED_KEY
1431+
mockEnv.TEST_HOSTED_KEY = undefined
14321432
})
14331433

14341434
it('should add cost to output when using hosted key with per_request pricing', async () => {
@@ -1541,7 +1541,12 @@ describe('Cost Field Handling', () => {
15411541

15421542
const mockContext = createToolExecutionContext()
15431543
// Pass user's own API key
1544-
const result = await executeTool('test_no_hosted_cost', { apiKey: 'user-api-key' }, false, mockContext)
1544+
const result = await executeTool(
1545+
'test_no_hosted_cost',
1546+
{ apiKey: 'user-api-key' },
1547+
false,
1548+
mockContext
1549+
)
15451550

15461551
expect(result.success).toBe(true)
15471552
// Should not have cost since user provided their own key

apps/sim/tools/index.ts

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createLogger } from '@sim/logger'
2-
import { generateInternalToken } from '@/lib/auth/internal'
32
import { getBYOKKey } from '@/lib/api-key/byok'
3+
import { generateInternalToken } from '@/lib/auth/internal'
44
import { logFixedUsage } from '@/lib/billing/core/usage-log'
55
import { env } from '@/lib/core/config/env'
66
import { isHosted } from '@/lib/core/config/feature-flags'
@@ -9,6 +9,7 @@ import {
99
secureFetchWithPinnedIP,
1010
validateUrlWithDNS,
1111
} from '@/lib/core/security/input-validation.server'
12+
import { PlatformEvents } from '@/lib/core/telemetry'
1213
import { generateRequestId } from '@/lib/core/utils/request'
1314
import { getBaseUrl } from '@/lib/core/utils/urls'
1415
import { parseMcpToolId } from '@/lib/mcp/utils'
@@ -30,7 +31,6 @@ import {
3031
getToolAsync,
3132
validateRequiredParametersAfterMerge,
3233
} from '@/tools/utils'
33-
import { PlatformEvents } from '@/lib/core/telemetry'
3434

3535
const logger = createLogger('Tools')
3636

@@ -154,7 +154,7 @@ async function executeWithRetry<T>(
154154
throw error
155155
}
156156

157-
const delayMs = baseDelayMs * Math.pow(2, attempt)
157+
const delayMs = baseDelayMs * 2 ** attempt
158158

159159
// Track throttling event via telemetry
160160
PlatformEvents.hostedKeyThrottled({
@@ -168,7 +168,9 @@ async function executeWithRetry<T>(
168168
workflowId: executionContext?.workflowId,
169169
})
170170

171-
logger.warn(`[${requestId}] Rate limited for ${toolId} (${envVarName}), retrying in ${delayMs}ms (attempt ${attempt + 1}/${maxRetries})`)
171+
logger.warn(
172+
`[${requestId}] Rate limited for ${toolId} (${envVarName}), retrying in ${delayMs}ms (attempt ${attempt + 1}/${maxRetries})`
173+
)
172174
await new Promise((resolve) => setTimeout(resolve, delayMs))
173175
}
174176
}
@@ -246,7 +248,10 @@ async function processHostedKeyCost(
246248
executionId: executionContext.executionId,
247249
metadata,
248250
})
249-
logger.debug(`[${requestId}] Logged hosted key cost for ${tool.id}: $${cost}`, metadata ? { metadata } : {})
251+
logger.debug(
252+
`[${requestId}] Logged hosted key cost for ${tool.id}: $${cost}`,
253+
metadata ? { metadata } : {}
254+
)
250255
} catch (error) {
251256
logger.error(`[${requestId}] Failed to log hosted key usage for ${tool.id}:`, error)
252257
}
@@ -648,7 +653,13 @@ export async function executeTool(
648653

649654
// Calculate hosted key cost and merge into output.cost
650655
if (hostedKeyInfo.isUsingHostedKey && finalResult.success) {
651-
const { cost: hostedKeyCost, metadata } = await processHostedKeyCost(tool, contextParams, finalResult.output, executionContext, requestId)
656+
const { cost: hostedKeyCost, metadata } = await processHostedKeyCost(
657+
tool,
658+
contextParams,
659+
finalResult.output,
660+
executionContext,
661+
requestId
662+
)
652663
if (hostedKeyCost > 0) {
653664
finalResult.output = {
654665
...finalResult.output,
@@ -677,15 +688,12 @@ export async function executeTool(
677688
// Execute the tool request directly (internal routes use regular fetch, external use SSRF-protected fetch)
678689
// Wrap with retry logic for hosted keys to handle rate limiting due to higher usage
679690
const result = hostedKeyInfo.isUsingHostedKey
680-
? await executeWithRetry(
681-
() => executeToolRequest(toolId, tool, contextParams),
682-
{
683-
requestId,
684-
toolId,
685-
envVarName: hostedKeyInfo.envVarName!,
686-
executionContext,
687-
}
688-
)
691+
? await executeWithRetry(() => executeToolRequest(toolId, tool, contextParams), {
692+
requestId,
693+
toolId,
694+
envVarName: hostedKeyInfo.envVarName!,
695+
executionContext,
696+
})
689697
: await executeToolRequest(toolId, tool, contextParams)
690698

691699
// Apply post-processing if available and not skipped
@@ -711,7 +719,13 @@ export async function executeTool(
711719

712720
// Calculate hosted key cost and merge into output.cost
713721
if (hostedKeyInfo.isUsingHostedKey && finalResult.success) {
714-
const { cost: hostedKeyCost, metadata } = await processHostedKeyCost(tool, contextParams, finalResult.output, executionContext, requestId)
722+
const { cost: hostedKeyCost, metadata } = await processHostedKeyCost(
723+
tool,
724+
contextParams,
725+
finalResult.output,
726+
executionContext,
727+
requestId
728+
)
715729
if (hostedKeyCost > 0) {
716730
finalResult.output = {
717731
...finalResult.output,

apps/sim/tools/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ export interface CustomPricing<P = Record<string, unknown>> {
206206
}
207207

208208
/** Union of all pricing models */
209-
export type ToolHostingPricing<P = Record<string, unknown>> =
210-
| PerRequestPricing
211-
| CustomPricing<P>
209+
export type ToolHostingPricing<P = Record<string, unknown>> = PerRequestPricing | CustomPricing<P>
212210

213211
/**
214212
* Configuration for hosted API key support

0 commit comments

Comments
 (0)