@lobehub/chat 1.119.1 → 1.119.2

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 (227) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/changelog/v1.json +5 -0
  3. package/package.json +5 -3
  4. package/packages/const/src/auth.ts +0 -36
  5. package/packages/const/src/index.ts +3 -1
  6. package/packages/database/src/models/__tests__/aiModel.test.ts +1 -2
  7. package/packages/database/src/models/aiModel.ts +2 -3
  8. package/packages/database/src/repositories/aiInfra/index.test.ts +1 -1
  9. package/packages/database/src/repositories/aiInfra/index.ts +4 -4
  10. package/packages/model-bank/src/aiModels/ai21.ts +1 -1
  11. package/packages/model-bank/src/aiModels/ai302.ts +1 -1
  12. package/packages/model-bank/src/aiModels/ai360.ts +1 -1
  13. package/packages/model-bank/src/aiModels/aihubmix.ts +2 -2
  14. package/packages/model-bank/src/aiModels/akashchat.ts +1 -1
  15. package/packages/model-bank/src/aiModels/anthropic.ts +1 -1
  16. package/packages/model-bank/src/aiModels/azure.ts +1 -1
  17. package/packages/model-bank/src/aiModels/azureai.ts +1 -1
  18. package/packages/model-bank/src/aiModels/baichuan.ts +1 -1
  19. package/packages/model-bank/src/aiModels/bedrock.ts +1 -1
  20. package/packages/model-bank/src/aiModels/bfl.ts +2 -3
  21. package/packages/model-bank/src/aiModels/cloudflare.ts +1 -1
  22. package/packages/model-bank/src/aiModels/cohere.ts +1 -1
  23. package/packages/model-bank/src/aiModels/deepseek.ts +1 -1
  24. package/packages/model-bank/src/aiModels/fal.ts +1 -1
  25. package/packages/model-bank/src/aiModels/fireworksai.ts +1 -1
  26. package/packages/model-bank/src/aiModels/giteeai.ts +1 -1
  27. package/packages/model-bank/src/aiModels/github.ts +1 -1
  28. package/packages/model-bank/src/aiModels/google.ts +2 -3
  29. package/packages/model-bank/src/aiModels/groq.ts +1 -1
  30. package/packages/model-bank/src/aiModels/higress.ts +1 -1
  31. package/packages/model-bank/src/aiModels/huggingface.ts +1 -1
  32. package/packages/model-bank/src/aiModels/hunyuan.ts +1 -1
  33. package/packages/model-bank/src/aiModels/index.ts +1 -1
  34. package/packages/model-bank/src/aiModels/infiniai.ts +1 -1
  35. package/packages/model-bank/src/aiModels/internlm.ts +1 -1
  36. package/packages/model-bank/src/aiModels/jina.ts +1 -1
  37. package/packages/model-bank/src/aiModels/lmstudio.ts +1 -1
  38. package/packages/model-bank/src/aiModels/lobehub.ts +1 -1
  39. package/packages/model-bank/src/aiModels/minimax.ts +1 -1
  40. package/packages/model-bank/src/aiModels/mistral.ts +1 -1
  41. package/packages/model-bank/src/aiModels/modelscope.ts +1 -1
  42. package/packages/model-bank/src/aiModels/moonshot.ts +1 -1
  43. package/packages/model-bank/src/aiModels/novita.ts +1 -1
  44. package/packages/model-bank/src/aiModels/nvidia.ts +1 -1
  45. package/packages/model-bank/src/aiModels/ollama.ts +1 -1
  46. package/packages/model-bank/src/aiModels/openai.ts +1 -1
  47. package/packages/model-bank/src/aiModels/openrouter.ts +1 -1
  48. package/packages/model-bank/src/aiModels/perplexity.ts +1 -1
  49. package/packages/model-bank/src/aiModels/ppio.ts +1 -1
  50. package/packages/model-bank/src/aiModels/qiniu.ts +1 -1
  51. package/packages/model-bank/src/aiModels/qwen.ts +1 -1
  52. package/packages/model-bank/src/aiModels/sambanova.ts +1 -1
  53. package/packages/model-bank/src/aiModels/search1api.ts +1 -1
  54. package/packages/model-bank/src/aiModels/sensenova.ts +1 -1
  55. package/packages/model-bank/src/aiModels/siliconcloud.ts +1 -1
  56. package/packages/model-bank/src/aiModels/spark.ts +1 -1
  57. package/packages/model-bank/src/aiModels/stepfun.ts +1 -1
  58. package/packages/model-bank/src/aiModels/taichu.ts +1 -1
  59. package/packages/model-bank/src/aiModels/tencentcloud.ts +1 -1
  60. package/packages/model-bank/src/aiModels/togetherai.ts +1 -1
  61. package/packages/model-bank/src/aiModels/upstage.ts +1 -1
  62. package/packages/model-bank/src/aiModels/v0.ts +1 -1
  63. package/packages/model-bank/src/aiModels/vertexai.ts +1 -1
  64. package/packages/model-bank/src/aiModels/vllm.ts +1 -1
  65. package/packages/model-bank/src/aiModels/volcengine.ts +1 -1
  66. package/packages/model-bank/src/aiModels/wenxin.ts +1 -1
  67. package/packages/model-bank/src/aiModels/xai.ts +1 -1
  68. package/packages/model-bank/src/aiModels/xinference.ts +1 -1
  69. package/packages/model-bank/src/aiModels/zeroone.ts +1 -1
  70. package/packages/model-bank/src/aiModels/zhipu.ts +1 -1
  71. package/packages/model-bank/src/index.ts +1 -0
  72. package/packages/model-bank/src/standard-parameters/index.ts +48 -0
  73. package/packages/{types/src → model-bank/src/types}/aiModel.ts +12 -1
  74. package/packages/model-bank/src/types/index.ts +1 -0
  75. package/packages/model-runtime/package.json +4 -1
  76. package/packages/model-runtime/src/BaseAI.ts +2 -2
  77. package/packages/model-runtime/src/ModelRuntime.test.ts +4 -4
  78. package/packages/model-runtime/src/RouterRuntime/createRuntime.ts +3 -7
  79. package/packages/model-runtime/src/ai302/index.ts +1 -1
  80. package/packages/model-runtime/src/aihubmix/index.ts +1 -2
  81. package/packages/model-runtime/src/anthropic/index.ts +1 -1
  82. package/packages/model-runtime/src/azureOpenai/index.ts +2 -3
  83. package/packages/model-runtime/src/azureai/index.ts +2 -3
  84. package/packages/model-runtime/src/bedrock/index.ts +1 -1
  85. package/packages/model-runtime/src/bfl/createImage.test.ts +4 -4
  86. package/packages/model-runtime/src/bfl/createImage.ts +2 -2
  87. package/packages/model-runtime/src/bfl/index.ts +1 -1
  88. package/packages/model-runtime/src/cloudflare/index.ts +1 -1
  89. package/packages/model-runtime/src/const/models.ts +64 -0
  90. package/packages/model-runtime/src/fal/index.test.ts +2 -3
  91. package/packages/model-runtime/src/fal/index.ts +1 -1
  92. package/packages/model-runtime/src/github/index.ts +1 -1
  93. package/packages/model-runtime/src/google/createImage.test.ts +1 -1
  94. package/packages/model-runtime/src/google/createImage.ts +1 -1
  95. package/packages/model-runtime/src/google/index.test.ts +1 -1
  96. package/packages/model-runtime/src/google/index.ts +4 -3
  97. package/packages/model-runtime/src/groq/index.ts +1 -1
  98. package/packages/model-runtime/src/helpers/parseToolCalls.ts +1 -2
  99. package/packages/model-runtime/src/huggingface/index.ts +1 -1
  100. package/packages/model-runtime/src/index.ts +3 -1
  101. package/packages/model-runtime/src/infiniai/index.ts +1 -1
  102. package/packages/model-runtime/src/ollama/index.test.ts +1 -1
  103. package/packages/model-runtime/src/ollama/index.ts +2 -3
  104. package/packages/model-runtime/src/openai/index.ts +16 -8
  105. package/packages/model-runtime/src/providerTestUtils.ts +1 -2
  106. package/packages/model-runtime/src/qiniu/index.test.ts +2 -3
  107. package/packages/model-runtime/src/siliconcloud/index.ts +1 -1
  108. package/packages/model-runtime/src/types/chat.ts +2 -22
  109. package/packages/model-runtime/src/{error.ts → types/error.ts} +29 -0
  110. package/packages/model-runtime/src/types/index.ts +4 -0
  111. package/packages/model-runtime/src/types/toolsCalling.ts +48 -0
  112. package/packages/model-runtime/src/types/type.ts +1 -1
  113. package/packages/model-runtime/src/types/usage.ts +27 -0
  114. package/packages/model-runtime/src/utils/anthropicHelpers.test.ts +2 -2
  115. package/packages/model-runtime/src/utils/anthropicHelpers.ts +1 -1
  116. package/packages/model-runtime/src/utils/createError.ts +1 -1
  117. package/packages/model-runtime/src/utils/errorResponse.test.ts +110 -0
  118. package/packages/model-runtime/src/utils/errorResponse.ts +64 -0
  119. package/packages/{utils/src → model-runtime/src/utils}/getFallbackModelProperty.ts +1 -1
  120. package/packages/model-runtime/src/utils/googleErrorParser.test.ts +1 -1
  121. package/packages/model-runtime/src/utils/googleErrorParser.ts +1 -1
  122. package/packages/model-runtime/src/utils/handleOpenAIError.ts +1 -1
  123. package/packages/model-runtime/src/utils/imageToBase64.test.ts +91 -0
  124. package/packages/model-runtime/src/utils/imageToBase64.ts +62 -0
  125. package/packages/model-runtime/src/utils/modelParse.test.ts +2 -2
  126. package/packages/model-runtime/src/utils/modelParse.ts +16 -10
  127. package/packages/model-runtime/src/utils/openaiCompatibleFactory/createImage.ts +1 -1
  128. package/packages/model-runtime/src/utils/openaiCompatibleFactory/index.ts +3 -3
  129. package/packages/model-runtime/src/utils/openaiHelpers.test.ts +2 -2
  130. package/packages/model-runtime/src/utils/openaiHelpers.ts +3 -4
  131. package/packages/model-runtime/src/utils/postProcessModelList.ts +2 -2
  132. package/packages/model-runtime/src/utils/safeParseJSON.test.ts +71 -0
  133. package/packages/model-runtime/src/utils/safeParseJSON.ts +12 -0
  134. package/packages/model-runtime/src/utils/streams/bedrock/claude.ts +1 -1
  135. package/packages/model-runtime/src/utils/streams/bedrock/llama.test.ts +1 -2
  136. package/packages/model-runtime/src/utils/streams/bedrock/llama.ts +1 -1
  137. package/packages/model-runtime/src/utils/streams/google-ai.test.ts +1 -1
  138. package/packages/model-runtime/src/utils/streams/google-ai.ts +1 -1
  139. package/packages/model-runtime/src/utils/streams/ollama.test.ts +1 -1
  140. package/packages/model-runtime/src/utils/streams/ollama.ts +2 -3
  141. package/packages/model-runtime/src/utils/streams/openai/openai.test.ts +1 -2
  142. package/packages/model-runtime/src/utils/streams/openai/openai.ts +1 -1
  143. package/packages/model-runtime/src/utils/streams/openai/responsesStream.ts +1 -1
  144. package/packages/model-runtime/src/utils/streams/protocol.ts +3 -3
  145. package/packages/model-runtime/src/utils/streams/vertex-ai.test.ts +1 -1
  146. package/packages/model-runtime/src/utils/streams/vertex-ai.ts +2 -2
  147. package/packages/model-runtime/src/utils/uuid.ts +7 -0
  148. package/packages/model-runtime/src/vertexai/index.ts +1 -1
  149. package/packages/types/src/agent/index.ts +2 -1
  150. package/packages/types/src/aiProvider.ts +10 -2
  151. package/packages/types/src/auth.ts +35 -0
  152. package/packages/types/src/discover/models.ts +1 -1
  153. package/packages/types/src/discover/providers.ts +1 -1
  154. package/packages/types/src/index.ts +4 -0
  155. package/packages/types/src/llm.ts +2 -47
  156. package/packages/types/src/session/agentSession.ts +3 -3
  157. package/packages/types/src/session/index.ts +2 -2
  158. package/packages/types/src/session/sessionGroup.ts +0 -2
  159. package/packages/types/src/user/settings/general.ts +1 -1
  160. package/packages/types/src/user/settings/modelProvider.ts +1 -1
  161. package/packages/utils/src/fetch/fetchSSE.ts +1 -1
  162. package/packages/utils/src/format.ts +2 -3
  163. package/packages/utils/src/index.ts +3 -1
  164. package/packages/utils/src/number.test.ts +1 -2
  165. package/packages/utils/src/number.ts +1 -2
  166. package/packages/utils/src/parseModels.test.ts +1 -2
  167. package/packages/utils/src/parseModels.ts +2 -3
  168. package/packages/utils/src/pricing.test.ts +1 -2
  169. package/packages/utils/src/pricing.ts +1 -1
  170. package/packages/utils/src/server/xor.ts +3 -1
  171. package/src/app/(backend)/middleware/auth/index.ts +1 -2
  172. package/src/app/(backend)/webapi/chat/vertexai/route.ts +1 -1
  173. package/src/app/(backend)/webapi/text-to-image/[provider]/route.ts +1 -2
  174. package/src/app/[variants]/(main)/discover/(list)/model/features/List/ModelTypeIcon.tsx +1 -2
  175. package/src/app/[variants]/(main)/image/@menu/components/SeedNumberInput/index.tsx +1 -1
  176. package/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/hooks/useAutoDimensions.ts +4 -3
  177. package/src/app/[variants]/(main)/settings/provider/features/ModelList/CreateNewModelModal/Form.tsx +1 -1
  178. package/src/app/[variants]/(main)/settings/provider/features/ModelList/ModelItem.tsx +1 -1
  179. package/src/app/[variants]/(main)/settings/provider/features/ModelList/SortModelModal/ListItem.tsx +1 -1
  180. package/src/app/[variants]/(main)/settings/provider/features/ModelList/SortModelModal/index.tsx +1 -1
  181. package/src/components/ModelSelect/index.tsx +1 -1
  182. package/src/database/_deprecated/core/migrations/migrateSettingsToUser/type.ts +2 -5
  183. package/src/features/Conversation/Extras/Usage/UsageDetail/ModelCard.tsx +1 -1
  184. package/src/features/Conversation/Extras/Usage/UsageDetail/pricing.ts +3 -4
  185. package/src/features/Conversation/Extras/Usage/UsageDetail/tokens.test.ts +1 -1
  186. package/src/features/Conversation/Extras/Usage/UsageDetail/tokens.ts +3 -2
  187. package/src/libs/trpc/async/context.ts +2 -1
  188. package/src/libs/trpc/edge/context.ts +2 -6
  189. package/src/libs/trpc/lambda/context.ts +1 -1
  190. package/src/migrations/FromV5ToV6/types/v5.ts +2 -2
  191. package/src/migrations/FromV5ToV6/types/v6.ts +2 -1
  192. package/src/server/globalConfig/genServerAiProviderConfig.ts +3 -3
  193. package/src/server/modules/ModelRuntime/index.test.ts +1 -1
  194. package/src/server/modules/ModelRuntime/index.ts +1 -1
  195. package/src/server/routers/async/caller.ts +2 -1
  196. package/src/server/routers/async/image.ts +2 -2
  197. package/src/server/routers/lambda/aiModel.ts +1 -1
  198. package/src/server/services/chunk/index.ts +2 -1
  199. package/src/server/services/generation/index.ts +2 -2
  200. package/src/services/_auth.ts +2 -1
  201. package/src/services/aiModel/server.test.ts +1 -1
  202. package/src/services/aiModel/type.ts +1 -1
  203. package/src/services/chat.ts +1 -1
  204. package/src/services/upload.ts +3 -3
  205. package/src/store/agent/slices/chat/action.ts +1 -1
  206. package/src/store/aiInfra/slices/aiModel/action.ts +6 -6
  207. package/src/store/aiInfra/slices/aiModel/initialState.ts +1 -1
  208. package/src/store/aiInfra/slices/aiModel/selectors.test.ts +1 -1
  209. package/src/store/aiInfra/slices/aiModel/selectors.ts +2 -1
  210. package/src/store/aiInfra/slices/aiProvider/__tests__/action.test.ts +7 -7
  211. package/src/store/aiInfra/slices/aiProvider/action.ts +8 -8
  212. package/src/store/aiInfra/slices/aiProvider/initialState.ts +2 -1
  213. package/src/store/electron/actions/app.ts +1 -1
  214. package/src/store/image/slices/generationConfig/action.test.ts +1 -1
  215. package/src/store/image/slices/generationConfig/action.ts +1 -1
  216. package/src/store/image/slices/generationConfig/hooks.test.ts +1 -1
  217. package/src/store/image/slices/generationConfig/hooks.ts +6 -3
  218. package/src/store/image/slices/generationConfig/selectors.test.ts +1 -1
  219. package/src/store/user/slices/auth/action.ts +1 -1
  220. package/src/store/user/slices/auth/selectors.ts +3 -4
  221. package/src/store/user/slices/modelList/action.ts +8 -7
  222. package/src/store/user/slices/modelList/selectors/modelProvider.ts +8 -5
  223. package/src/store/user/slices/preference/selectors.ts +3 -2
  224. package/src/store/user/slices/settings/selectors/settings.ts +1 -2
  225. package/src/store/user/slices/sync/selectors.ts +1 -1
  226. package/packages/const/src/image.ts +0 -51
  227. /package/packages/{utils/src → model-runtime/src/utils}/getFallbackModelProperty.test.ts +0 -0
@@ -1,4 +1,5 @@
1
1
  import type { ChatModelCard } from '@lobechat/types';
2
+ import { AIBaseModelCard } from 'model-bank';
2
3
 
3
4
  import type { ModelProviderKey } from '../types';
4
5
 
@@ -25,16 +26,16 @@ export const MODEL_LIST_CONFIGS = {
25
26
  reasoningKeywords: ['thinking', '-2.5-'],
26
27
  visionKeywords: ['gemini', 'learnlm'],
27
28
  },
29
+ llama: {
30
+ functionCallKeywords: ['llama-3.2', 'llama-3.3', 'llama-4'],
31
+ reasoningKeywords: [],
32
+ visionKeywords: ['llava'],
33
+ },
28
34
  moonshot: {
29
35
  functionCallKeywords: ['moonshot', 'kimi'],
30
36
  reasoningKeywords: ['thinking'],
31
37
  visionKeywords: ['vision', 'kimi-latest', 'kimi-thinking-preview'],
32
38
  },
33
- ollama: {
34
- functionCallKeywords: ['llama-3.2', 'llama-3.3', 'llama-4'],
35
- reasoningKeywords: [],
36
- visionKeywords: ['llava'],
37
- },
38
39
  openai: {
39
40
  excludeKeywords: ['audio'],
40
41
  functionCallKeywords: ['4o', '4.1', 'o3', 'o4', 'oss'],
@@ -81,13 +82,13 @@ export const MODEL_LIST_CONFIGS = {
81
82
  },
82
83
  } as const;
83
84
 
84
- // 模型提供商关键词配置
85
- export const PROVIDER_DETECTION_CONFIG = {
85
+ // 模型所有者 (提供商) 关键词配置
86
+ export const MODEL_OWNER_DETECTION_CONFIG = {
86
87
  anthropic: ['claude'],
87
88
  deepseek: ['deepseek'],
88
89
  google: ['gemini', 'imagen'],
90
+ llama: ['llama', 'llava'],
89
91
  moonshot: ['moonshot', 'kimi'],
90
- ollama: ['llama', 'llava'],
91
92
  openai: ['o1', 'o3', 'o4', 'gpt-'],
92
93
  qwen: ['qwen', 'qwq', 'qvq'],
93
94
  v0: ['v0'],
@@ -175,7 +176,12 @@ const findKnownModelByProvider = async (
175
176
  // 尝试动态导入对应的配置文件
176
177
  const modules = await import('model-bank');
177
178
 
178
- const providerModels = modules[provider];
179
+ // 如果提供商配置文件不存在,跳过
180
+ if (!(provider in modules)) {
181
+ return null;
182
+ }
183
+
184
+ const providerModels = modules[provider as keyof typeof modules] as AIBaseModelCard[];
179
185
 
180
186
  // 如果导入成功且有数据,进行查找
181
187
  if (Array.isArray(providerModels)) {
@@ -197,7 +203,7 @@ const findKnownModelByProvider = async (
197
203
  export const detectModelProvider = (modelId: string): keyof typeof MODEL_LIST_CONFIGS => {
198
204
  const lowerModelId = modelId.toLowerCase();
199
205
 
200
- for (const [provider, keywords] of Object.entries(PROVIDER_DETECTION_CONFIG)) {
206
+ for (const [provider, keywords] of Object.entries(MODEL_OWNER_DETECTION_CONFIG)) {
201
207
  const hasKeyword = isKeywordListMatch(lowerModelId, keywords);
202
208
 
203
209
  if (hasKeyword && provider in MODEL_LIST_CONFIGS) {
@@ -1,9 +1,9 @@
1
- import { imageUrlToBase64 } from '@lobechat/utils';
2
1
  import createDebug from 'debug';
3
2
  import { RuntimeImageGenParamsValue } from 'model-bank';
4
3
  import OpenAI from 'openai';
5
4
 
6
5
  import { CreateImagePayload, CreateImageResponse } from '../../types/image';
6
+ import { imageUrlToBase64 } from '../imageToBase64';
7
7
  import { convertImageUrlToFile } from '../openaiHelpers';
8
8
  import { parseDataUri } from '../uriParser';
9
9
 
@@ -1,15 +1,13 @@
1
- import { getModelPropertyWithFallback } from '@lobechat/utils';
2
1
  import dayjs from 'dayjs';
3
2
  import utc from 'dayjs/plugin/utc';
4
3
  import { LOBE_DEFAULT_MODEL_LIST } from 'model-bank';
4
+ import type { AiModelType } from 'model-bank';
5
5
  import OpenAI, { ClientOptions } from 'openai';
6
6
  import { Stream } from 'openai/streaming';
7
7
 
8
- import type { AiModelType } from '@/types/aiModel';
9
8
  import type { ChatModelCard } from '@/types/llm';
10
9
 
11
10
  import { LobeRuntimeAI } from '../../BaseAI';
12
- import { AgentRuntimeErrorType, ILobeAgentRuntimeErrorType } from '../../error';
13
11
  import {
14
12
  ChatCompletionErrorPayload,
15
13
  ChatCompletionTool,
@@ -24,10 +22,12 @@ import {
24
22
  TextToSpeechOptions,
25
23
  TextToSpeechPayload,
26
24
  } from '../../types';
25
+ import { AgentRuntimeErrorType, ILobeAgentRuntimeErrorType } from '../../types/error';
27
26
  import { CreateImagePayload, CreateImageResponse } from '../../types/image';
28
27
  import { AgentRuntimeError } from '../createError';
29
28
  import { debugResponse, debugStream } from '../debugStream';
30
29
  import { desensitizeUrl } from '../desensitizeUrl';
30
+ import { getModelPropertyWithFallback } from '../getFallbackModelProperty';
31
31
  import { handleOpenAIError } from '../handleOpenAIError';
32
32
  import { convertOpenAIMessages, convertOpenAIResponseInputs } from '../openaiHelpers';
33
33
  import { postProcessModelList } from '../postProcessModelList';
@@ -1,7 +1,7 @@
1
- import { imageUrlToBase64 } from '@lobechat/utils';
2
1
  import OpenAI from 'openai';
3
2
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
4
3
 
4
+ import { imageUrlToBase64 } from './imageToBase64';
5
5
  import {
6
6
  convertImageUrlToFile,
7
7
  convertMessageContent,
@@ -11,7 +11,7 @@ import {
11
11
  import { parseDataUri } from './uriParser';
12
12
 
13
13
  // 模拟依赖
14
- vi.mock('@lobechat/utils');
14
+ vi.mock('./imageToBase64');
15
15
  vi.mock('./uriParser');
16
16
 
17
17
  describe('convertMessageContent', () => {
@@ -1,9 +1,8 @@
1
- import { imageUrlToBase64 } from '@lobechat/utils';
2
1
  import OpenAI, { toFile } from 'openai';
3
2
 
4
- import { disableStreamModels, systemToUserModels } from '@/const/models';
5
- import { ChatStreamPayload, OpenAIChatMessage } from '@/libs/model-runtime';
6
-
3
+ import { disableStreamModels, systemToUserModels } from '../const/models';
4
+ import { ChatStreamPayload, OpenAIChatMessage } from '../types';
5
+ import { imageUrlToBase64 } from './imageToBase64';
7
6
  import { parseDataUri } from './uriParser';
8
7
 
9
8
  export const convertMessageContent = async (
@@ -1,5 +1,5 @@
1
- import { CHAT_MODEL_IMAGE_GENERATION_PARAMS } from '@/const/image';
2
- import type { AiModelType } from '@/types/aiModel';
1
+ import { AiModelType, CHAT_MODEL_IMAGE_GENERATION_PARAMS } from 'model-bank';
2
+
3
3
  import type { ChatModelCard } from '@/types/llm';
4
4
 
5
5
  // Whitelist for automatic image model generation
@@ -0,0 +1,71 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { safeParseJSON } from './safeParseJSON';
4
+
5
+ describe('safeParseJSON', () => {
6
+ it('should parse a valid JSON string', () => {
7
+ const validJSON = '{"name": "John", "age": 30}';
8
+ const result = safeParseJSON(validJSON);
9
+ expect(result).toEqual({ name: 'John', age: 30 });
10
+ });
11
+
12
+ it('should return undefined for invalid JSON', () => {
13
+ const invalidJSON = '{name: John}';
14
+ const result = safeParseJSON(invalidJSON);
15
+ expect(result).toBeUndefined();
16
+ });
17
+
18
+ it('should parse an empty object', () => {
19
+ const emptyObject = '{}';
20
+ const result = safeParseJSON(emptyObject);
21
+ expect(result).toEqual({});
22
+ });
23
+
24
+ it('should parse an array', () => {
25
+ const arrayJSON = '[1, 2, 3]';
26
+ const result = safeParseJSON(arrayJSON);
27
+ expect(result).toEqual([1, 2, 3]);
28
+ });
29
+
30
+ it('should parse nested objects', () => {
31
+ const nestedJSON = '{"user": {"name": "John", "age": 30}}';
32
+ const result = safeParseJSON(nestedJSON);
33
+ expect(result).toEqual({ user: { name: 'John', age: 30 } });
34
+ });
35
+
36
+ it('should return undefined for an empty string', () => {
37
+ const result = safeParseJSON('');
38
+ expect(result).toBeUndefined();
39
+ });
40
+
41
+ it('should return undefined for non-string input', () => {
42
+ // @ts-expect-error: Testing with invalid input type
43
+ const result = safeParseJSON(123);
44
+ expect(result).toBeUndefined();
45
+ });
46
+
47
+ it('should parse JSON with special characters', () => {
48
+ const specialJSON = '{"message": "Hello, \\"world\\"!"}';
49
+ const result = safeParseJSON(specialJSON);
50
+ expect(result).toEqual({ message: 'Hello, "world"!' });
51
+ });
52
+
53
+ it('should parse large JSON without throwing an error', () => {
54
+ const largeJSON = JSON.stringify({ data: Array(1000).fill('test') });
55
+ const result = safeParseJSON(largeJSON);
56
+ expect(result).toHaveProperty('data');
57
+ expect(Array.isArray(result!.data)).toBe(true);
58
+ expect(result!.data).toHaveLength(1000);
59
+ });
60
+
61
+ it('should handle JSON with different data types', () => {
62
+ const mixedJSON = '{"string": "text", "number": 42, "boolean": true, "null": null}';
63
+ const result = safeParseJSON(mixedJSON);
64
+ expect(result).toEqual({
65
+ string: 'text',
66
+ number: 42,
67
+ boolean: true,
68
+ null: null,
69
+ });
70
+ });
71
+ });
@@ -0,0 +1,12 @@
1
+ export const safeParseJSON = <T = Record<string, any>>(text?: string) => {
2
+ if (typeof text !== 'string') return undefined;
3
+
4
+ let json: T;
5
+ try {
6
+ json = JSON.parse(text);
7
+ } catch {
8
+ return undefined;
9
+ }
10
+
11
+ return json;
12
+ };
@@ -1,7 +1,7 @@
1
1
  import { InvokeModelWithResponseStreamResponse } from '@aws-sdk/client-bedrock-runtime';
2
- import { nanoid } from '@lobechat/utils';
3
2
 
4
3
  import { ChatStreamCallbacks } from '../../../types';
4
+ import { nanoid } from '../../uuid';
5
5
  import { transformAnthropicStream } from '../anthropic';
6
6
  import {
7
7
  StreamContext,
@@ -1,8 +1,7 @@
1
1
  import { InvokeModelWithResponseStreamResponse } from '@aws-sdk/client-bedrock-runtime';
2
- import * as uuidModule from '@lobechat/utils';
3
- import { Readable } from 'stream';
4
2
  import { describe, expect, it, vi } from 'vitest';
5
3
 
4
+ import * as uuidModule from '../../uuid';
6
5
  import { AWSBedrockLlamaStream } from './llama';
7
6
 
8
7
  describe('AWSBedrockLlamaStream', () => {
@@ -1,7 +1,7 @@
1
1
  import { InvokeModelWithResponseStreamResponse } from '@aws-sdk/client-bedrock-runtime';
2
- import { nanoid } from '@lobechat/utils';
3
2
 
4
3
  import { ChatStreamCallbacks } from '../../../types';
4
+ import { nanoid } from '../../uuid';
5
5
  import {
6
6
  StreamContext,
7
7
  StreamProtocolChunk,
@@ -1,7 +1,7 @@
1
1
  import { GenerateContentResponse } from '@google/genai';
2
- import * as uuidModule from '@lobechat/utils';
3
2
  import { describe, expect, it, vi } from 'vitest';
4
3
 
4
+ import * as uuidModule from '../uuid';
5
5
  import { GoogleGenerativeAIStream } from './google-ai';
6
6
 
7
7
  describe('GoogleGenerativeAIStream', () => {
@@ -1,11 +1,11 @@
1
1
  import { GenerateContentResponse } from '@google/genai';
2
- import { nanoid } from '@lobechat/utils';
3
2
 
4
3
  import errorLocale from '@/locales/default/error';
5
4
  import { ModelTokensUsage } from '@/types/message';
6
5
  import { GroundingSearch } from '@/types/search';
7
6
 
8
7
  import { ChatStreamCallbacks } from '../../types';
8
+ import { nanoid } from '../uuid';
9
9
  import {
10
10
  StreamContext,
11
11
  StreamProtocolChunk,
@@ -1,7 +1,7 @@
1
- import * as uuidModule from '@lobechat/utils';
2
1
  import { ChatResponse } from 'ollama/browser';
3
2
  import { describe, expect, it, vi } from 'vitest';
4
3
 
4
+ import * as uuidModule from '../uuid';
5
5
  import { OllamaStream } from './ollama';
6
6
 
7
7
  describe('OllamaStream', () => {
@@ -1,8 +1,7 @@
1
- import { nanoid } from '@lobechat/utils';
2
1
  import { ChatResponse } from 'ollama/browser';
3
2
 
4
- import { ChatStreamCallbacks } from '@/libs/model-runtime';
5
-
3
+ import { ChatStreamCallbacks } from '../../types';
4
+ import { nanoid } from '../uuid';
6
5
  import {
7
6
  StreamContext,
8
7
  StreamProtocolChunk,
@@ -1,7 +1,6 @@
1
1
  import { describe, expect, it, vi } from 'vitest';
2
2
 
3
- import { AgentRuntimeErrorType } from '@/libs/model-runtime';
4
-
3
+ import { AgentRuntimeErrorType } from '../../../types/error';
5
4
  import { FIRST_CHUNK_ERROR_KEY } from '../protocol';
6
5
  import { OpenAIStream } from './openai';
7
6
 
@@ -3,8 +3,8 @@ import type { Stream } from 'openai/streaming';
3
3
 
4
4
  import { ChatMessageError, CitationItem } from '@/types/message';
5
5
 
6
- import { AgentRuntimeErrorType, ILobeAgentRuntimeErrorType } from '../../../error';
7
6
  import { ChatStreamCallbacks } from '../../../types';
7
+ import { AgentRuntimeErrorType, ILobeAgentRuntimeErrorType } from '../../../types/error';
8
8
  import { convertUsage } from '../../usageConverter';
9
9
  import {
10
10
  FIRST_CHUNK_ERROR_KEY,
@@ -3,7 +3,7 @@ import type { Stream } from 'openai/streaming';
3
3
 
4
4
  import { ChatMessageError, CitationItem } from '@/types/message';
5
5
 
6
- import { AgentRuntimeErrorType } from '../../../error';
6
+ import { AgentRuntimeErrorType } from '../../../types/error';
7
7
  import { convertResponseUsage } from '../../usageConverter';
8
8
  import {
9
9
  FIRST_CHUNK_ERROR_KEY,
@@ -1,10 +1,10 @@
1
- import { nanoid, safeParseJSON } from '@lobechat/utils';
2
-
3
1
  import { CitationItem, ModelSpeed, ModelTokensUsage } from '@/types/message';
4
2
 
5
- import { AgentRuntimeErrorType } from '../../error';
6
3
  import { parseToolCalls } from '../../helpers';
7
4
  import { ChatStreamCallbacks } from '../../types';
5
+ import { AgentRuntimeErrorType } from '../../types/error';
6
+ import { safeParseJSON } from '../safeParseJSON';
7
+ import { nanoid } from '../uuid';
8
8
 
9
9
  /**
10
10
  * context in the stream to save temporarily data
@@ -1,6 +1,6 @@
1
- import * as uuidModule from '@lobechat/utils';
2
1
  import { describe, expect, it, vi } from 'vitest';
3
2
 
3
+ import * as uuidModule from '../uuid';
4
4
  import { VertexAIStream } from './vertex-ai';
5
5
 
6
6
  describe('VertexAIStream', () => {
@@ -1,9 +1,9 @@
1
1
  import { GenerateContentResponse } from '@google/genai';
2
- import { nanoid } from '@lobechat/utils';
3
2
 
4
- import { ModelTokensUsage } from '@/types/message';
5
3
  import { GroundingSearch } from '@/types/search';
6
4
 
5
+ import { ModelTokensUsage } from '../../types';
6
+ import { nanoid } from '../uuid';
7
7
  import { type GoogleAIStreamOptions } from './google-ai';
8
8
  import {
9
9
  StreamContext,
@@ -0,0 +1,7 @@
1
+ // generate('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 16); //=> "4f90d13a42"
2
+ import { customAlphabet } from 'nanoid/non-secure';
3
+
4
+ export const createNanoId = (size = 8) =>
5
+ customAlphabet('1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', size);
6
+
7
+ export const nanoid = createNanoId();
@@ -1,7 +1,7 @@
1
1
  import { GoogleGenAI, GoogleGenAIOptions } from '@google/genai';
2
2
 
3
- import { AgentRuntimeErrorType } from '../error';
4
3
  import { LobeGoogleAI } from '../google';
4
+ import { AgentRuntimeErrorType } from '../types/error';
5
5
  import { AgentRuntimeError } from '../utils/createError';
6
6
 
7
7
  const DEFAULT_VERTEXAI_LOCATION = 'global';
@@ -1,6 +1,7 @@
1
+ import { LLMParams } from '../../../model-bank/src/types/aiModel';
1
2
  import { FileItem } from '../files';
2
3
  import { KnowledgeBaseItem } from '../knowledgeBase';
3
- import { FewShots, LLMParams } from '../llm';
4
+ import { FewShots } from '../llm';
4
5
  import { LobeAgentChatConfig } from './chatConfig';
5
6
 
6
7
  export type TTSServer = 'openai' | 'edge' | 'microsoft';
@@ -1,7 +1,15 @@
1
1
  import { z } from 'zod';
2
2
 
3
- import { AiModelForSelect, EnabledAiModel, ModelSearchImplementType } from './aiModel';
4
- import { ResponseAnimation } from './llm';
3
+ import { AiModelForSelect, EnabledAiModel, ModelSearchImplementType } from '../../model-bank/src/types/aiModel';
4
+
5
+ export type ResponseAnimationStyle = 'smooth' | 'fadeIn' | 'none';
6
+ export type ResponseAnimation =
7
+ | {
8
+ speed?: number;
9
+ text?: ResponseAnimationStyle;
10
+ toolsCalling?: ResponseAnimationStyle;
11
+ }
12
+ | ResponseAnimationStyle;
5
13
 
6
14
  export const AiProviderSourceEnum = {
7
15
  Builtin: 'builtin',
@@ -0,0 +1,35 @@
1
+ /* eslint-disable typescript-sort-keys/interface */
2
+ export interface ClientSecretPayload {
3
+ /**
4
+ * password
5
+ */
6
+ accessCode?: string;
7
+ /**
8
+ * Represents the user's API key
9
+ *
10
+ * If provider need multi keys like bedrock,
11
+ * this will be used as the checker whether to use frontend key
12
+ */
13
+ apiKey?: string;
14
+ /**
15
+ * Represents the endpoint of provider
16
+ */
17
+ baseURL?: string;
18
+
19
+ azureApiVersion?: string;
20
+
21
+ awsAccessKeyId?: string;
22
+ awsRegion?: string;
23
+ awsSecretAccessKey?: string;
24
+ awsSessionToken?: string;
25
+
26
+ cloudflareBaseURLOrAccountID?: string;
27
+
28
+ /**
29
+ * user id
30
+ * in client db mode it's a uuid
31
+ * in server db mode it's a user id
32
+ */
33
+ userId?: string;
34
+ }
35
+ /* eslint-enable */
@@ -1,4 +1,4 @@
1
- import { LobeDefaultAiModelListItem } from '@/types/aiModel';
1
+ import { LobeDefaultAiModelListItem } from '../../../model-bank/src/types/aiModel';
2
2
  import { ModelProviderCard } from '@/types/llm';
3
3
 
4
4
  export enum ModelSorts {
@@ -1,4 +1,4 @@
1
- import { LobeDefaultAiModelListItem } from '@/types/aiModel';
1
+ import { LobeDefaultAiModelListItem } from '../../../model-bank/src/types/aiModel';
2
2
  import { ModelProviderCard } from '@/types/llm';
3
3
 
4
4
  export enum ProviderSorts {
@@ -1,5 +1,8 @@
1
1
  export * from './agent';
2
+ export * from './aiProvider';
2
3
  export * from './artifact';
4
+ export * from './asyncTask';
5
+ export * from './auth';
3
6
  export * from './chunk';
4
7
  export * from './clientDB';
5
8
  export * from './eval';
@@ -8,6 +11,7 @@ export * from './knowledgeBase';
8
11
  export * from './llm';
9
12
  export * from './message';
10
13
  export * from './meta';
14
+ export * from './serverConfig';
11
15
  export * from './user';
12
16
  export * from './user/settings';
13
17
  // FIXME: I think we need a refactor for the "openai" types
@@ -1,10 +1,7 @@
1
- import { ModelParamsSchema } from 'model-bank';
1
+ import { ModelParamsSchema , AiModelType, Pricing } from 'model-bank';
2
2
  import { ReactNode } from 'react';
3
3
 
4
- import { AiModelType, Pricing } from '@/types/aiModel';
5
- import { AiProviderSettings } from '@/types/aiProvider';
6
-
7
- export type ModelPriceCurrency = 'CNY' | 'USD';
4
+ import { AiProviderSettings } from './aiProvider';
8
5
 
9
6
  export interface ChatModelCard {
10
7
  /**
@@ -64,15 +61,6 @@ export interface ChatModelCard {
64
61
  vision?: boolean;
65
62
  }
66
63
 
67
- export type ResponseAnimationStyle = 'smooth' | 'fadeIn' | 'none';
68
- export type ResponseAnimation =
69
- | {
70
- speed?: number;
71
- text?: ResponseAnimationStyle;
72
- toolsCalling?: ResponseAnimationStyle;
73
- }
74
- | ResponseAnimationStyle;
75
-
76
64
  export interface ModelProviderCard {
77
65
  /**
78
66
  * url to get api key
@@ -155,39 +143,6 @@ export interface ModelProviderCard {
155
143
  url: string;
156
144
  }
157
145
 
158
- // 语言模型的设置参数
159
- export interface LLMParams {
160
- /**
161
- * 控制生成文本中的惩罚系数,用于减少重复性
162
- * @default 0
163
- */
164
- frequency_penalty?: number;
165
- /**
166
- * 生成文本的最大长度
167
- */
168
- max_tokens?: number;
169
- /**
170
- * 控制生成文本中的惩罚系数,用于减少主题的变化
171
- * @default 0
172
- */
173
- presence_penalty?: number;
174
- /**
175
- * 生成文本的随机度量,用于控制文本的创造性和多样性
176
- * @default 1
177
- */
178
- reasoning_effort?: string;
179
- /**
180
- * 控制模型推理能力
181
- * @default medium
182
- */
183
- temperature?: number;
184
- /**
185
- * 控制生成文本中最高概率的单个 token
186
- * @default 1
187
- */
188
- top_p?: number;
189
- }
190
-
191
146
  export type LLMRoleType = 'user' | 'system' | 'assistant' | 'tool';
192
147
 
193
148
  export interface LLMMessage {
@@ -1,7 +1,7 @@
1
- import { LobeAgentConfig } from '@/types/agent';
2
-
1
+ import { LobeAgentConfig } from '../agent';
3
2
  import { MetaData } from '../meta';
4
- import { SessionGroupId } from './sessionGroup';
3
+
4
+ export type SessionGroupId = 'default' | 'pinned' | string;
5
5
 
6
6
  export enum LobeSessionType {
7
7
  Agent = 'agent',
@@ -1,5 +1,5 @@
1
- import { LobeSessions } from '@/types/session/agentSession';
2
- import { LobeSessionGroups, SessionGroupId } from '@/types/session/sessionGroup';
1
+ import { LobeSessions, SessionGroupId } from './agentSession';
2
+ import { LobeSessionGroups } from './sessionGroup';
3
3
 
4
4
  export * from './agentSession';
5
5
  export * from './sessionGroup';
@@ -5,8 +5,6 @@ export enum SessionDefaultGroup {
5
5
  Pinned = 'pinned',
6
6
  }
7
7
 
8
- export type SessionGroupId = SessionDefaultGroup | string;
9
-
10
8
  export interface SessionGroupItem {
11
9
  createdAt: Date;
12
10
  id: string;
@@ -1,6 +1,6 @@
1
1
  import type { HighlighterProps, MermaidProps, NeutralColors, PrimaryColors } from '@lobehub/ui';
2
2
 
3
- import { ResponseAnimationStyle } from '@/types/llm';
3
+ import type { ResponseAnimationStyle } from '../../aiProvider';
4
4
 
5
5
  export type AnimationMode = 'disabled' | 'agile' | 'elegant';
6
6
 
@@ -1,5 +1,5 @@
1
1
  import { ModelProviderKey } from '@/libs/model-runtime';
2
- import { AiFullModelCard } from '@/types/aiModel';
2
+ import { AiFullModelCard } from '../../../../model-bank/src/types/aiModel';
3
3
  import { ChatModelCard } from '@/types/llm';
4
4
 
5
5
  export interface ProviderConfig {
@@ -3,7 +3,7 @@ import { ChatErrorType } from '@lobechat/types';
3
3
 
4
4
  import { MESSAGE_CANCEL_FLAT } from '@/const/message';
5
5
  import { LOBE_CHAT_OBSERVATION_ID, LOBE_CHAT_TRACE_ID } from '@/const/trace';
6
- import { ResponseAnimation, ResponseAnimationStyle } from '@/types/llm';
6
+ import { ResponseAnimation, ResponseAnimationStyle } from '@lobechat/types';
7
7
  import {
8
8
  ChatMessageError,
9
9
  MessageToolCall,
@@ -1,10 +1,9 @@
1
+ import { USD_TO_CNY } from '@lobechat/const';
1
2
  import dayjs from 'dayjs';
2
3
  import { isNumber } from 'lodash-es';
4
+ import { ModelPriceCurrency } from 'model-bank';
3
5
  import numeral from 'numeral';
4
6
 
5
- import { USD_TO_CNY } from '@/const/currency';
6
- import { ModelPriceCurrency } from '@/types/llm';
7
-
8
7
  export const formatSize = (bytes: number, fractionDigits: number = 1): string => {
9
8
  if (!bytes && bytes !== 0) return '--';
10
9
 
@@ -1,5 +1,7 @@
1
1
  export * from './client/cookie';
2
- export * from './getFallbackModelProperty';
2
+ export * from './format';
3
3
  export * from './imageToBase64';
4
+ export * from './parseModels';
5
+ export * from './pricing';
4
6
  export * from './safeParseJSON';
5
7
  export * from './uuid';