Skip to content

Commit 472aff5

Browse files
fix(resolver): json/array field parsing (#2074)
* fix(resolver): json/array field parsing * remove comment
1 parent 4d5c574 commit 472aff5

File tree

12 files changed

+45
-80
lines changed

12 files changed

+45
-80
lines changed

apps/sim/blocks/blocks/discord.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
773773
reason: { type: 'string', description: 'Reason for moderation action' },
774774
archived: { type: 'string', description: 'Archive status (true/false)' },
775775
attachmentFiles: { type: 'json', description: 'Files to attach (UI upload)' },
776-
files: { type: 'json', description: 'Files to attach (UserFile array)' },
776+
files: { type: 'array', description: 'Files to attach (UserFile array)' },
777777
limit: { type: 'number', description: 'Message limit' },
778778
autoArchiveDuration: { type: 'number', description: 'Thread auto-archive duration in minutes' },
779779
channelType: { type: 'number', description: 'Discord channel type (0=text, 2=voice, etc.)' },

apps/sim/blocks/blocks/firecrawl.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,7 @@ export const FirecrawlBlock: BlockConfig<FirecrawlResponse> = {
187187
case 'scrape':
188188
if (url) result.url = url
189189
if (formats) {
190-
try {
191-
result.formats = typeof formats === 'string' ? JSON.parse(formats) : formats
192-
} catch {
193-
result.formats = ['markdown']
194-
}
190+
result.formats = Array.isArray(formats) ? formats : ['markdown']
195191
}
196192
if (timeout) result.timeout = Number.parseInt(timeout)
197193
if (waitFor) result.waitFor = Number.parseInt(waitFor)
@@ -218,11 +214,7 @@ export const FirecrawlBlock: BlockConfig<FirecrawlResponse> = {
218214

219215
case 'extract':
220216
if (urls) {
221-
try {
222-
result.urls = typeof urls === 'string' ? JSON.parse(urls) : urls
223-
} catch {
224-
result.urls = [urls]
225-
}
217+
result.urls = Array.isArray(urls) ? urls : [urls]
226218
}
227219
if (prompt) result.prompt = prompt
228220
break

apps/sim/blocks/blocks/gmail.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ export const GmailBlock: BlockConfig<GmailToolResponse> = {
462462
},
463463
cc: { type: 'string', description: 'CC recipients (comma-separated)' },
464464
bcc: { type: 'string', description: 'BCC recipients (comma-separated)' },
465-
attachments: { type: 'json', description: 'Files to attach (UserFile array)' },
465+
attachments: { type: 'array', description: 'Files to attach (UserFile array)' },
466466
// Read operation inputs
467467
folder: { type: 'string', description: 'Gmail folder' },
468468
manualFolder: { type: 'string', description: 'Manual folder name' },

apps/sim/blocks/blocks/hubspot.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -824,42 +824,23 @@ Return ONLY the JSON array of property names - no explanations, no markdown, no
824824
}
825825

826826
if (propertiesToSet) {
827-
try {
828-
cleanParams.properties =
829-
typeof propertiesToSet === 'string' ? JSON.parse(propertiesToSet) : propertiesToSet
830-
} catch (error) {
831-
throw new Error('Invalid JSON in properties field')
832-
}
827+
cleanParams.properties = propertiesToSet
833828
}
834829

835830
if (properties && !searchProperties) {
836831
cleanParams.properties = properties
837832
}
838833

839834
if (searchProperties) {
840-
try {
841-
cleanParams.properties =
842-
typeof searchProperties === 'string' ? JSON.parse(searchProperties) : searchProperties
843-
} catch (error) {
844-
throw new Error('Invalid JSON in searchProperties field')
845-
}
835+
cleanParams.properties = searchProperties
846836
}
847837

848838
if (filterGroups) {
849-
try {
850-
cleanParams.filterGroups =
851-
typeof filterGroups === 'string' ? JSON.parse(filterGroups) : filterGroups
852-
} catch (error) {
853-
throw new Error('Invalid JSON in filterGroups field')
854-
}
839+
cleanParams.filterGroups = filterGroups
855840
}
856841

857842
if (sorts) {
858-
try {
859-
cleanParams.sorts = typeof sorts === 'string' ? JSON.parse(sorts) : sorts
860-
} catch (error) {
861-
throw new Error('Invalid JSON in sorts field')
862-
}
843+
cleanParams.sorts = sorts
863844
}
864845

865846
if (associations) {

apps/sim/blocks/blocks/mem0.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,14 @@ export const Mem0Block: BlockConfig<Mem0Response> = {
148148
if (params.operation === 'add') {
149149
if (!params.messages) {
150150
errors.push('Messages are required for add operation')
151+
} else if (!Array.isArray(params.messages) || params.messages.length === 0) {
152+
errors.push('Messages must be a non-empty array')
151153
} else {
152-
try {
153-
const messagesArray =
154-
typeof params.messages === 'string' ? JSON.parse(params.messages) : params.messages
155-
156-
if (!Array.isArray(messagesArray) || messagesArray.length === 0) {
157-
errors.push('Messages must be a non-empty array')
158-
} else {
159-
for (const msg of messagesArray) {
160-
if (!msg.role || !msg.content) {
161-
errors.push("Each message must have 'role' and 'content' properties")
162-
break
163-
}
164-
}
154+
for (const msg of params.messages) {
155+
if (!msg.role || !msg.content) {
156+
errors.push("Each message must have 'role' and 'content' properties")
157+
break
165158
}
166-
} catch (_e: any) {
167-
errors.push('Messages must be valid JSON')
168159
}
169160
}
170161

apps/sim/blocks/blocks/microsoft_teams.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ export const MicrosoftTeamsBlock: BlockConfig<MicrosoftTeamsResponse> = {
442442
},
443443
reactionType: { type: 'string', description: 'Emoji reaction (e.g., ❤️, 👍, 😊)' },
444444
attachmentFiles: { type: 'json', description: 'Files to attach (UI upload)' },
445-
files: { type: 'json', description: 'Files to attach (UserFile array)' },
445+
files: { type: 'array', description: 'Files to attach (UserFile array)' },
446446
},
447447
outputs: {
448448
content: { type: 'string', description: 'Formatted message content from chat/channel' },

apps/sim/blocks/blocks/outlook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ export const OutlookBlock: BlockConfig<OutlookResponse> = {
396396
body: { type: 'string', description: 'Email content' },
397397
contentType: { type: 'string', description: 'Content type (Text or HTML)' },
398398
attachmentFiles: { type: 'json', description: 'Files to attach (UI upload)' },
399-
attachments: { type: 'json', description: 'Files to attach (UserFile array)' },
399+
attachments: { type: 'array', description: 'Files to attach (UserFile array)' },
400400
// Forward operation inputs
401401
messageId: { type: 'string', description: 'Message ID to forward' },
402402
comment: { type: 'string', description: 'Optional comment for forwarding' },

apps/sim/blocks/blocks/sharepoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ export const SharepointBlock: BlockConfig<SharepointResponse> = {
360360
folderPath: { type: 'string', description: 'Folder path for file upload' },
361361
fileName: { type: 'string', description: 'File name override' },
362362
uploadFiles: { type: 'json', description: 'Files to upload (UI upload)' },
363-
files: { type: 'json', description: 'Files to upload (UserFile array)' },
363+
files: { type: 'array', description: 'Files to upload (UserFile array)' },
364364
},
365365
outputs: {
366366
sites: {

apps/sim/blocks/blocks/slack.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export const SlackBlock: BlockConfig<SlackResponse> = {
445445
manualChannel: { type: 'string', description: 'Manual channel identifier' },
446446
text: { type: 'string', description: 'Message text' },
447447
attachmentFiles: { type: 'json', description: 'Files to attach (UI upload)' },
448-
files: { type: 'json', description: 'Files to attach (UserFile array)' },
448+
files: { type: 'array', description: 'Files to attach (UserFile array)' },
449449
title: { type: 'string', description: 'Canvas title' },
450450
content: { type: 'string', description: 'Canvas content' },
451451
limit: { type: 'string', description: 'Message limit' },

apps/sim/blocks/blocks/telegram.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export const TelegramBlock: BlockConfig<TelegramResponse> = {
282282
type: 'json',
283283
description: 'Files to attach (UI upload)',
284284
},
285-
files: { type: 'json', description: 'Files to attach (UserFile array)' },
285+
files: { type: 'array', description: 'Files to attach (UserFile array)' },
286286
caption: { type: 'string', description: 'Caption for media' },
287287
messageId: { type: 'string', description: 'Message ID to delete' },
288288
},

0 commit comments

Comments
 (0)