(
workflowId: string,
workflowState: WorkflowState,
options?: { updateLastSaved?: boolean }
)
| 43 | } |
| 44 | |
| 45 | export function applyWorkflowStateToStores( |
| 46 | workflowId: string, |
| 47 | workflowState: WorkflowState, |
| 48 | options?: { updateLastSaved?: boolean } |
| 49 | ) { |
| 50 | logger.debug('[applyWorkflowStateToStores] Applying state', { |
| 51 | workflowId, |
| 52 | blockCount: Object.keys(workflowState.blocks || {}).length, |
| 53 | edgeCount: workflowState.edges?.length ?? 0, |
| 54 | edgePreview: workflowState.edges?.slice(0, 3).map((e) => `${e.source} -> ${e.target}`), |
| 55 | }) |
| 56 | const workflowStore = useWorkflowStore.getState() |
| 57 | const cloned = cloneWorkflowState(workflowState) |
| 58 | logger.debug('[applyWorkflowStateToStores] Cloned state edges', { |
| 59 | clonedEdgeCount: cloned.edges?.length ?? 0, |
| 60 | }) |
| 61 | workflowStore.replaceWorkflowState(cloned, options) |
| 62 | const subBlockValues = extractSubBlockValues(workflowState) |
| 63 | useSubBlockStore.getState().setWorkflowValues(workflowId, subBlockValues) |
| 64 | if (Object.hasOwn(workflowState, 'variables')) { |
| 65 | applyWorkflowVariablesToStore(workflowId, workflowState.variables) |
| 66 | } |
| 67 | |
| 68 | // Verify what's in the store after apply |
| 69 | const afterState = workflowStore.getWorkflowState() |
| 70 | logger.info('[applyWorkflowStateToStores] Applied workflow state to stores', { |
| 71 | workflowId, |
| 72 | afterEdgeCount: afterState.edges?.length ?? 0, |
| 73 | }) |
| 74 | } |
| 75 | |
| 76 | export function applyWorkflowVariablesToStore( |
| 77 | workflowId: string, |
no test coverage detected