@lobehub/chat 1.142.0 → 1.142.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 (210) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/Dockerfile +3 -3
  3. package/Dockerfile.database +3 -3
  4. package/Dockerfile.pglite +3 -3
  5. package/README.md +1 -1
  6. package/README.zh-CN.md +1 -1
  7. package/changelog/v1.json +18 -0
  8. package/docs/self-hosting/advanced/model-list.mdx +11 -0
  9. package/docs/self-hosting/advanced/model-list.zh-CN.mdx +11 -0
  10. package/docs/self-hosting/environment-variables/model-provider.mdx +23 -14
  11. package/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx +23 -14
  12. package/docs/usage/providers/aihubmix.zh-CN.mdx +1 -4
  13. package/locales/ar/models.json +17 -8
  14. package/locales/bg-BG/models.json +17 -8
  15. package/locales/de-DE/models.json +17 -8
  16. package/locales/en-US/models.json +17 -8
  17. package/locales/es-ES/models.json +17 -8
  18. package/locales/fa-IR/models.json +17 -8
  19. package/locales/fr-FR/models.json +17 -8
  20. package/locales/it-IT/models.json +17 -8
  21. package/locales/ja-JP/models.json +17 -8
  22. package/locales/ko-KR/models.json +17 -8
  23. package/locales/nl-NL/models.json +17 -8
  24. package/locales/pl-PL/models.json +17 -8
  25. package/locales/pt-BR/models.json +17 -8
  26. package/locales/ru-RU/models.json +17 -8
  27. package/locales/tr-TR/models.json +17 -8
  28. package/locales/vi-VN/models.json +17 -8
  29. package/locales/zh-CN/models.json +17 -8
  30. package/locales/zh-TW/models.json +17 -8
  31. package/package.json +2 -2
  32. package/packages/context-engine/src/processors/__tests__/MessageContent.test.ts +17 -17
  33. package/packages/context-engine/src/types.ts +4 -4
  34. package/packages/database/src/models/__tests__/generation.test.ts +2 -2
  35. package/packages/database/src/models/__tests__/generationBatch.test.ts +1 -1
  36. package/packages/database/src/models/__tests__/generationTopic.test.ts +2 -4
  37. package/packages/database/src/models/__tests__/message.test.ts +2 -2
  38. package/packages/database/src/models/asyncTask.ts +3 -4
  39. package/packages/database/src/models/chatGroup.ts +2 -2
  40. package/packages/database/src/models/chunk.ts +2 -3
  41. package/packages/database/src/models/drizzleMigration.ts +1 -1
  42. package/packages/database/src/models/file.ts +1 -2
  43. package/packages/database/src/models/generation.ts +8 -4
  44. package/packages/database/src/models/generationBatch.ts +1 -1
  45. package/packages/database/src/models/generationTopic.ts +2 -2
  46. package/packages/database/src/models/knowledgeBase.ts +2 -3
  47. package/packages/database/src/models/message.ts +9 -9
  48. package/packages/database/src/models/session.ts +8 -10
  49. package/packages/database/src/models/thread.ts +2 -3
  50. package/packages/database/src/models/topic.ts +2 -4
  51. package/packages/database/src/models/user.ts +1 -2
  52. package/packages/database/src/schemas/generation.ts +1 -2
  53. package/packages/database/src/schemas/message.ts +1 -3
  54. package/packages/model-runtime/src/core/streams/anthropic.ts +1 -2
  55. package/packages/model-runtime/src/core/streams/protocol.ts +1 -2
  56. package/packages/model-runtime/src/core/usageConverters/anthropic.ts +1 -2
  57. package/packages/model-runtime/src/core/usageConverters/google-ai.ts +1 -2
  58. package/packages/model-runtime/src/core/usageConverters/utils/computeChatCost.test.ts +1 -2
  59. package/packages/model-runtime/src/core/usageConverters/utils/computeChatCost.ts +1 -2
  60. package/packages/model-runtime/src/core/usageConverters/utils/withUsageCost.ts +1 -2
  61. package/packages/model-runtime/src/types/image.ts +1 -2
  62. package/packages/prompts/src/chains/__tests__/summaryHistory.test.ts +2 -2
  63. package/packages/prompts/src/chains/summaryHistory.ts +2 -2
  64. package/packages/prompts/src/chains/summaryTitle.ts +2 -3
  65. package/packages/prompts/src/contexts/supervisor/makeDecision.ts +2 -2
  66. package/packages/prompts/src/prompts/chatMessages/index.test.ts +11 -11
  67. package/packages/prompts/src/prompts/chatMessages/index.ts +13 -10
  68. package/packages/prompts/src/prompts/groupChat/index.test.ts +3 -4
  69. package/packages/prompts/src/prompts/groupChat/index.ts +3 -3
  70. package/packages/types/src/aiChat.ts +2 -2
  71. package/packages/types/src/exportConfig.ts +6 -6
  72. package/packages/types/src/importer.ts +2 -2
  73. package/packages/types/src/index.ts +2 -0
  74. package/packages/types/src/message/common/base.ts +27 -0
  75. package/packages/types/src/message/common/index.ts +5 -0
  76. package/packages/types/src/message/common/metadata.ts +67 -0
  77. package/packages/types/src/message/{tools.ts → common/tools.ts} +1 -1
  78. package/packages/types/src/message/common/translate.ts +8 -0
  79. package/packages/types/src/message/db/index.ts +2 -0
  80. package/packages/types/src/message/db/item.ts +29 -0
  81. package/packages/types/src/message/db/params.ts +57 -0
  82. package/packages/types/src/message/index.ts +3 -6
  83. package/packages/types/src/message/{chat.ts → ui/chat.ts} +13 -40
  84. package/packages/types/src/message/ui/extra.ts +16 -0
  85. package/packages/types/src/message/ui/index.ts +4 -0
  86. package/packages/types/src/message/{rag.ts → ui/rag.ts} +11 -1
  87. package/src/app/[variants]/(main)/chat/(workspace)/@conversation/features/ChatInput/V1Mobile/useSend.ts +1 -1
  88. package/src/app/[variants]/(main)/chat/(workspace)/features/ShareButton/index.tsx +0 -3
  89. package/src/app/[variants]/(main)/profile/stats/features/ModelsRank.tsx +1 -1
  90. package/src/app/[variants]/(main)/settings/llm/components/Checker.tsx +1 -2
  91. package/src/app/[variants]/(main)/settings/provider/detail/ollama/CheckError.tsx +1 -2
  92. package/src/app/[variants]/(main)/settings/provider/features/CreateNewProvider/index.tsx +1 -2
  93. package/src/app/[variants]/(main)/settings/provider/features/ProviderConfig/Checker.tsx +1 -2
  94. package/src/database/_deprecated/models/__tests__/message.test.ts +6 -7
  95. package/src/database/_deprecated/models/message.ts +13 -13
  96. package/src/features/AgentSetting/AgentTTS/SelectWithTTSPreview.tsx +1 -1
  97. package/src/features/ChatInput/ActionBar/STT/browser.tsx +1 -1
  98. package/src/features/ChatInput/ActionBar/STT/common.tsx +1 -2
  99. package/src/features/ChatInput/ActionBar/STT/openai.tsx +1 -1
  100. package/src/features/ChatItem/components/ErrorContent.tsx +5 -0
  101. package/src/features/Conversation/Error/ErrorJsonViewer.tsx +1 -2
  102. package/src/features/Conversation/Error/OllamaBizError/index.tsx +2 -3
  103. package/src/features/Conversation/Error/index.tsx +3 -4
  104. package/src/features/Conversation/Error/style.tsx +5 -1
  105. package/src/features/Conversation/Messages/Assistant/Actions/index.tsx +2 -2
  106. package/src/features/Conversation/Messages/Assistant/Block.tsx +1 -1
  107. package/src/features/Conversation/Messages/Assistant/Extra/index.test.tsx +2 -2
  108. package/src/features/Conversation/Messages/Assistant/Extra/index.tsx +1 -1
  109. package/src/features/Conversation/Messages/Assistant/FileChunks/Item/index.tsx +1 -1
  110. package/src/features/Conversation/Messages/Assistant/FileChunks/index.tsx +1 -2
  111. package/src/features/Conversation/Messages/Assistant/MessageContent.tsx +2 -2
  112. package/src/features/Conversation/Messages/Assistant/Tool/Render/CustomRender.tsx +2 -2
  113. package/src/features/Conversation/Messages/Assistant/Tool/Render/ErrorResponse.tsx +1 -2
  114. package/src/features/Conversation/Messages/Assistant/Tool/Render/PluginSettings.tsx +1 -1
  115. package/src/features/Conversation/Messages/Assistant/index.tsx +2 -2
  116. package/src/features/Conversation/Messages/Default.tsx +3 -3
  117. package/src/features/Conversation/Messages/Supervisor/index.tsx +2 -2
  118. package/src/features/Conversation/Messages/User/Actions.tsx +2 -2
  119. package/src/features/Conversation/Messages/User/FileListViewer/Item.tsx +1 -1
  120. package/src/features/Conversation/Messages/User/FileListViewer/index.tsx +1 -2
  121. package/src/features/Conversation/Messages/User/MessageContent.tsx +2 -3
  122. package/src/features/Conversation/Messages/User/VideoFileListViewer.tsx +1 -2
  123. package/src/features/Conversation/Messages/User/index.tsx +2 -2
  124. package/src/features/Conversation/components/ChatItem/ShareMessageModal/SharePdf/index.tsx +2 -2
  125. package/src/features/Conversation/components/ChatItem/ShareMessageModal/SharePdf/template.ts +2 -2
  126. package/src/features/Conversation/components/Extras/TTS/InitPlayer.tsx +1 -1
  127. package/src/features/Conversation/components/Extras/TTS/Player.tsx +1 -2
  128. package/src/features/Conversation/components/Extras/Translate.tsx +1 -1
  129. package/src/features/Conversation/components/Extras/Usage/UsageDetail/index.tsx +1 -1
  130. package/src/features/Conversation/components/Extras/Usage/UsageDetail/tokens.ts +1 -1
  131. package/src/features/Conversation/components/Extras/Usage/index.tsx +1 -2
  132. package/src/features/Conversation/components/ShareMessageModal/ShareImage/Preview.tsx +2 -2
  133. package/src/features/Conversation/components/ShareMessageModal/ShareImage/index.tsx +2 -2
  134. package/src/features/Conversation/components/ShareMessageModal/ShareText/index.tsx +2 -2
  135. package/src/features/Conversation/components/ShareMessageModal/ShareText/template.test.ts +3 -3
  136. package/src/features/Conversation/components/ShareMessageModal/ShareText/template.ts +2 -2
  137. package/src/features/Conversation/components/ShareMessageModal/index.tsx +3 -3
  138. package/src/features/Conversation/types/index.ts +5 -5
  139. package/src/features/Portal/Home/Body/Files/FileList/Item.tsx +1 -1
  140. package/src/features/Portal/Home/Body/Plugins/ArtifactList/Item/index.tsx +1 -1
  141. package/src/features/Portal/Thread/Chat/ChatInput/useSend.ts +1 -1
  142. package/src/features/ShareModal/ShareJSON/generateMessages.test.ts +3 -3
  143. package/src/features/ShareModal/ShareJSON/generateMessages.ts +3 -2
  144. package/src/features/ShareModal/SharePdf/index.tsx +2 -2
  145. package/src/features/ShareModal/ShareText/template.test.ts +3 -3
  146. package/src/features/ShareModal/ShareText/template.ts +2 -2
  147. package/src/libs/langchain/loaders/code/__tests__/long.json +1 -1
  148. package/src/libs/langchain/loaders/code/__tests__/long.txt +1 -1
  149. package/src/server/routers/lambda/__tests__/message.test.ts +2 -3
  150. package/src/server/routers/lambda/message.ts +2 -4
  151. package/src/services/chat/chat.test.ts +27 -25
  152. package/src/services/chat/contextEngineering.test.ts +21 -21
  153. package/src/services/chat/contextEngineering.ts +2 -2
  154. package/src/services/chat/index.ts +5 -8
  155. package/src/services/message/_deprecated.test.ts +7 -7
  156. package/src/services/message/_deprecated.ts +10 -10
  157. package/src/services/message/client.test.ts +10 -10
  158. package/src/services/message/client.ts +6 -5
  159. package/src/services/message/server.ts +4 -3
  160. package/src/services/message/type.ts +10 -11
  161. package/src/services/thread/type.ts +2 -1
  162. package/src/store/chat/helpers.test.ts +5 -5
  163. package/src/store/chat/helpers.ts +5 -5
  164. package/src/store/chat/initialState.ts +0 -3
  165. package/src/store/chat/slices/aiChat/actions/__tests__/fixtures.ts +5 -4
  166. package/src/store/chat/slices/aiChat/actions/__tests__/generateAIChatV2.test.ts +4 -4
  167. package/src/store/chat/slices/aiChat/actions/__tests__/rag.test.ts +6 -6
  168. package/src/store/chat/slices/aiChat/actions/generateAIChat.ts +17 -12
  169. package/src/store/chat/slices/aiChat/actions/generateAIChatV2.ts +7 -8
  170. package/src/store/chat/slices/aiChat/actions/generateAIGroupChat.ts +10 -6
  171. package/src/store/chat/slices/aiChat/actions/memory.ts +2 -3
  172. package/src/store/chat/slices/builtinTool/actions/__tests__/dalle.test.ts +3 -3
  173. package/src/store/chat/slices/builtinTool/actions/__tests__/search.test.ts +3 -3
  174. package/src/store/chat/slices/message/action.test.ts +13 -8
  175. package/src/store/chat/slices/message/action.ts +19 -18
  176. package/src/store/chat/slices/message/initialState.ts +3 -2
  177. package/src/store/chat/slices/message/reducer.test.ts +6 -6
  178. package/src/store/chat/slices/message/reducer.ts +11 -8
  179. package/src/store/chat/slices/message/selectors.test.ts +9 -9
  180. package/src/store/chat/slices/message/selectors.ts +10 -9
  181. package/src/store/chat/slices/message/supervisor.ts +2 -2
  182. package/src/store/chat/slices/plugin/action.test.ts +16 -13
  183. package/src/store/chat/slices/plugin/action.ts +11 -11
  184. package/src/store/chat/slices/portal/selectors.test.ts +8 -8
  185. package/src/store/chat/slices/thread/action.test.ts +2 -2
  186. package/src/store/chat/slices/thread/action.ts +9 -5
  187. package/src/store/chat/slices/thread/selectors/index.ts +11 -11
  188. package/src/store/chat/slices/thread/selectors/util.ts +2 -3
  189. package/src/store/chat/slices/topic/action.test.ts +6 -6
  190. package/src/store/chat/slices/topic/action.ts +2 -3
  191. package/src/store/chat/slices/translate/action.ts +2 -3
  192. package/src/store/chat/slices/tts/action.ts +1 -1
  193. package/src/store/chat/store.ts +0 -3
  194. package/src/store/image/slices/createImage/action.test.ts +9 -2
  195. package/src/store/image/slices/createImage/action.ts +6 -4
  196. package/src/tools/local-system/Render/ListFiles/Result.tsx +1 -1
  197. package/src/tools/local-system/Render/ListFiles/index.tsx +1 -1
  198. package/src/tools/local-system/Render/ReadLocalFile/index.tsx +1 -1
  199. package/src/tools/local-system/Render/RenameLocalFile/index.tsx +1 -1
  200. package/src/tools/local-system/Render/RunCommand/index.tsx +1 -1
  201. package/src/tools/local-system/Render/SearchFiles/index.tsx +1 -1
  202. package/src/tools/local-system/Render/WriteFile/index.tsx +1 -1
  203. package/src/tools/web-browsing/Render/Search/index.tsx +1 -3
  204. package/packages/types/src/message/base.ts +0 -173
  205. package/packages/types/src/message/translate.ts +0 -4
  206. package/src/store/chat/slices/share/action.test.ts +0 -22
  207. package/src/store/chat/slices/share/action.ts +0 -18
  208. package/src/store/chat/slices/share/initialState.ts +0 -7
  209. /package/packages/types/src/message/{image.ts → common/image.ts} +0 -0
  210. /package/packages/types/src/message/{video.ts → ui/video.ts} +0 -0
@@ -1,7 +1,6 @@
1
+ import { ChatCitationItem, ModelSpeed, ModelUsage } from '@lobechat/types';
1
2
  import type { Pricing } from 'model-bank';
2
3
 
3
- import { ChatCitationItem, ModelSpeed, ModelUsage } from '@/types/message';
4
-
5
4
  import { parseToolCalls } from '../../helpers';
6
5
  import { ChatStreamCallbacks } from '../../types';
7
6
  import { AgentRuntimeErrorType } from '../../types/error';
@@ -1,6 +1,5 @@
1
1
  import Anthropic from '@anthropic-ai/sdk';
2
-
3
- import { ModelUsage } from '@/types/message';
2
+ import { ModelUsage } from '@lobechat/types';
4
3
 
5
4
  import { ChatPayloadForTransformStream } from '../streams/protocol';
6
5
  import { withUsageCost } from './utils/withUsageCost';
@@ -3,10 +3,9 @@ import {
3
3
  MediaModality,
4
4
  ModalityTokenCount,
5
5
  } from '@google/genai';
6
+ import { ModelUsage } from '@lobechat/types';
6
7
  import type { Pricing } from 'model-bank';
7
8
 
8
- import { ModelUsage } from '@/types/message';
9
-
10
9
  import { withUsageCost } from './utils/withUsageCost';
11
10
 
12
11
  const getTokenCount = (details: ModalityTokenCount[] | undefined, modality: MediaModality) => {
@@ -1,3 +1,4 @@
1
+ import { ModelTokensUsage } from '@lobechat/types';
1
2
  import { Pricing } from 'model-bank';
2
3
  import anthropicChatModels from 'model-bank/anthropic';
3
4
  import googleChatModels from 'model-bank/google';
@@ -5,8 +6,6 @@ import lobehubChatModels from 'model-bank/lobehub';
5
6
  import openaiChatModels from 'model-bank/openai';
6
7
  import { describe, expect, it } from 'vitest';
7
8
 
8
- import { ModelTokensUsage } from '@/types/message';
9
-
10
9
  import { computeChatCost } from './computeChatCost';
11
10
 
12
11
  describe('computeChatPricing', () => {
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable sort-keys-fix/sort-keys-fix */
2
2
  import { CREDITS_PER_DOLLAR, USD_TO_CNY } from '@lobechat/const/currency';
3
+ import { ModelTokensUsage } from '@lobechat/types';
3
4
  import debug from 'debug';
4
5
  import {
5
6
  FixedPricingUnit,
@@ -10,8 +11,6 @@ import {
10
11
  TieredPricingUnit,
11
12
  } from 'model-bank';
12
13
 
13
- import { ModelTokensUsage } from '@/types/message';
14
-
15
14
  const log = debug('lobe-cost:computeChatPricing');
16
15
 
17
16
  export interface PricingUnitBreakdown {
@@ -1,7 +1,6 @@
1
+ import type { ModelUsage } from '@lobechat/types';
1
2
  import type { Pricing } from 'model-bank';
2
3
 
3
- import type { ModelUsage } from '@/types/message';
4
-
5
4
  import { computeChatCost } from './computeChatCost';
6
5
  import type { ComputeChatCostOptions } from './computeChatCost';
7
6
 
@@ -1,8 +1,7 @@
1
1
  /* eslint-disable typescript-sort-keys/interface */
2
+ import { ModelUsage } from '@lobechat/types';
2
3
  import { RuntimeImageGenParams } from 'model-bank';
3
4
 
4
- import { ModelUsage } from '@/types/message';
5
-
6
5
  export type CreateImagePayload = {
7
6
  model: string;
8
7
  params: RuntimeImageGenParams;
@@ -1,4 +1,4 @@
1
- import { ChatMessage } from '@lobechat/types';
1
+ import { UIChatMessage } from '@lobechat/types';
2
2
  import { Mock, describe, expect, it, vi } from 'vitest';
3
3
 
4
4
  import { chainSummaryHistory } from '../summaryHistory';
@@ -9,7 +9,7 @@ describe('chainSummaryHistory', () => {
9
9
  const messages = [
10
10
  { content: 'Hello, how can I assist you?', role: 'assistant' },
11
11
  { content: 'I need help with my account.', role: 'user' },
12
- ] as ChatMessage[];
12
+ ] as UIChatMessage[];
13
13
 
14
14
  // Act
15
15
  const result = chainSummaryHistory(messages);
@@ -1,8 +1,8 @@
1
- import { ChatMessage, ChatStreamPayload } from '@lobechat/types';
1
+ import { ChatStreamPayload, UIChatMessage } from '@lobechat/types';
2
2
 
3
3
  import { chatHistoryPrompts } from '../prompts';
4
4
 
5
- export const chainSummaryHistory = (messages: ChatMessage[]): Partial<ChatStreamPayload> => ({
5
+ export const chainSummaryHistory = (messages: UIChatMessage[]): Partial<ChatStreamPayload> => ({
6
6
  messages: [
7
7
  {
8
8
  content: `You're an assistant who's good at extracting key takeaways from conversations and summarizing them. Please summarize according to the user's needs. The content you need to summarize is located in the <chat_history> </chat_history> group of xml tags. The summary needs to maintain the original language.`,
@@ -1,8 +1,7 @@
1
- import { ChatMessage } from '@/types/message/chat';
2
- import { ChatStreamPayload, OpenAIChatMessage } from '@/types/openai/chat';
1
+ import { ChatStreamPayload, OpenAIChatMessage, UIChatMessage } from '@lobechat/types';
3
2
 
4
3
  export const chainSummaryTitle = (
5
- messages: (ChatMessage | OpenAIChatMessage)[],
4
+ messages: (UIChatMessage | OpenAIChatMessage)[],
6
5
  locale: string,
7
6
  ): Partial<ChatStreamPayload> => ({
8
7
  messages: [
@@ -1,4 +1,4 @@
1
- import { ChatCompletionTool, ChatMessage, ChatStreamPayload } from '@lobechat/types';
1
+ import { ChatCompletionTool, ChatStreamPayload, UIChatMessage } from '@lobechat/types';
2
2
 
3
3
  import { groupChatPrompts, groupSupervisorPrompts } from '../../prompts';
4
4
  import { SupervisorToolName, SupervisorTools } from './tools';
@@ -17,7 +17,7 @@ interface AgentItem {
17
17
  export interface SupervisorContext {
18
18
  allowDM?: boolean;
19
19
  availableAgents: AgentItem[];
20
- messages: ChatMessage[];
20
+ messages: UIChatMessage[];
21
21
  // Group scene controls which tools are exposed (e.g., todos only in 'productive')
22
22
  scene?: 'casual' | 'productive';
23
23
  systemPrompt?: string;
@@ -1,4 +1,4 @@
1
- import { ChatMessage } from '@lobechat/types';
1
+ import { UIChatMessage } from '@lobechat/types';
2
2
  import { describe, expect, it } from 'vitest';
3
3
 
4
4
  import {
@@ -10,8 +10,8 @@ import {
10
10
 
11
11
  let messageCounter = 0;
12
12
  const createMessage = (
13
- overrides: Partial<ChatMessage> & Pick<ChatMessage, 'role' | 'content'>,
14
- ): ChatMessage => ({
13
+ overrides: Partial<UIChatMessage> & Pick<UIChatMessage, 'role' | 'content'>,
14
+ ): UIChatMessage => ({
15
15
  id: overrides.id ?? `msg-${++messageCounter}`,
16
16
  createdAt: overrides.createdAt ?? 0,
17
17
  updatedAt: overrides.updatedAt ?? 0,
@@ -22,7 +22,7 @@ const createMessage = (
22
22
  describe('chatHistoryPrompts', () => {
23
23
  // Test with empty messages array
24
24
  it('should return empty chat history with empty messages', () => {
25
- const messages: ChatMessage[] = [];
25
+ const messages: UIChatMessage[] = [];
26
26
  const result = chatHistoryPrompts(messages);
27
27
 
28
28
  expect(result).toBe(`<chat_history>
@@ -37,7 +37,7 @@ describe('chatHistoryPrompts', () => {
37
37
  role: 'user',
38
38
  content: 'Hello',
39
39
  },
40
- ] as ChatMessage[];
40
+ ] as UIChatMessage[];
41
41
  const result = chatHistoryPrompts(messages);
42
42
 
43
43
  expect(result).toBe(`<chat_history>
@@ -60,7 +60,7 @@ describe('chatHistoryPrompts', () => {
60
60
  role: 'user',
61
61
  content: 'How are you?',
62
62
  },
63
- ] as ChatMessage[];
63
+ ] as UIChatMessage[];
64
64
  const result = chatHistoryPrompts(messages);
65
65
 
66
66
  expect(result).toBe(`<chat_history>
@@ -81,7 +81,7 @@ describe('chatHistoryPrompts', () => {
81
81
  role: 'assistant',
82
82
  content: '<test> & </test>',
83
83
  },
84
- ] as ChatMessage[];
84
+ ] as UIChatMessage[];
85
85
 
86
86
  const result = chatHistoryPrompts(messages);
87
87
 
@@ -98,7 +98,7 @@ describe('chatHistoryPrompts', () => {
98
98
  role: 'user',
99
99
  content: 'Line 1\nLine 2',
100
100
  },
101
- ] as ChatMessage[];
101
+ ] as UIChatMessage[];
102
102
 
103
103
  const result = chatHistoryPrompts(messages);
104
104
 
@@ -110,7 +110,7 @@ describe('chatHistoryPrompts', () => {
110
110
 
111
111
  describe('groupSupervisorPrompts', () => {
112
112
  it('should format messages and exclude supervisor role', () => {
113
- const messages: ChatMessage[] = [
113
+ const messages: UIChatMessage[] = [
114
114
  createMessage({ role: 'user', content: 'Hello everyone' }),
115
115
  createMessage({ role: 'assistant', agentId: 'agent-1', content: 'Reporting in' }),
116
116
  createMessage({
@@ -136,7 +136,7 @@ describe('groupSupervisorPrompts', () => {
136
136
 
137
137
  describe('groupMemeberSpeakingPrompts', () => {
138
138
  it('should wrap messages in chat_group tags', () => {
139
- const messages: ChatMessage[] = [
139
+ const messages: UIChatMessage[] = [
140
140
  createMessage({ role: 'user', content: 'Need assistance' }),
141
141
  createMessage({ role: 'assistant', content: 'On it!' }),
142
142
  ];
@@ -156,7 +156,7 @@ describe('consolidateGroupChatHistory', () => {
156
156
  });
157
157
 
158
158
  it('should format messages with agent titles and default labels', () => {
159
- const messages: ChatMessage[] = [
159
+ const messages: UIChatMessage[] = [
160
160
  createMessage({ role: 'assistant', content: ' ' }), // filtered out
161
161
  createMessage({ role: 'user', content: 'Hello group' }),
162
162
  createMessage({ role: 'assistant', agentId: 'agent-1', content: 'Status update' }),
@@ -1,17 +1,17 @@
1
- import { ChatMessage } from '@lobechat/types';
1
+ import { UIChatMessage } from '@lobechat/types';
2
2
 
3
- const chatMessage = (message: ChatMessage) => {
3
+ const chatMessage = (message: UIChatMessage) => {
4
4
  return `<${message.role}>${message.content}</${message.role}>`;
5
5
  };
6
6
 
7
- export const chatHistoryPrompts = (messages: ChatMessage[]) => {
7
+ export const chatHistoryPrompts = (messages: UIChatMessage[]) => {
8
8
  return `<chat_history>
9
9
  ${messages.map((m) => chatMessage(m)).join('\n')}
10
10
  </chat_history>`;
11
11
  };
12
12
 
13
- export const groupSupervisorPrompts = (messages: ChatMessage[]) => {
14
- const formatMessage = (message: ChatMessage) => {
13
+ export const groupSupervisorPrompts = (messages: UIChatMessage[]) => {
14
+ const formatMessage = (message: UIChatMessage) => {
15
15
  const author = message.role === 'user' ? 'user' : message.agentId || 'assistant';
16
16
  const targetAttr = message.targetId ? ` target="${message.targetId}"` : '';
17
17
  return `<message author="${author}"${targetAttr}>${message.content}</message>`;
@@ -23,7 +23,7 @@ export const groupSupervisorPrompts = (messages: ChatMessage[]) => {
23
23
  return filteredMessages.map((m) => formatMessage(m)).join('\n');
24
24
  };
25
25
 
26
- export const groupMemeberSpeakingPrompts = (messages: ChatMessage[]) => {
26
+ export const groupMemeberSpeakingPrompts = (messages: UIChatMessage[]) => {
27
27
  return `<chat_group>
28
28
  ${messages.map((m) => chatMessage(m)).join('\n')}
29
29
  </chat_group>`;
@@ -36,10 +36,13 @@ ${messages.map((m) => chatMessage(m)).join('\n')}
36
36
  * - Agent sees DMs they sent
37
37
  * - Agent sees user messages that are group messages or targeted to them
38
38
  * - For DM messages not involving the agent, content is replaced with "***"
39
- *
39
+ *
40
40
  * TODO: Use context engineering to filter messages
41
41
  */
42
- export const filterMessagesForAgent = (messages: ChatMessage[], agentId: string): ChatMessage[] => {
42
+ export const filterMessagesForAgent = (
43
+ messages: UIChatMessage[],
44
+ agentId: string,
45
+ ): UIChatMessage[] => {
43
46
  return messages
44
47
  .filter((message) => {
45
48
  // Exclude supervisor messages (messages with role="supervisor")
@@ -107,7 +110,7 @@ export const filterMessagesForAgent = (messages: ChatMessage[], agentId: string)
107
110
  * for use in system messages. Each message is formatted as "(AuthorName): content"
108
111
  */
109
112
  export const consolidateGroupChatHistory = (
110
- messages: ChatMessage[],
113
+ messages: UIChatMessage[],
111
114
  agents: { id: string; title: string }[] = [],
112
115
  ) => {
113
116
  if (messages.length === 0) return '';
@@ -115,7 +118,7 @@ export const consolidateGroupChatHistory = (
115
118
  // Create a map for quick agent lookup
116
119
  const agentMap = new Map(agents.map((agent) => [agent.id, agent.title]));
117
120
 
118
- const formatMessage = (message: ChatMessage) => {
121
+ const formatMessage = (message: UIChatMessage) => {
119
122
  let authorName: string;
120
123
 
121
124
  if (message.role === 'user') {
@@ -1,7 +1,6 @@
1
+ import type { UIChatMessage } from '@lobechat/types';
1
2
  import { beforeEach, describe, expect, it, vi } from 'vitest';
2
3
 
3
- import type { ChatMessage } from '@/types/index';
4
-
5
4
  import { filterMessagesForAgent } from '../chatMessages';
6
5
  import { buildGroupChatSystemPrompt } from './index';
7
6
 
@@ -13,7 +12,7 @@ describe('buildGroupChatSystemPrompt', () => {
13
12
  vi.spyOn(Date, 'now').mockReturnValue(mockTimestamp);
14
13
  });
15
14
 
16
- const messages: ChatMessage[] = [
15
+ const messages: UIChatMessage[] = [
17
16
  {
18
17
  id: 'm1',
19
18
  role: 'user',
@@ -109,7 +108,7 @@ describe('filterMessagesForAgent', () => {
109
108
  role: 'user' | 'assistant' | 'system',
110
109
  content: string,
111
110
  options?: { agentId?: string; targetId?: string },
112
- ): ChatMessage => ({
111
+ ): UIChatMessage => ({
113
112
  id,
114
113
  role,
115
114
  content,
@@ -1,4 +1,4 @@
1
- import { ChatMessage } from '@/types/index';
1
+ import { UIChatMessage } from '@lobechat/types';
2
2
 
3
3
  export interface GroupMemberInfo {
4
4
  id: string;
@@ -27,7 +27,7 @@ export const buildGroupChatSystemPrompt = ({
27
27
  baseSystemRole?: string;
28
28
  groupMembers: GroupMemberInfo[];
29
29
  instruction?: string;
30
- messages: ChatMessage[];
30
+ messages: UIChatMessage[];
31
31
  targetId?: string;
32
32
  }): string => {
33
33
  const membersTag = buildGroupMembersTag(groupMembers);
@@ -138,7 +138,7 @@ RULES:
138
138
  WHEN ASKING AGENTS TO SPEAK:
139
139
 
140
140
  - Only reference agents from the member list. Never invent new IDs.
141
- - Do not excessivly gathering information from user, you should only ask for information when it's necessary.
141
+ - Do not excessivly gathering information from user, you should only ask for information when it's necessary.
142
142
  - If need many information from user, make single agent to ask for all.
143
143
  ${dmRules}
144
144
 
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
2
 
3
- import { ChatMessage } from './message';
3
+ import { UIChatMessage } from './message';
4
4
  import { OpenAIChatMessage } from './openai/chat';
5
5
  import { LobeUniformTool, LobeUniformToolSchema } from './tool';
6
6
  import { ChatTopic } from './topic';
@@ -50,7 +50,7 @@ export const AiSendMessageServerSchema = z.object({
50
50
  export interface SendMessageServerResponse {
51
51
  assistantMessageId: string;
52
52
  isCreateNewTopic: boolean;
53
- messages: ChatMessage[];
53
+ messages: UIChatMessage[];
54
54
  topicId: string;
55
55
  topics?: ChatTopic[];
56
56
  userMessageId: string;
@@ -1,7 +1,7 @@
1
- import { ChatMessage } from '@/types/message';
2
- import { LobeSessions, SessionGroupItem } from '@/types/session';
3
- import { ChatTopic } from '@/types/topic';
4
- import { UserSettings } from '@/types/user/settings';
1
+ import { UIChatMessage } from './message';
2
+ import { LobeSessions, SessionGroupItem } from './session';
3
+ import { ChatTopic } from './topic';
4
+ import { UserSettings } from './user/settings';
5
5
 
6
6
  // ---------- TODO: this file need to be deleted in V2 ---------- //
7
7
 
@@ -44,7 +44,7 @@ export interface ConfigModelMap {
44
44
  * 配置状态:会话
45
45
  */
46
46
  export interface ConfigStateSessions {
47
- messages: ChatMessage[];
47
+ messages: UIChatMessage[];
48
48
  sessionGroups: SessionGroupItem[];
49
49
  sessions: LobeSessions;
50
50
  topics: ChatTopic[];
@@ -54,7 +54,7 @@ export interface ConfigStateSessions {
54
54
  * 配置状态:单个会话
55
55
  */
56
56
  export interface ConfigStateSingleSession {
57
- messages: ChatMessage[];
57
+ messages: UIChatMessage[];
58
58
  sessions: LobeSessions;
59
59
  topics: ChatTopic[];
60
60
  }
@@ -5,7 +5,7 @@ import {
5
5
  ChatTTS,
6
6
  ChatToolPayload,
7
7
  ChatTranslate,
8
- MessageRoleType,
8
+ UIMessageRoleType,
9
9
  } from './message';
10
10
  import { MetaData } from './meta';
11
11
  import { SessionGroupId } from './session';
@@ -51,7 +51,7 @@ export interface ImportMessage {
51
51
  pluginState?: any;
52
52
 
53
53
  quotaId?: string;
54
- role: MessageRoleType;
54
+ role: UIMessageRoleType;
55
55
 
56
56
  sessionId?: string;
57
57
  tool_call_id?: string;
@@ -11,6 +11,7 @@ export * from './discover';
11
11
  export * from './eval';
12
12
  export * from './fetch';
13
13
  export * from './files';
14
+ export * from './generation';
14
15
  export * from './hotkey';
15
16
  export * from './knowledgeBase';
16
17
  export * from './llm';
@@ -20,6 +21,7 @@ export * from './plugins';
20
21
  export * from './rag';
21
22
  export * from './search';
22
23
  export * from './serverConfig';
24
+ export * from './service';
23
25
  export * from './session';
24
26
  export * from './tool';
25
27
  export * from './topic';
@@ -0,0 +1,27 @@
1
+ /* eslint-disable sort-keys-fix/sort-keys-fix , typescript-sort-keys/interface */
2
+ import type { ILobeAgentRuntimeErrorType } from '@lobechat/model-runtime';
3
+ import type { IPluginErrorType } from '@lobehub/chat-plugin-sdk';
4
+
5
+ import { ErrorType } from '../../fetch';
6
+
7
+ /**
8
+ * 聊天消息错误对象
9
+ */
10
+ export interface ChatMessageError {
11
+ body?: any;
12
+ message: string;
13
+ type: ErrorType | IPluginErrorType | ILobeAgentRuntimeErrorType;
14
+ }
15
+
16
+ export interface ChatCitationItem {
17
+ id?: string;
18
+ onlyUrl?: boolean;
19
+ title?: string;
20
+ url: string;
21
+ }
22
+
23
+ export interface ModelReasoning {
24
+ content?: string;
25
+ duration?: number;
26
+ signature?: string;
27
+ }
@@ -0,0 +1,5 @@
1
+ export * from './base';
2
+ export * from './image';
3
+ export * from './metadata';
4
+ export * from './tools';
5
+ export * from './translate';
@@ -0,0 +1,67 @@
1
+ /* eslint-disable sort-keys-fix/sort-keys-fix , typescript-sort-keys/interface */
2
+
3
+ export interface ModelTokensUsage {
4
+ // Input tokens breakdown
5
+ /**
6
+ * user prompt input
7
+ */
8
+ // Input cache tokens
9
+ inputCachedTokens?: number;
10
+ inputCacheMissTokens?: number;
11
+ inputWriteCacheTokens?: number;
12
+
13
+ inputTextTokens?: number;
14
+ /**
15
+ * user prompt image
16
+ */
17
+ inputImageTokens?: number;
18
+ inputAudioTokens?: number;
19
+ /**
20
+ * currently only pplx has citation_tokens
21
+ */
22
+ inputCitationTokens?: number;
23
+
24
+ // Output tokens breakdown
25
+ outputTextTokens?: number;
26
+ outputImageTokens?: number;
27
+ outputAudioTokens?: number;
28
+ outputReasoningTokens?: number;
29
+
30
+ // Prediction tokens
31
+ acceptedPredictionTokens?: number;
32
+ rejectedPredictionTokens?: number;
33
+
34
+ // Total tokens
35
+ // TODO: make all following fields required
36
+ totalInputTokens?: number;
37
+ totalOutputTokens?: number;
38
+ totalTokens?: number;
39
+ }
40
+
41
+ export interface ModelUsage extends ModelTokensUsage {
42
+ /**
43
+ * dollar
44
+ */
45
+ cost?: number;
46
+ }
47
+
48
+ export interface ModelSpeed {
49
+ /**
50
+ * tokens per second
51
+ */
52
+ tps?: number;
53
+ /**
54
+ * time to first token
55
+ */
56
+ ttft?: number;
57
+ /**
58
+ * from output start to output finish
59
+ */
60
+ duration?: number;
61
+ /**
62
+ * from input start to output finish
63
+ */
64
+ latency?: number;
65
+ }
66
+
67
+ export interface MessageMetadata extends ModelUsage, ModelSpeed {}
@@ -2,7 +2,7 @@ import { IPluginErrorType } from '@lobehub/chat-plugin-sdk';
2
2
  import type { PartialDeep } from 'type-fest';
3
3
  import { z } from 'zod';
4
4
 
5
- import { LobeToolRenderType } from '../tool';
5
+ import { LobeToolRenderType } from '../../tool';
6
6
 
7
7
  export interface ChatPluginPayload {
8
8
  apiName: string;
@@ -0,0 +1,8 @@
1
+ export interface Translate {
2
+ from?: string;
3
+ to: string;
4
+ }
5
+
6
+ export interface ChatTranslate extends Translate {
7
+ content?: string;
8
+ }
@@ -0,0 +1,2 @@
1
+ export * from './item';
2
+ export * from './params';
@@ -0,0 +1,29 @@
1
+ import { GroundingSearch } from '../../search';
2
+ import { MessageMetadata, ModelReasoning } from '../common';
3
+
4
+ export interface DBMessageItem {
5
+ agentId: string | null;
6
+ clientId: string | null;
7
+ content: string | null;
8
+ createdAt: Date;
9
+ error: any | null;
10
+ favorite: boolean | null;
11
+ id: string;
12
+ metadata?: MessageMetadata | null;
13
+ model: string | null;
14
+ observationId: string | null;
15
+ parentId: string | null;
16
+ provider: string | null;
17
+ quotaId: string | null;
18
+ reasoning: ModelReasoning | null;
19
+ role: string;
20
+ search: GroundingSearch | null;
21
+ sessionId: string | null;
22
+ threadId: string | null;
23
+ tools: any | null;
24
+ topicId: string | null;
25
+ // jsonb type
26
+ traceId: string | null;
27
+ updatedAt: Date;
28
+ userId: string;
29
+ }
@@ -0,0 +1,57 @@
1
+ import { GroundingSearch } from '../../search';
2
+ import {
3
+ ChatImageItem,
4
+ ChatMessageError,
5
+ ChatToolPayload,
6
+ MessageMetadata,
7
+ MessageToolCall,
8
+ ModelReasoning,
9
+ } from '../common';
10
+
11
+ export interface NewMessage {
12
+ agentId?: string | null;
13
+ clientId?: string | null;
14
+ content?: string | null;
15
+ createdAt?: Date;
16
+ // optional because it has a default value
17
+ error?: any | null;
18
+ favorite?: boolean;
19
+ id?: string;
20
+ model?: string | null;
21
+ observationId?: string | null;
22
+ parentId?: string | null;
23
+ provider?: string | null;
24
+ quotaId?: string | null;
25
+ // optional because it has a default function
26
+ role: 'user' | 'system' | 'assistant' | 'tool';
27
+ // required because it's notNull
28
+ sessionId?: string | null;
29
+ threadId?: string | null;
30
+ tools?: any | null;
31
+ topicId?: string | null;
32
+ traceId?: string | null;
33
+ // optional because it's generated
34
+ updatedAt?: Date;
35
+ userId: string; // optional because it's generated
36
+ }
37
+
38
+ export interface UpdateMessageParams {
39
+ content?: string;
40
+ error?: ChatMessageError | null;
41
+ imageList?: ChatImageItem[];
42
+ metadata?: MessageMetadata;
43
+ model?: string;
44
+ provider?: string;
45
+ reasoning?: ModelReasoning;
46
+ role?: string;
47
+ search?: GroundingSearch;
48
+ toolCalls?: MessageToolCall[];
49
+ tools?: ChatToolPayload[] | null;
50
+ }
51
+
52
+ export interface NewMessageQueryParams {
53
+ embeddingsId: string;
54
+ messageId: string;
55
+ rewriteQuery: string;
56
+ userQuery: string;
57
+ }
@@ -1,9 +1,6 @@
1
- export * from './base';
2
- export * from './chat';
3
- export * from './image';
4
- export * from './rag';
5
- export * from './tools';
6
- export * from './video';
1
+ export * from './common';
2
+ export * from './db';
3
+ export * from './ui';
7
4
 
8
5
  export interface ModelRankItem {
9
6
  count: number;