@saar-ai/web-widget 0.22.0 → 0.23.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.
@@ -379,6 +379,8 @@ var WidgetFormFillReportSchema = object({
379
379
  * shopper's cart, for a shopper who asked for it in words rather than by
380
380
  * pressing a card's button. The server never touches a cart itself — see
381
381
  * {@link WidgetChatAddToCartEventSchema} for why that is structural.
382
+ * - `variant-options` — the variants the shopper can pick, drawn as chips
383
+ * with prices (SAA-509) — {@link WidgetChatVariantOptionsEventSchema}.
382
384
  * - `capture-card` — a small form for one contact detail (`./capture.ts`).
383
385
  * - `capture-saved` — that detail was saved from the conversation while its
384
386
  * form was open; the widget closes the form as answered (`./capture.ts`).
@@ -673,6 +675,58 @@ var WidgetChatAddToCartEventSchema = object({
673
675
  type: literal("add-to-cart"),
674
676
  item: WidgetChatCardSchema
675
677
  });
678
+ /** The most variants one `variant-options` event carries — the same cap `add_to_cart` hands the model. */
679
+ var MAX_VARIANT_OPTIONS = 20;
680
+ /** The most option pairs (Size, Colour…) one variant carries. */
681
+ var MAX_VARIANT_OPTION_PAIRS = 10;
682
+ var VariantOptionTextSchema = string().trim().min(1).max(100);
683
+ /**
684
+ * One variant the shopper can pick, as a chip (SAA-509). In stock by
685
+ * construction: there is no availability field, because the owner's rule is
686
+ * that a sold-out value is never drawn or announced.
687
+ */
688
+ var WidgetChatVariantOptionSchema = object({
689
+ /** The INTERNAL catalog UUID, as on a card. */
690
+ variantId: string().min(1).max(ID_MAX),
691
+ /** The platform-native id a `'platform'`-space bridge adds by — see {@link WidgetChatCardSchema}. */
692
+ platformVariantId: string().min(1).max(ID_MAX).optional(),
693
+ /** The variant's own title: the chip label when it has no option pairs. */
694
+ title: VariantOptionTextSchema,
695
+ options: array(object({
696
+ name: VariantOptionTextSchema,
697
+ value: VariantOptionTextSchema
698
+ })).max(10),
699
+ /** ISO 4217 minor units, in the product's `currency`. */
700
+ priceMinor: number().int().min(0)
701
+ });
702
+ /**
703
+ * The concierge asking the shopper to pick a variant (SAA-509): the widget
704
+ * draws each option as a tappable chip with its price, grouped per option
705
+ * name, under the line that asks ("Which size?").
706
+ *
707
+ * Emitted by `add_to_cart` when it answers `needs_variant_choice` (several
708
+ * in-stock variants, none chosen) or `sold_out` (the shopper asked for one
709
+ * that is sold out: `variants` is then the nearest in-stock alternatives).
710
+ * Structured so the model never has to list values in prose, and so the
711
+ * price on each chip is the catalogue's integer, never a number the model
712
+ * recited.
713
+ *
714
+ * `product` is the card fields a cart line needs, minus every variant
715
+ * field: the representative variant a card is priced with is exactly what
716
+ * must not be added. A chip tap builds the cart item from `product` plus the
717
+ * chosen variant, and adds it through the same path every add takes.
718
+ */
719
+ var WidgetChatVariantOptionsEventSchema = object({
720
+ type: literal("variant-options"),
721
+ product: WidgetChatCardSchema.pick({
722
+ productId: true,
723
+ title: true,
724
+ imageUrl: true,
725
+ handle: true,
726
+ currency: true
727
+ }),
728
+ variants: array(WidgetChatVariantOptionSchema).min(1).max(20)
729
+ });
676
730
  /**
677
731
  * First AI turn after a release back to the AI — see the module doc comment.
678
732
  * Carries nothing: the widget only needs to know that it happened, and when
@@ -701,6 +755,7 @@ var WidgetChatSseEventSchema = discriminatedUnion("type", [
701
755
  WidgetChatEscalatedEventSchema,
702
756
  WidgetChatCheckoutEventSchema,
703
757
  WidgetChatAddToCartEventSchema,
758
+ WidgetChatVariantOptionsEventSchema,
704
759
  ...ACT_EVENT_SCHEMAS,
705
760
  WidgetChatCaptureCardEventSchema,
706
761
  WidgetChatCaptureSavedEventSchema,
@@ -723,6 +778,7 @@ var WidgetToolEventSchema = discriminatedUnion("type", [
723
778
  WidgetChatEscalatedEventSchema,
724
779
  WidgetChatCheckoutEventSchema,
725
780
  WidgetChatAddToCartEventSchema,
781
+ WidgetChatVariantOptionsEventSchema,
726
782
  ...ACT_EVENT_SCHEMAS,
727
783
  WidgetChatCaptureCardEventSchema,
728
784
  WidgetChatCaptureSavedEventSchema,
@@ -1156,4 +1212,4 @@ function parseWidgetChatCart(value) {
1156
1212
  return parsed.success ? parsed.data : null;
1157
1213
  }
1158
1214
  //#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 };
1215
+ 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 };
@@ -4681,6 +4681,9 @@ var defaultWidgetMessages = {
4681
4681
  choose_options: "Choose options",
4682
4682
  choose_options_label: "Choose options for {title}",
4683
4683
  choose_options_after_call: "I’ll ask about options after the call",
4684
+ options_label: "Choose {option} for {title}",
4685
+ options_price_from: "from {price}",
4686
+ options_added: "Added to cart",
4684
4687
  cards_label: "Recommended products",
4685
4688
  cards_slide: "{n} of {total}",
4686
4689
  cards_prev: "Previous products",
@@ -8451,7 +8454,7 @@ var DEFAULT_LAYOUT = {
8451
8454
  };
8452
8455
  var INTERRUPT_SEEN_STORAGE_KEY = "wgt_dock_interrupt_seen";
8453
8456
  function Dock(props) {
8454
- const { identity, color = DEFAULT_COLOR$1, type = DEFAULT_TYPE$1, layout = DEFAULT_LAYOUT, copy = {}, direction = "ltr", locale = "en", messages = defaultWidgetMessages, voice, escalated = false, offline = false, status, notice, statusKind, operatorLine, operatorName, reconnecting = false, roomDropped = false, partialTranscript, preamble, clause, channel = "text", shelf, transcript, transcriptCount, lastTurn, composing = false, unread = false, sheetExtra, followKey, revealSheet = false, showPrice = true, cardImageAspect = DEFAULT_CARD_ASPECT, bottomOffset = "auto", curationHref, productHref, navigate, draft, onDraftChange, onSubmit, composerDisabled = false, onAttach, attachSlot, attachBusy, proactive, pageKey, conciergeScrollRef, onEndCall, skinStyle, skin, preview = false, announcement, attribution, privacyChoices, initialDraft, initialSelection, initialFocus, initialMinimised, insets, hold, audio, onReady, onShown } = props;
8457
+ const { identity, color = DEFAULT_COLOR$1, type = DEFAULT_TYPE$1, layout = DEFAULT_LAYOUT, copy = {}, direction = "ltr", locale = "en", messages = defaultWidgetMessages, voice, escalated = false, offline = false, status, notice, statusKind, operatorLine, operatorName, reconnecting = false, roomDropped = false, partialTranscript, preamble, clause, channel = "text", shelf, transcript, transcriptCount, lastTurn, composing = false, unread = false, sheetExtra, voiceShelfExtra, followKey, revealSheet = false, showPrice = true, cardImageAspect = DEFAULT_CARD_ASPECT, bottomOffset = "auto", curationHref, productHref, navigate, draft, onDraftChange, onSubmit, composerDisabled = false, onAttach, attachSlot, attachBusy, proactive, pageKey, conciergeScrollRef, onEndCall, skinStyle, skin, preview = false, announcement, attribution, privacyChoices, initialDraft, initialSelection, initialFocus, initialMinimised, insets, hold, audio, onReady, onShown } = props;
8455
8458
  const scopeId = useId().replace(/[^a-zA-Z0-9_-]/g, "");
8456
8459
  const rootRef = useRef(null);
8457
8460
  const rowRef = useRef(null);
@@ -9467,6 +9470,7 @@ function Dock(props) {
9467
9470
  ...productHref ? { productHref } : {},
9468
9471
  ...navigate ? { navigate } : {}
9469
9472
  }) : null,
9473
+ channel === "voice" && !showTranscript ? voiceShelfExtra : null,
9470
9474
  channel === "text" || showTranscript ? transcript : null,
9471
9475
  sheetExtra,
9472
9476
  attribution !== void 0 ? /* @__PURE__ */ jsx("a", {
@@ -11739,7 +11743,7 @@ function callMarkState(state, bot, ended, muted) {
11739
11743
  * labelled controls; then the summary once it ends. Styled by
11740
11744
  * `styles/call-view.css` (`.wgc`). See docs/CONCIERGE_GENERATIONS.md "Call mode".
11741
11745
  */
11742
- function CallView({ state, callerSpeaking = false, turns, renderCards, suggestions, choices, extras, onSay, checkout = false, cart, messages, locale, voice, name, title, actions, record, bot, avatar, hint, onText, onBackToChat, testIds }) {
11746
+ function CallView({ state, callerSpeaking = false, turns, renderCards, renderOptions, suggestions, choices, extras, onSay, checkout = false, cart, messages, locale, voice, name, title, actions, record, bot, avatar, hint, onText, onBackToChat, testIds }) {
11743
11747
  const t = (key) => callText(messages, key);
11744
11748
  const ended = !record.active;
11745
11749
  const { word, explain } = callStatus(state, {
@@ -11747,7 +11751,7 @@ function CallView({ state, callerSpeaking = false, turns, renderCards, suggestio
11747
11751
  callerSpeaking
11748
11752
  });
11749
11753
  const [said, setSaid] = useState([]);
11750
- const shown = turns.slice(record.from).filter((turn, i, all) => turn.speaker === "event" ? false : turn.filler ? i === all.length - 1 : turn.text.trim() !== "" || (turn.cards?.items.length ?? 0) > 0);
11754
+ const shown = turns.slice(record.from).filter((turn, i, all) => turn.speaker === "event" ? false : turn.filler ? i === all.length - 1 : turn.text.trim() !== "" || (turn.cards?.items.length ?? 0) > 0 || turn.options !== void 0);
11751
11755
  const last = shown[shown.length - 1];
11752
11756
  const pending = ended ? null : state === "thinking" && !(last?.speaker === "agent" && last.final === false) ? "agent" : callerSpeaking && !(last?.speaker === "caller" && last.final === false) ? "caller" : null;
11753
11757
  const streamRef = useRef(null);
@@ -11878,6 +11882,10 @@ function CallView({ state, callerSpeaking = false, turns, renderCards, suggestio
11878
11882
  !you && turn.cards && turn.cards.items.length > 0 ? /* @__PURE__ */ jsx("div", {
11879
11883
  className: "wgc-cards",
11880
11884
  children: renderCards(turn.cards)
11885
+ }) : null,
11886
+ !you && turn.options && renderOptions ? /* @__PURE__ */ jsx("div", {
11887
+ className: "wgc-cards",
11888
+ children: renderOptions(turn.options)
11881
11889
  }) : null
11882
11890
  ]
11883
11891
  }, i);
@@ -12633,7 +12641,7 @@ function positionFor(dock) {
12633
12641
  const align = dock?.layout?.desktopAlign;
12634
12642
  return align === "left" || align === "right" ? `bottom-${align}` : DEFAULT_CONCIERGE_POSITION;
12635
12643
  }
12636
- function ShellRenderer({ turns, showMic, callPhase, micOpen, onToggleMic, onEndCall, statusKind, statusLine, escalated, operatorName, humanTyping, composing, replyStreaming, channel, draft, onDraftChange, submit, attaching, onAttach, attachInput, transcript, extras, messages, skinStyle, avatar, attribution, privacyChoices, voice: derivedVoice, renderCards, suggestions, call: callHooks, cart, capturing, showBasket, captureChoices, dock, locale }) {
12644
+ function ShellRenderer({ turns, showMic, callPhase, micOpen, onToggleMic, onEndCall, statusKind, statusLine, escalated, operatorName, humanTyping, composing, replyStreaming, channel, draft, onDraftChange, submit, attaching, onAttach, attachInput, transcript, extras, messages, skinStyle, avatar, attribution, privacyChoices, voice: derivedVoice, renderCards, renderOptions, suggestions, call: callHooks, cart, capturing, showBasket, captureChoices, dock, locale }) {
12637
12645
  const [restored] = useState(readOpen);
12638
12646
  const [open, setOpen] = useState(dock?.initialMinimised === false || restored);
12639
12647
  const onShown = dock?.onShown;
@@ -12841,6 +12849,7 @@ function ShellRenderer({ turns, showMic, callPhase, micOpen, onToggleMic, onEndC
12841
12849
  callerSpeaking: voiceInput.callerSpeaking === true,
12842
12850
  turns,
12843
12851
  renderCards,
12852
+ renderOptions,
12844
12853
  suggestions,
12845
12854
  choices: captureChoices,
12846
12855
  ...capturing || attaching !== null || showBasket && (cart?.lines.length ?? 0) > 0 ? { extras } : {},
@@ -12884,7 +12893,9 @@ function ShellRenderer({ turns, showMic, callPhase, micOpen, onToggleMic, onEndC
12884
12893
  * Imported by `cdn/ui.ts` and by `rendererFor`; never by `voice-widget.tsx`,
12885
12894
  * so a bundle built around the OTHER renderer does not carry this one.
12886
12895
  */
12887
- function DockRenderer({ turns, lastTurn, operatorName, composing, onEndCall, voice, statusLine, statusKind, notice, escalated, humanTyping, draft, onDraftChange, submit, showBasket, cart, attaching, capturing, onAttach, attachInput, transcript, extras, messages, locale, navigate, curationHref, productHref, skinStyle, avatar, attribution, privacyChoices, dock }) {
12896
+ function DockRenderer({ turns, lastTurn, operatorName, composing, onEndCall, voice, statusLine, statusKind, notice, escalated, humanTyping, draft, onDraftChange, submit, showBasket, cart, attaching, capturing, onAttach, attachInput, transcript, renderOptions, extras, messages, locale, navigate, curationHref, productHref, skinStyle, avatar, attribution, privacyChoices, dock }) {
12897
+ const asked = turns.findLastIndex((turn) => turn.options !== void 0);
12898
+ const openOptions = asked >= 0 && !turns.slice(asked + 1).some((turn) => turn.speaker === "caller") ? turns[asked]?.options : void 0;
12888
12899
  return /* @__PURE__ */ jsx(Dock, {
12889
12900
  identity: {
12890
12901
  name: "",
@@ -12912,12 +12923,13 @@ function DockRenderer({ turns, lastTurn, operatorName, composing, onEndCall, voi
12912
12923
  draft,
12913
12924
  onDraftChange,
12914
12925
  onSubmit: submit,
12915
- revealSheet: showBasket && cart !== void 0 && cart.lines.length > 0 || attaching !== null || capturing,
12916
- followKey: turns.reduce((n, turn) => n + 1 + turn.text.length + (turn.cards?.items.length ?? 0), 0) + (humanTyping ? 1 : 0),
12926
+ revealSheet: showBasket && cart !== void 0 && cart.lines.length > 0 || attaching !== null || capturing || openOptions !== void 0,
12927
+ followKey: turns.reduce((n, turn) => n + 1 + turn.text.length + (turn.cards?.items.length ?? 0) + (turn.options ? 1 : 0), 0) + (humanTyping ? 1 : 0),
12917
12928
  ...onAttach ? { onAttach } : {},
12918
12929
  attachBusy: attaching !== null && !attaching.failed,
12919
12930
  ...attachInput !== null ? { attachSlot: attachInput } : {},
12920
12931
  sheetExtra: extras,
12932
+ ...openOptions ? { voiceShelfExtra: renderOptions(openOptions) } : {},
12921
12933
  transcript,
12922
12934
  transcriptCount: turns.length,
12923
12935
  ...lastTurn !== void 0 ? { lastTurn } : {},
@@ -13266,6 +13278,170 @@ function WidgetCardList({ cards, onAddToCart, onChooseOptions, chooseOptionsBusy
13266
13278
  });
13267
13279
  }
13268
13280
  //#endregion
13281
+ //#region src/variant-option-groups.ts
13282
+ var valueOf = (variant, name) => name === "" ? variant.title : variant.options.find((o) => o.name === name)?.value;
13283
+ var fits = (variant, selected, skip) => Object.keys(selected).every((n) => n === skip || valueOf(variant, n) === selected[n]);
13284
+ /**
13285
+ * The option names the chips are grouped by, in the first variant's order:
13286
+ * only names every variant carries and whose value varies. Variants that do
13287
+ * not share one set of names (or have none) are one group of titles, so every
13288
+ * variant is still a chip.
13289
+ */
13290
+ function optionNames(variants) {
13291
+ const names = [...new Set(variants[0]?.options.map((o) => o.name))].filter((n) => variants.every((v) => v.options.length === variants[0]?.options.length && valueOf(v, n)) && new Set(variants.map((v) => valueOf(v, n))).size > 1);
13292
+ return names.length > 0 ? names : [""];
13293
+ }
13294
+ /**
13295
+ * The chips for the current selection. Each group offers the values still
13296
+ * reachable from the choices made in the groups BEFORE it, so a later group
13297
+ * never offers a combination that does not exist; each chip is priced against
13298
+ * every other choice that still fits it.
13299
+ */
13300
+ function optionGroups(variants, selected) {
13301
+ const names = optionNames(variants);
13302
+ return names.map((name, g) => {
13303
+ const earlier = Object.fromEntries(names.slice(0, g).flatMap((n) => selected[n] === void 0 ? [] : [[n, selected[n]]]));
13304
+ const reachable = variants.filter((v) => fits(v, earlier));
13305
+ return {
13306
+ name,
13307
+ chips: [...new Set(reachable.map((v) => valueOf(v, name)))].map((value) => {
13308
+ const withValue = reachable.filter((v) => valueOf(v, name) === value);
13309
+ const fitting = withValue.filter((v) => fits(v, selected, name));
13310
+ const prices = (fitting.length > 0 ? fitting : withValue).map((v) => v.priceMinor);
13311
+ const priceMinor = Math.min(...prices);
13312
+ return {
13313
+ value,
13314
+ priceMinor,
13315
+ from: prices.some((p) => p !== priceMinor)
13316
+ };
13317
+ })
13318
+ };
13319
+ });
13320
+ }
13321
+ /**
13322
+ * The selection after a tap: that value in that group, every other choice
13323
+ * kept only while some variant still has all of them.
13324
+ */
13325
+ function selectOption(variants, selected, name, value) {
13326
+ const next = { [name]: value };
13327
+ for (const n of optionNames(variants)) {
13328
+ const kept = selected[n];
13329
+ if (n === name || kept === void 0) continue;
13330
+ if (variants.some((v) => fits(v, {
13331
+ ...next,
13332
+ [n]: kept
13333
+ }))) next[n] = kept;
13334
+ }
13335
+ return next;
13336
+ }
13337
+ /** The one variant a complete selection names, or `undefined` while any group is unchosen. */
13338
+ function resolvedVariant(variants, selected) {
13339
+ return optionNames(variants).every((n) => selected[n] !== void 0) ? variants.find((v) => fits(v, selected)) : void 0;
13340
+ }
13341
+ /**
13342
+ * The cart item a chosen variant adds: the product's display fields plus THIS
13343
+ * variant's ids and price. The same shape a card's Add button hands
13344
+ * `resolveAddToCartHandler`, so a chip adds through the one add path.
13345
+ */
13346
+ function cartItemFor({ product }, { variantId, platformVariantId, priceMinor }) {
13347
+ return {
13348
+ ...product,
13349
+ variantId,
13350
+ ...platformVariantId !== void 0 ? { platformVariantId } : {},
13351
+ priceMinor,
13352
+ available: true
13353
+ };
13354
+ }
13355
+ //#endregion
13356
+ //#region src/variant-options.tsx
13357
+ /**
13358
+ * SAA-509 — the variant choice as tappable chips under the line that asks
13359
+ * for it ("Which size?"): one row per option (Size, Colour…), each chip a
13360
+ * value and its price. Only in-stock variants reach it, so there is no
13361
+ * sold-out state to draw.
13362
+ *
13363
+ * A tap that completes the choice adds that variant through `onAddToCart`,
13364
+ * the one path every add takes, and the concierge hears of it through the
13365
+ * `cart_add` report that path sends; on a call it is said instead (`onSay`).
13366
+ * A tap that leaves an option unchosen narrows the next row; after an add the
13367
+ * next tap starts a fresh choice, and a tap on the added chip does nothing.
13368
+ * Chips are `aria-pressed` toggles in labelled groups, and stay focusable
13369
+ * while inert (`aria-disabled`, as card buttons do).
13370
+ */
13371
+ function VariantOptionChips({ options, onAddToCart, messages, locale, showPrice = true, onSay, busy = false }) {
13372
+ const [selected, setSelected] = useState({});
13373
+ const [adding, setAdding] = useState(false);
13374
+ const [added, setAdded] = useState([]);
13375
+ const addingRef = useRef(false);
13376
+ const { variants, product } = options;
13377
+ const chosen = resolvedVariant(variants, selected);
13378
+ const text = (key) => messages[key] ?? defaultWidgetMessages[key];
13379
+ const inert = !onAddToCart && !onSay || adding || busy;
13380
+ const pick = async (name, value) => {
13381
+ if (inert || addingRef.current) return;
13382
+ const done = chosen !== void 0 && added.includes(chosen.variantId);
13383
+ if (done && selected[name] === value) return;
13384
+ const next = selectOption(variants, done ? {} : selected, name, value);
13385
+ setSelected(next);
13386
+ const variant = resolvedVariant(variants, next);
13387
+ if (!variant) return;
13388
+ addingRef.current = true;
13389
+ setAdding(true);
13390
+ try {
13391
+ if (onSay) await onSay([product.title, ...Object.values(next)].join(", "));
13392
+ else {
13393
+ await onAddToCart?.(cartItemFor(options, variant));
13394
+ setAdded((prev) => [...prev, variant.variantId]);
13395
+ }
13396
+ } catch {} finally {
13397
+ addingRef.current = false;
13398
+ setAdding(false);
13399
+ }
13400
+ };
13401
+ const groups = optionGroups(variants, selected);
13402
+ return /* @__PURE__ */ jsx("div", {
13403
+ "data-testid": "widget-variant-options",
13404
+ className: "flex w-full flex-col gap-2 pt-1",
13405
+ children: groups.map((group) => /* @__PURE__ */ jsxs("div", {
13406
+ role: "group",
13407
+ "aria-label": formatMessage(text("options_label"), {
13408
+ option: group.name || product.title,
13409
+ title: product.title
13410
+ }),
13411
+ children: [groups.length > 1 ? /* @__PURE__ */ jsx("p", {
13412
+ "aria-hidden": "true",
13413
+ className: "px-1 pb-1 text-[11px] font-medium text-[var(--widget-foreground-muted)]",
13414
+ children: group.name
13415
+ }) : null, /* @__PURE__ */ jsx("ul", {
13416
+ className: "flex flex-wrap gap-1.5",
13417
+ children: group.chips.map((chip) => {
13418
+ const pressed = selected[group.name] === chip.value;
13419
+ const done = pressed && chosen !== void 0 && added.includes(chosen.variantId);
13420
+ const price = formatMoney(chip.priceMinor, product.currency, locale);
13421
+ return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("button", {
13422
+ type: "button",
13423
+ "data-testid": "widget-variant-option",
13424
+ "data-phase": pressed && adding ? "adding" : done ? "added" : "idle",
13425
+ "aria-pressed": pressed,
13426
+ "aria-disabled": inert,
13427
+ onClick: () => void pick(group.name, chip.value),
13428
+ className: "cursor-pointer rounded-full bg-[var(--widget-chip)] px-3 py-1.5 text-xs font-medium text-[var(--widget-foreground)] ring-1 ring-black/10 transition-colors hover:bg-[var(--widget-accent)] hover:text-[var(--widget-accent-foreground)] focus-visible:ring-2 focus-visible:ring-[var(--widget-accent-ring)] focus-visible:outline-none aria-disabled:cursor-default aria-pressed:bg-[var(--widget-accent)] aria-pressed:text-[var(--widget-accent-foreground)]",
13429
+ children: [
13430
+ done ? "✓ " : "",
13431
+ /* @__PURE__ */ jsx("bdi", { children: chip.value }),
13432
+ showPrice ? ` · ${chip.from ? formatMessage(text("options_price_from"), { price }) : price}` : "",
13433
+ done ? /* @__PURE__ */ jsxs("span", {
13434
+ className: "sr-only",
13435
+ children: [" ", text("options_added")]
13436
+ }) : null
13437
+ ]
13438
+ }) }, chip.value);
13439
+ })
13440
+ })]
13441
+ }, group.name))
13442
+ });
13443
+ }
13444
+ //#endregion
13269
13445
  //#region src/widget-cart-summary.tsx
13270
13446
  /**
13271
13447
  * The basket, inside the conversation.
@@ -13826,6 +14002,16 @@ function VoiceWidgetWithRenderer({ renderer, state, turns, onToggleMic, onEndCal
13826
14002
  ...dock?.showPrice !== void 0 ? { showPrice: dock.showPrice } : {},
13827
14003
  ...dock?.cardImageAspect !== void 0 ? { imageAspect: dock.cardImageAspect } : {}
13828
14004
  });
14005
+ const sayOnCall = (callPhase === "live" || callPhase === "waiting") && call?.sendText ? call.sendText : void 0;
14006
+ const renderOptions = (options) => /* @__PURE__ */ jsx(VariantOptionChips, {
14007
+ options,
14008
+ ...onAddToCart ? { onAddToCart } : {},
14009
+ ...sayOnCall ? { onSay: sayOnCall } : {},
14010
+ busy: chooseOptionsBusy,
14011
+ messages,
14012
+ locale,
14013
+ ...dock?.showPrice !== void 0 ? { showPrice: dock.showPrice } : {}
14014
+ }, `${options.product.productId}:${options.variants.map((v) => v.variantId).join()}`);
13829
14015
  const openers = suggestions ?? SUGGESTION_KEYS.map((key) => messages[key]);
13830
14016
  const renderLog = (shown) => /* @__PURE__ */ jsxs("div", {
13831
14017
  role: "log",
@@ -13874,6 +14060,10 @@ function VoiceWidgetWithRenderer({ renderer, state, turns, onToggleMic, onEndCal
13874
14060
  className: "w-full",
13875
14061
  children: renderCards(turn.cards)
13876
14062
  }) : null,
14063
+ turn.options ? /* @__PURE__ */ jsx("div", {
14064
+ className: "w-full",
14065
+ children: renderOptions(turn.options)
14066
+ }) : null,
13877
14067
  turn.delivery !== void 0 ? /* @__PURE__ */ jsx(TurnDeliveryStatus, {
13878
14068
  delivery: turn.delivery,
13879
14069
  messages
@@ -14044,6 +14234,7 @@ function VoiceWidgetWithRenderer({ renderer, state, turns, onToggleMic, onEndCal
14044
14234
  attachInput,
14045
14235
  transcript: renderLog(turns),
14046
14236
  renderCards,
14237
+ renderOptions,
14047
14238
  suggestions: openers,
14048
14239
  call,
14049
14240
  extras,
@@ -16882,6 +17073,21 @@ async function streamReply(args) {
16882
17073
  onCardsEvent(cardsEvent);
16883
17074
  break;
16884
17075
  }
17076
+ case "variant-options": {
17077
+ const data = evt.data;
17078
+ const product = data?.product;
17079
+ if (!product || typeof product.title !== "string" || typeof product.currency !== "string") break;
17080
+ if (!Array.isArray(data.variants) || data.variants.length === 0) break;
17081
+ const options = {
17082
+ product,
17083
+ variants: data.variants
17084
+ };
17085
+ setTurns((prev) => prev.map((t) => t.id === agentTurnId ? {
17086
+ ...t,
17087
+ options
17088
+ } : t));
17089
+ break;
17090
+ }
16885
17091
  case "checkout": {
16886
17092
  const data = evt.data;
16887
17093
  if (!data?.handoffId || !data.url || !data.itemCount) break;
@@ -17066,7 +17272,7 @@ function callStartStamp(spoken, others) {
17066
17272
  * cache makes a second `start()` after `stop()` free).
17067
17273
  */
17068
17274
  async function loadVoiceProtocol() {
17069
- const [telemetry, chat] = await Promise.all([import("./telemetry-ZeV7hBI7.js"), import("./chat-DrpWeT5w.js")]);
17275
+ const [telemetry, chat] = await Promise.all([import("./telemetry-ZeV7hBI7.js"), import("./chat-BBmFAzkg.js")]);
17070
17276
  return {
17071
17277
  decodeTelemetry: telemetry.decodeTelemetry,
17072
17278
  encodeCallerText: telemetry.encodeCallerText,
@@ -20358,6 +20564,7 @@ function ConciergeHost({ renderer, embedKey, apiBase, socketUrl, socketPath, bri
20358
20564
  ...turn.delivery ? { delivery: turn.delivery } : {},
20359
20565
  ...turn.shared ? { shared: turn.shared } : {},
20360
20566
  ...turn.cards ? { cards: turn.cards } : {},
20567
+ ...turn.options ? { options: turn.options } : {},
20361
20568
  ...turn.attachments ? { attachments: turn.attachments } : {},
20362
20569
  ...turn.operatorName ? { operatorName: turn.operatorName } : {}
20363
20570
  });
@@ -20443,14 +20650,32 @@ function ConciergeHost({ renderer, embedKey, apiBase, socketUrl, socketPath, bri
20443
20650
  existing.items.push(...event.items);
20444
20651
  if (existing.curationId !== event.curationId) delete existing.curationId;
20445
20652
  }
20653
+ const optionsByTurn = /* @__PURE__ */ new Map();
20654
+ const unboundOptions = [];
20655
+ for (const event of voice.widgetEvents) {
20656
+ if (event.type !== "variant-options") continue;
20657
+ const entry = {
20658
+ stamp: order.stampEvent(event),
20659
+ options: {
20660
+ product: event.product,
20661
+ variants: event.variants
20662
+ }
20663
+ };
20664
+ if (event.turnId === void 0) unboundOptions.push(entry);
20665
+ else optionsByTurn.set(event.turnId, {
20666
+ ...entry,
20667
+ stamp: optionsByTurn.get(event.turnId)?.stamp ?? entry.stamp
20668
+ });
20669
+ }
20446
20670
  const anchors = /* @__PURE__ */ new Map();
20447
20671
  for (const { line, i } of visible) {
20448
20672
  const turnId = line.turnId;
20449
20673
  if (line.speaker !== "agent" || line.filler === true || turnId === void 0) continue;
20450
- if (!byTurn.has(turnId) || anchors.has(turnId)) continue;
20674
+ if (!byTurn.has(turnId) && !optionsByTurn.has(turnId) || anchors.has(turnId)) continue;
20451
20675
  anchors.set(turnId, i);
20452
20676
  }
20453
20677
  const orphaned = [...unbound, ...[...byTurn].filter(([turnId]) => !anchors.has(turnId)).map(([, cards]) => cards)];
20678
+ const orphanedOptions = [...unboundOptions, ...[...optionsByTurn].filter(([turnId]) => !anchors.has(turnId)).map(([, o]) => o)];
20454
20679
  /**
20455
20680
  * ── Why the bound row simply keeps the LINE's stamp ───────────────────
20456
20681
  *
@@ -20488,7 +20713,9 @@ function ConciergeHost({ renderer, embedKey, apiBase, socketUrl, socketPath, bri
20488
20713
  */
20489
20714
  const spoken = visible.map(({ line, i }) => {
20490
20715
  const turnId = line.turnId;
20491
- const bound = turnId !== void 0 && anchors.get(turnId) === i ? byTurn.get(turnId) : void 0;
20716
+ const anchored = turnId !== void 0 && anchors.get(turnId) === i;
20717
+ const bound = anchored ? byTurn.get(turnId) : void 0;
20718
+ const boundOptions = anchored ? optionsByTurn.get(turnId)?.options : void 0;
20492
20719
  return {
20493
20720
  stamp: spokenStamps[i],
20494
20721
  turn: {
@@ -20501,7 +20728,8 @@ function ConciergeHost({ renderer, embedKey, apiBase, socketUrl, socketPath, bri
20501
20728
  ...bound === void 0 ? {} : { cards: {
20502
20729
  ...bound.curationId !== void 0 ? { curationId: bound.curationId } : {},
20503
20730
  items: bound.items
20504
- } }
20731
+ } },
20732
+ ...boundOptions === void 0 ? {} : { options: boundOptions }
20505
20733
  }
20506
20734
  };
20507
20735
  });
@@ -20518,12 +20746,27 @@ function ConciergeHost({ renderer, embedKey, apiBase, socketUrl, socketPath, bri
20518
20746
  }
20519
20747
  }
20520
20748
  }));
20749
+ const renderedOptions = orphanedOptions.map(({ stamp, options }) => ({
20750
+ stamp,
20751
+ turn: {
20752
+ speaker: "agent",
20753
+ text: "",
20754
+ locale,
20755
+ final: true,
20756
+ options
20757
+ }
20758
+ }));
20521
20759
  const callStart = callStartStamp(spoken, [
20522
20760
  ...typed,
20523
20761
  ...rendered,
20762
+ ...renderedOptions,
20524
20763
  ...past.rows
20525
20764
  ]);
20526
- const rows = [...spoken, ...rendered];
20765
+ const rows = [
20766
+ ...spoken,
20767
+ ...rendered,
20768
+ ...renderedOptions
20769
+ ];
20527
20770
  if (callStart !== null) rows.push({
20528
20771
  stamp: callStart,
20529
20772
  turn: {
@@ -20973,4 +21216,4 @@ function ConciergeHost({ renderer, embedKey, apiBase, socketUrl, socketPath, bri
20973
21216
  });
20974
21217
  }
20975
21218
  //#endregion
20976
- export { botStateFor as $, rowWidthLen as $t, DockRenderer as A, resolveWidgetMessages as An, MOBILE_MARGIN as At, ConciergeLauncher as B, RopeKnot as Bn, SHEET_TOP_CLEARANCE as Bt, VoiceWidgetWithRenderer as C, parseHex as Cn, DOCK_MINIMISED_STORAGE_KEY as Ct, WidgetCartSummary as D, withAlpha as Dn, FLOAT_GAP as Dt, readsAsCheckoutIntent as E, srgbToLinear as En, FLOAT_DUCK_DISMISS_MS as Et, IDLE_CALL_RECORD as F, WIDGET_AVATARS as Fn, ROW_H as Ft, nearestPosition as G, containerAnchor as Gt, DEFAULT_CONCIERGE_POSITION as H, labelProps as Hn, SHORT_VIEWPORT as Ht, WidgetMarkdown as I, WIDGET_IDENTITY_AVATARS as In, SHEET_EXPANDED_DESKTOP_MAX as It, positionForArrow as J, persistMinimised as Jt, panelClasses as K, geometryVars as Kt, parseBlocks as L, dockAvatarFor as Ln, SHEET_EXPANDED_VH as Lt, deriveWidgetView as M, MorphingLoader as Mn, PILL_MARK as Mt, ConciergeShell as N, DEFAULT_WIDGET_AVATAR as Nn, PROACTIVE_NUDGE_MS as Nt, WidgetCardList as O, defaultWidgetMessages as On, GLASS_IDLE_MS as Ot, CallView as P, MARK_VARIANTS as Pn, RADII$1 as Pt, IDLE_SNAPSHOT as Q, readStoredMinimised as Qt, stripBidiControls as R, isWidgetAvatar as Rn, SHEET_GAP as Rt, VoiceWidget as S, oklchToOklab as Sn, DOCK_ALIGN_STORAGE_KEY as St, readsAsCartViewIntent as T, rotateHue as Tn, DRAG_TAP_SLOP_PX as Tt, alignOf as U, cn as Un, Z_INDEX as Ut, CONCIERGE_POSITIONS as V, BotFace as Vn, SHEET_TUCK as Vt, edgeOf as W, bottomLen as Wt, MARK_STATES as X, readStored as Xt, LAUNCHER_VARIANTS as Y, pillAnchor as Yt, Mark as Z, readStoredAlign as Zt, useVoiceSession as _, mixToward as _n, CONTROL as _t, MAX_REPORTED_CART_LINES as a, SYSTEM_FONT_STACK as an, Dock as at, useChatSession as b, oklabToOklch as bn, DESKTOP_GUTTER as bt, deriveCallPhase as c, themeToCss as cn, deriveDockView as ct, resolveCheckoutUrl as d, contrastRatio as dn, deriveConciergeState as dt, sheetMaxHeightLen as en, SseFrameParser as et, toChatCart as f, formatHex as fn, idleConciergeInput as ft, createWidgetVoiceTokenFetcher as g, linearToSrgb as gn, BOTTOM_FLOOR as gt, ROOM_EVENTS as h, linearRgbToOklab as hn, ACTIVITY_W as ht, ConciergeWidget as i, SHEET_RADIUS_MAX_PX as in, latencyBetween as it, ShellRenderer as j, widgetMessagesFromCopy as jn, PILL_H as jt, rendererFor as k, formatMessage as kn, MARK as kt, mergeAddedCartLine as l, themeToInlineStyle as ln, idleDockInput as lt, deriveWidgetTheme as m, hexToOklch as mn, WIDGET_MESSAGE_MAX_LENGTH as mt, CART_LINE_VARIANT_ID_SHAPE as n, writeStored as nn, SessionLog as nt, cartLinesFromSnapshot as o, WIDGET_THEME_TOKENS as on, DOCK_STATES as ot, WidgetThemeScope as p, hexToOklab as pn, formatMoney as pt, positionClasses as q, persistAlign as qt, ConciergeHost as r, CARD_RADIUS_MAX_PX as rn, formatMs as rt, chooseOptionsAction as s, deriveTheme as sn, deriveDockState as st, CART_LINE_PLATFORM_VARIANT_ID_SHAPE as t, snapAlign as tn, SESSION_EVENTS as tt, resolveAddToCartHandler as u, themeToMarkedHostCss as un, CONCIERGE_STATES as ut, CHECKOUT_CAPTURE_REQUIRED as v, oklabToHex as vn, DESKTOP_BOTTOM as vt, basketIntentFromTurns as w, relativeLuminance as wn, DRAG_CLICK_WINDOW_MS as wt, detectPage as x, oklchToHex as xn, DESKTOP_WIDTHS as xt, isSameOriginPath as y, oklabToLinearRgb as yn, DESKTOP_BREAKPOINT as yt, textDirectionFor as z, KNOT_PATH as zn, SHEET_PEEK_MAX as zt };
21219
+ export { IDLE_SNAPSHOT as $, readStoredMinimised as $t, rendererFor as A, formatMessage as An, MARK as At, textDirectionFor as B, KNOT_PATH as Bn, SHEET_PEEK_MAX as Bt, VoiceWidgetWithRenderer as C, oklchToOklab as Cn, DOCK_ALIGN_STORAGE_KEY as Ct, WidgetCartSummary as D, srgbToLinear as Dn, FLOAT_DUCK_DISMISS_MS as Dt, readsAsCheckoutIntent as E, rotateHue as En, DRAG_TAP_SLOP_PX as Et, CallView as F, MARK_VARIANTS as Fn, RADII$1 as Ft, edgeOf as G, bottomLen as Gt, CONCIERGE_POSITIONS as H, BotFace as Hn, SHEET_TUCK as Ht, IDLE_CALL_RECORD as I, WIDGET_AVATARS as In, ROW_H as It, positionClasses as J, persistAlign as Jt, nearestPosition as K, containerAnchor as Kt, WidgetMarkdown as L, WIDGET_IDENTITY_AVATARS as Ln, SHEET_EXPANDED_DESKTOP_MAX as Lt, ShellRenderer as M, widgetMessagesFromCopy as Mn, PILL_H as Mt, deriveWidgetView as N, MorphingLoader as Nn, PILL_MARK as Nt, VariantOptionChips as O, withAlpha as On, FLOAT_GAP as Ot, ConciergeShell as P, DEFAULT_WIDGET_AVATAR as Pn, PROACTIVE_NUDGE_MS as Pt, Mark as Q, readStoredAlign as Qt, parseBlocks as R, dockAvatarFor as Rn, SHEET_EXPANDED_VH as Rt, VoiceWidget as S, oklchToHex as Sn, DESKTOP_WIDTHS as St, readsAsCartViewIntent as T, relativeLuminance as Tn, DRAG_CLICK_WINDOW_MS as Tt, DEFAULT_CONCIERGE_POSITION as U, labelProps as Un, SHORT_VIEWPORT as Ut, ConciergeLauncher as V, RopeKnot as Vn, SHEET_TOP_CLEARANCE as Vt, alignOf as W, cn as Wn, Z_INDEX as Wt, LAUNCHER_VARIANTS as X, pillAnchor as Xt, positionForArrow as Y, persistMinimised as Yt, MARK_STATES as Z, readStored as Zt, useVoiceSession as _, linearToSrgb as _n, BOTTOM_FLOOR as _t, MAX_REPORTED_CART_LINES as a, SHEET_RADIUS_MAX_PX as an, latencyBetween as at, useChatSession as b, oklabToLinearRgb as bn, DESKTOP_BREAKPOINT as bt, deriveCallPhase as c, deriveTheme as cn, deriveDockState as ct, resolveCheckoutUrl as d, themeToMarkedHostCss as dn, CONCIERGE_STATES as dt, rowWidthLen as en, botStateFor as et, toChatCart as f, contrastRatio as fn, deriveConciergeState as ft, createWidgetVoiceTokenFetcher as g, linearRgbToOklab as gn, ACTIVITY_W as gt, ROOM_EVENTS as h, hexToOklch as hn, WIDGET_MESSAGE_MAX_LENGTH as ht, ConciergeWidget as i, CARD_RADIUS_MAX_PX as in, formatMs as it, DockRenderer as j, resolveWidgetMessages as jn, MOBILE_MARGIN as jt, WidgetCardList as k, defaultWidgetMessages as kn, GLASS_IDLE_MS as kt, mergeAddedCartLine as l, themeToCss as ln, deriveDockView as lt, deriveWidgetTheme as m, hexToOklab as mn, formatMoney as mt, CART_LINE_VARIANT_ID_SHAPE as n, snapAlign as nn, SESSION_EVENTS as nt, cartLinesFromSnapshot as o, SYSTEM_FONT_STACK as on, Dock as ot, WidgetThemeScope as p, formatHex as pn, idleConciergeInput as pt, panelClasses as q, geometryVars as qt, ConciergeHost as r, writeStored as rn, SessionLog as rt, chooseOptionsAction as s, WIDGET_THEME_TOKENS as sn, DOCK_STATES as st, CART_LINE_PLATFORM_VARIANT_ID_SHAPE as t, sheetMaxHeightLen as tn, SseFrameParser as tt, resolveAddToCartHandler as u, themeToInlineStyle as un, idleDockInput as ut, CHECKOUT_CAPTURE_REQUIRED as v, mixToward as vn, CONTROL as vt, basketIntentFromTurns as w, parseHex as wn, DOCK_MINIMISED_STORAGE_KEY as wt, detectPage as x, oklabToOklch as xn, DESKTOP_GUTTER as xt, isSameOriginPath as y, oklabToHex as yn, DESKTOP_BOTTOM as yt, stripBidiControls as z, isWidgetAvatar as zn, SHEET_GAP as zt };