🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
💄 style(hetero-agent): show a model's weekly quota only when it is selected (#23071)
YuTengjing8ee13b039952
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.jsonindex 16b615e1cb9..4a3b9aa8a29 100644--- a/locales/zh-CN/chat.json+++ b/locales/zh-CN/chat.json@@ -1608,7 +1608,7 @@"heteroAgent.executionTarget.wakeStarting": "云端设备仍在启动,使用它的运行会等待其就绪。","heteroAgent.executionTarget.wakesWhenUsed": "使用时自动唤醒","heteroAgent.executionTarget.workspaceGroup": "工作区设备",- "heteroAgent.fullAccess.label": "完全访问权限",+ "heteroAgent.fullAccess.label": "完全访问","heteroAgent.fullAccess.tooltip": "本地编码 Agent 运行时对工作目录拥有完全的读写权限。当前暂不支持切换权限模式。","heteroAgent.kimiCodeQuota.calendar.title": "Kimi Code 用量日历","heteroAgent.kimiCodeQuota.errorGeneric": "无法获取 Kimi Code 额度,请稍后重试。",diff --git a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/ClaudeCodeQuotaMenu.tsx b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/ClaudeCodeQuotaMenu.tsxindex 6c540b7029f..73733da1fba 100644--- a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/ClaudeCodeQuotaMenu.tsx+++ b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/ClaudeCodeQuotaMenu.tsx@@ -13,6 +13,7 @@ import { fetchClaudeCodeQuotaSnapshot } from '@/services/heteroAgentQuota';import { getAgentQuotaStoreState } from '@/store/agentQuota';import { getElectronStoreState } from '@/store/electron';+import { useSelectedHeteroModel } from '../../HeteroModel/useEffectiveHeteroProvider';import QuotaAccountSwitcher from './QuotaAccountSwitcher';import type { FetchQuotaOptions, QuotaWindowItem } from './QuotaMenu';import QuotaMenu, { createQuotaSourceKey } from './QuotaMenu';@@ -20,6 +21,7 @@ import {buildClaudePanelSnapshot,hasRenderableWindow,isQuotaStale,+ isScopedQuotaModel,newestCapturedAt,} from './quotaViewModel';@@ -94,6 +96,7 @@ interface ClaudeCodeQuotaMenuProps {const ClaudeCodeQuotaMenu = memo<ClaudeCodeQuotaMenuProps>(({ deviceId, env }) => {const { t } = useTranslation('chat');const agentId = useAgentId();+ const selectedModel = useSelectedHeteroModel();const sourceKey = createQuotaSourceKey('claude-code', agentId, deviceId ?? 'local', env);// A persisted account becomes eligible for a device only after this mounted// menu has observed that device return the same external account identity.@@ -257,6 +260,8 @@ const ClaudeCodeQuotaMenu = memo<ClaudeCodeQuotaMenuProps>(({ deviceId, env }) ={compactGroup: 'scopedWeekly',compactLabel: quota.scopedWeekly.modelName,+ // A model's own weekly limit only bounds runs on that model.+ hideInCompact: !isScopedQuotaModel(selectedModel, quota.scopedWeekly.modelName),key: 'scopedWeekly',label: t('heteroAgent.claudeQuota.scopedWeekly', {model: quota.scopedWeekly.modelName,@@ -266,7 +271,7 @@ const ClaudeCodeQuotaMenu = memo<ClaudeCodeQuotaMenuProps>(({ deviceId, env }) =]: []),],- [t],+ [selectedModel, t],);const getReasonText = useCallback(diff --git a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.claudeCode.test.tsx b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.claudeCode.test.tsxindex 1a202a846af..492304214c6 100644--- a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.claudeCode.test.tsx+++ b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.claudeCode.test.tsx@@ -46,6 +46,10 @@ vi.mock('@/features/AgentQuotaCalendar', () => ({}));vi.mock('@/features/ChatInput/hooks/useAgentId', () => ({ useAgentId: () => 'agent-1' }));+const selectedModel = vi.hoisted(() => ({ current: 'fable' as string | undefined }));+vi.mock('../../HeteroModel/useEffectiveHeteroProvider', () => ({+ useSelectedHeteroModel: () => selectedModel.current,+}));const { confirmModalMock, toastErrorMock, toastSuccessMock } = vi.hoisted(() => ({confirmModalMock: vi.fn(),@@ -294,6 +298,54 @@ describe('ClaudeCodeQuotaMenu', () => {).toEqual(['normal', 'low']);});+ it('leaves a model-scoped window out of the compact values when another model is selected', async () => {+ selectedModel.current = 'opus';+ mockService.getClaudeCodeQuota.mockResolvedValue(+ claudeSnapshot({+ scopedWeekly: {+ modelName: 'Fable',+ window: { resetsAt: null, usedPercent: 0, windowMinutes: 10_080 },+ },+ session: { resetsAt: null, usedPercent: 53, windowMinutes: 300 },+ weekly: { resetsAt: null, usedPercent: 6, windowMinutes: 10_080 },+ }),+ );++ try {+ render(<ClaudeCodeQuotaMenu />);++ expect(await screen.findByText('heteroAgent.claudeQuota.scopedWeekly:Fable')).toBeTruthy();+ const trigger = screen.getByRole('button', { name: 'heteroAgent.claudeQuota.tooltip' });+ expect(trigger.textContent).toContain('heteroAgent.quota.compactLeft:47');+ expect(trigger.textContent).not.toContain('Fable heteroAgent.quota.compactLeft');+ } finally {+ selectedModel.current = 'fable';+ }+ });++ it('keeps a model-scoped window out of the compact values even when it is the only window', async () => {+ selectedModel.current = 'opus';+ mockService.getClaudeCodeQuota.mockResolvedValue(+ claudeSnapshot({+ scopedWeekly: {+ modelName: 'Fable',+ window: { resetsAt: null, usedPercent: 0, windowMinutes: 10_080 },+ },+ }),+ );++ try {+ render(<ClaudeCodeQuotaMenu />);++ expect(await screen.findByText('heteroAgent.claudeQuota.scopedWeekly:Fable')).toBeTruthy();+ const trigger = screen.getByRole('button', { name: 'heteroAgent.claudeQuota.tooltip' });+ expect(trigger.textContent).not.toContain('Fable');+ expect(trigger.textContent).not.toContain('heteroAgent.quota.compactLeft');+ } finally {+ selectedModel.current = 'fable';+ }+ });+it('warns below 15 percent and keeps compact zero quota numeric', async () => {mockService.getClaudeCodeQuota.mockResolvedValue(claudeSnapshot({diff --git a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.test.tsx b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.test.tsxindex a9d00201599..9fc6c894b8c 100644--- a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.test.tsx+++ b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.test.tsx@@ -41,6 +41,9 @@ vi.mock('@/features/AgentQuotaCalendar', () => ({}));vi.mock('@/features/ChatInput/hooks/useAgentId', () => ({ useAgentId: () => 'agent-1' }));+vi.mock('../../HeteroModel/useEffectiveHeteroProvider', () => ({+ useSelectedHeteroModel: () => undefined,+}));const { confirmModalMock, toastErrorMock, toastSuccessMock } = vi.hoisted(() => ({confirmModalMock: vi.fn(),diff --git a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.tsx b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.tsxindex 8757f075590..1c51e1b1c56 100644--- a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.tsx+++ b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/QuotaMenu.tsx@@ -135,6 +135,8 @@ export interface QuotaWindowItem {compactGroup?: string;/** Optional scope label shown before this window's compact percentage. */compactLabel?: string;+ /** Listed in the panel only, not in the compact trigger. */+ hideInCompact?: boolean;key: string;label: string;window: HeteroQuotaWindow | null;@@ -512,7 +514,8 @@ const QuotaMenu = <S extends QuotaSnapshotBase>({const windows = quota ? getWindows(quota) : [];const compactItemsByGroup = new Map<string, CompactQuotaItem>();for (const item of windows) {- if (!item.window) continue;+ // With nothing left to show, the trigger falls back to its icon; the panel lists every window.+ if (!item.window || item.hideInCompact) continue;const leftPercent = clampPercent(100 - item.window.usedPercent);const compactGroup = item.compactGroup ?? 'default';diff --git a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/quotaViewModel.test.ts b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/quotaViewModel.test.tsindex 64206a0e789..ecc01f54bc8 100644--- a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/quotaViewModel.test.ts+++ b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/quotaViewModel.test.ts@@ -2,7 +2,12 @@ import type { ClaudeCodeQuotaSnapshot } from '@lobechat/electron-client-ipc';import { describe, expect, it } from 'vitest';import type { QuotaReadingRow } from './quotaViewModel';-import { buildClaudePanelSnapshot, isQuotaStale, newestCapturedAt } from './quotaViewModel';+import {+ buildClaudePanelSnapshot,+ isQuotaStale,+ isScopedQuotaModel,+ newestCapturedAt,+} from './quotaViewModel';const reset = Date.parse('2026-07-21T14:00:00Z');const sessionReset = Date.parse('2026-07-18T20:50:00Z');@@ -271,3 +276,24 @@ describe('isQuotaStale', () => {expect(isQuotaStale(new Date(snap.updatedAt), now, 5 * 60_000)).toBe(true);});});++describe('isScopedQuotaModel', () => {+ it('matches the selected model by alias or full id', () => {+ expect(isScopedQuotaModel('fable', 'Fable')).toBe(true);+ expect(isScopedQuotaModel('claude-fable-5-2', 'Fable')).toBe(true);+ });++ it('matches a multi-word display name by its model family', () => {+ expect(isScopedQuotaModel('fable', 'Claude Fable 5')).toBe(true);+ expect(isScopedQuotaModel('opus', 'Claude Fable 5')).toBe(false);+ });++ it('does not treat the CLI default as selecting the scoped model', () => {+ expect(isScopedQuotaModel('default', 'Fable')).toBe(false);+ });++ it('does not match another model or no selection', () => {+ expect(isScopedQuotaModel('opus', 'Fable')).toBe(false);+ expect(isScopedQuotaModel(undefined, 'Fable')).toBe(false);+ });+});diff --git a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/quotaViewModel.ts b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/quotaViewModel.tsindex 9f6c74be9e2..ef7ccbaef6a 100644--- a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/quotaViewModel.ts+++ b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/quotaViewModel.ts@@ -136,3 +136,19 @@ export const isQuotaStale = (const receivedAtMs = toMs(receivedAt);return receivedAtMs === null || now - receivedAtMs > maxAgeMs;};++/**+ * Whether the selected model is the one a model-scoped limit applies to. The CLI names+ * models by alias or id (`fable`, `claude-fable-5-2`) while the limit names the model by+ * display name (`Fable`, possibly `Claude Fable 5`), so both are compared by family.+ *+ * The CLI default (`default`) is not a selection of that model, so it does not match even+ * when the account's default happens to be it; the panel still lists the limit.+ */+export const isScopedQuotaModel = (selectedModel: string | undefined, scopeModelName: string) => {+ const family = scopeModelName+ .toLowerCase()+ .split(/[\s-]+/)+ .find((word) => word && word !== 'claude');+ return !!selectedModel && !!family && selectedModel.toLowerCase().includes(family);+};diff --git a/src/features/ChatInput/ControlBar/HeteroModel/index.tsx b/src/features/ChatInput/ControlBar/HeteroModel/index.tsxindex 5b6628a5683..befa5fbaca6 100644--- a/src/features/ChatInput/ControlBar/HeteroModel/index.tsx+++ b/src/features/ChatInput/ControlBar/HeteroModel/index.tsx@@ -1,47 +1,26 @@'use client';import type { ListHeterogeneousAgentModelsParams } from '@lobechat/types';-import { applyTopicModelToHeterogeneousProvider } from '@lobechat/types';-import isEqual from 'fast-deep-equal';import { memo } from 'react';import { usePermission } from '@/hooks/usePermission';-import { useAgentStore } from '@/store/agent';-import { agentByIdSelectors } from '@/store/agent/selectors';-import { useChatStore } from '@/store/chat';-import { topicSelectors } from '@/store/chat/slices/topic/selectors';-import { useAgentId } from '../../hooks/useAgentId';import { useChatInputResourceAccess } from '../../hooks/useChatInputResourceAccess';-import { useTopicId } from '../../hooks/useTopicId';import { ModelCatalogSelector } from './ModelCatalogSelector';import SelectorMenu from './SelectorMenu';import { resolveSelectorShape } from './selectorView';+import { useEffectiveHeteroProvider } from './useEffectiveHeteroProvider';import { useHeteroProviderPatch } from './useHeteroProviderPatch';const HeteroModel = memo(() => {- const agentId = useAgentId();- const provider = useAgentStore(- (s) => agentByIdSelectors.getAgencyConfigById(agentId)(s)?.heterogeneousProvider,- isEqual,- );+ const { agentId, effectiveProvider, provider, topicId, topicPin } = useEffectiveHeteroProvider();const { allowed: canCreateContent, reason } = usePermission('create_content');// Model, effort and speed picks are topic-scoped once a topic exists; mode// still writes the shared heterogeneous-provider config.const { canConfigureResource } = useChatInputResourceAccess();const enabled = canCreateContent && canConfigureResource;const patch = useHeteroProviderPatch({ agentId, enabled, provider });- // Model, effort and speed pins follow this composer's topic once one exists- // (see `useTopicId`), never the global active topic.- const topicId = useTopicId();const topicScoped = !!topicId;- const topicPin = useChatStore(- (s) => (topicId ? topicSelectors.getTopicHeteroPinById(topicId)(s) : undefined),- isEqual,- );- const effectiveProvider = provider- ? applyTopicModelToHeterogeneousProvider(provider, topicPin)- : undefined;const shape = resolveSelectorShape(effectiveProvider, enabled);diff --git a/src/features/ChatInput/ControlBar/HeteroModel/useEffectiveHeteroProvider.ts b/src/features/ChatInput/ControlBar/HeteroModel/useEffectiveHeteroProvider.tsnew file mode 100644index 00000000000..e083ee6826d--- /dev/null+++ b/src/features/ChatInput/ControlBar/HeteroModel/useEffectiveHeteroProvider.ts@@ -0,0 +1,42 @@+import {+ applyTopicModelToHeterogeneousProvider,+ getHeteroSelectorCapability,+} from '@lobechat/types';+import isEqual from 'fast-deep-equal';++import { useAgentStore } from '@/store/agent';+import { agentByIdSelectors } from '@/store/agent/selectors';+import { useChatStore } from '@/store/chat';+import { topicSelectors } from '@/store/chat/slices/topic/selectors';++import { useAgentId } from '../../hooks/useAgentId';+import { useTopicId } from '../../hooks/useTopicId';++/**+ * The composer's heterogeneous provider with this topic's model, effort and speed pins+ * applied. Pins follow this composer's topic (see `useTopicId`), never the global active+ * topic; without a topic the agent's own config applies.+ */+export const useEffectiveHeteroProvider = () => {+ const agentId = useAgentId();+ const provider = useAgentStore(+ (s) => agentByIdSelectors.getAgencyConfigById(agentId)(s)?.heterogeneousProvider,+ isEqual,+ );+ const topicId = useTopicId();+ const topicPin = useChatStore(+ (s) => (topicId ? topicSelectors.getTopicHeteroPinById(topicId)(s) : undefined),+ isEqual,+ );+ const effectiveProvider = provider+ ? applyTopicModelToHeterogeneousProvider(provider, topicPin)+ : undefined;++ return { agentId, effectiveProvider, provider, topicId, topicPin };+};++/** The model this composer's next run uses, as the CLI names it (e.g. `opus`, `fable`). */+export const useSelectedHeteroModel = (): string | undefined => {+ const { effectiveProvider } = useEffectiveHeteroProvider();+ return getHeteroSelectorCapability(effectiveProvider?.type)?.model?.resolve(effectiveProvider);+};