diff --git a/src/agents/pi-embedded-runner/history.test.ts b/src/agents/pi-embedded-runner/history.test.ts new file mode 100644 index 00000000000..93e5ac5a0de --- /dev/null +++ b/src/agents/pi-embedded-runner/history.test.ts @@ -0,0 +1,16 @@ +import { describe, expect, it } from "vitest"; +import { getHistoryLimitFromSessionKey } from "./history.js"; + +describe("getHistoryLimitFromSessionKey", () => { + it("matches channel history limits across canonical provider aliases", () => { + expect( + getHistoryLimitFromSessionKey("agent:main:z-ai:channel:general", { + channels: { + "z.ai": { + historyLimit: 17, + }, + }, + }), + ).toBe(17); + }); +}); diff --git a/src/agents/pi-embedded-runner/history.ts b/src/agents/pi-embedded-runner/history.ts index 6515c0c13d5..4a52280cfbb 100644 --- a/src/agents/pi-embedded-runner/history.ts +++ b/src/agents/pi-embedded-runner/history.ts @@ -1,5 +1,6 @@ import type { AgentMessage } from "@mariozechner/pi-agent-core"; import type { OpenClawConfig } from "../../config/config.js"; +import { normalizeProviderId } from "../provider-id.js"; const THREAD_SUFFIX_REGEX = /^(.*)(?::(?:thread|topic):\d+)$/i; @@ -51,7 +52,7 @@ export function getHistoryLimitFromSessionKey( const parts = sessionKey.split(":").filter(Boolean); const providerParts = parts.length >= 3 && parts[0] === "agent" ? parts.slice(2) : parts; - const provider = providerParts[0]?.toLowerCase(); + const provider = normalizeProviderId(providerParts[0] ?? ""); if (!provider) { return undefined; } @@ -74,15 +75,22 @@ export function getHistoryLimitFromSessionKey( if (!channels || typeof channels !== "object") { return undefined; } - const entry = (channels as Record)[providerId]; - if (!entry || typeof entry !== "object" || Array.isArray(entry)) { - return undefined; + for (const [configuredProviderId, value] of Object.entries( + channels as Record, + )) { + if (normalizeProviderId(configuredProviderId) !== providerId) { + continue; + } + if (!value || typeof value !== "object" || Array.isArray(value)) { + return undefined; + } + return value as { + historyLimit?: number; + dmHistoryLimit?: number; + dms?: Record; + }; } - return entry as { - historyLimit?: number; - dmHistoryLimit?: number; - dms?: Record; - }; + return undefined; }; const providerConfig = resolveProviderConfig(config, provider);