({ chatId })
| 24 | } |
| 25 | |
| 26 | const ObjectPage: React.FC<ObjectPageProps> = ({ chatId }) => { |
| 27 | const stores = useAppStores() |
| 28 | const { message } = App.useApp() |
| 29 | const [selectedModel, setSelectedModel] = useState<string | undefined>( |
| 30 | stores.settings.settings.defaultLLMId |
| 31 | ) |
| 32 | |
| 33 | // 从状态中获取对象聊天数据 |
| 34 | const chat = stores.pages.findPageById(chatId) as ObjectChat | undefined |
| 35 | |
| 36 | if (!chat || chat.type !== 'object') { |
| 37 | return <div>对象页面数据加载错误</div> |
| 38 | } |
| 39 | |
| 40 | // 获取LLM配置 |
| 41 | const getLLMConfig = useCallback(() => { |
| 42 | const targetModelId = selectedModel || stores.settings.settings.defaultLLMId |
| 43 | const { llmConfigs } = stores.settings.settings |
| 44 | if (!llmConfigs || llmConfigs.length === 0) { |
| 45 | return null |
| 46 | } |
| 47 | |
| 48 | return llmConfigs.find((config) => config.id === targetModelId) || llmConfigs[0] |
| 49 | }, [selectedModel, stores.settings.settings, stores.settings.settings.defaultLLMId]) |
| 50 | |
| 51 | const handleModelChange = useCallback((modelId: string) => { |
| 52 | setSelectedModel(modelId) |
| 53 | }, []) |
| 54 | |
| 55 | // 处理节点选择(用于图谱交互) |
| 56 | const handleNodeClick = useCallback( |
| 57 | (nodeId: string) => { |
| 58 | stores.object.selectObjectNode(chat.id, nodeId) |
| 59 | }, |
| 60 | [stores.object, chat.id] |
| 61 | ) |
| 62 | |
| 63 | // 获取节点的完整上下文信息 |
| 64 | const getNodeContext = useCallback( |
| 65 | (nodeId: string) => { |
| 66 | const { nodes } = chat.objectData |
| 67 | const node = nodes[nodeId] |
| 68 | if (!node) return null |
| 69 | |
| 70 | // 获取祖先节点链 |
| 71 | const getAncestorChain = (currentNode: ObjectNodeType): ObjectNodeType[] => { |
| 72 | const chain = [currentNode] |
| 73 | let current = currentNode |
| 74 | while (current.parentId && nodes[current.parentId]) { |
| 75 | current = nodes[current.parentId] |
| 76 | chain.unshift(current) |
| 77 | } |
| 78 | return chain |
| 79 | } |
| 80 | |
| 81 | // 获取平级节点 |
| 82 | const getSiblings = (currentNode: ObjectNodeType): ObjectNodeType[] => { |
| 83 | if (!currentNode.parentId) return [] |
nothing calls this directly
no test coverage detected