feat: implement edge source handle change functionality and enhance node interactions for HumanInput node

This commit is contained in:
twwu
2025-12-30 16:05:33 +08:00
parent 0e2b59d661
commit 44a688cb81
9 changed files with 80 additions and 1 deletions

View File

@ -151,11 +151,65 @@ export const useEdgesInteractions = () => {
setEdges(newEdges)
}, [store, getNodesReadOnly])
const handleEdgeSourceHandleChange = useCallback((nodeId: string, oldHandleId: string, newHandleId: string) => {
if (getNodesReadOnly())
return
const { getNodes, setNodes, edges, setEdges } = store.getState()
const nodes = getNodes()
// Find edges connected to the old handle
const affectedEdges = edges.filter(
edge => edge.source === nodeId && edge.sourceHandle === oldHandleId,
)
if (affectedEdges.length === 0)
return
// Update node metadata: remove old handle, add new handle
const nodesConnectedSourceOrTargetHandleIdsMap = getNodesConnectedSourceOrTargetHandleIdsMap(
[
...affectedEdges.map(edge => ({ type: 'remove', edge })),
...affectedEdges.map(edge => ({
type: 'add',
edge: { ...edge, sourceHandle: newHandleId },
})),
],
nodes,
)
const newNodes = produce(nodes, (draft: Node[]) => {
draft.forEach((node) => {
if (nodesConnectedSourceOrTargetHandleIdsMap[node.id]) {
node.data = {
...node.data,
...nodesConnectedSourceOrTargetHandleIdsMap[node.id],
}
}
})
})
setNodes(newNodes)
// Update edges to use new sourceHandle and regenerate edge IDs
const newEdges = produce(edges, (draft) => {
draft.forEach((edge) => {
if (edge.source === nodeId && edge.sourceHandle === oldHandleId) {
edge.sourceHandle = newHandleId
edge.id = `${edge.source}-${newHandleId}-${edge.target}-${edge.targetHandle}`
}
})
})
setEdges(newEdges)
handleSyncWorkflowDraft()
saveStateToHistory(WorkflowHistoryEvent.EdgeSourceHandleChange)
}, [getNodesReadOnly, store, handleSyncWorkflowDraft, saveStateToHistory])
return {
handleEdgeEnter,
handleEdgeLeave,
handleEdgeDeleteByDeleteBranch,
handleEdgeDelete,
handleEdgesChange,
handleEdgeSourceHandleChange,
}
}

View File

@ -299,6 +299,7 @@ export const useNodesInteractions = () => {
|| connectingNode.data.type === BlockEnum.VariableAggregator)
&& node.data.type !== BlockEnum.IfElse
&& node.data.type !== BlockEnum.QuestionClassifier
&& node.data.type !== BlockEnum.HumanInput
) {
n.data._isEntering = true
}
@ -1017,6 +1018,7 @@ export const useNodesInteractions = () => {
if (
nodeType !== BlockEnum.IfElse
&& nodeType !== BlockEnum.QuestionClassifier
&& nodeType !== BlockEnum.HumanInput
) {
newNode.data._connectedSourceHandleIds = [sourceHandle]
}
@ -1053,6 +1055,7 @@ export const useNodesInteractions = () => {
if (
nodeType !== BlockEnum.IfElse
&& nodeType !== BlockEnum.QuestionClassifier
&& nodeType !== BlockEnum.HumanInput
&& nodeType !== BlockEnum.LoopEnd
) {
newEdge = {
@ -1244,6 +1247,7 @@ export const useNodesInteractions = () => {
if (
nodeType !== BlockEnum.IfElse
&& nodeType !== BlockEnum.QuestionClassifier
&& nodeType !== BlockEnum.HumanInput
&& nodeType !== BlockEnum.LoopEnd
) {
newNextEdge = {

View File

@ -27,6 +27,7 @@ export const WorkflowHistoryEvent = {
NodeDelete: 'NodeDelete',
EdgeDelete: 'EdgeDelete',
EdgeDeleteByDeleteBranch: 'EdgeDeleteByDeleteBranch',
EdgeSourceHandleChange: 'EdgeSourceHandleChange',
NodeAdd: 'NodeAdd',
NodeResize: 'NodeResize',
NoteAdd: 'NoteAdd',

View File

@ -49,6 +49,7 @@ export const useWorkflowNodeFinished = () => {
if (data.node_type === BlockEnum.QuestionClassifier)
currentNode.data._runningBranchId = data?.outputs?.class_id
// todo: add human-input node support
}
})
setNodes(newNodes)