@saar-ai/web-widget 0.22.0 → 0.24.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 (36) hide show
  1. package/dist/capture-card/capture-card-dom.d.ts +2 -0
  2. package/dist/capture-card/capture-card-dom.d.ts.map +1 -1
  3. package/dist/chunks/{capture-card-dom-_bYXscCg.js → capture-card-dom-C0IKjuBA.js} +138 -99
  4. package/dist/chunks/{chat-DrpWeT5w.js → chat-Bvu3c3dk.js} +80 -6
  5. package/dist/chunks/{host-widget-ETlw6B5z.js → host-widget-FCxPyMok.js} +260 -16
  6. package/dist/concierge-shell.css +1 -1
  7. package/dist/dock/dock-renderer.d.ts +1 -1
  8. package/dist/dock/dock-renderer.d.ts.map +1 -1
  9. package/dist/dock/dock.d.ts +5 -0
  10. package/dist/dock/dock.d.ts.map +1 -1
  11. package/dist/generated/concierge-shell-css.d.ts.map +1 -1
  12. package/dist/generated/widget-css.d.ts.map +1 -1
  13. package/dist/host-widget.d.ts.map +1 -1
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +4 -4
  17. package/dist/messages.d.ts +15 -0
  18. package/dist/messages.d.ts.map +1 -1
  19. package/dist/next/index.js +1 -1
  20. package/dist/use-chat-session.d.ts +9 -1
  21. package/dist/use-chat-session.d.ts.map +1 -1
  22. package/dist/use-voice-session.d.ts +38 -1
  23. package/dist/use-voice-session.d.ts.map +1 -1
  24. package/dist/variant-option-groups.d.ts +44 -0
  25. package/dist/variant-option-groups.d.ts.map +1 -0
  26. package/dist/variant-options.d.ts +34 -0
  27. package/dist/variant-options.d.ts.map +1 -0
  28. package/dist/voice-widget.d.ts +9 -1
  29. package/dist/voice-widget.d.ts.map +1 -1
  30. package/dist/widget/call-view.d.ts +4 -2
  31. package/dist/widget/call-view.d.ts.map +1 -1
  32. package/dist/widget/shell-renderer.d.ts +1 -1
  33. package/dist/widget/shell-renderer.d.ts.map +1 -1
  34. package/dist/widget.css +1 -1
  35. package/package.json +1 -1
  36. package/src/styles/concierge-shell-entry.css +1 -0
@@ -20,6 +20,8 @@ export interface CaptureCardSpec {
20
20
  readonly channel: CaptureCardConsentChannel;
21
21
  readonly text: string;
22
22
  };
23
+ /** The other details asked for in the same card (SAA-512), each answered on its own. */
24
+ readonly fields?: readonly Omit<CaptureCardSpec, 'consent' | 'fields'>[];
23
25
  }
24
26
  export type CaptureCardAnswer = {
25
27
  readonly field: string;
@@ -1 +1 @@
1
- {"version":3,"file":"capture-card-dom.d.ts","sourceRoot":"","sources":["../../src/capture-card/capture-card-dom.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAGL,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,EAC3B,MAAM,uCAAuC,CAAC;AAE/C,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,wEAAwE;IACxE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,wDAAwD;IACxD,QAAQ,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,yBAAyB,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3F;AAED,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAC9E;IAAE,Q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AAO,GAAG,UAAU,KAAK,IAAI,CAAC;IAC7D,yFAAyF;IACzF,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACrC;AAED,KAAK,OAAO,GACR,eAAe,GACf,eAAe,GACf,YAAY,GACZ,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,UAAU,GACV,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,qBAAqB,CAAC;AAE1B,yFAAyF;AACzF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CACtC,MAAM,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAuE9D,CAAC;AAuCF;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,kBAAkB,GAAG,MAAM,IAAI,CAgS3F"}
@@ -153,6 +153,8 @@ function mountCaptureCard(root, options) {
153
153
  const id = `wgt-capture-${++nextId}`;
154
154
  let live = true;
155
155
  let busy = false;
156
+ /** Whether any send of this card had a value taken (SAA-512). */
157
+ let saved = false;
156
158
  const form = el("form");
157
159
  form.noValidate = true;
158
160
  form.dir = RTL.test(options.locale) ? "rtl" : "ltr";
@@ -177,71 +179,81 @@ function mountCaptureCard(root, options) {
177
179
  });
178
180
  form.append(intro);
179
181
  }
180
- const label = el("label", card.label);
181
- label.htmlFor = `${id}-input`;
182
- label.style.fontWeight = "600";
183
- form.append(label);
184
- const describedBy = [];
185
- if (card.purpose !== void 0) {
186
- const purpose = el("p", card.purpose);
187
- purpose.id = `${id}-purpose`;
188
- Object.assign(purpose.style, {
189
- margin: "0",
190
- color: "var(--widget-foreground-muted)"
191
- });
192
- form.append(purpose);
193
- describedBy.push(purpose.id);
194
- }
195
- const choices = card.input === "choice" && card.choices && card.choices.length > 0 ? card.choices : null;
196
- const listed = choices !== null ? choices.map((choice) => [choice, choice]) : card.input === "country" ? countryChoices(options.locale) : null;
197
- let field;
198
- if (listed !== null) {
199
- const select = el("select");
200
- const placeholder = el("option", copy.choose);
201
- placeholder.value = "";
202
- select.append(placeholder);
203
- for (const [value, text] of listed) {
204
- const option = el("option", text);
205
- option.value = value;
206
- select.append(option);
182
+ const rows = [card, ...card.fields ?? []].map((spec, index) => {
183
+ const rowId = `${id}-${index}`;
184
+ const label = el("label", spec.label);
185
+ label.htmlFor = `${rowId}-input`;
186
+ label.style.fontWeight = "600";
187
+ form.append(label);
188
+ const describedBy = [];
189
+ if (spec.purpose !== void 0) {
190
+ const purpose = el("p", spec.purpose);
191
+ purpose.id = `${rowId}-purpose`;
192
+ Object.assign(purpose.style, {
193
+ margin: "0",
194
+ color: "var(--widget-foreground-muted)"
195
+ });
196
+ form.append(purpose);
197
+ describedBy.push(purpose.id);
207
198
  }
208
- field = select;
209
- } else {
210
- const input = el("input");
211
- const kind = INPUT_KINDS[card.input];
212
- input.type = kind?.[0] ?? "text";
213
- if (kind) {
214
- input.dir = "ltr";
215
- if (kind[1]) input.inputMode = kind[1];
216
- if (kind[2]) input.autocomplete = kind[2];
199
+ const choices = spec.input === "choice" && spec.choices && spec.choices.length > 0 ? spec.choices : null;
200
+ const listed = choices !== null ? choices.map((choice) => [choice, choice]) : spec.input === "country" ? countryChoices(options.locale) : null;
201
+ let field;
202
+ if (listed !== null) {
203
+ const select = el("select");
204
+ const placeholder = el("option", copy.choose);
205
+ placeholder.value = "";
206
+ select.append(placeholder);
207
+ for (const [value, text] of listed) {
208
+ const option = el("option", text);
209
+ option.value = value;
210
+ select.append(option);
211
+ }
212
+ field = select;
213
+ } else {
214
+ const input = el("input");
215
+ const kind = INPUT_KINDS[spec.input];
216
+ input.type = kind?.[0] ?? "text";
217
+ if (kind) {
218
+ input.dir = "ltr";
219
+ if (kind[1]) input.inputMode = kind[1];
220
+ if (kind[2]) input.autocomplete = kind[2];
221
+ }
222
+ if (spec.maxLength !== void 0) input.maxLength = spec.maxLength;
223
+ field = input;
217
224
  }
218
- if (card.maxLength !== void 0) input.maxLength = card.maxLength;
219
- field = input;
220
- }
221
- field.id = `${id}-input`;
222
- field.name = card.field;
223
- Object.assign(field.style, {
224
- width: "100%",
225
- boxSizing: "border-box",
226
- padding: "8px 10px",
227
- borderRadius: "8px",
228
- border: "1px solid var(--widget-foreground-muted)",
229
- background: "transparent",
230
- color: "inherit",
231
- font: "inherit"
232
- });
233
- form.append(field);
234
- const error = el("p");
235
- error.id = `${id}-error`;
236
- error.setAttribute("aria-live", "polite");
237
- Object.assign(error.style, {
238
- margin: "0",
239
- minHeight: "0",
240
- color: "var(--widget-foreground)"
225
+ field.id = `${rowId}-input`;
226
+ field.name = spec.field;
227
+ Object.assign(field.style, {
228
+ width: "100%",
229
+ boxSizing: "border-box",
230
+ padding: "8px 10px",
231
+ borderRadius: "8px",
232
+ border: "1px solid var(--widget-foreground-muted)",
233
+ background: "transparent",
234
+ color: "inherit",
235
+ font: "inherit"
236
+ });
237
+ form.append(field);
238
+ const error = el("p");
239
+ error.id = `${rowId}-error`;
240
+ error.setAttribute("aria-live", "polite");
241
+ Object.assign(error.style, {
242
+ margin: "0",
243
+ minHeight: "0",
244
+ color: "var(--widget-foreground)"
245
+ });
246
+ form.append(error);
247
+ describedBy.push(error.id);
248
+ field.setAttribute("aria-describedby", describedBy.join(" "));
249
+ return {
250
+ spec,
251
+ field,
252
+ error,
253
+ choices,
254
+ done: false
255
+ };
241
256
  });
242
- form.append(error);
243
- describedBy.push(error.id);
244
- field.setAttribute("aria-describedby", describedBy.join(" "));
245
257
  let consent = null;
246
258
  if (card.consent) {
247
259
  const row = el("div");
@@ -299,10 +311,10 @@ function mountCaptureCard(root, options) {
299
311
  });
300
312
  actions.append(send, refuse);
301
313
  form.append(actions);
302
- const showError = (key) => {
303
- error.textContent = key === null ? "" : copy[key === "phone" && card.region ? "phoneLocal" : key];
304
- if (key === null) field.removeAttribute("aria-invalid");
305
- else field.setAttribute("aria-invalid", "true");
314
+ const showError = (row, key) => {
315
+ row.error.textContent = key === null ? "" : copy[key === "phone" && row.spec.region ? "phoneLocal" : key];
316
+ if (key === null) row.field.removeAttribute("aria-invalid");
317
+ else row.field.setAttribute("aria-invalid", "true");
306
318
  };
307
319
  const finish = (outcome) => {
308
320
  const done = el("p", outcome === "declined" ? copy.declined : options.checkout === "last" ? copy.checkoutReady : copy.saved);
@@ -315,63 +327,90 @@ function mountCaptureCard(root, options) {
315
327
  form.replaceWith(done);
316
328
  options.onAnswered(outcome);
317
329
  };
318
- const answer = async (body, outcome) => {
330
+ /**
331
+ * Sends one answer per detail still open, in order, and stops at the first
332
+ * that is not taken. In a card of several details, one that closed
333
+ * meanwhile (saved from the conversation) counts as answered. The card
334
+ * finishes once every detail sent is answered, as saved when any value was
335
+ * taken by any send of this card.
336
+ */
337
+ const answer = async (bodies) => {
319
338
  if (busy) return;
320
339
  busy = true;
321
340
  send.disabled = true;
322
341
  refuse.disabled = true;
323
- let status;
324
- try {
325
- status = await options.submit(body);
326
- } catch {
327
- status = null;
342
+ let failed = null;
343
+ for (const [row, body] of bodies) {
344
+ let status;
345
+ try {
346
+ status = await options.submit(body);
347
+ } catch {
348
+ status = null;
349
+ }
350
+ if (!live) return;
351
+ const next = captureCardOutcomeOf(status);
352
+ if (next === "done" || next === "closed" && rows[1]) {
353
+ row.done = true;
354
+ if (next === "done" && "value" in body) saved = true;
355
+ } else {
356
+ failed = [row, next];
357
+ break;
358
+ }
328
359
  }
329
- if (!live) return;
330
360
  busy = false;
331
361
  send.disabled = false;
332
362
  refuse.disabled = false;
333
- const next = captureCardOutcomeOf(status);
334
- if (next === "done") {
335
- finish(outcome);
363
+ if (failed === null) {
364
+ finish(saved ? "saved" : "declined");
336
365
  return;
337
366
  }
338
- showError(next);
367
+ const [row, next] = failed;
368
+ showError(row, next);
339
369
  if (next === "closed") {
340
370
  send.disabled = true;
341
371
  refuse.disabled = true;
342
- } else field.focus();
372
+ } else row.field.focus();
343
373
  };
344
374
  const onSubmit = (event) => {
345
375
  event.preventDefault();
346
- const checked = checkCaptureCardValue({
347
- input: choices !== null ? "choice" : card.input,
348
- ...card.maxLength !== void 0 ? { maxLength: card.maxLength } : {},
349
- ...choices !== null ? { choices } : {},
350
- ...card.region ? { region: card.region } : {}
351
- }, field.value);
352
- if (!checked.ok) {
353
- showError(checked.error);
354
- field.focus();
355
- return;
376
+ const bodies = [];
377
+ for (const row of rows) {
378
+ if (row.done) continue;
379
+ const { spec, field, choices } = row;
380
+ if (row !== rows[0] && field.value.trim() === "") {
381
+ showError(row, null);
382
+ continue;
383
+ }
384
+ const checked = checkCaptureCardValue({
385
+ input: choices !== null ? "choice" : spec.input,
386
+ ...spec.maxLength !== void 0 ? { maxLength: spec.maxLength } : {},
387
+ ...choices !== null ? { choices } : {},
388
+ ...spec.region ? { region: spec.region } : {}
389
+ }, field.value);
390
+ if (!checked.ok) {
391
+ showError(row, checked.error);
392
+ field.focus();
393
+ return;
394
+ }
395
+ showError(row, null);
396
+ bodies.push([row, {
397
+ field: spec.field,
398
+ value: checked.value,
399
+ ...consent !== null && row === rows[0] ? { consent: consent.checked } : {}
400
+ }]);
356
401
  }
357
- showError(null);
358
- answer({
359
- field: card.field,
360
- value: checked.value,
361
- ...consent !== null ? { consent: consent.checked } : {}
362
- }, "saved");
402
+ answer(bodies);
363
403
  };
364
404
  const onRefuse = () => {
365
- showError(null);
366
- answer({
367
- field: card.field,
405
+ answer(rows.filter((row) => !row.done).map((row) => [row, {
406
+ field: row.spec.field,
368
407
  refused: true
369
- }, "declined");
408
+ }]));
370
409
  };
371
410
  form.addEventListener("submit", onSubmit);
372
411
  refuse.addEventListener("click", onRefuse);
373
412
  root.replaceChildren(form);
374
- if (options.autoFocus) field.focus();
413
+ if (options.autoFocus) rows[0].field.focus();
375
414
  return () => {
376
415
  live = false;
377
416
  form.removeEventListener("submit", onSubmit);
@@ -216,9 +216,8 @@ function cardText(max) {
216
216
  return string().trim().min(1).max(max).refine((text) => !hasUnsafeCardText(text), "must not contain control or format characters");
217
217
  }
218
218
  var FieldKeySchema = string().regex(CAPTURE_CARD_FIELD_PATTERN);
219
- /** The concierge asking the widget to show a card for one contact detail. */
220
- var WidgetChatCaptureCardEventSchema = object({
221
- type: literal(CAPTURE_CARD_EVENT_TYPE),
219
+ /** One detail a card asks for: its key, how it is typed in, and the tenant's wording. */
220
+ var CaptureCardFieldSchema = object({
222
221
  field: FieldKeySchema,
223
222
  input: _enum(CAPTURE_CARD_INPUTS).catch("text"),
224
223
  label: cardText(120),
@@ -226,7 +225,19 @@ var WidgetChatCaptureCardEventSchema = object({
226
225
  choices: array(cardText(120)).min(1).max(100).optional(),
227
226
  maxLength: number().int().min(1).max(CAPTURE_CARD_VALUE_MAX).optional(),
228
227
  /** A phone card only: the region a number without its country code is read in. */
229
- region: string().regex(CAPTURE_CARD_REGION_PATTERN).optional().catch(void 0),
228
+ region: string().regex(CAPTURE_CARD_REGION_PATTERN).optional().catch(void 0)
229
+ });
230
+ /**
231
+ * The concierge asking the widget to show a card for a contact detail, and,
232
+ * in `fields`, for the other details the same step still needs (SAA-512),
233
+ * answered together with one Send. Each is answered as its own
234
+ * `POST /widget/capture`. A widget built before `fields` shows the first
235
+ * detail alone, as before, and the concierge asks for the rest afterwards.
236
+ */
237
+ var WidgetChatCaptureCardEventSchema = CaptureCardFieldSchema.extend({
238
+ type: literal(CAPTURE_CARD_EVENT_TYPE),
239
+ /** More details in the same card, after the first; never the first again. */
240
+ fields: array(CaptureCardFieldSchema).min(1).max(3).optional().catch(void 0),
230
241
  /**
231
242
  * The tenant's consent wording for one outreach channel, shown beside an
232
243
  * unticked checkbox. The server keeps which wording version this is; the
@@ -379,6 +390,8 @@ var WidgetFormFillReportSchema = object({
379
390
  * shopper's cart, for a shopper who asked for it in words rather than by
380
391
  * pressing a card's button. The server never touches a cart itself — see
381
392
  * {@link WidgetChatAddToCartEventSchema} for why that is structural.
393
+ * - `variant-options` — the variants the shopper can pick, drawn as chips
394
+ * with prices (SAA-509) — {@link WidgetChatVariantOptionsEventSchema}.
382
395
  * - `capture-card` — a small form for one contact detail (`./capture.ts`).
383
396
  * - `capture-saved` — that detail was saved from the conversation while its
384
397
  * form was open; the widget closes the form as answered (`./capture.ts`).
@@ -673,6 +686,58 @@ var WidgetChatAddToCartEventSchema = object({
673
686
  type: literal("add-to-cart"),
674
687
  item: WidgetChatCardSchema
675
688
  });
689
+ /** The most variants one `variant-options` event carries — the same cap `add_to_cart` hands the model. */
690
+ var MAX_VARIANT_OPTIONS = 20;
691
+ /** The most option pairs (Size, Colour…) one variant carries. */
692
+ var MAX_VARIANT_OPTION_PAIRS = 10;
693
+ var VariantOptionTextSchema = string().trim().min(1).max(100);
694
+ /**
695
+ * One variant the shopper can pick, as a chip (SAA-509). In stock by
696
+ * construction: there is no availability field, because the owner's rule is
697
+ * that a sold-out value is never drawn or announced.
698
+ */
699
+ var WidgetChatVariantOptionSchema = object({
700
+ /** The INTERNAL catalog UUID, as on a card. */
701
+ variantId: string().min(1).max(ID_MAX),
702
+ /** The platform-native id a `'platform'`-space bridge adds by — see {@link WidgetChatCardSchema}. */
703
+ platformVariantId: string().min(1).max(ID_MAX).optional(),
704
+ /** The variant's own title: the chip label when it has no option pairs. */
705
+ title: VariantOptionTextSchema,
706
+ options: array(object({
707
+ name: VariantOptionTextSchema,
708
+ value: VariantOptionTextSchema
709
+ })).max(10),
710
+ /** ISO 4217 minor units, in the product's `currency`. */
711
+ priceMinor: number().int().min(0)
712
+ });
713
+ /**
714
+ * The concierge asking the shopper to pick a variant (SAA-509): the widget
715
+ * draws each option as a tappable chip with its price, grouped per option
716
+ * name, under the line that asks ("Which size?").
717
+ *
718
+ * Emitted by `add_to_cart` when it answers `needs_variant_choice` (several
719
+ * in-stock variants, none chosen) or `sold_out` (the shopper asked for one
720
+ * that is sold out: `variants` is then the nearest in-stock alternatives).
721
+ * Structured so the model never has to list values in prose, and so the
722
+ * price on each chip is the catalogue's integer, never a number the model
723
+ * recited.
724
+ *
725
+ * `product` is the card fields a cart line needs, minus every variant
726
+ * field: the representative variant a card is priced with is exactly what
727
+ * must not be added. A chip tap builds the cart item from `product` plus the
728
+ * chosen variant, and adds it through the same path every add takes.
729
+ */
730
+ var WidgetChatVariantOptionsEventSchema = object({
731
+ type: literal("variant-options"),
732
+ product: WidgetChatCardSchema.pick({
733
+ productId: true,
734
+ title: true,
735
+ imageUrl: true,
736
+ handle: true,
737
+ currency: true
738
+ }),
739
+ variants: array(WidgetChatVariantOptionSchema).min(1).max(20)
740
+ });
676
741
  /**
677
742
  * First AI turn after a release back to the AI — see the module doc comment.
678
743
  * Carries nothing: the widget only needs to know that it happened, and when
@@ -687,7 +752,14 @@ var WidgetChatResumedEventSchema = object({ type: literal("resumed") });
687
752
  var WidgetChatReadEventSchema = object({ type: literal("read") });
688
753
  var WidgetChatDoneEventSchema = object({
689
754
  type: literal("done"),
690
- turnId: string().min(1)
755
+ turnId: string().min(1),
756
+ /**
757
+ * The turn failed (SAA-512): what streamed before this was the failed-turn
758
+ * line (or the budget line), not a reply. For the server's own consumers
759
+ * (a text channel, a hand-back, the test console); the widget draws the line
760
+ * like any reply and ignores this.
761
+ */
762
+ failed: literal(true).optional()
691
763
  });
692
764
  var WidgetChatErrorEventSchema = object({
693
765
  type: literal("error"),
@@ -701,6 +773,7 @@ var WidgetChatSseEventSchema = discriminatedUnion("type", [
701
773
  WidgetChatEscalatedEventSchema,
702
774
  WidgetChatCheckoutEventSchema,
703
775
  WidgetChatAddToCartEventSchema,
776
+ WidgetChatVariantOptionsEventSchema,
704
777
  ...ACT_EVENT_SCHEMAS,
705
778
  WidgetChatCaptureCardEventSchema,
706
779
  WidgetChatCaptureSavedEventSchema,
@@ -723,6 +796,7 @@ var WidgetToolEventSchema = discriminatedUnion("type", [
723
796
  WidgetChatEscalatedEventSchema,
724
797
  WidgetChatCheckoutEventSchema,
725
798
  WidgetChatAddToCartEventSchema,
799
+ WidgetChatVariantOptionsEventSchema,
726
800
  ...ACT_EVENT_SCHEMAS,
727
801
  WidgetChatCaptureCardEventSchema,
728
802
  WidgetChatCaptureSavedEventSchema,
@@ -1156,4 +1230,4 @@ function parseWidgetChatCart(value) {
1156
1230
  return parsed.success ? parsed.data : null;
1157
1231
  }
1158
1232
  //#endregion
1159
- export { CART_LINE_PLATFORM_VARIANT_ID_PATTERN, CART_LINE_VARIANT_ID_PATTERN, DROPPABLE_CARD_FIELDS, MAX_CARDS_PER_EVENT, MAX_CART_LINES, WidgetCartAddFailedReportSchema, WidgetCartAddReportSchema, WidgetChatAddToCartEventSchema, WidgetChatCardSchema, WidgetChatCardsEventSchema, WidgetChatCartLineSchema, WidgetChatCartSchema, WidgetChatCartSourceSchema, WidgetChatCheckoutEventSchema, WidgetChatDoneEventSchema, WidgetChatErrorEventSchema, WidgetChatEscalatedEventSchema, WidgetChatReadEventSchema, WidgetChatReportSchema, WidgetChatResumedEventSchema, WidgetChatSseEventSchema, WidgetChatTextDeltaEventSchema, WidgetToolEventSchema, WidgetVariantChoiceRequestReportSchema, buildWidgetChatCard, buildWidgetChatCardsEvent, buildWithDroppableFields, extractWidgetToolEvent, parseWidgetChatCart, parseWidgetChatReport };
1233
+ export { CART_LINE_PLATFORM_VARIANT_ID_PATTERN, CART_LINE_VARIANT_ID_PATTERN, DROPPABLE_CARD_FIELDS, MAX_CARDS_PER_EVENT, MAX_CART_LINES, MAX_VARIANT_OPTIONS, MAX_VARIANT_OPTION_PAIRS, WidgetCartAddFailedReportSchema, WidgetCartAddReportSchema, WidgetChatAddToCartEventSchema, WidgetChatCardSchema, WidgetChatCardsEventSchema, WidgetChatCartLineSchema, WidgetChatCartSchema, WidgetChatCartSourceSchema, WidgetChatCheckoutEventSchema, WidgetChatDoneEventSchema, WidgetChatErrorEventSchema, WidgetChatEscalatedEventSchema, WidgetChatReadEventSchema, WidgetChatReportSchema, WidgetChatResumedEventSchema, WidgetChatSseEventSchema, WidgetChatTextDeltaEventSchema, WidgetChatVariantOptionSchema, WidgetChatVariantOptionsEventSchema, WidgetToolEventSchema, WidgetVariantChoiceRequestReportSchema, buildWidgetChatCard, buildWidgetChatCardsEvent, buildWithDroppableFields, extractWidgetToolEvent, parseWidgetChatCart, parseWidgetChatReport };