MCPcopy Create free account
hub / github.com/WJX20/claude-code / normalizeMessage

Function normalizeMessage

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

Source from the content-addressed store, hash-verified

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

Callers 1

submitMessageMethod · 0.85

Calls 9

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

Tested by

no test coverage detected