Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { usePanelResize } from './use-panel-resize'
export { useRunWorkflow } from './use-run-workflow'
export { type UsageData, useUsageLimits } from './use-usage-limits'

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { createLogger } from '@/lib/logs/console/logger'
import { useRegisterGlobalCommands } from '@/app/workspace/[workspaceId]/providers/global-commands-provider'
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
import { Variables } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/variables/variables'
import { useWorkflowExecution } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-workflow-execution'
import { useDeleteWorkflow } from '@/app/workspace/[workspaceId]/w/hooks'
import { useChatStore } from '@/stores/chat/store'
import { usePanelStore } from '@/stores/panel-new/store'
Expand All @@ -35,7 +36,7 @@ import { useWorkflowJsonStore } from '@/stores/workflows/json/store'
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
import { Copilot, Deploy, Editor, Toolbar } from './components'
import { usePanelResize, useRunWorkflow, useUsageLimits } from './hooks'
import { usePanelResize, useUsageLimits } from './hooks'

const logger = createLogger('Panel')
/**
Expand Down Expand Up @@ -99,12 +100,43 @@ export function Panel() {
autoRefresh: !isRegistryLoading,
})

// Run workflow hook
const { runWorkflow, cancelWorkflow, isExecuting } = useRunWorkflow({ usageExceeded })
// Workflow execution hook
const { handleRunWorkflow, handleCancelExecution, isExecuting } = useWorkflowExecution()

// Panel resize hook
const { handleMouseDown } = usePanelResize()

/**
* Opens subscription settings modal
*/
const openSubscriptionSettings = () => {
if (typeof window !== 'undefined') {
window.dispatchEvent(
new CustomEvent('open-settings', {
detail: { tab: 'subscription' },
})
)
}
}

/**
* Runs the workflow with usage limit check
*/
const runWorkflow = useCallback(async () => {
if (usageExceeded) {
openSubscriptionSettings()
return
}
await handleRunWorkflow()
}, [usageExceeded, handleRunWorkflow])

/**
* Cancels the currently executing workflow
*/
const cancelWorkflow = useCallback(async () => {
await handleCancelExecution()
}, [handleCancelExecution])

// Chat state
const { isChatOpen, setIsChatOpen } = useChatStore()
const { isOpen: isVariablesOpen, setIsOpen: setVariablesOpen } = useVariablesStore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { type ConsoleEntry, useTerminalConsoleStore } from '@/stores/terminal'
import { useWorkflowDiffStore } from '@/stores/workflow-diff'
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
import { mergeSubblockState } from '@/stores/workflows/utils'
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
import { useCurrentWorkflow } from './use-current-workflow'

const logger = createLogger('useWorkflowExecution')
Expand Down Expand Up @@ -671,10 +672,14 @@ export function useWorkflowExecution() {
const executionWorkflowState =
hasActiveDiffWorkflow && executionDiffWorkflow ? executionDiffWorkflow : null
const usingDiffForExecution = executionWorkflowState !== null

// Read blocks and edges directly from store to ensure we get the latest state,
// even if React hasn't re-rendered yet after adding blocks/edges
const latestWorkflowState = useWorkflowStore.getState().getWorkflowState()
const workflowBlocks = (executionWorkflowState?.blocks ??
currentWorkflow.blocks) as typeof currentWorkflow.blocks
latestWorkflowState.blocks) as typeof currentWorkflow.blocks
const workflowEdges = (executionWorkflowState?.edges ??
currentWorkflow.edges) as typeof currentWorkflow.edges
latestWorkflowState.edges) as typeof currentWorkflow.edges

// Filter out blocks without type (these are layout-only blocks)
const validBlocks = Object.entries(workflowBlocks).reduce(
Expand Down