MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / processUserMessage

Function processUserMessage

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

Source from the content-addressed store, hash-verified

820}
821
822function processUserMessage(
823 msg: UserMessage | NormalizedUserMessage,
824 breakdown: MessageBreakdown,
825 toolUseIdToName: Map<string, string>,
826): void {
827 // Handle both string and array content
828 if (typeof msg.message!.content === 'string') {
829 // Simple string content
830 const tokens = roughTokenCountEstimation(msg.message!.content)
831 breakdown.userMessageTokens += tokens
832 return
833 }
834
835 // Process each content block individually
836 for (const block of msg.message!.content ?? []) {
837 const blockStr = jsonStringify(block)
838 const blockTokens = roughTokenCountEstimation(blockStr)
839
840 if ('type' in block && block.type === 'tool_result') {
841 const toolUseId = 'tool_use_id' in block ? block.tool_use_id : undefined
842 const toolName =
843 (toolUseId ? toolUseIdToName.get(toolUseId) : undefined) || 'unknown'
844 breakdown.toolResultsByType.set(
845 toolName,
846 (breakdown.toolResultsByType.get(toolName) || 0) + blockTokens,
847 )
848 } else {
849 // Text blocks or other non-tool content
850 breakdown.userMessageTokens += blockTokens
851 }
852 }
853}
854
855function processAttachment(
856 msg: AttachmentMessage,

Callers 1

approximateMessageTokensFunction · 0.85

Calls 4

jsonStringifyFunction · 0.85
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected