@saar-ai/web-widget 0.17.0 → 0.18.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 (67) hide show
  1. package/dist/avatar-face.d.ts +9 -3
  2. package/dist/avatar-face.d.ts.map +1 -1
  3. package/dist/avatar.d.ts +15 -2
  4. package/dist/avatar.d.ts.map +1 -1
  5. package/dist/chunks/{host-widget-BPHMVIjq.js → host-widget-BhtqtvaY.js} +1833 -1322
  6. package/dist/concierge-shell.css +1 -1
  7. package/dist/dock/dock-row.d.ts +4 -2
  8. package/dist/dock/dock-row.d.ts.map +1 -1
  9. package/dist/dock/dock.d.ts +6 -0
  10. package/dist/dock/dock.d.ts.map +1 -1
  11. package/dist/dock/geometry.d.ts +1 -2
  12. package/dist/dock/geometry.d.ts.map +1 -1
  13. package/dist/generated/concierge-shell-css.d.ts.map +1 -1
  14. package/dist/generated/widget-css.d.ts.map +1 -1
  15. package/dist/host-widget.d.ts +2 -3
  16. package/dist/host-widget.d.ts.map +1 -1
  17. package/dist/index.d.ts +4 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +4 -4
  20. package/dist/messages.d.ts +4 -3
  21. package/dist/messages.d.ts.map +1 -1
  22. package/dist/next/index.js +1 -1
  23. package/dist/spoken-transcript.d.ts +21 -7
  24. package/dist/spoken-transcript.d.ts.map +1 -1
  25. package/dist/theme/derive.d.ts +71 -3
  26. package/dist/theme/derive.d.ts.map +1 -1
  27. package/dist/theme/host-tone.d.ts +0 -7
  28. package/dist/theme/host-tone.d.ts.map +1 -1
  29. package/dist/theme/index.d.ts +5 -1
  30. package/dist/theme/index.d.ts.map +1 -1
  31. package/dist/theme/widget-derive.d.ts +17 -0
  32. package/dist/theme/widget-derive.d.ts.map +1 -0
  33. package/dist/theme/widget-theme-scope.d.ts +17 -0
  34. package/dist/theme/widget-theme-scope.d.ts.map +1 -0
  35. package/dist/use-voice-session.d.ts +1 -1
  36. package/dist/use-voice-session.d.ts.map +1 -1
  37. package/dist/voice-widget.d.ts +32 -2
  38. package/dist/voice-widget.d.ts.map +1 -1
  39. package/dist/widget/call-view.d.ts +146 -0
  40. package/dist/widget/call-view.d.ts.map +1 -0
  41. package/dist/widget/concierge-launcher.d.ts +21 -2
  42. package/dist/widget/concierge-launcher.d.ts.map +1 -1
  43. package/dist/widget/concierge-shell.d.ts +49 -67
  44. package/dist/widget/concierge-shell.d.ts.map +1 -1
  45. package/dist/widget/launcher-look.d.ts +37 -0
  46. package/dist/widget/launcher-look.d.ts.map +1 -0
  47. package/dist/widget/mark-look.d.ts +35 -0
  48. package/dist/widget/mark-look.d.ts.map +1 -0
  49. package/dist/widget/mark.d.ts +35 -0
  50. package/dist/widget/mark.d.ts.map +1 -0
  51. package/dist/widget/mic-button.d.ts +27 -0
  52. package/dist/widget/mic-button.d.ts.map +1 -0
  53. package/dist/widget/shell-renderer.d.ts +1 -1
  54. package/dist/widget/shell-renderer.d.ts.map +1 -1
  55. package/dist/widget/style-of.d.ts +9 -0
  56. package/dist/widget/style-of.d.ts.map +1 -0
  57. package/dist/widget/use-follow-bottom.d.ts +17 -0
  58. package/dist/widget/use-follow-bottom.d.ts.map +1 -0
  59. package/dist/widget-cards.d.ts.map +1 -1
  60. package/dist/widget.css +1 -1
  61. package/package.json +14 -2
  62. package/src/styles/call-view.css +280 -0
  63. package/src/styles/concierge-shell-entry.css +10 -0
  64. package/src/styles/mark.css +94 -0
  65. package/src/styles/widget-panel.css +644 -0
  66. package/dist/widget/transcript-geometry.d.ts +0 -226
  67. package/dist/widget/transcript-geometry.d.ts.map +0 -1
@@ -3982,12 +3982,38 @@ function KnotSvg({ state, tightenKey }) {
3982
3982
  *
3983
3983
  * `'orb'` is `BotFace`, the animated gradient blob this widget has always
3984
3984
  * shipped. `'knot'` is `RopeKnot`, a hand-drawn rope line that ties and
3985
- * unties itself through the same four {@link BotState}s. Kept as data,
3985
+ * unties itself through the same four {@link BotState}s. `'bars'`,
3986
+ * `'monogram'` and `'dot'` are `widget/mark.tsx`'s flat brand mark. Kept as data,
3986
3987
  * separate from the components, for the same reason `bot-state.ts` keeps
3987
3988
  * `BotState` separate from `BotFace`: parsing and defaulting have to be
3988
3989
  * assertable without rendering either avatar.
3989
3990
  */
3990
- var WIDGET_AVATARS = ["orb", "knot"];
3991
+ var MARK_VARIANTS = [
3992
+ "bars",
3993
+ "monogram",
3994
+ "dot"
3995
+ ];
3996
+ var WIDGET_AVATARS = [
3997
+ "orb",
3998
+ "knot",
3999
+ ...MARK_VARIANTS
4000
+ ];
4001
+ /**
4002
+ * §9.1's `identity.avatar` — the drawn marks plus the two that are not drawn
4003
+ * from a name: an `image` and `none`. `bars`, `monogram` and `dot` (added
4004
+ * 2026-11-03) are the widget generation's marks and the default for a NEW
4005
+ * config; the dock draws them through {@link dockAvatarFor}.
4006
+ */
4007
+ var WIDGET_IDENTITY_AVATARS = [
4008
+ ...WIDGET_AVATARS,
4009
+ "image",
4010
+ "none"
4011
+ ];
4012
+ /** The dock's face for an avatar it has no drawing for: the orb for bars and monogram, nothing for dot. */
4013
+ function dockAvatarFor(avatar) {
4014
+ if (avatar === "bars" || avatar === "monogram") return "orb";
4015
+ return avatar === "dot" ? "none" : avatar;
4016
+ }
3991
4017
  /** What every layer in this package falls back to when a tenant never published one. */
3992
4018
  var DEFAULT_WIDGET_AVATAR = "orb";
3993
4019
  /** Whether a value is an avatar this widget knows how to render. Mirrors `bot-state.ts`'s `isBotState`. */
@@ -5250,7 +5276,7 @@ function deriveText(surfaceHex) {
5250
5276
  C: TEXT_C,
5251
5277
  h: hue
5252
5278
  });
5253
- if (contrastRatio(candidate, surfaceHex) >= TEXT_CONTRAST_MIN) return candidate;
5279
+ if (contrastRatio(candidate, surfaceHex) >= 4.5) return candidate;
5254
5280
  const next = Number((L + step).toFixed(4));
5255
5281
  if (next < 0 || next > 1) break;
5256
5282
  L = next;
@@ -5313,8 +5339,8 @@ function deriveText(surfaceHex) {
5313
5339
  * a mid-lightness surface can be unreachable from one side and comfortable
5314
5340
  * from the other.
5315
5341
  */
5316
- function deriveRing(primaryHex, surfaceHex) {
5317
- if (contrastRatio(primaryHex, surfaceHex) >= RING_CONTRAST_MIN) return primaryHex;
5342
+ function deriveRing(primaryHex, surfaceHex, floor = RING_CONTRAST_MIN) {
5343
+ if (contrastRatio(primaryHex, surfaceHex) >= floor) return primaryHex;
5318
5344
  const primary = hexToOklch(primaryHex);
5319
5345
  const preferDark = hexToOklch(surfaceHex).L >= .5;
5320
5346
  for (const goDark of preferDark ? [true, false] : [false, true]) {
@@ -5329,7 +5355,7 @@ function deriveRing(primaryHex, surfaceHex) {
5329
5355
  C: primary.C,
5330
5356
  h: primary.h
5331
5357
  });
5332
- if (contrastRatio(candidate, surfaceHex) >= RING_CONTRAST_MIN) return candidate;
5358
+ if (contrastRatio(candidate, surfaceHex) >= floor) return candidate;
5333
5359
  }
5334
5360
  }
5335
5361
  return contrastRatio("#000000", surfaceHex) >= contrastRatio("#ffffff", surfaceHex) ? "#000000" : "#ffffff";
@@ -5386,8 +5412,8 @@ function deriveTheme(color, type) {
5386
5412
  dark: deriveVars(color, type, supplied && suppliedIsDark ? supplied : DEFAULT_DARK_SURFACE)
5387
5413
  };
5388
5414
  }
5389
- function block(vars, selector, indent) {
5390
- return `${indent}${selector} {\n${WIDGET_THEME_TOKENS.map((t) => `${indent} ${t}: ${vars[t]};`).join("\n")}\n${indent}}`;
5415
+ function block(vars, selector, indent, tokens) {
5416
+ return `${indent}${selector} {\n${tokens.map((t) => `${indent} ${t}: ${vars[t]};`).join("\n")}\n${indent}}`;
5391
5417
  }
5392
5418
  /**
5393
5419
  * The theme as a CSS text block: the unconditional rule, plus — for
@@ -5405,12 +5431,12 @@ function block(vars, selector, indent) {
5405
5431
  * `:host` is the default because the dock lives in a shadow root; pass a class
5406
5432
  * or `:root` for the console preview, which renders in light DOM.
5407
5433
  */
5408
- function themeToCss(theme, selector = ":host") {
5409
- let css = `${block(theme.light, selector, "")}\n`;
5434
+ function themeToCss(theme, selector = ":host", tokens = WIDGET_THEME_TOKENS) {
5435
+ let css = `${block(theme.light, selector, "", tokens)}\n`;
5410
5436
  if (theme.dark) {
5411
5437
  const host = selector === ":host";
5412
- css += `\n@media (prefers-color-scheme: dark) {\n${block(theme.dark, host ? `:host(:not(${TONE_MARK}"light"]))` : selector, " ")}\n}\n`;
5413
- if (host) css += `\n${block(theme.dark, `:host(${TONE_MARK}"dark"])`, "")}\n`;
5438
+ css += `\n@media (prefers-color-scheme: dark) {\n${block(theme.dark, host ? `:host(:not(${TONE_MARK}"light"]))` : selector, " ", tokens)}\n}\n`;
5439
+ if (host) css += `\n${block(theme.dark, `:host(${TONE_MARK}"dark"])`, "", tokens)}\n`;
5414
5440
  }
5415
5441
  return css;
5416
5442
  }
@@ -5421,9 +5447,20 @@ var TONE_MARK = "[data-wgt-tone=";
5421
5447
  * host page's tone beats the media query on that element too. Matches
5422
5448
  * nothing in light DOM. Empty unless the tone is `auto`.
5423
5449
  */
5424
- function themeToMarkedHostCss(theme, selector) {
5450
+ function themeToMarkedHostCss(theme, selector, tokens = WIDGET_THEME_TOKENS) {
5425
5451
  if (!theme.dark) return "";
5426
- return `${block(theme.light, `:host(${TONE_MARK}"light"]) ${selector}`, "")}\n\n${block(theme.dark, `:host(${TONE_MARK}"dark"]) ${selector}`, "")}\n`;
5452
+ return `${block(theme.light, `:host(${TONE_MARK}"light"]) ${selector}`, "", tokens)}\n\n${block(theme.dark, `:host(${TONE_MARK}"dark"]) ${selector}`, "", tokens)}\n`;
5453
+ }
5454
+ /**
5455
+ * The tenant's tokens for one scoped element (`[data-wgt-scope]`), with the
5456
+ * host's tone marks on it; `host` adds a `:host` block first, for an element
5457
+ * that renders in a shadow root as well as in light DOM. Two blocks with the
5458
+ * same body rather than one selector list, because one invalid selector
5459
+ * invalidates a whole rule.
5460
+ */
5461
+ function scopedThemeCss(theme, scope, tokens = WIDGET_THEME_TOKENS, host = false) {
5462
+ const css = `${themeToCss(theme, scope, tokens)}\n${themeToMarkedHostCss(theme, scope, tokens)}`;
5463
+ return host ? `${themeToCss(theme, ":host", tokens)}\n${css}` : css;
5427
5464
  }
5428
5465
  /**
5429
5466
  * The theme as a `style` attribute value, for the `core` stage — which paints
@@ -5434,8 +5471,8 @@ function themeToMarkedHostCss(theme, selector) {
5434
5471
  * current `prefers-color-scheme` and the adopted stylesheet takes over the
5435
5472
  * responsiveness at the React handover.
5436
5473
  */
5437
- function themeToInlineStyle(vars) {
5438
- return WIDGET_THEME_TOKENS.map((t) => `${t}:${vars[t]};`).join("");
5474
+ function themeToInlineStyle(vars, tokens = WIDGET_THEME_TOKENS) {
5475
+ return tokens.map((t) => `${t}:${vars[t]};`).join("");
5439
5476
  }
5440
5477
  //#endregion
5441
5478
  //#region src/dock/geometry.ts
@@ -5443,8 +5480,7 @@ function themeToInlineStyle(vars) {
5443
5480
  * DOCK GEOMETRY — every length the dock's row, pill and sheet are built from
5444
5481
  * (docs/DOCK_SPEC.md §3), and the CSS expressions that carry them.
5445
5482
  *
5446
- * ONE module owns all of it, for the same reason `transcript-geometry.ts`
5447
- * owns the panel's four lengths: the dock is drawn TWICE, by two renderers
5483
+ * ONE module owns all of it because the dock is drawn TWICE, by two renderers
5448
5484
  * with no shared runtime. The CDN `core` stage paints the resting row and the
5449
5485
  * pill in plain DOM before any framework loads, writing these values as an
5450
5486
  * inline `style` attribute; the React dock then adopts a stylesheet built
@@ -5521,7 +5557,7 @@ var DESKTOP_WIDTHS = {
5521
5557
  full: null
5522
5558
  };
5523
5559
  /** §9.1 `type.radius`, in px. Mirrors `theme/derive.ts`'s `--wgt-radius`. */
5524
- var RADII = {
5560
+ var RADII$1 = {
5525
5561
  square: 0,
5526
5562
  soft: 12,
5527
5563
  round: 20,
@@ -6875,7 +6911,7 @@ function DockMarkFace({ identity, mark, size, testId, handoff, operatorName }) {
6875
6911
  const initials = handoff === true ? handoffInitials(operatorName) : "";
6876
6912
  const handoffKind = handoff !== true ? void 0 : initials === "" ? "person" : "initials";
6877
6913
  const url = handoffKind === void 0 && identity.avatar === "image" ? safeAvatarUrl(identity.avatarUrl) : void 0;
6878
- const kind = url ? "image" : identity.avatar === "image" ? "none" : identity.avatar;
6914
+ const kind = url ? "image" : identity.avatar === "image" ? "none" : dockAvatarFor(identity.avatar);
6879
6915
  return /* @__PURE__ */ jsx("span", {
6880
6916
  className: "wgt-mark-face",
6881
6917
  "data-mark": mark,
@@ -8392,11 +8428,11 @@ function BrandWordmark({ name }) {
8392
8428
  }
8393
8429
  //#endregion
8394
8430
  //#region src/dock/dock.tsx
8395
- var DEFAULT_COLOR = {
8431
+ var DEFAULT_COLOR$1 = {
8396
8432
  primary: "#4c1d50",
8397
8433
  tone: "light"
8398
8434
  };
8399
- var DEFAULT_TYPE = {
8435
+ var DEFAULT_TYPE$1 = {
8400
8436
  font: "inherit",
8401
8437
  radius: "soft",
8402
8438
  caps: "none"
@@ -8408,7 +8444,7 @@ var DEFAULT_LAYOUT = {
8408
8444
  };
8409
8445
  var INTERRUPT_SEEN_STORAGE_KEY = "wgt_dock_interrupt_seen";
8410
8446
  function Dock(props) {
8411
- const { identity, color = DEFAULT_COLOR, type = DEFAULT_TYPE, 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;
8447
+ 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;
8412
8448
  const scopeId = useId().replace(/[^a-zA-Z0-9_-]/g, "");
8413
8449
  const rootRef = useRef(null);
8414
8450
  const rowRef = useRef(null);
@@ -9296,15 +9332,9 @@ function Dock(props) {
9296
9332
  * Emitted TWICE, against `:host` and against this instance's own scope
9297
9333
  * attribute, because the dock renders in both worlds: inside `core.ts`'s
9298
9334
  * shadow root for the CDN embed, and in LIGHT DOM for a Next.js host and
9299
- * the marketing preview. A selector list would be worse than useless —
9300
- * one invalid selector invalidates the whole rule — so they are two blocks
9301
- * with identical bodies.
9335
+ * the marketing preview.
9302
9336
  */
9303
- const themeCss = useMemo(() => {
9304
- const theme = deriveTheme(color, type);
9305
- const scope = `[data-wgt-scope="${scopeId}"]`;
9306
- return `${themeToCss(theme, ":host")}\n${themeToCss(theme, scope)}\n${themeToMarkedHostCss(theme, scope)}`;
9307
- }, [
9337
+ const themeCss = useMemo(() => scopedThemeCss(deriveTheme(color, type), `[data-wgt-scope="${scopeId}"]`, void 0, true), [
9308
9338
  color,
9309
9339
  type,
9310
9340
  scopeId
@@ -10158,7 +10188,7 @@ function createLucideIcon(iconDataOrName, iconNode = [], aliases = []) {
10158
10188
  * This source code is licensed under the ISC license.
10159
10189
  * See the LICENSE file in the root directory of this source tree.
10160
10190
  */
10161
- var __iconData$6 = {
10191
+ var __iconData$5 = {
10162
10192
  name: "grip-vertical",
10163
10193
  size: 24,
10164
10194
  node: [
@@ -10200,8 +10230,8 @@ var __iconData$6 = {
10200
10230
  }]
10201
10231
  ]
10202
10232
  };
10203
- __iconData$6.node;
10204
- var GripVertical = createLucideIcon(__iconData$6);
10233
+ __iconData$5.node;
10234
+ var GripVertical = createLucideIcon(__iconData$5);
10205
10235
  //#endregion
10206
10236
  //#region ../../node_modules/.pnpm/lucide-react@1.50.0_@types+react@19.3.0_react@19.3.1/node_modules/lucide-react/dist/esm/icons/mic-off.mjs
10207
10237
  /**
@@ -10210,7 +10240,7 @@ var GripVertical = createLucideIcon(__iconData$6);
10210
10240
  * This source code is licensed under the ISC license.
10211
10241
  * See the LICENSE file in the root directory of this source tree.
10212
10242
  */
10213
- var __iconData$5 = {
10243
+ var __iconData$4 = {
10214
10244
  name: "mic-off",
10215
10245
  size: 24,
10216
10246
  node: [
@@ -10240,8 +10270,8 @@ var __iconData$5 = {
10240
10270
  }]
10241
10271
  ]
10242
10272
  };
10243
- __iconData$5.node;
10244
- var MicOff = createLucideIcon(__iconData$5);
10273
+ __iconData$4.node;
10274
+ var MicOff = createLucideIcon(__iconData$4);
10245
10275
  //#endregion
10246
10276
  //#region ../../node_modules/.pnpm/lucide-react@1.50.0_@types+react@19.3.0_react@19.3.1/node_modules/lucide-react/dist/esm/icons/mic.mjs
10247
10277
  /**
@@ -10250,7 +10280,7 @@ var MicOff = createLucideIcon(__iconData$5);
10250
10280
  * This source code is licensed under the ISC license.
10251
10281
  * See the LICENSE file in the root directory of this source tree.
10252
10282
  */
10253
- var __iconData$4 = {
10283
+ var __iconData$3 = {
10254
10284
  name: "mic",
10255
10285
  size: 24,
10256
10286
  node: [
@@ -10272,8 +10302,8 @@ var __iconData$4 = {
10272
10302
  }]
10273
10303
  ]
10274
10304
  };
10275
- __iconData$4.node;
10276
- var Mic = createLucideIcon(__iconData$4);
10305
+ __iconData$3.node;
10306
+ var Mic = createLucideIcon(__iconData$3);
10277
10307
  //#endregion
10278
10308
  //#region ../../node_modules/.pnpm/lucide-react@1.50.0_@types+react@19.3.0_react@19.3.1/node_modules/lucide-react/dist/esm/icons/phone-off.mjs
10279
10309
  /**
@@ -10282,7 +10312,7 @@ var Mic = createLucideIcon(__iconData$4);
10282
10312
  * This source code is licensed under the ISC license.
10283
10313
  * See the LICENSE file in the root directory of this source tree.
10284
10314
  */
10285
- var __iconData$3 = {
10315
+ var __iconData$2 = {
10286
10316
  name: "phone-off",
10287
10317
  size: 24,
10288
10318
  node: [
@@ -10300,8 +10330,8 @@ var __iconData$3 = {
10300
10330
  }]
10301
10331
  ]
10302
10332
  };
10303
- __iconData$3.node;
10304
- var PhoneOff = createLucideIcon(__iconData$3);
10333
+ __iconData$2.node;
10334
+ var PhoneOff = createLucideIcon(__iconData$2);
10305
10335
  //#endregion
10306
10336
  //#region ../../node_modules/.pnpm/lucide-react@1.50.0_@types+react@19.3.0_react@19.3.1/node_modules/lucide-react/dist/esm/icons/send.mjs
10307
10337
  /**
@@ -10310,7 +10340,7 @@ var PhoneOff = createLucideIcon(__iconData$3);
10310
10340
  * This source code is licensed under the ISC license.
10311
10341
  * See the LICENSE file in the root directory of this source tree.
10312
10342
  */
10313
- var __iconData$2 = {
10343
+ var __iconData$1 = {
10314
10344
  name: "send",
10315
10345
  size: 24,
10316
10346
  node: [["path", {
@@ -10321,30 +10351,8 @@ var __iconData$2 = {
10321
10351
  key: "12cjpa"
10322
10352
  }]]
10323
10353
  };
10324
- __iconData$2.node;
10325
- var Send = createLucideIcon(__iconData$2);
10326
- //#endregion
10327
- //#region ../../node_modules/.pnpm/lucide-react@1.50.0_@types+react@19.3.0_react@19.3.1/node_modules/lucide-react/dist/esm/icons/square.mjs
10328
- /**
10329
- * @license lucide-react v1.50.0 - ISC
10330
- *
10331
- * This source code is licensed under the ISC license.
10332
- * See the LICENSE file in the root directory of this source tree.
10333
- */
10334
- var __iconData$1 = {
10335
- name: "square",
10336
- size: 24,
10337
- node: [["rect", {
10338
- width: "18",
10339
- height: "18",
10340
- x: "3",
10341
- y: "3",
10342
- rx: "2",
10343
- key: "afitv7"
10344
- }]]
10345
- };
10346
10354
  __iconData$1.node;
10347
- var Square = createLucideIcon(__iconData$1);
10355
+ var Send = createLucideIcon(__iconData$1);
10348
10356
  //#endregion
10349
10357
  //#region ../../node_modules/.pnpm/lucide-react@1.50.0_@types+react@19.3.0_react@19.3.1/node_modules/lucide-react/dist/esm/icons/x.mjs
10350
10358
  /**
@@ -10367,8 +10375,158 @@ var __iconData = {
10367
10375
  __iconData.node;
10368
10376
  var X = createLucideIcon(__iconData);
10369
10377
  //#endregion
10378
+ //#region src/widget/mark-look.ts
10379
+ /**
10380
+ * The mark's static geometry and colours, shared by the React `Mark`
10381
+ * (`mark.tsx`) and the plain-DOM cold launcher (`cdn/launcher-dom.ts`).
10382
+ *
10383
+ * Framework-free on purpose: `launcher-dom.ts` ships in the `core` artefact,
10384
+ * which carries no React. Both renderers read the same declarations, so the
10385
+ * cold launcher and the React one cannot drift apart at the handover. They
10386
+ * are CSS declaration strings rather than style objects because `core` ships
10387
+ * unminified whitespace and a budget with a few hundred bytes of headroom: one
10388
+ * line of CSS per element costs a fraction of an object literal. React reads
10389
+ * them through `styleOf`. Animation lives in `styles/mark.css`, which only
10390
+ * the React stage loads.
10391
+ */
10392
+ function isMarkVariant(value) {
10393
+ return typeof value === "string" && MARK_VARIANTS.includes(value);
10394
+ }
10395
+ /** Resting heights of the four bars, as a fraction of the bar box. */
10396
+ var MARK_BARS = [
10397
+ .5,
10398
+ .9,
10399
+ .65,
10400
+ .4
10401
+ ];
10402
+ var markRootCss = (size) => `position:relative;display:grid;place-items:center;flex:none;width:${size}px;height:${size}px;border-radius:50%;background:var(--wgt-primary,var(--widget-accent,#111827));color:var(--wgt-on-primary,var(--wmk-on,#fff))`;
10403
+ var markBarsCss = (size) => `display:flex;align-items:center;gap:${tenth(size * .055)}px;height:46%`;
10404
+ var markBarCss = (size, k) => `display:block;width:${Math.max(2, tenth(size * .07))}px;height:100%;border-radius:99px;background:currentColor;transform:scaleY(${k})`;
10405
+ var markMonoCss = (size) => `font-weight:600;font-size:${tenth(size * .44)}px;line-height:1;font-family:var(--wgt-font,inherit)`;
10406
+ var MARK_PIP_CSS = "width:30%;height:30%;border-radius:50%;background:currentColor";
10407
+ function tenth(n) {
10408
+ return Math.round(n * 10) / 10;
10409
+ }
10410
+ /** What the mark draws: a monogram with no letter falls back to bars. */
10411
+ function drawnMark(variant, name) {
10412
+ const letter = variant === "monogram" ? firstGrapheme(name) : "";
10413
+ return {
10414
+ drawn: variant === "monogram" && letter === "" ? "bars" : variant,
10415
+ letter
10416
+ };
10417
+ }
10418
+ /**
10419
+ * The monogram's letter: the first grapheme of the agent's name, uppercased.
10420
+ * A grapheme, not a code unit, so an accented or emoji-led name keeps its
10421
+ * first visible character whole. Empty name ⇒ `''`; callers then draw bars.
10422
+ */
10423
+ function firstGrapheme(name) {
10424
+ const trimmed = name?.trim() ?? "";
10425
+ if (trimmed === "") return "";
10426
+ return ((Intl.Segmenter ? new Intl.Segmenter().segment(trimmed)[Symbol.iterator]().next().value?.segment : Array.from(trimmed)[0]) ?? "").toLocaleUpperCase();
10427
+ }
10428
+ //#endregion
10429
+ //#region src/widget/style-of.ts
10430
+ var cache = /* @__PURE__ */ new Map();
10431
+ /**
10432
+ * A CSS declaration string as a React style object — how the React launcher
10433
+ * and mark read the declarations they share with the cold launcher
10434
+ * (`launcher-look.ts`, `mark-look.ts`). Memoised: the strings are a handful of
10435
+ * constants, and a stable object is one React does not diff key by key.
10436
+ */
10437
+ function styleOf(css) {
10438
+ let style = cache.get(css);
10439
+ if (style === void 0) {
10440
+ const out = {};
10441
+ for (const declaration of css.split(";")) {
10442
+ const colon = declaration.indexOf(":");
10443
+ if (colon < 0) continue;
10444
+ const name = declaration.slice(0, colon).trim();
10445
+ out[name.startsWith("--") ? name : name.replace(/-([a-z])/g, (_, c) => c.toUpperCase())] = declaration.slice(colon + 1).trim();
10446
+ }
10447
+ style = out;
10448
+ cache.set(css, style);
10449
+ }
10450
+ return style;
10451
+ }
10452
+ //#endregion
10453
+ //#region src/widget/mark.tsx
10454
+ /** Every state the mark draws. `muted` and `connecting` come from the voice session, not `BotState`. */
10455
+ var MARK_STATES = [
10456
+ "idle",
10457
+ "connecting",
10458
+ "listening",
10459
+ "thinking",
10460
+ "speaking",
10461
+ "muted"
10462
+ ];
10463
+ /**
10464
+ * The mark's state from the session's. Muted wins over everything except
10465
+ * speaking: the agent can still talk while the shopper's mic is off.
10466
+ */
10467
+ function markStateFor(state, flags = {}) {
10468
+ return flags.muted && state !== "speaking" ? "muted" : state;
10469
+ }
10470
+ /**
10471
+ * The simple brand mark: a flat disc in the tenant's primary with four bars,
10472
+ * a monogram, or a dot. Motion carries the state (`styles/mark.css`): bars
10473
+ * follow the voice while listening or speaking, a ring ripples while
10474
+ * listening, an arc orbits while thinking. Transform and opacity only, and
10475
+ * static under `prefers-reduced-motion`.
10476
+ */
10477
+ function Mark({ variant, state = "idle", size, name, label, extraCss, testId }) {
10478
+ const { drawn, letter } = drawnMark(variant, name);
10479
+ return /* @__PURE__ */ jsxs("span", {
10480
+ ...label === void 0 ? { "aria-hidden": true } : {
10481
+ role: "img",
10482
+ "aria-label": label
10483
+ },
10484
+ className: "wmk",
10485
+ "data-mark": drawn,
10486
+ "data-mark-state": state,
10487
+ "data-testid": testId,
10488
+ style: styleOf(extraCss ? `${markRootCss(size)};${extraCss}` : markRootCss(size)),
10489
+ children: [
10490
+ state === "listening" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", { className: "wmk-r" }), /* @__PURE__ */ jsx("span", { className: "wmk-r" })] }) : null,
10491
+ drawn === "bars" ? /* @__PURE__ */ jsx("span", {
10492
+ className: "wmk-b",
10493
+ style: styleOf(markBarsCss(size)),
10494
+ children: MARK_BARS.map((k, i) => /* @__PURE__ */ jsx("i", {
10495
+ className: "wmk-i",
10496
+ style: styleOf(markBarCss(size, k))
10497
+ }, i))
10498
+ }) : drawn === "monogram" ? /* @__PURE__ */ jsx("span", {
10499
+ className: "wmk-m",
10500
+ style: styleOf(markMonoCss(size)),
10501
+ children: letter
10502
+ }) : /* @__PURE__ */ jsx("span", {
10503
+ className: "wmk-p",
10504
+ style: styleOf(MARK_PIP_CSS)
10505
+ }),
10506
+ state === "thinking" ? /* @__PURE__ */ jsx("svg", {
10507
+ className: "wmk-a",
10508
+ viewBox: "0 0 94 94",
10509
+ width: size + 18,
10510
+ height: size + 18,
10511
+ "aria-hidden": true,
10512
+ children: /* @__PURE__ */ jsx("circle", {
10513
+ cx: "47",
10514
+ cy: "47",
10515
+ r: "45",
10516
+ fill: "none"
10517
+ })
10518
+ }) : null
10519
+ ]
10520
+ });
10521
+ }
10522
+ //#endregion
10370
10523
  //#region src/avatar-face.tsx
10371
- function AvatarFace({ avatar, state, size, label, messageArrived, tightenKey }) {
10524
+ /** Mark diameter per slot: the launcher's face box and the panel's hero. */
10525
+ var MARK_SIZE = {
10526
+ sm: 48,
10527
+ lg: 64
10528
+ };
10529
+ function AvatarFace({ avatar, state, size, label, messageArrived, tightenKey, name, muted, markSize }) {
10372
10530
  switch (avatar) {
10373
10531
  case "orb": return /* @__PURE__ */ jsx(BotFace, {
10374
10532
  state,
@@ -10382,10 +10540,60 @@ function AvatarFace({ avatar, state, size, label, messageArrived, tightenKey })
10382
10540
  label,
10383
10541
  tightenKey
10384
10542
  });
10543
+ case "bars":
10544
+ case "monogram":
10545
+ case "dot": return /* @__PURE__ */ jsx(Mark, {
10546
+ variant: avatar,
10547
+ state: markStateFor(state, { muted }),
10548
+ size: markSize ?? MARK_SIZE[size],
10549
+ ...name !== void 0 ? { name } : {},
10550
+ ...label !== void 0 ? { label } : {}
10551
+ });
10385
10552
  default: throw new Error(`Unhandled widget avatar: ${String(avatar)}`);
10386
10553
  }
10387
10554
  }
10388
10555
  //#endregion
10556
+ //#region src/widget/launcher-look.ts
10557
+ /**
10558
+ * The collapsed launcher's look, shared by `concierge-launcher.tsx` (React)
10559
+ * and `cdn/launcher-dom.ts` (the plain-DOM cold twin `core` paints first).
10560
+ *
10561
+ * One set of declarations, two renderers: the handover from the cold pill to
10562
+ * React's must not visibly jump, and the cheapest way to keep two renderings
10563
+ * identical is to give them nothing to disagree about. Every value reads a
10564
+ * `--wgt-*` token with a literal fallback, because the cold launcher paints
10565
+ * before any stylesheet defining those tokens has been adopted. Strings, not
10566
+ * objects, for the reason `mark-look.ts` gives. Framework-free: ships in `core`.
10567
+ */
10568
+ var LAUNCHER_VARIANTS = ["pill", "round"];
10569
+ var DEFAULT_LAUNCHER_VARIANT = "pill";
10570
+ /** Mark diameter inside each launcher. */
10571
+ var LAUNCHER_MARK_SIZE = {
10572
+ pill: 44,
10573
+ round: 60
10574
+ };
10575
+ var LAUNCHER_SURFACE = "var(--wgt-panel-surface,var(--widget-card,#fff))";
10576
+ var LAUNCHER_TEXT = "var(--wgt-text,var(--widget-foreground,#1c1618))";
10577
+ var MUTED = "var(--wgt-text-muted,var(--widget-foreground-muted,rgba(28,22,24,.73)))";
10578
+ var LAUNCHER_ELEVATION = "var(--wgt-elevation,0 0 0 1px rgba(0,0,0,.06),0 24px 60px -22px rgba(0,0,0,.32))";
10579
+ /** The live-call dot, and `--wgt-live`'s value: constant, so it reads as "live" on every theme. */
10580
+ var LIVE_COLOR = "#E5484D";
10581
+ var RADIUS = "var(--wgt-launcher-radius,999px)";
10582
+ /** The fixed root, before the anchor. */
10583
+ var launcherRootCss = (variant) => `display:flex;align-items:center;color:${LAUNCHER_TEXT}` + (variant === "pill" ? `;gap:4px;padding:6px;border-radius:${RADIUS};background:${LAUNCHER_SURFACE};box-shadow:${LAUNCHER_ELEVATION};backdrop-filter:var(--wgt-panel-filter,none);white-space:nowrap` : "");
10584
+ /** The open control: mark + text in the pill, the mark alone in the round. */
10585
+ var launcherOpenCss = (variant) => `position:relative;border:0;margin:0;padding:0;background:none;color:${LAUNCHER_TEXT};font:inherit;cursor:pointer;` + (variant === "pill" ? `display:flex;align-items:center;gap:12px;min-height:48px;padding-inline-end:10px;border-radius:${RADIUS};text-align:start` : "display:grid;place-items:center;width:64px;height:64px;border-radius:50%");
10586
+ /** The round launcher's mark carries the elevation; the pill's sits on a surface. */
10587
+ var ROUND_MARK_CSS = `box-shadow:${LAUNCHER_ELEVATION}`;
10588
+ var LAUNCHER_TEXT_CSS = `display:block;min-width:0;color:${LAUNCHER_TEXT}`;
10589
+ var LAUNCHER_TITLE_CSS = `display:block;max-width:14rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:15px;font-weight:600;line-height:1.3;color:${LAUNCHER_TEXT}`;
10590
+ var LAUNCHER_SUB_CSS = `display:block;white-space:nowrap;font-size:12px;line-height:1.3;color:${MUTED};font-variant-numeric:tabular-nums`;
10591
+ var LAUNCHER_GRIP_CSS = `position:relative;z-index:1;display:grid;place-items:center;min-width:28px;min-height:44px;padding:0;border:0;border-radius:999px;background:none;color:${MUTED};cursor:grab;touch-action:none`;
10592
+ /** In the round launcher the grip is a small disc on the circle's lower start edge. */
10593
+ var ROUND_GRIP_CSS = `position:absolute;bottom:-4px;inset-inline-start:-4px;z-index:1;min-height:28px;background:${LAUNCHER_SURFACE};box-shadow:${LAUNCHER_ELEVATION}`;
10594
+ /** The grip's hit area: 44px across around the 28px grip, which keeps its look. */
10595
+ var GRIP_HIT_CSS = "position:absolute;inset:-8px";
10596
+ //#endregion
10389
10597
  //#region src/widget/position.ts
10390
10598
  /**
10391
10599
  * Where the concierge sits on the host page, and how a visitor moves it.
@@ -10491,7 +10699,7 @@ var QUIET = {
10491
10699
  badge: false,
10492
10700
  initials: false
10493
10701
  };
10494
- function ConciergeLauncher({ label, srLabel, moveLabel, position, onPositionChange, onOpen, hidden, id, testId, avatar = "orb", spec = QUIET, initials = "" }) {
10702
+ function ConciergeLauncher({ label, srLabel, moveLabel, position, onPositionChange, onOpen, hidden, id, testId, avatar = "orb", spec = QUIET, initials = "", launcher = DEFAULT_LAUNCHER_VARIANT, agentName, subLabel, callLabel }) {
10495
10703
  const rootRef = useRef(null);
10496
10704
  /** Pixel offset while a drag is in flight; `null` when it is not. */
10497
10705
  const [drag, setDrag] = useState(null);
@@ -10575,15 +10783,24 @@ function ConciergeLauncher({ label, srLabel, moveLabel, position, onPositionChan
10575
10783
  if (next !== position) onPositionChange(next);
10576
10784
  };
10577
10785
  const dragging = drag !== null;
10786
+ const markSize = LAUNCHER_MARK_SIZE[launcher];
10787
+ const round = launcher === "round";
10788
+ const sub = callLabel ?? subLabel;
10789
+ const showText = !round && (label !== void 0 || sub !== void 0);
10790
+ const ariaLabel = round || label === void 0 ? [srLabel, callLabel].filter(Boolean).join(" · ") : void 0;
10578
10791
  return /* @__PURE__ */ jsxs("div", {
10579
10792
  ref: rootRef,
10580
10793
  id,
10581
10794
  "data-testid": testId,
10582
10795
  "data-position": position,
10796
+ "data-launcher": launcher,
10583
10797
  "aria-hidden": hidden,
10584
- className: cn("fixed z-50 flex items-center gap-1 rounded-full border border-white/40 bg-[var(--widget-card)] py-1.5 pe-4 ps-2 shadow-[0_12px_32px_-12px_color-mix(in_oklab,var(--brand-plum)_35%,transparent)] backdrop-blur-xl", positionClasses(position), dragging ? "cursor-grabbing" : "transition-[opacity,scale] duration-300 ease-out", hidden ? "pointer-events-none scale-75 opacity-0" : "pointer-events-auto opacity-100", !hidden && spec.dimmed ? "opacity-60" : null, spec.disabled ? "cursor-default opacity-70" : null),
10585
- style: drag ? { transform: `translate(${drag.dx}px, ${drag.dy}px)` } : void 0,
10586
- children: [onPositionChange ? /* @__PURE__ */ jsx("button", {
10798
+ className: cn("fixed z-50", positionClasses(position), dragging ? "cursor-grabbing" : "transition-[opacity,scale] duration-300 ease-out", hidden ? "pointer-events-none scale-75 opacity-0" : "pointer-events-auto opacity-100", !hidden && spec.dimmed ? "opacity-60" : null, spec.disabled ? "cursor-default opacity-70" : null),
10799
+ style: {
10800
+ ...styleOf(launcherRootCss(launcher)),
10801
+ ...drag ? { transform: `translate(${drag.dx}px, ${drag.dy}px)` } : {}
10802
+ },
10803
+ children: [onPositionChange ? /* @__PURE__ */ jsxs("button", {
10587
10804
  type: "button",
10588
10805
  "aria-label": moveLabel,
10589
10806
  title: moveLabel,
@@ -10594,14 +10811,21 @@ function ConciergeLauncher({ label, srLabel, moveLabel, position, onPositionChan
10594
10811
  onPointerUp,
10595
10812
  onPointerCancel: onPointerUp,
10596
10813
  onKeyDown: onGripKeyDown,
10597
- className: cn("touch-none rounded-full p-1 text-[var(--widget-foreground-muted)] transition-colors", "hover:bg-brand-plum/10 hover:text-brand-plum focus-visible:ring-brand-plum/30 focus-visible:ring-2 focus-visible:outline-none", dragging ? "cursor-grabbing" : "cursor-grab"),
10598
- children: /* @__PURE__ */ jsx(GripVertical, {
10814
+ className: FOCUS_RING,
10815
+ style: {
10816
+ ...styleOf(round ? `${LAUNCHER_GRIP_CSS};${ROUND_GRIP_CSS}` : LAUNCHER_GRIP_CSS),
10817
+ cursor: dragging ? "grabbing" : "grab"
10818
+ },
10819
+ children: [/* @__PURE__ */ jsx(GripVertical, {
10599
10820
  className: "size-4",
10600
10821
  "aria-hidden": true
10601
- })
10822
+ }), /* @__PURE__ */ jsx("span", {
10823
+ "aria-hidden": true,
10824
+ style: styleOf(GRIP_HIT_CSS)
10825
+ })]
10602
10826
  }) : null, /* @__PURE__ */ jsxs("button", {
10603
10827
  type: "button",
10604
- "aria-label": label === void 0 ? srLabel : void 0,
10828
+ "aria-label": ariaLabel,
10605
10829
  tabIndex: hidden || spec.disabled ? -1 : 0,
10606
10830
  disabled: spec.disabled,
10607
10831
  ...spec.busy ? { "aria-busy": true } : {},
@@ -10612,17 +10836,29 @@ function ConciergeLauncher({ label, srLabel, moveLabel, position, onPositionChan
10612
10836
  onOpen();
10613
10837
  },
10614
10838
  "data-testid": testId ? `${testId}-open` : void 0,
10615
- className: "flex items-center gap-2.5 rounded-full focus-visible:ring-brand-plum/30 focus-visible:ring-2 focus-visible:outline-none",
10839
+ className: FOCUS_RING,
10840
+ style: styleOf(launcherOpenCss(launcher)),
10616
10841
  children: [/* @__PURE__ */ jsxs("span", {
10617
10842
  "aria-hidden": true,
10618
- className: "relative block size-12 shrink-0",
10843
+ className: "relative block shrink-0",
10844
+ style: {
10845
+ width: markSize,
10846
+ height: markSize
10847
+ },
10619
10848
  children: [
10620
10849
  spec.initials && initials !== "" ? /* @__PURE__ */ jsx("span", {
10621
10850
  "data-testid": "widget-launcher-initials",
10622
- className: "absolute start-1/2 top-1/2 flex size-9 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full bg-[var(--widget-accent)] text-[13px] font-semibold text-[var(--widget-accent-foreground)] rtl:translate-x-1/2",
10851
+ style: styleOf(`${markRootCss(markSize)};${round ? `${ROUND_MARK_CSS};` : ""}font-weight:600;font-size:${Math.round(markSize * .34)}px;line-height:1;font-family:var(--wgt-font,inherit)`),
10623
10852
  children: initials
10853
+ }) : isMarkVariant(avatar) ? /* @__PURE__ */ jsx(Mark, {
10854
+ variant: avatar,
10855
+ state: spec.busy ? "connecting" : "idle",
10856
+ size: markSize,
10857
+ ...agentName !== void 0 ? { name: agentName } : {},
10858
+ ...round ? { extraCss: ROUND_MARK_CSS } : {}
10624
10859
  }) : /* @__PURE__ */ jsx("span", {
10625
- className: "absolute start-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 scale-[0.75] rtl:translate-x-1/2",
10860
+ className: "absolute start-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 rtl:translate-x-1/2",
10861
+ style: { scale: String(markSize / 64) },
10626
10862
  children: /* @__PURE__ */ jsx(AvatarFace, {
10627
10863
  avatar,
10628
10864
  state: "idle",
@@ -10632,490 +10868,893 @@ function ConciergeLauncher({ label, srLabel, moveLabel, position, onPositionChan
10632
10868
  }),
10633
10869
  spec.busy ? /* @__PURE__ */ jsx("span", {
10634
10870
  "data-testid": "widget-launcher-busy",
10635
- className: "pointer-events-none absolute inset-0 animate-spin rounded-full border-2 border-transparent border-t-[var(--widget-accent)] motion-reduce:animate-none"
10871
+ className: "pointer-events-none absolute -inset-[3px] animate-spin rounded-full border-2 border-transparent border-t-[var(--wgt-primary,#111827)] motion-reduce:animate-none"
10636
10872
  }) : null,
10637
10873
  spec.badge ? /* @__PURE__ */ jsx("span", {
10638
10874
  "data-testid": "widget-launcher-badge",
10639
- className: "absolute end-0 top-0 size-3 rounded-full bg-[var(--widget-accent)] ring-2 ring-[var(--widget-card)]"
10875
+ style: BADGE_STYLE
10876
+ }) : null,
10877
+ round && callLabel !== void 0 ? /* @__PURE__ */ jsx("span", {
10878
+ "data-testid": "widget-launcher-live",
10879
+ title: callLabel,
10880
+ style: LIVE_STYLE
10640
10881
  }) : null
10641
10882
  ]
10642
- }), label === void 0 ? null : /* @__PURE__ */ jsx("span", {
10883
+ }), showText ? /* @__PURE__ */ jsxs("span", {
10643
10884
  dir: "auto",
10644
- className: "max-w-[14rem] truncate text-sm font-medium text-[var(--widget-foreground)]",
10645
- children: label
10646
- })]
10885
+ style: styleOf(LAUNCHER_TEXT_CSS),
10886
+ children: [label !== void 0 ? /* @__PURE__ */ jsx("span", {
10887
+ style: styleOf(LAUNCHER_TITLE_CSS),
10888
+ children: label
10889
+ }) : null, sub !== void 0 ? /* @__PURE__ */ jsx("span", {
10890
+ "data-testid": "widget-launcher-sub",
10891
+ style: styleOf(LAUNCHER_SUB_CSS),
10892
+ children: sub
10893
+ }) : null]
10894
+ }) : null]
10647
10895
  })]
10648
10896
  });
10649
10897
  }
10898
+ /** Something landed behind the closed panel. Text-coloured, so it reads on any brand mark. */
10899
+ var BADGE_STYLE = {
10900
+ position: "absolute",
10901
+ top: 0,
10902
+ insetInlineEnd: 0,
10903
+ width: 12,
10904
+ height: 12,
10905
+ borderRadius: "50%",
10906
+ background: LAUNCHER_TEXT,
10907
+ boxShadow: `0 0 0 2px ${LAUNCHER_SURFACE}`
10908
+ };
10909
+ /** A call is live (round launcher). */
10910
+ var LIVE_STYLE = {
10911
+ position: "absolute",
10912
+ top: 2,
10913
+ insetInlineStart: 2,
10914
+ width: 14,
10915
+ height: 14,
10916
+ borderRadius: "50%",
10917
+ background: `var(--wgt-live,${LIVE_COLOR})`,
10918
+ boxShadow: `0 0 0 2px ${LAUNCHER_SURFACE}`
10919
+ };
10920
+ var FOCUS_RING = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--wgt-ring,#111827)]";
10650
10921
  //#endregion
10651
- //#region src/widget/transcript-geometry.ts
10652
- /**
10653
- * PANEL GEOMETRY — where the conversation's first row sits, as a FRACTION of
10654
- * the panel's height, and what that costs horizontally.
10655
- *
10656
- * Four CSS length expressions and the arithmetic behind them, used by
10657
- * `concierge-shell.tsx`'s `transcriptEdgeFade`. Their own module, and NOT
10658
- * re-exported from `index.ts`: `concierge-shell.geometry.test.tsx` has to read
10659
- * the exact strings the component ships (jsdom's CSS serializer mangles a
10660
- * `max()` containing a subtraction, so reading them back off a rendered element
10661
- * tests jsdom rather than this widget), while the package's public API stays
10662
- * the components themselves.
10663
- *
10664
- * One ratio ties the four lengths together, and it is the whole
10665
- * repair for a bug that shipped: the panel is an ellipse (`rounded-full` on a
10666
- * `w x 1.6w` box), so how much width it offers depends entirely on how far down
10667
- * you are. The clearances below scaled with `cqh` while the transcript's
10668
- * horizontal inset was a fixed 8px tuned for the oval's wide middle, so the
10669
- * taller the panel got the HIGHER the first message sat proportionally — into a
10670
- * narrower part of the curve, with no matching inset. Measured live in
10671
- * Storybook, first agent bubble's top-left corner against the curve at its own
10672
- * top edge: 14px inside the ellipse at a 582px panel, 37px at 720px, 62px at
10673
- * 920px (the 2000x1150 desktop it was reported on). `overflow-clip` on the
10674
- * surface then cut exactly that much off the bubble.
10675
- *
10676
- * 0.1924 is not chosen, it is READ OFF the short panel: 112px (the tuned
10677
- * clearance, see {@link TRANSCRIPT_FADE_TOP_LEN}) over 582px (the panel a
10678
- * 375x812 phone renders) is 0.19244. Holding that ratio at every size is what
10679
- * makes the geometry scale-invariant — every panel then presents the first row
10680
- * at the same point on the same curve, and ONE horizontal inset serves all of
10681
- * them ({@link TRANSCRIPT_INSET_X}). Expressed as `19.24cqh` in the lengths
10682
- * below; `cqh` is the panel's own height, via `[container-type:size]` on the
10683
- * panel div (verified live: `14cqh` resolved to 128.8px on a 920px panel).
10684
- *
10685
- * Not a JS constant that gets multiplied out — the panel's height is never
10686
- * known to JS, only to CSS, which is why every length here is an expression.
10687
- */
10688
- /**
10689
- * Top ramp when the transcript starts at the panel's top, under the floating
10690
- * orb — it has to span the orb, so a message is gone before it reaches it
10691
- * rather than sliding out from behind it half-visible.
10692
- *
10693
- * A CSS length EXPRESSION, not a bare number, since the aspect-ratio panel
10694
- * (`w-[min(97vw,50dvh)]` + `aspect-[5/8]`) ranges from ~582px tall (mobile,
10695
- * width-bound) to 800px+ (desktop, height-bound) — a fixed 112px clearance
10696
- * tuned for the OLD fixed-520px panel left too little air under the orb on a
10697
- * tall one and too much on a short one. `max(112px, 19.24cqh)` is a floor, not
10698
- * a fixed value: it stays exactly 112px (today's tuned figure) on a short
10699
- * panel, where 19.24cqh would fall below it, and grows with `cqh` — the query
10700
- * container's own height, established by `[container-type:size]` on the
10701
- * panel div below — once the panel is tall enough that 19.24% of it exceeds
10702
- * 112px. `cqh` rather than `dvh` specifically: the panel's real rendered
10703
- * height, not the viewport's, since the panel does not always fill the
10704
- * viewport (mobile: width-bound, height is `w / (8/5)`, shorter than 100dvh).
10705
- *
10706
- * 19.24, not the 14 this shipped with: 14cqh gave a TALL panel proportionally
10707
- * LESS clearance than the 112px floor gives a short one (14% against 19.24%),
10708
- * which pushed the first message up into the narrowing part of the ellipse —
10709
- * see the ratio's own note above for the measurements. The floor and the
10710
- * scaling term now agree at 582px (19.24% of 582 = 111.98), so the two meet
10711
- * without a step rather than crossing over at some unrelated height.
10712
- */
10713
- var TRANSCRIPT_FADE_TOP_LEN = "max(112px, 19.24cqh)";
10714
- /**
10715
- * Top ramp when a `badge` sits above the transcript.
10716
- *
10717
- * A badge has ALREADY pushed the transcript clear of the orb, so reusing the
10718
- * orb-sized ramp charges for the same clearance twice: it left a 112px dead
10719
- * band directly under the badge and dissolved the opening message for no
10720
- * reason (measured in `WithABadgeAndNoVoice` — orb ends 565, badge 573-598,
10721
- * first message could not start above 710). At that point the fade is only
10722
- * doing its ordinary job of softening a scroll edge, so it wants an ordinary
10723
- * scroll-edge length. Same floor+`cqh` scheme as {@link TRANSCRIPT_FADE_TOP_LEN}
10724
- * above and for the same reason — this ramp needs to soften proportionally
10725
- * more of a tall panel's scroll edge than a short one's.
10726
- *
10727
- * The third arm is the ellipse, and it is what keeps this variant honest at
10728
- * sizes the badge's own fixed offsets stop covering. With a badge the first row
10729
- * is pushed down by chrome that does NOT scale — 1px surface border + 6px
10730
- * column padding + the badge wrapper's `mt-[104px]` + 4px list padding = 115px
10731
- * — so the row lands at `(115px + this ramp) / panelHeight`, a fraction that
10732
- * SHRINKS as the panel grows. `19.24cqh - 115px` is that equation solved for
10733
- * the ramp, so the row lands on the same point of the curve the no-badge
10734
- * variant does. It is inert on the panels this variant was tuned against
10735
- * (negative at 582px, 4.5px at 720px, so the other two arms win) and takes over
10736
- * only above ~745px, where the fixed 115px has stopped being enough.
10737
- *
10738
- * The badge's own height is counted as ZERO in that 115px, deliberately:
10739
- * `badge` is an arbitrary node from the host (`voice-widget.tsx` passes a
10740
- * one-line status pill, ~26px), and only the shortest-badge bound holds for
10741
- * every caller. A taller badge pushes the row further down, which is the safe
10742
- * direction.
10743
- */
10744
- var TRANSCRIPT_FADE_TOP_WITH_BADGE_LEN = "max(28px, 4cqh, 19.24cqh - 115px)";
10745
- var TRANSCRIPT_FADE_BOTTOM_LEN = "max(136px, 23.36cqh)";
10746
- /**
10747
- * The transcript's horizontal inset — the width the ellipse actually costs.
10748
- *
10749
- * `10.6cqw` is where the curve is at the first row's height: on an ellipse of
10750
- * width `w`, at the fraction 0.1924 of the way down (the ratio the clearances
10751
- * above hold at every size), the left edge lies `w * (1 - sqrt(1 - (2*0.1924 -
10752
- * 1)^2)) / 2` = `0.1058 * w` in from the bounding box. Rounded up to 10.6% so
10753
- * the rounding goes toward clearance rather than away from it.
10754
- *
10755
- * `- 11px` because 11px of that is already paid for by fixed chrome outside
10756
- * this element: the surface's 1px border plus the inner column's `px-2.5`. The
10757
- * inset is measured from the PANEL's box, which is where the curve is; this
10758
- * padding only has to make up the difference. Verified live: a 363.8px-wide
10759
- * panel put the first bubble's left edge at 19px = 11px chrome + the 8px this
10760
- * replaces.
10761
- *
10762
- * The `8px` floor is the value this shipped with, kept as a lower bound so a
10763
- * degenerately small panel can never end up with less padding than a plain
10764
- * scroll edge wants. It is inert at every real size (the formula gives 27.6px
10765
- * on the smallest panel the widget renders).
10766
- *
10767
- * Symmetric on purpose, and applied as `padding-inline` so it stays symmetric
10768
- * in RTL: the ellipse is symmetric, the visitor's own bubbles are `justify-end`
10769
- * against the other side of it, and either side is the first row's side
10770
- * depending on who spoke.
10771
- */
10772
- var TRANSCRIPT_INSET_X = "max(8px, 10.6cqw - 11px)";
10773
- /**
10774
- * The composer overlay's bottom offset when the microphone is drawn.
10775
- *
10776
- * `11.86cqh` is {@link COMPOSER_ROW_FRACTION} as a length. `- 63px` is
10777
- * everything between this offset and the input's bottom edge that does NOT
10778
- * scale: the surface's 1px border (the overlay is positioned against the inner
10779
- * column's padding box, one border inside the panel) plus the 62px microphone
10780
- * block — a 10px `gap-2.5`, the row's 4px `mt-1`, and a 48px `size-12` button.
10781
- *
10782
- * `max(6px, …)` keeps the 6px this shipped with as a floor, and the two arms
10783
- * MEET at the panel it was tuned on rather than crossing somewhere unrelated:
10784
- * `11.86cqh - 63px` is 6.03px at 582px, so a phone renders what it rendered
10785
- * before to a hundredth of a pixel and only larger panels lift the composer.
10786
- */
10787
- var COMPOSER_BOTTOM_LEN = "max(6px, 15cqh - 63px)";
10788
- /**
10789
- * The composer overlay's bottom offset when there is NO microphone.
10790
- *
10791
- * Same target row, minus only the 1px surface border: with `voice` omitted the
10792
- * overlay's last child IS the input, so the 62px the microphone block
10793
- * contributed above has to come from this offset instead. That is a real move —
10794
- * 6px to 68px on a phone — and it is the fix rather than a side effect. Left at
10795
- * 6px the input sits 7px off a `rounded-full` panel's bottom tip, where the
10796
- * ellipse offers 79px of width in total; no width cap can rescue that row, so
10797
- * the row itself has to come up to where the panel is wide enough to hold it.
10798
- *
10799
- * The band it moves into is the one the microphone would have occupied, which
10800
- * the transcript already clears ({@link TRANSCRIPT_FADE_BOTTOM_LEN} is sized
10801
- * for the input + microphone pair regardless of whether the pair is drawn), so
10802
- * nothing above has to move to make room.
10803
- */
10804
- var COMPOSER_BOTTOM_NO_VOICE_LEN = "max(6px, 15cqh - 1px)";
10805
- /**
10806
- * The composer's width cap — what the ellipse actually offers at that row.
10807
- *
10808
- * On an ellipse of width `w`, at the fraction `1 - 0.1186` of the way down, the
10809
- * full chord is `w * sqrt(1 - (2*0.8814 - 1)^2)` = `0.6465 * w`. So `64.65cqw`
10810
- * is not a taste-tuned percentage, it is the panel's own width at the row the
10811
- * two offsets above pin the input to — where `w-[71%]`, the class this caps,
10812
- * was 6.4% of the panel too wide at EVERY size (10.8px of overhang on a phone,
10813
- * 52.0px on a 920px panel, because the row also drifts lower as the panel
10814
- * grows).
10815
- *
10816
- * `- 10px` is clearance, 5px each side, matching the 5px the transcript's rows
10817
- * clear the curve by — the panel paints a 1.5px gradient ring plus a 1px
10818
- * surface border at that edge, and the input's own rounding means the arc, not
10819
- * the corner, is what approaches the curve.
10820
- *
10821
- * Applied as `max-width` over the existing `w-[71%]`, not in place of it: 71%
10822
- * stays the upper bound the composer had, and this only ever tightens it (the
10823
- * ellipse term is below 71% for any panel, since 0.6465 < 0.71). The `160px`
10824
- * floor is the "cap it sensibly" arm — it stops a degenerately small panel from
10825
- * resolving the composer to a few dozen pixels of unusable input, and it is
10826
- * inert at every size the widget really renders (it binds only below a 248px
10827
- * panel; the narrowest phone in circulation, 320px, gives 310px).
10828
- */
10829
- var COMPOSER_MAX_WIDTH_LEN = "max(160px, 71.41cqw - 10px)";
10830
- /**
10831
- * The opaque ground the composer sits on, which has to keep covering it.
10832
- *
10833
- * The transcript runs the panel's whole height and passes BEHIND this row, so
10834
- * this gradient is the only thing between a message and the input's own
10835
- * translucent chip fill. It was a fixed `h-[132px]`, tuned when the composer
10836
- * was pinned 6px off the bottom on every panel — and the moment the offsets
10837
- * above start lifting the composer on a tall panel, a fixed ground stops
10838
- * reaching its top edge (the composer's top is `11.86cqh + 40px` above the
10839
- * panel's bottom: 109px at 582px, but 149px at 920px, against 132px of ground).
10840
- *
10841
- * 22.68cqh is the same read-off-the-short-panel derivation as everything else
10842
- * here — 132/582 = 0.22680 — so a phone renders exactly the 132px it rendered
10843
- * before and the ground grows with the row it is under. It stays above the
10844
- * composer's own top at every size, and stays the same shade taller than the
10845
- * transcript's bottom clearance that it is today ({@link
10846
- * TRANSCRIPT_FADE_BOTTOM_LEN} is 20.27cqh against this 22.68cqh, exactly the
10847
- * 118:132 relationship the two were tuned at), so they still meet without a
10848
- * seam or a band of doubly-darkened panel.
10849
- */
10850
- var COMPOSER_GROUND_LEN = "max(150px, 25.77cqh)";
10851
- //#endregion
10852
- //#region src/widget/concierge-shell.tsx
10922
+ //#region ../widget-protocol/dist/text-direction.js
10853
10923
  /**
10854
- * How far off the bottom still counts as "following the conversation".
10924
+ * Base direction for a block of text whose language is the CONTENT's, not the
10925
+ * reader's. Pure, string-only and dependency-free: a STATIC import into the
10926
+ * chat bundle a shopper downloads, shared by the console (`apps/web`) and the
10927
+ * widget (`@saar-ai/web-widget`), which used to keep a hand copy each.
10855
10928
  *
10856
- * Not zero: fractional scroll metrics on zoomed and hi-dpi displays never
10857
- * land exactly on the bottom, and a smooth scroll is still in flight when the
10858
- * next streamed token resizes the content. Both would read as the visitor
10859
- * having deliberately scrolled up, and stop the transcript following.
10929
+ * It lives here rather than in `@wesence/i18n` because the widget's published
10930
+ * bundle may resolve no `@wesence/*` module at all (`docs/PACKAGE_DISTRIBUTION.md`,
10931
+ * enforced by `scripts/check-npm-bundle-provenance.mjs`), the same reason
10932
+ * `./money` lives here.
10933
+ *
10934
+ * ## Why the console's own direction is the wrong answer
10935
+ *
10936
+ * `<html dir>` is set from the operator's UI locale, and every element inherits
10937
+ * it. That is right for the chrome and wrong for a transcript: an
10938
+ * English-speaking agent reading an Arabic conversation would render each
10939
+ * message with an LTR base direction, and the Unicode bidirectional algorithm
10940
+ * would then lay out the runs in the wrong order and throw trailing punctuation
10941
+ * to the wrong end of the line.
10942
+ *
10943
+ * The failure is invisible to the person looking at it. An agent who cannot read
10944
+ * Arabic sees Arabic-looking text and moves on; the customer is the one who gets
10945
+ * quoted back a sentence that reads incorrectly. The reverse case is just as
10946
+ * real — an Arabic-speaking agent reading English conversations under an RTL
10947
+ * base.
10948
+ *
10949
+ * ## Mixed runs are the normal case here, not an edge case
10950
+ *
10951
+ * Verified against live recognition output: Arabic comes back as
10952
+ * `رقم الـ order هو 4471. Please check من فضلك.` and Hindi as
10953
+ * `मेरा order number 4471 है।`. Latin nouns inside a non-Latin sentence are what
10954
+ * this product's transcripts actually contain, so bidirectional layout is
10955
+ * exercised on ordinary traffic rather than by an unusual customer.
10956
+ *
10957
+ * ## `auto` is the floor, not the goal
10958
+ *
10959
+ * With a known language this returns a definite direction. Without one it
10960
+ * returns `auto`, which delegates to the browser's first-strong-character
10961
+ * heuristic — better than inheriting the chrome, but wrong for a message that
10962
+ * opens with an English word and continues in Arabic (`Please check من فضلك`).
10963
+ * The real fix is to persist the conversation's resolved locale and pass it in;
10964
+ * see the note in `Transcript`.
10860
10965
  */
10861
- var FOLLOW_TOLERANCE_PX = 24;
10862
- /**
10863
- * Build the transcript's mask + the padding that matches it.
10864
- *
10865
- * The two must be derived together: the padding is what lets the first and
10866
- * last messages scroll clear of the ramp, so a ramp length that is not also
10867
- * the padding leaves the newest message permanently half-dissolved.
10868
- *
10869
- * The top half of the top ramp is fully transparent (SAA-435): text beside
10870
- * the orb read through at 20-45% under the old eased ramp, which looked like
10871
- * no fade at all. It now clears completely before it reaches the orb's row.
10872
- *
10873
- * The top ramp's stops are scaled from `topLen` rather than hardcoded, so the
10874
- * shortened badge variant keeps the same eased shape instead of becoming a
10875
- * steep two-point cut. `topLen` is a CSS length EXPRESSION now (a `max(<px>,
10876
- * <N>cqh)` floor, see the constants above), not a plain number — `at(fraction)`
10877
- * therefore emits `calc(<topLen> * <fraction>)` rather than doing the
10878
- * multiplication in JS, so each stop scales with the query container's
10879
- * height (`cqh`) exactly the way `topLen` itself does. `calc()` accepts a
10880
- * `max()` expression as its left operand (`max()` resolves to a `<length>`,
10881
- * and a `<length>` may be multiplied by a bare `<number>` inside `calc()`),
10882
- * so this composes without a second unit-handling special case.
10883
- *
10884
- * The bottom ramp's own inner taper (the last four stops, `96px`/`72px`/
10885
- * `48px`/`24px`) stays fixed pixels, deliberately NOT scaled by `cqh`: it is
10886
- * a small, fixed-shape cosmetic fade against the very bottom edge, sized
10887
- * once and unrelated to how much CLEARANCE the composer needs above it —
10888
- * that clearance is what `TRANSCRIPT_FADE_BOTTOM_LEN` (the transition point
10889
- * this taper starts from, and the padding below) controls, and that is what
10890
- * scales.
10891
- *
10892
- * The horizontal inset rides along here rather than staying a `px-2` class for
10893
- * the same reason the vertical padding does: it is derived from `topLen` — the
10894
- * curve is only knowable once you know how far down the first row starts (see
10895
- * {@link TRANSCRIPT_INSET_X}) — and splitting a derived pair across a class and
10896
- * a style object is exactly how the two drift apart.
10897
- */
10898
- function transcriptEdgeFade(topLen, shift) {
10899
- const at = (fraction) => shift ? `calc(${shift} + ${topLen} * ${fraction})` : `calc(${topLen} * ${fraction})`;
10900
- const top = shift ? `calc(${shift} + ${topLen})` : topLen;
10901
- const gradient = `linear-gradient(to bottom, ${[
10902
- "transparent 0",
10903
- `transparent ${at(.5)}`,
10904
- `rgba(0,0,0,0.25) ${at(.7)}`,
10905
- `rgba(0,0,0,0.65) ${at(.86)}`,
10906
- `#000 ${top}`,
10907
- `#000 calc(100% - ${TRANSCRIPT_FADE_BOTTOM_LEN})`,
10908
- "rgba(0,0,0,0.86) calc(100% - 96px)",
10909
- "rgba(0,0,0,0.60) calc(100% - 72px)",
10910
- "rgba(0,0,0,0.32) calc(100% - 48px)",
10911
- "rgba(0,0,0,0.10) calc(100% - 24px)",
10912
- "transparent 100%"
10913
- ].join(", ")})`;
10914
- return {
10915
- maskImage: gradient,
10916
- WebkitMaskImage: gradient,
10917
- paddingTop: top,
10918
- paddingBottom: TRANSCRIPT_FADE_BOTTOM_LEN,
10919
- paddingInline: TRANSCRIPT_INSET_X
10920
- };
10921
- }
10922
- /** All variants built once — none depends on props beyond badge and pill presence. */
10923
- var TRANSCRIPT_EDGE_FADE = transcriptEdgeFade(TRANSCRIPT_FADE_TOP_LEN);
10924
10966
  /**
10925
- * SAA-484: the call-state pill sits 107-130px down the panel, under the orb.
10926
- * With no badge above the transcript, the orb's ramp left text readable beside
10927
- * it. 64px puts the ramp's transparent half past the pill on a phone's 582px
10928
- * panel (120px) and on a desktop's 720px one (133px).
10967
+ * Languages written right-to-left. Keyed on the language subtag, so a region
10968
+ * never has to be enumerated.
10969
+ *
10970
+ * Beyond Arabic on purpose: Hebrew, Farsi, Urdu and Pashto are the scripts a CX
10971
+ * product in this region acquires next, and getting one wrong is the same silent
10972
+ * failure. Adding a language to the product must not also require remembering
10973
+ * this file.
10929
10974
  */
10930
- var TRANSCRIPT_EDGE_FADE_WITH_PILL = transcriptEdgeFade(TRANSCRIPT_FADE_TOP_LEN, "64px");
10931
- var TRANSCRIPT_EDGE_FADE_WITH_BADGE = transcriptEdgeFade(TRANSCRIPT_FADE_TOP_WITH_BADGE_LEN);
10975
+ var RTL_LANGUAGES = /* @__PURE__ */ new Set([
10976
+ "ar",
10977
+ "he",
10978
+ "iw",
10979
+ "fa",
10980
+ "ur",
10981
+ "ps",
10982
+ "sd",
10983
+ "ug",
10984
+ "yi",
10985
+ "dv"
10986
+ ]);
10987
+ /** Known LTR languages this product targets, so a typo does not silently pass. */
10988
+ var KNOWN_LTR_LANGUAGES = /* @__PURE__ */ new Set([
10989
+ "en",
10990
+ "hi",
10991
+ "es",
10992
+ "fr",
10993
+ "de",
10994
+ "pt",
10995
+ "it",
10996
+ "nl",
10997
+ "id",
10998
+ "ta",
10999
+ "te",
11000
+ "bn",
11001
+ "mr",
11002
+ "gu",
11003
+ "kn",
11004
+ "ml",
11005
+ "pa"
11006
+ ]);
11007
+ /** A well-formed BCP-47-ish language subtag: two or three ASCII letters. */
11008
+ var LANGUAGE_SUBTAG = /^[a-z]{2,3}$/;
10932
11009
  /**
10933
- * Maps the call onto the pill it shows, reusing fields `ConciergeShellVoice`
10934
- * already carries rather than inventing new plumbing:
10935
- *
10936
- * - `'connecting'` → `connecting`
10937
- * - `'waiting'` (the agent is thinking, between the caller's turn ending and
10938
- * the reply starting) → `thinking`
10939
- * - `'live'` + `agentSpeaking` → `speaking`
10940
- * - `'live'` otherwise → `listening`
10941
- * - `'idle'` / `'blocked'` → `null`, no pill
11010
+ * The base direction for text in `locale`.
10942
11011
  *
10943
- * `agentSpeaking` is already a real field on {@link ConciergeShellVoice} —
10944
- * this function only reads it, it does not require every caller to start
10945
- * setting it; a caller that never populates it simply never reaches
10946
- * `'speaking'`, which is exactly the same "renders sensibly with what it is
10947
- * given" contract every other optional field on this interface follows.
11012
+ * @param locale BCP-47 tag from stored conversation data — untyped by the time
11013
+ * it reaches here, so anything malformed resolves to `auto` rather than to a
11014
+ * guess.
10948
11015
  */
10949
- function voiceStatePillState(voice) {
10950
- if (!voice) return null;
10951
- switch (voice.phase) {
10952
- case "connecting": return "connecting";
10953
- case "waiting": return "thinking";
10954
- case "live": return voice.agentSpeaking ? "speaking" : "listening";
10955
- default: return null;
10956
- }
11016
+ function textDirectionFor$1(locale) {
11017
+ if (locale === void 0 || locale === null || locale === "") return "auto";
11018
+ const language = locale.toLowerCase().split("-")[0] ?? "";
11019
+ if (!LANGUAGE_SUBTAG.test(language)) return "auto";
11020
+ if (RTL_LANGUAGES.has(language)) return "rtl";
11021
+ if (KNOWN_LTR_LANGUAGES.has(language)) return "ltr";
11022
+ return "auto";
10957
11023
  }
11024
+ //#endregion
11025
+ //#region src/text-direction.ts
11026
+ var textDirectionFor = textDirectionFor$1;
11027
+ //#endregion
11028
+ //#region src/widget-markdown.tsx
10958
11029
  /**
10959
- * The label a pill state shows, falling back to the package's brand-neutral
10960
- * English word (`defaultWidgetMessages`) when the host's own `labels` omit
10961
- * it — the same "an existing caller renders sensibly without changes"
10962
- * contract every field added to `ConciergeShellVoice.labels` after 0.2.0
10963
- * follows.
11030
+ * Only `http(s)` and `mailto` survive.
11031
+ *
11032
+ * A model can emit `[click here](javascript:…)` as easily as a real URL, and a
11033
+ * bare `href` would execute it on click. Anything else renders as plain text,
11034
+ * so a rejected link still shows its label rather than vanishing.
10964
11035
  */
10965
- function voiceStatePillLabel(pillState, labels) {
10966
- switch (pillState) {
10967
- case "connecting": return labels?.connecting ?? defaultWidgetMessages.voice_state_connecting;
10968
- case "listening": return labels?.listening ?? defaultWidgetMessages.voice_state_listening;
10969
- case "thinking": return labels?.thinking ?? defaultWidgetMessages.voice_state_thinking;
10970
- case "speaking": return labels?.speaking ?? defaultWidgetMessages.voice_state_speaking;
10971
- }
10972
- }
10973
- /**
10974
- * The leading dot's colour, in brand tokens — never a literal, so it follows
10975
- * `skinStyle` when a tenant publishes their own brand colours, the same
10976
- * reasoning every other brand-coloured glow in this file already states.
10977
- * `listening` and `speaking` share `--brand-rose`: both are "the room is
10978
- * live" states from the caller's point of view (a caller talking and an
10979
- * agent talking back both read as "the call is active"), where
10980
- * `connecting`/`thinking` are the two states with genuinely nothing to
10981
- * listen to yet.
10982
- */
10983
- function voiceStatePillDotColor(pillState) {
10984
- switch (pillState) {
10985
- case "connecting": return "var(--brand-amber)";
10986
- case "thinking": return "var(--brand-plum)";
10987
- case "listening":
10988
- case "speaking": return "var(--brand-rose)";
10989
- }
11036
+ function safeHref(raw) {
11037
+ const href = raw.trim();
11038
+ if (/^https?:\/\//i.test(href)) return href;
11039
+ if (/^mailto:[^\s]+@[^\s]+$/i.test(href)) return href;
11040
+ return null;
10990
11041
  }
10991
11042
  /**
10992
- * The footer's two controls: opaque pills in the band the column reserves
10993
- * under the panel (SAA-435), readable over any host page. Inherited colour
10994
- * there was the HOST's, which is how "Privacy choices" went near-invisible.
11043
+ * The bidi embedding and isolate controls (U+202A-U+202E, U+2066-U+2069),
11044
+ * removed from what a bubble shows (SAA-436). A right-to-left override typed
11045
+ * into a message reverses the rest of it on screen ("exe.txt" spoofing); the
11046
+ * bubble's own `dir="auto"` and `unicode-bidi: isolate` already order real
11047
+ * mixed-direction text, so nothing legitimate needs them.
10995
11048
  */
10996
- var FOOTER_PILL = "absolute bottom-[env(safe-area-inset-bottom,0px)] h-7 rounded-full bg-[var(--widget-card)] px-2.5 text-xs shadow-sm ring-1 ring-black/5 transition-opacity duration-300";
11049
+ function stripBidiControls(text) {
11050
+ return text.replace(/[\u202A-\u202E\u2066-\u2069]/g, "");
11051
+ }
10997
11052
  /**
10998
- * The attribution badge under the panel: same slot as `FOOTER_PILL` but plain text and a
10999
- * dot, never a chip (SAA-451), so no fill, ring or shadow; `h-7` keeps the hit area.
11053
+ * Inline constructs, innermost-last.
11054
+ *
11055
+ * Code is matched FIRST and never recurses into its own body: `` `**not
11056
+ * bold**` `` is a literal in every Markdown dialect, and parsing emphasis
11057
+ * inside it is the classic way a renderer mangles a code sample.
11000
11058
  */
11001
- var BADGE_LINK = "absolute bottom-[env(safe-area-inset-bottom,0px)] h-7 px-1 transition-opacity duration-300";
11002
- /** How long the opening flourish runs. Matches `.widget-portal`'s own duration. */
11003
- var PORTAL_MS = 720;
11004
- function ConciergeShell({ open, onOpenChange, state, messageArrived = false, launcher, launcherInitials, typing = false, operatorName, avatar = "orb", labels, children, badge, draft, onDraftChange, onSubmit, composerDisabled = false, voice, announcement, skin, skinStyle, idPrefix = "concierge", scrollKey, composerLeading, testIds, position = DEFAULT_CONCIERGE_POSITION, onPositionChange, attribution, privacyChoices, focusOnOpen = true }) {
11005
- const triggerId = `${idPrefix}-trigger`;
11006
- const inputId = `${idPrefix}-input`;
11007
- const [portalActive, setPortalActive] = useState(false);
11008
- const panelRef = useRef(null);
11009
- const transcriptRef = useRef(null);
11010
- /** The transcript's content box — what grows as a reply streams in. */
11011
- const transcriptContentRef = useRef(null);
11012
- useEffect(() => {
11013
- if (!open) return;
11014
- setPortalActive(true);
11015
- const id = window.setTimeout(() => setPortalActive(false), PORTAL_MS);
11016
- return () => window.clearTimeout(id);
11017
- }, [open]);
11018
- /**
11019
- * The knot's equivalent of the orb's `bot-nod` flourish — `BotFace` fires
11020
- * `messageArrived` off `className` presence alone (a CSS animation restarts
11021
- * whenever a class newly APPLIES), which works because `messageArrived`
11022
- * itself is a derived, level-triggered boolean ("was the last turn from the
11023
- * caller") that a component only needs to read once per render. `RopeKnot`'s
11024
- * tighten/tap flourish is EDGE-triggered instead — it plays once per bump of
11025
- * `tightenKey`, the exact vehicle a launcher press already uses
11026
- * (`concierge-launcher.tsx`) — so this only bumps it on the RISING edge
11027
- * (`false` → `true`), not on every render where `messageArrived` merely
11028
- * stays `true` (e.g. while the agent is still thinking about the same
11029
- * caller turn).
11030
- */
11031
- const wasMessageArrived = useRef(false);
11032
- const [knotTightenKey, setKnotTightenKey] = useState(0);
11033
- useEffect(() => {
11034
- if (messageArrived && !wasMessageArrived.current) setKnotTightenKey((k) => k + 1);
11035
- wasMessageArrived.current = messageArrived;
11036
- }, [messageArrived]);
11059
+ function parseInline(src) {
11060
+ const out = [];
11061
+ let rest = src;
11062
+ while (rest.length > 0) {
11063
+ const match = /`([^`]+)`|\*\*([\s\S]+?)\*\*|__([\s\S]+?)__|(?<!\*)\*(?!\s)([^*\n]+?)\*(?!\*)|(?<!_)_(?!\s)([^_\n]+?)_(?!_)|\[([^\]]*)\]\(([^)\s]+)\)|(https:\/\/[^\s<>"'`]*[^\s<>"'`.,;:!?)\]])/.exec(rest);
11064
+ if (!match || match.index === void 0) {
11065
+ out.push({
11066
+ kind: "text",
11067
+ text: rest
11068
+ });
11069
+ break;
11070
+ }
11071
+ if (match.index > 0) out.push({
11072
+ kind: "text",
11073
+ text: rest.slice(0, match.index)
11074
+ });
11075
+ const [full, code, boldStar, boldUnd, italStar, italUnd, linkText, linkHref, bare] = match;
11076
+ if (code !== void 0) out.push({
11077
+ kind: "code",
11078
+ text: code
11079
+ });
11080
+ else if (boldStar !== void 0 || boldUnd !== void 0) out.push({
11081
+ kind: "bold",
11082
+ children: parseInline(boldStar ?? boldUnd)
11083
+ });
11084
+ else if (italStar !== void 0 || italUnd !== void 0) out.push({
11085
+ kind: "italic",
11086
+ children: parseInline(italStar ?? italUnd)
11087
+ });
11088
+ else if (linkHref !== void 0) {
11089
+ const href = safeHref(linkHref);
11090
+ const children = parseInline(linkText ?? "").flatMap((n) => n.kind === "link" ? n.children : [n]);
11091
+ out.push(href ? {
11092
+ kind: "link",
11093
+ href,
11094
+ children
11095
+ } : {
11096
+ kind: "text",
11097
+ text: linkText ?? ""
11098
+ });
11099
+ } else if (bare !== void 0) out.push({
11100
+ kind: "link",
11101
+ href: bare,
11102
+ children: [{
11103
+ kind: "text",
11104
+ text: bare
11105
+ }]
11106
+ });
11107
+ rest = rest.slice(match.index + full.length);
11108
+ }
11109
+ return out.filter((n) => !(n.kind === "text" && n.text === ""));
11110
+ }
11111
+ function sameOrigin(href) {
11112
+ try {
11113
+ return new URL(href).origin === window.location.origin;
11114
+ } catch {
11115
+ return false;
11116
+ }
11117
+ }
11118
+ function renderInline(nodes, keyPrefix) {
11119
+ return nodes.map((node, i) => {
11120
+ const key = `${keyPrefix}-${i}`;
11121
+ switch (node.kind) {
11122
+ case "text": return /* @__PURE__ */ jsx(Fragment$1, { children: node.text }, key);
11123
+ case "bold": return /* @__PURE__ */ jsx("strong", { children: renderInline(node.children, key) }, key);
11124
+ case "italic": return /* @__PURE__ */ jsx("em", { children: renderInline(node.children, key) }, key);
11125
+ case "code": return /* @__PURE__ */ jsx("code", {
11126
+ className: "rounded bg-black/10 px-1 py-0.5 font-mono text-[0.85em]",
11127
+ children: node.text
11128
+ }, key);
11129
+ case "link": return /* @__PURE__ */ jsx("a", {
11130
+ href: node.href,
11131
+ ...sameOrigin(node.href) ? {} : {
11132
+ target: "_blank",
11133
+ rel: "noopener noreferrer nofollow"
11134
+ },
11135
+ className: "underline underline-offset-2 [overflow-wrap:anywhere]",
11136
+ children: renderInline(node.children, key)
11137
+ }, key);
11138
+ }
11139
+ });
11140
+ }
11141
+ var BULLET = /^\s*[-*+]\s+(.*)$/;
11142
+ var ORDERED = /^\s*\d+[.)]\s+(.*)$/;
11143
+ /**
11144
+ * Group lines into blocks.
11145
+ *
11146
+ * A blank line always closes the current block; a list item closes a paragraph
11147
+ * and vice versa. That last rule is what fixes the reported bug — the model
11148
+ * writes its intro and its bullets with no blank line between them, so
11149
+ * splitting on blank lines alone left `intro - item - item` as one paragraph.
11150
+ */
11151
+ function parseBlocks(markdown) {
11152
+ const blocks = [];
11153
+ let paragraph = [];
11154
+ let list = null;
11155
+ const flushParagraph = () => {
11156
+ if (paragraph.length > 0) blocks.push({
11157
+ kind: "paragraph",
11158
+ lines: paragraph
11159
+ });
11160
+ paragraph = [];
11161
+ };
11162
+ const flushList = () => {
11163
+ if (list) blocks.push({
11164
+ kind: "list",
11165
+ ordered: list.ordered,
11166
+ items: list.items
11167
+ });
11168
+ list = null;
11169
+ };
11170
+ for (const line of markdown.split("\n")) {
11171
+ if (line.trim() === "") {
11172
+ flushParagraph();
11173
+ flushList();
11174
+ continue;
11175
+ }
11176
+ const bullet = BULLET.exec(line);
11177
+ const ordered = bullet ? null : ORDERED.exec(line);
11178
+ if (bullet ?? ordered) {
11179
+ flushParagraph();
11180
+ const isOrdered = ordered !== null;
11181
+ const text = (bullet?.[1] ?? ordered?.[1] ?? "").trim();
11182
+ if (list && list.ordered !== isOrdered) flushList();
11183
+ list ??= {
11184
+ ordered: isOrdered,
11185
+ items: []
11186
+ };
11187
+ list.items.push(text);
11188
+ continue;
11189
+ }
11190
+ flushList();
11191
+ paragraph.push(line.trim());
11192
+ }
11193
+ flushParagraph();
11194
+ flushList();
11195
+ return blocks;
11196
+ }
11197
+ /**
11198
+ * Renders one turn's text.
11199
+ *
11200
+ * Safe to call on a PARTIAL string: this runs on every streamed delta, so a
11201
+ * half-written `**bold` is common. Unterminated markers simply fail to match
11202
+ * and render as the literal characters they are, which then resolve
11203
+ * themselves on the delta that closes them — no flicker beyond the marker
11204
+ * briefly showing, and never a thrown parse error mid-stream.
11205
+ */
11206
+ function WidgetMarkdown({ text }) {
11207
+ return parseBlocks(stripBidiControls(text)).map((block, i) => {
11208
+ if (block.kind === "list") return /* @__PURE__ */ jsx(block.ordered ? "ol" : "ul", {
11209
+ className: `my-1 space-y-1 ps-4 ${block.ordered ? "list-decimal" : "list-disc"}`,
11210
+ children: block.items.map((item, j) => /* @__PURE__ */ jsx("li", { children: renderInline(parseInline(item), `b${i}-i${j}`) }, `b${i}-i${j}`))
11211
+ }, `b${i}`);
11212
+ return /* @__PURE__ */ jsx("p", {
11213
+ className: "[&:not(:first-child)]:mt-2",
11214
+ children: block.lines.map((line, j) => /* @__PURE__ */ jsxs(Fragment$1, { children: [j > 0 ? /* @__PURE__ */ jsx("br", {}) : null, renderInline(parseInline(line), `b${i}-l${j}`)] }, `b${i}-l${j}`))
11215
+ }, `b${i}`);
11216
+ });
11217
+ }
11218
+ //#endregion
11219
+ //#region src/widget/mic-button.tsx
11220
+ /**
11221
+ * What the microphone control means right now: start, mute or unmute, or,
11222
+ * ahead of all three, the REASON it means nothing (`labels.unavailable`).
11223
+ *
11224
+ * While connecting, dialling or the browser's prompt still open, it is inert
11225
+ * and busy: one impatient press must not become a second call, or a mute of a
11226
+ * call that does not exist yet. It reports no pressed state then, because
11227
+ * there is no call yet to have muted.
11228
+ */
11229
+ function micControl(voice) {
11230
+ const connecting = voice.phase === "connecting";
11231
+ const inCall = voice.phase !== "idle";
11232
+ const unusable = voice.disabled === true || voice.phase === "blocked";
11233
+ const connectingLabel = voice.labels.connecting ?? defaultWidgetMessages.voice_state_connecting;
11234
+ const muted = inCall && voice.muted === true;
11235
+ return {
11236
+ label: unusable ? voice.labels.unavailable ?? voice.labels.start : connecting ? connectingLabel : inCall ? (muted ? voice.labels.unmute : voice.labels.mute) ?? voice.labels.start : voice.labels.start,
11237
+ onClick: connecting ? void 0 : inCall ? voice.onToggleMute ?? voice.onStart : voice.onStart,
11238
+ disabled: unusable || connecting,
11239
+ busy: connecting,
11240
+ pressed: inCall && !connecting ? muted : void 0,
11241
+ live: inCall && !connecting && !muted,
11242
+ muted,
11243
+ connectingLabel
11244
+ };
11245
+ }
11246
+ /** The microphone control, in the composer and in the call view's controls. */
11247
+ function MicButton({ voice, testId, className }) {
11248
+ const mic = micControl(voice);
11249
+ return /* @__PURE__ */ jsx("button", {
11250
+ type: "button",
11251
+ onClick: mic.onClick,
11252
+ disabled: mic.disabled,
11253
+ "data-testid": testId,
11254
+ title: mic.label,
11255
+ "aria-label": mic.label,
11256
+ "aria-busy": mic.busy || void 0,
11257
+ "aria-pressed": mic.pressed,
11258
+ "data-live": mic.live ? "" : void 0,
11259
+ className: cn(className, mic.busy && "cursor-wait"),
11260
+ children: mic.busy ? /* @__PURE__ */ jsx("span", {
11261
+ "aria-hidden": "true",
11262
+ "data-testid": "widget-mic-spinner",
11263
+ children: /* @__PURE__ */ jsx(MorphingLoader, {
11264
+ size: "sm",
11265
+ label: mic.connectingLabel
11266
+ })
11267
+ }) : mic.muted ? /* @__PURE__ */ jsx(MicOff, {}) : /* @__PURE__ */ jsx(Mic, {})
11268
+ });
11269
+ }
11270
+ //#endregion
11271
+ //#region src/widget/use-follow-bottom.ts
11272
+ /**
11273
+ * How far off the bottom still counts as "following the conversation".
11274
+ *
11275
+ * Not zero: fractional scroll metrics on zoomed and hi-dpi displays never
11276
+ * land exactly on the bottom, and a smooth scroll is still in flight when the
11277
+ * next streamed token resizes the content.
11278
+ */
11279
+ var FOLLOW_TOLERANCE_PX = 24;
11280
+ /** `smooth`, or `auto` where the visitor asked for less motion. */
11281
+ function scrollBehavior() {
11282
+ return typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth";
11283
+ }
11284
+ /**
11285
+ * Keeps a scrolling log on its newest line while the reader is there: the
11286
+ * panel's transcript and the call view's turns.
11287
+ *
11288
+ * A rise in `rows`, or any change of `nudge`, jumps to the bottom (with
11289
+ * `keepReader`, only while following: a call delivers turns every few seconds,
11290
+ * and a caller re-reading a card must not be pulled down); a fall in
11291
+ * `rows` does not, because a row going away is not a new turn (SAA-484).
11292
+ * Between turns a `ResizeObserver` on `content` and on the viewport follows a
11293
+ * reply as it streams, but only while following. Only a scroll UP stops
11294
+ * following: a smooth scroll fires `scroll` events on its way down, each short
11295
+ * of the bottom. jsdom and older engines ship no `scrollTo` or
11296
+ * `ResizeObserver`; without them this does nothing rather than throw.
11297
+ */
11298
+ function useFollowBottom(viewport, content, rows, nudge, keepReader = false) {
11299
+ const following = useRef(true);
11300
+ const lastRows = useRef(rows);
11301
+ useEffect(() => {
11302
+ const el = viewport.current;
11303
+ const before = lastRows.current;
11304
+ lastRows.current = rows;
11305
+ if (typeof rows === "number" && typeof before === "number" && rows < before) return;
11306
+ if (typeof el?.scrollTo !== "function") return;
11307
+ if (keepReader && !following.current) return;
11308
+ following.current = true;
11309
+ el.scrollTo({
11310
+ top: el.scrollHeight,
11311
+ behavior: scrollBehavior()
11312
+ });
11313
+ }, [rows, nudge]);
11314
+ const watching = useRef({ el: null });
11315
+ useEffect(() => {
11316
+ const el = viewport.current;
11317
+ if (watching.current.el === el) return;
11318
+ watching.current.stop?.();
11319
+ watching.current = { el };
11320
+ if (!el || typeof el.scrollTo !== "function" || typeof ResizeObserver === "undefined") return;
11321
+ let lastTop = el.scrollTop;
11322
+ const onScroll = () => {
11323
+ if (el.scrollHeight - el.scrollTop - el.clientHeight <= FOLLOW_TOLERANCE_PX) following.current = true;
11324
+ else if (el.scrollTop < lastTop) following.current = false;
11325
+ lastTop = el.scrollTop;
11326
+ };
11327
+ const observer = new ResizeObserver(() => {
11328
+ if (following.current) el.scrollTo({
11329
+ top: el.scrollHeight,
11330
+ behavior: "auto"
11331
+ });
11332
+ });
11333
+ if (content.current) observer.observe(content.current);
11334
+ observer.observe(el);
11335
+ el.addEventListener("scroll", onScroll, { passive: true });
11336
+ watching.current.stop = () => {
11337
+ observer.disconnect();
11338
+ el.removeEventListener("scroll", onScroll);
11339
+ };
11340
+ });
11341
+ useEffect(() => () => {
11342
+ watching.current.stop?.();
11343
+ watching.current = { el: null };
11344
+ }, []);
11345
+ }
11346
+ //#endregion
11347
+ //#region src/widget/call-view.tsx
11348
+ /**
11349
+ * The call view's own words. Kept out of `defaultWidgetMessages` so the dock's
11350
+ * `ui.mjs` does not carry them; a host catalogue overrides any of them by key.
11351
+ */
11352
+ var defaultCallMessages = {
11353
+ call_your_turn: "Your turn",
11354
+ call_muted: "Muted",
11355
+ call_paused: "Paused",
11356
+ call_mic_blocked: "Mic blocked",
11357
+ call_human: "With a teammate",
11358
+ call_offline: "Offline",
11359
+ call_problem: "Call problem",
11360
+ call_ended: "Call ended",
11361
+ call_interrupted: "Interrupted",
11362
+ call_try_saying: "Try saying",
11363
+ call_to_text: "Type instead",
11364
+ call_back_to_call: "Back to call",
11365
+ call_back_to_chat: "Back to chat",
11366
+ call_summary_added: "Added to your basket: {items}",
11367
+ call_summary_checkout: "Your checkout is ready.",
11368
+ call_on_call: "On call"
11369
+ };
11370
+ /** One message, from the host's catalogue when it has the key. */
11371
+ function callText(messages, key) {
11372
+ return messages[key] ?? defaultCallMessages[key] ?? defaultWidgetMessages[key] ?? "";
11373
+ }
11374
+ /**
11375
+ * The header's one word for each of the fourteen states. A `Record` over the
11376
+ * union, so a new state fails to compile until it has a word.
11377
+ */
11378
+ var CALL_WORDS = {
11379
+ connecting: "voice_state_connecting",
11380
+ listening: "call_your_turn",
11381
+ thinking: "voice_state_thinking",
11382
+ speaking: "voice_state_speaking",
11383
+ muted: "call_muted",
11384
+ ducked: "call_paused",
11385
+ reconnecting: "dock_still_here",
11386
+ mic_blocked: "call_mic_blocked",
11387
+ human: "call_human",
11388
+ offline: "call_offline",
11389
+ error: "call_problem",
11390
+ typing: "call_your_turn",
11391
+ dormant: "call_your_turn",
11392
+ cards: "call_your_turn"
11393
+ };
11394
+ /**
11395
+ * The states whose reason the host's status line spells out under the header.
11396
+ * All but `ducked` are also announced, as in `widget-view.ts`.
11397
+ */
11398
+ var EXPLAINED = /* @__PURE__ */ new Set([
11399
+ "muted",
11400
+ "ducked",
11401
+ "reconnecting",
11402
+ "mic_blocked",
11403
+ "human",
11404
+ "offline",
11405
+ "error"
11406
+ ]);
11407
+ function callStatus(state, { ended, callerSpeaking }) {
11408
+ const explain = EXPLAINED.has(state);
11409
+ return {
11410
+ word: state === "listening" && callerSpeaking ? "voice_state_listening" : ended && !explain ? "call_ended" : CALL_WORDS[state],
11411
+ explain
11412
+ };
11413
+ }
11414
+ /** `mm:ss`, minutes uncapped. */
11415
+ function formatCallTime(ms) {
11416
+ const s = Math.max(0, Math.floor(ms / 1e3));
11417
+ return `${String(Math.floor(s / 60)).padStart(2, "0")}:${String(s % 60).padStart(2, "0")}`;
11418
+ }
11419
+ var IDLE_CALL_RECORD = {
11420
+ id: 0,
11421
+ active: false,
11422
+ startedAt: null,
11423
+ endedAt: null,
11424
+ from: 0,
11425
+ cart: []
11426
+ };
11427
+ function advanceCallRecord(prev, next) {
11428
+ const talking = next.phase === "live" || next.phase === "waiting";
11429
+ if (next.phase === "idle") {
11430
+ if (!prev.active) return prev;
11431
+ return {
11432
+ ...prev,
11433
+ active: false,
11434
+ endedAt: prev.startedAt === null ? null : next.now
11435
+ };
11436
+ }
11437
+ if (!prev.active) return {
11438
+ id: prev.id + 1,
11439
+ active: true,
11440
+ startedAt: talking ? next.now : null,
11441
+ endedAt: null,
11442
+ from: next.turns,
11443
+ cart: next.cart,
11444
+ checkoutFrom: next.checkout
11445
+ };
11446
+ const rec = talking && prev.startedAt === null ? {
11447
+ ...prev,
11448
+ startedAt: next.now
11449
+ } : prev;
11450
+ return !rec.checkout && next.checkout && next.checkout !== rec.checkoutFrom ? {
11451
+ ...rec,
11452
+ checkout: true
11453
+ } : rec;
11454
+ }
11455
+ function useCallRecord(phase, turns, cart, checkout) {
11456
+ const ref = useRef(IDLE_CALL_RECORD);
11457
+ const mounted = useRef(false);
11458
+ useEffect(() => {
11459
+ mounted.current = true;
11460
+ }, []);
11461
+ ref.current = advanceCallRecord(ref.current, {
11462
+ phase,
11463
+ now: performance.now(),
11464
+ turns: mounted.current ? turns.length : turns.findLastIndex((turn) => turn.event === "call_started") + 1,
11465
+ cart: cart ?? [],
11466
+ checkout
11467
+ });
11468
+ return ref.current;
11469
+ }
11470
+ /** The titles whose quantity grew since the call began, in basket order. */
11471
+ function addedDuringCall(before, after) {
11472
+ const had = new Map(before.map((line) => [line.key, line.quantity]));
11473
+ return after.filter((line) => line.quantity > (had.get(line.key) ?? 0)).map((l) => l.title);
11474
+ }
11475
+ /** A call that is live and counting: the timer and the launcher's label tick. */
11476
+ var counting = (record) => record.active && record.startedAt !== null;
11477
+ /** `performance.now()`, re-read once a second while `running`. */
11478
+ function useNow(running) {
11479
+ const [now, setNow] = useState(() => performance.now());
11480
+ useEffect(() => {
11481
+ if (!running) return;
11482
+ setNow(performance.now());
11483
+ const id = window.setInterval(() => setNow(performance.now()), 1e3);
11484
+ return () => window.clearInterval(id);
11485
+ }, [running]);
11486
+ return now;
11487
+ }
11488
+ var NO_TURNS = [];
11489
+ /**
11490
+ * The panel's call lifecycle. A running call takes the panel over unless the
11491
+ * shopper chose "Type instead"; an ended one shows its summary until they
11492
+ * close it. Both choices hold for that call only: the next one shows again.
11493
+ * Absent `call` (the marketing preview), the call view never shows.
11494
+ */
11495
+ function useCallMode(voice, call) {
11496
+ const record = useCallRecord(voice?.phase ?? "idle", call?.turns ?? NO_TURNS, call?.cart, call?.checkout);
11497
+ const [textCall, setTextCall] = useState(0);
11498
+ const [closedCall, setClosedCall] = useState(0);
11499
+ const now = useNow(counting(record));
11500
+ return {
11501
+ shown: call !== void 0 && voice !== void 0 && textCall !== record.id && (record.active || record.endedAt !== null && closedCall !== record.id),
11502
+ record,
11503
+ launcherLabel: counting(record) ? `${callText(call?.messages ?? defaultWidgetMessages, "call_on_call")} · ${formatCallTime(now - record.startedAt)}` : void 0,
11504
+ toText: () => setTextCall(record.id),
11505
+ backToCall: () => setTextCall(0),
11506
+ closeSummary: () => setClosedCall(record.id)
11507
+ };
11508
+ }
11509
+ function CallTimer({ record }) {
11510
+ const now = useNow(counting(record));
11511
+ return /* @__PURE__ */ jsxs("span", {
11512
+ role: "timer",
11513
+ "data-testid": "widget-call-timer",
11514
+ className: "wgc-tm",
11515
+ children: [counting(record) ? /* @__PURE__ */ jsx("i", {
11516
+ "aria-hidden": true,
11517
+ "data-testid": "widget-call-live"
11518
+ }) : null, record.startedAt === null ? "00:00" : formatCallTime((record.endedAt ?? now) - record.startedAt)]
11519
+ });
11520
+ }
11521
+ /**
11522
+ * The widget generation's call: a header that names the state, the call's
11523
+ * own turns with their cards, the "Try saying" lines and the call controls,
11524
+ * then the summary once it ends. Styled by `styles/call-view.css` (`.wgc`).
11525
+ * See docs/CONCIERGE_GENERATIONS.md "Call mode".
11526
+ */
11527
+ function CallView({ state, callerSpeaking = false, turns, renderCards, suggestions, onSay, checkout = false, cart, messages, voice, name, actions, record, bot, avatar, hint, onText, onBackToChat, testIds }) {
11528
+ const t = (key) => callText(messages, key);
11529
+ const ended = !record.active;
11530
+ const { word, explain } = callStatus(state, {
11531
+ ended,
11532
+ callerSpeaking
11533
+ });
11534
+ const [said, setSaid] = useState([]);
11535
+ 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);
11536
+ const streamRef = useRef(null);
11537
+ const contentRef = useRef(null);
11538
+ const rootRef = useRef(null);
11539
+ useEffect(() => {
11540
+ const root = rootRef.current;
11541
+ const active = (root?.getRootNode())?.activeElement;
11542
+ if (root && (!active || active === document.body)) (root.querySelector("button.wgc-mk,[data-end]") ?? root.querySelector(".wgc-ctl button,.wgc-sum button"))?.focus();
11543
+ }, []);
11544
+ useFollowBottom(streamRef, contentRef, shown.length, void 0, true);
11545
+ const interrupting = voice.agentSpeaking === true && voice.onInterrupt !== void 0;
11546
+ const fixable = voice.phase === "blocked" && voice.onFixPermission !== void 0;
11547
+ const lines = !ended && onSay && (state === "muted" || state === "listening" && !callerSpeaking) ? suggestions.filter((line) => !said.includes(line)) : [];
11548
+ const added = ended ? addedDuringCall(record.cart, cart ?? []) : [];
11549
+ const mark = /* @__PURE__ */ jsx(AvatarFace, {
11550
+ avatar,
11551
+ state: ended ? "idle" : bot,
11552
+ size: "sm",
11553
+ markSize: 44,
11554
+ muted: voice.muted === true && !ended,
11555
+ ...name !== void 0 ? { name } : {}
11556
+ });
11557
+ return /* @__PURE__ */ jsxs("div", {
11558
+ ref: rootRef,
11559
+ "data-testid": "widget-call-view",
11560
+ "data-call-state": state,
11561
+ className: "wgc",
11562
+ children: [
11563
+ /* @__PURE__ */ jsxs("div", {
11564
+ className: "wgc-hd",
11565
+ children: [
11566
+ interrupting ? /* @__PURE__ */ jsx("button", {
11567
+ type: "button",
11568
+ "data-testid": "widget-interrupt",
11569
+ "aria-label": voice.labels.interrupt ?? defaultWidgetMessages.dock_interrupt,
11570
+ onClick: () => voice.onInterrupt?.("tap"),
11571
+ className: "wgc-mk",
11572
+ children: mark
11573
+ }) : /* @__PURE__ */ jsx("span", {
11574
+ className: "wgc-mk",
11575
+ children: mark
11576
+ }),
11577
+ /* @__PURE__ */ jsx("p", {
11578
+ "data-testid": "widget-voice-state",
11579
+ className: "wgc-st",
11580
+ children: t(word)
11581
+ }),
11582
+ /* @__PURE__ */ jsx("span", {
11583
+ role: "status",
11584
+ "data-testid": "widget-call-announce",
11585
+ className: "sr-only",
11586
+ children: (ended || explain && state !== "ducked") && !(explain && hint) ? t(word) : null
11587
+ }),
11588
+ /* @__PURE__ */ jsx(CallTimer, { record }),
11589
+ actions
11590
+ ]
11591
+ }),
11592
+ explain && hint || fixable ? /* @__PURE__ */ jsxs("div", {
11593
+ className: "wgc-hint",
11594
+ children: [explain ? hint : null, fixable ? /* @__PURE__ */ jsx("button", {
11595
+ type: "button",
11596
+ "data-testid": "widget-fix-permission",
11597
+ onClick: voice.onFixPermission,
11598
+ className: "wgc-chip",
11599
+ children: voice.labels.fixBrowser ?? defaultWidgetMessages.dock_fix_browser
11600
+ }) : null]
11601
+ }) : null,
11602
+ /* @__PURE__ */ jsx("div", {
11603
+ ref: streamRef,
11604
+ role: "log",
11605
+ className: "wgc-log no-scrollbar",
11606
+ children: /* @__PURE__ */ jsx("div", {
11607
+ ref: contentRef,
11608
+ children: shown.map((turn, i) => {
11609
+ const you = turn.speaker === "caller";
11610
+ return /* @__PURE__ */ jsxs("div", {
11611
+ className: "wgc-t",
11612
+ "data-you": you ? "" : void 0,
11613
+ children: [turn.text.trim() !== "" ? /* @__PURE__ */ jsxs("p", {
11614
+ dir: textDirectionFor(turn.locale),
11615
+ lang: turn.locale,
11616
+ "data-testid": you ? "widget-turn-caller" : "widget-turn-agent",
11617
+ "data-cut": turn.cut || turn.filler ? "" : void 0,
11618
+ "data-cur": i === shown.length - 1 && !ended ? "" : void 0,
11619
+ "data-partial": turn.final === false ? "" : void 0,
11620
+ className: "wgc-tx",
11621
+ children: [stripBidiControls(turn.text), turn.cut ? /* @__PURE__ */ jsx("span", {
11622
+ className: "wgc-cut",
11623
+ children: t("call_interrupted")
11624
+ }) : null]
11625
+ }) : null, !you && turn.cards && turn.cards.items.length > 0 ? /* @__PURE__ */ jsx("div", {
11626
+ className: "wgc-cards",
11627
+ children: renderCards(turn.cards)
11628
+ }) : null]
11629
+ }, i);
11630
+ })
11631
+ })
11632
+ }),
11633
+ lines.length > 0 ? /* @__PURE__ */ jsxs("div", {
11634
+ className: "wgc-say",
11635
+ children: [/* @__PURE__ */ jsx("p", { children: t("call_try_saying") }), /* @__PURE__ */ jsx("ul", {
11636
+ "data-testid": "widget-suggestions",
11637
+ "aria-label": messages.suggestions_label,
11638
+ children: lines.map((line) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
11639
+ type: "button",
11640
+ "data-testid": "widget-suggestion",
11641
+ className: "wgc-chip",
11642
+ onClick: () => {
11643
+ Promise.resolve(onSay?.(line)).then((sent) => {
11644
+ if (sent !== false) setSaid((prev) => [...prev, line]);
11645
+ });
11646
+ },
11647
+ children: line
11648
+ }) }, line))
11649
+ })]
11650
+ }) : null,
11651
+ ended ? /* @__PURE__ */ jsxs("section", {
11652
+ "data-testid": "widget-call-summary",
11653
+ className: "wgc-sum",
11654
+ children: [
11655
+ added.length > 0 ? /* @__PURE__ */ jsx("p", { children: formatMessage(t("call_summary_added"), { items: added.join(", ") }) }) : null,
11656
+ checkout ? /* @__PURE__ */ jsx("p", { children: t("call_summary_checkout") }) : null,
11657
+ /* @__PURE__ */ jsx("button", {
11658
+ type: "button",
11659
+ "data-testid": "widget-call-back-to-chat",
11660
+ onClick: onBackToChat,
11661
+ children: t("call_back_to_chat")
11662
+ })
11663
+ ]
11664
+ }) : /* @__PURE__ */ jsxs("div", {
11665
+ className: "wgc-ctl",
11666
+ children: [
11667
+ /* @__PURE__ */ jsx(MicButton, {
11668
+ voice,
11669
+ testId: testIds?.mic
11670
+ }),
11671
+ voice.onEnd !== void 0 ? /* @__PURE__ */ jsx("button", {
11672
+ type: "button",
11673
+ "data-testid": testIds?.endCall,
11674
+ "data-end": "",
11675
+ onClick: voice.onEnd,
11676
+ "aria-label": voice.labels.end ?? "",
11677
+ children: /* @__PURE__ */ jsx(PhoneOff, {})
11678
+ }) : null,
11679
+ /* @__PURE__ */ jsx("button", {
11680
+ type: "button",
11681
+ "data-testid": "widget-call-to-text",
11682
+ onClick: onText,
11683
+ "aria-label": t("call_to_text"),
11684
+ children: /* @__PURE__ */ jsx("svg", {
11685
+ viewBox: "0 0 24 24",
11686
+ width: "20",
11687
+ height: "20",
11688
+ fill: "none",
11689
+ stroke: "currentColor",
11690
+ strokeWidth: "1.75",
11691
+ "aria-hidden": true,
11692
+ children: /* @__PURE__ */ jsx("path", { d: "M4 20l1.3-4A8 8 0 1 1 8 19z" })
11693
+ })
11694
+ })
11695
+ ]
11696
+ })
11697
+ ]
11698
+ });
11699
+ }
11700
+ //#endregion
11701
+ //#region src/widget/concierge-shell.tsx
11702
+ /**
11703
+ * Maps the call onto the pill it shows, reusing fields `ConciergeShellVoice`
11704
+ * already carries rather than inventing new plumbing:
11705
+ *
11706
+ * - `'connecting'` → `connecting`
11707
+ * - `'waiting'` (the agent is thinking, between the caller's turn ending and
11708
+ * the reply starting) → `thinking`
11709
+ * - `'live'` + `agentSpeaking` → `speaking`
11710
+ * - `'live'` otherwise → `listening`
11711
+ * - `'idle'` / `'blocked'` → `null`, no pill
11712
+ *
11713
+ * `agentSpeaking` is already a real field on {@link ConciergeShellVoice} —
11714
+ * this function only reads it, it does not require every caller to start
11715
+ * setting it; a caller that never populates it simply never reaches
11716
+ * `'speaking'`, which is exactly the same "renders sensibly with what it is
11717
+ * given" contract every other optional field on this interface follows.
11718
+ */
11719
+ function voiceStatePillState(voice) {
11720
+ const phase = voice?.phase;
11721
+ return phase === "connecting" ? "connecting" : phase === "waiting" ? "thinking" : phase === "live" ? voice?.agentSpeaking ? "speaking" : "listening" : null;
11722
+ }
11723
+ function ConciergeShell({ open, onOpenChange, state, messageArrived = false, launcher, launcherInitials, launcherVariant, agentName, typing = false, operatorName, avatar = "orb", labels, children, badge, draft, onDraftChange, onSubmit, composerDisabled = false, voice, call, announcement, skin, skinStyle, idPrefix = "concierge", scrollKey, composerLeading, testIds, position = DEFAULT_CONCIERGE_POSITION, onPositionChange, attribution, privacyChoices, focusOnOpen = true }) {
11724
+ const triggerId = `${idPrefix}-trigger`;
11725
+ const inputId = `${idPrefix}-input`;
11726
+ const panelRef = useRef(null);
11727
+ const transcriptRef = useRef(null);
11728
+ /** The transcript's content box — what grows as a reply streams in. */
11729
+ const transcriptContentRef = useRef(null);
11730
+ const callMode = useCallMode(voice, call);
11731
+ const callLabel = callMode.launcherLabel;
11732
+ /** By id within the shell's own root: a shadow root has its own ids, which `document` cannot see. */
11733
+ const byId = (id) => (panelRef.current?.getRootNode())?.getElementById(id);
11734
+ const focusInput = () => window.setTimeout(() => byId(inputId)?.focus(), 0);
11037
11735
  /**
11038
- * Whether the transcript is following the conversation.
11039
- *
11040
- * True while the visitor is at (or near) the bottom, false the moment they
11041
- * scroll up to re-read something — see the observer below for why the
11042
- * distinction has to exist rather than always scrolling.
11736
+ * The knot's tighten flourish is EDGE-triggered (one play per bump of
11737
+ * `tightenKey`), so it is bumped only on the rising edge of
11738
+ * `messageArrived`, not on every render where it stays `true`.
11043
11739
  */
11044
- const following = useRef(true);
11045
- const lastScrollKey = useRef(scrollKey);
11740
+ const wasMessageArrived = useRef(false);
11741
+ const [knotTightenKey, setKnotTightenKey] = useState(0);
11046
11742
  useEffect(() => {
11047
- const el = transcriptRef.current;
11048
- const before = lastScrollKey.current;
11049
- const shrank = typeof scrollKey === "number" && typeof before === "number" && scrollKey < before;
11050
- lastScrollKey.current = scrollKey;
11051
- if (shrank || typeof el?.scrollTo !== "function") return;
11052
- following.current = true;
11053
- el.scrollTo({
11054
- top: el.scrollHeight,
11055
- behavior: "smooth"
11056
- });
11057
- }, [scrollKey, state]);
11743
+ if (messageArrived && !wasMessageArrived.current) setKnotTightenKey((k) => k + 1);
11744
+ wasMessageArrived.current = messageArrived;
11745
+ }, [messageArrived]);
11058
11746
  /**
11059
- * Follow the reply as it STREAMS, not just as it starts.
11060
- *
11061
- * `scrollKey` is `turns.length` (`voice-widget.tsx`), so the effect above
11062
- * fires once, when the agent's turn is appended and still empty or one
11063
- * token long. Everything after that arrives by SSE into the SAME turn: the
11064
- * bubble grows downward under a scroll position that was correct when it
11065
- * was pinned and is stale a word later. The visitor watched the TOP of a
11066
- * long answer and had to scroll for every line of it — the newest text, the
11067
- * only part they had not read, was the part off-screen.
11068
- *
11069
- * A `ResizeObserver` on the content is what closes that gap: it fires on
11070
- * every layout change the growing text produces, at whatever rate the
11071
- * tokens land, with no polling and no dependency on how the host chooses to
11072
- * stream. `scrollKey` still owns the jump to a NEW turn; this owns staying
11073
- * there while that turn fills in.
11074
- *
11075
- * Gated on `following` so it never fights the visitor. Scrolling up to
11076
- * re-read an earlier answer while the agent is still typing is an ordinary
11077
- * thing to do, and a transcript that yanks itself back down every 50ms
11078
- * makes it impossible. `atBottom` uses a tolerance rather than an equality
11079
- * — fractional scroll metrics on zoomed or hi-dpi displays never land
11080
- * exactly, and smooth scrolling is still in flight when the next resize
11081
- * arrives.
11082
- *
11083
- * `behavior: 'auto'`, unlike the jump above: a smooth scroll started every
11084
- * time a token lands never finishes before the next one restarts it, which
11085
- * reads as the transcript lagging behind its own text.
11747
+ * Follow the reply as it STREAMS, not just as it starts: `scrollKey` fires
11748
+ * once per turn, and the tokens after that grow the content box. The
11749
+ * viewport is watched too: the status line and the call row change its
11750
+ * height.
11086
11751
  */
11087
- useEffect(() => {
11088
- const el = transcriptRef.current;
11089
- if (!el || typeof el.scrollTo !== "function") return;
11090
- if (typeof ResizeObserver === "undefined") return;
11091
- const atBottom = () => el.scrollHeight - el.scrollTop - el.clientHeight <= FOLLOW_TOLERANCE_PX;
11092
- let lastTop = el.scrollTop;
11093
- const onScroll = () => {
11094
- if (atBottom()) following.current = true;
11095
- else if (el.scrollTop < lastTop) following.current = false;
11096
- lastTop = el.scrollTop;
11097
- };
11098
- const observer = new ResizeObserver(() => {
11099
- if (!following.current) return;
11100
- el.scrollTo({
11101
- top: el.scrollHeight,
11102
- behavior: "auto"
11103
- });
11104
- });
11105
- const content = transcriptContentRef.current;
11106
- if (content) observer.observe(content);
11107
- observer.observe(el);
11108
- el.addEventListener("scroll", onScroll, { passive: true });
11109
- return () => {
11110
- observer.disconnect();
11111
- el.removeEventListener("scroll", onScroll);
11112
- };
11113
- }, [open]);
11752
+ useFollowBottom(transcriptRef, transcriptContentRef, scrollKey, state);
11114
11753
  const skipFocus = useRef(!focusOnOpen);
11115
11754
  const handleClose = useCallback(() => {
11116
11755
  onOpenChange(false);
11117
11756
  window.setTimeout(() => {
11118
- document.getElementById(triggerId)?.focus({ preventScroll: true });
11757
+ byId(triggerId)?.focus({ preventScroll: true });
11119
11758
  }, 400);
11120
11759
  }, [onOpenChange, triggerId]);
11121
11760
  useEffect(() => {
@@ -11133,15 +11772,16 @@ function ConciergeShell({ open, onOpenChange, state, messageArrived = false, lau
11133
11772
  if (focusable.length === 0) return;
11134
11773
  const first = focusable[0];
11135
11774
  const last = focusable[focusable.length - 1];
11136
- if (e.shiftKey && document.activeElement === first) {
11775
+ const active = panel.getRootNode().activeElement;
11776
+ if (e.shiftKey && active === first) {
11137
11777
  e.preventDefault();
11138
11778
  last.focus();
11139
- } else if (!e.shiftKey && document.activeElement === last) {
11779
+ } else if (!e.shiftKey && active === last) {
11140
11780
  e.preventDefault();
11141
11781
  first.focus();
11142
11782
  }
11143
11783
  };
11144
- const focusTimer = skipFocus.current ? void 0 : window.setTimeout(() => document.getElementById(inputId)?.focus(), 120);
11784
+ const focusTimer = skipFocus.current ? void 0 : window.setTimeout(() => byId(inputId)?.focus(), 120);
11145
11785
  skipFocus.current = false;
11146
11786
  window.addEventListener("keydown", onKeyDown);
11147
11787
  return () => {
@@ -11153,52 +11793,23 @@ function ConciergeShell({ open, onOpenChange, state, messageArrived = false, lau
11153
11793
  handleClose,
11154
11794
  inputId
11155
11795
  ]);
11156
- /**
11157
- * A call is running — anything but `idle`, including the phases that are not
11158
- * speakable yet. The composer dims from the moment the caller commits to
11159
- * voice, not only once the transport catches up.
11160
- */
11796
+ /** A call is running — anything but `idle`, including the phases not speakable yet. */
11161
11797
  const inCall = voice !== void 0 && voice.phase !== "idle";
11162
- /**
11163
- * The voice-state pill's own state — `null` for `'idle'` (covered by
11164
- * `inCall` too) AND `'blocked'` (NOT covered by `inCall`, which is why this
11165
- * is its own value rather than reusing that boolean: a refused microphone
11166
- * is still "a call", but it is not one of the four states the pill knows
11167
- * how to draw — see `voiceStatePillState`'s own doc comment).
11168
- */
11798
+ /** `null` for `idle` and `blocked` — see `voiceStatePillState`. */
11169
11799
  const voicePillState = voiceStatePillState(voice);
11170
- /**
11171
- * The call has been asked for and has not answered yet — the transport
11172
- * dialing, or the browser's own microphone prompt still open in front of
11173
- * the caller (the host folds both into this one phase; see
11174
- * `useVoiceSession`'s `micPending` and `host-widget.tsx`'s `callPhase`).
11175
- *
11176
- * For as long as it lasts, the round control is a SPINNER and is inert. A
11177
- * microphone glyph here says "talk now" during the one stretch where
11178
- * talking provably does nothing, and a pressable one turns a single
11179
- * impatient gesture into either a second call or a mute of a call that does
11180
- * not exist yet. The wait ends by itself, in one of two directions: `live`
11181
- * (the microphone comes back) or `blocked` (the existing refused
11182
- * presentation) — never in a spinner nobody can clear.
11183
- */
11184
- const connecting = voice?.phase === "connecting";
11185
11800
  /** No voice leg to press at all, or a microphone the browser refused. */
11186
11801
  const micUnusable = voice !== void 0 && (voice.disabled === true || voice.phase === "blocked");
11187
- /** Same fallback contract as the pill's own labels — see `voiceStatePillLabel`. */
11188
- const connectingLabel = voice?.labels.connecting ?? defaultWidgetMessages.voice_state_connecting;
11189
- /**
11190
- * Start, mute or unmute — whichever the one round control means right now —
11191
- * or, ahead of all three, the REASON it means nothing at all.
11192
- *
11193
- * `labels.unavailable` wins whenever `micUnusable` holds, because none of
11194
- * the other three describe this button any more: every one of them names an
11195
- * action, and an unusable control performs none. It is checked before
11196
- * `connecting` too, so a host that disables the control mid-dial (an
11197
- * escalation landing while the transport is still connecting) never leaves
11198
- * "Connecting" as the name of a button that will now never connect. See
11199
- * `ConciergeShellVoice.labels.unavailable`.
11200
- */
11201
- const micLabel = micUnusable ? voice?.labels.unavailable ?? voice?.labels.start ?? "" : connecting ? connectingLabel : inCall ? (voice?.muted === true ? voice.labels.unmute : voice.labels.mute) ?? voice.labels.start : voice?.labels.start ?? "";
11802
+ const showEnd = inCall && voice.onEnd !== void 0;
11803
+ /** The call view's own controls, kept in reach while it is not shown. */
11804
+ const interrupting = inCall && voice.agentSpeaking === true && voice.onInterrupt !== void 0;
11805
+ const fixable = voice?.phase === "blocked" && voice.onFixPermission !== void 0;
11806
+ const closeButton = /* @__PURE__ */ jsx("button", {
11807
+ type: "button",
11808
+ className: "wgp-ib",
11809
+ "aria-label": labels.close,
11810
+ onClick: handleClose,
11811
+ children: /* @__PURE__ */ jsx(X, {})
11812
+ });
11202
11813
  const counting = draft.length >= WIDGET_MESSAGE_COUNT_FROM;
11203
11814
  const submit = (e) => {
11204
11815
  e.preventDefault();
@@ -11222,268 +11833,257 @@ function ConciergeShell({ open, onOpenChange, state, messageArrived = false, lau
11222
11833
  hidden: open,
11223
11834
  avatar,
11224
11835
  ...launcher !== void 0 ? { spec: launcher } : {},
11225
- ...launcherInitials !== void 0 ? { initials: launcherInitials } : {}
11836
+ ...launcherInitials !== void 0 ? { initials: launcherInitials } : {},
11837
+ ...launcherVariant !== void 0 ? { launcher: launcherVariant } : {},
11838
+ ...agentName !== void 0 ? { agentName } : {},
11839
+ ...callLabel !== void 0 ? { callLabel } : {}
11226
11840
  }),
11227
11841
  /* @__PURE__ */ jsx("div", {
11228
11842
  "aria-hidden": true,
11229
- className: cn("bg-brand-ink/10 fixed inset-0 z-40 backdrop-blur-[2px] transition-opacity duration-500", open ? "pointer-events-auto opacity-100" : "pointer-events-none opacity-0")
11843
+ className: cn("fixed inset-0 z-40 transition-opacity duration-300 max-sm:bg-black/25", open ? "pointer-events-auto opacity-100" : "pointer-events-none opacity-0")
11230
11844
  }),
11231
11845
  /* @__PURE__ */ jsx("div", {
11232
11846
  "aria-hidden": !open,
11233
- className: cn("pointer-events-none fixed inset-x-0 z-50 flex", panelClasses(position)),
11234
- children: /* @__PURE__ */ jsxs("div", {
11235
- className: cn("relative flex flex-col items-center", open && (attribution || privacyChoices) && "pb-[calc(2.25rem+env(safe-area-inset-bottom,0px))]"),
11236
- children: [
11847
+ className: cn("wgp-row pointer-events-none fixed inset-x-0 z-50 flex", panelClasses(position)),
11848
+ children: /* @__PURE__ */ jsx("div", {
11849
+ ref: panelRef,
11850
+ role: "dialog",
11851
+ "aria-modal": "true",
11852
+ "aria-label": labels.dialog,
11853
+ "data-testid": testIds?.panel,
11854
+ "data-open": open ? "" : void 0,
11855
+ className: cn("wgp origin-bottom", open ? "pointer-events-auto" : "pointer-events-none"),
11856
+ children: callMode.shown && call && voice ? /* @__PURE__ */ jsx(CallView, {
11857
+ ...call,
11858
+ voice,
11859
+ ...agentName !== void 0 ? { name: agentName } : {},
11860
+ checkout: callMode.record.checkout,
11861
+ actions: closeButton,
11862
+ record: callMode.record,
11863
+ bot: state,
11864
+ avatar,
11865
+ hint: badge,
11866
+ onText: () => {
11867
+ callMode.toText();
11868
+ focusInput();
11869
+ },
11870
+ onBackToChat: () => {
11871
+ callMode.closeSummary();
11872
+ focusInput();
11873
+ },
11874
+ testIds: {
11875
+ ...testIds?.mic !== void 0 ? { mic: testIds.mic } : {},
11876
+ ...testIds?.endCall !== void 0 ? { endCall: testIds.endCall } : {}
11877
+ }
11878
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [
11237
11879
  /* @__PURE__ */ jsxs("div", {
11238
- ref: panelRef,
11239
- role: "dialog",
11240
- "aria-modal": "true",
11241
- "aria-label": labels.dialog,
11242
- "data-testid": testIds?.panel,
11243
- className: cn("origin-bottom rounded-full transition-[transform,opacity] duration-[700ms] motion-reduce:transition-none", open ? "pointer-events-auto aspect-[5/8] w-[min(97vw,50dvh)] min-h-0 scale-100 opacity-100 [container-type:size]" : "pointer-events-none size-16 scale-90 opacity-0"),
11244
- style: { transitionTimingFunction: "cubic-bezier(0.16, 1, 0.3, 1)" },
11880
+ className: "wgp-hd",
11245
11881
  children: [
11246
- /* @__PURE__ */ jsx("div", {
11247
- "aria-hidden": true,
11248
- className: cn("pointer-events-none absolute -inset-4 rounded-full opacity-25 blur-xl motion-reduce:animate-none", open ? "animate-[spin_18s_linear_infinite]" : "opacity-0"),
11249
- style: { background: "conic-gradient(from 0deg, color-mix(in oklab, var(--brand-plum) 14%, transparent), color-mix(in oklab, var(--brand-rose) 16%, transparent), color-mix(in oklab, var(--brand-amber) 16%, transparent), color-mix(in oklab, var(--brand-plum) 14%, transparent))" }
11882
+ /* @__PURE__ */ jsx("span", {
11883
+ className: "wgp-mk",
11884
+ children: /* @__PURE__ */ jsx(AvatarFace, {
11885
+ avatar,
11886
+ state,
11887
+ size: "sm",
11888
+ markSize: 34,
11889
+ messageArrived,
11890
+ tightenKey: knotTightenKey,
11891
+ ...agentName !== void 0 ? { name: agentName } : {}
11892
+ })
11250
11893
  }),
11251
- /* @__PURE__ */ jsx("div", {
11252
- "aria-hidden": true,
11253
- className: "pointer-events-none absolute inset-0 rounded-full p-[1.5px]",
11254
- style: {
11255
- background: "conic-gradient(from 140deg, color-mix(in oklab, var(--brand-plum) 45%, transparent), color-mix(in oklab, var(--brand-rose) 40%, transparent), color-mix(in oklab, var(--brand-amber) 45%, transparent), color-mix(in oklab, var(--brand-plum) 45%, transparent))",
11256
- WebkitMask: "linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)",
11257
- WebkitMaskComposite: "xor",
11258
- maskComposite: "exclude"
11259
- }
11260
- }),
11261
- /* @__PURE__ */ jsx("button", {
11262
- type: "button",
11263
- "aria-label": labels.close,
11264
- onClick: handleClose,
11265
- className: cn("absolute end-[8%] top-[8%] z-20 rounded-full bg-[var(--widget-card)] p-1.5 text-[var(--widget-foreground)] shadow-[0_2px_10px_-2px_color-mix(in_oklab,var(--brand-plum)_35%,transparent)] ring-1 ring-black/5", "hover:text-brand-plum hover:ring-brand-plum/30 focus-visible:ring-brand-plum/50 focus-visible:ring-2 focus-visible:outline-none", open ? "opacity-100 delay-[350ms]" : "opacity-0"),
11266
- children: /* @__PURE__ */ jsx(X, { className: "size-4" })
11894
+ /* @__PURE__ */ jsxs("div", {
11895
+ className: "wgp-hd-t",
11896
+ children: [/* @__PURE__ */ jsx("p", {
11897
+ className: "wgp-name",
11898
+ dir: "auto",
11899
+ children: labels.title ?? labels.dialog
11900
+ }), /* @__PURE__ */ jsxs("div", {
11901
+ className: "wgp-sub",
11902
+ children: [
11903
+ /* @__PURE__ */ jsx("span", {
11904
+ "data-testid": "widget-voice-state",
11905
+ className: cn("wgp-pill", voicePillState ? "opacity-100" : "opacity-0"),
11906
+ children: voicePillState ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
11907
+ "aria-hidden": true,
11908
+ "data-live": voicePillState === "speaking" || voicePillState === "listening" ? "" : void 0,
11909
+ className: cn(voicePillState !== "listening" && "animate-pulse motion-reduce:animate-none")
11910
+ }), /* @__PURE__ */ jsx("span", { children: voice?.labels[voicePillState] ?? defaultWidgetMessages[`voice_state_${voicePillState}`] })] }) : null
11911
+ }),
11912
+ operatorName === void 0 ? null : /* @__PURE__ */ jsx("span", {
11913
+ "data-testid": "widget-operator-name",
11914
+ dir: "auto",
11915
+ children: operatorName
11916
+ }),
11917
+ badge
11918
+ ]
11919
+ })]
11267
11920
  }),
11268
11921
  /* @__PURE__ */ jsxs("div", {
11269
- className: cn("relative flex h-full w-full flex-col items-center overflow-clip rounded-full border border-white/40 bg-[var(--widget-card)] backdrop-blur-xl", "shadow-[0_30px_80px_-20px_color-mix(in_oklab,var(--brand-plum)_25%,transparent),inset_0_1px_0_rgba(255,255,255,0.75)]"),
11922
+ className: "wgp-act",
11923
+ children: [voice && !inCall && !micUnusable ? /* @__PURE__ */ jsx("button", {
11924
+ type: "button",
11925
+ className: "wgp-ib",
11926
+ "data-testid": "widget-voice-cta",
11927
+ "aria-label": voice.labels.start,
11928
+ title: voice.labels.start,
11929
+ onClick: voice.onStart,
11930
+ children: /* @__PURE__ */ jsx(Mic, {})
11931
+ }) : null, closeButton]
11932
+ })
11933
+ ]
11934
+ }),
11935
+ /* @__PURE__ */ jsx("div", {
11936
+ ref: transcriptRef,
11937
+ className: "wgp-msgs no-scrollbar",
11938
+ children: /* @__PURE__ */ jsxs("div", {
11939
+ ref: transcriptContentRef,
11940
+ children: [
11941
+ children,
11942
+ privacyChoices?.slot ? /* @__PURE__ */ jsx("div", {
11943
+ ref: privacyChoices.slot,
11944
+ className: "wgp-consent"
11945
+ }) : null,
11946
+ typing ? /* @__PURE__ */ jsxs("p", {
11947
+ "data-testid": "widget-typing-indicator",
11948
+ className: "wgp-typing",
11949
+ children: [/* @__PURE__ */ jsx("span", {
11950
+ className: "sr-only",
11951
+ children: defaultWidgetMessages.typing
11952
+ }), [
11953
+ 0,
11954
+ 1,
11955
+ 2
11956
+ ].map((i) => /* @__PURE__ */ jsx("span", {
11957
+ "aria-hidden": "true",
11958
+ style: {
11959
+ animationDelay: `${i * 150}ms`,
11960
+ animationDuration: "1.2s"
11961
+ }
11962
+ }, i))]
11963
+ }) : null
11964
+ ]
11965
+ })
11966
+ }),
11967
+ /* @__PURE__ */ jsxs("form", {
11968
+ className: "wgp-cz",
11969
+ onSubmit: submit,
11970
+ children: [
11971
+ showEnd || interrupting || fixable || call !== void 0 && inCall ? /* @__PURE__ */ jsxs("div", {
11972
+ className: "wgp-call",
11973
+ children: [
11974
+ fixable ? /* @__PURE__ */ jsx("button", {
11975
+ type: "button",
11976
+ onClick: voice.onFixPermission,
11977
+ "data-testid": "widget-fix-permission",
11978
+ className: "wgp-fix",
11979
+ children: voice.labels.fixBrowser ?? defaultWidgetMessages.dock_fix_browser
11980
+ }) : null,
11981
+ interrupting ? /* @__PURE__ */ jsx("button", {
11982
+ type: "button",
11983
+ onClick: () => voice.onInterrupt?.("tap"),
11984
+ "data-testid": "widget-interrupt",
11985
+ "aria-label": voice.labels.interrupt ?? defaultWidgetMessages.dock_interrupt,
11986
+ className: "wgp-ib",
11987
+ children: /* @__PURE__ */ jsx("svg", {
11988
+ viewBox: "0 0 24 24",
11989
+ width: "20",
11990
+ height: "20",
11991
+ "aria-hidden": true,
11992
+ children: /* @__PURE__ */ jsx("rect", {
11993
+ x: "7",
11994
+ y: "7",
11995
+ width: "10",
11996
+ height: "10",
11997
+ rx: "2",
11998
+ fill: "currentColor"
11999
+ })
12000
+ })
12001
+ }) : null,
12002
+ call !== void 0 && inCall ? /* @__PURE__ */ jsx("button", {
12003
+ type: "button",
12004
+ onClick: callMode.backToCall,
12005
+ "data-testid": "widget-back-to-call",
12006
+ className: "wgp-fix",
12007
+ children: callText(call.messages, "call_back_to_call")
12008
+ }) : null,
12009
+ showEnd ? /* @__PURE__ */ jsx("button", {
12010
+ type: "button",
12011
+ onClick: voice.onEnd,
12012
+ "data-testid": testIds?.endCall,
12013
+ title: voice.labels.end ?? "",
12014
+ "aria-label": voice.labels.end ?? "",
12015
+ "data-end": "",
12016
+ className: "wgp-ib",
12017
+ children: /* @__PURE__ */ jsx(PhoneOff, {})
12018
+ }) : null
12019
+ ]
12020
+ }) : null,
12021
+ counting ? /* @__PURE__ */ jsxs("span", {
12022
+ id: `${inputId}-count`,
12023
+ "data-testid": "widget-composer-count",
12024
+ className: "wgp-count",
12025
+ children: [
12026
+ draft.length,
12027
+ "/",
12028
+ WIDGET_MESSAGE_MAX_LENGTH
12029
+ ]
12030
+ }) : null,
12031
+ /* @__PURE__ */ jsxs("div", {
12032
+ className: "wgp-field",
11270
12033
  children: [
11271
- /* @__PURE__ */ jsx("div", {
11272
- "aria-hidden": true,
11273
- className: "pointer-events-none absolute -top-16 -right-10 h-56 w-56 rounded-full bg-[radial-gradient(circle,color-mix(in_oklab,var(--brand-amber)_7%,transparent),transparent_70%)] blur-2xl"
12034
+ composerLeading,
12035
+ /* @__PURE__ */ jsx("label", {
12036
+ htmlFor: inputId,
12037
+ className: "sr-only",
12038
+ children: labels.composerPlaceholder
11274
12039
  }),
11275
- /* @__PURE__ */ jsx("div", {
11276
- "aria-hidden": true,
11277
- className: "pointer-events-none absolute -bottom-20 -left-12 h-52 w-52 rounded-full bg-[radial-gradient(circle,color-mix(in_oklab,var(--brand-rose)_5%,transparent),transparent_70%)] blur-2xl"
12040
+ /* @__PURE__ */ jsx("input", {
12041
+ id: inputId,
12042
+ "data-testid": testIds?.input,
12043
+ value: draft,
12044
+ onChange: (e) => onDraftChange(e.target.value),
12045
+ placeholder: labels.composerPlaceholder,
12046
+ dir: "auto",
12047
+ maxLength: WIDGET_MESSAGE_MAX_LENGTH,
12048
+ ...counting ? { "aria-describedby": `${inputId}-count` } : {},
12049
+ disabled: composerDisabled,
12050
+ autoComplete: "off",
12051
+ className: cn("wgp-in", inCall && draft === "" && "opacity-60 focus:opacity-100")
11278
12052
  }),
11279
- /* @__PURE__ */ jsxs("div", {
11280
- className: cn("relative flex h-full w-full flex-col items-center justify-center px-2.5 py-1.5 transition-opacity duration-300 motion-reduce:transition-none", open ? "translate-y-0 opacity-100 delay-[300ms]" : "translate-y-2 opacity-0"),
11281
- children: [
11282
- /* @__PURE__ */ jsxs("div", {
11283
- className: "pointer-events-none absolute inset-x-0 top-1.5 z-10 flex flex-col items-center gap-1",
11284
- children: [/* @__PURE__ */ jsxs("div", {
11285
- className: "relative",
11286
- children: [/* @__PURE__ */ jsx("div", {
11287
- "aria-hidden": true,
11288
- className: "absolute inset-0 rounded-full bg-[radial-gradient(circle,var(--widget-card)_58%,transparent_72%)]"
11289
- }), /* @__PURE__ */ jsx(AvatarFace, {
11290
- avatar,
11291
- state,
11292
- size: "lg",
11293
- messageArrived,
11294
- tightenKey: knotTightenKey
11295
- })]
11296
- }), /* @__PURE__ */ jsx("div", {
11297
- "data-testid": "widget-voice-state",
11298
- className: cn("flex items-center gap-1.5 rounded-full bg-[var(--widget-card)] px-2.5 py-1 text-[10px] font-medium tracking-wider text-[var(--widget-foreground-muted)] uppercase [&:lang(ar)]:tracking-normal [&:lang(hi)]:tracking-normal ring-1 ring-black/5 shadow-[0_2px_8px_-2px_rgba(0,0,0,0.15)] transition-opacity duration-300", voicePillState ? "opacity-100" : "opacity-0"),
11299
- children: voicePillState ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
11300
- "aria-hidden": true,
11301
- className: cn("size-1.5 shrink-0 rounded-full", voicePillState !== "listening" && "animate-pulse motion-reduce:animate-none"),
11302
- style: { backgroundColor: voiceStatePillDotColor(voicePillState) }
11303
- }), /* @__PURE__ */ jsx("span", { children: voiceStatePillLabel(voicePillState, voice?.labels) })] }) : null
11304
- })]
11305
- }),
11306
- badge == null && operatorName === void 0 ? null : /* @__PURE__ */ jsxs("div", {
11307
- className: cn("z-10 w-[68%] shrink-0 text-center", voicePillState ? "mt-[124px]" : "mt-[104px]"),
11308
- children: [operatorName === void 0 ? null : /* @__PURE__ */ jsx("p", {
11309
- "data-testid": "widget-operator-name",
11310
- dir: "auto",
11311
- className: "text-[11px] font-medium text-[var(--widget-foreground-muted)]",
11312
- children: operatorName
11313
- }), badge]
11314
- }),
11315
- /* @__PURE__ */ jsx("div", {
11316
- ref: transcriptRef,
11317
- className: "no-scrollbar w-full min-h-0 flex-1 overflow-y-auto",
11318
- style: badge != null ? TRANSCRIPT_EDGE_FADE_WITH_BADGE : voicePillState ? TRANSCRIPT_EDGE_FADE_WITH_PILL : TRANSCRIPT_EDGE_FADE,
11319
- children: /* @__PURE__ */ jsxs("div", {
11320
- ref: transcriptContentRef,
11321
- children: [
11322
- children,
11323
- privacyChoices?.slot ? /* @__PURE__ */ jsx("div", { ref: privacyChoices.slot }) : null,
11324
- typing ? /* @__PURE__ */ jsxs("p", {
11325
- "data-testid": "widget-typing-indicator",
11326
- className: "flex items-center gap-1 px-1 py-1 text-[var(--widget-foreground-muted)]",
11327
- children: [/* @__PURE__ */ jsx("span", {
11328
- className: "sr-only",
11329
- children: defaultWidgetMessages.typing
11330
- }), [
11331
- 0,
11332
- 1,
11333
- 2
11334
- ].map((i) => /* @__PURE__ */ jsx("span", {
11335
- "aria-hidden": "true",
11336
- className: "h-1.5 w-1.5 animate-bounce rounded-full bg-current motion-reduce:animate-none",
11337
- style: {
11338
- animationDelay: `${i * 140}ms`,
11339
- animationDuration: "1s"
11340
- }
11341
- }, i))]
11342
- }) : null
11343
- ]
11344
- })
11345
- }),
11346
- /* @__PURE__ */ jsx("div", {
11347
- "aria-hidden": true,
11348
- className: "pointer-events-none absolute inset-x-0 bottom-0 z-10 bg-[linear-gradient(to_bottom,transparent,var(--widget-card)_38%,var(--widget-card))]",
11349
- style: { height: COMPOSER_GROUND_LEN }
11350
- }),
11351
- /* @__PURE__ */ jsx("div", {
11352
- className: "pointer-events-none absolute inset-x-0 z-20 flex justify-center",
11353
- style: { bottom: voice ? COMPOSER_BOTTOM_LEN : COMPOSER_BOTTOM_NO_VOICE_LEN },
11354
- children: /* @__PURE__ */ jsxs("div", {
11355
- className: cn("flex w-[71%] flex-col items-center gap-2.5", open ? "pointer-events-auto" : "pointer-events-none"),
11356
- style: { maxWidth: COMPOSER_MAX_WIDTH_LEN },
11357
- children: [/* @__PURE__ */ jsxs("form", {
11358
- className: "flex w-full items-center gap-2",
11359
- onSubmit: submit,
11360
- children: [composerLeading, /* @__PURE__ */ jsxs("div", {
11361
- className: "relative flex-1",
11362
- children: [
11363
- /* @__PURE__ */ jsx("label", {
11364
- htmlFor: inputId,
11365
- className: "sr-only",
11366
- children: labels.composerPlaceholder
11367
- }),
11368
- /* @__PURE__ */ jsx("input", {
11369
- id: inputId,
11370
- "data-testid": testIds?.input,
11371
- value: draft,
11372
- onChange: (e) => onDraftChange(e.target.value),
11373
- placeholder: labels.composerPlaceholder,
11374
- dir: "auto",
11375
- maxLength: WIDGET_MESSAGE_MAX_LENGTH,
11376
- ...counting ? { "aria-describedby": `${inputId}-count` } : {},
11377
- disabled: composerDisabled,
11378
- className: cn("border-brand-plum/12 h-[40px] w-full rounded-3xl border bg-[var(--widget-chip)] ps-4 pe-12 text-[16px] [@media(min-width:640px)_and_(pointer:fine)]:text-[14px] text-[var(--widget-foreground)] placeholder:text-[var(--widget-foreground-muted)]", "focus:border-brand-plum/30 focus:ring-brand-plum/15 transition-[border-color] focus:bg-[var(--widget-bubble)] focus:ring-2 focus:outline-none disabled:opacity-50", inCall && draft === "" && "opacity-60 focus:opacity-100")
11379
- }),
11380
- counting ? /* @__PURE__ */ jsxs("span", {
11381
- id: `${inputId}-count`,
11382
- "data-testid": "widget-composer-count",
11383
- className: "absolute end-4 -top-5 text-[11px] text-[var(--widget-foreground-muted)] tabular-nums",
11384
- children: [
11385
- draft.length,
11386
- "/",
11387
- WIDGET_MESSAGE_MAX_LENGTH
11388
- ]
11389
- }) : null,
11390
- draft.trim() && /* @__PURE__ */ jsx("button", {
11391
- type: "submit",
11392
- "aria-label": labels.send,
11393
- "data-testid": testIds?.send,
11394
- disabled: composerDisabled,
11395
- className: "from-brand-plum to-brand-rose text-[var(--widget-accent-foreground)] absolute end-2 top-1/2 flex size-9 -translate-y-1/2 items-center justify-center rounded-full bg-gradient-to-br transition-[transform,opacity] hover:scale-105 disabled:opacity-40",
11396
- children: /* @__PURE__ */ jsx(Send, { className: "size-4 rtl:-scale-x-100" })
11397
- })
11398
- ]
11399
- })]
11400
- }), voice ? /* @__PURE__ */ jsxs("div", {
11401
- className: "mt-1 flex items-center gap-3",
11402
- children: [
11403
- /* @__PURE__ */ jsx("button", {
11404
- type: "button",
11405
- onClick: connecting ? void 0 : inCall ? voice.onToggleMute ?? voice.onStart : voice.onStart,
11406
- disabled: micUnusable || connecting,
11407
- "data-testid": testIds?.mic,
11408
- title: micLabel,
11409
- "aria-label": micLabel,
11410
- ...connecting ? { "aria-busy": true } : {},
11411
- ...inCall && !connecting ? { "aria-pressed": voice.muted ?? false } : {},
11412
- className: cn("from-brand-plum to-brand-rose text-[var(--widget-accent-foreground)] flex size-12 shrink-0 items-center justify-center rounded-full bg-gradient-to-br transition-[transform,opacity]", micUnusable ? "cursor-not-allowed opacity-40" : connecting ? "cursor-wait" : cn("hover:scale-105 focus-visible:ring-2 focus-visible:ring-white/50 focus-visible:outline-none", "shadow-[0_0_0_1px_color-mix(in_oklab,var(--brand-plum)_18%,transparent),0_4px_14px_-2px_color-mix(in_oklab,var(--brand-plum)_45%,transparent),0_0_22px_-4px_color-mix(in_oklab,var(--brand-rose)_40%,transparent)]", "hover:shadow-[0_0_0_1px_color-mix(in_oklab,var(--brand-plum)_26%,transparent),0_6px_18px_-2px_color-mix(in_oklab,var(--brand-plum)_60%,transparent),0_0_30px_-4px_color-mix(in_oklab,var(--brand-rose)_55%,transparent)]"), inCall && !connecting && voice.muted !== true && "ring-brand-rose/50 ring-4"),
11413
- children: connecting ? /* @__PURE__ */ jsx("span", {
11414
- "aria-hidden": "true",
11415
- "data-testid": "widget-mic-spinner",
11416
- className: "flex items-center justify-center",
11417
- children: /* @__PURE__ */ jsx(MorphingLoader, {
11418
- size: "md",
11419
- variant: "light",
11420
- label: connectingLabel
11421
- })
11422
- }) : inCall && voice.muted === true ? /* @__PURE__ */ jsx(MicOff, { className: "size-5" }) : /* @__PURE__ */ jsx(Mic, { className: "size-5" })
11423
- }),
11424
- inCall && voice.agentSpeaking === true && voice.onInterrupt !== void 0 ? /* @__PURE__ */ jsx("button", {
11425
- type: "button",
11426
- onClick: () => voice.onInterrupt?.("tap"),
11427
- "data-testid": "widget-interrupt",
11428
- title: voice.labels.interrupt ?? "",
11429
- "aria-label": voice.labels.interrupt ?? "",
11430
- className: cn("flex size-10 shrink-0 items-center justify-center rounded-full bg-[var(--widget-chip)] text-[var(--widget-foreground)] transition-colors", "hover:bg-[var(--widget-bubble)] focus-visible:ring-2 focus-visible:ring-[var(--widget-accent-ring)] focus-visible:outline-none"),
11431
- children: /* @__PURE__ */ jsx(Square, { className: "size-4" })
11432
- }) : null,
11433
- voice.phase === "blocked" && voice.onFixPermission !== void 0 ? /* @__PURE__ */ jsx("button", {
11434
- type: "button",
11435
- onClick: voice.onFixPermission,
11436
- "data-testid": "widget-fix-permission",
11437
- className: cn("shrink-0 rounded-full bg-[var(--widget-chip)] px-3 py-2 text-xs font-medium text-[var(--widget-foreground)] transition-colors", "hover:bg-[var(--widget-bubble)] focus-visible:ring-2 focus-visible:ring-[var(--widget-accent-ring)] focus-visible:outline-none"),
11438
- children: voice.labels.fixBrowser ?? defaultWidgetMessages.dock_fix_browser
11439
- }) : null,
11440
- inCall && voice.onEnd !== void 0 ? /* @__PURE__ */ jsx("button", {
11441
- type: "button",
11442
- onClick: voice.onEnd,
11443
- "data-testid": testIds?.endCall,
11444
- title: voice.labels.end ?? "",
11445
- "aria-label": voice.labels.end ?? "",
11446
- className: cn("bg-destructive/10 text-destructive hover:bg-destructive/20 flex size-10 shrink-0 items-center justify-center rounded-full transition-colors", "focus-visible:ring-destructive/30 focus-visible:ring-2 focus-visible:outline-none"),
11447
- children: /* @__PURE__ */ jsx(PhoneOff, { className: "size-4" })
11448
- }) : null
11449
- ]
11450
- }) : null]
11451
- })
11452
- })
11453
- ]
11454
- })
12053
+ voice ? /* @__PURE__ */ jsx(MicButton, {
12054
+ voice,
12055
+ testId: testIds?.mic,
12056
+ className: "wgp-ib"
12057
+ }) : null,
12058
+ draft.trim() ? /* @__PURE__ */ jsx("button", {
12059
+ type: "submit",
12060
+ "aria-label": labels.send,
12061
+ "data-testid": testIds?.send,
12062
+ disabled: composerDisabled,
12063
+ className: "wgp-ib wgp-send",
12064
+ children: /* @__PURE__ */ jsx(Send, { className: "rtl:-scale-x-100" })
12065
+ }) : null
11455
12066
  ]
11456
- })
12067
+ }),
12068
+ attribution || privacyChoices ? /* @__PURE__ */ jsxs("p", {
12069
+ className: "wgp-foot",
12070
+ children: [attribution ? /* @__PURE__ */ jsx("a", {
12071
+ href: attribution.href,
12072
+ target: "_blank",
12073
+ rel: "noopener noreferrer",
12074
+ "data-testid": "widget-branding",
12075
+ style: BRAND_BADGE_PLAIN,
12076
+ children: /* @__PURE__ */ jsx(BrandWordmark, { name: attribution.name })
12077
+ }) : null, privacyChoices ? /* @__PURE__ */ jsx("button", {
12078
+ type: "button",
12079
+ onClick: privacyChoices.open,
12080
+ "data-testid": "widget-privacy-choices",
12081
+ children: privacyChoices.label
12082
+ }) : null]
12083
+ }) : null
11457
12084
  ]
11458
- }),
11459
- attribution ? /* @__PURE__ */ jsx("a", {
11460
- href: attribution.href,
11461
- target: "_blank",
11462
- rel: "noopener noreferrer",
11463
- "data-testid": "widget-branding",
11464
- className: cn(BADGE_LINK, "left-1/2 inline-flex -translate-x-1/2 items-center whitespace-nowrap", open ? "pointer-events-auto opacity-100" : "pointer-events-none opacity-0"),
11465
- style: BRAND_BADGE_PLAIN,
11466
- children: /* @__PURE__ */ jsx(BrandWordmark, { name: attribution.name })
11467
- }) : null,
11468
- privacyChoices ? /* @__PURE__ */ jsx("button", {
11469
- type: "button",
11470
- onClick: privacyChoices.open,
11471
- "data-testid": "widget-privacy-choices",
11472
- className: cn(FOOTER_PILL, "end-0 text-[var(--widget-foreground)] underline", open ? "pointer-events-auto opacity-100" : "pointer-events-none opacity-0"),
11473
- children: privacyChoices.label
11474
- }) : null
11475
- ]
11476
- })
11477
- }),
11478
- portalActive && /* @__PURE__ */ jsx("div", {
11479
- "aria-hidden": true,
11480
- className: cn("pointer-events-none fixed z-[55]", positionClasses(position)),
11481
- children: /* @__PURE__ */ jsx("div", {
11482
- className: "widget-portal size-16",
11483
- children: /* @__PURE__ */ jsx(MorphingLoader, {
11484
- size: "full",
11485
- label: labels.open
11486
- })
12085
+ })
12086
+ ] })
11487
12087
  })
11488
12088
  }),
11489
12089
  /* @__PURE__ */ jsx("div", {
@@ -11781,7 +12381,7 @@ function positionFor(dock) {
11781
12381
  const align = dock?.layout?.desktopAlign;
11782
12382
  return align === "left" || align === "right" ? `bottom-${align}` : DEFAULT_CONCIERGE_POSITION;
11783
12383
  }
11784
- 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, dock }) {
12384
+ 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, dock }) {
11785
12385
  const [restored] = useState(readOpen);
11786
12386
  const [open, setOpen] = useState(dock?.initialMinimised === false || restored);
11787
12387
  const onShown = dock?.onShown;
@@ -11796,6 +12396,7 @@ function ShellRenderer({ turns, showMic, callPhase, micOpen, onToggleMic, onEndC
11796
12396
  const [position, setPosition] = useState(() => positionFor(dock));
11797
12397
  const draggable = dock?.layout?.draggable !== false;
11798
12398
  const launcherLabel = dock?.copy?.minimisedLabel?.trim();
12399
+ const agentName = dock?.identity?.name?.trim();
11799
12400
  /**
11800
12401
  * The host's voice bag, merged the same way `DockRenderer` merges it: the
11801
12402
  * conversation derives the PHASE fields (`agentSpeaking`, `micOpen` …) and
@@ -11943,18 +12544,23 @@ function ShellRenderer({ turns, showMic, callPhase, micOpen, onToggleMic, onEndC
11943
12544
  })
11944
12545
  })]
11945
12546
  })] }) : null;
12547
+ const checkout = callHooks?.widgetEvents?.findLast((event) => event.type === "checkout");
12548
+ const published = dock?.identity?.avatar;
12549
+ const face = avatar ?? (isWidgetAvatar(published) ? published : void 0);
11946
12550
  return /* @__PURE__ */ jsxs(ConciergeShell, {
11947
12551
  open,
11948
12552
  onOpenChange: setOpen,
11949
12553
  ...restored ? { focusOnOpen: false } : {},
11950
12554
  state: view.avatar,
11951
12555
  ...skinStyle !== void 0 ? { skinStyle } : {},
11952
- ...avatar !== void 0 ? { avatar } : {},
12556
+ ...face !== void 0 ? { avatar: face } : {},
11953
12557
  ...attribution !== void 0 ? { attribution } : {},
11954
12558
  ...privacyChoices !== void 0 ? { privacyChoices } : {},
11955
12559
  launcher: view.launcher,
11956
12560
  ...view.handoff && operatorName !== void 0 ? { operatorName } : {},
11957
12561
  launcherInitials: view.launcher.initials ? handoffInitials(operatorName) : "",
12562
+ ...dock?.layout?.launcher !== void 0 ? { launcherVariant: dock.layout.launcher } : {},
12563
+ ...agentName ? { agentName } : {},
11958
12564
  typing: view.typing,
11959
12565
  messageArrived: lastTurn?.speaker === "caller",
11960
12566
  idPrefix: "widget",
@@ -11969,12 +12575,24 @@ function ShellRenderer({ turns, showMic, callPhase, micOpen, onToggleMic, onEndC
11969
12575
  open: messages.open,
11970
12576
  close: messages.minimize,
11971
12577
  dialog: messages.conversation,
12578
+ ...agentName ? { title: agentName } : {},
11972
12579
  composerPlaceholder: messages.type_placeholder,
11973
12580
  send: messages.send,
11974
12581
  move: messages.move,
11975
12582
  ...launcherLabel ? { launcher: launcherLabel } : {}
11976
12583
  },
11977
12584
  ...voice !== void 0 ? { voice } : {},
12585
+ ...voice !== void 0 ? { call: {
12586
+ state: view.state,
12587
+ callerSpeaking: voiceInput.callerSpeaking === true,
12588
+ turns,
12589
+ renderCards,
12590
+ suggestions,
12591
+ ...callHooks?.sendText !== void 0 ? { onSay: callHooks.sendText } : {},
12592
+ ...checkout !== void 0 ? { checkout } : {},
12593
+ ...cart !== void 0 ? { cart: cart.lines } : {},
12594
+ messages
12595
+ } } : {},
11978
12596
  composerLeading,
11979
12597
  badge: statusText === void 0 ? null : /* @__PURE__ */ jsx("p", {
11980
12598
  "data-testid": "widget-status",
@@ -11982,7 +12600,7 @@ function ShellRenderer({ turns, showMic, callPhase, micOpen, onToggleMic, onEndC
11982
12600
  role: "status",
11983
12601
  "aria-live": "polite"
11984
12602
  } : {},
11985
- className: "mt-1 max-w-full rounded-2xl bg-[var(--widget-chip)] px-2.5 py-1 text-center text-[10px] leading-snug font-semibold tracking-wide text-[var(--widget-foreground-muted)] [&:lang(ar)]:tracking-normal [&:lang(hi)]:tracking-normal",
12603
+ className: "m-0",
11986
12604
  children: statusText
11987
12605
  }),
11988
12606
  testIds: {
@@ -12006,259 +12624,68 @@ function ShellRenderer({ turns, showMic, callPhase, micOpen, onToggleMic, onEndC
12006
12624
  * here that both renderers would need; what is dock-specific (the follow key,
12007
12625
  * when the sheet reveals itself) stays, because it describes this chrome.
12008
12626
  *
12009
- * Imported by `cdn/ui.ts` and by `rendererFor`; never by `voice-widget.tsx`,
12010
- * so a bundle built around the OTHER renderer does not carry this one.
12011
- */
12012
- 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 }) {
12013
- return /* @__PURE__ */ jsx(Dock, {
12014
- identity: {
12015
- name: "",
12016
- avatar: avatar === "knot" ? "knot" : "orb"
12017
- },
12018
- ...dock,
12019
- voice: {
12020
- ...voice,
12021
- ...dock?.voice ?? {}
12022
- },
12023
- messages,
12024
- locale,
12025
- status: statusLine,
12026
- ...statusKind !== void 0 ? { statusKind } : {},
12027
- ...notice !== void 0 ? { notice } : {},
12028
- escalated,
12029
- ...operatorName !== void 0 ? { operatorName } : {},
12030
- ...onEndCall !== void 0 ? { onEndCall } : {},
12031
- ...skinStyle !== void 0 ? { skinStyle } : {},
12032
- ...attribution !== void 0 ? { attribution } : {},
12033
- ...privacyChoices !== void 0 ? { privacyChoices } : {},
12034
- ...curationHref ? { curationHref } : {},
12035
- ...productHref ? { productHref } : {},
12036
- ...navigate ? { navigate } : {},
12037
- draft,
12038
- onDraftChange,
12039
- onSubmit: submit,
12040
- revealSheet: showBasket && cart !== void 0 && cart.lines.length > 0 || attaching !== null || capturing,
12041
- followKey: turns.reduce((n, turn) => n + 1 + turn.text.length + (turn.cards?.items.length ?? 0), 0) + (humanTyping ? 1 : 0),
12042
- ...onAttach ? { onAttach } : {},
12043
- attachBusy: attaching !== null && !attaching.failed,
12044
- ...attachInput !== null ? { attachSlot: attachInput } : {},
12045
- sheetExtra: extras,
12046
- transcript,
12047
- transcriptCount: turns.length,
12048
- ...lastTurn !== void 0 ? { lastTurn } : {},
12049
- composing
12050
- });
12051
- }
12052
- //#endregion
12053
- //#region src/renderers.ts
12054
- /**
12055
- * The one module that names BOTH renderers — docs/CONCIERGE_GENERATIONS.md §3.
12056
- *
12057
- * `VoiceWidget` and `ConciergeWidget` (the npm components) resolve a missing
12058
- * `renderer` here from `ui.generation`. The CDN entries never import this
12059
- * file: `cdn/ui.ts` passes `DockRenderer` and `cdn/ui-widget.ts` passes
12060
- * `ShellRenderer` to `ConciergeHost` directly, which is what keeps each chunk
12061
- * to one renderer's code (rule 3 of §3: nothing under `widget/` is reachable
12062
- * from `cdn/ui.ts`, and vice versa — the budget guard measures it).
12063
- *
12064
- * Absent ⇒ the dock. That is the npm components' compatibility default, not
12065
- * the product's: the published config defaults to `widget`
12066
- * (`widget-config-upcast.ts`), and `cdn/core.ts` reads it that way. A React
12067
- * host that wants the widget says so.
12068
- */
12069
- function rendererFor(generation) {
12070
- return generation === "widget" ? ShellRenderer : DockRenderer;
12071
- }
12072
- //#endregion
12073
- //#region src/widget-markdown.tsx
12074
- /**
12075
- * Only `http(s)` and `mailto` survive.
12076
- *
12077
- * A model can emit `[click here](javascript:…)` as easily as a real URL, and a
12078
- * bare `href` would execute it on click. Anything else renders as plain text,
12079
- * so a rejected link still shows its label rather than vanishing.
12080
- */
12081
- function safeHref(raw) {
12082
- const href = raw.trim();
12083
- if (/^https?:\/\//i.test(href)) return href;
12084
- if (/^mailto:[^\s]+@[^\s]+$/i.test(href)) return href;
12085
- return null;
12086
- }
12087
- /**
12088
- * The bidi embedding and isolate controls (U+202A-U+202E, U+2066-U+2069),
12089
- * removed from what a bubble shows (SAA-436). A right-to-left override typed
12090
- * into a message reverses the rest of it on screen ("exe.txt" spoofing); the
12091
- * bubble's own `dir="auto"` and `unicode-bidi: isolate` already order real
12092
- * mixed-direction text, so nothing legitimate needs them.
12093
- */
12094
- function stripBidiControls(text) {
12095
- return text.replace(/[\u202A-\u202E\u2066-\u2069]/g, "");
12096
- }
12097
- /**
12098
- * Inline constructs, innermost-last.
12099
- *
12100
- * Code is matched FIRST and never recurses into its own body: `` `**not
12101
- * bold**` `` is a literal in every Markdown dialect, and parsing emphasis
12102
- * inside it is the classic way a renderer mangles a code sample.
12103
- */
12104
- function parseInline(src) {
12105
- const out = [];
12106
- let rest = src;
12107
- while (rest.length > 0) {
12108
- const match = /`([^`]+)`|\*\*([\s\S]+?)\*\*|__([\s\S]+?)__|(?<!\*)\*(?!\s)([^*\n]+?)\*(?!\*)|(?<!_)_(?!\s)([^_\n]+?)_(?!_)|\[([^\]]*)\]\(([^)\s]+)\)|(https:\/\/[^\s<>"'`]*[^\s<>"'`.,;:!?)\]])/.exec(rest);
12109
- if (!match || match.index === void 0) {
12110
- out.push({
12111
- kind: "text",
12112
- text: rest
12113
- });
12114
- break;
12115
- }
12116
- if (match.index > 0) out.push({
12117
- kind: "text",
12118
- text: rest.slice(0, match.index)
12119
- });
12120
- const [full, code, boldStar, boldUnd, italStar, italUnd, linkText, linkHref, bare] = match;
12121
- if (code !== void 0) out.push({
12122
- kind: "code",
12123
- text: code
12124
- });
12125
- else if (boldStar !== void 0 || boldUnd !== void 0) out.push({
12126
- kind: "bold",
12127
- children: parseInline(boldStar ?? boldUnd)
12128
- });
12129
- else if (italStar !== void 0 || italUnd !== void 0) out.push({
12130
- kind: "italic",
12131
- children: parseInline(italStar ?? italUnd)
12132
- });
12133
- else if (linkHref !== void 0) {
12134
- const href = safeHref(linkHref);
12135
- const children = parseInline(linkText ?? "").flatMap((n) => n.kind === "link" ? n.children : [n]);
12136
- out.push(href ? {
12137
- kind: "link",
12138
- href,
12139
- children
12140
- } : {
12141
- kind: "text",
12142
- text: linkText ?? ""
12143
- });
12144
- } else if (bare !== void 0) out.push({
12145
- kind: "link",
12146
- href: bare,
12147
- children: [{
12148
- kind: "text",
12149
- text: bare
12150
- }]
12151
- });
12152
- rest = rest.slice(match.index + full.length);
12153
- }
12154
- return out.filter((n) => !(n.kind === "text" && n.text === ""));
12155
- }
12156
- function sameOrigin(href) {
12157
- try {
12158
- return new URL(href).origin === window.location.origin;
12159
- } catch {
12160
- return false;
12161
- }
12162
- }
12163
- function renderInline(nodes, keyPrefix) {
12164
- return nodes.map((node, i) => {
12165
- const key = `${keyPrefix}-${i}`;
12166
- switch (node.kind) {
12167
- case "text": return /* @__PURE__ */ jsx(Fragment$1, { children: node.text }, key);
12168
- case "bold": return /* @__PURE__ */ jsx("strong", { children: renderInline(node.children, key) }, key);
12169
- case "italic": return /* @__PURE__ */ jsx("em", { children: renderInline(node.children, key) }, key);
12170
- case "code": return /* @__PURE__ */ jsx("code", {
12171
- className: "rounded bg-black/10 px-1 py-0.5 font-mono text-[0.85em]",
12172
- children: node.text
12173
- }, key);
12174
- case "link": return /* @__PURE__ */ jsx("a", {
12175
- href: node.href,
12176
- ...sameOrigin(node.href) ? {} : {
12177
- target: "_blank",
12178
- rel: "noopener noreferrer nofollow"
12179
- },
12180
- className: "underline underline-offset-2 [overflow-wrap:anywhere]",
12181
- children: renderInline(node.children, key)
12182
- }, key);
12183
- }
12184
- });
12185
- }
12186
- var BULLET = /^\s*[-*+]\s+(.*)$/;
12187
- var ORDERED = /^\s*\d+[.)]\s+(.*)$/;
12188
- /**
12189
- * Group lines into blocks.
12190
- *
12191
- * A blank line always closes the current block; a list item closes a paragraph
12192
- * and vice versa. That last rule is what fixes the reported bug — the model
12193
- * writes its intro and its bullets with no blank line between them, so
12194
- * splitting on blank lines alone left `intro - item - item` as one paragraph.
12627
+ * Imported by `cdn/ui.ts` and by `rendererFor`; never by `voice-widget.tsx`,
12628
+ * so a bundle built around the OTHER renderer does not carry this one.
12195
12629
  */
12196
- function parseBlocks(markdown) {
12197
- const blocks = [];
12198
- let paragraph = [];
12199
- let list = null;
12200
- const flushParagraph = () => {
12201
- if (paragraph.length > 0) blocks.push({
12202
- kind: "paragraph",
12203
- lines: paragraph
12204
- });
12205
- paragraph = [];
12206
- };
12207
- const flushList = () => {
12208
- if (list) blocks.push({
12209
- kind: "list",
12210
- ordered: list.ordered,
12211
- items: list.items
12212
- });
12213
- list = null;
12214
- };
12215
- for (const line of markdown.split("\n")) {
12216
- if (line.trim() === "") {
12217
- flushParagraph();
12218
- flushList();
12219
- continue;
12220
- }
12221
- const bullet = BULLET.exec(line);
12222
- const ordered = bullet ? null : ORDERED.exec(line);
12223
- if (bullet ?? ordered) {
12224
- flushParagraph();
12225
- const isOrdered = ordered !== null;
12226
- const text = (bullet?.[1] ?? ordered?.[1] ?? "").trim();
12227
- if (list && list.ordered !== isOrdered) flushList();
12228
- list ??= {
12229
- ordered: isOrdered,
12230
- items: []
12231
- };
12232
- list.items.push(text);
12233
- continue;
12234
- }
12235
- flushList();
12236
- paragraph.push(line.trim());
12237
- }
12238
- flushParagraph();
12239
- flushList();
12240
- return blocks;
12630
+ 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 }) {
12631
+ return /* @__PURE__ */ jsx(Dock, {
12632
+ identity: {
12633
+ name: "",
12634
+ avatar: avatar === "knot" ? "knot" : "orb"
12635
+ },
12636
+ ...dock,
12637
+ voice: {
12638
+ ...voice,
12639
+ ...dock?.voice ?? {}
12640
+ },
12641
+ messages,
12642
+ locale,
12643
+ status: statusLine,
12644
+ ...statusKind !== void 0 ? { statusKind } : {},
12645
+ ...notice !== void 0 ? { notice } : {},
12646
+ escalated,
12647
+ ...operatorName !== void 0 ? { operatorName } : {},
12648
+ ...onEndCall !== void 0 ? { onEndCall } : {},
12649
+ ...skinStyle !== void 0 ? { skinStyle } : {},
12650
+ ...attribution !== void 0 ? { attribution } : {},
12651
+ ...privacyChoices !== void 0 ? { privacyChoices } : {},
12652
+ ...curationHref ? { curationHref } : {},
12653
+ ...productHref ? { productHref } : {},
12654
+ ...navigate ? { navigate } : {},
12655
+ draft,
12656
+ onDraftChange,
12657
+ onSubmit: submit,
12658
+ revealSheet: showBasket && cart !== void 0 && cart.lines.length > 0 || attaching !== null || capturing,
12659
+ followKey: turns.reduce((n, turn) => n + 1 + turn.text.length + (turn.cards?.items.length ?? 0), 0) + (humanTyping ? 1 : 0),
12660
+ ...onAttach ? { onAttach } : {},
12661
+ attachBusy: attaching !== null && !attaching.failed,
12662
+ ...attachInput !== null ? { attachSlot: attachInput } : {},
12663
+ sheetExtra: extras,
12664
+ transcript,
12665
+ transcriptCount: turns.length,
12666
+ ...lastTurn !== void 0 ? { lastTurn } : {},
12667
+ composing
12668
+ });
12241
12669
  }
12670
+ //#endregion
12671
+ //#region src/renderers.ts
12242
12672
  /**
12243
- * Renders one turn's text.
12673
+ * The one module that names BOTH renderers — docs/CONCIERGE_GENERATIONS.md §3.
12244
12674
  *
12245
- * Safe to call on a PARTIAL string: this runs on every streamed delta, so a
12246
- * half-written `**bold` is common. Unterminated markers simply fail to match
12247
- * and render as the literal characters they are, which then resolve
12248
- * themselves on the delta that closes them — no flicker beyond the marker
12249
- * briefly showing, and never a thrown parse error mid-stream.
12675
+ * `VoiceWidget` and `ConciergeWidget` (the npm components) resolve a missing
12676
+ * `renderer` here from `ui.generation`. The CDN entries never import this
12677
+ * file: `cdn/ui.ts` passes `DockRenderer` and `cdn/ui-widget.ts` passes
12678
+ * `ShellRenderer` to `ConciergeHost` directly, which is what keeps each chunk
12679
+ * to one renderer's code (rule 3 of §3: nothing under `widget/` is reachable
12680
+ * from `cdn/ui.ts`, and vice versa — the budget guard measures it).
12681
+ *
12682
+ * Absent ⇒ the dock. That is the npm components' compatibility default, not
12683
+ * the product's: the published config defaults to `widget`
12684
+ * (`widget-config-upcast.ts`), and `cdn/core.ts` reads it that way. A React
12685
+ * host that wants the widget says so.
12250
12686
  */
12251
- function WidgetMarkdown({ text }) {
12252
- return parseBlocks(stripBidiControls(text)).map((block, i) => {
12253
- if (block.kind === "list") return /* @__PURE__ */ jsx(block.ordered ? "ol" : "ul", {
12254
- className: `my-1 space-y-1 ps-4 ${block.ordered ? "list-decimal" : "list-disc"}`,
12255
- children: block.items.map((item, j) => /* @__PURE__ */ jsx("li", { children: renderInline(parseInline(item), `b${i}-i${j}`) }, `b${i}-i${j}`))
12256
- }, `b${i}`);
12257
- return /* @__PURE__ */ jsx("p", {
12258
- className: "[&:not(:first-child)]:mt-2",
12259
- children: block.lines.map((line, j) => /* @__PURE__ */ jsxs(Fragment$1, { children: [j > 0 ? /* @__PURE__ */ jsx("br", {}) : null, renderInline(parseInline(line), `b${i}-l${j}`)] }, `b${i}-l${j}`))
12260
- }, `b${i}`);
12261
- });
12687
+ function rendererFor(generation) {
12688
+ return generation === "widget" ? ShellRenderer : DockRenderer;
12262
12689
  }
12263
12690
  //#endregion
12264
12691
  //#region src/widget-cards.tsx
@@ -12344,6 +12771,7 @@ function CardBody({ item, href, roomy, locale, navigate, showPrice, imageAspect
12344
12771
  children: formatMoney(item.priceMinor, item.currency, locale)
12345
12772
  }) : null,
12346
12773
  item.reason ? /* @__PURE__ */ jsx("p", {
12774
+ "data-testid": "widget-card-reason",
12347
12775
  className: "line-clamp-2 text-pretty text-xs text-[var(--widget-foreground-muted)] italic",
12348
12776
  children: item.reason
12349
12777
  }) : null
@@ -12658,152 +13086,46 @@ function WidgetCartSummary({ lines, subtotalMinor, currency, discountMinor, onCh
12658
13086
  });
12659
13087
  }
12660
13088
  /**
12661
- * Checkout → spinner → gone.
12662
- *
12663
- * The spinner exists because building the permalink is a real server
12664
- * round-trip. There is no third state: on success the shopper is already on
12665
- * their way to Shopify, so the only thing left to render is the failure.
12666
- */
12667
- function CheckoutButton({ onCheckout, navigate, messages }) {
12668
- const [phase, setPhase] = useState("idle");
12669
- const start = async () => {
12670
- if (phase === "working") return;
12671
- setPhase("working");
12672
- const href = await onCheckout();
12673
- if (href === false) {
12674
- setPhase("idle");
12675
- return;
12676
- }
12677
- if (href === null) {
12678
- setPhase("failed");
12679
- return;
12680
- }
12681
- (navigate ?? ((url) => window.location.assign(url)))(href);
12682
- };
12683
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("button", {
12684
- type: "button",
12685
- "data-testid": "widget-checkout-button",
12686
- "data-phase": phase,
12687
- disabled: phase === "working",
12688
- onClick: () => void start(),
12689
- className: "mt-3 flex w-full cursor-pointer items-center justify-center gap-2 rounded-full bg-[var(--widget-accent)] px-4 py-2.5 text-sm font-semibold text-[var(--widget-accent-foreground)] transition-opacity disabled:cursor-default disabled:opacity-70",
12690
- children: [phase === "working" ? /* @__PURE__ */ jsx("span", {
12691
- "aria-hidden": "true",
12692
- className: "h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent motion-reduce:animate-none"
12693
- }) : null, messages.checkout_now]
12694
- }), phase === "failed" ? /* @__PURE__ */ jsx("p", {
12695
- role: "status",
12696
- className: "mt-2 text-center text-xs text-[var(--widget-foreground-muted)]",
12697
- children: messages.checkout_failed
12698
- }) : null] });
12699
- }
12700
- //#endregion
12701
- //#region ../widget-protocol/dist/text-direction.js
12702
- /**
12703
- * Base direction for a block of text whose language is the CONTENT's, not the
12704
- * reader's. Pure, string-only and dependency-free: a STATIC import into the
12705
- * chat bundle a shopper downloads, shared by the console (`apps/web`) and the
12706
- * widget (`@saar-ai/web-widget`), which used to keep a hand copy each.
12707
- *
12708
- * It lives here rather than in `@wesence/i18n` because the widget's published
12709
- * bundle may resolve no `@wesence/*` module at all (`docs/PACKAGE_DISTRIBUTION.md`,
12710
- * enforced by `scripts/check-npm-bundle-provenance.mjs`), the same reason
12711
- * `./money` lives here.
12712
- *
12713
- * ## Why the console's own direction is the wrong answer
12714
- *
12715
- * `<html dir>` is set from the operator's UI locale, and every element inherits
12716
- * it. That is right for the chrome and wrong for a transcript: an
12717
- * English-speaking agent reading an Arabic conversation would render each
12718
- * message with an LTR base direction, and the Unicode bidirectional algorithm
12719
- * would then lay out the runs in the wrong order and throw trailing punctuation
12720
- * to the wrong end of the line.
12721
- *
12722
- * The failure is invisible to the person looking at it. An agent who cannot read
12723
- * Arabic sees Arabic-looking text and moves on; the customer is the one who gets
12724
- * quoted back a sentence that reads incorrectly. The reverse case is just as
12725
- * real — an Arabic-speaking agent reading English conversations under an RTL
12726
- * base.
12727
- *
12728
- * ## Mixed runs are the normal case here, not an edge case
12729
- *
12730
- * Verified against live recognition output: Arabic comes back as
12731
- * `رقم الـ order هو 4471. Please check من فضلك.` and Hindi as
12732
- * `मेरा order number 4471 है।`. Latin nouns inside a non-Latin sentence are what
12733
- * this product's transcripts actually contain, so bidirectional layout is
12734
- * exercised on ordinary traffic rather than by an unusual customer.
12735
- *
12736
- * ## `auto` is the floor, not the goal
12737
- *
12738
- * With a known language this returns a definite direction. Without one it
12739
- * returns `auto`, which delegates to the browser's first-strong-character
12740
- * heuristic — better than inheriting the chrome, but wrong for a message that
12741
- * opens with an English word and continues in Arabic (`Please check من فضلك`).
12742
- * The real fix is to persist the conversation's resolved locale and pass it in;
12743
- * see the note in `Transcript`.
12744
- */
12745
- /**
12746
- * Languages written right-to-left. Keyed on the language subtag, so a region
12747
- * never has to be enumerated.
12748
- *
12749
- * Beyond Arabic on purpose: Hebrew, Farsi, Urdu and Pashto are the scripts a CX
12750
- * product in this region acquires next, and getting one wrong is the same silent
12751
- * failure. Adding a language to the product must not also require remembering
12752
- * this file.
12753
- */
12754
- var RTL_LANGUAGES = /* @__PURE__ */ new Set([
12755
- "ar",
12756
- "he",
12757
- "iw",
12758
- "fa",
12759
- "ur",
12760
- "ps",
12761
- "sd",
12762
- "ug",
12763
- "yi",
12764
- "dv"
12765
- ]);
12766
- /** Known LTR languages this product targets, so a typo does not silently pass. */
12767
- var KNOWN_LTR_LANGUAGES = /* @__PURE__ */ new Set([
12768
- "en",
12769
- "hi",
12770
- "es",
12771
- "fr",
12772
- "de",
12773
- "pt",
12774
- "it",
12775
- "nl",
12776
- "id",
12777
- "ta",
12778
- "te",
12779
- "bn",
12780
- "mr",
12781
- "gu",
12782
- "kn",
12783
- "ml",
12784
- "pa"
12785
- ]);
12786
- /** A well-formed BCP-47-ish language subtag: two or three ASCII letters. */
12787
- var LANGUAGE_SUBTAG = /^[a-z]{2,3}$/;
12788
- /**
12789
- * The base direction for text in `locale`.
12790
- *
12791
- * @param locale BCP-47 tag from stored conversation data — untyped by the time
12792
- * it reaches here, so anything malformed resolves to `auto` rather than to a
12793
- * guess.
13089
+ * Checkout → spinner → gone.
13090
+ *
13091
+ * The spinner exists because building the permalink is a real server
13092
+ * round-trip. There is no third state: on success the shopper is already on
13093
+ * their way to Shopify, so the only thing left to render is the failure.
12794
13094
  */
12795
- function textDirectionFor$1(locale) {
12796
- if (locale === void 0 || locale === null || locale === "") return "auto";
12797
- const language = locale.toLowerCase().split("-")[0] ?? "";
12798
- if (!LANGUAGE_SUBTAG.test(language)) return "auto";
12799
- if (RTL_LANGUAGES.has(language)) return "rtl";
12800
- if (KNOWN_LTR_LANGUAGES.has(language)) return "ltr";
12801
- return "auto";
13095
+ function CheckoutButton({ onCheckout, navigate, messages }) {
13096
+ const [phase, setPhase] = useState("idle");
13097
+ const start = async () => {
13098
+ if (phase === "working") return;
13099
+ setPhase("working");
13100
+ const href = await onCheckout();
13101
+ if (href === false) {
13102
+ setPhase("idle");
13103
+ return;
13104
+ }
13105
+ if (href === null) {
13106
+ setPhase("failed");
13107
+ return;
13108
+ }
13109
+ (navigate ?? ((url) => window.location.assign(url)))(href);
13110
+ };
13111
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("button", {
13112
+ type: "button",
13113
+ "data-testid": "widget-checkout-button",
13114
+ "data-phase": phase,
13115
+ disabled: phase === "working",
13116
+ onClick: () => void start(),
13117
+ className: "mt-3 flex w-full cursor-pointer items-center justify-center gap-2 rounded-full bg-[var(--widget-accent)] px-4 py-2.5 text-sm font-semibold text-[var(--widget-accent-foreground)] transition-opacity disabled:cursor-default disabled:opacity-70",
13118
+ children: [phase === "working" ? /* @__PURE__ */ jsx("span", {
13119
+ "aria-hidden": "true",
13120
+ className: "h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent motion-reduce:animate-none"
13121
+ }) : null, messages.checkout_now]
13122
+ }), phase === "failed" ? /* @__PURE__ */ jsx("p", {
13123
+ role: "status",
13124
+ className: "mt-2 text-center text-xs text-[var(--widget-foreground-muted)]",
13125
+ children: messages.checkout_failed
13126
+ }) : null] });
12802
13127
  }
12803
13128
  //#endregion
12804
- //#region src/text-direction.ts
12805
- var textDirectionFor = textDirectionFor$1;
12806
- //#endregion
12807
13129
  //#region src/voice-widget.tsx
12808
13130
  /**
12809
13131
  * The "still composing" affordance, shown in the agent's own bubble from the
@@ -13115,7 +13437,7 @@ function VoiceWidget({ renderer, generation, ...props }) {
13115
13437
  });
13116
13438
  }
13117
13439
  /** `VoiceWidget` with the renderer decided — the component the CDN entries and `ConciergeHost` use. */
13118
- function VoiceWidgetWithRenderer({ renderer, state, turns, onToggleMic, onEndCall, callPhase = "idle", onSendText, micOpen, status, statusKind, notice, mode = "voice", escalated = false, humanTyping = false, onTyping, onAddToCart, onChooseOptions, chooseOptionsBusy = false, curationHref, productHref, onAttachFile, cart, captureCard, messages = defaultWidgetMessages, suggestions, navigate, locale = "en", skinStyle, avatar, attribution, privacyChoices, dock }) {
13440
+ function VoiceWidgetWithRenderer({ renderer, state, turns, onToggleMic, onEndCall, callPhase = "idle", onSendText, micOpen, status, statusKind, notice, mode = "voice", escalated = false, humanTyping = false, onTyping, onAddToCart, onChooseOptions, chooseOptionsBusy = false, curationHref, productHref, onAttachFile, cart, captureCard, messages = defaultWidgetMessages, suggestions, navigate, locale = "en", skinStyle, avatar, attribution, privacyChoices, call, dock }) {
13119
13441
  const [draft, setDraft] = useState("");
13120
13442
  const [sending, setSending] = useState(false);
13121
13443
  /** Roomy mode — see the expand control in the header. Collapses back on close, so a reopened widget starts small. */
@@ -13209,6 +13531,21 @@ function VoiceWidgetWithRenderer({ renderer, state, turns, onToggleMic, onEndCal
13209
13531
  * with two slices while §3.4 had a latest-exchange view (2026-09-11); since
13210
13532
  * 2026-09-15 the visor always holds the whole log, so it renders one.
13211
13533
  */
13534
+ const renderCards = (cards) => /* @__PURE__ */ jsx(WidgetCardList, {
13535
+ cards,
13536
+ onAddToCart,
13537
+ onChooseOptions,
13538
+ chooseOptionsBusy,
13539
+ curationHref,
13540
+ productHref,
13541
+ navigate,
13542
+ locale,
13543
+ messages,
13544
+ roomy: false,
13545
+ ...dock?.showPrice !== void 0 ? { showPrice: dock.showPrice } : {},
13546
+ ...dock?.cardImageAspect !== void 0 ? { imageAspect: dock.cardImageAspect } : {}
13547
+ });
13548
+ const openers = suggestions ?? SUGGESTION_KEYS.map((key) => messages[key]);
13212
13549
  const renderLog = (shown) => /* @__PURE__ */ jsxs("div", {
13213
13550
  role: "log",
13214
13551
  "aria-live": "polite",
@@ -13254,20 +13591,7 @@ function VoiceWidgetWithRenderer({ renderer, state, turns, onToggleMic, onEndCal
13254
13591
  }) : null,
13255
13592
  turn.cards && turn.cards.items.length > 0 ? /* @__PURE__ */ jsx("div", {
13256
13593
  className: "w-full",
13257
- children: /* @__PURE__ */ jsx(WidgetCardList, {
13258
- cards: turn.cards,
13259
- onAddToCart,
13260
- onChooseOptions,
13261
- chooseOptionsBusy,
13262
- curationHref,
13263
- productHref,
13264
- navigate,
13265
- locale,
13266
- messages,
13267
- roomy: false,
13268
- ...dock?.showPrice !== void 0 ? { showPrice: dock.showPrice } : {},
13269
- ...dock?.cardImageAspect !== void 0 ? { imageAspect: dock.cardImageAspect } : {}
13270
- })
13594
+ children: renderCards(turn.cards)
13271
13595
  }) : null,
13272
13596
  turn.delivery !== void 0 ? /* @__PURE__ */ jsx(TurnDeliveryStatus, {
13273
13597
  delivery: turn.delivery,
@@ -13288,7 +13612,7 @@ function VoiceWidgetWithRenderer({ renderer, state, turns, onToggleMic, onEndCal
13288
13612
  "aria-label": messages.suggestions_label,
13289
13613
  "data-testid": "widget-suggestions",
13290
13614
  className: "flex flex-wrap gap-2 pt-1",
13291
- children: (suggestions ?? SUGGESTION_KEYS.map((key) => messages[key])).map((text) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
13615
+ children: openers.map((text) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("button", {
13292
13616
  type: "button",
13293
13617
  "data-testid": "widget-suggestion",
13294
13618
  disabled: sending,
@@ -13437,6 +13761,9 @@ function VoiceWidgetWithRenderer({ renderer, state, turns, onToggleMic, onEndCal
13437
13761
  onAttach,
13438
13762
  attachInput,
13439
13763
  transcript: renderLog(turns),
13764
+ renderCards,
13765
+ suggestions: openers,
13766
+ call,
13440
13767
  extras,
13441
13768
  messages,
13442
13769
  locale,
@@ -16323,6 +16650,109 @@ async function streamReply(args) {
16323
16650
  }
16324
16651
  }
16325
16652
  //#endregion
16653
+ //#region src/spoken-transcript.ts
16654
+ /** The words of `provisional` after the `settled` prefix the caller heard. */
16655
+ function droppedWords(settled, provisional) {
16656
+ return provisional.trim().slice(settled.trim().length).split(/\s+/u).filter(Boolean).length;
16657
+ }
16658
+ /**
16659
+ * The turns the worker reported as cut short, from `turn.latency` frames,
16660
+ * added to `ids` (a fresh set when omitted) so a caller can accumulate them.
16661
+ */
16662
+ function interruptedTurnIds(turns, ids = /* @__PURE__ */ new Set()) {
16663
+ for (const turn of turns) if (turn.interruptedBy !== void 0) ids.add(turn.turnId);
16664
+ return ids;
16665
+ }
16666
+ /**
16667
+ * So little that a bubble is noise: up to three words and under 24 characters.
16668
+ * A single "word" (a script written without spaces) must also be under
16669
+ * {@link NEGLIGIBLE_UNSPACED_MAX_CHARS}, or a cut-off sentence in Chinese or
16670
+ * Thai would count as one word.
16671
+ */
16672
+ function isNegligibleText(raw) {
16673
+ const text = raw.trim();
16674
+ const words = text.split(/\s+/u).length;
16675
+ const cap = words > 1 ? 24 : 8;
16676
+ return words <= 3 && text.length < cap;
16677
+ }
16678
+ /**
16679
+ * Which settled agent lines were cut off by the caller. A line counts as cut
16680
+ * off when the hook saw it truncated, or when the worker reported its turn
16681
+ * interrupted and it is that turn's LAST agent line (`interruptedBy` covers
16682
+ * the turn; earlier lines of it finished). Fillers are never replies.
16683
+ */
16684
+ function cutLineIndexes(lines, interrupted) {
16685
+ const cut = /* @__PURE__ */ new Set();
16686
+ const seen = /* @__PURE__ */ new Set();
16687
+ for (let i = lines.length - 1; i >= 0; i -= 1) {
16688
+ const line = lines[i];
16689
+ if (line.speaker !== "agent" || !line.final || line.filler) continue;
16690
+ const last = !seen.has(line.turnId);
16691
+ seen.add(line.turnId);
16692
+ if (line.truncated || last && interrupted.has(line.turnId)) cut.add(i);
16693
+ }
16694
+ return cut;
16695
+ }
16696
+ /** The cut-off lines ({@link cutLineIndexes}) that draw the "Interrupted" tag. */
16697
+ function taggedCutIndexes(lines, cut, interrupted) {
16698
+ return new Set([...cut].filter((i) => {
16699
+ const line = lines[i];
16700
+ return interrupted.has(line.turnId) || (line.dropped ?? 0) >= 3;
16701
+ }));
16702
+ }
16703
+ /** The cut-off lines ({@link cutLineIndexes}) with so little spoken that they draw nothing. */
16704
+ function negligibleLineIndexes(lines, cut) {
16705
+ return new Set([...cut].filter((i) => isNegligibleText(lines[i].text)));
16706
+ }
16707
+ /**
16708
+ * Which typed turns are the server's copy of a line the call is drawing live.
16709
+ *
16710
+ * Only turns the poll delivered (they carry `seq`) can be copies; a turn the
16711
+ * shopper typed is never hidden. A copy reaches the screen AFTER the line it
16712
+ * copies (the server stores a line once it is spoken, and the poll fetches it
16713
+ * later), so a live line only absorbs a copy stamped after it. That keeps a new
16714
+ * call's greeting from hiding the previous call's identical one. Each live line
16715
+ * absorbs at most one copy, so a caller who said "yes" twice keeps both answers
16716
+ * if the poll only has one of them.
16717
+ *
16718
+ * When a new call starts, `useVoiceSession` clears its transcript, the live
16719
+ * lines are gone, and the server's copies draw instead. That is how the
16720
+ * previous call stays on screen.
16721
+ *
16722
+ * @param typedStamps, spokenStamps `TurnOrderClock` stamps, index for index
16723
+ */
16724
+ function echoedTurnIndexes(typed, typedStamps, spoken, spokenStamps) {
16725
+ const key = (line) => `${line.speaker}\u0000${line.text.trim().replace(/\s+/gu, " ")}`;
16726
+ const live = [];
16727
+ spoken.forEach((line, i) => {
16728
+ if (line.final) live.push([key(line), spokenStamps[i]]);
16729
+ });
16730
+ const echoed = /* @__PURE__ */ new Set();
16731
+ typed.forEach((turn, i) => {
16732
+ if (turn.seq === void 0 || turn.speaker === "event") return;
16733
+ const k = key(turn);
16734
+ const at = live.findIndex(([lk, stamp]) => lk === k && stamp < typedStamps[i]);
16735
+ if (at < 0) return;
16736
+ live.splice(at, 1);
16737
+ echoed.add(i);
16738
+ });
16739
+ return echoed;
16740
+ }
16741
+ /**
16742
+ * Where the "Call started" divider goes: just before the call's first line,
16743
+ * when something is already on screen above it. `null` means no divider.
16744
+ *
16745
+ * Stamps are integers from `TurnOrderClock`, so half a step before the first
16746
+ * line sorts the divider between it and the row above it.
16747
+ *
16748
+ * @param spoken this call's rows, @param others every other row on screen
16749
+ */
16750
+ function callStartStamp(spoken, others) {
16751
+ if (spoken.length === 0) return null;
16752
+ const first = Math.min(...spoken.map((row) => row.stamp));
16753
+ return others.some((row) => row.stamp < first) ? first - .5 : null;
16754
+ }
16755
+ //#endregion
16326
16756
  //#region src/use-voice-session.ts
16327
16757
  /**
16328
16758
  * Loads the call's wire-protocol codec and validation schema — see the module
@@ -16485,7 +16915,8 @@ function coalesceTranscript(lines, line) {
16485
16915
  text: open.text.length >= MAX_AGENT_LINE_CHARS ? open.text : joinClauses(open.text, line.text)
16486
16916
  } : line.speaker === "agent" && line.final && isCutShort(line.text, open.text) ? {
16487
16917
  ...line,
16488
- truncated: true
16918
+ truncated: true,
16919
+ dropped: droppedWords(line.text, open.text)
16489
16920
  } : line;
16490
16921
  return [
16491
16922
  ...lines.slice(0, at),
@@ -17127,6 +17558,151 @@ function useVoiceSession(options = {}) {
17127
17558
  };
17128
17559
  }
17129
17560
  //#endregion
17561
+ //#region src/theme/widget-derive.ts
17562
+ /**
17563
+ * The widget generation's extra `--wgt-*` tokens (docs/DOCK_SPEC.md §9.2),
17564
+ * derived on top of the dock's eighteen. Separate from `derive.ts` so the dock
17565
+ * chunk does not carry tokens it never reads (bundle budget).
17566
+ */
17567
+ var WIDGET_GEN_EXTRA_TOKENS = [
17568
+ "--wgt-panel-radius",
17569
+ "--wgt-card-lg-radius",
17570
+ "--wgt-btn-radius",
17571
+ "--wgt-chip-radius",
17572
+ "--wgt-bubble-radius",
17573
+ "--wgt-bubble-tail-radius",
17574
+ "--wgt-launcher-radius",
17575
+ "--wgt-text-2",
17576
+ "--wgt-surface-3",
17577
+ "--wgt-panel-surface",
17578
+ "--wgt-panel-filter",
17579
+ "--wgt-elevation",
17580
+ "--wgt-card-elevation",
17581
+ "--wgt-accent-ink",
17582
+ "--wgt-live"
17583
+ ];
17584
+ /** Every token the widget generation reads: the dock's, then the extras. */
17585
+ var WIDGET_GEN_TOKENS = [...WIDGET_THEME_TOKENS, ...WIDGET_GEN_EXTRA_TOKENS];
17586
+ /**
17587
+ * px per `type.radius`, in the order of the radius tokens above: panel, card,
17588
+ * button, chip, bubble, bubble tail, launcher. `999` is "fully round", a
17589
+ * length the browser clamps to half the box.
17590
+ */
17591
+ var RADII = {
17592
+ square: [
17593
+ 4,
17594
+ 2,
17595
+ 2,
17596
+ 2,
17597
+ 2,
17598
+ 2,
17599
+ 4
17600
+ ],
17601
+ soft: [
17602
+ 16,
17603
+ 12,
17604
+ 10,
17605
+ 10,
17606
+ 16,
17607
+ 4,
17608
+ 14
17609
+ ],
17610
+ round: [
17611
+ 24,
17612
+ 18,
17613
+ 999,
17614
+ 999,
17615
+ 20,
17616
+ 6,
17617
+ 999
17618
+ ],
17619
+ pill: [
17620
+ 28,
17621
+ 20,
17622
+ 999,
17623
+ 999,
17624
+ 20,
17625
+ 6,
17626
+ 999
17627
+ ]
17628
+ };
17629
+ /** Secondary text sits this far from the text toward the surface, before the readability walk. */
17630
+ var TEXT_2_MIX = .2;
17631
+ /** The quiet fill is one step deeper than `--wgt-surface-2` (6 %). */
17632
+ var SURFACE_3_MIX = .1;
17633
+ /** `color.glass`: the panel's surface alpha; `widget-derive.test.ts` measures text over black and white pages. */
17634
+ var PANEL_GLASS_ALPHA = .8;
17635
+ var PANEL_GLASS_FILTER = "blur(24px) saturate(1.6)";
17636
+ /** [panel, card] shadows for a light surface, then for a dark one. */
17637
+ var ELEVATION = [["0 0 0 1px rgb(0 0 0 / 0.06), 0 24px 60px -22px rgb(0 0 0 / 0.32)", "0 0 0 1px rgb(0 0 0 / 0.06), 0 8px 20px -16px rgb(0 0 0 / 0.35)"], ["0 0 0 1px rgb(255 255 255 / 0.08), 0 30px 80px -20px rgb(0 0 0 / 0.75)", "0 0 0 1px rgb(255 255 255 / 0.08)"]];
17638
+ /** Secondary text: walked back toward the text until it clears the 4.5:1 floor. */
17639
+ function deriveText2(text, surface) {
17640
+ for (let t = TEXT_2_MIX; t > 0; t = Number((t - .05).toFixed(2))) {
17641
+ const candidate = mixToward(text, surface, t);
17642
+ if (contrastRatio(candidate, surface) >= 4.5) return candidate;
17643
+ }
17644
+ return text;
17645
+ }
17646
+ function extend(base, type, glass) {
17647
+ const surface = base["--wgt-surface"];
17648
+ const text = base["--wgt-text"];
17649
+ const values = [
17650
+ ...RADII[type.radius].map((n) => `${n}px`),
17651
+ deriveText2(text, surface),
17652
+ mixToward(surface, text, SURFACE_3_MIX),
17653
+ glass ? withAlpha(surface, PANEL_GLASS_ALPHA) : surface,
17654
+ glass ? PANEL_GLASS_FILTER : "none",
17655
+ ...ELEVATION[hexToOklch(surface).L >= .5 ? 0 : 1],
17656
+ deriveRing(base["--wgt-primary"], surface, TEXT_CONTRAST_MIN),
17657
+ LIVE_COLOR
17658
+ ];
17659
+ const out = { ...base };
17660
+ WIDGET_GEN_EXTRA_TOKENS.forEach((token, i) => out[token] = values[i]);
17661
+ return out;
17662
+ }
17663
+ /**
17664
+ * Every `--wgt-*` token the widget generation reads, from the published
17665
+ * `color` + `type` groups: {@link deriveTheme}'s eighteen plus the extras,
17666
+ * per block, with the same tone rules. Pure, and throws on the same inputs.
17667
+ */
17668
+ function deriveWidgetTheme(color, type) {
17669
+ const base = deriveTheme(color, type);
17670
+ const glass = color.glass === true;
17671
+ return {
17672
+ light: extend(base.light, type, glass),
17673
+ ...base.dark ? { dark: extend(base.dark, type, glass) } : {}
17674
+ };
17675
+ }
17676
+ //#endregion
17677
+ //#region src/theme/widget-theme-scope.tsx
17678
+ var DEFAULT_COLOR = {
17679
+ primary: "#111827",
17680
+ tone: "light"
17681
+ };
17682
+ var DEFAULT_TYPE = {
17683
+ font: "inherit",
17684
+ radius: "round",
17685
+ caps: "none"
17686
+ };
17687
+ /**
17688
+ * Puts the tenant's `--wgt-*` tokens (docs/DOCK_SPEC.md §9.2) on the widget
17689
+ * generation for every mount without a `core` stage (docs/CONCIERGE_GENERATIONS.md
17690
+ * §3.4). A scoped stylesheet rather than inline style so `tone: 'auto'` can carry
17691
+ * its `prefers-color-scheme` query. Every value comes out of `deriveWidgetTheme`.
17692
+ */
17693
+ function WidgetThemeScope({ color = DEFAULT_COLOR, type = DEFAULT_TYPE, children }) {
17694
+ const id = useId();
17695
+ return /* @__PURE__ */ jsxs("div", {
17696
+ "data-wgt-scope": id,
17697
+ style: { display: "contents" },
17698
+ children: [/* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: useMemo(() => scopedThemeCss(deriveWidgetTheme(color, type), `[data-wgt-scope="${id}"]`, WIDGET_GEN_TOKENS), [
17699
+ color,
17700
+ type,
17701
+ id
17702
+ ]) } }), children]
17703
+ });
17704
+ }
17705
+ //#endregion
17130
17706
  //#region ../widget-bridge/dist/page-context.js
17131
17707
  function clampId(value, max) {
17132
17708
  if (typeof value !== "string") return void 0;
@@ -17799,93 +18375,6 @@ var TurnOrderClock = class {
17799
18375
  return stamp;
17800
18376
  }
17801
18377
  };
17802
- /**
17803
- * The turns the worker reported as cut short, from `turn.latency` frames,
17804
- * added to `ids` (a fresh set when omitted) so a caller can accumulate them.
17805
- */
17806
- function interruptedTurnIds(turns, ids = /* @__PURE__ */ new Set()) {
17807
- for (const turn of turns) if (turn.interruptedBy !== void 0) ids.add(turn.turnId);
17808
- return ids;
17809
- }
17810
- /**
17811
- * So little that a bubble is noise: up to three words and under 24 characters.
17812
- * A single "word" (a script written without spaces) must also be under
17813
- * {@link NEGLIGIBLE_UNSPACED_MAX_CHARS}, or a cut-off sentence in Chinese or
17814
- * Thai would count as one word.
17815
- */
17816
- function isNegligibleText(raw) {
17817
- const text = raw.trim();
17818
- const words = text.split(/\s+/u).length;
17819
- const cap = words > 1 ? 24 : 8;
17820
- return words <= 3 && text.length < cap;
17821
- }
17822
- /**
17823
- * Which settled agent lines were cut off with so little spoken that they draw
17824
- * nothing. A line counts as cut off when the hook saw it truncated, or when
17825
- * the worker reported its turn interrupted and it is that turn's LAST agent
17826
- * line (`interruptedBy` covers the turn; earlier lines of it finished).
17827
- * Fillers are never replies.
17828
- */
17829
- function negligibleLineIndexes(lines, interrupted) {
17830
- const hidden = /* @__PURE__ */ new Set();
17831
- const seen = /* @__PURE__ */ new Set();
17832
- for (let i = lines.length - 1; i >= 0; i -= 1) {
17833
- const line = lines[i];
17834
- if (line.speaker !== "agent" || !line.final || line.filler) continue;
17835
- const last = !seen.has(line.turnId);
17836
- seen.add(line.turnId);
17837
- if ((line.truncated || last && interrupted.has(line.turnId)) && isNegligibleText(line.text)) hidden.add(i);
17838
- }
17839
- return hidden;
17840
- }
17841
- /**
17842
- * Which typed turns are the server's copy of a line the call is drawing live.
17843
- *
17844
- * Only turns the poll delivered (they carry `seq`) can be copies; a turn the
17845
- * shopper typed is never hidden. A copy reaches the screen AFTER the line it
17846
- * copies (the server stores a line once it is spoken, and the poll fetches it
17847
- * later), so a live line only absorbs a copy stamped after it. That keeps a new
17848
- * call's greeting from hiding the previous call's identical one. Each live line
17849
- * absorbs at most one copy, so a caller who said "yes" twice keeps both answers
17850
- * if the poll only has one of them.
17851
- *
17852
- * When a new call starts, `useVoiceSession` clears its transcript, the live
17853
- * lines are gone, and the server's copies draw instead. That is how the
17854
- * previous call stays on screen.
17855
- *
17856
- * @param typedStamps, spokenStamps `TurnOrderClock` stamps, index for index
17857
- */
17858
- function echoedTurnIndexes(typed, typedStamps, spoken, spokenStamps) {
17859
- const key = (line) => `${line.speaker}\u0000${line.text.trim().replace(/\s+/gu, " ")}`;
17860
- const live = [];
17861
- spoken.forEach((line, i) => {
17862
- if (line.final) live.push([key(line), spokenStamps[i]]);
17863
- });
17864
- const echoed = /* @__PURE__ */ new Set();
17865
- typed.forEach((turn, i) => {
17866
- if (turn.seq === void 0 || turn.speaker === "event") return;
17867
- const k = key(turn);
17868
- const at = live.findIndex(([lk, stamp]) => lk === k && stamp < typedStamps[i]);
17869
- if (at < 0) return;
17870
- live.splice(at, 1);
17871
- echoed.add(i);
17872
- });
17873
- return echoed;
17874
- }
17875
- /**
17876
- * Where the "Call started" divider goes: just before the call's first line,
17877
- * when something is already on screen above it. `null` means no divider.
17878
- *
17879
- * Stamps are integers from `TurnOrderClock`, so half a step before the first
17880
- * line sorts the divider between it and the row above it.
17881
- *
17882
- * @param spoken this call's rows, @param others every other row on screen
17883
- */
17884
- function callStartStamp(spoken, others) {
17885
- if (spoken.length === 0) return null;
17886
- const first = Math.min(...spoken.map((row) => row.stamp));
17887
- return others.some((row) => row.stamp < first) ? first - .5 : null;
17888
- }
17889
18378
  //#endregion
17890
18379
  //#region src/host-widget.tsx
17891
18380
  /**
@@ -18267,10 +18756,28 @@ function deriveCallPhase(voice) {
18267
18756
  * when the caller did not. See `renderers.ts` for why they are two functions.
18268
18757
  */
18269
18758
  function ConciergeWidget({ renderer, ...props }) {
18270
- return /* @__PURE__ */ jsx(ConciergeHost, {
18759
+ const host = /* @__PURE__ */ jsx(ConciergeHost, {
18271
18760
  ...props,
18272
18761
  renderer: renderer ?? rendererFor(props.generation)
18273
18762
  });
18763
+ const brand = useMemo(() => brandColor(props.brandPrimary), [props.brandPrimary]);
18764
+ return props.generation === "widget" ? /* @__PURE__ */ jsx(WidgetThemeScope, {
18765
+ color: props.color ?? brand,
18766
+ type: props.type,
18767
+ children: host
18768
+ }) : host;
18769
+ }
18770
+ function brandColor(primary) {
18771
+ if (primary === void 0) return void 0;
18772
+ try {
18773
+ parseHex(primary);
18774
+ } catch {
18775
+ return;
18776
+ }
18777
+ return {
18778
+ primary,
18779
+ tone: "light"
18780
+ };
18274
18781
  }
18275
18782
  function ConciergeHost({ renderer, embedKey, apiBase, socketUrl, socketPath, bridge, siteProfile, collector, messages = defaultWidgetMessages, locale = "en", productHref, hostRoutes, curationHref, brandPrimary, brandSecondary, brandAccent, avatar, attribution, privacyChoices, color, type, identity, layout, copy, bottomOffset, showPrice, cardImageAspect, starters, voiceAvailable, direction, proactive, initialDraft, initialSelection, initialFocus, initialMinimised, insets, hold, audio, onReady, cartLineIds }) {
18276
18783
  /**
@@ -19566,7 +20073,9 @@ function ConciergeHost({ renderer, embedKey, apiBase, socketUrl, socketPath, bri
19566
20073
  }]);
19567
20074
  const lastIndexBySpeaker = /* @__PURE__ */ new Map();
19568
20075
  lines.forEach((l, i) => lastIndexBySpeaker.set(l.speaker, i));
19569
- const negligible = negligibleLineIndexes(lines, interruptedRef.current);
20076
+ const cut = cutLineIndexes(lines, interruptedRef.current);
20077
+ const negligible = negligibleLineIndexes(lines, cut);
20078
+ const tagged = taggedCutIndexes(lines, cut, interruptedRef.current);
19570
20079
  const visible = lines.map((line, i) => ({
19571
20080
  line,
19572
20081
  i
@@ -19679,6 +20188,7 @@ function ConciergeHost({ renderer, embedKey, apiBase, socketUrl, socketPath, bri
19679
20188
  locale: line.locale,
19680
20189
  final: line.final,
19681
20190
  ...line.filler ? { filler: true } : {},
20191
+ ...tagged.has(i) ? { cut: true } : {},
19682
20192
  ...bound === void 0 ? {} : { cards: {
19683
20193
  ...bound.curationId !== void 0 ? { curationId: bound.curationId } : {},
19684
20194
  items: bound.items
@@ -20120,7 +20630,8 @@ function ConciergeHost({ renderer, embedKey, apiBase, socketUrl, socketPath, bri
20120
20630
  onToggleMic,
20121
20631
  ...voiceEnabled ? {
20122
20632
  onEndCall: () => void voice.stop(),
20123
- callPhase
20633
+ callPhase,
20634
+ call: voice
20124
20635
  } : {},
20125
20636
  onSendText,
20126
20637
  escalated,
@@ -20148,4 +20659,4 @@ function ConciergeHost({ renderer, embedKey, apiBase, socketUrl, socketPath, bri
20148
20659
  });
20149
20660
  }
20150
20661
  //#endregion
20151
- export { DOCK_STATES as $, WIDGET_THEME_TOKENS as $t, stripBidiControls as A, RopeKnot as An, SHEET_EXPANDED_VH as At, edgeOf as B, persistAlign as Bt, readsAsCartViewIntent as C, resolveWidgetMessages as Cn, MOBILE_MARGIN as Ct, WidgetCardList as D, WIDGET_AVATARS as Dn, RADII as Dt, WidgetCartSummary as E, DEFAULT_WIDGET_AVATAR as En, PROACTIVE_NUDGE_MS as Et, ConciergeShell as F, SHORT_VIEWPORT as Ft, IDLE_SNAPSHOT as G, readStoredMinimised as Gt, panelClasses as H, pillAnchor as Ht, ConciergeLauncher as I, Z_INDEX as It, SESSION_EVENTS as J, snapAlign as Jt, botStateFor as K, rowWidthLen as Kt, CONCIERGE_POSITIONS as L, bottomLen as Lt, DockRenderer as M, labelProps as Mn, SHEET_PEEK_MAX as Mt, ShellRenderer as N, cn as Nn, SHEET_TOP_CLEARANCE as Nt, WidgetMarkdown as O, isWidgetAvatar as On, ROW_H as Ot, deriveWidgetView as P, SHEET_TUCK as Pt, Dock as Q, SYSTEM_FONT_STACK as Qt, DEFAULT_CONCIERGE_POSITION as R, containerAnchor as Rt, basketIntentFromTurns as S, formatMessage as Sn, MARK as St, textDirectionFor as T, MorphingLoader as Tn, PILL_MARK as Tt, positionClasses as U, readStored as Ut, nearestPosition as V, persistMinimised as Vt, positionForArrow as W, readStoredAlign as Wt, formatMs as X, CARD_RADIUS_MAX_PX as Xt, SessionLog as Y, writeStored as Yt, latencyBetween as Z, SHEET_RADIUS_MAX_PX as Zt, isSameOriginPath as _, relativeLuminance as _n, DRAG_CLICK_WINDOW_MS as _t, MAX_REPORTED_CART_LINES as a, formatHex as an, idleConciergeInput as at, VoiceWidget as b, withAlpha as bn, FLOAT_GAP as bt, deriveCallPhase as c, linearRgbToOklab as cn, ACTIVITY_W as ct, resolveCheckoutUrl as d, oklabToHex as dn, DESKTOP_BOTTOM as dt, deriveTheme as en, deriveDockState as et, toChatCart as f, oklabToLinearRgb as fn, DESKTOP_BREAKPOINT as ft, CHECKOUT_CAPTURE_REQUIRED as g, parseHex as gn, DOCK_MINIMISED_STORAGE_KEY as gt, useVoiceSession as h, oklchToOklab as hn, DOCK_ALIGN_STORAGE_KEY as ht, ConciergeWidget as i, contrastRatio as in, deriveConciergeState as it, rendererFor as j, BotFace as jn, SHEET_GAP as jt, parseBlocks as k, KNOT_PATH as kn, SHEET_EXPANDED_DESKTOP_MAX as kt, mergeAddedCartLine as l, linearToSrgb as ln, BOTTOM_FLOOR as lt, createWidgetVoiceTokenFetcher as m, oklchToHex as mn, DESKTOP_WIDTHS as mt, CART_LINE_VARIANT_ID_SHAPE as n, themeToInlineStyle as nn, idleDockInput as nt, cartLinesFromSnapshot as o, hexToOklab as on, formatMoney as ot, ROOM_EVENTS as p, oklabToOklch as pn, DESKTOP_GUTTER as pt, SseFrameParser as q, sheetMaxHeightLen as qt, ConciergeHost as r, themeToMarkedHostCss as rn, CONCIERGE_STATES as rt, chooseOptionsAction as s, hexToOklch as sn, WIDGET_MESSAGE_MAX_LENGTH as st, CART_LINE_PLATFORM_VARIANT_ID_SHAPE as t, themeToCss as tn, deriveDockView as tt, resolveAddToCartHandler as u, mixToward as un, CONTROL as ut, useChatSession as v, rotateHue as vn, DRAG_TAP_SLOP_PX as vt, readsAsCheckoutIntent as w, widgetMessagesFromCopy as wn, PILL_H as wt, VoiceWidgetWithRenderer as x, defaultWidgetMessages as xn, GLASS_IDLE_MS as xt, detectPage as y, srgbToLinear as yn, FLOAT_DUCK_DISMISS_MS as yt, alignOf as z, geometryVars as zt };
20662
+ 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 };