@@ -143,12 +143,16 @@ export const MistralParseBlock: BlockConfig<MistralParserOutput> = {
143143 } ,
144144}
145145
146+ /**
147+ * V2 Block - Restored from main branch for backwards compatibility
148+ * Hidden from toolbar, uses filePath subblock ID for advanced mode
149+ */
146150export const MistralParseV2Block : BlockConfig < MistralParserOutput > = {
147151 ...MistralParseBlock ,
148152 type : 'mistral_parse_v2' ,
149153 name : 'Mistral Parser' ,
150154 description : 'Extract text from PDF documents' ,
151- hideFromToolbar : false ,
155+ hideFromToolbar : true ,
152156 subBlocks : [
153157 {
154158 id : 'fileUpload' ,
@@ -159,16 +163,14 @@ export const MistralParseV2Block: BlockConfig<MistralParserOutput> = {
159163 placeholder : 'Upload a PDF document' ,
160164 mode : 'basic' ,
161165 maxSize : 50 ,
162- required : true ,
163166 } ,
164167 {
165- id : 'fileReference ' ,
166- title : 'File Reference ' ,
168+ id : 'filePath ' ,
169+ title : 'PDF Document ' ,
167170 type : 'short-input' as SubBlockType ,
168171 canonicalParamId : 'document' ,
169- placeholder : 'File reference from previous block ' ,
172+ placeholder : 'Document URL ' ,
170173 mode : 'advanced' ,
171- required : true ,
172174 } ,
173175 {
174176 id : 'resultType' ,
@@ -213,6 +215,137 @@ export const MistralParseV2Block: BlockConfig<MistralParserOutput> = {
213215 resultType : params . resultType || 'markdown' ,
214216 }
215217
218+ // Original V2 pattern: fileUpload (basic) or filePath (advanced) or document (wired)
219+ const documentInput = params . fileUpload || params . filePath || params . document
220+ if ( ! documentInput ) {
221+ throw new Error ( 'PDF document is required' )
222+ }
223+ // Smart handling: object → fileUpload param, string → filePath param
224+ if ( typeof documentInput === 'object' ) {
225+ parameters . fileUpload = documentInput
226+ } else if ( typeof documentInput === 'string' ) {
227+ parameters . filePath = documentInput . trim ( )
228+ }
229+
230+ let pagesArray : number [ ] | undefined
231+ if ( params . pages && params . pages . trim ( ) !== '' ) {
232+ try {
233+ pagesArray = params . pages
234+ . split ( ',' )
235+ . map ( ( p : string ) => p . trim ( ) )
236+ . filter ( ( p : string ) => p . length > 0 )
237+ . map ( ( p : string ) => {
238+ const num = Number . parseInt ( p , 10 )
239+ if ( Number . isNaN ( num ) || num < 0 ) {
240+ throw new Error ( `Invalid page number: ${ p } ` )
241+ }
242+ return num
243+ } )
244+
245+ if ( pagesArray && pagesArray . length === 0 ) {
246+ pagesArray = undefined
247+ }
248+ } catch ( error : unknown ) {
249+ const errorMessage = error instanceof Error ? error . message : String ( error )
250+ throw new Error ( `Page number format error: ${ errorMessage } ` )
251+ }
252+ }
253+
254+ if ( pagesArray && pagesArray . length > 0 ) {
255+ parameters . pages = pagesArray
256+ }
257+
258+ return parameters
259+ } ,
260+ } ,
261+ } ,
262+ inputs : {
263+ document : { type : 'json' , description : 'Document input (file upload or URL reference)' } ,
264+ filePath : { type : 'string' , description : 'PDF document URL (advanced mode)' } ,
265+ fileUpload : { type : 'json' , description : 'Uploaded PDF file (basic mode)' } ,
266+ apiKey : { type : 'string' , description : 'Mistral API key' } ,
267+ resultType : { type : 'string' , description : 'Output format type' } ,
268+ pages : { type : 'string' , description : 'Page selection' } ,
269+ } ,
270+ outputs : {
271+ pages : { type : 'array' , description : 'Array of page objects from Mistral OCR' } ,
272+ model : { type : 'string' , description : 'Mistral OCR model identifier' } ,
273+ usage_info : { type : 'json' , description : 'Usage statistics from the API' } ,
274+ document_annotation : { type : 'string' , description : 'Structured annotation data' } ,
275+ } ,
276+ }
277+
278+ /**
279+ * V3 Block - New file handling pattern with UserFile normalization
280+ * Uses fileReference subblock ID with canonicalParamId for proper file handling
281+ */
282+ export const MistralParseV3Block : BlockConfig < MistralParserOutput > = {
283+ ...MistralParseBlock ,
284+ type : 'mistral_parse_v3' ,
285+ name : 'Mistral Parser' ,
286+ description : 'Extract text from PDF documents' ,
287+ hideFromToolbar : false ,
288+ subBlocks : [
289+ {
290+ id : 'fileUpload' ,
291+ title : 'PDF Document' ,
292+ type : 'file-upload' as SubBlockType ,
293+ canonicalParamId : 'document' ,
294+ acceptedTypes : 'application/pdf' ,
295+ placeholder : 'Upload a PDF document' ,
296+ mode : 'basic' ,
297+ maxSize : 50 ,
298+ required : true ,
299+ } ,
300+ {
301+ id : 'fileReference' ,
302+ title : 'File Reference' ,
303+ type : 'short-input' as SubBlockType ,
304+ canonicalParamId : 'document' ,
305+ placeholder : 'File reference from previous block' ,
306+ mode : 'advanced' ,
307+ required : true ,
308+ } ,
309+ {
310+ id : 'resultType' ,
311+ title : 'Output Format' ,
312+ type : 'dropdown' ,
313+ options : [
314+ { id : 'markdown' , label : 'Markdown' } ,
315+ { id : 'text' , label : 'Plain Text' } ,
316+ { id : 'json' , label : 'JSON' } ,
317+ ] ,
318+ } ,
319+ {
320+ id : 'pages' ,
321+ title : 'Specific Pages' ,
322+ type : 'short-input' ,
323+ placeholder : 'e.g. 0,1,2 (leave empty for all pages)' ,
324+ } ,
325+ {
326+ id : 'apiKey' ,
327+ title : 'API Key' ,
328+ type : 'short-input' as SubBlockType ,
329+ placeholder : 'Enter your Mistral API key' ,
330+ password : true ,
331+ required : true ,
332+ } ,
333+ ] ,
334+ tools : {
335+ access : [ 'mistral_parser_v3' ] ,
336+ config : {
337+ tool : ( ) => 'mistral_parser_v3' ,
338+ params : ( params ) => {
339+ if ( ! params || ! params . apiKey || params . apiKey . trim ( ) === '' ) {
340+ throw new Error ( 'Mistral API key is required' )
341+ }
342+
343+ const parameters : Record < string , unknown > = {
344+ apiKey : params . apiKey . trim ( ) ,
345+ resultType : params . resultType || 'markdown' ,
346+ }
347+
348+ // V3 pattern: normalize file inputs from basic/advanced modes
216349 const documentInput = normalizeFileInput (
217350 params . fileUpload || params . fileReference || params . document ,
218351 { single : true }
0 commit comments