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

Function normalizeStartFile

apps/sim/executor/utils/start-block.ts:327–375  ·  view source on GitHub ↗
(file: unknown)

Source from the content-addressed store, hash-verified

325}
326
327function normalizeStartFile(file: unknown): UserFile | null {
328 if (!isRecordLike(file)) {
329 return null
330 }
331
332 const id = typeof file.id === 'string' ? file.id : ''
333 const name = typeof file.name === 'string' ? file.name : ''
334 const url =
335 typeof file.url === 'string' ? file.url : typeof file.path === 'string' ? file.path : ''
336 const size = typeof file.size === 'number' ? file.size : Number.NaN
337 const type = typeof file.type === 'string' ? file.type : ''
338 const explicitKey = typeof file.key === 'string' ? file.key : ''
339
340 let key = explicitKey
341 let context = typeof file.context === 'string' ? file.context : undefined
342
343 if (!key && url && isInternalFileUrl(url)) {
344 try {
345 const parsed = parseInternalFileUrl(url)
346 key = parsed.key
347 context = context || parsed.context
348 } catch {
349 return null
350 }
351 }
352
353 if (!context && key) {
354 try {
355 context = inferContextFromKey(key)
356 } catch {
357 // Older file outputs may have opaque keys; keep the file shape intact.
358 }
359 }
360
361 if (!id || !name || !url || !Number.isFinite(size) || !type || !key) {
362 return null
363 }
364
365 return {
366 id,
367 name,
368 url,
369 size,
370 type,
371 key,
372 ...(context && { context }),
373 ...(typeof file.base64 === 'string' && { base64: file.base64 }),
374 }
375}
376
377function getFilesFromWorkflowInput(workflowInput: unknown): UserFile[] | undefined {
378 if (!isRecordLike(workflowInput)) {

Callers

nothing calls this directly

Calls 4

isRecordLikeFunction · 0.90
isInternalFileUrlFunction · 0.90
parseInternalFileUrlFunction · 0.90
inferContextFromKeyFunction · 0.90

Tested by

no test coverage detected