listpage-next 0.0.221 → 0.0.223
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/dist/features/ChatClient/ui/ConversationDropdownMenu/index.d.ts +13 -0
- package/dist/features/ChatClient/ui/ConversationDropdownMenu/index.js +56 -0
- package/dist/features/ChatClient/ui/index.d.ts +1 -0
- package/dist/features/ChatClient/ui/index.js +1 -0
- package/dist/features/ChatClient/utils/parseSse.js +2 -6
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type BaseConversation = {
|
|
2
|
+
id: string;
|
|
3
|
+
title: string;
|
|
4
|
+
};
|
|
5
|
+
export interface ConversationDropdownMenuProps<T extends BaseConversation = BaseConversation> {
|
|
6
|
+
request: () => Promise<{
|
|
7
|
+
list: T[];
|
|
8
|
+
}>;
|
|
9
|
+
onSelect?: (item: T) => void;
|
|
10
|
+
activeKey?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const ConversationDropdownMenu: <T extends BaseConversation = any>(props: ConversationDropdownMenuProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { HistoryOutlined } from "@ant-design/icons";
|
|
3
|
+
import { useRequest } from "ahooks";
|
|
4
|
+
import { Button, Dropdown, Tooltip } from "antd";
|
|
5
|
+
const ConversationDropdownMenu = (props)=>{
|
|
6
|
+
const { request, onSelect, activeKey } = props;
|
|
7
|
+
const { data, run: refresh } = useRequest(()=>request(), {
|
|
8
|
+
manual: true
|
|
9
|
+
});
|
|
10
|
+
const menus = [
|
|
11
|
+
{
|
|
12
|
+
label: '历史会话',
|
|
13
|
+
type: 'group'
|
|
14
|
+
},
|
|
15
|
+
...(data?.list ?? []).map((item)=>({
|
|
16
|
+
key: item.id,
|
|
17
|
+
label: item.title || item,
|
|
18
|
+
type: 'item',
|
|
19
|
+
onClick: ()=>{
|
|
20
|
+
if (item.id !== activeKey) onSelect?.(item);
|
|
21
|
+
}
|
|
22
|
+
}))
|
|
23
|
+
];
|
|
24
|
+
return /*#__PURE__*/ jsx(Tooltip, {
|
|
25
|
+
title: "历史会话",
|
|
26
|
+
children: /*#__PURE__*/ jsx(Dropdown, {
|
|
27
|
+
trigger: [
|
|
28
|
+
'click'
|
|
29
|
+
],
|
|
30
|
+
menu: {
|
|
31
|
+
items: menus,
|
|
32
|
+
activeKey: activeKey
|
|
33
|
+
},
|
|
34
|
+
popupRender: (originNode)=>{
|
|
35
|
+
if (!data?.list?.length) return /*#__PURE__*/ jsx("div", {
|
|
36
|
+
style: {
|
|
37
|
+
padding: '12px 24px',
|
|
38
|
+
background: '#eee',
|
|
39
|
+
color: '#000',
|
|
40
|
+
borderRadius: 8
|
|
41
|
+
},
|
|
42
|
+
children: "暂无历史会话"
|
|
43
|
+
});
|
|
44
|
+
return originNode;
|
|
45
|
+
},
|
|
46
|
+
children: /*#__PURE__*/ jsx(Button, {
|
|
47
|
+
onClick: refresh,
|
|
48
|
+
type: "text",
|
|
49
|
+
icon: /*#__PURE__*/ jsx(HistoryOutlined, {
|
|
50
|
+
size: 16
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
export { ConversationDropdownMenu };
|
|
@@ -31,7 +31,6 @@ async function* parseSseStream(stream) {
|
|
|
31
31
|
const reader = stream.getReader();
|
|
32
32
|
const decoder = new TextDecoder();
|
|
33
33
|
let buffer = '';
|
|
34
|
-
let type = '';
|
|
35
34
|
try {
|
|
36
35
|
while(true){
|
|
37
36
|
const { done, value } = await reader.read();
|
|
@@ -44,15 +43,12 @@ async function* parseSseStream(stream) {
|
|
|
44
43
|
const line = buffer.slice(0, idx).trim();
|
|
45
44
|
buffer = buffer.slice(idx + 1);
|
|
46
45
|
if (line) {
|
|
47
|
-
if (line.startsWith('event:'))
|
|
46
|
+
if (line.startsWith('event:')) line.slice(6).trim();
|
|
48
47
|
else if (line.startsWith('data:')) {
|
|
49
48
|
const raw = line.slice(5).trim();
|
|
50
49
|
try {
|
|
51
50
|
const data = JSON.parse(raw);
|
|
52
|
-
yield
|
|
53
|
-
type: type,
|
|
54
|
-
data
|
|
55
|
-
};
|
|
51
|
+
yield data;
|
|
56
52
|
} catch {}
|
|
57
53
|
}
|
|
58
54
|
}
|