(value: unknown)
| 50 | } |
| 51 | |
| 52 | const 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 | |
| 77 | interface ToolBodyParams extends Partial<FileParserInput> { |
| 78 | files?: FileUploadInput[] |
no test coverage detected