Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(chat): refine quota and rate-limit recovery UX (#17222)

Arvin Xu384de99fc7c2
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index 63e1ef2a1a2..70a689abc49 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -378,6 +378,7 @@
"heteroAgent.quota.duration.hour_other": "{{count}}h",
"heteroAgent.quota.duration.minute_one": "{{count}}m",
"heteroAgent.quota.duration.minute_other": "{{count}}m",
+ "heteroAgent.quota.exhausted": "Exhausted",
"heteroAgent.quota.left": "{{percent}}% left",
"heteroAgent.quota.noData": "Quota is not available yet.",
"heteroAgent.quota.refresh": "Refresh quota",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index 1ddc7cafc5c..3ac4bf8b83c 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -378,6 +378,7 @@
"heteroAgent.quota.duration.hour_other": "{{count}}小时",
"heteroAgent.quota.duration.minute_one": "{{count}}分钟",
"heteroAgent.quota.duration.minute_other": "{{count}}分钟",
+ "heteroAgent.quota.exhausted": "已耗尽",
"heteroAgent.quota.left": "剩余 {{percent}}%",
"heteroAgent.quota.noData": "暂未获取到额度。",
"heteroAgent.quota.refresh": "刷新额度",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index e85fdc93028..124087e1e87 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -307,6 +307,7 @@ export default {
'heteroAgent.codexQuota.title': 'Codex quota',
'heteroAgent.codexQuota.tooltip': 'View Codex quota',
'heteroAgent.quota.compactLeft': '{{percent}}%',
+ 'heteroAgent.quota.exhausted': 'Exhausted',
'heteroAgent.quota.duration.day_one': '{{count}}d',
'heteroAgent.quota.duration.day_other': '{{count}}d',
'heteroAgent.quota.duration.hour_one': '{{count}}h',
diff --git a/src/features/Conversation/Error/index.test.tsx b/src/features/Conversation/Error/index.test.tsx
index 2133770ae31..1e1ab9f63ce 100644
--- a/src/features/Conversation/Error/index.test.tsx
+++ b/src/features/Conversation/Error/index.test.tsx
@@ -4,13 +4,14 @@ import type * as modelRuntimeModule from '@lobechat/model-runtime';
import { AgentRuntimeErrorType } from '@lobechat/model-runtime';
import type * as lobechatTypesModule from '@lobechat/types';
import type * as lobehubUiModule from '@lobehub/ui';
-import { render, screen } from '@testing-library/react';
+import { fireEvent, render, screen } from '@testing-library/react';
import type { ReactNode } from 'react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import ErrorMessageExtra from './index';
const navigateMock = vi.fn();
+const updateMessageErrorMock = vi.fn();
const serverConfigMock = vi.hoisted(() => ({ enableBusinessFeatures: false }));
@@ -92,8 +93,19 @@ vi.mock('@/features/Conversation/ChatItem/components/ErrorContent', () => ({
}));
vi.mock('@/features/Electron/HeterogeneousAgent/StatusGuide', () => ({
- default: ({ agentType, error }: { agentType?: string; error?: { code?: string } }) => (
- <div>{`guide:${agentType}:${error?.code}`}</div>
+ default: ({
+ agentType,
+ error,
+ onDismiss,
+ }: {
+ agentType?: string;
+ error?: { code?: string };
+ onDismiss?: () => void;
+ }) => (
+ <div>
+ {`guide:${agentType}:${error?.code}`}
+ {onDismiss && <button onClick={onDismiss}>dismiss</button>}
+ </div>
),
}));
@@ -127,12 +139,14 @@ vi.mock('@/features/Conversation/store', () => ({
markHeteroOverloadRetryExhausted: vi.fn(),
recordHeteroOverloadRetry: vi.fn(),
resetHeteroOverloadRetry: vi.fn(),
+ updateMessageError: updateMessageErrorMock,
}),
}));
describe('ErrorMessageExtra', () => {
beforeEach(() => {
serverConfigMock.enableBusinessFeatures = false;
+ updateMessageErrorMock.mockClear();
});
it('keeps the localized message for known error types even when a traceId exists', () => {
@@ -284,6 +298,27 @@ describe('ErrorMessageExtra', () => {
expect(screen.getByText('guide:claude-code:rate_limit')).toBeInTheDocument();
});
+ it('dismisses only the current heterogeneous error field', () => {
+ render(
+ <ErrorMessageExtra
+ error={{ message: 'response.undefined' }}
+ data={{
+ error: {
+ body: {
+ agentType: 'claude-code',
+ code: HeterogeneousAgentSessionErrorCode.RateLimit,
+ },
+ } as any,
+ id: 'failed-step-2',
+ }}
+ />,
+ );
+
+ fireEvent.click(screen.getByRole('button', { name: 'dismiss' }));
+
+ expect(updateMessageErrorMock).toHaveBeenCalledWith('failed-step-2', null);
+ });
+
it('renders the heterogeneous guide from the session body without relying on the top-level error type', () => {
render(
<ErrorMessageExtra
diff --git a/src/features/Conversation/Error/index.tsx b/src/features/Conversation/Error/index.tsx
index 528d20b5c89..f824b0caf26 100644
--- a/src/features/Conversation/Error/index.tsx
+++ b/src/features/Conversation/Error/index.tsx
@@ -257,6 +257,7 @@ const ErrorMessageExtra = memo<ErrorExtraProps>(
const rawErrorMessage = getRawErrorMessage(error) || alertError?.message;
const delAndRegenerateMessage = useConversationStore((s) => s.delAndRegenerateMessage);
+ const updateMessageError = useConversationStore((s) => s.updateMessageError);
const resetHeteroOverloadRetry = useConversationStore((s) => s.resetHeteroOverloadRetry);
// Standalone surface: data.id is the top-level assistant message, so its
// parentId is the user message. Group surface passes retryScopeId directly.
@@ -345,6 +346,7 @@ const ErrorMessageExtra = memo<ErrorExtraProps>(
autoRetry={autoRetry}
error={sessionErrorBody}
schedule={schedule}
+ onDismiss={() => void updateMessageError(data.id, null)}
onOpenSystemTools={() => navigate('/settings/system-tools')}
onRetry={handleManualRetry}
/>
diff --git a/src/features/Electron/HeterogeneousAgent/StatusGuide/GuideShell.tsx b/src/features/Electron/HeterogeneousAgent/StatusGuide/GuideShell.tsx
index e2d3afcf5fd..0da0274d653 100644
--- a/src/features/Electron/HeterogeneousAgent/StatusGuide/GuideShell.tsx
+++ b/src/features/Electron/HeterogeneousAgent/StatusGuide/GuideShell.tsx
@@ -1,6 +1,8 @@
-import { Avatar, Block, Flexbox, Text } from '@lobehub/ui';
+import { ActionIcon, Avatar, Block, Flexbox, Text, Tooltip } from '@lobehub/ui';
import { cssVar } from 'antd-style';
+import { X } from 'lucide-react';
import type { ReactNode } from 'react';
+import { useTranslation } from 'react-i18next';
import type { HeterogeneousAgentStatusGuideVariant } from './types';
@@ -15,6 +17,7 @@ interface GuideShellProps {
compact?: boolean;
headerDescription?: ReactNode;
icon: ReactNode;
+ onDismiss?: () => void;
title: string;
variant: HeterogeneousAgentStatusGuideVariant;
}
@@ -25,9 +28,11 @@ const GuideShell = ({
compact = false,
headerDescription,
icon,
+ onDismiss,
title,
variant,
}: GuideShellProps) => {
+ const { t } = useTranslation('common');
const showHeader = variant !== 'embedded';
// Compact cards keep the actions on the same row as the title/description
// (right-aligned) so the whole status reads as a single tight line.
@@ -51,7 +56,16 @@ const GuideShell = ({
{headerDescription}
</Flexbox>
</Flexbox>
- {actionsInHeader && <Flexbox style={{ flexShrink: 0 }}>{actions}</Flexbox>}
+ {(actionsInHeader || onDismiss) && (
+ <Flexbox horizontal align="center" gap={8} style={{ flexShrink: 0 }}>
+ {actionsInHeader && actions}
+ {onDismiss && (
+ <Tooltip title={t('close')}>
+ <ActionIcon aria-label={t('close')} icon={X} size="small" onClick={onDismiss} />
+ </Tooltip>
+ )}
+ </Flexbox>
+ )}
</Flexbox>
) : (
headerDescription
diff --git a/src/features/Electron/HeterogeneousAgent/StatusGuide/index.tsx b/src/features/Electron/HeterogeneousAgent/StatusGuide/index.tsx
index fddf742f436..89a24b2d67f 100644
--- a/src/features/Electron/HeterogeneousAgent/StatusGuide/index.tsx
+++ b/src/features/Electron/HeterogeneousAgent/StatusGuide/index.tsx
@@ -15,6 +15,7 @@ const HeterogeneousAgentStatusGuide = memo<HeterogeneousAgentStatusGuideProps>(
agentType = 'codex',
autoRetry,
error,
+ onDismiss,
onOpenSystemTools,
onRetry,
schedule,
@@ -28,6 +29,7 @@ const HeterogeneousAgentStatusGuide = memo<HeterogeneousAgentStatusGuideProps>(
autoRetry,
config,
error,
+ onDismiss,
onOpenSystemTools,
onRetry,
schedule,
diff --git a/src/features/Electron/HeterogeneousAgent/StatusGuide/states/RateLimitState.tsx b/src/features/Electron/HeterogeneousAgent/StatusGuide/states/RateLimitState.tsx
index 20eac4e1e26..57c9f50d30c 100644
--- a/src/features/Electron/HeterogeneousAgent/StatusGuide/states/RateLimitState.tsx
+++ b/src/features/Electron/HeterogeneousAgent/StatusGuide/states/RateLimitState.tsx
@@ -18,6 +18,7 @@ const extractTimezoneLabel = (value?: string) => {
const RateLimitState = ({
config,
error,
+ onDismiss,
onOpenSystemTools,
onRetry,
schedule,
@@ -171,6 +172,7 @@ const RateLimitState = ({
)}
</Text>
}
+ onDismiss={onDismiss}
>
<Flexbox gap={8}>
{formattedResetAt && (
diff --git a/src/features/Electron/HeterogeneousAgent/StatusGuide/types.ts b/src/features/Electron/HeterogeneousAgent/StatusGuide/types.ts
index 6a0f1e9721f..101816b4fd7 100644
--- a/src/features/Electron/HeterogeneousAgent/StatusGuide/types.ts
+++ b/src/features/Electron/HeterogeneousAgent/StatusGuide/types.ts
@@ -34,6 +34,7 @@ export interface HeterogeneousAgentStatusGuideProps {
agentType?: string;
autoRetry?: HeterogeneousAgentAutoRetryState;
error?: HeterogeneousAgentSessionError | null;
+ onDismiss?: () => void;
onOpenSystemTools?: () => void;
onRetry?: () => void;
schedule?: HeterogeneousAgentScheduleState;
@@ -57,6 +58,7 @@ export interface HeterogeneousAgentGuideStateProps {
autoRetry?: HeterogeneousAgentAutoRetryState;
config: HeterogeneousAgentGuideConfig;
error?: HeterogeneousAgentSessionError | null;
+ onDismiss?: () => void;
onOpenSystemTools?: () => void;
onRetry?: () => void;
schedule?: HeterogeneousAgentScheduleState;
diff --git a/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/QuotaMenu.test.tsx b/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/QuotaMenu.test.tsx
index 308bfb5cad6..cf7887de0a1 100644
--- a/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/QuotaMenu.test.tsx
+++ b/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/QuotaMenu.test.tsx
@@ -123,6 +123,21 @@ describe('ClaudeCodeQuotaMenu', () => {
});
});
+ it('warns below 15 percent and labels zero quota as exhausted', async () => {
+ mockService.getClaudeCodeQuota.mockResolvedValue(
+ claudeSnapshot({
+ session: { resetsAt: null, usedPercent: 100, windowMinutes: 300 },
+ weekly: { resetsAt: null, usedPercent: 86, windowMinutes: 10_080 },
+ }),
+ );
+
+ render(<ClaudeCodeQuotaMenu />);
+
+ expect(await screen.findAllByText('heteroAgent.quota.exhausted')).toHaveLength(2);
+ expect(screen.getByText('heteroAgent.quota.left:14')).toBeTruthy();
+ expect(document.querySelectorAll('[data-quota-level="low"]')).toHaveLength(3);
+ });
+
it('maps unavailable reasons to their localized explanations', async () => {
mockService.getClaudeCodeQuota.mockResolvedValue(
claudeSnapshot({
diff --git a/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/QuotaMenu.tsx b/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/QuotaMenu.tsx
index 86aeef60b04..8fa6bcbf8fe 100644
--- a/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/QuotaMenu.tsx
+++ b/src/routes/(main)/agent/features/Conversation/HeterogeneousChatInput/QuotaMenu.tsx
@@ -49,6 +49,9 @@ const styles = createStaticStyles(({ css }) => ({
border-radius: inherit;
background: ${cssVar.colorSuccess};
`,
+ progressFillWarning: css`
+ background: ${cssVar.colorWarning};
+ `,
progressTrack: css`
overflow: hidden;
@@ -85,6 +88,14 @@ const styles = createStaticStyles(({ css }) => ({
color: ${cssVar.colorTextSecondary};
background: ${cssVar.colorFillSecondary};
}
+
+ &[data-quota-level='low'] {
+ color: ${cssVar.colorWarningText};
+
+ &:hover {
+ color: ${cssVar.colorWarningText};
+ }
+ }
`,
triggerOpen: css`
color: ${cssVar.colorTextSecondary};
@@ -99,6 +110,9 @@ const styles = createStaticStyles(({ css }) => ({
}));
const clampPercent = (value: number) => Math.min(100, Math.max(0, Math.round(value)));
+const LOW_QUOTA_THRESHOLD = 15;
+
+const isLowQuota = (leftPercent: number) => leftPercent < LOW_QUOTA_THRESHOLD;
type QuotaSourcePart = Record<string, string | undefined> | string | null | undefined;
@@ -351,6 +365,7 @@ const QuotaMenu = <S extends QuotaSnapshotBase>({
const leftPercent = clampPercent(100 - window.usedPercent);
const resetLabel = formatResetCountdown(window.resetsAt);
+ const lowQuota = isLowQuota(leftPercent);
return (
<Flexbox className={styles.window} gap={4} key={key}>
@@ -358,11 +373,17 @@ const QuotaMenu = <S extends QuotaSnapshotBase>({
{label}
</Text>
<div className={styles.progressTrack}>
- <div className={styles.progressFill} style={{ width: `${leftPercent}%` }} />
+ <div
+ className={cx(styles.progressFill, lowQuota && styles.progressFillWarning)}
+ data-quota-level={lowQuota ? 'low' : 'normal'}
+ style={{ width: `${leftPercent}%` }}
+ />
</div>
<Flexbox horizontal style={{ justifyContent: 'space-between' }}>
<Text className={styles.value} style={{ fontSize: 12 }}>
- {t('heteroAgent.quota.left', { percent: leftPercent })}
+ {leftPercent === 0
+ ? t('heteroAgent.quota.exhausted')
+ : t('heteroAgent.quota.left', { percent: leftPercent })}
</Text>
{resetLabel && (
<Text style={{ fontSize: 12 }} type="secondary">
@@ -428,10 +449,21 @@ const QuotaMenu = <S extends QuotaSnapshotBase>({
aria-label={tooltip}
className={cx(styles.trigger, open && styles.triggerOpen)}
type="button"
+ data-quota-level={
+ compactLeftPercent === undefined
+ ? undefined
+ : isLowQuota(compactLeftPercent)
+ ? 'low'
+ : 'normal'
+ }
>
<Icon icon={GaugeIcon} size={14} />
{compactLeftPercent !== undefined && (
- <span>{t('heteroAgent.quota.compactLeft', { percent: compactLeftPercent })}</span>
+ <span>
+ {compactLeftPercent === 0
+ ? t('heteroAgent.quota.exhausted')
+ : t('heteroAgent.quota.compactLeft', { percent: compactLeftPercent })}
+ </span>
)}
<Icon icon={ChevronDownIcon} size={12} />
</button>