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

Function buildMessageMaps

src/renderer/src/services/messagesService.ts:12–31  ·  view source on GitHub ↗
(messages: ChatMessage[])

Source from the content-addressed store, hash-verified

10}
11
12function buildMessageMaps(messages: ChatMessage[]): MessageMaps {
13 const messageMap = new Map<string, ChatMessage>()
14 const childrenMap = new Map<string | undefined, ChatMessage[]>()
15
16 for (const msg of messages) {
17 messageMap.set(msg.id, msg)
18 const parentId = msg.parentMessageId
19 if (!childrenMap.has(parentId)) {
20 childrenMap.set(parentId, [])
21 }
22 childrenMap.get(parentId)!.push(msg)
23 }
24
25 // 对每个 children 数组按 branchIndex 排序
26 for (const children of childrenMap.values()) {
27 children.sort((a, b) => (a.branchIndex ?? 0) - (b.branchIndex ?? 0))
28 }
29
30 return { messageMap, childrenMap }
31}
32
33// ==================== 消息 CRUD ====================
34

Callers 2

deleteMessageFunction · 0.85
switchBranchFunction · 0.85

Calls 2

hasMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected