fix(ai): allow prompt cache keys for compatible proxies (#9442)

This commit is contained in:
Danila Poyarkov 2026-11-04 14:36:35 +04:00 • committed by GitHub
parent a3a1005053
commit 0f4d5e960a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 252 additions and 7 deletions

View file

@ -549,6 +549,27 @@ describe("ModelRegistry", () => {
expect(compat?.supportsEagerToolInputStreaming).toBe(false);
});
test("custom models inherit and override prompt cache key mode independently of long retention", async () => {
const provider: ModelsJsonProvider = {
baseUrl: "https://proxy.example.com/v1",
api: "openai-completions",
compat: { promptCacheKeyMode: "enabled", supportsLongCacheRetention: false },
models: [{ id: "inherited" }, { id: "disabled", compat: { promptCacheKeyMode: "disabled" } }],
};
writeRawModelsJson({ demo: provider });
const registry = await createModelRegistry(authStorage, modelsJsonPath);
expect(registry.getError()).toBeUndefined();
expect(registry.find("demo", "inherited")?.compat).toMatchObject({
promptCacheKeyMode: "enabled",
supportsLongCacheRetention: false,
});
expect(registry.find("demo", "disabled")?.compat).toMatchObject({
promptCacheKeyMode: "disabled",
supportsLongCacheRetention: false,
});
});
test("compat schema accepts long cache retention flag", async () => {
writeRawModelsJson({
demo: {
@ -922,6 +943,22 @@ describe("ModelRegistry", () => {
expect((opus?.compat as OpenAICompletionsCompat | undefined)?.supportsFinishReason).toBe(true);
});
test("built-in models inherit prompt cache key support unless overridden", async () => {
const provider: ModelsJsonProvider = {
baseUrl: "https://proxy.example.com/v1",
compat: { promptCacheKeyMode: "enabled" },
modelOverrides: {
"gpt-4o-mini": { compat: { promptCacheKeyMode: "disabled" } },
},
};
writeRawModelsJson({ openai: provider });
const registry = await createModelRegistry(authStorage, modelsJsonPath);
expect(registry.getError()).toBeUndefined();
expect(registry.find("openai", "gpt-4o")?.compat).toMatchObject({ promptCacheKeyMode: "enabled" });
expect(registry.find("openai", "gpt-4o-mini")?.compat).toMatchObject({ promptCacheKeyMode: "disabled" });
});
test("model override deep merges compat settings", async () => {
writeRawModelsJson({
openrouter: {