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

Function reconstructContentReplacementState

src/utils/toolResultStorage.ts:984–1014  ·  view source on GitHub ↗
(
  messages: Message[],
  records: ContentReplacementRecord[],
  inheritedReplacements?: ReadonlyMap<string, string>,
)

Source from the content-addressed store, hash-verified

982 * resumes (parent IDs aren't in the subagent's messages).
983 */
984export function reconstructContentReplacementState(
985 messages: Message[],
986 records: ContentReplacementRecord[],
987 inheritedReplacements?: ReadonlyMap<string, string>,
988): ContentReplacementState {
989 const state = createContentReplacementState()
990 const candidateIds = new Set(
991 collectCandidatesByMessage(messages)
992 .flat()
993 .map(c => c.toolUseId),
994 )
995
996 for (const id of candidateIds) {
997 state.seenIds.add(id)
998 }
999 for (const r of records) {
1000 if (r.kind === 'tool-result' && candidateIds.has(r.toolUseId)) {
1001 state.replacements.set(r.toolUseId, r.replacement)
1002 }
1003 }
1004 if (inheritedReplacements) {
1005 for (const [id, replacement] of inheritedReplacements) {
1006 if (candidateIds.has(id) && !state.replacements.has(id)) {
1007 state.replacements.set(id, replacement)
1008 }
1009 }
1010 }
1011 evictOldestFromSet(state.seenIds, MAX_TRACKED_REPLACEMENT_IDS)
1012 evictOldestFromMap(state.replacements, MAX_TRACKED_REPLACEMENT_IDS)
1013 return state
1014}
1015
1016/**
1017 * AgentTool-resume variant: encapsulates the feature-flag gate + parent

Calls 7

evictOldestFromSetFunction · 0.85
evictOldestFromMapFunction · 0.85
setMethod · 0.80
addMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected