@@ -14,12 +14,11 @@ import {
1414} from '@/components/emcn'
1515import { cn } from '@/lib/core/utils/cn'
1616import {
17- getEffectiveBlockOutputPaths ,
1817 getEffectiveBlockOutputType ,
1918 getOutputPathsFromSchema ,
2019} from '@/lib/workflows/blocks/block-outputs'
20+ import { getBlockReferenceTags } from '@/lib/workflows/blocks/block-reference-tags'
2121import { hasTriggerCapability } from '@/lib/workflows/triggers/trigger-utils'
22- import { TRIGGER_TYPES } from '@/lib/workflows/triggers/triggers'
2322import { KeyboardNavigationHandler } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tag-dropdown/components/keyboard-navigation-handler'
2423import type {
2524 BlockTagGroup ,
@@ -177,17 +176,6 @@ const ensureRootTag = (tags: string[], rootTag: string): string[] => {
177176 return [ rootTag , ...tags ]
178177}
179178
180- /**
181- * Gets a subblock value from the store.
182- *
183- * @param blockId - The block identifier
184- * @param property - The property name to retrieve
185- * @returns The value from the subblock store
186- */
187- const getSubBlockValue = ( blockId : string , property : string ) : any => {
188- return useSubBlockStore . getState ( ) . getValue ( blockId , property )
189- }
190-
191179/**
192180 * Gets the output type for a specific path in a block's outputs.
193181 *
@@ -1055,53 +1043,19 @@ export const TagDropdown: React.FC<TagDropdownProps> = ({
10551043 return { tags : [ ] , variableInfoMap : emptyVariableInfoMap , blockTagGroups : [ ] }
10561044 }
10571045
1058- const blockName = sourceBlock . name || sourceBlock . type
1059- const normalizedBlockName = normalizeName ( blockName )
1060-
10611046 const mergedSubBlocks = getMergedSubBlocks ( activeSourceBlockId )
1062- let blockTags : string [ ]
1063-
1064- if ( sourceBlock . type === 'variables' ) {
1065- const variablesValue = getSubBlockValue ( activeSourceBlockId , 'variables' )
1066-
1067- if ( variablesValue && Array . isArray ( variablesValue ) && variablesValue . length > 0 ) {
1068- const validAssignments = variablesValue . filter ( ( assignment : { variableName ?: string } ) =>
1069- assignment ?. variableName ?. trim ( )
1070- )
1071- blockTags = validAssignments . map (
1072- ( assignment : { variableName : string } ) =>
1073- `${ normalizedBlockName } .${ assignment . variableName . trim ( ) } `
1074- )
1075- } else {
1076- blockTags = [ normalizedBlockName ]
1077- }
1078- } else {
1079- const sourceBlockConfig = getBlock ( sourceBlock . type )
1080- const isTriggerCapable = sourceBlockConfig ? hasTriggerCapability ( sourceBlockConfig ) : false
1081- const effectiveTriggerMode = Boolean ( sourceBlock . triggerMode && isTriggerCapable )
1082- const outputPaths = getEffectiveBlockOutputPaths ( sourceBlock . type , mergedSubBlocks , {
1083- triggerMode : effectiveTriggerMode ,
1084- preferToolOutputs : ! effectiveTriggerMode ,
1085- } )
1086- const allTags = outputPaths . map ( ( path ) => `${ normalizedBlockName } .${ path } ` )
1087-
1088- if ( sourceBlock . type === 'human_in_the_loop' && activeSourceBlockId === blockId ) {
1089- blockTags = allTags . filter (
1090- ( tag ) => tag . endsWith ( '.url' ) || tag . endsWith ( '.resumeEndpoint' )
1091- )
1092- } else if ( allTags . length === 0 ) {
1093- blockTags = [ normalizedBlockName ]
1094- } else {
1095- blockTags = allTags
1096- }
1097- }
1098-
1099- blockTags = ensureRootTag ( blockTags , normalizedBlockName )
1100- const shouldShowRootTag =
1101- sourceBlock . type === TRIGGER_TYPES . GENERIC_WEBHOOK || sourceBlock . type === 'start_trigger'
1102- if ( ! shouldShowRootTag ) {
1103- blockTags = blockTags . filter ( ( tag ) => tag !== normalizedBlockName )
1104- }
1047+ const blockName = sourceBlock . name || sourceBlock . type
1048+ const blockTags = getBlockReferenceTags ( {
1049+ block : {
1050+ id : activeSourceBlockId ,
1051+ type : sourceBlock . type ,
1052+ name : sourceBlock . name ,
1053+ triggerMode : sourceBlock . triggerMode ,
1054+ subBlocks : mergedSubBlocks ,
1055+ } ,
1056+ currentBlockId : blockId ,
1057+ subBlocks : mergedSubBlocks ,
1058+ } )
11051059
11061060 const blockTagGroups : BlockTagGroup [ ] = [
11071061 {
@@ -1331,57 +1285,19 @@ export const TagDropdown: React.FC<TagDropdownProps> = ({
13311285 continue
13321286 }
13331287
1334- const blockName = accessibleBlock . name || accessibleBlock . type
1335- const normalizedBlockName = normalizeName ( blockName )
1336-
13371288 const mergedSubBlocks = getMergedSubBlocks ( accessibleBlockId )
1338-
1339- let blockTags : string [ ]
1340-
1341- if ( accessibleBlock . type === 'variables' ) {
1342- const variablesValue = getSubBlockValue ( accessibleBlockId , 'variables' )
1343-
1344- if ( variablesValue && Array . isArray ( variablesValue ) && variablesValue . length > 0 ) {
1345- const validAssignments = variablesValue . filter ( ( assignment : { variableName ?: string } ) =>
1346- assignment ?. variableName ?. trim ( )
1347- )
1348- blockTags = validAssignments . map (
1349- ( assignment : { variableName : string } ) =>
1350- `${ normalizedBlockName } .${ assignment . variableName . trim ( ) } `
1351- )
1352- } else {
1353- blockTags = [ normalizedBlockName ]
1354- }
1355- } else {
1356- const accessibleBlockConfig = getBlock ( accessibleBlock . type )
1357- const isTriggerCapable = accessibleBlockConfig
1358- ? hasTriggerCapability ( accessibleBlockConfig )
1359- : false
1360- const effectiveTriggerMode = Boolean ( accessibleBlock . triggerMode && isTriggerCapable )
1361- const outputPaths = getEffectiveBlockOutputPaths ( accessibleBlock . type , mergedSubBlocks , {
1362- triggerMode : effectiveTriggerMode ,
1363- preferToolOutputs : ! effectiveTriggerMode ,
1364- } )
1365- const allTags = outputPaths . map ( ( path ) => `${ normalizedBlockName } .${ path } ` )
1366-
1367- if ( accessibleBlock . type === 'human_in_the_loop' && accessibleBlockId === blockId ) {
1368- blockTags = allTags . filter (
1369- ( tag ) => tag . endsWith ( '.url' ) || tag . endsWith ( '.resumeEndpoint' )
1370- )
1371- } else if ( allTags . length === 0 ) {
1372- blockTags = [ normalizedBlockName ]
1373- } else {
1374- blockTags = allTags
1375- }
1376- }
1377-
1378- blockTags = ensureRootTag ( blockTags , normalizedBlockName )
1379- const shouldShowRootTag =
1380- accessibleBlock . type === TRIGGER_TYPES . GENERIC_WEBHOOK ||
1381- accessibleBlock . type === 'start_trigger'
1382- if ( ! shouldShowRootTag ) {
1383- blockTags = blockTags . filter ( ( tag ) => tag !== normalizedBlockName )
1384- }
1289+ const blockName = accessibleBlock . name || accessibleBlock . type
1290+ const blockTags = getBlockReferenceTags ( {
1291+ block : {
1292+ id : accessibleBlockId ,
1293+ type : accessibleBlock . type ,
1294+ name : accessibleBlock . name ,
1295+ triggerMode : accessibleBlock . triggerMode ,
1296+ subBlocks : mergedSubBlocks ,
1297+ } ,
1298+ currentBlockId : blockId ,
1299+ subBlocks : mergedSubBlocks ,
1300+ } )
13851301
13861302 blockTagGroups . push ( {
13871303 blockName,
0 commit comments