MCPcopy Create free account
hub / github.com/freecodexyz/free-code / getAssistantMessageContentLength

Function getAssistantMessageContentLength

src/utils/tokens.ts:183–199  ·  view source on GitHub ↗
(
  message: AssistantMessage,
)

Source from the content-addressed store, hash-verified

181 * Note: signature_delta is excluded from streaming counts (not model output).
182 */
183export function getAssistantMessageContentLength(
184 message: AssistantMessage,
185): number {
186 let contentLength = 0
187 for (const block of message.message.content) {
188 if (block.type === 'text') {
189 contentLength += block.text.length
190 } else if (block.type === 'thinking') {
191 contentLength += block.thinking.length
192 } else if (block.type === 'redacted_thinking') {
193 contentLength += block.data.length
194 } else if (block.type === 'tool_use') {
195 contentLength += jsonStringify(block.input).length
196 }
197 }
198 return contentLength
199}
200
201/**
202 * Get the current context window size in tokens.

Callers 2

callFunction · 0.85

Calls 1

jsonStringifyFunction · 0.85

Tested by

no test coverage detected