From 472aff5dd76a56f9a3573df3e6fac0c3536ab548 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Thu, 20 Nov 2025 00:27:12 -0800 Subject: [PATCH] fix(resolver): json/array field parsing (#2074) * fix(resolver): json/array field parsing * remove comment --- apps/sim/blocks/blocks/discord.ts | 2 +- apps/sim/blocks/blocks/firecrawl.ts | 12 ++----- apps/sim/blocks/blocks/gmail.ts | 2 +- apps/sim/blocks/blocks/hubspot.ts | 27 +++------------ apps/sim/blocks/blocks/mem0.ts | 21 ++++-------- apps/sim/blocks/blocks/microsoft_teams.ts | 2 +- apps/sim/blocks/blocks/outlook.ts | 2 +- apps/sim/blocks/blocks/sharepoint.ts | 2 +- apps/sim/blocks/blocks/slack.ts | 2 +- apps/sim/blocks/blocks/telegram.ts | 2 +- apps/sim/blocks/blocks/zep.ts | 33 +++++-------------- .../handlers/generic/generic-handler.ts | 18 ++++++++++ 12 files changed, 45 insertions(+), 80 deletions(-) diff --git a/apps/sim/blocks/blocks/discord.ts b/apps/sim/blocks/blocks/discord.ts index 8d9eb0d8f..3d9fc3657 100644 --- a/apps/sim/blocks/blocks/discord.ts +++ b/apps/sim/blocks/blocks/discord.ts @@ -773,7 +773,7 @@ export const DiscordBlock: BlockConfig = { reason: { type: 'string', description: 'Reason for moderation action' }, archived: { type: 'string', description: 'Archive status (true/false)' }, attachmentFiles: { type: 'json', description: 'Files to attach (UI upload)' }, - files: { type: 'json', description: 'Files to attach (UserFile array)' }, + files: { type: 'array', description: 'Files to attach (UserFile array)' }, limit: { type: 'number', description: 'Message limit' }, autoArchiveDuration: { type: 'number', description: 'Thread auto-archive duration in minutes' }, channelType: { type: 'number', description: 'Discord channel type (0=text, 2=voice, etc.)' }, diff --git a/apps/sim/blocks/blocks/firecrawl.ts b/apps/sim/blocks/blocks/firecrawl.ts index 70a025445..dc66c8277 100644 --- a/apps/sim/blocks/blocks/firecrawl.ts +++ b/apps/sim/blocks/blocks/firecrawl.ts @@ -187,11 +187,7 @@ export const FirecrawlBlock: BlockConfig = { case 'scrape': if (url) result.url = url if (formats) { - try { - result.formats = typeof formats === 'string' ? JSON.parse(formats) : formats - } catch { - result.formats = ['markdown'] - } + result.formats = Array.isArray(formats) ? formats : ['markdown'] } if (timeout) result.timeout = Number.parseInt(timeout) if (waitFor) result.waitFor = Number.parseInt(waitFor) @@ -218,11 +214,7 @@ export const FirecrawlBlock: BlockConfig = { case 'extract': if (urls) { - try { - result.urls = typeof urls === 'string' ? JSON.parse(urls) : urls - } catch { - result.urls = [urls] - } + result.urls = Array.isArray(urls) ? urls : [urls] } if (prompt) result.prompt = prompt break diff --git a/apps/sim/blocks/blocks/gmail.ts b/apps/sim/blocks/blocks/gmail.ts index 93d9400dd..b6bb64e44 100644 --- a/apps/sim/blocks/blocks/gmail.ts +++ b/apps/sim/blocks/blocks/gmail.ts @@ -462,7 +462,7 @@ export const GmailBlock: BlockConfig = { }, cc: { type: 'string', description: 'CC recipients (comma-separated)' }, bcc: { type: 'string', description: 'BCC recipients (comma-separated)' }, - attachments: { type: 'json', description: 'Files to attach (UserFile array)' }, + attachments: { type: 'array', description: 'Files to attach (UserFile array)' }, // Read operation inputs folder: { type: 'string', description: 'Gmail folder' }, manualFolder: { type: 'string', description: 'Manual folder name' }, diff --git a/apps/sim/blocks/blocks/hubspot.ts b/apps/sim/blocks/blocks/hubspot.ts index 061d13adb..499a1d0e9 100644 --- a/apps/sim/blocks/blocks/hubspot.ts +++ b/apps/sim/blocks/blocks/hubspot.ts @@ -824,12 +824,7 @@ Return ONLY the JSON array of property names - no explanations, no markdown, no } if (propertiesToSet) { - try { - cleanParams.properties = - typeof propertiesToSet === 'string' ? JSON.parse(propertiesToSet) : propertiesToSet - } catch (error) { - throw new Error('Invalid JSON in properties field') - } + cleanParams.properties = propertiesToSet } if (properties && !searchProperties) { @@ -837,29 +832,15 @@ Return ONLY the JSON array of property names - no explanations, no markdown, no } if (searchProperties) { - try { - cleanParams.properties = - typeof searchProperties === 'string' ? JSON.parse(searchProperties) : searchProperties - } catch (error) { - throw new Error('Invalid JSON in searchProperties field') - } + cleanParams.properties = searchProperties } if (filterGroups) { - try { - cleanParams.filterGroups = - typeof filterGroups === 'string' ? JSON.parse(filterGroups) : filterGroups - } catch (error) { - throw new Error('Invalid JSON in filterGroups field') - } + cleanParams.filterGroups = filterGroups } if (sorts) { - try { - cleanParams.sorts = typeof sorts === 'string' ? JSON.parse(sorts) : sorts - } catch (error) { - throw new Error('Invalid JSON in sorts field') - } + cleanParams.sorts = sorts } if (associations) { diff --git a/apps/sim/blocks/blocks/mem0.ts b/apps/sim/blocks/blocks/mem0.ts index e67f8dc6a..ee855db30 100644 --- a/apps/sim/blocks/blocks/mem0.ts +++ b/apps/sim/blocks/blocks/mem0.ts @@ -148,23 +148,14 @@ export const Mem0Block: BlockConfig = { if (params.operation === 'add') { if (!params.messages) { errors.push('Messages are required for add operation') + } else if (!Array.isArray(params.messages) || params.messages.length === 0) { + errors.push('Messages must be a non-empty array') } else { - try { - const messagesArray = - typeof params.messages === 'string' ? JSON.parse(params.messages) : params.messages - - if (!Array.isArray(messagesArray) || messagesArray.length === 0) { - errors.push('Messages must be a non-empty array') - } else { - for (const msg of messagesArray) { - if (!msg.role || !msg.content) { - errors.push("Each message must have 'role' and 'content' properties") - break - } - } + for (const msg of params.messages) { + if (!msg.role || !msg.content) { + errors.push("Each message must have 'role' and 'content' properties") + break } - } catch (_e: any) { - errors.push('Messages must be valid JSON') } } diff --git a/apps/sim/blocks/blocks/microsoft_teams.ts b/apps/sim/blocks/blocks/microsoft_teams.ts index e66a708d3..0e07a6302 100644 --- a/apps/sim/blocks/blocks/microsoft_teams.ts +++ b/apps/sim/blocks/blocks/microsoft_teams.ts @@ -442,7 +442,7 @@ export const MicrosoftTeamsBlock: BlockConfig = { }, reactionType: { type: 'string', description: 'Emoji reaction (e.g., ❤️, 👍, 😊)' }, attachmentFiles: { type: 'json', description: 'Files to attach (UI upload)' }, - files: { type: 'json', description: 'Files to attach (UserFile array)' }, + files: { type: 'array', description: 'Files to attach (UserFile array)' }, }, outputs: { content: { type: 'string', description: 'Formatted message content from chat/channel' }, diff --git a/apps/sim/blocks/blocks/outlook.ts b/apps/sim/blocks/blocks/outlook.ts index 0b097a845..835bde069 100644 --- a/apps/sim/blocks/blocks/outlook.ts +++ b/apps/sim/blocks/blocks/outlook.ts @@ -396,7 +396,7 @@ export const OutlookBlock: BlockConfig = { body: { type: 'string', description: 'Email content' }, contentType: { type: 'string', description: 'Content type (Text or HTML)' }, attachmentFiles: { type: 'json', description: 'Files to attach (UI upload)' }, - attachments: { type: 'json', description: 'Files to attach (UserFile array)' }, + attachments: { type: 'array', description: 'Files to attach (UserFile array)' }, // Forward operation inputs messageId: { type: 'string', description: 'Message ID to forward' }, comment: { type: 'string', description: 'Optional comment for forwarding' }, diff --git a/apps/sim/blocks/blocks/sharepoint.ts b/apps/sim/blocks/blocks/sharepoint.ts index 60c638b12..063a83822 100644 --- a/apps/sim/blocks/blocks/sharepoint.ts +++ b/apps/sim/blocks/blocks/sharepoint.ts @@ -360,7 +360,7 @@ export const SharepointBlock: BlockConfig = { folderPath: { type: 'string', description: 'Folder path for file upload' }, fileName: { type: 'string', description: 'File name override' }, uploadFiles: { type: 'json', description: 'Files to upload (UI upload)' }, - files: { type: 'json', description: 'Files to upload (UserFile array)' }, + files: { type: 'array', description: 'Files to upload (UserFile array)' }, }, outputs: { sites: { diff --git a/apps/sim/blocks/blocks/slack.ts b/apps/sim/blocks/blocks/slack.ts index 8bdb7ac11..a78c939fe 100644 --- a/apps/sim/blocks/blocks/slack.ts +++ b/apps/sim/blocks/blocks/slack.ts @@ -445,7 +445,7 @@ export const SlackBlock: BlockConfig = { manualChannel: { type: 'string', description: 'Manual channel identifier' }, text: { type: 'string', description: 'Message text' }, attachmentFiles: { type: 'json', description: 'Files to attach (UI upload)' }, - files: { type: 'json', description: 'Files to attach (UserFile array)' }, + files: { type: 'array', description: 'Files to attach (UserFile array)' }, title: { type: 'string', description: 'Canvas title' }, content: { type: 'string', description: 'Canvas content' }, limit: { type: 'string', description: 'Message limit' }, diff --git a/apps/sim/blocks/blocks/telegram.ts b/apps/sim/blocks/blocks/telegram.ts index d37844a30..6c40812a4 100644 --- a/apps/sim/blocks/blocks/telegram.ts +++ b/apps/sim/blocks/blocks/telegram.ts @@ -282,7 +282,7 @@ export const TelegramBlock: BlockConfig = { type: 'json', description: 'Files to attach (UI upload)', }, - files: { type: 'json', description: 'Files to attach (UserFile array)' }, + files: { type: 'array', description: 'Files to attach (UserFile array)' }, caption: { type: 'string', description: 'Caption for media' }, messageId: { type: 'string', description: 'Message ID to delete' }, }, diff --git a/apps/sim/blocks/blocks/zep.ts b/apps/sim/blocks/blocks/zep.ts index 500be0848..0798986ba 100644 --- a/apps/sim/blocks/blocks/zep.ts +++ b/apps/sim/blocks/blocks/zep.ts @@ -222,23 +222,14 @@ export const ZepBlock: BlockConfig = { if (operation === 'add_messages') { if (!params.messages) { errors.push('Messages are required') + } else if (!Array.isArray(params.messages) || params.messages.length === 0) { + errors.push('Messages must be a non-empty array') } else { - try { - const messagesArray = - typeof params.messages === 'string' ? JSON.parse(params.messages) : params.messages - - if (!Array.isArray(messagesArray) || messagesArray.length === 0) { - errors.push('Messages must be a non-empty array') - } else { - for (const msg of messagesArray) { - if (!msg.role || !msg.content) { - errors.push("Each message must have 'role' and 'content' properties") - break - } - } + for (const msg of params.messages) { + if (!msg.role || !msg.content) { + errors.push("Each message must have 'role' and 'content' properties") + break } - } catch (_e: any) { - errors.push('Messages must be valid JSON') } } } @@ -263,16 +254,8 @@ export const ZepBlock: BlockConfig = { if (params.metadata) result.metadata = params.metadata // Add messages for add operation - if (operation === 'add_messages') { - if (params.messages) { - try { - const messagesArray = - typeof params.messages === 'string' ? JSON.parse(params.messages) : params.messages - result.messages = messagesArray - } catch (e: any) { - throw new Error(`Zep Block Error: ${e.message || 'Messages must be valid JSON'}`) - } - } + if (operation === 'add_messages' && params.messages) { + result.messages = params.messages } return result diff --git a/apps/sim/executor/handlers/generic/generic-handler.ts b/apps/sim/executor/handlers/generic/generic-handler.ts index eacf260cd..a564192b4 100644 --- a/apps/sim/executor/handlers/generic/generic-handler.ts +++ b/apps/sim/executor/handlers/generic/generic-handler.ts @@ -42,6 +42,24 @@ export class GenericBlockHandler implements BlockHandler { }) } } + + if (blockConfig?.inputs) { + for (const [key, inputSchema] of Object.entries(blockConfig.inputs)) { + const value = finalInputs[key] + if (typeof value === 'string' && value.trim().length > 0) { + const inputType = typeof inputSchema === 'object' ? inputSchema.type : inputSchema + if (inputType === 'json' || inputType === 'array') { + try { + finalInputs[key] = JSON.parse(value.trim()) + } catch (error) { + logger.warn(`Failed to parse ${inputType} field "${key}":`, { + error: error instanceof Error ? error.message : String(error), + }) + } + } + } + } + } } try {