Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/lib/glm-coding-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ export async function queryGlmCodingPlanQuota(
: undefined;
const window = { percentRemaining: clampPercent(100 - limit.percentage), resetTimeIso };

const isQuotaWindow =
limit.type === "TOKENS_LIMIT" ||
(descriptor.envelope === "zai" && limit.type === "CREDIT_LIMIT");
const isQuotaWindow = limit.type === "TOKENS_LIMIT" || limit.type === "CREDIT_LIMIT";
if (isQuotaWindow && limit.unit === 3) windows.fiveHour = window;
else if (isQuotaWindow && limit.unit === 6) windows.weekly = window;
else if (limit.type === "TIME_LIMIT") windows.mcp = window;
Expand Down
19 changes: 16 additions & 3 deletions tests/lib.glm-coding-plan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ describe("provider-specific GLM envelopes", () => {
}
});

it("maps Z.ai credit limits to percent windows without inferring credit amounts", async () => {
it("maps credit limits to percent windows for both providers without inferring credit amounts", async () => {
const resetMs = 1_735_776_000_000;
const creditLimits = [
{
Expand Down Expand Up @@ -275,11 +275,24 @@ describe("provider-specific GLM envelopes", () => {

configure(providers[1]);
stubJson(quotaResponse(creditLimits));
await expect(queryZhipuQuota()).resolves.toEqual({
const zhipuResult = await queryZhipuQuota();
expect(zhipuResult).toEqual({
success: true,
label: "Zhipu",
windows: {},
windows: {
fiveHour: {
percentRemaining: 96,
resetTimeIso: new Date(resetMs).toISOString(),
},
weekly: {
percentRemaining: 89,
resetTimeIso: new Date(resetMs + 1_000).toISOString(),
},
},
});
expect(zhipuResult).not.toHaveProperty("windows.fiveHour.usage");
expect(zhipuResult).not.toHaveProperty("windows.fiveHour.currentValue");
expect(zhipuResult).not.toHaveProperty("windows.fiveHour.remaining");
});

it("allows Z.ai root limits but keeps Zhipu strict to data.limits", async () => {
Expand Down