@nethru/kit 1.1.17 → 1.1.18
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,8 +1,9 @@
|
|
|
1
1
|
import React, { useMemo } from 'react';
|
|
2
|
-
import { Box, keyframes } from '@mui/material';
|
|
2
|
+
import { Box, IconButton, keyframes, Stack, Tooltip } from '@mui/material';
|
|
3
3
|
import MarkdownContent from "./content/MarkdownContent";
|
|
4
4
|
import ToolContent from "./content/ToolContent";
|
|
5
5
|
import { ToolContextProvider } from "./contexts/ToolContext";
|
|
6
|
+
import ReplayRoundedIcon from "@mui/icons-material/ReplayRounded";
|
|
6
7
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
8
|
const slideIn = keyframes`
|
|
8
9
|
from {
|
|
@@ -15,20 +16,43 @@ const slideIn = keyframes`
|
|
|
15
16
|
}
|
|
16
17
|
`;
|
|
17
18
|
const ChatMessage = ({
|
|
18
|
-
message
|
|
19
|
+
message,
|
|
20
|
+
retryable,
|
|
21
|
+
onRetry
|
|
19
22
|
}) => {
|
|
20
23
|
const textContent = useMemo(() => message.content.filter(c => c.type === 'text'), [message]);
|
|
21
|
-
return /*#__PURE__*/_jsxs(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
return /*#__PURE__*/_jsxs(Stack, {
|
|
25
|
+
gap: 0.5,
|
|
26
|
+
sx: {
|
|
27
|
+
...styles.options.base,
|
|
28
|
+
...(retryable && styles.options.hover)
|
|
29
|
+
},
|
|
30
|
+
children: [/*#__PURE__*/_jsxs(Box, {
|
|
31
|
+
sx: message.role === 'user' ? styles.messageUser : styles.messageAssistant,
|
|
32
|
+
children: [/*#__PURE__*/_jsx(ToolContextProvider, {
|
|
33
|
+
message: message,
|
|
34
|
+
children: /*#__PURE__*/_jsx(ToolContent, {})
|
|
35
|
+
}), textContent.map((item, index) => /*#__PURE__*/_jsx(Box, {
|
|
36
|
+
sx: styles.contentItem,
|
|
37
|
+
children: /*#__PURE__*/_jsx(MarkdownContent, {
|
|
38
|
+
content: item.value
|
|
39
|
+
})
|
|
40
|
+
}, index))]
|
|
41
|
+
}), /*#__PURE__*/_jsx(Stack, {
|
|
42
|
+
className: "chat-options",
|
|
43
|
+
direction: "row",
|
|
44
|
+
justifyContent: "flex-end",
|
|
45
|
+
children: /*#__PURE__*/_jsx(Tooltip, {
|
|
46
|
+
title: "\uC7AC\uC2DC\uB3C4",
|
|
47
|
+
children: /*#__PURE__*/_jsx(IconButton, {
|
|
48
|
+
onClick: onRetry,
|
|
49
|
+
size: "small",
|
|
50
|
+
children: /*#__PURE__*/_jsx(ReplayRoundedIcon, {
|
|
51
|
+
fontSize: "small"
|
|
52
|
+
})
|
|
53
|
+
})
|
|
30
54
|
})
|
|
31
|
-
}
|
|
55
|
+
})]
|
|
32
56
|
});
|
|
33
57
|
};
|
|
34
58
|
export default ChatMessage;
|
|
@@ -72,5 +96,20 @@ const styles = {
|
|
|
72
96
|
'&:last-child': {
|
|
73
97
|
marginBottom: 0
|
|
74
98
|
}
|
|
99
|
+
},
|
|
100
|
+
options: {
|
|
101
|
+
base: {
|
|
102
|
+
'& .chat-options': {
|
|
103
|
+
opacity: 0,
|
|
104
|
+
pointerEvents: 'none',
|
|
105
|
+
transition: 'opacity 0.15s ease'
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
hover: {
|
|
109
|
+
'&:hover .chat-options': {
|
|
110
|
+
opacity: 1,
|
|
111
|
+
pointerEvents: 'auto'
|
|
112
|
+
}
|
|
113
|
+
}
|
|
75
114
|
}
|
|
76
115
|
};
|
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
1
|
+
import React, { useEffect, useMemo } from 'react';
|
|
2
2
|
import ChatMessage from './ChatMessage';
|
|
3
3
|
import LoadingIndicator from './LoadingIndicator';
|
|
4
|
+
import { useChatContext } from "./contexts/ChatContext";
|
|
4
5
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
6
|
const ChatMessages = ({
|
|
6
7
|
messages,
|
|
7
8
|
isLoading,
|
|
8
9
|
chatContainerRef
|
|
9
10
|
}) => {
|
|
11
|
+
const {
|
|
12
|
+
retrySend
|
|
13
|
+
} = useChatContext();
|
|
10
14
|
useEffect(() => {
|
|
11
15
|
if (messages.length === 0) return;
|
|
12
16
|
const message = messages[messages.length - 1];
|
|
13
17
|
//if(message.role === 'assistant') console.log(message);
|
|
14
18
|
}, [messages.length]);
|
|
19
|
+
const lastUserIdx = useMemo(() => messages.findLastIndex(m => m.role === 'user'), [messages.length]);
|
|
15
20
|
return /*#__PURE__*/_jsxs("div", {
|
|
16
21
|
style: styles.container,
|
|
17
22
|
ref: chatContainerRef,
|
|
18
23
|
children: [messages.map((message, index) => /*#__PURE__*/_jsx(ChatMessage, {
|
|
19
|
-
message: message
|
|
24
|
+
message: message,
|
|
25
|
+
retryable: !isLoading && index === lastUserIdx,
|
|
26
|
+
onRetry: _ => retrySend(message.content[0].value)
|
|
20
27
|
}, index)), isLoading && /*#__PURE__*/_jsx(LoadingIndicator, {})]
|
|
21
28
|
});
|
|
22
29
|
};
|
|
@@ -28,7 +35,6 @@ const styles = {
|
|
|
28
35
|
padding: '10px',
|
|
29
36
|
display: 'flex',
|
|
30
37
|
flexDirection: 'column',
|
|
31
|
-
gap: '1rem',
|
|
32
38
|
background: '#fcfcfd'
|
|
33
39
|
}
|
|
34
40
|
};
|
|
@@ -101,18 +101,20 @@ export function ChatProvider({
|
|
|
101
101
|
});
|
|
102
102
|
return await response.json();
|
|
103
103
|
}
|
|
104
|
-
const sendMessage = async () => {
|
|
105
|
-
const message = inputValue.trim();
|
|
104
|
+
const sendMessage = async (messageToSend = null) => {
|
|
105
|
+
const message = messageToSend ?? inputValue.trim();
|
|
106
106
|
if (!message) return;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
107
|
+
if (!messageToSend) {
|
|
108
|
+
const userMessage = {
|
|
109
|
+
role: 'user',
|
|
110
|
+
content: [{
|
|
111
|
+
type: 'text',
|
|
112
|
+
value: message
|
|
113
|
+
}]
|
|
114
|
+
};
|
|
115
|
+
setMessages(prev => [...prev, userMessage]);
|
|
116
|
+
setInputValue('');
|
|
117
|
+
}
|
|
116
118
|
setIsLoading(true);
|
|
117
119
|
try {
|
|
118
120
|
let data = option === 'ANALYZE' ? await analyzePage(message) : await answer(message);
|
|
@@ -140,6 +142,10 @@ export function ChatProvider({
|
|
|
140
142
|
setConversationId(null);
|
|
141
143
|
setInputValue('');
|
|
142
144
|
};
|
|
145
|
+
const retrySend = async retryMessage => {
|
|
146
|
+
setMessages(prev => prev.at(-1)?.role === 'assistant' ? prev.slice(0, -1) : prev);
|
|
147
|
+
await sendMessage(retryMessage);
|
|
148
|
+
};
|
|
143
149
|
const value = {
|
|
144
150
|
messages,
|
|
145
151
|
inputValue,
|
|
@@ -159,6 +165,7 @@ export function ChatProvider({
|
|
|
159
165
|
chatContainerRef,
|
|
160
166
|
pageRef,
|
|
161
167
|
sendMessage,
|
|
168
|
+
retrySend,
|
|
162
169
|
clearChat,
|
|
163
170
|
conversationId
|
|
164
171
|
};
|