MCPcopy Index your code
hub / github.com/anomalyco/opencode / transformShareData

Function transformShareData

packages/opencode/src/cli/cmd/import.ts:49–79  ·  view source on GitHub ↗
(shareData: ShareData[])

Source from the content-addressed store, hash-verified

47 * This groups parts by their messageID to reconstruct the hierarchy before writing to disk.
48 */
49export function transformShareData(shareData: ShareData[]): {
50 info: SDKSession
51 messages: Array<{ info: Message; parts: Part[] }>
52} | null {
53 const sessionItem = shareData.find((d) => d.type === "session")
54 if (!sessionItem) return null
55
56 const messageMap = new Map<string, Message>()
57 const partMap = new Map<string, Part[]>()
58
59 for (const item of shareData) {
60 if (item.type === "message") {
61 messageMap.set(item.data.id, item.data)
62 } else if (item.type === "part") {
63 if (!partMap.has(item.data.messageID)) {
64 partMap.set(item.data.messageID, [])
65 }
66 partMap.get(item.data.messageID)!.push(item.data)
67 }
68 }
69
70 if (messageMap.size === 0) return null
71
72 return {
73 info: sessionItem.data,
74 messages: Array.from(messageMap.values()).map((msg) => ({
75 info: msg,
76 parts: partMap.get(msg.id) ?? [],
77 })),
78 }
79}
80
81type ExportData = { info: SDKSession; messages: Array<{ info: Message; parts: Part[] }> }
82

Callers 2

import.test.tsFile · 0.90
import.tsFile · 0.85

Calls 6

pushMethod · 0.80
findMethod · 0.65
getMethod · 0.65
setMethod · 0.45
fromMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected