MCPcopy Create free account
hub / github.com/Noumena-Network/code / processAssistantMessage

Function processAssistantMessage

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

Source from the content-addressed store, hash-verified

781}
782
783function processAssistantMessage(
784 msg: AssistantMessage | NormalizedAssistantMessage,
785 breakdown: MessageBreakdown,
786): void {
787 // Process each content block individually
788 for (const block of msg.message.content) {
789 const blockStr = jsonStringify(block)
790 const blockTokens = roughTokenCountEstimation(blockStr)
791
792 if ('type' in block && block.type === 'tool_use') {
793 breakdown.toolCallTokens += blockTokens
794 const toolName = ('name' in block ? block.name : undefined) || 'unknown'
795 breakdown.toolCallsByType.set(
796 toolName,
797 (breakdown.toolCallsByType.get(toolName) || 0) + blockTokens,
798 )
799 } else {
800 // Text blocks or other non-tool content
801 breakdown.assistantMessageTokens += blockTokens
802 }
803 }
804}
805
806function processUserMessage(
807 msg: UserMessage | NormalizedUserMessage,

Callers 1

approximateMessageTokensFunction · 0.85

Calls 4

jsonStringifyFunction · 0.85
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected