refactor: move text chunk limits to providers
This commit is contained in:
@@ -55,20 +55,15 @@ describe("resolveTextChunkLimit", () => {
|
||||
expect(resolveTextChunkLimit(undefined, "discord")).toBe(2000);
|
||||
});
|
||||
|
||||
it("supports a global override", () => {
|
||||
const cfg = { messages: { textChunkLimit: 1234 } };
|
||||
expect(resolveTextChunkLimit(cfg, "whatsapp")).toBe(1234);
|
||||
expect(resolveTextChunkLimit(cfg, "discord")).toBe(1234);
|
||||
});
|
||||
|
||||
it("prefers per-surface overrides over global", () => {
|
||||
const cfg = {
|
||||
messages: {
|
||||
textChunkLimit: 1234,
|
||||
textChunkLimitBySurface: { discord: 111 },
|
||||
},
|
||||
};
|
||||
expect(resolveTextChunkLimit(cfg, "discord")).toBe(111);
|
||||
it("supports provider overrides", () => {
|
||||
const cfg = { telegram: { textChunkLimit: 1234 } };
|
||||
expect(resolveTextChunkLimit(cfg, "whatsapp")).toBe(4000);
|
||||
expect(resolveTextChunkLimit(cfg, "telegram")).toBe(1234);
|
||||
});
|
||||
|
||||
it("uses the matching provider override", () => {
|
||||
const cfg = { discord: { textChunkLimit: 111 } };
|
||||
expect(resolveTextChunkLimit(cfg, "discord")).toBe(111);
|
||||
expect(resolveTextChunkLimit(cfg, "telegram")).toBe(4000);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,19 +22,21 @@ const DEFAULT_CHUNK_LIMIT_BY_SURFACE: Record<TextChunkSurface, number> = {
|
||||
};
|
||||
|
||||
export function resolveTextChunkLimit(
|
||||
cfg: Pick<ClawdisConfig, "messages"> | undefined,
|
||||
cfg: ClawdisConfig | undefined,
|
||||
surface?: TextChunkSurface,
|
||||
): number {
|
||||
const surfaceOverride = surface
|
||||
? cfg?.messages?.textChunkLimitBySurface?.[surface]
|
||||
: undefined;
|
||||
const surfaceOverride = (() => {
|
||||
if (!surface) return undefined;
|
||||
if (surface === "whatsapp") return cfg?.whatsapp?.textChunkLimit;
|
||||
if (surface === "telegram") return cfg?.telegram?.textChunkLimit;
|
||||
if (surface === "discord") return cfg?.discord?.textChunkLimit;
|
||||
if (surface === "signal") return cfg?.signal?.textChunkLimit;
|
||||
if (surface === "imessage") return cfg?.imessage?.textChunkLimit;
|
||||
return undefined;
|
||||
})();
|
||||
if (typeof surfaceOverride === "number" && surfaceOverride > 0) {
|
||||
return surfaceOverride;
|
||||
}
|
||||
const globalOverride = cfg?.messages?.textChunkLimit;
|
||||
if (typeof globalOverride === "number" && globalOverride > 0) {
|
||||
return globalOverride;
|
||||
}
|
||||
if (surface) return DEFAULT_CHUNK_LIMIT_BY_SURFACE[surface];
|
||||
return 4000;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user