@@ -86,7 +86,6 @@ export function createPruningTool(
8686
8787 const toolMetadata = new Map < string , { tool : string , parameters ?: any } > ( )
8888 for ( const id of prunedIds ) {
89- // Look up with lowercase since all IDs are stored lowercase
9089 const meta = state . toolParameters . get ( id . toLowerCase ( ) )
9190 if ( meta ) {
9291 toolMetadata . set ( id . toLowerCase ( ) , meta )
@@ -144,7 +143,6 @@ async function calculateTokensSaved(
144143 } )
145144 const messages = messagesResponse . data || messagesResponse
146145
147- // Build map of tool call ID -> output content
148146 const toolOutputs = new Map < string , string > ( )
149147 for ( const msg of messages ) {
150148 if ( msg . role === 'tool' && msg . tool_call_id ) {
@@ -153,7 +151,6 @@ async function calculateTokensSaved(
153151 : JSON . stringify ( msg . content )
154152 toolOutputs . set ( msg . tool_call_id . toLowerCase ( ) , content )
155153 }
156- // Handle Anthropic format
157154 if ( msg . role === 'user' && Array . isArray ( msg . content ) ) {
158155 for ( const part of msg . content ) {
159156 if ( part . type === 'tool_result' && part . tool_use_id ) {
@@ -166,7 +163,6 @@ async function calculateTokensSaved(
166163 }
167164 }
168165
169- // Collect content for pruned outputs
170166 const contents : string [ ] = [ ]
171167 for ( const id of prunedIds ) {
172168 const content = toolOutputs . get ( id . toLowerCase ( ) )
@@ -176,14 +172,12 @@ async function calculateTokensSaved(
176172 }
177173
178174 if ( contents . length === 0 ) {
179- return prunedIds . length * 500 // fallback estimate
175+ return prunedIds . length * 500
180176 }
181177
182- // Estimate tokens
183178 const tokenCounts = await estimateTokensBatch ( contents )
184179 return tokenCounts . reduce ( ( sum , count ) => sum + count , 0 )
185180 } catch ( error : any ) {
186- // If we can't calculate, estimate based on average
187181 return prunedIds . length * 500
188182 }
189183}
0 commit comments