( toolId: string, blockType: string, currentValues?: Record<string, unknown>, canonicalModeOverrides?: CanonicalModeOverrides, blockConfigOverride?: Pick<ToolInputBlockConfig, 'subBlocks'> )
| 985 | * visibility from the tool's param definitions. |
| 986 | */ |
| 987 | export function getSubBlocksForToolInput( |
| 988 | toolId: string, |
| 989 | blockType: string, |
| 990 | currentValues?: Record<string, unknown>, |
| 991 | canonicalModeOverrides?: CanonicalModeOverrides, |
| 992 | blockConfigOverride?: Pick<ToolInputBlockConfig, 'subBlocks'> |
| 993 | ): SubBlocksForToolInput | null { |
| 994 | try { |
| 995 | const toolConfig = getTool(toolId) |
| 996 | if (!toolConfig) { |
| 997 | logger.warn(`Tool not found: ${toolId}`) |
| 998 | return null |
| 999 | } |
| 1000 | |
| 1001 | const blockConfigs = getBlockConfigurations() |
| 1002 | const blockConfig = blockConfigOverride ?? blockConfigs[blockType] |
| 1003 | if (!blockConfig?.subBlocks?.length) { |
| 1004 | return null |
| 1005 | } |
| 1006 | |
| 1007 | const allSubBlocks = blockConfig.subBlocks as BlockSubBlockConfig[] |
| 1008 | const canonicalIndex = buildCanonicalIndex(allSubBlocks) |
| 1009 | |
| 1010 | // Build values for condition evaluation |
| 1011 | const values = currentValues || {} |
| 1012 | const valuesWithOperation = { ...values } |
| 1013 | if (valuesWithOperation.operation === undefined) { |
| 1014 | const parts = toolId.split('_') |
| 1015 | valuesWithOperation.operation = |
| 1016 | parts.length >= 3 ? parts.slice(2).join('_') : parts[parts.length - 1] |
| 1017 | } |
| 1018 | |
| 1019 | // Build a map of tool param IDs to their resolved visibility |
| 1020 | const toolParamVisibility: Record<string, ParameterVisibility> = {} |
| 1021 | for (const [paramId, param] of Object.entries(toolConfig.params || {})) { |
| 1022 | toolParamVisibility[paramId] = |
| 1023 | param.visibility ?? (param.required ? 'user-or-llm' : 'user-only') |
| 1024 | } |
| 1025 | |
| 1026 | // Track which canonical groups we've already included (to avoid duplicates) |
| 1027 | const includedCanonicalIds = new Set<string>() |
| 1028 | |
| 1029 | const filtered: BlockSubBlockConfig[] = [] |
| 1030 | |
| 1031 | for (const sb of allSubBlocks) { |
| 1032 | // Skip excluded types |
| 1033 | if (EXCLUDED_SUBBLOCK_TYPES.has(sb.type)) continue |
| 1034 | |
| 1035 | // Skip trigger-mode-only subblocks |
| 1036 | if (isTriggerModeSubBlock(sb)) continue |
| 1037 | |
| 1038 | // Hide tool API key fields when running on hosted Sim or when env var is set |
| 1039 | if (isSubBlockHidden(sb)) continue |
| 1040 | |
| 1041 | // Determine the effective param ID (canonical or subblock id) |
| 1042 | const effectiveParamId = sb.canonicalParamId || sb.id |
| 1043 | |
| 1044 | // Resolve paramVisibility: explicit > inferred from tool params > skip |
no test coverage detected