From f256a9fa8cef12e6858846951bb50748fc6a85d5 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Tue, 3 Feb 2026 12:15:26 -0800 Subject: [PATCH] make interface simpler --- apps/sim/blocks/blocks/google_slides.ts | 10 ++-------- apps/sim/blocks/blocks/linear.ts | 18 ++++++++---------- apps/sim/blocks/blocks/mistral_parse.ts | 12 ++++-------- apps/sim/blocks/blocks/pulse.ts | 14 +++++--------- apps/sim/blocks/blocks/reducto.ts | 12 ++++-------- apps/sim/blocks/utils.ts | 19 +++++++++++++++---- 6 files changed, 38 insertions(+), 47 deletions(-) diff --git a/apps/sim/blocks/blocks/google_slides.ts b/apps/sim/blocks/blocks/google_slides.ts index 31d47ff74..784fc73fc 100644 --- a/apps/sim/blocks/blocks/google_slides.ts +++ b/apps/sim/blocks/blocks/google_slides.ts @@ -962,16 +962,10 @@ export const GoogleSlidesV2Block: BlockConfig = { if (params.operation === 'add_image') { const imageInput = params.imageFile || params.imageFileReference || params.imageSource - const normalizedFiles = normalizeFileInput(imageInput) - if (!normalizedFiles || normalizedFiles.length === 0) { + const fileObject = normalizeFileInput(imageInput, { single: true }) + if (!fileObject) { throw new Error('Image file is required.') } - if (normalizedFiles.length > 1) { - throw new Error( - 'File reference must be a single file, not an array. Use to select one file.' - ) - } - const fileObject = normalizedFiles[0] const imageUrl = resolveHttpsUrlFromFileInput(fileObject) if (!imageUrl) { throw new Error('Image file must include a https URL.') diff --git a/apps/sim/blocks/blocks/linear.ts b/apps/sim/blocks/blocks/linear.ts index d7c245a85..2b8e43587 100644 --- a/apps/sim/blocks/blocks/linear.ts +++ b/apps/sim/blocks/blocks/linear.ts @@ -1775,17 +1775,15 @@ Return ONLY the date string in YYYY-MM-DD format - no explanations, no quotes, n throw new Error('Issue ID is required.') } // Normalize file inputs - handles JSON stringified values from advanced mode - // Take the first file from whichever input has data (Linear only accepts single file) const attachmentFile = - normalizeFileInput(params.attachmentFileUpload, { single: true }) || - normalizeFileInput(params.file, { single: true }) - // Check for multiple files - if ( - (normalizedUpload && normalizedUpload.length > 1) || - (normalizedFile && normalizedFile.length > 1) - ) { - throw new Error('Attachment file must be a single file.') - } + normalizeFileInput(params.attachmentFileUpload, { + single: true, + errorMessage: 'Attachment file must be a single file.', + }) || + normalizeFileInput(params.file, { + single: true, + errorMessage: 'Attachment file must be a single file.', + }) const attachmentUrl = params.url?.trim() || (attachmentFile ? (attachmentFile as { url?: string }).url : undefined) diff --git a/apps/sim/blocks/blocks/mistral_parse.ts b/apps/sim/blocks/blocks/mistral_parse.ts index 472d1ff35..424f65b8a 100644 --- a/apps/sim/blocks/blocks/mistral_parse.ts +++ b/apps/sim/blocks/blocks/mistral_parse.ts @@ -214,17 +214,13 @@ export const MistralParseV2Block: BlockConfig = { } const documentInput = normalizeFileInput( - params.fileUpload || params.fileReference || params.document + params.fileUpload || params.fileReference || params.document, + { single: true } ) - if (!documentInput || documentInput.length === 0) { + if (!documentInput) { throw new Error('PDF document is required') } - if (documentInput.length > 1) { - throw new Error( - 'File reference must be a single file, not an array. Use to select one file.' - ) - } - parameters.file = documentInput[0] + parameters.file = documentInput let pagesArray: number[] | undefined if (params.pages && params.pages.trim() !== '') { diff --git a/apps/sim/blocks/blocks/pulse.ts b/apps/sim/blocks/blocks/pulse.ts index fa8347a05..c61f11070 100644 --- a/apps/sim/blocks/blocks/pulse.ts +++ b/apps/sim/blocks/blocks/pulse.ts @@ -183,18 +183,14 @@ export const PulseV2Block: BlockConfig = { apiKey: params.apiKey.trim(), } - const normalizedFiles = normalizeFileInput( - params.fileUpload || params.fileReference || params.document + const normalizedFile = normalizeFileInput( + params.fileUpload || params.fileReference || params.document, + { single: true } ) - if (!normalizedFiles || normalizedFiles.length === 0) { + if (!normalizedFile) { throw new Error('Document file is required') } - if (normalizedFiles.length > 1) { - throw new Error( - 'File reference must be a single file, not an array. Use to select one file.' - ) - } - parameters.file = normalizedFiles[0] + parameters.file = normalizedFile if (params.pages && params.pages.trim() !== '') { parameters.pages = params.pages.trim() diff --git a/apps/sim/blocks/blocks/reducto.ts b/apps/sim/blocks/blocks/reducto.ts index 62a973ee4..fb9d39370 100644 --- a/apps/sim/blocks/blocks/reducto.ts +++ b/apps/sim/blocks/blocks/reducto.ts @@ -188,17 +188,13 @@ export const ReductoV2Block: BlockConfig = { } const documentInput = normalizeFileInput( - params.fileUpload || params.fileReference || params.document + params.fileUpload || params.fileReference || params.document, + { single: true } ) - if (!documentInput || documentInput.length === 0) { + if (!documentInput) { throw new Error('PDF document file is required') } - if (documentInput.length > 1) { - throw new Error( - 'File reference must be a single file, not an array. Use to select one file.' - ) - } - parameters.file = documentInput[0] + parameters.file = documentInput let pagesArray: number[] | undefined if (params.pages && params.pages.trim() !== '') { diff --git a/apps/sim/blocks/utils.ts b/apps/sim/blocks/utils.ts index 9c800d50f..7de0b518a 100644 --- a/apps/sim/blocks/utils.ts +++ b/apps/sim/blocks/utils.ts @@ -250,6 +250,9 @@ export function createVersionedToolSelector> } } +const DEFAULT_MULTIPLE_FILES_ERROR = + 'File reference must be a single file, not an array. Use to select one file.' + /** * Normalizes file input from block params to a consistent format. * Handles the case where template resolution JSON.stringify's arrays/objects @@ -260,12 +263,13 @@ export function createVersionedToolSelector> * - An array of file objects (basic mode or properly resolved) * - A single file object * - A JSON string of file(s) (from advanced mode template resolution) - * @param options.single - If true, returns only the first file object instead of an array + * @param options.single - If true, returns single file object and throws if multiple provided + * @param options.errorMessage - Custom error message when single is true and multiple files provided * @returns Normalized file(s), or undefined if no files */ export function normalizeFileInput( fileParam: unknown, - options: { single: true } + options: { single: true; errorMessage?: string } ): object | undefined export function normalizeFileInput( fileParam: unknown, @@ -273,7 +277,7 @@ export function normalizeFileInput( ): object[] | undefined export function normalizeFileInput( fileParam: unknown, - options?: { single?: boolean } + options?: { single?: boolean; errorMessage?: string } ): object | object[] | undefined { if (!fileParam) return undefined @@ -295,5 +299,12 @@ export function normalizeFileInput( if (!files) return undefined - return options?.single ? files[0] : files + if (options?.single) { + if (files.length > 1) { + throw new Error(options.errorMessage ?? DEFAULT_MULTIPLE_FILES_ERROR) + } + return files[0] + } + + return files }