listpage-next 0.0.83 → 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/index.d.ts +2 -3
- package/dist/features/ChatClient/components/ClientContent/index.js +23 -18
- package/dist/features/ChatClient/components/Layout/ChatPage.d.ts +6 -6
- package/dist/features/ChatClient/components/Layout/ChatPage.js +34 -30
- package/dist/features/ChatClient/context/client.d.ts +23 -0
- package/dist/features/ChatClient/context/client.js +29 -0
- package/dist/features/ChatClient/context/index.d.ts +2 -17
- package/dist/features/ChatClient/context/index.js +2 -29
- package/dist/features/ChatClient/context/message.d.ts +31 -0
- package/dist/features/ChatClient/context/message.js +124 -0
- package/dist/features/ChatClient/context/useChatContext.d.ts +6 -0
- package/dist/features/ChatClient/context/useChatContext.js +14 -0
- package/dist/features/ChatClient/context/useMessageContext.d.ts +2 -0
- package/dist/features/ChatClient/context/useMessageContext.js +6 -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,
|
|
@@ -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,33 +1,38 @@
|
|
|
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";
|
|
5
6
|
import { Container } from "./styles.js";
|
|
6
|
-
import { useChatClientContext } from "../../context/index.js";
|
|
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 {
|
|
10
|
+
const { style, className, children, headerProps, footerProps } = props;
|
|
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,
|
|
14
16
|
children: /*#__PURE__*/ jsx(PageLoading, {})
|
|
15
17
|
});
|
|
16
|
-
return /*#__PURE__*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
children:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
return /*#__PURE__*/ jsx(MessageProvider, {
|
|
19
|
+
request: request.chat,
|
|
20
|
+
initialMessages: data || [],
|
|
21
|
+
children: /*#__PURE__*/ jsxs(Container, {
|
|
22
|
+
style: style,
|
|
23
|
+
className: className,
|
|
24
|
+
children: [
|
|
25
|
+
/*#__PURE__*/ jsx(Header, {
|
|
26
|
+
...headerProps
|
|
27
|
+
}),
|
|
28
|
+
/*#__PURE__*/ jsx(Content, {
|
|
29
|
+
children: children
|
|
30
|
+
}),
|
|
31
|
+
/*#__PURE__*/ jsx(Footer, {
|
|
32
|
+
...footerProps
|
|
33
|
+
})
|
|
34
|
+
]
|
|
35
|
+
})
|
|
31
36
|
});
|
|
32
37
|
};
|
|
33
38
|
export { ClientContent };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
|
-
import {
|
|
3
|
-
export interface ChatPageProps<
|
|
2
|
+
import { BaseMessageInfo, ClientRequest } from "../../context";
|
|
3
|
+
export interface ChatPageProps<SessionData = any, MessageInfo extends BaseMessageInfo = any> {
|
|
4
4
|
logo?: string;
|
|
5
5
|
title?: string;
|
|
6
6
|
children?: ReactNode;
|
|
7
|
-
request:
|
|
8
|
-
onClickConversation?: (key: string, item:
|
|
7
|
+
request: ClientRequest<SessionData, MessageInfo>;
|
|
8
|
+
onClickConversation?: (key: string, item: SessionData) => void;
|
|
9
9
|
onClickNewConversation?: () => void;
|
|
10
10
|
onClickMoreAgent?: () => void;
|
|
11
|
-
onRenameConversation?: (key: string, item:
|
|
12
|
-
onDeleteConversation?: (key: string, item:
|
|
11
|
+
onRenameConversation?: (key: string, item: SessionData) => Promise<void>;
|
|
12
|
+
onDeleteConversation?: (key: string, item: SessionData) => Promise<void>;
|
|
13
13
|
}
|
|
14
14
|
export declare const ChatPage: (props: ChatPageProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -5,37 +5,41 @@ import { HistoryConversation } from "../HistoryConversation/index.js";
|
|
|
5
5
|
import { NewConversation } from "../NewConversation/index.js";
|
|
6
6
|
import { ChatClientProvider } from "../../context/index.js";
|
|
7
7
|
import { Content, Layout } from "./styles.js";
|
|
8
|
-
const
|
|
8
|
+
const ChatPageComponent = (props)=>{
|
|
9
9
|
const { logo, title, children, request, onClickConversation, onClickNewConversation, onClickMoreAgent, onRenameConversation, onDeleteConversation } = props;
|
|
10
|
-
return /*#__PURE__*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
]
|
|
38
|
-
})
|
|
10
|
+
return /*#__PURE__*/ jsxs(Layout, {
|
|
11
|
+
style: {
|
|
12
|
+
height: '100vh'
|
|
13
|
+
},
|
|
14
|
+
children: [
|
|
15
|
+
/*#__PURE__*/ jsxs(Sider, {
|
|
16
|
+
children: [
|
|
17
|
+
/*#__PURE__*/ jsx(Logo, {
|
|
18
|
+
icon: logo,
|
|
19
|
+
title: title || '智能对话'
|
|
20
|
+
}),
|
|
21
|
+
/*#__PURE__*/ jsx(NewConversation, {
|
|
22
|
+
onClickNew: onClickNewConversation,
|
|
23
|
+
onClickMoreAgent: onClickMoreAgent
|
|
24
|
+
}),
|
|
25
|
+
/*#__PURE__*/ jsx(HistoryConversation, {
|
|
26
|
+
request: request.getConversations,
|
|
27
|
+
onSelect: onClickConversation,
|
|
28
|
+
onRename: onRenameConversation,
|
|
29
|
+
onDelete: onDeleteConversation
|
|
30
|
+
})
|
|
31
|
+
]
|
|
32
|
+
}),
|
|
33
|
+
/*#__PURE__*/ jsx(Content, {
|
|
34
|
+
children: children
|
|
35
|
+
})
|
|
36
|
+
]
|
|
39
37
|
});
|
|
40
38
|
};
|
|
39
|
+
const ChatPage = (props)=>/*#__PURE__*/ jsx(ChatClientProvider, {
|
|
40
|
+
request: props.request,
|
|
41
|
+
children: /*#__PURE__*/ jsx(ChatPageComponent, {
|
|
42
|
+
...props
|
|
43
|
+
})
|
|
44
|
+
});
|
|
41
45
|
export { ChatPage };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { InfiniteListProps, InfiniteListRef, RenderActions } from "../../../components/InfiniteList";
|
|
3
|
+
import { BaseMessageInfo, SendMessageRequest } from "./message";
|
|
4
|
+
export type ClientRequest<SessionData = any, MessageInfo extends BaseMessageInfo = any> = {
|
|
5
|
+
getConversations: InfiniteListProps<SessionData>['request'];
|
|
6
|
+
getMessages: () => Promise<MessageInfo[]>;
|
|
7
|
+
chat: SendMessageRequest<MessageInfo>;
|
|
8
|
+
};
|
|
9
|
+
export interface ChatClientContextProps<SessionData = any, MessageInfo extends BaseMessageInfo = any> {
|
|
10
|
+
request: ClientRequest<SessionData, MessageInfo>;
|
|
11
|
+
collapsed: boolean;
|
|
12
|
+
setCollapsed: (collapsed: boolean) => void;
|
|
13
|
+
showUpdateTitleModal: (title: string, onSubmit?: (title: string) => any) => void;
|
|
14
|
+
conversationListRef: InfiniteListRef<SessionData>;
|
|
15
|
+
conversationAction: Partial<RenderActions<SessionData>>;
|
|
16
|
+
}
|
|
17
|
+
export interface ChatClientProviderProps<SessionData = any, MessageInfo extends BaseMessageInfo = any> {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
request: ClientRequest<SessionData, MessageInfo>;
|
|
20
|
+
}
|
|
21
|
+
export declare const ChatClientContext: import("react").Context<ChatClientContextProps<any, any>>;
|
|
22
|
+
export declare const ChatClientProvider: (props: ChatClientProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
export declare function useChatClientContext(): ChatClientContextProps<any, any>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useState } from "react";
|
|
3
|
+
import { useUpdateTitleModal } from "./useUpdateTitleModal.js";
|
|
4
|
+
import { useConversationListRef } from "./useConversationListRef.js";
|
|
5
|
+
const ChatClientContext = /*#__PURE__*/ createContext({});
|
|
6
|
+
const ChatClientProvider = (props)=>{
|
|
7
|
+
const { children, request } = props;
|
|
8
|
+
const { updateTitleModalEle, showUpdateTitleModal } = useUpdateTitleModal();
|
|
9
|
+
const [collapsed, setCollapsed] = useState(false);
|
|
10
|
+
const { conversationListRef, ...conversationActions } = useConversationListRef();
|
|
11
|
+
return /*#__PURE__*/ jsxs(ChatClientContext.Provider, {
|
|
12
|
+
value: {
|
|
13
|
+
request,
|
|
14
|
+
collapsed,
|
|
15
|
+
setCollapsed,
|
|
16
|
+
showUpdateTitleModal,
|
|
17
|
+
conversationListRef,
|
|
18
|
+
conversationAction: conversationActions
|
|
19
|
+
},
|
|
20
|
+
children: [
|
|
21
|
+
children,
|
|
22
|
+
updateTitleModalEle
|
|
23
|
+
]
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
function useChatClientContext() {
|
|
27
|
+
return useContext(ChatClientContext);
|
|
28
|
+
}
|
|
29
|
+
export { ChatClientContext, ChatClientProvider, useChatClientContext };
|
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export interface ChatClientContextProps<ConversationItemData = any> {
|
|
4
|
-
submitting: boolean;
|
|
5
|
-
collapsed: boolean;
|
|
6
|
-
setCollapsed: (collapsed: boolean) => void;
|
|
7
|
-
showUpdateTitleModal: (title: string, onSubmit?: (title: string) => any) => void;
|
|
8
|
-
conversationListRef: InfiniteListRef<ConversationItemData>;
|
|
9
|
-
conversationAction: Partial<RenderActions<ConversationItemData>>;
|
|
10
|
-
}
|
|
11
|
-
export interface ChatClientProviderProps {
|
|
12
|
-
children: ReactNode;
|
|
13
|
-
submitting?: boolean;
|
|
14
|
-
}
|
|
15
|
-
export declare const ChatClientContext: import("react").Context<ChatClientContextProps<any>>;
|
|
16
|
-
export declare const ChatClientProvider: (props: ChatClientProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
17
|
-
export declare function useChatClientContext(): ChatClientContextProps<any>;
|
|
1
|
+
export * from './client';
|
|
2
|
+
export * from './message';
|
|
@@ -1,29 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { useUpdateTitleModal } from "./useUpdateTitleModal.js";
|
|
4
|
-
import { useConversationListRef } from "./useConversationListRef.js";
|
|
5
|
-
const ChatClientContext = /*#__PURE__*/ createContext({});
|
|
6
|
-
const ChatClientProvider = (props)=>{
|
|
7
|
-
const { children, submitting = false } = props;
|
|
8
|
-
const { updateTitleModalEle, showUpdateTitleModal } = useUpdateTitleModal();
|
|
9
|
-
const [collapsed, setCollapsed] = useState(false);
|
|
10
|
-
const { conversationListRef, ...conversationActions } = useConversationListRef();
|
|
11
|
-
return /*#__PURE__*/ jsxs(ChatClientContext.Provider, {
|
|
12
|
-
value: {
|
|
13
|
-
submitting,
|
|
14
|
-
collapsed,
|
|
15
|
-
setCollapsed,
|
|
16
|
-
showUpdateTitleModal,
|
|
17
|
-
conversationListRef,
|
|
18
|
-
conversationAction: conversationActions
|
|
19
|
-
},
|
|
20
|
-
children: [
|
|
21
|
-
children,
|
|
22
|
-
updateTitleModalEle
|
|
23
|
-
]
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
function useChatClientContext() {
|
|
27
|
-
return useContext(ChatClientContext);
|
|
28
|
-
}
|
|
29
|
-
export { ChatClientContext, ChatClientProvider, useChatClientContext };
|
|
1
|
+
export * from "./client.js";
|
|
2
|
+
export * from "./message.js";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export type MessageStatus = 'loading' | 'success' | 'failed';
|
|
3
|
+
export type BaseMessageInfo = {
|
|
4
|
+
id: string;
|
|
5
|
+
role: string;
|
|
6
|
+
content: string;
|
|
7
|
+
reasoning?: string;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
export type Message<MessageInfo extends BaseMessageInfo = any> = {
|
|
11
|
+
id: string;
|
|
12
|
+
status: MessageStatus;
|
|
13
|
+
info: MessageInfo;
|
|
14
|
+
};
|
|
15
|
+
export type MessageContextValue<MessageInfo extends BaseMessageInfo = any> = {
|
|
16
|
+
messages: Message<MessageInfo>[];
|
|
17
|
+
sendMessage: (info: MessageInfo) => void;
|
|
18
|
+
isRequesting: boolean;
|
|
19
|
+
};
|
|
20
|
+
export type SendMessageRequest<MessageInfo extends BaseMessageInfo = any> = (info: MessageInfo, callbacks: {
|
|
21
|
+
onCreated: (info: MessageInfo) => void;
|
|
22
|
+
onUpdate: (id: string, info: MessageInfo) => void;
|
|
23
|
+
onSuccess: (id: string, info: MessageInfo) => void;
|
|
24
|
+
onError: (id: string, info: MessageInfo) => void;
|
|
25
|
+
}) => Promise<void>;
|
|
26
|
+
export declare const MessageContext: import("react").Context<MessageContextValue<any>>;
|
|
27
|
+
export declare const MessageProvider: <MessageInfo extends BaseMessageInfo = any>({ initialMessages, children, request, }: {
|
|
28
|
+
children: ReactNode;
|
|
29
|
+
initialMessages: MessageInfo[];
|
|
30
|
+
request: SendMessageRequest<MessageInfo>;
|
|
31
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useRef, useState } from "react";
|
|
3
|
+
import { useMount } from "ahooks";
|
|
4
|
+
const MessageContext = /*#__PURE__*/ createContext({});
|
|
5
|
+
const MessageProvider = ({ initialMessages, children, request })=>{
|
|
6
|
+
const [isRequesting, setIsRequesting] = useState(false);
|
|
7
|
+
const messagesRef = useRef([]);
|
|
8
|
+
const [messages, setMessages] = useState([]);
|
|
9
|
+
useMount(()=>{
|
|
10
|
+
messagesRef.current = initialMessages.map((info)=>({
|
|
11
|
+
id: info.id,
|
|
12
|
+
status: 'success',
|
|
13
|
+
info
|
|
14
|
+
}));
|
|
15
|
+
setMessages([
|
|
16
|
+
...messagesRef.current
|
|
17
|
+
]);
|
|
18
|
+
});
|
|
19
|
+
const createAssistantMessage = useCallback(()=>{
|
|
20
|
+
const message = {
|
|
21
|
+
id: 'placeholder',
|
|
22
|
+
status: 'loading',
|
|
23
|
+
info: {
|
|
24
|
+
id: 'placeholder',
|
|
25
|
+
role: 'assistant',
|
|
26
|
+
content: ''
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
messagesRef.current.push(message);
|
|
30
|
+
}, []);
|
|
31
|
+
const createUserMessage = useCallback((info)=>{
|
|
32
|
+
const message = {
|
|
33
|
+
id: 'placeholder',
|
|
34
|
+
status: 'loading',
|
|
35
|
+
info: {
|
|
36
|
+
...info,
|
|
37
|
+
id: 'placeholder'
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
messagesRef.current.push(message);
|
|
41
|
+
}, []);
|
|
42
|
+
const completeUserMessage = useCallback((info)=>{
|
|
43
|
+
const index = messagesRef.current.findIndex((msg)=>'placeholder' === msg.id);
|
|
44
|
+
if (-1 !== index) {
|
|
45
|
+
const message = messagesRef.current[index];
|
|
46
|
+
message.status = 'success';
|
|
47
|
+
message.info = info;
|
|
48
|
+
message.id = info.id;
|
|
49
|
+
}
|
|
50
|
+
}, []);
|
|
51
|
+
const completeAssistantMessage = useCallback((id, info)=>{
|
|
52
|
+
const index = messagesRef.current.findIndex((msg)=>msg.id === id);
|
|
53
|
+
if (-1 !== index) {
|
|
54
|
+
const message = messagesRef.current[index];
|
|
55
|
+
message.status = 'success';
|
|
56
|
+
message.info = info;
|
|
57
|
+
message.id = info.id;
|
|
58
|
+
}
|
|
59
|
+
setIsRequesting(false);
|
|
60
|
+
}, []);
|
|
61
|
+
const updateMessage = useCallback((id, info)=>{
|
|
62
|
+
const index = messagesRef.current.findIndex((msg)=>msg.id === id);
|
|
63
|
+
if (-1 !== index) {
|
|
64
|
+
const message = messagesRef.current[index];
|
|
65
|
+
message.status = 'loading';
|
|
66
|
+
message.info = info;
|
|
67
|
+
message.id = info.id;
|
|
68
|
+
}
|
|
69
|
+
}, []);
|
|
70
|
+
const sendMessage = useCallback((info)=>{
|
|
71
|
+
setIsRequesting(true);
|
|
72
|
+
createUserMessage(info);
|
|
73
|
+
setMessages([
|
|
74
|
+
...messagesRef.current
|
|
75
|
+
]);
|
|
76
|
+
request(info, {
|
|
77
|
+
onCreated: (info)=>{
|
|
78
|
+
completeUserMessage(info);
|
|
79
|
+
createAssistantMessage();
|
|
80
|
+
console.log([
|
|
81
|
+
...messagesRef.current
|
|
82
|
+
]);
|
|
83
|
+
setMessages([
|
|
84
|
+
...messagesRef.current
|
|
85
|
+
]);
|
|
86
|
+
},
|
|
87
|
+
onUpdate: (id, info)=>{
|
|
88
|
+
updateMessage(id, info);
|
|
89
|
+
setMessages([
|
|
90
|
+
...messagesRef.current
|
|
91
|
+
]);
|
|
92
|
+
},
|
|
93
|
+
onSuccess: (id, info)=>{
|
|
94
|
+
completeAssistantMessage(id, info);
|
|
95
|
+
setMessages([
|
|
96
|
+
...messagesRef.current
|
|
97
|
+
]);
|
|
98
|
+
},
|
|
99
|
+
onError: (id, info)=>{
|
|
100
|
+
completeAssistantMessage(id, info);
|
|
101
|
+
setMessages([
|
|
102
|
+
...messagesRef.current
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}, [
|
|
107
|
+
completeAssistantMessage,
|
|
108
|
+
completeUserMessage,
|
|
109
|
+
createAssistantMessage,
|
|
110
|
+
createUserMessage,
|
|
111
|
+
request,
|
|
112
|
+
updateMessage,
|
|
113
|
+
setMessages
|
|
114
|
+
]);
|
|
115
|
+
return /*#__PURE__*/ jsx(MessageContext.Provider, {
|
|
116
|
+
value: {
|
|
117
|
+
messages,
|
|
118
|
+
sendMessage,
|
|
119
|
+
isRequesting
|
|
120
|
+
},
|
|
121
|
+
children: children
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
export { MessageContext, MessageProvider };
|
|
@@ -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 };
|