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

Function normalizeFileParseResult

apps/sim/tools/file/parser.ts:52–75  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

50}
51
52const normalizeFileParseResult = (value: unknown): FileParseResult => {
53 if (isRecord(value) && isFileParseResult(value.output)) {
54 return value.output
55 }
56
57 if (isFileParseResult(value)) {
58 return value
59 }
60
61 const record = isRecord(value) ? value : {}
62 const file = isUserFile(record.file) ? record.file : undefined
63 const metadata = isRecord(record.metadata) ? record.metadata : undefined
64 const fallback: FileParseResult = {
65 content: typeof record.content === 'string' ? record.content : '',
66 fileType: typeof record.fileType === 'string' ? record.fileType : '',
67 size: typeof record.size === 'number' ? record.size : 0,
68 name: typeof record.name === 'string' ? record.name : 'unknown',
69 binary: typeof record.binary === 'boolean' ? record.binary : false,
70 ...(metadata && { metadata }),
71 ...(file && { file }),
72 }
73
74 return Object.assign({}, record, fallback)
75}
76
77interface ToolBodyParams extends Partial<FileParserInput> {
78 files?: FileUploadInput[]

Callers 1

parseFileParserResponseFunction · 0.85

Calls 3

isFileParseResultFunction · 0.85
isRecordFunction · 0.70
isUserFileFunction · 0.70

Tested by

no test coverage detected