Skip to content

Commit 57bf024

Browse files
committed
fix(tools): resolve the key reference with the registry's own resolver
1 parent b8aff28 commit 57bf024

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

‎apps/sim/lib/tool-execution/application/execute-tool.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,10 @@ describe('executeToolForCaller', () => {
530530
'the caller references a variable holding their own key',
531531
{ input: { url: 'https://a.co', apiKey: '{{FIRECRAWL_KEY}}' } },
532532
],
533+
[
534+
'the reference pads the variable name',
535+
{ input: { url: 'https://a.co', apiKey: '{{ FIRECRAWL_KEY }}' } },
536+
],
533537
[
534538
'the tool has no hosted key',
535539
{ toolId: 'zendesk_get_ticket', input: { ticketId: '4', subdomain: 'a', apiToken: 't' } },

‎apps/sim/lib/tool-execution/application/execute-tool.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import { OrchestrationError } from '@/lib/core/orchestration/types'
2020
import { getEffectiveDecryptedEnv } from '@/lib/environment/utils'
2121
import { principalUserId } from '@/lib/integrations/principal-scope.server'
2222
import { toolExecutionOperations } from '@/lib/tool-execution/application/operations'
23-
import { extractEnvVarName, isEnvVarReference } from '@/executor/constants'
23+
import { isEnvVarReference } from '@/executor/constants'
24+
import { resolveEnvVarReferences } from '@/executor/utils/reference-validation'
2425
import { executeTool as executeRegistryTool } from '@/tools'
2526
import type { ExecutableToolConfig } from '@/tools/types'
2627
import { getTool } from '@/tools/utils'
@@ -82,18 +83,23 @@ function hostedKeyParamFor(
8283
/**
8384
* Whether a `{{VAR}}` key resolves to a key of the caller's own.
8485
*
85-
* The registry resolves the reference from this same environment before it
86-
* decides on Sim's key, and a variable that is missing or empty leaves the
87-
* parameter for Sim's key to fill.
86+
* Resolved exactly as the registry resolves it — same environment, same
87+
* options — before it decides on Sim's key. A variable that is missing or
88+
* empty leaves the parameter for Sim's key to fill.
8889
*/
8990
async function referencesOwnKey(
9091
value: unknown,
9192
userId: string,
9293
workspaceId: string
9394
): Promise<boolean> {
9495
if (typeof value !== 'string' || !isEnvVarReference(value)) return false
95-
const env = await getEffectiveDecryptedEnv(userId, workspaceId)
96-
return Boolean(env[extractEnvVarName(value)]?.trim())
96+
const missingKeys: string[] = []
97+
const resolved = resolveEnvVarReferences(
98+
value,
99+
await getEffectiveDecryptedEnv(userId, workspaceId),
100+
{ allowEmbedded: false, missingKeys }
101+
)
102+
return missingKeys.length === 0 && typeof resolved === 'string' && resolved.trim().length > 0
97103
}
98104

99105
/**

0 commit comments

Comments
 (0)