MCPcopy Create free account
hub / github.com/Noumena-Network/code / insertMessageChain

Method insertMessageChain

src/utils/sessionStorage.ts:1075–1165  ·  view source on GitHub ↗
(
    messages: Transcript,
    isSidechain: boolean = false,
    agentId?: string,
    startingParentUuid?: UUID | null,
    teamInfo?: { teamName?: string; agentName?: string },
  )

Source from the content-addressed store, hash-verified

1073 }
1074
1075 async insertMessageChain(
1076 messages: Transcript,
1077 isSidechain: boolean = false,
1078 agentId?: string,
1079 startingParentUuid?: UUID | null,
1080 teamInfo?: { teamName?: string; agentName?: string },
1081 ) {
1082 return this.trackWrite(async () => {
1083 let parentUuid: UUID | null = startingParentUuid ?? null
1084
1085 // First user/assistant message materializes the session file.
1086 // Hook progress/attachment messages alone stay buffered.
1087 if (
1088 this.sessionFile === null &&
1089 messages.some(m => m.type === 'user' || m.type === 'assistant')
1090 ) {
1091 await this.materializeSessionFile()
1092 }
1093
1094 // Get current git branch once for this message chain
1095 let gitBranch: string | undefined
1096 try {
1097 gitBranch = await getBranch()
1098 } catch {
1099 // Not in a git repo or git command failed
1100 gitBranch = undefined
1101 }
1102
1103 // Get slug if one exists for this session (used for plan files, etc.)
1104 const sessionId = getSessionId()
1105 const slug = getPlanSlugCache().get(sessionId)
1106
1107 for (const message of messages) {
1108 const isCompactBoundary = isCompactBoundaryMessage(message)
1109
1110 // For tool_result messages, use the assistant message UUID from the message
1111 // if available (set at creation time), otherwise fall back to sequential parent
1112 let effectiveParentUuid = parentUuid
1113 if (
1114 message.type === 'user' &&
1115 'sourceToolAssistantUUID' in message &&
1116 message.sourceToolAssistantUUID
1117 ) {
1118 effectiveParentUuid = message.sourceToolAssistantUUID
1119 }
1120
1121 const transcriptMessage: TranscriptMessage = {
1122 parentUuid: isCompactBoundary ? null : effectiveParentUuid,
1123 logicalParentUuid: isCompactBoundary ? parentUuid : undefined,
1124 isSidechain,
1125 teamName: teamInfo?.teamName,
1126 agentName: teamInfo?.agentName,
1127 promptId:
1128 message.type === 'user' ? (getPromptId() ?? undefined) : undefined,
1129 agentId,
1130 ...message,
1131 // Session-stamp fields MUST come after the spread. On --fork-session
1132 // and --resume, messages arrive as SerializedMessage (carries source

Callers 3

recordTranscriptFullFunction · 0.80
recordTranscriptFunction · 0.80

Calls 14

trackWriteMethod · 0.95
appendEntryMethod · 0.95
getBranchFunction · 0.85
getSessionIdFunction · 0.85
getPlanSlugCacheFunction · 0.85
getPromptIdFunction · 0.85
getUserTypeFunction · 0.85
getEntrypointFunction · 0.85
getCwdFunction · 0.85
isChainParticipantFunction · 0.85

Tested by

no test coverage detected