fix(agents): extend cache-ttl eligibility for moonshot and zai
Co-authored-by: lailoo <lailoo@users.noreply.github.com>
This commit is contained in:
@@ -14,6 +14,7 @@ Docs: https://docs.openclaw.ai
|
||||
|
||||
### Fixes
|
||||
|
||||
- Agents/Context pruning: extend `cache-ttl` eligibility to Moonshot/Kimi and ZAI/GLM providers (including OpenRouter model refs), so `contextPruning.mode: "cache-ttl"` is no longer silently skipped for those sessions. (#24497) Thanks @lailoo.
|
||||
- Sessions/Store: canonicalize inbound mixed-case session keys for metadata and route updates, and migrate legacy case-variant entries to a single lowercase key to prevent duplicate sessions and missing TUI/WebUI history. (#9561) Thanks @hillghost86.
|
||||
- Telegram/Reactions: soft-fail reaction action errors (policy/token/emoji/API), accept snake_case `message_id`, and fallback to inbound message-id context when explicit `messageId` is omitted so DM reactions stay stable without regeneration loops. (#20236, #21001) Thanks @PeterShanxin and @vincentkoc.
|
||||
- Telegram/Polling: scope persisted polling offsets to bot identity and reuse a single awaited runner-stop path on abort/retry, preventing cross-token offset bleed and overlapping pollers during restart/error recovery. (#10850, #11347) Thanks @talhaorak, @anooprdawar, and @vincentkoc.
|
||||
|
||||
30
src/agents/pi-embedded-runner/cache-ttl.test.ts
Normal file
30
src/agents/pi-embedded-runner/cache-ttl.test.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isCacheTtlEligibleProvider } from "./cache-ttl.js";
|
||||
|
||||
describe("isCacheTtlEligibleProvider", () => {
|
||||
it("allows anthropic", () => {
|
||||
expect(isCacheTtlEligibleProvider("anthropic", "claude-sonnet-4-20250514")).toBe(true);
|
||||
});
|
||||
|
||||
it("allows moonshot and zai providers", () => {
|
||||
expect(isCacheTtlEligibleProvider("moonshot", "kimi-k2.5")).toBe(true);
|
||||
expect(isCacheTtlEligibleProvider("zai", "glm-5")).toBe(true);
|
||||
});
|
||||
|
||||
it("is case-insensitive for native providers", () => {
|
||||
expect(isCacheTtlEligibleProvider("Moonshot", "Kimi-K2.5")).toBe(true);
|
||||
expect(isCacheTtlEligibleProvider("ZAI", "GLM-5")).toBe(true);
|
||||
});
|
||||
|
||||
it("allows openrouter cache-ttl models", () => {
|
||||
expect(isCacheTtlEligibleProvider("openrouter", "anthropic/claude-sonnet-4")).toBe(true);
|
||||
expect(isCacheTtlEligibleProvider("openrouter", "moonshotai/kimi-k2.5")).toBe(true);
|
||||
expect(isCacheTtlEligibleProvider("openrouter", "moonshot/kimi-k2.5")).toBe(true);
|
||||
expect(isCacheTtlEligibleProvider("openrouter", "zai/glm-5")).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects unsupported providers and models", () => {
|
||||
expect(isCacheTtlEligibleProvider("openai", "gpt-4o")).toBe(false);
|
||||
expect(isCacheTtlEligibleProvider("openrouter", "openai/gpt-4o")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -8,13 +8,25 @@ export type CacheTtlEntryData = {
|
||||
modelId?: string;
|
||||
};
|
||||
|
||||
const CACHE_TTL_NATIVE_PROVIDERS = new Set(["anthropic", "moonshot", "zai"]);
|
||||
const OPENROUTER_CACHE_TTL_MODEL_PREFIXES = [
|
||||
"anthropic/",
|
||||
"moonshot/",
|
||||
"moonshotai/",
|
||||
"zai/",
|
||||
] as const;
|
||||
|
||||
function isOpenRouterCacheTtlModel(modelId: string): boolean {
|
||||
return OPENROUTER_CACHE_TTL_MODEL_PREFIXES.some((prefix) => modelId.startsWith(prefix));
|
||||
}
|
||||
|
||||
export function isCacheTtlEligibleProvider(provider: string, modelId: string): boolean {
|
||||
const normalizedProvider = provider.toLowerCase();
|
||||
const normalizedModelId = modelId.toLowerCase();
|
||||
if (normalizedProvider === "anthropic") {
|
||||
if (CACHE_TTL_NATIVE_PROVIDERS.has(normalizedProvider)) {
|
||||
return true;
|
||||
}
|
||||
if (normalizedProvider === "openrouter" && normalizedModelId.startsWith("anthropic/")) {
|
||||
if (normalizedProvider === "openrouter" && isOpenRouterCacheTtlModel(normalizedModelId)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user