Skip to content

Commit 4b6414f

Browse files
committed
reuse versioned tool selector
1 parent 52b2349 commit 4b6414f

File tree

3 files changed

+18
-37
lines changed

3 files changed

+18
-37
lines changed

apps/sim/blocks/blocks/github.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { GithubIcon } from '@/components/icons'
22
import type { BlockConfig } from '@/blocks/types'
33
import { AuthMode } from '@/blocks/types'
4+
import { createVersionedToolSelector } from '@/blocks/utils'
45
import type { GitHubResponse } from '@/tools/github/types'
56
import { getTrigger } from '@/triggers'
67

@@ -1347,10 +1348,11 @@ export const GitHubV2Block: BlockConfig<GitHubResponse> = {
13471348
access: (GitHubBlock.tools?.access || []).map((toolId) => `${toolId}_v2`),
13481349
config: {
13491350
...GitHubBlock.tools?.config,
1350-
tool: (params) => {
1351-
const baseToolId = (GitHubBlock.tools?.config as any)?.tool(params)
1352-
return `${baseToolId}_v2`
1353-
},
1351+
tool: createVersionedToolSelector({
1352+
baseToolSelector: (params) => (GitHubBlock.tools?.config as any)?.tool(params),
1353+
suffix: '_v2',
1354+
fallbackToolId: 'github_create_issue_v2',
1355+
}),
13541356
params: (GitHubBlock.tools?.config as any)?.params,
13551357
},
13561358
},

apps/sim/blocks/blocks/google_calendar.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { GoogleCalendarIcon } from '@/components/icons'
22
import type { BlockConfig } from '@/blocks/types'
33
import { AuthMode } from '@/blocks/types'
4+
import { createVersionedToolSelector } from '@/blocks/utils'
45
import type { GoogleCalendarResponse } from '@/tools/google_calendar/types'
56

67
export const GoogleCalendarBlock: BlockConfig<GoogleCalendarResponse> = {
@@ -403,19 +404,11 @@ export const GoogleCalendarV2Block: BlockConfig<GoogleCalendarResponse> = {
403404
],
404405
config: {
405406
...GoogleCalendarBlock.tools?.config,
406-
tool: (params) => {
407-
const operation = params.operation || 'create'
408-
if (
409-
operation !== 'create' &&
410-
operation !== 'list' &&
411-
operation !== 'get' &&
412-
operation !== 'quick_add' &&
413-
operation !== 'invite'
414-
) {
415-
throw new Error(`Invalid Google Calendar operation: ${operation}`)
416-
}
417-
return `google_calendar_${operation}_v2`
418-
},
407+
tool: createVersionedToolSelector({
408+
baseToolSelector: (params) => `google_calendar_${params.operation || 'create'}`,
409+
suffix: '_v2',
410+
fallbackToolId: 'google_calendar_create_v2',
411+
}),
419412
params: GoogleCalendarBlock.tools?.config?.params,
420413
},
421414
},

apps/sim/blocks/blocks/notion.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { NotionIcon } from '@/components/icons'
22
import type { BlockConfig } from '@/blocks/types'
33
import { AuthMode } from '@/blocks/types'
4+
import { createVersionedToolSelector } from '@/blocks/utils'
45
import type { NotionResponse } from '@/tools/notion/types'
56

67
// Legacy block - hidden from toolbar
@@ -385,26 +386,11 @@ export const NotionV2Block: BlockConfig<any> = {
385386
'notion_create_database_v2',
386387
],
387388
config: {
388-
tool: (params) => {
389-
switch (params.operation) {
390-
case 'notion_read':
391-
return 'notion_read_v2'
392-
case 'notion_read_database':
393-
return 'notion_read_database_v2'
394-
case 'notion_write':
395-
return 'notion_write_v2'
396-
case 'notion_create_page':
397-
return 'notion_create_page_v2'
398-
case 'notion_query_database':
399-
return 'notion_query_database_v2'
400-
case 'notion_search':
401-
return 'notion_search_v2'
402-
case 'notion_create_database':
403-
return 'notion_create_database_v2'
404-
default:
405-
return 'notion_read_v2'
406-
}
407-
},
389+
tool: createVersionedToolSelector({
390+
baseToolSelector: (params) => params.operation || 'notion_read',
391+
suffix: '_v2',
392+
fallbackToolId: 'notion_read_v2',
393+
}),
408394
params: NotionBlock.tools?.config?.params,
409395
},
410396
},

0 commit comments

Comments
 (0)