@@ -2,7 +2,7 @@ import { createLogger } from '@sim/logger'
22import { DocumentIcon } from '@/components/icons'
33import { inferContextFromKey } from '@/lib/uploads/utils/file-utils'
44import type { BlockConfig , SubBlockType } from '@/blocks/types'
5- import { createVersionedToolSelector } from '@/blocks/utils'
5+ import { createVersionedToolSelector , normalizeFileInput } from '@/blocks/utils'
66import type { FileParserOutput , FileParserV3Output } from '@/tools/file/types'
77
88const logger = createLogger ( 'FileBlock' )
@@ -200,27 +200,25 @@ export const FileV2Block: BlockConfig<FileParserOutput> = {
200200 throw new Error ( 'File is required' )
201201 }
202202
203- if ( typeof fileInput === 'string' ) {
204- return {
205- filePath : fileInput . trim ( ) ,
206- fileType : params . fileType || 'auto' ,
207- workspaceId : params . _context ?. workspaceId ,
208- }
209- }
210-
211- if ( Array . isArray ( fileInput ) && fileInput . length > 0 ) {
212- const filePaths = resolveFilePathsFromInput ( fileInput )
213- return {
214- filePath : filePaths . length === 1 ? filePaths [ 0 ] : filePaths ,
215- fileType : params . fileType || 'auto' ,
203+ // First, try to normalize as file objects (handles JSON strings from advanced mode)
204+ const normalizedFiles = normalizeFileInput ( fileInput )
205+ if ( normalizedFiles ) {
206+ const filePaths = resolveFilePathsFromInput ( normalizedFiles )
207+ if ( filePaths . length > 0 ) {
208+ return {
209+ filePath : filePaths . length === 1 ? filePaths [ 0 ] : filePaths ,
210+ fileType : params . fileType || 'auto' ,
211+ workspaceId : params . _context ?. workspaceId ,
212+ }
216213 }
217214 }
218215
219- const resolvedSingle = resolveFilePathsFromInput ( fileInput )
220- if ( resolvedSingle . length > 0 ) {
216+ // If normalization fails, treat as direct URL string
217+ if ( typeof fileInput === 'string' && fileInput . trim ( ) ) {
221218 return {
222- filePath : resolvedSingle [ 0 ] ,
219+ filePath : fileInput . trim ( ) ,
223220 fileType : params . fileType || 'auto' ,
221+ workspaceId : params . _context ?. workspaceId ,
224222 }
225223 }
226224
@@ -292,39 +290,25 @@ export const FileV3Block: BlockConfig<FileParserV3Output> = {
292290 throw new Error ( 'File input is required' )
293291 }
294292
295- if ( typeof fileInput === 'string' ) {
296- return {
297- filePath : fileInput . trim ( ) ,
298- fileType : params . fileType || 'auto' ,
299- workspaceId : params . _context ?. workspaceId ,
300- workflowId : params . _context ?. workflowId ,
301- executionId : params . _context ?. executionId ,
302- }
303- }
304-
305- if ( Array . isArray ( fileInput ) ) {
306- const filePaths = resolveFilePathsFromInput ( fileInput )
307- if ( filePaths . length === 0 ) {
308- logger . error ( 'No valid file paths found in file input array' )
309- throw new Error ( 'File input is required' )
310- }
311- return {
312- filePath : filePaths . length === 1 ? filePaths [ 0 ] : filePaths ,
313- fileType : params . fileType || 'auto' ,
314- workspaceId : params . _context ?. workspaceId ,
315- workflowId : params . _context ?. workflowId ,
316- executionId : params . _context ?. executionId ,
293+ // First, try to normalize as file objects (handles JSON strings from advanced mode)
294+ const normalizedFiles = normalizeFileInput ( fileInput )
295+ if ( normalizedFiles ) {
296+ const filePaths = resolveFilePathsFromInput ( normalizedFiles )
297+ if ( filePaths . length > 0 ) {
298+ return {
299+ filePath : filePaths . length === 1 ? filePaths [ 0 ] : filePaths ,
300+ fileType : params . fileType || 'auto' ,
301+ workspaceId : params . _context ?. workspaceId ,
302+ workflowId : params . _context ?. workflowId ,
303+ executionId : params . _context ?. executionId ,
304+ }
317305 }
318306 }
319307
320- if ( typeof fileInput === 'object' ) {
321- const resolvedPaths = resolveFilePathsFromInput ( fileInput )
322- if ( resolvedPaths . length === 0 ) {
323- logger . error ( 'File input object missing path, url, or key' )
324- throw new Error ( 'File input is required' )
325- }
308+ // If normalization fails, treat as direct URL string
309+ if ( typeof fileInput === 'string' && fileInput . trim ( ) ) {
326310 return {
327- filePath : resolvedPaths [ 0 ] ,
311+ filePath : fileInput . trim ( ) ,
328312 fileType : params . fileType || 'auto' ,
329313 workspaceId : params . _context ?. workspaceId ,
330314 workflowId : params . _context ?. workflowId ,
0 commit comments