This commit is contained in:
Siddharth Ganesan
2025-07-08 21:33:39 -07:00
parent f1734766c3
commit cc249c2dd0
5 changed files with 19 additions and 48 deletions

View File

@@ -111,7 +111,6 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
loops: normalizedData.loops,
})
// Use normalized table data - reconstruct complete state object
// First get any existing state properties, then override with normalized data
const existingState =

View File

@@ -107,7 +107,7 @@ export function ImportControls({ disabled = false }: ImportControlsProps) {
}
// Create a new workflow
const newWorkflowId = await createWorkflow({
name: `Imported Workflow - ${new Date().toLocaleString()}`,
description: 'Workflow imported from YAML',
@@ -115,10 +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
const result = await importWorkflowFromYaml(
yamlContent,
{
// This avoids timing issues with workflow reload during navigation
const result = await importWorkflowFromYaml(
yamlContent,
{
addBlock: collaborativeAddBlock,
addEdge: collaborativeAddEdge,
applyAutoLayout: () => {

View File

@@ -69,8 +69,6 @@ export async function loadWorkflowFromNormalizedTables(
parentId,
extent,
}
})
// Convert edges to the expected format
@@ -95,20 +93,16 @@ export async function loadWorkflowFromNormalizedTables(
id: subflow.id,
...config,
}
} else if (subflow.type === SUBFLOW_TYPES.PARALLEL) {
parallels[subflow.id] = {
id: subflow.id,
...config,
}
} else {
logger.warn(`Unknown subflow type: ${subflow.type} for subflow ${subflow.id}`)
}
})
return {
blocks: blocksMap,
edges: edgesArray,
@@ -160,8 +154,6 @@ export async function saveWorkflowToNormalizedTables(
extent: block.data?.extent || null,
}))
await tx.insert(workflowBlocks).values(blockInserts)
}
@@ -223,8 +215,6 @@ export async function saveWorkflowToNormalizedTables(
hasActiveWebhook: state.hasActiveWebhook,
}
return {
success: true,
jsonBlob,
@@ -281,7 +271,6 @@ export async function migrateWorkflowToNormalizedTables(
const result = await saveWorkflowToNormalizedTables(workflowId, workflowState)
if (result.success) {
return { success: true }
}
return { success: false, error: result.error }

View File

@@ -474,7 +474,7 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
})
})
// Update subblock store for this workflow
// Update subblock store for this workflow
useSubBlockStore.setState((state) => ({
workflowValues: {
...state.workflowValues,

View File

@@ -351,8 +351,6 @@ export async function importWorkflowFromYaml(
},
targetWorkflowId?: string
): Promise<{ success: boolean; errors: string[]; warnings: string[]; summary?: string }> {
try {
// Parse YAML
const { data: yamlWorkflow, errors: parseErrors } = parseWorkflowYaml(yamlContent)
@@ -368,8 +366,6 @@ export async function importWorkflowFromYaml(
return { success: false, errors, warnings }
}
// Get the existing workflow state (to preserve starter blocks if they exist)
let existingBlocks: Record<string, any> = {}
@@ -380,19 +376,18 @@ export async function importWorkflowFromYaml(
if (response.ok) {
const workflowData = await response.json()
existingBlocks = workflowData.data?.state?.blocks || {}
}
} catch (error) {
logger.warn(`Failed to fetch existing blocks for workflow ${targetWorkflowId}:`, error)
}
} else {
// For active workflow, use from store
existingBlocks = workflowActions.getExistingBlocks()
} catch (error) {
logger.warn(`Failed to fetch existing blocks for workflow ${targetWorkflowId}:`, error)
}
const existingStarterBlocks = Object.values(existingBlocks).filter(
(block: any) => block.type === 'starter'
)
} else {
// For active workflow, use from store
existingBlocks = workflowActions.getExistingBlocks()
}
const existingStarterBlocks = Object.values(existingBlocks).filter(
(block: any) => block.type === 'starter'
)
// Get stores and current workflow info
const { useWorkflowStore } = require('@/stores/workflows/workflow/store')
@@ -407,8 +402,6 @@ export async function importWorkflowFromYaml(
return { success: false, errors: ['No active workflow'], warnings: [] }
}
// Build complete blocks object
const completeBlocks: Record<string, any> = {}
const completeSubBlockValues: Record<string, Record<string, any>> = {}
@@ -443,8 +436,6 @@ export async function importWorkflowFromYaml(
: {}),
...starterBlock.inputs, // Override with YAML values
}
} else {
// Create new starter block
starterBlockId = crypto.randomUUID()
@@ -478,8 +469,6 @@ export async function importWorkflowFromYaml(
// Set starter block values
completeSubBlockValues[starterBlockId] = { ...starterBlock.inputs }
}
}
}
@@ -488,7 +477,6 @@ export async function importWorkflowFromYaml(
let blocksProcessed = 0
for (const block of blocks) {
if (block.type === 'starter') {
continue // Already handled above
}
@@ -549,8 +537,6 @@ export async function importWorkflowFromYaml(
}
}
// Create complete edges using the ID mapping
const completeEdges: any[] = []
for (const edge of edges) {
@@ -563,7 +549,6 @@ export async function importWorkflowFromYaml(
source: sourceId,
target: targetId,
})
} else {
logger.warn(`Skipping edge - missing blocks: ${edge.source} -> ${edge.target}`)
}
@@ -597,7 +582,7 @@ export async function importWorkflowFromYaml(
hasActiveWebhook: false,
}
// Save directly to database via API
// Save directly to database via API
const response = await fetch(`/api/workflows/${activeWorkflowId}/state`, {
method: 'PUT',
headers: {
@@ -622,14 +607,14 @@ export async function importWorkflowFromYaml(
if (!targetWorkflowId) {
useWorkflowStore.setState(completeWorkflowState)
// Set subblock values in local store
// Set subblock values in local store
useSubBlockStore.setState((state: any) => ({
workflowValues: {
...state.workflowValues,
[activeWorkflowId]: completeSubBlockValues,
},
}))
}
}
// Brief delay for UI to update
await new Promise((resolve) => setTimeout(resolve, 100))
@@ -640,8 +625,6 @@ export async function importWorkflowFromYaml(
const totalBlocksCreated =
Object.keys(completeBlocks).length - (existingStarterBlocks.length > 0 ? 1 : 0)
return {
success: true,
errors: [],