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

Function processAssistantMessage

src/utils/analyzeContext.ts:792–820  ·  view source on GitHub ↗
(
  msg: AssistantMessage | NormalizedAssistantMessage,
  breakdown: MessageBreakdown,
)

Source from the content-addressed store, hash-verified

790}
791
792function processAssistantMessage(
793 msg: AssistantMessage | NormalizedAssistantMessage,
794 breakdown: MessageBreakdown,
795): void {
796 // Process each content block individually
797 const contentBlocks = Array.isArray(msg.message!.content)
798 ? msg.message!.content
799 : []
800 for (const block of contentBlocks) {
801 const blockStr = jsonStringify(block)
802 const blockTokens = roughTokenCountEstimation(blockStr)
803
804 if (
805 typeof block !== 'string' &&
806 'type' in block &&
807 block.type === 'tool_use'
808 ) {
809 breakdown.toolCallTokens += blockTokens
810 const toolName = ('name' in block ? block.name : undefined) || 'unknown'
811 breakdown.toolCallsByType.set(
812 toolName,
813 (breakdown.toolCallsByType.get(toolName) || 0) + blockTokens,
814 )
815 } else {
816 // Text blocks or other non-tool content
817 breakdown.assistantMessageTokens += blockTokens
818 }
819 }
820}
821
822function processUserMessage(
823 msg: UserMessage | NormalizedUserMessage,

Callers 1

approximateMessageTokensFunction · 0.85

Calls 4

jsonStringifyFunction · 0.85
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected