(filePath: string)
| 348 | } |
| 349 | |
| 350 | function validateFileReferenceShape(filePath: string): { isValid: boolean; error?: string } { |
| 351 | const trimmed = filePath.trim() |
| 352 | if ( |
| 353 | trimmed.startsWith('http://') || |
| 354 | trimmed.startsWith('https://') || |
| 355 | isInternalFileUrl(trimmed) |
| 356 | ) { |
| 357 | return { isValid: true } |
| 358 | } |
| 359 | |
| 360 | if (trimmed.startsWith('data:')) { |
| 361 | return { |
| 362 | isValid: false, |
| 363 | error: 'File input must be a URL or uploaded file reference, not inline file content', |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | if (filePath.length > MAX_FILE_REFERENCE_LENGTH) { |
| 368 | return { |
| 369 | isValid: false, |
| 370 | error: 'File reference is too long; provide a file URL or upload the file instead', |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | if (/[\x00-\x08\x0B\x0C\x0E-\x1F]/.test(filePath)) { |
| 375 | return { |
| 376 | isValid: false, |
| 377 | error: |
| 378 | 'File reference contains binary content; provide a file URL or upload the file instead', |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | const newlineCount = filePath.match(/\r\n|\r|\n/g)?.length ?? 0 |
| 383 | if (newlineCount > 2) { |
| 384 | return { |
| 385 | isValid: false, |
| 386 | error: |
| 387 | 'File reference looks like inline file content; provide a file URL or upload the file instead', |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | return { isValid: true } |
| 392 | } |
| 393 | |
| 394 | function parsedOutputTooLargeResponse(results?: unknown[]): NextResponse { |
| 395 | const hasPartialResults = Boolean(results && results.length > 0) |
no test coverage detected