feat(logs): show compression tokens in request log UI (#1923)

Integrated into release/v3.7.9
This commit is contained in:
Andrew Munsell
2026-05-04 05:19:50 -07:00
committed by GitHub
parent 372c887ca3
commit 3f063e5c52
4 changed files with 14 additions and 8 deletions

View File

@@ -1437,7 +1437,9 @@ export async function handleChatCore({
const cachedUsage =
extractUsageFromResponse(cached as Record<string, unknown>, provider) ||
((cached as Record<string, unknown>)?.usage as Record<string, unknown> | undefined);
const cachedCost = cachedUsage ? await calculateCost(provider, model, cachedUsage as Record<string, number>) : 0;
const cachedCost = cachedUsage
? await calculateCost(provider, model, cachedUsage as Record<string, number>)
: 0;
persistAttemptLogs({
status: 200,
tokens: (cached as Record<string, unknown>)?.usage,

View File

@@ -216,12 +216,9 @@ function cleanupArtifacts(text: string): string {
}
function recapitalizeSentences(text: string): string {
return text.replace(
/(^|[.!?]\s+|^\s+)([a-z])/gm,
(_match, prefix: string, char: string) => {
return `${prefix}${char.toUpperCase()}`;
}
);
return text.replace(/(^|[.!?]\s+|^\s+)([a-z])/gm, (_match, prefix: string, char: string) => {
return `${prefix}${char.toUpperCase()}`;
});
}
function createCavemanStats(

View File

@@ -85,7 +85,10 @@ export function validateCompression(original: string, compressed: string): Valid
);
requireExactPresence(
"LaTeX block",
collectMatches(original, /\\begin\{[A-Za-z*]{1,50}\}(?:(?!\\end\{)[^])*\\end\{[A-Za-z*]{1,50}\}/g),
collectMatches(
original,
/\\begin\{[A-Za-z*]{1,50}\}(?:(?!\\end\{)[^])*\\end\{[A-Za-z*]{1,50}\}/g
),
compressed,
errors
);

View File

@@ -0,0 +1,4 @@
-- Migration 041: Add tokens_compressed to call_logs
-- Tracks how many tokens were removed by proactive context compression.
-- NULL = compression not applied. N > 0 = tokens eliminated.
ALTER TABLE call_logs ADD COLUMN tokens_compressed INTEGER DEFAULT NULL;