MCPcopy
hub / github.com/simstudioai/sim / parseFile

Function parseFile

apps/sim/lib/file-parsers/index.ts:135–164  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

133 * @returns Parsed content and metadata
134 */
135export async function parseFile(filePath: string): Promise<FileParseResult> {
136 try {
137 if (!filePath) {
138 throw new Error('No file path provided')
139 }
140
141 if (!existsSync(filePath)) {
142 throw new Error(`File not found: ${filePath}`)
143 }
144
145 const extension = path.extname(filePath).toLowerCase().substring(1)
146 logger.info('Attempting to parse file with extension:', extension)
147
148 const parsers = getParserInstances()
149
150 if (!Object.keys(parsers).includes(extension)) {
151 logger.info('No parser found for extension:', extension)
152 throw new Error(
153 `Unsupported file type: ${extension}. Supported types are: ${Object.keys(parsers).join(', ')}`
154 )
155 }
156
157 logger.info('Using parser for extension:', extension)
158 const parser = parsers[extension]
159 return await parser.parseFile(filePath)
160 } catch (error) {
161 logger.error('File parsing error:', error)
162 throw error
163 }
164}
165
166/**
167 * Parse a buffer based on file extension

Callers 2

index.test.tsFile · 0.90
handleLocalFileFunction · 0.90

Calls 5

getParserInstancesFunction · 0.85
infoMethod · 0.80
joinMethod · 0.80
errorMethod · 0.80
parseFileMethod · 0.65

Tested by

no test coverage detected