@gobolt/genesis 0.3.2 → 0.3.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.
- package/dist/components/Chat/Message.d.ts +1 -0
- package/dist/index.cjs +85 -58
- package/dist/index.js +85 -58
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -74920,20 +74920,7 @@ const Message$1 = ({ message: message2, handle, isThinking = false }) => {
|
|
|
74920
74920
|
const isBot = handle === "bot";
|
|
74921
74921
|
return /* @__PURE__ */ jsxRuntime.jsxs(MessageContainer, { $isBot: isBot, children: [
|
|
74922
74922
|
/* @__PURE__ */ jsxRuntime.jsx(IconContainer, { children: isBot ? /* @__PURE__ */ jsxRuntime.jsx(BotIcon, {}) : /* @__PURE__ */ jsxRuntime.jsx(UserIcon, {}) }),
|
|
74923
|
-
/* @__PURE__ */ jsxRuntime.jsx(TextContainer, { $isBot: isBot, children: isThinking ? /* @__PURE__ */ jsxRuntime.jsx(ThinkingIndicator, {}) : handle === "bot" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
74924
|
-
Markdown,
|
|
74925
|
-
{
|
|
74926
|
-
components: {
|
|
74927
|
-
p: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mb-2 last:mb-0", children }),
|
|
74928
|
-
ul: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "list-disc pl-4 mb-2", children }),
|
|
74929
|
-
ol: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("ol", { className: "list-decimal pl-4 mb-2", children }),
|
|
74930
|
-
li: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("li", { className: "mb-1", children }),
|
|
74931
|
-
code: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("code", { className: "bg-gray-200 rounded px-1 py-0.5", children }),
|
|
74932
|
-
pre: ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "bg-gray-200 rounded p-2 mb-2 overflow-x-auto", children })
|
|
74933
|
-
},
|
|
74934
|
-
children: message2
|
|
74935
|
-
}
|
|
74936
|
-
) : /* @__PURE__ */ jsxRuntime.jsx(MessageText, { children: message2 }) })
|
|
74923
|
+
/* @__PURE__ */ jsxRuntime.jsx(TextContainer, { $isBot: isBot, children: isThinking ? /* @__PURE__ */ jsxRuntime.jsx(ThinkingIndicator, {}) : handle === "bot" ? /* @__PURE__ */ jsxRuntime.jsx(Markdown, { children: message2 }) : /* @__PURE__ */ jsxRuntime.jsx(MessageText, { children: message2 }) })
|
|
74937
74924
|
] });
|
|
74938
74925
|
};
|
|
74939
74926
|
const getStateColors = (colors2, type4, state) => {
|
|
@@ -75349,7 +75336,7 @@ const ChatContainer = styled.div`
|
|
|
75349
75336
|
display: flex;
|
|
75350
75337
|
flex-direction: column;
|
|
75351
75338
|
position: relative;
|
|
75352
|
-
width:
|
|
75339
|
+
width: 600px;
|
|
75353
75340
|
overflow: hidden;
|
|
75354
75341
|
`;
|
|
75355
75342
|
const HeroContainer = styled.div`
|
|
@@ -75413,21 +75400,40 @@ const Chat = ({
|
|
|
75413
75400
|
const [isLocked, setIsLocked] = React.useState(false);
|
|
75414
75401
|
React.useEffect(() => {
|
|
75415
75402
|
if (isSimulated) return;
|
|
75416
|
-
|
|
75417
|
-
|
|
75418
|
-
|
|
75419
|
-
|
|
75420
|
-
|
|
75403
|
+
const socketUrlToUse = window.location.hostname === "localhost" && window.location.port === "6006" ? "http://localhost:3000" : socketUrl;
|
|
75404
|
+
console.log("Connecting to socket server at:", socketUrlToUse);
|
|
75405
|
+
socketRef.current = lookup(socketUrlToUse, {
|
|
75406
|
+
transports: ["polling", "websocket"],
|
|
75407
|
+
reconnection: true,
|
|
75408
|
+
reconnectionAttempts: 5,
|
|
75409
|
+
reconnectionDelay: 1e3,
|
|
75410
|
+
withCredentials: true,
|
|
75411
|
+
forceNew: true,
|
|
75412
|
+
autoConnect: true,
|
|
75413
|
+
timeout: 1e4
|
|
75421
75414
|
});
|
|
75422
75415
|
const socket = socketRef.current;
|
|
75423
75416
|
socket.on("connect", () => {
|
|
75424
75417
|
console.log("Socket connected successfully");
|
|
75418
|
+
setServerError("");
|
|
75419
|
+
setServerStatus("ready");
|
|
75420
|
+
serverReadyRef.current = true;
|
|
75425
75421
|
});
|
|
75426
75422
|
socket.on("connect_error", (error2) => {
|
|
75427
75423
|
console.error("Socket connection error:", error2);
|
|
75428
|
-
setServerError(
|
|
75424
|
+
setServerError(`Connection error: ${error2.message}`);
|
|
75425
|
+
setServerStatus("error");
|
|
75426
|
+
serverReadyRef.current = false;
|
|
75427
|
+
setMessages((prev2) => prev2.filter((msg) => !msg.isThinking));
|
|
75428
|
+
setIsLocked(false);
|
|
75429
|
+
});
|
|
75430
|
+
socket.on("disconnect", (reason) => {
|
|
75431
|
+
console.log("Socket disconnected:", reason);
|
|
75432
|
+
setServerError(`Disconnected: ${reason}`);
|
|
75429
75433
|
setServerStatus("error");
|
|
75430
75434
|
serverReadyRef.current = false;
|
|
75435
|
+
setMessages((prev2) => prev2.filter((msg) => !msg.isThinking));
|
|
75436
|
+
setIsLocked(false);
|
|
75431
75437
|
});
|
|
75432
75438
|
socket.on("new connection", () => {
|
|
75433
75439
|
console.log("New connection established");
|
|
@@ -75441,16 +75447,20 @@ const Chat = ({
|
|
|
75441
75447
|
socket.on("message", (newMessage) => {
|
|
75442
75448
|
setMessages((prev2) => {
|
|
75443
75449
|
if (newMessage.sender === "bot") {
|
|
75444
|
-
|
|
75445
|
-
|
|
75446
|
-
if (
|
|
75447
|
-
|
|
75448
|
-
return { ...newMessage, isThinking: false };
|
|
75450
|
+
if (newMessage.content === "Processing your message...") {
|
|
75451
|
+
const hasThinkingMessage = prev2.some((msg) => msg.isThinking);
|
|
75452
|
+
if (hasThinkingMessage) {
|
|
75453
|
+
return prev2;
|
|
75449
75454
|
}
|
|
75450
|
-
return
|
|
75451
|
-
}
|
|
75452
|
-
|
|
75453
|
-
|
|
75455
|
+
return [...prev2, { ...newMessage, isThinking: true }];
|
|
75456
|
+
}
|
|
75457
|
+
const thinkingMessage = prev2.find((msg) => msg.isThinking);
|
|
75458
|
+
if (thinkingMessage) {
|
|
75459
|
+
return prev2.map(
|
|
75460
|
+
(msg) => msg.isThinking ? { ...newMessage, isThinking: false } : msg
|
|
75461
|
+
);
|
|
75462
|
+
}
|
|
75463
|
+
return [...prev2, { ...newMessage, isThinking: false }];
|
|
75454
75464
|
}
|
|
75455
75465
|
const lastUserMsg = [...prev2].reverse().find((msg) => msg.sender === "user");
|
|
75456
75466
|
if (lastUserMsg && lastUserMsg.content === newMessage.content) {
|
|
@@ -75458,6 +75468,7 @@ const Chat = ({
|
|
|
75458
75468
|
}
|
|
75459
75469
|
return [...prev2, newMessage];
|
|
75460
75470
|
});
|
|
75471
|
+
setIsLocked(false);
|
|
75461
75472
|
});
|
|
75462
75473
|
socket.on("update-bot-message", (updatedData) => {
|
|
75463
75474
|
console.log("Received bot message update:", updatedData);
|
|
@@ -75477,8 +75488,10 @@ const Chat = ({
|
|
|
75477
75488
|
const timeoutId = setTimeout(() => {
|
|
75478
75489
|
if (!serverReadyRef.current) {
|
|
75479
75490
|
console.log("Server status check failed");
|
|
75480
|
-
setServerError("
|
|
75491
|
+
setServerError("Server status check failed - please check the server");
|
|
75481
75492
|
setServerStatus("error");
|
|
75493
|
+
setMessages((prev2) => prev2.filter((msg) => !msg.isThinking));
|
|
75494
|
+
setIsLocked(false);
|
|
75482
75495
|
}
|
|
75483
75496
|
}, 2e3);
|
|
75484
75497
|
return () => {
|
|
@@ -75505,41 +75518,48 @@ const Chat = ({
|
|
|
75505
75518
|
}
|
|
75506
75519
|
};
|
|
75507
75520
|
const sendMessage = () => {
|
|
75508
|
-
var _a;
|
|
75521
|
+
var _a, _b;
|
|
75509
75522
|
if (!message2.trim() || isLocked) return;
|
|
75523
|
+
const timestamp = Date.now();
|
|
75510
75524
|
const userMessage = {
|
|
75511
75525
|
content: message2,
|
|
75512
75526
|
sender: handle,
|
|
75513
|
-
id: `
|
|
75514
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
75515
|
-
};
|
|
75516
|
-
const thinkingMessage = {
|
|
75517
|
-
content: "",
|
|
75518
|
-
sender: "bot",
|
|
75519
|
-
id: `id_${Date.now()}_thinking`,
|
|
75520
|
-
isThinking: true,
|
|
75527
|
+
id: `user_${timestamp}_${Math.random().toString(36).substr(2, 9)}`,
|
|
75521
75528
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
75522
75529
|
};
|
|
75523
75530
|
setIsLocked(true);
|
|
75524
|
-
setMessages((prev2) => [...prev2,
|
|
75525
|
-
if (
|
|
75531
|
+
setMessages((prev2) => [...prev2, userMessage]);
|
|
75532
|
+
if ((_a = socketRef.current) == null ? void 0 : _a.connected) {
|
|
75533
|
+
const botMessageId = `bot_${timestamp}`;
|
|
75534
|
+
const thinkingMessage = {
|
|
75535
|
+
content: "",
|
|
75536
|
+
sender: "bot",
|
|
75537
|
+
id: botMessageId,
|
|
75538
|
+
isThinking: true,
|
|
75539
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
75540
|
+
};
|
|
75541
|
+
setMessages((prev2) => [...prev2, thinkingMessage]);
|
|
75542
|
+
}
|
|
75543
|
+
if (!((_b = socketRef.current) == null ? void 0 : _b.connected)) {
|
|
75526
75544
|
setServerError("Not connected to server");
|
|
75527
75545
|
setIsLocked(false);
|
|
75528
75546
|
return;
|
|
75529
75547
|
}
|
|
75530
75548
|
socketRef.current.emit("message", userMessage);
|
|
75531
|
-
|
|
75532
|
-
|
|
75533
|
-
(
|
|
75534
|
-
(
|
|
75535
|
-
|
|
75536
|
-
|
|
75537
|
-
|
|
75538
|
-
|
|
75539
|
-
|
|
75540
|
-
|
|
75541
|
-
|
|
75542
|
-
|
|
75549
|
+
if (socketRef.current.connected) {
|
|
75550
|
+
setTimeout(() => {
|
|
75551
|
+
setMessages(
|
|
75552
|
+
(prev2) => prev2.map(
|
|
75553
|
+
(msg) => msg.isThinking ? { ...msg, content: "Processing your message..." } : msg
|
|
75554
|
+
)
|
|
75555
|
+
);
|
|
75556
|
+
}, 300);
|
|
75557
|
+
setTimeout(() => {
|
|
75558
|
+
setMessages((prev2) => prev2.filter((msg) => !msg.isThinking));
|
|
75559
|
+
setServerError("No response from server");
|
|
75560
|
+
setIsLocked(false);
|
|
75561
|
+
}, 1e4);
|
|
75562
|
+
}
|
|
75543
75563
|
setMessage("");
|
|
75544
75564
|
};
|
|
75545
75565
|
const toggleChat = () => {
|
|
@@ -75548,15 +75568,22 @@ const Chat = ({
|
|
|
75548
75568
|
const handleInputChange = (e2) => {
|
|
75549
75569
|
setMessage(e2.payload.value);
|
|
75550
75570
|
};
|
|
75571
|
+
if (serverStatus === "error") {
|
|
75572
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ErrorMessage, { children: "Network error" });
|
|
75573
|
+
}
|
|
75574
|
+
const uniqueMessages = messages2.filter(
|
|
75575
|
+
(msg, index2, self2) => index2 === self2.findIndex((t2) => t2.id === msg.id)
|
|
75576
|
+
);
|
|
75577
|
+
console.log("uniqueMessages", uniqueMessages);
|
|
75551
75578
|
return /* @__PURE__ */ jsxRuntime.jsxs(ChatContainer, { children: [
|
|
75552
75579
|
/* @__PURE__ */ jsxRuntime.jsx(HeroContainer, { $isVisible: !isChatOpen, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
75553
|
-
title
|
|
75580
|
+
title ? /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "heading3", children: title }) : null,
|
|
75554
75581
|
/* @__PURE__ */ jsxRuntime.jsx(Subtitle, { children: "Click the Chat Icon below to begin" }),
|
|
75555
|
-
serverError
|
|
75582
|
+
serverError ? /* @__PURE__ */ jsxRuntime.jsx(ErrorMessage, { children: serverError }) : null
|
|
75556
75583
|
] }) }),
|
|
75557
75584
|
isChatOpen ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
75558
|
-
/* @__PURE__ */ jsxRuntime.jsx(HeroContainer, { $isVisible: true, children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: title
|
|
75559
|
-
/* @__PURE__ */ jsxRuntime.jsx(MessageList, { ref: messageListRef, children:
|
|
75585
|
+
/* @__PURE__ */ jsxRuntime.jsx(HeroContainer, { $isVisible: true, children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: title ? /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "heading2", children: title }) : null }) }),
|
|
75586
|
+
/* @__PURE__ */ jsxRuntime.jsx(MessageList, { ref: messageListRef, children: uniqueMessages.map((msg) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
75560
75587
|
Message$1,
|
|
75561
75588
|
{
|
|
75562
75589
|
message: msg.content,
|
package/dist/index.js
CHANGED
|
@@ -74902,20 +74902,7 @@ const Message$1 = ({ message: message2, handle, isThinking = false }) => {
|
|
|
74902
74902
|
const isBot = handle === "bot";
|
|
74903
74903
|
return /* @__PURE__ */ jsxs(MessageContainer, { $isBot: isBot, children: [
|
|
74904
74904
|
/* @__PURE__ */ jsx(IconContainer, { children: isBot ? /* @__PURE__ */ jsx(BotIcon, {}) : /* @__PURE__ */ jsx(UserIcon, {}) }),
|
|
74905
|
-
/* @__PURE__ */ jsx(TextContainer, { $isBot: isBot, children: isThinking ? /* @__PURE__ */ jsx(ThinkingIndicator, {}) : handle === "bot" ? /* @__PURE__ */ jsx(
|
|
74906
|
-
Markdown,
|
|
74907
|
-
{
|
|
74908
|
-
components: {
|
|
74909
|
-
p: ({ children }) => /* @__PURE__ */ jsx("p", { className: "mb-2 last:mb-0", children }),
|
|
74910
|
-
ul: ({ children }) => /* @__PURE__ */ jsx("ul", { className: "list-disc pl-4 mb-2", children }),
|
|
74911
|
-
ol: ({ children }) => /* @__PURE__ */ jsx("ol", { className: "list-decimal pl-4 mb-2", children }),
|
|
74912
|
-
li: ({ children }) => /* @__PURE__ */ jsx("li", { className: "mb-1", children }),
|
|
74913
|
-
code: ({ children }) => /* @__PURE__ */ jsx("code", { className: "bg-gray-200 rounded px-1 py-0.5", children }),
|
|
74914
|
-
pre: ({ children }) => /* @__PURE__ */ jsx("pre", { className: "bg-gray-200 rounded p-2 mb-2 overflow-x-auto", children })
|
|
74915
|
-
},
|
|
74916
|
-
children: message2
|
|
74917
|
-
}
|
|
74918
|
-
) : /* @__PURE__ */ jsx(MessageText, { children: message2 }) })
|
|
74905
|
+
/* @__PURE__ */ jsx(TextContainer, { $isBot: isBot, children: isThinking ? /* @__PURE__ */ jsx(ThinkingIndicator, {}) : handle === "bot" ? /* @__PURE__ */ jsx(Markdown, { children: message2 }) : /* @__PURE__ */ jsx(MessageText, { children: message2 }) })
|
|
74919
74906
|
] });
|
|
74920
74907
|
};
|
|
74921
74908
|
const getStateColors = (colors2, type4, state) => {
|
|
@@ -75331,7 +75318,7 @@ const ChatContainer = styled.div`
|
|
|
75331
75318
|
display: flex;
|
|
75332
75319
|
flex-direction: column;
|
|
75333
75320
|
position: relative;
|
|
75334
|
-
width:
|
|
75321
|
+
width: 600px;
|
|
75335
75322
|
overflow: hidden;
|
|
75336
75323
|
`;
|
|
75337
75324
|
const HeroContainer = styled.div`
|
|
@@ -75395,21 +75382,40 @@ const Chat = ({
|
|
|
75395
75382
|
const [isLocked, setIsLocked] = useState(false);
|
|
75396
75383
|
useEffect(() => {
|
|
75397
75384
|
if (isSimulated) return;
|
|
75398
|
-
|
|
75399
|
-
|
|
75400
|
-
|
|
75401
|
-
|
|
75402
|
-
|
|
75385
|
+
const socketUrlToUse = window.location.hostname === "localhost" && window.location.port === "6006" ? "http://localhost:3000" : socketUrl;
|
|
75386
|
+
console.log("Connecting to socket server at:", socketUrlToUse);
|
|
75387
|
+
socketRef.current = lookup(socketUrlToUse, {
|
|
75388
|
+
transports: ["polling", "websocket"],
|
|
75389
|
+
reconnection: true,
|
|
75390
|
+
reconnectionAttempts: 5,
|
|
75391
|
+
reconnectionDelay: 1e3,
|
|
75392
|
+
withCredentials: true,
|
|
75393
|
+
forceNew: true,
|
|
75394
|
+
autoConnect: true,
|
|
75395
|
+
timeout: 1e4
|
|
75403
75396
|
});
|
|
75404
75397
|
const socket = socketRef.current;
|
|
75405
75398
|
socket.on("connect", () => {
|
|
75406
75399
|
console.log("Socket connected successfully");
|
|
75400
|
+
setServerError("");
|
|
75401
|
+
setServerStatus("ready");
|
|
75402
|
+
serverReadyRef.current = true;
|
|
75407
75403
|
});
|
|
75408
75404
|
socket.on("connect_error", (error2) => {
|
|
75409
75405
|
console.error("Socket connection error:", error2);
|
|
75410
|
-
setServerError(
|
|
75406
|
+
setServerError(`Connection error: ${error2.message}`);
|
|
75407
|
+
setServerStatus("error");
|
|
75408
|
+
serverReadyRef.current = false;
|
|
75409
|
+
setMessages((prev2) => prev2.filter((msg) => !msg.isThinking));
|
|
75410
|
+
setIsLocked(false);
|
|
75411
|
+
});
|
|
75412
|
+
socket.on("disconnect", (reason) => {
|
|
75413
|
+
console.log("Socket disconnected:", reason);
|
|
75414
|
+
setServerError(`Disconnected: ${reason}`);
|
|
75411
75415
|
setServerStatus("error");
|
|
75412
75416
|
serverReadyRef.current = false;
|
|
75417
|
+
setMessages((prev2) => prev2.filter((msg) => !msg.isThinking));
|
|
75418
|
+
setIsLocked(false);
|
|
75413
75419
|
});
|
|
75414
75420
|
socket.on("new connection", () => {
|
|
75415
75421
|
console.log("New connection established");
|
|
@@ -75423,16 +75429,20 @@ const Chat = ({
|
|
|
75423
75429
|
socket.on("message", (newMessage) => {
|
|
75424
75430
|
setMessages((prev2) => {
|
|
75425
75431
|
if (newMessage.sender === "bot") {
|
|
75426
|
-
|
|
75427
|
-
|
|
75428
|
-
if (
|
|
75429
|
-
|
|
75430
|
-
return { ...newMessage, isThinking: false };
|
|
75432
|
+
if (newMessage.content === "Processing your message...") {
|
|
75433
|
+
const hasThinkingMessage = prev2.some((msg) => msg.isThinking);
|
|
75434
|
+
if (hasThinkingMessage) {
|
|
75435
|
+
return prev2;
|
|
75431
75436
|
}
|
|
75432
|
-
return
|
|
75433
|
-
}
|
|
75434
|
-
|
|
75435
|
-
|
|
75437
|
+
return [...prev2, { ...newMessage, isThinking: true }];
|
|
75438
|
+
}
|
|
75439
|
+
const thinkingMessage = prev2.find((msg) => msg.isThinking);
|
|
75440
|
+
if (thinkingMessage) {
|
|
75441
|
+
return prev2.map(
|
|
75442
|
+
(msg) => msg.isThinking ? { ...newMessage, isThinking: false } : msg
|
|
75443
|
+
);
|
|
75444
|
+
}
|
|
75445
|
+
return [...prev2, { ...newMessage, isThinking: false }];
|
|
75436
75446
|
}
|
|
75437
75447
|
const lastUserMsg = [...prev2].reverse().find((msg) => msg.sender === "user");
|
|
75438
75448
|
if (lastUserMsg && lastUserMsg.content === newMessage.content) {
|
|
@@ -75440,6 +75450,7 @@ const Chat = ({
|
|
|
75440
75450
|
}
|
|
75441
75451
|
return [...prev2, newMessage];
|
|
75442
75452
|
});
|
|
75453
|
+
setIsLocked(false);
|
|
75443
75454
|
});
|
|
75444
75455
|
socket.on("update-bot-message", (updatedData) => {
|
|
75445
75456
|
console.log("Received bot message update:", updatedData);
|
|
@@ -75459,8 +75470,10 @@ const Chat = ({
|
|
|
75459
75470
|
const timeoutId = setTimeout(() => {
|
|
75460
75471
|
if (!serverReadyRef.current) {
|
|
75461
75472
|
console.log("Server status check failed");
|
|
75462
|
-
setServerError("
|
|
75473
|
+
setServerError("Server status check failed - please check the server");
|
|
75463
75474
|
setServerStatus("error");
|
|
75475
|
+
setMessages((prev2) => prev2.filter((msg) => !msg.isThinking));
|
|
75476
|
+
setIsLocked(false);
|
|
75464
75477
|
}
|
|
75465
75478
|
}, 2e3);
|
|
75466
75479
|
return () => {
|
|
@@ -75487,41 +75500,48 @@ const Chat = ({
|
|
|
75487
75500
|
}
|
|
75488
75501
|
};
|
|
75489
75502
|
const sendMessage = () => {
|
|
75490
|
-
var _a;
|
|
75503
|
+
var _a, _b;
|
|
75491
75504
|
if (!message2.trim() || isLocked) return;
|
|
75505
|
+
const timestamp = Date.now();
|
|
75492
75506
|
const userMessage = {
|
|
75493
75507
|
content: message2,
|
|
75494
75508
|
sender: handle,
|
|
75495
|
-
id: `
|
|
75496
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
75497
|
-
};
|
|
75498
|
-
const thinkingMessage = {
|
|
75499
|
-
content: "",
|
|
75500
|
-
sender: "bot",
|
|
75501
|
-
id: `id_${Date.now()}_thinking`,
|
|
75502
|
-
isThinking: true,
|
|
75509
|
+
id: `user_${timestamp}_${Math.random().toString(36).substr(2, 9)}`,
|
|
75503
75510
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
75504
75511
|
};
|
|
75505
75512
|
setIsLocked(true);
|
|
75506
|
-
setMessages((prev2) => [...prev2,
|
|
75507
|
-
if (
|
|
75513
|
+
setMessages((prev2) => [...prev2, userMessage]);
|
|
75514
|
+
if ((_a = socketRef.current) == null ? void 0 : _a.connected) {
|
|
75515
|
+
const botMessageId = `bot_${timestamp}`;
|
|
75516
|
+
const thinkingMessage = {
|
|
75517
|
+
content: "",
|
|
75518
|
+
sender: "bot",
|
|
75519
|
+
id: botMessageId,
|
|
75520
|
+
isThinking: true,
|
|
75521
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
75522
|
+
};
|
|
75523
|
+
setMessages((prev2) => [...prev2, thinkingMessage]);
|
|
75524
|
+
}
|
|
75525
|
+
if (!((_b = socketRef.current) == null ? void 0 : _b.connected)) {
|
|
75508
75526
|
setServerError("Not connected to server");
|
|
75509
75527
|
setIsLocked(false);
|
|
75510
75528
|
return;
|
|
75511
75529
|
}
|
|
75512
75530
|
socketRef.current.emit("message", userMessage);
|
|
75513
|
-
|
|
75514
|
-
|
|
75515
|
-
(
|
|
75516
|
-
(
|
|
75517
|
-
|
|
75518
|
-
|
|
75519
|
-
|
|
75520
|
-
|
|
75521
|
-
|
|
75522
|
-
|
|
75523
|
-
|
|
75524
|
-
|
|
75531
|
+
if (socketRef.current.connected) {
|
|
75532
|
+
setTimeout(() => {
|
|
75533
|
+
setMessages(
|
|
75534
|
+
(prev2) => prev2.map(
|
|
75535
|
+
(msg) => msg.isThinking ? { ...msg, content: "Processing your message..." } : msg
|
|
75536
|
+
)
|
|
75537
|
+
);
|
|
75538
|
+
}, 300);
|
|
75539
|
+
setTimeout(() => {
|
|
75540
|
+
setMessages((prev2) => prev2.filter((msg) => !msg.isThinking));
|
|
75541
|
+
setServerError("No response from server");
|
|
75542
|
+
setIsLocked(false);
|
|
75543
|
+
}, 1e4);
|
|
75544
|
+
}
|
|
75525
75545
|
setMessage("");
|
|
75526
75546
|
};
|
|
75527
75547
|
const toggleChat = () => {
|
|
@@ -75530,15 +75550,22 @@ const Chat = ({
|
|
|
75530
75550
|
const handleInputChange = (e2) => {
|
|
75531
75551
|
setMessage(e2.payload.value);
|
|
75532
75552
|
};
|
|
75553
|
+
if (serverStatus === "error") {
|
|
75554
|
+
return /* @__PURE__ */ jsx(ErrorMessage, { children: "Network error" });
|
|
75555
|
+
}
|
|
75556
|
+
const uniqueMessages = messages2.filter(
|
|
75557
|
+
(msg, index2, self2) => index2 === self2.findIndex((t2) => t2.id === msg.id)
|
|
75558
|
+
);
|
|
75559
|
+
console.log("uniqueMessages", uniqueMessages);
|
|
75533
75560
|
return /* @__PURE__ */ jsxs(ChatContainer, { children: [
|
|
75534
75561
|
/* @__PURE__ */ jsx(HeroContainer, { $isVisible: !isChatOpen, children: /* @__PURE__ */ jsxs("div", { children: [
|
|
75535
|
-
title
|
|
75562
|
+
title ? /* @__PURE__ */ jsx(Typography, { variant: "heading3", children: title }) : null,
|
|
75536
75563
|
/* @__PURE__ */ jsx(Subtitle, { children: "Click the Chat Icon below to begin" }),
|
|
75537
|
-
serverError
|
|
75564
|
+
serverError ? /* @__PURE__ */ jsx(ErrorMessage, { children: serverError }) : null
|
|
75538
75565
|
] }) }),
|
|
75539
75566
|
isChatOpen ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
75540
|
-
/* @__PURE__ */ jsx(HeroContainer, { $isVisible: true, children: /* @__PURE__ */ jsx("div", { children: title
|
|
75541
|
-
/* @__PURE__ */ jsx(MessageList, { ref: messageListRef, children:
|
|
75567
|
+
/* @__PURE__ */ jsx(HeroContainer, { $isVisible: true, children: /* @__PURE__ */ jsx("div", { children: title ? /* @__PURE__ */ jsx(Typography, { variant: "heading2", children: title }) : null }) }),
|
|
75568
|
+
/* @__PURE__ */ jsx(MessageList, { ref: messageListRef, children: uniqueMessages.map((msg) => /* @__PURE__ */ jsx(
|
|
75542
75569
|
Message$1,
|
|
75543
75570
|
{
|
|
75544
75571
|
message: msg.content,
|