Skip to content

Commit 7151e81

Browse files
TheodoreSpeaksTheodore Li
andauthored
fix(api-key-reminder) Add reminder on hosted keys that api key isnt needed (#3512)
* Add reminder on hosted keys that api key isnt needed * Fix test case --------- Co-authored-by: Theodore Li <theo@sim.ai>
1 parent 5815d9f commit 7151e81

File tree

5 files changed

+87
-5
lines changed

5 files changed

+87
-5
lines changed

apps/sim/lib/copilot/chat-payload.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createLogger } from '@sim/logger'
22
import { processFileAttachments } from '@/lib/copilot/chat-context'
3+
import { getCopilotToolDescription } from '@/lib/copilot/tool-descriptions'
34
import { isHosted } from '@/lib/core/config/feature-flags'
45
import { createMcpToolId } from '@/lib/mcp/utils'
56
import { getWorkflowById } from '@/lib/workflows/utils'
@@ -55,7 +56,10 @@ export async function buildIntegrationToolSchemas(): Promise<ToolSchema[]> {
5556
const strippedName = stripVersionSuffix(toolId)
5657
integrationTools.push({
5758
name: strippedName,
58-
description: toolConfig.description || toolConfig.name || strippedName,
59+
description: getCopilotToolDescription(toolConfig, {
60+
isHosted,
61+
fallbackName: strippedName,
62+
}),
5963
input_schema: userSchema as unknown as Record<string, unknown>,
6064
defer_loading: true,
6165
...(toolConfig.oauth?.required && {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { getCopilotToolDescription } from '@/lib/copilot/tool-descriptions'
3+
4+
describe('getCopilotToolDescription', () => {
5+
it.concurrent('returns the base description when hosted keys are not active', () => {
6+
expect(
7+
getCopilotToolDescription(
8+
{
9+
name: 'Brandfetch Search',
10+
description: 'Search for brands by company name',
11+
hosting: { apiKeyParam: 'apiKey' } as never,
12+
},
13+
{ isHosted: false }
14+
)
15+
).toBe('Search for brands by company name')
16+
})
17+
18+
it.concurrent('appends the hosted API key note when the tool supports hosting', () => {
19+
expect(
20+
getCopilotToolDescription(
21+
{
22+
name: 'Brandfetch Search',
23+
description: 'Search for brands by company name',
24+
hosting: { apiKeyParam: 'apiKey' } as never,
25+
},
26+
{ isHosted: true }
27+
)
28+
).toBe('Search for brands by company name <note>API key is hosted by Sim.</note>')
29+
})
30+
31+
it.concurrent('uses the fallback name when no description exists', () => {
32+
expect(
33+
getCopilotToolDescription(
34+
{
35+
name: '',
36+
description: '',
37+
hosting: { apiKeyParam: 'apiKey' } as never,
38+
},
39+
{ isHosted: true, fallbackName: 'brandfetch_search' }
40+
)
41+
).toBe('brandfetch_search <note>API key is hosted by Sim.</note>')
42+
})
43+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { ToolConfig } from '@/tools/types'
2+
3+
const HOSTED_API_KEY_NOTE = '<note>API key is hosted by Sim.</note>'
4+
5+
export function getCopilotToolDescription(
6+
tool: Pick<ToolConfig, 'description' | 'hosting' | 'name'>,
7+
options?: {
8+
isHosted?: boolean
9+
fallbackName?: string
10+
}
11+
): string {
12+
const baseDescription = tool.description || tool.name || options?.fallbackName || ''
13+
14+
if (!options?.isHosted || !tool.hosting) {
15+
return baseDescription
16+
}
17+
18+
if (baseDescription.includes(HOSTED_API_KEY_NOTE)) {
19+
return baseDescription
20+
}
21+
22+
return baseDescription
23+
? `${baseDescription} ${HOSTED_API_KEY_NOTE}`
24+
: HOSTED_API_KEY_NOTE
25+
}

apps/sim/lib/copilot/tools/server/blocks/get-blocks-metadata-tool.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { existsSync, readFileSync } from 'fs'
22
import { join } from 'path'
33
import { createLogger } from '@sim/logger'
4+
import { getCopilotToolDescription } from '@/lib/copilot/tool-descriptions'
45
import type { BaseServerTool } from '@/lib/copilot/tools/server/base-tool'
56
import { GetBlocksMetadataInput, GetBlocksMetadataResult } from '@/lib/copilot/tools/shared/schemas'
6-
import { getAllowedIntegrationsFromEnv } from '@/lib/core/config/feature-flags'
7+
import { getAllowedIntegrationsFromEnv, isHosted } from '@/lib/core/config/feature-flags'
78
import { registry as blockRegistry } from '@/blocks/registry'
89
import { AuthMode, type BlockConfig, isHiddenFromDisplay } from '@/blocks/types'
910
import { getUserPermissionConfig } from '@/ee/access-control/utils/permission-check'
@@ -161,7 +162,10 @@ export const getBlocksMetadataServerTool: BaseServerTool<
161162
return {
162163
id: toolId,
163164
name: tool.name || toolId,
164-
description: tool.description || '',
165+
description: getCopilotToolDescription(tool, {
166+
isHosted,
167+
fallbackName: toolId,
168+
}),
165169
inputs: tool.params || {},
166170
outputs: tool.outputs || {},
167171
}
@@ -246,7 +250,12 @@ export const getBlocksMetadataServerTool: BaseServerTool<
246250
operations[opId] = {
247251
toolId: resolvedToolId,
248252
toolName: toolCfg?.name || resolvedToolId,
249-
description: toolCfg?.description || undefined,
253+
description: toolCfg
254+
? getCopilotToolDescription(toolCfg, {
255+
isHosted,
256+
fallbackName: resolvedToolId,
257+
})
258+
: undefined,
250259
inputs: { ...filteredToolParams, ...(operationInputs[opId] || {}) },
251260
outputs: toolOutputs,
252261
inputSchema: operationParameters[opId] || [],

apps/sim/lib/copilot/vfs/serializers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { isHosted } from '@/lib/core/config/feature-flags'
2+
import { getCopilotToolDescription } from '@/lib/copilot/tool-descriptions'
23
import { isSubBlockHiddenByHostedKey } from '@/lib/workflows/subblocks/visibility'
34
import type { BlockConfig, SubBlockConfig } from '@/blocks/types'
45
import { PROVIDER_DEFINITIONS } from '@/providers/models'
@@ -721,7 +722,7 @@ export function serializeIntegrationSchema(tool: ToolConfig): string {
721722
{
722723
id: tool.id,
723724
name: tool.name,
724-
description: tool.description,
725+
description: getCopilotToolDescription(tool, { isHosted }),
725726
version: tool.version,
726727
oauth: tool.oauth
727728
? { required: tool.oauth.required, provider: tool.oauth.provider }

0 commit comments

Comments
 (0)