🤯 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
⚡️ perf(model-bank): keep the aiModels catalog off the boot path (#19291)
Inneif6ba7c15c664
diff --git a/eslint.config.mjs b/eslint.config.mjsindex a39a6a74372..1bb82bf0a86 100644--- a/eslint.config.mjs+++ b/eslint.config.mjs@@ -8,12 +8,21 @@ const tsconfigRootDir = fileURLToPath(new URL('.', import.meta.url));const baseRestrictedImportOptions = restrictedImports.rules['no-restricted-imports'][1];+// Shared by every src/** no-restricted-imports block: flat config replaces a+// rule per file instead of merging it, so a scoped override would otherwise+// drop these.const performanceRestrictedImportPaths = [{message:'Import the imperative facade from "@/features/ShareModal" so the modal implementation stays outside initial chunks.',name: '@/features/ShareModal/Modal',},+ {+ allowTypeImports: true,+ message:+ 'Do not import the model-bank root barrel; it re-exports the full aiModels catalog (1.4 MB raw). Use a subpath such as "model-bank/aiModel", "model-bank/modelProvider", "model-bank/standardParameters" or "model-bank/utils".',+ name: 'model-bank',+ },];// On desktop the shell — every NavPanelPortal sidebar, the titlebar, the command@@ -155,6 +164,13 @@ export default eslint('no-restricted-imports': createRestrictedImportRule(),},},+ {+ // Bundle-size restrictions target shipped code; tests may reach the barrels.+ files: ['src/**/*.test.{ts,tsx}'],+ rules: {+ 'no-restricted-imports': ['error', baseRestrictedImportOptions],+ },+ },{// Boot-path trees are statically reachable from the SPA entry. A heavy// @lobehub/ui member imported here lands in the first-screen chunk togetherdiff --git a/packages/model-bank/package.json b/packages/model-bank/package.jsonindex 4d067ee799b..4d024d867d8 100644--- a/packages/model-bank/package.json+++ b/packages/model-bank/package.json@@ -2,8 +2,11 @@"name": "model-bank","version": "1.0.0","private": true,+ "sideEffects": false,"exports": {".": "./src/index.ts",+ "./knowledgeCutoff": "./src/const/knowledgeCutoff.ts",+ "./utils": "./src/utils.ts","./aiModel": "./src/types/aiModel.ts","./aiProvider": "./src/types/aiProvider.ts","./modelProvider": "./src/const/modelProvider.ts",diff --git a/packages/model-runtime/package.json b/packages/model-runtime/package.jsonindex d9a8a8de842..587f05514b2 100644--- a/packages/model-runtime/package.json+++ b/packages/model-runtime/package.json@@ -5,6 +5,7 @@"exports": {".": "./src/index.ts","./errors": "./src/errors/index.ts",+ "./errors/specs": "./src/errors/specs.ts","./getModelPropertyWithFallback": "./src/utils/getFallbackModelProperty.ts","./helpers/parseToolCalls": "./src/helpers/parseToolCalls.ts","./providers/anthropic/modelId": "./src/providers/anthropic/modelId.ts",diff --git a/packages/model-runtime/src/utils/modelExtendParams.ts b/packages/model-runtime/src/utils/modelExtendParams.tsindex ccc522a6116..a5ebd1aed0e 100644--- a/packages/model-runtime/src/utils/modelExtendParams.ts+++ b/packages/model-runtime/src/utils/modelExtendParams.ts@@ -1,6 +1,6 @@import type { LobeAgentChatConfig } from '@lobechat/types';-import type { AiModelReasoningConfig, ExtendParamsType } from 'model-bank';-import { MODEL_REASONING_EXTEND_PARAMS } from 'model-bank';+import type { AiModelReasoningConfig, ExtendParamsType } from 'model-bank/aiModel';+import { MODEL_REASONING_EXTEND_PARAMS } from 'model-bank/aiModel';import { isAdaptiveThinkingDefaultOnModel } from '../providers/anthropic/modelId';diff --git a/src/features/ChatInput/ActionBar/Params/Controls.tsx b/src/features/ChatInput/ActionBar/Params/Controls.tsxindex d22ec8ec3ff..6847cffff83 100644--- a/src/features/ChatInput/ActionBar/Params/Controls.tsx+++ b/src/features/ChatInput/ActionBar/Params/Controls.tsx@@ -11,7 +11,7 @@ import { createStaticStyles, cssVar, cx } from 'antd-style';import { debounce } from 'es-toolkit/compat';import isEqual from 'fast-deep-equal';import { ChevronDown, ChevronUp } from 'lucide-react';-import { MODEL_REASONING_EXTEND_PARAMS } from 'model-bank';+import { MODEL_REASONING_EXTEND_PARAMS } from 'model-bank/aiModel';import type { ReactNode } from 'react';import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';diff --git a/src/features/ChatInput/hooks/useReasoningEffortControl.ts b/src/features/ChatInput/hooks/useReasoningEffortControl.tsindex a92d2e9972b..f5360c5df96 100644--- a/src/features/ChatInput/hooks/useReasoningEffortControl.ts+++ b/src/features/ChatInput/hooks/useReasoningEffortControl.ts@@ -3,7 +3,7 @@import { resolveDefaultThinkingLevelForModel } from '@lobechat/model-runtime/utils/modelExtendParams';import isEqual from 'fast-deep-equal';import type { AiModelReasoningConfig } from 'model-bank';-import { MODEL_REASONING_PARAM_DEFAULTS, MODEL_REASONING_PARAM_LEVELS } from 'model-bank';+import { MODEL_REASONING_PARAM_DEFAULTS, MODEL_REASONING_PARAM_LEVELS } from 'model-bank/aiModel';import { useCallback } from 'react';import { aiModelSelectors, useAiInfraStore } from '@/store/aiInfra';diff --git a/src/features/Conversation/Error/ChatInvalidApiKey.tsx b/src/features/Conversation/Error/ChatInvalidApiKey.tsxindex df51d9312dc..b4b418ad0bd 100644--- a/src/features/Conversation/Error/ChatInvalidApiKey.tsx+++ b/src/features/Conversation/Error/ChatInvalidApiKey.tsx@@ -1,5 +1,5 @@import { Button } from '@lobehub/ui/base-ui';-import { ModelProvider } from 'model-bank';+import { ModelProvider } from 'model-bank/modelProvider';import { memo } from 'react';import { useTranslation } from 'react-i18next';import urlJoin from 'url-join';diff --git a/src/features/ModelSwitchPanel/components/ControlsForm/ControlsForm.tsx b/src/features/ModelSwitchPanel/components/ControlsForm/ControlsForm.tsxindex 909552e1d22..ed932c8eebc 100644--- a/src/features/ModelSwitchPanel/components/ControlsForm/ControlsForm.tsx+++ b/src/features/ModelSwitchPanel/components/ControlsForm/ControlsForm.tsx@@ -4,7 +4,7 @@ import { Flexbox, Form } from '@lobehub/ui';import { Switch } from '@lobehub/ui/base-ui';import { Form as AntdForm } from 'antd';import isEqual from 'fast-deep-equal';-import { MODEL_REASONING_EXTEND_PARAMS } from 'model-bank';+import { MODEL_REASONING_EXTEND_PARAMS } from 'model-bank/aiModel';import type { ReactNode } from 'react';import { memo, useEffect, useMemo } from 'react';import { Trans, useTranslation } from 'react-i18next';diff --git a/src/features/ModelSwitchPanel/components/ControlsForm/ReasoningModeSegmented.tsx b/src/features/ModelSwitchPanel/components/ControlsForm/ReasoningModeSegmented.tsxindex 105f9a9ae9d..134f5c13ab7 100644--- a/src/features/ModelSwitchPanel/components/ControlsForm/ReasoningModeSegmented.tsx+++ b/src/features/ModelSwitchPanel/components/ControlsForm/ReasoningModeSegmented.tsx@@ -1,5 +1,5 @@import { Segmented } from '@lobehub/ui/base-ui';-import { MODEL_REASONING_PARAM_LEVELS } from 'model-bank';+import { MODEL_REASONING_PARAM_LEVELS } from 'model-bank/aiModel';import { memo } from 'react';import { useTranslation } from 'react-i18next';diff --git a/src/features/Settings/provider/detail/azure/index.tsx b/src/features/Settings/provider/detail/azure/index.tsxindex e8094fd9d4b..d6c093589c8 100644--- a/src/features/Settings/provider/detail/azure/index.tsx+++ b/src/features/Settings/provider/detail/azure/index.tsx@@ -1,6 +1,6 @@'use client';-import { ModelProvider } from 'model-bank';+import { ModelProvider } from 'model-bank/modelProvider';import { AzureProviderCard } from 'model-bank/modelProviders';import { useTranslation } from 'react-i18next';diff --git a/src/features/Settings/provider/detail/azureai/index.tsx b/src/features/Settings/provider/detail/azureai/index.tsxindex c28fd332daf..0a797f70a84 100644--- a/src/features/Settings/provider/detail/azureai/index.tsx+++ b/src/features/Settings/provider/detail/azureai/index.tsx@@ -1,6 +1,6 @@'use client';-import { ModelProvider } from 'model-bank';+import { ModelProvider } from 'model-bank/modelProvider';import { AzureAIProviderCard } from 'model-bank/modelProviders';import { useTranslation } from 'react-i18next';diff --git a/src/features/Settings/provider/features/ModelList/ModelItem.tsx b/src/features/Settings/provider/features/ModelList/ModelItem.tsxindex 0300f410a07..f050b165102 100644--- a/src/features/Settings/provider/features/ModelList/ModelItem.tsx+++ b/src/features/Settings/provider/features/ModelList/ModelItem.tsx@@ -4,7 +4,7 @@ import { ActionIcon, confirmModal, Switch, Tag, Text, toast } from '@lobehub/ui/import { createStaticStyles, cssVar } from 'antd-style';import { LucidePencil, TrashIcon } from 'lucide-react';import { type AiProviderModelListItem } from 'model-bank';-import { AiModelSourceEnum } from 'model-bank';+import { AiModelSourceEnum } from 'model-bank/aiModel';import React, { memo, use, useState } from 'react';import { useTranslation } from 'react-i18next';diff --git a/src/helpers/getSearchConfig.ts b/src/helpers/getSearchConfig.tsindex 328e5e78466..1e8b1430c6f 100644--- a/src/helpers/getSearchConfig.ts+++ b/src/helpers/getSearchConfig.ts@@ -1,4 +1,4 @@-import { resolveSearchDecision, type SearchDecision } from 'model-bank';+import { resolveSearchDecision, type SearchDecision } from 'model-bank/utils';import { getAgentStoreState } from '@/store/agent';import { chatConfigByIdSelectors } from '@/store/agent/selectors';diff --git a/src/routes/(main)/(create)/features/GenerationInput/GenerationInvalidAPIKey.tsx b/src/routes/(main)/(create)/features/GenerationInput/GenerationInvalidAPIKey.tsxindex 7ab5597db45..f5728d16573 100644--- a/src/routes/(main)/(create)/features/GenerationInput/GenerationInvalidAPIKey.tsx+++ b/src/routes/(main)/(create)/features/GenerationInput/GenerationInvalidAPIKey.tsx@@ -1,7 +1,7 @@'use client';import { Button } from '@lobehub/ui/base-ui';-import { ModelProvider } from 'model-bank';+import { ModelProvider } from 'model-bank/modelProvider';import { memo } from 'react';import { useTranslation } from 'react-i18next';import urlJoin from 'url-join';diff --git a/src/routes/(main)/(create)/image/features/ConfigPanel/components/InputNumber/index.tsx b/src/routes/(main)/(create)/image/features/ConfigPanel/components/InputNumber/index.tsxindex 37988578269..c708ba6d9dc 100644--- a/src/routes/(main)/(create)/image/features/ConfigPanel/components/InputNumber/index.tsx+++ b/src/routes/(main)/(create)/image/features/ConfigPanel/components/InputNumber/index.tsx@@ -3,7 +3,7 @@import { Flexbox, InputNumber, Tooltip } from '@lobehub/ui';import { Button } from '@lobehub/ui/base-ui';import { Dices } from 'lucide-react';-import { MAX_SEED } from 'model-bank';+import { MAX_SEED } from 'model-bank/standardParameters';import { type CSSProperties } from 'react';import { memo, useCallback } from 'react';import { useTranslation } from 'react-i18next';diff --git a/src/routes/(main)/(create)/image/features/ConfigPanel/hooks/useAutoDimensions.ts b/src/routes/(main)/(create)/image/features/ConfigPanel/hooks/useAutoDimensions.tsindex 26a9bb3f744..0691895677b 100644--- a/src/routes/(main)/(create)/image/features/ConfigPanel/hooks/useAutoDimensions.ts+++ b/src/routes/(main)/(create)/image/features/ConfigPanel/hooks/useAutoDimensions.ts@@ -1,4 +1,4 @@-import { DEFAULT_DIMENSION_CONSTRAINTS } from 'model-bank';+import { DEFAULT_DIMENSION_CONSTRAINTS } from 'model-bank/standardParameters';import { useImageStore } from '@/store/image';import { imageGenerationConfigSelectors } from '@/store/image/selectors';diff --git a/src/services/_auth.ts b/src/services/_auth.tsindex 67a35196ff4..ab8ee5b2dac 100644--- a/src/services/_auth.ts+++ b/src/services/_auth.ts@@ -7,7 +7,7 @@ import {type OpenAICompatibleKeyVault,type VertexAIKeyVault,} from '@lobechat/types';-import { clientApiKeyManager } from '@lobechat/utils/client';+import { clientApiKeyManager } from '@lobechat/utils/client/apiKeyManager';import { ModelProvider } from 'model-bank/modelProvider';import { aiProviderSelectors, useAiInfraStore } from '@/store/aiInfra';diff --git a/src/store/aiInfra/slices/aiModel/selectors.ts b/src/store/aiInfra/slices/aiModel/selectors.tsindex 3ef0bc071de..cd3570512bf 100644--- a/src/store/aiInfra/slices/aiModel/selectors.ts+++ b/src/store/aiInfra/slices/aiModel/selectors.ts@@ -1,6 +1,8 @@-import type { ExtendParamsType } from 'model-bank';-import { MODEL_REASONING_EXTEND_PARAMS } from 'model-bank';-import { AiModelSourceEnum } from 'model-bank/aiModel';+import {+ AiModelSourceEnum,+ type ExtendParamsType,+ MODEL_REASONING_EXTEND_PARAMS,+} from 'model-bank/aiModel';import { type AIProviderStoreState } from '@/store/aiInfra/initialState';import { ModelSearchImplement } from '@/types/search';diff --git a/src/store/file/slices/upload/action.test.ts b/src/store/file/slices/upload/action.test.tsindex a750780dd1c..d17c85dab09 100644--- a/src/store/file/slices/upload/action.test.ts+++ b/src/store/file/slices/upload/action.test.ts@@ -170,11 +170,9 @@ describe('FileUploadAction', () => {vi.mocked(getImageDimensions).mockResolvedValue(undefined);vi.spyOn(uploadService, 'uploadBase64ToS3').mockRejectedValue(new Error('Upload failed'));- await expect(- act(async () => {- await result.current.uploadBase64FileWithProgress(base64Data);- }),- ).rejects.toThrow('Upload failed');+ await expect(result.current.uploadBase64FileWithProgress(base64Data)).rejects.toThrow(+ 'Upload failed',+ );});it('should delegate handled base64 upload errors to the business upload error handler', async () => {@@ -1035,13 +1033,7 @@ describe('FileUploadAction', () => {vi.mocked(getImageDimensions).mockResolvedValue(undefined);vi.spyOn(fileService, 'checkFileHash').mockRejectedValue(new Error('Hash check failed'));- await expect(- act(async () => {- await uploadWithProgress({- file: mockFile,- });- }),- ).rejects.toThrow('Hash check failed');+ await expect(uploadWithProgress({ file: mockFile })).rejects.toThrow('Hash check failed');});it('should handle uploadFileToS3 errors', async () => {@@ -1054,13 +1046,7 @@ describe('FileUploadAction', () => {vi.spyOn(fileService, 'checkFileHash').mockResolvedValue(mockCheckResult);vi.spyOn(uploadService, 'uploadFileToS3').mockRejectedValue(new Error('Upload failed'));- await expect(- act(async () => {- await uploadWithProgress({- file: mockFile,- });- }),- ).rejects.toThrow('Upload failed');+ await expect(uploadWithProgress({ file: mockFile })).rejects.toThrow('Upload failed');});it('should handle createFile errors', async () => {@@ -1081,13 +1067,7 @@ describe('FileUploadAction', () => {vi.spyOn(uploadService, 'uploadFileToS3').mockResolvedValue(mockUploadResult);vi.spyOn(fileService, 'createFile').mockRejectedValue(new Error('DB creation failed'));- await expect(- act(async () => {- await uploadWithProgress({- file: mockFile,- });- }),- ).rejects.toThrow('DB creation failed');+ await expect(uploadWithProgress({ file: mockFile })).rejects.toThrow('DB creation failed');});});});diff --git a/src/store/image/slices/generationConfig/action.ts b/src/store/image/slices/generationConfig/action.tsindex a0bea4ac558..e9d96164f66 100644--- a/src/store/image/slices/generationConfig/action.ts+++ b/src/store/image/slices/generationConfig/action.ts@@ -5,7 +5,7 @@ import {type RuntimeImageGenParamsKeys,type RuntimeImageGenParamsValue,} from 'model-bank';-import { extractDefaultValues } from 'model-bank';+import { extractDefaultValues } from 'model-bank/standardParameters';import { aiProviderSelectors, getAiInfraStoreState } from '@/store/aiInfra';import { useGlobalStore } from '@/store/global';diff --git a/src/store/image/slices/generationConfig/hooks.ts b/src/store/image/slices/generationConfig/hooks.tsindex 015ea1b054e..c31b989f125 100644--- a/src/store/image/slices/generationConfig/hooks.ts+++ b/src/store/image/slices/generationConfig/hooks.ts@@ -1,5 +1,5 @@import { type RuntimeImageGenParams, type RuntimeImageGenParamsKeys } from 'model-bank';-import { DEFAULT_ASPECT_RATIO, PRESET_ASPECT_RATIOS } from 'model-bank';+import { DEFAULT_ASPECT_RATIO, PRESET_ASPECT_RATIOS } from 'model-bank/standardParameters';import { useCallback, useMemo } from 'react';import { useImageStore } from '../../store';diff --git a/src/store/image/slices/generationConfig/initialState.ts b/src/store/image/slices/generationConfig/initialState.tsindex 8607e89af3b..7ba16b16037 100644--- a/src/store/image/slices/generationConfig/initialState.ts+++ b/src/store/image/slices/generationConfig/initialState.ts@@ -1,6 +1,7 @@import type { ModelParamsSchema, RuntimeImageGenParams } from 'model-bank';-import { extractDefaultValues, ModelProvider } from 'model-bank';import { nanoBanana2Parameters } from 'model-bank/imageParameters';+import { ModelProvider } from 'model-bank/modelProvider';+import { extractDefaultValues } from 'model-bank/standardParameters';import { DEFAULT_IMAGE_CONFIG } from '@/const/settings';diff --git a/src/store/video/slices/generationConfig/action.ts b/src/store/video/slices/generationConfig/action.tsindex d94c239903f..587d17ea97a 100644--- a/src/store/video/slices/generationConfig/action.ts+++ b/src/store/video/slices/generationConfig/action.ts@@ -1,11 +1,11 @@+import { type AIVideoModelCard } from 'model-bank/aiModel';import {- type AIVideoModelCard,extractVideoDefaultValues,type RuntimeVideoGenParams,type RuntimeVideoGenParamsKeys,type RuntimeVideoGenParamsValue,type VideoModelParamsSchema,-} from 'model-bank';+} from 'model-bank/standardParameters';import { aiProviderSelectors, getAiInfraStoreState } from '@/store/aiInfra';import { useGlobalStore } from '@/store/global';diff --git a/src/store/video/slices/generationConfig/initialState.ts b/src/store/video/slices/generationConfig/initialState.tsindex 475007484bd..8e746e23e24 100644--- a/src/store/video/slices/generationConfig/initialState.ts+++ b/src/store/video/slices/generationConfig/initialState.ts@@ -1,12 +1,12 @@/* eslint-disable perfectionist/sort-interfaces */+import { ModelProvider } from 'model-bank/modelProvider';import {extractVideoDefaultValues,- ModelProvider,PRESET_VIDEO_ASPECT_RATIOS,PRESET_VIDEO_RESOLUTIONS,type RuntimeVideoGenParams,type VideoModelParamsSchema,-} from 'model-bank';+} from 'model-bank/standardParameters';export const DEFAULT_AI_VIDEO_PROVIDER = ModelProvider.LobeHub;export const DEFAULT_AI_VIDEO_MODEL = 'dreamina-seedance-2-0-260128';diff --git a/src/utils/aiProvider.ts b/src/utils/aiProvider.tsindex bd3efb97d72..45c73edbaf3 100644--- a/src/utils/aiProvider.ts+++ b/src/utils/aiProvider.ts@@ -1,5 +1,5 @@import type { BuiltinModelIdentifier, EnabledAiModel } from 'model-bank';-import { isAiModelVisible } from 'model-bank';+import { isAiModelVisible } from 'model-bank/aiModel';const getBuiltinModelIdentifierKey = ({ id, providerId }: BuiltinModelIdentifier) =>`${providerId}\u0000${id}`;diff --git a/src/utils/errorResponse.ts b/src/utils/errorResponse.tsindex a03f26d57f0..8c35c087a3d 100644--- a/src/utils/errorResponse.ts+++ b/src/utils/errorResponse.ts@@ -1,5 +1,5 @@import { AUTH_REQUIRED_HEADER } from '@lobechat/desktop-bridge';-import { getErrorCodeSpec } from '@lobechat/model-runtime/errors';+import { getErrorCodeSpec } from '@lobechat/model-runtime/errors/specs';import type { ILobeAgentRuntimeErrorType } from '@lobechat/model-runtime/types/error';import type { ErrorResponse, ErrorType } from '@lobechat/types';import { ChatErrorType } from '@lobechat/types';