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

Function deriveInputFromFormat

apps/sim/executor/utils/start-block.ts:272–318  ·  view source on GitHub ↗
(
  inputFormat: InputFormatField[],
  workflowInput: unknown
)

Source from the content-addressed store, hash-verified

270}
271
272function deriveInputFromFormat(
273 inputFormat: InputFormatField[],
274 workflowInput: unknown
275): DerivedInputResult {
276 const structuredInput: Record<string, unknown> = {}
277
278 if (inputFormat.length === 0) {
279 return {
280 structuredInput,
281 finalInput: getRawInputCandidate(workflowInput),
282 hasStructured: false,
283 }
284 }
285
286 for (const field of inputFormat) {
287 const fieldName = readInputFormatFieldName(field)
288 if (!fieldName) continue
289
290 let fieldValue: unknown
291 const workflowRecord = isRecordLike(workflowInput) ? workflowInput : undefined
292
293 if (workflowRecord) {
294 const inputContainer = workflowRecord.input
295 if (isRecordLike(inputContainer) && Object.hasOwn(inputContainer, fieldName)) {
296 fieldValue = inputContainer[fieldName]
297 } else if (Object.hasOwn(workflowRecord, fieldName)) {
298 fieldValue = workflowRecord[fieldName]
299 }
300 }
301
302 // Use the default value from inputFormat if the field value wasn't provided at runtime
303 if (fieldValue === undefined || fieldValue === null) {
304 fieldValue = field.value
305 }
306
307 structuredInput[fieldName] = coerceValue(field.type, fieldValue)
308 }
309
310 const hasStructured = Object.keys(structuredInput).length > 0
311 const finalInput = hasStructured ? structuredInput : getRawInputCandidate(workflowInput)
312
313 return {
314 structuredInput,
315 finalInput,
316 hasStructured,
317 }
318}
319
320function getRawInputCandidate(workflowInput: unknown): unknown {
321 if (isRecordLike(workflowInput) && Object.hasOwn(workflowInput, 'input')) {

Callers 1

buildStartBlockOutputFunction · 0.85

Calls 4

isRecordLikeFunction · 0.90
getRawInputCandidateFunction · 0.85
readInputFormatFieldNameFunction · 0.85
coerceValueFunction · 0.70

Tested by

no test coverage detected