mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
Lint
This commit is contained in:
@@ -110,14 +110,14 @@ export async function GET(request: NextRequest, { params }: { params: Promise<{
|
||||
parallelsCount: Object.keys(normalizedData.parallels).length,
|
||||
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
|
||||
subBlocks: normalizedData.blocks[sampleBlockId]?.subBlocks,
|
||||
})
|
||||
}
|
||||
// Use normalized table data - reconstruct complete state object
|
||||
|
||||
@@ -85,19 +85,19 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
|
||||
return NextResponse.json({ error: 'Access denied' }, { status: 403 })
|
||||
}
|
||||
|
||||
// Save to normalized tables
|
||||
// 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
|
||||
subBlocks: state.blocks[sampleBlockId]?.subBlocks,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// Ensure all required fields are present for WorkflowState type
|
||||
const workflowState = {
|
||||
blocks: state.blocks,
|
||||
@@ -111,7 +111,7 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
|
||||
hasActiveSchedule: state.hasActiveSchedule || false,
|
||||
hasActiveWebhook: state.hasActiveWebhook || false,
|
||||
}
|
||||
|
||||
|
||||
const saveResult = await saveWorkflowToNormalizedTables(workflowId, workflowState)
|
||||
|
||||
if (!saveResult.success) {
|
||||
|
||||
+19
-15
@@ -117,22 +117,26 @@ 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, {
|
||||
addBlock: collaborativeAddBlock,
|
||||
addEdge: collaborativeAddEdge,
|
||||
applyAutoLayout: () => {
|
||||
// Trigger auto layout
|
||||
window.dispatchEvent(new CustomEvent('trigger-auto-layout'))
|
||||
const result = await importWorkflowFromYaml(
|
||||
yamlContent,
|
||||
{
|
||||
addBlock: collaborativeAddBlock,
|
||||
addEdge: collaborativeAddEdge,
|
||||
applyAutoLayout: () => {
|
||||
// Trigger auto layout
|
||||
window.dispatchEvent(new CustomEvent('trigger-auto-layout'))
|
||||
},
|
||||
setSubBlockValue: (blockId: string, subBlockId: string, value: any) => {
|
||||
// Use the collaborative function - the same one called when users type into fields
|
||||
collaborativeSetSubblockValue(blockId, subBlockId, value)
|
||||
},
|
||||
getExistingBlocks: () => {
|
||||
// For a new workflow, we'll get the starter block from the server
|
||||
return {}
|
||||
},
|
||||
},
|
||||
setSubBlockValue: (blockId: string, subBlockId: string, value: any) => {
|
||||
// Use the collaborative function - the same one called when users type into fields
|
||||
collaborativeSetSubblockValue(blockId, subBlockId, value)
|
||||
},
|
||||
getExistingBlocks: () => {
|
||||
// For a new workflow, we'll get the starter block from the server
|
||||
return {}
|
||||
},
|
||||
}, newWorkflowId) // Pass the new workflow ID to import into
|
||||
newWorkflowId
|
||||
) // Pass the new workflow ID to import into
|
||||
|
||||
// Navigate to the new workflow AFTER import is complete
|
||||
if (result.success) {
|
||||
|
||||
@@ -69,12 +69,12 @@ export async function loadWorkflowFromNormalizedTables(
|
||||
parentId,
|
||||
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
|
||||
subBlocks: block.subBlocks,
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -175,7 +175,7 @@ export async function saveWorkflowToNormalizedTables(
|
||||
logger.debug(`Saving ${blockInserts.length} blocks. Sample block:`, {
|
||||
blockId: blockInserts[0].id,
|
||||
type: blockInserts[0].type,
|
||||
subBlocks: blockInserts[0].subBlocks
|
||||
subBlocks: blockInserts[0].subBlocks,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -475,7 +475,10 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
|
||||
})
|
||||
|
||||
// Debug: Log what values are being extracted from the database
|
||||
logger.debug(`Extracted subblock values from database for workflow ${id}:`, subblockValues)
|
||||
logger.debug(
|
||||
`Extracted subblock values from database for workflow ${id}:`,
|
||||
subblockValues
|
||||
)
|
||||
|
||||
// Update subblock store for this workflow
|
||||
useSubBlockStore.setState((state) => ({
|
||||
@@ -484,7 +487,7 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
|
||||
[id]: subblockValues,
|
||||
},
|
||||
}))
|
||||
|
||||
|
||||
// Debug: Verify SubBlockStore was updated
|
||||
const updatedValues = useSubBlockStore.getState().workflowValues[id]
|
||||
logger.debug(`SubBlockStore updated for workflow ${id}:`, updatedValues)
|
||||
|
||||
@@ -378,7 +378,7 @@ export async function importWorkflowFromYaml(
|
||||
|
||||
// Get the existing workflow state (to preserve starter blocks if they exist)
|
||||
let existingBlocks: Record<string, any> = {}
|
||||
|
||||
|
||||
if (targetWorkflowId) {
|
||||
// For target workflow, fetch from API
|
||||
try {
|
||||
@@ -386,7 +386,10 @@ 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))
|
||||
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)
|
||||
@@ -395,7 +398,7 @@ export async function importWorkflowFromYaml(
|
||||
// For active workflow, use from store
|
||||
existingBlocks = workflowActions.getExistingBlocks()
|
||||
}
|
||||
|
||||
|
||||
const existingStarterBlocks = Object.values(existingBlocks).filter(
|
||||
(block: any) => block.type === 'starter'
|
||||
)
|
||||
@@ -413,8 +416,10 @@ export async function importWorkflowFromYaml(
|
||||
if (!activeWorkflowId) {
|
||||
return { success: false, errors: ['No active workflow'], warnings: [] }
|
||||
}
|
||||
|
||||
logger.info(`Importing YAML into workflow: ${activeWorkflowId} ${targetWorkflowId ? '(specified target)' : '(active workflow)'}`)
|
||||
|
||||
logger.info(
|
||||
`Importing YAML into workflow: ${activeWorkflowId} ${targetWorkflowId ? '(specified target)' : '(active workflow)'}`
|
||||
)
|
||||
|
||||
// Build complete blocks object
|
||||
const completeBlocks: Record<string, any> = {}
|
||||
@@ -615,11 +620,11 @@ export async function importWorkflowFromYaml(
|
||||
// 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],
|
||||
firstBlockId: Object.keys(completeBlocks)[0],
|
||||
firstBlock: Object.values(completeBlocks)[0],
|
||||
firstBlockSubBlocks: Object.values(completeBlocks)[0]?.subBlocks
|
||||
firstBlockSubBlocks: Object.values(completeBlocks)[0]?.subBlocks,
|
||||
})
|
||||
|
||||
|
||||
const response = await fetch(`/api/workflows/${activeWorkflowId}/state`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
@@ -654,7 +659,7 @@ export async function importWorkflowFromYaml(
|
||||
[activeWorkflowId]: completeSubBlockValues,
|
||||
},
|
||||
}))
|
||||
|
||||
|
||||
// Verify SubBlockStore was updated
|
||||
const subBlockStoreValues = useSubBlockStore.getState().workflowValues[activeWorkflowId]
|
||||
logger.debug('SubBlockStore after update:', subBlockStoreValues)
|
||||
|
||||
Reference in New Issue
Block a user