🤯 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
🐛 fix(chat): show unavailable model notice (#16383)
YuTengjing765f1237ea26
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.jsonindex c3494ce072c..05cc649d4ce 100644--- a/locales/en-US/chat.json+++ b/locales/en-US/chat.json@@ -317,6 +317,7 @@"input.inputCompletionError.retry": "Retry","input.inputCompletionError.settings": "Settings","input.inputCompletionError.title": "Input suggestions paused",+ "input.modelUnavailable": "The current model is no longer available. Choose another model to continue.","input.more": "More","input.send": "Send","input.sendWithCmdEnter": "Press <key/> to send",diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.jsonindex 0b04656c11e..b198891eaf9 100644--- a/locales/zh-CN/chat.json+++ b/locales/zh-CN/chat.json@@ -317,6 +317,7 @@"input.inputCompletionError.retry": "重试","input.inputCompletionError.settings": "设置","input.inputCompletionError.title": "输入补全已暂停",+ "input.modelUnavailable": "当前模型已下线。请选择其他模型后继续使用。","input.more": "更多","input.send": "发送","input.sendWithCmdEnter": "按 <key/> 发送",diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.tsindex 62ecc22e101..1e549685544 100644--- a/packages/locales/src/default/chat.ts+++ b/packages/locales/src/default/chat.ts@@ -255,6 +255,8 @@ export default {'input.inputCompletionError.retry': 'Retry','input.inputCompletionError.settings': 'Settings','input.inputCompletionError.title': 'Input suggestions paused',+ 'input.modelUnavailable':+ 'The current model is no longer available. Choose another model to continue.','input.more': 'More','input.send': 'Send','input.sendWithCmdEnter': 'Press <key/> to send',diff --git a/src/features/ChatInput/CurrentModelNotice/index.tsx b/src/features/ChatInput/CurrentModelNotice/index.tsxnew file mode 100644index 00000000000..b8d3330ec7b--- /dev/null+++ b/src/features/ChatInput/CurrentModelNotice/index.tsx@@ -0,0 +1,42 @@+'use client';++import { Alert } from '@lobehub/ui';+import { createStaticStyles, cx } from 'antd-style';+import { memo } from 'react';+import { useTranslation } from 'react-i18next';++import { useCurrentModelNotice } from './useCurrentModelNotice';++const styles = createStaticStyles(({ css }) => ({+ alert: css`+ .ant-alert-message {+ font-size: 12px;+ line-height: 18px !important;+ }++ .ant-alert-icon {+ height: 18px !important;+ }+ `,+}));++const CurrentModelNotice = memo(() => {+ const { t } = useTranslation('chat');+ const noticeKey = useCurrentModelNotice();++ if (!noticeKey) return null;++ return (+ <Alert+ classNames={{ alert: cx(styles.alert) }}+ style={{ fontSize: 12 }}+ title={t(noticeKey)}+ type={'warning'}+ variant={'borderless'}+ />+ );+});++CurrentModelNotice.displayName = 'CurrentModelNotice';++export default CurrentModelNotice;diff --git a/src/features/ChatInput/CurrentModelNotice/useCurrentModelNotice.test.tsx b/src/features/ChatInput/CurrentModelNotice/useCurrentModelNotice.test.tsxnew file mode 100644index 00000000000..9585c09e4f3--- /dev/null+++ b/src/features/ChatInput/CurrentModelNotice/useCurrentModelNotice.test.tsx@@ -0,0 +1,142 @@+import { renderHook } from '@testing-library/react';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { useCurrentModelNotice } from './useCurrentModelNotice';++interface TestModel {+ abilities?: {+ functionCall?: boolean;+ };+ id: string;+}++interface TestProviderWithModels {+ children: TestModel[];+ id: string;+}++const testState = vi.hoisted(() => ({+ agent: {+ agencyConfig: undefined as { heterogeneousProvider?: { type: string } } | undefined,+ enableAgentMode: true,+ model: 'gpt-4o',+ provider: 'openai',+ },+ aiInfra: {+ enabledChatModelList: [] as TestProviderWithModels[],+ isInitAiProviderRuntimeState: false,+ },+}));++type StoreSelector<T = unknown, S = Record<PropertyKey, unknown>> = (state: S) => T;++vi.mock('@/features/ChatInput/hooks/useAgentId', () => ({+ useAgentId: () => 'agent-id',+}));++vi.mock('@/hooks/useEnabledChatModels', () => ({+ useEnabledChatModels: () => testState.aiInfra.enabledChatModelList,+}));++vi.mock('@/store/agent', () => ({+ useAgentStore: <T,>(selector: StoreSelector<T, typeof testState.agent>) =>+ selector(testState.agent),+}));++vi.mock('@/store/agent/selectors', () => ({+ agentByIdSelectors: {+ getAgentEnableModeById: () => (s: typeof testState.agent) => s.enableAgentMode,+ getAgentModelById: () => (s: typeof testState.agent) => s.model,+ getAgentModelProviderById: () => (s: typeof testState.agent) => s.provider,+ isAgentHeterogeneousById: () => (s: typeof testState.agent) =>+ Boolean(s.agencyConfig?.heterogeneousProvider),+ },+}));++vi.mock('@/store/aiInfra', () => ({+ aiProviderSelectors: {+ isInitAiProviderRuntimeState: (s: typeof testState.aiInfra) => s.isInitAiProviderRuntimeState,+ },+ useAiInfraStore: <T,>(selector: StoreSelector<T, typeof testState.aiInfra>) =>+ selector(testState.aiInfra),+}));++describe('useCurrentModelNotice', () => {+ beforeEach(() => {+ testState.agent.agencyConfig = undefined;+ testState.agent.enableAgentMode = true;+ testState.agent.model = 'gpt-4o';+ testState.agent.provider = 'openai';+ testState.aiInfra.enabledChatModelList = [];+ testState.aiInfra.isInitAiProviderRuntimeState = false;+ });++ it('does not return a notice before the model runtime config is ready', () => {+ const { result } = renderHook(() => useCurrentModelNotice());++ expect(result.current).toBeUndefined();+ });++ it('returns unavailable model copy when the ready model config no longer contains the selected model', () => {+ testState.agent.enableAgentMode = false;+ testState.aiInfra.isInitAiProviderRuntimeState = true;++ const { result } = renderHook(() => useCurrentModelNotice());++ expect(result.current).toBe('input.modelUnavailable');+ });++ it('returns unsupported tool-use copy only when agent mode is enabled and the selected model exists but lacks tool calls', () => {+ testState.aiInfra.isInitAiProviderRuntimeState = true;+ testState.aiInfra.enabledChatModelList = [+ { children: [{ abilities: { functionCall: false }, id: 'gpt-4o' }], id: 'openai' },+ ];++ const { result } = renderHook(() => useCurrentModelNotice());++ expect(result.current).toBe('input.agentModeUnsupportedModel');+ });++ it('returns unavailable model copy when the selected model is enabled globally but absent from the chat selector list', () => {+ testState.aiInfra.isInitAiProviderRuntimeState = true;+ testState.aiInfra.enabledChatModelList = [+ { children: [{ abilities: { functionCall: true }, id: 'gpt-image-1' }], id: 'openai' },+ ];++ const { result } = renderHook(() => useCurrentModelNotice());++ expect(result.current).toBe('input.modelUnavailable');+ });++ it('does not return unsupported tool-use copy when agent mode is disabled', () => {+ testState.agent.enableAgentMode = false;+ testState.aiInfra.isInitAiProviderRuntimeState = true;+ testState.aiInfra.enabledChatModelList = [+ { children: [{ abilities: { functionCall: false }, id: 'gpt-4o' }], id: 'openai' },+ ];++ const { result } = renderHook(() => useCurrentModelNotice());++ expect(result.current).toBeUndefined();+ });++ it('does not return a notice when the ready model supports tool use', () => {+ testState.aiInfra.isInitAiProviderRuntimeState = true;+ testState.aiInfra.enabledChatModelList = [+ { children: [{ abilities: { functionCall: true }, id: 'gpt-4o' }], id: 'openai' },+ ];++ const { result } = renderHook(() => useCurrentModelNotice());++ expect(result.current).toBeUndefined();+ });++ it('does not return a notice for heterogeneous agents', () => {+ testState.agent.agencyConfig = { heterogeneousProvider: { type: 'codex' } };+ testState.aiInfra.isInitAiProviderRuntimeState = true;++ const { result } = renderHook(() => useCurrentModelNotice());++ expect(result.current).toBeUndefined();+ });+});diff --git a/src/features/ChatInput/CurrentModelNotice/useCurrentModelNotice.ts b/src/features/ChatInput/CurrentModelNotice/useCurrentModelNotice.tsnew file mode 100644index 00000000000..103c5a93eae--- /dev/null+++ b/src/features/ChatInput/CurrentModelNotice/useCurrentModelNotice.ts@@ -0,0 +1,69 @@+import { useAgentId } from '@/features/ChatInput/hooks/useAgentId';+import { useEnabledChatModels } from '@/hooks/useEnabledChatModels';+import { useAgentStore } from '@/store/agent';+import { agentByIdSelectors } from '@/store/agent/selectors';+import { aiProviderSelectors, useAiInfraStore } from '@/store/aiInfra';+import { type EnabledProviderWithModels } from '@/types/aiProvider';++interface CurrentModelNoticeModel {+ abilities?: {+ functionCall?: boolean;+ };+}++interface ResolveCurrentModelNoticeKeyParams {+ currentChatModel?: CurrentModelNoticeModel;+ enableAgentMode: boolean;+ isHeterogeneousAgent: boolean;+ isModelConfigReady: boolean;+}++const findEnabledChatModel = (+ enabledChatModelList: EnabledProviderWithModels[],+ model: string,+ provider: string,+) => {+ return enabledChatModelList+ .find((item) => item.id === provider)+ ?.children.find((item) => item.id === model);+};++export const resolveCurrentModelNoticeKey = ({+ currentChatModel,+ enableAgentMode,+ isHeterogeneousAgent,+ isModelConfigReady,+}: ResolveCurrentModelNoticeKeyParams) => {+ if (isHeterogeneousAgent || !isModelConfigReady) return;++ // Example: an agent still references `gpt-4-32k`, or a model reclassified to+ // image/video; once absent from the chat selector, it should read as unavailable.+ if (!currentChatModel) return 'input.modelUnavailable';++ if (enableAgentMode && !currentChatModel.abilities?.functionCall)+ return 'input.agentModeUnsupportedModel';+};++export const useCurrentModelNotice = () => {+ const agentId = useAgentId();++ const [enableAgentMode, isHeterogeneousAgent, model, provider] = useAgentStore((s) => [+ agentByIdSelectors.getAgentEnableModeById(agentId)(s),+ agentByIdSelectors.isAgentHeterogeneousById(agentId)(s),+ agentByIdSelectors.getAgentModelById(agentId)(s),+ agentByIdSelectors.getAgentModelProviderById(agentId)(s),+ ]);++ const enabledChatModelList = useEnabledChatModels();+ const isModelConfigReady = useAiInfraStore((s) =>+ aiProviderSelectors.isInitAiProviderRuntimeState(s),+ );+ const currentChatModel = findEnabledChatModel(enabledChatModelList, model, provider);++ return resolveCurrentModelNoticeKey({+ currentChatModel,+ enableAgentMode,+ isHeterogeneousAgent,+ isModelConfigReady,+ });+};diff --git a/src/features/ChatInput/Desktop/AgentModeNotice.test.tsx b/src/features/ChatInput/Desktop/AgentModeNotice.test.tsxdeleted file mode 100644index 26ebd461b54..00000000000--- a/src/features/ChatInput/Desktop/AgentModeNotice.test.tsx+++ /dev/null@@ -1,136 +0,0 @@-import { render, screen } from '@testing-library/react';-import type { ReactNode } from 'react';-import { beforeEach, describe, expect, it, vi } from 'vitest';--import AgentModeNotice from './AgentModeNotice';--interface TestModel {- abilities?: {- functionCall?: boolean;- };- id: string;- providerId: string;-}--const testState = vi.hoisted(() => ({- agent: {- agencyConfig: undefined as { heterogeneousProvider?: { type: string } } | undefined,- enableAgentMode: true,- model: 'gpt-4o',- provider: 'openai',- },- aiInfra: {- enabledAiModels: [] as TestModel[],- isInitAiProviderRuntimeState: false,- },-}));--type StoreSelector<T = unknown, S = Record<PropertyKey, unknown>> = (state: S) => T;--vi.mock('@lobehub/ui', () => ({- Alert: ({ title }: { title: ReactNode }) => <div role="alert">{title}</div>,-}));--vi.mock('antd-style', () => ({- createStaticStyles: () => ({ alert: 'alert' }),- cx: (...classes: string[]) => classes.filter(Boolean).join(' '),-}));--vi.mock('react-i18next', () => ({- useTranslation: () => ({ t: (key: string) => key }),-}));--vi.mock('@/features/ChatInput/hooks/useAgentId', () => ({- useAgentId: () => 'agent-id',-}));--vi.mock('@/store/agent', () => ({- useAgentStore: <T,>(selector: StoreSelector<T, typeof testState.agent>) =>- selector(testState.agent),-}));--vi.mock('@/store/agent/selectors', () => ({- agentByIdSelectors: {- getAgentEnableModeById: () => (s: typeof testState.agent) => s.enableAgentMode,- isAgentHeterogeneousById: () => (s: typeof testState.agent) =>- Boolean(s.agencyConfig?.heterogeneousProvider),- getAgentModelById: () => (s: typeof testState.agent) => s.model,- getAgentModelProviderById: () => (s: typeof testState.agent) => s.provider,- },-}));--vi.mock('@/store/aiInfra', () => ({- aiModelSelectors: {- isModelSupportToolUse: (model: string, provider: string) => (s: typeof testState.aiInfra) =>- s.enabledAiModels.find((item) => item.id === model && item.providerId === provider)?.abilities- ?.functionCall || false,- },- aiProviderSelectors: {- isInitAiProviderRuntimeState: (s: typeof testState.aiInfra) => s.isInitAiProviderRuntimeState,- },- useAiInfraStore: <T,>(selector: StoreSelector<T, typeof testState.aiInfra>) =>- selector(testState.aiInfra),-}));--describe('AgentModeNotice', () => {- beforeEach(() => {- testState.agent.agencyConfig = undefined;- testState.agent.enableAgentMode = true;- testState.agent.model = 'gpt-4o';- testState.agent.provider = 'openai';- testState.aiInfra.enabledAiModels = [];- testState.aiInfra.isInitAiProviderRuntimeState = false;- });-- it('does not render before the model runtime config is ready', () => {- render(<AgentModeNotice />);-- expect(screen.queryByRole('alert')).not.toBeInTheDocument();- });-- it('renders after the model runtime config is ready when the model lacks tool use', () => {- testState.aiInfra.isInitAiProviderRuntimeState = true;- testState.aiInfra.enabledAiModels = [- { abilities: { functionCall: false }, id: 'gpt-4o', providerId: 'openai' },- ];-- render(<AgentModeNotice />);-- expect(screen.getByRole('alert')).toHaveTextContent('input.agentModeUnsupportedModel');- });-- it('does not render when the ready model supports tool use', () => {- testState.aiInfra.isInitAiProviderRuntimeState = true;- testState.aiInfra.enabledAiModels = [- { abilities: { functionCall: true }, id: 'gpt-4o', providerId: 'openai' },- ];-- render(<AgentModeNotice />);-- expect(screen.queryByRole('alert')).not.toBeInTheDocument();- });-- it('does not render when agent mode is disabled', () => {- testState.agent.enableAgentMode = false;- testState.aiInfra.isInitAiProviderRuntimeState = true;- testState.aiInfra.enabledAiModels = [- { abilities: { functionCall: false }, id: 'gpt-4o', providerId: 'openai' },- ];-- render(<AgentModeNotice />);-- expect(screen.queryByRole('alert')).not.toBeInTheDocument();- });-- it('does not render for heterogeneous agents', () => {- testState.agent.agencyConfig = { heterogeneousProvider: { type: 'codex' } };- testState.aiInfra.isInitAiProviderRuntimeState = true;- testState.aiInfra.enabledAiModels = [- { abilities: { functionCall: false }, id: 'gpt-4o', providerId: 'openai' },- ];-- render(<AgentModeNotice />);-- expect(screen.queryByRole('alert')).not.toBeInTheDocument();- });-});diff --git a/src/features/ChatInput/Desktop/AgentModeNotice.tsx b/src/features/ChatInput/Desktop/AgentModeNotice.tsxdeleted file mode 100644index 1ed70daf545..00000000000--- a/src/features/ChatInput/Desktop/AgentModeNotice.tsx+++ /dev/null@@ -1,63 +0,0 @@-'use client';--import { Alert } from '@lobehub/ui';-import { createStaticStyles, cx } from 'antd-style';-import { memo } from 'react';-import { useTranslation } from 'react-i18next';--import { useAgentId } from '@/features/ChatInput/hooks/useAgentId';-import { useAgentStore } from '@/store/agent';-import { agentByIdSelectors } from '@/store/agent/selectors';-import { aiModelSelectors, aiProviderSelectors, useAiInfraStore } from '@/store/aiInfra';--const styles = createStaticStyles(({ css }) => ({- alert: css`- .ant-alert-message {- font-size: 12px;- line-height: 18px !important;- }-- .ant-alert-icon {- height: 18px !important;- }- `,-}));--/**- * Warns the user when Agent mode is enabled but the currently selected model- * does not support function/tool calling — agentic runs need tool calling to- * work, so we suggest switching to a model with agent capability.- */-const AgentModeNotice = memo(() => {- const { t } = useTranslation('chat');- const agentId = useAgentId();-- const [enableAgentMode, isHeterogeneousAgent, model, provider] = useAgentStore((s) => [- agentByIdSelectors.getAgentEnableModeById(agentId)(s),- agentByIdSelectors.isAgentHeterogeneousById(agentId)(s),- agentByIdSelectors.getAgentModelById(agentId)(s),- agentByIdSelectors.getAgentModelProviderById(agentId)(s),- ]);-- const [isModelConfigReady, supportToolUse] = useAiInfraStore((s) => [- aiProviderSelectors.isInitAiProviderRuntimeState(s),- aiModelSelectors.isModelSupportToolUse(model, provider)(s),- ]);-- if (isHeterogeneousAgent || !enableAgentMode || !isModelConfigReady || supportToolUse)- return null;-- return (- <Alert- classNames={{ alert: cx(styles.alert) }}- style={{ fontSize: 12 }}- title={t('input.agentModeUnsupportedModel')}- type={'warning'}- variant={'borderless'}- />- );-});--AgentModeNotice.displayName = 'AgentModeNotice';--export default AgentModeNotice;diff --git a/src/features/ChatInput/Desktop/index.tsx b/src/features/ChatInput/Desktop/index.tsxindex 8fff8003205..3a152be3640 100644--- a/src/features/ChatInput/Desktop/index.tsx+++ b/src/features/ChatInput/Desktop/index.tsx@@ -9,6 +9,7 @@ import { memo, useEffect } from 'react';import { createPortal } from 'react-dom';import { useTranslation } from 'react-i18next';+import CurrentModelNotice from '@/features/ChatInput/CurrentModelNotice';import { useChatInputStore } from '@/features/ChatInput/store';import { LayoutContainerContext } from '@/routes/(main)/_layout/DesktopLayoutContainer/LayoutContainerContext';import { useChatStore } from '@/store/chat';@@ -25,7 +26,6 @@ import { useSkillDrop } from '../InputEditor/ActionTag/useSkillDrop';import { type PlaceholderVariant } from '../InputEditor/Placeholder';import SendArea from '../SendArea';import TypoBar from '../TypoBar';-import AgentModeNotice from './AgentModeNotice';import ContextContainer from './ContextContainer';const styles = createStaticStyles(({ css, cssVar }) => ({@@ -166,7 +166,7 @@ const DesktopChatInput = memo<DesktopChatInputProps>(onDragOver={skillDrop.onDragOver}onDrop={skillDrop.onDrop}>- {!isConfigLoading && <AgentModeNotice />}+ {!isConfigLoading && <CurrentModelNotice />}<ChatInputdata-testid="chat-input"defaultHeight={chatInputHeight || 32}diff --git a/src/features/ChatInput/Mobile/index.tsx b/src/features/ChatInput/Mobile/index.tsxindex 94976cde967..f152901e6dc 100644--- a/src/features/ChatInput/Mobile/index.tsx+++ b/src/features/ChatInput/Mobile/index.tsx@@ -5,6 +5,7 @@ import { Flexbox } from '@lobehub/ui';import { createStaticStyles, cssVar, cx } from 'antd-style';import { memo } from 'react';+import CurrentModelNotice from '@/features/ChatInput/CurrentModelNotice';import { useChatInputStore } from '@/features/ChatInput/store';import dynamic from '@/libs/next/dynamic';@@ -40,9 +41,11 @@ const DesktopChatInput = memo(() => {{!expand && fileNode}<FlexboxclassName={cx(styles.container, expand && styles.fullscreen)}+ gap={8}paddingBlock={'0 12px'}paddingInline={12}>+ <CurrentModelNotice /><ChatInputfullscreen={expand}header={<ChatInputActionBar left={<ActionBar />} />}