Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 智谱 unit 缺失窗口按重置时间升序兜底,对齐新套餐变体
JupiterTheWarlock532ef60f3a07
diff --git a/apps/desktop/src/main/maker-host/__tests__/provider-account-usage.test.ts b/apps/desktop/src/main/maker-host/__tests__/provider-account-usage.test.tsindex 02454ba7af..76f91c7a64 100644--- a/apps/desktop/src/main/maker-host/__tests__/provider-account-usage.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/provider-account-usage.test.ts@@ -138,6 +138,44 @@ describe('parseZhipuCodingPlanQuota', () => {expect(() => parseZhipuCodingPlanQuota({ success: true }, 1)).toThrow(/invalid/);expect(() => parseZhipuCodingPlanQuota(null, 1)).toThrow(/invalid/);});++ it('classifies unit-less limits by reset order (new plan variant), ignoring TIME_LIMIT', () => {+ // 新套餐 unit 缺失变体:两条 TOKENS_LIMIT,nextResetTime 较近的归 5 小时、+ // 较远的归周限;故意把周限放数组前面,验证不依赖输入顺序。+ const snapshot = parseZhipuCodingPlanQuota(+ {+ success: true,+ data: {+ limits: [+ { type: 'TOKENS_LIMIT', percentage: 53, nextResetTime: 2_000_000_000_000 },+ { type: 'TOKENS_LIMIT', percentage: 44, nextResetTime: 1_000_000_000_000 },+ { type: 'TIME_LIMIT', percentage: 7 },+ ],+ level: 'pro',+ },+ },+ 7,+ );+ expect(snapshot.fiveHour).toEqual({ usedPercent: 44, resetsAt: 1_000_000_000_000 });+ expect(snapshot.weekly).toEqual({ usedPercent: 53, resetsAt: 2_000_000_000_000 });+ });++ it('falls back to five-hour for a single unit-less limit (old plan)', () => {+ const snapshot = parseZhipuCodingPlanQuota(+ {+ success: true,+ data: {+ limits: [+ { type: 'TOKENS_LIMIT', percentage: 2, nextResetTime: 1_774_967_594_803 },+ { type: 'TIME_LIMIT', percentage: 0 },+ ],+ },+ },+ 7,+ );+ expect(snapshot.fiveHour).toEqual({ usedPercent: 2, resetsAt: 1_774_967_594_803 });+ expect(snapshot.weekly).toBeNull();+ });});describe('resolveProviderAccountUsage', () => {diff --git a/apps/desktop/src/main/maker-host/provider-account-usage.ts b/apps/desktop/src/main/maker-host/provider-account-usage.tsindex d9d16a43b4..488485f75f 100644--- a/apps/desktop/src/main/maker-host/provider-account-usage.ts+++ b/apps/desktop/src/main/maker-host/provider-account-usage.ts@@ -308,19 +308,24 @@ export function parseZhipuCodingPlanQuota(? line.nextResetTime: null;const unit = typeof line.unit === 'number' ? line.unit : null;- // unit 3 = 5 小时窗口、6 = 每周窗口;缺失时兑底:无 reset 优先归 5 小时。+ // unit 3 = 5 小时窗口、6 = 每周窗口(新套餐 unit 6 的 number 有 7 和 1 两种取值,+ // 只锚 unit);缺失时兑底见下。if (unit === 3 && !fiveHour) fiveHour = { usedPercent: percent, resetsAt };else if (unit === 6 && !weekly) weekly = { usedPercent: percent, resetsAt };else if (unit == null) unclassified.push({ reset: resetsAt, percent });}+ // unit 缺失的兑底(与社区工具同口径):无 nextResetTime 的条目优先归 5 小时+ // (0% 状态下 5 小时桶可能没有 reset),其余按 reset 升序依次填入空缺槽位——+ // 新套餐周末比 5 小时窗更早重置时,按数组顺序填会标反。+ unclassified.sort((a, b) => {+ const aHas = a.reset === null ? 0 : 1;+ const bHas = b.reset === null ? 0 : 1;+ if (aHas !== bHas) return aHas - bHas;+ return (a.reset ?? 0) - (b.reset ?? 0);+ });for (const entry of unclassified) {- if (!fiveHour && entry.reset === null) fiveHour = { usedPercent: entry.percent, resetsAt: null };- else if (!fiveHour || !weekly) {- const target = fiveHour ? 'weekly' : 'fiveHour';- const window = { usedPercent: entry.percent, resetsAt: entry.reset };- if (target === 'weekly') weekly = window;- else fiveHour = window;- }+ if (!fiveHour) fiveHour = { usedPercent: entry.percent, resetsAt: entry.reset };+ else if (!weekly) weekly = { usedPercent: entry.percent, resetsAt: entry.reset };}return { kind: 'zhipu-coding-plan-quota', noPlan: false, level, fiveHour, weekly, fetchedAt };}