Skip to content

Commit 7f91608

Browse files
author
Theodore Li
committed
Fix greptile comments
1 parent ed468d7 commit 7f91608

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

apps/sim/executor/handlers/agent/agent-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { mcpServers } from '@sim/db/schema'
33
import { createLogger } from '@sim/logger'
44
import { and, eq, inArray, isNull } from 'drizzle-orm'
55
import { createMcpToolId } from '@/lib/mcp/utils'
6+
import { getCustomToolById } from '@/lib/workflows/custom-tools/operations'
67
import { getAllBlocks } from '@/blocks'
78
import type { BlockOutput } from '@/blocks/types'
89
import {
@@ -283,7 +284,6 @@ export class AgentBlockHandler implements BlockHandler {
283284
}
284285

285286
try {
286-
const { getCustomToolById } = await import('@/lib/workflows/custom-tools/operations')
287287
const tool = await getCustomToolById({
288288
toolId: customToolId,
289289
userId: ctx.userId,

apps/sim/lib/workflows/custom-tools/operations.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,36 @@ export async function getCustomToolById(params: {
158158
return legacyTool[0] || null
159159
}
160160

161+
export async function getCustomToolByIdOrTitle(params: {
162+
identifier: string
163+
userId: string
164+
workspaceId?: string
165+
}) {
166+
const { identifier, userId, workspaceId } = params
167+
168+
const conditions = [
169+
or(eq(customTools.id, identifier), eq(customTools.title, identifier)),
170+
]
171+
172+
if (workspaceId) {
173+
const workspaceTool = await db
174+
.select()
175+
.from(customTools)
176+
.where(and(eq(customTools.workspaceId, workspaceId), ...conditions))
177+
.limit(1)
178+
if (workspaceTool[0]) return workspaceTool[0]
179+
}
180+
181+
const legacyTool = await db
182+
.select()
183+
.from(customTools)
184+
.where(
185+
and(isNull(customTools.workspaceId), eq(customTools.userId, userId), ...conditions)
186+
)
187+
.limit(1)
188+
return legacyTool[0] || null
189+
}
190+
161191
export async function deleteCustomTool(params: {
162192
toolId: string
163193
userId: string

apps/sim/tools/index.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const {
2424
mockRateLimiterFns,
2525
mockGetCustomToolById,
2626
mockListCustomTools,
27+
mockGetCustomToolByIdOrTitle,
2728
} = vi.hoisted(() => ({
2829
mockIsHosted: { value: false },
2930
mockEnv: { NEXT_PUBLIC_APP_URL: 'http://localhost:3000' } as Record<string, string | undefined>,
@@ -36,6 +37,7 @@ const {
3637
},
3738
mockGetCustomToolById: vi.fn(),
3839
mockListCustomTools: vi.fn(),
40+
mockGetCustomToolByIdOrTitle: vi.fn(),
3941
}))
4042

4143
// Mock feature flags
@@ -225,6 +227,7 @@ vi.mock('@/hooks/queries/utils/custom-tool-cache', () => {
225227
vi.mock('@/lib/workflows/custom-tools/operations', () => ({
226228
getCustomToolById: mockGetCustomToolById,
227229
listCustomTools: mockListCustomTools,
230+
getCustomToolByIdOrTitle: mockGetCustomToolByIdOrTitle,
228231
}))
229232

230233
vi.mock('@/tools/utils.server', async (importOriginal) => {
@@ -320,7 +323,7 @@ describe('Custom Tools', () => {
320323
})
321324

322325
it('resolves custom tools through the async helper', async () => {
323-
mockGetCustomToolById.mockResolvedValue({
326+
mockGetCustomToolByIdOrTitle.mockResolvedValue({
324327
id: 'remote-tool-123',
325328
title: 'Custom Weather Tool',
326329
schema: {

apps/sim/tools/utils.server.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {
33
secureFetchWithPinnedIP,
44
validateUrlWithDNS,
55
} from '@/lib/core/security/input-validation.server'
6+
import { getCustomToolByIdOrTitle } from '@/lib/workflows/custom-tools/operations'
67
import { isCustomTool } from '@/executor/constants'
7-
import type { CustomToolDefinition } from '@/hooks/queries/custom-tools'
88
import { extractErrorMessage } from '@/tools/error-extractors'
99
import { tools } from '@/tools/registry'
1010
import type { ToolConfig, ToolResponse } from '@/tools/types'
@@ -114,23 +114,18 @@ async function fetchCustomToolFromDB(
114114
return undefined
115115
}
116116

117-
const { getCustomToolById, listCustomTools } = await import(
118-
'@/lib/workflows/custom-tools/operations'
119-
)
120-
121-
// Try to find by ID first, fall back to searching by title
122-
const customTool =
123-
(await getCustomToolById({ toolId: identifier, userId, workspaceId })) ??
124-
(await listCustomTools({ userId, workspaceId })).find(
125-
(t: { title: string }) => t.title === identifier
126-
)
117+
const customTool = await getCustomToolByIdOrTitle({
118+
identifier,
119+
userId,
120+
workspaceId,
121+
})
127122

128123
if (!customTool) {
129124
logger.error(`Custom tool not found: ${identifier}`)
130125
return undefined
131126
}
132127

133-
const toolConfig = createToolConfig(customTool as unknown as CustomToolDefinition, customToolId)
128+
const toolConfig = createToolConfig(customTool, customToolId)
134129

135130
return {
136131
...toolConfig,

apps/sim/tools/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ export function getTool(toolId: string, _workspaceId?: string): ToolConfig | und
295295

296296
// Helper function to create a tool config from a custom tool
297297
export function createToolConfig(
298-
customTool: CustomToolDefinition,
298+
customTool: { title: string; schema: any; code?: string },
299299
customToolId: string
300300
): ToolConfig {
301301
// Create a parameter schema from the custom tool schema

0 commit comments

Comments
 (0)