@lobehub/chat 0.44.1 → 0.44.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 0.44.2](https://github.com/lobehub/lobe-chat/compare/v0.44.1...v0.44.2)
6
+
7
+ <sup>Released on **2023-08-13**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: 修正重新生成时切分历史消息的逻辑.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: 修正重新生成时切分历史消息的逻辑, closes [#50](https://github.com/lobehub/lobe-chat/issues/50) ([de5141f](https://github.com/lobehub/lobe-chat/commit/de5141f))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
5
30
  ### [Version 0.44.1](https://github.com/lobehub/lobe-chat/compare/v0.44.0...v0.44.1)
6
31
 
7
32
  <sup>Released on **2023-08-12**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.44.1",
3
+ "version": "0.44.2",
4
4
  "description": "Lobe Chat is an open-source chatbot client using LangChain, Typescript and Next.js",
5
5
  "keywords": [
6
6
  "chatbot",
@@ -223,22 +223,34 @@ export const chatMessage: StateCreator<
223
223
  const chats = chatSelectors.currentChats(get());
224
224
 
225
225
  const currentIndex = chats.findIndex((c) => c.id === messageId);
226
+ const currentMessage = chats[currentIndex];
227
+ let contextMessages: ChatMessage[] = [];
228
+
229
+ switch (currentMessage.role) {
230
+ case 'function':
231
+ case 'user': {
232
+ contextMessages = chats.slice(0, currentIndex + 1);
233
+ break;
234
+ }
235
+ case 'assistant': {
236
+ // 消息是 AI 发出的因此需要找到它的 user 消息
237
+ const userId = currentMessage.parentId;
238
+ const userIndex = chats.findIndex((c) => c.id === userId);
239
+ // 如果消息没有 parentId,那么同 user/function 模式
240
+ contextMessages = chats.slice(0, userIndex < 0 ? currentIndex + 1 : userIndex + 1);
241
+ break;
242
+ }
243
+ }
226
244
 
227
- const histories = chats
228
- .slice(0, currentIndex + 1)
229
- // 如果点击重新发送的 message 其 role 是 assistant 或者 function,那么需要移除
230
- // 如果点击重新发送的 message 其 role 是 user,则不需要移除
231
- .filter((c) => !(c.role === 'assistant' && c.id === messageId));
232
-
233
- if (histories.length <= 0) return;
245
+ if (contextMessages.length <= 0) return;
234
246
 
235
247
  const { realFetchAIResponse } = get();
236
248
 
237
- const latestMsg = histories.filter((s) => s.role === 'user').at(-1);
249
+ const latestMsg = contextMessages.filter((s) => s.role === 'user').at(-1);
238
250
 
239
251
  if (!latestMsg) return;
240
252
 
241
- await realFetchAIResponse(histories, latestMsg.id);
253
+ await realFetchAIResponse(contextMessages, latestMsg.id);
242
254
  },
243
255
 
244
256
  sendMessage: async (message) => {