Skip to content

Commit 7e56bee

Browse files
committed
tool inp edge case
1 parent b0b814e commit 7e56bee

4 files changed

Lines changed: 68 additions & 8 deletions

File tree

apps/sim/lib/workflows/comparison/normalize.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import type { Edge } from 'reactflow'
77
import { isNonEmptyValue } from '@/lib/workflows/subblocks/visibility'
8+
import { isSyntheticToolSubBlockId } from '@/lib/workflows/tool-input/synthetic-subblocks'
89
import type {
910
BlockState,
1011
Loop,
@@ -410,13 +411,6 @@ export function extractBlockFieldsForComparison(block: BlockState): ExtractedBlo
410411
}
411412
}
412413

413-
/**
414-
* Pattern matching synthetic subBlock IDs created by ToolSubBlockRenderer.
415-
* These IDs follow the format `{subBlockId}-tool-{index}-{paramId}` and are
416-
* mirrors of values already stored in toolConfig.value.tools[N].params.
417-
*/
418-
const SYNTHETIC_TOOL_SUBBLOCK_RE = /-tool-\d+-/
419-
420414
/**
421415
* Filters subBlock IDs to exclude system, trigger runtime, and synthetic tool subBlocks.
422416
*
@@ -429,7 +423,7 @@ export function filterSubBlockIds(subBlockIds: string[]): string[] {
429423
if (TRIGGER_RUNTIME_SUBBLOCK_IDS.includes(id)) return false
430424
if (SYSTEM_SUBBLOCK_IDS.some((sysId) => id === sysId || id.startsWith(`${sysId}_`)))
431425
return false
432-
if (SYNTHETIC_TOOL_SUBBLOCK_RE.test(id)) return false
426+
if (isSyntheticToolSubBlockId(id)) return false
433427
return true
434428
})
435429
.sort()

apps/sim/lib/workflows/search-replace/indexer.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,59 @@ describe('indexWorkflowSearchMatches', () => {
786786
)
787787
})
788788

789+
it('does not double index synthetic tool-input mirror subblocks', () => {
790+
const workflow = createSearchReplaceWorkflowFixture()
791+
workflow.blocks['tool-input-1'] = {
792+
id: 'tool-input-1',
793+
type: 'custom',
794+
name: 'Tool Input Block',
795+
position: { x: 0, y: 0 },
796+
enabled: true,
797+
outputs: {},
798+
subBlocks: {
799+
tools: {
800+
id: 'tools',
801+
type: 'tool-input',
802+
value: [
803+
{
804+
type: 'api',
805+
toolId: 'http_request',
806+
title: 'API',
807+
params: {
808+
url: 'Lmfap',
809+
},
810+
},
811+
],
812+
},
813+
'tools-tool-0-url': {
814+
id: 'tools-tool-0-url',
815+
type: 'short-input',
816+
value: 'Lmfap',
817+
},
818+
},
819+
}
820+
821+
const matches = indexWorkflowSearchMatches({
822+
workflow,
823+
query: 'lmf',
824+
mode: 'text',
825+
blockConfigs: {
826+
...SEARCH_REPLACE_BLOCK_CONFIGS,
827+
custom: {
828+
subBlocks: [{ id: 'tools', title: 'Tools', type: 'tool-input' }],
829+
},
830+
},
831+
}).filter((match) => match.blockId === 'tool-input-1')
832+
833+
expect(matches).toEqual([
834+
expect.objectContaining({
835+
subBlockId: 'tools',
836+
valuePath: [0, 'params', 'url'],
837+
searchText: 'Lmfap',
838+
}),
839+
])
840+
})
841+
789842
it('attaches selector context to selector-backed tool input params', () => {
790843
const workflow = createSearchReplaceWorkflowFixture()
791844
workflow.blocks['tool-input-1'] = {

apps/sim/lib/workflows/search-replace/indexer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
resolveCanonicalMode,
3636
resolveDependencyValue,
3737
} from '@/lib/workflows/subblocks/visibility'
38+
import { isSyntheticToolSubBlockId } from '@/lib/workflows/tool-input/synthetic-subblocks'
3839
import { parseStoredToolInputValue, type StoredTool } from '@/lib/workflows/tool-input/types'
3940
import { getBlock } from '@/blocks/registry'
4041
import type { SubBlockConfig } from '@/blocks/types'
@@ -945,6 +946,7 @@ export function indexWorkflowSearchMatches(
945946
}
946947

947948
for (const [subBlockId, subBlockState] of Object.entries(block.subBlocks ?? {})) {
949+
if (isSyntheticToolSubBlockId(subBlockId)) continue
948950
const subBlockConfig = configsById.get(subBlockId)
949951
if (subBlockConfig?.hidden) continue
950952
if (subBlockConfig && !isSubBlockFeatureEnabled(subBlockConfig)) continue
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const SYNTHETIC_TOOL_SUBBLOCK_RE = /-tool-\d+-/
2+
3+
/**
4+
* Returns true for ToolSubBlockRenderer mirror subblocks.
5+
*
6+
* These IDs follow `{subBlockId}-tool-{index}-{paramId}` and duplicate values
7+
* already stored in the aggregate `tool-input` subblock.
8+
*/
9+
export function isSyntheticToolSubBlockId(subBlockId: string): boolean {
10+
return SYNTHETIC_TOOL_SUBBLOCK_RE.test(subBlockId)
11+
}

0 commit comments

Comments
 (0)