Skip to content

Commit 59578dd

Browse files
committed
added mistral v2, files v2, and finalized textract
1 parent dcaae1d commit 59578dd

File tree

16 files changed

+368
-188
lines changed

16 files changed

+368
-188
lines changed

apps/docs/components/ui/icon-mapping.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export const blockTypeToIconMap: Record<string, IconComponent> = {
154154
elasticsearch: ElasticsearchIcon,
155155
elevenlabs: ElevenLabsIcon,
156156
exa: ExaAIIcon,
157-
file: DocumentIcon,
157+
file_v2: DocumentIcon,
158158
firecrawl: FirecrawlIcon,
159159
fireflies: FirefliesIcon,
160160
github_v2: GithubIcon,
@@ -196,7 +196,7 @@ export const blockTypeToIconMap: Record<string, IconComponent> = {
196196
microsoft_excel_v2: MicrosoftExcelIcon,
197197
microsoft_planner: MicrosoftPlannerIcon,
198198
microsoft_teams: MicrosoftTeamsIcon,
199-
mistral_parse: MistralIcon,
199+
mistral_parse_v2: MistralIcon,
200200
mongodb: MongoDBIcon,
201201
mysql: MySQLIcon,
202202
neo4j: Neo4jIcon,

apps/docs/content/docs/en/tools/file.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: Read and parse multiple files
66
import { BlockInfoCard } from "@/components/ui/block-info-card"
77

88
<BlockInfoCard
9-
type="file"
9+
type="file_v2"
1010
color="#40916C"
1111
/>
1212

@@ -48,7 +48,7 @@ Parse one or more uploaded files or files from URLs (text, PDF, CSV, images, etc
4848

4949
| Parameter | Type | Description |
5050
| --------- | ---- | ----------- |
51-
| `files` | array | Array of parsed files |
52-
| `combinedContent` | string | Combined content of all parsed files |
51+
| `files` | array | Array of parsed files with content, metadata, and file properties |
52+
| `combinedContent` | string | All file contents merged into a single text string |
5353

5454

apps/docs/content/docs/en/tools/mistral_parse.mdx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: Extract text from PDF documents
66
import { BlockInfoCard } from "@/components/ui/block-info-card"
77

88
<BlockInfoCard
9-
type="mistral_parse"
9+
type="mistral_parse_v2"
1010
color="#000000"
1111
/>
1212

@@ -57,15 +57,5 @@ Parse PDF documents using Mistral OCR API
5757
| `success` | boolean | Whether the PDF was parsed successfully |
5858
| `content` | string | Extracted content in the requested format \(markdown, text, or JSON\) |
5959
| `metadata` | object | Processing metadata including jobId, fileType, pageCount, and usage info |
60-
|`jobId` | string | Unique job identifier |
61-
|`fileType` | string | File type \(e.g., pdf\) |
62-
|`fileName` | string | Original file name |
63-
|`source` | string | Source type \(url\) |
64-
|`pageCount` | number | Number of pages processed |
65-
|`model` | string | Mistral model used |
66-
|`resultType` | string | Output format \(markdown, text, json\) |
67-
|`processedAt` | string | Processing timestamp |
68-
|`sourceUrl` | string | Source URL if applicable |
69-
|`usageInfo` | object | Usage statistics from OCR processing |
7060

7161

apps/sim/app/api/tools/textract/parse/route.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,12 @@ export async function POST(request: NextRequest) {
423423

424424
let fileUrl = validatedData.filePath
425425

426-
if (validatedData.filePath?.includes('/api/files/serve/')) {
426+
const isInternalFilePath =
427+
validatedData.filePath?.startsWith('/api/files/serve/') ||
428+
(validatedData.filePath?.startsWith('/') &&
429+
validatedData.filePath?.includes('/api/files/serve/'))
430+
431+
if (isInternalFilePath) {
427432
try {
428433
const storageKey = extractStorageKey(validatedData.filePath)
429434
const context = inferContextFromKey(storageKey)

apps/sim/blocks/blocks/file.ts

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { createLogger } from '@sim/logger'
22
import { DocumentIcon } from '@/components/icons'
33
import type { BlockConfig, SubBlockType } from '@/blocks/types'
4+
import { createVersionedToolSelector } from '@/blocks/utils'
45
import type { FileParserOutput } from '@/tools/file/types'
56

67
const logger = createLogger('FileBlock')
78

89
export 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

Comments
 (0)