@nethru/kit 1.1.2 → 1.1.3
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.
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Stack } from "@mui/material";
|
|
3
|
+
import { useChatContext } from './contexts/ChatContext';
|
|
3
4
|
import ChatMessages from './ChatMessages';
|
|
4
5
|
import ChatInput from './ChatInput';
|
|
5
|
-
import useChatApi from './hooks/useChatApi';
|
|
6
6
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
7
|
function AiChat({
|
|
8
|
-
defaultMessages,
|
|
9
8
|
sx
|
|
10
9
|
}) {
|
|
11
10
|
const {
|
|
@@ -15,7 +14,7 @@ function AiChat({
|
|
|
15
14
|
isLoading,
|
|
16
15
|
chatContainerRef,
|
|
17
16
|
sendMessage
|
|
18
|
-
} =
|
|
17
|
+
} = useChatContext();
|
|
19
18
|
return /*#__PURE__*/_jsxs(Stack, {
|
|
20
19
|
sx: {
|
|
21
20
|
...styles.container,
|
|
@@ -37,7 +36,7 @@ export default AiChat;
|
|
|
37
36
|
const styles = {
|
|
38
37
|
container: {
|
|
39
38
|
width: '100%',
|
|
40
|
-
height: '
|
|
39
|
+
height: '100%',
|
|
41
40
|
background: 'white',
|
|
42
41
|
display: 'flex',
|
|
43
42
|
flexDirection: 'column',
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from 'react';
|
|
1
|
+
import React, { createContext, useContext, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { getConfig } from "../../../js/config";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
const ChatContext = /*#__PURE__*/createContext();
|
|
5
|
+
export function ChatProvider({
|
|
6
|
+
children,
|
|
7
|
+
defaultMessages = []
|
|
8
|
+
}) {
|
|
9
|
+
const [messages, setMessages] = useState(defaultMessages);
|
|
5
10
|
const [inputValue, setInputValue] = useState('');
|
|
6
11
|
const [isLoading, setIsLoading] = useState(false);
|
|
7
12
|
const [conversationId, setConversationId] = useState(null);
|
|
@@ -77,14 +82,32 @@ const useChatApi = defaultMessages => {
|
|
|
77
82
|
setIsLoading(false);
|
|
78
83
|
}
|
|
79
84
|
};
|
|
80
|
-
|
|
85
|
+
const clearChat = () => {
|
|
86
|
+
setMessages([]);
|
|
87
|
+
setConversationId(null);
|
|
88
|
+
setInputValue('');
|
|
89
|
+
};
|
|
90
|
+
const value = {
|
|
81
91
|
messages,
|
|
82
92
|
inputValue,
|
|
83
93
|
setInputValue,
|
|
84
94
|
isLoading,
|
|
85
95
|
tools,
|
|
86
96
|
chatContainerRef,
|
|
87
|
-
sendMessage
|
|
97
|
+
sendMessage,
|
|
98
|
+
clearChat,
|
|
99
|
+
conversationId
|
|
88
100
|
};
|
|
89
|
-
|
|
90
|
-
|
|
101
|
+
return /*#__PURE__*/_jsx(ChatContext.Provider, {
|
|
102
|
+
value: value,
|
|
103
|
+
children: children
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
export function useChatContext() {
|
|
107
|
+
const context = useContext(ChatContext);
|
|
108
|
+
if (!context) {
|
|
109
|
+
throw new Error('useChatContext must be used within a ChatProvider');
|
|
110
|
+
}
|
|
111
|
+
return context;
|
|
112
|
+
}
|
|
113
|
+
export default ChatContext;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { configure, getConfig } from './js/config';
|
|
2
2
|
export { default as AiChat } from './components/chat/AiChat';
|
|
3
|
+
export { ChatProvider, useChatContext } from './components/chat/contexts/ChatContext';
|
|
3
4
|
export { default as PieChart } from './components/charts/PieChart';
|
|
4
5
|
export { default as ColumnChart } from './components/charts/ColumnChart';
|
|
5
6
|
export { default as StackedAreaTrendChart } from './components/charts/StackedAreaTrendChart';
|