@saar-ai/web-widget 0.10.0 → 0.11.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/adopt-stylesheet.d.ts +11 -0
- package/dist/adopt-stylesheet.d.ts.map +1 -0
- package/dist/chunks/{host-widget-BtiYIMwb.js → host-widget-BZKCb7yR.js} +1777 -127
- package/dist/concierge-shell.css +2 -0
- package/dist/concierge-state.d.ts +234 -0
- package/dist/concierge-state.d.ts.map +1 -0
- package/dist/dock/dock-renderer.d.ts +3 -0
- package/dist/dock/dock-renderer.d.ts.map +1 -0
- package/dist/dock/dock-state.d.ts +34 -174
- package/dist/dock/dock-state.d.ts.map +1 -1
- package/dist/generated/concierge-shell-css.d.ts +2 -0
- package/dist/generated/concierge-shell-css.d.ts.map +1 -0
- package/dist/generated/widget-css.d.ts.map +1 -1
- package/dist/host-widget.d.ts +24 -1
- package/dist/host-widget.d.ts.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +205 -138
- package/dist/mount.d.ts +4 -5
- package/dist/mount.d.ts.map +1 -1
- package/dist/next/index.js +1 -1
- package/dist/renderers.d.ts +3 -0
- package/dist/renderers.d.ts.map +1 -0
- package/dist/styles.d.ts +1 -0
- package/dist/styles.d.ts.map +1 -1
- package/dist/voice-widget.d.ts +93 -3
- package/dist/voice-widget.d.ts.map +1 -1
- package/dist/widget/concierge-launcher.d.ts +53 -0
- package/dist/widget/concierge-launcher.d.ts.map +1 -0
- package/dist/widget/concierge-shell.d.ts +255 -0
- package/dist/widget/concierge-shell.d.ts.map +1 -0
- package/dist/widget/position.d.ts +65 -0
- package/dist/widget/position.d.ts.map +1 -0
- package/dist/widget/shell-renderer.d.ts +3 -0
- package/dist/widget/shell-renderer.d.ts.map +1 -0
- package/dist/widget/transcript-geometry.d.ts +220 -0
- package/dist/widget/transcript-geometry.d.ts.map +1 -0
- package/dist/widget/widget-view.d.ts +74 -0
- package/dist/widget/widget-view.d.ts.map +1 -0
- package/dist/widget.css +1 -1
- package/package.json +1 -1
- package/src/styles/concierge-shell-entry.css +42 -0
- package/src/styles/widget-entry.css +39 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Fragment as Fragment$1, useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
2
|
+
import { Fragment as Fragment$1, createContext, createElement, forwardRef, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
3
3
|
//#region ../../node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
|
|
4
4
|
function r(e) {
|
|
5
5
|
var t, f, n = "";
|
|
@@ -3896,6 +3896,125 @@ function KnotSvg({ state, tightenKey }) {
|
|
|
3896
3896
|
});
|
|
3897
3897
|
}
|
|
3898
3898
|
//#endregion
|
|
3899
|
+
//#region src/avatar.ts
|
|
3900
|
+
/**
|
|
3901
|
+
* Which face the widget draws — a per-tenant `appearance.avatar` choice.
|
|
3902
|
+
*
|
|
3903
|
+
* `'orb'` is `BotFace`, the animated gradient blob this widget has always
|
|
3904
|
+
* shipped. `'knot'` is `RopeKnot`, a hand-drawn rope line that ties and
|
|
3905
|
+
* unties itself through the same four {@link BotState}s. Kept as data,
|
|
3906
|
+
* separate from the components, for the same reason `bot-state.ts` keeps
|
|
3907
|
+
* `BotState` separate from `BotFace`: parsing and defaulting have to be
|
|
3908
|
+
* assertable without rendering either avatar.
|
|
3909
|
+
*/
|
|
3910
|
+
var WIDGET_AVATARS = ["orb", "knot"];
|
|
3911
|
+
/** What every layer in this package falls back to when a tenant never published one. */
|
|
3912
|
+
var DEFAULT_WIDGET_AVATAR = "orb";
|
|
3913
|
+
/** Whether a value is an avatar this widget knows how to render. Mirrors `bot-state.ts`'s `isBotState`. */
|
|
3914
|
+
function isWidgetAvatar(value) {
|
|
3915
|
+
return typeof value === "string" && WIDGET_AVATARS.includes(value);
|
|
3916
|
+
}
|
|
3917
|
+
//#endregion
|
|
3918
|
+
//#region src/morphing-loader.tsx
|
|
3919
|
+
/**
|
|
3920
|
+
* A voice-frequency visualizer loader.
|
|
3921
|
+
*
|
|
3922
|
+
* Six soft vertical bars rise and fall like a calm voice waveform,
|
|
3923
|
+
* using the plum brand family with no amber or yellow tints.
|
|
3924
|
+
* Respects prefers-reduced-motion by resting the bars at mid-height.
|
|
3925
|
+
*/
|
|
3926
|
+
function MorphingLoader({ size = "md", variant = "brand", className, label = "Loading" }) {
|
|
3927
|
+
const dims = {
|
|
3928
|
+
sm: "h-3 w-3",
|
|
3929
|
+
md: "h-5 w-5",
|
|
3930
|
+
lg: "h-10 w-10",
|
|
3931
|
+
full: "h-full w-full"
|
|
3932
|
+
}[size];
|
|
3933
|
+
const barWidth = {
|
|
3934
|
+
sm: "w-px",
|
|
3935
|
+
md: "w-[2px]",
|
|
3936
|
+
lg: "w-[3px]",
|
|
3937
|
+
full: "w-[5%]"
|
|
3938
|
+
}[size];
|
|
3939
|
+
const gap = {
|
|
3940
|
+
sm: "gap-px",
|
|
3941
|
+
md: "gap-[2px]",
|
|
3942
|
+
lg: "gap-[3px]",
|
|
3943
|
+
full: "gap-[2%]"
|
|
3944
|
+
}[size];
|
|
3945
|
+
const bars = [
|
|
3946
|
+
{
|
|
3947
|
+
min: .35,
|
|
3948
|
+
max: .65,
|
|
3949
|
+
opacityMin: .45,
|
|
3950
|
+
opacityMax: .75,
|
|
3951
|
+
duration: 1.2,
|
|
3952
|
+
delay: 0
|
|
3953
|
+
},
|
|
3954
|
+
{
|
|
3955
|
+
min: .3,
|
|
3956
|
+
max: .85,
|
|
3957
|
+
opacityMin: .4,
|
|
3958
|
+
opacityMax: .9,
|
|
3959
|
+
duration: 1.35,
|
|
3960
|
+
delay: .12
|
|
3961
|
+
},
|
|
3962
|
+
{
|
|
3963
|
+
min: .25,
|
|
3964
|
+
max: 1,
|
|
3965
|
+
opacityMin: .35,
|
|
3966
|
+
opacityMax: 1,
|
|
3967
|
+
duration: 1.5,
|
|
3968
|
+
delay: .24
|
|
3969
|
+
},
|
|
3970
|
+
{
|
|
3971
|
+
min: .25,
|
|
3972
|
+
max: 1,
|
|
3973
|
+
opacityMin: .35,
|
|
3974
|
+
opacityMax: 1,
|
|
3975
|
+
duration: 1.5,
|
|
3976
|
+
delay: .36
|
|
3977
|
+
},
|
|
3978
|
+
{
|
|
3979
|
+
min: .3,
|
|
3980
|
+
max: .85,
|
|
3981
|
+
opacityMin: .4,
|
|
3982
|
+
opacityMax: .9,
|
|
3983
|
+
duration: 1.35,
|
|
3984
|
+
delay: .48
|
|
3985
|
+
},
|
|
3986
|
+
{
|
|
3987
|
+
min: .35,
|
|
3988
|
+
max: .65,
|
|
3989
|
+
opacityMin: .45,
|
|
3990
|
+
opacityMax: .75,
|
|
3991
|
+
duration: 1.2,
|
|
3992
|
+
delay: .6
|
|
3993
|
+
}
|
|
3994
|
+
];
|
|
3995
|
+
const isLight = variant === "light";
|
|
3996
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
3997
|
+
className: cn("relative inline-flex items-end justify-center", dims, gap, isLight && "text-[var(--widget-accent-foreground)]", className),
|
|
3998
|
+
role: "status",
|
|
3999
|
+
"aria-label": label,
|
|
4000
|
+
children: [bars.map((bar, i) => /* @__PURE__ */ jsx("span", {
|
|
4001
|
+
className: cn("rounded-full motion-reduce:scale-y-75 motion-reduce:opacity-70", "animate-[voice-bar_1.4s_cubic-bezier(0.45,0,0.55,1)_infinite]", barWidth, "h-full", isLight ? "bg-current opacity-90" : "bg-gradient-to-t from-brand-plum to-[color-mix(in_oklab,var(--brand-plum)_55%,white)]"),
|
|
4002
|
+
style: {
|
|
4003
|
+
animationDuration: `${bar.duration}s`,
|
|
4004
|
+
animationDelay: `${bar.delay}s`,
|
|
4005
|
+
["--voice-min"]: bar.min,
|
|
4006
|
+
["--voice-max"]: bar.max,
|
|
4007
|
+
["--voice-min-opacity"]: bar.opacityMin,
|
|
4008
|
+
["--voice-max-opacity"]: bar.opacityMax
|
|
4009
|
+
},
|
|
4010
|
+
"aria-hidden": true
|
|
4011
|
+
}, i)), /* @__PURE__ */ jsx("span", {
|
|
4012
|
+
className: "sr-only",
|
|
4013
|
+
children: label
|
|
4014
|
+
})]
|
|
4015
|
+
});
|
|
4016
|
+
}
|
|
4017
|
+
//#endregion
|
|
3899
4018
|
//#region src/card-aspect.ts
|
|
3900
4019
|
/** The CSS `aspect-ratio` value each of §9.1's three choices means. */
|
|
3901
4020
|
var CARD_ASPECT = Object.freeze({
|
|
@@ -7682,9 +7801,9 @@ function safeImageUrl(url) {
|
|
|
7682
7801
|
return /^https:\/\//i.test(url) ? url : void 0;
|
|
7683
7802
|
}
|
|
7684
7803
|
//#endregion
|
|
7685
|
-
//#region src/
|
|
7686
|
-
/** Every state the
|
|
7687
|
-
var
|
|
7804
|
+
//#region src/concierge-state.ts
|
|
7805
|
+
/** Every state the session can be in — §5.1's ten, plus the four the shipped widget already had. */
|
|
7806
|
+
var CONCIERGE_STATES = [
|
|
7688
7807
|
"dormant",
|
|
7689
7808
|
"connecting",
|
|
7690
7809
|
"listening",
|
|
@@ -7700,8 +7819,8 @@ var DOCK_STATES = [
|
|
|
7700
7819
|
"error",
|
|
7701
7820
|
"cards"
|
|
7702
7821
|
];
|
|
7703
|
-
/** A
|
|
7704
|
-
var
|
|
7822
|
+
/** A concierge nobody has touched, on a tenant with no voice. Every field explicit — see `ConciergeStateInput`. */
|
|
7823
|
+
var idleConciergeInput = {
|
|
7705
7824
|
engaged: false,
|
|
7706
7825
|
voice: {
|
|
7707
7826
|
enabled: false,
|
|
@@ -7729,12 +7848,6 @@ var idleDockInput = {
|
|
|
7729
7848
|
composing: false,
|
|
7730
7849
|
textIdle: false
|
|
7731
7850
|
};
|
|
7732
|
-
/** §1 rule 5 — the three states in which the audio channel is open. */
|
|
7733
|
-
var AUDIO_OPEN = new Set([
|
|
7734
|
-
"listening",
|
|
7735
|
-
"thinking",
|
|
7736
|
-
"speaking"
|
|
7737
|
-
]);
|
|
7738
7851
|
/** The live voice states, in `botStateFor`'s order. `null` when the room is not usably live. */
|
|
7739
7852
|
function liveVoiceState(voice) {
|
|
7740
7853
|
if (!voice.enabled) return null;
|
|
@@ -7746,20 +7859,108 @@ function liveVoiceState(voice) {
|
|
|
7746
7859
|
if (!voice.micOpen) return "muted";
|
|
7747
7860
|
return "listening";
|
|
7748
7861
|
}
|
|
7862
|
+
/** See {@link ConciergeSnapshot.callActive}. */
|
|
7863
|
+
function callActive(voice) {
|
|
7864
|
+
if (!voice.enabled) return false;
|
|
7865
|
+
return voice.phase === "connecting" || voice.phase === "connected" || voice.micPending;
|
|
7866
|
+
}
|
|
7749
7867
|
/**
|
|
7750
|
-
* §5.1's
|
|
7868
|
+
* §5.1's precedence, as a function. The ONLY place a session fact becomes a
|
|
7869
|
+
* state.
|
|
7870
|
+
*
|
|
7871
|
+
* @param input the session, as data — see {@link ConciergeStateInput}
|
|
7872
|
+
* @returns the state and the facts every renderer shares
|
|
7873
|
+
*/
|
|
7874
|
+
function deriveConciergeState(input) {
|
|
7875
|
+
const { voice } = input;
|
|
7876
|
+
const base = (() => {
|
|
7877
|
+
if (input.error !== void 0 && input.error !== "") return "error";
|
|
7878
|
+
if (input.offline) return "offline";
|
|
7879
|
+
if (input.escalated) return "human";
|
|
7880
|
+
if (voice.enabled && voice.micBlocked) return "mic_blocked";
|
|
7881
|
+
if (input.reconnecting) return "reconnecting";
|
|
7882
|
+
if (input.ducked) return "ducked";
|
|
7883
|
+
if (input.engaged) return liveVoiceState(voice) ?? (input.channel === "text" ? "typing" : "dormant");
|
|
7884
|
+
return "dormant";
|
|
7885
|
+
})();
|
|
7886
|
+
const state = input.shelfCount > 0 && !input.sheetOpen && (base === "ducked" || base === "dormant") ? "cards" : base;
|
|
7887
|
+
return {
|
|
7888
|
+
state,
|
|
7889
|
+
callActive: callActive(voice),
|
|
7890
|
+
handoff: state === "human",
|
|
7891
|
+
shelfCount: input.shelfCount
|
|
7892
|
+
};
|
|
7893
|
+
}
|
|
7894
|
+
//#endregion
|
|
7895
|
+
//#region src/dock/dock-state.ts
|
|
7896
|
+
/**
|
|
7897
|
+
* THE DOCK'S VIEW — docs/DOCK_SPEC.md §5.1, drawn.
|
|
7898
|
+
*
|
|
7899
|
+
* Which state the session is in is decided in `../concierge-state.ts`
|
|
7900
|
+
* (`deriveConciergeState`) and shared with the widget generation
|
|
7901
|
+
* (docs/CONCIERGE_GENERATIONS.md §3). This module owns the other half for the
|
|
7902
|
+
* dock: what each of those states LOOKS like as a row — its caption, its
|
|
7903
|
+
* control set, its border, its mark's treatment, what it does to the sheet,
|
|
7904
|
+
* and whether it may recede to glass. Everything under `dock/` renders what
|
|
7905
|
+
* `deriveDockState` returns; nothing else in the dock decides a state, and
|
|
7906
|
+
* nothing in here decides one either.
|
|
7907
|
+
*
|
|
7908
|
+
* The precedence order, the `cards` rule and the live-voice ordering used to
|
|
7909
|
+
* live in this file. They moved out on 2026-09-17 with the split, unchanged,
|
|
7910
|
+
* so that both renderers read one state machine; `dock-state.test.ts` still
|
|
7911
|
+
* asserts §5.1 row by row through `deriveDockState`, whose signature and
|
|
7912
|
+
* output are exactly what they were.
|
|
7913
|
+
*
|
|
7914
|
+
* ## Glass is a decision too
|
|
7915
|
+
*
|
|
7916
|
+
* `DockView.glass` (§3.6) is derived here rather than in the row: which
|
|
7917
|
+
* states may recede to the colourless surface is exactly the kind of rule
|
|
7918
|
+
* that drifts when two components each hold half of it.
|
|
7919
|
+
*
|
|
7920
|
+
* ## Copy is a KEY, never a string
|
|
7921
|
+
*
|
|
7922
|
+
* `caption` carries either `{ kind: 'message', key }` — a `WidgetMessages`
|
|
7923
|
+
* key the renderer resolves against the tenant's own catalogue — or
|
|
7924
|
+
* `{ kind: 'text', text }` for something live (a partial transcript, a spoken
|
|
7925
|
+
* clause, an operator's line, the host's error). This module never formats
|
|
7926
|
+
* and never localises: it has no messages, on purpose, so the table can be
|
|
7927
|
+
* asserted without one.
|
|
7928
|
+
*/
|
|
7929
|
+
var DOCK_STATES = CONCIERGE_STATES;
|
|
7930
|
+
/** A dock nobody has touched, on a tenant with no voice — see `idleConciergeInput`. */
|
|
7931
|
+
var idleDockInput = idleConciergeInput;
|
|
7932
|
+
/** §1 rule 5 — the three states in which the audio channel is open. */
|
|
7933
|
+
var AUDIO_OPEN = new Set([
|
|
7934
|
+
"listening",
|
|
7935
|
+
"thinking",
|
|
7936
|
+
"speaking"
|
|
7937
|
+
]);
|
|
7938
|
+
/**
|
|
7939
|
+
* §5.1's table, as a function — the dock's public entry point, unchanged.
|
|
7751
7940
|
*
|
|
7752
7941
|
* @param input the session, as data — see {@link DockStateInput}
|
|
7753
7942
|
* @returns everything the row, the caption and the sheet need for one render
|
|
7754
7943
|
*/
|
|
7755
7944
|
function deriveDockState(input) {
|
|
7756
|
-
|
|
7945
|
+
return deriveDockView(deriveConciergeState(input), input);
|
|
7946
|
+
}
|
|
7947
|
+
/**
|
|
7948
|
+
* The dock's presentation of a state the shared machine already decided.
|
|
7949
|
+
*
|
|
7950
|
+
* Takes the snapshot AND the input: the snapshot for everything a renderer
|
|
7951
|
+
* may not recompute (the state, `handoff`, `callActive`, `shelfCount`), the
|
|
7952
|
+
* input for CONTENT — a partial transcript, a preamble, the operator's line,
|
|
7953
|
+
* the host's error text. The one thing this function never does is look at
|
|
7954
|
+
* the input to decide which state it is in.
|
|
7955
|
+
*/
|
|
7956
|
+
function deriveDockView(snapshot, input) {
|
|
7957
|
+
const derived = deriveView(snapshot.state, input);
|
|
7757
7958
|
const view = {
|
|
7758
7959
|
...derived,
|
|
7759
|
-
callActive: callActive
|
|
7960
|
+
callActive: snapshot.callActive,
|
|
7760
7961
|
glass: glassFor(derived.state, input),
|
|
7761
|
-
shelfCount:
|
|
7762
|
-
handoff:
|
|
7962
|
+
shelfCount: snapshot.shelfCount,
|
|
7963
|
+
handoff: snapshot.handoff
|
|
7763
7964
|
};
|
|
7764
7965
|
if (input.notice === void 0 || input.notice === "") return view;
|
|
7765
7966
|
if (view.state === "error" || view.state === "offline" || view.state === "human") return view;
|
|
@@ -7776,24 +7977,8 @@ function glassFor(state, input) {
|
|
|
7776
7977
|
if (state === "ducked") return true;
|
|
7777
7978
|
return state === "typing" && input.textIdle && !input.composing;
|
|
7778
7979
|
}
|
|
7779
|
-
|
|
7780
|
-
function callActive(voice) {
|
|
7781
|
-
if (!voice.enabled) return false;
|
|
7782
|
-
return voice.phase === "connecting" || voice.phase === "connected" || voice.micPending;
|
|
7783
|
-
}
|
|
7784
|
-
function deriveView(input) {
|
|
7980
|
+
function deriveView(state, input) {
|
|
7785
7981
|
const { voice } = input;
|
|
7786
|
-
const base = (() => {
|
|
7787
|
-
if (input.error !== void 0 && input.error !== "") return "error";
|
|
7788
|
-
if (input.offline) return "offline";
|
|
7789
|
-
if (input.escalated) return "human";
|
|
7790
|
-
if (voice.enabled && voice.micBlocked) return "mic_blocked";
|
|
7791
|
-
if (input.reconnecting) return "reconnecting";
|
|
7792
|
-
if (input.ducked) return "ducked";
|
|
7793
|
-
if (input.engaged) return liveVoiceState(voice) ?? (input.channel === "text" ? "typing" : "dormant");
|
|
7794
|
-
return "dormant";
|
|
7795
|
-
})();
|
|
7796
|
-
const state = input.shelfCount > 0 && !input.sheetOpen && (base === "ducked" || base === "dormant") ? "cards" : base;
|
|
7797
7982
|
const border = AUDIO_OPEN.has(state) ? "primary" : "rest";
|
|
7798
7983
|
const mark = border === "primary" ? "live" : "dimmed";
|
|
7799
7984
|
switch (state) {
|
|
@@ -9572,6 +9757,1470 @@ function botStateFor(snapshot) {
|
|
|
9572
9757
|
return "listening";
|
|
9573
9758
|
}
|
|
9574
9759
|
//#endregion
|
|
9760
|
+
//#region ../../node_modules/.pnpm/lucide-react@1.25.0_react@19.2.7/node_modules/lucide-react/dist/esm/shared/src/utils/mergeClasses.mjs
|
|
9761
|
+
/**
|
|
9762
|
+
* @license lucide-react v1.25.0 - ISC
|
|
9763
|
+
*
|
|
9764
|
+
* This source code is licensed under the ISC license.
|
|
9765
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
9766
|
+
*/
|
|
9767
|
+
var mergeClasses = (...classes) => classes.filter((className, index, array) => {
|
|
9768
|
+
return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
|
|
9769
|
+
}).join(" ").trim();
|
|
9770
|
+
//#endregion
|
|
9771
|
+
//#region ../../node_modules/.pnpm/lucide-react@1.25.0_react@19.2.7/node_modules/lucide-react/dist/esm/shared/src/utils/toKebabCase.mjs
|
|
9772
|
+
/**
|
|
9773
|
+
* @license lucide-react v1.25.0 - ISC
|
|
9774
|
+
*
|
|
9775
|
+
* This source code is licensed under the ISC license.
|
|
9776
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
9777
|
+
*/
|
|
9778
|
+
var toKebabCase = (string) => string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
9779
|
+
//#endregion
|
|
9780
|
+
//#region ../../node_modules/.pnpm/lucide-react@1.25.0_react@19.2.7/node_modules/lucide-react/dist/esm/shared/src/utils/toCamelCase.mjs
|
|
9781
|
+
/**
|
|
9782
|
+
* @license lucide-react v1.25.0 - ISC
|
|
9783
|
+
*
|
|
9784
|
+
* This source code is licensed under the ISC license.
|
|
9785
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
9786
|
+
*/
|
|
9787
|
+
var toCamelCase = (string) => string.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2) => p2 ? p2.toUpperCase() : p1.toLowerCase());
|
|
9788
|
+
//#endregion
|
|
9789
|
+
//#region ../../node_modules/.pnpm/lucide-react@1.25.0_react@19.2.7/node_modules/lucide-react/dist/esm/shared/src/utils/toPascalCase.mjs
|
|
9790
|
+
/**
|
|
9791
|
+
* @license lucide-react v1.25.0 - ISC
|
|
9792
|
+
*
|
|
9793
|
+
* This source code is licensed under the ISC license.
|
|
9794
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
9795
|
+
*/
|
|
9796
|
+
var toPascalCase = (string) => {
|
|
9797
|
+
const camelCase = toCamelCase(string);
|
|
9798
|
+
return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
|
|
9799
|
+
};
|
|
9800
|
+
//#endregion
|
|
9801
|
+
//#region ../../node_modules/.pnpm/lucide-react@1.25.0_react@19.2.7/node_modules/lucide-react/dist/esm/defaultAttributes.mjs
|
|
9802
|
+
/**
|
|
9803
|
+
* @license lucide-react v1.25.0 - ISC
|
|
9804
|
+
*
|
|
9805
|
+
* This source code is licensed under the ISC license.
|
|
9806
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
9807
|
+
*/
|
|
9808
|
+
var defaultAttributes = {
|
|
9809
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
9810
|
+
width: 24,
|
|
9811
|
+
height: 24,
|
|
9812
|
+
viewBox: "0 0 24 24",
|
|
9813
|
+
fill: "none",
|
|
9814
|
+
stroke: "currentColor",
|
|
9815
|
+
strokeWidth: 2,
|
|
9816
|
+
strokeLinecap: "round",
|
|
9817
|
+
strokeLinejoin: "round"
|
|
9818
|
+
};
|
|
9819
|
+
//#endregion
|
|
9820
|
+
//#region ../../node_modules/.pnpm/lucide-react@1.25.0_react@19.2.7/node_modules/lucide-react/dist/esm/shared/src/utils/hasA11yProp.mjs
|
|
9821
|
+
/**
|
|
9822
|
+
* @license lucide-react v1.25.0 - ISC
|
|
9823
|
+
*
|
|
9824
|
+
* This source code is licensed under the ISC license.
|
|
9825
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
9826
|
+
*/
|
|
9827
|
+
var hasA11yProp = (props) => {
|
|
9828
|
+
for (const prop in props) if (prop.startsWith("aria-") || prop === "role" || prop === "title") return true;
|
|
9829
|
+
return false;
|
|
9830
|
+
};
|
|
9831
|
+
//#endregion
|
|
9832
|
+
//#region ../../node_modules/.pnpm/lucide-react@1.25.0_react@19.2.7/node_modules/lucide-react/dist/esm/context.mjs
|
|
9833
|
+
/**
|
|
9834
|
+
* @license lucide-react v1.25.0 - ISC
|
|
9835
|
+
*
|
|
9836
|
+
* This source code is licensed under the ISC license.
|
|
9837
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
9838
|
+
*/
|
|
9839
|
+
var LucideContext = createContext({});
|
|
9840
|
+
var useLucideContext = () => useContext(LucideContext);
|
|
9841
|
+
//#endregion
|
|
9842
|
+
//#region ../../node_modules/.pnpm/lucide-react@1.25.0_react@19.2.7/node_modules/lucide-react/dist/esm/Icon.mjs
|
|
9843
|
+
/**
|
|
9844
|
+
* @license lucide-react v1.25.0 - ISC
|
|
9845
|
+
*
|
|
9846
|
+
* This source code is licensed under the ISC license.
|
|
9847
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
9848
|
+
*/
|
|
9849
|
+
var Icon = forwardRef(({ color, size, strokeWidth, absoluteStrokeWidth, className = "", children, iconNode, ...rest }, ref) => {
|
|
9850
|
+
const { size: contextSize = 24, strokeWidth: contextStrokeWidth = 2, absoluteStrokeWidth: contextAbsoluteStrokeWidth = false, color: contextColor = "currentColor", className: contextClass = "" } = useLucideContext() ?? {};
|
|
9851
|
+
const calculatedStrokeWidth = absoluteStrokeWidth ?? contextAbsoluteStrokeWidth ? Number(strokeWidth ?? contextStrokeWidth) * 24 / Number(size ?? contextSize) : strokeWidth ?? contextStrokeWidth;
|
|
9852
|
+
return createElement("svg", {
|
|
9853
|
+
ref,
|
|
9854
|
+
...defaultAttributes,
|
|
9855
|
+
width: size ?? contextSize ?? defaultAttributes.width,
|
|
9856
|
+
height: size ?? contextSize ?? defaultAttributes.height,
|
|
9857
|
+
stroke: color ?? contextColor,
|
|
9858
|
+
strokeWidth: calculatedStrokeWidth,
|
|
9859
|
+
className: mergeClasses("lucide", contextClass, className),
|
|
9860
|
+
...!children && !hasA11yProp(rest) && { "aria-hidden": "true" },
|
|
9861
|
+
...rest
|
|
9862
|
+
}, [...iconNode.map(([tag, attrs]) => createElement(tag, attrs)), ...Array.isArray(children) ? children : [children]]);
|
|
9863
|
+
});
|
|
9864
|
+
//#endregion
|
|
9865
|
+
//#region ../../node_modules/.pnpm/lucide-react@1.25.0_react@19.2.7/node_modules/lucide-react/dist/esm/createLucideIcon.mjs
|
|
9866
|
+
/**
|
|
9867
|
+
* @license lucide-react v1.25.0 - ISC
|
|
9868
|
+
*
|
|
9869
|
+
* This source code is licensed under the ISC license.
|
|
9870
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
9871
|
+
*/
|
|
9872
|
+
var createLucideIcon = (iconName, iconNode) => {
|
|
9873
|
+
const Component = forwardRef(({ className, ...props }, ref) => createElement(Icon, {
|
|
9874
|
+
ref,
|
|
9875
|
+
iconNode,
|
|
9876
|
+
className: mergeClasses(`lucide-${toKebabCase(toPascalCase(iconName))}`, `lucide-${iconName}`, className),
|
|
9877
|
+
...props
|
|
9878
|
+
}));
|
|
9879
|
+
Component.displayName = toPascalCase(iconName);
|
|
9880
|
+
return Component;
|
|
9881
|
+
};
|
|
9882
|
+
/**
|
|
9883
|
+
* @license lucide-react v1.25.0 - ISC
|
|
9884
|
+
*
|
|
9885
|
+
* This source code is licensed under the ISC license.
|
|
9886
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
9887
|
+
*/
|
|
9888
|
+
var GripVertical = createLucideIcon("grip-vertical", [
|
|
9889
|
+
["circle", {
|
|
9890
|
+
cx: "9",
|
|
9891
|
+
cy: "12",
|
|
9892
|
+
r: "1",
|
|
9893
|
+
key: "1vctgf"
|
|
9894
|
+
}],
|
|
9895
|
+
["circle", {
|
|
9896
|
+
cx: "9",
|
|
9897
|
+
cy: "5",
|
|
9898
|
+
r: "1",
|
|
9899
|
+
key: "hp0tcf"
|
|
9900
|
+
}],
|
|
9901
|
+
["circle", {
|
|
9902
|
+
cx: "9",
|
|
9903
|
+
cy: "19",
|
|
9904
|
+
r: "1",
|
|
9905
|
+
key: "fkjjf6"
|
|
9906
|
+
}],
|
|
9907
|
+
["circle", {
|
|
9908
|
+
cx: "15",
|
|
9909
|
+
cy: "12",
|
|
9910
|
+
r: "1",
|
|
9911
|
+
key: "1tmaij"
|
|
9912
|
+
}],
|
|
9913
|
+
["circle", {
|
|
9914
|
+
cx: "15",
|
|
9915
|
+
cy: "5",
|
|
9916
|
+
r: "1",
|
|
9917
|
+
key: "19l28e"
|
|
9918
|
+
}],
|
|
9919
|
+
["circle", {
|
|
9920
|
+
cx: "15",
|
|
9921
|
+
cy: "19",
|
|
9922
|
+
r: "1",
|
|
9923
|
+
key: "f4zoj3"
|
|
9924
|
+
}]
|
|
9925
|
+
]);
|
|
9926
|
+
/**
|
|
9927
|
+
* @license lucide-react v1.25.0 - ISC
|
|
9928
|
+
*
|
|
9929
|
+
* This source code is licensed under the ISC license.
|
|
9930
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
9931
|
+
*/
|
|
9932
|
+
var MicOff = createLucideIcon("mic-off", [
|
|
9933
|
+
["path", {
|
|
9934
|
+
d: "M12 19v3",
|
|
9935
|
+
key: "npa21l"
|
|
9936
|
+
}],
|
|
9937
|
+
["path", {
|
|
9938
|
+
d: "M15 9.34V5a3 3 0 0 0-5.68-1.33",
|
|
9939
|
+
key: "1gzdoj"
|
|
9940
|
+
}],
|
|
9941
|
+
["path", {
|
|
9942
|
+
d: "M16.95 16.95A7 7 0 0 1 5 12v-2",
|
|
9943
|
+
key: "cqa7eg"
|
|
9944
|
+
}],
|
|
9945
|
+
["path", {
|
|
9946
|
+
d: "M18.89 13.23A7 7 0 0 0 19 12v-2",
|
|
9947
|
+
key: "16hl24"
|
|
9948
|
+
}],
|
|
9949
|
+
["path", {
|
|
9950
|
+
d: "m2 2 20 20",
|
|
9951
|
+
key: "1ooewy"
|
|
9952
|
+
}],
|
|
9953
|
+
["path", {
|
|
9954
|
+
d: "M9 9v3a3 3 0 0 0 5.12 2.12",
|
|
9955
|
+
key: "r2i35w"
|
|
9956
|
+
}]
|
|
9957
|
+
]);
|
|
9958
|
+
/**
|
|
9959
|
+
* @license lucide-react v1.25.0 - ISC
|
|
9960
|
+
*
|
|
9961
|
+
* This source code is licensed under the ISC license.
|
|
9962
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
9963
|
+
*/
|
|
9964
|
+
var Mic = createLucideIcon("mic", [
|
|
9965
|
+
["path", {
|
|
9966
|
+
d: "M12 19v3",
|
|
9967
|
+
key: "npa21l"
|
|
9968
|
+
}],
|
|
9969
|
+
["path", {
|
|
9970
|
+
d: "M19 10v2a7 7 0 0 1-14 0v-2",
|
|
9971
|
+
key: "1vc78b"
|
|
9972
|
+
}],
|
|
9973
|
+
["rect", {
|
|
9974
|
+
x: "9",
|
|
9975
|
+
y: "2",
|
|
9976
|
+
width: "6",
|
|
9977
|
+
height: "13",
|
|
9978
|
+
rx: "3",
|
|
9979
|
+
key: "s6n7sd"
|
|
9980
|
+
}]
|
|
9981
|
+
]);
|
|
9982
|
+
/**
|
|
9983
|
+
* @license lucide-react v1.25.0 - ISC
|
|
9984
|
+
*
|
|
9985
|
+
* This source code is licensed under the ISC license.
|
|
9986
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
9987
|
+
*/
|
|
9988
|
+
var PhoneOff = createLucideIcon("phone-off", [
|
|
9989
|
+
["path", {
|
|
9990
|
+
d: "M10.1 13.9a14 14 0 0 0 3.732 2.668 1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2 18 18 0 0 1-12.728-5.272",
|
|
9991
|
+
key: "1wngk7"
|
|
9992
|
+
}],
|
|
9993
|
+
["path", {
|
|
9994
|
+
d: "M22 2 2 22",
|
|
9995
|
+
key: "y4kqgn"
|
|
9996
|
+
}],
|
|
9997
|
+
["path", {
|
|
9998
|
+
d: "M4.76 13.582A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 .244.473",
|
|
9999
|
+
key: "10hv5p"
|
|
10000
|
+
}]
|
|
10001
|
+
]);
|
|
10002
|
+
/**
|
|
10003
|
+
* @license lucide-react v1.25.0 - ISC
|
|
10004
|
+
*
|
|
10005
|
+
* This source code is licensed under the ISC license.
|
|
10006
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
10007
|
+
*/
|
|
10008
|
+
var Send = createLucideIcon("send", [["path", {
|
|
10009
|
+
d: "M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",
|
|
10010
|
+
key: "1ffxy3"
|
|
10011
|
+
}], ["path", {
|
|
10012
|
+
d: "m21.854 2.147-10.94 10.939",
|
|
10013
|
+
key: "12cjpa"
|
|
10014
|
+
}]]);
|
|
10015
|
+
/**
|
|
10016
|
+
* @license lucide-react v1.25.0 - ISC
|
|
10017
|
+
*
|
|
10018
|
+
* This source code is licensed under the ISC license.
|
|
10019
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
10020
|
+
*/
|
|
10021
|
+
var X = createLucideIcon("x", [["path", {
|
|
10022
|
+
d: "M18 6 6 18",
|
|
10023
|
+
key: "1bl5f8"
|
|
10024
|
+
}], ["path", {
|
|
10025
|
+
d: "m6 6 12 12",
|
|
10026
|
+
key: "d8bk6v"
|
|
10027
|
+
}]]);
|
|
10028
|
+
//#endregion
|
|
10029
|
+
//#region src/avatar-face.tsx
|
|
10030
|
+
function AvatarFace({ avatar, state, size, label, messageArrived, tightenKey }) {
|
|
10031
|
+
switch (avatar) {
|
|
10032
|
+
case "orb": return /* @__PURE__ */ jsx(BotFace, {
|
|
10033
|
+
state,
|
|
10034
|
+
size,
|
|
10035
|
+
label,
|
|
10036
|
+
messageArrived
|
|
10037
|
+
});
|
|
10038
|
+
case "knot": return /* @__PURE__ */ jsx(RopeKnot, {
|
|
10039
|
+
state,
|
|
10040
|
+
size,
|
|
10041
|
+
label,
|
|
10042
|
+
tightenKey
|
|
10043
|
+
});
|
|
10044
|
+
default: throw new Error(`Unhandled widget avatar: ${String(avatar)}`);
|
|
10045
|
+
}
|
|
10046
|
+
}
|
|
10047
|
+
//#endregion
|
|
10048
|
+
//#region src/widget/position.ts
|
|
10049
|
+
/**
|
|
10050
|
+
* Where the concierge sits on the host page, and how a visitor moves it.
|
|
10051
|
+
*
|
|
10052
|
+
* Six anchors, not four. The two centres exist because the launcher is a PILL
|
|
10053
|
+
* with a label on it now, not a round button: a wide control tucked into a
|
|
10054
|
+
* corner reads as an ad, and the middle of an edge is where a host page's own
|
|
10055
|
+
* content is least likely to be. The corners remain because they are where a
|
|
10056
|
+
* tenant with a fixed footer or a cookie bar needs it.
|
|
10057
|
+
*
|
|
10058
|
+
* The tenant picks the default in the widget config; a visitor may drag it
|
|
10059
|
+
* somewhere else, and where they put it is theirs — see `nearestPosition`.
|
|
10060
|
+
*/
|
|
10061
|
+
var CONCIERGE_POSITIONS = [
|
|
10062
|
+
"top-left",
|
|
10063
|
+
"top-center",
|
|
10064
|
+
"top-right",
|
|
10065
|
+
"bottom-left",
|
|
10066
|
+
"bottom-center",
|
|
10067
|
+
"bottom-right"
|
|
10068
|
+
];
|
|
10069
|
+
var DEFAULT_CONCIERGE_POSITION = "bottom-center";
|
|
10070
|
+
function edgeOf(position) {
|
|
10071
|
+
return position.startsWith("top") ? "top" : "bottom";
|
|
10072
|
+
}
|
|
10073
|
+
function alignOf(position) {
|
|
10074
|
+
if (position.endsWith("left")) return "left";
|
|
10075
|
+
if (position.endsWith("right")) return "right";
|
|
10076
|
+
return "center";
|
|
10077
|
+
}
|
|
10078
|
+
/**
|
|
10079
|
+
* The anchor a dropped widget should snap to.
|
|
10080
|
+
*
|
|
10081
|
+
* Thirds horizontally, halves vertically, measured on the widget's own CENTRE
|
|
10082
|
+
* rather than the pointer: a visitor drags the grip, which sits at one end of
|
|
10083
|
+
* the pill, and snapping on the pointer would send a pill they dropped dead
|
|
10084
|
+
* centre off to whichever side they happened to be holding.
|
|
10085
|
+
*
|
|
10086
|
+
* Pure arithmetic on numbers the caller measures, so it is testable without a
|
|
10087
|
+
* DOM and cannot disagree with itself across browsers.
|
|
10088
|
+
* @param centre the widget's centre point, in viewport pixels
|
|
10089
|
+
* @param viewport the viewport's size, in pixels
|
|
10090
|
+
*/
|
|
10091
|
+
function nearestPosition(centre, viewport) {
|
|
10092
|
+
const edge = centre.y < viewport.height / 2 ? "top" : "bottom";
|
|
10093
|
+
const third = viewport.width / 3;
|
|
10094
|
+
return `${edge}-${centre.x < third ? "left" : centre.x < third * 2 ? "center" : "right"}`;
|
|
10095
|
+
}
|
|
10096
|
+
/**
|
|
10097
|
+
* The anchor an arrow key moves to.
|
|
10098
|
+
*
|
|
10099
|
+
* The keyboard equivalent of dragging, and not a nicety: a pointer-only way to
|
|
10100
|
+
* move the widget is unusable for anyone who cannot drag, and the widget can
|
|
10101
|
+
* cover a host page's own controls. Left/right walk the three columns and stop
|
|
10102
|
+
* at the ends rather than wrapping — a control that jumps from one edge of the
|
|
10103
|
+
* screen to the other because a key was held is disorienting. Up/down flip the
|
|
10104
|
+
* edge.
|
|
10105
|
+
* @param position where it is now
|
|
10106
|
+
* @param key the arrow key pressed
|
|
10107
|
+
*/
|
|
10108
|
+
function positionForArrow(position, key) {
|
|
10109
|
+
const edge = edgeOf(position);
|
|
10110
|
+
const align = alignOf(position);
|
|
10111
|
+
if (key === "ArrowUp") return `top-${align}`;
|
|
10112
|
+
if (key === "ArrowDown") return `bottom-${align}`;
|
|
10113
|
+
const columns = [
|
|
10114
|
+
"left",
|
|
10115
|
+
"center",
|
|
10116
|
+
"right"
|
|
10117
|
+
];
|
|
10118
|
+
const next = columns.indexOf(align) + (key === "ArrowRight" ? 1 : -1);
|
|
10119
|
+
return `${edge}-${columns[Math.min(Math.max(next, 0), columns.length - 1)]}`;
|
|
10120
|
+
}
|
|
10121
|
+
/** Tailwind classes pinning a fixed element to one anchor. */
|
|
10122
|
+
function positionClasses(position) {
|
|
10123
|
+
return `${edgeOf(position) === "top" ? "top-4 sm:top-6" : "bottom-4 sm:bottom-6"} ${{
|
|
10124
|
+
left: "left-4 sm:left-6",
|
|
10125
|
+
center: "left-1/2 -translate-x-1/2",
|
|
10126
|
+
right: "right-4 sm:right-6"
|
|
10127
|
+
}[alignOf(position)]}`;
|
|
10128
|
+
}
|
|
10129
|
+
/**
|
|
10130
|
+
* How the open PANEL lines up under (or over) the launcher.
|
|
10131
|
+
*
|
|
10132
|
+
* The panel is much wider than the pill, so it cannot simply share the
|
|
10133
|
+
* launcher's anchor: pinned left it would still be pinned left, but pinned
|
|
10134
|
+
* centre it has to centre on the viewport rather than on the pill.
|
|
10135
|
+
*/
|
|
10136
|
+
function panelClasses(position) {
|
|
10137
|
+
return `${edgeOf(position) === "top" ? "top-4 sm:top-6" : "bottom-4 sm:bottom-6"} ${{
|
|
10138
|
+
left: "justify-start ps-4 sm:ps-6",
|
|
10139
|
+
center: "justify-center",
|
|
10140
|
+
right: "justify-end pe-4 sm:pe-6"
|
|
10141
|
+
}[alignOf(position)]}`;
|
|
10142
|
+
}
|
|
10143
|
+
//#endregion
|
|
10144
|
+
//#region src/widget/concierge-launcher.tsx
|
|
10145
|
+
function ConciergeLauncher({ label, srLabel, moveLabel, position, onPositionChange, onOpen, hidden, id, testId, avatar = "orb" }) {
|
|
10146
|
+
const rootRef = useRef(null);
|
|
10147
|
+
/** Pixel offset while a drag is in flight; `null` when it is not. */
|
|
10148
|
+
const [drag, setDrag] = useState(null);
|
|
10149
|
+
/**
|
|
10150
|
+
* Bumped on every press — `RopeKnot`'s click feedback (`rk-tighten` +
|
|
10151
|
+
* `rk-tap`), the same gesture the Lovable prototype's `RopeKnotTrigger`
|
|
10152
|
+
* wired directly into its own `onClick`. `BotFace` has no equivalent prop
|
|
10153
|
+
* and ignores an unused number, so this costs the orb nothing.
|
|
10154
|
+
*/
|
|
10155
|
+
const [tightenKey, setTightenKey] = useState(0);
|
|
10156
|
+
/**
|
|
10157
|
+
* Where the drag started: the pointer, and the pill's centre AT THAT MOMENT.
|
|
10158
|
+
*
|
|
10159
|
+
* The centre is captured on pointer-DOWN rather than measured on pointer-up,
|
|
10160
|
+
* because the pill's rendered box only moves once React has committed the
|
|
10161
|
+
* offset and the browser has painted it. Measuring it at the end made the
|
|
10162
|
+
* snap depend on paint timing: a fast drag — or any burst of pointer events
|
|
10163
|
+
* inside one task — landed the pill exactly where it started, since the box
|
|
10164
|
+
* had not moved yet. Pointer delta plus the starting centre is the same
|
|
10165
|
+
* arithmetic with none of that dependency.
|
|
10166
|
+
*/
|
|
10167
|
+
const origin = useRef(null);
|
|
10168
|
+
const endDrag = useCallback((clientX, clientY) => {
|
|
10169
|
+
const start = origin.current;
|
|
10170
|
+
origin.current = null;
|
|
10171
|
+
setDrag(null);
|
|
10172
|
+
if (!start || !onPositionChange) return;
|
|
10173
|
+
const next = nearestPosition({
|
|
10174
|
+
x: start.centre.x + (clientX - start.pointer.x),
|
|
10175
|
+
y: start.centre.y + (clientY - start.pointer.y)
|
|
10176
|
+
}, {
|
|
10177
|
+
width: window.innerWidth,
|
|
10178
|
+
height: window.innerHeight
|
|
10179
|
+
});
|
|
10180
|
+
if (next !== position) onPositionChange(next);
|
|
10181
|
+
}, [onPositionChange, position]);
|
|
10182
|
+
const onPointerDown = (event) => {
|
|
10183
|
+
if (!onPositionChange) return;
|
|
10184
|
+
try {
|
|
10185
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
10186
|
+
} catch {}
|
|
10187
|
+
const box = rootRef.current?.getBoundingClientRect();
|
|
10188
|
+
origin.current = {
|
|
10189
|
+
pointer: {
|
|
10190
|
+
x: event.clientX,
|
|
10191
|
+
y: event.clientY
|
|
10192
|
+
},
|
|
10193
|
+
centre: box ? {
|
|
10194
|
+
x: box.left + box.width / 2,
|
|
10195
|
+
y: box.top + box.height / 2
|
|
10196
|
+
} : {
|
|
10197
|
+
x: event.clientX,
|
|
10198
|
+
y: event.clientY
|
|
10199
|
+
}
|
|
10200
|
+
};
|
|
10201
|
+
setDrag({
|
|
10202
|
+
dx: 0,
|
|
10203
|
+
dy: 0
|
|
10204
|
+
});
|
|
10205
|
+
};
|
|
10206
|
+
const onPointerMove = (event) => {
|
|
10207
|
+
const start = origin.current;
|
|
10208
|
+
if (!start) return;
|
|
10209
|
+
setDrag({
|
|
10210
|
+
dx: event.clientX - start.pointer.x,
|
|
10211
|
+
dy: event.clientY - start.pointer.y
|
|
10212
|
+
});
|
|
10213
|
+
};
|
|
10214
|
+
const onPointerUp = (event) => {
|
|
10215
|
+
if (!origin.current) return;
|
|
10216
|
+
try {
|
|
10217
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
10218
|
+
} catch {}
|
|
10219
|
+
endDrag(event.clientX, event.clientY);
|
|
10220
|
+
};
|
|
10221
|
+
const onGripKeyDown = (event) => {
|
|
10222
|
+
if (!onPositionChange) return;
|
|
10223
|
+
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight" && event.key !== "ArrowUp" && event.key !== "ArrowDown") return;
|
|
10224
|
+
event.preventDefault();
|
|
10225
|
+
const next = positionForArrow(position, event.key);
|
|
10226
|
+
if (next !== position) onPositionChange(next);
|
|
10227
|
+
};
|
|
10228
|
+
const dragging = drag !== null;
|
|
10229
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
10230
|
+
ref: rootRef,
|
|
10231
|
+
id,
|
|
10232
|
+
"data-testid": testId,
|
|
10233
|
+
"data-position": position,
|
|
10234
|
+
"aria-hidden": hidden,
|
|
10235
|
+
className: cn("fixed z-50 flex items-center gap-1 rounded-full border border-white/40 bg-[var(--widget-card)] py-1.5 pe-4 ps-2 shadow-[0_12px_32px_-12px_color-mix(in_oklab,var(--brand-plum)_35%,transparent)] backdrop-blur-xl", positionClasses(position), dragging ? "cursor-grabbing" : "transition-[opacity,scale] duration-300 ease-out", hidden ? "pointer-events-none scale-75 opacity-0" : "pointer-events-auto opacity-100"),
|
|
10236
|
+
style: drag ? { transform: `translate(${drag.dx}px, ${drag.dy}px)` } : void 0,
|
|
10237
|
+
children: [onPositionChange ? /* @__PURE__ */ jsx("button", {
|
|
10238
|
+
type: "button",
|
|
10239
|
+
"aria-label": moveLabel,
|
|
10240
|
+
title: moveLabel,
|
|
10241
|
+
tabIndex: hidden ? -1 : 0,
|
|
10242
|
+
"data-testid": testId ? `${testId}-grip` : void 0,
|
|
10243
|
+
onPointerDown,
|
|
10244
|
+
onPointerMove,
|
|
10245
|
+
onPointerUp,
|
|
10246
|
+
onPointerCancel: onPointerUp,
|
|
10247
|
+
onKeyDown: onGripKeyDown,
|
|
10248
|
+
className: cn("touch-none rounded-full p-1 text-[var(--widget-foreground-muted)] transition-colors", "hover:bg-brand-plum/10 hover:text-brand-plum focus-visible:ring-brand-plum/30 focus-visible:ring-2 focus-visible:outline-none", dragging ? "cursor-grabbing" : "cursor-grab"),
|
|
10249
|
+
children: /* @__PURE__ */ jsx(GripVertical, {
|
|
10250
|
+
className: "size-4",
|
|
10251
|
+
"aria-hidden": true
|
|
10252
|
+
})
|
|
10253
|
+
}) : null, /* @__PURE__ */ jsxs("button", {
|
|
10254
|
+
type: "button",
|
|
10255
|
+
"aria-label": label === void 0 ? srLabel : void 0,
|
|
10256
|
+
tabIndex: hidden ? -1 : 0,
|
|
10257
|
+
onClick: () => {
|
|
10258
|
+
setTightenKey((k) => k + 1);
|
|
10259
|
+
onOpen();
|
|
10260
|
+
},
|
|
10261
|
+
"data-testid": testId ? `${testId}-open` : void 0,
|
|
10262
|
+
className: "flex items-center gap-2.5 rounded-full focus-visible:ring-brand-plum/30 focus-visible:ring-2 focus-visible:outline-none",
|
|
10263
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
10264
|
+
"aria-hidden": true,
|
|
10265
|
+
className: "relative block size-12 shrink-0",
|
|
10266
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
10267
|
+
className: "absolute start-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 scale-[0.75] rtl:translate-x-1/2",
|
|
10268
|
+
children: /* @__PURE__ */ jsx(AvatarFace, {
|
|
10269
|
+
avatar,
|
|
10270
|
+
state: "idle",
|
|
10271
|
+
size: "sm",
|
|
10272
|
+
tightenKey
|
|
10273
|
+
})
|
|
10274
|
+
})
|
|
10275
|
+
}), label === void 0 ? null : /* @__PURE__ */ jsx("span", {
|
|
10276
|
+
dir: "auto",
|
|
10277
|
+
className: "max-w-[14rem] truncate text-sm font-medium text-[var(--widget-foreground)]",
|
|
10278
|
+
children: label
|
|
10279
|
+
})]
|
|
10280
|
+
})]
|
|
10281
|
+
});
|
|
10282
|
+
}
|
|
10283
|
+
//#endregion
|
|
10284
|
+
//#region src/widget/transcript-geometry.ts
|
|
10285
|
+
/**
|
|
10286
|
+
* PANEL GEOMETRY — where the conversation's first row sits, as a FRACTION of
|
|
10287
|
+
* the panel's height, and what that costs horizontally.
|
|
10288
|
+
*
|
|
10289
|
+
* Four CSS length expressions and the arithmetic behind them, used by
|
|
10290
|
+
* `concierge-shell.tsx`'s `transcriptEdgeFade`. Their own module, and NOT
|
|
10291
|
+
* re-exported from `index.ts`: `concierge-shell.geometry.test.tsx` has to read
|
|
10292
|
+
* the exact strings the component ships (jsdom's CSS serializer mangles a
|
|
10293
|
+
* `max()` containing a subtraction, so reading them back off a rendered element
|
|
10294
|
+
* tests jsdom rather than this widget), while the package's public API stays
|
|
10295
|
+
* the components themselves.
|
|
10296
|
+
*
|
|
10297
|
+
* One ratio ties the four lengths together, and it is the whole
|
|
10298
|
+
* repair for a bug that shipped: the panel is an ellipse (`rounded-full` on a
|
|
10299
|
+
* `w x 1.6w` box), so how much width it offers depends entirely on how far down
|
|
10300
|
+
* you are. The clearances below scaled with `cqh` while the transcript's
|
|
10301
|
+
* horizontal inset was a fixed 8px tuned for the oval's wide middle, so the
|
|
10302
|
+
* taller the panel got the HIGHER the first message sat proportionally — into a
|
|
10303
|
+
* narrower part of the curve, with no matching inset. Measured live in
|
|
10304
|
+
* Storybook, first agent bubble's top-left corner against the curve at its own
|
|
10305
|
+
* top edge: 14px inside the ellipse at a 582px panel, 37px at 720px, 62px at
|
|
10306
|
+
* 920px (the 2000x1150 desktop it was reported on). `overflow-clip` on the
|
|
10307
|
+
* surface then cut exactly that much off the bubble.
|
|
10308
|
+
*
|
|
10309
|
+
* 0.1924 is not chosen, it is READ OFF the short panel: 112px (the tuned
|
|
10310
|
+
* clearance, see {@link TRANSCRIPT_FADE_TOP_LEN}) over 582px (the panel a
|
|
10311
|
+
* 375x812 phone renders) is 0.19244. Holding that ratio at every size is what
|
|
10312
|
+
* makes the geometry scale-invariant — every panel then presents the first row
|
|
10313
|
+
* at the same point on the same curve, and ONE horizontal inset serves all of
|
|
10314
|
+
* them ({@link TRANSCRIPT_INSET_X}). Expressed as `19.24cqh` in the lengths
|
|
10315
|
+
* below; `cqh` is the panel's own height, via `[container-type:size]` on the
|
|
10316
|
+
* panel div (verified live: `14cqh` resolved to 128.8px on a 920px panel).
|
|
10317
|
+
*
|
|
10318
|
+
* Not a JS constant that gets multiplied out — the panel's height is never
|
|
10319
|
+
* known to JS, only to CSS, which is why every length here is an expression.
|
|
10320
|
+
*/
|
|
10321
|
+
/**
|
|
10322
|
+
* Top ramp when the transcript starts at the panel's top, under the floating
|
|
10323
|
+
* orb — it has to span the orb, so a message is gone before it reaches it
|
|
10324
|
+
* rather than sliding out from behind it half-visible.
|
|
10325
|
+
*
|
|
10326
|
+
* A CSS length EXPRESSION, not a bare number, since the aspect-ratio panel
|
|
10327
|
+
* (`w-[min(97vw,50dvh)]` + `aspect-[5/8]`) ranges from ~582px tall (mobile,
|
|
10328
|
+
* width-bound) to 800px+ (desktop, height-bound) — a fixed 112px clearance
|
|
10329
|
+
* tuned for the OLD fixed-520px panel left too little air under the orb on a
|
|
10330
|
+
* tall one and too much on a short one. `max(112px, 19.24cqh)` is a floor, not
|
|
10331
|
+
* a fixed value: it stays exactly 112px (today's tuned figure) on a short
|
|
10332
|
+
* panel, where 19.24cqh would fall below it, and grows with `cqh` — the query
|
|
10333
|
+
* container's own height, established by `[container-type:size]` on the
|
|
10334
|
+
* panel div below — once the panel is tall enough that 19.24% of it exceeds
|
|
10335
|
+
* 112px. `cqh` rather than `dvh` specifically: the panel's real rendered
|
|
10336
|
+
* height, not the viewport's, since the panel does not always fill the
|
|
10337
|
+
* viewport (mobile: width-bound, height is `w / (8/5)`, shorter than 100dvh).
|
|
10338
|
+
*
|
|
10339
|
+
* 19.24, not the 14 this shipped with: 14cqh gave a TALL panel proportionally
|
|
10340
|
+
* LESS clearance than the 112px floor gives a short one (14% against 19.24%),
|
|
10341
|
+
* which pushed the first message up into the narrowing part of the ellipse —
|
|
10342
|
+
* see the ratio's own note above for the measurements. The floor and the
|
|
10343
|
+
* scaling term now agree at 582px (19.24% of 582 = 111.98), so the two meet
|
|
10344
|
+
* without a step rather than crossing over at some unrelated height.
|
|
10345
|
+
*/
|
|
10346
|
+
var TRANSCRIPT_FADE_TOP_LEN = "max(112px, 19.24cqh)";
|
|
10347
|
+
/**
|
|
10348
|
+
* Top ramp when a `badge` sits above the transcript.
|
|
10349
|
+
*
|
|
10350
|
+
* A badge has ALREADY pushed the transcript clear of the orb, so reusing the
|
|
10351
|
+
* orb-sized ramp charges for the same clearance twice: it left a 112px dead
|
|
10352
|
+
* band directly under the badge and dissolved the opening message for no
|
|
10353
|
+
* reason (measured in `WithABadgeAndNoVoice` — orb ends 565, badge 573-598,
|
|
10354
|
+
* first message could not start above 710). At that point the fade is only
|
|
10355
|
+
* doing its ordinary job of softening a scroll edge, so it wants an ordinary
|
|
10356
|
+
* scroll-edge length. Same floor+`cqh` scheme as {@link TRANSCRIPT_FADE_TOP_LEN}
|
|
10357
|
+
* above and for the same reason — this ramp needs to soften proportionally
|
|
10358
|
+
* more of a tall panel's scroll edge than a short one's.
|
|
10359
|
+
*
|
|
10360
|
+
* The third arm is the ellipse, and it is what keeps this variant honest at
|
|
10361
|
+
* sizes the badge's own fixed offsets stop covering. With a badge the first row
|
|
10362
|
+
* is pushed down by chrome that does NOT scale — 1px surface border + 6px
|
|
10363
|
+
* column padding + the badge wrapper's `mt-[104px]` + 4px list padding = 115px
|
|
10364
|
+
* — so the row lands at `(115px + this ramp) / panelHeight`, a fraction that
|
|
10365
|
+
* SHRINKS as the panel grows. `19.24cqh - 115px` is that equation solved for
|
|
10366
|
+
* the ramp, so the row lands on the same point of the curve the no-badge
|
|
10367
|
+
* variant does. It is inert on the panels this variant was tuned against
|
|
10368
|
+
* (negative at 582px, 4.5px at 720px, so the other two arms win) and takes over
|
|
10369
|
+
* only above ~745px, where the fixed 115px has stopped being enough.
|
|
10370
|
+
*
|
|
10371
|
+
* The badge's own height is counted as ZERO in that 115px, deliberately:
|
|
10372
|
+
* `badge` is an arbitrary node from the host (`voice-widget.tsx` passes a
|
|
10373
|
+
* one-line status pill, ~26px), and only the shortest-badge bound holds for
|
|
10374
|
+
* every caller. A taller badge pushes the row further down, which is the safe
|
|
10375
|
+
* direction.
|
|
10376
|
+
*/
|
|
10377
|
+
var TRANSCRIPT_FADE_TOP_WITH_BADGE_LEN = "max(28px, 4cqh, 19.24cqh - 115px)";
|
|
10378
|
+
var TRANSCRIPT_FADE_BOTTOM_LEN = "max(118px, 20.27cqh)";
|
|
10379
|
+
/**
|
|
10380
|
+
* The transcript's horizontal inset — the width the ellipse actually costs.
|
|
10381
|
+
*
|
|
10382
|
+
* `10.6cqw` is where the curve is at the first row's height: on an ellipse of
|
|
10383
|
+
* width `w`, at the fraction 0.1924 of the way down (the ratio the clearances
|
|
10384
|
+
* above hold at every size), the left edge lies `w * (1 - sqrt(1 - (2*0.1924 -
|
|
10385
|
+
* 1)^2)) / 2` = `0.1058 * w` in from the bounding box. Rounded up to 10.6% so
|
|
10386
|
+
* the rounding goes toward clearance rather than away from it.
|
|
10387
|
+
*
|
|
10388
|
+
* `- 11px` because 11px of that is already paid for by fixed chrome outside
|
|
10389
|
+
* this element: the surface's 1px border plus the inner column's `px-2.5`. The
|
|
10390
|
+
* inset is measured from the PANEL's box, which is where the curve is; this
|
|
10391
|
+
* padding only has to make up the difference. Verified live: a 363.8px-wide
|
|
10392
|
+
* panel put the first bubble's left edge at 19px = 11px chrome + the 8px this
|
|
10393
|
+
* replaces.
|
|
10394
|
+
*
|
|
10395
|
+
* The `8px` floor is the value this shipped with, kept as a lower bound so a
|
|
10396
|
+
* degenerately small panel can never end up with less padding than a plain
|
|
10397
|
+
* scroll edge wants. It is inert at every real size (the formula gives 27.6px
|
|
10398
|
+
* on the smallest panel the widget renders).
|
|
10399
|
+
*
|
|
10400
|
+
* Symmetric on purpose, and applied as `padding-inline` so it stays symmetric
|
|
10401
|
+
* in RTL: the ellipse is symmetric, the visitor's own bubbles are `justify-end`
|
|
10402
|
+
* against the other side of it, and either side is the first row's side
|
|
10403
|
+
* depending on who spoke.
|
|
10404
|
+
*/
|
|
10405
|
+
var TRANSCRIPT_INSET_X = "max(8px, 10.6cqw - 11px)";
|
|
10406
|
+
/**
|
|
10407
|
+
* The composer overlay's bottom offset when the microphone is drawn.
|
|
10408
|
+
*
|
|
10409
|
+
* `11.86cqh` is {@link COMPOSER_ROW_FRACTION} as a length. `- 63px` is
|
|
10410
|
+
* everything between this offset and the input's bottom edge that does NOT
|
|
10411
|
+
* scale: the surface's 1px border (the overlay is positioned against the inner
|
|
10412
|
+
* column's padding box, one border inside the panel) plus the 62px microphone
|
|
10413
|
+
* block — a 10px `gap-2.5`, the row's 4px `mt-1`, and a 48px `size-12` button.
|
|
10414
|
+
*
|
|
10415
|
+
* `max(6px, …)` keeps the 6px this shipped with as a floor, and the two arms
|
|
10416
|
+
* MEET at the panel it was tuned on rather than crossing somewhere unrelated:
|
|
10417
|
+
* `11.86cqh - 63px` is 6.03px at 582px, so a phone renders what it rendered
|
|
10418
|
+
* before to a hundredth of a pixel and only larger panels lift the composer.
|
|
10419
|
+
*/
|
|
10420
|
+
var COMPOSER_BOTTOM_LEN = "max(6px, 11.86cqh - 63px)";
|
|
10421
|
+
/**
|
|
10422
|
+
* The composer overlay's bottom offset when there is NO microphone.
|
|
10423
|
+
*
|
|
10424
|
+
* Same target row, minus only the 1px surface border: with `voice` omitted the
|
|
10425
|
+
* overlay's last child IS the input, so the 62px the microphone block
|
|
10426
|
+
* contributed above has to come from this offset instead. That is a real move —
|
|
10427
|
+
* 6px to 68px on a phone — and it is the fix rather than a side effect. Left at
|
|
10428
|
+
* 6px the input sits 7px off a `rounded-full` panel's bottom tip, where the
|
|
10429
|
+
* ellipse offers 79px of width in total; no width cap can rescue that row, so
|
|
10430
|
+
* the row itself has to come up to where the panel is wide enough to hold it.
|
|
10431
|
+
*
|
|
10432
|
+
* The band it moves into is the one the microphone would have occupied, which
|
|
10433
|
+
* the transcript already clears ({@link TRANSCRIPT_FADE_BOTTOM_LEN} is sized
|
|
10434
|
+
* for the input + microphone pair regardless of whether the pair is drawn), so
|
|
10435
|
+
* nothing above has to move to make room.
|
|
10436
|
+
*/
|
|
10437
|
+
var COMPOSER_BOTTOM_NO_VOICE_LEN = "max(6px, 11.86cqh - 1px)";
|
|
10438
|
+
/**
|
|
10439
|
+
* The composer's width cap — what the ellipse actually offers at that row.
|
|
10440
|
+
*
|
|
10441
|
+
* On an ellipse of width `w`, at the fraction `1 - 0.1186` of the way down, the
|
|
10442
|
+
* full chord is `w * sqrt(1 - (2*0.8814 - 1)^2)` = `0.6465 * w`. So `64.65cqw`
|
|
10443
|
+
* is not a taste-tuned percentage, it is the panel's own width at the row the
|
|
10444
|
+
* two offsets above pin the input to — where `w-[71%]`, the class this caps,
|
|
10445
|
+
* was 6.4% of the panel too wide at EVERY size (10.8px of overhang on a phone,
|
|
10446
|
+
* 52.0px on a 920px panel, because the row also drifts lower as the panel
|
|
10447
|
+
* grows).
|
|
10448
|
+
*
|
|
10449
|
+
* `- 10px` is clearance, 5px each side, matching the 5px the transcript's rows
|
|
10450
|
+
* clear the curve by — the panel paints a 1.5px gradient ring plus a 1px
|
|
10451
|
+
* surface border at that edge, and the input's own rounding means the arc, not
|
|
10452
|
+
* the corner, is what approaches the curve.
|
|
10453
|
+
*
|
|
10454
|
+
* Applied as `max-width` over the existing `w-[71%]`, not in place of it: 71%
|
|
10455
|
+
* stays the upper bound the composer had, and this only ever tightens it (the
|
|
10456
|
+
* ellipse term is below 71% for any panel, since 0.6465 < 0.71). The `160px`
|
|
10457
|
+
* floor is the "cap it sensibly" arm — it stops a degenerately small panel from
|
|
10458
|
+
* resolving the composer to a few dozen pixels of unusable input, and it is
|
|
10459
|
+
* inert at every size the widget really renders (it binds only below a 248px
|
|
10460
|
+
* panel; the narrowest phone in circulation, 320px, gives 310px).
|
|
10461
|
+
*/
|
|
10462
|
+
var COMPOSER_MAX_WIDTH_LEN = "max(160px, 64.65cqw - 10px)";
|
|
10463
|
+
/**
|
|
10464
|
+
* The opaque ground the composer sits on, which has to keep covering it.
|
|
10465
|
+
*
|
|
10466
|
+
* The transcript runs the panel's whole height and passes BEHIND this row, so
|
|
10467
|
+
* this gradient is the only thing between a message and the input's own
|
|
10468
|
+
* translucent chip fill. It was a fixed `h-[132px]`, tuned when the composer
|
|
10469
|
+
* was pinned 6px off the bottom on every panel — and the moment the offsets
|
|
10470
|
+
* above start lifting the composer on a tall panel, a fixed ground stops
|
|
10471
|
+
* reaching its top edge (the composer's top is `11.86cqh + 40px` above the
|
|
10472
|
+
* panel's bottom: 109px at 582px, but 149px at 920px, against 132px of ground).
|
|
10473
|
+
*
|
|
10474
|
+
* 22.68cqh is the same read-off-the-short-panel derivation as everything else
|
|
10475
|
+
* here — 132/582 = 0.22680 — so a phone renders exactly the 132px it rendered
|
|
10476
|
+
* before and the ground grows with the row it is under. It stays above the
|
|
10477
|
+
* composer's own top at every size, and stays the same shade taller than the
|
|
10478
|
+
* transcript's bottom clearance that it is today ({@link
|
|
10479
|
+
* TRANSCRIPT_FADE_BOTTOM_LEN} is 20.27cqh against this 22.68cqh, exactly the
|
|
10480
|
+
* 118:132 relationship the two were tuned at), so they still meet without a
|
|
10481
|
+
* seam or a band of doubly-darkened panel.
|
|
10482
|
+
*/
|
|
10483
|
+
var COMPOSER_GROUND_LEN = "max(132px, 22.68cqh)";
|
|
10484
|
+
//#endregion
|
|
10485
|
+
//#region src/widget/concierge-shell.tsx
|
|
10486
|
+
/**
|
|
10487
|
+
* How far off the bottom still counts as "following the conversation".
|
|
10488
|
+
*
|
|
10489
|
+
* Not zero: fractional scroll metrics on zoomed and hi-dpi displays never
|
|
10490
|
+
* land exactly on the bottom, and a smooth scroll is still in flight when the
|
|
10491
|
+
* next streamed token resizes the content. Both would read as the visitor
|
|
10492
|
+
* having deliberately scrolled up, and stop the transcript following.
|
|
10493
|
+
*/
|
|
10494
|
+
var FOLLOW_TOLERANCE_PX = 24;
|
|
10495
|
+
/**
|
|
10496
|
+
* Build the transcript's mask + the padding that matches it.
|
|
10497
|
+
*
|
|
10498
|
+
* The two must be derived together: the padding is what lets the first and
|
|
10499
|
+
* last messages scroll clear of the ramp, so a ramp length that is not also
|
|
10500
|
+
* the padding leaves the newest message permanently half-dissolved.
|
|
10501
|
+
*
|
|
10502
|
+
* The top ramp's stops are scaled from `topLen` rather than hardcoded, so the
|
|
10503
|
+
* shortened badge variant keeps the same eased shape instead of becoming a
|
|
10504
|
+
* steep two-point cut. `topLen` is a CSS length EXPRESSION now (a `max(<px>,
|
|
10505
|
+
* <N>cqh)` floor, see the constants above), not a plain number — `at(fraction)`
|
|
10506
|
+
* therefore emits `calc(<topLen> * <fraction>)` rather than doing the
|
|
10507
|
+
* multiplication in JS, so each stop scales with the query container's
|
|
10508
|
+
* height (`cqh`) exactly the way `topLen` itself does. `calc()` accepts a
|
|
10509
|
+
* `max()` expression as its left operand (`max()` resolves to a `<length>`,
|
|
10510
|
+
* and a `<length>` may be multiplied by a bare `<number>` inside `calc()`),
|
|
10511
|
+
* so this composes without a second unit-handling special case.
|
|
10512
|
+
*
|
|
10513
|
+
* The bottom ramp's own inner taper (the last four stops, `96px`/`72px`/
|
|
10514
|
+
* `48px`/`24px`) stays fixed pixels, deliberately NOT scaled by `cqh`: it is
|
|
10515
|
+
* a small, fixed-shape cosmetic fade against the very bottom edge, sized
|
|
10516
|
+
* once and unrelated to how much CLEARANCE the composer needs above it —
|
|
10517
|
+
* that clearance is what `TRANSCRIPT_FADE_BOTTOM_LEN` (the transition point
|
|
10518
|
+
* this taper starts from, and the padding below) controls, and that is what
|
|
10519
|
+
* scales.
|
|
10520
|
+
*
|
|
10521
|
+
* The horizontal inset rides along here rather than staying a `px-2` class for
|
|
10522
|
+
* the same reason the vertical padding does: it is derived from `topLen` — the
|
|
10523
|
+
* curve is only knowable once you know how far down the first row starts (see
|
|
10524
|
+
* {@link TRANSCRIPT_INSET_X}) — and splitting a derived pair across a class and
|
|
10525
|
+
* a style object is exactly how the two drift apart.
|
|
10526
|
+
*/
|
|
10527
|
+
function transcriptEdgeFade(topLen) {
|
|
10528
|
+
const at = (fraction) => `calc(${topLen} * ${fraction})`;
|
|
10529
|
+
const gradient = `linear-gradient(to bottom, ${[
|
|
10530
|
+
"transparent 0",
|
|
10531
|
+
`rgba(0,0,0,0.06) ${at(.21)}`,
|
|
10532
|
+
`rgba(0,0,0,0.20) ${at(.43)}`,
|
|
10533
|
+
`rgba(0,0,0,0.45) ${at(.64)}`,
|
|
10534
|
+
`rgba(0,0,0,0.75) ${at(.82)}`,
|
|
10535
|
+
`#000 ${topLen}`,
|
|
10536
|
+
`#000 calc(100% - ${TRANSCRIPT_FADE_BOTTOM_LEN})`,
|
|
10537
|
+
"rgba(0,0,0,0.86) calc(100% - 96px)",
|
|
10538
|
+
"rgba(0,0,0,0.60) calc(100% - 72px)",
|
|
10539
|
+
"rgba(0,0,0,0.32) calc(100% - 48px)",
|
|
10540
|
+
"rgba(0,0,0,0.10) calc(100% - 24px)",
|
|
10541
|
+
"transparent 100%"
|
|
10542
|
+
].join(", ")})`;
|
|
10543
|
+
return {
|
|
10544
|
+
maskImage: gradient,
|
|
10545
|
+
WebkitMaskImage: gradient,
|
|
10546
|
+
paddingTop: topLen,
|
|
10547
|
+
paddingBottom: TRANSCRIPT_FADE_BOTTOM_LEN,
|
|
10548
|
+
paddingInline: TRANSCRIPT_INSET_X
|
|
10549
|
+
};
|
|
10550
|
+
}
|
|
10551
|
+
/** Both variants built once — neither depends on props beyond badge presence. */
|
|
10552
|
+
var TRANSCRIPT_EDGE_FADE = transcriptEdgeFade(TRANSCRIPT_FADE_TOP_LEN);
|
|
10553
|
+
var TRANSCRIPT_EDGE_FADE_WITH_BADGE = transcriptEdgeFade(TRANSCRIPT_FADE_TOP_WITH_BADGE_LEN);
|
|
10554
|
+
/**
|
|
10555
|
+
* Maps the call onto the pill it shows, reusing fields `ConciergeShellVoice`
|
|
10556
|
+
* already carries rather than inventing new plumbing:
|
|
10557
|
+
*
|
|
10558
|
+
* - `'connecting'` → `connecting`
|
|
10559
|
+
* - `'waiting'` (the agent is thinking, between the caller's turn ending and
|
|
10560
|
+
* the reply starting) → `thinking`
|
|
10561
|
+
* - `'live'` + `agentSpeaking` → `speaking`
|
|
10562
|
+
* - `'live'` otherwise → `listening`
|
|
10563
|
+
* - `'idle'` / `'blocked'` → `null`, no pill
|
|
10564
|
+
*
|
|
10565
|
+
* `agentSpeaking` is already a real field on {@link ConciergeShellVoice} —
|
|
10566
|
+
* this function only reads it, it does not require every caller to start
|
|
10567
|
+
* setting it; a caller that never populates it simply never reaches
|
|
10568
|
+
* `'speaking'`, which is exactly the same "renders sensibly with what it is
|
|
10569
|
+
* given" contract every other optional field on this interface follows.
|
|
10570
|
+
*/
|
|
10571
|
+
function voiceStatePillState(voice) {
|
|
10572
|
+
if (!voice) return null;
|
|
10573
|
+
switch (voice.phase) {
|
|
10574
|
+
case "connecting": return "connecting";
|
|
10575
|
+
case "waiting": return "thinking";
|
|
10576
|
+
case "live": return voice.agentSpeaking ? "speaking" : "listening";
|
|
10577
|
+
default: return null;
|
|
10578
|
+
}
|
|
10579
|
+
}
|
|
10580
|
+
/**
|
|
10581
|
+
* The label a pill state shows, falling back to the package's brand-neutral
|
|
10582
|
+
* English word (`defaultWidgetMessages`) when the host's own `labels` omit
|
|
10583
|
+
* it — the same "an existing caller renders sensibly without changes"
|
|
10584
|
+
* contract every field added to `ConciergeShellVoice.labels` after 0.2.0
|
|
10585
|
+
* follows.
|
|
10586
|
+
*/
|
|
10587
|
+
function voiceStatePillLabel(pillState, labels) {
|
|
10588
|
+
switch (pillState) {
|
|
10589
|
+
case "connecting": return labels?.connecting ?? defaultWidgetMessages.voice_state_connecting;
|
|
10590
|
+
case "listening": return labels?.listening ?? defaultWidgetMessages.voice_state_listening;
|
|
10591
|
+
case "thinking": return labels?.thinking ?? defaultWidgetMessages.voice_state_thinking;
|
|
10592
|
+
case "speaking": return labels?.speaking ?? defaultWidgetMessages.voice_state_speaking;
|
|
10593
|
+
}
|
|
10594
|
+
}
|
|
10595
|
+
/**
|
|
10596
|
+
* The leading dot's colour, in brand tokens — never a literal, so it follows
|
|
10597
|
+
* `skinStyle` when a tenant publishes their own brand colours, the same
|
|
10598
|
+
* reasoning every other brand-coloured glow in this file already states.
|
|
10599
|
+
* `listening` and `speaking` share `--brand-rose`: both are "the room is
|
|
10600
|
+
* live" states from the caller's point of view (a caller talking and an
|
|
10601
|
+
* agent talking back both read as "the call is active"), where
|
|
10602
|
+
* `connecting`/`thinking` are the two states with genuinely nothing to
|
|
10603
|
+
* listen to yet.
|
|
10604
|
+
*/
|
|
10605
|
+
function voiceStatePillDotColor(pillState) {
|
|
10606
|
+
switch (pillState) {
|
|
10607
|
+
case "connecting": return "var(--brand-amber)";
|
|
10608
|
+
case "thinking": return "var(--brand-plum)";
|
|
10609
|
+
case "listening":
|
|
10610
|
+
case "speaking": return "var(--brand-rose)";
|
|
10611
|
+
}
|
|
10612
|
+
}
|
|
10613
|
+
/** How long the opening flourish runs. Matches `.widget-portal`'s own duration. */
|
|
10614
|
+
var PORTAL_MS = 720;
|
|
10615
|
+
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 }) {
|
|
10616
|
+
const triggerId = `${idPrefix}-trigger`;
|
|
10617
|
+
const inputId = `${idPrefix}-input`;
|
|
10618
|
+
const [portalActive, setPortalActive] = useState(false);
|
|
10619
|
+
const panelRef = useRef(null);
|
|
10620
|
+
const transcriptRef = useRef(null);
|
|
10621
|
+
/** The transcript's content box — what grows as a reply streams in. */
|
|
10622
|
+
const transcriptContentRef = useRef(null);
|
|
10623
|
+
useEffect(() => {
|
|
10624
|
+
if (!open) return;
|
|
10625
|
+
setPortalActive(true);
|
|
10626
|
+
const id = window.setTimeout(() => setPortalActive(false), PORTAL_MS);
|
|
10627
|
+
return () => window.clearTimeout(id);
|
|
10628
|
+
}, [open]);
|
|
10629
|
+
/**
|
|
10630
|
+
* The knot's equivalent of the orb's `bot-nod` flourish — `BotFace` fires
|
|
10631
|
+
* `messageArrived` off `className` presence alone (a CSS animation restarts
|
|
10632
|
+
* whenever a class newly APPLIES), which works because `messageArrived`
|
|
10633
|
+
* itself is a derived, level-triggered boolean ("was the last turn from the
|
|
10634
|
+
* caller") that a component only needs to read once per render. `RopeKnot`'s
|
|
10635
|
+
* tighten/tap flourish is EDGE-triggered instead — it plays once per bump of
|
|
10636
|
+
* `tightenKey`, the exact vehicle a launcher press already uses
|
|
10637
|
+
* (`concierge-launcher.tsx`) — so this only bumps it on the RISING edge
|
|
10638
|
+
* (`false` → `true`), not on every render where `messageArrived` merely
|
|
10639
|
+
* stays `true` (e.g. while the agent is still thinking about the same
|
|
10640
|
+
* caller turn).
|
|
10641
|
+
*/
|
|
10642
|
+
const wasMessageArrived = useRef(false);
|
|
10643
|
+
const [knotTightenKey, setKnotTightenKey] = useState(0);
|
|
10644
|
+
useEffect(() => {
|
|
10645
|
+
if (messageArrived && !wasMessageArrived.current) setKnotTightenKey((k) => k + 1);
|
|
10646
|
+
wasMessageArrived.current = messageArrived;
|
|
10647
|
+
}, [messageArrived]);
|
|
10648
|
+
/**
|
|
10649
|
+
* Whether the transcript is following the conversation.
|
|
10650
|
+
*
|
|
10651
|
+
* True while the visitor is at (or near) the bottom, false the moment they
|
|
10652
|
+
* scroll up to re-read something — see the observer below for why the
|
|
10653
|
+
* distinction has to exist rather than always scrolling.
|
|
10654
|
+
*/
|
|
10655
|
+
const following = useRef(true);
|
|
10656
|
+
useEffect(() => {
|
|
10657
|
+
const el = transcriptRef.current;
|
|
10658
|
+
if (typeof el?.scrollTo !== "function") return;
|
|
10659
|
+
following.current = true;
|
|
10660
|
+
el.scrollTo({
|
|
10661
|
+
top: el.scrollHeight,
|
|
10662
|
+
behavior: "smooth"
|
|
10663
|
+
});
|
|
10664
|
+
}, [scrollKey, state]);
|
|
10665
|
+
/**
|
|
10666
|
+
* Follow the reply as it STREAMS, not just as it starts.
|
|
10667
|
+
*
|
|
10668
|
+
* `scrollKey` is `turns.length` (`voice-widget.tsx`), so the effect above
|
|
10669
|
+
* fires once, when the agent's turn is appended and still empty or one
|
|
10670
|
+
* token long. Everything after that arrives by SSE into the SAME turn: the
|
|
10671
|
+
* bubble grows downward under a scroll position that was correct when it
|
|
10672
|
+
* was pinned and is stale a word later. The visitor watched the TOP of a
|
|
10673
|
+
* long answer and had to scroll for every line of it — the newest text, the
|
|
10674
|
+
* only part they had not read, was the part off-screen.
|
|
10675
|
+
*
|
|
10676
|
+
* A `ResizeObserver` on the content is what closes that gap: it fires on
|
|
10677
|
+
* every layout change the growing text produces, at whatever rate the
|
|
10678
|
+
* tokens land, with no polling and no dependency on how the host chooses to
|
|
10679
|
+
* stream. `scrollKey` still owns the jump to a NEW turn; this owns staying
|
|
10680
|
+
* there while that turn fills in.
|
|
10681
|
+
*
|
|
10682
|
+
* Gated on `following` so it never fights the visitor. Scrolling up to
|
|
10683
|
+
* re-read an earlier answer while the agent is still typing is an ordinary
|
|
10684
|
+
* thing to do, and a transcript that yanks itself back down every 50ms
|
|
10685
|
+
* makes it impossible. `atBottom` uses a tolerance rather than an equality
|
|
10686
|
+
* — fractional scroll metrics on zoomed or hi-dpi displays never land
|
|
10687
|
+
* exactly, and smooth scrolling is still in flight when the next resize
|
|
10688
|
+
* arrives.
|
|
10689
|
+
*
|
|
10690
|
+
* `behavior: 'auto'`, unlike the jump above: a smooth scroll started every
|
|
10691
|
+
* time a token lands never finishes before the next one restarts it, which
|
|
10692
|
+
* reads as the transcript lagging behind its own text.
|
|
10693
|
+
*/
|
|
10694
|
+
useEffect(() => {
|
|
10695
|
+
const el = transcriptRef.current;
|
|
10696
|
+
if (!el || typeof el.scrollTo !== "function") return;
|
|
10697
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
10698
|
+
const atBottom = () => el.scrollHeight - el.scrollTop - el.clientHeight <= FOLLOW_TOLERANCE_PX;
|
|
10699
|
+
const onScroll = () => {
|
|
10700
|
+
following.current = atBottom();
|
|
10701
|
+
};
|
|
10702
|
+
const observer = new ResizeObserver(() => {
|
|
10703
|
+
if (!following.current) return;
|
|
10704
|
+
el.scrollTo({
|
|
10705
|
+
top: el.scrollHeight,
|
|
10706
|
+
behavior: "auto"
|
|
10707
|
+
});
|
|
10708
|
+
});
|
|
10709
|
+
const content = transcriptContentRef.current;
|
|
10710
|
+
if (content) observer.observe(content);
|
|
10711
|
+
el.addEventListener("scroll", onScroll, { passive: true });
|
|
10712
|
+
return () => {
|
|
10713
|
+
observer.disconnect();
|
|
10714
|
+
el.removeEventListener("scroll", onScroll);
|
|
10715
|
+
};
|
|
10716
|
+
}, [open]);
|
|
10717
|
+
const handleClose = useCallback(() => {
|
|
10718
|
+
onOpenChange(false);
|
|
10719
|
+
window.setTimeout(() => {
|
|
10720
|
+
document.getElementById(triggerId)?.focus({ preventScroll: true });
|
|
10721
|
+
}, 400);
|
|
10722
|
+
}, [onOpenChange, triggerId]);
|
|
10723
|
+
useEffect(() => {
|
|
10724
|
+
if (!open) return;
|
|
10725
|
+
const onKeyDown = (e) => {
|
|
10726
|
+
if (e.key === "Escape") {
|
|
10727
|
+
e.preventDefault();
|
|
10728
|
+
handleClose();
|
|
10729
|
+
return;
|
|
10730
|
+
}
|
|
10731
|
+
if (e.key !== "Tab") return;
|
|
10732
|
+
const panel = panelRef.current;
|
|
10733
|
+
if (!panel) return;
|
|
10734
|
+
const focusable = Array.from(panel.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])")).filter((el) => !el.hasAttribute("disabled") && el.offsetParent !== null);
|
|
10735
|
+
if (focusable.length === 0) return;
|
|
10736
|
+
const first = focusable[0];
|
|
10737
|
+
const last = focusable[focusable.length - 1];
|
|
10738
|
+
if (e.shiftKey && document.activeElement === first) {
|
|
10739
|
+
e.preventDefault();
|
|
10740
|
+
last.focus();
|
|
10741
|
+
} else if (!e.shiftKey && document.activeElement === last) {
|
|
10742
|
+
e.preventDefault();
|
|
10743
|
+
first.focus();
|
|
10744
|
+
}
|
|
10745
|
+
};
|
|
10746
|
+
const focusTimer = window.setTimeout(() => document.getElementById(inputId)?.focus(), 120);
|
|
10747
|
+
window.addEventListener("keydown", onKeyDown);
|
|
10748
|
+
return () => {
|
|
10749
|
+
window.clearTimeout(focusTimer);
|
|
10750
|
+
window.removeEventListener("keydown", onKeyDown);
|
|
10751
|
+
};
|
|
10752
|
+
}, [
|
|
10753
|
+
open,
|
|
10754
|
+
handleClose,
|
|
10755
|
+
inputId
|
|
10756
|
+
]);
|
|
10757
|
+
/**
|
|
10758
|
+
* A call is running — anything but `idle`, including the phases that are not
|
|
10759
|
+
* speakable yet. The composer dims from the moment the caller commits to
|
|
10760
|
+
* voice, not only once the transport catches up.
|
|
10761
|
+
*/
|
|
10762
|
+
const inCall = voice !== void 0 && voice.phase !== "idle";
|
|
10763
|
+
/**
|
|
10764
|
+
* The voice-state pill's own state — `null` for `'idle'` (covered by
|
|
10765
|
+
* `inCall` too) AND `'blocked'` (NOT covered by `inCall`, which is why this
|
|
10766
|
+
* is its own value rather than reusing that boolean: a refused microphone
|
|
10767
|
+
* is still "a call", but it is not one of the four states the pill knows
|
|
10768
|
+
* how to draw — see `voiceStatePillState`'s own doc comment).
|
|
10769
|
+
*/
|
|
10770
|
+
const voicePillState = voiceStatePillState(voice);
|
|
10771
|
+
/**
|
|
10772
|
+
* The call has been asked for and has not answered yet — the transport
|
|
10773
|
+
* dialing, or the browser's own microphone prompt still open in front of
|
|
10774
|
+
* the caller (the host folds both into this one phase; see
|
|
10775
|
+
* `useVoiceSession`'s `micPending` and `host-widget.tsx`'s `callPhase`).
|
|
10776
|
+
*
|
|
10777
|
+
* For as long as it lasts, the round control is a SPINNER and is inert. A
|
|
10778
|
+
* microphone glyph here says "talk now" during the one stretch where
|
|
10779
|
+
* talking provably does nothing, and a pressable one turns a single
|
|
10780
|
+
* impatient gesture into either a second call or a mute of a call that does
|
|
10781
|
+
* not exist yet. The wait ends by itself, in one of two directions: `live`
|
|
10782
|
+
* (the microphone comes back) or `blocked` (the existing refused
|
|
10783
|
+
* presentation) — never in a spinner nobody can clear.
|
|
10784
|
+
*/
|
|
10785
|
+
const connecting = voice?.phase === "connecting";
|
|
10786
|
+
/** No voice leg to press at all, or a microphone the browser refused. */
|
|
10787
|
+
const micUnusable = voice !== void 0 && (voice.disabled === true || voice.phase === "blocked");
|
|
10788
|
+
/** Same fallback contract as the pill's own labels — see `voiceStatePillLabel`. */
|
|
10789
|
+
const connectingLabel = voice?.labels.connecting ?? defaultWidgetMessages.voice_state_connecting;
|
|
10790
|
+
/**
|
|
10791
|
+
* Start, mute or unmute — whichever the one round control means right now —
|
|
10792
|
+
* or, ahead of all three, the REASON it means nothing at all.
|
|
10793
|
+
*
|
|
10794
|
+
* `labels.unavailable` wins whenever `micUnusable` holds, because none of
|
|
10795
|
+
* the other three describe this button any more: every one of them names an
|
|
10796
|
+
* action, and an unusable control performs none. It is checked before
|
|
10797
|
+
* `connecting` too, so a host that disables the control mid-dial (an
|
|
10798
|
+
* escalation landing while the transport is still connecting) never leaves
|
|
10799
|
+
* "Connecting" as the name of a button that will now never connect. See
|
|
10800
|
+
* `ConciergeShellVoice.labels.unavailable`.
|
|
10801
|
+
*/
|
|
10802
|
+
const micLabel = micUnusable ? voice?.labels.unavailable ?? voice?.labels.start ?? "" : connecting ? connectingLabel : inCall ? (voice?.muted === true ? voice.labels.unmute : voice.labels.mute) ?? voice.labels.start : voice?.labels.start ?? "";
|
|
10803
|
+
const submit = (e) => {
|
|
10804
|
+
e.preventDefault();
|
|
10805
|
+
if (!draft.trim() || composerDisabled) return;
|
|
10806
|
+
onSubmit();
|
|
10807
|
+
};
|
|
10808
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
10809
|
+
className: "contents",
|
|
10810
|
+
"data-skin": skin,
|
|
10811
|
+
style: skinStyle,
|
|
10812
|
+
children: [
|
|
10813
|
+
/* @__PURE__ */ jsx(ConciergeLauncher, {
|
|
10814
|
+
id: triggerId,
|
|
10815
|
+
...testIds?.trigger !== void 0 ? { testId: testIds.trigger } : {},
|
|
10816
|
+
...labels.launcher !== void 0 ? { label: labels.launcher } : {},
|
|
10817
|
+
srLabel: labels.open,
|
|
10818
|
+
moveLabel: labels.move ?? labels.open,
|
|
10819
|
+
position,
|
|
10820
|
+
...onPositionChange !== void 0 ? { onPositionChange } : {},
|
|
10821
|
+
onOpen: () => onOpenChange(true),
|
|
10822
|
+
hidden: open,
|
|
10823
|
+
avatar
|
|
10824
|
+
}),
|
|
10825
|
+
/* @__PURE__ */ jsx("div", {
|
|
10826
|
+
"aria-hidden": true,
|
|
10827
|
+
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")
|
|
10828
|
+
}),
|
|
10829
|
+
/* @__PURE__ */ jsx("div", {
|
|
10830
|
+
"aria-hidden": !open,
|
|
10831
|
+
className: cn("pointer-events-none fixed inset-x-0 z-50 flex", panelClasses(position)),
|
|
10832
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
10833
|
+
className: "relative flex flex-col items-center",
|
|
10834
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
10835
|
+
ref: panelRef,
|
|
10836
|
+
role: "dialog",
|
|
10837
|
+
"aria-modal": "true",
|
|
10838
|
+
"aria-label": labels.dialog,
|
|
10839
|
+
"data-testid": testIds?.panel,
|
|
10840
|
+
className: cn("origin-bottom rounded-full transition-[transform,opacity] duration-[700ms] motion-reduce:transition-none", open ? "pointer-events-auto aspect-[5/8] w-[min(97vw,50dvh)] min-h-0 scale-100 opacity-100 [container-type:size]" : "pointer-events-none size-16 scale-90 opacity-0"),
|
|
10841
|
+
style: { transitionTimingFunction: "cubic-bezier(0.16, 1, 0.3, 1)" },
|
|
10842
|
+
children: [
|
|
10843
|
+
/* @__PURE__ */ jsx("div", {
|
|
10844
|
+
"aria-hidden": true,
|
|
10845
|
+
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"),
|
|
10846
|
+
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))" }
|
|
10847
|
+
}),
|
|
10848
|
+
/* @__PURE__ */ jsx("div", {
|
|
10849
|
+
"aria-hidden": true,
|
|
10850
|
+
className: "pointer-events-none absolute inset-0 rounded-full p-[1.5px]",
|
|
10851
|
+
style: {
|
|
10852
|
+
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))",
|
|
10853
|
+
WebkitMask: "linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)",
|
|
10854
|
+
WebkitMaskComposite: "xor",
|
|
10855
|
+
maskComposite: "exclude"
|
|
10856
|
+
}
|
|
10857
|
+
}),
|
|
10858
|
+
/* @__PURE__ */ jsx("button", {
|
|
10859
|
+
type: "button",
|
|
10860
|
+
"aria-label": labels.close,
|
|
10861
|
+
onClick: handleClose,
|
|
10862
|
+
className: cn("absolute end-[8%] top-[8%] z-20 rounded-full bg-[var(--widget-card)] p-1.5 text-[var(--widget-foreground)] shadow-[0_2px_10px_-2px_color-mix(in_oklab,var(--brand-plum)_35%,transparent)] ring-1 ring-black/5", "hover:text-brand-plum hover:ring-brand-plum/30 focus-visible:ring-brand-plum/50 focus-visible:ring-2 focus-visible:outline-none", open ? "opacity-100 delay-[350ms]" : "opacity-0"),
|
|
10863
|
+
children: /* @__PURE__ */ jsx(X, { className: "size-4" })
|
|
10864
|
+
}),
|
|
10865
|
+
/* @__PURE__ */ jsxs("div", {
|
|
10866
|
+
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)]"),
|
|
10867
|
+
children: [
|
|
10868
|
+
/* @__PURE__ */ jsx("div", {
|
|
10869
|
+
"aria-hidden": true,
|
|
10870
|
+
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"
|
|
10871
|
+
}),
|
|
10872
|
+
/* @__PURE__ */ jsx("div", {
|
|
10873
|
+
"aria-hidden": true,
|
|
10874
|
+
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"
|
|
10875
|
+
}),
|
|
10876
|
+
/* @__PURE__ */ jsxs("div", {
|
|
10877
|
+
className: cn("relative flex h-full w-full flex-col items-center justify-center px-2.5 py-1.5 transition-opacity duration-300 motion-reduce:transition-none", open ? "translate-y-0 opacity-100 delay-[300ms]" : "translate-y-2 opacity-0"),
|
|
10878
|
+
children: [
|
|
10879
|
+
/* @__PURE__ */ jsxs("div", {
|
|
10880
|
+
className: "pointer-events-none absolute inset-x-0 top-1.5 z-10 flex flex-col items-center gap-1",
|
|
10881
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
10882
|
+
className: "relative",
|
|
10883
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
10884
|
+
"aria-hidden": true,
|
|
10885
|
+
className: "absolute inset-0 rounded-full bg-[radial-gradient(circle,var(--widget-card)_58%,transparent_72%)]"
|
|
10886
|
+
}), /* @__PURE__ */ jsx(AvatarFace, {
|
|
10887
|
+
avatar,
|
|
10888
|
+
state,
|
|
10889
|
+
size: "lg",
|
|
10890
|
+
messageArrived,
|
|
10891
|
+
tightenKey: knotTightenKey
|
|
10892
|
+
})]
|
|
10893
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
10894
|
+
"data-testid": "widget-voice-state",
|
|
10895
|
+
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"),
|
|
10896
|
+
children: voicePillState ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
10897
|
+
"aria-hidden": true,
|
|
10898
|
+
className: cn("size-1.5 shrink-0 rounded-full", voicePillState !== "listening" && "animate-pulse motion-reduce:animate-none"),
|
|
10899
|
+
style: { backgroundColor: voiceStatePillDotColor(voicePillState) }
|
|
10900
|
+
}), /* @__PURE__ */ jsx("span", { children: voiceStatePillLabel(voicePillState, voice?.labels) })] }) : null
|
|
10901
|
+
})]
|
|
10902
|
+
}),
|
|
10903
|
+
badge == null ? null : /* @__PURE__ */ jsx("div", {
|
|
10904
|
+
className: "z-10 mt-[104px] w-[68%] shrink-0 text-center",
|
|
10905
|
+
children: badge
|
|
10906
|
+
}),
|
|
10907
|
+
/* @__PURE__ */ jsx("div", {
|
|
10908
|
+
ref: transcriptRef,
|
|
10909
|
+
className: "no-scrollbar w-full min-h-0 flex-1 overflow-y-auto",
|
|
10910
|
+
style: badge == null ? TRANSCRIPT_EDGE_FADE : TRANSCRIPT_EDGE_FADE_WITH_BADGE,
|
|
10911
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
10912
|
+
ref: transcriptContentRef,
|
|
10913
|
+
children
|
|
10914
|
+
})
|
|
10915
|
+
}),
|
|
10916
|
+
/* @__PURE__ */ jsx("div", {
|
|
10917
|
+
"aria-hidden": true,
|
|
10918
|
+
className: "pointer-events-none absolute inset-x-0 bottom-0 z-10 bg-[linear-gradient(to_bottom,transparent,var(--widget-card)_38%,var(--widget-card))]",
|
|
10919
|
+
style: { height: COMPOSER_GROUND_LEN }
|
|
10920
|
+
}),
|
|
10921
|
+
/* @__PURE__ */ jsx("div", {
|
|
10922
|
+
className: "pointer-events-none absolute inset-x-0 z-20 flex justify-center",
|
|
10923
|
+
style: { bottom: voice ? COMPOSER_BOTTOM_LEN : COMPOSER_BOTTOM_NO_VOICE_LEN },
|
|
10924
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
10925
|
+
className: cn("flex w-[71%] flex-col items-center gap-2.5", open ? "pointer-events-auto" : "pointer-events-none"),
|
|
10926
|
+
style: { maxWidth: COMPOSER_MAX_WIDTH_LEN },
|
|
10927
|
+
children: [/* @__PURE__ */ jsxs("form", {
|
|
10928
|
+
className: "flex w-full items-center gap-2",
|
|
10929
|
+
onSubmit: submit,
|
|
10930
|
+
children: [composerLeading, /* @__PURE__ */ jsxs("div", {
|
|
10931
|
+
className: "relative flex-1",
|
|
10932
|
+
children: [
|
|
10933
|
+
/* @__PURE__ */ jsx("label", {
|
|
10934
|
+
htmlFor: inputId,
|
|
10935
|
+
className: "sr-only",
|
|
10936
|
+
children: labels.composerPlaceholder
|
|
10937
|
+
}),
|
|
10938
|
+
/* @__PURE__ */ jsx("input", {
|
|
10939
|
+
id: inputId,
|
|
10940
|
+
"data-testid": testIds?.input,
|
|
10941
|
+
value: draft,
|
|
10942
|
+
onChange: (e) => onDraftChange(e.target.value),
|
|
10943
|
+
placeholder: labels.composerPlaceholder,
|
|
10944
|
+
dir: "auto",
|
|
10945
|
+
disabled: composerDisabled,
|
|
10946
|
+
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-[border-color] focus:bg-[var(--widget-bubble)] focus:ring-2 focus:outline-none disabled:opacity-50", inCall && draft === "" && "opacity-60 focus:opacity-100")
|
|
10947
|
+
}),
|
|
10948
|
+
draft.trim() && /* @__PURE__ */ jsx("button", {
|
|
10949
|
+
type: "submit",
|
|
10950
|
+
"aria-label": labels.send,
|
|
10951
|
+
"data-testid": testIds?.send,
|
|
10952
|
+
disabled: composerDisabled,
|
|
10953
|
+
className: "from-brand-plum to-brand-rose text-[var(--widget-accent-foreground)] absolute end-2 top-1/2 flex size-9 -translate-y-1/2 items-center justify-center rounded-full bg-gradient-to-br transition-[transform,opacity] hover:scale-105 disabled:opacity-40",
|
|
10954
|
+
children: /* @__PURE__ */ jsx(Send, { className: "size-4 rtl:-scale-x-100" })
|
|
10955
|
+
})
|
|
10956
|
+
]
|
|
10957
|
+
})]
|
|
10958
|
+
}), voice ? /* @__PURE__ */ jsxs("div", {
|
|
10959
|
+
className: "mt-1 flex items-center gap-3",
|
|
10960
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
10961
|
+
type: "button",
|
|
10962
|
+
onClick: connecting ? void 0 : inCall ? voice.onToggleMute ?? voice.onStart : voice.onStart,
|
|
10963
|
+
disabled: micUnusable || connecting,
|
|
10964
|
+
"data-testid": testIds?.mic,
|
|
10965
|
+
title: micLabel,
|
|
10966
|
+
"aria-label": micLabel,
|
|
10967
|
+
...connecting ? { "aria-busy": true } : {},
|
|
10968
|
+
...inCall && !connecting ? { "aria-pressed": voice.muted ?? false } : {},
|
|
10969
|
+
className: cn("from-brand-plum to-brand-rose text-[var(--widget-accent-foreground)] flex size-12 shrink-0 items-center justify-center rounded-full bg-gradient-to-br transition-[transform,opacity]", micUnusable ? "cursor-not-allowed opacity-40" : connecting ? "cursor-wait" : cn("hover:scale-105 focus-visible:ring-2 focus-visible:ring-white/50 focus-visible:outline-none", "shadow-[0_0_0_1px_color-mix(in_oklab,var(--brand-plum)_18%,transparent),0_4px_14px_-2px_color-mix(in_oklab,var(--brand-plum)_45%,transparent),0_0_22px_-4px_color-mix(in_oklab,var(--brand-rose)_40%,transparent)]", "hover:shadow-[0_0_0_1px_color-mix(in_oklab,var(--brand-plum)_26%,transparent),0_6px_18px_-2px_color-mix(in_oklab,var(--brand-plum)_60%,transparent),0_0_30px_-4px_color-mix(in_oklab,var(--brand-rose)_55%,transparent)]"), inCall && !connecting && voice.muted !== true && "ring-brand-rose/50 ring-4"),
|
|
10970
|
+
children: connecting ? /* @__PURE__ */ jsx("span", {
|
|
10971
|
+
"aria-hidden": "true",
|
|
10972
|
+
"data-testid": "widget-mic-spinner",
|
|
10973
|
+
className: "flex items-center justify-center",
|
|
10974
|
+
children: /* @__PURE__ */ jsx(MorphingLoader, {
|
|
10975
|
+
size: "md",
|
|
10976
|
+
variant: "light",
|
|
10977
|
+
label: connectingLabel
|
|
10978
|
+
})
|
|
10979
|
+
}) : inCall && voice.muted === true ? /* @__PURE__ */ jsx(MicOff, { className: "size-5" }) : /* @__PURE__ */ jsx(Mic, { className: "size-5" })
|
|
10980
|
+
}), inCall && voice.onEnd !== void 0 ? /* @__PURE__ */ jsx("button", {
|
|
10981
|
+
type: "button",
|
|
10982
|
+
onClick: voice.onEnd,
|
|
10983
|
+
"data-testid": testIds?.endCall,
|
|
10984
|
+
title: voice.labels.end ?? "",
|
|
10985
|
+
"aria-label": voice.labels.end ?? "",
|
|
10986
|
+
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"),
|
|
10987
|
+
children: /* @__PURE__ */ jsx(PhoneOff, { className: "size-4" })
|
|
10988
|
+
}) : null]
|
|
10989
|
+
}) : null]
|
|
10990
|
+
})
|
|
10991
|
+
})
|
|
10992
|
+
]
|
|
10993
|
+
})
|
|
10994
|
+
]
|
|
10995
|
+
})
|
|
10996
|
+
]
|
|
10997
|
+
}), attribution ? /* @__PURE__ */ jsxs("a", {
|
|
10998
|
+
href: attribution.href,
|
|
10999
|
+
target: "_blank",
|
|
11000
|
+
rel: "noopener noreferrer",
|
|
11001
|
+
"data-testid": "widget-branding",
|
|
11002
|
+
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"),
|
|
11003
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
11004
|
+
"aria-hidden": true,
|
|
11005
|
+
className: "size-2.5 rounded-full bg-gradient-to-br from-brand-rose to-brand-amber"
|
|
11006
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
11007
|
+
className: "text-brand-plum font-semibold tracking-tight",
|
|
11008
|
+
children: attribution.name
|
|
11009
|
+
})]
|
|
11010
|
+
}) : null]
|
|
11011
|
+
})
|
|
11012
|
+
}),
|
|
11013
|
+
portalActive && /* @__PURE__ */ jsx("div", {
|
|
11014
|
+
"aria-hidden": true,
|
|
11015
|
+
className: cn("pointer-events-none fixed z-[55]", positionClasses(position)),
|
|
11016
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
11017
|
+
className: "widget-portal size-16",
|
|
11018
|
+
children: /* @__PURE__ */ jsx(MorphingLoader, {
|
|
11019
|
+
size: "full",
|
|
11020
|
+
label: labels.open
|
|
11021
|
+
})
|
|
11022
|
+
})
|
|
11023
|
+
}),
|
|
11024
|
+
/* @__PURE__ */ jsx("div", {
|
|
11025
|
+
"aria-live": "polite",
|
|
11026
|
+
"aria-atomic": "false",
|
|
11027
|
+
className: "sr-only",
|
|
11028
|
+
children: announcement
|
|
11029
|
+
})
|
|
11030
|
+
]
|
|
11031
|
+
});
|
|
11032
|
+
}
|
|
11033
|
+
//#endregion
|
|
11034
|
+
//#region src/widget/shell-renderer.tsx
|
|
11035
|
+
/**
|
|
11036
|
+
* The widget — launcher and panel — as a `ConciergeRenderer`
|
|
11037
|
+
* (docs/CONCIERGE_GENERATIONS.md §3).
|
|
11038
|
+
*
|
|
11039
|
+
* Revived from the wiring `voice-widget.tsx` had before the dock (`3a6452ca^`)
|
|
11040
|
+
* and re-pointed at the `ConversationView` both renderers now read. What
|
|
11041
|
+
* differs from the dock is presentation only: the shell has no row, so the
|
|
11042
|
+
* status line is a badge under the panel header rather than a caption; the
|
|
11043
|
+
* attachment control sits before the composer rather than in a `human` row;
|
|
11044
|
+
* the panel is a thing that opens and closes, so this renderer owns that
|
|
11045
|
+
* state — and the launcher position, since dragging the launcher is a fact
|
|
11046
|
+
* about this chrome and not about the conversation.
|
|
11047
|
+
*
|
|
11048
|
+
* Phase 4 (§4) records, per state, where the widget-native presentation
|
|
11049
|
+
* should differ from the mapping here; this is the working baseline.
|
|
11050
|
+
*/
|
|
11051
|
+
/** §9.1 `layout.desktopAlign` in the shell's own anchor vocabulary. */
|
|
11052
|
+
function positionFor(dock) {
|
|
11053
|
+
const align = dock?.layout?.desktopAlign;
|
|
11054
|
+
return align === "left" || align === "right" ? `bottom-${align}` : DEFAULT_CONCIERGE_POSITION;
|
|
11055
|
+
}
|
|
11056
|
+
function ShellRenderer({ state, turns, showMic, callPhase, micOpen, onToggleMic, onEndCall, statusLine, escalated, humanTyping, draft, onDraftChange, submit, attaching, onAttach, attachInput, transcript, extras, messages, skinStyle, avatar, attribution, dock }) {
|
|
11057
|
+
const [open, setOpen] = useState(dock?.initialMinimised === false);
|
|
11058
|
+
const onReady = dock?.onReady;
|
|
11059
|
+
useLayoutEffect(() => {
|
|
11060
|
+
onReady?.();
|
|
11061
|
+
}, []);
|
|
11062
|
+
const [position, setPosition] = useState(() => positionFor(dock));
|
|
11063
|
+
const draggable = dock?.layout?.draggable !== false;
|
|
11064
|
+
const launcherLabel = dock?.copy?.minimisedLabel?.trim();
|
|
11065
|
+
const voiceUnavailable = showMic && escalated ? messages.voice_unavailable_escalated : void 0;
|
|
11066
|
+
const lastTurn = turns[turns.length - 1];
|
|
11067
|
+
const voice = showMic ? {
|
|
11068
|
+
phase: callPhase,
|
|
11069
|
+
onStart: onToggleMic,
|
|
11070
|
+
...onEndCall !== void 0 ? { onEnd: onEndCall } : {},
|
|
11071
|
+
onToggleMute: onToggleMic,
|
|
11072
|
+
muted: !micOpen,
|
|
11073
|
+
...voiceUnavailable !== void 0 ? { disabled: true } : {},
|
|
11074
|
+
labels: {
|
|
11075
|
+
start: messages.mic_start,
|
|
11076
|
+
end: messages.call_end,
|
|
11077
|
+
mute: messages.mic_stop,
|
|
11078
|
+
unmute: messages.mic_start,
|
|
11079
|
+
connecting: messages.voice_state_connecting,
|
|
11080
|
+
listening: messages.voice_state_listening,
|
|
11081
|
+
thinking: messages.voice_state_thinking,
|
|
11082
|
+
speaking: messages.voice_state_speaking,
|
|
11083
|
+
...voiceUnavailable !== void 0 ? { unavailable: voiceUnavailable } : {}
|
|
11084
|
+
}
|
|
11085
|
+
} : void 0;
|
|
11086
|
+
const composerLeading = onAttach ? /* @__PURE__ */ jsxs(Fragment, { children: [attachInput, /* @__PURE__ */ jsxs("button", {
|
|
11087
|
+
type: "button",
|
|
11088
|
+
onClick: onAttach,
|
|
11089
|
+
"data-testid": "widget-attach-button",
|
|
11090
|
+
disabled: attaching !== null && !attaching.failed,
|
|
11091
|
+
className: "flex size-9 shrink-0 cursor-pointer items-center justify-center rounded-full bg-[var(--widget-chip)] text-[var(--widget-foreground-muted)] transition-[background-color,color] hover:text-[var(--widget-foreground)] disabled:cursor-default disabled:opacity-50",
|
|
11092
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
11093
|
+
className: "sr-only",
|
|
11094
|
+
children: messages.attach_label
|
|
11095
|
+
}), /* @__PURE__ */ jsx("svg", {
|
|
11096
|
+
viewBox: "0 0 24 24",
|
|
11097
|
+
className: "h-4 w-4",
|
|
11098
|
+
fill: "none",
|
|
11099
|
+
"aria-hidden": "true",
|
|
11100
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
11101
|
+
d: "M8 12l5.5-5.5a3 3 0 1 1 4.24 4.24L9.5 19a5 5 0 1 1-7.07-7.07L11.5 3",
|
|
11102
|
+
stroke: "currentColor",
|
|
11103
|
+
strokeWidth: "1.8",
|
|
11104
|
+
strokeLinecap: "round",
|
|
11105
|
+
strokeLinejoin: "round"
|
|
11106
|
+
})
|
|
11107
|
+
})]
|
|
11108
|
+
})] }) : null;
|
|
11109
|
+
return /* @__PURE__ */ jsxs(ConciergeShell, {
|
|
11110
|
+
open,
|
|
11111
|
+
onOpenChange: setOpen,
|
|
11112
|
+
state,
|
|
11113
|
+
...skinStyle !== void 0 ? { skinStyle } : {},
|
|
11114
|
+
...avatar !== void 0 ? { avatar } : {},
|
|
11115
|
+
...attribution !== void 0 ? { attribution } : {},
|
|
11116
|
+
messageArrived: lastTurn?.speaker === "caller",
|
|
11117
|
+
idPrefix: "widget",
|
|
11118
|
+
scrollKey: turns.length + (humanTyping ? 1 : 0),
|
|
11119
|
+
draft,
|
|
11120
|
+
onDraftChange,
|
|
11121
|
+
onSubmit: submit,
|
|
11122
|
+
position,
|
|
11123
|
+
...draggable ? { onPositionChange: setPosition } : {},
|
|
11124
|
+
labels: {
|
|
11125
|
+
open: messages.open,
|
|
11126
|
+
close: messages.minimize,
|
|
11127
|
+
dialog: messages.conversation,
|
|
11128
|
+
composerPlaceholder: messages.type_placeholder,
|
|
11129
|
+
send: messages.send,
|
|
11130
|
+
move: messages.move,
|
|
11131
|
+
...launcherLabel ? { launcher: launcherLabel } : {}
|
|
11132
|
+
},
|
|
11133
|
+
...voice !== void 0 ? { voice } : {},
|
|
11134
|
+
composerLeading,
|
|
11135
|
+
badge: statusLine === void 0 ? null : /* @__PURE__ */ jsx("p", {
|
|
11136
|
+
"data-testid": "widget-status",
|
|
11137
|
+
className: "mt-1 max-w-full rounded-2xl bg-[var(--widget-chip)] px-2.5 py-1 text-center text-[10px] leading-snug font-semibold tracking-wide text-[var(--widget-foreground-muted)]",
|
|
11138
|
+
children: statusLine
|
|
11139
|
+
}),
|
|
11140
|
+
testIds: {
|
|
11141
|
+
trigger: "voice-widget-launcher",
|
|
11142
|
+
panel: "voice-widget",
|
|
11143
|
+
input: "widget-text-input",
|
|
11144
|
+
endCall: "widget-end-call",
|
|
11145
|
+
send: "widget-send",
|
|
11146
|
+
mic: "widget-mic"
|
|
11147
|
+
},
|
|
11148
|
+
children: [transcript, extras]
|
|
11149
|
+
});
|
|
11150
|
+
}
|
|
11151
|
+
//#endregion
|
|
11152
|
+
//#region src/dock/dock-renderer.tsx
|
|
11153
|
+
/**
|
|
11154
|
+
* The dock as a `ConciergeRenderer` — docs/CONCIERGE_GENERATIONS.md §3.
|
|
11155
|
+
*
|
|
11156
|
+
* What used to be the tail of `VoiceWidget` verbatim: every prop the `Dock`
|
|
11157
|
+
* takes, from the `ConversationView` the widget derives. Nothing is computed
|
|
11158
|
+
* here that both renderers would need; what is dock-specific (the follow key,
|
|
11159
|
+
* when the sheet reveals itself) stays, because it describes this chrome.
|
|
11160
|
+
*
|
|
11161
|
+
* Imported by `cdn/ui.ts` and by `rendererFor`; never by `voice-widget.tsx`,
|
|
11162
|
+
* so a bundle built around the OTHER renderer does not carry this one.
|
|
11163
|
+
*/
|
|
11164
|
+
function DockRenderer({ turns, lastTurn, operatorName, composing, onEndCall, voice, statusLine, statusKind, notice, escalated, humanTyping, draft, onDraftChange, submit, showBasket, cart, attaching, onAttach, attachInput, transcript, extras, messages, locale, navigate, curationHref, productHref, skinStyle, avatar, attribution, dock }) {
|
|
11165
|
+
return /* @__PURE__ */ jsx(Dock, {
|
|
11166
|
+
identity: {
|
|
11167
|
+
name: "",
|
|
11168
|
+
avatar: avatar === "knot" ? "knot" : "orb"
|
|
11169
|
+
},
|
|
11170
|
+
...dock,
|
|
11171
|
+
voice: {
|
|
11172
|
+
...voice,
|
|
11173
|
+
...dock?.voice ?? {}
|
|
11174
|
+
},
|
|
11175
|
+
messages,
|
|
11176
|
+
locale,
|
|
11177
|
+
status: statusLine,
|
|
11178
|
+
...statusKind !== void 0 ? { statusKind } : {},
|
|
11179
|
+
...notice !== void 0 ? { notice } : {},
|
|
11180
|
+
escalated,
|
|
11181
|
+
...operatorName !== void 0 ? { operatorName } : {},
|
|
11182
|
+
...onEndCall !== void 0 ? { onEndCall } : {},
|
|
11183
|
+
...skinStyle !== void 0 ? { skinStyle } : {},
|
|
11184
|
+
...attribution !== void 0 ? { attribution } : {},
|
|
11185
|
+
...curationHref ? { curationHref } : {},
|
|
11186
|
+
...productHref ? { productHref } : {},
|
|
11187
|
+
...navigate ? { navigate } : {},
|
|
11188
|
+
draft,
|
|
11189
|
+
onDraftChange,
|
|
11190
|
+
onSubmit: submit,
|
|
11191
|
+
revealSheet: showBasket && cart !== void 0 && cart.lines.length > 0 || attaching !== null,
|
|
11192
|
+
followKey: turns.reduce((n, turn) => n + 1 + turn.text.length + (turn.cards?.items.length ?? 0), 0) + (humanTyping ? 1 : 0),
|
|
11193
|
+
...onAttach ? { onAttach } : {},
|
|
11194
|
+
attachBusy: attaching !== null && !attaching.failed,
|
|
11195
|
+
...attachInput !== null ? { attachSlot: attachInput } : {},
|
|
11196
|
+
sheetExtra: extras,
|
|
11197
|
+
transcript,
|
|
11198
|
+
transcriptCount: turns.length,
|
|
11199
|
+
...lastTurn !== void 0 ? { lastTurn } : {},
|
|
11200
|
+
composing
|
|
11201
|
+
});
|
|
11202
|
+
}
|
|
11203
|
+
//#endregion
|
|
11204
|
+
//#region src/renderers.ts
|
|
11205
|
+
/**
|
|
11206
|
+
* The one module that names BOTH renderers — docs/CONCIERGE_GENERATIONS.md §3.
|
|
11207
|
+
*
|
|
11208
|
+
* `VoiceWidget` and `ConciergeWidget` (the npm components) resolve a missing
|
|
11209
|
+
* `renderer` here from `ui.generation`. The CDN entries never import this
|
|
11210
|
+
* file: `cdn/ui.ts` passes `DockRenderer` and `cdn/ui-widget.ts` passes
|
|
11211
|
+
* `ShellRenderer` to `ConciergeHost` directly, which is what keeps each chunk
|
|
11212
|
+
* to one renderer's code (rule 3 of §3: nothing under `widget/` is reachable
|
|
11213
|
+
* from `cdn/ui.ts`, and vice versa — the budget guard measures it).
|
|
11214
|
+
*
|
|
11215
|
+
* Absent ⇒ the dock. That is the npm components' compatibility default, not
|
|
11216
|
+
* the product's: the published config defaults to `widget`
|
|
11217
|
+
* (`widget-config-upcast.ts`), and `cdn/core.ts` reads it that way. A React
|
|
11218
|
+
* host that wants the widget says so.
|
|
11219
|
+
*/
|
|
11220
|
+
function rendererFor(generation) {
|
|
11221
|
+
return generation === "widget" ? ShellRenderer : DockRenderer;
|
|
11222
|
+
}
|
|
11223
|
+
//#endregion
|
|
9575
11224
|
//#region src/widget-markdown.tsx
|
|
9576
11225
|
/**
|
|
9577
11226
|
* Only `http(s)` and `mailto` survive.
|
|
@@ -10565,7 +12214,20 @@ function basketIntentFromTurns(turns) {
|
|
|
10565
12214
|
* `dir`, resolved from that line's locale rather than inherited from the page —
|
|
10566
12215
|
* inheriting is what renders Arabic punctuation on the wrong end of a sentence.
|
|
10567
12216
|
*/
|
|
10568
|
-
|
|
12217
|
+
/**
|
|
12218
|
+
* The public component: picks a renderer when the caller did not. Kept apart
|
|
12219
|
+
* from `VoiceWidgetWithRenderer` so that a CDN entry which imports only the
|
|
12220
|
+
* latter never bundles the renderer it does not draw — `rendererFor` is the
|
|
12221
|
+
* one place both are named.
|
|
12222
|
+
*/
|
|
12223
|
+
function VoiceWidget({ renderer, generation, ...props }) {
|
|
12224
|
+
return /* @__PURE__ */ jsx(VoiceWidgetWithRenderer, {
|
|
12225
|
+
...props,
|
|
12226
|
+
renderer: renderer ?? rendererFor(generation)
|
|
12227
|
+
});
|
|
12228
|
+
}
|
|
12229
|
+
/** `VoiceWidget` with the renderer decided — the component the CDN entries and `ConciergeHost` use. */
|
|
12230
|
+
function VoiceWidgetWithRenderer({ renderer, state, turns, onToggleMic, onEndCall, callPhase = "idle", onSendText, micOpen, status, statusKind, notice, mode = "voice", escalated = false, humanTyping = false, onTyping, onAddToCart, onChooseOptions, chooseOptionsBusy = false, curationHref, productHref, onAttachFile, cart, messages = defaultWidgetMessages, navigate, locale = "en", skinStyle, avatar, attribution, dock }) {
|
|
10569
12231
|
const [draft, setDraft] = useState("");
|
|
10570
12232
|
const [sending, setSending] = useState(false);
|
|
10571
12233
|
/** Roomy mode — see the expand control in the header. Collapses back on close, so a reopened widget starts small. */
|
|
@@ -10815,69 +12477,81 @@ function VoiceWidget({ state, turns, onToggleMic, onEndCall, callPhase = "idle",
|
|
|
10815
12477
|
const lastSpoken = [...turns].reverse().find((t) => t.speaker !== "event");
|
|
10816
12478
|
const replyStreaming = lastSpoken?.speaker === "agent" && lastSpoken.final === false && lastSpoken.filler !== true;
|
|
10817
12479
|
const composing = humanTyping || channel === "text" && (sending || replyStreaming);
|
|
10818
|
-
|
|
10819
|
-
|
|
10820
|
-
|
|
10821
|
-
|
|
10822
|
-
|
|
10823
|
-
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
12480
|
+
/**
|
|
12481
|
+
* The attachment input lives with the conversation, not with either chrome:
|
|
12482
|
+
* the widget that owns the file input also owns what "uploading" looks like.
|
|
12483
|
+
* The renderers draw only the button that opens it.
|
|
12484
|
+
*/
|
|
12485
|
+
const canAttach = onAttachFile !== void 0 && escalated;
|
|
12486
|
+
const attachInput = canAttach ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("label", {
|
|
12487
|
+
className: "sr-only",
|
|
12488
|
+
htmlFor: fileInputId,
|
|
12489
|
+
children: messages.attach_label
|
|
12490
|
+
}), /* @__PURE__ */ jsx("input", {
|
|
12491
|
+
id: fileInputId,
|
|
12492
|
+
ref: fileInputRef,
|
|
12493
|
+
type: "file",
|
|
12494
|
+
"data-testid": "widget-attach-input",
|
|
12495
|
+
className: "sr-only",
|
|
12496
|
+
onChange: (event) => void onFileSelected(event)
|
|
12497
|
+
})] }) : null;
|
|
12498
|
+
const onAttach = canAttach ? () => fileInputRef.current?.click() : void 0;
|
|
12499
|
+
const extras = /* @__PURE__ */ jsxs(Fragment, { children: [cart && cart.lines.length > 0 && showBasket ? /* @__PURE__ */ jsx(WidgetCartSummary, {
|
|
12500
|
+
lines: cart.lines,
|
|
12501
|
+
subtotalMinor: cart.subtotalMinor,
|
|
12502
|
+
currency: cart.currency,
|
|
12503
|
+
...cart.discountMinor !== void 0 ? { discountMinor: cart.discountMinor } : {},
|
|
12504
|
+
onCheckout: cart.onCheckout,
|
|
10829
12505
|
locale,
|
|
10830
|
-
|
|
10831
|
-
...
|
|
10832
|
-
|
|
12506
|
+
messages,
|
|
12507
|
+
...navigate ? { navigate } : {}
|
|
12508
|
+
}) : null, attaching ? /* @__PURE__ */ jsx("p", {
|
|
12509
|
+
role: "status",
|
|
12510
|
+
className: `text-xs ${attaching.failed ? "text-destructive" : "text-[var(--widget-foreground-muted)]"}`,
|
|
12511
|
+
children: attaching.failed ? formatMessage(messages.attach_error, { filename: attaching.filename }) : formatMessage(messages.attach_uploading, { filename: attaching.filename })
|
|
12512
|
+
}) : null] });
|
|
12513
|
+
return /* @__PURE__ */ jsx(renderer, {
|
|
12514
|
+
state,
|
|
12515
|
+
turns,
|
|
12516
|
+
lastTurn,
|
|
12517
|
+
operatorName,
|
|
12518
|
+
composing,
|
|
12519
|
+
channel,
|
|
12520
|
+
mode,
|
|
12521
|
+
showMic,
|
|
12522
|
+
callPhase,
|
|
12523
|
+
micOpen,
|
|
12524
|
+
onToggleMic,
|
|
12525
|
+
onEndCall,
|
|
12526
|
+
voice: derivedVoice,
|
|
12527
|
+
statusLine,
|
|
12528
|
+
statusKind,
|
|
12529
|
+
notice,
|
|
10833
12530
|
escalated,
|
|
10834
|
-
|
|
10835
|
-
...onEndCall !== void 0 ? { onEndCall } : {},
|
|
10836
|
-
...skinStyle !== void 0 ? { skinStyle } : {},
|
|
10837
|
-
...attribution !== void 0 ? { attribution } : {},
|
|
10838
|
-
...curationHref ? { curationHref } : {},
|
|
10839
|
-
...productHref ? { productHref } : {},
|
|
10840
|
-
...navigate ? { navigate } : {},
|
|
12531
|
+
humanTyping,
|
|
10841
12532
|
draft,
|
|
10842
12533
|
onDraftChange: (value) => {
|
|
10843
12534
|
setDraft(value);
|
|
10844
12535
|
if (value.trim() !== "") onTyping?.();
|
|
10845
12536
|
},
|
|
10846
|
-
|
|
10847
|
-
|
|
10848
|
-
|
|
10849
|
-
|
|
10850
|
-
|
|
10851
|
-
|
|
10852
|
-
|
|
10853
|
-
htmlFor: fileInputId,
|
|
10854
|
-
children: messages.attach_label
|
|
10855
|
-
}), /* @__PURE__ */ jsx("input", {
|
|
10856
|
-
id: fileInputId,
|
|
10857
|
-
ref: fileInputRef,
|
|
10858
|
-
type: "file",
|
|
10859
|
-
"data-testid": "widget-attach-input",
|
|
10860
|
-
className: "sr-only",
|
|
10861
|
-
onChange: (event) => void onFileSelected(event)
|
|
10862
|
-
})] }) } : {},
|
|
10863
|
-
sheetExtra: /* @__PURE__ */ jsxs(Fragment, { children: [cart && cart.lines.length > 0 && showBasket ? /* @__PURE__ */ jsx(WidgetCartSummary, {
|
|
10864
|
-
lines: cart.lines,
|
|
10865
|
-
subtotalMinor: cart.subtotalMinor,
|
|
10866
|
-
currency: cart.currency,
|
|
10867
|
-
...cart.discountMinor !== void 0 ? { discountMinor: cart.discountMinor } : {},
|
|
10868
|
-
onCheckout: cart.onCheckout,
|
|
10869
|
-
locale,
|
|
10870
|
-
messages,
|
|
10871
|
-
...navigate ? { navigate } : {}
|
|
10872
|
-
}) : null, attaching ? /* @__PURE__ */ jsx("p", {
|
|
10873
|
-
role: "status",
|
|
10874
|
-
className: `text-xs ${attaching.failed ? "text-destructive" : "text-[var(--widget-foreground-muted)]"}`,
|
|
10875
|
-
children: attaching.failed ? formatMessage(messages.attach_error, { filename: attaching.filename }) : formatMessage(messages.attach_uploading, { filename: attaching.filename })
|
|
10876
|
-
}) : null] }),
|
|
12537
|
+
submit: () => void submit(),
|
|
12538
|
+
sending,
|
|
12539
|
+
showBasket,
|
|
12540
|
+
cart,
|
|
12541
|
+
attaching,
|
|
12542
|
+
onAttach,
|
|
12543
|
+
attachInput,
|
|
10877
12544
|
transcript: renderLog(turns),
|
|
10878
|
-
|
|
10879
|
-
|
|
10880
|
-
|
|
12545
|
+
extras,
|
|
12546
|
+
messages,
|
|
12547
|
+
locale,
|
|
12548
|
+
navigate,
|
|
12549
|
+
curationHref,
|
|
12550
|
+
productHref,
|
|
12551
|
+
skinStyle,
|
|
12552
|
+
avatar,
|
|
12553
|
+
attribution,
|
|
12554
|
+
dock
|
|
10881
12555
|
});
|
|
10882
12556
|
}
|
|
10883
12557
|
//#endregion
|
|
@@ -15077,42 +16751,17 @@ function deriveCallPhase(voice) {
|
|
|
15077
16751
|
return voice.state === "thinking" ? "waiting" : "live";
|
|
15078
16752
|
}
|
|
15079
16753
|
/**
|
|
15080
|
-
* The
|
|
15081
|
-
*
|
|
15082
|
-
*
|
|
15083
|
-
* (`useChatSession`) and owns its own open/closed state; a host wanting
|
|
15084
|
-
* different session plumbing should compose `VoiceWidget` directly instead
|
|
15085
|
-
* (this component is a convenience, not the only way to use the package).
|
|
15086
|
-
*
|
|
15087
|
-
* ## Voice — offered when, and only when, the tenant published it
|
|
15088
|
-
*
|
|
15089
|
-
* This used to be hardcoded `mode="text"`, on the reasoning that "a generic
|
|
15090
|
-
* host bridge carries no voice transport — LiveKit token minting is a
|
|
15091
|
-
* server concern this package cannot assume any host has". That reasoning
|
|
15092
|
-
* no longer holds: `apps/api`'s `POST /widget/voice/token`
|
|
15093
|
-
* (`docs/WIDGET_EMBED_PLAN.md` §5.6/§7) mints a LiveKit session for ANY
|
|
15094
|
-
* `apiBase` this component is given, the same API surface `useChatSession`
|
|
15095
|
-
* already talks to — so a host with no voice leg of its own (the CDN embed,
|
|
15096
|
-
* an npm consumer) can still offer one.
|
|
15097
|
-
*
|
|
15098
|
-
* Three things must ALL hold before the microphone renders at all:
|
|
15099
|
-
*
|
|
15100
|
-
* 1. `apiBase` is known — `createWidgetVoiceTokenFetcher` needs the widget's
|
|
15101
|
-
* mount point, same contract `useChatSession` already uses (see
|
|
15102
|
-
* `ConciergeWidgetProps.apiBase`'s doc comment).
|
|
15103
|
-
* 2. `session.chatToken` exists — `POST /widget/voice/token` is
|
|
15104
|
-
* authenticated by it, same as every other post-`/session` call.
|
|
15105
|
-
* 3. `session.modalities.voice` is `true` — the TENANT's own published
|
|
15106
|
-
* widget config opted in. `false` (the default before this feature, and
|
|
15107
|
-
* for every tenant who hasn't turned it on) keeps this component exactly
|
|
15108
|
-
* as it always behaved: text-only, no mic control drawn at all.
|
|
15109
|
-
*
|
|
15110
|
-
* `useVoiceSession`'s own `import('livekit-client')` stays behind `start()`
|
|
15111
|
-
* regardless of any of this — see that hook's doc comment — so nothing
|
|
15112
|
-
* about offering voice here costs a byte until a caller actually presses
|
|
15113
|
-
* the microphone.
|
|
16754
|
+
* The public component. Everything below it — the session, the bridge, the
|
|
16755
|
+
* voice and cart plumbing — is `ConciergeHost`; this only picks the chrome
|
|
16756
|
+
* when the caller did not. See `renderers.ts` for why they are two functions.
|
|
15114
16757
|
*/
|
|
15115
|
-
function ConciergeWidget({
|
|
16758
|
+
function ConciergeWidget({ renderer, ...props }) {
|
|
16759
|
+
return /* @__PURE__ */ jsx(ConciergeHost, {
|
|
16760
|
+
...props,
|
|
16761
|
+
renderer: renderer ?? rendererFor(props.generation)
|
|
16762
|
+
});
|
|
16763
|
+
}
|
|
16764
|
+
function ConciergeHost({ renderer, embedKey, apiBase, socketUrl, socketPath, bridge, siteProfile, collector, messages = defaultWidgetMessages, locale = "en", productHref, hostRoutes, curationHref, brandPrimary, brandSecondary, brandAccent, avatar, attribution, color, type, identity, layout, copy, bottomOffset, showPrice, cardImageAspect, voiceAvailable, direction, proactive, initialDraft, initialSelection, initialFocus, initialMinimised, insets, hold, audio, onReady, cartLineIds }) {
|
|
15116
16765
|
/**
|
|
15117
16766
|
* Maps the tenant's semantic config fields onto the widget's historical
|
|
15118
16767
|
* CSS custom properties — this is the "one becomes the other" site
|
|
@@ -16821,7 +18470,8 @@ function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, sit
|
|
|
16821
18470
|
...audio !== void 0 ? { audio } : {},
|
|
16822
18471
|
...onReady !== void 0 ? { onReady } : {}
|
|
16823
18472
|
};
|
|
16824
|
-
return /* @__PURE__ */ jsx(
|
|
18473
|
+
return /* @__PURE__ */ jsx(VoiceWidgetWithRenderer, {
|
|
18474
|
+
renderer,
|
|
16825
18475
|
state: inCall ? voice.state : "idle",
|
|
16826
18476
|
turns: widgetTurns,
|
|
16827
18477
|
mode: voiceEnabled ? "voice" : "text",
|
|
@@ -16854,4 +18504,4 @@ function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, sit
|
|
|
16854
18504
|
});
|
|
16855
18505
|
}
|
|
16856
18506
|
//#endregion
|
|
16857
|
-
export {
|
|
18507
|
+
export { exchangeCount as $, themeToCss as $t, DockRenderer as A, cn as An, SHEET_PEEK_MAX as At, positionClasses as B, pillAnchor as Bt, readsAsCheckoutIntent as C, DEFAULT_WIDGET_AVATAR as Cn, PILL_MARK as Ct, WidgetMarkdown as D, RopeKnot as Dn, SHEET_EXPANDED_DESKTOP_MAX as Dt, WidgetCardList as E, KNOT_PATH as En, ROW_H as Et, DEFAULT_CONCIERGE_POSITION as F, bottomLen as Ft, SESSION_EVENTS as G, sheetMaxHeightLen as Gt, IDLE_SNAPSHOT as H, readStoredAlign as Ht, alignOf as I, containerAnchor as It, latencyBetween as J, CARD_RADIUS_MAX_PX as Jt, SessionLog as K, snapAlign as Kt, edgeOf as L, geometryVars as Lt, ConciergeShell as M, SHEET_TUCK as Mt, ConciergeLauncher as N, SHORT_VIEWPORT as Nt, parseBlocks as O, BotFace as On, SHEET_EXPANDED_VH as Ot, CONCIERGE_POSITIONS as P, Z_INDEX as Pt, deriveDockView as Q, deriveTheme as Qt, nearestPosition as R, persistAlign as Rt, readsAsCartViewIntent as S, MorphingLoader as Sn, PILL_H as St, WidgetCartSummary as T, isWidgetAvatar as Tn, RADII as Tt, botStateFor as U, readStoredMinimised as Ut, positionForArrow as V, readStored as Vt, SseFrameParser as W, rowWidthLen as Wt, DOCK_STATES as X, SYSTEM_FONT_STACK as Xt, Dock as Y, SHEET_RADIUS_MAX_PX as Yt, deriveDockState as Z, WIDGET_THEME_TOKENS as Zt, useChatSession as _, withAlpha as _n, FLOAT_DUCK_DISMISS_MS as _t, MAX_REPORTED_CART_LINES as a, linearRgbToOklab as an, formatMoney as at, VoiceWidgetWithRenderer as b, resolveWidgetMessages as bn, MARK as bt, deriveCallPhase as c, oklabToHex as cn, CONTROL as ct, resolveCheckoutUrl as d, oklchToHex as dn, DESKTOP_GUTTER as dt, themeToInlineStyle as en, idleDockInput as et, toChatCart as f, oklchToOklab as fn, DESKTOP_WIDTHS as ft, isSameOriginPath as g, srgbToLinear as gn, DRAG_TAP_SLOP_PX as gt, useVoiceSession as h, rotateHue as hn, DRAG_CLICK_WINDOW_MS as ht, ConciergeWidget as i, hexToOklch as in, idleConciergeInput as it, ShellRenderer as j, SHEET_TOP_CLEARANCE as jt, rendererFor as k, labelProps as kn, SHEET_GAP as kt, mergeAddedCartLine as l, oklabToLinearRgb as ln, DESKTOP_BOTTOM as lt, createWidgetVoiceTokenFetcher as m, relativeLuminance as mn, DOCK_MINIMISED_STORAGE_KEY as mt, CART_LINE_VARIANT_ID_SHAPE as n, formatHex as nn, CONCIERGE_STATES as nt, cartLinesFromSnapshot as o, linearToSrgb as on, ACTIVITY_W as ot, ROOM_EVENTS as p, parseHex as pn, DOCK_ALIGN_STORAGE_KEY as pt, formatMs as q, writeStored as qt, ConciergeHost as r, hexToOklab as rn, deriveConciergeState as rt, chooseOptionsAction as s, mixToward as sn, BOTTOM_FLOOR as st, CART_LINE_PLATFORM_VARIANT_ID_SHAPE as t, contrastRatio as tn, latestExchangeStart as tt, resolveAddToCartHandler as u, oklabToOklch as un, DESKTOP_BREAKPOINT as ut, detectPage as v, defaultWidgetMessages as vn, FLOAT_GAP as vt, textDirectionFor as w, WIDGET_AVATARS as wn, PROACTIVE_NUDGE_MS as wt, basketIntentFromTurns as x, widgetMessagesFromCopy as xn, MOBILE_MARGIN as xt, VoiceWidget as y, formatMessage as yn, GLASS_IDLE_MS as yt, panelClasses as z, persistMinimised as zt };
|