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

Function processUserMessage

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

Source from the content-addressed store, hash-verified

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

Callers 1

approximateMessageTokensFunction · 0.85

Calls 4

jsonStringifyFunction · 0.85
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected