@lobehub/chat 1.142.1 → 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 (107) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/changelog/v1.json +9 -0
  3. package/package.json +1 -1
  4. package/packages/context-engine/src/processors/__tests__/MessageContent.test.ts +17 -17
  5. package/packages/context-engine/src/types.ts +4 -4
  6. package/packages/database/src/models/__tests__/message.test.ts +2 -2
  7. package/packages/database/src/models/message.ts +9 -9
  8. package/packages/database/src/models/topic.ts +2 -2
  9. package/packages/prompts/src/chains/__tests__/summaryHistory.test.ts +2 -2
  10. package/packages/prompts/src/chains/summaryHistory.ts +2 -2
  11. package/packages/prompts/src/chains/summaryTitle.ts +2 -2
  12. package/packages/prompts/src/contexts/supervisor/makeDecision.ts +2 -2
  13. package/packages/prompts/src/prompts/chatMessages/index.test.ts +11 -11
  14. package/packages/prompts/src/prompts/chatMessages/index.ts +13 -10
  15. package/packages/prompts/src/prompts/groupChat/index.test.ts +3 -4
  16. package/packages/prompts/src/prompts/groupChat/index.ts +3 -3
  17. package/packages/types/src/aiChat.ts +2 -2
  18. package/packages/types/src/exportConfig.ts +3 -3
  19. package/packages/types/src/importer.ts +2 -2
  20. package/packages/types/src/message/common/base.ts +0 -146
  21. package/packages/types/src/message/common/index.ts +2 -0
  22. package/packages/types/src/message/common/metadata.ts +67 -0
  23. package/packages/types/src/message/{tools.ts → common/tools.ts} +1 -1
  24. package/packages/types/src/message/common/translate.ts +4 -0
  25. package/packages/types/src/message/db/index.ts +2 -0
  26. package/packages/types/src/message/db/item.ts +29 -0
  27. package/packages/types/src/message/db/params.ts +57 -0
  28. package/packages/types/src/message/index.ts +1 -1
  29. package/packages/types/src/message/ui/chat.ts +9 -41
  30. package/packages/types/src/message/ui/extra.ts +16 -0
  31. package/packages/types/src/message/ui/index.ts +1 -0
  32. package/packages/types/src/message/ui/rag.ts +10 -0
  33. package/src/app/[variants]/(main)/chat/(workspace)/features/ShareButton/index.tsx +0 -3
  34. package/src/app/[variants]/(main)/settings/provider/features/CreateNewProvider/index.tsx +1 -2
  35. package/src/database/_deprecated/models/__tests__/message.test.ts +6 -6
  36. package/src/database/_deprecated/models/message.ts +13 -13
  37. package/src/features/Conversation/Error/OllamaBizError/index.tsx +2 -2
  38. package/src/features/Conversation/Error/index.tsx +3 -3
  39. package/src/features/Conversation/Messages/Assistant/Actions/index.tsx +2 -2
  40. package/src/features/Conversation/Messages/Assistant/Extra/index.test.tsx +2 -2
  41. package/src/features/Conversation/Messages/Assistant/MessageContent.tsx +2 -2
  42. package/src/features/Conversation/Messages/Assistant/Tool/Render/CustomRender.tsx +2 -2
  43. package/src/features/Conversation/Messages/Assistant/index.tsx +2 -2
  44. package/src/features/Conversation/Messages/Default.tsx +3 -3
  45. package/src/features/Conversation/Messages/Supervisor/index.tsx +2 -2
  46. package/src/features/Conversation/Messages/User/Actions.tsx +2 -2
  47. package/src/features/Conversation/Messages/User/MessageContent.tsx +2 -2
  48. package/src/features/Conversation/Messages/User/index.tsx +2 -2
  49. package/src/features/Conversation/components/ChatItem/ShareMessageModal/SharePdf/index.tsx +2 -2
  50. package/src/features/Conversation/components/ChatItem/ShareMessageModal/SharePdf/template.ts +2 -2
  51. package/src/features/Conversation/components/ShareMessageModal/ShareImage/Preview.tsx +2 -2
  52. package/src/features/Conversation/components/ShareMessageModal/ShareImage/index.tsx +2 -2
  53. package/src/features/Conversation/components/ShareMessageModal/ShareText/index.tsx +2 -2
  54. package/src/features/Conversation/components/ShareMessageModal/ShareText/template.test.ts +3 -3
  55. package/src/features/Conversation/components/ShareMessageModal/ShareText/template.ts +2 -2
  56. package/src/features/Conversation/components/ShareMessageModal/index.tsx +2 -2
  57. package/src/features/Conversation/types/index.ts +5 -5
  58. package/src/features/ShareModal/ShareJSON/generateMessages.test.ts +3 -3
  59. package/src/features/ShareModal/ShareJSON/generateMessages.ts +2 -2
  60. package/src/features/ShareModal/SharePdf/index.tsx +2 -2
  61. package/src/features/ShareModal/ShareText/template.test.ts +3 -3
  62. package/src/features/ShareModal/ShareText/template.ts +2 -2
  63. package/src/server/routers/lambda/__tests__/message.test.ts +2 -2
  64. package/src/server/routers/lambda/message.ts +2 -2
  65. package/src/services/chat/chat.test.ts +27 -25
  66. package/src/services/chat/contextEngineering.test.ts +21 -21
  67. package/src/services/chat/contextEngineering.ts +2 -2
  68. package/src/services/chat/index.ts +3 -3
  69. package/src/services/message/_deprecated.test.ts +2 -2
  70. package/src/services/message/_deprecated.ts +4 -4
  71. package/src/services/message/client.test.ts +4 -4
  72. package/src/services/message/client.ts +5 -5
  73. package/src/services/message/server.ts +3 -3
  74. package/src/services/message/type.ts +7 -7
  75. package/src/store/chat/helpers.test.ts +5 -5
  76. package/src/store/chat/helpers.ts +4 -5
  77. package/src/store/chat/initialState.ts +0 -3
  78. package/src/store/chat/slices/aiChat/actions/__tests__/fixtures.ts +4 -4
  79. package/src/store/chat/slices/aiChat/actions/__tests__/generateAIChatV2.test.ts +2 -2
  80. package/src/store/chat/slices/aiChat/actions/__tests__/rag.test.ts +6 -6
  81. package/src/store/chat/slices/aiChat/actions/generateAIChat.ts +6 -6
  82. package/src/store/chat/slices/aiChat/actions/generateAIChatV2.ts +4 -4
  83. package/src/store/chat/slices/aiChat/actions/generateAIGroupChat.ts +10 -6
  84. package/src/store/chat/slices/aiChat/actions/memory.ts +2 -2
  85. package/src/store/chat/slices/builtinTool/actions/__tests__/dalle.test.ts +3 -3
  86. package/src/store/chat/slices/builtinTool/actions/__tests__/search.test.ts +3 -3
  87. package/src/store/chat/slices/message/action.test.ts +13 -8
  88. package/src/store/chat/slices/message/action.ts +4 -4
  89. package/src/store/chat/slices/message/initialState.ts +2 -2
  90. package/src/store/chat/slices/message/reducer.test.ts +6 -6
  91. package/src/store/chat/slices/message/reducer.ts +7 -4
  92. package/src/store/chat/slices/message/selectors.test.ts +9 -9
  93. package/src/store/chat/slices/message/selectors.ts +9 -9
  94. package/src/store/chat/slices/message/supervisor.ts +2 -2
  95. package/src/store/chat/slices/plugin/action.test.ts +16 -13
  96. package/src/store/chat/slices/plugin/action.ts +5 -4
  97. package/src/store/chat/slices/portal/selectors.test.ts +8 -8
  98. package/src/store/chat/slices/thread/action.test.ts +2 -2
  99. package/src/store/chat/slices/thread/action.ts +9 -5
  100. package/src/store/chat/slices/thread/selectors/index.ts +10 -11
  101. package/src/store/chat/slices/thread/selectors/util.ts +2 -4
  102. package/src/store/chat/slices/topic/action.test.ts +6 -6
  103. package/src/store/chat/slices/topic/action.ts +2 -2
  104. package/src/store/chat/store.ts +0 -3
  105. package/src/store/chat/slices/share/action.test.ts +0 -22
  106. package/src/store/chat/slices/share/action.ts +0 -18
  107. package/src/store/chat/slices/share/initialState.ts +0 -7
@@ -3,9 +3,6 @@ import type { ILobeAgentRuntimeErrorType } from '@lobechat/model-runtime';
3
3
  import type { IPluginErrorType } from '@lobehub/chat-plugin-sdk';
4
4
 
5
5
  import { ErrorType } from '../../fetch';
6
- import { GroundingSearch } from '../../search';
7
- import { ChatToolPayload, MessageToolCall } from '../tools';
8
- import { ChatImageItem } from './image';
9
6
 
10
7
  /**
11
8
  * 聊天消息错误对象
@@ -28,146 +25,3 @@ export interface ModelReasoning {
28
25
  duration?: number;
29
26
  signature?: string;
30
27
  }
31
-
32
- export interface ModelTokensUsage {
33
- // Input tokens breakdown
34
- /**
35
- * user prompt input
36
- */
37
- // Input cache tokens
38
- inputCachedTokens?: number;
39
- inputCacheMissTokens?: number;
40
- inputWriteCacheTokens?: number;
41
-
42
- inputTextTokens?: number;
43
- /**
44
- * user prompt image
45
- */
46
- inputImageTokens?: number;
47
- inputAudioTokens?: number;
48
- /**
49
- * currently only pplx has citation_tokens
50
- */
51
- inputCitationTokens?: number;
52
-
53
- // Output tokens breakdown
54
- outputTextTokens?: number;
55
- outputImageTokens?: number;
56
- outputAudioTokens?: number;
57
- outputReasoningTokens?: number;
58
-
59
- // Prediction tokens
60
- acceptedPredictionTokens?: number;
61
- rejectedPredictionTokens?: number;
62
-
63
- // Total tokens
64
- // TODO: make all following fields required
65
- totalInputTokens?: number;
66
- totalOutputTokens?: number;
67
- totalTokens?: number;
68
- }
69
-
70
- export interface ModelUsage extends ModelTokensUsage {
71
- /**
72
- * dollar
73
- */
74
- cost?: number;
75
- }
76
-
77
- export interface ModelSpeed {
78
- /**
79
- * tokens per second
80
- */
81
- tps?: number;
82
- /**
83
- * time to first token
84
- */
85
- ttft?: number;
86
- /**
87
- * from output start to output finish
88
- */
89
- duration?: number;
90
- /**
91
- * from input start to output finish
92
- */
93
- latency?: number;
94
- }
95
-
96
- export interface MessageMetadata extends ModelUsage, ModelSpeed {}
97
-
98
- export type MessageRoleType = 'user' | 'system' | 'assistant' | 'tool' | 'supervisor';
99
-
100
- export interface MessageItem {
101
- agentId: string | null;
102
- clientId: string | null;
103
- content: string | null;
104
- createdAt: Date;
105
- error: any | null;
106
- favorite: boolean | null;
107
- id: string;
108
- metadata?: MessageMetadata | null;
109
- model: string | null;
110
- observationId: string | null;
111
- parentId: string | null;
112
- provider: string | null;
113
- quotaId: string | null;
114
- reasoning: ModelReasoning | null;
115
- role: string;
116
- search: GroundingSearch | null;
117
- sessionId: string | null;
118
- threadId: string | null;
119
- tools: any | null;
120
- topicId: string | null;
121
- // jsonb type
122
- traceId: string | null;
123
- updatedAt: Date;
124
- userId: string;
125
- }
126
-
127
- export interface NewMessage {
128
- agentId?: string | null;
129
- clientId?: string | null;
130
- content?: string | null;
131
- createdAt?: Date;
132
- // optional because it has a default value
133
- error?: any | null;
134
- favorite?: boolean;
135
- id?: string;
136
- model?: string | null;
137
- observationId?: string | null;
138
- parentId?: string | null;
139
- provider?: string | null;
140
- quotaId?: string | null;
141
- // optional because it has a default function
142
- role: 'user' | 'system' | 'assistant' | 'tool';
143
- // required because it's notNull
144
- sessionId?: string | null;
145
- threadId?: string | null;
146
- tools?: any | null;
147
- topicId?: string | null;
148
- traceId?: string | null;
149
- // optional because it's generated
150
- updatedAt?: Date;
151
- userId: string; // optional because it's generated
152
- }
153
-
154
- export interface UpdateMessageParams {
155
- content?: string;
156
- error?: ChatMessageError | null;
157
- imageList?: ChatImageItem[];
158
- metadata?: MessageMetadata;
159
- model?: string;
160
- provider?: string;
161
- reasoning?: ModelReasoning;
162
- role?: string;
163
- search?: GroundingSearch;
164
- toolCalls?: MessageToolCall[];
165
- tools?: ChatToolPayload[] | null;
166
- }
167
-
168
- export interface NewMessageQueryParams {
169
- embeddingsId: string;
170
- messageId: string;
171
- rewriteQuery: string;
172
- userQuery: string;
173
- }
@@ -1,3 +1,5 @@
1
1
  export * from './base';
2
2
  export * from './image';
3
+ export * from './metadata';
4
+ export * from './tools';
3
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;
@@ -2,3 +2,7 @@ export interface Translate {
2
2
  from?: string;
3
3
  to: string;
4
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,5 +1,5 @@
1
1
  export * from './common';
2
- export * from './tools';
2
+ export * from './db';
3
3
  export * from './ui';
4
4
 
5
5
  export interface ModelRankItem {
@@ -2,26 +2,13 @@ import { UploadFileItem } from '../../files';
2
2
  import { MetaData } from '../../meta';
3
3
  import { MessageSemanticSearchChunk } from '../../rag';
4
4
  import { GroundingSearch } from '../../search';
5
- import type {
6
- ChatMessageError,
7
- MessageMetadata,
8
- MessageRoleType,
9
- ModelReasoning,
10
- } from '../common/base';
11
- import { ChatImageItem } from '../common/image';
12
- import { Translate } from '../common/translate';
13
- import { ChatPluginPayload, ChatToolPayload } from '../tools';
5
+ import { ChatImageItem, ChatMessageError, MessageMetadata, ModelReasoning } from '../common';
6
+ import { ChatPluginPayload, ChatToolPayload } from '../common/tools';
7
+ import { ChatMessageExtra } from './extra';
8
+ import { ChatFileChunk } from './rag';
14
9
  import { ChatVideoItem } from './video';
15
10
 
16
- export interface ChatTranslate extends Translate {
17
- content?: string;
18
- }
19
-
20
- export interface ChatTTS {
21
- contentMd5?: string;
22
- file?: string;
23
- voice?: string;
24
- }
11
+ export type UIMessageRoleType = 'user' | 'system' | 'assistant' | 'tool' | 'supervisor';
25
12
 
26
13
  export interface ChatFileItem {
27
14
  content?: string;
@@ -32,25 +19,6 @@ export interface ChatFileItem {
32
19
  url: string;
33
20
  }
34
21
 
35
- export interface ChatFileChunk {
36
- fileId: string;
37
- fileType: string;
38
- fileUrl: string;
39
- filename: string;
40
- id: string;
41
- similarity?: number;
42
- text: string;
43
- }
44
-
45
- export interface ChatMessageExtra {
46
- fromModel?: string;
47
- fromProvider?: string;
48
- // 翻译
49
- translate?: ChatTranslate | false | null;
50
- // TTS
51
- tts?: ChatTTS;
52
- }
53
-
54
22
  export interface AssistantContentBlock {
55
23
  content: string;
56
24
  fileList?: ChatFileItem[];
@@ -59,7 +27,7 @@ export interface AssistantContentBlock {
59
27
  tools?: ChatToolPayload[];
60
28
  }
61
29
 
62
- export interface ChatMessage {
30
+ export interface UIChatMessage {
63
31
  // Group chat fields (alphabetically before other fields)
64
32
  agentId?: string | 'supervisor';
65
33
  /**
@@ -109,7 +77,7 @@ export interface ChatMessage {
109
77
  /**
110
78
  * message role type
111
79
  */
112
- role: MessageRoleType;
80
+ role: UIMessageRoleType;
113
81
  search?: GroundingSearch | null;
114
82
  sessionId?: string;
115
83
  /**
@@ -132,7 +100,7 @@ export interface ChatMessage {
132
100
  }
133
101
 
134
102
  export interface CreateMessageParams
135
- extends Partial<Omit<ChatMessage, 'content' | 'role' | 'topicId' | 'chunksList'>> {
103
+ extends Partial<Omit<UIChatMessage, 'content' | 'role' | 'topicId' | 'chunksList'>> {
136
104
  content: string;
137
105
  error?: ChatMessageError | null;
138
106
  fileChunks?: MessageSemanticSearchChunk[];
@@ -140,7 +108,7 @@ export interface CreateMessageParams
140
108
  fromModel?: string;
141
109
  fromProvider?: string;
142
110
  groupId?: string;
143
- role: MessageRoleType;
111
+ role: UIMessageRoleType;
144
112
  sessionId: string;
145
113
  targetId?: string | null;
146
114
  threadId?: string | null;
@@ -0,0 +1,16 @@
1
+ import { ChatTranslate } from '../common';
2
+
3
+ export interface ChatTTS {
4
+ contentMd5?: string;
5
+ file?: string;
6
+ voice?: string;
7
+ }
8
+
9
+ export interface ChatMessageExtra {
10
+ fromModel?: string;
11
+ fromProvider?: string;
12
+ // 翻译
13
+ translate?: ChatTranslate | false | null;
14
+ // TTS
15
+ tts?: ChatTTS;
16
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './chat';
2
+ export * from './extra';
2
3
  export * from './rag';
3
4
  export * from './video';
@@ -2,6 +2,16 @@ import { z } from 'zod';
2
2
 
3
3
  import { MessageSemanticSearchChunk } from '../../rag';
4
4
 
5
+ export interface ChatFileChunk {
6
+ fileId: string;
7
+ fileType: string;
8
+ fileUrl: string;
9
+ filename: string;
10
+ id: string;
11
+ similarity?: number;
12
+ text: string;
13
+ }
14
+
5
15
  export const SemanticSearchChunkSchema = z.object({
6
16
  id: z.string(),
7
17
  similarity: z.number(),
@@ -8,7 +8,6 @@ import { useTranslation } from 'react-i18next';
8
8
 
9
9
  import { DESKTOP_HEADER_ICON_SIZE, MOBILE_HEADER_ICON_SIZE } from '@/const/layoutTokens';
10
10
  import { useWorkspaceModal } from '@/hooks/useWorkspaceModal';
11
- import { useChatStore } from '@/store/chat';
12
11
 
13
12
  const ShareModal = dynamic(() => import('@/features/ShareModal'));
14
13
 
@@ -21,13 +20,11 @@ interface ShareButtonProps {
21
20
  const ShareButton = memo<ShareButtonProps>(({ mobile, setOpen, open }) => {
22
21
  const [isModalOpen, setIsModalOpen] = useWorkspaceModal(open, setOpen);
23
22
  const { t } = useTranslation('common');
24
- const [shareLoading] = useChatStore((s) => [s.shareLoading]);
25
23
 
26
24
  return (
27
25
  <>
28
26
  <ActionIcon
29
27
  icon={Share2}
30
- loading={shareLoading}
31
28
  onClick={() => setIsModalOpen(true)}
32
29
  size={mobile ? MOBILE_HEADER_ICON_SIZE : DESKTOP_HEADER_ICON_SIZE}
33
30
  title={t('share')}
@@ -18,8 +18,8 @@ import { Flexbox } from 'react-layout-kit';
18
18
  import { useAiInfraStore } from '@/store/aiInfra/store';
19
19
  import { CreateAiProviderParams } from '@/types/aiProvider';
20
20
 
21
- import { CUSTOM_PROVIDER_SDK_OPTIONS } from '../customProviderSdkOptions';
22
21
  import { KeyVaultsConfigKey, LLMProviderApiTokenKey, LLMProviderBaseUrlKey } from '../../const';
22
+ import { CUSTOM_PROVIDER_SDK_OPTIONS } from '../customProviderSdkOptions';
23
23
 
24
24
  interface CreateNewProviderProps {
25
25
  onClose?: () => void;
@@ -142,7 +142,6 @@ const CreateNewProvider = memo<CreateNewProviderProps>(({ onClose, open }) => {
142
142
  return (
143
143
  <FormModal
144
144
  destroyOnHidden
145
- height={'90%'}
146
145
  items={[
147
146
  {
148
147
  children: basicItems,
@@ -1,4 +1,4 @@
1
- import { ChatMessage } from '@lobechat/types';
1
+ import { UIChatMessage } from '@lobechat/types';
2
2
  import { afterEach, beforeEach, describe, expect, it } from 'vitest';
3
3
 
4
4
  import { CreateMessageParams, MessageModel } from '../message';
@@ -63,7 +63,7 @@ describe('MessageModel', () => {
63
63
 
64
64
  describe('batchCreate', () => {
65
65
  it('should batch create message records', async () => {
66
- const messagesToCreate = [messageData, messageData] as ChatMessage[];
66
+ const messagesToCreate = [messageData, messageData] as UIChatMessage[];
67
67
  const results = await MessageModel.batchCreate(messagesToCreate);
68
68
 
69
69
  expect(results.success).toBeTruthy();
@@ -87,7 +87,7 @@ describe('MessageModel', () => {
87
87
  describe('query', () => {
88
88
  it('should query messages with pagination', async () => {
89
89
  // 创建多条消息以测试查询方法
90
- await MessageModel.batchCreate([messageData, messageData] as ChatMessage[]);
90
+ await MessageModel.batchCreate([messageData, messageData] as UIChatMessage[]);
91
91
 
92
92
  const queriedMessages = await MessageModel.query({
93
93
  pageSize: 1,
@@ -101,7 +101,7 @@ describe('MessageModel', () => {
101
101
 
102
102
  it('should query correctly without topic id', async () => {
103
103
  // 创建多条消息以测试查询方法
104
- await MessageModel.batchCreate([messageData, messageData] as ChatMessage[]);
104
+ await MessageModel.batchCreate([messageData, messageData] as UIChatMessage[]);
105
105
 
106
106
  const queriedMessages = await MessageModel.query({ sessionId: messageData.sessionId });
107
107
 
@@ -113,7 +113,7 @@ describe('MessageModel', () => {
113
113
  await MessageModel.batchCreate([
114
114
  messageData,
115
115
  { ...messageData, topicId: undefined },
116
- ] as ChatMessage[]);
116
+ ] as UIChatMessage[]);
117
117
 
118
118
  const queriedMessages = await MessageModel.query({ sessionId: messageData.sessionId });
119
119
 
@@ -121,7 +121,7 @@ describe('MessageModel', () => {
121
121
  });
122
122
 
123
123
  it('should should have correct order', async () => {
124
- const data: ChatMessage[] = [
124
+ const data: UIChatMessage[] = [
125
125
  {
126
126
  role: 'user',
127
127
  content: '1',
@@ -1,4 +1,4 @@
1
- import { ChatMessage } from '@lobechat/types';
1
+ import { UIChatMessage } from '@lobechat/types';
2
2
  import type { PartialDeep } from 'type-fest';
3
3
 
4
4
  import { BaseModel } from '@/database/_deprecated/core';
@@ -11,8 +11,8 @@ import { nanoid } from '@/utils/uuid';
11
11
  * @deprecated
12
12
  */
13
13
  export interface CreateMessageParams
14
- extends Partial<Omit<ChatMessage, 'content' | 'role'>>,
15
- Pick<ChatMessage, 'content' | 'role'> {
14
+ extends Partial<Omit<UIChatMessage, 'content' | 'role'>>,
15
+ Pick<UIChatMessage, 'content' | 'role'> {
16
16
  files?: string[];
17
17
  fromModel?: string;
18
18
  fromProvider?: string;
@@ -39,7 +39,7 @@ class _MessageModel extends BaseModel {
39
39
  topicId,
40
40
  pageSize = 9999,
41
41
  current = 0,
42
- }: QueryMessageParams): Promise<ChatMessage[]> {
42
+ }: QueryMessageParams): Promise<UIChatMessage[]> {
43
43
  const offset = current * pageSize;
44
44
 
45
45
  const query = !!topicId
@@ -57,15 +57,15 @@ class _MessageModel extends BaseModel {
57
57
 
58
58
  const messages = dbMessages.map((msg) => this.mapToChatMessage(msg));
59
59
 
60
- const finalList: ChatMessage[] = [];
60
+ const finalList: UIChatMessage[] = [];
61
61
 
62
- const addItem = (item: ChatMessage) => {
62
+ const addItem = (item: UIChatMessage) => {
63
63
  const isExist = finalList.some((i) => item.id === i.id);
64
64
  if (!isExist) {
65
65
  finalList.push(item);
66
66
  }
67
67
  };
68
- const messageMap = new Map<string, ChatMessage>();
68
+ const messageMap = new Map<string, UIChatMessage>();
69
69
  for (const item of messages) messageMap.set(item.id, item);
70
70
 
71
71
  for (const item of messages) {
@@ -110,18 +110,18 @@ class _MessageModel extends BaseModel {
110
110
  async create(data: CreateMessageParams) {
111
111
  const id = nanoid();
112
112
 
113
- const messageData: DB_Message = this.mapChatMessageToDBMessage(data as ChatMessage);
113
+ const messageData: DB_Message = this.mapChatMessageToDBMessage(data as UIChatMessage);
114
114
 
115
115
  return this._addWithSync(messageData, id);
116
116
  }
117
117
 
118
- async batchCreate(messages: ChatMessage[]) {
118
+ async batchCreate(messages: UIChatMessage[]) {
119
119
  const data: DB_Message[] = messages.map((m) => this.mapChatMessageToDBMessage(m));
120
120
 
121
121
  return this._batchAdd(data);
122
122
  }
123
123
 
124
- async duplicateMessages(messages: ChatMessage[]): Promise<ChatMessage[]> {
124
+ async duplicateMessages(messages: UIChatMessage[]): Promise<UIChatMessage[]> {
125
125
  const duplicatedMessages = await this.createDuplicateMessages(messages);
126
126
  // 批量添加复制后的消息到数据库
127
127
  await this.batchCreate(duplicatedMessages);
@@ -230,7 +230,7 @@ class _MessageModel extends BaseModel {
230
230
 
231
231
  // **************** Helper *************** //
232
232
 
233
- private async createDuplicateMessages(messages: ChatMessage[]): Promise<ChatMessage[]> {
233
+ private async createDuplicateMessages(messages: UIChatMessage[]): Promise<UIChatMessage[]> {
234
234
  // 创建一个映射来存储原始消息ID和复制消息ID之间的关系
235
235
  const idMapping = new Map<string, string>();
236
236
 
@@ -252,7 +252,7 @@ class _MessageModel extends BaseModel {
252
252
  return duplicatedMessages;
253
253
  }
254
254
 
255
- private mapChatMessageToDBMessage(message: ChatMessage): DB_Message {
255
+ private mapChatMessageToDBMessage(message: UIChatMessage): DB_Message {
256
256
  const { extra, ...messageData } = message;
257
257
 
258
258
  return { ...messageData, ...extra } as DB_Message;
@@ -270,7 +270,7 @@ class _MessageModel extends BaseModel {
270
270
  extra: { fromModel, fromProvider, translate, tts },
271
271
  meta: {},
272
272
  topicId: item.topicId ?? undefined,
273
- } as ChatMessage;
273
+ } as UIChatMessage;
274
274
  };
275
275
  }
276
276
 
@@ -1,4 +1,4 @@
1
- import { ChatMessage } from '@lobechat/types';
1
+ import { UIChatMessage } from '@lobechat/types';
2
2
  import { Skeleton } from 'antd';
3
3
  import dynamic from 'next/dynamic';
4
4
  import { memo } from 'react';
@@ -24,7 +24,7 @@ interface OllamaErrorResponse {
24
24
 
25
25
  const UNRESOLVED_MODEL_REGEXP = /model "([\w+,-_]+)" not found/;
26
26
 
27
- const OllamaBizError = memo<ChatMessage>(({ error, id }) => {
27
+ const OllamaBizError = memo<UIChatMessage>(({ error, id }) => {
28
28
  const errorBody: OllamaErrorResponse = (error as any)?.body;
29
29
 
30
30
  const errorMessage = errorBody.error?.message;