MCPcopy Index your code
hub / github.com/codeaashu/claude-code / processUserMessage

Function processUserMessage

src/utils/analyzeContext.ts:805–837  ·  view source on GitHub ↗
(
  msg: UserMessage | NormalizedUserMessage,
  breakdown: MessageBreakdown,
  toolUseIdToName: Map<string, string>,
)

Source from the content-addressed store, hash-verified

803}
804
805function processUserMessage(
806 msg: UserMessage | NormalizedUserMessage,
807 breakdown: MessageBreakdown,
808 toolUseIdToName: Map<string, string>,
809): void {
810 // Handle both string and array content
811 if (typeof msg.message.content === 'string') {
812 // Simple string content
813 const tokens = roughTokenCountEstimation(msg.message.content)
814 breakdown.userMessageTokens += tokens
815 return
816 }
817
818 // Process each content block individually
819 for (const block of msg.message.content) {
820 const blockStr = jsonStringify(block)
821 const blockTokens = roughTokenCountEstimation(blockStr)
822
823 if ('type' in block && block.type === 'tool_result') {
824 breakdown.toolResultTokens += blockTokens
825 const toolUseId = 'tool_use_id' in block ? block.tool_use_id : undefined
826 const toolName =
827 (toolUseId ? toolUseIdToName.get(toolUseId) : undefined) || 'unknown'
828 breakdown.toolResultsByType.set(
829 toolName,
830 (breakdown.toolResultsByType.get(toolName) || 0) + blockTokens,
831 )
832 } else {
833 // Text blocks or other non-tool content
834 breakdown.userMessageTokens += blockTokens
835 }
836 }
837}
838
839function processAttachment(
840 msg: AttachmentMessage,

Callers 1

approximateMessageTokensFunction · 0.85

Calls 4

jsonStringifyFunction · 0.85
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected