fix(workflow): lock chatflow start node from type change

This commit is contained in:
yyh
2026-02-13 12:56:49 +08:00
parent 086f6a2bb3
commit 0893c8531d
3 changed files with 14 additions and 1 deletions

View File

@@ -102,6 +102,7 @@ describe('workflow-app/useAvailableNodesMetaData', () => {
expect(nodeTypes).toContain(BlockEnum.TriggerPlugin)
expect(nodeTypes).not.toContain(BlockEnum.Answer)
expect(startNode?.metaData.isUndeletable).toBe(false)
expect(startNode?.metaData.isTypeFixed).toBe(false)
})
it('should include chatflow-only nodes when chat mode is enabled', () => {
@@ -117,6 +118,7 @@ describe('workflow-app/useAvailableNodesMetaData', () => {
expect(nodeTypes).not.toContain(BlockEnum.TriggerSchedule)
expect(nodeTypes).not.toContain(BlockEnum.TriggerPlugin)
expect(startNode?.metaData.isUndeletable).toBe(true)
expect(startNode?.metaData.isTypeFixed).toBe(true)
})
it('should hide sandbox-only nodes and keep agent when sandbox is disabled', () => {

View File

@@ -57,6 +57,7 @@ export const useAvailableNodesMetaData = () => {
metaData: {
...StartDefault.metaData,
isUndeletable: isChatMode, // start node is undeletable in chat mode, @use-nodes-interactions: handleNodeDelete function
isTypeFixed: isChatMode, // start node (user input) is immutable in chatflow mode
},
}), [isChatMode])

View File

@@ -63,6 +63,7 @@ import { checkMakeGroupAvailability } from './use-make-group'
import { useNodesMetaData } from './use-nodes-meta-data'
import { useNodesSyncDraft } from './use-nodes-sync-draft'
import {
useIsChatMode,
useNodesReadOnly,
useWorkflow,
useWorkflowReadOnly,
@@ -326,6 +327,7 @@ export const useNodesInteractions = () => {
const { store: workflowHistoryStore } = useWorkflowHistoryStore()
const { handleSyncWorkflowDraft } = useNodesSyncDraft()
const { getAfterNodesInSameBranch } = useWorkflow()
const isChatMode = useIsChatMode()
const { getNodesReadOnly } = useNodesReadOnly()
const { getWorkflowReadOnly } = useWorkflowReadOnly()
const { handleSetHelpline } = useHelpline()
@@ -1963,7 +1965,14 @@ export const useNodesInteractions = () => {
return
const { nodes, setNodes, edges, setEdges } = collaborativeWorkflow.getState()
const currentNode = nodes.find(node => node.id === currentNodeId)!
const currentNode = nodes.find(node => node.id === currentNodeId)
if (!currentNode)
return
// In chatflow mode, the Start (user input) node is immutable.
if (isChatMode && currentNode.data.type === BlockEnum.Start)
return
const connectedEdges = getConnectedEdges([currentNode], edges)
const nodesWithSameType = nodes.filter(
node => node.data.type === nodeType,
@@ -2051,6 +2060,7 @@ export const useNodesInteractions = () => {
})
},
[
isChatMode,
getNodesReadOnly,
collaborativeWorkflow,
handleSyncWorkflowDraft,