@gobolt/genesis 0.3.4 → 0.3.5
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,4 +1,3 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
1
|
import { default as Message } from './Message';
|
|
3
2
|
type Message = {
|
|
4
3
|
id: string;
|
|
@@ -6,6 +5,17 @@ type Message = {
|
|
|
6
5
|
sender: string;
|
|
7
6
|
isThinking?: boolean;
|
|
8
7
|
timestamp: string;
|
|
8
|
+
respondedBy?: "ai" | "search";
|
|
9
|
+
};
|
|
10
|
+
export type ChatHistoryRecord = {
|
|
11
|
+
visitorId: string;
|
|
12
|
+
visitorEmail: string;
|
|
13
|
+
name: string;
|
|
14
|
+
question: string;
|
|
15
|
+
response: string;
|
|
16
|
+
timeToRespond: number;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
responseBy: "search" | "ai";
|
|
9
19
|
};
|
|
10
20
|
export interface ChatProps {
|
|
11
21
|
socketUrl: string;
|
|
@@ -14,6 +24,8 @@ export interface ChatProps {
|
|
|
14
24
|
title?: string;
|
|
15
25
|
isSimulated?: boolean;
|
|
16
26
|
authToken?: string;
|
|
27
|
+
overrideStyle?: React.CSSProperties;
|
|
28
|
+
onChange?: (chatHistoryRecord: ChatHistoryRecord) => void;
|
|
17
29
|
}
|
|
18
|
-
declare const Chat:
|
|
30
|
+
declare const Chat: ({ socketUrl, isOpen, messageHistory, title, isSimulated, authToken, overrideStyle, onChange, }: ChatProps) => import("react/jsx-runtime").JSX.Element;
|
|
19
31
|
export default Chat;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StoryObj } from '@storybook/react';
|
|
2
2
|
declare const meta: {
|
|
3
3
|
title: string;
|
|
4
|
-
component: import('
|
|
4
|
+
component: ({ socketUrl, isOpen, messageHistory, title, isSimulated, authToken, overrideStyle, onChange, }: import('..').ChatProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
5
|
parameters: {
|
|
6
6
|
layout: string;
|
|
7
7
|
docs: {
|
package/dist/index.cjs
CHANGED
|
@@ -75336,7 +75336,8 @@ const ChatContainer = styled.div`
|
|
|
75336
75336
|
display: flex;
|
|
75337
75337
|
flex-direction: column;
|
|
75338
75338
|
position: relative;
|
|
75339
|
-
width:
|
|
75339
|
+
width: "100%";
|
|
75340
|
+
max-width: "800px";
|
|
75340
75341
|
overflow: hidden;
|
|
75341
75342
|
`;
|
|
75342
75343
|
const HeroContainer = styled.div`
|
|
@@ -75387,7 +75388,9 @@ const Chat = ({
|
|
|
75387
75388
|
messageHistory = [],
|
|
75388
75389
|
title = null,
|
|
75389
75390
|
isSimulated = false,
|
|
75390
|
-
authToken
|
|
75391
|
+
authToken,
|
|
75392
|
+
overrideStyle,
|
|
75393
|
+
onChange
|
|
75391
75394
|
}) => {
|
|
75392
75395
|
const [isChatOpen, setIsChatOpen] = React.useState(isOpen);
|
|
75393
75396
|
const [message2, setMessage] = React.useState("");
|
|
@@ -75399,6 +75402,8 @@ const Chat = ({
|
|
|
75399
75402
|
const serverReadyRef = React.useRef(false);
|
|
75400
75403
|
const handle = "user";
|
|
75401
75404
|
const [isLocked, setIsLocked] = React.useState(false);
|
|
75405
|
+
const [messageStartTime, setMessageStartTime] = React.useState(null);
|
|
75406
|
+
const [currentQuestion, setCurrentQuestion] = React.useState("");
|
|
75402
75407
|
React.useEffect(() => {
|
|
75403
75408
|
if (isSimulated) return;
|
|
75404
75409
|
const socketUrlToUse = window.location.hostname === "localhost" && window.location.port === "6006" ? "http://localhost:3000" : socketUrl;
|
|
@@ -75556,6 +75561,8 @@ const Chat = ({
|
|
|
75556
75561
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
75557
75562
|
};
|
|
75558
75563
|
setIsLocked(true);
|
|
75564
|
+
setMessageStartTime(Date.now());
|
|
75565
|
+
setCurrentQuestion(message2);
|
|
75559
75566
|
setMessages((prev2) => [...prev2, userMessage]);
|
|
75560
75567
|
if ((_a = socketRef.current) == null ? void 0 : _a.connected) {
|
|
75561
75568
|
const botMessageId = `bot_${timestamp}`;
|
|
@@ -75590,6 +75597,29 @@ const Chat = ({
|
|
|
75590
75597
|
}
|
|
75591
75598
|
setMessage("");
|
|
75592
75599
|
};
|
|
75600
|
+
React.useEffect(() => {
|
|
75601
|
+
const lastMessage = messages2.at(-1);
|
|
75602
|
+
if (!lastMessage || !messageStartTime || !currentQuestion) return;
|
|
75603
|
+
if (lastMessage.sender === "bot" && !lastMessage.isThinking) {
|
|
75604
|
+
const timeToRespond = Date.now() - messageStartTime;
|
|
75605
|
+
const chatHistoryRecord = {
|
|
75606
|
+
visitorId: "user",
|
|
75607
|
+
// You might want to get this from props or context
|
|
75608
|
+
visitorEmail: "",
|
|
75609
|
+
// You might want to get this from props or context
|
|
75610
|
+
name: handle,
|
|
75611
|
+
question: currentQuestion,
|
|
75612
|
+
response: lastMessage.content,
|
|
75613
|
+
timeToRespond,
|
|
75614
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
75615
|
+
responseBy: lastMessage.respondedBy || "ai"
|
|
75616
|
+
// Use the respondedBy from the message, default to "ai"
|
|
75617
|
+
};
|
|
75618
|
+
onChange == null ? void 0 : onChange(chatHistoryRecord);
|
|
75619
|
+
setMessageStartTime(null);
|
|
75620
|
+
setCurrentQuestion("");
|
|
75621
|
+
}
|
|
75622
|
+
}, [messages2, messageStartTime, currentQuestion, onChange, handle]);
|
|
75593
75623
|
const toggleChat = () => {
|
|
75594
75624
|
setIsChatOpen(!isChatOpen);
|
|
75595
75625
|
};
|
|
@@ -75603,9 +75633,9 @@ const Chat = ({
|
|
|
75603
75633
|
(msg, index2, self2) => index2 === self2.findIndex((t2) => t2.id === msg.id)
|
|
75604
75634
|
);
|
|
75605
75635
|
console.log("uniqueMessages", uniqueMessages);
|
|
75606
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(ChatContainer, { children: [
|
|
75636
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ChatContainer, { style: overrideStyle || {}, children: [
|
|
75607
75637
|
/* @__PURE__ */ jsxRuntime.jsx(HeroContainer, { $isVisible: !isChatOpen, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
75608
|
-
title
|
|
75638
|
+
title && /* @__PURE__ */ jsxRuntime.jsx(Typography, { variant: "heading3", children: title }),
|
|
75609
75639
|
/* @__PURE__ */ jsxRuntime.jsx(Subtitle, { children: "Click the Chat Icon below to begin" }),
|
|
75610
75640
|
serverError ? /* @__PURE__ */ jsxRuntime.jsx(ErrorMessage, { children: serverError }) : null
|
|
75611
75641
|
] }) }),
|
package/dist/index.js
CHANGED
|
@@ -75318,7 +75318,8 @@ const ChatContainer = styled.div`
|
|
|
75318
75318
|
display: flex;
|
|
75319
75319
|
flex-direction: column;
|
|
75320
75320
|
position: relative;
|
|
75321
|
-
width:
|
|
75321
|
+
width: "100%";
|
|
75322
|
+
max-width: "800px";
|
|
75322
75323
|
overflow: hidden;
|
|
75323
75324
|
`;
|
|
75324
75325
|
const HeroContainer = styled.div`
|
|
@@ -75369,7 +75370,9 @@ const Chat = ({
|
|
|
75369
75370
|
messageHistory = [],
|
|
75370
75371
|
title = null,
|
|
75371
75372
|
isSimulated = false,
|
|
75372
|
-
authToken
|
|
75373
|
+
authToken,
|
|
75374
|
+
overrideStyle,
|
|
75375
|
+
onChange
|
|
75373
75376
|
}) => {
|
|
75374
75377
|
const [isChatOpen, setIsChatOpen] = useState(isOpen);
|
|
75375
75378
|
const [message2, setMessage] = useState("");
|
|
@@ -75381,6 +75384,8 @@ const Chat = ({
|
|
|
75381
75384
|
const serverReadyRef = useRef(false);
|
|
75382
75385
|
const handle = "user";
|
|
75383
75386
|
const [isLocked, setIsLocked] = useState(false);
|
|
75387
|
+
const [messageStartTime, setMessageStartTime] = useState(null);
|
|
75388
|
+
const [currentQuestion, setCurrentQuestion] = useState("");
|
|
75384
75389
|
useEffect(() => {
|
|
75385
75390
|
if (isSimulated) return;
|
|
75386
75391
|
const socketUrlToUse = window.location.hostname === "localhost" && window.location.port === "6006" ? "http://localhost:3000" : socketUrl;
|
|
@@ -75538,6 +75543,8 @@ const Chat = ({
|
|
|
75538
75543
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
75539
75544
|
};
|
|
75540
75545
|
setIsLocked(true);
|
|
75546
|
+
setMessageStartTime(Date.now());
|
|
75547
|
+
setCurrentQuestion(message2);
|
|
75541
75548
|
setMessages((prev2) => [...prev2, userMessage]);
|
|
75542
75549
|
if ((_a = socketRef.current) == null ? void 0 : _a.connected) {
|
|
75543
75550
|
const botMessageId = `bot_${timestamp}`;
|
|
@@ -75572,6 +75579,29 @@ const Chat = ({
|
|
|
75572
75579
|
}
|
|
75573
75580
|
setMessage("");
|
|
75574
75581
|
};
|
|
75582
|
+
useEffect(() => {
|
|
75583
|
+
const lastMessage = messages2.at(-1);
|
|
75584
|
+
if (!lastMessage || !messageStartTime || !currentQuestion) return;
|
|
75585
|
+
if (lastMessage.sender === "bot" && !lastMessage.isThinking) {
|
|
75586
|
+
const timeToRespond = Date.now() - messageStartTime;
|
|
75587
|
+
const chatHistoryRecord = {
|
|
75588
|
+
visitorId: "user",
|
|
75589
|
+
// You might want to get this from props or context
|
|
75590
|
+
visitorEmail: "",
|
|
75591
|
+
// You might want to get this from props or context
|
|
75592
|
+
name: handle,
|
|
75593
|
+
question: currentQuestion,
|
|
75594
|
+
response: lastMessage.content,
|
|
75595
|
+
timeToRespond,
|
|
75596
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
75597
|
+
responseBy: lastMessage.respondedBy || "ai"
|
|
75598
|
+
// Use the respondedBy from the message, default to "ai"
|
|
75599
|
+
};
|
|
75600
|
+
onChange == null ? void 0 : onChange(chatHistoryRecord);
|
|
75601
|
+
setMessageStartTime(null);
|
|
75602
|
+
setCurrentQuestion("");
|
|
75603
|
+
}
|
|
75604
|
+
}, [messages2, messageStartTime, currentQuestion, onChange, handle]);
|
|
75575
75605
|
const toggleChat = () => {
|
|
75576
75606
|
setIsChatOpen(!isChatOpen);
|
|
75577
75607
|
};
|
|
@@ -75585,9 +75615,9 @@ const Chat = ({
|
|
|
75585
75615
|
(msg, index2, self2) => index2 === self2.findIndex((t2) => t2.id === msg.id)
|
|
75586
75616
|
);
|
|
75587
75617
|
console.log("uniqueMessages", uniqueMessages);
|
|
75588
|
-
return /* @__PURE__ */ jsxs(ChatContainer, { children: [
|
|
75618
|
+
return /* @__PURE__ */ jsxs(ChatContainer, { style: overrideStyle || {}, children: [
|
|
75589
75619
|
/* @__PURE__ */ jsx(HeroContainer, { $isVisible: !isChatOpen, children: /* @__PURE__ */ jsxs("div", { children: [
|
|
75590
|
-
title
|
|
75620
|
+
title && /* @__PURE__ */ jsx(Typography, { variant: "heading3", children: title }),
|
|
75591
75621
|
/* @__PURE__ */ jsx(Subtitle, { children: "Click the Chat Icon below to begin" }),
|
|
75592
75622
|
serverError ? /* @__PURE__ */ jsx(ErrorMessage, { children: serverError }) : null
|
|
75593
75623
|
] }) }),
|