@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.
Files changed (120) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +219 -15
  3. package/dist/constructorio-ui-pia-bundled.js +12 -12
  4. package/lib/cjs/components/Answer/Answer.js +13 -0
  5. package/lib/cjs/components/Answer/AnswerStyles.css +8 -0
  6. package/lib/cjs/components/CioPia/CioPia.js +76 -0
  7. package/lib/cjs/components/CioPia/CioPiaStyles.css +32 -0
  8. package/lib/cjs/components/CioPia/Disclaimer.js +16 -0
  9. package/lib/cjs/components/CioPia/PiaCustomCarousel.js +41 -0
  10. package/lib/cjs/components/CioPia/index.js +6 -0
  11. package/lib/cjs/components/ConversationHistory/ConversationHistory.js +36 -0
  12. package/lib/cjs/components/ConversationHistory/ConversationHistoryStyles.css +51 -0
  13. package/lib/cjs/components/Error/ErrorBlock.js +23 -0
  14. package/lib/cjs/components/Error/ErrorStyles.css +46 -0
  15. package/lib/cjs/components/Feedback/Feedback.js +28 -0
  16. package/lib/cjs/components/Feedback/FeedbackStyles.css +31 -0
  17. package/lib/cjs/components/Input/Input.js +40 -0
  18. package/lib/cjs/components/Input/InputStyles.css +102 -0
  19. package/lib/cjs/components/LoadingSkeleton/LoadingSkeleton.js +11 -0
  20. package/lib/cjs/components/LoadingSkeleton/LoadingSkeletonStyles.css +32 -0
  21. package/lib/cjs/components/PiaConversation/PiaConversation.js +20 -0
  22. package/lib/cjs/components/PiaConversation/PiaConversationStyles.css +91 -0
  23. package/lib/cjs/components/PiaConversation/PiaModal.js +74 -0
  24. package/lib/cjs/components/SuggestedQuestion/SuggestedQuestion.js +16 -0
  25. package/lib/cjs/components/SuggestedQuestion/SuggestedQuestionStyles.css +33 -0
  26. package/lib/cjs/components/SuggestedQuestionsContainer/SuggestedQuestionsContainer.js +14 -0
  27. package/lib/cjs/components/SuggestedQuestionsContainer/SuggestedQuestionsContainerStyles.css +37 -0
  28. package/lib/cjs/components/SuggestedQuestionsContainer/SuggestedQuestionsSkeleton.js +11 -0
  29. package/lib/cjs/constants.js +17 -0
  30. package/lib/cjs/hooks/mocks/MockConstructorIOClient.js +20 -0
  31. package/lib/cjs/hooks/mocks/agent.js +146 -0
  32. package/lib/cjs/hooks/mocks/types.js +2 -0
  33. package/lib/cjs/hooks/useAnswerResults.js +62 -0
  34. package/lib/cjs/hooks/useCioClient.js +21 -0
  35. package/lib/cjs/hooks/useCioPia.js +29 -0
  36. package/lib/cjs/hooks/useConversation.js +74 -0
  37. package/lib/cjs/hooks/useSuggestedQuestions.js +52 -0
  38. package/lib/cjs/stories/assets/storybook-styles.css +112 -0
  39. package/lib/cjs/styles.css +26 -0
  40. package/lib/cjs/types.js +10 -0
  41. package/lib/cjs/utils/index.js +4 -0
  42. package/lib/cjs/utils/styleHelpers.js +14 -0
  43. package/lib/cjs/utils/transformers.js +29 -0
  44. package/lib/cjs/utils/translate.js +29 -0
  45. package/lib/cjs/version.js +3 -0
  46. package/lib/mjs/components/Answer/Answer.js +10 -0
  47. package/lib/mjs/components/Answer/AnswerStyles.css +8 -0
  48. package/lib/mjs/components/CioPia/CioPia.js +72 -0
  49. package/lib/mjs/components/CioPia/CioPiaStyles.css +32 -0
  50. package/lib/mjs/components/CioPia/Disclaimer.js +12 -0
  51. package/lib/mjs/components/CioPia/PiaCustomCarousel.js +37 -0
  52. package/lib/mjs/components/CioPia/index.js +3 -0
  53. package/lib/mjs/components/ConversationHistory/ConversationHistory.js +32 -0
  54. package/lib/mjs/components/ConversationHistory/ConversationHistoryStyles.css +51 -0
  55. package/lib/mjs/components/Error/ErrorBlock.js +20 -0
  56. package/lib/mjs/components/Error/ErrorStyles.css +46 -0
  57. package/lib/mjs/components/Feedback/Feedback.js +24 -0
  58. package/lib/mjs/components/Feedback/FeedbackStyles.css +31 -0
  59. package/lib/mjs/components/Input/Input.js +37 -0
  60. package/lib/mjs/components/Input/InputStyles.css +102 -0
  61. package/lib/mjs/components/LoadingSkeleton/LoadingSkeleton.js +7 -0
  62. package/lib/mjs/components/LoadingSkeleton/LoadingSkeletonStyles.css +32 -0
  63. package/lib/mjs/components/PiaConversation/PiaConversation.js +16 -0
  64. package/lib/mjs/components/PiaConversation/PiaConversationStyles.css +91 -0
  65. package/lib/mjs/components/PiaConversation/PiaModal.js +70 -0
  66. package/lib/mjs/components/SuggestedQuestion/SuggestedQuestion.js +13 -0
  67. package/lib/mjs/components/SuggestedQuestion/SuggestedQuestionStyles.css +33 -0
  68. package/lib/mjs/components/SuggestedQuestionsContainer/SuggestedQuestionsContainer.js +10 -0
  69. package/lib/mjs/components/SuggestedQuestionsContainer/SuggestedQuestionsContainerStyles.css +37 -0
  70. package/lib/mjs/components/SuggestedQuestionsContainer/SuggestedQuestionsSkeleton.js +7 -0
  71. package/lib/mjs/constants.js +14 -0
  72. package/lib/mjs/hooks/mocks/MockConstructorIOClient.js +35 -0
  73. package/lib/mjs/hooks/mocks/agent.js +138 -0
  74. package/lib/mjs/hooks/mocks/types.js +1 -0
  75. package/lib/mjs/hooks/useAnswerResults.js +57 -0
  76. package/lib/mjs/hooks/useCioClient.js +23 -0
  77. package/lib/mjs/hooks/useCioPia.js +25 -0
  78. package/lib/mjs/hooks/useConversation.js +71 -0
  79. package/lib/mjs/hooks/useSuggestedQuestions.js +48 -0
  80. package/lib/mjs/index.js +6 -0
  81. package/lib/mjs/stories/assets/storybook-styles.css +112 -0
  82. package/lib/mjs/styles.css +26 -0
  83. package/lib/mjs/types.js +6 -0
  84. package/lib/mjs/utils/index.js +1 -0
  85. package/lib/mjs/utils/styleHelpers.js +9 -0
  86. package/lib/mjs/utils/transformers.js +30 -0
  87. package/lib/mjs/utils/translate.js +25 -0
  88. package/lib/mjs/version.js +1 -0
  89. package/lib/types/components/Answer/Answer.d.ts +9 -0
  90. package/lib/types/components/CioPia/CioPia.d.ts +17 -0
  91. package/lib/types/components/CioPia/Disclaimer.d.ts +8 -0
  92. package/lib/types/components/CioPia/PiaCustomCarousel.d.ts +10 -0
  93. package/lib/types/components/CioPia/index.d.ts +3 -0
  94. package/lib/types/components/ConversationHistory/ConversationHistory.d.ts +14 -0
  95. package/lib/types/components/Error/ErrorBlock.d.ts +7 -0
  96. package/lib/types/components/Feedback/Feedback.d.ts +10 -0
  97. package/lib/types/components/Input/Input.d.ts +12 -0
  98. package/lib/types/components/LoadingSkeleton/LoadingSkeleton.d.ts +2 -0
  99. package/lib/types/components/PiaConversation/PiaConversation.d.ts +8 -0
  100. package/lib/types/components/PiaConversation/PiaModal.d.ts +12 -0
  101. package/lib/types/components/SuggestedQuestion/SuggestedQuestion.d.ts +7 -0
  102. package/lib/types/components/SuggestedQuestionsContainer/SuggestedQuestionsContainer.d.ts +10 -0
  103. package/lib/types/components/SuggestedQuestionsContainer/SuggestedQuestionsSkeleton.d.ts +2 -0
  104. package/lib/types/constants.d.ts +8 -0
  105. package/lib/types/hooks/mocks/MockConstructorIOClient.d.ts +14 -0
  106. package/lib/types/hooks/mocks/agent.d.ts +10 -0
  107. package/lib/types/hooks/mocks/types.d.ts +75 -0
  108. package/lib/types/hooks/useAnswerResults.d.ts +18 -0
  109. package/lib/types/hooks/useCioClient.d.ts +13 -0
  110. package/lib/types/hooks/useCioPia.d.ts +17 -0
  111. package/lib/types/hooks/useConversation.d.ts +19 -0
  112. package/lib/types/hooks/useSuggestedQuestions.d.ts +16 -0
  113. package/lib/types/index.d.ts +5 -0
  114. package/lib/types/types.d.ts +102 -0
  115. package/lib/types/utils/index.d.ts +1 -0
  116. package/lib/types/utils/styleHelpers.d.ts +1 -0
  117. package/lib/types/utils/transformers.d.ts +7 -0
  118. package/lib/types/utils/translate.d.ts +10 -0
  119. package/lib/types/version.d.ts +2 -0
  120. package/package.json +15 -4
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Constructor.io
3
+ Copyright (c) 2025 Constructor.io Corporation
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,14 +1,28 @@
1
- # Constructor AI Product Insights Agent UI library
1
+ # Constructor.io AI Product Insights Agent UI Library
2
2
 
3
- ![minzipped size](https://img.shields.io/bundlephobia/minzip/@constructor-io/constructorio-ui-pia?color=green)
4
- [![NPM Version](https://img.shields.io/npm/v/@constructor-io/constructorio-ui-pia)](https://www.npmjs.com/package/@constructor-io/constructorio-ui-pia)
3
+ [![npm](https://img.shields.io/npm/v/@constructor-io/constructorio-ui-pia)](https://www.npmjs.com/package/@constructor-io/constructorio-ui-pia)
5
4
  [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Constructor-io/constructorio-ui-pia/blob/main/LICENSE)
6
5
 
7
- ## Introduction
6
+ A UI library that provides React components to manage the fetching and rendering logic for [Constructor.io's AI Product Insights Agent](https://constructor.io/). TypeScript support is available.
8
7
 
9
- AI Product Insights Agent is an NLP chatbot embedded in product detail pages, designed to answer key technical product questions essential for final purchase decisions.
8
+ ## Table of Contents
10
9
 
11
- Our [Storybook Docs](https://constructor-io.github.io/constructorio-ui-pia/?path=/docs/general-introduction--docs) are the best place to explore the behavior and the available configuration options for this UI library.
10
+ - [Overview](#overview)
11
+ - [Installation](#installation)
12
+ - [Usage](#usage)
13
+ - [Customization](#customization)
14
+ - [Troubleshooting](#troubleshooting)
15
+ - [Local Development](#local-development)
16
+ - [Publishing New Versions](#publishing-new-versions)
17
+ - [Supporting Docs](#supporting-docs)
18
+ - [Related Libraries](#related-libraries)
19
+ - [License](#license)
20
+
21
+ ## Overview
22
+
23
+ [Constructor.io's AI Product Insights Agent](https://constructor.io/) is an NLP chatbot embedded in product detail pages, designed to answer key technical product questions essential for final purchase decisions. This UI library simplifies the integration process by providing React components that handle the fetching and rendering logic for the AI Product Insights Agent.
24
+
25
+ [Our Storybook Docs](https://constructor-io.github.io/constructorio-ui-pia/?path=/docs/general-introduction--docs) are the best place to explore the behavior and the available configuration options for this UI library.
12
26
 
13
27
  ## Installation
14
28
 
@@ -16,11 +30,78 @@ Our [Storybook Docs](https://constructor-io.github.io/constructorio-ui-pia/?path
16
30
  npm i @constructor-io/constructorio-ui-pia
17
31
  ```
18
32
 
33
+ ### Prerequisites
34
+
35
+ - Node.js >= 20
36
+ - React >= 16.12.0
37
+ - React DOM >= 16.12.0
38
+
19
39
  ## Usage
20
40
 
41
+ ### Using the React Component
42
+
43
+ The `CioPia` component handles state management, data fetching, and rendering logic for the AI Product Insights Agent.
44
+
45
+ ```jsx
46
+ import CioPia from '@constructor-io/constructorio-ui-pia';
47
+ import '@constructor-io/constructorio-ui-pia/styles.css';
48
+
49
+ function YourComponent() {
50
+ return (
51
+ <CioPia apiKey='YOUR_API_KEY' itemId='PRODUCT_ITEM_ID' />
52
+ );
53
+ }
54
+ ```
55
+
56
+ #### Display Modes
57
+
58
+ The component supports multiple display modes via the `displayConfigs` prop:
59
+
60
+ ```jsx
61
+ // Default inline mode
62
+ <CioPia apiKey='YOUR_API_KEY' itemId='PRODUCT_ITEM_ID' />
63
+
64
+ // Conversation mode with chat history
65
+ <CioPia
66
+ apiKey='YOUR_API_KEY'
67
+ itemId='PRODUCT_ITEM_ID'
68
+ displayConfigs={{ mode: 'conversation' }}
69
+ />
70
+
71
+ // Modal mode
72
+ <CioPia
73
+ apiKey='YOUR_API_KEY'
74
+ itemId='PRODUCT_ITEM_ID'
75
+ displayConfigs={{ type: 'modal' }}
76
+ />
77
+ ```
78
+
79
+ #### Configuration Options
80
+
81
+ | Prop | Type | Description |
82
+ |------|------|-------------|
83
+ | `apiKey` | `string` | Your Constructor.io API key (required) |
84
+ | `itemId` | `string` | The product item ID (required) |
85
+ | `variationId` | `string` | Optional variation ID |
86
+ | `threadId` | `string` | Optional thread ID for conversation context (must be a valid UUID) |
87
+ | `displayConfigs` | `object` | Display configuration options (see below) |
88
+ | `callbacks` | `object` | Callback handlers for user interactions |
89
+ | `translations` | `object` | UI string translations for internationalization |
90
+ | `componentOverrides` | `object` | Custom component overrides |
91
+
92
+ **Display Configs:**
93
+
94
+ | Option | Type | Default | Description |
95
+ |--------|------|---------|-------------|
96
+ | `mode` | `'default' \| 'conversation'` | `'default'` | Display mode |
97
+ | `type` | `'inline' \| 'modal'` | `'inline'` | Component type |
98
+ | `showFeedback` | `boolean` | `false` | Show feedback controls on answers |
99
+ | `showPreviousItems` | `boolean` | `true` | Show product carousels from previous conversation entries |
100
+ | `learnMoreUrl` | `string` | - | URL for the "Learn More" disclaimer link |
101
+
21
102
  ### Using the JavaScript Bundle
22
103
 
23
- This is a framework agnostic method that can be used in any JavaScript project. The `CioPia` function provides a simple interface to inject the PIA component into the provided `selector`.
104
+ This is a framework-agnostic method that can be used in any JavaScript project. The `CioPia` function provides a simple interface to inject the PIA component into the provided `selector`.
24
105
 
25
106
  In addition to [PIA component props](https://constructor-io.github.io/constructorio-ui-pia/?path=/docs/components-ciopia--docs), this function also accepts `selector` and `includeCSS`.
26
107
 
@@ -30,20 +111,143 @@ import CioPia from '@constructor-io/constructorio-ui-pia/constructorio-ui-pia-bu
30
111
  CioPia({
31
112
  selector: '#pia-container',
32
113
  includeCSS: true, // Include the default CSS styles - defaults to true
33
- apiKey: 'key_M57QS8SMPdLdLx4x',
34
- itemId: '12345',
35
- variationId: 'variation-abc',
114
+ apiKey: 'YOUR_API_KEY',
115
+ itemId: 'PRODUCT_ITEM_ID',
116
+ variationId: 'VARIATION_ID',
36
117
  // Optional: provide a thread ID to preserve conversation context (must be a valid UUID)
37
118
  threadId: '550e8400-e29b-41d4-a716-446655440000',
38
119
  });
39
120
  ```
40
121
 
41
- ## Requirements
122
+ ## Customization
123
+
124
+ ### Styling
125
+
126
+ By default, importing React components from this library does not pull any CSS into your project.
127
+
128
+ If you wish to use some starter styles from this library, add an import statement similar to the example below:
129
+
130
+ ```js
131
+ import '@constructor-io/constructorio-ui-pia/styles.css';
132
+ ```
133
+
134
+ - These starter styles can be used as a foundation to build on top of, or just as a reference for you to replace completely.
135
+ - To opt out of all default styling, do not import the `styles.css` stylesheet.
136
+ - All starter styles in this library are scoped within the `.cio-pia` CSS selector.
137
+ - These starter styles are intended to be extended by layering in your own CSS rules.
138
+
139
+ > Note: When using the JavaScript Bundle, CSS is included by default via the `includeCSS` option (defaults to `true`).
140
+
141
+ ### Translations
142
+
143
+ All UI strings can be customized via the `translations` prop for internationalization:
144
+
145
+ ```jsx
146
+ <CioPia
147
+ apiKey='YOUR_API_KEY'
148
+ itemId='PRODUCT_ITEM_ID'
149
+ translations={{
150
+ 'Any questions about this product?': 'Have a question about this product?',
151
+ 'Ask anything': 'Type your question...',
152
+ Send: 'Submit',
153
+ }}
154
+ />
155
+ ```
156
+
157
+ ### Component Overrides
158
+
159
+ You can override individual components using the `componentOverrides` prop. See our [Storybook Docs](https://constructor-io.github.io/constructorio-ui-pia/?path=/docs/general-introduction--docs) for available override options.
160
+
161
+ ## Troubleshooting
162
+
163
+ ### Known Issues
164
+
165
+ **Older JavaScript environments**
166
+
167
+ The library provides two different builds: CommonJS (cjs) and ECMAScript Modules (mjs).
168
+
169
+ For ECMAScript Modules (mjs) build, the JavaScript version is ESNext which might not be supported by your environment. If that's the case and your environment is using an older JavaScript version like ES6 (ES2015), you may get this error:
170
+
171
+ `Module parse failed: Unexpected token (15:32)
172
+ You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file`
173
+
174
+ To solve this you can import the CommonJS (cjs) build which supports ES6 (ES2015) syntax:
175
+
176
+ `import CioPia from '@constructor-io/constructorio-ui-pia/cjs'`
177
+
178
+ **ESLint**
179
+
180
+ There is a known issue with ESLint where it fails to resolve the paths exposed in the `exports` statement of NPM packages. If you are receiving the following error, you can safely disable ESLint using `// eslint-disable-line` for that line.
181
+
182
+ `Unable to resolve path to module '@constructor-io/constructorio-ui-pia/styles.css'`
183
+
184
+ Relevant open issues: [Issue 1868](https://github.com/import-js/eslint-plugin-import/issues/1868), [Issue 1810](https://github.com/import-js/eslint-plugin-import/issues/1810)
185
+
186
+ ## Local Development
187
+
188
+ ### Development Scripts
189
+
190
+ ```bash
191
+ npm ci # Install dependencies for local dev
192
+ npm run dev # Start a local dev server for Storybook
193
+ npm run lint # Run lint
194
+ npm run test # Run tests
195
+ npm run check-types # Run TypeScript type checking
196
+ ```
197
+
198
+ ### Library Maintenance
199
+
200
+ ```bash
201
+ npm run compile # Generate lib folder for publishing to npm
202
+ npm run build-storybook # Generate Storybook static bundle for deploy with GitHub Pages
203
+ ```
204
+
205
+ ## Publishing New Versions
206
+
207
+ Dispatch the [Publish](https://github.com/Constructor-io/constructorio-ui-pia/actions/workflows/publish.yml) workflow in GitHub Actions. You're required to provide two arguments:
208
+
209
+ - **Version Strategy**: `major`, `minor`, or `patch`.
210
+ - **Title**: A title for the release.
211
+
212
+ This workflow will automatically:
213
+
214
+ 1. Bump the library version using the provided strategy.
215
+ 2. Create a new git tag.
216
+ 3. Create a new GitHub release.
217
+ 4. Compile the library.
218
+ 5. Publish the new version to NPM.
219
+ 6. Deploy the Storybook docs to GitHub Pages.
220
+
221
+ #### Note: Please don't manually increase the package.json version or create new git tags.
222
+
223
+ The library version is tracked by releases and git tags. We intentionally keep the package.json version at `0.0.0` to avoid pushing changes to the `main` branch. This solves many security concerns by avoiding the need for branch-protection rule exceptions.
224
+
225
+ ## New Storybook Version
226
+
227
+ Dispatch the [Deploy Storybook](https://github.com/Constructor-io/constructorio-ui-pia/actions/workflows/deploy-storybook.yml) workflow in GitHub Actions.
228
+
229
+ #### Note: This is already done automatically when publishing a new version.
230
+
231
+ ## Supporting Docs
232
+
233
+ - [Storybook Docs](https://constructor-io.github.io/constructorio-ui-pia/?path=/docs/general-introduction--docs)
234
+ - [Constructor.io API Documentation](https://docs.constructor.io/)
235
+
236
+ ## Related Libraries
237
+
238
+ - [@constructor-io/constructorio-client-javascript](https://github.com/Constructor-io/constructorio-client-javascript) - JavaScript client for Constructor.io API
239
+ - [@constructor-io/constructorio-ui-autocomplete](https://github.com/Constructor-io/constructorio-ui-autocomplete) - Autocomplete UI library
240
+ - [@constructor-io/constructorio-ui-plp](https://github.com/Constructor-io/constructorio-ui-plp) - Product Listing Page UI library
241
+ - [@constructor-io/constructorio-ui-quizzes](https://github.com/Constructor-io/constructorio-ui-quizzes) - Quizzes UI library
242
+
243
+ ## Contributing
42
244
 
43
- - Node.js v18.20.3 (LTS Hydrogen)
44
- - React >=16.12.0
45
- - React DOM >=16.12.0
245
+ 1. Fork the repo and create a new branch.
246
+ 2. Run `npm ci` to install dependencies.
247
+ 3. Make your changes.
248
+ 4. Run `npm run lint` and `npm run test` to verify.
249
+ 5. Submit a PR for review.
46
250
 
47
251
  ## License
48
252
 
49
- MIT © Constructor.io
253
+ MIT &copy; [Constructor.io Corporation](https://constructor.io/)