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

Function extractInputFieldsFromBlocks

apps/sim/lib/workflows/input-format.ts:147–204  ·  view source on GitHub ↗
(
  blocks: Record<string, unknown> | null | undefined
)

Source from the content-addressed store, hash-verified

145 * @returns Array of input field definitions
146 */
147export function extractInputFieldsFromBlocks(
148 blocks: Record<string, unknown> | null | undefined
149): WorkflowInputField[] {
150 if (!blocks) return []
151
152 // Find trigger block
153 const triggerEntry = Object.entries(blocks).find(([, block]) => {
154 const b = block as Record<string, unknown>
155 return typeof b.type === 'string' && isInputDefinitionTrigger(b.type)
156 })
157
158 if (!triggerEntry) return []
159
160 const triggerBlock = triggerEntry[1] as Record<string, unknown>
161 const subBlocks = triggerBlock.subBlocks as Record<string, { value?: unknown }> | undefined
162 const inputFormat = subBlocks?.inputFormat?.value
163
164 // Try primary location: subBlocks.inputFormat.value
165 if (Array.isArray(inputFormat)) {
166 return inputFormat
167 .filter(
168 (field: unknown): field is { name: string; type?: string; description?: string } =>
169 typeof field === 'object' &&
170 field !== null &&
171 'name' in field &&
172 typeof (field as { name: unknown }).name === 'string' &&
173 (field as { name: string }).name.trim() !== ''
174 )
175 .map((field) => ({
176 name: field.name,
177 type: field.type || 'string',
178 ...(field.description && { description: field.description }),
179 }))
180 }
181
182 // Try legacy location: config.params.inputFormat
183 const config = triggerBlock.config as { params?: { inputFormat?: unknown } } | undefined
184 const legacyFormat = config?.params?.inputFormat
185
186 if (Array.isArray(legacyFormat)) {
187 return legacyFormat
188 .filter(
189 (field: unknown): field is { name: string; type?: string; description?: string } =>
190 typeof field === 'object' &&
191 field !== null &&
192 'name' in field &&
193 typeof (field as { name: unknown }).name === 'string' &&
194 (field as { name: string }).name.trim() !== ''
195 )
196 .map((field) => ({
197 name: field.name,
198 type: field.type || 'string',
199 ...(field.description && { description: field.description }),
200 }))
201 }
202
203 return []
204}

Callers 6

fetchWorkflowInputFieldsFunction · 0.90
WorkflowInputMapperInputFunction · 0.90
InputMappingFunction · 0.90
route.tsFile · 0.90

Calls 1

isInputDefinitionTriggerFunction · 0.90

Tested by

no test coverage detected