mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-28 03:00:29 -04:00
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:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user