MCPcopy Index your code
hub / github.com/simstudioai/sim / getSubBlocksForToolInput

Function getSubBlocksForToolInput

apps/sim/tools/params.ts:987–1133  ·  view source on GitHub ↗
(
  toolId: string,
  blockType: string,
  currentValues?: Record<string, unknown>,
  canonicalModeOverrides?: CanonicalModeOverrides,
  blockConfigOverride?: Pick<ToolInputBlockConfig, 'subBlocks'>
)

Source from the content-addressed store, hash-verified

985 * visibility from the tool's param definitions.
986 */
987export 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

Callers 2

getToolInputParamConfigsFunction · 0.90
tool-input.tsxFile · 0.90

Calls 13

getToolFunction · 0.90
buildCanonicalIndexFunction · 0.90
isTriggerModeSubBlockFunction · 0.90
isSubBlockHiddenFunction · 0.90
isCanonicalPairFunction · 0.90
resolveCanonicalModeFunction · 0.90
getBlockConfigurationsFunction · 0.85
joinMethod · 0.80
errorMethod · 0.80
warnMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected