@lobehub/chat 0.162.2 → 0.162.4
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 +42 -0
- package/README.md +8 -8
- package/README.zh-CN.md +8 -8
- package/package.json +2 -2
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/__tests__/useAutoFocus.test.ts +20 -82
- package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/useAutoFocus.ts +7 -33
- package/src/app/(main)/chat/@session/features/SessionListContent/DefaultMode.tsx +4 -1
- package/src/store/session/slices/session/action.ts +27 -23
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,48 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.162.4](https://github.com/lobehub/lobe-chat/compare/v0.162.3...v0.162.4)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2024-05-28**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: Fix auto focus issues.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: Fix auto focus issues, closes [#2697](https://github.com/lobehub/lobe-chat/issues/2697) ([8df856e](https://github.com/lobehub/lobe-chat/commit/8df856e))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
### [Version 0.162.3](https://github.com/lobehub/lobe-chat/compare/v0.162.2...v0.162.3)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2024-05-28**</sup>
|
|
33
|
+
|
|
34
|
+
<br/>
|
|
35
|
+
|
|
36
|
+
<details>
|
|
37
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
38
|
+
|
|
39
|
+
</details>
|
|
40
|
+
|
|
41
|
+
<div align="right">
|
|
42
|
+
|
|
43
|
+
[](#readme-top)
|
|
44
|
+
|
|
45
|
+
</div>
|
|
46
|
+
|
|
5
47
|
### [Version 0.162.2](https://github.com/lobehub/lobe-chat/compare/v0.162.1...v0.162.2)
|
|
6
48
|
|
|
7
49
|
<sup>Released on **2024-05-28**</sup>
|
package/README.md
CHANGED
|
@@ -262,14 +262,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.
|
|
|
262
262
|
|
|
263
263
|
<!-- AGENT LIST -->
|
|
264
264
|
|
|
265
|
-
| Recent Submits | Description
|
|
266
|
-
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
267
|
-
| [
|
|
268
|
-
| [
|
|
269
|
-
| [
|
|
270
|
-
| [
|
|
271
|
-
|
|
272
|
-
> 📊 Total agents: [<kbd>**
|
|
265
|
+
| Recent Submits | Description |
|
|
266
|
+
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
267
|
+
| [Node.js Optimizer](https://chat-preview.lobehub.com/market?agent=node-js-devoloper)<br/><sup>By **[chrisuhg](https://github.com/chrisuhg)** on **2024-05-28**</sup> | Specializes in Node.js code review, performance optimization, asynchronous programming, error handling, code refactoring, dependency management, security enhancement, test coverage, and documentation writing.<br/>`node-js` `code-optimization` `performance-optimization` `asynchronous-programming` `error-handling` |
|
|
268
|
+
| [Foreign Colleague Evaluation Assistant](https://chat-preview.lobehub.com/market?agent=praise-assistant)<br/><sup>By **[johnnyqian](https://github.com/johnnyqian)** on **2024-05-27**</sup> | Give positive feedback to your colleagues<br/>`foreign-company` `evaluate` `review` `software-engineer` `praise` |
|
|
269
|
+
| [SEO Optimization Expert](https://chat-preview.lobehub.com/market?agent=seo-helper)<br/><sup>By **[tutorial0](https://github.com/tutorial0)** on **2024-05-27**</sup> | Proficient in SEO terminology and optimization strategies, providing comprehensive SEO solutions and practical advice.<br/>`seo` `search-engine-optimization` `consulting` |
|
|
270
|
+
| [Chinese Text Refinement Master](https://chat-preview.lobehub.com/market?agent=chinese-touch-ups)<br/><sup>By **[S45618](https://github.com/S45618)** on **2024-05-24**</sup> | Proficient in Chinese proofreading and rhetoric, aiming to enhance the fluency and elegance of the text.<br/>`proofreading` `text-refinement` `rhetorical-improvement` `classical-literature` `language-editing` |
|
|
271
|
+
|
|
272
|
+
> 📊 Total agents: [<kbd>**276**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
|
|
273
273
|
|
|
274
274
|
<!-- AGENT LIST -->
|
|
275
275
|
|
package/README.zh-CN.md
CHANGED
|
@@ -250,14 +250,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
|
|
|
250
250
|
|
|
251
251
|
<!-- AGENT LIST -->
|
|
252
252
|
|
|
253
|
-
| 最近新增 | 助手说明
|
|
254
|
-
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
255
|
-
| [
|
|
256
|
-
| [
|
|
257
|
-
| [
|
|
258
|
-
| [
|
|
259
|
-
|
|
260
|
-
> 📊 Total agents: [<kbd>**
|
|
253
|
+
| 最近新增 | 助手说明 |
|
|
254
|
+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
255
|
+
| [Node.js 优化师](https://chat-preview.lobehub.com/market?agent=node-js-devoloper)<br/><sup>By **[chrisuhg](https://github.com/chrisuhg)** on **2024-05-28**</sup> | 擅长 Node.js 代码审查、性能优化、异步编程、错误处理、代码重构、依赖管理、安全增强、测试覆盖率和文档编写。<br/>`node-js` `代码优化` `性能优化` `异步编程` `错误处理` |
|
|
256
|
+
| [外企同事评价助手](https://chat-preview.lobehub.com/market?agent=praise-assistant)<br/><sup>By **[johnnyqian](https://github.com/johnnyqian)** on **2024-05-27**</sup> | 给你的同事好评<br/>`foreign-company` `evaluate` `review` `software-engineer` `praise` |
|
|
257
|
+
| [SEO 优化专家](https://chat-preview.lobehub.com/market?agent=seo-helper)<br/><sup>By **[tutorial0](https://github.com/tutorial0)** on **2024-05-27**</sup> | 精通 SEO 术语和优化策略,提供全面 SEO 解决方案和实用建议。<br/>`seo` `搜索引擎优化` `咨询` |
|
|
258
|
+
| [中文润色大师](https://chat-preview.lobehub.com/market?agent=chinese-touch-ups)<br/><sup>By **[S45618](https://github.com/S45618)** on **2024-05-24**</sup> | 精通中文校对与修辞,旨在提升文本之流畅与雅致<br/>`校对` `文字润色` `修辞改进` `古典文学` `语言编辑` |
|
|
259
|
+
|
|
260
|
+
> 📊 Total agents: [<kbd>**276**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
|
|
261
261
|
|
|
262
262
|
<!-- AGENT LIST -->
|
|
263
263
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.162.
|
|
3
|
+
"version": "0.162.4",
|
|
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",
|
|
@@ -150,7 +150,7 @@
|
|
|
150
150
|
"react": "^18.3.1",
|
|
151
151
|
"react-dom": "^18.3.1",
|
|
152
152
|
"react-hotkeys-hook": "^4.5.0",
|
|
153
|
-
"react-i18next": "
|
|
153
|
+
"react-i18next": "14.0.2",
|
|
154
154
|
"react-layout-kit": "^1.9.0",
|
|
155
155
|
"react-lazy-load": "^4.0.1",
|
|
156
156
|
"react-virtuoso": "^4.7.11",
|
|
@@ -1,107 +1,45 @@
|
|
|
1
1
|
import { act, renderHook } from '@testing-library/react';
|
|
2
|
-
import {
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
enum ElType {
|
|
7
|
-
div,
|
|
8
|
-
input,
|
|
9
|
-
markdown,
|
|
10
|
-
debug,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// 模拟elementFromPoint方法
|
|
14
|
-
document.elementFromPoint = function (x) {
|
|
15
|
-
if (x === ElType.div) {
|
|
16
|
-
return document.createElement('div');
|
|
17
|
-
}
|
|
4
|
+
import { useChatStore } from '@/store/chat';
|
|
5
|
+
import { chatSelectors } from '@/store/chat/selectors';
|
|
18
6
|
|
|
19
|
-
|
|
20
|
-
return document.createElement('input');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (x === ElType.debug) {
|
|
24
|
-
return document.createElement('pre');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (x === ElType.markdown) {
|
|
28
|
-
const markdownEl = document.createElement('article');
|
|
29
|
-
const markdownChildEl = document.createElement('p');
|
|
30
|
-
markdownEl.appendChild(markdownChildEl);
|
|
31
|
-
return markdownChildEl;
|
|
32
|
-
}
|
|
7
|
+
import { useAutoFocus } from '../useAutoFocus';
|
|
33
8
|
|
|
34
|
-
|
|
35
|
-
};
|
|
9
|
+
vi.mock('zustand/traditional');
|
|
36
10
|
|
|
37
11
|
describe('useAutoFocus', () => {
|
|
38
|
-
it('should focus
|
|
39
|
-
const
|
|
40
|
-
|
|
12
|
+
it('should focus the input when chatKey changes', () => {
|
|
13
|
+
const focusMock = vi.fn();
|
|
14
|
+
const inputRef = { current: { focus: focusMock } };
|
|
41
15
|
|
|
42
|
-
// Simulate a mousedown event on an element outside of input or markdown element
|
|
43
16
|
act(() => {
|
|
44
|
-
|
|
17
|
+
useChatStore.setState({ activeId: '1', activeTopicId: '2' });
|
|
45
18
|
});
|
|
46
19
|
|
|
47
|
-
|
|
48
|
-
act(() => {
|
|
49
|
-
document.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }));
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
expect(inputRef.current?.focus).toHaveBeenCalledTimes(1);
|
|
53
|
-
});
|
|
20
|
+
renderHook(() => useAutoFocus(inputRef as any));
|
|
54
21
|
|
|
55
|
-
|
|
56
|
-
const inputRef = { current: { focus: vi.fn() } } as RefObject<any>;
|
|
57
|
-
renderHook(() => useAutoFocus(inputRef));
|
|
22
|
+
expect(focusMock).toHaveBeenCalledTimes(1);
|
|
58
23
|
|
|
59
|
-
// Simulate a mousedown event on an input element
|
|
60
24
|
act(() => {
|
|
61
|
-
|
|
25
|
+
useChatStore.setState({ activeId: '1', activeTopicId: '3' });
|
|
62
26
|
});
|
|
63
27
|
|
|
64
|
-
|
|
65
|
-
act(() => {
|
|
66
|
-
document.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }));
|
|
67
|
-
});
|
|
28
|
+
renderHook(() => useAutoFocus(inputRef as any));
|
|
68
29
|
|
|
69
|
-
|
|
30
|
+
// I don't know why its 3, but is large than 2 is fine
|
|
31
|
+
expect(focusMock).toHaveBeenCalledTimes(3);
|
|
70
32
|
});
|
|
71
33
|
|
|
72
|
-
it('should not focus
|
|
73
|
-
const inputRef = { current:
|
|
74
|
-
renderHook(() => useAutoFocus(inputRef));
|
|
34
|
+
it('should not focus the input if inputRef is not available', () => {
|
|
35
|
+
const inputRef = { current: null };
|
|
75
36
|
|
|
76
|
-
// Simulate a mousedown event on a markdown element
|
|
77
37
|
act(() => {
|
|
78
|
-
|
|
79
|
-
new MouseEvent('mousedown', { bubbles: true, clientX: ElType.markdown }),
|
|
80
|
-
);
|
|
38
|
+
useChatStore.setState({ activeId: '1', activeTopicId: '2' });
|
|
81
39
|
});
|
|
82
40
|
|
|
83
|
-
|
|
84
|
-
act(() => {
|
|
85
|
-
document.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }));
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
expect(inputRef.current?.focus).not.toHaveBeenCalled();
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should not focus inputRef when mouseup event happens inside of debug element', () => {
|
|
92
|
-
const inputRef = { current: { focus: vi.fn() } } as RefObject<any>;
|
|
93
|
-
renderHook(() => useAutoFocus(inputRef));
|
|
94
|
-
|
|
95
|
-
// Simulate a mousedown event on a debug element
|
|
96
|
-
act(() => {
|
|
97
|
-
document.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, clientX: ElType.debug }));
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// Simulate a mouseup event
|
|
101
|
-
act(() => {
|
|
102
|
-
document.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }));
|
|
103
|
-
});
|
|
41
|
+
renderHook(() => useAutoFocus(inputRef as any));
|
|
104
42
|
|
|
105
|
-
expect(inputRef.current
|
|
43
|
+
expect(inputRef.current).toBeNull();
|
|
106
44
|
});
|
|
107
45
|
});
|
package/src/app/(main)/chat/(workspace)/@conversation/features/ChatInput/Desktop/useAutoFocus.ts
CHANGED
|
@@ -1,39 +1,13 @@
|
|
|
1
1
|
import { TextAreaRef } from 'antd/es/input/TextArea';
|
|
2
2
|
import { RefObject, useEffect } from 'react';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let isInputOrMarkdown = false;
|
|
7
|
-
|
|
8
|
-
const onMousedown = (e: MouseEvent) => {
|
|
9
|
-
isInputOrMarkdown = false;
|
|
10
|
-
const element = document.elementFromPoint(e.clientX, e.clientY);
|
|
11
|
-
if (!element) return;
|
|
12
|
-
let currentElement: Element | null = element;
|
|
13
|
-
// 因为点击 Markdown 元素时,element 会是 article 标签的子元素
|
|
14
|
-
// Debug 信息时,element 会是 pre 标签
|
|
15
|
-
// 所以向上查找全局点击对象是否是 Markdown 或者 Input 或者 Debug 元素
|
|
16
|
-
while (currentElement && !isInputOrMarkdown) {
|
|
17
|
-
isInputOrMarkdown = ['TEXTAREA', 'INPUT', 'ARTICLE', 'PRE'].includes(
|
|
18
|
-
currentElement.tagName,
|
|
19
|
-
);
|
|
20
|
-
currentElement = currentElement.parentElement;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
4
|
+
import { useChatStore } from '@/store/chat';
|
|
5
|
+
import { chatSelectors } from '@/store/chat/selectors';
|
|
23
6
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// 所以全局点击元素不是 Markdown 或者 Input 元素的话就聚焦
|
|
27
|
-
if (!isInputOrMarkdown) {
|
|
28
|
-
inputRef.current?.focus();
|
|
29
|
-
}
|
|
30
|
-
};
|
|
7
|
+
export const useAutoFocus = (inputRef: RefObject<TextAreaRef>) => {
|
|
8
|
+
const chatKey = useChatStore(chatSelectors.currentChatKey);
|
|
31
9
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
document.removeEventListener('mousedown', onMousedown);
|
|
36
|
-
document.removeEventListener('mouseup', onMouseup);
|
|
37
|
-
};
|
|
38
|
-
}, []);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
inputRef.current?.focus();
|
|
12
|
+
}, [chatKey]);
|
|
39
13
|
};
|
|
@@ -7,6 +7,8 @@ import { useGlobalStore } from '@/store/global';
|
|
|
7
7
|
import { systemStatusSelectors } from '@/store/global/selectors';
|
|
8
8
|
import { useSessionStore } from '@/store/session';
|
|
9
9
|
import { sessionSelectors } from '@/store/session/selectors';
|
|
10
|
+
import { useUserStore } from '@/store/user';
|
|
11
|
+
import { authSelectors } from '@/store/user/selectors';
|
|
10
12
|
import { SessionDefaultGroup } from '@/types/session';
|
|
11
13
|
|
|
12
14
|
import Actions from '../SessionListContent/CollapseGroup/Actions';
|
|
@@ -23,8 +25,9 @@ const DefaultMode = memo(() => {
|
|
|
23
25
|
const [renameGroupModalOpen, setRenameGroupModalOpen] = useState(false);
|
|
24
26
|
const [configGroupModalOpen, setConfigGroupModalOpen] = useState(false);
|
|
25
27
|
|
|
28
|
+
const isLogin = useUserStore(authSelectors.isLogin);
|
|
26
29
|
const [useFetchSessions] = useSessionStore((s) => [s.useFetchSessions]);
|
|
27
|
-
useFetchSessions();
|
|
30
|
+
useFetchSessions(isLogin);
|
|
28
31
|
|
|
29
32
|
const defaultSessions = useSessionStore(sessionSelectors.defaultSessions, isEqual);
|
|
30
33
|
const customSessionGroups = useSessionStore(sessionSelectors.customSessionGroups, isEqual);
|
|
@@ -72,7 +72,7 @@ export interface SessionAction {
|
|
|
72
72
|
|
|
73
73
|
updateSearchKeywords: (keywords: string) => void;
|
|
74
74
|
|
|
75
|
-
useFetchSessions: () => SWRResponse<ChatSessionList>;
|
|
75
|
+
useFetchSessions: (isLogin: boolean | undefined) => SWRResponse<ChatSessionList>;
|
|
76
76
|
useSearchSessions: (keyword?: string) => SWRResponse<any>;
|
|
77
77
|
|
|
78
78
|
internal_dispatchSessions: (payload: SessionDispatch) => void;
|
|
@@ -192,29 +192,33 @@ export const createSessionSlice: StateCreator<
|
|
|
192
192
|
await refreshSessions();
|
|
193
193
|
},
|
|
194
194
|
|
|
195
|
-
useFetchSessions: () =>
|
|
196
|
-
useClientDataSWR<ChatSessionList>(
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
195
|
+
useFetchSessions: (isLogin) =>
|
|
196
|
+
useClientDataSWR<ChatSessionList>(
|
|
197
|
+
[FETCH_SESSIONS_KEY, isLogin],
|
|
198
|
+
() => sessionService.getGroupedSessions(),
|
|
199
|
+
{
|
|
200
|
+
fallbackData: {
|
|
201
|
+
sessionGroups: [],
|
|
202
|
+
sessions: [],
|
|
203
|
+
},
|
|
204
|
+
onSuccess: (data) => {
|
|
205
|
+
if (
|
|
206
|
+
get().isSessionsFirstFetchFinished &&
|
|
207
|
+
isEqual(get().sessions, data.sessions) &&
|
|
208
|
+
isEqual(get().sessionGroups, data.sessionGroups)
|
|
209
|
+
)
|
|
210
|
+
return;
|
|
211
|
+
|
|
212
|
+
get().internal_processSessions(
|
|
213
|
+
data.sessions,
|
|
214
|
+
data.sessionGroups,
|
|
215
|
+
n('useFetchSessions/updateData') as any,
|
|
216
|
+
);
|
|
217
|
+
set({ isSessionsFirstFetchFinished: true }, false, n('useFetchSessions/onSuccess', data));
|
|
218
|
+
},
|
|
219
|
+
suspense: true,
|
|
215
220
|
},
|
|
216
|
-
|
|
217
|
-
}),
|
|
221
|
+
),
|
|
218
222
|
useSearchSessions: (keyword) =>
|
|
219
223
|
useSWR<LobeSessions>(
|
|
220
224
|
[SEARCH_SESSIONS_KEY, keyword],
|