@lobehub/chat 1.98.2 → 1.99.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cursor/rules/backend-architecture.mdc +93 -17
- package/.cursor/rules/cursor-ux.mdc +45 -35
- package/.cursor/rules/project-introduce.mdc +72 -6
- package/.cursor/rules/rules-attach.mdc +16 -7
- package/.eslintrc.js +10 -0
- package/CHANGELOG.md +44 -0
- package/apps/desktop/README.md +7 -0
- package/apps/desktop/electron-builder.js +5 -0
- package/apps/desktop/package.json +2 -1
- package/apps/desktop/src/main/appBrowsers.ts +1 -1
- package/apps/desktop/src/main/const/dir.ts +3 -0
- package/apps/desktop/src/main/controllers/UploadFileCtr.ts +13 -8
- package/apps/desktop/src/main/core/App.ts +8 -0
- package/apps/desktop/src/main/core/BrowserManager.ts +5 -2
- package/apps/desktop/src/main/core/StaticFileServerManager.ts +221 -0
- package/apps/desktop/src/main/services/fileSrv.ts +231 -44
- package/apps/desktop/src/main/utils/next-electron-rsc.ts +36 -5
- package/changelog/v1.json +14 -0
- package/docs/development/database-schema.dbml +70 -0
- package/locales/ar/common.json +2 -0
- package/locales/ar/components.json +35 -0
- package/locales/ar/error.json +2 -0
- package/locales/ar/image.json +100 -0
- package/locales/ar/metadata.json +4 -0
- package/locales/ar/modelProvider.json +1 -0
- package/locales/ar/models.json +15 -0
- package/locales/ar/plugin.json +22 -0
- package/locales/ar/providers.json +3 -0
- package/locales/ar/setting.json +5 -0
- package/locales/bg-BG/common.json +2 -0
- package/locales/bg-BG/components.json +35 -0
- package/locales/bg-BG/error.json +2 -0
- package/locales/bg-BG/image.json +100 -0
- package/locales/bg-BG/metadata.json +4 -0
- package/locales/bg-BG/modelProvider.json +1 -0
- package/locales/bg-BG/models.json +15 -0
- package/locales/bg-BG/plugin.json +22 -0
- package/locales/bg-BG/providers.json +3 -0
- package/locales/bg-BG/setting.json +5 -0
- package/locales/de-DE/common.json +2 -0
- package/locales/de-DE/components.json +35 -0
- package/locales/de-DE/error.json +2 -0
- package/locales/de-DE/image.json +100 -0
- package/locales/de-DE/metadata.json +4 -0
- package/locales/de-DE/modelProvider.json +1 -0
- package/locales/de-DE/models.json +15 -0
- package/locales/de-DE/plugin.json +22 -0
- package/locales/de-DE/providers.json +3 -0
- package/locales/de-DE/setting.json +5 -0
- package/locales/en-US/common.json +2 -0
- package/locales/en-US/components.json +35 -0
- package/locales/en-US/error.json +2 -0
- package/locales/en-US/image.json +100 -0
- package/locales/en-US/metadata.json +4 -0
- package/locales/en-US/modelProvider.json +1 -0
- package/locales/en-US/models.json +15 -0
- package/locales/en-US/plugin.json +22 -0
- package/locales/en-US/providers.json +3 -0
- package/locales/en-US/setting.json +5 -0
- package/locales/es-ES/common.json +2 -0
- package/locales/es-ES/components.json +35 -0
- package/locales/es-ES/error.json +2 -0
- package/locales/es-ES/image.json +100 -0
- package/locales/es-ES/metadata.json +4 -0
- package/locales/es-ES/modelProvider.json +1 -0
- package/locales/es-ES/models.json +15 -0
- package/locales/es-ES/plugin.json +22 -0
- package/locales/es-ES/providers.json +3 -0
- package/locales/es-ES/setting.json +5 -0
- package/locales/fa-IR/common.json +2 -0
- package/locales/fa-IR/components.json +35 -0
- package/locales/fa-IR/error.json +2 -0
- package/locales/fa-IR/image.json +100 -0
- package/locales/fa-IR/metadata.json +4 -0
- package/locales/fa-IR/modelProvider.json +1 -0
- package/locales/fa-IR/models.json +15 -0
- package/locales/fa-IR/plugin.json +22 -0
- package/locales/fa-IR/providers.json +3 -0
- package/locales/fa-IR/setting.json +5 -0
- package/locales/fr-FR/common.json +2 -0
- package/locales/fr-FR/components.json +35 -0
- package/locales/fr-FR/error.json +2 -0
- package/locales/fr-FR/image.json +100 -0
- package/locales/fr-FR/metadata.json +4 -0
- package/locales/fr-FR/modelProvider.json +1 -0
- package/locales/fr-FR/models.json +15 -0
- package/locales/fr-FR/plugin.json +22 -0
- package/locales/fr-FR/providers.json +3 -0
- package/locales/fr-FR/setting.json +5 -0
- package/locales/it-IT/common.json +2 -0
- package/locales/it-IT/components.json +35 -0
- package/locales/it-IT/error.json +2 -0
- package/locales/it-IT/image.json +100 -0
- package/locales/it-IT/metadata.json +4 -0
- package/locales/it-IT/modelProvider.json +1 -0
- package/locales/it-IT/models.json +15 -0
- package/locales/it-IT/plugin.json +22 -0
- package/locales/it-IT/providers.json +3 -0
- package/locales/it-IT/setting.json +5 -0
- package/locales/ja-JP/common.json +2 -0
- package/locales/ja-JP/components.json +35 -0
- package/locales/ja-JP/error.json +2 -0
- package/locales/ja-JP/image.json +100 -0
- package/locales/ja-JP/metadata.json +4 -0
- package/locales/ja-JP/modelProvider.json +1 -0
- package/locales/ja-JP/models.json +15 -0
- package/locales/ja-JP/plugin.json +22 -0
- package/locales/ja-JP/providers.json +3 -0
- package/locales/ja-JP/setting.json +5 -0
- package/locales/ko-KR/common.json +2 -0
- package/locales/ko-KR/components.json +35 -0
- package/locales/ko-KR/error.json +2 -0
- package/locales/ko-KR/image.json +100 -0
- package/locales/ko-KR/metadata.json +4 -0
- package/locales/ko-KR/modelProvider.json +1 -0
- package/locales/ko-KR/models.json +15 -0
- package/locales/ko-KR/plugin.json +22 -0
- package/locales/ko-KR/providers.json +3 -0
- package/locales/ko-KR/setting.json +5 -0
- package/locales/nl-NL/common.json +2 -0
- package/locales/nl-NL/components.json +35 -0
- package/locales/nl-NL/error.json +2 -0
- package/locales/nl-NL/image.json +100 -0
- package/locales/nl-NL/metadata.json +4 -0
- package/locales/nl-NL/modelProvider.json +1 -0
- package/locales/nl-NL/models.json +15 -0
- package/locales/nl-NL/plugin.json +22 -0
- package/locales/nl-NL/providers.json +3 -0
- package/locales/nl-NL/setting.json +5 -0
- package/locales/pl-PL/common.json +2 -0
- package/locales/pl-PL/components.json +35 -0
- package/locales/pl-PL/error.json +2 -0
- package/locales/pl-PL/image.json +100 -0
- package/locales/pl-PL/metadata.json +4 -0
- package/locales/pl-PL/modelProvider.json +1 -0
- package/locales/pl-PL/models.json +15 -0
- package/locales/pl-PL/plugin.json +22 -0
- package/locales/pl-PL/providers.json +3 -0
- package/locales/pl-PL/setting.json +5 -0
- package/locales/pt-BR/common.json +2 -0
- package/locales/pt-BR/components.json +35 -0
- package/locales/pt-BR/error.json +2 -0
- package/locales/pt-BR/image.json +100 -0
- package/locales/pt-BR/metadata.json +4 -0
- package/locales/pt-BR/modelProvider.json +1 -0
- package/locales/pt-BR/models.json +15 -0
- package/locales/pt-BR/plugin.json +22 -0
- package/locales/pt-BR/providers.json +3 -0
- package/locales/pt-BR/setting.json +5 -0
- package/locales/ru-RU/common.json +2 -0
- package/locales/ru-RU/components.json +35 -0
- package/locales/ru-RU/error.json +2 -0
- package/locales/ru-RU/image.json +100 -0
- package/locales/ru-RU/metadata.json +4 -0
- package/locales/ru-RU/modelProvider.json +1 -0
- package/locales/ru-RU/models.json +15 -0
- package/locales/ru-RU/plugin.json +22 -0
- package/locales/ru-RU/providers.json +3 -0
- package/locales/ru-RU/setting.json +5 -0
- package/locales/tr-TR/common.json +2 -0
- package/locales/tr-TR/components.json +35 -0
- package/locales/tr-TR/error.json +2 -0
- package/locales/tr-TR/image.json +100 -0
- package/locales/tr-TR/metadata.json +4 -0
- package/locales/tr-TR/modelProvider.json +1 -0
- package/locales/tr-TR/models.json +15 -0
- package/locales/tr-TR/plugin.json +22 -0
- package/locales/tr-TR/providers.json +3 -0
- package/locales/tr-TR/setting.json +5 -0
- package/locales/vi-VN/common.json +2 -0
- package/locales/vi-VN/components.json +35 -0
- package/locales/vi-VN/error.json +2 -0
- package/locales/vi-VN/image.json +100 -0
- package/locales/vi-VN/metadata.json +4 -0
- package/locales/vi-VN/modelProvider.json +1 -0
- package/locales/vi-VN/models.json +15 -0
- package/locales/vi-VN/plugin.json +22 -0
- package/locales/vi-VN/providers.json +3 -0
- package/locales/vi-VN/setting.json +5 -0
- package/locales/zh-CN/common.json +2 -0
- package/locales/zh-CN/components.json +35 -0
- package/locales/zh-CN/error.json +2 -0
- package/locales/zh-CN/image.json +100 -0
- package/locales/zh-CN/metadata.json +4 -0
- package/locales/zh-CN/modelProvider.json +1 -0
- package/locales/zh-CN/models.json +15 -0
- package/locales/zh-CN/plugin.json +22 -0
- package/locales/zh-CN/providers.json +3 -0
- package/locales/zh-CN/setting.json +5 -0
- package/locales/zh-TW/common.json +2 -0
- package/locales/zh-TW/components.json +35 -0
- package/locales/zh-TW/error.json +2 -0
- package/locales/zh-TW/image.json +100 -0
- package/locales/zh-TW/metadata.json +4 -0
- package/locales/zh-TW/modelProvider.json +1 -0
- package/locales/zh-TW/models.json +15 -0
- package/locales/zh-TW/plugin.json +22 -0
- package/locales/zh-TW/providers.json +3 -0
- package/locales/zh-TW/setting.json +5 -0
- package/package.json +11 -4
- package/packages/electron-server-ipc/src/events/file.ts +3 -1
- package/packages/electron-server-ipc/src/types/file.ts +15 -0
- package/src/app/[variants]/(main)/_layout/Desktop/SideBar/TopActions.tsx +11 -1
- package/src/app/[variants]/(main)/image/@menu/components/AspectRatioSelect/index.tsx +73 -0
- package/src/app/[variants]/(main)/image/@menu/components/SeedNumberInput/index.tsx +39 -0
- package/src/app/[variants]/(main)/image/@menu/components/SizeSelect/index.tsx +89 -0
- package/src/app/[variants]/(main)/image/@menu/default.tsx +11 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/AspectRatioSelect.tsx +24 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/DimensionControlGroup.tsx +107 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/ImageNum.tsx +290 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/ImageUpload.tsx +504 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/ImageUrl.tsx +18 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/ImageUrlsUpload.tsx +19 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/ModelSelect.tsx +155 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/MultiImagesUpload/ImageManageModal.tsx +415 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/MultiImagesUpload/index.tsx +732 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/SeedNumberInput.tsx +24 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/SizeSelect.tsx +17 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/SizeSliderInput.tsx +15 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/StepsSliderInput.tsx +11 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/constants.ts +1 -0
- package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/index.tsx +93 -0
- package/src/app/[variants]/(main)/image/@topic/default.tsx +17 -0
- package/src/app/[variants]/(main)/image/@topic/features/Topics/NewTopicButton.tsx +64 -0
- package/src/app/[variants]/(main)/image/@topic/features/Topics/SkeletonList.tsx +34 -0
- package/src/app/[variants]/(main)/image/@topic/features/Topics/TopicItem.tsx +136 -0
- package/src/app/[variants]/(main)/image/@topic/features/Topics/TopicItemContainer.tsx +91 -0
- package/src/app/[variants]/(main)/image/@topic/features/Topics/TopicList.tsx +57 -0
- package/src/app/[variants]/(main)/image/@topic/features/Topics/TopicUrlSync.tsx +37 -0
- package/src/app/[variants]/(main)/image/@topic/features/Topics/index.tsx +19 -0
- package/src/app/[variants]/(main)/image/NotSupportClient.tsx +153 -0
- package/src/app/[variants]/(main)/image/_layout/Desktop/Container.tsx +35 -0
- package/src/app/[variants]/(main)/image/_layout/Desktop/RegisterHotkeys.tsx +10 -0
- package/src/app/[variants]/(main)/image/_layout/Desktop/index.tsx +30 -0
- package/src/app/[variants]/(main)/image/_layout/Mobile/index.tsx +14 -0
- package/src/app/[variants]/(main)/image/_layout/type.ts +7 -0
- package/src/app/[variants]/(main)/image/features/GenerationFeed/BatchItem.tsx +196 -0
- package/src/app/[variants]/(main)/image/features/GenerationFeed/GenerationItem/ActionButtons.tsx +60 -0
- package/src/app/[variants]/(main)/image/features/GenerationFeed/GenerationItem/ElapsedTime.tsx +90 -0
- package/src/app/[variants]/(main)/image/features/GenerationFeed/GenerationItem/ErrorState.tsx +65 -0
- package/src/app/[variants]/(main)/image/features/GenerationFeed/GenerationItem/LoadingState.tsx +44 -0
- package/src/app/[variants]/(main)/image/features/GenerationFeed/GenerationItem/SuccessState.tsx +49 -0
- package/src/app/[variants]/(main)/image/features/GenerationFeed/GenerationItem/index.tsx +154 -0
- package/src/app/[variants]/(main)/image/features/GenerationFeed/GenerationItem/styles.ts +51 -0
- package/src/app/[variants]/(main)/image/features/GenerationFeed/GenerationItem/types.ts +39 -0
- package/src/app/[variants]/(main)/image/features/GenerationFeed/GenerationItem/utils.ts +11 -0
- package/src/app/[variants]/(main)/image/features/GenerationFeed/index.tsx +97 -0
- package/src/app/[variants]/(main)/image/features/ImageWorkspace/Content.tsx +48 -0
- package/src/app/[variants]/(main)/image/features/ImageWorkspace/EmptyState.tsx +37 -0
- package/src/app/[variants]/(main)/image/features/ImageWorkspace/SkeletonList.tsx +50 -0
- package/src/app/[variants]/(main)/image/features/ImageWorkspace/index.tsx +23 -0
- package/src/app/[variants]/(main)/image/features/PromptInput/Title.tsx +38 -0
- package/src/app/[variants]/(main)/image/features/PromptInput/index.tsx +114 -0
- package/src/app/[variants]/(main)/image/layout.tsx +19 -0
- package/src/app/[variants]/(main)/image/loading.tsx +3 -0
- package/src/app/[variants]/(main)/image/page.tsx +47 -0
- package/src/app/[variants]/(main)/settings/system-agent/index.tsx +2 -1
- package/src/chains/summaryGenerationTitle.ts +25 -0
- package/src/components/ImageItem/index.tsx +9 -6
- package/src/{features/Conversation/Error → components/InvalidAPIKey}/APIKeyForm/Bedrock.tsx +3 -4
- package/src/{features/Conversation/Error → components/InvalidAPIKey}/APIKeyForm/ProviderApiKeyForm.tsx +5 -4
- package/src/components/InvalidAPIKey/APIKeyForm/index.tsx +108 -0
- package/src/{features/Conversation/Error → components/InvalidAPIKey}/APIKeyForm/useApiKey.ts +2 -1
- package/src/components/InvalidAPIKey/index.tsx +30 -0
- package/src/components/KeyValueEditor/index.tsx +203 -0
- package/src/components/KeyValueEditor/utils.ts +42 -0
- package/src/config/aiModels/fal.ts +52 -0
- package/src/config/aiModels/index.ts +3 -0
- package/src/config/aiModels/openai.ts +20 -6
- package/src/config/llm.ts +6 -0
- package/src/config/modelProviders/fal.ts +21 -0
- package/src/config/modelProviders/index.ts +3 -0
- package/src/config/paramsSchemas/fal/flux-kontext-dev.ts +8 -0
- package/src/config/paramsSchemas/fal/flux-pro-kontext.ts +11 -0
- package/src/config/paramsSchemas/fal/flux-schnell.ts +9 -0
- package/src/config/paramsSchemas/fal/imagen4.ts +10 -0
- package/src/config/paramsSchemas/openai/gpt-image-1.ts +10 -0
- package/src/const/hotkeys.ts +2 -2
- package/src/const/image.ts +6 -0
- package/src/const/settings/systemAgent.ts +1 -0
- package/src/database/client/migrations.json +27 -0
- package/src/database/migrations/0026_add_autovacuum_tuning.sql +2 -0
- package/src/database/migrations/0027_ai_image.sql +47 -0
- package/src/database/migrations/meta/0027_snapshot.json +6003 -0
- package/src/database/migrations/meta/_journal.json +7 -0
- package/src/database/models/__tests__/asyncTask.test.ts +7 -5
- package/src/database/models/__tests__/file.test.ts +287 -0
- package/src/database/models/__tests__/generation.test.ts +786 -0
- package/src/database/models/__tests__/generationBatch.test.ts +614 -0
- package/src/database/models/__tests__/generationTopic.test.ts +411 -0
- package/src/database/models/aiModel.ts +2 -0
- package/src/database/models/asyncTask.ts +1 -1
- package/src/database/models/file.ts +28 -20
- package/src/database/models/generation.ts +197 -0
- package/src/database/models/generationBatch.ts +212 -0
- package/src/database/models/generationTopic.ts +131 -0
- package/src/database/repositories/aiInfra/index.test.ts +157 -1
- package/src/database/repositories/aiInfra/index.ts +37 -19
- package/src/database/repositories/tableViewer/index.test.ts +1 -1
- package/src/database/schemas/file.ts +8 -0
- package/src/database/schemas/generation.ts +127 -0
- package/src/database/schemas/index.ts +1 -0
- package/src/database/schemas/relations.ts +45 -1
- package/src/database/type.ts +2 -0
- package/src/database/utils/idGenerator.ts +3 -0
- package/src/features/Conversation/Error/ChatInvalidApiKey.tsx +39 -0
- package/src/features/Conversation/Error/InvalidAccessCode.tsx +2 -2
- package/src/features/Conversation/Error/index.tsx +3 -3
- package/src/features/ImageSidePanel/index.tsx +83 -0
- package/src/features/ImageTopicPanel/index.tsx +79 -0
- package/src/features/PluginDevModal/MCPManifestForm/CollapsibleSection.tsx +62 -0
- package/src/features/PluginDevModal/MCPManifestForm/QuickImportSection.tsx +158 -0
- package/src/features/PluginDevModal/MCPManifestForm/index.tsx +99 -155
- package/src/features/PluginStore/McpList/Detail/Settings/index.tsx +5 -2
- package/src/hooks/useDownloadImage.ts +31 -0
- package/src/hooks/useFetchGenerationTopics.ts +13 -0
- package/src/hooks/useHotkeys/imageScope.ts +48 -0
- package/src/libs/mcp/client.ts +55 -22
- package/src/libs/mcp/types.ts +42 -6
- package/src/libs/model-runtime/BaseAI.ts +3 -1
- package/src/libs/model-runtime/ModelRuntime.test.ts +80 -0
- package/src/libs/model-runtime/ModelRuntime.ts +15 -1
- package/src/libs/model-runtime/UniformRuntime/index.ts +4 -1
- package/src/libs/model-runtime/fal/index.test.ts +442 -0
- package/src/libs/model-runtime/fal/index.ts +88 -0
- package/src/libs/model-runtime/openai/index.test.ts +396 -2
- package/src/libs/model-runtime/openai/index.ts +129 -3
- package/src/libs/model-runtime/runtimeMap.ts +2 -0
- package/src/libs/model-runtime/types/image.ts +25 -0
- package/src/libs/model-runtime/types/type.ts +1 -0
- package/src/libs/model-runtime/utils/openaiCompatibleFactory/index.ts +10 -0
- package/src/libs/standard-parameters/index.ts +1 -0
- package/src/libs/standard-parameters/meta-schema.test.ts +214 -0
- package/src/libs/standard-parameters/meta-schema.ts +147 -0
- package/src/libs/swr/index.ts +1 -0
- package/src/libs/trpc/async/asyncAuth.ts +29 -8
- package/src/libs/trpc/async/context.ts +42 -4
- package/src/libs/trpc/async/index.ts +17 -4
- package/src/libs/trpc/async/init.ts +8 -0
- package/src/libs/trpc/client/lambda.ts +19 -2
- package/src/locales/default/common.ts +2 -0
- package/src/locales/default/components.ts +35 -0
- package/src/locales/default/error.ts +2 -0
- package/src/locales/default/image.ts +100 -0
- package/src/locales/default/index.ts +2 -0
- package/src/locales/default/metadata.ts +4 -0
- package/src/locales/default/modelProvider.ts +2 -0
- package/src/locales/default/plugin.ts +22 -0
- package/src/locales/default/setting.ts +5 -0
- package/src/middleware.ts +1 -0
- package/src/server/modules/ElectronIPCClient/index.ts +9 -1
- package/src/server/modules/S3/index.ts +15 -0
- package/src/server/routers/async/caller.ts +9 -1
- package/src/server/routers/async/image.ts +253 -0
- package/src/server/routers/async/index.ts +2 -0
- package/src/server/routers/lambda/aiProvider.test.ts +2 -0
- package/src/server/routers/lambda/generation.test.ts +267 -0
- package/src/server/routers/lambda/generation.ts +86 -0
- package/src/server/routers/lambda/generationBatch.test.ts +376 -0
- package/src/server/routers/lambda/generationBatch.ts +56 -0
- package/src/server/routers/lambda/generationTopic.test.ts +508 -0
- package/src/server/routers/lambda/generationTopic.ts +93 -0
- package/src/server/routers/lambda/image.ts +248 -0
- package/src/server/routers/lambda/index.ts +8 -0
- package/src/server/routers/tools/mcp.ts +15 -0
- package/src/server/services/file/__tests__/index.test.ts +135 -0
- package/src/server/services/file/impls/local.test.ts +153 -52
- package/src/server/services/file/impls/local.ts +70 -46
- package/src/server/services/file/impls/s3.test.ts +114 -0
- package/src/server/services/file/impls/s3.ts +40 -0
- package/src/server/services/file/impls/type.ts +10 -0
- package/src/server/services/file/index.ts +14 -0
- package/src/server/services/generation/index.ts +239 -0
- package/src/server/services/mcp/index.ts +20 -2
- package/src/services/__tests__/generation.test.ts +40 -0
- package/src/services/__tests__/generationBatch.test.ts +36 -0
- package/src/services/__tests__/generationTopic.test.ts +72 -0
- package/src/services/electron/file.ts +3 -1
- package/src/services/generation.ts +16 -0
- package/src/services/generationBatch.ts +25 -0
- package/src/services/generationTopic.ts +28 -0
- package/src/services/image.ts +33 -0
- package/src/services/mcp.ts +12 -7
- package/src/services/upload.ts +43 -9
- package/src/store/aiInfra/slices/aiProvider/action.ts +31 -6
- package/src/store/aiInfra/slices/aiProvider/initialState.ts +1 -0
- package/src/store/aiInfra/slices/aiProvider/selectors.ts +3 -0
- package/src/store/chat/slices/aiChat/actions/generateAIChat.ts +5 -5
- package/src/store/chat/slices/message/action.ts +2 -2
- package/src/store/chat/slices/translate/action.ts +1 -1
- package/src/store/global/initialState.ts +9 -0
- package/src/store/global/selectors/systemStatus.ts +8 -0
- package/src/store/image/index.ts +2 -0
- package/src/store/image/initialState.ts +25 -0
- package/src/store/image/selectors.ts +4 -0
- package/src/store/image/slices/createImage/action.test.ts +330 -0
- package/src/store/image/slices/createImage/action.ts +134 -0
- package/src/store/image/slices/createImage/initialState.ts +9 -0
- package/src/store/image/slices/createImage/selectors.test.ts +114 -0
- package/src/store/image/slices/createImage/selectors.ts +9 -0
- package/src/store/image/slices/generationBatch/action.test.ts +495 -0
- package/src/store/image/slices/generationBatch/action.ts +303 -0
- package/src/store/image/slices/generationBatch/initialState.ts +13 -0
- package/src/store/image/slices/generationBatch/reducer.test.ts +568 -0
- package/src/store/image/slices/generationBatch/reducer.ts +101 -0
- package/src/store/image/slices/generationBatch/selectors.test.ts +307 -0
- package/src/store/image/slices/generationBatch/selectors.ts +36 -0
- package/src/store/image/slices/generationConfig/action.test.ts +351 -0
- package/src/store/image/slices/generationConfig/action.ts +295 -0
- package/src/store/image/slices/generationConfig/hooks.test.ts +304 -0
- package/src/store/image/slices/generationConfig/hooks.ts +118 -0
- package/src/store/image/slices/generationConfig/index.ts +1 -0
- package/src/store/image/slices/generationConfig/initialState.ts +37 -0
- package/src/store/image/slices/generationConfig/selectors.test.ts +204 -0
- package/src/store/image/slices/generationConfig/selectors.ts +25 -0
- package/src/store/image/slices/generationTopic/action.test.ts +687 -0
- package/src/store/image/slices/generationTopic/action.ts +319 -0
- package/src/store/image/slices/generationTopic/index.ts +2 -0
- package/src/store/image/slices/generationTopic/initialState.ts +14 -0
- package/src/store/image/slices/generationTopic/reducer.test.ts +198 -0
- package/src/store/image/slices/generationTopic/reducer.ts +66 -0
- package/src/store/image/slices/generationTopic/selectors.test.ts +103 -0
- package/src/store/image/slices/generationTopic/selectors.ts +15 -0
- package/src/store/image/store.ts +42 -0
- package/src/store/image/utils/size.ts +51 -0
- package/src/store/tool/slices/customPlugin/action.ts +10 -1
- package/src/store/tool/slices/mcpStore/action.ts +6 -4
- package/src/store/user/slices/settings/selectors/__snapshots__/settings.test.ts.snap +4 -0
- package/src/store/user/slices/settings/selectors/systemAgent.ts +2 -0
- package/src/types/aiModel.ts +8 -3
- package/src/types/aiProvider.ts +2 -0
- package/src/types/asyncTask.ts +2 -0
- package/src/types/files/index.ts +5 -0
- package/src/types/generation/index.ts +80 -0
- package/src/types/hotkey.ts +2 -0
- package/src/types/plugins/mcp.ts +2 -6
- package/src/types/tool/plugin.ts +8 -0
- package/src/types/user/settings/keyVaults.ts +5 -0
- package/src/types/user/settings/systemAgent.ts +1 -0
- package/src/utils/client/downloadFile.ts +33 -4
- package/src/utils/number.test.ts +105 -0
- package/src/utils/number.ts +25 -0
- package/src/utils/server/__tests__/geo.test.ts +6 -3
- package/src/utils/storeDebug.test.ts +152 -0
- package/src/utils/storeDebug.ts +16 -7
- package/src/utils/time.test.ts +259 -0
- package/src/utils/time.ts +18 -0
- package/src/utils/units.ts +61 -0
- package/src/utils/url.test.ts +358 -9
- package/src/utils/url.ts +105 -3
- package/{vitest.server.config.ts → vitest.config.server.ts} +3 -0
- package/.cursor/rules/i18n/i18n-auto-attached.mdc +0 -6
- package/src/features/Conversation/Error/APIKeyForm/index.tsx +0 -105
- package/src/features/Conversation/Error/InvalidAPIKey.tsx +0 -16
- package/src/features/PluginDevModal/MCPManifestForm/EnvEditor.tsx +0 -227
- /package/.cursor/rules/{i18n/i18n.mdc → i18n.mdc} +0 -0
- /package/src/app/[variants]/(main)/settings/system-agent/features/{createForm.tsx → SystemAgentForm.tsx} +0 -0
- /package/src/{features/Conversation/Error → components/InvalidAPIKey}/APIKeyForm/LoadingContext.ts +0 -0
@@ -0,0 +1,504 @@
|
|
1
|
+
'use client';
|
2
|
+
|
3
|
+
import { createStyles, useTheme } from 'antd-style';
|
4
|
+
import { Image as ImageIcon, X } from 'lucide-react';
|
5
|
+
import React, { type FC, memo, useEffect, useRef, useState } from 'react';
|
6
|
+
import { useTranslation } from 'react-i18next';
|
7
|
+
import { Center } from 'react-layout-kit';
|
8
|
+
|
9
|
+
import { useFileStore } from '@/store/file';
|
10
|
+
import { FileUploadStatus } from '@/types/files/upload';
|
11
|
+
|
12
|
+
// ======== Business Types ======== //
|
13
|
+
|
14
|
+
export interface ImageUploadProps {
|
15
|
+
// Callback when URL changes
|
16
|
+
className?: string; // Image URL
|
17
|
+
onChange?: (url?: string) => void;
|
18
|
+
style?: React.CSSProperties;
|
19
|
+
value?: string | null;
|
20
|
+
}
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Internal type for managing upload state
|
24
|
+
*/
|
25
|
+
interface UploadState {
|
26
|
+
error?: string; // Upload progress (0-100)
|
27
|
+
previewUrl: string;
|
28
|
+
progress: number;
|
29
|
+
// Local blob URL for preview
|
30
|
+
status: FileUploadStatus;
|
31
|
+
}
|
32
|
+
|
33
|
+
// ======== Styles ======== //
|
34
|
+
|
35
|
+
const useStyles = createStyles(({ css, token }) => {
|
36
|
+
return {
|
37
|
+
changeButton: css`
|
38
|
+
cursor: pointer;
|
39
|
+
|
40
|
+
padding-block: 8px;
|
41
|
+
padding-inline: 16px;
|
42
|
+
border: 1px solid ${token.colorBorder};
|
43
|
+
border-radius: ${token.borderRadius}px;
|
44
|
+
|
45
|
+
font-size: 12px;
|
46
|
+
font-weight: 500;
|
47
|
+
color: ${token.colorText};
|
48
|
+
|
49
|
+
background: ${token.colorBgContainer};
|
50
|
+
box-shadow: ${token.boxShadowSecondary};
|
51
|
+
|
52
|
+
&:hover {
|
53
|
+
border-color: ${token.colorPrimary};
|
54
|
+
color: ${token.colorPrimary};
|
55
|
+
background: ${token.colorBgElevated};
|
56
|
+
}
|
57
|
+
`,
|
58
|
+
changeOverlay: css`
|
59
|
+
position: absolute;
|
60
|
+
z-index: 5;
|
61
|
+
inset: 0;
|
62
|
+
|
63
|
+
display: flex;
|
64
|
+
align-items: center;
|
65
|
+
justify-content: center;
|
66
|
+
|
67
|
+
opacity: 0;
|
68
|
+
background: ${token.colorBgMask};
|
69
|
+
|
70
|
+
transition: opacity ${token.motionDurationMid} ease;
|
71
|
+
`,
|
72
|
+
container: css`
|
73
|
+
width: 100%;
|
74
|
+
`,
|
75
|
+
deleteIcon: css`
|
76
|
+
cursor: pointer;
|
77
|
+
|
78
|
+
position: absolute;
|
79
|
+
z-index: 10;
|
80
|
+
inset-block-start: 8px;
|
81
|
+
inset-inline-end: 8px;
|
82
|
+
|
83
|
+
display: flex;
|
84
|
+
align-items: center;
|
85
|
+
justify-content: center;
|
86
|
+
|
87
|
+
width: 24px;
|
88
|
+
height: 24px;
|
89
|
+
border-radius: 50%;
|
90
|
+
|
91
|
+
color: ${token.colorTextLightSolid};
|
92
|
+
|
93
|
+
opacity: 0;
|
94
|
+
background: ${token.colorBgMask};
|
95
|
+
|
96
|
+
transition: opacity ${token.motionDurationMid} ease;
|
97
|
+
|
98
|
+
&:hover {
|
99
|
+
color: ${token.colorError};
|
100
|
+
background: ${token.colorErrorBg};
|
101
|
+
}
|
102
|
+
`,
|
103
|
+
imageStyle: css`
|
104
|
+
width: 100%;
|
105
|
+
height: 100%;
|
106
|
+
object-fit: cover;
|
107
|
+
`,
|
108
|
+
placeholder: css`
|
109
|
+
cursor: pointer;
|
110
|
+
|
111
|
+
width: 100%;
|
112
|
+
height: 160px;
|
113
|
+
border: 2px dashed ${token.colorBorder};
|
114
|
+
border-radius: ${token.borderRadiusLG}px;
|
115
|
+
|
116
|
+
background: ${token.colorFillAlter};
|
117
|
+
|
118
|
+
transition: all ${token.motionDurationMid} ease;
|
119
|
+
|
120
|
+
&:hover {
|
121
|
+
border-color: ${token.colorPrimary};
|
122
|
+
background: ${token.colorFillSecondary};
|
123
|
+
}
|
124
|
+
`,
|
125
|
+
placeholderIcon: css`
|
126
|
+
color: ${token.colorTextTertiary};
|
127
|
+
`,
|
128
|
+
placeholderText: css`
|
129
|
+
font-size: 12px;
|
130
|
+
line-height: 1.4;
|
131
|
+
color: ${token.colorTextSecondary};
|
132
|
+
text-align: center;
|
133
|
+
`,
|
134
|
+
successDisplay: css`
|
135
|
+
cursor: pointer;
|
136
|
+
|
137
|
+
position: relative;
|
138
|
+
|
139
|
+
overflow: hidden;
|
140
|
+
|
141
|
+
width: 100%;
|
142
|
+
height: 160px;
|
143
|
+
border-radius: ${token.borderRadiusLG}px;
|
144
|
+
|
145
|
+
background: ${token.colorBgContainer};
|
146
|
+
|
147
|
+
&:hover .change-overlay {
|
148
|
+
opacity: 1;
|
149
|
+
}
|
150
|
+
|
151
|
+
&:hover .delete-icon {
|
152
|
+
opacity: 1;
|
153
|
+
}
|
154
|
+
`,
|
155
|
+
uploadingDisplay: css`
|
156
|
+
position: relative;
|
157
|
+
|
158
|
+
overflow: hidden;
|
159
|
+
|
160
|
+
width: 100%;
|
161
|
+
height: 160px;
|
162
|
+
border: 2px solid ${token.colorPrimary};
|
163
|
+
border-radius: ${token.borderRadiusLG}px;
|
164
|
+
|
165
|
+
background: ${token.colorFillSecondary};
|
166
|
+
`,
|
167
|
+
uploadingOverlay: css`
|
168
|
+
position: absolute;
|
169
|
+
z-index: 5;
|
170
|
+
inset: 0;
|
171
|
+
|
172
|
+
display: flex;
|
173
|
+
align-items: center;
|
174
|
+
justify-content: center;
|
175
|
+
|
176
|
+
background: ${token.colorBgMask};
|
177
|
+
`,
|
178
|
+
};
|
179
|
+
});
|
180
|
+
|
181
|
+
// ======== Utils ======== //
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Check if a URL is a local blob URL
|
185
|
+
*/
|
186
|
+
const isLocalBlobUrl = (url: string): boolean => url.startsWith('blob:');
|
187
|
+
|
188
|
+
// ======== Sub-Components ======== //
|
189
|
+
|
190
|
+
/**
|
191
|
+
* 圆形进度条组件 (复用自 MultiImagesUpload)
|
192
|
+
*/
|
193
|
+
interface CircularProgressProps {
|
194
|
+
showText?: boolean; // 0-100
|
195
|
+
size?: number;
|
196
|
+
strokeWidth?: number;
|
197
|
+
value: number;
|
198
|
+
}
|
199
|
+
|
200
|
+
const CircularProgress: FC<CircularProgressProps> = memo(
|
201
|
+
({ value, size = 60, strokeWidth = 6, showText = true }) => {
|
202
|
+
const theme = useTheme();
|
203
|
+
|
204
|
+
// Ensure value is between 0 and 100
|
205
|
+
const progress = Math.min(100, Math.max(0, value));
|
206
|
+
|
207
|
+
// Calculate circle properties
|
208
|
+
const radius = (size - strokeWidth) / 2;
|
209
|
+
const circumference = radius * 2 * Math.PI;
|
210
|
+
const offset = circumference - (progress / 100) * circumference;
|
211
|
+
|
212
|
+
return (
|
213
|
+
<div
|
214
|
+
style={{
|
215
|
+
alignItems: 'center',
|
216
|
+
display: 'flex',
|
217
|
+
height: size,
|
218
|
+
justifyContent: 'center',
|
219
|
+
position: 'relative',
|
220
|
+
width: size,
|
221
|
+
}}
|
222
|
+
>
|
223
|
+
{/* Background circle */}
|
224
|
+
<svg
|
225
|
+
height={size}
|
226
|
+
style={{ position: 'absolute', transform: 'rotate(-90deg)' }}
|
227
|
+
width={size}
|
228
|
+
>
|
229
|
+
<circle
|
230
|
+
cx={size / 2}
|
231
|
+
cy={size / 2}
|
232
|
+
fill="none"
|
233
|
+
r={radius}
|
234
|
+
stroke={theme.colorBorder}
|
235
|
+
strokeWidth={strokeWidth}
|
236
|
+
/>
|
237
|
+
</svg>
|
238
|
+
|
239
|
+
{/* Progress circle */}
|
240
|
+
<svg
|
241
|
+
height={size}
|
242
|
+
style={{ position: 'absolute', transform: 'rotate(-90deg)' }}
|
243
|
+
width={size}
|
244
|
+
>
|
245
|
+
<circle
|
246
|
+
cx={size / 2}
|
247
|
+
cy={size / 2}
|
248
|
+
fill="none"
|
249
|
+
r={radius}
|
250
|
+
stroke={theme.colorPrimary}
|
251
|
+
strokeDasharray={circumference}
|
252
|
+
strokeDashoffset={offset}
|
253
|
+
strokeLinecap="round"
|
254
|
+
strokeWidth={strokeWidth}
|
255
|
+
style={{
|
256
|
+
transition: 'stroke-dashoffset 0.2s ease-in-out',
|
257
|
+
}}
|
258
|
+
/>
|
259
|
+
</svg>
|
260
|
+
|
261
|
+
{/* Progress text */}
|
262
|
+
{showText && (
|
263
|
+
<span
|
264
|
+
style={{
|
265
|
+
color: theme.colorPrimary,
|
266
|
+
fontSize: '12px',
|
267
|
+
fontWeight: 600,
|
268
|
+
position: 'relative',
|
269
|
+
zIndex: 1,
|
270
|
+
}}
|
271
|
+
>
|
272
|
+
{Math.round(progress)}%
|
273
|
+
</span>
|
274
|
+
)}
|
275
|
+
</div>
|
276
|
+
);
|
277
|
+
},
|
278
|
+
);
|
279
|
+
|
280
|
+
CircularProgress.displayName = 'CircularProgress';
|
281
|
+
|
282
|
+
/**
|
283
|
+
* 占位视图组件
|
284
|
+
*/
|
285
|
+
interface PlaceholderProps {
|
286
|
+
onClick?: () => void;
|
287
|
+
}
|
288
|
+
|
289
|
+
const Placeholder: FC<PlaceholderProps> = memo(({ onClick }) => {
|
290
|
+
const { styles } = useStyles();
|
291
|
+
const { t } = useTranslation('components');
|
292
|
+
|
293
|
+
return (
|
294
|
+
<Center className={styles.placeholder} gap={16} horizontal={false} onClick={onClick}>
|
295
|
+
<ImageIcon className={styles.placeholderIcon} size={48} strokeWidth={1.5} />
|
296
|
+
<div className={styles.placeholderText}>
|
297
|
+
{t('ImageUpload.placeholder.primary', 'Add Image')}
|
298
|
+
<br />
|
299
|
+
{t('ImageUpload.placeholder.secondary', 'Click to upload')}
|
300
|
+
</div>
|
301
|
+
</Center>
|
302
|
+
);
|
303
|
+
});
|
304
|
+
|
305
|
+
Placeholder.displayName = 'Placeholder';
|
306
|
+
|
307
|
+
/**
|
308
|
+
* 上传中视图组件
|
309
|
+
*/
|
310
|
+
interface UploadingDisplayProps {
|
311
|
+
previewUrl: string;
|
312
|
+
progress: number;
|
313
|
+
}
|
314
|
+
|
315
|
+
const UploadingDisplay: FC<UploadingDisplayProps> = memo(({ previewUrl, progress }) => {
|
316
|
+
const { styles } = useStyles();
|
317
|
+
|
318
|
+
return (
|
319
|
+
<div className={styles.uploadingDisplay}>
|
320
|
+
<img alt="Uploading preview" className={styles.imageStyle} src={previewUrl} />
|
321
|
+
<div className={styles.uploadingOverlay}>
|
322
|
+
<CircularProgress value={progress} />
|
323
|
+
</div>
|
324
|
+
</div>
|
325
|
+
);
|
326
|
+
});
|
327
|
+
|
328
|
+
UploadingDisplay.displayName = 'UploadingDisplay';
|
329
|
+
|
330
|
+
/**
|
331
|
+
* 成功视图组件
|
332
|
+
*/
|
333
|
+
interface SuccessDisplayProps {
|
334
|
+
imageUrl: string;
|
335
|
+
onChangeImage?: () => void;
|
336
|
+
onDelete?: () => void;
|
337
|
+
}
|
338
|
+
|
339
|
+
const SuccessDisplay: FC<SuccessDisplayProps> = memo(({ imageUrl, onDelete, onChangeImage }) => {
|
340
|
+
const { styles } = useStyles();
|
341
|
+
const { t } = useTranslation('components');
|
342
|
+
|
343
|
+
const handleDelete = (event: React.MouseEvent) => {
|
344
|
+
event.stopPropagation();
|
345
|
+
onDelete?.();
|
346
|
+
};
|
347
|
+
|
348
|
+
const handleChangeImage = (event: React.MouseEvent) => {
|
349
|
+
event.stopPropagation();
|
350
|
+
onChangeImage?.();
|
351
|
+
};
|
352
|
+
|
353
|
+
return (
|
354
|
+
<div className={styles.successDisplay} onClick={onChangeImage}>
|
355
|
+
<img alt="Uploaded image" className={styles.imageStyle} src={imageUrl} />
|
356
|
+
|
357
|
+
{/* Delete button */}
|
358
|
+
<div className={`${styles.deleteIcon} delete-icon`} onClick={handleDelete}>
|
359
|
+
<X size={14} />
|
360
|
+
</div>
|
361
|
+
|
362
|
+
{/* Change image overlay */}
|
363
|
+
<div className={`${styles.changeOverlay} change-overlay`} onClick={handleChangeImage}>
|
364
|
+
<button className={styles.changeButton} type="button">
|
365
|
+
{t('ImageUpload.actions.changeImage', 'Click to change image')}
|
366
|
+
</button>
|
367
|
+
</div>
|
368
|
+
</div>
|
369
|
+
);
|
370
|
+
});
|
371
|
+
|
372
|
+
SuccessDisplay.displayName = 'SuccessDisplay';
|
373
|
+
|
374
|
+
// ======== Main Component ======== //
|
375
|
+
|
376
|
+
const ImageUpload: FC<ImageUploadProps> = memo(({ value, onChange, style, className }) => {
|
377
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
378
|
+
const uploadWithProgress = useFileStore((s) => s.uploadWithProgress);
|
379
|
+
const [uploadState, setUploadState] = useState<UploadState | null>(null);
|
380
|
+
|
381
|
+
// Cleanup blob URLs to prevent memory leaks
|
382
|
+
useEffect(() => {
|
383
|
+
return () => {
|
384
|
+
if (uploadState?.previewUrl && isLocalBlobUrl(uploadState.previewUrl)) {
|
385
|
+
URL.revokeObjectURL(uploadState.previewUrl);
|
386
|
+
}
|
387
|
+
};
|
388
|
+
}, [uploadState?.previewUrl]);
|
389
|
+
|
390
|
+
const handleFileSelect = () => {
|
391
|
+
inputRef.current?.click();
|
392
|
+
};
|
393
|
+
|
394
|
+
const handleFileChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
395
|
+
const file = event.target.files?.[0];
|
396
|
+
if (!file) return;
|
397
|
+
|
398
|
+
// Create preview URL
|
399
|
+
const previewUrl = URL.createObjectURL(file);
|
400
|
+
|
401
|
+
// Set initial upload state
|
402
|
+
setUploadState({
|
403
|
+
previewUrl,
|
404
|
+
progress: 0,
|
405
|
+
status: 'pending',
|
406
|
+
});
|
407
|
+
|
408
|
+
try {
|
409
|
+
// Start upload
|
410
|
+
const result = await uploadWithProgress({
|
411
|
+
file,
|
412
|
+
onStatusUpdate: (updateData) => {
|
413
|
+
if (updateData.type === 'updateFile') {
|
414
|
+
setUploadState((prev) => {
|
415
|
+
if (!prev) return null;
|
416
|
+
|
417
|
+
const fileStatus = updateData.value.status;
|
418
|
+
if (!fileStatus) return prev;
|
419
|
+
|
420
|
+
return {
|
421
|
+
...prev,
|
422
|
+
error: fileStatus === 'error' ? 'Upload failed' : undefined,
|
423
|
+
progress: updateData.value.uploadState?.progress || 0,
|
424
|
+
status: fileStatus,
|
425
|
+
};
|
426
|
+
});
|
427
|
+
} else if (updateData.type === 'removeFile') {
|
428
|
+
// Handle file removal
|
429
|
+
setUploadState(null);
|
430
|
+
}
|
431
|
+
},
|
432
|
+
skipCheckFileType: true,
|
433
|
+
});
|
434
|
+
|
435
|
+
if (result?.url) {
|
436
|
+
// Upload successful
|
437
|
+
onChange?.(result.url);
|
438
|
+
}
|
439
|
+
} catch {
|
440
|
+
// Upload failed
|
441
|
+
setUploadState((prev) =>
|
442
|
+
prev
|
443
|
+
? {
|
444
|
+
...prev,
|
445
|
+
error: 'Upload failed',
|
446
|
+
status: 'error',
|
447
|
+
}
|
448
|
+
: null,
|
449
|
+
);
|
450
|
+
} finally {
|
451
|
+
// Cleanup
|
452
|
+
if (isLocalBlobUrl(previewUrl)) {
|
453
|
+
URL.revokeObjectURL(previewUrl);
|
454
|
+
}
|
455
|
+
|
456
|
+
// Clear upload state after a delay to show completion
|
457
|
+
setTimeout(() => {
|
458
|
+
setUploadState(null);
|
459
|
+
}, 1000);
|
460
|
+
}
|
461
|
+
};
|
462
|
+
|
463
|
+
const handleDelete = () => {
|
464
|
+
onChange?.(undefined);
|
465
|
+
};
|
466
|
+
|
467
|
+
// Determine which view to render
|
468
|
+
const hasImage = Boolean(value);
|
469
|
+
const isUploading = Boolean(uploadState);
|
470
|
+
|
471
|
+
return (
|
472
|
+
<div className={className} style={style}>
|
473
|
+
{/* Hidden file input */}
|
474
|
+
<input
|
475
|
+
accept="image/*"
|
476
|
+
onChange={handleFileChange}
|
477
|
+
onClick={(e) => {
|
478
|
+
// Reset value to allow re-selecting the same file
|
479
|
+
e.currentTarget.value = '';
|
480
|
+
}}
|
481
|
+
ref={inputRef}
|
482
|
+
style={{ display: 'none' }}
|
483
|
+
type="file"
|
484
|
+
/>
|
485
|
+
|
486
|
+
{/* Conditional rendering based on state */}
|
487
|
+
{isUploading && uploadState ? (
|
488
|
+
<UploadingDisplay previewUrl={uploadState.previewUrl} progress={uploadState.progress} />
|
489
|
+
) : hasImage ? (
|
490
|
+
<SuccessDisplay
|
491
|
+
imageUrl={value!}
|
492
|
+
onChangeImage={handleFileSelect}
|
493
|
+
onDelete={handleDelete}
|
494
|
+
/>
|
495
|
+
) : (
|
496
|
+
<Placeholder onClick={handleFileSelect} />
|
497
|
+
)}
|
498
|
+
</div>
|
499
|
+
);
|
500
|
+
});
|
501
|
+
|
502
|
+
ImageUpload.displayName = 'ImageUpload';
|
503
|
+
|
504
|
+
export default ImageUpload;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { memo } from 'react';
|
2
|
+
|
3
|
+
import { useGenerationConfigParam } from '@/store/image/slices/generationConfig/hooks';
|
4
|
+
|
5
|
+
import ImageUpload from './ImageUpload';
|
6
|
+
|
7
|
+
const ImageUrl = memo(() => {
|
8
|
+
const { value: imageUrl, setValue } = useGenerationConfigParam('imageUrl');
|
9
|
+
|
10
|
+
// Extract the first URL from the array for single image display
|
11
|
+
const handleChange = (url?: string) => {
|
12
|
+
setValue(url ?? null);
|
13
|
+
};
|
14
|
+
|
15
|
+
return <ImageUpload onChange={handleChange} value={imageUrl} />;
|
16
|
+
});
|
17
|
+
|
18
|
+
export default ImageUrl;
|
package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/ImageUrlsUpload.tsx
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
import { memo } from 'react';
|
2
|
+
|
3
|
+
import { useGenerationConfigParam } from '@/store/image/slices/generationConfig/hooks';
|
4
|
+
|
5
|
+
import MultiImagesUpload from './MultiImagesUpload';
|
6
|
+
|
7
|
+
const ImageUrlsUpload = memo(() => {
|
8
|
+
const { value, setValue } = useGenerationConfigParam('imageUrls');
|
9
|
+
|
10
|
+
const handleChange = (urls: string[]) => {
|
11
|
+
// Directly set the URLs to the store
|
12
|
+
// The store will handle URL to path conversion when needed
|
13
|
+
setValue(urls);
|
14
|
+
};
|
15
|
+
|
16
|
+
return <MultiImagesUpload onChange={handleChange} value={value} />;
|
17
|
+
});
|
18
|
+
|
19
|
+
export default ImageUrlsUpload;
|
@@ -0,0 +1,155 @@
|
|
1
|
+
import { ActionIcon, Icon, Select, type SelectProps } from '@lobehub/ui';
|
2
|
+
import { createStyles, useTheme } from 'antd-style';
|
3
|
+
import { LucideArrowRight, LucideBolt } from 'lucide-react';
|
4
|
+
import Link from 'next/link';
|
5
|
+
import { useRouter } from 'next/navigation';
|
6
|
+
import { memo, useMemo } from 'react';
|
7
|
+
import { useTranslation } from 'react-i18next';
|
8
|
+
import { Flexbox } from 'react-layout-kit';
|
9
|
+
|
10
|
+
import { ModelItemRender, ProviderItemRender } from '@/components/ModelSelect';
|
11
|
+
import { isDeprecatedEdition } from '@/const/version';
|
12
|
+
import { useAiInfraStore } from '@/store/aiInfra';
|
13
|
+
import { aiProviderSelectors } from '@/store/aiInfra/slices/aiProvider/selectors';
|
14
|
+
import { useImageStore } from '@/store/image';
|
15
|
+
import { imageGenerationConfigSelectors } from '@/store/image/slices/generationConfig/selectors';
|
16
|
+
import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';
|
17
|
+
import { EnabledProviderWithModels } from '@/types/aiProvider';
|
18
|
+
|
19
|
+
const useStyles = createStyles(({ css, prefixCls }) => ({
|
20
|
+
popup: css`
|
21
|
+
&.${prefixCls}-select-dropdown .${prefixCls}-select-item-option-grouped {
|
22
|
+
padding-inline-start: 12px;
|
23
|
+
}
|
24
|
+
`,
|
25
|
+
}));
|
26
|
+
|
27
|
+
interface ModelOption {
|
28
|
+
label: any;
|
29
|
+
provider: string;
|
30
|
+
value: string;
|
31
|
+
}
|
32
|
+
|
33
|
+
const ModelSelect = memo(() => {
|
34
|
+
const { styles } = useStyles();
|
35
|
+
const { t } = useTranslation('components');
|
36
|
+
const theme = useTheme();
|
37
|
+
const { showLLM } = useServerConfigStore(featureFlagsSelectors);
|
38
|
+
const router = useRouter();
|
39
|
+
|
40
|
+
const [currentModel, currentProvider] = useImageStore((s) => [
|
41
|
+
imageGenerationConfigSelectors.model(s),
|
42
|
+
imageGenerationConfigSelectors.provider(s),
|
43
|
+
]);
|
44
|
+
const setModelAndProviderOnSelect = useImageStore((s) => s.setModelAndProviderOnSelect);
|
45
|
+
|
46
|
+
const enabledImageModelList = useAiInfraStore(aiProviderSelectors.enabledImageModelList);
|
47
|
+
|
48
|
+
const options = useMemo<SelectProps['options']>(() => {
|
49
|
+
const getImageModels = (provider: EnabledProviderWithModels) => {
|
50
|
+
const modelOptions = provider.children.map((model) => ({
|
51
|
+
label: <ModelItemRender {...model} {...model.abilities} showInfoTag={false} />,
|
52
|
+
provider: provider.id,
|
53
|
+
value: `${provider.id}/${model.id}`,
|
54
|
+
}));
|
55
|
+
|
56
|
+
// if there are no models, add a placeholder guide
|
57
|
+
if (modelOptions.length === 0) {
|
58
|
+
return [
|
59
|
+
{
|
60
|
+
disabled: true,
|
61
|
+
label: (
|
62
|
+
<Flexbox gap={8} horizontal style={{ color: theme.colorTextTertiary }}>
|
63
|
+
{t('ModelSwitchPanel.emptyModel')}
|
64
|
+
<Icon icon={LucideArrowRight} />
|
65
|
+
</Flexbox>
|
66
|
+
),
|
67
|
+
onClick: () => {
|
68
|
+
router.push(
|
69
|
+
isDeprecatedEdition ? '/settings/llm' : `/settings/provider/${provider.id}`,
|
70
|
+
);
|
71
|
+
},
|
72
|
+
value: `${provider.id}/empty`,
|
73
|
+
},
|
74
|
+
];
|
75
|
+
}
|
76
|
+
|
77
|
+
return modelOptions;
|
78
|
+
};
|
79
|
+
|
80
|
+
// if there are no providers at all
|
81
|
+
if (enabledImageModelList.length === 0) {
|
82
|
+
return [
|
83
|
+
{
|
84
|
+
disabled: true,
|
85
|
+
label: (
|
86
|
+
<Flexbox gap={8} horizontal style={{ color: theme.colorTextTertiary }}>
|
87
|
+
{t('ModelSwitchPanel.emptyProvider')}
|
88
|
+
<Icon icon={LucideArrowRight} />
|
89
|
+
</Flexbox>
|
90
|
+
),
|
91
|
+
onClick: () => {
|
92
|
+
router.push(isDeprecatedEdition ? '/settings/llm' : '/settings/provider');
|
93
|
+
},
|
94
|
+
value: 'no-provider',
|
95
|
+
},
|
96
|
+
];
|
97
|
+
}
|
98
|
+
|
99
|
+
if (enabledImageModelList.length === 1) {
|
100
|
+
const provider = enabledImageModelList[0];
|
101
|
+
return getImageModels(provider);
|
102
|
+
}
|
103
|
+
|
104
|
+
return enabledImageModelList.map((provider) => ({
|
105
|
+
label: (
|
106
|
+
<Flexbox horizontal justify="space-between">
|
107
|
+
<ProviderItemRender
|
108
|
+
logo={provider.logo}
|
109
|
+
name={provider.name}
|
110
|
+
provider={provider.id}
|
111
|
+
source={provider.source}
|
112
|
+
/>
|
113
|
+
{showLLM && (
|
114
|
+
<Link
|
115
|
+
href={isDeprecatedEdition ? '/settings/llm' : `/settings/provider/${provider.id}`}
|
116
|
+
>
|
117
|
+
<ActionIcon
|
118
|
+
icon={LucideBolt}
|
119
|
+
size={'small'}
|
120
|
+
title={t('ModelSwitchPanel.goToSettings')}
|
121
|
+
/>
|
122
|
+
</Link>
|
123
|
+
)}
|
124
|
+
</Flexbox>
|
125
|
+
),
|
126
|
+
options: getImageModels(provider),
|
127
|
+
}));
|
128
|
+
}, [enabledImageModelList, showLLM, t, theme.colorTextTertiary, router]);
|
129
|
+
|
130
|
+
return (
|
131
|
+
<Select
|
132
|
+
classNames={{
|
133
|
+
root: styles.popup,
|
134
|
+
}}
|
135
|
+
onChange={(value, option) => {
|
136
|
+
// Skip onChange for disabled options (empty states)
|
137
|
+
if (value === 'no-provider' || value.includes('/empty')) return;
|
138
|
+
const model = value.split('/').slice(1).join('/');
|
139
|
+
const provider = (option as unknown as ModelOption).provider;
|
140
|
+
if (model !== currentModel || provider !== currentProvider) {
|
141
|
+
setModelAndProviderOnSelect(model, provider);
|
142
|
+
}
|
143
|
+
}}
|
144
|
+
options={options}
|
145
|
+
shadow
|
146
|
+
size={'large'}
|
147
|
+
style={{
|
148
|
+
width: '100%',
|
149
|
+
}}
|
150
|
+
value={currentProvider && currentModel ? `${currentProvider}/${currentModel}` : undefined}
|
151
|
+
/>
|
152
|
+
);
|
153
|
+
});
|
154
|
+
|
155
|
+
export default ModelSelect;
|