@lobehub/chat 1.43.6 → 1.44.0

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.
Files changed (298) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/changelog/v1.json +9 -0
  3. package/docs/self-hosting/server-database/docker-compose.mdx +2 -2
  4. package/locales/ar/common.json +1 -0
  5. package/locales/ar/modelProvider.json +176 -0
  6. package/locales/ar/setting.json +1 -0
  7. package/locales/bg-BG/common.json +1 -0
  8. package/locales/bg-BG/modelProvider.json +176 -0
  9. package/locales/bg-BG/setting.json +1 -0
  10. package/locales/de-DE/common.json +1 -0
  11. package/locales/de-DE/modelProvider.json +176 -0
  12. package/locales/de-DE/setting.json +1 -0
  13. package/locales/en-US/common.json +1 -0
  14. package/locales/en-US/modelProvider.json +176 -0
  15. package/locales/en-US/setting.json +1 -0
  16. package/locales/es-ES/common.json +1 -0
  17. package/locales/es-ES/modelProvider.json +176 -0
  18. package/locales/es-ES/setting.json +1 -0
  19. package/locales/fa-IR/common.json +1 -0
  20. package/locales/fa-IR/modelProvider.json +176 -0
  21. package/locales/fa-IR/setting.json +1 -0
  22. package/locales/fr-FR/common.json +1 -0
  23. package/locales/fr-FR/modelProvider.json +176 -0
  24. package/locales/fr-FR/setting.json +1 -0
  25. package/locales/it-IT/common.json +1 -0
  26. package/locales/it-IT/modelProvider.json +176 -0
  27. package/locales/it-IT/setting.json +1 -0
  28. package/locales/ja-JP/common.json +1 -0
  29. package/locales/ja-JP/modelProvider.json +176 -0
  30. package/locales/ja-JP/setting.json +1 -0
  31. package/locales/ko-KR/common.json +1 -0
  32. package/locales/ko-KR/modelProvider.json +176 -0
  33. package/locales/ko-KR/setting.json +1 -0
  34. package/locales/nl-NL/common.json +1 -0
  35. package/locales/nl-NL/modelProvider.json +176 -0
  36. package/locales/nl-NL/setting.json +1 -0
  37. package/locales/pl-PL/common.json +1 -0
  38. package/locales/pl-PL/modelProvider.json +176 -0
  39. package/locales/pl-PL/setting.json +1 -0
  40. package/locales/pt-BR/common.json +1 -0
  41. package/locales/pt-BR/modelProvider.json +176 -0
  42. package/locales/pt-BR/setting.json +1 -0
  43. package/locales/ru-RU/common.json +1 -0
  44. package/locales/ru-RU/modelProvider.json +176 -0
  45. package/locales/ru-RU/setting.json +1 -0
  46. package/locales/tr-TR/common.json +1 -0
  47. package/locales/tr-TR/modelProvider.json +176 -0
  48. package/locales/tr-TR/setting.json +1 -0
  49. package/locales/vi-VN/common.json +1 -0
  50. package/locales/vi-VN/modelProvider.json +176 -0
  51. package/locales/vi-VN/setting.json +1 -0
  52. package/locales/zh-CN/common.json +1 -0
  53. package/locales/zh-CN/modelProvider.json +176 -0
  54. package/locales/zh-CN/setting.json +1 -0
  55. package/locales/zh-TW/common.json +1 -0
  56. package/locales/zh-TW/modelProvider.json +176 -0
  57. package/locales/zh-TW/setting.json +1 -0
  58. package/package.json +4 -4
  59. package/src/app/(main)/(mobile)/me/settings/features/Category.tsx +1 -1
  60. package/src/app/(main)/(mobile)/me/settings/features/useCategory.tsx +12 -5
  61. package/src/app/(main)/changelog/features/VersionTag.tsx +1 -2
  62. package/src/app/(main)/chat/(workspace)/@conversation/features/ChatList/ChatItem/Thread.tsx +1 -1
  63. package/src/app/(main)/chat/(workspace)/@conversation/features/ChatList/ChatItem/ThreadItem.tsx +1 -2
  64. package/src/app/(main)/chat/(workspace)/@conversation/features/ChatList/ChatItem/index.tsx +0 -1
  65. package/src/app/(main)/chat/(workspace)/@conversation/features/ChatList/WelcomeChatItem/InboxWelcome/AgentsSuggest.tsx +1 -1
  66. package/src/app/(main)/chat/(workspace)/@conversation/features/ChatList/WelcomeChatItem/InboxWelcome/QuestionSuggest.tsx +1 -1
  67. package/src/app/(main)/chat/(workspace)/@conversation/features/ZenModeToast/Toast.tsx +1 -1
  68. package/src/app/(main)/chat/(workspace)/@topic/features/TopicListContent/ThreadItem/index.tsx +0 -2
  69. package/src/app/(main)/chat/(workspace)/@topic/features/TopicListContent/TopicItem/index.tsx +0 -1
  70. package/src/app/(main)/chat/(workspace)/_layout/Desktop/ChatHeader/Tags.tsx +2 -3
  71. package/src/app/(main)/chat/@session/features/SessionListContent/CollapseGroup/index.tsx +1 -1
  72. package/src/app/(main)/chat/features/Migration/Start.tsx +1 -1
  73. package/src/app/(main)/discover/(detail)/assistant/[slug]/features/ConversationExample/TopicList.tsx +4 -3
  74. package/src/app/(main)/discover/(detail)/assistant/[slug]/features/Header.tsx +1 -1
  75. package/src/app/(main)/discover/(detail)/features/ShareButton.tsx +2 -1
  76. package/src/app/(main)/discover/(detail)/model/[...slugs]/features/Header.tsx +1 -1
  77. package/src/app/(main)/discover/(detail)/plugin/[slug]/features/Header.tsx +1 -1
  78. package/src/app/(main)/discover/(detail)/provider/[slug]/features/Header.tsx +1 -1
  79. package/src/app/(main)/discover/(list)/_layout/Desktop/Nav.tsx +0 -1
  80. package/src/app/(main)/discover/(list)/assistants/features/Card.tsx +1 -1
  81. package/src/app/(main)/discover/(list)/models/features/Card.tsx +1 -1
  82. package/src/app/(main)/discover/(list)/plugins/features/Card.tsx +1 -1
  83. package/src/app/(main)/discover/(list)/providers/features/Card.tsx +1 -1
  84. package/src/app/(main)/discover/components/GridLoadingCard.tsx +2 -1
  85. package/src/app/(main)/discover/components/Title.tsx +1 -1
  86. package/src/app/(main)/files/(content)/@menu/features/KnowledgeBase/EmptyStatus.tsx +1 -1
  87. package/src/app/(main)/files/(content)/@menu/features/KnowledgeBase/Item/index.tsx +0 -1
  88. package/src/app/(main)/files/(content)/@modal/(.)[id]/FullscreenModal.tsx +2 -2
  89. package/src/app/(main)/files/(content)/NotSupportClient.tsx +2 -2
  90. package/src/app/(main)/profile/_layout/Desktop/SideBar.tsx +1 -1
  91. package/src/app/(main)/profile/stats/features/ShareButton/Preview.tsx +5 -5
  92. package/src/app/(main)/repos/[id]/evals/components/Container.tsx +1 -1
  93. package/src/app/(main)/repos/[id]/evals/dataset/DatasetList/Item.tsx +0 -1
  94. package/src/app/(main)/settings/_layout/Desktop/SideBar.tsx +1 -1
  95. package/src/app/(main)/settings/about/features/ItemCard.tsx +3 -3
  96. package/src/app/(main)/settings/about/features/Version.tsx +1 -1
  97. package/src/app/(main)/settings/hooks/useCategory.tsx +22 -9
  98. package/src/app/(main)/settings/llm/components/ProviderConfig/index.tsx +2 -1
  99. package/src/app/(main)/settings/llm/components/ProviderModelList/ModelFetcher.tsx +0 -1
  100. package/src/app/(main)/settings/provider/(detail)/[id]/index.tsx +19 -0
  101. package/src/app/(main)/settings/provider/(detail)/[id]/page.tsx +95 -0
  102. package/src/app/(main)/settings/provider/(detail)/azure/page.tsx +119 -0
  103. package/src/app/(main)/settings/provider/(detail)/bedrock/page.tsx +91 -0
  104. package/src/app/(main)/settings/provider/(detail)/cloudflare/page.tsx +58 -0
  105. package/src/app/(main)/settings/provider/(detail)/github/page.tsx +67 -0
  106. package/src/app/(main)/settings/provider/(detail)/huggingface/page.tsx +67 -0
  107. package/src/app/(main)/settings/provider/(detail)/ollama/Checker.tsx +73 -0
  108. package/src/app/(main)/settings/provider/(detail)/ollama/page.tsx +34 -0
  109. package/src/app/(main)/settings/provider/(detail)/openai/page.tsx +23 -0
  110. package/src/app/(main)/settings/provider/(detail)/wenxin/page.tsx +61 -0
  111. package/src/app/(main)/settings/provider/(list)/Footer.tsx +36 -0
  112. package/src/app/(main)/settings/provider/(list)/ProviderGrid/Card.tsx +134 -0
  113. package/src/app/(main)/settings/provider/(list)/ProviderGrid/index.tsx +91 -0
  114. package/src/app/(main)/settings/provider/(list)/index.tsx +19 -0
  115. package/src/app/(main)/settings/provider/ProviderMenu/AddNew.tsx +28 -0
  116. package/src/app/(main)/settings/provider/ProviderMenu/All.tsx +29 -0
  117. package/src/app/(main)/settings/provider/ProviderMenu/Item.tsx +69 -0
  118. package/src/app/(main)/settings/provider/ProviderMenu/List.tsx +76 -0
  119. package/src/app/(main)/settings/provider/ProviderMenu/SearchResult.tsx +43 -0
  120. package/src/app/(main)/settings/provider/ProviderMenu/SkeletonList.tsx +60 -0
  121. package/src/app/(main)/settings/provider/ProviderMenu/SortProviderModal/GroupItem.tsx +30 -0
  122. package/src/app/(main)/settings/provider/ProviderMenu/SortProviderModal/index.tsx +91 -0
  123. package/src/app/(main)/settings/provider/ProviderMenu/index.tsx +80 -0
  124. package/src/app/(main)/settings/provider/_layout/Desktop.tsx +37 -0
  125. package/src/app/(main)/settings/provider/_layout/Mobile.tsx +14 -0
  126. package/src/app/(main)/settings/provider/const.ts +20 -0
  127. package/src/app/(main)/settings/provider/features/CreateNewProvider/index.tsx +146 -0
  128. package/src/app/(main)/settings/provider/features/ModelList/CreateNewModelModal/Form.tsx +105 -0
  129. package/src/app/(main)/settings/provider/features/ModelList/CreateNewModelModal/index.tsx +69 -0
  130. package/src/app/(main)/settings/provider/features/ModelList/DisabledModels.tsx +29 -0
  131. package/src/app/(main)/settings/provider/features/ModelList/EmptyModels.tsx +101 -0
  132. package/src/app/(main)/settings/provider/features/ModelList/EnabledModelList/index.tsx +85 -0
  133. package/src/app/(main)/settings/provider/features/ModelList/ModelConfigModal/Form.tsx +109 -0
  134. package/src/app/(main)/settings/provider/features/ModelList/ModelConfigModal/index.tsx +76 -0
  135. package/src/app/(main)/settings/provider/features/ModelList/ModelItem.tsx +346 -0
  136. package/src/app/(main)/settings/provider/features/ModelList/ModelTitle/Search.tsx +37 -0
  137. package/src/app/(main)/settings/provider/features/ModelList/ModelTitle/index.tsx +145 -0
  138. package/src/app/(main)/settings/provider/features/ModelList/SearchResult.tsx +67 -0
  139. package/src/app/(main)/settings/provider/features/ModelList/SkeletonList.tsx +63 -0
  140. package/src/app/(main)/settings/provider/features/ModelList/SortModelModal/ListItem.tsx +20 -0
  141. package/src/app/(main)/settings/provider/features/ModelList/SortModelModal/index.tsx +96 -0
  142. package/src/app/(main)/settings/provider/features/ModelList/index.tsx +59 -0
  143. package/src/app/(main)/settings/provider/features/ProviderConfig/Checker.tsx +120 -0
  144. package/src/app/(main)/settings/provider/features/ProviderConfig/SkeletonInput.tsx +5 -0
  145. package/src/app/(main)/settings/provider/features/ProviderConfig/UpdateProviderInfo/SettingModal.tsx +137 -0
  146. package/src/app/(main)/settings/provider/features/ProviderConfig/UpdateProviderInfo/index.tsx +49 -0
  147. package/src/app/(main)/settings/provider/features/ProviderConfig/index.tsx +343 -0
  148. package/src/app/(main)/settings/provider/layout.tsx +21 -0
  149. package/src/app/(main)/settings/provider/page.tsx +17 -0
  150. package/src/app/(main)/settings/provider/type.ts +5 -0
  151. package/src/app/(main)/settings/sync/features/DeviceInfo/Card.tsx +1 -1
  152. package/src/app/(main)/settings/sync/features/DeviceInfo/index.tsx +1 -1
  153. package/src/app/@modal/(.)changelog/modal/features/ReadDetail.tsx +1 -1
  154. package/src/app/@modal/(.)changelog/modal/features/VersionTag.tsx +1 -2
  155. package/src/app/@modal/(.)changelog/modal/layout.tsx +1 -1
  156. package/src/components/Cell/index.tsx +1 -1
  157. package/src/components/DragUpload/index.tsx +2 -3
  158. package/src/components/FeatureList/index.tsx +1 -1
  159. package/src/components/FileParsingStatus/EmbeddingStatus.tsx +1 -1
  160. package/src/components/FileParsingStatus/index.tsx +1 -1
  161. package/src/components/FunctionModal/style.tsx +2 -2
  162. package/src/components/GoBack/index.tsx +1 -2
  163. package/src/components/HotKeys/index.tsx +1 -1
  164. package/src/components/InstantSwitch/index.tsx +28 -0
  165. package/src/components/Menu/index.tsx +1 -1
  166. package/src/components/ModelSelect/index.tsx +2 -3
  167. package/src/components/Notification/index.tsx +2 -1
  168. package/src/components/StatisticCard/index.tsx +5 -6
  169. package/src/config/aiModels/ai21.ts +38 -0
  170. package/src/config/aiModels/ai360.ts +71 -0
  171. package/src/config/aiModels/anthropic.ts +152 -0
  172. package/src/config/aiModels/azure.ts +86 -0
  173. package/src/config/aiModels/baichuan.ts +107 -0
  174. package/src/config/aiModels/bedrock.ts +315 -0
  175. package/src/config/aiModels/cloudflare.ts +88 -0
  176. package/src/config/aiModels/deepseek.ts +27 -0
  177. package/src/config/aiModels/fireworksai.ts +232 -0
  178. package/src/config/aiModels/giteeai.ts +137 -0
  179. package/src/config/aiModels/github.ts +273 -0
  180. package/src/config/aiModels/google.ts +317 -0
  181. package/src/config/aiModels/groq.ts +202 -0
  182. package/src/config/aiModels/higress.ts +2828 -0
  183. package/src/config/aiModels/huggingface.ts +56 -0
  184. package/src/config/aiModels/hunyuan.ts +151 -0
  185. package/src/config/aiModels/index.ts +98 -0
  186. package/src/config/aiModels/internlm.ts +40 -0
  187. package/src/config/aiModels/minimax.ts +55 -0
  188. package/src/config/aiModels/mistral.ts +172 -0
  189. package/src/config/aiModels/moonshot.ts +44 -0
  190. package/src/config/aiModels/novita.ts +124 -0
  191. package/src/config/aiModels/ollama.ts +412 -0
  192. package/src/config/aiModels/openai.ts +537 -0
  193. package/src/config/aiModels/openrouter.ts +252 -0
  194. package/src/config/aiModels/perplexity.ts +67 -0
  195. package/src/config/aiModels/qwen.ts +302 -0
  196. package/src/config/aiModels/sensenova.ts +114 -0
  197. package/src/config/aiModels/siliconcloud.ts +679 -0
  198. package/src/config/aiModels/spark.ts +68 -0
  199. package/src/config/aiModels/stepfun.ts +153 -0
  200. package/src/config/aiModels/taichu.ts +19 -0
  201. package/src/config/aiModels/togetherai.ts +334 -0
  202. package/src/config/aiModels/upstage.ts +37 -0
  203. package/src/config/aiModels/wenxin.ts +171 -0
  204. package/src/config/aiModels/xai.ts +72 -0
  205. package/src/config/aiModels/zeroone.ts +156 -0
  206. package/src/config/aiModels/zhipu.ts +235 -0
  207. package/src/config/featureFlags/schema.ts +3 -0
  208. package/src/config/modelProviders/anthropic.ts +1 -0
  209. package/src/config/modelProviders/github.ts +0 -1
  210. package/src/config/modelProviders/google.ts +1 -0
  211. package/src/config/modelProviders/stepfun.ts +2 -0
  212. package/src/database/migrations/0013_add_ai_infra.sql +44 -0
  213. package/src/database/migrations/meta/0013_snapshot.json +3598 -0
  214. package/src/database/migrations/meta/_journal.json +7 -0
  215. package/src/database/repositories/aiInfra/index.ts +115 -0
  216. package/src/database/schemas/aiInfra.ts +69 -0
  217. package/src/database/schemas/index.ts +1 -0
  218. package/src/database/server/models/__tests__/aiModel.test.ts +318 -0
  219. package/src/database/server/models/__tests__/aiProvider.test.ts +373 -0
  220. package/src/database/server/models/aiModel.ts +250 -0
  221. package/src/database/server/models/aiProvider.ts +234 -0
  222. package/src/features/AgentSetting/AgentPrompt/index.tsx +2 -2
  223. package/src/features/ChatInput/ActionBar/Token/TokenTag.tsx +2 -1
  224. package/src/features/ChatInput/ActionBar/Tools/index.tsx +2 -3
  225. package/src/features/ChatInput/ActionBar/Upload/ServerMode.tsx +2 -3
  226. package/src/features/ChatInput/Desktop/FilePreview/FileItem/index.tsx +3 -2
  227. package/src/features/ChatInput/Desktop/FilePreview/FileList.tsx +2 -2
  228. package/src/features/ChatInput/Mobile/Files/FileItem/File.tsx +2 -2
  229. package/src/features/ChatInput/Mobile/InputArea/index.tsx +1 -1
  230. package/src/features/ChatInput/STT/common.tsx +1 -1
  231. package/src/features/Conversation/Error/style.tsx +2 -2
  232. package/src/features/Conversation/Messages/Assistant/FileChunks/Item/style.ts +2 -2
  233. package/src/features/Conversation/Messages/Assistant/FileChunks/index.tsx +1 -1
  234. package/src/features/Conversation/Messages/Assistant/ToolCallItem/Inspector/style.ts +2 -3
  235. package/src/features/Conversation/Messages/Assistant/ToolCallItem/style.ts +2 -3
  236. package/src/features/Conversation/Messages/User/FileListViewer/Item.tsx +0 -1
  237. package/src/features/Conversation/components/BackBottom/style.ts +2 -2
  238. package/src/features/Conversation/components/MarkdownElements/LobeArtifact/Render/Icon.tsx +2 -3
  239. package/src/features/Conversation/components/MarkdownElements/LobeArtifact/Render/index.tsx +3 -3
  240. package/src/features/Conversation/components/MarkdownElements/LobeThinking/Render.tsx +1 -1
  241. package/src/features/Conversation/components/OTPInput.tsx +2 -2
  242. package/src/features/DataImporter/Loading.tsx +1 -1
  243. package/src/features/FileManager/FileList/EmptyStatus.tsx +1 -1
  244. package/src/features/FileManager/FileList/index.tsx +1 -1
  245. package/src/features/FileManager/UploadDock/Item.tsx +1 -1
  246. package/src/features/FileManager/UploadDock/index.tsx +4 -4
  247. package/src/features/FileViewer/NotSupport/index.tsx +1 -1
  248. package/src/features/FileViewer/Renderer/MSDoc/index.tsx +0 -1
  249. package/src/features/FileViewer/Renderer/TXT/index.tsx +1 -1
  250. package/src/features/InitClientDB/EnableModal.tsx +1 -1
  251. package/src/features/InitClientDB/ErrorResult.tsx +1 -1
  252. package/src/features/InitClientDB/InitIndicator.tsx +1 -1
  253. package/src/features/KnowledgeBaseModal/AddFilesToKnowledgeBase/SelectForm.tsx +0 -1
  254. package/src/features/ModelSwitchPanel/index.tsx +2 -2
  255. package/src/features/PluginsUI/Render/Loading.tsx +0 -1
  256. package/src/features/Portal/Home/Body/Files/FileList/Item.tsx +1 -1
  257. package/src/features/Portal/Home/Body/Plugins/ArtifactList/Item/style.ts +1 -2
  258. package/src/features/Setting/SettingContainer.tsx +8 -1
  259. package/src/features/ShareModal/ShareImage/style.ts +2 -2
  260. package/src/features/ShareModal/style.ts +2 -2
  261. package/src/features/User/DataStatistics.tsx +1 -1
  262. package/src/hooks/useEnabledChatModels.ts +10 -1
  263. package/src/hooks/useModelSupportToolUse.ts +15 -0
  264. package/src/hooks/useModelSupportVision.ts +15 -0
  265. package/src/layout/AuthProvider/Clerk/useAppearance.ts +3 -3
  266. package/src/layout/GlobalProvider/AppTheme.tsx +1 -1
  267. package/src/layout/GlobalProvider/StoreInitialization.tsx +5 -0
  268. package/src/locales/default/common.ts +1 -0
  269. package/src/locales/default/modelProvider.ts +178 -0
  270. package/src/locales/default/setting.ts +1 -0
  271. package/src/server/modules/KeyVaultsEncrypt/index.ts +1 -1
  272. package/src/server/routers/lambda/aiModel.ts +128 -0
  273. package/src/server/routers/lambda/aiProvider.ts +127 -0
  274. package/src/server/routers/lambda/index.ts +4 -0
  275. package/src/services/__tests__/_auth.test.ts +16 -49
  276. package/src/services/__tests__/chat.test.ts +2 -0
  277. package/src/services/_auth.ts +42 -25
  278. package/src/services/aiModel.ts +52 -0
  279. package/src/services/aiProvider.ts +47 -0
  280. package/src/services/chat.ts +62 -18
  281. package/src/store/aiInfra/index.ts +2 -0
  282. package/src/store/aiInfra/initialState.ts +11 -0
  283. package/src/store/aiInfra/selectors.ts +2 -0
  284. package/src/store/aiInfra/slices/aiModel/action.ts +146 -0
  285. package/src/store/aiInfra/slices/aiModel/index.ts +3 -0
  286. package/src/store/aiInfra/slices/aiModel/initialState.ts +14 -0
  287. package/src/store/aiInfra/slices/aiModel/selectors.ts +63 -0
  288. package/src/store/aiInfra/slices/aiProvider/action.ts +208 -0
  289. package/src/store/aiInfra/slices/aiProvider/index.ts +3 -0
  290. package/src/store/aiInfra/slices/aiProvider/initialState.ts +32 -0
  291. package/src/store/aiInfra/slices/aiProvider/selectors.ts +99 -0
  292. package/src/store/aiInfra/store.ts +25 -0
  293. package/src/store/global/initialState.ts +1 -0
  294. package/src/store/serverConfig/selectors.test.ts +1 -0
  295. package/src/styles/global.ts +1 -1
  296. package/src/types/aiModel.ts +32 -6
  297. package/src/types/aiProvider.ts +11 -4
  298. package/src/utils/fetch/fetchSSE.ts +3 -1
@@ -0,0 +1,343 @@
1
+ 'use client';
2
+
3
+ import { ProviderCombine } from '@lobehub/icons';
4
+ import { Avatar, Form, type FormItemProps, Icon, type ItemGroup, Tooltip } from '@lobehub/ui';
5
+ import { useDebounceFn } from 'ahooks';
6
+ import { Input, Skeleton, Switch } from 'antd';
7
+ import { createStyles } from 'antd-style';
8
+ import { LockIcon } from 'lucide-react';
9
+ import Link from 'next/link';
10
+ import { ReactNode, memo, useLayoutEffect } from 'react';
11
+ import { Trans, useTranslation } from 'react-i18next';
12
+ import { Center, Flexbox } from 'react-layout-kit';
13
+ import urlJoin from 'url-join';
14
+
15
+ import InstantSwitch from '@/components/InstantSwitch';
16
+ import { FORM_STYLE } from '@/const/layoutTokens';
17
+ import { AES_GCM_URL, BASE_PROVIDER_DOC_URL } from '@/const/url';
18
+ import { isServerMode } from '@/const/version';
19
+ import { aiProviderSelectors, useAiInfraStore } from '@/store/aiInfra';
20
+ import {
21
+ AiProviderDetailItem,
22
+ AiProviderSourceEnum,
23
+ AiProviderSourceType,
24
+ } from '@/types/aiProvider';
25
+
26
+ import { KeyVaultsConfigKey, LLMProviderApiTokenKey, LLMProviderBaseUrlKey } from '../../const';
27
+ import Checker from './Checker';
28
+ import { SkeletonInput } from './SkeletonInput';
29
+ import UpdateProviderInfo from './UpdateProviderInfo';
30
+
31
+ const useStyles = createStyles(({ css, prefixCls, responsive, token }) => ({
32
+ aceGcm: css`
33
+ padding-block: 0 !important;
34
+ .${prefixCls}-form-item-label {
35
+ display: none;
36
+ }
37
+ .${prefixCls}-form-item-control {
38
+ width: 100%;
39
+
40
+ font-size: 12px;
41
+ color: ${token.colorTextSecondary};
42
+ text-align: center;
43
+
44
+ opacity: 0.66;
45
+
46
+ transition: opacity 0.2s ${token.motionEaseInOut};
47
+
48
+ &:hover {
49
+ opacity: 1;
50
+ }
51
+ }
52
+ `,
53
+ form: css`
54
+ .${prefixCls}-form-item-control:has(.${prefixCls}-input,.${prefixCls}-select) {
55
+ flex: none;
56
+ width: min(70%, 800px);
57
+ min-width: min(70%, 800px) !important;
58
+ }
59
+ ${responsive.mobile} {
60
+ width: 100%;
61
+ min-width: unset !important;
62
+ }
63
+ .${prefixCls}-select-selection-overflow-item {
64
+ font-size: 12px;
65
+ }
66
+ `,
67
+ help: css`
68
+ border-radius: 50%;
69
+
70
+ font-size: 12px;
71
+ font-weight: 500;
72
+ color: ${token.colorTextDescription};
73
+
74
+ background: ${token.colorFillTertiary};
75
+
76
+ &:hover {
77
+ color: ${token.colorText};
78
+ background: ${token.colorFill};
79
+ }
80
+ `,
81
+ switchLoading: css`
82
+ width: 44px !important;
83
+ min-width: 44px !important;
84
+ height: 22px !important;
85
+ border-radius: 12px !important;
86
+ `,
87
+ }));
88
+
89
+ export interface ProviderConfigProps extends Omit<AiProviderDetailItem, 'enabled' | 'source'> {
90
+ apiKeyItems?: FormItemProps[];
91
+ canDeactivate?: boolean;
92
+ checkerItem?: FormItemProps;
93
+ className?: string;
94
+ enabled?: boolean;
95
+ extra?: ReactNode;
96
+ hideSwitch?: boolean;
97
+ modelList?: {
98
+ azureDeployName?: boolean;
99
+ notFoundContent?: ReactNode;
100
+ placeholder?: string;
101
+ showModelFetcher?: boolean;
102
+ };
103
+ showAceGcm?: boolean;
104
+ source?: AiProviderSourceType;
105
+ title?: ReactNode;
106
+ }
107
+
108
+ const ProviderConfig = memo<ProviderConfigProps>(
109
+ ({
110
+ apiKeyItems,
111
+ id,
112
+ settings,
113
+ checkModel,
114
+ checkerItem,
115
+ logo,
116
+ className,
117
+ name,
118
+ showAceGcm = true,
119
+ extra,
120
+ source = AiProviderSourceEnum.Builtin,
121
+ }) => {
122
+ const {
123
+ proxyUrl,
124
+ showApiKey = true,
125
+ defaultShowBrowserRequest,
126
+ disableBrowserRequest,
127
+ showChecker = true,
128
+ } = settings;
129
+ const { t } = useTranslation('modelProvider');
130
+ const [form] = Form.useForm();
131
+ const { cx, styles } = useStyles();
132
+
133
+ const [
134
+ toggleProviderEnabled,
135
+ useFetchAiProviderItem,
136
+ updateAiProviderConfig,
137
+ enabled,
138
+ isLoading,
139
+ isFetchOnClient,
140
+ isProviderEndpointNotEmpty,
141
+ isProviderApiKeyNotEmpty,
142
+ ] = useAiInfraStore((s) => [
143
+ s.toggleProviderEnabled,
144
+ s.useFetchAiProviderItem,
145
+ s.updateAiProviderConfig,
146
+ aiProviderSelectors.isProviderEnabled(id)(s),
147
+ aiProviderSelectors.isAiProviderConfigLoading(id)(s),
148
+ aiProviderSelectors.isProviderFetchOnClient(id)(s),
149
+ aiProviderSelectors.isActiveProviderEndpointNotEmpty(s),
150
+ aiProviderSelectors.isActiveProviderApiKeyNotEmpty(s),
151
+ ]);
152
+
153
+ const { data } = useFetchAiProviderItem(id);
154
+
155
+ useLayoutEffect(() => {
156
+ if (isLoading) return;
157
+
158
+ // set the first time
159
+ form.setFieldsValue(data);
160
+ }, [isLoading, id, data]);
161
+
162
+ const { run: debouncedUpdate } = useDebounceFn(updateAiProviderConfig, { wait: 500 });
163
+
164
+ const isCustom = source === AiProviderSourceEnum.Custom;
165
+
166
+ const apiKeyItem: FormItemProps[] = !showApiKey
167
+ ? []
168
+ : (apiKeyItems ?? [
169
+ {
170
+ children: isLoading ? (
171
+ <SkeletonInput />
172
+ ) : (
173
+ <Input.Password
174
+ autoComplete={'new-password'}
175
+ placeholder={t(`providerModels.config.apiKey.placeholder`, { name })}
176
+ />
177
+ ),
178
+ desc: t(`providerModels.config.apiKey.desc`, { name }),
179
+ label: t(`providerModels.config.apiKey.title`),
180
+ name: [KeyVaultsConfigKey, LLMProviderApiTokenKey],
181
+ },
182
+ ]);
183
+
184
+ const aceGcmItem: FormItemProps = {
185
+ children: (
186
+ <>
187
+ <Icon icon={LockIcon} style={{ marginRight: 4 }} />
188
+ <Trans i18nKey="providerModels.config.aesGcm" ns={'modelProvider'}>
189
+ 您的秘钥与代理地址等将使用
190
+ <Link href={AES_GCM_URL} style={{ marginInline: 4 }} target={'_blank'}>
191
+ AES-GCM
192
+ </Link>
193
+ 加密算法进行加密
194
+ </Trans>
195
+ </>
196
+ ),
197
+ className: styles.aceGcm,
198
+ minWidth: undefined,
199
+ };
200
+
201
+ const showEndpoint = !!proxyUrl || isCustom;
202
+
203
+ const endpointItem = showEndpoint
204
+ ? {
205
+ children: isLoading ? (
206
+ <SkeletonInput />
207
+ ) : (
208
+ <Input
209
+ allowClear
210
+ placeholder={
211
+ (!!proxyUrl && proxyUrl?.placeholder) ||
212
+ t('providerModels.config.baseURL.placeholder')
213
+ }
214
+ />
215
+ ),
216
+ desc: (!!proxyUrl && proxyUrl?.desc) || t('providerModels.config.baseURL.desc'),
217
+ label: (!!proxyUrl && proxyUrl?.title) || t('providerModels.config.baseURL.title'),
218
+ name: [KeyVaultsConfigKey, LLMProviderBaseUrlKey],
219
+ }
220
+ : undefined;
221
+
222
+ /*
223
+ * Conditions to show Client Fetch Switch
224
+ * 1. provider is not disabled browser request
225
+ * 2. provider show browser request by default
226
+ * 3. Provider allow to edit endpoint and the value of endpoint is not empty
227
+ * 4. There is an apikey provided by user
228
+ */
229
+ const showClientFetch =
230
+ !disableBrowserRequest &&
231
+ (defaultShowBrowserRequest ||
232
+ (showEndpoint && isProviderEndpointNotEmpty) ||
233
+ (showApiKey && isProviderApiKeyNotEmpty));
234
+ const clientFetchItem = showClientFetch && {
235
+ children: isLoading ? (
236
+ <Skeleton.Button active className={styles.switchLoading} />
237
+ ) : (
238
+ <Switch disabled={isLoading} value={isFetchOnClient} />
239
+ ),
240
+ desc: t('providerModels.config.fetchOnClient.desc'),
241
+ label: t('providerModels.config.fetchOnClient.title'),
242
+ minWidth: undefined,
243
+ name: 'fetchOnClient',
244
+ };
245
+
246
+ const configItems = [
247
+ ...apiKeyItem,
248
+ endpointItem,
249
+ clientFetchItem,
250
+ showChecker
251
+ ? (checkerItem ?? {
252
+ children: isLoading ? (
253
+ <Skeleton.Button active />
254
+ ) : (
255
+ <Checker model={checkModel!} provider={id} />
256
+ ),
257
+ desc: t('providerModels.config.checker.desc'),
258
+ label: t('providerModels.config.checker.title'),
259
+ minWidth: undefined,
260
+ })
261
+ : undefined,
262
+ showAceGcm && isServerMode && aceGcmItem,
263
+ ].filter(Boolean) as FormItemProps[];
264
+
265
+ const logoUrl = data?.logo ?? logo;
266
+ const model: ItemGroup = {
267
+ children: configItems,
268
+
269
+ defaultActive: true,
270
+
271
+ extra: (
272
+ <Flexbox align={'center'} gap={8} horizontal>
273
+ {extra}
274
+
275
+ {isCustom && <UpdateProviderInfo />}
276
+ {isLoading ? (
277
+ <Skeleton.Button active className={styles.switchLoading} />
278
+ ) : (
279
+ <InstantSwitch
280
+ enabled={enabled}
281
+ onChange={async (enabled) => {
282
+ await toggleProviderEnabled(id as any, enabled);
283
+ }}
284
+ />
285
+ )}
286
+ </Flexbox>
287
+ ),
288
+ title: (
289
+ <Flexbox
290
+ align={'center'}
291
+ gap={4}
292
+ horizontal
293
+ style={{
294
+ height: 24,
295
+ maxHeight: 24,
296
+ ...(enabled ? {} : { filter: 'grayscale(100%)', maxHeight: 24, opacity: 0.66 }),
297
+ }}
298
+ >
299
+ {isCustom ? (
300
+ <Flexbox align={'center'} gap={8} horizontal>
301
+ {logoUrl ? (
302
+ <Avatar avatar={logoUrl} shape={'circle'} size={32} title={name || id} />
303
+ ) : (
304
+ <ProviderCombine provider={'not-exist-provider'} size={24} />
305
+ )}
306
+ {name}
307
+ </Flexbox>
308
+ ) : (
309
+ <ProviderCombine provider={id} size={24} />
310
+ )}
311
+ <Tooltip title={t('providerModels.config.helpDoc')}>
312
+ <Link
313
+ href={urlJoin(BASE_PROVIDER_DOC_URL, id)}
314
+ onClick={(e) => e.stopPropagation()}
315
+ target={'_blank'}
316
+ >
317
+ <Center className={styles.help} height={20} width={20}>
318
+ ?
319
+ </Center>
320
+ </Link>
321
+ </Tooltip>
322
+ </Flexbox>
323
+ ),
324
+ };
325
+
326
+ return (
327
+ <Form
328
+ className={cx(styles.form, className)}
329
+ form={form}
330
+ items={[model]}
331
+ onValuesChange={(_, values) => {
332
+ debouncedUpdate(id, values);
333
+ }}
334
+ variant={'pure'}
335
+ {...FORM_STYLE}
336
+ />
337
+ );
338
+ },
339
+ );
340
+
341
+ export default ProviderConfig;
342
+
343
+ export { SkeletonInput } from './SkeletonInput';
@@ -0,0 +1,21 @@
1
+ import { notFound } from 'next/navigation';
2
+ import { PropsWithChildren } from 'react';
3
+
4
+ import ServerLayout from '@/components/server/ServerLayout';
5
+ import { serverFeatureFlags } from '@/config/featureFlags';
6
+
7
+ import Desktop from './_layout/Desktop';
8
+ import Mobile from './_layout/Mobile';
9
+
10
+ const Layout = ServerLayout({ Desktop, Mobile });
11
+
12
+ const ProviderSettingsLayout = ({ children }: PropsWithChildren) => {
13
+ const showLLM = serverFeatureFlags().showProvider;
14
+ if (!showLLM) return notFound();
15
+
16
+ return <Layout>{children}</Layout>;
17
+ };
18
+
19
+ ProviderSettingsLayout.displayName = 'ProviderSettingsLayout';
20
+
21
+ export default ProviderSettingsLayout;
@@ -0,0 +1,17 @@
1
+ import { metadataModule } from '@/server/metadata';
2
+ import { translation } from '@/server/translation';
3
+
4
+ import Page from './(list)';
5
+
6
+ export const generateMetadata = async () => {
7
+ const { t } = await translation('setting');
8
+ return metadataModule.generate({
9
+ description: t('header.desc'),
10
+ title: t('tab.provider'),
11
+ url: '/settings/provider',
12
+ });
13
+ };
14
+
15
+ export default () => {
16
+ return <Page />;
17
+ };
@@ -0,0 +1,5 @@
1
+ import { ProviderConfigProps } from './features/ProviderConfig';
2
+
3
+ export interface ProviderItem extends Omit<ProviderConfigProps, 'id' | 'source'> {
4
+ id: string;
5
+ }
@@ -4,8 +4,8 @@ import { Center, Flexbox } from 'react-layout-kit';
4
4
 
5
5
  const useStyles = createStyles(({ css, token, responsive }) => ({
6
6
  container: css`
7
- background: ${token.colorFillTertiary};
8
7
  border-radius: ${token.borderRadius}px;
8
+ background: ${token.colorFillTertiary};
9
9
 
10
10
  .${responsive.mobile} {
11
11
  width: 100%;
@@ -23,8 +23,8 @@ const useStyles = createStyles(({ css, cx, responsive, isDarkMode, token, stylis
23
23
  content: css`
24
24
  z-index: 2;
25
25
  padding: 8px;
26
- background: ${rgba(token.colorBgContainer, isDarkMode ? 0.7 : 1)};
27
26
  border-radius: ${token.borderRadiusLG - 1}px;
27
+ background: ${rgba(token.colorBgContainer, isDarkMode ? 0.7 : 1)};
28
28
  `,
29
29
  glow: cx(
30
30
  stylish.gradientAnimation,
@@ -19,9 +19,9 @@ const useStyles = createStyles(
19
19
 
20
20
  margin-block: 16px 32px;
21
21
  padding: 16px;
22
+ border-radius: ${token.borderRadiusLG}px;
22
23
 
23
24
  background: ${token.colorFillTertiary};
24
- border-radius: ${token.borderRadiusLG}px;
25
25
  `,
26
26
  );
27
27
 
@@ -10,10 +10,9 @@ const useStyles = createStyles(({ token, css }) => {
10
10
  margin: 0;
11
11
  padding-block: 4px;
12
12
  padding-inline: 12px;
13
+ border-radius: 16px;
13
14
 
14
15
  color: ${token.colorTextSecondary};
15
-
16
- border-radius: 16px;
17
16
  `,
18
17
  };
19
18
  });
@@ -11,8 +11,8 @@ import Pagination from './features/Pagination';
11
11
  const useStyles = createStyles(
12
12
  ({ css, prefixCls, token }) => css`
13
13
  .${prefixCls}-modal-close {
14
- background: ${token.colorBgElevated} !important;
15
14
  border: 1px solid ${token.colorBorderSecondary};
15
+ background: ${token.colorBgElevated} !important;
16
16
  }
17
17
  `,
18
18
  );
@@ -9,8 +9,8 @@ import Divider from './Divider';
9
9
  const useStyles = createStyles(({ css, token }) => ({
10
10
  container: css`
11
11
  position: relative;
12
- font-size: 15px;
13
12
  border-radius: 0;
13
+ font-size: 15px;
14
14
 
15
15
  &:active {
16
16
  background: ${token.colorFillTertiary};
@@ -19,15 +19,14 @@ const useStyles = createStyles(({ css, token }) => {
19
19
  width: 320px;
20
20
  height: 200px;
21
21
  padding: ${token.borderRadiusLG + 4}px;
22
+ border-radius: 16px;
22
23
 
23
24
  background: ${token.geekblue};
24
- border-radius: 16px;
25
25
  `,
26
26
  content: css`
27
27
  width: 100%;
28
28
  height: 100%;
29
29
  padding: 16px;
30
-
31
30
  border: 1.5px dashed #fff;
32
31
  border-radius: ${token.borderRadiusLG}px;
33
32
  `,
@@ -37,9 +36,9 @@ const useStyles = createStyles(({ css, token }) => {
37
36
  color: #fff;
38
37
  `,
39
38
  icon: css`
39
+ border-radius: ${token.borderRadiusLG}px;
40
40
  color: ${darken(0.05, token.geekblue)};
41
41
  background: ${lighten(0.38, token.geekblue)};
42
- border-radius: ${token.borderRadiusLG}px;
43
42
  `,
44
43
  iconGroup: css`
45
44
  margin-block-start: -44px;
@@ -20,8 +20,8 @@ const useStyles = createStyles(({ css, token, isDarkMode, responsive }) => ({
20
20
  iconCtn: css`
21
21
  width: 72px;
22
22
  height: 72px;
23
- background: ${isDarkMode ? token.blue1 : token.geekblue1};
24
23
  border-radius: 50%;
24
+ background: ${isDarkMode ? token.blue1 : token.geekblue1};
25
25
  `,
26
26
  title: css`
27
27
  margin-block-end: 0;
@@ -12,12 +12,12 @@ import { AsyncTaskStatus, FileParsingTask } from '@/types/asyncTask';
12
12
  const useStyles = createStyles(({ css, token, isDarkMode }) => ({
13
13
  errorReason: css`
14
14
  padding: 4px;
15
+ border-radius: 4px;
15
16
 
16
17
  font-family: monospace;
17
18
  font-size: 12px;
18
19
 
19
20
  background: ${isDarkMode ? darken(0.1, token.colorText) : lighten(0.1, token.colorText)};
20
- border-radius: 4px;
21
21
  `,
22
22
  }));
23
23
 
@@ -14,12 +14,12 @@ import EmbeddingStatus from './EmbeddingStatus';
14
14
  const useStyles = createStyles(({ css, token, isDarkMode }) => ({
15
15
  errorReason: css`
16
16
  padding: 4px;
17
+ border-radius: 4px;
17
18
 
18
19
  font-family: monospace;
19
20
  font-size: 12px;
20
21
 
21
22
  background: ${isDarkMode ? darken(0.1, token.colorText) : lighten(0.1, token.colorText)};
22
- border-radius: 4px;
23
23
  `,
24
24
  }));
25
25
 
@@ -10,11 +10,11 @@ export const useStyles = createStyles(({ css, token, prefixCls, isDarkMode, resp
10
10
 
11
11
  width: min(90vw, 450px);
12
12
  padding: 0;
13
-
14
- background: ${isDarkMode ? token.colorBgElevated : token.colorBgLayout};
15
13
  border: 1px solid ${token.colorSplit};
16
14
  border-radius: ${token.borderRadiusLG}px;
17
15
 
16
+ background: ${isDarkMode ? token.colorBgElevated : token.colorBgLayout};
17
+
18
18
  ${responsive.mobile} {
19
19
  width: unset;
20
20
  }
@@ -12,11 +12,10 @@ const useStyles = createStyles(({ css, token }) => {
12
12
  width: fit-content;
13
13
  height: 24px;
14
14
  padding-inline: 8px;
15
+ border-radius: 6px;
15
16
 
16
17
  color: ${token.colorTextTertiary};
17
18
 
18
- border-radius: 6px;
19
-
20
19
  &:hover {
21
20
  color: ${token.colorTextSecondary};
22
21
  background: ${token.colorFillTertiary};
@@ -19,13 +19,13 @@ const useStyles = createStyles(
19
19
  min-width: 16px;
20
20
  height: 22px;
21
21
  padding-inline: 8px;
22
+ border-radius: ${token.borderRadius}px;
22
23
 
23
24
  line-height: 22px;
24
25
  color: ${inverseTheme ? token.colorTextTertiary : token.colorTextSecondary};
25
26
  text-align: center;
26
27
 
27
28
  background: ${inverseTheme ? rgba(token.colorTextTertiary, 0.15) : token.colorFillTertiary};
28
- border-radius: ${token.borderRadius}px;
29
29
  }
30
30
  `,
31
31
  );
@@ -0,0 +1,28 @@
1
+ import { Switch, SwitchProps } from 'antd';
2
+ import { memo, useState } from 'react';
3
+
4
+ interface InstantSwitchProps {
5
+ enabled: boolean;
6
+ onChange: (enabled: boolean) => Promise<void>;
7
+ size?: SwitchProps['size'];
8
+ }
9
+
10
+ const InstantSwitch = memo<InstantSwitchProps>(({ enabled, onChange, size }) => {
11
+ const [value, setValue] = useState(enabled);
12
+ const [loading, setLoading] = useState(false);
13
+ return (
14
+ <Switch
15
+ loading={loading}
16
+ onChange={async (enabled) => {
17
+ setLoading(true);
18
+ setValue(enabled);
19
+ await onChange(enabled);
20
+ setLoading(false);
21
+ }}
22
+ size={size}
23
+ value={value}
24
+ />
25
+ );
26
+ });
27
+
28
+ export default InstantSwitch;
@@ -10,8 +10,8 @@ const useStyles = createStyles(({ css, token, prefixCls }) => ({
10
10
  `,
11
11
  menu: css`
12
12
  flex: 1;
13
- background: transparent;
14
13
  border: none !important;
14
+ background: transparent;
15
15
 
16
16
  .${prefixCls}-menu-item-divider {
17
17
  margin-block: 0.125rem;
@@ -17,13 +17,13 @@ const useStyles = createStyles(({ css, token }) => ({
17
17
  custom: css`
18
18
  width: 36px;
19
19
  height: 20px;
20
+ border-radius: 4px;
20
21
 
21
22
  font-family: ${token.fontFamilyCode};
22
23
  font-size: 12px;
23
24
  color: ${rgba(token.colorWarning, 0.75)};
24
25
 
25
26
  background: ${token.colorWarningBg};
26
- border-radius: 4px;
27
27
  `,
28
28
  tag: css`
29
29
  cursor: default;
@@ -34,7 +34,6 @@ const useStyles = createStyles(({ css, token }) => ({
34
34
 
35
35
  width: 20px;
36
36
  height: 20px;
37
-
38
37
  border-radius: 4px;
39
38
  `,
40
39
  tagBlue: css`
@@ -48,13 +47,13 @@ const useStyles = createStyles(({ css, token }) => ({
48
47
  token: css`
49
48
  width: 36px;
50
49
  height: 20px;
50
+ border-radius: 4px;
51
51
 
52
52
  font-family: ${token.fontFamilyCode};
53
53
  font-size: 11px;
54
54
  color: ${token.colorTextSecondary};
55
55
 
56
56
  background: ${token.colorFillTertiary};
57
- border-radius: 4px;
58
57
  `,
59
58
  }));
60
59
 
@@ -22,9 +22,10 @@ const useStyles = createStyles(({ css, token, isDarkMode }) => ({
22
22
 
23
23
  overflow: hidden;
24
24
 
25
- background: ${token.colorBgContainer};
26
25
  border: 1px solid ${token.colorSplit};
27
26
  border-radius: 8px;
27
+
28
+ background: ${token.colorBgContainer};
28
29
  box-shadow: ${token.boxShadowSecondary};
29
30
  `,
30
31
  mobileContainer: css`