Skip to content

Commit 42936c8

Browse files
fix(autoconnect): fixed autoconnect error for conditional block (#215)
* fix(autoconnect): fix bug where autoconnect didn't work for conditional block * improvement(ui): file upload * fix twilio block error * run format --------- Co-authored-by: Emir Karabeg <emirkarabeg@berkeley.edu>
1 parent da7c7e3 commit 42936c8

File tree

35 files changed

+730
-626
lines changed

35 files changed

+730
-626
lines changed

sim/app/api/schedules/execute/route.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export async function GET(req: NextRequest) {
320320
)
321321

322322
logger.info(`[${requestId}] Executing workflow ${schedule.workflowId}`)
323-
323+
324324
// Get workflow variables
325325
let workflowVariables = {}
326326
if (workflowRecord.variables) {
@@ -332,15 +332,20 @@ export async function GET(req: NextRequest) {
332332
// Otherwise use as is (already parsed JSON)
333333
workflowVariables = workflowRecord.variables
334334
}
335-
logger.debug(`[${requestId}] Loaded ${Object.keys(workflowVariables).length} workflow variables for: ${schedule.workflowId}`)
335+
logger.debug(
336+
`[${requestId}] Loaded ${Object.keys(workflowVariables).length} workflow variables for: ${schedule.workflowId}`
337+
)
336338
} catch (error) {
337-
logger.error(`[${requestId}] Failed to parse workflow variables: ${schedule.workflowId}`, error)
339+
logger.error(
340+
`[${requestId}] Failed to parse workflow variables: ${schedule.workflowId}`,
341+
error
342+
)
338343
// Continue execution even if variables can't be parsed
339344
}
340345
} else {
341346
logger.debug(`[${requestId}] No workflow variables found for: ${schedule.workflowId}`)
342347
}
343-
348+
344349
const executor = new Executor(
345350
serializedWorkflow,
346351
processedBlockStates, // Use the processed block states

sim/app/api/webhooks/trigger/[path]/route.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,14 @@ async function processWebhook(
631631
// Otherwise use as is (already parsed JSON)
632632
workflowVariables = foundWorkflow.variables
633633
}
634-
logger.debug(`[${requestId}] Loaded ${Object.keys(workflowVariables).length} workflow variables for: ${foundWorkflow.id}`)
634+
logger.debug(
635+
`[${requestId}] Loaded ${Object.keys(workflowVariables).length} workflow variables for: ${foundWorkflow.id}`
636+
)
635637
} catch (error) {
636-
logger.error(`[${requestId}] Failed to parse workflow variables: ${foundWorkflow.id}`, error)
638+
logger.error(
639+
`[${requestId}] Failed to parse workflow variables: ${foundWorkflow.id}`,
640+
error
641+
)
637642
// Continue execution even if variables can't be parsed
638643
}
639644
} else {

sim/app/api/workflows/[id]/execute/route.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,16 @@ describe('Workflow Execution API Route', () => {
260260

261261
// Verify execute was called with the input body
262262
expect(executeMock).toHaveBeenCalledWith('workflow-id')
263-
263+
264264
// Updated expectations to match actual implementation
265265
// The structure should match: serializedWorkflow, processedBlockStates, decryptedEnvVars, processedInput, workflowVariables
266266
expect(Executor).toHaveBeenCalledWith(
267267
expect.anything(), // serializedWorkflow
268268
expect.anything(), // processedBlockStates
269269
expect.anything(), // decryptedEnvVars
270-
expect.objectContaining({ // processedInput
271-
input: requestBody
270+
expect.objectContaining({
271+
// processedInput
272+
input: requestBody,
272273
}),
273274
expect.anything() // workflowVariables
274275
)
@@ -313,8 +314,9 @@ describe('Workflow Execution API Route', () => {
313314
expect.anything(), // serializedWorkflow
314315
expect.anything(), // processedBlockStates
315316
expect.anything(), // decryptedEnvVars
316-
expect.objectContaining({ // processedInput
317-
input: structuredInput
317+
expect.objectContaining({
318+
// processedInput
319+
input: structuredInput,
318320
}),
319321
expect.anything() // workflowVariables
320322
)
@@ -463,8 +465,8 @@ describe('Workflow Execution API Route', () => {
463465
it('should pass workflow variables to the Executor', async () => {
464466
// Create mock variables for the workflow
465467
const workflowVariables = {
466-
'variable1': { id: 'var1', name: 'variable1', type: 'string', value: '"test value"' },
467-
'variable2': { id: 'var2', name: 'variable2', type: 'boolean', value: 'true' }
468+
variable1: { id: 'var1', name: 'variable1', type: 'string', value: '"test value"' },
469+
variable2: { id: 'var2', name: 'variable2', type: 'boolean', value: 'true' },
468470
}
469471

470472
// Mock workflow with variables
@@ -539,15 +541,15 @@ describe('Workflow Execution API Route', () => {
539541

540542
// Verify the Executor was constructed with workflow variables
541543
expect(executorConstructorMock).toHaveBeenCalled()
542-
544+
543545
// Check that the 5th parameter (workflow variables) was passed
544546
const executorCalls = executorConstructorMock.mock.calls
545547
expect(executorCalls.length).toBeGreaterThan(0)
546-
548+
547549
// Each call to the constructor should have at least 5 parameters
548550
const lastCall = executorCalls[executorCalls.length - 1]
549551
expect(lastCall.length).toBeGreaterThanOrEqual(5)
550-
552+
551553
// The 5th parameter should be the workflow variables
552554
expect(lastCall[4]).toEqual(workflowVariables)
553555
})

sim/app/api/workflows/[id]/execute/route.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,22 @@ async function executeWorkflow(workflow: any, requestId: string, input?: any) {
3838
}
3939

4040
// Log input to help debug
41-
logger.info(`[${requestId}] Executing workflow with input:`,
42-
input ? JSON.stringify(input, null, 2) : 'No input provided');
43-
41+
logger.info(
42+
`[${requestId}] Executing workflow with input:`,
43+
input ? JSON.stringify(input, null, 2) : 'No input provided'
44+
)
45+
4446
// Validate and structure input for maximum compatibility
45-
let processedInput = input;
47+
let processedInput = input
4648
if (input && typeof input === 'object') {
4749
// Ensure input is properly structured for the starter block
4850
if (input.input === undefined) {
4951
// If input is not already nested, structure it properly
50-
processedInput = { input: input };
51-
logger.info(`[${requestId}] Restructured input for workflow:`, JSON.stringify(processedInput, null, 2));
52+
processedInput = { input: input }
53+
logger.info(
54+
`[${requestId}] Restructured input for workflow:`,
55+
JSON.stringify(processedInput, null, 2)
56+
)
5257
}
5358
}
5459

@@ -174,7 +179,9 @@ async function executeWorkflow(workflow: any, requestId: string, input?: any) {
174179
// Otherwise use as is (already parsed JSON)
175180
workflowVariables = workflow.variables
176181
}
177-
logger.debug(`[${requestId}] Loaded ${Object.keys(workflowVariables).length} workflow variables for: ${workflowId}`)
182+
logger.debug(
183+
`[${requestId}] Loaded ${Object.keys(workflowVariables).length} workflow variables for: ${workflowId}`
184+
)
178185
} catch (error) {
179186
logger.error(`[${requestId}] Failed to parse workflow variables: ${workflowId}`, error)
180187
// Continue execution even if variables can't be parsed
@@ -188,13 +195,13 @@ async function executeWorkflow(workflow: any, requestId: string, input?: any) {
188195
const serializedWorkflow = new Serializer().serializeWorkflow(mergedStates, edges, loops)
189196

190197
const executor = new Executor(
191-
serializedWorkflow,
192-
processedBlockStates,
193-
decryptedEnvVars,
194-
processedInput,
198+
serializedWorkflow,
199+
processedBlockStates,
200+
decryptedEnvVars,
201+
processedInput,
195202
workflowVariables
196203
)
197-
204+
198205
const result = await executor.execute(workflowId)
199206

200207
logger.info(`[${requestId}] Workflow execution completed: ${workflowId}`, {
@@ -278,7 +285,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
278285

279286
const bodyText = await request.text()
280287
logger.info(`[${requestId}] Raw request body:`, bodyText)
281-
288+
282289
let body = {}
283290
if (bodyText && bodyText.trim()) {
284291
try {
@@ -293,9 +300,9 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
293300
}
294301

295302
// Don't double-nest the input if it's already structured
296-
const hasContent = Object.keys(body).length > 0;
297-
const input = hasContent ? { input: body } : {};
298-
303+
const hasContent = Object.keys(body).length > 0
304+
const input = hasContent ? { input: body } : {}
305+
299306
logger.info(`[${requestId}] Input passed to workflow:`, JSON.stringify(input, null, 2))
300307

301308
// Execute workflow with the structured input

sim/app/w/[id]/components/workflow-block/components/sub-block/hooks/use-sub-block-value.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useCallback, useEffect, useRef } from 'react'
2+
import { isEqual } from 'lodash'
23
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
34
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
4-
import { isEqual } from 'lodash'
55

66
/**
77
* Custom hook to get and set values for a sub-block in a workflow.
88
* Handles complex object values properly by using deep equality comparison.
9-
*
9+
*
1010
* @param blockId The ID of the block containing the sub-block
1111
* @param subBlockId The ID of the sub-block
1212
* @param triggerWorkflowUpdate Whether to trigger a workflow update when the value changes
@@ -30,10 +30,7 @@ export function useSubBlockValue<T = any>(
3030

3131
// Get value from subblock store
3232
const storeValue = useSubBlockStore(
33-
useCallback(
34-
(state) => state.getValue(blockId, subBlockId),
35-
[blockId, subBlockId]
36-
)
33+
useCallback((state) => state.getValue(blockId, subBlockId), [blockId, subBlockId])
3734
)
3835

3936
// Update the ref if the store value changes
@@ -51,16 +48,19 @@ export function useSubBlockValue<T = any>(
5148
// Use deep comparison to avoid unnecessary updates for complex objects
5249
if (!isEqual(valueRef.current, newValue)) {
5350
valueRef.current = newValue
54-
51+
5552
// Ensure we're passing the actual value, not a reference that might change
56-
const valueCopy = newValue === null
57-
? null
58-
: (typeof newValue === 'object' ? JSON.parse(JSON.stringify(newValue)) : newValue)
59-
53+
const valueCopy =
54+
newValue === null
55+
? null
56+
: typeof newValue === 'object'
57+
? JSON.parse(JSON.stringify(newValue))
58+
: newValue
59+
6060
// Update the subblock store with the new value
6161
// The store's setValue method will now trigger the debounced sync automatically
6262
useSubBlockStore.getState().setValue(blockId, subBlockId, valueCopy)
63-
63+
6464
if (triggerWorkflowUpdate) {
6565
useWorkflowStore.getState().triggerUpdate()
6666
}

0 commit comments

Comments
 (0)