Replicates agent-core's per-char token weighting exactly, over the same * `text` + `think` parts its gate counts. agent-core * (`packages/agent-core/src/utils/tokens.ts`) sums per-part estimates, each * `estimateTokens(s) = Math.ceil(asciiCount / 4) + nonAsciiCount` (ASCII ~4 * chars/token,
(text: string)
| 637 | * contribute 0. Matching it ensures Chinese-heavy tool results blank at the |
| 638 | * same gate as the agent. */ |
| 639 | function estimateTokens(text: string): number { |
| 640 | let asciiCount = 0; |
| 641 | let nonAsciiCount = 0; |
| 642 | for (const char of text) { |
| 643 | if (char.codePointAt(0)! <= 127) { |
| 644 | asciiCount++; |
| 645 | } else { |
| 646 | nonAsciiCount++; |
| 647 | } |
| 648 | } |
| 649 | return Math.ceil(asciiCount / 4) + nonAsciiCount; |
| 650 | } |
| 651 | |
| 652 | function estimateContentTokens(content: readonly ContentPart[]): number { |
| 653 | let total = 0; |
no outgoing calls
no test coverage detected