@constructor-io/constructorio-ui-pia 2.0.0 → 2.1.1
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/LICENSE +1 -1
- package/README.md +219 -15
- package/dist/constructorio-ui-pia-bundled.js +11 -11
- package/lib/cjs/components/Answer/Answer.js +13 -0
- package/lib/cjs/components/Answer/AnswerStyles.css +8 -0
- package/lib/cjs/components/CioPia/CioPia.js +76 -0
- package/lib/cjs/components/CioPia/CioPiaStyles.css +32 -0
- package/lib/cjs/components/CioPia/Disclaimer.js +16 -0
- package/lib/cjs/components/CioPia/PiaCustomCarousel.js +41 -0
- package/lib/cjs/components/CioPia/index.js +6 -0
- package/lib/cjs/components/ConversationHistory/ConversationHistory.js +36 -0
- package/lib/cjs/components/ConversationHistory/ConversationHistoryStyles.css +51 -0
- package/lib/cjs/components/Error/ErrorBlock.js +23 -0
- package/lib/cjs/components/Error/ErrorStyles.css +46 -0
- package/lib/cjs/components/Feedback/Feedback.js +28 -0
- package/lib/cjs/components/Feedback/FeedbackStyles.css +31 -0
- package/lib/cjs/components/Input/Input.js +40 -0
- package/lib/cjs/components/Input/InputStyles.css +102 -0
- package/lib/cjs/components/LoadingSkeleton/LoadingSkeleton.js +11 -0
- package/lib/cjs/components/LoadingSkeleton/LoadingSkeletonStyles.css +32 -0
- package/lib/cjs/components/PiaConversation/PiaConversation.js +20 -0
- package/lib/cjs/components/PiaConversation/PiaConversationStyles.css +91 -0
- package/lib/cjs/components/PiaConversation/PiaModal.js +74 -0
- package/lib/cjs/components/SuggestedQuestion/SuggestedQuestion.js +16 -0
- package/lib/cjs/components/SuggestedQuestion/SuggestedQuestionStyles.css +33 -0
- package/lib/cjs/components/SuggestedQuestionsContainer/SuggestedQuestionsContainer.js +14 -0
- package/lib/cjs/components/SuggestedQuestionsContainer/SuggestedQuestionsContainerStyles.css +37 -0
- package/lib/cjs/components/SuggestedQuestionsContainer/SuggestedQuestionsSkeleton.js +11 -0
- package/lib/cjs/constants.js +17 -0
- package/lib/cjs/hooks/mocks/MockConstructorIOClient.js +20 -0
- package/lib/cjs/hooks/mocks/agent.js +146 -0
- package/lib/cjs/hooks/mocks/types.js +2 -0
- package/lib/cjs/hooks/useAnswerResults.js +62 -0
- package/lib/cjs/hooks/useCioClient.js +21 -0
- package/lib/cjs/hooks/useCioPia.js +29 -0
- package/lib/cjs/hooks/useConversation.js +74 -0
- package/lib/cjs/hooks/useSuggestedQuestions.js +52 -0
- package/lib/cjs/stories/assets/storybook-styles.css +112 -0
- package/lib/cjs/styles.css +26 -0
- package/lib/cjs/types.js +10 -0
- package/lib/cjs/utils/index.js +4 -0
- package/lib/cjs/utils/styleHelpers.js +14 -0
- package/lib/cjs/utils/transformers.js +29 -0
- package/lib/cjs/utils/translate.js +29 -0
- package/lib/cjs/version.js +3 -0
- package/lib/mjs/components/Answer/Answer.js +10 -0
- package/lib/mjs/components/Answer/AnswerStyles.css +8 -0
- package/lib/mjs/components/CioPia/CioPia.js +72 -0
- package/lib/mjs/components/CioPia/CioPiaStyles.css +32 -0
- package/lib/mjs/components/CioPia/Disclaimer.js +12 -0
- package/lib/mjs/components/CioPia/PiaCustomCarousel.js +37 -0
- package/lib/mjs/components/CioPia/index.js +3 -0
- package/lib/mjs/components/ConversationHistory/ConversationHistory.js +32 -0
- package/lib/mjs/components/ConversationHistory/ConversationHistoryStyles.css +51 -0
- package/lib/mjs/components/Error/ErrorBlock.js +20 -0
- package/lib/mjs/components/Error/ErrorStyles.css +46 -0
- package/lib/mjs/components/Feedback/Feedback.js +24 -0
- package/lib/mjs/components/Feedback/FeedbackStyles.css +31 -0
- package/lib/mjs/components/Input/Input.js +37 -0
- package/lib/mjs/components/Input/InputStyles.css +102 -0
- package/lib/mjs/components/LoadingSkeleton/LoadingSkeleton.js +7 -0
- package/lib/mjs/components/LoadingSkeleton/LoadingSkeletonStyles.css +32 -0
- package/lib/mjs/components/PiaConversation/PiaConversation.js +16 -0
- package/lib/mjs/components/PiaConversation/PiaConversationStyles.css +91 -0
- package/lib/mjs/components/PiaConversation/PiaModal.js +70 -0
- package/lib/mjs/components/SuggestedQuestion/SuggestedQuestion.js +13 -0
- package/lib/mjs/components/SuggestedQuestion/SuggestedQuestionStyles.css +33 -0
- package/lib/mjs/components/SuggestedQuestionsContainer/SuggestedQuestionsContainer.js +10 -0
- package/lib/mjs/components/SuggestedQuestionsContainer/SuggestedQuestionsContainerStyles.css +37 -0
- package/lib/mjs/components/SuggestedQuestionsContainer/SuggestedQuestionsSkeleton.js +7 -0
- package/lib/mjs/constants.js +14 -0
- package/lib/mjs/hooks/mocks/MockConstructorIOClient.js +35 -0
- package/lib/mjs/hooks/mocks/agent.js +138 -0
- package/lib/mjs/hooks/mocks/types.js +1 -0
- package/lib/mjs/hooks/useAnswerResults.js +57 -0
- package/lib/mjs/hooks/useCioClient.js +23 -0
- package/lib/mjs/hooks/useCioPia.js +25 -0
- package/lib/mjs/hooks/useConversation.js +71 -0
- package/lib/mjs/hooks/useSuggestedQuestions.js +48 -0
- package/lib/mjs/index.js +6 -0
- package/lib/mjs/stories/assets/storybook-styles.css +112 -0
- package/lib/mjs/styles.css +26 -0
- package/lib/mjs/types.js +6 -0
- package/lib/mjs/utils/index.js +1 -0
- package/lib/mjs/utils/styleHelpers.js +9 -0
- package/lib/mjs/utils/transformers.js +30 -0
- package/lib/mjs/utils/translate.js +25 -0
- package/lib/mjs/version.js +1 -0
- package/lib/types/components/Answer/Answer.d.ts +9 -0
- package/lib/types/components/CioPia/CioPia.d.ts +17 -0
- package/lib/types/components/CioPia/Disclaimer.d.ts +8 -0
- package/lib/types/components/CioPia/PiaCustomCarousel.d.ts +10 -0
- package/lib/types/components/CioPia/index.d.ts +3 -0
- package/lib/types/components/ConversationHistory/ConversationHistory.d.ts +14 -0
- package/lib/types/components/Error/ErrorBlock.d.ts +7 -0
- package/lib/types/components/Feedback/Feedback.d.ts +10 -0
- package/lib/types/components/Input/Input.d.ts +12 -0
- package/lib/types/components/LoadingSkeleton/LoadingSkeleton.d.ts +2 -0
- package/lib/types/components/PiaConversation/PiaConversation.d.ts +8 -0
- package/lib/types/components/PiaConversation/PiaModal.d.ts +12 -0
- package/lib/types/components/SuggestedQuestion/SuggestedQuestion.d.ts +7 -0
- package/lib/types/components/SuggestedQuestionsContainer/SuggestedQuestionsContainer.d.ts +10 -0
- package/lib/types/components/SuggestedQuestionsContainer/SuggestedQuestionsSkeleton.d.ts +2 -0
- package/lib/types/constants.d.ts +8 -0
- package/lib/types/hooks/mocks/MockConstructorIOClient.d.ts +14 -0
- package/lib/types/hooks/mocks/agent.d.ts +10 -0
- package/lib/types/hooks/mocks/types.d.ts +75 -0
- package/lib/types/hooks/useAnswerResults.d.ts +18 -0
- package/lib/types/hooks/useCioClient.d.ts +13 -0
- package/lib/types/hooks/useCioPia.d.ts +17 -0
- package/lib/types/hooks/useConversation.d.ts +19 -0
- package/lib/types/hooks/useSuggestedQuestions.d.ts +16 -0
- package/lib/types/index.d.ts +5 -0
- package/lib/types/types.d.ts +102 -0
- package/lib/types/utils/index.d.ts +1 -0
- package/lib/types/utils/styleHelpers.d.ts +1 -0
- package/lib/types/utils/transformers.d.ts +7 -0
- package/lib/types/utils/translate.d.ts +10 -0
- package/lib/types/version.d.ts +2 -0
- package/package.json +14 -3
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
.cio-pia-conversation {
|
|
2
|
+
max-height: var(--cio-pia-conversation-max-height);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.cio-pia-conversation-footer {
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-direction: column;
|
|
8
|
+
gap: 8px;
|
|
9
|
+
flex-shrink: 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
body.cio-pia-modal-open {
|
|
13
|
+
overflow: hidden;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.cio-pia-modal {
|
|
17
|
+
border: none;
|
|
18
|
+
border-radius: 12px;
|
|
19
|
+
padding: 0;
|
|
20
|
+
width: 90%;
|
|
21
|
+
max-width: var(--cio-pia-modal-max-width);
|
|
22
|
+
min-width: var(--cio-pia-modal-min-width);
|
|
23
|
+
max-height: var(--cio-pia-modal-height);
|
|
24
|
+
overflow: hidden;
|
|
25
|
+
box-shadow:
|
|
26
|
+
0px 8px 32px rgba(0, 0, 0, 0.12),
|
|
27
|
+
0px 2px 8px rgba(0, 0, 0, 0.08);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.cio-pia-modal::backdrop {
|
|
31
|
+
background: rgba(0, 0, 0, 0.5);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.cio-pia-modal-content {
|
|
35
|
+
display: flex;
|
|
36
|
+
flex-direction: column;
|
|
37
|
+
height: var(--cio-pia-modal-height);
|
|
38
|
+
max-height: var(--cio-pia-modal-height);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.cio-pia-modal-header {
|
|
42
|
+
display: flex;
|
|
43
|
+
align-items: center;
|
|
44
|
+
justify-content: space-between;
|
|
45
|
+
padding: 16px 20px;
|
|
46
|
+
box-shadow: 0px 1px 4px 0px rgba(18, 18, 105, 0.1);
|
|
47
|
+
flex-shrink: 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.cio-pia-modal-close-button {
|
|
51
|
+
background: none;
|
|
52
|
+
border: none;
|
|
53
|
+
cursor: pointer;
|
|
54
|
+
padding: 4px;
|
|
55
|
+
display: flex;
|
|
56
|
+
align-items: center;
|
|
57
|
+
color: rgba(15, 19, 36, 0.6);
|
|
58
|
+
border-radius: 4px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.cio-pia-modal-close-button:hover {
|
|
62
|
+
color: #14151a;
|
|
63
|
+
background: rgba(0, 0, 0, 0.05);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.cio-pia-modal-body {
|
|
67
|
+
flex: 1;
|
|
68
|
+
overflow: hidden;
|
|
69
|
+
display: flex;
|
|
70
|
+
flex-direction: column;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.cio-pia-modal-body .cio-pia-conversation {
|
|
74
|
+
max-height: none;
|
|
75
|
+
flex: 1;
|
|
76
|
+
min-height: 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.cio-pia-modal-body .cio-pia-conversation-history {
|
|
80
|
+
max-height: none;
|
|
81
|
+
flex: 1;
|
|
82
|
+
padding: 16px 20px 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.cio-pia-modal-body .cio-pia-conversation-footer {
|
|
86
|
+
padding: 0 20px 20px;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.cio-pia-modal-body .cio-pia-title {
|
|
90
|
+
padding: 0 20px;
|
|
91
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
|
+
const Input_1 = tslib_1.__importDefault(require("../Input/Input"));
|
|
6
|
+
const translate_1 = require("../../utils/translate");
|
|
7
|
+
const SuggestedQuestionsContainer_1 = tslib_1.__importDefault(require("../SuggestedQuestionsContainer/SuggestedQuestionsContainer"));
|
|
8
|
+
const OVERFLOW_HIDDEN_CLASS = 'cio-pia-modal-open';
|
|
9
|
+
function CloseIcon() {
|
|
10
|
+
return (react_1.default.createElement("svg", { width: '20', height: '20', viewBox: '0 0 20 20', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
|
|
11
|
+
react_1.default.createElement("path", { d: 'M15.8334 5.34166L14.6584 4.16666L10.0001 8.82499L5.34175 4.16666L4.16675 5.34166L8.82508 9.99999L4.16675 14.6583L5.34175 15.8333L10.0001 11.175L14.6584 15.8333L15.8334 14.6583L11.1751 9.99999L15.8334 5.34166Z', fill: 'currentColor' })));
|
|
12
|
+
}
|
|
13
|
+
function PiaModal({ initialQuestions, handleSubmitQuestion, isLoading, componentOverrides, translations, onClose, children, }) {
|
|
14
|
+
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
|
|
15
|
+
const dialogRef = (0, react_1.useRef)(null);
|
|
16
|
+
const openModal = (0, react_1.useCallback)(() => {
|
|
17
|
+
setIsOpen(true);
|
|
18
|
+
}, []);
|
|
19
|
+
const closeModal = (0, react_1.useCallback)(() => {
|
|
20
|
+
setIsOpen(false);
|
|
21
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
22
|
+
}, [onClose]);
|
|
23
|
+
(0, react_1.useEffect)(() => {
|
|
24
|
+
const dialog = dialogRef.current;
|
|
25
|
+
if (!dialog)
|
|
26
|
+
return undefined;
|
|
27
|
+
if (isOpen) {
|
|
28
|
+
dialog.showModal();
|
|
29
|
+
document.body.classList.add(OVERFLOW_HIDDEN_CLASS);
|
|
30
|
+
}
|
|
31
|
+
else if (dialog.open) {
|
|
32
|
+
dialog.close();
|
|
33
|
+
document.body.classList.remove(OVERFLOW_HIDDEN_CLASS);
|
|
34
|
+
}
|
|
35
|
+
return () => {
|
|
36
|
+
document.body.classList.remove(OVERFLOW_HIDDEN_CLASS);
|
|
37
|
+
};
|
|
38
|
+
}, [isOpen]);
|
|
39
|
+
(0, react_1.useEffect)(() => {
|
|
40
|
+
const dialog = dialogRef.current;
|
|
41
|
+
if (!dialog)
|
|
42
|
+
return undefined;
|
|
43
|
+
const handleCancel = (e) => {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
closeModal();
|
|
46
|
+
};
|
|
47
|
+
const handleClick = (e) => {
|
|
48
|
+
if (e.target === dialog)
|
|
49
|
+
closeModal();
|
|
50
|
+
};
|
|
51
|
+
dialog.addEventListener('cancel', handleCancel);
|
|
52
|
+
dialog.addEventListener('click', handleClick);
|
|
53
|
+
return () => {
|
|
54
|
+
dialog.removeEventListener('cancel', handleCancel);
|
|
55
|
+
dialog.removeEventListener('click', handleClick);
|
|
56
|
+
};
|
|
57
|
+
}, [closeModal]);
|
|
58
|
+
const handleQuestion = (0, react_1.useCallback)((question) => {
|
|
59
|
+
handleSubmitQuestion(question);
|
|
60
|
+
openModal();
|
|
61
|
+
}, [handleSubmitQuestion, openModal]);
|
|
62
|
+
return (react_1.default.createElement("div", { className: 'cio-pia-container', "data-testid": 'cio-pia-container' },
|
|
63
|
+
react_1.default.createElement("p", { className: 'cio-pia-title', "data-testid": 'cio-pia-title' }, (0, translate_1.translate)('Any questions about this product?', translations)),
|
|
64
|
+
react_1.default.createElement(Input_1.default, { onSubmit: handleQuestion, disabled: isLoading || isOpen, translations: translations }),
|
|
65
|
+
initialQuestions.length > 0 && (react_1.default.createElement(SuggestedQuestionsContainer_1.default, { questions: initialQuestions, onQuestionClick: handleQuestion, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.suggestedQuestions })),
|
|
66
|
+
react_1.default.createElement("dialog", { ref: dialogRef, className: 'cio-pia-modal', "aria-labelledby": 'cio-pia-modal-title' },
|
|
67
|
+
react_1.default.createElement("div", { className: 'cio-pia-modal-content' },
|
|
68
|
+
react_1.default.createElement("div", { className: 'cio-pia-modal-header' },
|
|
69
|
+
react_1.default.createElement("p", { className: 'cio-pia-title', id: 'cio-pia-modal-title' }, (0, translate_1.translate)('Ask about this product', translations)),
|
|
70
|
+
react_1.default.createElement("button", { type: 'button', className: 'cio-pia-modal-close-button', "aria-label": 'Close', onClick: closeModal },
|
|
71
|
+
react_1.default.createElement(CloseIcon, null))),
|
|
72
|
+
react_1.default.createElement("div", { className: 'cio-pia-modal-body' }, children)))));
|
|
73
|
+
}
|
|
74
|
+
exports.default = PiaModal;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
|
+
function QuestionSvg() {
|
|
6
|
+
return (react_1.default.createElement("div", { className: 'cio-pia-suggested-question-icon' },
|
|
7
|
+
react_1.default.createElement("svg", { width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none', xmlns: 'http://www.w3.org/2000/svg' },
|
|
8
|
+
react_1.default.createElement("g", { id: 'help' },
|
|
9
|
+
react_1.default.createElement("path", { id: 'Vector', d: 'M8.00004 1.33331C4.32004 1.33331 1.33337 4.31998 1.33337 7.99998C1.33337 11.68 4.32004 14.6666 8.00004 14.6666C11.68 14.6666 14.6667 11.68 14.6667 7.99998C14.6667 4.31998 11.68 1.33331 8.00004 1.33331ZM8.66671 12.6666H7.33337V11.3333H8.66671V12.6666ZM10.0467 7.49998L9.44671 8.11331C8.96671 8.59998 8.66671 8.99998 8.66671 9.99998H7.33337V9.66665C7.33337 8.93331 7.63337 8.26665 8.11337 7.77998L8.94004 6.93998C9.18671 6.69998 9.33337 6.36665 9.33337 5.99998C9.33337 5.26665 8.73337 4.66665 8.00004 4.66665C7.26671 4.66665 6.66671 5.26665 6.66671 5.99998H5.33337C5.33337 4.52665 6.52671 3.33331 8.00004 3.33331C9.47337 3.33331 10.6667 4.52665 10.6667 5.99998C10.6667 6.58665 10.4267 7.11998 10.0467 7.49998Z', fill: '#0F1324', fillOpacity: '0.6' })))));
|
|
10
|
+
}
|
|
11
|
+
function SuggestedQuestion({ question, onClick }) {
|
|
12
|
+
return (react_1.default.createElement("button", { type: 'button', className: 'cio-pia-suggested-question', onClick: onClick },
|
|
13
|
+
react_1.default.createElement(QuestionSvg, null),
|
|
14
|
+
question));
|
|
15
|
+
}
|
|
16
|
+
exports.default = SuggestedQuestion;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
.cio-pia-suggested-question {
|
|
2
|
+
background: #ffffff;
|
|
3
|
+
border: 1px solid #dee0e3;
|
|
4
|
+
border-radius: 4px;
|
|
5
|
+
padding: 4px 12px 4px 4px;
|
|
6
|
+
display: flex;
|
|
7
|
+
flex: 0 0 auto;
|
|
8
|
+
justify-content: center;
|
|
9
|
+
align-items: center;
|
|
10
|
+
min-width: fit-content;
|
|
11
|
+
font-size: 12px;
|
|
12
|
+
font-style: normal;
|
|
13
|
+
font-weight: 500;
|
|
14
|
+
color: #14151a;
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
box-shadow:
|
|
17
|
+
0px 0.4px 1px 0px rgba(18, 18, 105, 0.13),
|
|
18
|
+
0px 0.9px 6px 0px rgba(18, 18, 105, 0.05),
|
|
19
|
+
0px 1px 3px 0px rgba(18, 18, 105, 0.05);
|
|
20
|
+
gap: 2px;
|
|
21
|
+
transition: all 0.2s ease;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.cio-pia-suggested-question:hover {
|
|
25
|
+
background-color: #f8f9fa;
|
|
26
|
+
border-color: #c4c7cc;
|
|
27
|
+
transform: translateY(-1px);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.cio-pia-suggested-question-icon {
|
|
31
|
+
display: flex;
|
|
32
|
+
padding: 4px;
|
|
33
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
|
+
const constructorio_ui_components_1 = require("@constructor-io/constructorio-ui-components");
|
|
6
|
+
const SuggestedQuestion_1 = tslib_1.__importDefault(require("../SuggestedQuestion/SuggestedQuestion"));
|
|
7
|
+
function SuggestedQuestionsContainer({ questions, onQuestionClick, componentOverride, }) {
|
|
8
|
+
if (!questions || questions.length === 0) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
return (react_1.default.createElement(constructorio_ui_components_1.RenderPropsWrapper, { props: { questions, onQuestionClick }, override: componentOverride === null || componentOverride === void 0 ? void 0 : componentOverride.reactNode },
|
|
12
|
+
react_1.default.createElement("div", { className: 'cio-pia-suggested-questions-container', "data-testid": 'suggested-questions-list' }, questions.map((question) => (react_1.default.createElement(SuggestedQuestion_1.default, { key: question.value, question: question.value, onClick: () => onQuestionClick(question.value) }))))));
|
|
13
|
+
}
|
|
14
|
+
exports.default = SuggestedQuestionsContainer;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
.cio-pia-suggested-questions-container {
|
|
2
|
+
display: grid;
|
|
3
|
+
grid-template-columns: repeat(3, 1fr);
|
|
4
|
+
gap: 16px;
|
|
5
|
+
width: 100%;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
@media (max-width: 768px) {
|
|
9
|
+
.cio-pia-suggested-questions-container {
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-wrap: nowrap;
|
|
12
|
+
overflow-x: auto;
|
|
13
|
+
gap: 8px;
|
|
14
|
+
padding: 4px 0px;
|
|
15
|
+
width: 100%;
|
|
16
|
+
max-width: 85vw;
|
|
17
|
+
|
|
18
|
+
scroll-behavior: smooth;
|
|
19
|
+
scrollbar-width: none;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.cio-pia-suggested-question-skeleton {
|
|
24
|
+
height: 28px;
|
|
25
|
+
border-radius: 4px;
|
|
26
|
+
background-color: rgba(0, 0, 0, 0.05);
|
|
27
|
+
animation: loading-animation 2s infinite ease-in-out;
|
|
28
|
+
&:nth-child(1) {
|
|
29
|
+
animation-delay: 0.3s;
|
|
30
|
+
}
|
|
31
|
+
&:nth-child(2) {
|
|
32
|
+
animation-delay: 0.6s;
|
|
33
|
+
}
|
|
34
|
+
&:nth-child(3) {
|
|
35
|
+
animation-delay: 0.9s;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
5
|
+
function SuggestedQuestionsSkeleton() {
|
|
6
|
+
return (react_1.default.createElement("div", { className: 'cio-pia-suggested-questions-container', "data-testid": 'suggested-questions-skeleton', "aria-busy": 'true', "aria-label": 'Loading suggestions' },
|
|
7
|
+
react_1.default.createElement("div", { className: 'cio-pia-suggested-question-skeleton' }),
|
|
8
|
+
react_1.default.createElement("div", { className: 'cio-pia-suggested-question-skeleton' }),
|
|
9
|
+
react_1.default.createElement("div", { className: 'cio-pia-suggested-question-skeleton' })));
|
|
10
|
+
}
|
|
11
|
+
exports.default = SuggestedQuestionsSkeleton;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DISCLAIMER_TEXT = exports.MOCK_QUESTIONS = exports.DEMO_QUESTION_ALTERNATIVE_PRODUCTS = exports.DEMO_QUESTION = exports.DEMO_ITEM_ID = exports.DEMO_API_KEY = void 0;
|
|
4
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
5
|
+
exports.DEMO_API_KEY = 'key_13TO6qN9H3BP3Wrn';
|
|
6
|
+
exports.DEMO_ITEM_ID = '149100215';
|
|
7
|
+
exports.DEMO_QUESTION = 'What is the nutritional content of this shake?';
|
|
8
|
+
exports.DEMO_QUESTION_ALTERNATIVE_PRODUCTS = 'What alternative products are available for this item?';
|
|
9
|
+
exports.MOCK_QUESTIONS = [
|
|
10
|
+
{ value: 'What is the nutritional content per serving?' },
|
|
11
|
+
{ value: 'How many calories does each bottle contain?' },
|
|
12
|
+
{ value: 'What is the shelf life of this product?' },
|
|
13
|
+
{ value: 'Is this shake suitable for specific dietary needs?' },
|
|
14
|
+
{ value: 'What flavor options are available for Ensure shakes?' },
|
|
15
|
+
{ value: 'What is the serving size and calorie count?' },
|
|
16
|
+
];
|
|
17
|
+
exports.DISCLAIMER_TEXT = 'AI-generated answers aim to help, but they may occasionally miss details or be inaccurate. Double-check important information before purchasing.';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const constructorio_client_javascript_1 = tslib_1.__importDefault(require("@constructor-io/constructorio-client-javascript"));
|
|
5
|
+
const agent_1 = tslib_1.__importDefault(require("./agent"));
|
|
6
|
+
const version_1 = tslib_1.__importDefault(require("../../version"));
|
|
7
|
+
class MockConstructorIOClient {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.options = Object.assign({ version: options.version || `cio-ui-pia-${version_1.default}`, serviceUrl: options.serviceUrl || 'https://ac.cnstrc.com', quizzesServiceUrl: options.quizzesServiceUrl || 'https://quizzes.cnstrc.com', agentServiceUrl: options.agentServiceUrl || 'https://agent.cnstrc.com', sessionId: options.sessionId || 0, clientId: options.clientId || 'this-is-a-random-client-id', sendTrackingEvents: options.sendTrackingEvents !== undefined ? options.sendTrackingEvents : true, beaconMode: options.beaconMode !== undefined ? options.beaconMode : true, networkParameters: options.networkParameters || {} }, options);
|
|
10
|
+
const cioClient = new constructorio_client_javascript_1.default(this.options);
|
|
11
|
+
this.search = cioClient.search;
|
|
12
|
+
this.browse = cioClient.browse;
|
|
13
|
+
this.recommendations = cioClient.recommendations;
|
|
14
|
+
this.tracker = cioClient.tracker;
|
|
15
|
+
this.quizzes = cioClient.quizzes;
|
|
16
|
+
// Use the mock agent instead of the one from the client
|
|
17
|
+
this.agent = new agent_1.default(this.options);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.default = MockConstructorIOClient;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
// Create URL for PIA API
|
|
5
|
+
function createAgentUrl({ itemId, threadId, variationId, question, isStreaming = false, options, parameters = {}, }) {
|
|
6
|
+
const { apiKey, agentServiceUrl } = options;
|
|
7
|
+
if (!agentServiceUrl)
|
|
8
|
+
throw new Error('Agent service URL is required');
|
|
9
|
+
let baseUrl = `${agentServiceUrl}/v1/item_questions`;
|
|
10
|
+
if (question) {
|
|
11
|
+
baseUrl += `/${encodeURIComponent(question)}/answer`;
|
|
12
|
+
}
|
|
13
|
+
if (isStreaming) {
|
|
14
|
+
baseUrl += '/streaming';
|
|
15
|
+
}
|
|
16
|
+
const url = new URL(baseUrl);
|
|
17
|
+
url.searchParams.append('item_id', itemId);
|
|
18
|
+
url.searchParams.append('key', apiKey);
|
|
19
|
+
if (threadId) {
|
|
20
|
+
url.searchParams.append('thread_id', threadId);
|
|
21
|
+
}
|
|
22
|
+
if (variationId) {
|
|
23
|
+
url.searchParams.append('variation_id', variationId);
|
|
24
|
+
}
|
|
25
|
+
// Any additional parameters
|
|
26
|
+
Object.entries(parameters).forEach(([key, value]) => {
|
|
27
|
+
if (value !== undefined) {
|
|
28
|
+
url.searchParams.append(key, String(value));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return url.toString();
|
|
32
|
+
}
|
|
33
|
+
// Map camelCase SuggestedQuestionsParameters to snake_case query params expected by the API
|
|
34
|
+
function mapSuggestedQuestionsParams(params) {
|
|
35
|
+
const result = {};
|
|
36
|
+
if (params.numResults !== undefined)
|
|
37
|
+
result.num_results = params.numResults;
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
class MockAgent {
|
|
41
|
+
constructor(options) {
|
|
42
|
+
this.options = options;
|
|
43
|
+
}
|
|
44
|
+
getSuggestedQuestions({ itemId, variationId, threadId, parameters = {}, }) {
|
|
45
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
if (!itemId)
|
|
47
|
+
throw new Error('Item ID is required');
|
|
48
|
+
if (!this.options.apiKey)
|
|
49
|
+
throw new Error('API key is required');
|
|
50
|
+
const url = createAgentUrl({
|
|
51
|
+
itemId,
|
|
52
|
+
variationId,
|
|
53
|
+
threadId,
|
|
54
|
+
options: this.options,
|
|
55
|
+
parameters: mapSuggestedQuestionsParams(parameters),
|
|
56
|
+
});
|
|
57
|
+
try {
|
|
58
|
+
const response = yield fetch(url);
|
|
59
|
+
if (!response.ok)
|
|
60
|
+
throw new Error(`Request failed with status ${response.status}`);
|
|
61
|
+
const data = yield response.json();
|
|
62
|
+
return data;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
66
|
+
throw new Error(errorMessage);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
getAnswerResults({ itemId, variationId, threadId, question, parameters = {}, }) {
|
|
71
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
if (!itemId)
|
|
73
|
+
throw new Error('Item ID is required');
|
|
74
|
+
if (!question)
|
|
75
|
+
throw new Error('Question is required');
|
|
76
|
+
if (!this.options.apiKey)
|
|
77
|
+
throw new Error('API key is required');
|
|
78
|
+
const url = createAgentUrl({
|
|
79
|
+
itemId,
|
|
80
|
+
threadId,
|
|
81
|
+
variationId,
|
|
82
|
+
question,
|
|
83
|
+
options: this.options,
|
|
84
|
+
parameters,
|
|
85
|
+
});
|
|
86
|
+
try {
|
|
87
|
+
const response = yield fetch(url);
|
|
88
|
+
if (!response.ok)
|
|
89
|
+
throw new Error(`Request failed with status ${response.status}`);
|
|
90
|
+
const data = yield response.json();
|
|
91
|
+
return data;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
95
|
+
throw new Error(errorMessage);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
getAnswerResultsStream({ itemId, threadId, variationId, question, parameters, onStart, onMessage, onEnd, }) {
|
|
100
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
if (!itemId)
|
|
102
|
+
throw new Error('Item ID is required');
|
|
103
|
+
if (!question)
|
|
104
|
+
throw new Error('Question is required');
|
|
105
|
+
if (!this.options.apiKey)
|
|
106
|
+
throw new Error('API key is required');
|
|
107
|
+
const url = createAgentUrl({
|
|
108
|
+
itemId,
|
|
109
|
+
threadId,
|
|
110
|
+
variationId,
|
|
111
|
+
question,
|
|
112
|
+
isStreaming: true,
|
|
113
|
+
options: this.options,
|
|
114
|
+
parameters,
|
|
115
|
+
});
|
|
116
|
+
try {
|
|
117
|
+
const eventSource = new EventSource(url);
|
|
118
|
+
eventSource.addEventListener('open', (event) => {
|
|
119
|
+
const data = JSON.parse(event.data);
|
|
120
|
+
if (onStart)
|
|
121
|
+
onStart(data);
|
|
122
|
+
});
|
|
123
|
+
eventSource.addEventListener('message', (event) => {
|
|
124
|
+
const data = JSON.parse(event.data);
|
|
125
|
+
if (onMessage)
|
|
126
|
+
onMessage(data);
|
|
127
|
+
});
|
|
128
|
+
eventSource.addEventListener('end', (event) => {
|
|
129
|
+
const data = JSON.parse(event.data);
|
|
130
|
+
if (onEnd)
|
|
131
|
+
onEnd(data);
|
|
132
|
+
eventSource.close();
|
|
133
|
+
});
|
|
134
|
+
eventSource.onerror = () => {
|
|
135
|
+
eventSource.close();
|
|
136
|
+
throw new Error('Unexpected error occurred. Please try again.');
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
141
|
+
throw new Error(errorMessage);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.default = MockAgent;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const transformers_1 = require("../utils/transformers");
|
|
6
|
+
const extractAndTransformItems = (data) => {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
if (!((_b = (_a = data === null || data === void 0 ? void 0 : data.item_results) === null || _a === void 0 ? void 0 : _a.response) === null || _b === void 0 ? void 0 : _b.results)) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const { results } = data.item_results.response;
|
|
12
|
+
if (!Array.isArray(results) || results.length === 0) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const transformedItems = results
|
|
16
|
+
.map(transformers_1.transformResultItem)
|
|
17
|
+
.filter((item) => item !== null);
|
|
18
|
+
return transformedItems.length > 0 ? transformedItems : null;
|
|
19
|
+
};
|
|
20
|
+
const fetchAnswerResults = ({ client, itemId, question, variationId, threadId, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const response = yield client.agent.getAnswerResults({
|
|
22
|
+
itemId,
|
|
23
|
+
variationId,
|
|
24
|
+
threadId,
|
|
25
|
+
question,
|
|
26
|
+
});
|
|
27
|
+
return response;
|
|
28
|
+
});
|
|
29
|
+
function useAnswerResults({ itemId, variationId, threadId, cioClient, }) {
|
|
30
|
+
const [answerResults, setAnswerResults] = (0, react_1.useState)(null);
|
|
31
|
+
const [items, setItems] = (0, react_1.useState)(null);
|
|
32
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
33
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
34
|
+
const fetchResult = (0, react_1.useCallback)((question) => {
|
|
35
|
+
if (!cioClient)
|
|
36
|
+
return;
|
|
37
|
+
setIsLoading(true);
|
|
38
|
+
setError(null);
|
|
39
|
+
fetchAnswerResults({ client: cioClient, itemId, question, variationId, threadId })
|
|
40
|
+
.then((fetchedAnswerResults) => {
|
|
41
|
+
setAnswerResults(fetchedAnswerResults);
|
|
42
|
+
setItems(extractAndTransformItems(fetchedAnswerResults));
|
|
43
|
+
setError(null);
|
|
44
|
+
})
|
|
45
|
+
.catch((err) => {
|
|
46
|
+
setError(err instanceof Error ? err : new Error('Error fetching answer'));
|
|
47
|
+
setAnswerResults(null);
|
|
48
|
+
setItems(null);
|
|
49
|
+
})
|
|
50
|
+
.finally(() => {
|
|
51
|
+
setIsLoading(false);
|
|
52
|
+
});
|
|
53
|
+
}, [cioClient, itemId, variationId, threadId]);
|
|
54
|
+
return {
|
|
55
|
+
data: answerResults,
|
|
56
|
+
items,
|
|
57
|
+
isLoading,
|
|
58
|
+
error,
|
|
59
|
+
getAnswer: fetchResult,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
exports.default = useAnswerResults;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const version_1 = tslib_1.__importDefault(require("../version"));
|
|
6
|
+
const MockConstructorIOClient_1 = tslib_1.__importDefault(require("./mocks/MockConstructorIOClient"));
|
|
7
|
+
const useCioClient = ({ apiKey, cioClient, options } = {}) => {
|
|
8
|
+
if (!apiKey && !cioClient) {
|
|
9
|
+
throw new Error('Api Key or Constructor Client required');
|
|
10
|
+
}
|
|
11
|
+
const memoizedCioClient = (0, react_1.useMemo)(() => {
|
|
12
|
+
if (cioClient)
|
|
13
|
+
return cioClient;
|
|
14
|
+
if (apiKey) {
|
|
15
|
+
return new MockConstructorIOClient_1.default(Object.assign({ apiKey, sendTrackingEvents: true, version: `cio-ui-pia-${version_1.default}` }, options));
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}, [apiKey, cioClient, options]);
|
|
19
|
+
return memoizedCioClient;
|
|
20
|
+
};
|
|
21
|
+
exports.default = useCioClient;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const useAnswerResults_1 = tslib_1.__importDefault(require("./useAnswerResults"));
|
|
5
|
+
const useCioClient_1 = tslib_1.__importDefault(require("./useCioClient"));
|
|
6
|
+
const useSuggestedQuestions_1 = tslib_1.__importDefault(require("./useSuggestedQuestions"));
|
|
7
|
+
function useCioPia(props) {
|
|
8
|
+
const { apiKey, itemId, variationId, threadId, cioClient: providedClient, suggestedQuestionsParameters, } = props;
|
|
9
|
+
const defaultClient = (0, useCioClient_1.default)({ apiKey });
|
|
10
|
+
const client = providedClient || defaultClient;
|
|
11
|
+
const suggestedQuestions = (0, useSuggestedQuestions_1.default)({
|
|
12
|
+
itemId,
|
|
13
|
+
variationId,
|
|
14
|
+
threadId,
|
|
15
|
+
cioClient: client,
|
|
16
|
+
parameters: suggestedQuestionsParameters,
|
|
17
|
+
});
|
|
18
|
+
const answers = (0, useAnswerResults_1.default)({
|
|
19
|
+
itemId,
|
|
20
|
+
variationId,
|
|
21
|
+
threadId,
|
|
22
|
+
cioClient: client,
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
suggestedQuestions,
|
|
26
|
+
answers,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.default = useCioPia;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
function useConversation({ pia, itemId, isConversation, }) {
|
|
5
|
+
var _a, _b, _c, _d;
|
|
6
|
+
const { suggestedQuestions, answers } = pia;
|
|
7
|
+
const { getAnswer } = answers;
|
|
8
|
+
const [currentQuestion, setCurrentQuestion] = (0, react_1.useState)('');
|
|
9
|
+
const [displayedQuestions, setDisplayedQuestions] = (0, react_1.useState)([]);
|
|
10
|
+
const [conversationHistory, setConversationHistory] = (0, react_1.useState)([]);
|
|
11
|
+
const entryIdRef = (0, react_1.useRef)(0);
|
|
12
|
+
const prevAnswerValueRef = (0, react_1.useRef)((_a = answers.data) === null || _a === void 0 ? void 0 : _a.value);
|
|
13
|
+
const handleSubmitQuestion = (0, react_1.useCallback)((question) => {
|
|
14
|
+
setCurrentQuestion(question);
|
|
15
|
+
getAnswer(question);
|
|
16
|
+
if (isConversation) {
|
|
17
|
+
entryIdRef.current += 1;
|
|
18
|
+
const id = entryIdRef.current;
|
|
19
|
+
setConversationHistory((prev) => [...prev, { id, question, answer: '' }]);
|
|
20
|
+
}
|
|
21
|
+
}, [getAnswer, isConversation]);
|
|
22
|
+
const resetState = (0, react_1.useCallback)(() => {
|
|
23
|
+
setCurrentQuestion('');
|
|
24
|
+
setDisplayedQuestions(suggestedQuestions.data);
|
|
25
|
+
setConversationHistory([]);
|
|
26
|
+
prevAnswerValueRef.current = undefined;
|
|
27
|
+
}, [suggestedQuestions.data]);
|
|
28
|
+
(0, react_1.useEffect)(() => {
|
|
29
|
+
setCurrentQuestion('');
|
|
30
|
+
setDisplayedQuestions([]);
|
|
31
|
+
setConversationHistory([]);
|
|
32
|
+
prevAnswerValueRef.current = undefined;
|
|
33
|
+
}, [itemId]);
|
|
34
|
+
(0, react_1.useEffect)(() => {
|
|
35
|
+
setDisplayedQuestions(suggestedQuestions.data);
|
|
36
|
+
}, [suggestedQuestions.data]);
|
|
37
|
+
(0, react_1.useEffect)(() => {
|
|
38
|
+
var _a;
|
|
39
|
+
if ((_a = answers.data) === null || _a === void 0 ? void 0 : _a.follow_up_questions)
|
|
40
|
+
setDisplayedQuestions(answers.data.follow_up_questions);
|
|
41
|
+
}, [answers.data]);
|
|
42
|
+
(0, react_1.useEffect)(() => {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
const answerValue = (_b = (_a = answers.data) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : '';
|
|
45
|
+
if (!isConversation || !answerValue)
|
|
46
|
+
return;
|
|
47
|
+
if (answerValue === prevAnswerValueRef.current)
|
|
48
|
+
return;
|
|
49
|
+
prevAnswerValueRef.current = answerValue;
|
|
50
|
+
setConversationHistory((prev) => {
|
|
51
|
+
if (prev.length === 0)
|
|
52
|
+
return prev;
|
|
53
|
+
const updated = [...prev];
|
|
54
|
+
updated[updated.length - 1] = Object.assign(Object.assign({}, updated[updated.length - 1]), { answer: answerValue });
|
|
55
|
+
return updated;
|
|
56
|
+
});
|
|
57
|
+
}, [isConversation, answers.data]);
|
|
58
|
+
const currentAnswer = (_c = (_b = answers.data) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : '';
|
|
59
|
+
const currentItems = (_d = answers.items) !== null && _d !== void 0 ? _d : null;
|
|
60
|
+
const error = answers.error || suggestedQuestions.error;
|
|
61
|
+
const isLoading = answers.isLoading || suggestedQuestions.isLoading;
|
|
62
|
+
return {
|
|
63
|
+
currentQuestion,
|
|
64
|
+
displayedQuestions,
|
|
65
|
+
conversationHistory,
|
|
66
|
+
currentAnswer,
|
|
67
|
+
currentItems,
|
|
68
|
+
isLoading,
|
|
69
|
+
error,
|
|
70
|
+
handleSubmitQuestion,
|
|
71
|
+
resetState,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
exports.default = useConversation;
|