Skip to content

Commit f256a9f

Browse files
committed
make interface simpler
1 parent 47c9604 commit f256a9f

File tree

6 files changed

+38
-47
lines changed

6 files changed

+38
-47
lines changed

apps/sim/blocks/blocks/google_slides.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -962,16 +962,10 @@ export const GoogleSlidesV2Block: BlockConfig<GoogleSlidesResponse> = {
962962

963963
if (params.operation === 'add_image') {
964964
const imageInput = params.imageFile || params.imageFileReference || params.imageSource
965-
const normalizedFiles = normalizeFileInput(imageInput)
966-
if (!normalizedFiles || normalizedFiles.length === 0) {
965+
const fileObject = normalizeFileInput(imageInput, { single: true })
966+
if (!fileObject) {
967967
throw new Error('Image file is required.')
968968
}
969-
if (normalizedFiles.length > 1) {
970-
throw new Error(
971-
'File reference must be a single file, not an array. Use <block.files[0]> to select one file.'
972-
)
973-
}
974-
const fileObject = normalizedFiles[0]
975969
const imageUrl = resolveHttpsUrlFromFileInput(fileObject)
976970
if (!imageUrl) {
977971
throw new Error('Image file must include a https URL.')

apps/sim/blocks/blocks/linear.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,17 +1775,15 @@ Return ONLY the date string in YYYY-MM-DD format - no explanations, no quotes, n
17751775
throw new Error('Issue ID is required.')
17761776
}
17771777
// Normalize file inputs - handles JSON stringified values from advanced mode
1778-
// Take the first file from whichever input has data (Linear only accepts single file)
17791778
const attachmentFile =
1780-
normalizeFileInput(params.attachmentFileUpload, { single: true }) ||
1781-
normalizeFileInput(params.file, { single: true })
1782-
// Check for multiple files
1783-
if (
1784-
(normalizedUpload && normalizedUpload.length > 1) ||
1785-
(normalizedFile && normalizedFile.length > 1)
1786-
) {
1787-
throw new Error('Attachment file must be a single file.')
1788-
}
1779+
normalizeFileInput(params.attachmentFileUpload, {
1780+
single: true,
1781+
errorMessage: 'Attachment file must be a single file.',
1782+
}) ||
1783+
normalizeFileInput(params.file, {
1784+
single: true,
1785+
errorMessage: 'Attachment file must be a single file.',
1786+
})
17891787
const attachmentUrl =
17901788
params.url?.trim() ||
17911789
(attachmentFile ? (attachmentFile as { url?: string }).url : undefined)

apps/sim/blocks/blocks/mistral_parse.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,13 @@ export const MistralParseV2Block: BlockConfig<MistralParserOutput> = {
214214
}
215215

216216
const documentInput = normalizeFileInput(
217-
params.fileUpload || params.fileReference || params.document
217+
params.fileUpload || params.fileReference || params.document,
218+
{ single: true }
218219
)
219-
if (!documentInput || documentInput.length === 0) {
220+
if (!documentInput) {
220221
throw new Error('PDF document is required')
221222
}
222-
if (documentInput.length > 1) {
223-
throw new Error(
224-
'File reference must be a single file, not an array. Use <block.attachments[0]> to select one file.'
225-
)
226-
}
227-
parameters.file = documentInput[0]
223+
parameters.file = documentInput
228224

229225
let pagesArray: number[] | undefined
230226
if (params.pages && params.pages.trim() !== '') {

apps/sim/blocks/blocks/pulse.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,14 @@ export const PulseV2Block: BlockConfig<PulseParserOutput> = {
183183
apiKey: params.apiKey.trim(),
184184
}
185185

186-
const normalizedFiles = normalizeFileInput(
187-
params.fileUpload || params.fileReference || params.document
186+
const normalizedFile = normalizeFileInput(
187+
params.fileUpload || params.fileReference || params.document,
188+
{ single: true }
188189
)
189-
if (!normalizedFiles || normalizedFiles.length === 0) {
190+
if (!normalizedFile) {
190191
throw new Error('Document file is required')
191192
}
192-
if (normalizedFiles.length > 1) {
193-
throw new Error(
194-
'File reference must be a single file, not an array. Use <block.attachments[0]> to select one file.'
195-
)
196-
}
197-
parameters.file = normalizedFiles[0]
193+
parameters.file = normalizedFile
198194

199195
if (params.pages && params.pages.trim() !== '') {
200196
parameters.pages = params.pages.trim()

apps/sim/blocks/blocks/reducto.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,13 @@ export const ReductoV2Block: BlockConfig<ReductoParserOutput> = {
188188
}
189189

190190
const documentInput = normalizeFileInput(
191-
params.fileUpload || params.fileReference || params.document
191+
params.fileUpload || params.fileReference || params.document,
192+
{ single: true }
192193
)
193-
if (!documentInput || documentInput.length === 0) {
194+
if (!documentInput) {
194195
throw new Error('PDF document file is required')
195196
}
196-
if (documentInput.length > 1) {
197-
throw new Error(
198-
'File reference must be a single file, not an array. Use <block.attachments[0]> to select one file.'
199-
)
200-
}
201-
parameters.file = documentInput[0]
197+
parameters.file = documentInput
202198

203199
let pagesArray: number[] | undefined
204200
if (params.pages && params.pages.trim() !== '') {

apps/sim/blocks/utils.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ export function createVersionedToolSelector<TParams extends Record<string, any>>
250250
}
251251
}
252252

253+
const DEFAULT_MULTIPLE_FILES_ERROR =
254+
'File reference must be a single file, not an array. Use <block.files[0]> to select one file.'
255+
253256
/**
254257
* Normalizes file input from block params to a consistent format.
255258
* Handles the case where template resolution JSON.stringify's arrays/objects
@@ -260,20 +263,21 @@ export function createVersionedToolSelector<TParams extends Record<string, any>>
260263
* - An array of file objects (basic mode or properly resolved)
261264
* - A single file object
262265
* - A JSON string of file(s) (from advanced mode template resolution)
263-
* @param options.single - If true, returns only the first file object instead of an array
266+
* @param options.single - If true, returns single file object and throws if multiple provided
267+
* @param options.errorMessage - Custom error message when single is true and multiple files provided
264268
* @returns Normalized file(s), or undefined if no files
265269
*/
266270
export function normalizeFileInput(
267271
fileParam: unknown,
268-
options: { single: true }
272+
options: { single: true; errorMessage?: string }
269273
): object | undefined
270274
export function normalizeFileInput(
271275
fileParam: unknown,
272276
options?: { single?: false }
273277
): object[] | undefined
274278
export function normalizeFileInput(
275279
fileParam: unknown,
276-
options?: { single?: boolean }
280+
options?: { single?: boolean; errorMessage?: string }
277281
): object | object[] | undefined {
278282
if (!fileParam) return undefined
279283

@@ -295,5 +299,12 @@ export function normalizeFileInput(
295299

296300
if (!files) return undefined
297301

298-
return options?.single ? files[0] : files
302+
if (options?.single) {
303+
if (files.length > 1) {
304+
throw new Error(options.errorMessage ?? DEFAULT_MULTIPLE_FILES_ERROR)
305+
}
306+
return files[0]
307+
}
308+
309+
return files
299310
}

0 commit comments

Comments
 (0)