MCPcopy Index your code
hub / github.com/Noumena-Network/code / buildConversationChain

Function buildConversationChain

src/utils/sessionStorage.ts:2227–2254  ·  view source on GitHub ↗
(
  messages: Map<UUID, TranscriptMessage>,
  leafMessage: TranscriptMessage,
  options?: { includeLogicalParents?: boolean },
)

Source from the content-addressed store, hash-verified

2225 * @returns Array of messages from root to leaf
2226 */
2227export function buildConversationChain(
2228 messages: Map<UUID, TranscriptMessage>,
2229 leafMessage: TranscriptMessage,
2230 options?: { includeLogicalParents?: boolean },
2231): TranscriptMessage[] {
2232 const transcript: TranscriptMessage[] = []
2233 const seen = new Set<UUID>()
2234 let currentMsg: TranscriptMessage | undefined = leafMessage
2235 while (currentMsg) {
2236 if (seen.has(currentMsg.uuid)) {
2237 logError(
2238 new Error(
2239 `Cycle detected in parentUuid chain at message ${currentMsg.uuid}. Returning partial transcript.`,
2240 ),
2241 )
2242 logEvent('ncode_chain_parent_cycle', {})
2243 break
2244 }
2245 seen.add(currentMsg.uuid)
2246 transcript.push(currentMsg)
2247 const parentUuid =
2248 currentMsg.parentUuid ??
2249 (options?.includeLogicalParents ? currentMsg.logicalParentUuid : null)
2250 currentMsg = parentUuid ? messages.get(parentUuid) : undefined
2251 }
2252 transcript.reverse()
2253 return recoverOrphanedParallelToolResults(messages, transcript, seen)
2254}
2255
2256/**
2257 * Post-pass for buildConversationChain: recover sibling assistant blocks and

Callers 7

loadTranscriptFromFileFunction · 0.85
loadFullLogFunction · 0.85
getLastSessionLogFunction · 0.85
getAgentTranscriptFunction · 0.85

Calls 6

logErrorFunction · 0.70
logEventFunction · 0.50
hasMethod · 0.45
addMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected