@dmanikanta17/chat-ui 0.1.23 → 0.1.24
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/index.js +22 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -881,6 +881,7 @@ function ChatUI({
|
|
|
881
881
|
if (!endpoint) return;
|
|
882
882
|
setIsLoading(true);
|
|
883
883
|
abortControllerRef.current = new AbortController();
|
|
884
|
+
let currentBotMessageId = null;
|
|
884
885
|
try {
|
|
885
886
|
const historyForApi = currentHistory.map((msg) => ({
|
|
886
887
|
role: msg.role,
|
|
@@ -918,8 +919,10 @@ function ChatUI({
|
|
|
918
919
|
id: botMessageId,
|
|
919
920
|
role: "assistant",
|
|
920
921
|
content: aiResponse,
|
|
921
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
922
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
923
|
+
isStreaming: true
|
|
922
924
|
};
|
|
925
|
+
currentBotMessageId = botMessageId;
|
|
923
926
|
setMessages((prev) => [...prev, botMessage]);
|
|
924
927
|
} else {
|
|
925
928
|
setMessages((prev) => {
|
|
@@ -935,9 +938,24 @@ function ChatUI({
|
|
|
935
938
|
});
|
|
936
939
|
}
|
|
937
940
|
}
|
|
941
|
+
if (currentBotMessageId) {
|
|
942
|
+
setMessages(
|
|
943
|
+
(prev) => prev.map(
|
|
944
|
+
(msg) => msg.id === currentBotMessageId ? { ...msg, isStreaming: false } : msg
|
|
945
|
+
)
|
|
946
|
+
);
|
|
947
|
+
}
|
|
938
948
|
const audio = new Audio(soundSrc);
|
|
939
949
|
audio.play().catch((e) => console.error("Error playing notification sound:", e));
|
|
940
950
|
} catch (error) {
|
|
951
|
+
if (currentBotMessageId) {
|
|
952
|
+
setMessages(
|
|
953
|
+
(prev) => prev.map(
|
|
954
|
+
(msg) => msg.id === currentBotMessageId ? { ...msg, isStreaming: false } : msg
|
|
955
|
+
)
|
|
956
|
+
);
|
|
957
|
+
} else if (abortControllerRef.current) {
|
|
958
|
+
}
|
|
941
959
|
if (error.name === "AbortError") {
|
|
942
960
|
console.log("Generation stopped by user");
|
|
943
961
|
} else {
|
|
@@ -1195,8 +1213,9 @@ function ChatUI({
|
|
|
1195
1213
|
"div",
|
|
1196
1214
|
{
|
|
1197
1215
|
className: cn(
|
|
1198
|
-
"
|
|
1199
|
-
message.role === "user" ? "flex-row" : "flex-row"
|
|
1216
|
+
"items-center gap-1.5 px-1 select-none",
|
|
1217
|
+
message.role === "user" ? "flex-row" : "flex-row",
|
|
1218
|
+
message.isStreaming ? "hidden" : "flex"
|
|
1200
1219
|
),
|
|
1201
1220
|
children: [
|
|
1202
1221
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "text-[10px] text-muted-foreground whitespace-nowrap", children: message.createdAt ? new Date(message.createdAt).toLocaleTimeString([], {
|