From 24c1b7e8ad0d8b202a06e1148894704d44dbe8f0 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Tue, 3 Mar 2026 15:07:49 +0000 Subject: [PATCH] fix(ui): treat compacted tool calls as zero tokens --- packages/ui/src/lib/token-utils.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/ui/src/lib/token-utils.ts b/packages/ui/src/lib/token-utils.ts index 5654998c..158c58f3 100644 --- a/packages/ui/src/lib/token-utils.ts +++ b/packages/ui/src/lib/token-utils.ts @@ -22,6 +22,12 @@ export function getPartCharCount(part: ClientPart): number { if (part.type === "tool") { const state = (part as any).state + // Tool calls may be compacted server-side. When that happens we treat the + // tool payload as effectively absent from context for token estimation. + const compacted = (state as any)?.time?.compacted + if (compacted !== undefined && compacted !== null) { + return 0 + } if (state) { if (state.input) { try {