@constructor-io/constructorio-ui-pia 2.3.0 → 2.6.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 (54) hide show
  1. package/dist/constructorio-ui-pia-bundled.js +77 -21
  2. package/lib/cjs/components/Answer/Answer.js +2 -1
  3. package/lib/cjs/components/CioPia/CioPia.js +12 -16
  4. package/lib/cjs/components/CioPia/PiaCustomCarousel.js +15 -1
  5. package/lib/cjs/components/Input/Input.js +2 -2
  6. package/lib/cjs/components/PiaConversation/PiaConversation.js +4 -4
  7. package/lib/cjs/components/PiaConversation/PiaModal.js +8 -4
  8. package/lib/cjs/components/PiaInlineAnswer/PiaInlineAnswer.js +18 -0
  9. package/lib/cjs/constants.js +0 -1
  10. package/lib/cjs/hooks/useAnswerResults.js +2 -4
  11. package/lib/cjs/hooks/useCioPia.js +5 -1
  12. package/lib/cjs/hooks/useConversation.js +61 -15
  13. package/lib/cjs/hooks/useViewportCallbacks.js +50 -0
  14. package/lib/cjs/index.js +5 -1
  15. package/lib/cjs/stories/assets/storybook-styles.css +89 -0
  16. package/lib/cjs/utils/contentTransformers.js +22 -0
  17. package/lib/cjs/utils/index.js +4 -0
  18. package/lib/cjs/utils/styleHelpers.js +0 -1
  19. package/lib/cjs/utils/translate.js +0 -1
  20. package/lib/cjs/version.js +1 -1
  21. package/lib/mjs/components/Answer/Answer.js +2 -1
  22. package/lib/mjs/components/CioPia/CioPia.js +12 -16
  23. package/lib/mjs/components/CioPia/PiaCustomCarousel.js +27 -2
  24. package/lib/mjs/components/Input/Input.js +2 -2
  25. package/lib/mjs/components/PiaConversation/PiaConversation.js +4 -4
  26. package/lib/mjs/components/PiaConversation/PiaModal.js +8 -4
  27. package/lib/mjs/components/PiaInlineAnswer/PiaInlineAnswer.js +14 -0
  28. package/lib/mjs/constants.js +0 -1
  29. package/lib/mjs/hooks/useAnswerResults.js +3 -5
  30. package/lib/mjs/hooks/useCioPia.js +5 -1
  31. package/lib/mjs/hooks/useConversation.js +60 -15
  32. package/lib/mjs/hooks/useViewportCallbacks.js +45 -0
  33. package/lib/mjs/index.js +2 -0
  34. package/lib/mjs/stories/assets/storybook-styles.css +89 -0
  35. package/lib/mjs/utils/contentTransformers.js +16 -0
  36. package/lib/mjs/utils/index.js +1 -0
  37. package/lib/mjs/utils/styleHelpers.js +0 -1
  38. package/lib/mjs/utils/translate.js +0 -1
  39. package/lib/mjs/version.js +1 -1
  40. package/lib/types/components/CioPia/CioPia.d.ts +12 -14
  41. package/lib/types/components/Input/Input.d.ts +2 -1
  42. package/lib/types/components/PiaConversation/PiaConversation.d.ts +4 -1
  43. package/lib/types/components/PiaConversation/PiaModal.d.ts +4 -1
  44. package/lib/types/components/PiaInlineAnswer/PiaInlineAnswer.d.ts +14 -0
  45. package/lib/types/hooks/mocks/MockConstructorIOClient.d.ts +1 -1
  46. package/lib/types/hooks/useCioPia.d.ts +1 -0
  47. package/lib/types/hooks/useConversation.d.ts +4 -1
  48. package/lib/types/hooks/useViewportCallbacks.d.ts +9 -0
  49. package/lib/types/index.d.ts +1 -0
  50. package/lib/types/types.d.ts +20 -4
  51. package/lib/types/utils/contentTransformers.d.ts +2 -0
  52. package/lib/types/utils/index.d.ts +1 -0
  53. package/lib/types/version.d.ts +1 -1
  54. package/package.json +20 -16
@@ -3,10 +3,13 @@ import { Translations, Question, CioPiaComponentOverrides } from '../../types';
3
3
  interface PiaModalProps {
4
4
  initialQuestions: Question[];
5
5
  handleSubmitQuestion: (question: string) => void;
6
+ handleQuestionClick: (question: string) => void;
7
+ containerRef?: (node: HTMLDivElement | null) => void;
6
8
  isLoading: boolean;
7
9
  componentOverrides?: CioPiaComponentOverrides;
8
10
  translations?: Translations;
11
+ onInputFocus?: () => void;
9
12
  onClose?: () => void;
10
13
  }
11
- export default function PiaModal({ initialQuestions, handleSubmitQuestion, isLoading, componentOverrides, translations, onClose, children, }: PropsWithChildren<PiaModalProps>): React.JSX.Element;
14
+ export default function PiaModal({ initialQuestions, handleSubmitQuestion, handleQuestionClick, containerRef, isLoading, componentOverrides, translations, onInputFocus, onClose, children, }: PropsWithChildren<PiaModalProps>): React.JSX.Element;
12
15
  export {};
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { Callbacks, CioPiaComponentOverrides, DisclaimerPosition, Translations, Item } from '../../types';
3
+ interface PiaInlineAnswerProps {
4
+ currentAnswer: string;
5
+ currentItems: Item[] | null;
6
+ showFeedback?: boolean;
7
+ learnMoreUrl?: string;
8
+ disclaimerPosition?: DisclaimerPosition;
9
+ translations?: Translations;
10
+ callbacks?: Callbacks;
11
+ componentOverrides?: CioPiaComponentOverrides;
12
+ }
13
+ export default function PiaInlineAnswer({ currentAnswer, currentItems, showFeedback, learnMoreUrl, disclaimerPosition, translations, callbacks, componentOverrides, }: PiaInlineAnswerProps): React.JSX.Element;
14
+ export {};
@@ -2,7 +2,7 @@ import { ConstructorClientOptions } from '@constructor-io/constructorio-client-j
2
2
  import { Recommendations, Browse, Search, Tracker, Quizzes } from '@constructor-io/constructorio-client-javascript/lib/types/constructorio';
3
3
  import MockAgent from './agent';
4
4
  declare class MockConstructorIOClient {
5
- private options;
5
+ options: ConstructorClientOptions;
6
6
  search: Search;
7
7
  browse: Browse;
8
8
  recommendations: Recommendations;
@@ -13,6 +13,7 @@ export interface UseCioPiaProps {
13
13
  formatImageUrl?: Formatters['formatImageUrl'];
14
14
  }
15
15
  export interface UseCioPiaReturn {
16
+ threadId: string;
16
17
  suggestedQuestions: UseSuggestedQuestionsReturn;
17
18
  answers: UseAnswerResultsReturn;
18
19
  }
@@ -1,4 +1,4 @@
1
- import { Callbacks, ConversationEntry, Question, Item } from '../types';
1
+ import { Callbacks, ConversationEntry, PiaCallbackContext, Question, Item } from '../types';
2
2
  import { UseCioPiaReturn } from './useCioPia';
3
3
  export interface UseConversationProps {
4
4
  pia: UseCioPiaReturn;
@@ -14,7 +14,10 @@ export interface UseConversationReturn {
14
14
  currentItems: Item[] | null;
15
15
  isLoading: boolean;
16
16
  error: Error | null;
17
+ context: PiaCallbackContext;
17
18
  handleSubmitQuestion: (question: string) => void;
19
+ handleQuestionClick: (question: string) => void;
20
+ handleInputFocus: () => void;
18
21
  resetState: () => void;
19
22
  }
20
23
  export default function useConversation({ pia, itemId, isConversation, callbacks, }: UseConversationProps): UseConversationReturn;
@@ -0,0 +1,9 @@
1
+ import { Callbacks, PiaCallbackContext } from '../types';
2
+ export interface UseViewportCallbacksProps {
3
+ callbacks?: Callbacks;
4
+ context: PiaCallbackContext;
5
+ }
6
+ export interface UseViewportCallbacksReturn {
7
+ containerRef: (node: HTMLDivElement | null) => void;
8
+ }
9
+ export default function useViewportCallbacks({ callbacks, context, }: UseViewportCallbacksProps): UseViewportCallbacksReturn;
@@ -1,5 +1,6 @@
1
1
  import CioPia from './components/CioPia';
2
2
  export { default as CioPia } from './components/CioPia';
3
3
  export type { CioPiaProps } from './components/CioPia';
4
+ export { sanitizeHtml, renderMarkdown } from './utils/contentTransformers';
4
5
  export * from './types';
5
6
  export default CioPia;
@@ -60,13 +60,26 @@ export type Translations = {
60
60
  'Learn More.'?: string;
61
61
  'Ask about this product'?: string;
62
62
  };
63
+ export type QuestionSource = 'user' | 'suggestion';
64
+ export interface PiaCallbackContext {
65
+ itemId: string;
66
+ threadId: string;
67
+ }
63
68
  export interface Callbacks {
64
- /** Called when a question is submitted (via Enter key, Send button, or suggested question click). */
65
- onQuestionSubmit?: (question: string) => void;
69
+ /** Called when a question is submitted (typed or suggested question clicked). */
70
+ onQuestionSubmit?: (question: string, context: PiaCallbackContext, source: QuestionSource) => void;
66
71
  /** Called when a product card in the carousel is clicked. */
67
72
  onProductCardClick?: (item: Item) => void;
68
73
  /** Called when the user submits positive or negative feedback on an answer. */
69
74
  onFeedback?: (type: FeedbackType) => void;
75
+ /** Called when a new answer is received. Passes the full conversation history. */
76
+ onAnswer?: (history: ConversationEntry[], context: PiaCallbackContext) => void;
77
+ /** Called when the user focuses the input field. */
78
+ onFocus?: (context: PiaCallbackContext) => void;
79
+ /** Called when the widget enters the viewport. */
80
+ onView?: (context: PiaCallbackContext) => void;
81
+ /** Called when the widget leaves the viewport. */
82
+ onOutOfView?: (context: PiaCallbackContext) => void;
70
83
  }
71
84
  /** Formatter functions for transforming data before display. */
72
85
  export interface Formatters {
@@ -82,7 +95,10 @@ export interface ConversationEntry {
82
95
  id: number;
83
96
  question: string;
84
97
  answer: string;
98
+ source: QuestionSource;
85
99
  items?: Item[] | null;
100
+ threadId?: string;
101
+ qnaResultId?: string;
86
102
  }
87
103
  /**
88
104
  * Render props passed to CioPia children function
@@ -113,8 +129,8 @@ export interface FeedbackRenderProps {
113
129
  onFeedback?: (type: FeedbackType) => void;
114
130
  }
115
131
  /**
116
- * Component overrides for CioPia
117
- * Allows customization of sub-components via reactNode or render props functions
132
+ * Component overrides for CioPia.
133
+ * Allows customization of sub-components via reactNode or render props functions.
118
134
  */
119
135
  export interface CioPiaComponentOverrides extends ComponentOverrideProps<CioPiaRenderProps> {
120
136
  carousel?: CarouselOverrides<Item>;
@@ -0,0 +1,2 @@
1
+ export declare function sanitizeHtml(html: string): string;
2
+ export declare function renderMarkdown(content: string): string;
@@ -1 +1,2 @@
1
1
  export * from './styleHelpers';
2
+ export { sanitizeHtml, renderMarkdown } from './contentTransformers';
@@ -1,2 +1,2 @@
1
- declare const _default: "2.3.0";
1
+ declare const _default: "2.6.2";
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.3.0",
3
+ "version": "2.6.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",
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "types": "lib/types/index.d.ts",
53
53
  "scripts": {
54
- "lint": "eslint src --ext js,ts,jsx,tsx",
54
+ "lint": "eslint src",
55
55
  "check-types": "npx tsc --noEmit",
56
56
  "copy-styles": "rsync -am --include='*/' --include='*.css' --exclude='*' src/ lib/mjs/ && rsync -am --include='*/' --include='*.css' --exclude='*' src/ lib/cjs/",
57
57
  "dev": "storybook dev -p 6006",
@@ -64,7 +64,7 @@
64
64
  "storybook-docs-dev": "storybook dev --docs -p 6007",
65
65
  "serve-built-storybook": "npx http-server docs",
66
66
  "compile": "rm -rf lib && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && npm run copy-styles && vite build",
67
- "check-license": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT;0BSD;BSD-2-Clause;ISC' --excludePackages 'picocolors@1.0.0;graceful-fs@4.2.11;lightningcss@1.30.2;lightningcss-darwin-arm64@1.30.2;lightningcss-linux-x64-gnu@1.30.2;lightningcss-linux-x64-musl@1.30.2'",
67
+ "check-license": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT;0BSD;BSD-2-Clause;ISC' --excludePackages 'lightningcss@1.32.0;lightningcss-darwin-arm64@1.32.0;lightningcss-linux-x64-gnu@1.32.0;lightningcss-linux-x64-musl@1.32.0'",
68
68
  "prepare": "husky"
69
69
  },
70
70
  "peerDependencies": {
@@ -82,10 +82,11 @@
82
82
  "@babel/preset-typescript": "^7.23.3",
83
83
  "@chromatic-com/storybook": "^3.2.5",
84
84
  "@cspell/eslint-plugin": "^8.17.5",
85
+ "@eslint/js": "^9.39.4",
85
86
  "@storybook/addon-a11y": "^8.6.4",
86
87
  "@storybook/addon-actions": "^8.6.4",
87
- "@storybook/addon-essentials": "^8.6.4",
88
- "@storybook/addon-interactions": "^8.6.4",
88
+ "@storybook/addon-essentials": "^8.6.18",
89
+ "@storybook/addon-interactions": "^8.6.18",
89
90
  "@storybook/addon-links": "^8.6.4",
90
91
  "@storybook/addon-onboarding": "^8.6.4",
91
92
  "@storybook/blocks": "^8.6.4",
@@ -97,32 +98,31 @@
97
98
  "@storybook/testing-library": "^0.2.1",
98
99
  "@testing-library/jest-dom": "^6.6.3",
99
100
  "@testing-library/react": "^16.2.0",
100
- "@types/jest": "^29.5.14",
101
+ "@types/dompurify": "^3.0.5",
102
+ "@types/jest": "^30.0.0",
101
103
  "@types/react": "^19.0.10",
102
104
  "@types/react-dom": "^19.0.4",
103
- "@typescript-eslint/eslint-plugin": "^7.18.0",
104
- "@typescript-eslint/parser": "^7.18.0",
105
105
  "chromatic": "^11.27.0",
106
- "eslint": "^8.57.1",
107
- "eslint-config-airbnb": "^19.0.4",
108
- "eslint-config-airbnb-typescript": "^18.0.0",
106
+ "eslint": "^9.39.4",
109
107
  "eslint-config-prettier": "^10.1.1",
108
+ "eslint-import-resolver-typescript": "^4.4.4",
110
109
  "eslint-plugin-import": "^2.31.0",
111
110
  "eslint-plugin-jsx-a11y": "^6.10.2",
112
111
  "eslint-plugin-prettier": "^5.2.3",
113
112
  "eslint-plugin-react": "^7.37.4",
114
- "eslint-plugin-react-hooks": "^4.3.0",
115
- "eslint-plugin-storybook": "^0.11.4",
116
- "globals": "^16.0.0",
113
+ "eslint-plugin-react-hooks": "^7.1.1",
114
+ "eslint-plugin-storybook": "^0.12.0",
115
+ "globals": "^16.5.0",
117
116
  "husky": "^9.1.7",
118
- "jest": "^29.7.0",
117
+ "jest": "^30.3.0",
119
118
  "jest-environment-jsdom": "^30.2.0",
119
+ "jest-environment-node": "^30.4.1",
120
120
  "license-checker": "^25.0.1",
121
121
  "prop-types": "^15.8.1",
122
122
  "start-server-and-test": "^2.0.10",
123
123
  "storybook": "^8.6.4",
124
124
  "typescript": "^4.9.4",
125
- "typescript-eslint": "^8.26.1",
125
+ "typescript-eslint": "^8.59.2",
126
126
  "vite": "^6.3.5",
127
127
  "vite-plugin-css-injected-by-js": "^3.5.2",
128
128
  "webpack": "^5.98.0"
@@ -130,5 +130,9 @@
130
130
  "volta": {
131
131
  "node": "22.18.0",
132
132
  "npm": "10.9.3"
133
+ },
134
+ "dependencies": {
135
+ "dompurify": "^3.4.2",
136
+ "marked": "^15.0.12"
133
137
  }
134
138
  }