fix: added check for empty strings in executor to be treated as null, add debug logs for async workflow executions with agent response format

This commit is contained in:
Waleed Latif
2025-03-11 01:48:20 -07:00
parent 6985b2e174
commit 1959b3b2c8
6 changed files with 226 additions and 23 deletions

View File

@@ -272,9 +272,43 @@ export async function GET(req: NextRequest) {
workflowId: schedule.workflowId,
}
// Process the block states to ensure response formats are properly parsed
// This is crucial for agent blocks with response format
const processedBlockStates = Object.entries(currentBlockStates).reduce(
(acc, [blockId, blockState]) => {
// Check if this block has a responseFormat that needs to be parsed
if (blockState.responseFormat && typeof blockState.responseFormat === 'string') {
try {
console.log(
`[Schedule Debug] Block ${blockId} has responseFormat as string:`,
blockState.responseFormat
)
// Attempt to parse the responseFormat if it's a string
const parsedResponseFormat = JSON.parse(blockState.responseFormat)
console.log(
`[Schedule Debug] Successfully parsed responseFormat for block ${blockId}:`,
parsedResponseFormat
)
acc[blockId] = {
...blockState,
responseFormat: parsedResponseFormat,
}
} catch (error) {
console.warn(`Failed to parse responseFormat for block ${blockId}:`, error)
acc[blockId] = blockState
}
} else {
acc[blockId] = blockState
}
return acc
},
{} as Record<string, Record<string, any>>
)
const executor = new Executor(
serializedWorkflow,
currentBlockStates,
processedBlockStates, // Use the processed block states
decryptedEnvVars,
input
)

View File

@@ -277,9 +277,43 @@ export async function POST(
console.log('Executing workflow with workflowId:', foundWorkflow.id)
// Process the block states to ensure response formats are properly parsed
// This is crucial for agent blocks with response format
const processedBlockStates = Object.entries(currentBlockStates).reduce(
(acc, [blockId, blockState]) => {
// Check if this block has a responseFormat that needs to be parsed
if (blockState.responseFormat && typeof blockState.responseFormat === 'string') {
try {
console.log(
`[Webhook Debug] Block ${blockId} has responseFormat as string:`,
blockState.responseFormat
)
// Attempt to parse the responseFormat if it's a string
const parsedResponseFormat = JSON.parse(blockState.responseFormat)
console.log(
`[Webhook Debug] Successfully parsed responseFormat for block ${blockId}:`,
parsedResponseFormat
)
acc[blockId] = {
...blockState,
responseFormat: parsedResponseFormat,
}
} catch (error) {
console.warn(`Failed to parse responseFormat for block ${blockId}:`, error)
acc[blockId] = blockState
}
} else {
acc[blockId] = blockState
}
return acc
},
{} as Record<string, Record<string, any>>
)
const executor = new Executor(
serializedWorkflow,
currentBlockStates,
processedBlockStates, // Use the processed block states
decryptedEnvVars,
enrichedInput
)

View File

@@ -111,9 +111,43 @@ async function executeWorkflow(workflow: any, input?: any) {
}
}
// Process the block states to ensure response formats are properly parsed
// This is crucial for agent blocks with response format
const processedBlockStates = Object.entries(currentBlockStates).reduce(
(acc, [blockId, blockState]) => {
// Check if this block has a responseFormat that needs to be parsed
if (blockState.responseFormat && typeof blockState.responseFormat === 'string') {
try {
console.log(
`[API Debug] Block ${blockId} has responseFormat as string:`,
blockState.responseFormat
)
// Attempt to parse the responseFormat if it's a string
const parsedResponseFormat = JSON.parse(blockState.responseFormat)
console.log(
`[API Debug] Successfully parsed responseFormat for block ${blockId}:`,
parsedResponseFormat
)
acc[blockId] = {
...blockState,
responseFormat: parsedResponseFormat,
}
} catch (error) {
console.warn(`Failed to parse responseFormat for block ${blockId}:`, error)
acc[blockId] = blockState
}
} else {
acc[blockId] = blockState
}
return acc
},
{} as Record<string, Record<string, any>>
)
// Serialize and execute the workflow
const serializedWorkflow = new Serializer().serializeWorkflow(mergedStates, edges, loops)
const executor = new Executor(serializedWorkflow, currentBlockStates, decryptedEnvVars, input)
const executor = new Executor(serializedWorkflow, processedBlockStates, decryptedEnvVars, input)
const result = await executor.execute(workflowId)
// Log each execution step and the final result

View File

@@ -120,6 +120,20 @@ export function useWorkflowExecution() {
useSubBlockStore.getState().workflowValues[activeWorkflowId]
)
console.log('Merged Block States for Execution:', currentBlockStates)
// Debug any responseFormat fields
const blockWithResponseFormat = Object.entries(currentBlockStates).find(
([_id, state]) => state.responseFormat
)
if (blockWithResponseFormat) {
console.log(
'ResponseFormat found:',
blockWithResponseFormat[0],
typeof blockWithResponseFormat[1].responseFormat,
blockWithResponseFormat[1].responseFormat
)
}
console.groupEnd()
// Get environment variables