@lobehub/chat 0.146.2 → 0.147.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 (358) hide show
  1. package/.env.example +3 -5
  2. package/.github/workflows/issue-close-require.yml +1 -1
  3. package/.github/workflows/release.yml +1 -1
  4. package/.github/workflows/test.yml +3 -1
  5. package/.i18nrc.js +13 -8
  6. package/.seorc.cjs +9 -0
  7. package/CHANGELOG.md +73 -0
  8. package/README.md +25 -25
  9. package/README.zh-CN.md +25 -25
  10. package/contributing/Home.md +1 -1
  11. package/docs/self-hosting/advanced/analytics.mdx +12 -0
  12. package/docs/self-hosting/advanced/analytics.zh-CN.mdx +10 -0
  13. package/docs/self-hosting/advanced/authentication.mdx +19 -0
  14. package/docs/self-hosting/advanced/authentication.zh-CN.mdx +15 -0
  15. package/docs/self-hosting/advanced/sso-providers/auth0.mdx +19 -2
  16. package/docs/self-hosting/advanced/sso-providers/auth0.zh-CN.mdx +15 -2
  17. package/docs/self-hosting/advanced/sso-providers/authentik.mdx +18 -3
  18. package/docs/self-hosting/advanced/sso-providers/authentik.zh-CN.mdx +14 -2
  19. package/docs/self-hosting/advanced/sso-providers/github.mdx +13 -0
  20. package/docs/self-hosting/advanced/sso-providers/github.zh-CN.mdx +13 -3
  21. package/docs/self-hosting/advanced/sso-providers/microsoft-entra-id.mdx +18 -2
  22. package/docs/self-hosting/advanced/sso-providers/microsoft-entra-id.zh-CN.mdx +15 -2
  23. package/docs/self-hosting/advanced/sso-providers/zitadel.mdx +17 -2
  24. package/docs/self-hosting/advanced/sso-providers/zitadel.zh-CN.mdx +14 -2
  25. package/docs/self-hosting/advanced/upstream-sync.mdx +13 -0
  26. package/docs/self-hosting/advanced/upstream-sync.zh-CN.mdx +10 -0
  27. package/docs/self-hosting/environment-variables/analytics.mdx +15 -0
  28. package/docs/self-hosting/environment-variables/analytics.zh-CN.mdx +13 -0
  29. package/docs/self-hosting/environment-variables/auth.mdx +14 -0
  30. package/docs/self-hosting/environment-variables/auth.zh-CN.mdx +15 -1
  31. package/docs/self-hosting/environment-variables/basic.mdx +15 -0
  32. package/docs/self-hosting/environment-variables/basic.zh-CN.mdx +11 -0
  33. package/docs/self-hosting/environment-variables/model-provider.mdx +26 -0
  34. package/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx +10 -0
  35. package/docs/self-hosting/environment-variables.mdx +13 -2
  36. package/docs/self-hosting/environment-variables.zh-CN.mdx +9 -0
  37. package/docs/self-hosting/examples/azure-openai.mdx +12 -0
  38. package/docs/self-hosting/examples/azure-openai.zh-CN.mdx +12 -0
  39. package/docs/self-hosting/examples/ollama.mdx +13 -0
  40. package/docs/self-hosting/examples/ollama.zh-CN.mdx +11 -0
  41. package/docs/self-hosting/faq/no-v1-suffix.mdx +12 -0
  42. package/docs/self-hosting/faq/no-v1-suffix.zh-CN.mdx +9 -0
  43. package/docs/self-hosting/faq/proxy-with-unable-to-verify-leaf-signature.mdx +14 -0
  44. package/docs/self-hosting/faq/proxy-with-unable-to-verify-leaf-signature.zh-CN.mdx +11 -0
  45. package/docs/self-hosting/platform/docker-compose.mdx +21 -5
  46. package/docs/self-hosting/platform/docker-compose.zh-CN.mdx +18 -5
  47. package/docs/self-hosting/platform/docker.mdx +26 -8
  48. package/docs/self-hosting/platform/docker.zh-CN.mdx +27 -9
  49. package/docs/self-hosting/platform/netlify.mdx +18 -2
  50. package/docs/self-hosting/platform/netlify.zh-CN.mdx +14 -1
  51. package/docs/self-hosting/platform/railway.mdx +12 -0
  52. package/docs/self-hosting/platform/railway.zh-CN.mdx +11 -0
  53. package/docs/self-hosting/platform/repocloud.mdx +12 -0
  54. package/docs/self-hosting/platform/repocloud.zh-CN.mdx +10 -0
  55. package/docs/self-hosting/platform/sealos.mdx +11 -0
  56. package/docs/self-hosting/platform/sealos.zh-CN.mdx +10 -0
  57. package/docs/self-hosting/platform/vercel.mdx +12 -0
  58. package/docs/self-hosting/platform/vercel.zh-CN.mdx +11 -0
  59. package/docs/self-hosting/platform/zeabur.mdx +11 -0
  60. package/docs/self-hosting/platform/zeabur.zh-CN.mdx +10 -0
  61. package/docs/self-hosting/start.mdx +12 -0
  62. package/docs/self-hosting/start.zh-CN.mdx +13 -0
  63. package/docs/usage/agents/concepts.mdx +13 -0
  64. package/docs/usage/agents/concepts.zh-CN.mdx +10 -0
  65. package/docs/usage/agents/custom-agent.mdx +16 -2
  66. package/docs/usage/agents/custom-agent.zh-CN.mdx +14 -2
  67. package/docs/usage/agents/model.mdx +11 -2
  68. package/docs/usage/agents/model.zh-CN.mdx +12 -0
  69. package/docs/usage/agents/prompt.mdx +15 -0
  70. package/docs/usage/agents/prompt.zh-CN.mdx +10 -0
  71. package/docs/usage/agents/topics.mdx +13 -0
  72. package/docs/usage/agents/topics.zh-CN.mdx +11 -0
  73. package/docs/usage/features/agent-market.mdx +11 -1
  74. package/docs/usage/features/agent-market.zh-CN.mdx +13 -0
  75. package/docs/usage/features/local-llm.mdx +12 -2
  76. package/docs/usage/features/local-llm.zh-CN.mdx +3 -3
  77. package/docs/usage/features/mobile.mdx +10 -1
  78. package/docs/usage/features/mobile.zh-CN.mdx +11 -0
  79. package/docs/usage/features/more.mdx +13 -0
  80. package/docs/usage/features/more.zh-CN.mdx +10 -0
  81. package/docs/usage/features/multi-ai-providers.mdx +14 -1
  82. package/docs/usage/features/multi-ai-providers.zh-CN.mdx +16 -0
  83. package/docs/usage/features/plugin-system.mdx +12 -1
  84. package/docs/usage/features/plugin-system.zh-CN.mdx +9 -0
  85. package/docs/usage/features/pwa.mdx +11 -1
  86. package/docs/usage/features/pwa.zh-CN.mdx +13 -0
  87. package/docs/usage/features/text-to-image.mdx +11 -1
  88. package/docs/usage/features/text-to-image.zh-CN.mdx +13 -0
  89. package/docs/usage/features/theme.mdx +12 -1
  90. package/docs/usage/features/theme.zh-CN.mdx +11 -0
  91. package/docs/usage/features/tts.mdx +14 -1
  92. package/docs/usage/features/tts.zh-CN.mdx +12 -0
  93. package/docs/usage/features/vision.mdx +11 -1
  94. package/docs/usage/features/vision.zh-CN.mdx +10 -0
  95. package/docs/usage/plugins/basic-usage.mdx +12 -0
  96. package/docs/usage/plugins/basic-usage.zh-CN.mdx +10 -0
  97. package/docs/usage/plugins/custom-plugin.mdx +12 -0
  98. package/docs/usage/plugins/custom-plugin.zh-CN.mdx +10 -0
  99. package/docs/usage/plugins/development.mdx +18 -0
  100. package/docs/usage/plugins/development.zh-CN.mdx +12 -0
  101. package/docs/usage/plugins/store.mdx +12 -0
  102. package/docs/usage/plugins/store.zh-CN.mdx +9 -0
  103. package/docs/usage/providers/groq.mdx +14 -2
  104. package/docs/usage/providers/groq.zh-CN.mdx +12 -2
  105. package/docs/usage/providers/ollama/gemma.mdx +13 -3
  106. package/docs/usage/providers/ollama/gemma.zh-CN.mdx +12 -3
  107. package/docs/usage/providers/ollama/qwen.mdx +12 -4
  108. package/docs/usage/providers/ollama/qwen.zh-CN.mdx +10 -3
  109. package/docs/usage/providers/ollama.mdx +19 -9
  110. package/docs/usage/providers/ollama.zh-CN.mdx +20 -9
  111. package/docs/usage/start.mdx +13 -2
  112. package/docs/usage/start.zh-CN.mdx +11 -2
  113. package/locales/ar/common.json +0 -26
  114. package/locales/ar/components.json +15 -0
  115. package/locales/ar/error.json +1 -52
  116. package/locales/ar/modelProvider.json +226 -0
  117. package/locales/ar/setting.json +48 -199
  118. package/locales/bg-BG/common.json +0 -26
  119. package/locales/bg-BG/components.json +15 -0
  120. package/locales/bg-BG/error.json +1 -52
  121. package/locales/bg-BG/modelProvider.json +226 -0
  122. package/locales/bg-BG/setting.json +48 -199
  123. package/locales/de-DE/common.json +0 -26
  124. package/locales/de-DE/components.json +15 -0
  125. package/locales/de-DE/error.json +1 -52
  126. package/locales/de-DE/modelProvider.json +226 -0
  127. package/locales/de-DE/setting.json +48 -199
  128. package/locales/en-US/common.json +0 -26
  129. package/locales/en-US/components.json +15 -0
  130. package/locales/en-US/error.json +1 -52
  131. package/locales/en-US/modelProvider.json +226 -0
  132. package/locales/en-US/setting.json +48 -199
  133. package/locales/es-ES/common.json +0 -26
  134. package/locales/es-ES/components.json +15 -0
  135. package/locales/es-ES/error.json +1 -52
  136. package/locales/es-ES/modelProvider.json +226 -0
  137. package/locales/es-ES/setting.json +48 -199
  138. package/locales/fr-FR/common.json +0 -26
  139. package/locales/fr-FR/components.json +15 -0
  140. package/locales/fr-FR/error.json +1 -52
  141. package/locales/fr-FR/modelProvider.json +226 -0
  142. package/locales/fr-FR/setting.json +48 -199
  143. package/locales/it-IT/common.json +0 -26
  144. package/locales/it-IT/components.json +15 -0
  145. package/locales/it-IT/error.json +1 -52
  146. package/locales/it-IT/modelProvider.json +226 -0
  147. package/locales/it-IT/setting.json +59 -210
  148. package/locales/ja-JP/common.json +0 -26
  149. package/locales/ja-JP/components.json +15 -0
  150. package/locales/ja-JP/error.json +1 -52
  151. package/locales/ja-JP/modelProvider.json +226 -0
  152. package/locales/ja-JP/setting.json +59 -210
  153. package/locales/ko-KR/common.json +0 -26
  154. package/locales/ko-KR/components.json +15 -0
  155. package/locales/ko-KR/error.json +1 -52
  156. package/locales/ko-KR/modelProvider.json +226 -0
  157. package/locales/ko-KR/setting.json +48 -199
  158. package/locales/nl-NL/common.json +0 -26
  159. package/locales/nl-NL/components.json +15 -0
  160. package/locales/nl-NL/error.json +4 -55
  161. package/locales/nl-NL/modelProvider.json +226 -0
  162. package/locales/nl-NL/setting.json +49 -200
  163. package/locales/pl-PL/common.json +0 -26
  164. package/locales/pl-PL/components.json +15 -0
  165. package/locales/pl-PL/error.json +1 -52
  166. package/locales/pl-PL/modelProvider.json +226 -0
  167. package/locales/pl-PL/setting.json +48 -199
  168. package/locales/pt-BR/common.json +0 -26
  169. package/locales/pt-BR/components.json +15 -0
  170. package/locales/pt-BR/error.json +1 -52
  171. package/locales/pt-BR/modelProvider.json +226 -0
  172. package/locales/pt-BR/setting.json +48 -199
  173. package/locales/ru-RU/common.json +0 -26
  174. package/locales/ru-RU/components.json +15 -0
  175. package/locales/ru-RU/error.json +1 -52
  176. package/locales/ru-RU/modelProvider.json +226 -0
  177. package/locales/ru-RU/setting.json +48 -199
  178. package/locales/tr-TR/common.json +0 -26
  179. package/locales/tr-TR/components.json +15 -0
  180. package/locales/tr-TR/error.json +1 -52
  181. package/locales/tr-TR/modelProvider.json +226 -0
  182. package/locales/tr-TR/setting.json +48 -199
  183. package/locales/vi-VN/common.json +0 -26
  184. package/locales/vi-VN/components.json +15 -0
  185. package/locales/vi-VN/error.json +1 -52
  186. package/locales/vi-VN/modelProvider.json +226 -0
  187. package/locales/vi-VN/setting.json +48 -199
  188. package/locales/zh-CN/common.json +0 -26
  189. package/locales/zh-CN/components.json +15 -0
  190. package/locales/zh-CN/error.json +2 -53
  191. package/locales/zh-CN/modelProvider.json +226 -0
  192. package/locales/zh-CN/setting.json +48 -199
  193. package/locales/zh-TW/common.json +0 -26
  194. package/locales/zh-TW/components.json +15 -0
  195. package/locales/zh-TW/error.json +1 -52
  196. package/locales/zh-TW/modelProvider.json +226 -0
  197. package/locales/zh-TW/setting.json +48 -199
  198. package/package.json +120 -116
  199. package/scripts/mdxWorkflow/index.ts +48 -0
  200. package/src/app/api/chat/[provider]/route.test.ts +4 -9
  201. package/src/app/api/chat/[provider]/route.ts +6 -23
  202. package/src/app/api/chat/{[provider]/agentRuntime.test.ts → agentRuntime.test.ts} +12 -12
  203. package/src/app/api/chat/{[provider]/agentRuntime.ts → agentRuntime.ts} +11 -30
  204. package/src/app/api/chat/auth/index.ts +42 -0
  205. package/src/app/api/chat/models/[provider]/route.ts +45 -0
  206. package/src/app/api/config/__snapshots__/route.test.ts.snap +127 -0
  207. package/src/app/api/config/route.test.ts +170 -0
  208. package/src/app/api/config/route.ts +46 -11
  209. package/src/app/api/plugin/gateway/route.ts +1 -1
  210. package/src/app/settings/llm/Azure/index.tsx +36 -43
  211. package/src/app/settings/llm/Bedrock/index.tsx +12 -20
  212. package/src/app/settings/llm/Ollama/index.tsx +2 -2
  213. package/src/app/settings/llm/OpenAI/index.tsx +9 -121
  214. package/src/app/settings/llm/OpenRouter/index.tsx +1 -1
  215. package/src/app/settings/llm/TogetherAI/index.tsx +0 -1
  216. package/src/app/settings/llm/components/ProviderConfig/index.tsx +48 -32
  217. package/src/app/settings/llm/components/ProviderModelList/CustomModelOption.tsx +94 -0
  218. package/src/app/settings/llm/components/ProviderModelList/MaxTokenSlider.tsx +88 -0
  219. package/src/app/settings/llm/components/ProviderModelList/ModelConfigModal.tsx +128 -0
  220. package/src/app/settings/llm/components/ProviderModelList/ModelFetcher.tsx +81 -0
  221. package/src/app/settings/llm/components/ProviderModelList/Option.tsx +38 -0
  222. package/src/app/settings/llm/components/ProviderModelList/index.tsx +142 -0
  223. package/src/app/settings/llm/const.ts +1 -1
  224. package/src/app/settings/llm/index.tsx +7 -6
  225. package/src/app/settings/tts/TTS/index.tsx +1 -1
  226. package/src/components/AntdStaticMethods/index.test.tsx +43 -0
  227. package/src/components/ModelIcon/index.tsx +25 -7
  228. package/src/components/ModelSelect/index.tsx +67 -56
  229. package/src/config/modelProviders/anthropic.ts +6 -1
  230. package/src/config/modelProviders/azure.ts +42 -0
  231. package/src/config/modelProviders/bedrock.ts +4 -1
  232. package/src/config/modelProviders/google.ts +2 -14
  233. package/src/config/modelProviders/groq.ts +3 -0
  234. package/src/config/modelProviders/index.ts +19 -14
  235. package/src/config/modelProviders/mistral.ts +5 -0
  236. package/src/config/modelProviders/moonshot.ts +3 -1
  237. package/src/config/modelProviders/ollama.ts +6 -17
  238. package/src/config/modelProviders/openai.ts +9 -13
  239. package/src/config/modelProviders/openrouter.ts +6 -1
  240. package/src/config/modelProviders/perplexity.ts +2 -0
  241. package/src/config/modelProviders/togetherai.ts +11 -0
  242. package/src/config/modelProviders/zeroone.ts +3 -0
  243. package/src/config/modelProviders/zhipu.ts +3 -0
  244. package/src/config/server/provider.ts +52 -7
  245. package/src/const/auth.ts +0 -1
  246. package/src/const/{settings.ts → settings/index.ts} +31 -4
  247. package/src/const/url.ts +1 -1
  248. package/src/database/core/db.ts +14 -0
  249. package/src/database/schemas/user.ts +1 -25
  250. package/src/features/AgentSetting/AgentConfig/ModelSelect.tsx +7 -11
  251. package/src/features/ChatInput/STT/common.tsx +80 -78
  252. package/src/features/ChatInput/STT/index.tsx +8 -6
  253. package/src/features/Conversation/Error/APIKeyForm/Bedrock.tsx +8 -8
  254. package/src/features/Conversation/Error/APIKeyForm/ProviderApiKeyForm.tsx +73 -0
  255. package/src/features/Conversation/Error/APIKeyForm/ProviderAvatar.tsx +74 -0
  256. package/src/features/Conversation/Error/APIKeyForm/index.tsx +25 -49
  257. package/src/features/ModelSwitchPanel/index.tsx +40 -13
  258. package/src/hooks/_header.ts +5 -20
  259. package/src/libs/agent-runtime/BaseAI.ts +17 -1
  260. package/src/libs/agent-runtime/anthropic/index.ts +3 -7
  261. package/src/libs/agent-runtime/azureOpenai/index.test.ts +166 -0
  262. package/src/libs/agent-runtime/azureOpenai/index.ts +16 -8
  263. package/src/libs/agent-runtime/bedrock/index.test.ts +199 -22
  264. package/src/libs/agent-runtime/bedrock/index.ts +11 -18
  265. package/src/libs/agent-runtime/groq/index.test.ts +350 -0
  266. package/src/libs/agent-runtime/groq/index.ts +14 -77
  267. package/src/libs/agent-runtime/mistral/index.test.ts +25 -19
  268. package/src/libs/agent-runtime/mistral/index.ts +24 -86
  269. package/src/libs/agent-runtime/moonshot/index.test.ts +2 -2
  270. package/src/libs/agent-runtime/moonshot/index.ts +14 -77
  271. package/src/libs/agent-runtime/openai/__snapshots__/index.test.ts.snap +99 -0
  272. package/src/libs/agent-runtime/openai/fixtures/openai-models.json +170 -0
  273. package/src/libs/agent-runtime/openai/index.test.ts +15 -50
  274. package/src/libs/agent-runtime/openai/index.ts +15 -107
  275. package/src/libs/agent-runtime/openrouter/__snapshots__/index.test.ts.snap +82 -0
  276. package/src/libs/agent-runtime/openrouter/fixtures/models.json +62 -0
  277. package/src/libs/agent-runtime/openrouter/index.test.ts +25 -9
  278. package/src/libs/agent-runtime/openrouter/index.ts +42 -84
  279. package/src/libs/agent-runtime/openrouter/type.ts +28 -0
  280. package/src/libs/agent-runtime/togetherai/index.test.ts +12 -9
  281. package/src/libs/agent-runtime/togetherai/index.ts +20 -85
  282. package/src/libs/agent-runtime/utils/anthropicHelpers.test.ts +14 -22
  283. package/src/libs/agent-runtime/utils/anthropicHelpers.ts +4 -10
  284. package/src/libs/agent-runtime/utils/openaiCompatibleFactory/index.ts +147 -0
  285. package/src/libs/agent-runtime/zeroone/index.test.ts +350 -0
  286. package/src/libs/agent-runtime/zeroone/index.ts +14 -77
  287. package/src/locales/default/common.ts +0 -28
  288. package/src/locales/default/components.ts +15 -0
  289. package/src/locales/default/error.ts +2 -54
  290. package/src/locales/default/index.ts +4 -0
  291. package/src/locales/default/modelProvider.ts +229 -0
  292. package/src/locales/default/setting.ts +51 -202
  293. package/src/migrations/FromV3ToV4/fixtures/azure-input-v3.json +79 -0
  294. package/src/migrations/FromV3ToV4/fixtures/azure-output-v4.json +75 -0
  295. package/src/migrations/FromV3ToV4/fixtures/ollama-input-v3.json +85 -0
  296. package/src/migrations/FromV3ToV4/fixtures/ollama-output-v4.json +86 -0
  297. package/src/migrations/FromV3ToV4/fixtures/openai-input-v3.json +77 -0
  298. package/src/migrations/FromV3ToV4/fixtures/openai-output-v4.json +79 -0
  299. package/src/migrations/FromV3ToV4/fixtures/openrouter-input-v3.json +82 -0
  300. package/src/migrations/FromV3ToV4/fixtures/openrouter-output-v4.json +89 -0
  301. package/src/migrations/FromV3ToV4/fixtures/output-v4-from-v1.json +203 -0
  302. package/src/migrations/FromV3ToV4/index.ts +96 -0
  303. package/src/migrations/FromV3ToV4/migrations.test.ts +195 -0
  304. package/src/migrations/FromV3ToV4/types/v3.ts +59 -0
  305. package/src/migrations/FromV3ToV4/types/v4.ts +37 -0
  306. package/src/migrations/index.ts +11 -3
  307. package/src/services/_auth.test.ts +4 -6
  308. package/src/services/_auth.ts +8 -60
  309. package/src/services/_header.ts +5 -22
  310. package/src/services/_url.ts +1 -0
  311. package/src/services/chat.ts +16 -6
  312. package/src/services/global.ts +1 -1
  313. package/src/services/models.ts +23 -0
  314. package/src/services/ollama.ts +2 -2
  315. package/src/store/chat/slices/share/action.test.ts +113 -0
  316. package/src/store/chat/slices/share/action.ts +1 -1
  317. package/src/store/global/slices/common/action.test.ts +166 -1
  318. package/src/store/global/slices/common/action.ts +2 -1
  319. package/src/store/global/slices/settings/{action.test.ts → actions/general.test.ts} +1 -19
  320. package/src/store/global/slices/settings/{action.ts → actions/general.ts} +4 -19
  321. package/src/store/global/slices/settings/actions/index.ts +18 -0
  322. package/src/store/global/slices/settings/actions/llm.test.ts +60 -0
  323. package/src/store/global/slices/settings/actions/llm.ts +88 -0
  324. package/src/store/global/slices/settings/initialState.ts +3 -1
  325. package/src/store/global/slices/settings/reducers/customModelCard.test.ts +204 -0
  326. package/src/store/global/slices/settings/reducers/customModelCard.ts +64 -0
  327. package/src/store/global/slices/settings/selectors/index.ts +1 -0
  328. package/src/store/global/slices/settings/selectors/modelConfig.test.ts +189 -0
  329. package/src/store/global/slices/settings/selectors/modelConfig.ts +179 -0
  330. package/src/store/global/slices/settings/selectors/modelProvider.test.ts +47 -138
  331. package/src/store/global/slices/settings/selectors/modelProvider.ts +102 -243
  332. package/src/store/global/store.ts +1 -1
  333. package/src/types/llm.ts +12 -1
  334. package/src/types/serverConfig.ts +22 -0
  335. package/src/types/settings/index.ts +0 -12
  336. package/src/types/settings/modelProvider.ts +34 -90
  337. package/src/utils/client/switchLang.test.ts +34 -0
  338. package/src/utils/difference.test.ts +46 -0
  339. package/src/utils/difference.ts +15 -2
  340. package/src/utils/fetch.ts +1 -3
  341. package/src/utils/parseModels.ts +62 -0
  342. package/vercel.json +1 -1
  343. package/docs/package.json +0 -5
  344. package/src/features/Conversation/Error/APIKeyForm/Anthropic.tsx +0 -40
  345. package/src/features/Conversation/Error/APIKeyForm/Google.tsx +0 -61
  346. package/src/features/Conversation/Error/APIKeyForm/Groq.tsx +0 -60
  347. package/src/features/Conversation/Error/APIKeyForm/Mistral.tsx +0 -60
  348. package/src/features/Conversation/Error/APIKeyForm/Moonshot.tsx +0 -60
  349. package/src/features/Conversation/Error/APIKeyForm/OpenAI.tsx +0 -63
  350. package/src/features/Conversation/Error/APIKeyForm/OpenRouter.tsx +0 -40
  351. package/src/features/Conversation/Error/APIKeyForm/Perplexity.tsx +0 -60
  352. package/src/features/Conversation/Error/APIKeyForm/TogetherAI.tsx +0 -40
  353. package/src/features/Conversation/Error/APIKeyForm/ZeroOne.tsx +0 -60
  354. package/src/features/Conversation/Error/APIKeyForm/Zhipu.tsx +0 -62
  355. package/src/libs/agent-runtime/utils/env.ts +0 -1
  356. package/src/store/global/slices/settings/selectors/__snapshots__/modelProvider.test.ts.snap +0 -230
  357. /package/src/app/api/chat/{auth.ts → auth/utils.ts} +0 -0
  358. /package/src/components/{AntdStaticMethods.tsx → AntdStaticMethods/index.tsx} +0 -0
@@ -1,40 +1,23 @@
1
1
  import { getPreferredRegion } from '@/app/api/config';
2
2
  import { createErrorResponse } from '@/app/api/errorResponse';
3
- import { LOBE_CHAT_AUTH_HEADER, OAUTH_AUTHORIZED } from '@/const/auth';
4
- import { AgentRuntimeError, ChatCompletionErrorPayload } from '@/libs/agent-runtime';
3
+ import { ChatCompletionErrorPayload } from '@/libs/agent-runtime';
5
4
  import { ChatErrorType } from '@/types/fetch';
6
5
  import { ChatStreamPayload } from '@/types/openai/chat';
7
6
  import { getTracePayload } from '@/utils/trace';
8
7
 
9
- import { checkAuthMethod, getJWTPayload } from '../auth';
10
- import AgentRuntime from './agentRuntime';
8
+ import AgentRuntime from '../agentRuntime';
9
+ import { checkAuth } from '../auth';
11
10
 
12
11
  export const runtime = 'edge';
13
12
 
14
13
  export const preferredRegion = getPreferredRegion();
15
14
 
16
- export const POST = async (req: Request, { params }: { params: { provider: string } }) => {
15
+ export const POST = checkAuth(async (req: Request, { params, jwtPayload }) => {
17
16
  const { provider } = params;
18
17
 
19
18
  try {
20
19
  // ============ 1. init chat model ============ //
21
-
22
- // get Authorization from header
23
- const authorization = req.headers.get(LOBE_CHAT_AUTH_HEADER);
24
- const oauthAuthorized = !!req.headers.get(OAUTH_AUTHORIZED);
25
-
26
- if (!authorization) throw AgentRuntimeError.createError(ChatErrorType.Unauthorized);
27
-
28
- // check the Auth With payload
29
- const jwtPayload = await getJWTPayload(authorization);
30
- checkAuthMethod(jwtPayload.accessCode, jwtPayload.apiKey, oauthAuthorized);
31
-
32
- const body = await req.clone().json();
33
- const agentRuntime = await AgentRuntime.initializeWithUserPayload(provider, jwtPayload, {
34
- apiVersion: jwtPayload.azureApiVersion,
35
- model: body.model,
36
- useAzure: jwtPayload.useAzure,
37
- });
20
+ const agentRuntime = await AgentRuntime.initializeWithUserPayload(provider, jwtPayload);
38
21
 
39
22
  // ============ 2. create chat completion ============ //
40
23
 
@@ -60,4 +43,4 @@ export const POST = async (req: Request, { params }: { params: { provider: strin
60
43
 
61
44
  return createErrorResponse(errorType, { error, ...res, provider });
62
45
  }
63
- };
46
+ });
@@ -18,6 +18,7 @@ import {
18
18
  LobeOpenAI,
19
19
  LobeOpenRouterAI,
20
20
  LobePerplexityAI,
21
+ LobeRuntimeAI,
21
22
  LobeTogetherAI,
22
23
  LobeZhipuAI,
23
24
  ModelProvider,
@@ -70,33 +71,32 @@ describe('AgentRuntime', () => {
70
71
  const jwtPayload: JWTPayload = {
71
72
  apiKey: 'user-azure-key',
72
73
  endpoint: 'user-azure-endpoint',
73
- useAzure: true,
74
+ azureApiVersion: '2024-02-01',
74
75
  };
75
76
  const runtime = await AgentRuntime.initializeWithUserPayload(
76
- ModelProvider.OpenAI,
77
+ ModelProvider.Azure,
77
78
  jwtPayload,
78
79
  );
79
80
 
80
81
  expect(runtime).toBeInstanceOf(AgentRuntime);
81
- expect(runtime['_runtime']).toBeInstanceOf(LobeOpenAI);
82
+ expect(runtime['_runtime']).toBeInstanceOf(LobeAzureOpenAI);
82
83
  expect(runtime['_runtime'].baseURL).toBe('user-azure-endpoint');
83
84
  });
84
85
  it('should initialize with azureOpenAIParams correctly', async () => {
85
- const jwtPayload: JWTPayload = { apiKey: 'user-openai-key', endpoint: 'user-endpoint' };
86
- const azureOpenAIParams = {
87
- apiVersion: 'custom-version',
88
- model: 'custom-model',
89
- useAzure: true,
86
+ const jwtPayload: JWTPayload = {
87
+ apiKey: 'user-openai-key',
88
+ endpoint: 'user-endpoint',
89
+ azureApiVersion: 'custom-version',
90
90
  };
91
+
91
92
  const runtime = await AgentRuntime.initializeWithUserPayload(
92
- ModelProvider.OpenAI,
93
+ ModelProvider.Azure,
93
94
  jwtPayload,
94
- azureOpenAIParams,
95
95
  );
96
96
 
97
97
  expect(runtime).toBeInstanceOf(AgentRuntime);
98
- const openAIRuntime = runtime['_runtime'] as LobeOpenAI;
99
- expect(openAIRuntime).toBeInstanceOf(LobeOpenAI);
98
+ const openAIRuntime = runtime['_runtime'] as LobeRuntimeAI;
99
+ expect(openAIRuntime).toBeInstanceOf(LobeAzureOpenAI);
100
100
  });
101
101
 
102
102
  it('should initialize with AzureAI correctly', async () => {
@@ -28,13 +28,7 @@ import {
28
28
  } from '@/libs/agent-runtime';
29
29
  import { TraceClient } from '@/libs/traces';
30
30
 
31
- import apiKeyManager from '../apiKeyManager';
32
-
33
- interface AzureOpenAIParams {
34
- apiVersion?: string;
35
- model: string;
36
- useAzure?: boolean;
37
- }
31
+ import apiKeyManager from './apiKeyManager';
38
32
 
39
33
  export interface AgentChatOptions {
40
34
  enableTrace?: boolean;
@@ -112,18 +106,18 @@ class AgentRuntime {
112
106
  });
113
107
  }
114
108
 
115
- static async initializeWithUserPayload(
116
- provider: string,
117
- payload: JWTPayload,
118
- azureOpenAI?: AzureOpenAIParams,
119
- ) {
109
+ async models() {
110
+ return this._runtime.models?.();
111
+ }
112
+
113
+ static async initializeWithUserPayload(provider: string, payload: JWTPayload) {
120
114
  let runtimeModel: LobeRuntimeAI;
121
115
 
122
116
  switch (provider) {
123
117
  default:
124
118
  case 'oneapi':
125
119
  case ModelProvider.OpenAI: {
126
- runtimeModel = this.initOpenAI(payload, azureOpenAI);
120
+ runtimeModel = this.initOpenAI(payload);
127
121
  break;
128
122
  }
129
123
 
@@ -196,27 +190,14 @@ class AgentRuntime {
196
190
  return new AgentRuntime(runtimeModel);
197
191
  }
198
192
 
199
- private static initOpenAI(payload: JWTPayload, azureOpenAI?: AzureOpenAIParams) {
200
- const { OPENAI_API_KEY, OPENAI_PROXY_URL, AZURE_API_VERSION, AZURE_API_KEY, USE_AZURE_OPENAI } =
201
- getServerConfig();
193
+ private static initOpenAI(payload: JWTPayload) {
194
+ const { OPENAI_API_KEY, OPENAI_PROXY_URL } = getServerConfig();
202
195
  const openaiApiKey = payload?.apiKey || OPENAI_API_KEY;
203
196
  const baseURL = payload?.endpoint || OPENAI_PROXY_URL;
204
197
 
205
- const azureApiKey = payload.apiKey || AZURE_API_KEY;
206
- const useAzure = azureOpenAI?.useAzure || USE_AZURE_OPENAI;
207
- const apiVersion = azureOpenAI?.apiVersion || AZURE_API_VERSION;
208
-
209
- const apiKey = apiKeyManager.pick(useAzure ? azureApiKey : openaiApiKey);
198
+ const apiKey = apiKeyManager.pick(openaiApiKey);
210
199
 
211
- return new LobeOpenAI({
212
- apiKey,
213
- azureOptions: {
214
- apiVersion,
215
- model: azureOpenAI?.model,
216
- },
217
- baseURL,
218
- useAzure,
219
- });
200
+ return new LobeOpenAI({ apiKey, baseURL });
220
201
  }
221
202
 
222
203
  private static initAzureOpenAI(payload: JWTPayload) {
@@ -0,0 +1,42 @@
1
+ import { createErrorResponse } from '@/app/api/errorResponse';
2
+ import { JWTPayload, LOBE_CHAT_AUTH_HEADER, OAUTH_AUTHORIZED } from '@/const/auth';
3
+ import { AgentRuntimeError, ChatCompletionErrorPayload } from '@/libs/agent-runtime';
4
+ import { ChatErrorType } from '@/types/fetch';
5
+
6
+ import { checkAuthMethod, getJWTPayload } from './utils';
7
+
8
+ type RequestOptions = { params: { provider: string } };
9
+
10
+ export type RequestHandler = (
11
+ req: Request,
12
+ options: RequestOptions & { jwtPayload: JWTPayload },
13
+ ) => Promise<Response>;
14
+
15
+ export const checkAuth =
16
+ (handler: RequestHandler) => async (req: Request, options: RequestOptions) => {
17
+ let jwtPayload: JWTPayload;
18
+
19
+ try {
20
+ // get Authorization from header
21
+ const authorization = req.headers.get(LOBE_CHAT_AUTH_HEADER);
22
+ const oauthAuthorized = !!req.headers.get(OAUTH_AUTHORIZED);
23
+
24
+ if (!authorization) throw AgentRuntimeError.createError(ChatErrorType.Unauthorized);
25
+
26
+ // check the Auth With payload
27
+ jwtPayload = await getJWTPayload(authorization);
28
+ checkAuthMethod(jwtPayload.accessCode, jwtPayload.apiKey, oauthAuthorized);
29
+ } catch (e) {
30
+ const {
31
+ errorType = ChatErrorType.InternalServerError,
32
+ error: errorContent,
33
+ ...res
34
+ } = e as ChatCompletionErrorPayload;
35
+
36
+ const error = errorContent || e;
37
+
38
+ return createErrorResponse(errorType, { error, ...res, provider: options.params?.provider });
39
+ }
40
+
41
+ return handler(req, { ...options, jwtPayload });
42
+ };
@@ -0,0 +1,45 @@
1
+ import { NextResponse } from 'next/server';
2
+
3
+ import { getPreferredRegion } from '@/app/api/config';
4
+ import { createErrorResponse } from '@/app/api/errorResponse';
5
+ import { ChatCompletionErrorPayload, ModelProvider } from '@/libs/agent-runtime';
6
+ import { ChatErrorType } from '@/types/fetch';
7
+
8
+ import AgentRuntime from '../../agentRuntime';
9
+ import { checkAuth } from '../../auth';
10
+
11
+ export const runtime = 'edge';
12
+
13
+ export const preferredRegion = getPreferredRegion();
14
+
15
+ const noNeedAPIKey = (provider: string) =>
16
+ [ModelProvider.OpenRouter, ModelProvider.TogetherAI].includes(provider as any);
17
+
18
+ export const GET = checkAuth(async (req, { params, jwtPayload }) => {
19
+ const { provider } = params;
20
+
21
+ try {
22
+ const hasDefaultApiKey = jwtPayload.apiKey || 'dont-need-api-key-for-model-list';
23
+
24
+ const agentRuntime = await AgentRuntime.initializeWithUserPayload(provider, {
25
+ ...jwtPayload,
26
+ apiKey: noNeedAPIKey(provider) ? hasDefaultApiKey : jwtPayload.apiKey,
27
+ });
28
+
29
+ const list = await agentRuntime.models();
30
+
31
+ return NextResponse.json(list);
32
+ } catch (e) {
33
+ const {
34
+ errorType = ChatErrorType.InternalServerError,
35
+ error: errorContent,
36
+ ...res
37
+ } = e as ChatCompletionErrorPayload;
38
+
39
+ const error = errorContent || e;
40
+ // track the error at server side
41
+ console.error(`Route: [${provider}] ${errorType}:`, error);
42
+
43
+ return createErrorResponse(errorType, { error, ...res, provider });
44
+ }
45
+ });
@@ -0,0 +1,127 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`GET /api/config > Model Provider env > CUSTOM_MODELS > custom deletion, addition, and renaming of models 1`] = `
4
+ [
5
+ {
6
+ "displayName": "llama",
7
+ "enabled": true,
8
+ "functionCall": true,
9
+ "id": "llama",
10
+ "vision": true,
11
+ },
12
+ {
13
+ "displayName": "claude-2",
14
+ "enabled": true,
15
+ "functionCall": true,
16
+ "id": "claude-2",
17
+ "vision": true,
18
+ },
19
+ {
20
+ "displayName": "gpt-4-32k",
21
+ "enabled": true,
22
+ "functionCall": true,
23
+ "id": "gpt-4-0125-preview",
24
+ "tokens": 128000,
25
+ },
26
+ ]
27
+ `;
28
+
29
+ exports[`GET /api/config > Model Provider env > OPENAI_MODEL_LIST > custom deletion, addition, and renaming of models 1`] = `
30
+ [
31
+ {
32
+ "displayName": "llama",
33
+ "enabled": true,
34
+ "functionCall": true,
35
+ "id": "llama",
36
+ "vision": true,
37
+ },
38
+ {
39
+ "displayName": "claude-2",
40
+ "enabled": true,
41
+ "functionCall": true,
42
+ "id": "claude-2",
43
+ "vision": true,
44
+ },
45
+ {
46
+ "displayName": "gpt-4-32k",
47
+ "enabled": true,
48
+ "functionCall": true,
49
+ "id": "gpt-4-0125-preview",
50
+ "tokens": 128000,
51
+ },
52
+ ]
53
+ `;
54
+
55
+ exports[`GET /api/config > Model Provider env > OPENAI_MODEL_LIST > should work correct with gpt-4 1`] = `
56
+ [
57
+ {
58
+ "displayName": "GPT-3.5 Turbo (1106)",
59
+ "enabled": true,
60
+ "functionCall": true,
61
+ "id": "gpt-3.5-turbo-1106",
62
+ "tokens": 16385,
63
+ },
64
+ {
65
+ "description": "GPT 3.5 Turbo,适用于各种文本生成和理解任务",
66
+ "displayName": "GPT-3.5 Turbo",
67
+ "enabled": true,
68
+ "functionCall": true,
69
+ "id": "gpt-3.5-turbo",
70
+ "tokens": 16385,
71
+ },
72
+ {
73
+ "displayName": "GPT-3.5 Turbo 16K",
74
+ "enabled": true,
75
+ "id": "gpt-3.5-turbo-16k",
76
+ "tokens": 16385,
77
+ },
78
+ {
79
+ "displayName": "GPT-4",
80
+ "enabled": true,
81
+ "functionCall": true,
82
+ "id": "gpt-4",
83
+ "tokens": 8192,
84
+ },
85
+ {
86
+ "displayName": "GPT-4 32K",
87
+ "enabled": true,
88
+ "functionCall": true,
89
+ "id": "gpt-4-32k",
90
+ "tokens": 32768,
91
+ },
92
+ {
93
+ "displayName": "GPT-4 Turbo Preview (1106)",
94
+ "enabled": true,
95
+ "functionCall": true,
96
+ "id": "gpt-4-1106-preview",
97
+ "tokens": 128000,
98
+ },
99
+ {
100
+ "description": "GPT-4 视觉预览版,支持视觉任务",
101
+ "displayName": "GPT-4 Turbo Vision Preview",
102
+ "enabled": true,
103
+ "id": "gpt-4-vision-preview",
104
+ "tokens": 128000,
105
+ "vision": true,
106
+ },
107
+ ]
108
+ `;
109
+
110
+ exports[`GET /api/config > Model Provider env > OPENROUTER_MODEL_LIST > custom deletion, addition, and renaming of models 1`] = `
111
+ [
112
+ {
113
+ "displayName": "google/gemma-7b-it",
114
+ "enabled": true,
115
+ "functionCall": true,
116
+ "id": "google/gemma-7b-it",
117
+ "vision": true,
118
+ },
119
+ {
120
+ "displayName": "Mistral-7B-Instruct",
121
+ "enabled": true,
122
+ "functionCall": true,
123
+ "id": "mistralai/mistral-7b-instruct",
124
+ "vision": true,
125
+ },
126
+ ]
127
+ `;
@@ -0,0 +1,170 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+
3
+ import { GlobalServerConfig } from '@/types/serverConfig';
4
+
5
+ import { GET } from './route';
6
+
7
+ beforeEach(() => {
8
+ vi.resetAllMocks();
9
+ });
10
+
11
+ describe('GET /api/config', () => {
12
+ describe('Model Provider env', () => {
13
+ describe('OPENAI_MODEL_LIST', () => {
14
+ it('custom deletion, addition, and renaming of models', async () => {
15
+ process.env.OPENAI_MODEL_LIST =
16
+ '-all,+llama,+claude-2,-gpt-3.5-turbo,gpt-4-0125-preview=gpt-4-turbo,gpt-4-0125-preview=gpt-4-32k';
17
+
18
+ const response = await GET();
19
+
20
+ // Assert
21
+ expect(response).toBeInstanceOf(Response);
22
+ expect(response.status).toBe(200);
23
+
24
+ const jsonResponse: GlobalServerConfig = await response.json();
25
+
26
+ const result = jsonResponse.languageModel?.openai?.serverModelCards;
27
+
28
+ expect(result).toMatchSnapshot();
29
+ process.env.OPENAI_MODEL_LIST = '';
30
+ });
31
+
32
+ it('should work correct with gpt-4', async () => {
33
+ process.env.OPENAI_MODEL_LIST =
34
+ '-all,+gpt-3.5-turbo-1106,+gpt-3.5-turbo,+gpt-3.5-turbo-16k,+gpt-4,+gpt-4-32k,+gpt-4-1106-preview,+gpt-4-vision-preview';
35
+
36
+ const response = await GET();
37
+ const jsonResponse: GlobalServerConfig = await response.json();
38
+
39
+ const result = jsonResponse.languageModel?.openai?.serverModelCards;
40
+
41
+ expect(result).toMatchSnapshot();
42
+
43
+ process.env.OPENAI_MODEL_LIST = '';
44
+ });
45
+
46
+ it('duplicate naming model', async () => {
47
+ process.env.OPENAI_MODEL_LIST =
48
+ 'gpt-4-0125-preview=gpt-4-turbo,gpt-4-0125-preview=gpt-4-32k';
49
+
50
+ const response = await GET();
51
+ const jsonResponse: GlobalServerConfig = await response.json();
52
+
53
+ const result = jsonResponse.languageModel?.openai?.serverModelCards;
54
+
55
+ expect(result?.find((s) => s.id === 'gpt-4-0125-preview')?.displayName).toEqual(
56
+ 'gpt-4-32k',
57
+ );
58
+
59
+ process.env.OPENAI_MODEL_LIST = '';
60
+ });
61
+
62
+ it('should delete model', async () => {
63
+ process.env.OPENAI_MODEL_LIST = '-gpt-4';
64
+
65
+ const res = await GET();
66
+ const data: GlobalServerConfig = await res.json();
67
+
68
+ const result = data.languageModel?.openai?.serverModelCards;
69
+
70
+ expect(result?.find((r) => r.id === 'gpt-4')).toBeUndefined();
71
+
72
+ process.env.OPENAI_MODEL_LIST = '';
73
+ });
74
+
75
+ it('show the hidden model', async () => {
76
+ process.env.OPENAI_MODEL_LIST = '+gpt-4-1106-preview';
77
+
78
+ const res = await GET();
79
+ const data: GlobalServerConfig = await res.json();
80
+
81
+ const result = data.languageModel?.openai?.serverModelCards;
82
+
83
+ expect(result?.find((o) => o.id === 'gpt-4-1106-preview')).toEqual({
84
+ displayName: 'GPT-4 Turbo Preview (1106)',
85
+ functionCall: true,
86
+ enabled: true,
87
+ id: 'gpt-4-1106-preview',
88
+ tokens: 128000,
89
+ });
90
+
91
+ process.env.OPENAI_MODEL_LIST = '';
92
+ });
93
+
94
+ it('only add the model', async () => {
95
+ process.env.OPENAI_MODEL_LIST = 'model1,model2,model3,model4';
96
+
97
+ const res = await GET();
98
+ const data: GlobalServerConfig = await res.json();
99
+
100
+ const result = data.languageModel?.openai?.serverModelCards;
101
+
102
+ expect(result).toContainEqual({
103
+ displayName: 'model1',
104
+ functionCall: true,
105
+ id: 'model1',
106
+ enabled: true,
107
+ vision: true,
108
+ });
109
+ expect(result).toContainEqual({
110
+ displayName: 'model2',
111
+ functionCall: true,
112
+ enabled: true,
113
+ id: 'model2',
114
+ vision: true,
115
+ });
116
+ expect(result).toContainEqual({
117
+ displayName: 'model3',
118
+ enabled: true,
119
+ functionCall: true,
120
+ id: 'model3',
121
+ vision: true,
122
+ });
123
+ expect(result).toContainEqual({
124
+ displayName: 'model4',
125
+ functionCall: true,
126
+ enabled: true,
127
+ id: 'model4',
128
+ vision: true,
129
+ });
130
+
131
+ process.env.OPENAI_MODEL_LIST = '';
132
+ });
133
+ });
134
+
135
+ describe('CUSTOM_MODELS', () => {
136
+ it('custom deletion, addition, and renaming of models', async () => {
137
+ process.env.CUSTOM_MODELS =
138
+ '-all,+llama,+claude-2,-gpt-3.5-turbo,gpt-4-0125-preview=gpt-4-turbo,gpt-4-0125-preview=gpt-4-32k';
139
+
140
+ const response = await GET();
141
+
142
+ // Assert
143
+ expect(response).toBeInstanceOf(Response);
144
+ expect(response.status).toBe(200);
145
+
146
+ const jsonResponse: GlobalServerConfig = await response.json();
147
+
148
+ const result = jsonResponse.languageModel?.openai?.serverModelCards;
149
+
150
+ expect(result).toMatchSnapshot();
151
+ });
152
+ });
153
+
154
+ describe('OPENROUTER_MODEL_LIST', () => {
155
+ it('custom deletion, addition, and renaming of models', async () => {
156
+ process.env.OPENROUTER_MODEL_LIST =
157
+ '-all,+google/gemma-7b-it,+mistralai/mistral-7b-instruct=Mistral-7B-Instruct';
158
+
159
+ const res = await GET();
160
+ const data: GlobalServerConfig = await res.json();
161
+
162
+ const result = data.languageModel?.openrouter?.serverModelCards;
163
+
164
+ expect(result).toMatchSnapshot();
165
+
166
+ process.env.OPENROUTER_MODEL_LIST = '';
167
+ });
168
+ });
169
+ });
170
+ });
@@ -1,5 +1,11 @@
1
+ import {
2
+ OllamaProviderCard,
3
+ OpenRouterProviderCard,
4
+ TogetherAIProviderCard,
5
+ } from '@/config/modelProviders';
1
6
  import { getServerConfig } from '@/config/server';
2
- import { GlobalServerConfig } from '@/types/settings';
7
+ import { GlobalServerConfig } from '@/types/serverConfig';
8
+ import { transformToChatModelCards } from '@/utils/parseModels';
3
9
 
4
10
  import { parseAgentConfig } from './parseDefaultAgent';
5
11
 
@@ -11,27 +17,32 @@ export const runtime = 'edge';
11
17
  export const GET = async () => {
12
18
  const {
13
19
  ENABLE_LANGFUSE,
14
- CUSTOM_MODELS,
20
+ ENABLE_OAUTH_SSO,
21
+
22
+ DEFAULT_AGENT_CONFIG,
23
+ OPENAI_MODEL_LIST,
24
+
15
25
  ENABLED_MOONSHOT,
16
26
  ENABLED_ZHIPU,
17
27
  ENABLED_AWS_BEDROCK,
18
28
  ENABLED_GOOGLE,
19
29
  ENABLED_GROQ,
20
- ENABLE_OAUTH_SSO,
21
- ENABLE_OLLAMA,
22
30
  ENABLED_PERPLEXITY,
23
31
  ENABLED_ANTHROPIC,
24
32
  ENABLED_MISTRAL,
33
+
34
+ ENABLE_OLLAMA,
35
+ OLLAMA_MODEL_LIST,
36
+
25
37
  ENABLED_OPENROUTER,
38
+ OPENROUTER_MODEL_LIST,
39
+
26
40
  ENABLED_ZEROONE,
27
41
  ENABLED_TOGETHERAI,
28
- DEFAULT_AGENT_CONFIG,
29
- OLLAMA_CUSTOM_MODELS,
30
- OPENROUTER_CUSTOM_MODELS,
42
+ TOGETHERAI_MODEL_LIST,
31
43
  } = getServerConfig();
32
44
 
33
45
  const config: GlobalServerConfig = {
34
- customModelName: CUSTOM_MODELS,
35
46
  defaultAgent: {
36
47
  config: parseAgentConfig(DEFAULT_AGENT_CONFIG),
37
48
  },
@@ -44,10 +55,34 @@ export const GET = async () => {
44
55
  groq: { enabled: ENABLED_GROQ },
45
56
  mistral: { enabled: ENABLED_MISTRAL },
46
57
  moonshot: { enabled: ENABLED_MOONSHOT },
47
- ollama: { customModelName: OLLAMA_CUSTOM_MODELS, enabled: ENABLE_OLLAMA },
48
- openrouter: { customModelName: OPENROUTER_CUSTOM_MODELS, enabled: ENABLED_OPENROUTER },
58
+
59
+ ollama: {
60
+ enabled: ENABLE_OLLAMA,
61
+ serverModelCards: transformToChatModelCards(
62
+ OLLAMA_MODEL_LIST,
63
+ OllamaProviderCard.chatModels,
64
+ ),
65
+ },
66
+ openai: {
67
+ serverModelCards: transformToChatModelCards(OPENAI_MODEL_LIST),
68
+ },
69
+ openrouter: {
70
+ enabled: ENABLED_OPENROUTER,
71
+ serverModelCards: transformToChatModelCards(
72
+ OPENROUTER_MODEL_LIST,
73
+ OpenRouterProviderCard.chatModels,
74
+ ),
75
+ },
49
76
  perplexity: { enabled: ENABLED_PERPLEXITY },
50
- togetherai: { enabled: ENABLED_TOGETHERAI },
77
+
78
+ togetherai: {
79
+ enabled: ENABLED_TOGETHERAI,
80
+ serverModelCards: transformToChatModelCards(
81
+ TOGETHERAI_MODEL_LIST,
82
+ TogetherAIProviderCard.chatModels,
83
+ ),
84
+ },
85
+
51
86
  zeroone: { enabled: ENABLED_ZEROONE },
52
87
  zhipu: { enabled: ENABLED_ZHIPU },
53
88
  },
@@ -1,7 +1,7 @@
1
1
  import { PluginRequestPayload } from '@lobehub/chat-plugin-sdk';
2
2
  import { createGatewayOnEdgeRuntime } from '@lobehub/chat-plugins-gateway';
3
3
 
4
- import { getJWTPayload } from '@/app/api/chat/auth';
4
+ import { getJWTPayload } from '@/app/api/chat/auth/utils';
5
5
  import { createErrorResponse } from '@/app/api/errorResponse';
6
6
  import { getServerConfig } from '@/config/server';
7
7
  import { LOBE_CHAT_AUTH_HEADER, OAUTH_AUTHORIZED } from '@/const/auth';