make interface simpler

This commit is contained in:
Vikhyath Mondreti
2026-02-03 12:15:26 -08:00
parent 47c9604577
commit f256a9fa8c
6 changed files with 38 additions and 47 deletions

View File

@@ -962,16 +962,10 @@ export const GoogleSlidesV2Block: BlockConfig<GoogleSlidesResponse> = {
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 <block.files[0]> to select one file.'
)
}
const fileObject = normalizedFiles[0]
const imageUrl = resolveHttpsUrlFromFileInput(fileObject)
if (!imageUrl) {
throw new Error('Image file must include a https URL.')

View File

@@ -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)

View File

@@ -214,17 +214,13 @@ export const MistralParseV2Block: BlockConfig<MistralParserOutput> = {
}
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 <block.attachments[0]> to select one file.'
)
}
parameters.file = documentInput[0]
parameters.file = documentInput
let pagesArray: number[] | undefined
if (params.pages && params.pages.trim() !== '') {

View File

@@ -183,18 +183,14 @@ export const PulseV2Block: BlockConfig<PulseParserOutput> = {
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 <block.attachments[0]> to select one file.'
)
}
parameters.file = normalizedFiles[0]
parameters.file = normalizedFile
if (params.pages && params.pages.trim() !== '') {
parameters.pages = params.pages.trim()

View File

@@ -188,17 +188,13 @@ export const ReductoV2Block: BlockConfig<ReductoParserOutput> = {
}
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 <block.attachments[0]> to select one file.'
)
}
parameters.file = documentInput[0]
parameters.file = documentInput
let pagesArray: number[] | undefined
if (params.pages && params.pages.trim() !== '') {

View File

@@ -250,6 +250,9 @@ export function createVersionedToolSelector<TParams extends Record<string, any>>
}
}
const DEFAULT_MULTIPLE_FILES_ERROR =
'File reference must be a single file, not an array. Use <block.files[0]> 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<TParams extends Record<string, any>>
* - 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
}