MCPcopy Create free account
hub / github.com/experdot/pointer / useChat

Function useChat

src/renderer/src/hooks/useChat.ts:74–248  ·  view source on GitHub ↗
({ pageId }: UseChatOptions)

Source from the content-addressed store, hash-verified

72}
73
74export function useChat({ pageId }: UseChatOptions): UseChatResult {
75 // 1. 核心状态
76 const core = useChatCore({ pageId })
77 const {
78 page,
79 messages,
80 currentPath,
81 isLoading,
82 record,
83 topics,
84 topicGroups,
85 outline,
86 getConfigs,
87 getConfigsWithOverride,
88 settings
89 } = core
90
91 // 检查 LLM 配置状态
92 const hasLLMConfig = settings.llmConfigs.items.length > 0
93 const hasDefaultLLM = settings.defaultLLMId !== undefined
94
95 // 2. 流式通信
96 const streaming = useChatStreaming({
97 pageId,
98 page,
99 messages,
100 currentPath,
101 record,
102 getConfigs,
103 getConfigsWithOverride
104 })
105
106 // 3. Topic 管理
107 const topicsHook = useChatTopics({
108 pageId,
109 messages,
110 currentPath,
111 topics
112 })
113
114 // 4. 标题生成
115 const titles = useChatTitles({
116 pageId,
117 messages,
118 currentPath
119 })
120
121 // 5. 消息操作(保留在主 hook 中,因为比较简单)
122 const deleteMessage = useCallback(
123 (messageId: string) => {
124 messagesService.deleteMessage(pageId, messageId)
125 },
126 [pageId]
127 )
128
129 const editMessage = useCallback(
130 async (messageId: string, content: string, attachments?: FileAttachment[]) => {
131 const message = messages.find((m) => m.id === messageId)

Callers 1

ChatEditorFunction · 0.90

Calls 6

useChatCoreFunction · 0.90
useChatStreamingFunction · 0.90
useChatTopicsFunction · 0.90
useChatTitlesFunction · 0.90
updateMessageMethod · 0.80
sendMessageMethod · 0.80

Tested by

no test coverage detected