@@ -2,6 +2,7 @@ import { createLogger } from '@sim/logger'
22import { useMutation , useQuery , useQueryClient } from '@tanstack/react-query'
33import type { WorkflowDeploymentVersionResponse } from '@/lib/workflows/persistence/utils'
44import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
5+ import { fetchDeploymentVersionState } from './workflows'
56
67const logger = createLogger ( 'DeploymentQueries' )
78
@@ -457,21 +458,14 @@ export function useGenerateVersionDescription() {
457458 '@/lib/workflows/comparison/compare'
458459 )
459460
460- const currentResponse = await fetch ( `/api/workflows/${ workflowId } /deployments/${ version } ` )
461- if ( ! currentResponse . ok ) {
462- throw new Error ( 'Failed to fetch current version state' )
463- }
464- const currentData = await currentResponse . json ( )
465- const currentState = currentData . deployedState
461+ const currentState = await fetchDeploymentVersionState ( workflowId , version )
466462
467463 let previousState = null
468464 if ( version > 1 ) {
469- const previousResponse = await fetch (
470- `/api/workflows/${ workflowId } /deployments/${ version - 1 } `
471- )
472- if ( previousResponse . ok ) {
473- const previousData = await previousResponse . json ( )
474- previousState = previousData . deployedState
465+ try {
466+ previousState = await fetchDeploymentVersionState ( workflowId , version - 1 )
467+ } catch {
468+ // Previous version may not exist, continue without it
475469 }
476470 }
477471
0 commit comments