fix(resolver): json/array field parsing (#2074)

* fix(resolver): json/array field parsing

* remove comment
This commit is contained in:
Vikhyath Mondreti
2025-11-20 00:27:12 -08:00
committed by GitHub
parent 4d5c574363
commit 472aff5dd7
12 changed files with 45 additions and 80 deletions
+1 -1
View File
@@ -773,7 +773,7 @@ export const DiscordBlock: BlockConfig<DiscordResponse> = {
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.)' },
+2 -10
View File
@@ -187,11 +187,7 @@ export const FirecrawlBlock: BlockConfig<FirecrawlResponse> = {
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<FirecrawlResponse> = {
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
+1 -1
View File
@@ -462,7 +462,7 @@ export const GmailBlock: BlockConfig<GmailToolResponse> = {
},
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' },
+4 -23
View File
@@ -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) {
+6 -15
View File
@@ -148,23 +148,14 @@ export const Mem0Block: BlockConfig<Mem0Response> = {
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')
}
}
+1 -1
View File
@@ -442,7 +442,7 @@ export const MicrosoftTeamsBlock: BlockConfig<MicrosoftTeamsResponse> = {
},
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' },
+1 -1
View File
@@ -396,7 +396,7 @@ export const OutlookBlock: BlockConfig<OutlookResponse> = {
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' },
+1 -1
View File
@@ -360,7 +360,7 @@ export const SharepointBlock: BlockConfig<SharepointResponse> = {
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: {
+1 -1
View File
@@ -445,7 +445,7 @@ export const SlackBlock: BlockConfig<SlackResponse> = {
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' },
+1 -1
View File
@@ -282,7 +282,7 @@ export const TelegramBlock: BlockConfig<TelegramResponse> = {
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' },
},
+8 -25
View File
@@ -222,23 +222,14 @@ export const ZepBlock: BlockConfig<ZepResponse> = {
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<ZepResponse> = {
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
@@ -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 {