listpage-next 0.0.84 → 0.0.85
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/components/ChatGuidance/index.js +1 -2
- package/dist/features/ChatClient/components/ChatSender/index.d.ts +0 -3
- package/dist/features/ChatClient/components/ChatSender/index.js +13 -9
- package/dist/features/ChatClient/components/ClientContent/Footer.js +1 -4
- package/dist/features/ChatClient/components/ClientContent/index.d.ts +2 -3
- package/dist/features/ChatClient/components/ClientContent/index.js +4 -2
- package/dist/features/ChatClient/context/client.d.ts +1 -0
- package/dist/features/ChatClient/context/message.d.ts +2 -2
- package/dist/features/ChatClient/context/message.js +2 -2
- package/dist/features/ChatClient/context/useChatContext.d.ts +6 -0
- package/dist/features/ChatClient/context/useChatContext.js +14 -0
- package/dist/features/ChatClient/index.d.ts +1 -0
- package/dist/features/ChatClient/index.js +2 -0
- package/package.json +1 -1
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
2
3
|
import { Button, Divider, Input } from "antd";
|
|
3
4
|
import { ChatInputBottom, ChatInputContent, ChatInputPanel } from "./styles.js";
|
|
4
|
-
import { useState } from "react";
|
|
5
5
|
import { ArrowUpOutlined, PauseCircleTwoTone } from "@ant-design/icons";
|
|
6
|
+
import { useMessageContext } from "../../context/useMessageContext.js";
|
|
6
7
|
const ChatSender = (props)=>{
|
|
7
|
-
const { placeholder,
|
|
8
|
+
const { placeholder, extra, style, className } = props;
|
|
9
|
+
const { isRequesting, sendMessage } = useMessageContext();
|
|
8
10
|
const [inputValue, setInputValue] = useState("");
|
|
9
11
|
const handleClick = async ()=>{
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
if (isRequesting) return;
|
|
13
|
+
sendMessage({
|
|
14
|
+
role: 'user',
|
|
15
|
+
content: inputValue.trim()
|
|
16
|
+
});
|
|
13
17
|
setInputValue("");
|
|
14
18
|
};
|
|
15
19
|
const handleKeyDown = (e)=>{
|
|
16
20
|
if ('Enter' === e.key && !e.shiftKey) {
|
|
17
21
|
e.preventDefault();
|
|
18
|
-
if (!
|
|
22
|
+
if (!isRequesting && inputValue) handleClick();
|
|
19
23
|
}
|
|
20
24
|
};
|
|
21
25
|
return /*#__PURE__*/ jsxs(ChatInputPanel, {
|
|
@@ -40,10 +44,10 @@ const ChatSender = (props)=>{
|
|
|
40
44
|
type: "vertical"
|
|
41
45
|
}),
|
|
42
46
|
/*#__PURE__*/ jsx(Button, {
|
|
43
|
-
disabled: !inputValue && !
|
|
44
|
-
loading:
|
|
47
|
+
disabled: !inputValue && !isRequesting,
|
|
48
|
+
loading: isRequesting,
|
|
45
49
|
shape: "circle",
|
|
46
|
-
icon:
|
|
50
|
+
icon: isRequesting ? /*#__PURE__*/ jsx(PauseCircleTwoTone, {}) : /*#__PURE__*/ jsx(ArrowUpOutlined, {}),
|
|
47
51
|
type: "primary",
|
|
48
52
|
variant: "filled",
|
|
49
53
|
onKeyDown: handleKeyDown,
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { styled } from "styled-components";
|
|
3
3
|
import { ChatSender } from "../ChatSender/index.js";
|
|
4
|
-
import { useMessageContext } from "../../context/useMessageContext.js";
|
|
5
4
|
const Footer = (props)=>{
|
|
6
5
|
const { visible = true, ...rest } = props;
|
|
7
|
-
const { isRequesting } = useMessageContext();
|
|
8
6
|
if (!visible) return false;
|
|
9
7
|
return /*#__PURE__*/ jsx(FooterContainer, {
|
|
10
8
|
children: /*#__PURE__*/ jsx(ChatSender, {
|
|
11
|
-
...rest
|
|
12
|
-
submitting: isRequesting
|
|
9
|
+
...rest
|
|
13
10
|
})
|
|
14
11
|
});
|
|
15
12
|
};
|
|
@@ -3,9 +3,8 @@ import { HeaderProps } from "./Header";
|
|
|
3
3
|
export interface ClientContentProps {
|
|
4
4
|
className?: string;
|
|
5
5
|
style?: React.CSSProperties;
|
|
6
|
-
children?: React.ReactNode;
|
|
7
6
|
headerProps?: HeaderProps;
|
|
8
|
-
footerProps?:
|
|
9
|
-
|
|
7
|
+
footerProps?: FooterProps;
|
|
8
|
+
children?: React.ReactNode;
|
|
10
9
|
}
|
|
11
10
|
export declare const ClientContent: (props: ClientContentProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRequest } from "ahooks";
|
|
2
3
|
import { Footer } from "./Footer.js";
|
|
3
4
|
import { Header } from "./Header.js";
|
|
4
5
|
import { Content } from "./Content.js";
|
|
@@ -6,8 +7,9 @@ import { Container } from "./styles.js";
|
|
|
6
7
|
import { MessageProvider, useChatClientContext } from "../../context/index.js";
|
|
7
8
|
import { PageLoading } from "../../../../components/Page/components/Loading/index.js";
|
|
8
9
|
const ClientContent = (props)=>{
|
|
9
|
-
const { style, className, children, headerProps, footerProps
|
|
10
|
+
const { style, className, children, headerProps, footerProps } = props;
|
|
10
11
|
const { request } = useChatClientContext();
|
|
12
|
+
const { loading, data } = useRequest(request.getMessages);
|
|
11
13
|
if (loading) return /*#__PURE__*/ jsx(Container, {
|
|
12
14
|
style: style,
|
|
13
15
|
className: className,
|
|
@@ -15,7 +17,7 @@ const ClientContent = (props)=>{
|
|
|
15
17
|
});
|
|
16
18
|
return /*#__PURE__*/ jsx(MessageProvider, {
|
|
17
19
|
request: request.chat,
|
|
18
|
-
|
|
20
|
+
initialMessages: data || [],
|
|
19
21
|
children: /*#__PURE__*/ jsxs(Container, {
|
|
20
22
|
style: style,
|
|
21
23
|
className: className,
|
|
@@ -3,6 +3,7 @@ import { InfiniteListProps, InfiniteListRef, RenderActions } from "../../../comp
|
|
|
3
3
|
import { BaseMessageInfo, SendMessageRequest } from "./message";
|
|
4
4
|
export type ClientRequest<SessionData = any, MessageInfo extends BaseMessageInfo = any> = {
|
|
5
5
|
getConversations: InfiniteListProps<SessionData>['request'];
|
|
6
|
+
getMessages: () => Promise<MessageInfo[]>;
|
|
6
7
|
chat: SendMessageRequest<MessageInfo>;
|
|
7
8
|
};
|
|
8
9
|
export interface ChatClientContextProps<SessionData = any, MessageInfo extends BaseMessageInfo = any> {
|
|
@@ -24,8 +24,8 @@ export type SendMessageRequest<MessageInfo extends BaseMessageInfo = any> = (inf
|
|
|
24
24
|
onError: (id: string, info: MessageInfo) => void;
|
|
25
25
|
}) => Promise<void>;
|
|
26
26
|
export declare const MessageContext: import("react").Context<MessageContextValue<any>>;
|
|
27
|
-
export declare const MessageProvider: <MessageInfo extends BaseMessageInfo = any>({
|
|
27
|
+
export declare const MessageProvider: <MessageInfo extends BaseMessageInfo = any>({ initialMessages, children, request, }: {
|
|
28
28
|
children: ReactNode;
|
|
29
|
-
|
|
29
|
+
initialMessages: MessageInfo[];
|
|
30
30
|
request: SendMessageRequest<MessageInfo>;
|
|
31
31
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -2,12 +2,12 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { createContext, useCallback, useRef, useState } from "react";
|
|
3
3
|
import { useMount } from "ahooks";
|
|
4
4
|
const MessageContext = /*#__PURE__*/ createContext({});
|
|
5
|
-
const MessageProvider = ({
|
|
5
|
+
const MessageProvider = ({ initialMessages, children, request })=>{
|
|
6
6
|
const [isRequesting, setIsRequesting] = useState(false);
|
|
7
7
|
const messagesRef = useRef([]);
|
|
8
8
|
const [messages, setMessages] = useState([]);
|
|
9
9
|
useMount(()=>{
|
|
10
|
-
messagesRef.current =
|
|
10
|
+
messagesRef.current = initialMessages.map((info)=>({
|
|
11
11
|
id: info.id,
|
|
12
12
|
status: 'success',
|
|
13
13
|
info
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useChatClientContext } from "./client.js";
|
|
2
|
+
import { useMessageContext } from "./useMessageContext.js";
|
|
3
|
+
function useChatContext() {
|
|
4
|
+
const { conversationAction } = useChatClientContext();
|
|
5
|
+
const { messages, sendMessage } = useMessageContext();
|
|
6
|
+
const { deleteItem, updateItem } = conversationAction ?? {};
|
|
7
|
+
return {
|
|
8
|
+
messages,
|
|
9
|
+
sendMessage,
|
|
10
|
+
deleteConversation: deleteItem,
|
|
11
|
+
updateConversation: updateItem
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export { useChatContext };
|