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

Function normalizeMessage

src/utils/queryHelpers.ts:97–217  ·  view source on GitHub ↗
(message: Message)

Source from the content-addressed store, hash-verified

95const toolProgressLastSentTime = new Map<string, number>()
96
97export function* normalizeMessage(message: Message): Generator<SDKMessage> {
98 switch (message.type) {
99 case 'assistant':
100 for (const _ of normalizeMessages([message])) {
101 // Skip empty messages (e.g., "(no content)") that shouldn't be output to SDK
102 if (!isNotEmptyMessage(_)) {
103 continue
104 }
105 yield {
106 type: 'assistant',
107 message: _.message,
108 parent_tool_use_id: null,
109 session_id: getSessionId(),
110 uuid: _.uuid,
111 error: _.error,
112 }
113 }
114 return
115 case 'progress':
116 if (
117 message.data.type === 'agent_progress' ||
118 message.data.type === 'skill_progress'
119 ) {
120 for (const _ of normalizeMessages([message.data.message])) {
121 switch (_.type) {
122 case 'assistant':
123 // Skip empty messages (e.g., "(no content)") that shouldn't be output to SDK
124 if (!isNotEmptyMessage(_)) {
125 break
126 }
127 yield {
128 type: 'assistant',
129 message: _.message,
130 parent_tool_use_id: message.parentToolUseID,
131 session_id: getSessionId(),
132 uuid: _.uuid,
133 error: _.error,
134 }
135 break
136 case 'user':
137 yield {
138 type: 'user',
139 message: _.message,
140 parent_tool_use_id: message.parentToolUseID,
141 session_id: getSessionId(),
142 uuid: _.uuid,
143 timestamp: _.timestamp,
144 isSynthetic: _.isMeta || _.isVisibleInTranscriptOnly,
145 tool_use_result: _.mcpMeta
146 ? { content: _.toolUseResult, ..._.mcpMeta }
147 : _.toolUseResult,
148 }
149 break
150 }
151 }
152 } else if (
153 message.data.type === 'bash_progress' ||
154 message.data.type === 'powershell_progress'

Callers 2

submitMessageMethod · 0.85

Calls 9

isEnvTruthyFunction · 0.90
normalizeMessagesFunction · 0.85
isNotEmptyMessageFunction · 0.85
getSessionIdFunction · 0.85
keysMethod · 0.80
deleteMethod · 0.80
setMethod · 0.80
getMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected