Skip to content

Commit 61342e2

Browse files
fix(notion): correctly register tool (#4337)
1 parent ed7786d commit 61342e2

6 files changed

Lines changed: 79 additions & 6 deletions

File tree

apps/sim/tools/index.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,38 @@ vi.mock('@/tools/registry', () => {
267267
params: {},
268268
request: { url: '/api/tools/serper/search', method: 'GET' },
269269
},
270+
notion_add_database_row: {
271+
id: 'notion_add_database_row',
272+
name: 'Add Notion Database Row',
273+
description: 'Add a new row to a Notion database with specified properties',
274+
version: '1.0.0',
275+
params: {},
276+
request: { url: 'https://api.notion.com/v1/pages', method: 'POST' },
277+
},
278+
notion_add_database_row_v2: {
279+
id: 'notion_add_database_row_v2',
280+
name: 'Add Notion Database Row',
281+
description: 'Add a new row to a Notion database with specified properties',
282+
version: '2.0.0',
283+
params: {},
284+
request: { url: 'https://api.notion.com/v1/pages', method: 'POST' },
285+
},
286+
notion_update_page: {
287+
id: 'notion_update_page',
288+
name: 'Notion Page Updater',
289+
description: 'Update properties of a Notion page',
290+
version: '1.0.0',
291+
params: {},
292+
request: { url: 'https://api.notion.com/v1/pages/x', method: 'PATCH' },
293+
},
294+
notion_update_page_v2: {
295+
id: 'notion_update_page_v2',
296+
name: 'Notion Page Updater',
297+
description: 'Update properties of a Notion page',
298+
version: '2.0.0',
299+
params: {},
300+
request: { url: 'https://api.notion.com/v1/pages/x', method: 'PATCH' },
301+
},
270302
}
271303
return { tools: mockTools }
272304
})
@@ -388,6 +420,19 @@ describe('Tools Registry', () => {
388420
expect(gmailTool?.name).toBe('Gmail Read')
389421
})
390422

423+
it.each([
424+
['notion_add_database_row', 'notion_add_database_row_v2'],
425+
['notion_update_page', 'notion_update_page_v2'],
426+
])('getTool resolves both the legacy and v2 ids for %s', (legacyId, v2Id) => {
427+
const legacy = getTool(legacyId)
428+
expect(legacy).toBeDefined()
429+
expect(legacy?.id).toBe(legacyId)
430+
431+
const v2 = getTool(v2Id)
432+
expect(v2).toBeDefined()
433+
expect(v2?.id).toBe(v2Id)
434+
})
435+
391436
it('getTool should return undefined for non-existent tool', () => {
392437
const nonExistentTool = getTool('non_existent_tool')
393438
expect(nonExistentTool).toBeUndefined()
@@ -399,6 +444,12 @@ describe('Custom Tools', () => {
399444
expect(getTool('custom_remote-tool-123', 'workspace-1')).toBeUndefined()
400445
})
401446

447+
it('returns the legacy notion_add_database_row tool through the async helper', async () => {
448+
const legacy = await getToolAsync('notion_add_database_row')
449+
expect(legacy).toBeDefined()
450+
expect(legacy?.id).toBe('notion_add_database_row')
451+
})
452+
402453
it('resolves custom tools through the async helper', async () => {
403454
mockGetCustomToolByIdOrTitle.mockResolvedValue({
404455
id: 'remote-tool-123',

apps/sim/tools/notion/add_database_row.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const notionAddDatabaseRowTool: ToolConfig<
1717
NotionAddDatabaseRowParams,
1818
NotionAddDatabaseRowResponse
1919
> = {
20-
id: 'notion_add_database_row_v2',
20+
id: 'notion_add_database_row',
2121
name: 'Add Notion Database Row',
2222
description: 'Add a new row to a Notion database with specified properties',
2323
version: '1.0.0',
@@ -107,3 +107,12 @@ export const notionAddDatabaseRowTool: ToolConfig<
107107
last_edited_time: PAGE_OUTPUT_PROPERTIES.last_edited_time,
108108
},
109109
}
110+
111+
export const notionAddDatabaseRowV2Tool: ToolConfig<
112+
NotionAddDatabaseRowParams,
113+
NotionAddDatabaseRowResponse
114+
> = {
115+
...notionAddDatabaseRowTool,
116+
id: 'notion_add_database_row_v2',
117+
version: '2.0.0',
118+
}

apps/sim/tools/notion/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { notionAddDatabaseRowTool } from '@/tools/notion/add_database_row'
1+
import {
2+
notionAddDatabaseRowTool,
3+
notionAddDatabaseRowV2Tool,
4+
} from '@/tools/notion/add_database_row'
25
import {
36
notionCreateDatabaseTool,
47
notionCreateDatabaseV2Tool,
@@ -52,4 +55,5 @@ export {
5255
notionSearchV2Tool,
5356
notionCreateDatabaseV2Tool,
5457
notionAddDatabaseRowTool,
58+
notionAddDatabaseRowV2Tool,
5559
}

apps/sim/tools/registry.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,7 @@ import {
17881788
} from '@/tools/neo4j'
17891789
import {
17901790
notionAddDatabaseRowTool,
1791+
notionAddDatabaseRowV2Tool,
17911792
notionCreateDatabaseTool,
17921793
notionCreateDatabaseV2Tool,
17931794
notionCreatePageTool,
@@ -1800,6 +1801,7 @@ import {
18001801
notionReadV2Tool,
18011802
notionSearchTool,
18021803
notionSearchV2Tool,
1804+
notionUpdatePageTool,
18031805
notionUpdatePageV2Tool,
18041806
notionWriteTool,
18051807
notionWriteV2Tool,
@@ -3527,6 +3529,8 @@ export const tools: Record<string, ToolConfig> = {
35273529
notion_query_database: notionQueryDatabaseTool,
35283530
notion_search: notionSearchTool,
35293531
notion_create_database: notionCreateDatabaseTool,
3532+
notion_add_database_row: notionAddDatabaseRowTool,
3533+
notion_update_page: notionUpdatePageTool,
35303534
// Notion V2 tools
35313535
notion_read_v2: notionReadV2Tool,
35323536
notion_read_database_v2: notionReadDatabaseV2Tool,
@@ -3536,7 +3540,7 @@ export const tools: Record<string, ToolConfig> = {
35363540
notion_search_v2: notionSearchV2Tool,
35373541
notion_create_database_v2: notionCreateDatabaseV2Tool,
35383542
notion_update_page_v2: notionUpdatePageV2Tool,
3539-
notion_add_database_row_v2: notionAddDatabaseRowTool,
3543+
notion_add_database_row_v2: notionAddDatabaseRowV2Tool,
35403544
obsidian_append_active: obsidianAppendActiveTool,
35413545
obsidian_append_note: obsidianAppendNoteTool,
35423546
obsidian_append_periodic_note: obsidianAppendPeriodicNoteTool,

apps/sim/tools/utils.server.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ import { extractErrorMessage } from '@/tools/error-extractors'
1010
import { tools } from '@/tools/registry'
1111
import type { ToolConfig, ToolResponse } from '@/tools/types'
1212
import type { RequestParams } from '@/tools/utils'
13-
import { createCustomToolRequestBody, createParamSchema, createToolConfig } from '@/tools/utils'
13+
import {
14+
createCustomToolRequestBody,
15+
createParamSchema,
16+
createToolConfig,
17+
resolveToolId,
18+
} from '@/tools/utils'
1419

1520
const logger = createLogger('ToolsUtils')
1621

@@ -92,7 +97,7 @@ export async function getToolAsync(
9297
toolId: string,
9398
context: GetToolAsyncContext = {}
9499
): Promise<ToolConfig | undefined> {
95-
const builtInTool = tools[toolId]
100+
const builtInTool = tools[resolveToolId(toolId)]
96101
if (builtInTool) return builtInTool
97102

98103
if (isCustomTool(toolId)) {

apps/sim/tools/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export function createCustomToolRequestBody(customTool: any, isClient = true, wo
282282
// Get a tool by its ID
283283
export function getTool(toolId: string, _workspaceId?: string): ToolConfig | undefined {
284284
// Check for built-in tools
285-
const builtInTool = tools[toolId]
285+
const builtInTool = tools[resolveToolId(toolId)]
286286
if (builtInTool) return builtInTool
287287

288288
// If not found or running on the server, return undefined

0 commit comments

Comments
 (0)