@constructor-io/constructorio-ui-pia 2.2.0 → 2.3.0
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/README.md +8 -0
- package/dist/constructorio-ui-pia-bundled.js +16 -16
- package/lib/cjs/components/CioPia/CioPia.js +6 -3
- package/lib/cjs/components/ConversationHistory/ConversationHistory.js +4 -2
- package/lib/cjs/components/ConversationHistory/ConversationHistoryStyles.css +1 -0
- package/lib/cjs/components/PiaConversation/PiaConversation.js +2 -2
- package/lib/cjs/components/PiaConversation/PiaModal.js +3 -2
- package/lib/cjs/hooks/useConversation.js +4 -2
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/CioPia/CioPia.js +6 -3
- package/lib/mjs/components/ConversationHistory/ConversationHistory.js +4 -2
- package/lib/mjs/components/ConversationHistory/ConversationHistoryStyles.css +1 -0
- package/lib/mjs/components/PiaConversation/PiaConversation.js +2 -2
- package/lib/mjs/components/PiaConversation/PiaModal.js +3 -2
- package/lib/mjs/hooks/useConversation.js +3 -2
- package/lib/mjs/version.js +1 -1
- package/lib/types/components/CioPia/CioPia.d.ts +12 -0
- package/lib/types/components/ConversationHistory/ConversationHistory.d.ts +3 -2
- package/lib/types/components/PiaConversation/PiaConversation.d.ts +1 -1
- package/lib/types/hooks/useConversation.d.ts +3 -2
- package/lib/types/types.d.ts +13 -0
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ const PiaModal_1 = tslib_1.__importDefault(require("../PiaConversation/PiaModal"
|
|
|
18
18
|
const PiaConversation_1 = tslib_1.__importDefault(require("../PiaConversation/PiaConversation"));
|
|
19
19
|
function CioPia(props) {
|
|
20
20
|
const { apiKey, itemId, threadId, variationId, cioClient, displayConfigs, componentOverrides, callbacks, formatters, children, translations, suggestedQuestionsParameters, } = props;
|
|
21
|
-
const { learnMoreUrl, showFeedback, mode = 'default', type = 'inline', showPreviousItems, } = displayConfigs || {};
|
|
21
|
+
const { learnMoreUrl, showFeedback, mode = 'default', type = 'inline', showPreviousItems, disclaimerPosition = 'bottom', } = displayConfigs || {};
|
|
22
22
|
const isConversation = mode === 'conversation' || type === 'modal';
|
|
23
23
|
const pia = (0, useCioPia_1.default)({
|
|
24
24
|
apiKey,
|
|
@@ -29,7 +29,7 @@ function CioPia(props) {
|
|
|
29
29
|
suggestedQuestionsParameters,
|
|
30
30
|
formatImageUrl: formatters === null || formatters === void 0 ? void 0 : formatters.formatImageUrl,
|
|
31
31
|
});
|
|
32
|
-
const { currentQuestion, displayedQuestions, conversationHistory, currentAnswer, currentItems, isLoading, error, handleSubmitQuestion, resetState, } = (0, useConversation_1.default)({ pia, itemId, isConversation });
|
|
32
|
+
const { currentQuestion, displayedQuestions, conversationHistory, currentAnswer, currentItems, isLoading, error, handleSubmitQuestion, resetState, } = (0, useConversation_1.default)({ pia, itemId, isConversation, callbacks });
|
|
33
33
|
const renderProps = {
|
|
34
34
|
items: currentItems,
|
|
35
35
|
isLoading,
|
|
@@ -48,6 +48,7 @@ function CioPia(props) {
|
|
|
48
48
|
showFeedback,
|
|
49
49
|
showPreviousItems,
|
|
50
50
|
learnMoreUrl,
|
|
51
|
+
disclaimerPosition,
|
|
51
52
|
translations,
|
|
52
53
|
callbacks,
|
|
53
54
|
componentOverrides,
|
|
@@ -60,6 +61,7 @@ function CioPia(props) {
|
|
|
60
61
|
}
|
|
61
62
|
if (isConversation)
|
|
62
63
|
return react_1.default.createElement(PiaConversation_1.default, Object.assign({}, conversationHistoryProps));
|
|
64
|
+
const disclaimer = (react_1.default.createElement(Disclaimer_1.default, { learnMoreUrl: learnMoreUrl, translations: translations, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.disclaimer }));
|
|
63
65
|
// Default inline mode
|
|
64
66
|
return (react_1.default.createElement("div", { className: 'cio-pia-container', "data-testid": 'cio-pia-container' },
|
|
65
67
|
react_1.default.createElement(constructorio_ui_components_1.RenderPropsWrapper, { props: renderProps, override: children || (componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.reactNode) },
|
|
@@ -69,10 +71,11 @@ function CioPia(props) {
|
|
|
69
71
|
!isLoading && error && react_1.default.createElement(ErrorBlock_1.default, { message: (error === null || error === void 0 ? void 0 : error.message) || 'Unexpected error' }),
|
|
70
72
|
!isLoading && !error && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
71
73
|
currentAnswer && (react_1.default.createElement("div", { className: 'cio-pia-answer-container' },
|
|
74
|
+
disclaimerPosition === 'top' && disclaimer,
|
|
72
75
|
react_1.default.createElement(Answer_1.default, { text: currentAnswer, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.answer }),
|
|
73
76
|
currentItems && (react_1.default.createElement(PiaCustomCarousel_1.default, { items: currentItems, componentOverrides: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.carousel, callbacks: callbacks })),
|
|
74
77
|
showFeedback && (react_1.default.createElement(Feedback_1.default, { translations: translations, onFeedback: callbacks === null || callbacks === void 0 ? void 0 : callbacks.onFeedback, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.feedback })),
|
|
75
|
-
|
|
78
|
+
disclaimerPosition === 'bottom' && disclaimer)),
|
|
76
79
|
react_1.default.createElement(SuggestedQuestionsContainer_1.default, { questions: displayedQuestions, onQuestionClick: handleSubmitQuestion, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.suggestedQuestions }))))));
|
|
77
80
|
}
|
|
78
81
|
exports.default = CioPia;
|
|
@@ -8,7 +8,7 @@ const Disclaimer_1 = tslib_1.__importDefault(require("../CioPia/Disclaimer"));
|
|
|
8
8
|
const ErrorBlock_1 = tslib_1.__importDefault(require("../Error/ErrorBlock"));
|
|
9
9
|
const LoadingSkeleton_1 = tslib_1.__importDefault(require("../LoadingSkeleton/LoadingSkeleton"));
|
|
10
10
|
const PiaCustomCarousel_1 = tslib_1.__importDefault(require("../CioPia/PiaCustomCarousel"));
|
|
11
|
-
function ConversationHistory({ conversationHistory, isLoading, error, currentItems, showFeedback, showPreviousItems = true, learnMoreUrl, translations, callbacks, componentOverrides, }) {
|
|
11
|
+
function ConversationHistory({ conversationHistory, isLoading, error, currentItems, showFeedback, showPreviousItems = true, learnMoreUrl, disclaimerPosition = 'bottom', translations, callbacks, componentOverrides, }) {
|
|
12
12
|
const scrollContainerRef = (0, react_1.useRef)(null);
|
|
13
13
|
(0, react_1.useEffect)(() => {
|
|
14
14
|
const container = scrollContainerRef.current;
|
|
@@ -19,7 +19,9 @@ function ConversationHistory({ conversationHistory, isLoading, error, currentIte
|
|
|
19
19
|
});
|
|
20
20
|
return () => cancelAnimationFrame(frameId);
|
|
21
21
|
}, [conversationHistory, isLoading]);
|
|
22
|
+
const disclaimer = (react_1.default.createElement(Disclaimer_1.default, { learnMoreUrl: learnMoreUrl, translations: translations, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.disclaimer }));
|
|
22
23
|
return (react_1.default.createElement("div", { className: 'cio-pia-conversation-history' },
|
|
24
|
+
disclaimerPosition === 'top' && disclaimer,
|
|
23
25
|
react_1.default.createElement("div", { ref: scrollContainerRef, className: 'cio-pia-conversation-entries', role: 'log', "aria-label": 'Conversation history' }, conversationHistory.map((entry, index) => {
|
|
24
26
|
const isLast = index === conversationHistory.length - 1;
|
|
25
27
|
const previousEntryItems = showPreviousItems ? entry.items : null;
|
|
@@ -35,6 +37,6 @@ function ConversationHistory({ conversationHistory, isLoading, error, currentIte
|
|
|
35
37
|
carouselItems && (react_1.default.createElement(PiaCustomCarousel_1.default, { items: carouselItems, componentOverrides: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.carousel, callbacks: callbacks })),
|
|
36
38
|
isLast && showFeedback && (react_1.default.createElement(Feedback_1.default, { translations: translations, onFeedback: callbacks === null || callbacks === void 0 ? void 0 : callbacks.onFeedback, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.feedback }))))));
|
|
37
39
|
})),
|
|
38
|
-
|
|
40
|
+
disclaimerPosition === 'bottom' && disclaimer));
|
|
39
41
|
}
|
|
40
42
|
exports.default = ConversationHistory;
|
|
@@ -7,11 +7,11 @@ const SuggestedQuestionsContainer_1 = tslib_1.__importDefault(require("../Sugges
|
|
|
7
7
|
const SuggestedQuestionsSkeleton_1 = tslib_1.__importDefault(require("../SuggestedQuestionsContainer/SuggestedQuestionsSkeleton"));
|
|
8
8
|
const translate_1 = require("../../utils/translate");
|
|
9
9
|
const ConversationHistory_1 = tslib_1.__importDefault(require("../ConversationHistory/ConversationHistory"));
|
|
10
|
-
function PiaConversation({ conversationHistory, isLoading, error, currentItems, showFeedback, showPreviousItems, learnMoreUrl, translations, callbacks, componentOverrides, displayedQuestions, handleSubmitQuestion, }) {
|
|
10
|
+
function PiaConversation({ conversationHistory, isLoading, error, currentItems, showFeedback, showPreviousItems, learnMoreUrl, disclaimerPosition, translations, callbacks, componentOverrides, displayedQuestions, handleSubmitQuestion, }) {
|
|
11
11
|
const hasHistory = conversationHistory.length > 0;
|
|
12
12
|
return (react_1.default.createElement("div", { className: 'cio-pia-container cio-pia-conversation', "data-testid": 'cio-pia-container' },
|
|
13
13
|
!hasHistory && (react_1.default.createElement("p", { className: 'cio-pia-title', "data-testid": 'cio-pia-title' }, (0, translate_1.translate)('Any questions about this product?', translations))),
|
|
14
|
-
react_1.default.createElement(ConversationHistory_1.default, { conversationHistory: conversationHistory, isLoading: isLoading, error: error, currentItems: currentItems, showFeedback: showFeedback, showPreviousItems: showPreviousItems, learnMoreUrl: learnMoreUrl, translations: translations, callbacks: callbacks, componentOverrides: componentOverrides }),
|
|
14
|
+
react_1.default.createElement(ConversationHistory_1.default, { conversationHistory: conversationHistory, isLoading: isLoading, error: error, currentItems: currentItems, showFeedback: showFeedback, showPreviousItems: showPreviousItems, learnMoreUrl: learnMoreUrl, disclaimerPosition: disclaimerPosition, translations: translations, callbacks: callbacks, componentOverrides: componentOverrides }),
|
|
15
15
|
react_1.default.createElement("div", { className: 'cio-pia-conversation-footer' },
|
|
16
16
|
isLoading && !error && react_1.default.createElement(SuggestedQuestionsSkeleton_1.default, null),
|
|
17
17
|
!isLoading && !error && (react_1.default.createElement(SuggestedQuestionsContainer_1.default, { questions: displayedQuestions, onQuestionClick: handleSubmitQuestion, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.suggestedQuestions })),
|
|
@@ -61,8 +61,9 @@ function PiaModal({ initialQuestions, handleSubmitQuestion, isLoading, component
|
|
|
61
61
|
}, [handleSubmitQuestion, openModal]);
|
|
62
62
|
return (react_1.default.createElement("div", { className: 'cio-pia-container', "data-testid": 'cio-pia-container' },
|
|
63
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(
|
|
65
|
-
|
|
64
|
+
react_1.default.createElement("div", { className: 'cio-pia-conversation-footer' },
|
|
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(Input_1.default, { onSubmit: handleQuestion, disabled: isLoading || isOpen, translations: translations })),
|
|
66
67
|
react_1.default.createElement("dialog", { ref: dialogRef, className: 'cio-pia-modal', "aria-labelledby": 'cio-pia-modal-title' },
|
|
67
68
|
react_1.default.createElement("div", { className: 'cio-pia-modal-content' },
|
|
68
69
|
react_1.default.createElement("div", { className: 'cio-pia-modal-header' },
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_1 = require("react");
|
|
4
|
-
function useConversation({ pia, itemId, isConversation, }) {
|
|
4
|
+
function useConversation({ pia, itemId, isConversation, callbacks, }) {
|
|
5
5
|
var _a, _b, _c, _d;
|
|
6
6
|
const { suggestedQuestions, answers } = pia;
|
|
7
7
|
const { getAnswer } = answers;
|
|
@@ -11,6 +11,8 @@ function useConversation({ pia, itemId, isConversation, }) {
|
|
|
11
11
|
const entryIdRef = (0, react_1.useRef)(0);
|
|
12
12
|
const prevAnswerValueRef = (0, react_1.useRef)((_a = answers.data) === null || _a === void 0 ? void 0 : _a.value);
|
|
13
13
|
const handleSubmitQuestion = (0, react_1.useCallback)((question) => {
|
|
14
|
+
var _a;
|
|
15
|
+
(_a = callbacks === null || callbacks === void 0 ? void 0 : callbacks.onQuestionSubmit) === null || _a === void 0 ? void 0 : _a.call(callbacks, question);
|
|
14
16
|
setCurrentQuestion(question);
|
|
15
17
|
getAnswer(question);
|
|
16
18
|
if (isConversation) {
|
|
@@ -18,7 +20,7 @@ function useConversation({ pia, itemId, isConversation, }) {
|
|
|
18
20
|
const id = entryIdRef.current;
|
|
19
21
|
setConversationHistory((prev) => [...prev, { id, question, answer: '' }]);
|
|
20
22
|
}
|
|
21
|
-
}, [getAnswer, isConversation]);
|
|
23
|
+
}, [getAnswer, isConversation, callbacks]);
|
|
22
24
|
const resetState = (0, react_1.useCallback)(() => {
|
|
23
25
|
setCurrentQuestion('');
|
|
24
26
|
setDisplayedQuestions(suggestedQuestions.data);
|
package/lib/cjs/version.js
CHANGED
|
@@ -15,7 +15,7 @@ import PiaModal from '../PiaConversation/PiaModal';
|
|
|
15
15
|
import PiaConversation from '../PiaConversation/PiaConversation';
|
|
16
16
|
export default function CioPia(props) {
|
|
17
17
|
const { apiKey, itemId, threadId, variationId, cioClient, displayConfigs, componentOverrides, callbacks, formatters, children, translations, suggestedQuestionsParameters, } = props;
|
|
18
|
-
const { learnMoreUrl, showFeedback, mode = 'default', type = 'inline', showPreviousItems, } = displayConfigs || {};
|
|
18
|
+
const { learnMoreUrl, showFeedback, mode = 'default', type = 'inline', showPreviousItems, disclaimerPosition = 'bottom', } = displayConfigs || {};
|
|
19
19
|
const isConversation = mode === 'conversation' || type === 'modal';
|
|
20
20
|
const pia = useCioPia({
|
|
21
21
|
apiKey,
|
|
@@ -26,7 +26,7 @@ export default function CioPia(props) {
|
|
|
26
26
|
suggestedQuestionsParameters,
|
|
27
27
|
formatImageUrl: formatters?.formatImageUrl,
|
|
28
28
|
});
|
|
29
|
-
const { currentQuestion, displayedQuestions, conversationHistory, currentAnswer, currentItems, isLoading, error, handleSubmitQuestion, resetState, } = useConversation({ pia, itemId, isConversation });
|
|
29
|
+
const { currentQuestion, displayedQuestions, conversationHistory, currentAnswer, currentItems, isLoading, error, handleSubmitQuestion, resetState, } = useConversation({ pia, itemId, isConversation, callbacks });
|
|
30
30
|
const renderProps = {
|
|
31
31
|
items: currentItems,
|
|
32
32
|
isLoading,
|
|
@@ -45,6 +45,7 @@ export default function CioPia(props) {
|
|
|
45
45
|
showFeedback,
|
|
46
46
|
showPreviousItems,
|
|
47
47
|
learnMoreUrl,
|
|
48
|
+
disclaimerPosition,
|
|
48
49
|
translations,
|
|
49
50
|
callbacks,
|
|
50
51
|
componentOverrides,
|
|
@@ -57,6 +58,7 @@ export default function CioPia(props) {
|
|
|
57
58
|
}
|
|
58
59
|
if (isConversation)
|
|
59
60
|
return React.createElement(PiaConversation, { ...conversationHistoryProps });
|
|
61
|
+
const disclaimer = (React.createElement(Disclaimer, { learnMoreUrl: learnMoreUrl, translations: translations, componentOverride: componentOverrides?.disclaimer }));
|
|
60
62
|
// Default inline mode
|
|
61
63
|
return (React.createElement("div", { className: 'cio-pia-container', "data-testid": 'cio-pia-container' },
|
|
62
64
|
React.createElement(RenderPropsWrapper, { props: renderProps, override: children || componentOverrides?.reactNode },
|
|
@@ -66,9 +68,10 @@ export default function CioPia(props) {
|
|
|
66
68
|
!isLoading && error && React.createElement(ErrorBlock, { message: error?.message || 'Unexpected error' }),
|
|
67
69
|
!isLoading && !error && (React.createElement(React.Fragment, null,
|
|
68
70
|
currentAnswer && (React.createElement("div", { className: 'cio-pia-answer-container' },
|
|
71
|
+
disclaimerPosition === 'top' && disclaimer,
|
|
69
72
|
React.createElement(Answer, { text: currentAnswer, componentOverride: componentOverrides?.answer }),
|
|
70
73
|
currentItems && (React.createElement(PiaCustomCarousel, { items: currentItems, componentOverrides: componentOverrides?.carousel, callbacks: callbacks })),
|
|
71
74
|
showFeedback && (React.createElement(Feedback, { translations: translations, onFeedback: callbacks?.onFeedback, componentOverride: componentOverrides?.feedback })),
|
|
72
|
-
|
|
75
|
+
disclaimerPosition === 'bottom' && disclaimer)),
|
|
73
76
|
React.createElement(SuggestedQuestionsContainer, { questions: displayedQuestions, onQuestionClick: handleSubmitQuestion, componentOverride: componentOverrides?.suggestedQuestions }))))));
|
|
74
77
|
}
|
|
@@ -5,7 +5,7 @@ import Disclaimer from '../CioPia/Disclaimer';
|
|
|
5
5
|
import ErrorBlock from '../Error/ErrorBlock';
|
|
6
6
|
import LoadingSkeleton from '../LoadingSkeleton/LoadingSkeleton';
|
|
7
7
|
import PiaCustomCarousel from '../CioPia/PiaCustomCarousel';
|
|
8
|
-
export default function ConversationHistory({ conversationHistory, isLoading, error, currentItems, showFeedback, showPreviousItems = true, learnMoreUrl, translations, callbacks, componentOverrides, }) {
|
|
8
|
+
export default function ConversationHistory({ conversationHistory, isLoading, error, currentItems, showFeedback, showPreviousItems = true, learnMoreUrl, disclaimerPosition = 'bottom', translations, callbacks, componentOverrides, }) {
|
|
9
9
|
const scrollContainerRef = useRef(null);
|
|
10
10
|
useEffect(() => {
|
|
11
11
|
const container = scrollContainerRef.current;
|
|
@@ -16,7 +16,9 @@ export default function ConversationHistory({ conversationHistory, isLoading, er
|
|
|
16
16
|
});
|
|
17
17
|
return () => cancelAnimationFrame(frameId);
|
|
18
18
|
}, [conversationHistory, isLoading]);
|
|
19
|
+
const disclaimer = (React.createElement(Disclaimer, { learnMoreUrl: learnMoreUrl, translations: translations, componentOverride: componentOverrides?.disclaimer }));
|
|
19
20
|
return (React.createElement("div", { className: 'cio-pia-conversation-history' },
|
|
21
|
+
disclaimerPosition === 'top' && disclaimer,
|
|
20
22
|
React.createElement("div", { ref: scrollContainerRef, className: 'cio-pia-conversation-entries', role: 'log', "aria-label": 'Conversation history' }, conversationHistory.map((entry, index) => {
|
|
21
23
|
const isLast = index === conversationHistory.length - 1;
|
|
22
24
|
const previousEntryItems = showPreviousItems ? entry.items : null;
|
|
@@ -32,5 +34,5 @@ export default function ConversationHistory({ conversationHistory, isLoading, er
|
|
|
32
34
|
carouselItems && (React.createElement(PiaCustomCarousel, { items: carouselItems, componentOverrides: componentOverrides?.carousel, callbacks: callbacks })),
|
|
33
35
|
isLast && showFeedback && (React.createElement(Feedback, { translations: translations, onFeedback: callbacks?.onFeedback, componentOverride: componentOverrides?.feedback }))))));
|
|
34
36
|
})),
|
|
35
|
-
|
|
37
|
+
disclaimerPosition === 'bottom' && disclaimer));
|
|
36
38
|
}
|
|
@@ -4,11 +4,11 @@ import SuggestedQuestionsContainer from '../SuggestedQuestionsContainer/Suggeste
|
|
|
4
4
|
import SuggestedQuestionsSkeleton from '../SuggestedQuestionsContainer/SuggestedQuestionsSkeleton';
|
|
5
5
|
import { translate } from '../../utils/translate';
|
|
6
6
|
import ConversationHistory from '../ConversationHistory/ConversationHistory';
|
|
7
|
-
export default function PiaConversation({ conversationHistory, isLoading, error, currentItems, showFeedback, showPreviousItems, learnMoreUrl, translations, callbacks, componentOverrides, displayedQuestions, handleSubmitQuestion, }) {
|
|
7
|
+
export default function PiaConversation({ conversationHistory, isLoading, error, currentItems, showFeedback, showPreviousItems, learnMoreUrl, disclaimerPosition, translations, callbacks, componentOverrides, displayedQuestions, handleSubmitQuestion, }) {
|
|
8
8
|
const hasHistory = conversationHistory.length > 0;
|
|
9
9
|
return (React.createElement("div", { className: 'cio-pia-container cio-pia-conversation', "data-testid": 'cio-pia-container' },
|
|
10
10
|
!hasHistory && (React.createElement("p", { className: 'cio-pia-title', "data-testid": 'cio-pia-title' }, translate('Any questions about this product?', translations))),
|
|
11
|
-
React.createElement(ConversationHistory, { conversationHistory: conversationHistory, isLoading: isLoading, error: error, currentItems: currentItems, showFeedback: showFeedback, showPreviousItems: showPreviousItems, learnMoreUrl: learnMoreUrl, translations: translations, callbacks: callbacks, componentOverrides: componentOverrides }),
|
|
11
|
+
React.createElement(ConversationHistory, { conversationHistory: conversationHistory, isLoading: isLoading, error: error, currentItems: currentItems, showFeedback: showFeedback, showPreviousItems: showPreviousItems, learnMoreUrl: learnMoreUrl, disclaimerPosition: disclaimerPosition, translations: translations, callbacks: callbacks, componentOverrides: componentOverrides }),
|
|
12
12
|
React.createElement("div", { className: 'cio-pia-conversation-footer' },
|
|
13
13
|
isLoading && !error && React.createElement(SuggestedQuestionsSkeleton, null),
|
|
14
14
|
!isLoading && !error && (React.createElement(SuggestedQuestionsContainer, { questions: displayedQuestions, onQuestionClick: handleSubmitQuestion, componentOverride: componentOverrides?.suggestedQuestions })),
|
|
@@ -58,8 +58,9 @@ export default function PiaModal({ initialQuestions, handleSubmitQuestion, isLoa
|
|
|
58
58
|
}, [handleSubmitQuestion, openModal]);
|
|
59
59
|
return (React.createElement("div", { className: 'cio-pia-container', "data-testid": 'cio-pia-container' },
|
|
60
60
|
React.createElement("p", { className: 'cio-pia-title', "data-testid": 'cio-pia-title' }, translate('Any questions about this product?', translations)),
|
|
61
|
-
React.createElement(
|
|
62
|
-
|
|
61
|
+
React.createElement("div", { className: 'cio-pia-conversation-footer' },
|
|
62
|
+
initialQuestions.length > 0 && (React.createElement(SuggestedQuestionsContainer, { questions: initialQuestions, onQuestionClick: handleQuestion, componentOverride: componentOverrides?.suggestedQuestions })),
|
|
63
|
+
React.createElement(Input, { onSubmit: handleQuestion, disabled: isLoading || isOpen, translations: translations })),
|
|
63
64
|
React.createElement("dialog", { ref: dialogRef, className: 'cio-pia-modal', "aria-labelledby": 'cio-pia-modal-title' },
|
|
64
65
|
React.createElement("div", { className: 'cio-pia-modal-content' },
|
|
65
66
|
React.createElement("div", { className: 'cio-pia-modal-header' },
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
-
export default function useConversation({ pia, itemId, isConversation, }) {
|
|
2
|
+
export default function useConversation({ pia, itemId, isConversation, callbacks, }) {
|
|
3
3
|
const { suggestedQuestions, answers } = pia;
|
|
4
4
|
const { getAnswer } = answers;
|
|
5
5
|
const [currentQuestion, setCurrentQuestion] = useState('');
|
|
@@ -8,6 +8,7 @@ export default function useConversation({ pia, itemId, isConversation, }) {
|
|
|
8
8
|
const entryIdRef = useRef(0);
|
|
9
9
|
const prevAnswerValueRef = useRef(answers.data?.value);
|
|
10
10
|
const handleSubmitQuestion = useCallback((question) => {
|
|
11
|
+
callbacks?.onQuestionSubmit?.(question);
|
|
11
12
|
setCurrentQuestion(question);
|
|
12
13
|
getAnswer(question);
|
|
13
14
|
if (isConversation) {
|
|
@@ -15,7 +16,7 @@ export default function useConversation({ pia, itemId, isConversation, }) {
|
|
|
15
16
|
const id = entryIdRef.current;
|
|
16
17
|
setConversationHistory((prev) => [...prev, { id, question, answer: '' }]);
|
|
17
18
|
}
|
|
18
|
-
}, [getAnswer, isConversation]);
|
|
19
|
+
}, [getAnswer, isConversation, callbacks]);
|
|
19
20
|
const resetState = useCallback(() => {
|
|
20
21
|
setCurrentQuestion('');
|
|
21
22
|
setDisplayedQuestions(suggestedQuestions.data);
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '2.
|
|
1
|
+
export default '2.3.0';
|
|
@@ -10,6 +10,18 @@ export interface CioPiaProps extends IncludeRenderProps<CioPiaRenderProps>, Incl
|
|
|
10
10
|
variationId?: string;
|
|
11
11
|
cioClient?: MockConstructorIOClient;
|
|
12
12
|
displayConfigs?: CioPiaDisplayConfigs;
|
|
13
|
+
/**
|
|
14
|
+
* Callback handlers for user interactions:
|
|
15
|
+
*
|
|
16
|
+
* `onQuestionSubmit: (question: string) => void`
|
|
17
|
+
* Called when a question is submitted (via Enter key, Send button, or suggested question click).
|
|
18
|
+
*
|
|
19
|
+
* `onProductCardClick: (item: Item) => void`
|
|
20
|
+
* Called when a product card in the carousel is clicked.
|
|
21
|
+
*
|
|
22
|
+
* `onFeedback: (type: 'up' | 'down') => void`
|
|
23
|
+
* Called when the user submits positive or negative feedback on an answer.
|
|
24
|
+
*/
|
|
13
25
|
callbacks?: Callbacks;
|
|
14
26
|
/** Define formatter functions outside the component or memoize to avoid unnecessary re-renders. */
|
|
15
27
|
formatters?: Formatters;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ConversationEntry, Translations, Item, Callbacks, CioPiaComponentOverrides } from '../../types';
|
|
2
|
+
import { ConversationEntry, Translations, Item, Callbacks, CioPiaComponentOverrides, DisclaimerPosition } from '../../types';
|
|
3
3
|
export interface ConversationHistoryProps {
|
|
4
4
|
conversationHistory: ConversationEntry[];
|
|
5
5
|
isLoading: boolean;
|
|
@@ -18,8 +18,9 @@ export interface ConversationHistoryProps {
|
|
|
18
18
|
*/
|
|
19
19
|
showPreviousItems?: boolean;
|
|
20
20
|
learnMoreUrl?: string;
|
|
21
|
+
disclaimerPosition?: DisclaimerPosition;
|
|
21
22
|
translations?: Translations;
|
|
22
23
|
callbacks?: Callbacks;
|
|
23
24
|
componentOverrides?: CioPiaComponentOverrides;
|
|
24
25
|
}
|
|
25
|
-
export default function ConversationHistory({ conversationHistory, isLoading, error, currentItems, showFeedback, showPreviousItems, learnMoreUrl, translations, callbacks, componentOverrides, }: ConversationHistoryProps): React.JSX.Element;
|
|
26
|
+
export default function ConversationHistory({ conversationHistory, isLoading, error, currentItems, showFeedback, showPreviousItems, learnMoreUrl, disclaimerPosition, translations, callbacks, componentOverrides, }: ConversationHistoryProps): React.JSX.Element;
|
|
@@ -5,4 +5,4 @@ export interface PiaConversationProps extends ConversationHistoryProps {
|
|
|
5
5
|
displayedQuestions: Question[];
|
|
6
6
|
handleSubmitQuestion: (question: string) => void;
|
|
7
7
|
}
|
|
8
|
-
export default function PiaConversation({ conversationHistory, isLoading, error, currentItems, showFeedback, showPreviousItems, learnMoreUrl, translations, callbacks, componentOverrides, displayedQuestions, handleSubmitQuestion, }: PiaConversationProps): React.JSX.Element;
|
|
8
|
+
export default function PiaConversation({ conversationHistory, isLoading, error, currentItems, showFeedback, showPreviousItems, learnMoreUrl, disclaimerPosition, translations, callbacks, componentOverrides, displayedQuestions, handleSubmitQuestion, }: PiaConversationProps): React.JSX.Element;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ConversationEntry, Question, Item } from '../types';
|
|
1
|
+
import { Callbacks, ConversationEntry, Question, Item } from '../types';
|
|
2
2
|
import { UseCioPiaReturn } from './useCioPia';
|
|
3
3
|
export interface UseConversationProps {
|
|
4
4
|
pia: UseCioPiaReturn;
|
|
5
5
|
itemId: string;
|
|
6
6
|
isConversation: boolean;
|
|
7
|
+
callbacks?: Callbacks;
|
|
7
8
|
}
|
|
8
9
|
export interface UseConversationReturn {
|
|
9
10
|
currentQuestion: string;
|
|
@@ -16,4 +17,4 @@ export interface UseConversationReturn {
|
|
|
16
17
|
handleSubmitQuestion: (question: string) => void;
|
|
17
18
|
resetState: () => void;
|
|
18
19
|
}
|
|
19
|
-
export default function useConversation({ pia, itemId, isConversation, }: UseConversationProps): UseConversationReturn;
|
|
20
|
+
export default function useConversation({ pia, itemId, isConversation, callbacks, }: UseConversationProps): UseConversationReturn;
|
package/lib/types/types.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export interface CioPiaProviderProps {
|
|
|
27
27
|
}
|
|
28
28
|
export type CioPiaMode = 'default' | 'conversation';
|
|
29
29
|
export type CioPiaType = 'inline' | 'modal';
|
|
30
|
+
export type DisclaimerPosition = 'top' | 'bottom';
|
|
30
31
|
export type CioPiaDisplayConfigs = {
|
|
31
32
|
learnMoreUrl?: string;
|
|
32
33
|
showFeedback?: boolean;
|
|
@@ -37,6 +38,14 @@ export type CioPiaDisplayConfigs = {
|
|
|
37
38
|
* The last entry always falls back to its own items when currentItems is not provided.
|
|
38
39
|
*/
|
|
39
40
|
showPreviousItems?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Position of the AI disclaimer message relative to the conversation content.
|
|
43
|
+
* - `'top'` — renders the disclaimer above the conversation history or answer.
|
|
44
|
+
* - `'bottom'` — renders the disclaimer below the conversation history or answer.
|
|
45
|
+
*
|
|
46
|
+
* @default 'bottom'
|
|
47
|
+
*/
|
|
48
|
+
disclaimerPosition?: DisclaimerPosition;
|
|
40
49
|
};
|
|
41
50
|
/**
|
|
42
51
|
* Translations type for internationalizing UI strings.
|
|
@@ -52,7 +61,11 @@ export type Translations = {
|
|
|
52
61
|
'Ask about this product'?: string;
|
|
53
62
|
};
|
|
54
63
|
export interface Callbacks {
|
|
64
|
+
/** Called when a question is submitted (via Enter key, Send button, or suggested question click). */
|
|
65
|
+
onQuestionSubmit?: (question: string) => void;
|
|
66
|
+
/** Called when a product card in the carousel is clicked. */
|
|
55
67
|
onProductCardClick?: (item: Item) => void;
|
|
68
|
+
/** Called when the user submits positive or negative feedback on an answer. */
|
|
56
69
|
onFeedback?: (type: FeedbackType) => void;
|
|
57
70
|
}
|
|
58
71
|
/** Formatter functions for transforming data before display. */
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "2.
|
|
1
|
+
declare const _default: "2.3.0";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED