@constructor-io/constructorio-ui-pia 2.1.0 → 2.1.2
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 +12 -12
- 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 +15 -4
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentOverrideProps } from '@constructor-io/constructorio-ui-components';
|
|
3
|
+
import { Translations, FeedbackRenderProps, FeedbackType } from '../../types';
|
|
4
|
+
interface FeedbackProps {
|
|
5
|
+
translations?: Translations;
|
|
6
|
+
onFeedback?: (type: FeedbackType) => void;
|
|
7
|
+
componentOverride?: ComponentOverrideProps<FeedbackRenderProps>;
|
|
8
|
+
}
|
|
9
|
+
export default function Feedback({ translations, onFeedback, componentOverride }: FeedbackProps): React.JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Translations } from '../../types';
|
|
3
|
+
interface InputProps {
|
|
4
|
+
value?: string;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
/** @deprecated Use the `translations` prop instead. */
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
onSubmit: (value: string) => void;
|
|
9
|
+
translations?: Translations;
|
|
10
|
+
}
|
|
11
|
+
declare function Input({ value: providedValue, placeholder, disabled, onSubmit, translations, }: InputProps): React.JSX.Element;
|
|
12
|
+
export default Input;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Question } from '../../types';
|
|
3
|
+
import { ConversationHistoryProps } from '../ConversationHistory/ConversationHistory';
|
|
4
|
+
export interface PiaConversationProps extends ConversationHistoryProps {
|
|
5
|
+
displayedQuestions: Question[];
|
|
6
|
+
handleSubmitQuestion: (question: string) => void;
|
|
7
|
+
}
|
|
8
|
+
export default function PiaConversation({ conversationHistory, isLoading, error, currentItems, showFeedback, learnMoreUrl, translations, callbacks, componentOverrides, displayedQuestions, handleSubmitQuestion, }: PiaConversationProps): React.JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
import { Translations, Question, CioPiaComponentOverrides } from '../../types';
|
|
3
|
+
interface PiaModalProps {
|
|
4
|
+
initialQuestions: Question[];
|
|
5
|
+
handleSubmitQuestion: (question: string) => void;
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
componentOverrides?: CioPiaComponentOverrides;
|
|
8
|
+
translations?: Translations;
|
|
9
|
+
onClose?: () => void;
|
|
10
|
+
}
|
|
11
|
+
export default function PiaModal({ initialQuestions, handleSubmitQuestion, isLoading, componentOverrides, translations, onClose, children, }: PropsWithChildren<PiaModalProps>): React.JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ComponentOverrideProps } from '@constructor-io/constructorio-ui-components';
|
|
3
|
+
import { Question, SuggestedQuestionsRenderProps } from '../../types';
|
|
4
|
+
interface SuggestedQuestionsContainerProps {
|
|
5
|
+
questions: Question[];
|
|
6
|
+
onQuestionClick: (question: string) => void;
|
|
7
|
+
componentOverride?: ComponentOverrideProps<SuggestedQuestionsRenderProps>;
|
|
8
|
+
}
|
|
9
|
+
export default function SuggestedQuestionsContainer({ questions, onQuestionClick, componentOverride, }: SuggestedQuestionsContainerProps): React.JSX.Element | null;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const DEMO_API_KEY = "key_13TO6qN9H3BP3Wrn";
|
|
2
|
+
export declare const DEMO_ITEM_ID = "149100215";
|
|
3
|
+
export declare const DEMO_QUESTION = "What is the nutritional content of this shake?";
|
|
4
|
+
export declare const DEMO_QUESTION_ALTERNATIVE_PRODUCTS = "What alternative products are available for this item?";
|
|
5
|
+
export declare const MOCK_QUESTIONS: {
|
|
6
|
+
value: string;
|
|
7
|
+
}[];
|
|
8
|
+
export declare const 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,14 @@
|
|
|
1
|
+
import { ConstructorClientOptions } from '@constructor-io/constructorio-client-javascript';
|
|
2
|
+
import { Recommendations, Browse, Search, Tracker, Quizzes } from '@constructor-io/constructorio-client-javascript/lib/types/constructorio';
|
|
3
|
+
import MockAgent from './agent';
|
|
4
|
+
declare class MockConstructorIOClient {
|
|
5
|
+
private options;
|
|
6
|
+
search: Search;
|
|
7
|
+
browse: Browse;
|
|
8
|
+
recommendations: Recommendations;
|
|
9
|
+
tracker: Tracker;
|
|
10
|
+
quizzes: Quizzes;
|
|
11
|
+
agent: MockAgent;
|
|
12
|
+
constructor(options: ConstructorClientOptions);
|
|
13
|
+
}
|
|
14
|
+
export default MockConstructorIOClient;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ConstructorClientOptions } from '@constructor-io/constructorio-client-javascript';
|
|
2
|
+
import { QuestionResponse, GetSuggestedQuestionsProps, GetAnswerResultsStreamProps, GetAnswerResultsProps, GetAnswerResultsResponse } from './types';
|
|
3
|
+
declare class MockAgent {
|
|
4
|
+
options: ConstructorClientOptions;
|
|
5
|
+
constructor(options: ConstructorClientOptions);
|
|
6
|
+
getSuggestedQuestions({ itemId, variationId, threadId, parameters, }: GetSuggestedQuestionsProps): Promise<QuestionResponse>;
|
|
7
|
+
getAnswerResults({ itemId, variationId, threadId, question, parameters, }: GetAnswerResultsProps): Promise<GetAnswerResultsResponse>;
|
|
8
|
+
getAnswerResultsStream({ itemId, threadId, variationId, question, parameters, onStart, onMessage, onEnd, }: GetAnswerResultsStreamProps): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export default MockAgent;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { ConstructorClientOptions, ItemData } from '@constructor-io/constructorio-client-javascript';
|
|
2
|
+
export type SuggestedQuestionsParameters = {
|
|
3
|
+
numResults?: number;
|
|
4
|
+
};
|
|
5
|
+
export type AgentUrlProps = {
|
|
6
|
+
itemId: string;
|
|
7
|
+
variationId?: string;
|
|
8
|
+
/** Thread ID for conversation context. Must be a valid UUID (e.g., "550e8400-e29b-41d4-a716-446655440000") */
|
|
9
|
+
threadId?: string;
|
|
10
|
+
question?: string;
|
|
11
|
+
isStreaming?: boolean;
|
|
12
|
+
options: ConstructorClientOptions;
|
|
13
|
+
parameters?: Record<string, string | number | boolean>;
|
|
14
|
+
};
|
|
15
|
+
export type GetSuggestedQuestionsProps = {
|
|
16
|
+
itemId: string;
|
|
17
|
+
variationId?: string;
|
|
18
|
+
/** Thread ID for conversation context. Must be a valid UUID (e.g., "550e8400-e29b-41d4-a716-446655440000") */
|
|
19
|
+
threadId?: string;
|
|
20
|
+
parameters?: SuggestedQuestionsParameters;
|
|
21
|
+
};
|
|
22
|
+
export interface Question {
|
|
23
|
+
value: string;
|
|
24
|
+
}
|
|
25
|
+
export interface QuestionResponse {
|
|
26
|
+
questions: Array<Question>;
|
|
27
|
+
}
|
|
28
|
+
export type GetAnswerResultsProps = {
|
|
29
|
+
itemId: string;
|
|
30
|
+
variationId?: string;
|
|
31
|
+
/** Thread ID for conversation context. Must be a valid UUID (e.g., "550e8400-e29b-41d4-a716-446655440000") */
|
|
32
|
+
threadId?: string;
|
|
33
|
+
question: string;
|
|
34
|
+
parameters?: Record<string, any>;
|
|
35
|
+
};
|
|
36
|
+
export type GetAnswerResultsStreamProps = GetAnswerResultsProps & {
|
|
37
|
+
onStart?: (event: StreamStartEvent) => void;
|
|
38
|
+
onMessage?: (event: StreamMessageEvent) => void;
|
|
39
|
+
onEnd?: (event: StreamEndEvent) => void;
|
|
40
|
+
};
|
|
41
|
+
/** Defines loose types for response-related types to account for future changes to API schema */
|
|
42
|
+
export interface ApiItemVariation extends Record<string, any> {
|
|
43
|
+
value: string;
|
|
44
|
+
data?: ItemData;
|
|
45
|
+
}
|
|
46
|
+
export interface ApiItem extends Record<string, any> {
|
|
47
|
+
value: string;
|
|
48
|
+
matched_terms: Array<string>;
|
|
49
|
+
data: ItemData;
|
|
50
|
+
variations?: Array<ApiItemVariation> | null;
|
|
51
|
+
variations_map?: Record<string, any> | Array<Record<string, any>> | null;
|
|
52
|
+
}
|
|
53
|
+
export interface AnswerItemResults {
|
|
54
|
+
request?: Record<string, any>;
|
|
55
|
+
response: {
|
|
56
|
+
results: Array<ApiItem>;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export interface GetAnswerResultsResponse {
|
|
60
|
+
qna_result_id: string;
|
|
61
|
+
value: string;
|
|
62
|
+
item_results?: AnswerItemResults;
|
|
63
|
+
follow_up_questions?: Array<Question>;
|
|
64
|
+
thread_id?: string;
|
|
65
|
+
}
|
|
66
|
+
export interface StreamStartEvent {
|
|
67
|
+
qna_result_id: string;
|
|
68
|
+
}
|
|
69
|
+
export interface StreamMessageEvent {
|
|
70
|
+
qna_result_id: string;
|
|
71
|
+
text: string;
|
|
72
|
+
}
|
|
73
|
+
export interface StreamEndEvent {
|
|
74
|
+
qna_result_id: string;
|
|
75
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Nullable } from '@constructor-io/constructorio-client-javascript';
|
|
2
|
+
import MockConstructorIOClient from './mocks/MockConstructorIOClient';
|
|
3
|
+
import { Item, GetAnswerResultsResponse } from '../types';
|
|
4
|
+
export interface UseAnswerResultsProps {
|
|
5
|
+
itemId: string;
|
|
6
|
+
variationId?: string;
|
|
7
|
+
threadId?: string;
|
|
8
|
+
cioClient: MockConstructorIOClient;
|
|
9
|
+
parameters?: Record<string, any>;
|
|
10
|
+
}
|
|
11
|
+
export interface UseAnswerResultsReturn {
|
|
12
|
+
data: Nullable<GetAnswerResultsResponse>;
|
|
13
|
+
items: Array<Item> | null;
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
error: Error | null;
|
|
16
|
+
getAnswer: (question: string) => void;
|
|
17
|
+
}
|
|
18
|
+
export default function useAnswerResults({ itemId, variationId, threadId, cioClient, }: UseAnswerResultsProps): UseAnswerResultsReturn;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ConstructorClientOptions, Nullable } from '@constructor-io/constructorio-client-javascript';
|
|
2
|
+
import MockConstructorIOClient from './mocks/MockConstructorIOClient';
|
|
3
|
+
/**
|
|
4
|
+
* Uses MockConstructorIOClient for now, to be replaced with the actual Client JS object
|
|
5
|
+
*/
|
|
6
|
+
export type UseCioClientProps = {
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
cioClient?: Nullable<MockConstructorIOClient>;
|
|
9
|
+
options?: Omit<ConstructorClientOptions, 'apiKey' | 'sendTrackingEvents' | 'version'>;
|
|
10
|
+
};
|
|
11
|
+
type UseCioClient = (props: UseCioClientProps) => Nullable<MockConstructorIOClient> | never;
|
|
12
|
+
declare const useCioClient: UseCioClient;
|
|
13
|
+
export default useCioClient;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SuggestedQuestionsParameters } from '../types';
|
|
2
|
+
import MockConstructorIOClient from './mocks/MockConstructorIOClient';
|
|
3
|
+
import { UseAnswerResultsReturn } from './useAnswerResults';
|
|
4
|
+
import { UseSuggestedQuestionsReturn } from './useSuggestedQuestions';
|
|
5
|
+
export interface UseCioPiaProps {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
itemId: string;
|
|
8
|
+
variationId?: string;
|
|
9
|
+
threadId?: string;
|
|
10
|
+
cioClient?: MockConstructorIOClient;
|
|
11
|
+
suggestedQuestionsParameters?: SuggestedQuestionsParameters;
|
|
12
|
+
}
|
|
13
|
+
export interface UseCioPiaReturn {
|
|
14
|
+
suggestedQuestions: UseSuggestedQuestionsReturn;
|
|
15
|
+
answers: UseAnswerResultsReturn;
|
|
16
|
+
}
|
|
17
|
+
export default function useCioPia(props: UseCioPiaProps): UseCioPiaReturn;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ConversationEntry, Question, Item } from '../types';
|
|
2
|
+
import { UseCioPiaReturn } from './useCioPia';
|
|
3
|
+
export interface UseConversationProps {
|
|
4
|
+
pia: UseCioPiaReturn;
|
|
5
|
+
itemId: string;
|
|
6
|
+
isConversation: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface UseConversationReturn {
|
|
9
|
+
currentQuestion: string;
|
|
10
|
+
displayedQuestions: Question[];
|
|
11
|
+
conversationHistory: ConversationEntry[];
|
|
12
|
+
currentAnswer: string;
|
|
13
|
+
currentItems: Item[] | null;
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
error: Error | null;
|
|
16
|
+
handleSubmitQuestion: (question: string) => void;
|
|
17
|
+
resetState: () => void;
|
|
18
|
+
}
|
|
19
|
+
export default function useConversation({ pia, itemId, isConversation, }: UseConversationProps): UseConversationReturn;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Question, SuggestedQuestionsParameters } from '../types';
|
|
2
|
+
import MockConstructorIOClient from './mocks/MockConstructorIOClient';
|
|
3
|
+
export interface UseSuggestedQuestionsProps {
|
|
4
|
+
itemId: string;
|
|
5
|
+
variationId?: string;
|
|
6
|
+
threadId?: string;
|
|
7
|
+
cioClient?: MockConstructorIOClient;
|
|
8
|
+
parameters?: SuggestedQuestionsParameters;
|
|
9
|
+
}
|
|
10
|
+
export interface UseSuggestedQuestionsReturn {
|
|
11
|
+
data: Array<Question>;
|
|
12
|
+
isLoading: boolean;
|
|
13
|
+
error: Error | null;
|
|
14
|
+
getSuggestedQuestions: () => void;
|
|
15
|
+
}
|
|
16
|
+
export default function useSuggestedQuestions({ itemId, variationId, threadId, cioClient, parameters, }: UseSuggestedQuestionsProps): UseSuggestedQuestionsReturn;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Product, CarouselOverrides, ComponentOverrideProps } from '@constructor-io/constructorio-ui-components';
|
|
3
|
+
import { ConstructorClientOptions, Nullable } from '@constructor-io/constructorio-client-javascript';
|
|
4
|
+
import { Question } from './hooks/mocks/types';
|
|
5
|
+
import MockConstructorIOClient from './hooks/mocks/MockConstructorIOClient';
|
|
6
|
+
export declare enum FeedbackType {
|
|
7
|
+
UP = "up",
|
|
8
|
+
DOWN = "down"
|
|
9
|
+
}
|
|
10
|
+
export interface PiaContextValue {
|
|
11
|
+
cioClient: Nullable<MockConstructorIOClient>;
|
|
12
|
+
cioClientOptions: CioClientOptions;
|
|
13
|
+
setCioClientOptions: React.Dispatch<CioClientOptions>;
|
|
14
|
+
itemId: string;
|
|
15
|
+
variationId?: string;
|
|
16
|
+
/** Thread ID for conversation context. Must be a valid UUID (e.g., "550e8400-e29b-41d4-a716-446655440000") */
|
|
17
|
+
threadId?: string;
|
|
18
|
+
}
|
|
19
|
+
export type CioClientOptions = Omit<ConstructorClientOptions, 'apiKey' | 'sendTrackingEvents'>;
|
|
20
|
+
export interface CioPiaProviderProps {
|
|
21
|
+
apiKey: string;
|
|
22
|
+
itemId: string;
|
|
23
|
+
variationId?: string;
|
|
24
|
+
/** Thread ID for conversation context. Must be a valid UUID (e.g., "550e8400-e29b-41d4-a716-446655440000") */
|
|
25
|
+
threadId?: string;
|
|
26
|
+
cioClient?: Nullable<MockConstructorIOClient>;
|
|
27
|
+
}
|
|
28
|
+
export type CioPiaMode = 'default' | 'conversation';
|
|
29
|
+
export type CioPiaType = 'inline' | 'modal';
|
|
30
|
+
export type CioPiaDisplayConfigs = {
|
|
31
|
+
learnMoreUrl?: string;
|
|
32
|
+
showFeedback?: boolean;
|
|
33
|
+
mode?: CioPiaMode;
|
|
34
|
+
type?: CioPiaType;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Translations type for internationalizing UI strings.
|
|
38
|
+
* All keys are optional - any non-provided translation will fallback to English default.
|
|
39
|
+
*/
|
|
40
|
+
export type Translations = {
|
|
41
|
+
'Any questions about this product?'?: string;
|
|
42
|
+
'Ask anything'?: string;
|
|
43
|
+
Send?: string;
|
|
44
|
+
'AI-generated answers aim to help, but they may occasionally miss details or be inaccurate. Double-check important information before purchasing.'?: string;
|
|
45
|
+
'Is this answer useful?'?: string;
|
|
46
|
+
'Learn More.'?: string;
|
|
47
|
+
'Ask about this product'?: string;
|
|
48
|
+
};
|
|
49
|
+
export interface Callbacks {
|
|
50
|
+
onProductCardClick?: (item: Item) => void;
|
|
51
|
+
onFeedback?: (type: FeedbackType) => void;
|
|
52
|
+
}
|
|
53
|
+
/** Extends Product type to include PIA-specific fields */
|
|
54
|
+
export interface Item extends Product, Record<string, any> {
|
|
55
|
+
url?: string;
|
|
56
|
+
matchedTerms?: string[];
|
|
57
|
+
}
|
|
58
|
+
export interface ConversationEntry {
|
|
59
|
+
id: number;
|
|
60
|
+
question: string;
|
|
61
|
+
answer: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Render props passed to CioPia children function
|
|
65
|
+
*/
|
|
66
|
+
export interface CioPiaRenderProps {
|
|
67
|
+
items: Item[] | null;
|
|
68
|
+
isLoading: boolean;
|
|
69
|
+
error?: Error | null;
|
|
70
|
+
currentAnswer: string;
|
|
71
|
+
currentQuestion: string;
|
|
72
|
+
displayedQuestions: Question[];
|
|
73
|
+
handleSubmitQuestion: (question: string) => void;
|
|
74
|
+
conversationHistory: ConversationEntry[];
|
|
75
|
+
}
|
|
76
|
+
export interface AnswerRenderProps {
|
|
77
|
+
text: string;
|
|
78
|
+
}
|
|
79
|
+
export interface SuggestedQuestionsRenderProps {
|
|
80
|
+
questions: Question[];
|
|
81
|
+
onQuestionClick: (question: string) => void;
|
|
82
|
+
}
|
|
83
|
+
export interface DisclaimerRenderProps {
|
|
84
|
+
learnMoreUrl?: string;
|
|
85
|
+
translations?: Translations;
|
|
86
|
+
}
|
|
87
|
+
export interface FeedbackRenderProps {
|
|
88
|
+
translations?: Translations;
|
|
89
|
+
onFeedback?: (type: FeedbackType) => void;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Component overrides for CioPia
|
|
93
|
+
* Allows customization of sub-components via reactNode or render props functions
|
|
94
|
+
*/
|
|
95
|
+
export interface CioPiaComponentOverrides extends ComponentOverrideProps<CioPiaRenderProps> {
|
|
96
|
+
carousel?: CarouselOverrides<Item>;
|
|
97
|
+
answer?: ComponentOverrideProps<AnswerRenderProps>;
|
|
98
|
+
suggestedQuestions?: ComponentOverrideProps<SuggestedQuestionsRenderProps>;
|
|
99
|
+
disclaimer?: ComponentOverrideProps<DisclaimerRenderProps>;
|
|
100
|
+
feedback?: ComponentOverrideProps<FeedbackRenderProps>;
|
|
101
|
+
}
|
|
102
|
+
export * from './hooks/mocks/types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './styleHelpers';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getPreferredColorScheme(): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Nullable } from '@constructor-io/constructorio-client-javascript';
|
|
2
|
+
import { Item, ApiItem } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Converts a raw ApiItem from the Get Answers API response into an Item object
|
|
5
|
+
* that can be used in the Carousel component.
|
|
6
|
+
*/
|
|
7
|
+
export declare function transformResultItem(resultItem: ApiItem): Nullable<Item>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Translations } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Translates a word using the provided translations object.
|
|
4
|
+
* Falls back to English defaults if translation is not provided.
|
|
5
|
+
*
|
|
6
|
+
* @param word - The key to translate
|
|
7
|
+
* @param translations - Optional user-provided translations object
|
|
8
|
+
* @returns The translated string or the original word if no translation exists
|
|
9
|
+
*/
|
|
10
|
+
export declare const translate: (word: string, translations?: Translations) => string;
|
package/package.json
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructor-io/constructorio-ui-pia",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Constructor.io AI Product Insights Agent UI library for web applications",
|
|
5
5
|
"author": "Constructor.io Corporation",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"constructor.io",
|
|
9
|
+
"ai",
|
|
10
|
+
"product insights",
|
|
11
|
+
"chatbot",
|
|
12
|
+
"ecommerce",
|
|
13
|
+
"react",
|
|
14
|
+
"ui",
|
|
15
|
+
"product discovery"
|
|
16
|
+
],
|
|
7
17
|
"homepage": "https://github.com/Constructor-io/constructorio-ui-pia#readme",
|
|
8
18
|
"repository": {
|
|
9
19
|
"type": "git",
|
|
@@ -33,10 +43,11 @@
|
|
|
33
43
|
}
|
|
34
44
|
},
|
|
35
45
|
"files": [
|
|
36
|
-
"dist/constructorio-ui-pia-bundled.js"
|
|
46
|
+
"dist/constructorio-ui-pia-bundled.js",
|
|
47
|
+
"lib/"
|
|
37
48
|
],
|
|
38
49
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
50
|
+
"node": ">=20"
|
|
40
51
|
},
|
|
41
52
|
"types": "lib/types/index.d.ts",
|
|
42
53
|
"scripts": {
|
|
@@ -58,7 +69,7 @@
|
|
|
58
69
|
},
|
|
59
70
|
"peerDependencies": {
|
|
60
71
|
"@constructor-io/constructorio-client-javascript": "^2.71.1",
|
|
61
|
-
"@constructor-io/constructorio-ui-components": "^1.
|
|
72
|
+
"@constructor-io/constructorio-ui-components": "^1.4.0",
|
|
62
73
|
"react": ">=16.12.0",
|
|
63
74
|
"react-dom": ">=16.12.0",
|
|
64
75
|
"tslib": "^2.4.0"
|