From 467736a1b4d8a57da1476195d6568bfcc0a46ac1 Mon Sep 17 00:00:00 2001 From: Jan Leon Date: Tue, 30 Jun 2026 02:56:23 +0200 Subject: [PATCH] chore(dead-code): remove unused prompt cache control helper (#5466) --- src/lib/promptCache/index.ts | 2 +- src/lib/promptCache/prefixAnalyzer.ts | 4 --- .../unit/prompt-cache-prefix-analyzer.test.ts | 30 +++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 tests/unit/prompt-cache-prefix-analyzer.test.ts diff --git a/src/lib/promptCache/index.ts b/src/lib/promptCache/index.ts index 2d1446f864..4fa4e6a03f 100644 --- a/src/lib/promptCache/index.ts +++ b/src/lib/promptCache/index.ts @@ -1 +1 @@ -export { analyzePrefix, shouldInjectCacheControl, generatePromptCacheKey } from "./prefixAnalyzer"; +export { analyzePrefix, generatePromptCacheKey } from "./prefixAnalyzer"; diff --git a/src/lib/promptCache/prefixAnalyzer.ts b/src/lib/promptCache/prefixAnalyzer.ts index 6f8e86e12e..b3aef53680 100644 --- a/src/lib/promptCache/prefixAnalyzer.ts +++ b/src/lib/promptCache/prefixAnalyzer.ts @@ -72,10 +72,6 @@ export function analyzePrefix(messages: Message[]): PrefixAnalysis { }; } -export function shouldInjectCacheControl(analysis: PrefixAnalysis, minTokens = 1024): boolean { - return analysis.prefixTokens >= minTokens && analysis.confidence >= 0.7; -} - export function generatePromptCacheKey(messages: Message[]): string { const analysis = analyzePrefix(messages); if (analysis.prefixHash) { diff --git a/tests/unit/prompt-cache-prefix-analyzer.test.ts b/tests/unit/prompt-cache-prefix-analyzer.test.ts new file mode 100644 index 0000000000..2e5978e7ef --- /dev/null +++ b/tests/unit/prompt-cache-prefix-analyzer.test.ts @@ -0,0 +1,30 @@ +import { describe, it } from "node:test"; +import assert from "node:assert/strict"; + +import { analyzePrefix, generatePromptCacheKey } from "../../src/lib/promptCache"; + +describe("prompt cache prefix analyzer", () => { + it("captures stable system prefixes and derives a cache key", () => { + const messages = [ + { role: "system", content: "You are helpful." }, + { role: "user", content: "Hello" }, + ]; + + const analysis = analyzePrefix(messages); + + assert.equal(analysis.prefixEndIdx, 0); + assert.equal(analysis.prefixType, "system_only"); + assert.equal(analysis.confidence, 0.9); + assert.ok(analysis.prefixTokens > 0); + assert.match(generatePromptCacheKey(messages), /^omni-[a-f0-9]{32}$/); + }); + + it("keeps the legacy empty-content key when there is no prefix", () => { + const messages = [{ role: "user", content: "Hello" }]; + + const analysis = analyzePrefix(messages); + + assert.equal(analysis.prefixEndIdx, -1); + assert.equal(generatePromptCacheKey(messages), "omni-e3b0c44298fc1c149afbf4c8996fb924"); + }); +});