11import { createLogger } from '@sim/logger'
22import { DocumentIcon } from '@/components/icons'
33import type { BlockConfig , SubBlockType } from '@/blocks/types'
4+ import { createVersionedToolSelector } from '@/blocks/utils'
45import type { FileParserOutput } from '@/tools/file/types'
56
67const logger = createLogger ( 'FileBlock' )
78
89export const FileBlock : BlockConfig < FileParserOutput > = {
910 type : 'file' ,
10- name : 'File' ,
11+ name : 'File (Legacy) ' ,
1112 description : 'Read and parse multiple files' ,
1213 longDescription : `Integrate File into the workflow. Can upload a file manually or insert a file url.` ,
1314 bestPractices : `
@@ -17,6 +18,7 @@ export const FileBlock: BlockConfig<FileParserOutput> = {
1718 category : 'tools' ,
1819 bgColor : '#40916C' ,
1920 icon : DocumentIcon ,
21+ hideFromToolbar : true ,
2022 subBlocks : [
2123 {
2224 id : 'inputMethod' ,
@@ -123,3 +125,92 @@ export const FileBlock: BlockConfig<FileParserOutput> = {
123125 } ,
124126 } ,
125127}
128+
129+ export const FileV2Block : BlockConfig < FileParserOutput > = {
130+ ...FileBlock ,
131+ type : 'file_v2' ,
132+ name : 'File' ,
133+ description : 'Read and parse multiple files' ,
134+ hideFromToolbar : false ,
135+ subBlocks : [
136+ {
137+ id : 'file' ,
138+ title : 'Files' ,
139+ type : 'file-upload' as SubBlockType ,
140+ canonicalParamId : 'fileInput' ,
141+ acceptedTypes :
142+ '.pdf,.csv,.doc,.docx,.txt,.md,.xlsx,.xls,.html,.htm,.pptx,.ppt,.json,.xml,.rtf' ,
143+ placeholder : 'Upload files to process' ,
144+ multiple : true ,
145+ mode : 'basic' ,
146+ maxSize : 100 ,
147+ } ,
148+ {
149+ id : 'filePath' ,
150+ title : 'Files' ,
151+ type : 'short-input' as SubBlockType ,
152+ canonicalParamId : 'fileInput' ,
153+ placeholder : 'File URL or reference from previous block' ,
154+ mode : 'advanced' ,
155+ } ,
156+ ] ,
157+ tools : {
158+ access : [ 'file_parser_v2' ] ,
159+ config : {
160+ tool : createVersionedToolSelector ( {
161+ baseToolSelector : ( ) => 'file_parser' ,
162+ suffix : '_v2' ,
163+ fallbackToolId : 'file_parser_v2' ,
164+ } ) ,
165+ params : ( params ) => {
166+ const fileInput = params . file || params . filePath || params . fileInput
167+ if ( ! fileInput ) {
168+ logger . error ( 'No file input provided' )
169+ throw new Error ( 'File is required' )
170+ }
171+
172+ if ( typeof fileInput === 'string' ) {
173+ return {
174+ filePath : fileInput . trim ( ) ,
175+ fileType : params . fileType || 'auto' ,
176+ workspaceId : params . _context ?. workspaceId ,
177+ }
178+ }
179+
180+ if ( Array . isArray ( fileInput ) && fileInput . length > 0 ) {
181+ const filePaths = fileInput . map ( ( file ) => file . path )
182+ return {
183+ filePath : filePaths . length === 1 ? filePaths [ 0 ] : filePaths ,
184+ fileType : params . fileType || 'auto' ,
185+ }
186+ }
187+
188+ if ( fileInput ?. path ) {
189+ return {
190+ filePath : fileInput . path ,
191+ fileType : params . fileType || 'auto' ,
192+ }
193+ }
194+
195+ logger . error ( 'Invalid file input format' )
196+ throw new Error ( 'Invalid file input' )
197+ } ,
198+ } ,
199+ } ,
200+ inputs : {
201+ fileInput : { type : 'json' , description : 'File input (upload or URL reference)' } ,
202+ filePath : { type : 'string' , description : 'File URL (advanced mode)' } ,
203+ file : { type : 'json' , description : 'Uploaded file data (basic mode)' } ,
204+ fileType : { type : 'string' , description : 'File type' } ,
205+ } ,
206+ outputs : {
207+ files : {
208+ type : 'json' ,
209+ description : 'Array of parsed file objects with content, metadata, and file properties' ,
210+ } ,
211+ combinedContent : {
212+ type : 'string' ,
213+ description : 'All file contents merged into a single text string' ,
214+ } ,
215+ } ,
216+ }
0 commit comments