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

Function buildPathToMessage

src/renderer/src/stores/tabsStore.ts:9–43  ·  view source on GitHub ↗
(messages: ChatMessage[], targetMessageId: string)

Source from the content-addressed store, hash-verified

7
8// 构建到指定消息的路径
9function buildPathToMessage(messages: ChatMessage[], targetMessageId: string): string[] {
10 const messageMap = new Map<string, ChatMessage>()
11 messages.forEach((msg) => messageMap.set(msg.id, msg))
12
13 const targetMessage = messageMap.get(targetMessageId)
14 if (!targetMessage) return []
15
16 // 构建从根到目标消息的路径
17 const path: string[] = []
18 let currentMsg: ChatMessage | undefined = targetMessage
19
20 while (currentMsg) {
21 path.unshift(currentMsg.id)
22 if (currentMsg.parentId) {
23 currentMsg = messageMap.get(currentMsg.parentId)
24 } else {
25 break
26 }
27 }
28
29 // 如果目标消息有子节点,继续延伸到第一个子节点
30 let lastNode = targetMessage
31 while (lastNode.children && lastNode.children.length > 0) {
32 const firstChildId = lastNode.children[0]
33 const firstChild = messageMap.get(firstChildId)
34 if (firstChild) {
35 path.push(firstChildId)
36 lastNode = firstChild
37 } else {
38 break
39 }
40 }
41
42 return path
43}
44
45export interface TabsState {
46 openTabs: string[] // 所有打开的 tab ID

Callers 1

tabsStore.tsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected