@@ -21,7 +21,7 @@ import {
2121 ReloadOutlined
2222} from '@ant-design/icons'
2323import { v4 as uuidv4 } from 'uuid'
24- import { ObjectChat , ObjectNode as ObjectNodeType } from '../../../types'
24+ import { ObjectChat , ObjectNode as ObjectNodeType , ObjectNodeReference } from '../../../types'
2525import { useAppContext } from '../../../store/AppContext'
2626import { useSettings } from '../../../store/hooks/useSettings'
2727import { createAIService } from '../../../services/aiService'
@@ -219,7 +219,7 @@ const ObjectAIGenerator: React.FC<ObjectAIGeneratorProps> = ({
219219 Name : key ,
220220 Value : value
221221 } ) )
222- information += `\n## 属性列表\n${ JSON . stringify ( properties , null , 2 ) } `
222+ information += `\n## 属性列表\n${ JSON . stringify ( properties ) } `
223223 }
224224
225225 // 添加子节点信息
@@ -241,10 +241,26 @@ const ObjectAIGenerator: React.FC<ObjectAIGeneratorProps> = ({
241241 . filter ( Boolean )
242242
243243 if ( children . length > 0 ) {
244- information += `\n## 子节点列表\n${ JSON . stringify ( children , null , 2 ) } `
244+ information += `\n## 子节点列表\n${ JSON . stringify ( children ) } `
245245 }
246246 }
247247
248+ // 添加引用信息
249+ if ( node . references && node . references . length > 0 ) {
250+ const references = node . references . map ( ( ref ) => {
251+ const refNode = nodes [ ref . id ]
252+ return {
253+ Name : ref . name ,
254+ Description : ref . description || '' ,
255+ Type : ref . type ,
256+ Strength : ref . strength ,
257+ NodeExists : ! ! refNode ,
258+ NodeDescription : refNode ?. description || ''
259+ }
260+ } )
261+ information += `\n## 引用关系\n${ JSON . stringify ( references ) } `
262+ }
263+
248264 return information
249265 }
250266
@@ -283,9 +299,43 @@ const ObjectAIGenerator: React.FC<ObjectAIGeneratorProps> = ({
283299 return node . children . map ( ( id ) => nodes [ id ] ) . filter ( Boolean )
284300 }
285301
302+ // 获取当前节点的引用信息
303+ const getCurrentReferences = ( node : ObjectNodeType ) => {
304+ if ( ! node . references ) return [ ]
305+ return node . references . map ( ( ref ) => ( {
306+ ...ref ,
307+ referencedNode : nodes [ ref . id ] || null
308+ } ) )
309+ }
310+
311+ // 获取引用当前节点的其他节点(反向引用)
312+ const getIncomingReferences = ( node : ObjectNodeType ) => {
313+ const incomingRefs : Array < {
314+ fromNode : ObjectNodeType
315+ reference : ObjectNodeReference
316+ } > = [ ]
317+
318+ Object . values ( nodes ) . forEach ( ( otherNode ) => {
319+ if ( otherNode . id !== node . id && otherNode . references ) {
320+ otherNode . references . forEach ( ( ref ) => {
321+ if ( ref . id === node . id ) {
322+ incomingRefs . push ( {
323+ fromNode : otherNode ,
324+ reference : ref
325+ } )
326+ }
327+ } )
328+ }
329+ } )
330+
331+ return incomingRefs
332+ }
333+
286334 const ancestorChain = buildAncestorChain ( currentNode )
287335 const siblings = getSiblings ( currentNode )
288336 const existingChildren = getExistingChildren ( currentNode )
337+ const currentReferences = getCurrentReferences ( currentNode )
338+ const incomingReferences = getIncomingReferences ( currentNode )
289339
290340 // 构建完整的上下文信息
291341 const getFullContextInformation = ( ) : string => {
@@ -323,6 +373,45 @@ const ObjectAIGenerator: React.FC<ObjectAIGeneratorProps> = ({
323373 contextInfo += '\n## 同级节点信息\n无同级节点\n'
324374 }
325375
376+ // 添加引用关系信息
377+ if ( currentReferences . length > 0 ) {
378+ contextInfo += '\n## 当前节点的引用关系\n'
379+ currentReferences . forEach ( ( ref ) => {
380+ contextInfo += `\n### 引用节点 - ${ ref . name } \n`
381+ contextInfo += `- **引用类型**: ${ ref . type } \n`
382+ contextInfo += `- **引用强度**: ${ ref . strength } \n`
383+ if ( ref . description ) {
384+ contextInfo += `- **引用描述**: ${ ref . description } \n`
385+ }
386+ if ( ref . referencedNode ) {
387+ contextInfo += `- **节点存在**: 是\n`
388+ contextInfo += `- **节点描述**: ${ ref . referencedNode . description || '无' } \n`
389+ } else {
390+ contextInfo += `- **节点存在**: 否(可能已被删除)\n`
391+ }
392+ contextInfo += '\n'
393+ } )
394+ } else {
395+ contextInfo += '\n## 当前节点的引用关系\n当前节点无引用其他节点\n'
396+ }
397+
398+ // 添加反向引用信息
399+ if ( incomingReferences . length > 0 ) {
400+ contextInfo += '\n## 被其他节点引用的情况\n'
401+ incomingReferences . forEach ( ( incomingRef ) => {
402+ contextInfo += `\n### 来自节点 - ${ incomingRef . fromNode . name } \n`
403+ contextInfo += `- **引用类型**: ${ incomingRef . reference . type } \n`
404+ contextInfo += `- **引用强度**: ${ incomingRef . reference . strength } \n`
405+ if ( incomingRef . reference . description ) {
406+ contextInfo += `- **引用描述**: ${ incomingRef . reference . description } \n`
407+ }
408+ contextInfo += `- **来源节点描述**: ${ incomingRef . fromNode . description || '无' } \n`
409+ contextInfo += '\n'
410+ } )
411+ } else {
412+ contextInfo += '\n## 被其他节点引用的情况\n当前节点未被其他节点引用\n'
413+ }
414+
326415 return contextInfo
327416 }
328417
@@ -331,6 +420,8 @@ const ObjectAIGenerator: React.FC<ObjectAIGeneratorProps> = ({
331420 ancestorChain,
332421 siblings,
333422 existingChildren,
423+ currentReferences,
424+ incomingReferences,
334425 // 新增:获取完整的上下文信息
335426 getFullContextInformation,
336427 // 新增:获取单个节点的完整信息
0 commit comments