Skip to content

Commit 173f5da

Browse files
authored
Merge pull request #256 from ConcealedBlade/fix/zhipu-credit-limit
fix(glm-coding-plan): recognize CREDIT_LIMIT windows for the Zhipu descriptor
2 parents fc95c13 + 4a1e25a commit 173f5da

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/lib/glm-coding-plan.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ export async function queryGlmCodingPlanQuota(
7575
: undefined;
7676
const window = { percentRemaining: clampPercent(100 - limit.percentage), resetTimeIso };
7777

78-
const isQuotaWindow =
79-
limit.type === "TOKENS_LIMIT" ||
80-
(descriptor.envelope === "zai" && limit.type === "CREDIT_LIMIT");
78+
const isQuotaWindow = limit.type === "TOKENS_LIMIT" || limit.type === "CREDIT_LIMIT";
8179
if (isQuotaWindow && limit.unit === 3) windows.fiveHour = window;
8280
else if (isQuotaWindow && limit.unit === 6) windows.weekly = window;
8381
else if (limit.type === "TIME_LIMIT") windows.mcp = window;

tests/lib.glm-coding-plan.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ describe("provider-specific GLM envelopes", () => {
227227
}
228228
});
229229

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

276276
configure(providers[1]);
277277
stubJson(quotaResponse(creditLimits));
278-
await expect(queryZhipuQuota()).resolves.toEqual({
278+
const zhipuResult = await queryZhipuQuota();
279+
expect(zhipuResult).toEqual({
279280
success: true,
280281
label: "Zhipu",
281-
windows: {},
282+
windows: {
283+
fiveHour: {
284+
percentRemaining: 96,
285+
resetTimeIso: new Date(resetMs).toISOString(),
286+
},
287+
weekly: {
288+
percentRemaining: 89,
289+
resetTimeIso: new Date(resetMs + 1_000).toISOString(),
290+
},
291+
},
282292
});
293+
expect(zhipuResult).not.toHaveProperty("windows.fiveHour.usage");
294+
expect(zhipuResult).not.toHaveProperty("windows.fiveHour.currentValue");
295+
expect(zhipuResult).not.toHaveProperty("windows.fiveHour.remaining");
283296
});
284297

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

0 commit comments

Comments
 (0)