@lobehub/chat 0.162.11 → 0.162.12

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.162.12](https://github.com/lobehub/lobe-chat/compare/v0.162.11...v0.162.12)
6
+
7
+ <sup>Released on **2024-05-31**</sup>
8
+
9
+ #### ♻ Code Refactoring
10
+
11
+ - **misc**: Refactor session meta method.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### Code refactoring
19
+
20
+ - **misc**: Refactor session meta method, closes [#2737](https://github.com/lobehub/lobe-chat/issues/2737) ([b103c3c](https://github.com/lobehub/lobe-chat/commit/b103c3c))
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.162.11](https://github.com/lobehub/lobe-chat/compare/v0.162.10...v0.162.11)
6
31
 
7
32
  <sup>Released on **2024-05-29**</sup>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "0.162.11",
3
+ "version": "0.162.12",
4
4
  "description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
5
5
  "keywords": [
6
6
  "framework",
@@ -6,6 +6,7 @@ import { SessionGroupModel } from '@/database/client/models/sessionGroup';
6
6
  import { UserModel } from '@/database/client/models/user';
7
7
  import { useUserStore } from '@/store/user';
8
8
  import { LobeAgentChatConfig, LobeAgentConfig } from '@/types/agent';
9
+ import { MetaData } from '@/types/meta';
9
10
  import {
10
11
  ChatSessionList,
11
12
  LobeAgentSession,
@@ -111,6 +112,18 @@ export class ClientService implements ISessionService {
111
112
  return SessionModel.updateConfig(activeId, config);
112
113
  }
113
114
 
115
+ async updateSessionMeta(
116
+ activeId: string,
117
+ meta: Partial<MetaData>,
118
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
119
+ _?: AbortSignal,
120
+ ) {
121
+ // inbox 不允许修改 meta
122
+ if (activeId === INBOX_SESSION_ID) return;
123
+
124
+ return SessionModel.update(activeId, { meta });
125
+ }
126
+
114
127
  async updateSessionChatConfig(
115
128
  activeId: string,
116
129
  config: DeepPartial<LobeAgentChatConfig>,
@@ -2,6 +2,7 @@
2
2
  import { DeepPartial } from 'utility-types';
3
3
 
4
4
  import { LobeAgentChatConfig, LobeAgentConfig } from '@/types/agent';
5
+ import { MetaData } from '@/types/meta';
5
6
  import { BatchTaskResult } from '@/types/service';
6
7
  import {
7
8
  ChatSessionList,
@@ -35,6 +36,9 @@ export interface ISessionService {
35
36
  config: DeepPartial<LobeAgentConfig>,
36
37
  signal?: AbortSignal,
37
38
  ): Promise<any>;
39
+
40
+ updateSessionMeta(id: string, meta: Partial<MetaData>, signal?: AbortSignal): Promise<any>;
41
+
38
42
  updateSessionChatConfig(
39
43
  id: string,
40
44
  config: DeepPartial<LobeAgentChatConfig>,
@@ -19,6 +19,7 @@ vi.mock('@/services/session', () => ({
19
19
  removeSession: vi.fn(),
20
20
  getAllSessions: vi.fn(),
21
21
  updateSession: vi.fn(),
22
+ updateSessionMeta: vi.fn(),
22
23
  updateSessionGroupId: vi.fn(),
23
24
  searchSessions: vi.fn(),
24
25
  updateSessionPinned: vi.fn(),
@@ -211,7 +212,7 @@ describe('SessionAction', () => {
211
212
  it('should update session meta and refresh sessions', async () => {
212
213
  const { result } = renderHook(() => useSessionStore());
213
214
  const meta = { title: 'Test Agent' };
214
- const updateSessionMock = vi.spyOn(sessionService, 'updateSession');
215
+ const updateSessionMock = vi.spyOn(sessionService, 'updateSessionMeta');
215
216
  const refreshSessionsMock = vi.spyOn(result.current, 'refreshSessions');
216
217
 
217
218
  // 模拟有当前会话
@@ -222,7 +223,7 @@ describe('SessionAction', () => {
222
223
  await result.current.updateSessionMeta(meta);
223
224
  });
224
225
 
225
- expect(updateSessionMock).toHaveBeenCalledWith('session-id', { meta });
226
+ expect(updateSessionMock).toHaveBeenCalledWith('session-id', meta, expect.any(AbortSignal));
226
227
  expect(refreshSessionsMock).toHaveBeenCalled();
227
228
  updateSessionMock.mockRestore();
228
229
  refreshSessionsMock.mockRestore();
@@ -188,7 +188,12 @@ export const createSessionSlice: StateCreator<
188
188
 
189
189
  const { activeId, refreshSessions } = get();
190
190
 
191
- await sessionService.updateSession(activeId, { meta });
191
+ const abortController = get().signalSessionMeta as AbortController;
192
+ if (abortController) abortController.abort('canceled');
193
+ const controller = new AbortController();
194
+ set({ signalSessionMeta: controller }, false, 'updateSessionMetaSignal');
195
+
196
+ await sessionService.updateSessionMeta(activeId, meta, controller.signal);
192
197
  await refreshSessions();
193
198
  },
194
199
 
@@ -16,6 +16,7 @@ export interface SessionState {
16
16
  * it means defaultSessions
17
17
  */
18
18
  sessions: LobeAgentSession[];
19
+ signalSessionMeta?: AbortController;
19
20
  }
20
21
 
21
22
  export const initialSessionState: SessionState = {