@saar-ai/web-widget 0.2.0 → 0.3.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.
- package/dist/avatar-face.d.ts +33 -0
- package/dist/avatar-face.d.ts.map +1 -0
- package/dist/avatar.d.ts +17 -0
- package/dist/avatar.d.ts.map +1 -0
- package/dist/bot-face.d.ts +17 -0
- package/dist/bot-face.d.ts.map +1 -1
- package/dist/chunks/{host-widget-iy3qC-1p.js → host-widget-BlihQKm5.js} +1362 -402
- package/dist/concierge-launcher.d.ts +4 -1
- package/dist/concierge-launcher.d.ts.map +1 -1
- package/dist/concierge-shell.d.ts +55 -6
- package/dist/concierge-shell.d.ts.map +1 -1
- package/dist/generated/widget-css.d.ts.map +1 -1
- package/dist/host-widget.d.ts +20 -1
- package/dist/host-widget.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/messages.d.ts +55 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/next/index.js +1 -1
- package/dist/rope-knot.d.ts +13 -0
- package/dist/rope-knot.d.ts.map +1 -0
- package/dist/session-log.d.ts +1 -1
- package/dist/session-log.d.ts.map +1 -1
- package/dist/use-chat-session.d.ts +65 -1
- package/dist/use-chat-session.d.ts.map +1 -1
- package/dist/voice-widget.d.ts +33 -4
- package/dist/voice-widget.d.ts.map +1 -1
- package/dist/widget-cards.d.ts +5 -2
- package/dist/widget-cards.d.ts.map +1 -1
- package/dist/widget.css +1 -1
- package/package.json +3 -2
- package/src/styles/concierge.css +377 -0
|
@@ -3422,7 +3422,14 @@ function BotFace({ state = "idle", size = "sm", messageArrived = false, label })
|
|
|
3422
3422
|
label
|
|
3423
3423
|
});
|
|
3424
3424
|
}
|
|
3425
|
-
/**
|
|
3425
|
+
/**
|
|
3426
|
+
* `role="img"` + a name, or nothing at all — never a name we invented.
|
|
3427
|
+
*
|
|
3428
|
+
* Exported so `rope-knot.tsx` (the 'knot' avatar) shares this exact
|
|
3429
|
+
* accessibility contract rather than redeclaring it — both avatars are
|
|
3430
|
+
* decorative-by-default for the identical reason (see this module's doc
|
|
3431
|
+
* comment), and a second copy would be free to drift.
|
|
3432
|
+
*/
|
|
3426
3433
|
function labelProps(label) {
|
|
3427
3434
|
return label === void 0 ? { "aria-hidden": true } : {
|
|
3428
3435
|
role: "img",
|
|
@@ -3432,7 +3439,7 @@ function labelProps(label) {
|
|
|
3432
3439
|
function BotFaceSmall({ state, label }) {
|
|
3433
3440
|
return /* @__PURE__ */ jsxs("div", {
|
|
3434
3441
|
...labelProps(label),
|
|
3435
|
-
className: "relative flex h-16 w-16 items-center justify-center rounded-3xl border border-brand-plum/10 bg-card/90 p-
|
|
3442
|
+
className: "relative flex h-16 w-16 items-center justify-center rounded-3xl border border-brand-plum/10 bg-card/90 p-0 backdrop-blur-md",
|
|
3436
3443
|
children: [/* @__PURE__ */ jsx("div", {
|
|
3437
3444
|
"aria-hidden": true,
|
|
3438
3445
|
className: cn("absolute inset-0 rounded-3xl bg-gradient-to-tr from-brand-rose/12 via-brand-amber/8 to-brand-plum/8 blur-md transition-opacity duration-500", state === "speaking" && "opacity-90 animate-[bot-halo-speak_1.8s_ease-in-out_infinite]", state === "listening" && "opacity-75 animate-[bot-halo-listen_2.2s_ease-in-out_infinite]", state === "thinking" && "opacity-55", state === "idle" && "opacity-45")
|
|
@@ -3618,6 +3625,285 @@ function BotOrbLarge({ state, messageArrived, label }) {
|
|
|
3618
3625
|
});
|
|
3619
3626
|
}
|
|
3620
3627
|
//#endregion
|
|
3628
|
+
//#region src/rope-knot.tsx
|
|
3629
|
+
/**
|
|
3630
|
+
* The `'knot'` avatar — a single hand-drawn line that loops through itself
|
|
3631
|
+
* into a knot, in the two sizes the widget uses (`sm` trigger, `lg` panel
|
|
3632
|
+
* orb-slot) and the same four {@link BotState}s `BotFace` (the `'orb'`
|
|
3633
|
+
* avatar) renders. Selected per tenant via `appearance.avatar` — see
|
|
3634
|
+
* `avatar.ts` — and otherwise a drop-in for `BotFace` at every call site:
|
|
3635
|
+
* same `state`/`size`/`label` contract, same `labelProps` accessibility rule
|
|
3636
|
+
* (imported from `bot-face.tsx` rather than redeclared).
|
|
3637
|
+
*
|
|
3638
|
+
* Ported from the Lovable prototype's `RopeKnot.tsx`.
|
|
3639
|
+
*
|
|
3640
|
+
* ## Why the colour vars are declared HERE, not in `concierge.css`
|
|
3641
|
+
*
|
|
3642
|
+
* The rope's colour is never hardcoded — `--knot-ink` and its
|
|
3643
|
+
* `-faint`/`-halo`/`-surface` derivatives alias `--brand-plum`, the same
|
|
3644
|
+
* tenant-config-driven variable `BotFace`'s gradient reads. They used to
|
|
3645
|
+
* live in a `:root { --knot-ink: var(--brand-plum, …); … }` block in
|
|
3646
|
+
* `concierge.css`, which was broken two ways at once: `:root` matches
|
|
3647
|
+
* nothing inside the CDN embed's shadow tree (the tenant's brand colours
|
|
3648
|
+
* never reach a shadow-mounted widget at all), and even in light DOM, a
|
|
3649
|
+
* `--x: var(--y)` declaration resolves `var(--y)` using the DECLARING
|
|
3650
|
+
* element's own cascade AT THAT MOMENT — `:root` has no tenant override on
|
|
3651
|
+
* it, that override lives on a DESCENDANT (`ConciergeShell`'s
|
|
3652
|
+
* `skinStyle`-carrying wrapper), so every tenant silently got the built-in
|
|
3653
|
+
* plum default regardless of what they published.
|
|
3654
|
+
*
|
|
3655
|
+
* `RopeKnotFrame`'s own root div is always rendered somewhere INSIDE that
|
|
3656
|
+
* `skinStyle` wrapper (`ConciergeShell` renders both the panel orb and,
|
|
3657
|
+
* via `ConciergeLauncher`, the collapsed pill, and both sit inside the one
|
|
3658
|
+
* `<div data-skin style={skinStyle}>` root). Declaring the vars on THIS
|
|
3659
|
+
* element via inline `style` means `var(--brand-plum, …)` resolves using
|
|
3660
|
+
* THIS element's own cascade — which, by the time render reaches here, has
|
|
3661
|
+
* already inherited whatever override the ancestor set. Everything BELOW
|
|
3662
|
+
* this div (the halo, the svg, the drawn path) then just inherits the
|
|
3663
|
+
* already-resolved values normally, in both light and shadow DOM, no
|
|
3664
|
+
* selector needed at all. Same fix `concierge.css`'s own `@theme inline`
|
|
3665
|
+
* block uses for `--color-brand-plum` (see that block's doc comment) —
|
|
3666
|
+
* "resolve where it's used," not "resolve once at the top."
|
|
3667
|
+
*
|
|
3668
|
+
* ## The crossfade
|
|
3669
|
+
*
|
|
3670
|
+
* Every state change freezes the `stroke-dasharray` the rope was showing —
|
|
3671
|
+
* read directly off the live element via `getComputedStyle` at the instant
|
|
3672
|
+
* the state actually changes — into `--rk-from`, then remounts the drawn
|
|
3673
|
+
* path so the incoming state's `rk-blend-to-*` animation eases OUT of that
|
|
3674
|
+
* exact shape instead of snapping back to the self-tying intro. This is a
|
|
3675
|
+
* single synchronous read inside the state-change effect, not a polling
|
|
3676
|
+
* loop: a CSS animation keeps an element's OWN computed style live at every
|
|
3677
|
+
* instant, so there is nothing to gain by sampling continuously, and a
|
|
3678
|
+
* `requestAnimationFrame` loop that ran forever — for the life of the
|
|
3679
|
+
* component, including a launcher pill that never leaves `state="idle"` and
|
|
3680
|
+
* can never blend at all, and regardless of `prefers-reduced-motion`, where
|
|
3681
|
+
* the dash never even changes — was a real cost on a merchant's page for no
|
|
3682
|
+
* benefit.
|
|
3683
|
+
*/
|
|
3684
|
+
var KNOT_PATH = "M2 54 C15 54 24 55 31 53 C40 50 44 40 54 41 C64 42 67 51 60 57 C52 64 38 64 33 57 C29 51 34 45 42 46 C50 47 58 52 68 53.5 C80 55 90 54 98 54";
|
|
3685
|
+
/** Short pulse rider used while listening/thinking. Dash-array sum equals `pathLength={100}`. */
|
|
3686
|
+
var PULSE_DASH = "9 91";
|
|
3687
|
+
/**
|
|
3688
|
+
* The colour vars every layer below reads — declared once, as inline style,
|
|
3689
|
+
* on `RopeKnotFrame`'s own root (see this module's doc comment for why not
|
|
3690
|
+
* `concierge.css`'s `:root`).
|
|
3691
|
+
*
|
|
3692
|
+
* `color-mix()` has no literal fallback here, consistent with the rest of
|
|
3693
|
+
* this package: `concierge-shell.tsx`'s glow/shadow effects and
|
|
3694
|
+
* `bot-face.tsx`'s halo already use unguarded `color-mix()` throughout, with
|
|
3695
|
+
* no `@supports` branch anywhere in this codebase. Adding one just for the
|
|
3696
|
+
* knot would be new, inconsistent machinery for a real but narrow gap — of
|
|
3697
|
+
* this widget's stated browser floor (`AGENTS.md` → "The browser floor",
|
|
3698
|
+
* ~March 2023), only the FLOOR's exact Chrome version (110) predates
|
|
3699
|
+
* `color-mix()` (Chrome 111); Safari's floor (16.4) and Firefox's (115) both
|
|
3700
|
+
* postdate their own `color-mix()` landings (16.2, 113). The honest
|
|
3701
|
+
* degradation on that one version: `stroke`/`background` are inherited
|
|
3702
|
+
* properties, so an unresolvable `var()` falls back to the inherited value
|
|
3703
|
+
* (effectively transparent/unset) rather than to solid ink — a fainter knot,
|
|
3704
|
+
* not a broken one.
|
|
3705
|
+
*/
|
|
3706
|
+
var KNOT_COLOR_VARS = {
|
|
3707
|
+
["--knot-ink"]: "var(--brand-plum, oklch(0.34 0.0728 128.34))",
|
|
3708
|
+
["--knot-ink-faint"]: "color-mix(in oklab, var(--knot-ink) 12%, transparent)",
|
|
3709
|
+
["--knot-halo"]: "color-mix(in oklab, var(--knot-ink) 12%, transparent)",
|
|
3710
|
+
["--knot-surface"]: "color-mix(in oklab, var(--knot-ink) 4%, var(--widget-card, oklch(0.99 0 0)))"
|
|
3711
|
+
};
|
|
3712
|
+
var PULSE_SPEED = {
|
|
3713
|
+
idle: "0s",
|
|
3714
|
+
listening: "2.2s",
|
|
3715
|
+
thinking: "1.6s",
|
|
3716
|
+
speaking: "1.1s"
|
|
3717
|
+
};
|
|
3718
|
+
function RopeKnot({ state = "idle", size = "sm", label, tightenKey = 0 }) {
|
|
3719
|
+
if (size === "lg") return /* @__PURE__ */ jsx(RopeKnotFrame, {
|
|
3720
|
+
state,
|
|
3721
|
+
label,
|
|
3722
|
+
tightenKey,
|
|
3723
|
+
outerClassName: "flex h-24 w-24 items-center justify-center",
|
|
3724
|
+
artClassName: "h-[4.8rem] w-[4.8rem]"
|
|
3725
|
+
});
|
|
3726
|
+
return /* @__PURE__ */ jsx(RopeKnotFrame, {
|
|
3727
|
+
state,
|
|
3728
|
+
label,
|
|
3729
|
+
tightenKey,
|
|
3730
|
+
outerClassName: "relative flex h-16 w-16 items-center justify-center rounded-3xl border border-brand-plum/10 bg-card/90 p-0 backdrop-blur-md",
|
|
3731
|
+
artClassName: "h-full w-full",
|
|
3732
|
+
chrome: true
|
|
3733
|
+
});
|
|
3734
|
+
}
|
|
3735
|
+
/**
|
|
3736
|
+
* The halo + sway wrapper both sizes share, and the ONE structural
|
|
3737
|
+
* difference between them: the small trigger carries `BotFaceSmall`'s card
|
|
3738
|
+
* chrome (border, blurred backdrop, rounded corners) so swapping avatars
|
|
3739
|
+
* never changes the trigger's frame — only what is drawn inside it. The
|
|
3740
|
+
* large slot carries none of that; `ConciergeShell` already gives the orb
|
|
3741
|
+
* slot its own ground (see that file's "opaque ground under the orb").
|
|
3742
|
+
*/
|
|
3743
|
+
function RopeKnotFrame({ state, label, tightenKey, outerClassName, artClassName, chrome = false }) {
|
|
3744
|
+
const halo = /* @__PURE__ */ jsx("div", {
|
|
3745
|
+
"aria-hidden": true,
|
|
3746
|
+
className: cn("pointer-events-none absolute inset-0 rounded-full bg-[radial-gradient(circle,var(--knot-halo),transparent_70%)] blur-md transition-opacity duration-500", state === "idle" && "opacity-0", state === "listening" && "rk-halo opacity-70", state === "thinking" && "opacity-40", state === "speaking" && "rk-halo opacity-60")
|
|
3747
|
+
});
|
|
3748
|
+
/**
|
|
3749
|
+
* Restarts the `rk-tighten` cinch on every `tightenKey` bump WITHOUT
|
|
3750
|
+
* remounting `KnotSvg` — this used to be `<div key={tightenKey}>`, which
|
|
3751
|
+
* looks like the obvious way to "replay" a CSS animation but tears down
|
|
3752
|
+
* and rebuilds the ENTIRE subtree underneath it on every bump. `KnotSvg`
|
|
3753
|
+
* carries the crossfade state (`blend`/`fromDash`/`tap`) in refs and
|
|
3754
|
+
* state that a remount wipes to their initial values — so a tighten
|
|
3755
|
+
* pulse that happened to land in the SAME commit as a state change (a
|
|
3756
|
+
* real, deterministic sequence: `useChatSession.sendText` sets the
|
|
3757
|
+
* transcript and flips `awaitingAgent` in one batch, which is exactly
|
|
3758
|
+
* `messageArrived`'s rising edge — `concierge-shell.tsx`'s tighten
|
|
3759
|
+
* trigger — landing together with a `listening` → `thinking` state
|
|
3760
|
+
* transition) both skipped the crossfade AND replayed the self-tying
|
|
3761
|
+
* intro from scratch, because the remount reset `blend` to 0.
|
|
3762
|
+
*
|
|
3763
|
+
* The fix is the standard "restart a CSS animation without touching the
|
|
3764
|
+
* DOM subtree" technique: remove the class, force a synchronous reflow
|
|
3765
|
+
* (reading `offsetWidth` — the read is what forces the browser to flush
|
|
3766
|
+
* layout, so the SUBSEQUENT class add is seen as a genuinely NEW
|
|
3767
|
+
* animation start rather than a no-op), then re-add it. `KnotSvg` is
|
|
3768
|
+
* never unmounted, so its own state survives untouched.
|
|
3769
|
+
*/
|
|
3770
|
+
const artRef = useRef(null);
|
|
3771
|
+
const prevTighten = useRef(tightenKey);
|
|
3772
|
+
useEffect(() => {
|
|
3773
|
+
if (tightenKey === prevTighten.current) return;
|
|
3774
|
+
prevTighten.current = tightenKey;
|
|
3775
|
+
const el = artRef.current;
|
|
3776
|
+
if (!el) return;
|
|
3777
|
+
el.classList.remove("rk-tighten");
|
|
3778
|
+
el.offsetWidth;
|
|
3779
|
+
el.classList.add("rk-tighten");
|
|
3780
|
+
}, [tightenKey]);
|
|
3781
|
+
const art = /* @__PURE__ */ jsx("div", {
|
|
3782
|
+
ref: artRef,
|
|
3783
|
+
className: cn("rk-tighten relative", artClassName),
|
|
3784
|
+
children: /* @__PURE__ */ jsx(KnotSvg, {
|
|
3785
|
+
state,
|
|
3786
|
+
tightenKey
|
|
3787
|
+
})
|
|
3788
|
+
});
|
|
3789
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
3790
|
+
...labelProps(label),
|
|
3791
|
+
className: cn("rk-sway relative", outerClassName),
|
|
3792
|
+
style: {
|
|
3793
|
+
...KNOT_COLOR_VARS,
|
|
3794
|
+
animationDuration: state === "idle" ? "6s" : "7s"
|
|
3795
|
+
},
|
|
3796
|
+
children: [halo, chrome ? /* @__PURE__ */ jsx("div", {
|
|
3797
|
+
className: "relative z-10 flex h-full w-full items-center justify-center rounded-2xl border border-brand-plum/10 bg-[var(--knot-surface)]",
|
|
3798
|
+
children: art
|
|
3799
|
+
}) : art]
|
|
3800
|
+
});
|
|
3801
|
+
}
|
|
3802
|
+
/** The drawn line itself — the part of the source `RopeKnot` component with no size opinion. */
|
|
3803
|
+
function KnotSvg({ state, tightenKey }) {
|
|
3804
|
+
const glowId = `rk-glow${useId()}`;
|
|
3805
|
+
const pathRef = useRef(null);
|
|
3806
|
+
const prev = useRef(state);
|
|
3807
|
+
const [blend, setBlend] = useState(0);
|
|
3808
|
+
const fromDash = useRef("100 0 0");
|
|
3809
|
+
useEffect(() => {
|
|
3810
|
+
if (prev.current === state) return;
|
|
3811
|
+
prev.current = state;
|
|
3812
|
+
const el = pathRef.current;
|
|
3813
|
+
if (el) {
|
|
3814
|
+
const d = getComputedStyle(el).strokeDasharray;
|
|
3815
|
+
if (d && d !== "none") fromDash.current = d.replace(/px/g, "");
|
|
3816
|
+
}
|
|
3817
|
+
setBlend((b) => b + 1);
|
|
3818
|
+
}, [state]);
|
|
3819
|
+
const [tap, setTap] = useState(false);
|
|
3820
|
+
useEffect(() => {
|
|
3821
|
+
if (tightenKey === 0) return;
|
|
3822
|
+
setTap(true);
|
|
3823
|
+
const t = setTimeout(() => setTap(false), 750);
|
|
3824
|
+
return () => clearTimeout(t);
|
|
3825
|
+
}, [tightenKey]);
|
|
3826
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
3827
|
+
viewBox: "0 0 100 100",
|
|
3828
|
+
className: cn("h-full w-full overflow-visible", state === "thinking" && "rk-thinking"),
|
|
3829
|
+
children: [
|
|
3830
|
+
/* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsxs("linearGradient", {
|
|
3831
|
+
id: glowId,
|
|
3832
|
+
x1: "0",
|
|
3833
|
+
y1: "0",
|
|
3834
|
+
x2: "1",
|
|
3835
|
+
y2: "0",
|
|
3836
|
+
children: [
|
|
3837
|
+
/* @__PURE__ */ jsx("stop", {
|
|
3838
|
+
offset: "0%",
|
|
3839
|
+
stopColor: "var(--knot-ink)",
|
|
3840
|
+
stopOpacity: "0"
|
|
3841
|
+
}),
|
|
3842
|
+
/* @__PURE__ */ jsx("stop", {
|
|
3843
|
+
offset: "50%",
|
|
3844
|
+
stopColor: "var(--knot-ink)",
|
|
3845
|
+
stopOpacity: "1"
|
|
3846
|
+
}),
|
|
3847
|
+
/* @__PURE__ */ jsx("stop", {
|
|
3848
|
+
offset: "100%",
|
|
3849
|
+
stopColor: "var(--knot-ink)",
|
|
3850
|
+
stopOpacity: "0"
|
|
3851
|
+
})
|
|
3852
|
+
]
|
|
3853
|
+
}) }),
|
|
3854
|
+
/* @__PURE__ */ jsx("path", {
|
|
3855
|
+
d: KNOT_PATH,
|
|
3856
|
+
fill: "none",
|
|
3857
|
+
stroke: "var(--knot-ink-faint)",
|
|
3858
|
+
strokeWidth: "3",
|
|
3859
|
+
strokeLinecap: "round",
|
|
3860
|
+
className: cn("transition-opacity duration-500", state === "listening" ? "opacity-100" : "opacity-60")
|
|
3861
|
+
}),
|
|
3862
|
+
/* @__PURE__ */ jsx("path", {
|
|
3863
|
+
ref: pathRef,
|
|
3864
|
+
d: KNOT_PATH,
|
|
3865
|
+
pathLength: 100,
|
|
3866
|
+
style: { ["--rk-from"]: fromDash.current },
|
|
3867
|
+
className: cn("rk-draw", state === "idle" && "rk-idle", state === "listening" && "rk-listening", state === "thinking" && "rk-thread", state === "speaking" && "rk-speaking", blend > 0 && !tap && "rk-blend", tap && "rk-tap"),
|
|
3868
|
+
fill: "none",
|
|
3869
|
+
stroke: "var(--knot-ink)",
|
|
3870
|
+
strokeLinecap: "round",
|
|
3871
|
+
strokeLinejoin: "round"
|
|
3872
|
+
}, blend),
|
|
3873
|
+
state !== "idle" && /* @__PURE__ */ jsx("path", {
|
|
3874
|
+
d: KNOT_PATH,
|
|
3875
|
+
pathLength: 100,
|
|
3876
|
+
className: cn("rk-pulse transition-opacity duration-500", state === "speaking" ? "opacity-0" : "opacity-100"),
|
|
3877
|
+
style: { animationDuration: PULSE_SPEED[state] },
|
|
3878
|
+
fill: "none",
|
|
3879
|
+
stroke: `url(#${glowId})`,
|
|
3880
|
+
strokeWidth: "4",
|
|
3881
|
+
strokeLinecap: "round",
|
|
3882
|
+
strokeDasharray: PULSE_DASH
|
|
3883
|
+
})
|
|
3884
|
+
]
|
|
3885
|
+
});
|
|
3886
|
+
}
|
|
3887
|
+
//#endregion
|
|
3888
|
+
//#region src/avatar.ts
|
|
3889
|
+
/**
|
|
3890
|
+
* Which face the widget draws — a per-tenant `appearance.avatar` choice.
|
|
3891
|
+
*
|
|
3892
|
+
* `'orb'` is `BotFace`, the animated gradient blob this widget has always
|
|
3893
|
+
* shipped. `'knot'` is `RopeKnot`, a hand-drawn rope line that ties and
|
|
3894
|
+
* unties itself through the same four {@link BotState}s. Kept as data,
|
|
3895
|
+
* separate from the components, for the same reason `bot-state.ts` keeps
|
|
3896
|
+
* `BotState` separate from `BotFace`: parsing and defaulting have to be
|
|
3897
|
+
* assertable without rendering either avatar.
|
|
3898
|
+
*/
|
|
3899
|
+
var WIDGET_AVATARS = ["orb", "knot"];
|
|
3900
|
+
/** What every layer in this package falls back to when a tenant never published one. */
|
|
3901
|
+
var DEFAULT_WIDGET_AVATAR = "orb";
|
|
3902
|
+
/** Whether a value is an avatar this widget knows how to render. Mirrors `bot-state.ts`'s `isBotState`. */
|
|
3903
|
+
function isWidgetAvatar(value) {
|
|
3904
|
+
return typeof value === "string" && WIDGET_AVATARS.includes(value);
|
|
3905
|
+
}
|
|
3906
|
+
//#endregion
|
|
3621
3907
|
//#region ../../node_modules/.pnpm/lucide-react@1.25.0_react@19.2.7/node_modules/lucide-react/dist/esm/shared/src/utils/mergeClasses.mjs
|
|
3622
3908
|
/**
|
|
3623
3909
|
* @license lucide-react v1.25.0 - ISC
|
|
@@ -3887,6 +4173,25 @@ var X = createLucideIcon("x", [["path", {
|
|
|
3887
4173
|
key: "d8bk6v"
|
|
3888
4174
|
}]]);
|
|
3889
4175
|
//#endregion
|
|
4176
|
+
//#region src/avatar-face.tsx
|
|
4177
|
+
function AvatarFace({ avatar, state, size, label, messageArrived, tightenKey }) {
|
|
4178
|
+
switch (avatar) {
|
|
4179
|
+
case "orb": return /* @__PURE__ */ jsx(BotFace, {
|
|
4180
|
+
state,
|
|
4181
|
+
size,
|
|
4182
|
+
label,
|
|
4183
|
+
messageArrived
|
|
4184
|
+
});
|
|
4185
|
+
case "knot": return /* @__PURE__ */ jsx(RopeKnot, {
|
|
4186
|
+
state,
|
|
4187
|
+
size,
|
|
4188
|
+
label,
|
|
4189
|
+
tightenKey
|
|
4190
|
+
});
|
|
4191
|
+
default: throw new Error(`Unhandled widget avatar: ${String(avatar)}`);
|
|
4192
|
+
}
|
|
4193
|
+
}
|
|
4194
|
+
//#endregion
|
|
3890
4195
|
//#region src/position.ts
|
|
3891
4196
|
/**
|
|
3892
4197
|
* Where the concierge sits on the host page, and how a visitor moves it.
|
|
@@ -3984,11 +4289,18 @@ function panelClasses(position) {
|
|
|
3984
4289
|
}
|
|
3985
4290
|
//#endregion
|
|
3986
4291
|
//#region src/concierge-launcher.tsx
|
|
3987
|
-
function ConciergeLauncher({ label, srLabel, moveLabel, position, onPositionChange, onOpen, hidden, id, testId }) {
|
|
4292
|
+
function ConciergeLauncher({ label, srLabel, moveLabel, position, onPositionChange, onOpen, hidden, id, testId, avatar = "orb" }) {
|
|
3988
4293
|
const rootRef = useRef(null);
|
|
3989
4294
|
/** Pixel offset while a drag is in flight; `null` when it is not. */
|
|
3990
4295
|
const [drag, setDrag] = useState(null);
|
|
3991
4296
|
/**
|
|
4297
|
+
* Bumped on every press — `RopeKnot`'s click feedback (`rk-tighten` +
|
|
4298
|
+
* `rk-tap`), the same gesture the Lovable prototype's `RopeKnotTrigger`
|
|
4299
|
+
* wired directly into its own `onClick`. `BotFace` has no equivalent prop
|
|
4300
|
+
* and ignores an unused number, so this costs the orb nothing.
|
|
4301
|
+
*/
|
|
4302
|
+
const [tightenKey, setTightenKey] = useState(0);
|
|
4303
|
+
/**
|
|
3992
4304
|
* Where the drag started: the pointer, and the pill's centre AT THAT MOMENT.
|
|
3993
4305
|
*
|
|
3994
4306
|
* The centre is captured on pointer-DOWN rather than measured on pointer-up,
|
|
@@ -4089,17 +4401,22 @@ function ConciergeLauncher({ label, srLabel, moveLabel, position, onPositionChan
|
|
|
4089
4401
|
type: "button",
|
|
4090
4402
|
"aria-label": label === void 0 ? srLabel : void 0,
|
|
4091
4403
|
tabIndex: hidden ? -1 : 0,
|
|
4092
|
-
onClick:
|
|
4404
|
+
onClick: () => {
|
|
4405
|
+
setTightenKey((k) => k + 1);
|
|
4406
|
+
onOpen();
|
|
4407
|
+
},
|
|
4093
4408
|
"data-testid": testId ? `${testId}-open` : void 0,
|
|
4094
4409
|
className: "flex items-center gap-2.5 rounded-full focus-visible:ring-brand-plum/30 focus-visible:ring-2 focus-visible:outline-none",
|
|
4095
4410
|
children: [/* @__PURE__ */ jsx("span", {
|
|
4096
4411
|
"aria-hidden": true,
|
|
4097
|
-
className: "relative block size-
|
|
4412
|
+
className: "relative block size-12 shrink-0",
|
|
4098
4413
|
children: /* @__PURE__ */ jsx("span", {
|
|
4099
|
-
className: "absolute start-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 scale-[0.
|
|
4100
|
-
children: /* @__PURE__ */ jsx(
|
|
4414
|
+
className: "absolute start-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 scale-[0.75] rtl:translate-x-1/2",
|
|
4415
|
+
children: /* @__PURE__ */ jsx(AvatarFace, {
|
|
4416
|
+
avatar,
|
|
4101
4417
|
state: "idle",
|
|
4102
|
-
size: "sm"
|
|
4418
|
+
size: "sm",
|
|
4419
|
+
tightenKey
|
|
4103
4420
|
})
|
|
4104
4421
|
})
|
|
4105
4422
|
}), label === void 0 ? null : /* @__PURE__ */ jsx("span", {
|
|
@@ -4111,6 +4428,108 @@ function ConciergeLauncher({ label, srLabel, moveLabel, position, onPositionChan
|
|
|
4111
4428
|
});
|
|
4112
4429
|
}
|
|
4113
4430
|
//#endregion
|
|
4431
|
+
//#region src/messages.ts
|
|
4432
|
+
/**
|
|
4433
|
+
* Message keys that carry a `{product}` placeholder — the avatar's
|
|
4434
|
+
* accessible-name states. Kept as a literal template, interpolated at
|
|
4435
|
+
* render time, never a brand name baked into this file (see the module doc
|
|
4436
|
+
* comment).
|
|
4437
|
+
*/
|
|
4438
|
+
/**
|
|
4439
|
+
* `Required<...>`, not `WidgetMessages`: keys added after 0.2.0 are optional
|
|
4440
|
+
* on the INTERFACE so a host's own complete catalogue keeps compiling, but
|
|
4441
|
+
* this object is the fallback every one of them resolves against, so it must
|
|
4442
|
+
* define all of them. The type is what makes a forgotten default a compile
|
|
4443
|
+
* error rather than an empty string on somebody's storefront.
|
|
4444
|
+
*/
|
|
4445
|
+
var defaultWidgetMessages = {
|
|
4446
|
+
state_idle: "{product} — idle",
|
|
4447
|
+
state_listening: "{product} — listening",
|
|
4448
|
+
state_thinking: "{product} — thinking",
|
|
4449
|
+
state_speaking: "{product} — speaking",
|
|
4450
|
+
mic_start: "Start talking",
|
|
4451
|
+
mic_stop: "Stop talking",
|
|
4452
|
+
open: "Open chat",
|
|
4453
|
+
minimize: "Minimise",
|
|
4454
|
+
conversation: "Chat conversation",
|
|
4455
|
+
empty: "Ask a question — speak or type.",
|
|
4456
|
+
type_placeholder: "Type a message",
|
|
4457
|
+
send: "Send",
|
|
4458
|
+
move: "Move the assistant",
|
|
4459
|
+
call_end: "End the call",
|
|
4460
|
+
handoff_event: "Handed to a human teammate",
|
|
4461
|
+
escalated_banner: "A human teammate will pick this up shortly.",
|
|
4462
|
+
status_sending: "Sending",
|
|
4463
|
+
status_sent: "Sent",
|
|
4464
|
+
typing: "Typing",
|
|
4465
|
+
suggestions_label: "Suggested questions",
|
|
4466
|
+
suggestion_1: "What is popular right now?",
|
|
4467
|
+
suggestion_2: "Help me pick something",
|
|
4468
|
+
suggestion_3: "Talk to a human",
|
|
4469
|
+
attach_label: "Attach a file",
|
|
4470
|
+
attach_uploading: "Sending {filename}…",
|
|
4471
|
+
attach_error: "Could not send {filename}. Try again.",
|
|
4472
|
+
attach_image_alt: "Attached image: {filename}",
|
|
4473
|
+
attach_download_hint: "Opens or downloads in a new tab",
|
|
4474
|
+
add_to_cart: "Add to cart",
|
|
4475
|
+
adding_to_cart: "Adding…",
|
|
4476
|
+
added_to_cart: "Added to cart",
|
|
4477
|
+
unavailable: "Unavailable",
|
|
4478
|
+
see_all: "See all {count}",
|
|
4479
|
+
cart_summary_title: "Your cart",
|
|
4480
|
+
cart_summary_total: "Total",
|
|
4481
|
+
checkout_now: "Checkout",
|
|
4482
|
+
checkout_failed: "Could not start checkout. Try again.",
|
|
4483
|
+
voice_state_connecting: "Connecting",
|
|
4484
|
+
voice_state_listening: "Listening",
|
|
4485
|
+
voice_state_thinking: "Thinking",
|
|
4486
|
+
voice_state_speaking: "Speaking"
|
|
4487
|
+
};
|
|
4488
|
+
/**
|
|
4489
|
+
* Interpolates `{token}` placeholders in a message template. Deliberately the
|
|
4490
|
+
* same `{token}` syntax `next-intl`'s ICU messages use for a plain variable,
|
|
4491
|
+
* so `apps/web`'s adapter can hand this package `t.raw(key)` (the
|
|
4492
|
+
* UN-interpolated template) and let this one function do the substitution —
|
|
4493
|
+
* one interpolation implementation, not two.
|
|
4494
|
+
*
|
|
4495
|
+
* A token with no matching var, or a var that isn't a string/number, is left
|
|
4496
|
+
* as literal text rather than thrown on — a missing translation must degrade
|
|
4497
|
+
* to a visibly-odd string, never a broken render.
|
|
4498
|
+
*/
|
|
4499
|
+
function formatMessage(template, vars) {
|
|
4500
|
+
if (!vars) return template;
|
|
4501
|
+
return template.replace(/\{(\w+)\}/g, (match, key) => {
|
|
4502
|
+
const value = vars[key];
|
|
4503
|
+
return value === void 0 ? match : String(value);
|
|
4504
|
+
});
|
|
4505
|
+
}
|
|
4506
|
+
/**
|
|
4507
|
+
* Merges tenant-authored overrides (typically the `widgetMessagesFromCopy`
|
|
4508
|
+
* result) over `defaultWidgetMessages`. An override that is `undefined`,
|
|
4509
|
+
* empty, or whitespace-only is skipped — a blank tenant string must not blank
|
|
4510
|
+
* out a working default, same "absent means unset" contract
|
|
4511
|
+
* `PublicWidgetConfig.copy`'s own fields carry.
|
|
4512
|
+
*/
|
|
4513
|
+
function resolveWidgetMessages(overrides) {
|
|
4514
|
+
if (!overrides) return defaultWidgetMessages;
|
|
4515
|
+
const merged = { ...defaultWidgetMessages };
|
|
4516
|
+
for (const [key, value] of Object.entries(overrides)) if (typeof value === "string" && value.trim() !== "") merged[key] = value;
|
|
4517
|
+
return merged;
|
|
4518
|
+
}
|
|
4519
|
+
/**
|
|
4520
|
+
* Maps `PublicWidgetConfig.copy`'s fields onto the `WidgetMessages` keys they
|
|
4521
|
+
* overlap with. `greeting` is deliberately NOT mapped here — it seeds the
|
|
4522
|
+
* first turn (`SessionBootResponse.greeting`), it is not a UI label, so a
|
|
4523
|
+
* caller that wants it has it already from the session boot response.
|
|
4524
|
+
* `offlineMessage` has no current `WidgetMessages` counterpart (nothing here
|
|
4525
|
+
* renders an "offline" state yet) and is likewise omitted rather than
|
|
4526
|
+
* guessed onto the nearest-sounding key.
|
|
4527
|
+
*/
|
|
4528
|
+
function widgetMessagesFromCopy(copy) {
|
|
4529
|
+
if (!copy) return {};
|
|
4530
|
+
return copy.placeholder !== void 0 ? { type_placeholder: copy.placeholder } : {};
|
|
4531
|
+
}
|
|
4532
|
+
//#endregion
|
|
4114
4533
|
//#region src/morphing-loader.tsx
|
|
4115
4534
|
/**
|
|
4116
4535
|
* A voice-frequency visualizer loader.
|
|
@@ -4190,7 +4609,7 @@ function MorphingLoader({ size = "md", variant = "brand", className, label = "Lo
|
|
|
4190
4609
|
];
|
|
4191
4610
|
const isLight = variant === "light";
|
|
4192
4611
|
return /* @__PURE__ */ jsxs("div", {
|
|
4193
|
-
className: cn("relative inline-flex items-end justify-center", dims, gap, isLight && "text-
|
|
4612
|
+
className: cn("relative inline-flex items-end justify-center", dims, gap, isLight && "text-[var(--widget-accent-foreground)]", className),
|
|
4194
4613
|
role: "status",
|
|
4195
4614
|
"aria-label": label,
|
|
4196
4615
|
children: [bars.map((bar, i) => /* @__PURE__ */ jsx("span", {
|
|
@@ -4216,8 +4635,21 @@ function MorphingLoader({ size = "md", variant = "brand", className, label = "Lo
|
|
|
4216
4635
|
* Top ramp when the transcript starts at the panel's top, under the floating
|
|
4217
4636
|
* orb — it has to span the orb, so a message is gone before it reaches it
|
|
4218
4637
|
* rather than sliding out from behind it half-visible.
|
|
4638
|
+
*
|
|
4639
|
+
* A CSS length EXPRESSION, not a bare number, since the aspect-ratio panel
|
|
4640
|
+
* (`w-[min(97vw,50dvh)]` + `aspect-[5/8]`) ranges from ~582px tall (mobile,
|
|
4641
|
+
* width-bound) to 800px+ (desktop, height-bound) — a fixed 112px clearance
|
|
4642
|
+
* tuned for the OLD fixed-520px panel left too little air under the orb on a
|
|
4643
|
+
* tall one and too much on a short one. `max(112px, 14cqh)` is a floor, not a
|
|
4644
|
+
* fixed value: it stays exactly 112px (today's tuned figure) on a short
|
|
4645
|
+
* panel, where 14cqh would fall below it, and grows with `cqh` — the query
|
|
4646
|
+
* container's own height, established by `[container-type:size]` on the
|
|
4647
|
+
* panel div below — once the panel is tall enough that 14% of it exceeds
|
|
4648
|
+
* 112px. `cqh` rather than `dvh` specifically: the panel's real rendered
|
|
4649
|
+
* height, not the viewport's, since the panel does not always fill the
|
|
4650
|
+
* viewport (mobile: width-bound, height is `w / (8/5)`, shorter than 100dvh).
|
|
4219
4651
|
*/
|
|
4220
|
-
var
|
|
4652
|
+
var TRANSCRIPT_FADE_TOP_LEN = "max(112px, 14cqh)";
|
|
4221
4653
|
/**
|
|
4222
4654
|
* Top ramp when a `badge` sits above the transcript.
|
|
4223
4655
|
*
|
|
@@ -4227,10 +4659,21 @@ var TRANSCRIPT_FADE_TOP_PX = 112;
|
|
|
4227
4659
|
* reason (measured in `WithABadgeAndNoVoice` — orb ends 565, badge 573-598,
|
|
4228
4660
|
* first message could not start above 710). At that point the fade is only
|
|
4229
4661
|
* doing its ordinary job of softening a scroll edge, so it wants an ordinary
|
|
4230
|
-
* scroll-edge length.
|
|
4662
|
+
* scroll-edge length. Same floor+`cqh` scheme as {@link TRANSCRIPT_FADE_TOP_LEN}
|
|
4663
|
+
* above and for the same reason — this ramp needs to soften proportionally
|
|
4664
|
+
* more of a tall panel's scroll edge than a short one's.
|
|
4665
|
+
*/
|
|
4666
|
+
var TRANSCRIPT_FADE_TOP_WITH_BADGE_LEN = "max(28px, 4cqh)";
|
|
4667
|
+
var TRANSCRIPT_FADE_BOTTOM_LEN = "max(118px, 15cqh)";
|
|
4668
|
+
/**
|
|
4669
|
+
* How far off the bottom still counts as "following the conversation".
|
|
4670
|
+
*
|
|
4671
|
+
* Not zero: fractional scroll metrics on zoomed and hi-dpi displays never
|
|
4672
|
+
* land exactly on the bottom, and a smooth scroll is still in flight when the
|
|
4673
|
+
* next streamed token resizes the content. Both would read as the visitor
|
|
4674
|
+
* having deliberately scrolled up, and stop the transcript following.
|
|
4231
4675
|
*/
|
|
4232
|
-
var
|
|
4233
|
-
var TRANSCRIPT_FADE_BOTTOM_PX = 118;
|
|
4676
|
+
var FOLLOW_TOLERANCE_PX = 24;
|
|
4234
4677
|
/**
|
|
4235
4678
|
* Build the transcript's mask + the padding that matches it.
|
|
4236
4679
|
*
|
|
@@ -4238,20 +4681,35 @@ var TRANSCRIPT_FADE_BOTTOM_PX = 118;
|
|
|
4238
4681
|
* last messages scroll clear of the ramp, so a ramp length that is not also
|
|
4239
4682
|
* the padding leaves the newest message permanently half-dissolved.
|
|
4240
4683
|
*
|
|
4241
|
-
* The top ramp's stops are scaled from `
|
|
4684
|
+
* The top ramp's stops are scaled from `topLen` rather than hardcoded, so the
|
|
4242
4685
|
* shortened badge variant keeps the same eased shape instead of becoming a
|
|
4243
|
-
* steep two-point cut.
|
|
4686
|
+
* steep two-point cut. `topLen` is a CSS length EXPRESSION now (a `max(<px>,
|
|
4687
|
+
* <N>cqh)` floor, see the constants above), not a plain number — `at(fraction)`
|
|
4688
|
+
* therefore emits `calc(<topLen> * <fraction>)` rather than doing the
|
|
4689
|
+
* multiplication in JS, so each stop scales with the query container's
|
|
4690
|
+
* height (`cqh`) exactly the way `topLen` itself does. `calc()` accepts a
|
|
4691
|
+
* `max()` expression as its left operand (`max()` resolves to a `<length>`,
|
|
4692
|
+
* and a `<length>` may be multiplied by a bare `<number>` inside `calc()`),
|
|
4693
|
+
* so this composes without a second unit-handling special case.
|
|
4694
|
+
*
|
|
4695
|
+
* The bottom ramp's own inner taper (the last four stops, `96px`/`72px`/
|
|
4696
|
+
* `48px`/`24px`) stays fixed pixels, deliberately NOT scaled by `cqh`: it is
|
|
4697
|
+
* a small, fixed-shape cosmetic fade against the very bottom edge, sized
|
|
4698
|
+
* once and unrelated to how much CLEARANCE the composer needs above it —
|
|
4699
|
+
* that clearance is what `TRANSCRIPT_FADE_BOTTOM_LEN` (the transition point
|
|
4700
|
+
* this taper starts from, and the padding below) controls, and that is what
|
|
4701
|
+
* scales.
|
|
4244
4702
|
*/
|
|
4245
|
-
function transcriptEdgeFade(
|
|
4246
|
-
const at = (fraction) =>
|
|
4703
|
+
function transcriptEdgeFade(topLen) {
|
|
4704
|
+
const at = (fraction) => `calc(${topLen} * ${fraction})`;
|
|
4247
4705
|
const gradient = `linear-gradient(to bottom, ${[
|
|
4248
4706
|
"transparent 0",
|
|
4249
|
-
`rgba(0,0,0,0.06) ${at(.21)}
|
|
4250
|
-
`rgba(0,0,0,0.20) ${at(.43)}
|
|
4251
|
-
`rgba(0,0,0,0.45) ${at(.64)}
|
|
4252
|
-
`rgba(0,0,0,0.75) ${at(.82)}
|
|
4253
|
-
`#000 ${
|
|
4254
|
-
`#000 calc(100% - ${
|
|
4707
|
+
`rgba(0,0,0,0.06) ${at(.21)}`,
|
|
4708
|
+
`rgba(0,0,0,0.20) ${at(.43)}`,
|
|
4709
|
+
`rgba(0,0,0,0.45) ${at(.64)}`,
|
|
4710
|
+
`rgba(0,0,0,0.75) ${at(.82)}`,
|
|
4711
|
+
`#000 ${topLen}`,
|
|
4712
|
+
`#000 calc(100% - ${TRANSCRIPT_FADE_BOTTOM_LEN})`,
|
|
4255
4713
|
"rgba(0,0,0,0.86) calc(100% - 96px)",
|
|
4256
4714
|
"rgba(0,0,0,0.60) calc(100% - 72px)",
|
|
4257
4715
|
"rgba(0,0,0,0.32) calc(100% - 48px)",
|
|
@@ -4261,35 +4719,176 @@ function transcriptEdgeFade(topPx) {
|
|
|
4261
4719
|
return {
|
|
4262
4720
|
maskImage: gradient,
|
|
4263
4721
|
WebkitMaskImage: gradient,
|
|
4264
|
-
paddingTop:
|
|
4265
|
-
paddingBottom:
|
|
4722
|
+
paddingTop: topLen,
|
|
4723
|
+
paddingBottom: TRANSCRIPT_FADE_BOTTOM_LEN
|
|
4266
4724
|
};
|
|
4267
4725
|
}
|
|
4268
4726
|
/** Both variants built once — neither depends on props beyond badge presence. */
|
|
4269
|
-
var TRANSCRIPT_EDGE_FADE = transcriptEdgeFade(
|
|
4270
|
-
var TRANSCRIPT_EDGE_FADE_WITH_BADGE = transcriptEdgeFade(
|
|
4727
|
+
var TRANSCRIPT_EDGE_FADE = transcriptEdgeFade(TRANSCRIPT_FADE_TOP_LEN);
|
|
4728
|
+
var TRANSCRIPT_EDGE_FADE_WITH_BADGE = transcriptEdgeFade(TRANSCRIPT_FADE_TOP_WITH_BADGE_LEN);
|
|
4729
|
+
/**
|
|
4730
|
+
* Maps the call onto the pill it shows, reusing fields `ConciergeShellVoice`
|
|
4731
|
+
* already carries rather than inventing new plumbing:
|
|
4732
|
+
*
|
|
4733
|
+
* - `'connecting'` → `connecting`
|
|
4734
|
+
* - `'waiting'` (the agent is thinking, between the caller's turn ending and
|
|
4735
|
+
* the reply starting) → `thinking`
|
|
4736
|
+
* - `'live'` + `agentSpeaking` → `speaking`
|
|
4737
|
+
* - `'live'` otherwise → `listening`
|
|
4738
|
+
* - `'idle'` / `'blocked'` → `null`, no pill
|
|
4739
|
+
*
|
|
4740
|
+
* `agentSpeaking` is already a real field on {@link ConciergeShellVoice} —
|
|
4741
|
+
* this function only reads it, it does not require every caller to start
|
|
4742
|
+
* setting it; a caller that never populates it simply never reaches
|
|
4743
|
+
* `'speaking'`, which is exactly the same "renders sensibly with what it is
|
|
4744
|
+
* given" contract every other optional field on this interface follows.
|
|
4745
|
+
*/
|
|
4746
|
+
function voiceStatePillState(voice) {
|
|
4747
|
+
if (!voice) return null;
|
|
4748
|
+
switch (voice.phase) {
|
|
4749
|
+
case "connecting": return "connecting";
|
|
4750
|
+
case "waiting": return "thinking";
|
|
4751
|
+
case "live": return voice.agentSpeaking ? "speaking" : "listening";
|
|
4752
|
+
default: return null;
|
|
4753
|
+
}
|
|
4754
|
+
}
|
|
4755
|
+
/**
|
|
4756
|
+
* The label a pill state shows, falling back to the package's brand-neutral
|
|
4757
|
+
* English word (`defaultWidgetMessages`) when the host's own `labels` omit
|
|
4758
|
+
* it — the same "an existing caller renders sensibly without changes"
|
|
4759
|
+
* contract every field added to `ConciergeShellVoice.labels` after 0.2.0
|
|
4760
|
+
* follows.
|
|
4761
|
+
*/
|
|
4762
|
+
function voiceStatePillLabel(pillState, labels) {
|
|
4763
|
+
switch (pillState) {
|
|
4764
|
+
case "connecting": return labels?.connecting ?? defaultWidgetMessages.voice_state_connecting;
|
|
4765
|
+
case "listening": return labels?.listening ?? defaultWidgetMessages.voice_state_listening;
|
|
4766
|
+
case "thinking": return labels?.thinking ?? defaultWidgetMessages.voice_state_thinking;
|
|
4767
|
+
case "speaking": return labels?.speaking ?? defaultWidgetMessages.voice_state_speaking;
|
|
4768
|
+
}
|
|
4769
|
+
}
|
|
4770
|
+
/**
|
|
4771
|
+
* The leading dot's colour, in brand tokens — never a literal, so it follows
|
|
4772
|
+
* `skinStyle` when a tenant publishes their own brand colours, the same
|
|
4773
|
+
* reasoning every other brand-coloured glow in this file already states.
|
|
4774
|
+
* `listening` and `speaking` share `--brand-rose`: both are "the room is
|
|
4775
|
+
* live" states from the caller's point of view (a caller talking and an
|
|
4776
|
+
* agent talking back both read as "the call is active"), where
|
|
4777
|
+
* `connecting`/`thinking` are the two states with genuinely nothing to
|
|
4778
|
+
* listen to yet.
|
|
4779
|
+
*/
|
|
4780
|
+
function voiceStatePillDotColor(pillState) {
|
|
4781
|
+
switch (pillState) {
|
|
4782
|
+
case "connecting": return "var(--brand-amber)";
|
|
4783
|
+
case "thinking": return "var(--brand-plum)";
|
|
4784
|
+
case "listening":
|
|
4785
|
+
case "speaking": return "var(--brand-rose)";
|
|
4786
|
+
}
|
|
4787
|
+
}
|
|
4271
4788
|
/** How long the opening flourish runs. Matches `.widget-portal`'s own duration. */
|
|
4272
4789
|
var PORTAL_MS = 720;
|
|
4273
|
-
function ConciergeShell({ open, onOpenChange, state, messageArrived = false, labels, children, badge, draft, onDraftChange, onSubmit, composerDisabled = false, voice, announcement, skin, skinStyle, idPrefix = "concierge", scrollKey, composerLeading, testIds, position = DEFAULT_CONCIERGE_POSITION, onPositionChange }) {
|
|
4790
|
+
function ConciergeShell({ open, onOpenChange, state, messageArrived = false, 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 }) {
|
|
4274
4791
|
const triggerId = `${idPrefix}-trigger`;
|
|
4275
4792
|
const inputId = `${idPrefix}-input`;
|
|
4276
4793
|
const [portalActive, setPortalActive] = useState(false);
|
|
4277
4794
|
const panelRef = useRef(null);
|
|
4278
4795
|
const transcriptRef = useRef(null);
|
|
4796
|
+
/** The transcript's content box — what grows as a reply streams in. */
|
|
4797
|
+
const transcriptContentRef = useRef(null);
|
|
4279
4798
|
useEffect(() => {
|
|
4280
4799
|
if (!open) return;
|
|
4281
4800
|
setPortalActive(true);
|
|
4282
4801
|
const id = window.setTimeout(() => setPortalActive(false), PORTAL_MS);
|
|
4283
4802
|
return () => window.clearTimeout(id);
|
|
4284
4803
|
}, [open]);
|
|
4804
|
+
/**
|
|
4805
|
+
* The knot's equivalent of the orb's `bot-nod` flourish — `BotFace` fires
|
|
4806
|
+
* `messageArrived` off `className` presence alone (a CSS animation restarts
|
|
4807
|
+
* whenever a class newly APPLIES), which works because `messageArrived`
|
|
4808
|
+
* itself is a derived, level-triggered boolean ("was the last turn from the
|
|
4809
|
+
* caller") that a component only needs to read once per render. `RopeKnot`'s
|
|
4810
|
+
* tighten/tap flourish is EDGE-triggered instead — it plays once per bump of
|
|
4811
|
+
* `tightenKey`, the exact vehicle a launcher press already uses
|
|
4812
|
+
* (`concierge-launcher.tsx`) — so this only bumps it on the RISING edge
|
|
4813
|
+
* (`false` → `true`), not on every render where `messageArrived` merely
|
|
4814
|
+
* stays `true` (e.g. while the agent is still thinking about the same
|
|
4815
|
+
* caller turn).
|
|
4816
|
+
*/
|
|
4817
|
+
const wasMessageArrived = useRef(false);
|
|
4818
|
+
const [knotTightenKey, setKnotTightenKey] = useState(0);
|
|
4819
|
+
useEffect(() => {
|
|
4820
|
+
if (messageArrived && !wasMessageArrived.current) setKnotTightenKey((k) => k + 1);
|
|
4821
|
+
wasMessageArrived.current = messageArrived;
|
|
4822
|
+
}, [messageArrived]);
|
|
4823
|
+
/**
|
|
4824
|
+
* Whether the transcript is following the conversation.
|
|
4825
|
+
*
|
|
4826
|
+
* True while the visitor is at (or near) the bottom, false the moment they
|
|
4827
|
+
* scroll up to re-read something — see the observer below for why the
|
|
4828
|
+
* distinction has to exist rather than always scrolling.
|
|
4829
|
+
*/
|
|
4830
|
+
const following = useRef(true);
|
|
4285
4831
|
useEffect(() => {
|
|
4286
4832
|
const el = transcriptRef.current;
|
|
4287
4833
|
if (typeof el?.scrollTo !== "function") return;
|
|
4834
|
+
following.current = true;
|
|
4288
4835
|
el.scrollTo({
|
|
4289
4836
|
top: el.scrollHeight,
|
|
4290
4837
|
behavior: "smooth"
|
|
4291
4838
|
});
|
|
4292
4839
|
}, [scrollKey, state]);
|
|
4840
|
+
/**
|
|
4841
|
+
* Follow the reply as it STREAMS, not just as it starts.
|
|
4842
|
+
*
|
|
4843
|
+
* `scrollKey` is `turns.length` (`voice-widget.tsx`), so the effect above
|
|
4844
|
+
* fires once, when the agent's turn is appended and still empty or one
|
|
4845
|
+
* token long. Everything after that arrives by SSE into the SAME turn: the
|
|
4846
|
+
* bubble grows downward under a scroll position that was correct when it
|
|
4847
|
+
* was pinned and is stale a word later. The visitor watched the TOP of a
|
|
4848
|
+
* long answer and had to scroll for every line of it — the newest text, the
|
|
4849
|
+
* only part they had not read, was the part off-screen.
|
|
4850
|
+
*
|
|
4851
|
+
* A `ResizeObserver` on the content is what closes that gap: it fires on
|
|
4852
|
+
* every layout change the growing text produces, at whatever rate the
|
|
4853
|
+
* tokens land, with no polling and no dependency on how the host chooses to
|
|
4854
|
+
* stream. `scrollKey` still owns the jump to a NEW turn; this owns staying
|
|
4855
|
+
* there while that turn fills in.
|
|
4856
|
+
*
|
|
4857
|
+
* Gated on `following` so it never fights the visitor. Scrolling up to
|
|
4858
|
+
* re-read an earlier answer while the agent is still typing is an ordinary
|
|
4859
|
+
* thing to do, and a transcript that yanks itself back down every 50ms
|
|
4860
|
+
* makes it impossible. `atBottom` uses a tolerance rather than an equality
|
|
4861
|
+
* — fractional scroll metrics on zoomed or hi-dpi displays never land
|
|
4862
|
+
* exactly, and smooth scrolling is still in flight when the next resize
|
|
4863
|
+
* arrives.
|
|
4864
|
+
*
|
|
4865
|
+
* `behavior: 'auto'`, unlike the jump above: a smooth scroll started every
|
|
4866
|
+
* time a token lands never finishes before the next one restarts it, which
|
|
4867
|
+
* reads as the transcript lagging behind its own text.
|
|
4868
|
+
*/
|
|
4869
|
+
useEffect(() => {
|
|
4870
|
+
const el = transcriptRef.current;
|
|
4871
|
+
if (!el || typeof el.scrollTo !== "function") return;
|
|
4872
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
4873
|
+
const atBottom = () => el.scrollHeight - el.scrollTop - el.clientHeight <= FOLLOW_TOLERANCE_PX;
|
|
4874
|
+
const onScroll = () => {
|
|
4875
|
+
following.current = atBottom();
|
|
4876
|
+
};
|
|
4877
|
+
const observer = new ResizeObserver(() => {
|
|
4878
|
+
if (!following.current) return;
|
|
4879
|
+
el.scrollTo({
|
|
4880
|
+
top: el.scrollHeight,
|
|
4881
|
+
behavior: "auto"
|
|
4882
|
+
});
|
|
4883
|
+
});
|
|
4884
|
+
const content = transcriptContentRef.current;
|
|
4885
|
+
if (content) observer.observe(content);
|
|
4886
|
+
el.addEventListener("scroll", onScroll, { passive: true });
|
|
4887
|
+
return () => {
|
|
4888
|
+
observer.disconnect();
|
|
4889
|
+
el.removeEventListener("scroll", onScroll);
|
|
4890
|
+
};
|
|
4891
|
+
}, [open]);
|
|
4293
4892
|
const handleClose = useCallback(() => {
|
|
4294
4893
|
onOpenChange(false);
|
|
4295
4894
|
window.setTimeout(() => {
|
|
@@ -4336,6 +4935,14 @@ function ConciergeShell({ open, onOpenChange, state, messageArrived = false, lab
|
|
|
4336
4935
|
* voice, not only once the transport catches up.
|
|
4337
4936
|
*/
|
|
4338
4937
|
const inCall = voice !== void 0 && voice.phase !== "idle";
|
|
4938
|
+
/**
|
|
4939
|
+
* The voice-state pill's own state — `null` for `'idle'` (covered by
|
|
4940
|
+
* `inCall` too) AND `'blocked'` (NOT covered by `inCall`, which is why this
|
|
4941
|
+
* is its own value rather than reusing that boolean: a refused microphone
|
|
4942
|
+
* is still "a call", but it is not one of the four states the pill knows
|
|
4943
|
+
* how to draw — see `voiceStatePillState`'s own doc comment).
|
|
4944
|
+
*/
|
|
4945
|
+
const voicePillState = voiceStatePillState(voice);
|
|
4339
4946
|
/** Start, mute or unmute — whichever the one round control means right now. */
|
|
4340
4947
|
const micLabel = inCall ? (voice?.muted === true ? voice.labels.unmute : voice.labels.mute) ?? voice.labels.start : voice?.labels.start ?? "";
|
|
4341
4948
|
const submit = (e) => {
|
|
@@ -4357,153 +4964,182 @@ function ConciergeShell({ open, onOpenChange, state, messageArrived = false, lab
|
|
|
4357
4964
|
position,
|
|
4358
4965
|
...onPositionChange !== void 0 ? { onPositionChange } : {},
|
|
4359
4966
|
onOpen: () => onOpenChange(true),
|
|
4360
|
-
hidden: open
|
|
4967
|
+
hidden: open,
|
|
4968
|
+
avatar
|
|
4361
4969
|
}),
|
|
4362
4970
|
/* @__PURE__ */ jsx("div", {
|
|
4363
4971
|
"aria-hidden": true,
|
|
4364
|
-
|
|
4365
|
-
className: cn("bg-brand-ink/10 fixed inset-0 z-40 backdrop-blur-[2px] transition-opacity duration-500", open ? "opacity-100" : "pointer-events-none opacity-0")
|
|
4972
|
+
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")
|
|
4366
4973
|
}),
|
|
4367
4974
|
/* @__PURE__ */ jsx("div", {
|
|
4368
4975
|
"aria-hidden": !open,
|
|
4369
4976
|
className: cn("pointer-events-none fixed inset-x-0 z-50 flex", panelClasses(position)),
|
|
4370
4977
|
children: /* @__PURE__ */ jsxs("div", {
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
/* @__PURE__ */ jsx("
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
className: "
|
|
4419
|
-
children: [/* @__PURE__ */
|
|
4420
|
-
"
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
className: "z-10 mt-[104px] w-[68%] shrink-0 text-center",
|
|
4431
|
-
children: badge
|
|
4432
|
-
}),
|
|
4433
|
-
/* @__PURE__ */ jsx("div", {
|
|
4434
|
-
ref: transcriptRef,
|
|
4435
|
-
className: "w-full max-w-[86%] min-h-0 flex-1 overflow-y-auto px-1",
|
|
4436
|
-
style: badge === void 0 ? TRANSCRIPT_EDGE_FADE : TRANSCRIPT_EDGE_FADE_WITH_BADGE,
|
|
4437
|
-
children
|
|
4438
|
-
}),
|
|
4439
|
-
/* @__PURE__ */ jsx("div", {
|
|
4440
|
-
"aria-hidden": true,
|
|
4441
|
-
className: "pointer-events-none absolute inset-x-0 bottom-0 z-10 h-[132px] bg-[linear-gradient(to_bottom,transparent,var(--widget-card)_38%,var(--widget-card))]"
|
|
4442
|
-
}),
|
|
4443
|
-
/* @__PURE__ */ jsx("div", {
|
|
4444
|
-
className: "pointer-events-none absolute inset-x-0 bottom-1.5 z-20 flex justify-center",
|
|
4445
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
4446
|
-
className: cn("flex w-[71%] flex-col items-center gap-2.5", open ? "pointer-events-auto" : "pointer-events-none"),
|
|
4447
|
-
children: [/* @__PURE__ */ jsxs("form", {
|
|
4448
|
-
className: "flex w-full items-center gap-2",
|
|
4449
|
-
onSubmit: submit,
|
|
4450
|
-
children: [composerLeading, /* @__PURE__ */ jsxs("div", {
|
|
4451
|
-
className: "relative flex-1",
|
|
4452
|
-
children: [
|
|
4453
|
-
/* @__PURE__ */ jsx("label", {
|
|
4454
|
-
htmlFor: inputId,
|
|
4455
|
-
className: "sr-only",
|
|
4456
|
-
children: labels.composerPlaceholder
|
|
4457
|
-
}),
|
|
4458
|
-
/* @__PURE__ */ jsx("input", {
|
|
4459
|
-
id: inputId,
|
|
4460
|
-
"data-testid": testIds?.input,
|
|
4461
|
-
value: draft,
|
|
4462
|
-
onChange: (e) => onDraftChange(e.target.value),
|
|
4463
|
-
placeholder: labels.composerPlaceholder,
|
|
4464
|
-
dir: "auto",
|
|
4465
|
-
disabled: composerDisabled,
|
|
4466
|
-
className: cn("border-brand-plum/12 h-[40px] w-full rounded-3xl border bg-[var(--widget-chip)] ps-4 pe-12 text-[14px] text-[var(--widget-foreground)] placeholder:text-[var(--widget-foreground-muted)]", "focus:border-brand-plum/30 focus:ring-brand-plum/15 transition-all focus:bg-[var(--widget-bubble)] focus:ring-2 focus:outline-none disabled:opacity-50", inCall && draft === "" && "opacity-60 focus:opacity-100")
|
|
4467
|
-
}),
|
|
4468
|
-
draft.trim() && /* @__PURE__ */ jsx("button", {
|
|
4469
|
-
type: "submit",
|
|
4470
|
-
"aria-label": labels.send,
|
|
4471
|
-
"data-testid": testIds?.send,
|
|
4472
|
-
disabled: composerDisabled,
|
|
4473
|
-
className: "from-brand-plum to-brand-rose text-primary-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-all hover:scale-105 disabled:opacity-40",
|
|
4474
|
-
children: /* @__PURE__ */ jsx(Send, { className: "size-4 rtl:-scale-x-100" })
|
|
4475
|
-
})
|
|
4476
|
-
]
|
|
4978
|
+
className: "relative flex flex-col items-center",
|
|
4979
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
4980
|
+
ref: panelRef,
|
|
4981
|
+
role: "dialog",
|
|
4982
|
+
"aria-modal": "true",
|
|
4983
|
+
"aria-label": labels.dialog,
|
|
4984
|
+
"data-testid": testIds?.panel,
|
|
4985
|
+
className: cn("origin-bottom rounded-full transition-all 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"),
|
|
4986
|
+
style: { transitionTimingFunction: "cubic-bezier(0.16, 1, 0.3, 1)" },
|
|
4987
|
+
children: [
|
|
4988
|
+
/* @__PURE__ */ jsx("div", {
|
|
4989
|
+
"aria-hidden": true,
|
|
4990
|
+
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"),
|
|
4991
|
+
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))" }
|
|
4992
|
+
}),
|
|
4993
|
+
/* @__PURE__ */ jsx("div", {
|
|
4994
|
+
"aria-hidden": true,
|
|
4995
|
+
className: "pointer-events-none absolute inset-0 rounded-full p-[1.5px]",
|
|
4996
|
+
style: {
|
|
4997
|
+
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))",
|
|
4998
|
+
WebkitMask: "linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)",
|
|
4999
|
+
WebkitMaskComposite: "xor",
|
|
5000
|
+
maskComposite: "exclude"
|
|
5001
|
+
}
|
|
5002
|
+
}),
|
|
5003
|
+
/* @__PURE__ */ jsx("button", {
|
|
5004
|
+
type: "button",
|
|
5005
|
+
"aria-label": labels.close,
|
|
5006
|
+
onClick: handleClose,
|
|
5007
|
+
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 transition-all duration-300", "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"),
|
|
5008
|
+
children: /* @__PURE__ */ jsx(X, { className: "size-4" })
|
|
5009
|
+
}),
|
|
5010
|
+
/* @__PURE__ */ jsxs("div", {
|
|
5011
|
+
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)]"),
|
|
5012
|
+
children: [
|
|
5013
|
+
/* @__PURE__ */ jsx("div", {
|
|
5014
|
+
"aria-hidden": true,
|
|
5015
|
+
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"
|
|
5016
|
+
}),
|
|
5017
|
+
/* @__PURE__ */ jsx("div", {
|
|
5018
|
+
"aria-hidden": true,
|
|
5019
|
+
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"
|
|
5020
|
+
}),
|
|
5021
|
+
/* @__PURE__ */ jsxs("div", {
|
|
5022
|
+
className: cn("relative flex h-full w-full flex-col items-center justify-center px-2.5 py-1.5 transition-all duration-300 motion-reduce:transition-none", open ? "translate-y-0 opacity-100 delay-[300ms]" : "translate-y-2 opacity-0"),
|
|
5023
|
+
children: [
|
|
5024
|
+
/* @__PURE__ */ jsxs("div", {
|
|
5025
|
+
className: "pointer-events-none absolute inset-x-0 top-1.5 z-10 flex flex-col items-center gap-1",
|
|
5026
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
5027
|
+
className: "relative",
|
|
5028
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
5029
|
+
"aria-hidden": true,
|
|
5030
|
+
className: "absolute inset-0 rounded-full bg-[radial-gradient(circle,var(--widget-card)_58%,transparent_72%)]"
|
|
5031
|
+
}), /* @__PURE__ */ jsx(AvatarFace, {
|
|
5032
|
+
avatar,
|
|
5033
|
+
state,
|
|
5034
|
+
size: "lg",
|
|
5035
|
+
messageArrived,
|
|
5036
|
+
tightenKey: knotTightenKey
|
|
4477
5037
|
})]
|
|
4478
|
-
}),
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
|
|
4492
|
-
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
5038
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
5039
|
+
"data-testid": "widget-voice-state",
|
|
5040
|
+
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 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"),
|
|
5041
|
+
children: voicePillState ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
5042
|
+
"aria-hidden": true,
|
|
5043
|
+
className: cn("size-1.5 shrink-0 rounded-full", voicePillState !== "listening" && "animate-pulse motion-reduce:animate-none"),
|
|
5044
|
+
style: { backgroundColor: voiceStatePillDotColor(voicePillState) }
|
|
5045
|
+
}), /* @__PURE__ */ jsx("span", { children: voiceStatePillLabel(voicePillState, voice?.labels) })] }) : null
|
|
5046
|
+
})]
|
|
5047
|
+
}),
|
|
5048
|
+
badge == null ? null : /* @__PURE__ */ jsx("div", {
|
|
5049
|
+
className: "z-10 mt-[104px] w-[68%] shrink-0 text-center",
|
|
5050
|
+
children: badge
|
|
5051
|
+
}),
|
|
5052
|
+
/* @__PURE__ */ jsx("div", {
|
|
5053
|
+
ref: transcriptRef,
|
|
5054
|
+
className: "no-scrollbar w-full min-h-0 flex-1 overflow-y-auto px-2",
|
|
5055
|
+
style: badge == null ? TRANSCRIPT_EDGE_FADE : TRANSCRIPT_EDGE_FADE_WITH_BADGE,
|
|
5056
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
5057
|
+
ref: transcriptContentRef,
|
|
5058
|
+
children
|
|
5059
|
+
})
|
|
5060
|
+
}),
|
|
5061
|
+
/* @__PURE__ */ jsx("div", {
|
|
5062
|
+
"aria-hidden": true,
|
|
5063
|
+
className: "pointer-events-none absolute inset-x-0 bottom-0 z-10 h-[132px] bg-[linear-gradient(to_bottom,transparent,var(--widget-card)_38%,var(--widget-card))]"
|
|
5064
|
+
}),
|
|
5065
|
+
/* @__PURE__ */ jsx("div", {
|
|
5066
|
+
className: "pointer-events-none absolute inset-x-0 bottom-1.5 z-20 flex justify-center",
|
|
5067
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
5068
|
+
className: cn("flex w-[71%] flex-col items-center gap-2.5", open ? "pointer-events-auto" : "pointer-events-none"),
|
|
5069
|
+
children: [/* @__PURE__ */ jsxs("form", {
|
|
5070
|
+
className: "flex w-full items-center gap-2",
|
|
5071
|
+
onSubmit: submit,
|
|
5072
|
+
children: [composerLeading, /* @__PURE__ */ jsxs("div", {
|
|
5073
|
+
className: "relative flex-1",
|
|
5074
|
+
children: [
|
|
5075
|
+
/* @__PURE__ */ jsx("label", {
|
|
5076
|
+
htmlFor: inputId,
|
|
5077
|
+
className: "sr-only",
|
|
5078
|
+
children: labels.composerPlaceholder
|
|
5079
|
+
}),
|
|
5080
|
+
/* @__PURE__ */ jsx("input", {
|
|
5081
|
+
id: inputId,
|
|
5082
|
+
"data-testid": testIds?.input,
|
|
5083
|
+
value: draft,
|
|
5084
|
+
onChange: (e) => onDraftChange(e.target.value),
|
|
5085
|
+
placeholder: labels.composerPlaceholder,
|
|
5086
|
+
dir: "auto",
|
|
5087
|
+
disabled: composerDisabled,
|
|
5088
|
+
className: cn("border-brand-plum/12 h-[40px] w-full rounded-3xl border bg-[var(--widget-chip)] ps-4 pe-12 text-[14px] text-[var(--widget-foreground)] placeholder:text-[var(--widget-foreground-muted)]", "focus:border-brand-plum/30 focus:ring-brand-plum/15 transition-all focus:bg-[var(--widget-bubble)] focus:ring-2 focus:outline-none disabled:opacity-50", inCall && draft === "" && "opacity-60 focus:opacity-100")
|
|
5089
|
+
}),
|
|
5090
|
+
draft.trim() && /* @__PURE__ */ jsx("button", {
|
|
5091
|
+
type: "submit",
|
|
5092
|
+
"aria-label": labels.send,
|
|
5093
|
+
"data-testid": testIds?.send,
|
|
5094
|
+
disabled: composerDisabled,
|
|
5095
|
+
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-all hover:scale-105 disabled:opacity-40",
|
|
5096
|
+
children: /* @__PURE__ */ jsx(Send, { className: "size-4 rtl:-scale-x-100" })
|
|
5097
|
+
})
|
|
5098
|
+
]
|
|
5099
|
+
})]
|
|
5100
|
+
}), voice ? /* @__PURE__ */ jsxs("div", {
|
|
5101
|
+
className: "mt-1 flex items-center gap-3",
|
|
5102
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
5103
|
+
type: "button",
|
|
5104
|
+
onClick: inCall ? voice.onToggleMute ?? voice.onStart : voice.onStart,
|
|
5105
|
+
disabled: voice.disabled || voice.phase === "blocked",
|
|
5106
|
+
"data-testid": testIds?.mic,
|
|
5107
|
+
title: micLabel,
|
|
5108
|
+
"aria-label": micLabel,
|
|
5109
|
+
...inCall ? { "aria-pressed": voice.muted ?? false } : {},
|
|
5110
|
+
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-all", voice.disabled || voice.phase === "blocked" ? "cursor-not-allowed opacity-40" : 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 && voice.muted !== true && "ring-brand-rose/50 ring-4"),
|
|
5111
|
+
children: inCall && voice.muted === true ? /* @__PURE__ */ jsx(MicOff, { className: "size-5" }) : /* @__PURE__ */ jsx(Mic, { className: "size-5" })
|
|
5112
|
+
}), inCall && voice.onEnd !== void 0 ? /* @__PURE__ */ jsx("button", {
|
|
5113
|
+
type: "button",
|
|
5114
|
+
onClick: voice.onEnd,
|
|
5115
|
+
"data-testid": testIds?.endCall,
|
|
5116
|
+
title: voice.labels.end ?? "",
|
|
5117
|
+
"aria-label": voice.labels.end ?? "",
|
|
5118
|
+
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"),
|
|
5119
|
+
children: /* @__PURE__ */ jsx(PhoneOff, { className: "size-4" })
|
|
5120
|
+
}) : null]
|
|
4498
5121
|
}) : null]
|
|
4499
|
-
})
|
|
5122
|
+
})
|
|
4500
5123
|
})
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
5124
|
+
]
|
|
5125
|
+
})
|
|
5126
|
+
]
|
|
5127
|
+
})
|
|
5128
|
+
]
|
|
5129
|
+
}), attribution ? /* @__PURE__ */ jsxs("a", {
|
|
5130
|
+
href: attribution.href,
|
|
5131
|
+
target: "_blank",
|
|
5132
|
+
rel: "noopener noreferrer",
|
|
5133
|
+
"data-testid": "widget-branding",
|
|
5134
|
+
className: cn("absolute top-full left-1/2 mt-2 inline-flex -translate-x-1/2 items-center gap-1.5 whitespace-nowrap text-xs transition-opacity duration-300", open ? "pointer-events-auto opacity-100" : "pointer-events-none opacity-0"),
|
|
5135
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
5136
|
+
"aria-hidden": true,
|
|
5137
|
+
className: "size-2.5 rounded-full bg-gradient-to-br from-brand-rose to-brand-amber"
|
|
5138
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
5139
|
+
className: "text-brand-plum font-semibold tracking-tight",
|
|
5140
|
+
children: attribution.name
|
|
5141
|
+
})]
|
|
5142
|
+
}) : null]
|
|
4507
5143
|
})
|
|
4508
5144
|
}),
|
|
4509
5145
|
portalActive && /* @__PURE__ */ jsx("div", {
|
|
@@ -4527,94 +5163,6 @@ function ConciergeShell({ open, onOpenChange, state, messageArrived = false, lab
|
|
|
4527
5163
|
});
|
|
4528
5164
|
}
|
|
4529
5165
|
//#endregion
|
|
4530
|
-
//#region src/messages.ts
|
|
4531
|
-
/**
|
|
4532
|
-
* Message keys that carry a `{product}` placeholder — the avatar's
|
|
4533
|
-
* accessible-name states. Kept as a literal template, interpolated at
|
|
4534
|
-
* render time, never a brand name baked into this file (see the module doc
|
|
4535
|
-
* comment).
|
|
4536
|
-
*/
|
|
4537
|
-
var defaultWidgetMessages = {
|
|
4538
|
-
state_idle: "{product} — idle",
|
|
4539
|
-
state_listening: "{product} — listening",
|
|
4540
|
-
state_thinking: "{product} — thinking",
|
|
4541
|
-
state_speaking: "{product} — speaking",
|
|
4542
|
-
mic_start: "Start talking",
|
|
4543
|
-
mic_stop: "Stop talking",
|
|
4544
|
-
open: "Open chat",
|
|
4545
|
-
minimize: "Minimise",
|
|
4546
|
-
conversation: "Chat conversation",
|
|
4547
|
-
empty: "Ask a question — speak or type.",
|
|
4548
|
-
type_placeholder: "Type a message",
|
|
4549
|
-
send: "Send",
|
|
4550
|
-
move: "Move the assistant",
|
|
4551
|
-
call_end: "End the call",
|
|
4552
|
-
escalated_banner: "A human teammate will pick this up shortly.",
|
|
4553
|
-
typing: "Typing",
|
|
4554
|
-
suggestions_label: "Suggested questions",
|
|
4555
|
-
suggestion_1: "What is popular right now?",
|
|
4556
|
-
suggestion_2: "Help me pick something",
|
|
4557
|
-
suggestion_3: "Talk to a human",
|
|
4558
|
-
attach_label: "Attach a file",
|
|
4559
|
-
attach_uploading: "Sending {filename}…",
|
|
4560
|
-
attach_error: "Could not send {filename}. Try again.",
|
|
4561
|
-
attach_image_alt: "Attached image: {filename}",
|
|
4562
|
-
attach_download_hint: "Opens or downloads in a new tab",
|
|
4563
|
-
add_to_cart: "Add to cart",
|
|
4564
|
-
adding_to_cart: "Adding…",
|
|
4565
|
-
added_to_cart: "Added to cart",
|
|
4566
|
-
unavailable: "Unavailable",
|
|
4567
|
-
see_all: "See all {count}",
|
|
4568
|
-
cart_summary_title: "Your cart",
|
|
4569
|
-
cart_summary_total: "Total",
|
|
4570
|
-
checkout_now: "Checkout",
|
|
4571
|
-
checkout_failed: "Could not start checkout. Try again."
|
|
4572
|
-
};
|
|
4573
|
-
/**
|
|
4574
|
-
* Interpolates `{token}` placeholders in a message template. Deliberately the
|
|
4575
|
-
* same `{token}` syntax `next-intl`'s ICU messages use for a plain variable,
|
|
4576
|
-
* so `apps/web`'s adapter can hand this package `t.raw(key)` (the
|
|
4577
|
-
* UN-interpolated template) and let this one function do the substitution —
|
|
4578
|
-
* one interpolation implementation, not two.
|
|
4579
|
-
*
|
|
4580
|
-
* A token with no matching var, or a var that isn't a string/number, is left
|
|
4581
|
-
* as literal text rather than thrown on — a missing translation must degrade
|
|
4582
|
-
* to a visibly-odd string, never a broken render.
|
|
4583
|
-
*/
|
|
4584
|
-
function formatMessage(template, vars) {
|
|
4585
|
-
if (!vars) return template;
|
|
4586
|
-
return template.replace(/\{(\w+)\}/g, (match, key) => {
|
|
4587
|
-
const value = vars[key];
|
|
4588
|
-
return value === void 0 ? match : String(value);
|
|
4589
|
-
});
|
|
4590
|
-
}
|
|
4591
|
-
/**
|
|
4592
|
-
* Merges tenant-authored overrides (typically the `widgetMessagesFromCopy`
|
|
4593
|
-
* result) over `defaultWidgetMessages`. An override that is `undefined`,
|
|
4594
|
-
* empty, or whitespace-only is skipped — a blank tenant string must not blank
|
|
4595
|
-
* out a working default, same "absent means unset" contract
|
|
4596
|
-
* `PublicWidgetConfig.copy`'s own fields carry.
|
|
4597
|
-
*/
|
|
4598
|
-
function resolveWidgetMessages(overrides) {
|
|
4599
|
-
if (!overrides) return defaultWidgetMessages;
|
|
4600
|
-
const merged = { ...defaultWidgetMessages };
|
|
4601
|
-
for (const [key, value] of Object.entries(overrides)) if (typeof value === "string" && value.trim() !== "") merged[key] = value;
|
|
4602
|
-
return merged;
|
|
4603
|
-
}
|
|
4604
|
-
/**
|
|
4605
|
-
* Maps `PublicWidgetConfig.copy`'s fields onto the `WidgetMessages` keys they
|
|
4606
|
-
* overlap with. `greeting` is deliberately NOT mapped here — it seeds the
|
|
4607
|
-
* first turn (`SessionBootResponse.greeting`), it is not a UI label, so a
|
|
4608
|
-
* caller that wants it has it already from the session boot response.
|
|
4609
|
-
* `offlineMessage` has no current `WidgetMessages` counterpart (nothing here
|
|
4610
|
-
* renders an "offline" state yet) and is likewise omitted rather than
|
|
4611
|
-
* guessed onto the nearest-sounding key.
|
|
4612
|
-
*/
|
|
4613
|
-
function widgetMessagesFromCopy(copy) {
|
|
4614
|
-
if (!copy) return {};
|
|
4615
|
-
return copy.placeholder !== void 0 ? { type_placeholder: copy.placeholder } : {};
|
|
4616
|
-
}
|
|
4617
|
-
//#endregion
|
|
4618
5166
|
//#region src/session-log.ts
|
|
4619
5167
|
/**
|
|
4620
5168
|
* The widget's own account of a call: what happened, when, and how long each
|
|
@@ -4664,7 +5212,9 @@ var SESSION_EVENTS = [
|
|
|
4664
5212
|
"widget_event_invalid",
|
|
4665
5213
|
"disconnected",
|
|
4666
5214
|
"stopped",
|
|
4667
|
-
"error"
|
|
5215
|
+
"error",
|
|
5216
|
+
"messages_read",
|
|
5217
|
+
"messages_delivered"
|
|
4668
5218
|
];
|
|
4669
5219
|
var DEFAULT_LIMIT = 200;
|
|
4670
5220
|
var SessionLog = class {
|
|
@@ -5018,6 +5568,22 @@ function formatMoney(priceMinor, currency, locale) {
|
|
|
5018
5568
|
//#endregion
|
|
5019
5569
|
//#region src/widget-cards.tsx
|
|
5020
5570
|
/**
|
|
5571
|
+
* Is this click a plain, unmodified left click — the only kind that should
|
|
5572
|
+
* ever trigger a soft-nav `navigate()` call instead of falling through to the
|
|
5573
|
+
* anchor's own default handling.
|
|
5574
|
+
*
|
|
5575
|
+
* A modifier click (Cmd/Ctrl-click to open in a new tab, Shift-click for a
|
|
5576
|
+
* new window, a middle-click) or one a caller upstream already called
|
|
5577
|
+
* `preventDefault()` on has to keep working exactly like a bare `<a>` would —
|
|
5578
|
+
* soft-navigating over any of those would break "open in new tab", "copy
|
|
5579
|
+
* link", and middle-click. Same convention every SPA router's own `<Link>`
|
|
5580
|
+
* follows, and shared by both anchors this component renders (a product
|
|
5581
|
+
* card's link and the "See all N" link) rather than duplicated per call site.
|
|
5582
|
+
*/
|
|
5583
|
+
function isPlainLeftClick(event) {
|
|
5584
|
+
return !event.defaultPrevented && event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
|
|
5585
|
+
}
|
|
5586
|
+
/**
|
|
5021
5587
|
* How many cards the inline chat strip shows before handing off to the
|
|
5022
5588
|
* curation results page instead of growing taller. A live curation
|
|
5023
5589
|
* verified against the demo tenant returns 4 items for a typical
|
|
@@ -5041,15 +5607,27 @@ var INLINE_CARD_LIMIT = 4;
|
|
|
5041
5607
|
* new tab, copy link, middle-click all keep working — and `navigate` is only
|
|
5042
5608
|
* consulted on a plain, unmodified left click, same convention every SPA
|
|
5043
5609
|
* router's own `<Link>` follows.
|
|
5610
|
+
*
|
|
5611
|
+
* ## The `roomy` switch is a LAYOUT variant, not just a size bump
|
|
5612
|
+
*
|
|
5613
|
+
* `roomy` (the expanded grid) keeps its original ROW arrangement — a fixed
|
|
5614
|
+
* square image beside the text, because a grid cell already has width to
|
|
5615
|
+
* spare. `!roomy` used to mean the same row, only smaller (the old vertical
|
|
5616
|
+
* stack, one full-width row per card). It now means the CAROUSEL card
|
|
5617
|
+
* instead: a narrow `basis-[calc(100%/1.25)]` slice with no width to spare
|
|
5618
|
+
* beside an image, so the image moves ABOVE the text — a COLUMN arrangement,
|
|
5619
|
+
* full-width and `aspect-square` rather than a fixed box. One switch, two
|
|
5620
|
+
* branches, each still driving image sizing/shape and the wrapper's flex
|
|
5621
|
+
* direction together — extended, not duplicated into a second component.
|
|
5044
5622
|
*/
|
|
5045
5623
|
function CardBody({ item, href, roomy, locale, navigate }) {
|
|
5046
5624
|
const inner = /* @__PURE__ */ jsxs(Fragment, { children: [item.imageUrl ? /* @__PURE__ */ jsx("img", {
|
|
5047
5625
|
src: item.imageUrl,
|
|
5048
5626
|
alt: item.title,
|
|
5049
|
-
className:
|
|
5627
|
+
className: roomy ? "h-[4.5rem] w-[4.5rem] shrink-0 rounded-lg object-cover" : "aspect-square w-full rounded-lg object-cover"
|
|
5050
5628
|
}) : /* @__PURE__ */ jsx("span", {
|
|
5051
5629
|
"aria-hidden": "true",
|
|
5052
|
-
className:
|
|
5630
|
+
className: roomy ? "h-[4.5rem] w-[4.5rem] shrink-0 rounded-lg bg-black/5" : "aspect-square w-full rounded-lg bg-black/5"
|
|
5053
5631
|
}), /* @__PURE__ */ jsxs("div", {
|
|
5054
5632
|
className: "w-full min-w-0 flex-1",
|
|
5055
5633
|
children: [
|
|
@@ -5062,12 +5640,12 @@ function CardBody({ item, href, roomy, locale, navigate }) {
|
|
|
5062
5640
|
children: formatMoney(item.priceMinor, item.currency, locale)
|
|
5063
5641
|
}),
|
|
5064
5642
|
item.reason ? /* @__PURE__ */ jsx("p", {
|
|
5065
|
-
className:
|
|
5643
|
+
className: "line-clamp-2 text-pretty text-xs text-[var(--widget-foreground-muted)] italic",
|
|
5066
5644
|
children: item.reason
|
|
5067
5645
|
}) : null
|
|
5068
5646
|
]
|
|
5069
5647
|
})] });
|
|
5070
|
-
const shared = `flex w-full min-w-0
|
|
5648
|
+
const shared = `flex w-full min-w-0 gap-3 ${roomy ? "flex-1 items-center" : "flex-col"}`;
|
|
5071
5649
|
if (href === void 0) return /* @__PURE__ */ jsx("div", {
|
|
5072
5650
|
className: shared,
|
|
5073
5651
|
children: inner
|
|
@@ -5077,7 +5655,7 @@ function CardBody({ item, href, roomy, locale, navigate }) {
|
|
|
5077
5655
|
"data-testid": "widget-card-link",
|
|
5078
5656
|
className: `${shared} cursor-pointer`,
|
|
5079
5657
|
onClick: (event) => {
|
|
5080
|
-
if (!navigate || event
|
|
5658
|
+
if (!navigate || !isPlainLeftClick(event)) return;
|
|
5081
5659
|
event.preventDefault();
|
|
5082
5660
|
navigate(href);
|
|
5083
5661
|
},
|
|
@@ -5100,7 +5678,7 @@ function CardBody({ item, href, roomy, locale, navigate }) {
|
|
|
5100
5678
|
* Changing quantity is the cart drawer's job, which is a surface that can show
|
|
5101
5679
|
* the quantity it is changing.
|
|
5102
5680
|
*/
|
|
5103
|
-
function AddToCartButton({ item, onAddToCart, messages }) {
|
|
5681
|
+
function AddToCartButton({ item, onAddToCart, messages, fullWidth = false }) {
|
|
5104
5682
|
const [phase, setPhase] = useState("idle");
|
|
5105
5683
|
const mounted = useRef(true);
|
|
5106
5684
|
useEffect(() => {
|
|
@@ -5125,7 +5703,7 @@ function AddToCartButton({ item, onAddToCart, messages }) {
|
|
|
5125
5703
|
"data-testid": "widget-card-add-to-cart",
|
|
5126
5704
|
"data-phase": "unavailable",
|
|
5127
5705
|
disabled: true,
|
|
5128
|
-
className:
|
|
5706
|
+
className: `cursor-default rounded-full bg-black/5 px-3 py-1.5 text-xs font-medium text-[var(--widget-foreground-muted)] ${fullWidth ? "w-full text-center" : "shrink-0"}`,
|
|
5129
5707
|
children: messages.unavailable
|
|
5130
5708
|
});
|
|
5131
5709
|
return /* @__PURE__ */ jsx("button", {
|
|
@@ -5135,7 +5713,7 @@ function AddToCartButton({ item, onAddToCart, messages }) {
|
|
|
5135
5713
|
disabled,
|
|
5136
5714
|
"aria-live": "polite",
|
|
5137
5715
|
onClick: () => void onClick(),
|
|
5138
|
-
className: `flex
|
|
5716
|
+
className: `flex cursor-pointer items-center justify-center gap-1.5 rounded-full px-3 py-1.5 text-xs font-medium transition-colors disabled:cursor-default ${fullWidth ? "w-full" : "shrink-0"} ${phase === "added" ? "bg-[var(--widget-accent)]/15 text-[var(--widget-accent)] ring-1 ring-[var(--widget-accent)]/30" : "bg-[var(--widget-accent)] text-[var(--widget-accent-foreground)] disabled:opacity-60"}`,
|
|
5139
5717
|
children: phase === "adding" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
5140
5718
|
"aria-hidden": "true",
|
|
5141
5719
|
className: "h-3 w-3 animate-spin rounded-full border-2 border-current border-t-transparent motion-reduce:animate-none"
|
|
@@ -5176,13 +5754,13 @@ function WidgetCardList({ cards, onAddToCart, curationHref, productHref, navigat
|
|
|
5176
5754
|
className: "mt-2 flex flex-col gap-2",
|
|
5177
5755
|
children: [/* @__PURE__ */ jsx("ul", {
|
|
5178
5756
|
"data-testid": "widget-card-list",
|
|
5179
|
-
"data-layout": roomy ? "grid" : "
|
|
5180
|
-
className: roomy ? "grid grid-cols-[repeat(auto-fit,minmax(15rem,1fr))] gap-2" : "flex
|
|
5757
|
+
"data-layout": roomy ? "grid" : "carousel",
|
|
5758
|
+
className: roomy ? "grid grid-cols-[repeat(auto-fit,minmax(15rem,1fr))] gap-2" : "no-scrollbar flex snap-x snap-mandatory gap-2 overflow-x-auto overscroll-x-contain",
|
|
5181
5759
|
children: visibleItems.map((item) => {
|
|
5182
5760
|
const href = item.handle && productHref ? productHref(item.handle) : void 0;
|
|
5183
5761
|
return /* @__PURE__ */ jsxs("li", {
|
|
5184
5762
|
"data-testid": "widget-card",
|
|
5185
|
-
className: `gap-3 rounded-xl border border-black/10 bg-[var(--widget-card)] p-2 ${roomy ? "
|
|
5763
|
+
className: `flex flex-col items-start gap-3 rounded-xl border border-black/10 bg-[var(--widget-card)] p-2 ${roomy ? "" : "min-w-0 shrink-0 basis-[calc(100%/1.25)] max-w-[180px] snap-start"}`,
|
|
5186
5764
|
children: [/* @__PURE__ */ jsx(CardBody, {
|
|
5187
5765
|
item,
|
|
5188
5766
|
href,
|
|
@@ -5192,7 +5770,8 @@ function WidgetCardList({ cards, onAddToCart, curationHref, productHref, navigat
|
|
|
5192
5770
|
}), /* @__PURE__ */ jsx(AddToCartButton, {
|
|
5193
5771
|
item,
|
|
5194
5772
|
onAddToCart,
|
|
5195
|
-
messages
|
|
5773
|
+
messages,
|
|
5774
|
+
fullWidth: !roomy
|
|
5196
5775
|
})]
|
|
5197
5776
|
}, `${item.productId}-${item.variantId ?? ""}`);
|
|
5198
5777
|
})
|
|
@@ -5201,7 +5780,7 @@ function WidgetCardList({ cards, onAddToCart, curationHref, productHref, navigat
|
|
|
5201
5780
|
"data-testid": "widget-card-see-all",
|
|
5202
5781
|
className: "self-start text-xs font-medium text-[var(--widget-foreground)] underline",
|
|
5203
5782
|
onClick: (event) => {
|
|
5204
|
-
if (!navigate || event
|
|
5783
|
+
if (!navigate || !isPlainLeftClick(event)) return;
|
|
5205
5784
|
event.preventDefault();
|
|
5206
5785
|
navigate(seeAllHref);
|
|
5207
5786
|
},
|
|
@@ -5470,6 +6049,87 @@ function TypingDots({ label }) {
|
|
|
5470
6049
|
}, i))]
|
|
5471
6050
|
});
|
|
5472
6051
|
}
|
|
6052
|
+
/**
|
|
6053
|
+
* A transcript EVENT — something that happened at a point in the
|
|
6054
|
+
* conversation, drawn as a quiet centred divider between the bubbles either
|
|
6055
|
+
* side of it.
|
|
6056
|
+
*
|
|
6057
|
+
* ## Why this is a row and not a bar
|
|
6058
|
+
*
|
|
6059
|
+
* The handoff to a human used to be a bar pinned under the whole transcript,
|
|
6060
|
+
* driven by `escalated`. It was reported from a live storefront still saying
|
|
6061
|
+
* a person "will pick this up shortly" while a person was already replying.
|
|
6062
|
+
* That is not a copy bug — chrome keyed on a transport flag has no position
|
|
6063
|
+
* in the conversation, so it cannot say WHEN the handoff happened and no
|
|
6064
|
+
* later message can retire it. As a row it has both: it sits where the
|
|
6065
|
+
* handoff occurred, it scrolls with the thread, and its pending line is
|
|
6066
|
+
* decided by what comes AFTER it.
|
|
6067
|
+
*
|
|
6068
|
+
* ## Two lines, and only one of them can go stale
|
|
6069
|
+
*
|
|
6070
|
+
* The marker is past tense ("Handed to a human teammate") and permanent — it
|
|
6071
|
+
* is a record, and a record does not expire. The promise ("… will pick this
|
|
6072
|
+
* up shortly") is future tense and shown ONLY while `awaitingReply`; the
|
|
6073
|
+
* moment an answer lands below the marker it disappears, because the answer
|
|
6074
|
+
* is the proof it was kept.
|
|
6075
|
+
*
|
|
6076
|
+
* `role="status"` on the pending line only: the marker is narrated as part of
|
|
6077
|
+
* the surrounding `role="log"` like any other transcript row, and announcing
|
|
6078
|
+
* it twice would be worse than announcing it once.
|
|
6079
|
+
*/
|
|
6080
|
+
function TranscriptEvent({ event, awaitingReply, messages }) {
|
|
6081
|
+
if (event !== "handoff") return null;
|
|
6082
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
6083
|
+
className: "flex flex-col items-center gap-1 py-1",
|
|
6084
|
+
"data-testid": "widget-handoff-event",
|
|
6085
|
+
children: [/* @__PURE__ */ jsxs("p", {
|
|
6086
|
+
className: "flex w-full items-center gap-3 text-[11px] font-medium tracking-wide text-[var(--widget-foreground-muted)]",
|
|
6087
|
+
children: [
|
|
6088
|
+
/* @__PURE__ */ jsx("span", {
|
|
6089
|
+
"aria-hidden": "true",
|
|
6090
|
+
className: "h-px flex-1 bg-[var(--widget-foreground-muted)]/25"
|
|
6091
|
+
}),
|
|
6092
|
+
/* @__PURE__ */ jsx("span", { children: messages.handoff_event ?? defaultWidgetMessages.handoff_event }),
|
|
6093
|
+
/* @__PURE__ */ jsx("span", {
|
|
6094
|
+
"aria-hidden": "true",
|
|
6095
|
+
className: "h-px flex-1 bg-[var(--widget-foreground-muted)]/25"
|
|
6096
|
+
})
|
|
6097
|
+
]
|
|
6098
|
+
}), awaitingReply ? /* @__PURE__ */ jsx("p", {
|
|
6099
|
+
role: "status",
|
|
6100
|
+
"data-testid": "widget-handoff-pending",
|
|
6101
|
+
className: "text-center text-[11px] text-[var(--widget-foreground-muted)]",
|
|
6102
|
+
children: messages.escalated_banner
|
|
6103
|
+
}) : null]
|
|
6104
|
+
});
|
|
6105
|
+
}
|
|
6106
|
+
/**
|
|
6107
|
+
* The shopper's own send state, under their own bubble.
|
|
6108
|
+
*
|
|
6109
|
+
* Two states, deliberately — see `ChatTurnDelivery`. A third ("delivered" or
|
|
6110
|
+
* "read" on a message the shopper SENT) would have to be inferred from the
|
|
6111
|
+
* absence of an error or from the arrival of a reply, and this codebase does
|
|
6112
|
+
* not ship a tick it cannot back with an observation.
|
|
6113
|
+
*
|
|
6114
|
+
* The state is carried on `data-delivery` as well as in the accessible name
|
|
6115
|
+
* so that the assertion in a test — and any host styling — reads the actual
|
|
6116
|
+
* state rather than matching on a glyph.
|
|
6117
|
+
*/
|
|
6118
|
+
function TurnDeliveryStatus({ delivery, messages }) {
|
|
6119
|
+
const label = delivery === "sent" ? messages.status_sent ?? defaultWidgetMessages.status_sent : messages.status_sending ?? defaultWidgetMessages.status_sending;
|
|
6120
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
6121
|
+
"data-testid": "widget-turn-status",
|
|
6122
|
+
"data-delivery": delivery,
|
|
6123
|
+
className: `pt-0.5 pe-0.5 text-[10px] leading-none text-[var(--widget-foreground-muted)] ${delivery === "sending" ? "opacity-60" : ""}`,
|
|
6124
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
6125
|
+
className: "sr-only",
|
|
6126
|
+
children: label
|
|
6127
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
6128
|
+
"aria-hidden": "true",
|
|
6129
|
+
children: delivery === "sent" ? "✓" : "◦"
|
|
6130
|
+
})]
|
|
6131
|
+
});
|
|
6132
|
+
}
|
|
5473
6133
|
/** Kept in sync with `ATTACHMENT_IMAGE_CONTENT_TYPES` in `apps/api/src/conversations/attachment-limits.ts` — display-only, never a security decision on this side. */
|
|
5474
6134
|
var INLINE_IMAGE_TYPES = new Set([
|
|
5475
6135
|
"image/png",
|
|
@@ -5577,7 +6237,7 @@ function readsAsCheckoutIntent(text) {
|
|
|
5577
6237
|
* `dir`, resolved from that line's locale rather than inherited from the page —
|
|
5578
6238
|
* inheriting is what renders Arabic punctuation on the wrong end of a sentence.
|
|
5579
6239
|
*/
|
|
5580
|
-
function VoiceWidget({ state, turns, onToggleMic, onEndCall, callPhase = "idle", onSendText, micOpen, open, onOpenChange, status, mode = "voice", escalated = false, onAddToCart, curationHref, productHref, onAttachFile, launcherLabel, position, onPositionChange, cart, messages = defaultWidgetMessages, navigate, locale = "en", skinStyle }) {
|
|
6240
|
+
function VoiceWidget({ state, turns, onToggleMic, onEndCall, callPhase = "idle", onSendText, micOpen, open, onOpenChange, status, mode = "voice", escalated = false, onAddToCart, curationHref, productHref, onAttachFile, launcherLabel, position, onPositionChange, cart, messages = defaultWidgetMessages, navigate, locale = "en", skinStyle, avatar, attribution }) {
|
|
5581
6241
|
const [draft, setDraft] = useState("");
|
|
5582
6242
|
const [sending, setSending] = useState(false);
|
|
5583
6243
|
/** Roomy mode — see the expand control in the header. Collapses back on close, so a reopened widget starts small. */
|
|
@@ -5637,6 +6297,8 @@ function VoiceWidget({ state, turns, onToggleMic, onEndCall, callPhase = "idle",
|
|
|
5637
6297
|
onOpenChange,
|
|
5638
6298
|
state,
|
|
5639
6299
|
...skinStyle !== void 0 ? { skinStyle } : {},
|
|
6300
|
+
...avatar !== void 0 ? { avatar } : {},
|
|
6301
|
+
...attribution !== void 0 ? { attribution } : {},
|
|
5640
6302
|
messageArrived: lastTurn?.speaker === "caller",
|
|
5641
6303
|
idPrefix: "widget",
|
|
5642
6304
|
scrollKey: turns.length,
|
|
@@ -5664,7 +6326,11 @@ function VoiceWidget({ state, turns, onToggleMic, onEndCall, callPhase = "idle",
|
|
|
5664
6326
|
start: messages.mic_start,
|
|
5665
6327
|
end: messages.call_end,
|
|
5666
6328
|
mute: messages.mic_stop,
|
|
5667
|
-
unmute: messages.mic_start
|
|
6329
|
+
unmute: messages.mic_start,
|
|
6330
|
+
connecting: messages.voice_state_connecting,
|
|
6331
|
+
listening: messages.voice_state_listening,
|
|
6332
|
+
thinking: messages.voice_state_thinking,
|
|
6333
|
+
speaking: messages.voice_state_speaking
|
|
5668
6334
|
}
|
|
5669
6335
|
} : void 0,
|
|
5670
6336
|
composerLeading: onAttachFile && escalated ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -5727,14 +6393,18 @@ function VoiceWidget({ state, turns, onToggleMic, onEndCall, callPhase = "idle",
|
|
|
5727
6393
|
turns.length === 0 ? /* @__PURE__ */ jsx("p", {
|
|
5728
6394
|
className: "py-8 text-center text-sm text-[var(--widget-foreground-muted)]",
|
|
5729
6395
|
children: messages.empty
|
|
5730
|
-
}) : turns.map((turn, i) => /* @__PURE__ */
|
|
6396
|
+
}) : turns.map((turn, i) => turn.speaker === "event" ? /* @__PURE__ */ jsx(TranscriptEvent, {
|
|
6397
|
+
event: turn.event,
|
|
6398
|
+
messages,
|
|
6399
|
+
awaitingReply: !turns.slice(i + 1).some((t) => t.speaker === "agent" && t.text.trim() !== "")
|
|
6400
|
+
}, `event-${i}`) : /* @__PURE__ */ jsxs("div", {
|
|
5731
6401
|
className: turn.speaker === "caller" ? "flex flex-col items-end" : "flex flex-col items-start",
|
|
5732
6402
|
children: [
|
|
5733
6403
|
turn.text !== "" || turn.speaker === "agent" && turn.final === false ? /* @__PURE__ */ jsx("div", {
|
|
5734
6404
|
dir: textDirectionFor(turn.locale),
|
|
5735
6405
|
lang: turn.locale,
|
|
5736
6406
|
"data-testid": turn.speaker === "caller" ? "widget-turn-caller" : turn.filler === true ? "widget-turn-agent-filler" : "widget-turn-agent",
|
|
5737
|
-
className: `max-w-[85%] px-3.5 py-2 text-[
|
|
6407
|
+
className: `max-w-[85%] px-3.5 py-2 text-[14px] leading-[1.55] shadow-sm ${turn.speaker === "caller" ? "from-brand-plum to-brand-plum/90 text-[var(--widget-accent-foreground)] rounded-2xl rounded-ee-md bg-gradient-to-br" : turn.filler === true ? "rounded-2xl rounded-es-md border border-dashed border-[var(--widget-foreground-muted)]/50 bg-transparent text-[var(--widget-foreground-muted)] shadow-none" : "ring-brand-plum/10 rounded-2xl rounded-es-md bg-[var(--widget-bubble)] text-[var(--widget-foreground)] ring-1"}`,
|
|
5738
6408
|
children: turn.speaker === "agent" && turn.text === "" && turn.final === false ? /* @__PURE__ */ jsx(TypingDots, { label: messages.typing }) : turn.speaker === "agent" && turn.filler === true ? /* @__PURE__ */ jsxs("span", {
|
|
5739
6409
|
className: "flex items-center gap-2 italic",
|
|
5740
6410
|
children: [/* @__PURE__ */ jsx("span", { children: turn.text }), /* @__PURE__ */ jsx(TypingDots, { label: messages.typing })]
|
|
@@ -5762,6 +6432,10 @@ function VoiceWidget({ state, turns, onToggleMic, onEndCall, callPhase = "idle",
|
|
|
5762
6432
|
messages,
|
|
5763
6433
|
roomy: false
|
|
5764
6434
|
})
|
|
6435
|
+
}) : null,
|
|
6436
|
+
turn.delivery !== void 0 ? /* @__PURE__ */ jsx(TurnDeliveryStatus, {
|
|
6437
|
+
delivery: turn.delivery,
|
|
6438
|
+
messages
|
|
5765
6439
|
}) : null
|
|
5766
6440
|
]
|
|
5767
6441
|
}, `${turn.speaker}-${i}`)),
|
|
@@ -5787,12 +6461,6 @@ function VoiceWidget({ state, turns, onToggleMic, onEndCall, callPhase = "idle",
|
|
|
5787
6461
|
messages,
|
|
5788
6462
|
...navigate ? { navigate } : {}
|
|
5789
6463
|
}) : null,
|
|
5790
|
-
escalated ? /* @__PURE__ */ jsx("p", {
|
|
5791
|
-
role: "status",
|
|
5792
|
-
"data-testid": "widget-escalated-banner",
|
|
5793
|
-
className: "rounded-xl bg-[var(--widget-chip)] ring-1 ring-black/5 px-3 py-2 text-center text-xs font-medium text-[var(--widget-foreground)]",
|
|
5794
|
-
children: messages.escalated_banner
|
|
5795
|
-
}) : null,
|
|
5796
6464
|
attaching ? /* @__PURE__ */ jsx("p", {
|
|
5797
6465
|
role: "status",
|
|
5798
6466
|
className: `text-xs ${attaching.failed ? "text-destructive" : "text-[var(--widget-foreground-muted)]"}`,
|
|
@@ -6158,6 +6826,13 @@ var DEFAULT_POLL_INTERVAL_MS = 4e3;
|
|
|
6158
6826
|
var DEFAULT_IDLE_POLL_INTERVAL_MS = 3e4;
|
|
6159
6827
|
/** `socket.io-client`'s `path` default — kept in sync with `apps/api/src/config/config.ts`'s `WIDGET_SOCKET_PATH` default. */
|
|
6160
6828
|
var DEFAULT_SOCKET_PATH = "/socket.io";
|
|
6829
|
+
/**
|
|
6830
|
+
* The `ChatTurn.id` of the handoff transcript event. A fixed literal because
|
|
6831
|
+
* there is at most one per session (see `markHandoffToHuman`), and prefixed
|
|
6832
|
+
* so it can never be mistaken for — or collide with — a server-minted turn
|
|
6833
|
+
* id in the id-keyed `setTurns` passes `send`/`streamReply` run.
|
|
6834
|
+
*/
|
|
6835
|
+
var HANDOFF_EVENT_TURN_ID = "event-handoff";
|
|
6161
6836
|
/** Must equal `WIDGET_DESK_MESSAGE_EVENT` in `apps/api/src/realtime/widget-room.ts`. */
|
|
6162
6837
|
var DESK_MESSAGE_EVENT = "desk:message";
|
|
6163
6838
|
/** Must equal the namespace `WidgetGateway` (`apps/api/src/realtime/widget.gateway.ts`) is mounted on. */
|
|
@@ -6214,6 +6889,7 @@ function useChatSession(options) {
|
|
|
6214
6889
|
const { embedKey, attribution, apiBase = DEFAULT_API_BASE, pollIntervalMs = DEFAULT_POLL_INTERVAL_MS, idlePollIntervalMs = DEFAULT_IDLE_POLL_INTERVAL_MS, socketUrl, socketPath = DEFAULT_SOCKET_PATH, collector } = options;
|
|
6215
6890
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
6216
6891
|
const socketFactory = options.socketImpl;
|
|
6892
|
+
const now = options.now ?? (() => Date.now());
|
|
6217
6893
|
const [turns, setTurns] = useState([]);
|
|
6218
6894
|
/**
|
|
6219
6895
|
* The tenant's collapsed-widget config, once the session has booted.
|
|
@@ -6248,6 +6924,88 @@ function useChatSession(options) {
|
|
|
6248
6924
|
const pollIntervalRef = useRef(pollIntervalMs);
|
|
6249
6925
|
const mountedRef = useRef(true);
|
|
6250
6926
|
const socketRef = useRef(null);
|
|
6927
|
+
/**
|
|
6928
|
+
* `StartWidgetSessionResult.visitorSessionId` — same value `collector`
|
|
6929
|
+
* (when supplied) receives via `setSession`, stored here too because the
|
|
6930
|
+
* read-receipt reporter below (SAA-137) needs it on every POST and has no
|
|
6931
|
+
* other source: `UseChatSessionResult` never exposes this id publicly (see
|
|
6932
|
+
* `SessionBootResponse.visitorSessionId`'s own doc comment).
|
|
6933
|
+
*/
|
|
6934
|
+
const visitorSessionIdRef = useRef(void 0);
|
|
6935
|
+
/**
|
|
6936
|
+
* The receipt reporters' `sinceStartMs` zero-point — captured once, at the
|
|
6937
|
+
* instant `POST /widget/session` is ISSUED.
|
|
6938
|
+
*
|
|
6939
|
+
* ## Why the request, not the response — the bug this fixes
|
|
6940
|
+
*
|
|
6941
|
+
* The server records `occurredAt = conversation_sessions.started_at +
|
|
6942
|
+
* sinceStartMs` (`WidgetChatService.recordClientIngestBatch`), and
|
|
6943
|
+
* `Turn.readAt`/`Turn.deliveredAt` only honour a receipt whose `occurredAt`
|
|
6944
|
+
* is at or after the turn's own `completedAt`. That makes the anchor's
|
|
6945
|
+
* ERROR DIRECTION decide whether the feature works at all.
|
|
6946
|
+
*
|
|
6947
|
+
* `started_at` is minted DURING the boot request, so the client instant it
|
|
6948
|
+
* corresponds to lies somewhere between issuing that request and receiving
|
|
6949
|
+
* its response. Anchoring on the RESPONSE — what this used to do — takes
|
|
6950
|
+
* the latest point in that interval, which makes every offset SHORT by the
|
|
6951
|
+
* whole boot round trip: a session boot resolves a visitor, a contact, a
|
|
6952
|
+
* conversation, a session row and a timeline event (plus, on the demo
|
|
6953
|
+
* storefront, a same-origin proxy hop), so that is hundreds of
|
|
6954
|
+
* milliseconds, while the gap between a turn committing and its `done`
|
|
6955
|
+
* frame reaching this browser is a fraction of it. The receipt for a reply
|
|
6956
|
+
* the shopper watched land was therefore stamped BEFORE that reply
|
|
6957
|
+
* completed, `readAt` returned null for it, and the console's second tick
|
|
6958
|
+
* never appeared on a real deployment — while every unit test passed,
|
|
6959
|
+
* because a fake clock that does not advance during the boot request makes
|
|
6960
|
+
* both anchors identical.
|
|
6961
|
+
*
|
|
6962
|
+
* Anchoring on the REQUEST takes the earliest point in the same interval,
|
|
6963
|
+
* so a receipt is never recorded before the moment it describes. The cost
|
|
6964
|
+
* is the mirror image: a receipt may be recorded LATE by however long that
|
|
6965
|
+
* boot round trip took, and an outbound turn completing inside that window
|
|
6966
|
+
* could be swept into a receipt fired just before it.
|
|
6967
|
+
*
|
|
6968
|
+
* Nothing on THIS side bounds that overshoot — a tab frozen or slept
|
|
6969
|
+
* between issuing the boot request and receiving its response stretches it
|
|
6970
|
+
* arbitrarily — so the bound is enforced where it can be witnessed rather
|
|
6971
|
+
* than estimated: `WidgetChatService.recordClientIngestBatch` clamps every
|
|
6972
|
+
* event to the instant the batch arrived, because whatever the client
|
|
6973
|
+
* believes, the thing it is reporting happened no later than the request
|
|
6974
|
+
* carrying it. The two halves are a pair; neither is sufficient alone.
|
|
6975
|
+
*/
|
|
6976
|
+
const sessionOriginRef = useRef(null);
|
|
6977
|
+
/**
|
|
6978
|
+
* Monotonic per session, half of a receipt's dedupe key
|
|
6979
|
+
* (`clientEventDedupeKey`, api-side). ONE counter across both receipt
|
|
6980
|
+
* kinds: the contract says "monotonic per session", not per kind, and the
|
|
6981
|
+
* key already carries `kind` so two kinds sharing a session cannot collide.
|
|
6982
|
+
*/
|
|
6983
|
+
const clientSeqRef = useRef(0);
|
|
6984
|
+
/**
|
|
6985
|
+
* `ChatTurn.id` of every FINAL inbound turn each reporter has already
|
|
6986
|
+
* accounted for — see the effect below for why finality, not array
|
|
6987
|
+
* length, is the watermark: `mergeIncoming`/the streaming reducer both
|
|
6988
|
+
* mutate a turn'S `text`/`final` IN PLACE as text arrives (same array
|
|
6989
|
+
* index, new content), so "have I seen this many turns" is not the same
|
|
6990
|
+
* question as "have I seen this turn's FINISHED content".
|
|
6991
|
+
*
|
|
6992
|
+
* TWO sets, not one, because the two receipts answer different questions
|
|
6993
|
+
* and fire at different moments: a turn that arrives on a hidden tab is
|
|
6994
|
+
* delivered immediately and read only when the shopper comes back, so a
|
|
6995
|
+
* shared watermark would silently swallow one of the two.
|
|
6996
|
+
*/
|
|
6997
|
+
const deliveredTurnIdsRef = useRef(/* @__PURE__ */ new Set());
|
|
6998
|
+
const readTurnIdsRef = useRef(/* @__PURE__ */ new Set());
|
|
6999
|
+
/**
|
|
7000
|
+
* Guards the handoff transcript event against a second append.
|
|
7001
|
+
*
|
|
7002
|
+
* `status` can be set to `'escalated'` more than once in a session — a
|
|
7003
|
+
* later turn can stream another `escalated` event, and `sendAttachment`
|
|
7004
|
+
* sets it independently — but the conversation is handed over once, and a
|
|
7005
|
+
* second marker in the thread would read as a second handoff that never
|
|
7006
|
+
* happened.
|
|
7007
|
+
*/
|
|
7008
|
+
const handoffEventAppendedRef = useRef(false);
|
|
6251
7009
|
useEffect(() => {
|
|
6252
7010
|
mountedRef.current = true;
|
|
6253
7011
|
return () => {
|
|
@@ -6268,13 +7026,53 @@ function useChatSession(options) {
|
|
|
6268
7026
|
if (fresh.length === 0) return;
|
|
6269
7027
|
for (const t of fresh) seenSeqRef.current.add(t.seq);
|
|
6270
7028
|
lastSeqRef.current = fresh.reduce((max, t) => Math.max(max, t.seq), lastSeqRef.current);
|
|
6271
|
-
setTurns((prev) =>
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
7029
|
+
setTurns((prev) => {
|
|
7030
|
+
const rendered = new Set(prev.map((t) => t.id));
|
|
7031
|
+
const unseen = fresh.filter((t) => !rendered.has(t.id));
|
|
7032
|
+
if (unseen.length === 0) return prev;
|
|
7033
|
+
return [...prev, ...unseen.map((t) => ({
|
|
7034
|
+
id: t.id,
|
|
7035
|
+
speaker: speakerFor(t.role),
|
|
7036
|
+
text: t.text ?? "",
|
|
7037
|
+
final: true,
|
|
7038
|
+
...t.attachments && t.attachments.length > 0 ? { attachments: t.attachments } : {}
|
|
7039
|
+
}))];
|
|
7040
|
+
});
|
|
7041
|
+
}, []);
|
|
7042
|
+
/**
|
|
7043
|
+
* Records the handoff to a human AS AN EVENT IN THE TRANSCRIPT, at the
|
|
7044
|
+
* point in the thread where it happened, and flips `status`.
|
|
7045
|
+
*
|
|
7046
|
+
* The two used to be separate concerns: `status === 'escalated'` drove a
|
|
7047
|
+
* banner rendered under the whole conversation. That banner was reported
|
|
7048
|
+
* from a live storefront still telling a shopper a human "will pick this
|
|
7049
|
+
* up shortly" while a human was already answering them — inevitable for
|
|
7050
|
+
* chrome keyed on a transport state, because it has no position in the
|
|
7051
|
+
* conversation and no later event can retire it. An event turn has both: a
|
|
7052
|
+
* position (here, immediately after the exchange that escalated) and
|
|
7053
|
+
* neighbours (a reply landing after it is exactly what tells the renderer
|
|
7054
|
+
* the promise is spent — see `VoiceWidget`).
|
|
7055
|
+
*
|
|
7056
|
+
* Appended once per session, guarded by `handoffEventAppendedRef`: the
|
|
7057
|
+
* conversation is handed over once, however many times the transport
|
|
7058
|
+
* re-reports it.
|
|
7059
|
+
*
|
|
7060
|
+
* The id is a fixed literal, not a generated one, because there is at most
|
|
7061
|
+
* one of these per session — and a stable id keeps this row from ever
|
|
7062
|
+
* colliding with a server turn id in `setTurns`' own map/filter passes.
|
|
7063
|
+
*/
|
|
7064
|
+
const markHandoffToHuman = useCallback(() => {
|
|
7065
|
+
if (!mountedRef.current) return;
|
|
7066
|
+
setStatus("escalated");
|
|
7067
|
+
if (handoffEventAppendedRef.current) return;
|
|
7068
|
+
handoffEventAppendedRef.current = true;
|
|
7069
|
+
setTurns((prev) => [...prev, {
|
|
7070
|
+
id: HANDOFF_EVENT_TURN_ID,
|
|
7071
|
+
speaker: "event",
|
|
7072
|
+
event: "handoff",
|
|
7073
|
+
text: "",
|
|
7074
|
+
final: true
|
|
7075
|
+
}]);
|
|
6278
7076
|
}, []);
|
|
6279
7077
|
const poll = useCallback(async () => {
|
|
6280
7078
|
const chatToken = chatTokenRef.current;
|
|
@@ -6315,6 +7113,7 @@ function useChatSession(options) {
|
|
|
6315
7113
|
(async () => {
|
|
6316
7114
|
try {
|
|
6317
7115
|
const stored = readStoredVisitor();
|
|
7116
|
+
const bootRequestedAt = now();
|
|
6318
7117
|
const res = await fetchImpl(withEmbedKeyParam(`${apiBase}/session`, embedKey), {
|
|
6319
7118
|
method: "POST",
|
|
6320
7119
|
headers: { "content-type": "application/json" },
|
|
@@ -6330,6 +7129,8 @@ function useChatSession(options) {
|
|
|
6330
7129
|
if (cancelled) return;
|
|
6331
7130
|
chatTokenRef.current = body.chatToken;
|
|
6332
7131
|
setChatToken(body.chatToken);
|
|
7132
|
+
visitorSessionIdRef.current = body.visitorSessionId;
|
|
7133
|
+
sessionOriginRef.current = bootRequestedAt;
|
|
6333
7134
|
setModalities({
|
|
6334
7135
|
text: body.modalities?.text ?? true,
|
|
6335
7136
|
voice: body.modalities?.voice ?? false
|
|
@@ -6417,6 +7218,268 @@ function useChatSession(options) {
|
|
|
6417
7218
|
pollIntervalMs,
|
|
6418
7219
|
idlePollIntervalMs
|
|
6419
7220
|
]);
|
|
7221
|
+
const send = useCallback(async (text, options) => {
|
|
7222
|
+
const chatToken = chatTokenRef.current;
|
|
7223
|
+
if (chatToken === void 0 || status === "streaming") return false;
|
|
7224
|
+
const callerTurnId = `caller-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
7225
|
+
const agentTurnId = `agent-${callerTurnId}`;
|
|
7226
|
+
setTurns((prev) => [
|
|
7227
|
+
...prev,
|
|
7228
|
+
...options?.silent ? [] : [{
|
|
7229
|
+
id: callerTurnId,
|
|
7230
|
+
speaker: "caller",
|
|
7231
|
+
text,
|
|
7232
|
+
final: true,
|
|
7233
|
+
delivery: "sending"
|
|
7234
|
+
}],
|
|
7235
|
+
{
|
|
7236
|
+
id: agentTurnId,
|
|
7237
|
+
speaker: "agent",
|
|
7238
|
+
text: "",
|
|
7239
|
+
final: false
|
|
7240
|
+
}
|
|
7241
|
+
]);
|
|
7242
|
+
setStatus((prev) => prev === "escalated" ? prev : "streaming");
|
|
7243
|
+
const rollBack = () => {
|
|
7244
|
+
setTurns((prev) => prev.filter((t) => t.id !== callerTurnId && t.id !== agentTurnId));
|
|
7245
|
+
};
|
|
7246
|
+
let res;
|
|
7247
|
+
try {
|
|
7248
|
+
res = await fetchImpl(withEmbedKeyParam(`${apiBase}/chat`, embedKey), {
|
|
7249
|
+
method: "POST",
|
|
7250
|
+
headers: {
|
|
7251
|
+
"content-type": "application/json",
|
|
7252
|
+
authorization: `Bearer ${chatToken}`
|
|
7253
|
+
},
|
|
7254
|
+
body: JSON.stringify({ message: text })
|
|
7255
|
+
});
|
|
7256
|
+
} catch {
|
|
7257
|
+
rollBack();
|
|
7258
|
+
setStatus("error");
|
|
7259
|
+
setError("Could not reach the conversation.");
|
|
7260
|
+
return false;
|
|
7261
|
+
}
|
|
7262
|
+
if (!res.ok || res.body === null) {
|
|
7263
|
+
rollBack();
|
|
7264
|
+
setStatus("error");
|
|
7265
|
+
setError(`The conversation could not accept that message (${res.status}).`);
|
|
7266
|
+
return false;
|
|
7267
|
+
}
|
|
7268
|
+
if (mountedRef.current) setTurns((prev) => prev.map((t) => t.id === callerTurnId ? {
|
|
7269
|
+
...t,
|
|
7270
|
+
delivery: "sent"
|
|
7271
|
+
} : t));
|
|
7272
|
+
streamReply({
|
|
7273
|
+
body: res.body,
|
|
7274
|
+
agentTurnId,
|
|
7275
|
+
setTurns,
|
|
7276
|
+
onCardsEvent: (evt) => {
|
|
7277
|
+
if (mountedRef.current) setCards((prev) => [...prev, evt]);
|
|
7278
|
+
},
|
|
7279
|
+
onCheckoutEvent: (evt) => {
|
|
7280
|
+
if (mountedRef.current) setCheckoutHandoffs((prev) => [...prev, evt]);
|
|
7281
|
+
},
|
|
7282
|
+
onEscalated: () => {
|
|
7283
|
+
markHandoffToHuman();
|
|
7284
|
+
},
|
|
7285
|
+
onDone: (turnId) => {
|
|
7286
|
+
if (!mountedRef.current) return;
|
|
7287
|
+
setTurns((prev) => prev.filter((t) => t.id !== turnId || t.id === agentTurnId).map((t) => t.id === agentTurnId ? {
|
|
7288
|
+
...t,
|
|
7289
|
+
id: turnId,
|
|
7290
|
+
final: true
|
|
7291
|
+
} : t));
|
|
7292
|
+
setStatus((prev) => prev === "escalated" ? prev : "idle");
|
|
7293
|
+
},
|
|
7294
|
+
onError: (message) => {
|
|
7295
|
+
if (!mountedRef.current) return;
|
|
7296
|
+
setTurns((prev) => prev.map((t) => t.id === agentTurnId ? {
|
|
7297
|
+
...t,
|
|
7298
|
+
final: true
|
|
7299
|
+
} : t));
|
|
7300
|
+
setStatus("error");
|
|
7301
|
+
setError(message);
|
|
7302
|
+
},
|
|
7303
|
+
isMounted: () => mountedRef.current
|
|
7304
|
+
});
|
|
7305
|
+
return true;
|
|
7306
|
+
}, [
|
|
7307
|
+
apiBase,
|
|
7308
|
+
embedKey,
|
|
7309
|
+
fetchImpl,
|
|
7310
|
+
status,
|
|
7311
|
+
markHandoffToHuman
|
|
7312
|
+
]);
|
|
7313
|
+
const sendEvent = useCallback(async (events) => {
|
|
7314
|
+
const chatToken = chatTokenRef.current;
|
|
7315
|
+
if (chatToken === void 0 || events.length === 0) return false;
|
|
7316
|
+
try {
|
|
7317
|
+
const res = await fetchImpl(withEmbedKeyParam(`${apiBase}/event`, embedKey), {
|
|
7318
|
+
method: "POST",
|
|
7319
|
+
headers: {
|
|
7320
|
+
"content-type": "application/json",
|
|
7321
|
+
authorization: `Bearer ${chatToken}`
|
|
7322
|
+
},
|
|
7323
|
+
body: JSON.stringify({ events })
|
|
7324
|
+
});
|
|
7325
|
+
if (res.ok) try {
|
|
7326
|
+
const body = await res.json();
|
|
7327
|
+
if (mountedRef.current && typeof body?.cartAttributionToken === "string") setCartAttributionToken(body.cartAttributionToken);
|
|
7328
|
+
} catch {}
|
|
7329
|
+
return res.ok;
|
|
7330
|
+
} catch {
|
|
7331
|
+
return false;
|
|
7332
|
+
}
|
|
7333
|
+
}, [
|
|
7334
|
+
apiBase,
|
|
7335
|
+
embedKey,
|
|
7336
|
+
fetchImpl
|
|
7337
|
+
]);
|
|
7338
|
+
/**
|
|
7339
|
+
* `POST /widget/ingest` with one event per receipt kind that just became
|
|
7340
|
+
* true — the two receipts behind the console's ticks on an outbound
|
|
7341
|
+
* bubble: `client.messages_delivered` (it reached this browser) and
|
|
7342
|
+
* `client.messages_read` (the shopper could actually see it).
|
|
7343
|
+
*
|
|
7344
|
+
* ## Two kinds, one POST
|
|
7345
|
+
*
|
|
7346
|
+
* The common case — a reply landing on a tab the shopper is looking at —
|
|
7347
|
+
* is both facts at once, and posting them separately would double the
|
|
7348
|
+
* requests to say one thing. They stay two EVENTS because they are two
|
|
7349
|
+
* claims: a turn that arrives on a backgrounded tab is delivered and not
|
|
7350
|
+
* read, and collapsing them would re-invent the inference this whole
|
|
7351
|
+
* feature exists to avoid.
|
|
7352
|
+
*
|
|
7353
|
+
* ## `sinceStartMs`, anchored to `sessionOriginRef` — never a wall clock
|
|
7354
|
+
*
|
|
7355
|
+
* Same discipline `@wesence/conversation-events`'s `ingest-contract.ts`
|
|
7356
|
+
* spells out at length: the SERVER converts this offset to
|
|
7357
|
+
* `occurredAt = conversation_sessions.started_at + sinceStartMs`, so the
|
|
7358
|
+
* offset has to be relative to the SAME real-world instant that row was
|
|
7359
|
+
* minted, not to an arbitrary browser timestamp. See `sessionOriginRef`'s
|
|
7360
|
+
* own doc comment for which END of the boot round trip that has to be, and
|
|
7361
|
+
* what silently broke while it was the other one.
|
|
7362
|
+
*
|
|
7363
|
+
* ## A WATERMARK, not a per-turn claim
|
|
7364
|
+
*
|
|
7365
|
+
* Each event means "as of now, the shopper's client had received (or had
|
|
7366
|
+
* on screen) the conversation" — never a specific turn id, because the
|
|
7367
|
+
* ingest contract carries none (see its own doc comment). The api-side
|
|
7368
|
+
* resolvers (`Turn.deliveredAt` / `Turn.readAt`) turn that into a per-turn
|
|
7369
|
+
* answer by comparing the event's `occurredAt` against each turn's own
|
|
7370
|
+
* `completedAt`.
|
|
7371
|
+
*
|
|
7372
|
+
* ## Best-effort, always — same posture as `sendEvent`
|
|
7373
|
+
*
|
|
7374
|
+
* Never throws, never surfaces to the caller as anything but a resolved
|
|
7375
|
+
* promise: a failed receipt POST must never read as a storefront error,
|
|
7376
|
+
* and the watermark sets are advanced regardless of the request's outcome
|
|
7377
|
+
* (a transient failure here is not worth retrying — the NEXT genuinely-new
|
|
7378
|
+
* inbound turn, or the next visibility change, naturally produces another
|
|
7379
|
+
* attempt).
|
|
7380
|
+
*/
|
|
7381
|
+
const sendClientReceipts = useCallback(async (kinds) => {
|
|
7382
|
+
const chatToken = chatTokenRef.current;
|
|
7383
|
+
const sessionId = visitorSessionIdRef.current;
|
|
7384
|
+
const origin = sessionOriginRef.current;
|
|
7385
|
+
if (chatToken === void 0 || sessionId === void 0 || origin === null) return;
|
|
7386
|
+
if (kinds.length === 0) return;
|
|
7387
|
+
const sinceStartMs = Math.max(0, Math.round(now() - origin));
|
|
7388
|
+
const events = kinds.map((kind) => {
|
|
7389
|
+
const clientSeq = clientSeqRef.current;
|
|
7390
|
+
clientSeqRef.current += 1;
|
|
7391
|
+
return {
|
|
7392
|
+
kind,
|
|
7393
|
+
clientSeq,
|
|
7394
|
+
sinceStartMs
|
|
7395
|
+
};
|
|
7396
|
+
});
|
|
7397
|
+
try {
|
|
7398
|
+
await fetchImpl(withEmbedKeyParam(`${apiBase}/ingest`, embedKey), {
|
|
7399
|
+
method: "POST",
|
|
7400
|
+
headers: {
|
|
7401
|
+
"content-type": "application/json",
|
|
7402
|
+
authorization: `Bearer ${chatToken}`
|
|
7403
|
+
},
|
|
7404
|
+
body: JSON.stringify({
|
|
7405
|
+
sessionId,
|
|
7406
|
+
events
|
|
7407
|
+
})
|
|
7408
|
+
});
|
|
7409
|
+
} catch {}
|
|
7410
|
+
}, [
|
|
7411
|
+
apiBase,
|
|
7412
|
+
embedKey,
|
|
7413
|
+
fetchImpl,
|
|
7414
|
+
now
|
|
7415
|
+
]);
|
|
7416
|
+
/**
|
|
7417
|
+
* Decides, on every `turns` change and every visibility flip, which of the
|
|
7418
|
+
* two receipts a NEW FINAL inbound (agent/human) turn has just earned.
|
|
7419
|
+
*
|
|
7420
|
+
* **Delivery does not wait for the tab.** A turn in `turns` has arrived in
|
|
7421
|
+
* this browser and been put in the transcript — that is the whole claim,
|
|
7422
|
+
* and it is equally true of a backgrounded tab. Gating it on visibility
|
|
7423
|
+
* (as the read receipt is, rightly) would have made "delivered" a slower
|
|
7424
|
+
* synonym for "read" and left the state it exists to express — reached
|
|
7425
|
+
* them, has not been looked at — unrepresentable.
|
|
7426
|
+
*
|
|
7427
|
+
* **Read waits for the tab, and nothing else.** `document.visibilityState
|
|
7428
|
+
* === 'visible'` is the honest limit of what a browser can say about the
|
|
7429
|
+
* shopper having seen a reply. It over-claims (a visible tab in another
|
|
7430
|
+
* window, a shopper who walked away) and this is stated plainly in the
|
|
7431
|
+
* field's own GraphQL description rather than dressed up.
|
|
7432
|
+
*
|
|
7433
|
+
* **`final`, not merely present, is what counts — for both.** A streaming
|
|
7434
|
+
* reply renders as an agent-speaker turn from its FIRST token
|
|
7435
|
+
* (`final: false`, `text: ''` at the instant `send()`'s optimistic caller
|
|
7436
|
+
* turn lands) — see `mergeIncoming`/the streaming reducer. Reporting that
|
|
7437
|
+
* placeholder as delivered or read would claim a receipt for content that
|
|
7438
|
+
* does not exist yet. Waiting for `final: true` is also why the watermarks
|
|
7439
|
+
* below are Sets of turn ids, not array-length cursors: the placeholder is
|
|
7440
|
+
* updated IN PLACE as tokens arrive (same index, growing text), so "how
|
|
7441
|
+
* many turns are there" never changes across that transition — only
|
|
7442
|
+
* `final` does.
|
|
7443
|
+
*
|
|
7444
|
+
* One event per kind per detection, not one per turn: several turns can
|
|
7445
|
+
* become final between two checks (a fast exchange, or turns that arrived
|
|
7446
|
+
* while the tab was hidden), and a receipt is a high-water mark anyway —
|
|
7447
|
+
* a single event covers all of them.
|
|
7448
|
+
*
|
|
7449
|
+
* Two triggers, not one: a NEW `turns` value fires it, and a
|
|
7450
|
+
* `visibilitychange` re-fires it so a turn that was DELIVERED to a hidden
|
|
7451
|
+
* tab still earns its read receipt when the shopper comes back —
|
|
7452
|
+
* otherwise no further `turns` change occurs once they do, and the read
|
|
7453
|
+
* tick would never arrive.
|
|
7454
|
+
*/
|
|
7455
|
+
useEffect(() => {
|
|
7456
|
+
const reportReceipts = () => {
|
|
7457
|
+
const delivered = deliveredTurnIdsRef.current;
|
|
7458
|
+
const read = readTurnIdsRef.current;
|
|
7459
|
+
const visible = typeof document === "undefined" || document.visibilityState === "visible";
|
|
7460
|
+
const kinds = [];
|
|
7461
|
+
let sawNewDelivery = false;
|
|
7462
|
+
let sawNewRead = false;
|
|
7463
|
+
for (const t of turns) {
|
|
7464
|
+
if (t.speaker !== "agent" || !t.final) continue;
|
|
7465
|
+
if (!delivered.has(t.id)) {
|
|
7466
|
+
delivered.add(t.id);
|
|
7467
|
+
sawNewDelivery = true;
|
|
7468
|
+
}
|
|
7469
|
+
if (visible && !read.has(t.id)) {
|
|
7470
|
+
read.add(t.id);
|
|
7471
|
+
sawNewRead = true;
|
|
7472
|
+
}
|
|
7473
|
+
}
|
|
7474
|
+
if (sawNewDelivery) kinds.push("client.messages_delivered");
|
|
7475
|
+
if (sawNewRead) kinds.push("client.messages_read");
|
|
7476
|
+
if (kinds.length > 0) sendClientReceipts(kinds);
|
|
7477
|
+
};
|
|
7478
|
+
reportReceipts();
|
|
7479
|
+
if (typeof document === "undefined") return;
|
|
7480
|
+
document.addEventListener("visibilitychange", reportReceipts);
|
|
7481
|
+
return () => document.removeEventListener("visibilitychange", reportReceipts);
|
|
7482
|
+
}, [turns, sendClientReceipts]);
|
|
6420
7483
|
return {
|
|
6421
7484
|
turns,
|
|
6422
7485
|
launcher,
|
|
@@ -6429,118 +7492,8 @@ function useChatSession(options) {
|
|
|
6429
7492
|
error,
|
|
6430
7493
|
ready,
|
|
6431
7494
|
connection,
|
|
6432
|
-
send
|
|
6433
|
-
|
|
6434
|
-
if (chatToken === void 0 || status === "streaming") return false;
|
|
6435
|
-
const callerTurnId = `caller-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
6436
|
-
const agentTurnId = `agent-${callerTurnId}`;
|
|
6437
|
-
setTurns((prev) => [
|
|
6438
|
-
...prev,
|
|
6439
|
-
...options?.silent ? [] : [{
|
|
6440
|
-
id: callerTurnId,
|
|
6441
|
-
speaker: "caller",
|
|
6442
|
-
text,
|
|
6443
|
-
final: true
|
|
6444
|
-
}],
|
|
6445
|
-
{
|
|
6446
|
-
id: agentTurnId,
|
|
6447
|
-
speaker: "agent",
|
|
6448
|
-
text: "",
|
|
6449
|
-
final: false
|
|
6450
|
-
}
|
|
6451
|
-
]);
|
|
6452
|
-
setStatus((prev) => prev === "escalated" ? prev : "streaming");
|
|
6453
|
-
const rollBack = () => {
|
|
6454
|
-
setTurns((prev) => prev.filter((t) => t.id !== callerTurnId && t.id !== agentTurnId));
|
|
6455
|
-
};
|
|
6456
|
-
let res;
|
|
6457
|
-
try {
|
|
6458
|
-
res = await fetchImpl(withEmbedKeyParam(`${apiBase}/chat`, embedKey), {
|
|
6459
|
-
method: "POST",
|
|
6460
|
-
headers: {
|
|
6461
|
-
"content-type": "application/json",
|
|
6462
|
-
authorization: `Bearer ${chatToken}`
|
|
6463
|
-
},
|
|
6464
|
-
body: JSON.stringify({ message: text })
|
|
6465
|
-
});
|
|
6466
|
-
} catch {
|
|
6467
|
-
rollBack();
|
|
6468
|
-
setStatus("error");
|
|
6469
|
-
setError("Could not reach the conversation.");
|
|
6470
|
-
return false;
|
|
6471
|
-
}
|
|
6472
|
-
if (!res.ok || res.body === null) {
|
|
6473
|
-
rollBack();
|
|
6474
|
-
setStatus("error");
|
|
6475
|
-
setError(`The conversation could not accept that message (${res.status}).`);
|
|
6476
|
-
return false;
|
|
6477
|
-
}
|
|
6478
|
-
streamReply({
|
|
6479
|
-
body: res.body,
|
|
6480
|
-
agentTurnId,
|
|
6481
|
-
setTurns,
|
|
6482
|
-
onCardsEvent: (evt) => {
|
|
6483
|
-
if (mountedRef.current) setCards((prev) => [...prev, evt]);
|
|
6484
|
-
},
|
|
6485
|
-
onCheckoutEvent: (evt) => {
|
|
6486
|
-
if (mountedRef.current) setCheckoutHandoffs((prev) => [...prev, evt]);
|
|
6487
|
-
},
|
|
6488
|
-
onEscalated: () => {
|
|
6489
|
-
if (!mountedRef.current) return;
|
|
6490
|
-
setStatus("escalated");
|
|
6491
|
-
},
|
|
6492
|
-
onDone: (turnId) => {
|
|
6493
|
-
if (!mountedRef.current) return;
|
|
6494
|
-
setTurns((prev) => prev.map((t) => t.id === agentTurnId ? {
|
|
6495
|
-
...t,
|
|
6496
|
-
id: turnId,
|
|
6497
|
-
final: true
|
|
6498
|
-
} : t));
|
|
6499
|
-
setStatus((prev) => prev === "escalated" ? prev : "idle");
|
|
6500
|
-
},
|
|
6501
|
-
onError: (message) => {
|
|
6502
|
-
if (!mountedRef.current) return;
|
|
6503
|
-
setTurns((prev) => prev.map((t) => t.id === agentTurnId ? {
|
|
6504
|
-
...t,
|
|
6505
|
-
final: true
|
|
6506
|
-
} : t));
|
|
6507
|
-
setStatus("error");
|
|
6508
|
-
setError(message);
|
|
6509
|
-
},
|
|
6510
|
-
isMounted: () => mountedRef.current
|
|
6511
|
-
});
|
|
6512
|
-
return true;
|
|
6513
|
-
}, [
|
|
6514
|
-
apiBase,
|
|
6515
|
-
embedKey,
|
|
6516
|
-
fetchImpl,
|
|
6517
|
-
status
|
|
6518
|
-
]),
|
|
6519
|
-
sendEvent: useCallback(async (events) => {
|
|
6520
|
-
const chatToken = chatTokenRef.current;
|
|
6521
|
-
if (chatToken === void 0 || events.length === 0) return false;
|
|
6522
|
-
try {
|
|
6523
|
-
const res = await fetchImpl(withEmbedKeyParam(`${apiBase}/event`, embedKey), {
|
|
6524
|
-
method: "POST",
|
|
6525
|
-
headers: {
|
|
6526
|
-
"content-type": "application/json",
|
|
6527
|
-
authorization: `Bearer ${chatToken}`
|
|
6528
|
-
},
|
|
6529
|
-
body: JSON.stringify({ events })
|
|
6530
|
-
});
|
|
6531
|
-
if (res.ok) try {
|
|
6532
|
-
const body = await res.json();
|
|
6533
|
-
if (mountedRef.current && typeof body?.cartAttributionToken === "string") setCartAttributionToken(body.cartAttributionToken);
|
|
6534
|
-
} catch {}
|
|
6535
|
-
return res.ok;
|
|
6536
|
-
} catch {
|
|
6537
|
-
return false;
|
|
6538
|
-
}
|
|
6539
|
-
}, [
|
|
6540
|
-
apiBase,
|
|
6541
|
-
embedKey,
|
|
6542
|
-
fetchImpl
|
|
6543
|
-
]),
|
|
7495
|
+
send,
|
|
7496
|
+
sendEvent,
|
|
6544
7497
|
checkout: useCallback(async (items, curationId, cartAttributionToken) => {
|
|
6545
7498
|
const chatToken = chatTokenRef.current;
|
|
6546
7499
|
if (chatToken === void 0 || items.length === 0) return null;
|
|
@@ -6611,9 +7564,10 @@ function useChatSession(options) {
|
|
|
6611
7564
|
speaker: "caller",
|
|
6612
7565
|
text: message ?? "",
|
|
6613
7566
|
final: true,
|
|
7567
|
+
delivery: "sent",
|
|
6614
7568
|
attachments: [sent.attachment]
|
|
6615
7569
|
}]);
|
|
6616
|
-
if (sent.escalated)
|
|
7570
|
+
if (sent.escalated) markHandoffToHuman();
|
|
6617
7571
|
else if (sent.message) {
|
|
6618
7572
|
/**
|
|
6619
7573
|
* Nobody could be put on the conversation, and this endpoint never
|
|
@@ -6632,7 +7586,8 @@ function useChatSession(options) {
|
|
|
6632
7586
|
}, [
|
|
6633
7587
|
apiBase,
|
|
6634
7588
|
embedKey,
|
|
6635
|
-
fetchImpl
|
|
7589
|
+
fetchImpl,
|
|
7590
|
+
markHandoffToHuman
|
|
6636
7591
|
])
|
|
6637
7592
|
};
|
|
6638
7593
|
}
|
|
@@ -7466,7 +8421,8 @@ function buildCartLineContext(item) {
|
|
|
7466
8421
|
...item.imageUrl !== void 0 ? { imageUrl: item.imageUrl } : {},
|
|
7467
8422
|
priceMinor: item.priceMinor,
|
|
7468
8423
|
currency: item.currency,
|
|
7469
|
-
...item.handle !== void 0 ? { handle: item.handle } : {}
|
|
8424
|
+
...item.handle !== void 0 ? { handle: item.handle } : {},
|
|
8425
|
+
...item.platformVariantId !== void 0 ? { platformVariantId: item.platformVariantId } : {}
|
|
7470
8426
|
};
|
|
7471
8427
|
}
|
|
7472
8428
|
/**
|
|
@@ -7505,7 +8461,7 @@ function buildCartLineContext(item) {
|
|
|
7505
8461
|
* about offering voice here costs a byte until a caller actually presses
|
|
7506
8462
|
* the microphone.
|
|
7507
8463
|
*/
|
|
7508
|
-
function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, collector, messages = defaultWidgetMessages, locale = "en", productHref, curationHref, brandPrimary, brandSecondary, brandAccent, defaultOpen = false }) {
|
|
8464
|
+
function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, collector, messages = defaultWidgetMessages, locale = "en", productHref, curationHref, brandPrimary, brandSecondary, brandAccent, avatar, defaultOpen = false, attribution }) {
|
|
7509
8465
|
const [open, setOpen] = useState(defaultOpen);
|
|
7510
8466
|
/**
|
|
7511
8467
|
* Maps the tenant's semantic config fields onto the widget's historical
|
|
@@ -7552,7 +8508,7 @@ function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, col
|
|
|
7552
8508
|
}) } : {});
|
|
7553
8509
|
const inCall = voiceEnabled && (voice.phase === "connecting" || voice.phase === "connected");
|
|
7554
8510
|
const onAddToCart = resolveAddToCartHandler(bridge, productHref);
|
|
7555
|
-
const navigate = bridge?.navigate;
|
|
8511
|
+
const navigate = useMemo(() => bridge?.navigate?.bind(bridge), [bridge]);
|
|
7556
8512
|
const onSendText = useCallback(async (text) => session.send(text), [session]);
|
|
7557
8513
|
/**
|
|
7558
8514
|
* The microphone is the only control that starts the voice leg — a
|
|
@@ -7613,6 +8569,8 @@ function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, col
|
|
|
7613
8569
|
text: turn.text,
|
|
7614
8570
|
locale,
|
|
7615
8571
|
final: turn.final,
|
|
8572
|
+
...turn.event ? { event: turn.event } : {},
|
|
8573
|
+
...turn.delivery ? { delivery: turn.delivery } : {},
|
|
7616
8574
|
...turn.cards ? { cards: turn.cards } : {},
|
|
7617
8575
|
...turn.attachments ? { attachments: turn.attachments } : {}
|
|
7618
8576
|
}));
|
|
@@ -7670,8 +8628,10 @@ function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, col
|
|
|
7670
8628
|
locale,
|
|
7671
8629
|
...session.launcher.label !== void 0 ? { launcherLabel: session.launcher.label } : {},
|
|
7672
8630
|
...session.launcher.position !== void 0 ? { position: session.launcher.position } : {},
|
|
7673
|
-
...skinStyle !== void 0 ? { skinStyle } : {}
|
|
8631
|
+
...skinStyle !== void 0 ? { skinStyle } : {},
|
|
8632
|
+
...avatar !== void 0 ? { avatar } : {},
|
|
8633
|
+
...attribution !== void 0 ? { attribution } : {}
|
|
7674
8634
|
});
|
|
7675
8635
|
}
|
|
7676
8636
|
//#endregion
|
|
7677
|
-
export { CONCIERGE_POSITIONS as A,
|
|
8637
|
+
export { CONCIERGE_POSITIONS as A, isWidgetAvatar as B, ConciergeShell as C, resolveWidgetMessages as D, formatMessage as E, panelClasses as F, BotFace as H, positionClasses as I, positionForArrow as L, alignOf as M, edgeOf as N, widgetMessagesFromCopy as O, nearestPosition as P, DEFAULT_WIDGET_AVATAR as R, latencyBetween as S, defaultWidgetMessages as T, labelProps as U, RopeKnot as V, cn as W, botStateFor as _, useVoiceSession as a, SessionLog as b, VoiceWidget as c, WidgetCartSummary as d, WidgetCardList as f, IDLE_SNAPSHOT as g, parseBlocks as h, createWidgetVoiceTokenFetcher as i, DEFAULT_CONCIERGE_POSITION as j, ConciergeLauncher as k, readsAsCheckoutIntent as l, WidgetMarkdown as m, resolveAddToCartHandler as n, useChatSession as o, formatMoney as p, ROOM_EVENTS as r, detectPage as s, ConciergeWidget as t, textDirectionFor as u, SseFrameParser as v, MorphingLoader as w, formatMs as x, SESSION_EVENTS as y, WIDGET_AVATARS as z };
|