@constructor-io/constructorio-ui-pia 2.14.0 → 2.16.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.
Files changed (29) hide show
  1. package/README.md +71 -35
  2. package/dist/constructorio-ui-pia-bundled.js +45 -45
  3. package/lib/cjs/components/CioPia/CheckoutTriggerBar.js +25 -0
  4. package/lib/cjs/components/CioPia/CioPiaQna.js +16 -4
  5. package/lib/cjs/components/CioPia/CioPiaStyles.css +33 -0
  6. package/lib/cjs/components/ConversationHistory/ConversationHistory.js +7 -2
  7. package/lib/cjs/components/PiaConversation/PiaConversation.js +2 -1
  8. package/lib/cjs/components/PiaConversation/PiaConversationStyles.css +5 -0
  9. package/lib/cjs/hooks/useConversation.js +41 -6
  10. package/lib/cjs/stories/assets/storybook-styles.css +12 -10
  11. package/lib/cjs/version.js +1 -1
  12. package/lib/mjs/components/CioPia/CheckoutTriggerBar.js +20 -0
  13. package/lib/mjs/components/CioPia/CioPiaQna.js +16 -4
  14. package/lib/mjs/components/CioPia/CioPiaStyles.css +33 -0
  15. package/lib/mjs/components/ConversationHistory/ConversationHistory.js +7 -3
  16. package/lib/mjs/components/PiaConversation/PiaConversation.js +2 -1
  17. package/lib/mjs/components/PiaConversation/PiaConversationStyles.css +5 -0
  18. package/lib/mjs/hooks/useConversation.js +39 -4
  19. package/lib/mjs/stories/assets/storybook-styles.css +12 -10
  20. package/lib/mjs/version.js +1 -1
  21. package/lib/types/components/CioPia/CheckoutTriggerBar.d.ts +11 -0
  22. package/lib/types/components/CioPia/index.d.ts +1 -1
  23. package/lib/types/components/CioPia/types.d.ts +52 -1
  24. package/lib/types/components/PiaConversation/PiaConversation.d.ts +3 -2
  25. package/lib/types/hooks/useConversation.d.ts +2 -1
  26. package/lib/types/index.d.ts +1 -1
  27. package/lib/types/types.d.ts +5 -0
  28. package/lib/types/version.d.ts +1 -1
  29. package/package.json +1 -1
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { CioPiaRenderProps } from '../../types';
3
+ import { translate } from '../../utils/translate';
4
+ import type { CheckoutTrigger } from './types';
5
+ interface CheckoutTriggerBarProps {
6
+ triggers: CheckoutTrigger[];
7
+ state: CioPiaRenderProps;
8
+ translations?: Parameters<typeof translate>[1];
9
+ }
10
+ export default function CheckoutTriggerBar({ triggers, state, translations, }: CheckoutTriggerBarProps): React.JSX.Element | null;
11
+ export {};
@@ -1,4 +1,4 @@
1
1
  import CioPia from './CioPia';
2
2
  export * from './CioPia';
3
- export type { CioPiaProps } from './types';
3
+ export type { CioPiaProps, CheckoutTrigger } from './types';
4
4
  export default CioPia;
@@ -1,6 +1,43 @@
1
+ import { ReactNode } from 'react';
1
2
  import { IncludeComponentOverrides, IncludeRenderProps } from '@constructor-io/constructorio-ui-components';
2
- import { CioPiaRenderProps, CioPiaComponentOverrides, Callbacks, CioPiaAbTest, CioPiaDisplayConfigs, CioPiaTrackingConfigs, Translations, SuggestedQuestionsParameters, AnswerRequestParameters, RecsPodParameters, Formatters, ProductCardDisplayProps } from '../../types';
3
+ import { CioPiaRenderProps, CioPiaComponentOverrides, Callbacks, CioPiaAbTest, CioPiaDisplayConfigs, CioPiaTrackingConfigs, Translations, SuggestedQuestionsParameters, AnswerRequestParameters, RecsPodParameters, Formatters, ConversationEntry, ProductCardDisplayProps } from '../../types';
3
4
  import type { CioClient } from '../../hooks/usePiaClient';
5
+ /**
6
+ * A single checkout entry point rendered inside the PIA `default` mode.
7
+ * The merchant owns the checkout flow itself (typically the `@constructor-io/constructorio-ui-checkout`
8
+ * `CheckoutFlowProvider`); PIA only surfaces the button(s) that start it.
9
+ */
10
+ export interface CheckoutTrigger {
11
+ /** Stable identifier for the trigger — used as React key and forwarded to `renderButton`. */
12
+ id: string;
13
+ /** Button label. Defaults to "Checkout". */
14
+ label?: string;
15
+ /** Disables the button. Forwarded to `renderButton`, which is responsible for applying it. */
16
+ disabled?: boolean;
17
+ /**
18
+ * Predicate deciding whether this trigger should render. Called with the same
19
+ * render-props snapshot the `children`/`componentOverrides.reactNode` render callback
20
+ * receives, so consumers can gate on conversation state (e.g. "at least one answer
21
+ * shown", "at least two turns"). Defaults to always visible.
22
+ *
23
+ * `state.conversationHistory` is only filled in `conversation` mode and the modal; in
24
+ * `default` mode it stays empty, so gate on `currentAnswer` there.
25
+ */
26
+ triggerWhen?: (state: CioPiaRenderProps) => boolean;
27
+ /** Custom button renderer. When provided, `label` / `disabled` are passed through but styling is your call. */
28
+ renderButton?: (props: {
29
+ onClick: () => void;
30
+ label: string;
31
+ disabled?: boolean;
32
+ id: string;
33
+ }) => ReactNode;
34
+ /**
35
+ * Fires when the button is clicked. The merchant wires this to their checkout entry
36
+ * (e.g. `flow.start()` from `useCheckoutFlow`). Receives the render-props snapshot so
37
+ * the handler can seed the checkout with the current answer/items/conversation.
38
+ */
39
+ onTrigger: (state: CioPiaRenderProps) => void;
40
+ }
4
41
  export interface CioPiaProps extends IncludeRenderProps<CioPiaRenderProps>, IncludeComponentOverrides<CioPiaComponentOverrides> {
5
42
  /** Your Constructor.io API key. */
6
43
  apiKey: string;
@@ -10,6 +47,15 @@ export interface CioPiaProps extends IncludeRenderProps<CioPiaRenderProps>, Incl
10
47
  itemName: string;
11
48
  /** Thread ID for conversation context. Must be a valid UUID (e.g., "550e8400-e29b-41d4-a716-446655440000"). */
12
49
  threadId?: string;
50
+ /**
51
+ * A conversation you manage, such as one saved from `onAnswer` in the browser or on your own
52
+ * server. When provided, including as `[]`, these entries are the conversation shown before the
53
+ * first question; pass `[]` rather than omitting it when nothing is saved.
54
+ * Read once on mount, so render after it has loaded, and cleared when `itemId` changes. Pass the
55
+ * `threadId` the entries came from, or the agent will not remember them. Used by
56
+ * `mode: 'conversation'` and `type: 'modal'` only; the modal shows them once it opens.
57
+ */
58
+ initialConversationHistory?: ConversationEntry[];
13
59
  /** Optional variation ID for the product. */
14
60
  variationId?: string;
15
61
  /** Optional Constructor.io client instance. If not provided, one will be created internally. */
@@ -28,6 +74,11 @@ export interface CioPiaProps extends IncludeRenderProps<CioPiaRenderProps>, Incl
28
74
  formatters?: Formatters;
29
75
  /** Props forwarded to the ProductCard rendered inside the carousel. */
30
76
  productCardProps?: ProductCardDisplayProps;
77
+ /**
78
+ * One or more checkout entry points. Rendered in `default` and `conversation` modes and
79
+ * in the modal, after the answer; ignored in `recommendations` mode.
80
+ */
81
+ checkoutTriggers?: CheckoutTrigger[];
31
82
  /** UI string translations for internationalization. */
32
83
  translations?: Translations;
33
84
  /** Parameters for the suggested questions request. */
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  import { FeedbackType, Item, Question } from '../../types';
3
3
  import { ConversationHistoryProps } from '../ConversationHistory/ConversationHistory';
4
4
  export interface PiaConversationProps extends ConversationHistoryProps {
@@ -10,5 +10,6 @@ export interface PiaConversationProps extends ConversationHistoryProps {
10
10
  onResultClick?: (item: Item, position: number, question: string, qnaResultId?: string) => void;
11
11
  qnaResultId?: string;
12
12
  onInputFocus?: () => void;
13
+ checkoutElement?: ReactNode;
13
14
  }
14
- export default function PiaConversation({ conversationHistory, isLoading, error, currentItems, showFeedback, showPreviousItems, learnMoreUrl, disclaimerPosition, translations, callbacks, componentOverrides, displayedQuestions, handleSubmitQuestion, handleQuestionClick, containerRef, handleFeedback, onResultClick, qnaResultId, onInputFocus, priceCurrency, }: PiaConversationProps): React.JSX.Element;
15
+ export default function PiaConversation({ conversationHistory, isLoading, error, currentItems, showFeedback, showPreviousItems, learnMoreUrl, disclaimerPosition, translations, callbacks, componentOverrides, displayedQuestions, handleSubmitQuestion, handleQuestionClick, containerRef, handleFeedback, onResultClick, qnaResultId, onInputFocus, priceCurrency, checkoutElement, }: PiaConversationProps): React.JSX.Element;
@@ -7,6 +7,7 @@ export interface UseConversationProps {
7
7
  isConversation: boolean;
8
8
  callbacks?: Callbacks;
9
9
  tracking?: UseTrackingReturn;
10
+ initialConversationHistory?: ConversationEntry[];
10
11
  }
11
12
  export interface UseConversationReturn {
12
13
  currentQuestion: string;
@@ -23,4 +24,4 @@ export interface UseConversationReturn {
23
24
  handleFeedback: (type: FeedbackType) => void;
24
25
  resetState: () => void;
25
26
  }
26
- export default function useConversation({ pia, itemId, isConversation, callbacks, tracking, }: UseConversationProps): UseConversationReturn;
27
+ export default function useConversation({ pia, itemId, isConversation, callbacks, tracking, initialConversationHistory, }: UseConversationProps): UseConversationReturn;
@@ -1,6 +1,6 @@
1
1
  import CioPia from './components/CioPia';
2
2
  export { default as CioPia } from './components/CioPia';
3
- export type { CioPiaProps } from './components/CioPia';
3
+ export type { CioPiaProps, CheckoutTrigger } from './components/CioPia';
4
4
  export { sanitizeHtml, renderMarkdown } from './utils/contentTransformers';
5
5
  export type { RenderMarkdownOptions, SanitizeOptions } from './utils/contentTransformers';
6
6
  export { AgentRequestError } from './errors';
@@ -165,13 +165,18 @@ export interface Item extends Product, Record<string, any> {
165
165
  url?: string;
166
166
  matchedTerms?: string[];
167
167
  }
168
+ /** One question and its answer, as passed to `onAnswer` and accepted by `initialConversationHistory`. */
168
169
  export interface ConversationEntry {
170
+ /** Unique within the conversation. Assigned by the widget: ids in `initialConversationHistory` are replaced. */
169
171
  id: number;
170
172
  question: string;
171
173
  answer: string;
174
+ /** Whether the shopper typed the question or clicked a suggested one. */
172
175
  source: QuestionSource;
176
+ /** Products shown with the answer. */
173
177
  items?: Item[] | null;
174
178
  threadId?: string;
179
+ /** Identifies the answer for feedback and product click tracking. */
175
180
  qnaResultId?: string;
176
181
  }
177
182
  /** Which kind of recommendations to fetch. */
@@ -1,2 +1,2 @@
1
- declare const _default: "2.14.0";
1
+ declare const _default: "2.16.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.14.0",
3
+ "version": "2.16.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",