@@ -33,28 +33,24 @@ const updateNodeAIStatus = (nodeId: string, aiStatus: Partial<NodeAIStatus>) =>
3333 const { pageState } = useCanvas ( )
3434 const { publish } = useMessage ( )
3535
36- if ( ! pageState . nodesStatus [ nodeId ] ) {
37- pageState . nodesStatus [ nodeId ] = { }
38- }
39-
40- if ( ! pageState . nodesStatus [ nodeId ] . aiStatus ) {
41- pageState . nodesStatus [ nodeId ] . aiStatus = {
36+ if ( ! pageState . aiNodesStatus [ nodeId ] ) {
37+ pageState . aiNodesStatus [ nodeId ] = {
4238 state : 'hidden' , // 默认隐藏
4339 aiContext : null ,
4440 lastAIAction : '' ,
4541 aiHistory : [ ]
4642 }
4743 }
4844
49- Object . assign ( pageState . nodesStatus [ nodeId ] . aiStatus , aiStatus )
45+ Object . assign ( pageState . aiNodesStatus [ nodeId ] , aiStatus )
5046
5147 // 发布状态更新事件
52- publish ( { topic : 'nodeAIStatusUpdate' , data : { nodeId, aiStatus : pageState . nodesStatus [ nodeId ] . aiStatus } } )
48+ publish ( { topic : 'nodeAIStatusUpdate' , data : { nodeId, aiStatus : pageState . aiNodesStatus [ nodeId ] } } )
5349}
5450
5551const getNodeAIStatus = ( nodeId : string ) : NodeAIStatus | null => {
5652 const { pageState } = useCanvas ( )
57- return pageState . nodesStatus [ nodeId ] ?. aiStatus || null
53+ return pageState . aiNodesStatus [ nodeId ] || null
5854}
5955
6056// 添加AI操作历史记录
@@ -130,17 +126,12 @@ const cancelNodeAIAction = (nodeId: string) => {
130126 return
131127 }
132128
133- // 恢复画布节点schema为originalNodeData
129+ // 恢复画布节点schema为originalNodeData,同步重建nodesMap
134130 if ( currentStatus . originalNodeData && currentStatus . state === 'confirm' ) {
135- const { getNode } = useCanvas ( )
131+ const { restoreNodeSubtree } = useCanvas ( )
136132 const { publish } = useMessage ( )
137- const node = getNode ( nodeId )
138- if ( node ) {
139- // 先删除AI新增的属性,再用原始数据覆盖,确保回滚幂等
140- Object . keys ( node ) . forEach ( ( key ) => delete node [ key ] )
141- Object . assign ( node , deepClone ( currentStatus . originalNodeData ) )
142- publish ( { topic : 'schemaChange' , data : { nodeId } } )
143- }
133+ restoreNodeSubtree ( nodeId , deepClone ( currentStatus . originalNodeData ) )
134+ publish ( { topic : 'schemaChange' , data : { nodeId } } )
144135 }
145136
146137 const newState = currentStatus . chatContent ? 'chat' : 'hidden'
@@ -200,17 +191,12 @@ const rejectNodeAIModification = (nodeId: string) => {
200191 return false
201192 }
202193
203- // 恢复画布节点schema为originalNodeData
194+ // 恢复画布节点schema为originalNodeData,同步重建nodesMap
204195 if ( currentAIStatus . originalNodeData ) {
205- const { getNode } = useCanvas ( )
196+ const { restoreNodeSubtree } = useCanvas ( )
206197 const { publish } = useMessage ( )
207- const node = getNode ( nodeId )
208- if ( node ) {
209- // 先删除AI新增的属性,再用原始数据覆盖,确保回滚幂等
210- Object . keys ( node ) . forEach ( ( key ) => delete node [ key ] )
211- Object . assign ( node , deepClone ( currentAIStatus . originalNodeData ) )
212- publish ( { topic : 'schemaChange' , data : { nodeId } } )
213- }
198+ restoreNodeSubtree ( nodeId , deepClone ( currentAIStatus . originalNodeData ) )
199+ publish ( { topic : 'schemaChange' , data : { nodeId } } )
214200 }
215201
216202 const newState = currentAIStatus . chatContent ? 'chat' : 'hidden'
@@ -245,30 +231,6 @@ const hasNodePendingAIModification = (nodeId: string): boolean => {
245231 const aiStatus = getNodeAIStatus ( nodeId )
246232 return aiStatus ?. state === 'confirm'
247233}
248-
249- /**
250- * 获取所有有待处理AI修改的节点ID
251- */
252- const getAllNodesWithPendingAIModification = ( ) : string [ ] => {
253- const { pageState } = useCanvas ( )
254- const pendingNodes : string [ ] = [ ]
255-
256- Object . entries ( pageState . nodesStatus ) . forEach ( ( [ nodeId , status ] ) => {
257- if ( status . aiStatus ?. state === 'confirm' ) {
258- pendingNodes . push ( nodeId )
259- }
260- } )
261-
262- return pendingNodes
263- }
264-
265- /**
266- * 检查页面是否有任何待处理的AI修改
267- */
268- const hasAnyPendingAIModification = ( ) : boolean => {
269- return getAllNodesWithPendingAIModification ( ) . length > 0
270- }
271-
272234// ==================== AI助手状态函数 ====================
273235
274236// 获取当前节点是否应该显示AI聊天界面
@@ -731,8 +693,6 @@ export default function () {
731693 rejectNodeAIModification,
732694 resetNodeAIAdoptionStatus,
733695 hasNodePendingAIModification,
734- getAllNodesWithPendingAIModification,
735- hasAnyPendingAIModification,
736696 findJsonPatchPath,
737697 applyAIPatches,
738698 // AI聊天请求构建
0 commit comments