(msg: WithParts)
| 150 | } |
| 151 | |
| 152 | export 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 | } |