@constructor-io/constructorio-ui-pia 2.6.4 → 2.8.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.
@@ -14,6 +14,7 @@ const translate_1 = require("../../utils/translate");
14
14
  const PiaInlineAnswer_1 = tslib_1.__importDefault(require("../PiaInlineAnswer/PiaInlineAnswer"));
15
15
  const PiaModal_1 = tslib_1.__importDefault(require("../PiaConversation/PiaModal"));
16
16
  const PiaConversation_1 = tslib_1.__importDefault(require("../PiaConversation/PiaConversation"));
17
+ // eslint-disable-next-line complexity
17
18
  function CioPia(props) {
18
19
  const { apiKey, itemId, threadId, variationId, cioClient, displayConfigs, componentOverrides, callbacks, formatters, children, translations, suggestedQuestionsParameters, } = props;
19
20
  const { learnMoreUrl, showFeedback, mode = 'default', type = 'inline', showPreviousItems, disclaimerPosition = 'bottom', } = displayConfigs || {};
@@ -68,7 +69,7 @@ function CioPia(props) {
68
69
  react_1.default.createElement(constructorio_ui_components_1.RenderPropsWrapper, { props: renderProps, override: children || (componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.reactNode) },
69
70
  react_1.default.createElement("p", { className: 'cio-pia-title', "data-testid": 'cio-pia-title' }, (0, translate_1.translate)('Any questions about this product?', translations)),
70
71
  react_1.default.createElement(Input_1.default, { onSubmit: handleSubmitQuestion, onFocus: handleInputFocus, value: currentQuestion, translations: translations }),
71
- isLoading && react_1.default.createElement(LoadingSkeleton_1.default, null),
72
+ isLoading && react_1.default.createElement(LoadingSkeleton_1.default, { componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.loading }),
72
73
  !isLoading && error && react_1.default.createElement(ErrorBlock_1.default, { message: (error === null || error === void 0 ? void 0 : error.message) || 'Unexpected error' }),
73
74
  !isLoading && !error && (react_1.default.createElement(react_1.default.Fragment, null,
74
75
  currentAnswer && (react_1.default.createElement(PiaInlineAnswer_1.default, { currentAnswer: currentAnswer, currentItems: currentItems, showFeedback: showFeedback, learnMoreUrl: learnMoreUrl, disclaimerPosition: disclaimerPosition, translations: translations, callbacks: callbacks, componentOverrides: componentOverrides })),
@@ -30,7 +30,7 @@ function ConversationHistory({ conversationHistory, isLoading, error, currentIte
30
30
  return (react_1.default.createElement("div", { key: entry.id, className: 'cio-pia-conversation-entry' },
31
31
  react_1.default.createElement("div", { className: 'cio-pia-chat-question' }, entry.question),
32
32
  isLast && isLoading && (react_1.default.createElement("div", { className: 'cio-pia-conversation-loading', "aria-live": 'polite' },
33
- react_1.default.createElement(LoadingSkeleton_1.default, null))),
33
+ react_1.default.createElement(LoadingSkeleton_1.default, { componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.loading }))),
34
34
  isLast && !isLoading && error && (react_1.default.createElement(ErrorBlock_1.default, { message: error.message || 'Unexpected error' })),
35
35
  entry.answer && (react_1.default.createElement("div", { className: 'cio-pia-answer-container' },
36
36
  react_1.default.createElement(Answer_1.default, { text: entry.answer, componentOverride: componentOverrides === null || componentOverrides === void 0 ? void 0 : componentOverrides.answer }),
@@ -2,10 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const react_1 = tslib_1.__importDefault(require("react"));
5
- function LoadingSkeleton() {
6
- return (react_1.default.createElement("div", { className: 'cio-pia-loading-skeleton', "data-testid": 'loading-skeleton' },
7
- react_1.default.createElement("div", { className: 'skeleton-bar' }),
8
- react_1.default.createElement("div", { className: 'skeleton-bar' }),
9
- react_1.default.createElement("div", { className: 'skeleton-bar skeleton-short' })));
5
+ const constructorio_ui_components_1 = require("@constructor-io/constructorio-ui-components");
6
+ const skeleton = (react_1.default.createElement("div", { className: 'cio-pia-loading-skeleton', "data-testid": 'loading-skeleton' },
7
+ react_1.default.createElement("div", { className: 'skeleton-bar' }),
8
+ react_1.default.createElement("div", { className: 'skeleton-bar' }),
9
+ react_1.default.createElement("div", { className: 'skeleton-bar skeleton-short' })));
10
+ function LoadingSkeleton({ componentOverride } = {}) {
11
+ return (react_1.default.createElement(constructorio_ui_components_1.RenderPropsWrapper, { props: { skeleton }, override: componentOverride === null || componentOverride === void 0 ? void 0 : componentOverride.reactNode }, skeleton));
10
12
  }
11
13
  exports.default = LoadingSkeleton;
@@ -1,6 +1,5 @@
1
1
  .cio-pia-loading-skeleton {
2
- min-width: 430px;
3
- max-width: 100%;
2
+ width: 100%;
4
3
  display: flex;
5
4
  flex-direction: column;
6
5
  gap: 8px;
@@ -13,8 +13,7 @@ class MockConstructorIOClient {
13
13
  this.recommendations = cioClient.recommendations;
14
14
  this.tracker = cioClient.tracker;
15
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);
16
+ this.agent = new agent_1.default(Object.assign(Object.assign({}, this.options), { clientId: options.clientId, sessionId: options.sessionId }));
18
17
  }
19
18
  }
20
19
  exports.default = MockConstructorIOClient;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  // Create URL for PIA API
5
5
  function createAgentUrl({ itemId, threadId, variationId, question, isStreaming = false, options, parameters = {}, }) {
6
- const { apiKey, agentServiceUrl } = options;
6
+ const { apiKey, agentServiceUrl, clientId, sessionId, userId, segments, version } = options;
7
7
  if (!agentServiceUrl)
8
8
  throw new Error('Agent service URL is required');
9
9
  let baseUrl = `${agentServiceUrl}/v1/item_questions`;
@@ -22,6 +22,21 @@ function createAgentUrl({ itemId, threadId, variationId, question, isStreaming =
22
22
  if (variationId) {
23
23
  url.searchParams.append('variation_id', variationId);
24
24
  }
25
+ if (clientId) {
26
+ url.searchParams.append('i', clientId);
27
+ }
28
+ if (sessionId != null) {
29
+ url.searchParams.append('s', String(sessionId));
30
+ }
31
+ if (userId) {
32
+ url.searchParams.append('ui', userId);
33
+ }
34
+ if (version) {
35
+ url.searchParams.append('c', version);
36
+ }
37
+ if (segments === null || segments === void 0 ? void 0 : segments.length) {
38
+ segments.forEach((segment) => url.searchParams.append('us', segment));
39
+ }
25
40
  // Any additional parameters
26
41
  Object.entries(parameters).forEach(([key, value]) => {
27
42
  if (value !== undefined) {
@@ -36,6 +36,7 @@ function useAnswerResults({ itemId, variationId, threadId, cioClient, formatImag
36
36
  return;
37
37
  setIsLoading(true);
38
38
  setError(null);
39
+ setAnswerResults(null);
39
40
  fetchAnswerResults({ client: cioClient, itemId, question, variationId, threadId })
40
41
  .then((fetchedAnswerResults) => {
41
42
  setAnswerResults(fetchedAnswerResults);
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '2.6.4';
3
+ exports.default = '2.8.0';
@@ -11,6 +11,7 @@ import { translate } from '../../utils/translate';
11
11
  import PiaInlineAnswer from '../PiaInlineAnswer/PiaInlineAnswer';
12
12
  import PiaModal from '../PiaConversation/PiaModal';
13
13
  import PiaConversation from '../PiaConversation/PiaConversation';
14
+ // eslint-disable-next-line complexity
14
15
  export default function CioPia(props) {
15
16
  const { apiKey, itemId, threadId, variationId, cioClient, displayConfigs, componentOverrides, callbacks, formatters, children, translations, suggestedQuestionsParameters, } = props;
16
17
  const { learnMoreUrl, showFeedback, mode = 'default', type = 'inline', showPreviousItems, disclaimerPosition = 'bottom', } = displayConfigs || {};
@@ -65,7 +66,7 @@ export default function CioPia(props) {
65
66
  React.createElement(RenderPropsWrapper, { props: renderProps, override: children || componentOverrides?.reactNode },
66
67
  React.createElement("p", { className: 'cio-pia-title', "data-testid": 'cio-pia-title' }, translate('Any questions about this product?', translations)),
67
68
  React.createElement(Input, { onSubmit: handleSubmitQuestion, onFocus: handleInputFocus, value: currentQuestion, translations: translations }),
68
- isLoading && React.createElement(LoadingSkeleton, null),
69
+ isLoading && React.createElement(LoadingSkeleton, { componentOverride: componentOverrides?.loading }),
69
70
  !isLoading && error && React.createElement(ErrorBlock, { message: error?.message || 'Unexpected error' }),
70
71
  !isLoading && !error && (React.createElement(React.Fragment, null,
71
72
  currentAnswer && (React.createElement(PiaInlineAnswer, { currentAnswer: currentAnswer, currentItems: currentItems, showFeedback: showFeedback, learnMoreUrl: learnMoreUrl, disclaimerPosition: disclaimerPosition, translations: translations, callbacks: callbacks, componentOverrides: componentOverrides })),
@@ -27,7 +27,7 @@ export default function ConversationHistory({ conversationHistory, isLoading, er
27
27
  return (React.createElement("div", { key: entry.id, className: 'cio-pia-conversation-entry' },
28
28
  React.createElement("div", { className: 'cio-pia-chat-question' }, entry.question),
29
29
  isLast && isLoading && (React.createElement("div", { className: 'cio-pia-conversation-loading', "aria-live": 'polite' },
30
- React.createElement(LoadingSkeleton, null))),
30
+ React.createElement(LoadingSkeleton, { componentOverride: componentOverrides?.loading }))),
31
31
  isLast && !isLoading && error && (React.createElement(ErrorBlock, { message: error.message || 'Unexpected error' })),
32
32
  entry.answer && (React.createElement("div", { className: 'cio-pia-answer-container' },
33
33
  React.createElement(Answer, { text: entry.answer, componentOverride: componentOverrides?.answer }),
@@ -1,7 +1,9 @@
1
1
  import React from 'react';
2
- export default function LoadingSkeleton() {
3
- return (React.createElement("div", { className: 'cio-pia-loading-skeleton', "data-testid": 'loading-skeleton' },
4
- React.createElement("div", { className: 'skeleton-bar' }),
5
- React.createElement("div", { className: 'skeleton-bar' }),
6
- React.createElement("div", { className: 'skeleton-bar skeleton-short' })));
2
+ import { RenderPropsWrapper, } from '@constructor-io/constructorio-ui-components';
3
+ const skeleton = (React.createElement("div", { className: 'cio-pia-loading-skeleton', "data-testid": 'loading-skeleton' },
4
+ React.createElement("div", { className: 'skeleton-bar' }),
5
+ React.createElement("div", { className: 'skeleton-bar' }),
6
+ React.createElement("div", { className: 'skeleton-bar skeleton-short' })));
7
+ export default function LoadingSkeleton({ componentOverride } = {}) {
8
+ return (React.createElement(RenderPropsWrapper, { props: { skeleton }, override: componentOverride?.reactNode }, skeleton));
7
9
  }
@@ -1,6 +1,5 @@
1
1
  .cio-pia-loading-skeleton {
2
- min-width: 430px;
3
- max-width: 100%;
2
+ width: 100%;
4
3
  display: flex;
5
4
  flex-direction: column;
6
5
  gap: 8px;
@@ -28,8 +28,11 @@ class MockConstructorIOClient {
28
28
  this.recommendations = cioClient.recommendations;
29
29
  this.tracker = cioClient.tracker;
30
30
  this.quizzes = cioClient.quizzes;
31
- // Use the mock agent instead of the one from the client
32
- this.agent = new MockAgent(this.options);
31
+ this.agent = new MockAgent({
32
+ ...this.options,
33
+ clientId: options.clientId,
34
+ sessionId: options.sessionId,
35
+ });
33
36
  }
34
37
  }
35
38
  export default MockConstructorIOClient;
@@ -1,6 +1,6 @@
1
1
  // Create URL for PIA API
2
2
  function createAgentUrl({ itemId, threadId, variationId, question, isStreaming = false, options, parameters = {}, }) {
3
- const { apiKey, agentServiceUrl } = options;
3
+ const { apiKey, agentServiceUrl, clientId, sessionId, userId, segments, version } = options;
4
4
  if (!agentServiceUrl)
5
5
  throw new Error('Agent service URL is required');
6
6
  let baseUrl = `${agentServiceUrl}/v1/item_questions`;
@@ -19,6 +19,21 @@ function createAgentUrl({ itemId, threadId, variationId, question, isStreaming =
19
19
  if (variationId) {
20
20
  url.searchParams.append('variation_id', variationId);
21
21
  }
22
+ if (clientId) {
23
+ url.searchParams.append('i', clientId);
24
+ }
25
+ if (sessionId != null) {
26
+ url.searchParams.append('s', String(sessionId));
27
+ }
28
+ if (userId) {
29
+ url.searchParams.append('ui', userId);
30
+ }
31
+ if (version) {
32
+ url.searchParams.append('c', version);
33
+ }
34
+ if (segments?.length) {
35
+ segments.forEach((segment) => url.searchParams.append('us', segment));
36
+ }
22
37
  // Any additional parameters
23
38
  Object.entries(parameters).forEach(([key, value]) => {
24
39
  if (value !== undefined) {
@@ -32,6 +32,7 @@ export default function useAnswerResults({ itemId, variationId, threadId, cioCli
32
32
  return;
33
33
  setIsLoading(true);
34
34
  setError(null);
35
+ setAnswerResults(null);
35
36
  fetchAnswerResults({ client: cioClient, itemId, question, variationId, threadId })
36
37
  .then((fetchedAnswerResults) => {
37
38
  setAnswerResults(fetchedAnswerResults);
@@ -1 +1 @@
1
- export default '2.6.4';
1
+ export default '2.8.0';
@@ -1,2 +1,8 @@
1
1
  import React from 'react';
2
- export default function LoadingSkeleton(): React.JSX.Element;
2
+ import { ComponentOverrideProps } from '@constructor-io/constructorio-ui-components';
3
+ import { LoadingRenderProps } from '../../types';
4
+ interface LoadingSkeletonProps {
5
+ componentOverride?: ComponentOverrideProps<LoadingRenderProps>;
6
+ }
7
+ export default function LoadingSkeleton({ componentOverride }?: LoadingSkeletonProps): React.JSX.Element;
8
+ export {};
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import { ReactNode } from 'react';
2
2
  import { Product, CarouselOverrides, ComponentOverrideProps } from '@constructor-io/constructorio-ui-components';
3
3
  import { ConstructorClientOptions, Nullable } from '@constructor-io/constructorio-client-javascript';
4
4
  import { Question } from './hooks/mocks/types';
@@ -128,6 +128,9 @@ export interface FeedbackRenderProps {
128
128
  translations?: Translations;
129
129
  onFeedback?: (type: FeedbackType) => void;
130
130
  }
131
+ export interface LoadingRenderProps {
132
+ skeleton: ReactNode;
133
+ }
131
134
  /**
132
135
  * Component overrides for CioPia.
133
136
  * Allows customization of sub-components via reactNode or render props functions.
@@ -138,5 +141,6 @@ export interface CioPiaComponentOverrides extends ComponentOverrideProps<CioPiaR
138
141
  suggestedQuestions?: ComponentOverrideProps<SuggestedQuestionsRenderProps>;
139
142
  disclaimer?: ComponentOverrideProps<DisclaimerRenderProps>;
140
143
  feedback?: ComponentOverrideProps<FeedbackRenderProps>;
144
+ loading?: ComponentOverrideProps<LoadingRenderProps>;
141
145
  }
142
146
  export * from './hooks/mocks/types';
@@ -1,2 +1,2 @@
1
- declare const _default: "2.6.4";
1
+ declare const _default: "2.8.0";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-pia",
3
- "version": "2.6.4",
3
+ "version": "2.8.0",
4
4
  "description": "Constructor.io AI Product Insights Agent UI library for web applications",
5
5
  "author": "Constructor.io Corporation",
6
6
  "license": "MIT",
@@ -69,7 +69,7 @@
69
69
  },
70
70
  "peerDependencies": {
71
71
  "@constructor-io/constructorio-client-javascript": "^2.71.1",
72
- "@constructor-io/constructorio-ui-components": "^1.4.0",
72
+ "@constructor-io/constructorio-ui-components": "^1.5.0",
73
73
  "react": ">=16.12.0",
74
74
  "react-dom": ">=16.12.0",
75
75
  "tslib": "^2.4.0"