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

Function countMessageTextTokens

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

Source from the content-addressed store, hash-verified

138}
139
140export function countMessageTextTokens(msg: WithParts): number {
141 const texts: string[] = []
142 const parts = Array.isArray(msg.parts) ? msg.parts : []
143 for (const part of parts) {
144 if (part.type === "text") {
145 texts.push(part.text)
146 }
147 }
148 if (texts.length === 0) return 0
149 return estimateTokensBatch(texts)
150}
151
152export function countAllMessageTokens(msg: WithParts): number {
153 const parts = Array.isArray(msg.parts) ? msg.parts : []

Callers

nothing calls this directly

Calls 1

estimateTokensBatchFunction · 0.85

Tested by

no test coverage detected