Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 模型来源行只显示最紧张的一个额度窗口 (#5422)

Dash73f364a103b9
diff --git a/apps/desktop/src/renderer/__tests__/modelSourceDetails.test.tsx b/apps/desktop/src/renderer/__tests__/modelSourceDetails.test.tsx
index d738607584..db422affe2 100644
--- a/apps/desktop/src/renderer/__tests__/modelSourceDetails.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/modelSourceDetails.test.tsx
@@ -129,9 +129,14 @@ describe('model source second line', () => {
{details('account-b')}
</ModelSourceUsageProvider>,
);
- expect(screen.getAllByText(quotaText('2小时 78%'))).toHaveLength(2);
+ // Only the tightest window is shown: account-a's weekly, account-b's five-hour.
+ expect(screen.getAllByText(quotaText('5天 42%'))).toHaveLength(2);
expect(screen.getByText(quotaText('2小时 12%'))).toBeTruthy();
- expect(screen.getAllByText(quotaText('5天 42%'))).toHaveLength(3);
+ expect(screen.queryByText(/2小时 78%/)).toBeNull();
+ expect(container.textContent).not.toContain('/');
+ expect(container.querySelector('[data-model-source-details]')?.getAttribute('title')).toBe(
+ 'account-a · Pro · 2小时 · 剩余 78% · 5天 · 剩余 42%',
+ );
expect(
reads.codex.mock.calls.filter(([enabled, id]) => enabled && id === 'account-a'),
).toHaveLength(1);
@@ -244,8 +249,8 @@ describe('model source second line', () => {
{details()}
</ModelSourceUsageProvider>,
);
- expect(screen.getByText(quotaText('2小时 78%'))).toBeTruthy();
- expect(screen.queryByText(quotaText('2小时 1%'))).toBeNull();
+ expect(screen.getByText(quotaText('5天 42%'))).toBeTruthy();
+ expect(screen.queryByText(/1%/)).toBeNull();
});
it('never falls back to Codex CLI quota for a ChatGPT bridge model', () => {
const { rerender } = render(
@@ -268,7 +273,7 @@ describe('model source second line', () => {
it('uses Claude model-scoped weekly quota and keeps unknown reset times honest', () => {
reads.claudeSnapshot = {
subscriptionType: 'max',
- fiveHour: { utilization: 0 },
+ fiveHour: { utilization: 95 },
sevenDay: { utilization: 50, resetsAt: now / 1000 + 86400 },
scoped: [
{
@@ -279,15 +284,17 @@ describe('model source second line', () => {
},
],
};
- render(
+ const { container } = render(
<ModelSourceUsageProvider providers={[provider('claude', 'claude')]} scope={local}>
{details('claude', 'claude-opus-5')}
</ModelSourceUsageProvider>,
);
expect(screen.getByText('claude · Max')).toBeTruthy();
- expect(screen.getByText(quotaText('— 100%'))).toBeTruthy();
- expect(screen.getByText(quotaText('2天 20%'))).toBeTruthy();
- expect(screen.queryByText(quotaText('1天 50%'))).toBeNull();
+ expect(screen.getByText(quotaText('— 5%'))).toBeTruthy();
+ expect(screen.queryByText(/20%/)).toBeNull();
+ expect(container.querySelector('[data-model-source-details]')?.getAttribute('title')).toBe(
+ 'claude · Max · 剩余 5% · 2天 · 剩余 20%',
+ );
});
it('shows current xAI weekly quota and hides stale values', () => {
reads.xaiSnapshot = {
@@ -321,7 +328,7 @@ describe('model source second line', () => {
</ModelSourceUsageProvider>,
);
const line = container.querySelector('[data-model-source-details]')!;
- expect(screen.getAllByText(reads.pendingLabel)).toHaveLength(2);
+ expect(screen.getAllByText(reads.pendingLabel)).toHaveLength(1);
expect(line.getAttribute('title')).toBe(
`account-a · Pro · ${reads.pendingLabel} · ${reads.pendingLabel}`,
);
@@ -335,6 +342,7 @@ describe('model source second line', () => {
it('replaces an expired period with reset pending, never inferred full quota', () => {
reads.accounts['account-a']!.rateLimits.primary!.resetsAt = now / 1000 + 1;
+ reads.accounts['account-a']!.rateLimits.secondary = null;
render(
<ModelSourceUsageProvider providers={[provider('account-a')]} scope={local}>
{details()}
@@ -353,4 +361,16 @@ describe('model source second line', () => {
expect(screen.getByText('—')).toBeTruthy();
expect(screen.queryByText('78%')).toBeNull();
});
+
+ it('keeps a live window at 0% used over a later window awaiting reset', () => {
+ reads.accounts['account-a'] = snapshot(0);
+ reads.accounts['account-a'].rateLimits.secondary!.resetsAt = now / 1000;
+ render(
+ <ModelSourceUsageProvider providers={[provider('account-a')]} scope={local}>
+ {details()}
+ </ModelSourceUsageProvider>,
+ );
+ expect(screen.getByText(quotaText('2小时 100%'))).toBeTruthy();
+ expect(screen.queryByText(reads.pendingLabel)).toBeNull();
+ });
});
diff --git a/apps/desktop/src/renderer/components/new-chat/ModelSourceDetails.tsx b/apps/desktop/src/renderer/components/new-chat/ModelSourceDetails.tsx
index 597b5777c3..0f60a7903f 100644
--- a/apps/desktop/src/renderer/components/new-chat/ModelSourceDetails.tsx
+++ b/apps/desktop/src/renderer/components/new-chat/ModelSourceDetails.tsx
@@ -168,9 +168,16 @@ export function ModelSourceDetails({
: [countdown, t('quotaCard.remainingPercent', { percent: remaining })]
.filter(Boolean)
.join(' · '),
- used: expired ? 0 : window.usedPercent,
+ // Expired windows rank below every live one, even a live window at 0% used.
+ used: expired ? -1 : window.usedPercent,
};
});
+ // The row only has room for one window: show the tightest live one (later window wins
+ // ties); the title keeps every window.
+ const tightest = parts.reduce<(typeof parts)[number] | undefined>(
+ (best, part) => (!best || part.used >= best.used ? part : best),
+ undefined,
+ );
const source = [label, plan].filter(Boolean).join(' · ');
return (
<div
@@ -179,38 +186,31 @@ export function ModelSourceDetails({
className="flex w-0 min-w-full items-center gap-1 whitespace-nowrap pl-[26px] pt-px text-12 leading-[1.4] text-[var(--text-secondary)]"
>
<span className="min-w-0 truncate">{source}</span>
- {parts.length > 0 && (
+ {tightest && (
<span aria-hidden className="shrink-0">
·
</span>
)}
- {parts.length > 0 && (
+ {tightest && (
<span className="min-w-0 max-w-[70%] truncate tabular-nums">
- <span className="inline-flex items-center gap-1">
- {parts.map((part, index) => (
- <span key={index} className="inline-flex items-center gap-1">
- {index > 0 && <span aria-hidden>/</span>}
- <span>
- {part.countdown}
- {part.percentage !== null && (
- <>
- {' '}
- <span
- className={
- part.used >= 90
- ? 'text-[var(--quota-bar-crit)]'
- : part.used > 70
- ? 'text-[var(--quota-bar-warn)]'
- : undefined
- }
- >
- {part.percentage}
- </span>
- </>
- )}
+ <span>
+ {tightest.countdown}
+ {tightest.percentage !== null && (
+ <>
+ {' '}
+ <span
+ className={
+ tightest.used >= 90
+ ? 'text-[var(--quota-bar-crit)]'
+ : tightest.used > 70
+ ? 'text-[var(--quota-bar-warn)]'
+ : undefined
+ }
+ >
+ {tightest.percentage}
</span>
- </span>
- ))}
+ </>
+ )}
</span>
</span>
)}