MCPcopy Index your code
hub / github.com/Opencode-DCP/opencode-dynamic-context-pruning / countAllMessageTokens

Function countAllMessageTokens

lib/token-utils.ts:152–164  ·  view source on GitHub ↗
(msg: WithParts)

Source from the content-addressed store, hash-verified

150}
151
152export function countAllMessageTokens(msg: WithParts): number {
153 const parts = Array.isArray(msg.parts) ? msg.parts : []
154 const texts: string[] = []
155 for (const part of parts) {
156 if (part.type === "text") {
157 texts.push(part.text)
158 } else {
159 texts.push(...extractToolContent(part))
160 }
161 }
162 if (texts.length === 0) return 0
163 return estimateTokensBatch(texts)
164}

Callers 3

buildPriorityMapFunction · 0.90
resolveSelectionFunction · 0.90
assertCountedFunction · 0.90

Calls 2

extractToolContentFunction · 0.85
estimateTokensBatchFunction · 0.85

Tested by 1

assertCountedFunction · 0.72