From f1734766c3ac2bb0317e1cbf54fc42d701d843f7 Mon Sep 17 00:00:00 2001 From: Siddharth Ganesan Date: Tue, 8 Jul 2025 21:33:33 -0700 Subject: [PATCH] Remove logs --- apps/sim/app/api/workflows/[id]/route.ts | 10 +-- .../sim/app/api/workflows/[id]/state/route.ts | 12 --- .../import-controls/import-controls.tsx | 11 ++- apps/sim/lib/workflows/db-helpers.ts | 31 ++----- apps/sim/stores/workflows/registry/store.ts | 12 +-- apps/sim/stores/workflows/yaml/importer.ts | 85 +++++-------------- 6 files changed, 37 insertions(+), 124 deletions(-) diff --git a/apps/sim/app/api/workflows/[id]/route.ts b/apps/sim/app/api/workflows/[id]/route.ts index 1139b2b62a..1ffd745140 100644 --- a/apps/sim/app/api/workflows/[id]/route.ts +++ b/apps/sim/app/api/workflows/[id]/route.ts @@ -111,15 +111,7 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{ loops: normalizedData.loops, }) - // Debug: Log sample block data from normalized tables - const sampleBlockId = Object.keys(normalizedData.blocks)[0] - if (sampleBlockId) { - logger.debug(`[${requestId}] Sample block from normalized tables:`, { - blockId: sampleBlockId, - block: normalizedData.blocks[sampleBlockId], - subBlocks: normalizedData.blocks[sampleBlockId]?.subBlocks, - }) - } + // Use normalized table data - reconstruct complete state object // First get any existing state properties, then override with normalized data const existingState = diff --git a/apps/sim/app/api/workflows/[id]/state/route.ts b/apps/sim/app/api/workflows/[id]/state/route.ts index cb992331f7..3b6c058e04 100644 --- a/apps/sim/app/api/workflows/[id]/state/route.ts +++ b/apps/sim/app/api/workflows/[id]/state/route.ts @@ -86,18 +86,6 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{ } // Save to normalized tables - logger.info(`[${requestId}] Saving workflow ${workflowId} state to normalized tables`) - - // Debug: Log sample block data being received - const sampleBlockId = Object.keys(state.blocks)[0] - if (sampleBlockId) { - logger.debug(`[${requestId}] Sample block data received:`, { - blockId: sampleBlockId, - block: state.blocks[sampleBlockId], - subBlocks: state.blocks[sampleBlockId]?.subBlocks, - }) - } - // Ensure all required fields are present for WorkflowState type const workflowState = { blocks: state.blocks, diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/control-bar/components/import-controls/import-controls.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/control-bar/components/import-controls/import-controls.tsx index cacf63881c..2e1dd512d9 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/control-bar/components/import-controls/import-controls.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/control-bar/components/import-controls/import-controls.tsx @@ -107,7 +107,7 @@ export function ImportControls({ disabled = false }: ImportControlsProps) { } // Create a new workflow - logger.info('Creating new workflow for YAML import') + const newWorkflowId = await createWorkflow({ name: `Imported Workflow - ${new Date().toLocaleString()}`, description: 'Workflow imported from YAML', @@ -115,11 +115,10 @@ export function ImportControls({ disabled = false }: ImportControlsProps) { }) // Import the YAML into the new workflow BEFORE navigation (creates complete state and saves directly to DB) - // This avoids timing issues with workflow reload during navigation - logger.info('Importing YAML into new workflow before navigation') - const result = await importWorkflowFromYaml( - yamlContent, - { + // This avoids timing issues with workflow reload during navigation + const result = await importWorkflowFromYaml( + yamlContent, + { addBlock: collaborativeAddBlock, addEdge: collaborativeAddEdge, applyAutoLayout: () => { diff --git a/apps/sim/lib/workflows/db-helpers.ts b/apps/sim/lib/workflows/db-helpers.ts index 4f460794c1..b3e4a8df2b 100644 --- a/apps/sim/lib/workflows/db-helpers.ts +++ b/apps/sim/lib/workflows/db-helpers.ts @@ -70,13 +70,7 @@ export async function loadWorkflowFromNormalizedTables( extent, } - // Debug: Log sample block subBlocks from database - if (block.type === 'agent') { - logger.debug(`Loaded ${block.type} block from database:`, { - blockId: block.id, - subBlocks: block.subBlocks, - }) - } + }) // Convert edges to the expected format @@ -101,23 +95,19 @@ export async function loadWorkflowFromNormalizedTables( id: subflow.id, ...config, } - logger.debug( - `[DB-HELPERS] Loaded loop ${subflow.id} with iterations: ${loopConfig.iterations || 'unknown'}` - ) + } else if (subflow.type === SUBFLOW_TYPES.PARALLEL) { parallels[subflow.id] = { id: subflow.id, ...config, } - logger.debug(`[DB-HELPERS] Loaded parallel ${subflow.id}`) + } else { logger.warn(`Unknown subflow type: ${subflow.type} for subflow ${subflow.id}`) } }) - logger.info( - `Loaded workflow ${workflowId} from normalized tables: ${blocks.length} blocks, ${edges.length} edges, ${subflows.length} subflows` - ) + return { blocks: blocksMap, @@ -170,14 +160,7 @@ export async function saveWorkflowToNormalizedTables( extent: block.data?.extent || null, })) - // Debug: Log sample block insert data - if (blockInserts.length > 0) { - logger.debug(`Saving ${blockInserts.length} blocks. Sample block:`, { - blockId: blockInserts[0].id, - type: blockInserts[0].type, - subBlocks: blockInserts[0].subBlocks, - }) - } + await tx.insert(workflowBlocks).values(blockInserts) } @@ -240,7 +223,7 @@ export async function saveWorkflowToNormalizedTables( hasActiveWebhook: state.hasActiveWebhook, } - logger.info(`Successfully saved workflow ${workflowId} to normalized tables`) + return { success: true, @@ -298,7 +281,7 @@ export async function migrateWorkflowToNormalizedTables( const result = await saveWorkflowToNormalizedTables(workflowId, workflowState) if (result.success) { - logger.info(`Successfully migrated workflow ${workflowId} to normalized tables`) + return { success: true } } return { success: false, error: result.error } diff --git a/apps/sim/stores/workflows/registry/store.ts b/apps/sim/stores/workflows/registry/store.ts index a2b55d6cbe..77e327afcd 100644 --- a/apps/sim/stores/workflows/registry/store.ts +++ b/apps/sim/stores/workflows/registry/store.ts @@ -474,23 +474,13 @@ export const useWorkflowRegistry = create()( }) }) - // Debug: Log what values are being extracted from the database - logger.debug( - `Extracted subblock values from database for workflow ${id}:`, - subblockValues - ) - - // Update subblock store for this workflow + // Update subblock store for this workflow useSubBlockStore.setState((state) => ({ workflowValues: { ...state.workflowValues, [id]: subblockValues, }, })) - - // Debug: Verify SubBlockStore was updated - const updatedValues = useSubBlockStore.getState().workflowValues[id] - logger.debug(`SubBlockStore updated for workflow ${id}:`, updatedValues) } else { // If no state in DB, use empty state - server should have created start block workflowState = { diff --git a/apps/sim/stores/workflows/yaml/importer.ts b/apps/sim/stores/workflows/yaml/importer.ts index 3a357e7e5e..0a82f176f7 100644 --- a/apps/sim/stores/workflows/yaml/importer.ts +++ b/apps/sim/stores/workflows/yaml/importer.ts @@ -351,7 +351,7 @@ export async function importWorkflowFromYaml( }, targetWorkflowId?: string ): Promise<{ success: boolean; errors: string[]; warnings: string[]; summary?: string }> { - logger.info('Starting YAML workflow import (complete state creation)') + try { // Parse YAML @@ -368,13 +368,7 @@ export async function importWorkflowFromYaml( return { success: false, errors, warnings } } - logger.info( - `Creating complete workflow state with ${blocks.length} blocks and ${edges.length} edges` - ) - logger.debug( - 'Blocks to import:', - blocks.map((b) => `${b.id} (${b.type}): ${b.name}`) - ) + // Get the existing workflow state (to preserve starter blocks if they exist) let existingBlocks: Record = {} @@ -386,23 +380,19 @@ export async function importWorkflowFromYaml( if (response.ok) { const workflowData = await response.json() existingBlocks = workflowData.data?.state?.blocks || {} - logger.debug( - `Fetched existing blocks for target workflow ${targetWorkflowId}:`, - Object.keys(existingBlocks) - ) + } - } catch (error) { - logger.warn(`Failed to fetch existing blocks for workflow ${targetWorkflowId}:`, error) + } catch (error) { + logger.warn(`Failed to fetch existing blocks for workflow ${targetWorkflowId}:`, error) + } + } else { + // For active workflow, use from store + existingBlocks = workflowActions.getExistingBlocks() } - } else { - // For active workflow, use from store - existingBlocks = workflowActions.getExistingBlocks() - } - - const existingStarterBlocks = Object.values(existingBlocks).filter( - (block: any) => block.type === 'starter' - ) - logger.debug(`Found ${existingStarterBlocks.length} existing starter blocks`) + + const existingStarterBlocks = Object.values(existingBlocks).filter( + (block: any) => block.type === 'starter' + ) // Get stores and current workflow info const { useWorkflowStore } = require('@/stores/workflows/workflow/store') @@ -417,9 +407,7 @@ export async function importWorkflowFromYaml( return { success: false, errors: ['No active workflow'], warnings: [] } } - logger.info( - `Importing YAML into workflow: ${activeWorkflowId} ${targetWorkflowId ? '(specified target)' : '(active workflow)'}` - ) + // Build complete blocks object const completeBlocks: Record = {} @@ -456,7 +444,7 @@ export async function importWorkflowFromYaml( ...starterBlock.inputs, // Override with YAML values } - logger.debug(`Using existing starter block: ${existingStarter.id}`) + } else { // Create new starter block starterBlockId = crypto.randomUUID() @@ -491,7 +479,7 @@ export async function importWorkflowFromYaml( // Set starter block values completeSubBlockValues[starterBlockId] = { ...starterBlock.inputs } - logger.debug(`Created new starter block: ${starterBlockId}`) + } } } @@ -500,7 +488,7 @@ export async function importWorkflowFromYaml( let blocksProcessed = 0 for (const block of blocks) { if (block.type === 'starter') { - logger.debug(`Skipping starter block: ${block.id} (already handled)`) + continue // Already handled above } @@ -528,7 +516,6 @@ export async function importWorkflowFromYaml( completeSubBlockValues[blockId] = { ...block.inputs } blocksProcessed++ - logger.debug(`Prepared ${block.type} block: ${blockId} -> ${block.name}`) } else if (blockConfig) { // Handle regular blocks const subBlocks: Record = {} @@ -557,15 +544,12 @@ export async function importWorkflowFromYaml( // Set block input values completeSubBlockValues[blockId] = { ...block.inputs } blocksProcessed++ - logger.debug(`Prepared ${block.type} block: ${blockId} -> ${block.name}`) } else { logger.warn(`No block config found for type: ${block.type} (block: ${block.id})`) } } - logger.info( - `Processed ${blocksProcessed} non-starter blocks, total blocks in state: ${Object.keys(completeBlocks).length}` - ) + // Create complete edges using the ID mapping const completeEdges: any[] = [] @@ -579,14 +563,13 @@ export async function importWorkflowFromYaml( source: sourceId, target: targetId, }) - logger.debug(`Prepared edge: ${sourceId} -> ${targetId}`) + } else { logger.warn(`Skipping edge - missing blocks: ${edge.source} -> ${edge.target}`) } } // Create complete workflow state with values already set in subBlocks - logger.info('Creating complete workflow state with embedded values...') // Merge subblock values directly into block subBlocks for (const [blockId, blockData] of Object.entries(completeBlocks)) { @@ -596,9 +579,6 @@ export async function importWorkflowFromYaml( for (const [subBlockId, subBlockData] of Object.entries(blockData.subBlocks || {})) { if (blockValues[subBlockId] !== undefined && blockValues[subBlockId] !== null) { ;(subBlockData as any).value = blockValues[subBlockId] - logger.debug( - `Embedded value in block: ${blockId}.${subBlockId} = ${blockValues[subBlockId]}` - ) } } } @@ -617,14 +597,7 @@ export async function importWorkflowFromYaml( hasActiveWebhook: false, } - // Save directly to database via API - logger.info('Saving complete workflow state directly to database...') - logger.debug('Sample block being saved:', { - firstBlockId: Object.keys(completeBlocks)[0], - firstBlock: Object.values(completeBlocks)[0], - firstBlockSubBlocks: Object.values(completeBlocks)[0]?.subBlocks, - }) - + // Save directly to database via API const response = await fetch(`/api/workflows/${activeWorkflowId}/state`, { method: 'PUT', headers: { @@ -644,42 +617,30 @@ export async function importWorkflowFromYaml( } const saveResponse = await response.json() - logger.info('Successfully saved to database:', saveResponse) // Update local state for immediate UI display (only if importing into active workflow) if (!targetWorkflowId) { - logger.info('Updating local state for immediate display (active workflow)...') useWorkflowStore.setState(completeWorkflowState) - // Set subblock values in local store - logger.debug('Setting SubBlockStore with values:', completeSubBlockValues) + // Set subblock values in local store useSubBlockStore.setState((state: any) => ({ workflowValues: { ...state.workflowValues, [activeWorkflowId]: completeSubBlockValues, }, })) - - // Verify SubBlockStore was updated - const subBlockStoreValues = useSubBlockStore.getState().workflowValues[activeWorkflowId] - logger.debug('SubBlockStore after update:', subBlockStoreValues) - } else { - logger.info('Skipping local state update (importing into non-active workflow)') - } + } // Brief delay for UI to update await new Promise((resolve) => setTimeout(resolve, 100)) // Apply auto layout - logger.info('Applying auto layout...') workflowActions.applyAutoLayout() const totalBlocksCreated = Object.keys(completeBlocks).length - (existingStarterBlocks.length > 0 ? 1 : 0) - logger.info( - `Successfully imported workflow: ${totalBlocksCreated} blocks created, ${completeEdges.length} edges, values set for ${Object.keys(completeSubBlockValues).length} blocks` - ) + return { success: true,