@cimulate/copilot-widget 1.57.0 → 1.58.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.
@@ -35,6 +35,8 @@ import { RefinedSearch } from '@cimulate/copilot-sdk';
35
35
  import { SearchParams } from '@cimulate/copilot-sdk';
36
36
  import { SessionContextEntry } from '@cimulate/agentforce-sdk';
37
37
 
38
+ export declare const addCartActionListener: (listener: EventListener) => void;
39
+
38
40
  export declare const addCartUpdateListener: (listener: EventListener) => void;
39
41
 
40
42
  declare interface AddToCartParams {
@@ -103,8 +105,51 @@ declare interface BrowseState extends CommonParams {
103
105
  categoryName?: string;
104
106
  }
105
107
 
108
+ export declare const CART_ACTION_EVENT = "cimulate:cart-action";
109
+
106
110
  export declare const CART_UPDATE_EVENT = "cimulate:cart-update";
107
111
 
112
+ /**
113
+ * `detail` of `cimulate:cart-action`. Call `respond` once with the latest cart
114
+ * after the storefront finishes the action. `itemId` is the basket line.
115
+ * `quantity` and `remove` also include `productId` (empty when the line has none)
116
+ * and `variants` (`lbl`, `type`, `value`), omitting entries with no value.
117
+ */
118
+ export declare type CartActionDetail = CartActionRequest & {
119
+ respond: (result: CartActionResult) => void;
120
+ };
121
+
122
+ export declare type CartActionRequest = {
123
+ action: "get";
124
+ } | {
125
+ action: "quantity";
126
+ itemId: string;
127
+ quantity: number;
128
+ productId: string;
129
+ variants: CartItemVariant[];
130
+ } | {
131
+ action: "remove";
132
+ itemId: string;
133
+ productId: string;
134
+ variants: CartItemVariant[];
135
+ } | {
136
+ action: "coupon";
137
+ code: string;
138
+ };
139
+
140
+ /**
141
+ * Cart the storefront passes to `respond` after it handles `cimulate:cart-action`.
142
+ * `cart` on a failure is the basket the storefront still knows about, when it has one.
143
+ */
144
+ export declare type CartActionResult = {
145
+ ok: true;
146
+ cart: CartDetails;
147
+ } | {
148
+ ok: false;
149
+ error: string;
150
+ cart?: CartDetails;
151
+ };
152
+
108
153
  export declare type CartChange = CartLineChange | CartCouponChange;
109
154
 
110
155
  /** A change to the set of applied coupon codes. */
@@ -192,11 +237,8 @@ export declare interface CartMutationApi {
192
237
  }
193
238
 
194
239
  /**
195
- * The api handed to a `Cart` override. Deliberately narrower than the shared
196
- * {@link OverrideApi}: it has no `sendMessage`, so the most sensitive slot cannot
197
- * post arbitrary text or reconcile a message by id. Basket edits go through the
198
- * structured {@link CartMutationApi}; checkout and express payment stay
199
- * widget-owned.
240
+ * Structured basket mutations without `sendMessage`.
241
+ * Agent-mode checkout stays widget-owned; direct-mode overrides own payment controls.
200
242
  */
201
243
  export declare interface CartOverrideApi extends Pick<MessagingContextType, "isConnected"> {
202
244
  cart: CartMutationApi;
@@ -242,6 +284,13 @@ declare type CartResponseData = {
242
284
  };
243
285
  };
244
286
 
287
+ /**
288
+ * `"agent"` (default) edits the basket with natural-language prompts.
289
+ * `"direct"` dispatches `cimulate:cart-action` and renders the cart the
290
+ * storefront returns from `detail.respond`.
291
+ */
292
+ export declare type CartTransport = "agent" | "direct";
293
+
245
294
  /**
246
295
  * Primary action for a settled cart mutation, derived from the previous-vs-new
247
296
  * cart diff, or from the agent's `cartSummary.cartOperation` (matched
@@ -361,16 +410,9 @@ export declare interface ComponentOverrides {
361
410
  */
362
411
  OrderConfirmation?: OverrideTagName;
363
412
  /**
364
- * Replaces the in-chat cart BODY (items, totals, coupons) — a presentational
365
- * slot. Checkout and the Apple/Google Pay iframe are NOT part of it: the widget
366
- * keeps rendering them itself, beneath the override. The slot receives a
367
- * {@link CartOverrideProps} — a display-only {@link DisplayCart} (no
368
- * checkout/express URLs) and a {@link CartOverrideApi} whose `cart` methods are
369
- * the only way to mutate the basket; there is no `sendMessage`. The widget
370
- * marks every cart snapshot except the newest `readOnly` and refuses mutations
371
- * while it is set (or the cart is busy/disconnected), but an override should
372
- * also reflect `readOnly` in its controls so a shopper can't act on a stale
373
- * basket.
413
+ * Receives {@link CartOverrideProps} with display data and structured cart actions.
414
+ * Agent mode replaces the cart body; checkout stays widget-owned.
415
+ * Direct mode replaces the iframe or built-in cart and its payment controls.
374
416
  */
375
417
  Cart?: OverrideTagName;
376
418
  /**
@@ -501,13 +543,7 @@ declare type CouponEntry = string | StructuredCoupon;
501
543
 
502
544
  declare type DialogPosition = "top" | "top-left" | "top-right" | "bottom" | "bottom-left" | "bottom-right" | "left" | "right" | "center";
503
545
 
504
- /**
505
- * The cart summary handed to a `Cart` override: {@link CartDetails} minus the
506
- * transactional URLs. The widget renders checkout and Apple/Google Pay itself,
507
- * beneath the override, so `checkoutButtonUrl` and `expressPaymentUrl` never
508
- * enter customer markup — everything else is display data for the override to
509
- * lay out.
510
- */
546
+ /** Cart display data excludes checkout and express payment URLs in both modes. */
511
547
  export declare type DisplayCart = Omit<CartDetails, "checkoutButtonUrl" | "expressPaymentUrl">;
512
548
 
513
549
  declare const ENTRY_TYPES: readonly ["ask_cim", "search", "browse", "pdp"];
@@ -560,7 +596,7 @@ export declare function getAuthLinkKey(): Promise<string>;
560
596
 
561
597
  export declare function getPageContext(): PageContext | null;
562
598
 
563
- export declare type HeaderActionName = "close" | "toggleExpanded" | "toggleFullscreen" | "toggleDialogPosition" | "minimize" | "clearChat" | "endConversation" | "downloadTranscript";
599
+ export declare type HeaderActionName = "cart" | "close" | "toggleExpanded" | "toggleFullscreen" | "toggleDialogPosition" | "minimize" | "clearChat" | "endConversation" | "downloadTranscript";
564
600
 
565
601
  /**
566
602
  * Header controls a `HeaderActions` override can invoke. Each method calls the
@@ -713,6 +749,7 @@ export declare interface MessagingContextType {
713
749
  progressMessage: string;
714
750
  progressSteps: string[];
715
751
  loading: boolean;
752
+ humanHandoff: boolean;
716
753
  error: string | null;
717
754
  sendError: SendError | null;
718
755
  sessionExpired: boolean;
@@ -733,6 +770,13 @@ export declare interface MessagingContextType {
733
770
  * is not connected or the request fails.
734
771
  */
735
772
  getAuthLinkKey: () => Promise<string>;
773
+ cartTransport: CartTransport;
774
+ directCart: CartDetails | null;
775
+ directCartError: string | null;
776
+ directCartLoading: boolean;
777
+ storefrontCartPageUrl: string;
778
+ loadDirectCart: () => Promise<void>;
779
+ applyDirectCartChange: (request: CartActionRequest) => Promise<SendMessageResult>;
736
780
  }
737
781
 
738
782
  /**
@@ -863,9 +907,20 @@ export declare interface MessagingModeConfig {
863
907
  * entries are ignored. `null` hides the connecting indicator entirely.
864
908
  */
865
909
  connectingMessages?: readonly string[] | null;
910
+ /**
911
+ * Who edits the basket. `"agent"` (default) sends the natural-language cart
912
+ * prompts. `"direct"` dispatches `cimulate:cart-action` and renders the cart
913
+ * the storefront passes to `detail.respond`.
914
+ */
915
+ cartTransport?: CartTransport;
916
+ /**
917
+ * Storefront cart page embedded in the cart tab. When set, that page replaces
918
+ * the built-in lines, coupon field, totals, and checkout.
919
+ */
920
+ storefrontCartPageUrl?: string;
866
921
  }
867
922
 
868
- export declare const MessagingProvider: ({ scrt2Url, orgId, esDeveloperName, routingAttributes, conversationId: configConversationId, continuationToken: configContinuationToken, lastEventId: configLastEventId, capabilitiesVersion, enablePageContext, enableLogging, onConnect, onMessage, onError, onProductResult, onEndConversation, onSessionUpdate, onWelcomeTimeout, children, }: MessagingProviderProps) => JSX_2.Element;
923
+ export declare const MessagingProvider: ({ scrt2Url, orgId, esDeveloperName, routingAttributes, conversationId: configConversationId, continuationToken: configContinuationToken, lastEventId: configLastEventId, capabilitiesVersion, enablePageContext, enableLogging, onConnect, onMessage, onError, onProductResult, onEndConversation, onSessionUpdate, onWelcomeTimeout, cartTransport, storefrontCartPageUrl, children, }: MessagingProviderProps) => JSX_2.Element;
869
924
 
870
925
  declare interface MessagingProviderProps {
871
926
  scrt2Url: string;
@@ -886,6 +941,8 @@ declare interface MessagingProviderProps {
886
941
  onEndConversation?: (conversationId: string | null) => Promise<void> | void;
887
942
  onSessionUpdate?: (update: MessagingSessionUpdate) => void;
888
943
  onWelcomeTimeout?: () => void;
944
+ cartTransport?: CartTransport;
945
+ storefrontCartPageUrl?: string;
889
946
  children: ReactNode;
890
947
  }
891
948
 
@@ -916,6 +973,7 @@ export declare interface MessagingSessionUpdate {
916
973
  declare interface MessagingState {
917
974
  connectionStatus: MessagingConnectionStatus;
918
975
  loading: boolean;
976
+ humanHandoff: boolean;
919
977
  conversationId: string | null;
920
978
  /**
921
979
  * SCRT2 MessagingSession record id, surfaced only on `message` events (there is
@@ -1119,7 +1177,8 @@ export declare interface OverrideFailureOptions {
1119
1177
  * - "Cart" → uses its own {@link CartOverrideProps}, not this
1120
1178
  * generic shape: a display-only {@link DisplayCart} plus
1121
1179
  * a structured `cart` mutation api and NO `sendMessage`.
1122
- * Checkout and express payment stay widget-owned. See
1180
+ * In agent mode, checkout and express payment stay widget-owned.
1181
+ * In direct mode, the override replaces the cart and its payment controls. See
1123
1182
  * ComponentOverrides.Cart.
1124
1183
  * - "HeaderActions" → uses its own {@link HeaderActionsOverrideProps}:
1125
1184
  * `payload.actions` is the live header state, and `api`
@@ -1357,6 +1416,8 @@ declare type RangeFilters = Array<{
1357
1416
  max: number;
1358
1417
  }>;
1359
1418
 
1419
+ export declare const removeCartActionListener: (listener: EventListener) => void;
1420
+
1360
1421
  export declare const removeCartUpdateListener: (listener: EventListener) => void;
1361
1422
 
1362
1423
  /**