Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion open-sse/handlers/chatCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions open-sse/services/compression/caveman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion open-sse/services/compression/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
4 changes: 4 additions & 0 deletions src/lib/db/migrations/041_compression_tokens.sql
Original file line number Diff line number Diff line change
@@ -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;