@saar-ai/web-widget 0.14.0 → 0.14.1
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/chunks/{host-widget-BJrw-B0B.js → host-widget-DlFlAZYq.js} +227 -57
- package/dist/concierge-shell.css +1 -1
- package/dist/consent/consent-prompt-dom.d.ts.map +1 -1
- package/dist/dock/dock-caption.d.ts.map +1 -1
- package/dist/generated/concierge-shell-css.d.ts.map +1 -1
- package/dist/generated/widget-css.d.ts.map +1 -1
- package/dist/host-widget.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/message-limit.d.ts +10 -0
- package/dist/message-limit.d.ts.map +1 -0
- package/dist/messages.d.ts +7 -0
- package/dist/messages.d.ts.map +1 -1
- package/dist/next/index.js +1 -1
- package/dist/use-chat-session.d.ts +11 -1
- package/dist/use-chat-session.d.ts.map +1 -1
- package/dist/voice-widget.d.ts.map +1 -1
- package/dist/widget/concierge-shell.d.ts +7 -1
- package/dist/widget/concierge-shell.d.ts.map +1 -1
- package/dist/widget/open-state.d.ts +3 -0
- package/dist/widget/open-state.d.ts.map +1 -0
- package/dist/widget/shell-renderer.d.ts.map +1 -1
- package/dist/widget/transcript-geometry.d.ts +12 -6
- package/dist/widget/transcript-geometry.d.ts.map +1 -1
- package/dist/widget-markdown.d.ts +8 -0
- package/dist/widget-markdown.d.ts.map +1 -1
- package/dist/widget.css +1 -1
- package/package.json +1 -1
|
@@ -4619,6 +4619,8 @@ var defaultWidgetMessages = {
|
|
|
4619
4619
|
dock_hide_conversation: "Hide conversation",
|
|
4620
4620
|
handoff_event: "Handed to a human teammate",
|
|
4621
4621
|
handback_event: "Back with the concierge",
|
|
4622
|
+
capture_saved_event: "Thanks — sent.",
|
|
4623
|
+
capture_declined_event: "No problem — skipped.",
|
|
4622
4624
|
escalated_banner: "A human teammate will pick this up shortly.",
|
|
4623
4625
|
status_sending: "Sending",
|
|
4624
4626
|
status_sent: "Sent",
|
|
@@ -5796,6 +5798,17 @@ function pillAnchor(dir, isDesktop, desktopAlign) {
|
|
|
5796
5798
|
};
|
|
5797
5799
|
}
|
|
5798
5800
|
//#endregion
|
|
5801
|
+
//#region src/message-limit.ts
|
|
5802
|
+
/**
|
|
5803
|
+
* The longest message `POST /widget/chat` accepts (`MAX_MESSAGE_LENGTH` in
|
|
5804
|
+
* `apps/api/src/widget/widget-chat.controller.ts`; a test pins the two). Both
|
|
5805
|
+
* composers cap their input at it (SAA-434), so a message is never refused
|
|
5806
|
+
* for its length after the shopper has typed it.
|
|
5807
|
+
*/
|
|
5808
|
+
var WIDGET_MESSAGE_MAX_LENGTH = 4e3;
|
|
5809
|
+
/** How close to the limit the composer starts showing its count. */
|
|
5810
|
+
var WIDGET_MESSAGE_COUNT_FROM = 3600;
|
|
5811
|
+
//#endregion
|
|
5799
5812
|
//#region src/dock/dock-caption.tsx
|
|
5800
5813
|
function DockCaption({ line, swapKey, draft, onDraftChange, onSubmit, placeholder, label, disabled = false, inputRef, durationMs, inputTestId, lineTestId = "widget-dock-caption" }) {
|
|
5801
5814
|
const outgoing = useCrossFade(line, swapKey, durationMs);
|
|
@@ -5818,6 +5831,7 @@ function DockCaption({ line, swapKey, draft, onDraftChange, onSubmit, placeholde
|
|
|
5818
5831
|
placeholder,
|
|
5819
5832
|
"aria-label": label,
|
|
5820
5833
|
autoComplete: "off",
|
|
5834
|
+
maxLength: WIDGET_MESSAGE_MAX_LENGTH,
|
|
5821
5835
|
disabled,
|
|
5822
5836
|
onChange: (event) => onDraftChange(event.target.value),
|
|
5823
5837
|
onKeyDown,
|
|
@@ -10644,7 +10658,7 @@ var TRANSCRIPT_FADE_TOP_LEN = "max(112px, 19.24cqh)";
|
|
|
10644
10658
|
* direction.
|
|
10645
10659
|
*/
|
|
10646
10660
|
var TRANSCRIPT_FADE_TOP_WITH_BADGE_LEN = "max(28px, 4cqh, 19.24cqh - 115px)";
|
|
10647
|
-
var TRANSCRIPT_FADE_BOTTOM_LEN = "max(
|
|
10661
|
+
var TRANSCRIPT_FADE_BOTTOM_LEN = "max(136px, 23.36cqh)";
|
|
10648
10662
|
/**
|
|
10649
10663
|
* The transcript's horizontal inset — the width the ellipse actually costs.
|
|
10650
10664
|
*
|
|
@@ -10686,7 +10700,7 @@ var TRANSCRIPT_INSET_X = "max(8px, 10.6cqw - 11px)";
|
|
|
10686
10700
|
* `11.86cqh - 63px` is 6.03px at 582px, so a phone renders what it rendered
|
|
10687
10701
|
* before to a hundredth of a pixel and only larger panels lift the composer.
|
|
10688
10702
|
*/
|
|
10689
|
-
var COMPOSER_BOTTOM_LEN = "max(6px,
|
|
10703
|
+
var COMPOSER_BOTTOM_LEN = "max(6px, 15cqh - 63px)";
|
|
10690
10704
|
/**
|
|
10691
10705
|
* The composer overlay's bottom offset when there is NO microphone.
|
|
10692
10706
|
*
|
|
@@ -10703,7 +10717,7 @@ var COMPOSER_BOTTOM_LEN = "max(6px, 11.86cqh - 63px)";
|
|
|
10703
10717
|
* for the input + microphone pair regardless of whether the pair is drawn), so
|
|
10704
10718
|
* nothing above has to move to make room.
|
|
10705
10719
|
*/
|
|
10706
|
-
var COMPOSER_BOTTOM_NO_VOICE_LEN = "max(6px,
|
|
10720
|
+
var COMPOSER_BOTTOM_NO_VOICE_LEN = "max(6px, 15cqh - 1px)";
|
|
10707
10721
|
/**
|
|
10708
10722
|
* The composer's width cap — what the ellipse actually offers at that row.
|
|
10709
10723
|
*
|
|
@@ -10728,7 +10742,7 @@ var COMPOSER_BOTTOM_NO_VOICE_LEN = "max(6px, 11.86cqh - 1px)";
|
|
|
10728
10742
|
* inert at every size the widget really renders (it binds only below a 248px
|
|
10729
10743
|
* panel; the narrowest phone in circulation, 320px, gives 310px).
|
|
10730
10744
|
*/
|
|
10731
|
-
var COMPOSER_MAX_WIDTH_LEN = "max(160px,
|
|
10745
|
+
var COMPOSER_MAX_WIDTH_LEN = "max(160px, 71.41cqw - 10px)";
|
|
10732
10746
|
/**
|
|
10733
10747
|
* The opaque ground the composer sits on, which has to keep covering it.
|
|
10734
10748
|
*
|
|
@@ -10749,7 +10763,7 @@ var COMPOSER_MAX_WIDTH_LEN = "max(160px, 64.65cqw - 10px)";
|
|
|
10749
10763
|
* 118:132 relationship the two were tuned at), so they still meet without a
|
|
10750
10764
|
* seam or a band of doubly-darkened panel.
|
|
10751
10765
|
*/
|
|
10752
|
-
var COMPOSER_GROUND_LEN = "max(
|
|
10766
|
+
var COMPOSER_GROUND_LEN = "max(150px, 25.77cqh)";
|
|
10753
10767
|
//#endregion
|
|
10754
10768
|
//#region src/widget/concierge-shell.tsx
|
|
10755
10769
|
/**
|
|
@@ -10768,6 +10782,10 @@ var FOLLOW_TOLERANCE_PX = 24;
|
|
|
10768
10782
|
* last messages scroll clear of the ramp, so a ramp length that is not also
|
|
10769
10783
|
* the padding leaves the newest message permanently half-dissolved.
|
|
10770
10784
|
*
|
|
10785
|
+
* The top half of the top ramp is fully transparent (SAA-435): text beside
|
|
10786
|
+
* the orb read through at 20-45% under the old eased ramp, which looked like
|
|
10787
|
+
* no fade at all. It now clears completely before it reaches the orb's row.
|
|
10788
|
+
*
|
|
10771
10789
|
* The top ramp's stops are scaled from `topLen` rather than hardcoded, so the
|
|
10772
10790
|
* shortened badge variant keeps the same eased shape instead of becoming a
|
|
10773
10791
|
* steep two-point cut. `topLen` is a CSS length EXPRESSION now (a `max(<px>,
|
|
@@ -10797,10 +10815,9 @@ function transcriptEdgeFade(topLen) {
|
|
|
10797
10815
|
const at = (fraction) => `calc(${topLen} * ${fraction})`;
|
|
10798
10816
|
const gradient = `linear-gradient(to bottom, ${[
|
|
10799
10817
|
"transparent 0",
|
|
10800
|
-
`
|
|
10801
|
-
`rgba(0,0,0,0.
|
|
10802
|
-
`rgba(0,0,0,0.
|
|
10803
|
-
`rgba(0,0,0,0.75) ${at(.82)}`,
|
|
10818
|
+
`transparent ${at(.5)}`,
|
|
10819
|
+
`rgba(0,0,0,0.25) ${at(.7)}`,
|
|
10820
|
+
`rgba(0,0,0,0.65) ${at(.86)}`,
|
|
10804
10821
|
`#000 ${topLen}`,
|
|
10805
10822
|
`#000 calc(100% - ${TRANSCRIPT_FADE_BOTTOM_LEN})`,
|
|
10806
10823
|
"rgba(0,0,0,0.86) calc(100% - 96px)",
|
|
@@ -10879,9 +10896,15 @@ function voiceStatePillDotColor(pillState) {
|
|
|
10879
10896
|
case "speaking": return "var(--brand-rose)";
|
|
10880
10897
|
}
|
|
10881
10898
|
}
|
|
10899
|
+
/**
|
|
10900
|
+
* The footer's two controls: opaque pills in the band the column reserves
|
|
10901
|
+
* under the panel (SAA-435), readable over any host page. Inherited colour
|
|
10902
|
+
* there was the HOST's, which is how "Privacy choices" went near-invisible.
|
|
10903
|
+
*/
|
|
10904
|
+
var FOOTER_PILL = "absolute bottom-[env(safe-area-inset-bottom,0px)] h-7 rounded-full bg-[var(--widget-card)] px-2.5 text-xs shadow-sm ring-1 ring-black/5 transition-opacity duration-300";
|
|
10882
10905
|
/** How long the opening flourish runs. Matches `.widget-portal`'s own duration. */
|
|
10883
10906
|
var PORTAL_MS = 720;
|
|
10884
|
-
function ConciergeShell({ open, onOpenChange, state, messageArrived = false, launcher, launcherInitials, typing = false, operatorName, avatar = "orb", labels, children, badge, draft, onDraftChange, onSubmit, composerDisabled = false, voice, announcement, skin, skinStyle, idPrefix = "concierge", scrollKey, composerLeading, testIds, position = DEFAULT_CONCIERGE_POSITION, onPositionChange, attribution, privacyChoices }) {
|
|
10907
|
+
function ConciergeShell({ open, onOpenChange, state, messageArrived = false, launcher, launcherInitials, typing = false, operatorName, avatar = "orb", labels, children, badge, draft, onDraftChange, onSubmit, composerDisabled = false, voice, announcement, skin, skinStyle, idPrefix = "concierge", scrollKey, composerLeading, testIds, position = DEFAULT_CONCIERGE_POSITION, onPositionChange, attribution, privacyChoices, focusOnOpen = true }) {
|
|
10885
10908
|
const triggerId = `${idPrefix}-trigger`;
|
|
10886
10909
|
const inputId = `${idPrefix}-input`;
|
|
10887
10910
|
const [portalActive, setPortalActive] = useState(false);
|
|
@@ -10983,6 +11006,7 @@ function ConciergeShell({ open, onOpenChange, state, messageArrived = false, lau
|
|
|
10983
11006
|
el.removeEventListener("scroll", onScroll);
|
|
10984
11007
|
};
|
|
10985
11008
|
}, [open]);
|
|
11009
|
+
const skipFocus = useRef(!focusOnOpen);
|
|
10986
11010
|
const handleClose = useCallback(() => {
|
|
10987
11011
|
onOpenChange(false);
|
|
10988
11012
|
window.setTimeout(() => {
|
|
@@ -11012,7 +11036,8 @@ function ConciergeShell({ open, onOpenChange, state, messageArrived = false, lau
|
|
|
11012
11036
|
first.focus();
|
|
11013
11037
|
}
|
|
11014
11038
|
};
|
|
11015
|
-
const focusTimer = window.setTimeout(() => document.getElementById(inputId)?.focus(), 120);
|
|
11039
|
+
const focusTimer = skipFocus.current ? void 0 : window.setTimeout(() => document.getElementById(inputId)?.focus(), 120);
|
|
11040
|
+
skipFocus.current = false;
|
|
11016
11041
|
window.addEventListener("keydown", onKeyDown);
|
|
11017
11042
|
return () => {
|
|
11018
11043
|
window.clearTimeout(focusTimer);
|
|
@@ -11069,6 +11094,7 @@ function ConciergeShell({ open, onOpenChange, state, messageArrived = false, lau
|
|
|
11069
11094
|
* `ConciergeShellVoice.labels.unavailable`.
|
|
11070
11095
|
*/
|
|
11071
11096
|
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 ?? "";
|
|
11097
|
+
const counting = draft.length >= WIDGET_MESSAGE_COUNT_FROM;
|
|
11072
11098
|
const submit = (e) => {
|
|
11073
11099
|
e.preventDefault();
|
|
11074
11100
|
if (!draft.trim() || composerDisabled) return;
|
|
@@ -11101,7 +11127,7 @@ function ConciergeShell({ open, onOpenChange, state, messageArrived = false, lau
|
|
|
11101
11127
|
"aria-hidden": !open,
|
|
11102
11128
|
className: cn("pointer-events-none fixed inset-x-0 z-50 flex", panelClasses(position)),
|
|
11103
11129
|
children: /* @__PURE__ */ jsxs("div", {
|
|
11104
|
-
className: "relative flex flex-col items-center",
|
|
11130
|
+
className: cn("relative flex flex-col items-center", open && (attribution || privacyChoices) && "pb-[calc(2.25rem+env(safe-area-inset-bottom,0px))]"),
|
|
11105
11131
|
children: [
|
|
11106
11132
|
/* @__PURE__ */ jsxs("div", {
|
|
11107
11133
|
ref: panelRef,
|
|
@@ -11237,9 +11263,21 @@ function ConciergeShell({ open, onOpenChange, state, messageArrived = false, lau
|
|
|
11237
11263
|
onChange: (e) => onDraftChange(e.target.value),
|
|
11238
11264
|
placeholder: labels.composerPlaceholder,
|
|
11239
11265
|
dir: "auto",
|
|
11266
|
+
maxLength: WIDGET_MESSAGE_MAX_LENGTH,
|
|
11267
|
+
...counting ? { "aria-describedby": `${inputId}-count` } : {},
|
|
11240
11268
|
disabled: composerDisabled,
|
|
11241
|
-
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")
|
|
11269
|
+
className: cn("border-brand-plum/12 h-[40px] w-full rounded-3xl border bg-[var(--widget-chip)] ps-4 pe-12 text-[16px] [@media(min-width:640px)_and_(pointer:fine)]:text-[14px] text-[var(--widget-foreground)] placeholder:text-[var(--widget-foreground-muted)]", "focus:border-brand-plum/30 focus:ring-brand-plum/15 transition-[border-color] focus:bg-[var(--widget-bubble)] focus:ring-2 focus:outline-none disabled:opacity-50", inCall && draft === "" && "opacity-60 focus:opacity-100")
|
|
11242
11270
|
}),
|
|
11271
|
+
counting ? /* @__PURE__ */ jsxs("span", {
|
|
11272
|
+
id: `${inputId}-count`,
|
|
11273
|
+
"data-testid": "widget-composer-count",
|
|
11274
|
+
className: "absolute end-4 -top-5 text-[11px] text-[var(--widget-foreground-muted)] tabular-nums",
|
|
11275
|
+
children: [
|
|
11276
|
+
draft.length,
|
|
11277
|
+
"/",
|
|
11278
|
+
WIDGET_MESSAGE_MAX_LENGTH
|
|
11279
|
+
]
|
|
11280
|
+
}) : null,
|
|
11243
11281
|
draft.trim() && /* @__PURE__ */ jsx("button", {
|
|
11244
11282
|
type: "submit",
|
|
11245
11283
|
"aria-label": labels.send,
|
|
@@ -11314,7 +11352,7 @@ function ConciergeShell({ open, onOpenChange, state, messageArrived = false, lau
|
|
|
11314
11352
|
target: "_blank",
|
|
11315
11353
|
rel: "noopener noreferrer",
|
|
11316
11354
|
"data-testid": "widget-branding",
|
|
11317
|
-
className: cn("
|
|
11355
|
+
className: cn(FOOTER_PILL, "left-1/2 inline-flex -translate-x-1/2 items-center gap-1.5 whitespace-nowrap", open ? "pointer-events-auto opacity-100" : "pointer-events-none opacity-0"),
|
|
11318
11356
|
children: [/* @__PURE__ */ jsx("span", {
|
|
11319
11357
|
"aria-hidden": true,
|
|
11320
11358
|
className: "size-2.5 rounded-full bg-gradient-to-br from-brand-rose to-brand-amber"
|
|
@@ -11327,7 +11365,7 @@ function ConciergeShell({ open, onOpenChange, state, messageArrived = false, lau
|
|
|
11327
11365
|
type: "button",
|
|
11328
11366
|
onClick: privacyChoices.open,
|
|
11329
11367
|
"data-testid": "widget-privacy-choices",
|
|
11330
|
-
className: cn("
|
|
11368
|
+
className: cn(FOOTER_PILL, "end-0 text-[var(--widget-foreground)] underline", open ? "pointer-events-auto opacity-100" : "pointer-events-none opacity-0"),
|
|
11331
11369
|
children: privacyChoices.label
|
|
11332
11370
|
}) : null
|
|
11333
11371
|
]
|
|
@@ -11592,6 +11630,31 @@ function deriveWidgetView(snapshot, input) {
|
|
|
11592
11630
|
throw new TypeError(`Unknown concierge state: ${JSON.stringify(state)}`);
|
|
11593
11631
|
}
|
|
11594
11632
|
//#endregion
|
|
11633
|
+
//#region src/widget/open-state.ts
|
|
11634
|
+
/**
|
|
11635
|
+
* Whether the widget's panel was open, for the rest of this browsing session
|
|
11636
|
+
* (SAA-435): an in-site navigation that remounts the widget, or a refresh,
|
|
11637
|
+
* reopens it instead of dropping the shopper back to the launcher.
|
|
11638
|
+
*
|
|
11639
|
+
* `sessionStorage`, so it ends with the tab. Every access is guarded: a
|
|
11640
|
+
* private window, blocked site data or a sandboxed frame throws, and the
|
|
11641
|
+
* widget then simply starts closed.
|
|
11642
|
+
*/
|
|
11643
|
+
var KEY = "wgt_panel_open";
|
|
11644
|
+
function readOpen() {
|
|
11645
|
+
try {
|
|
11646
|
+
return sessionStorage.getItem(KEY) === "1";
|
|
11647
|
+
} catch {
|
|
11648
|
+
return false;
|
|
11649
|
+
}
|
|
11650
|
+
}
|
|
11651
|
+
function writeOpen(open) {
|
|
11652
|
+
try {
|
|
11653
|
+
if (open) sessionStorage.setItem(KEY, "1");
|
|
11654
|
+
else sessionStorage.removeItem(KEY);
|
|
11655
|
+
} catch {}
|
|
11656
|
+
}
|
|
11657
|
+
//#endregion
|
|
11595
11658
|
//#region src/widget/shell-renderer.tsx
|
|
11596
11659
|
/**
|
|
11597
11660
|
* The widget — launcher and panel — as a `ConciergeRenderer`
|
|
@@ -11615,7 +11678,9 @@ function positionFor(dock) {
|
|
|
11615
11678
|
return align === "left" || align === "right" ? `bottom-${align}` : DEFAULT_CONCIERGE_POSITION;
|
|
11616
11679
|
}
|
|
11617
11680
|
function ShellRenderer({ turns, showMic, callPhase, micOpen, onToggleMic, onEndCall, statusKind, statusLine, escalated, operatorName, humanTyping, composing, replyStreaming, channel, draft, onDraftChange, submit, attaching, onAttach, attachInput, transcript, extras, messages, skinStyle, avatar, attribution, privacyChoices, voice: derivedVoice, dock }) {
|
|
11618
|
-
const [
|
|
11681
|
+
const [restored] = useState(readOpen);
|
|
11682
|
+
const [open, setOpen] = useState(dock?.initialMinimised === false || restored);
|
|
11683
|
+
useEffect(() => writeOpen(open), [open]);
|
|
11619
11684
|
const onReady = dock?.onReady;
|
|
11620
11685
|
useLayoutEffect(() => {
|
|
11621
11686
|
onReady?.();
|
|
@@ -11720,7 +11785,9 @@ function ShellRenderer({ turns, showMic, callPhase, micOpen, onToggleMic, onEndC
|
|
|
11720
11785
|
* `resolveCaption` makes, for the same reason — a renderer that invented
|
|
11721
11786
|
* copy would need translating twice.
|
|
11722
11787
|
*/
|
|
11723
|
-
const
|
|
11788
|
+
const handoffAt = turns.findLastIndex((t) => t.event === "handoff");
|
|
11789
|
+
const promiseKept = view.status?.kind === "message" && view.status.key === "escalated_banner" && turns.slice(handoffAt + 1).some((t) => t.speaker === "agent" && t.text.trim() !== "");
|
|
11790
|
+
const statusText = view.status === null || promiseKept ? void 0 : view.status.kind === "text" ? view.status.text : messages[view.status.key] ?? void 0;
|
|
11724
11791
|
const voice = showMic ? {
|
|
11725
11792
|
phase: callPhase,
|
|
11726
11793
|
onStart: onToggleMic,
|
|
@@ -11770,6 +11837,7 @@ function ShellRenderer({ turns, showMic, callPhase, micOpen, onToggleMic, onEndC
|
|
|
11770
11837
|
return /* @__PURE__ */ jsxs(ConciergeShell, {
|
|
11771
11838
|
open,
|
|
11772
11839
|
onOpenChange: setOpen,
|
|
11840
|
+
...restored ? { focusOnOpen: false } : {},
|
|
11773
11841
|
state: view.avatar,
|
|
11774
11842
|
...skinStyle !== void 0 ? { skinStyle } : {},
|
|
11775
11843
|
...avatar !== void 0 ? { avatar } : {},
|
|
@@ -11908,6 +11976,16 @@ function safeHref(raw) {
|
|
|
11908
11976
|
return null;
|
|
11909
11977
|
}
|
|
11910
11978
|
/**
|
|
11979
|
+
* The bidi embedding and isolate controls (U+202A-U+202E, U+2066-U+2069),
|
|
11980
|
+
* removed from what a bubble shows (SAA-436). A right-to-left override typed
|
|
11981
|
+
* into a message reverses the rest of it on screen ("exe.txt" spoofing); the
|
|
11982
|
+
* bubble's own `dir="auto"` and `unicode-bidi: isolate` already order real
|
|
11983
|
+
* mixed-direction text, so nothing legitimate needs them.
|
|
11984
|
+
*/
|
|
11985
|
+
function stripBidiControls(text) {
|
|
11986
|
+
return text.replace(/[\u202A-\u202E\u2066-\u2069]/g, "");
|
|
11987
|
+
}
|
|
11988
|
+
/**
|
|
11911
11989
|
* Inline constructs, innermost-last.
|
|
11912
11990
|
*
|
|
11913
11991
|
* Code is matched FIRST and never recurses into its own body: `` `**not
|
|
@@ -11918,7 +11996,7 @@ function parseInline(src) {
|
|
|
11918
11996
|
const out = [];
|
|
11919
11997
|
let rest = src;
|
|
11920
11998
|
while (rest.length > 0) {
|
|
11921
|
-
const match = /`([^`]+)`|\*\*([\s\S]+?)\*\*|__([\s\S]+?)__|(?<!\*)\*(?!\s)([^*\n]+?)\*(?!\*)|(?<!_)_(?!\s)([^_\n]+?)_(?!_)|\[([^\]]*)\]\(([^)\s]+)\)/.exec(rest);
|
|
11999
|
+
const match = /`([^`]+)`|\*\*([\s\S]+?)\*\*|__([\s\S]+?)__|(?<!\*)\*(?!\s)([^*\n]+?)\*(?!\*)|(?<!_)_(?!\s)([^_\n]+?)_(?!_)|\[([^\]]*)\]\(([^)\s]+)\)|(https:\/\/[^\s<>"'`]*[^\s<>"'`.,;:!?)\]])/.exec(rest);
|
|
11922
12000
|
if (!match || match.index === void 0) {
|
|
11923
12001
|
out.push({
|
|
11924
12002
|
kind: "text",
|
|
@@ -11930,7 +12008,7 @@ function parseInline(src) {
|
|
|
11930
12008
|
kind: "text",
|
|
11931
12009
|
text: rest.slice(0, match.index)
|
|
11932
12010
|
});
|
|
11933
|
-
const [full, code, boldStar, boldUnd, italStar, italUnd, linkText, linkHref] = match;
|
|
12011
|
+
const [full, code, boldStar, boldUnd, italStar, italUnd, linkText, linkHref, bare] = match;
|
|
11934
12012
|
if (code !== void 0) out.push({
|
|
11935
12013
|
kind: "code",
|
|
11936
12014
|
text: code
|
|
@@ -11945,7 +12023,7 @@ function parseInline(src) {
|
|
|
11945
12023
|
});
|
|
11946
12024
|
else if (linkHref !== void 0) {
|
|
11947
12025
|
const href = safeHref(linkHref);
|
|
11948
|
-
const children = parseInline(linkText ?? "");
|
|
12026
|
+
const children = parseInline(linkText ?? "").flatMap((n) => n.kind === "link" ? n.children : [n]);
|
|
11949
12027
|
out.push(href ? {
|
|
11950
12028
|
kind: "link",
|
|
11951
12029
|
href,
|
|
@@ -11954,11 +12032,25 @@ function parseInline(src) {
|
|
|
11954
12032
|
kind: "text",
|
|
11955
12033
|
text: linkText ?? ""
|
|
11956
12034
|
});
|
|
11957
|
-
}
|
|
12035
|
+
} else if (bare !== void 0) out.push({
|
|
12036
|
+
kind: "link",
|
|
12037
|
+
href: bare,
|
|
12038
|
+
children: [{
|
|
12039
|
+
kind: "text",
|
|
12040
|
+
text: bare
|
|
12041
|
+
}]
|
|
12042
|
+
});
|
|
11958
12043
|
rest = rest.slice(match.index + full.length);
|
|
11959
12044
|
}
|
|
11960
12045
|
return out.filter((n) => !(n.kind === "text" && n.text === ""));
|
|
11961
12046
|
}
|
|
12047
|
+
function sameOrigin(href) {
|
|
12048
|
+
try {
|
|
12049
|
+
return new URL(href).origin === window.location.origin;
|
|
12050
|
+
} catch {
|
|
12051
|
+
return false;
|
|
12052
|
+
}
|
|
12053
|
+
}
|
|
11962
12054
|
function renderInline(nodes, keyPrefix) {
|
|
11963
12055
|
return nodes.map((node, i) => {
|
|
11964
12056
|
const key = `${keyPrefix}-${i}`;
|
|
@@ -11972,9 +12064,11 @@ function renderInline(nodes, keyPrefix) {
|
|
|
11972
12064
|
}, key);
|
|
11973
12065
|
case "link": return /* @__PURE__ */ jsx("a", {
|
|
11974
12066
|
href: node.href,
|
|
11975
|
-
|
|
11976
|
-
|
|
11977
|
-
|
|
12067
|
+
...sameOrigin(node.href) ? {} : {
|
|
12068
|
+
target: "_blank",
|
|
12069
|
+
rel: "noopener noreferrer nofollow"
|
|
12070
|
+
},
|
|
12071
|
+
className: "underline underline-offset-2 [overflow-wrap:anywhere]",
|
|
11978
12072
|
children: renderInline(node.children, key)
|
|
11979
12073
|
}, key);
|
|
11980
12074
|
}
|
|
@@ -12046,7 +12140,7 @@ function parseBlocks(markdown) {
|
|
|
12046
12140
|
* briefly showing, and never a thrown parse error mid-stream.
|
|
12047
12141
|
*/
|
|
12048
12142
|
function WidgetMarkdown({ text }) {
|
|
12049
|
-
return parseBlocks(text).map((block, i) => {
|
|
12143
|
+
return parseBlocks(stripBidiControls(text)).map((block, i) => {
|
|
12050
12144
|
if (block.kind === "list") return /* @__PURE__ */ jsx(block.ordered ? "ol" : "ul", {
|
|
12051
12145
|
className: `my-1 space-y-1 ps-4 ${block.ordered ? "list-decimal" : "list-disc"}`,
|
|
12052
12146
|
children: block.items.map((item, j) => /* @__PURE__ */ jsx("li", { children: renderInline(parseInline(item), `b${i}-i${j}`) }, `b${i}-i${j}`))
|
|
@@ -12665,11 +12759,12 @@ function TypingDots({ label }) {
|
|
|
12665
12759
|
* it twice would be worse than announcing it once.
|
|
12666
12760
|
*/
|
|
12667
12761
|
function TranscriptEvent({ event, awaitingReply, messages }) {
|
|
12668
|
-
|
|
12669
|
-
|
|
12762
|
+
const key = event === void 0 ? void 0 : `${event}_event`;
|
|
12763
|
+
if (key === void 0 || !(key in defaultWidgetMessages)) return null;
|
|
12764
|
+
const handback = event !== "handoff";
|
|
12670
12765
|
return /* @__PURE__ */ jsxs("div", {
|
|
12671
12766
|
className: "wgt-turn-row flex flex-col items-center gap-1 py-1",
|
|
12672
|
-
"data-testid":
|
|
12767
|
+
"data-testid": `widget-${event}-event`,
|
|
12673
12768
|
"data-dock-follow": "",
|
|
12674
12769
|
children: [/* @__PURE__ */ jsxs("p", {
|
|
12675
12770
|
className: "flex w-full items-center gap-3 text-[11px] font-medium tracking-wide text-[var(--widget-foreground-muted)] [&:lang(ar)]:tracking-normal [&:lang(hi)]:tracking-normal",
|
|
@@ -12678,7 +12773,7 @@ function TranscriptEvent({ event, awaitingReply, messages }) {
|
|
|
12678
12773
|
"aria-hidden": "true",
|
|
12679
12774
|
className: "h-px flex-1 bg-[var(--widget-foreground-muted)]/25"
|
|
12680
12775
|
}),
|
|
12681
|
-
/* @__PURE__ */ jsx("span", { children:
|
|
12776
|
+
/* @__PURE__ */ jsx("span", { children: messages[key] ?? defaultWidgetMessages[key] }),
|
|
12682
12777
|
/* @__PURE__ */ jsx("span", {
|
|
12683
12778
|
"aria-hidden": "true",
|
|
12684
12779
|
className: "h-px flex-1 bg-[var(--widget-foreground-muted)]/25"
|
|
@@ -12959,7 +13054,7 @@ function VoiceWidgetWithRenderer({ renderer, state, turns, onToggleMic, onEndCal
|
|
|
12959
13054
|
};
|
|
12960
13055
|
const submit = async () => {
|
|
12961
13056
|
const text = draft.trim();
|
|
12962
|
-
if (text === ""
|
|
13057
|
+
if (text === "") return;
|
|
12963
13058
|
setSending(true);
|
|
12964
13059
|
setDraft("");
|
|
12965
13060
|
try {
|
|
@@ -13016,7 +13111,7 @@ function VoiceWidgetWithRenderer({ renderer, state, turns, onToggleMic, onEndCal
|
|
|
13016
13111
|
}) : shown.map((turn, i) => turn.speaker === "event" ? /* @__PURE__ */ jsx(TranscriptEvent, {
|
|
13017
13112
|
event: turn.event,
|
|
13018
13113
|
messages,
|
|
13019
|
-
awaitingReply: !shown.slice(i + 1).some((t) => t.
|
|
13114
|
+
awaitingReply: !shown.slice(i + 1).some((t) => t.event === "handoff" || t.event === "handback" || t.speaker === "agent" && t.text.trim() !== "")
|
|
13020
13115
|
}, `event-${i}`) : /* @__PURE__ */ jsxs("div", {
|
|
13021
13116
|
"data-dock-follow": "",
|
|
13022
13117
|
className: turn.speaker === "caller" ? "wgt-turn-row flex flex-col items-end" : "wgt-turn-row flex flex-col items-start",
|
|
@@ -13031,13 +13126,13 @@ function VoiceWidgetWithRenderer({ renderer, state, turns, onToggleMic, onEndCal
|
|
|
13031
13126
|
dir: textDirectionFor(turn.locale),
|
|
13032
13127
|
lang: turn.locale,
|
|
13033
13128
|
"data-testid": turn.speaker === "caller" ? "widget-turn-caller" : turn.filler === true ? "widget-turn-agent-filler" : "widget-turn-agent",
|
|
13034
|
-
className: `max-w-[85%] px-3.5 py-2 text-[14px] leading-[1.55] shadow-sm ${turn.speaker === "caller" ? "from-brand-plum to-brand-plum/90 text-[var(--widget-accent-foreground)] rounded-2xl rounded-ee-md bg-gradient-to-br" : turn.filler === true ? "rounded-2xl rounded-es-md border border-dashed border-[var(--widget-foreground-muted)]/50 bg-transparent text-[var(--widget-foreground-muted)] shadow-none" : AGENT_BUBBLE_CLASS}`,
|
|
13129
|
+
className: `max-w-[85%] px-3.5 py-2 text-[14px] leading-[1.55] shadow-sm [unicode-bidi:isolate] ${turn.speaker === "caller" ? "from-brand-plum to-brand-plum/90 text-[var(--widget-accent-foreground)] rounded-2xl rounded-ee-md bg-gradient-to-br" : turn.filler === true ? "rounded-2xl rounded-es-md border border-dashed border-[var(--widget-foreground-muted)]/50 bg-transparent text-[var(--widget-foreground-muted)] shadow-none" : AGENT_BUBBLE_CLASS}`,
|
|
13035
13130
|
children: turn.speaker === "agent" && turn.text === "" && turn.final === false ? /* @__PURE__ */ jsx(TypingDots, { label: messages.typing }) : turn.speaker === "agent" && turn.filler === true ? /* @__PURE__ */ jsxs("span", {
|
|
13036
13131
|
className: "flex items-center gap-2 italic",
|
|
13037
13132
|
children: [/* @__PURE__ */ jsx("span", { children: turn.text }), /* @__PURE__ */ jsx(TypingDots, { label: messages.typing })]
|
|
13038
13133
|
}) : turn.speaker === "agent" ? /* @__PURE__ */ jsx(WidgetMarkdown, { text: turn.text }) : /* @__PURE__ */ jsx("span", {
|
|
13039
13134
|
className: `whitespace-pre-wrap ${turn.final === false ? "italic opacity-70" : ""}`,
|
|
13040
|
-
children: turn.text
|
|
13135
|
+
children: stripBidiControls(turn.text)
|
|
13041
13136
|
})
|
|
13042
13137
|
}) : null,
|
|
13043
13138
|
turn.attachments && turn.attachments.length > 0 ? /* @__PURE__ */ jsx("div", {
|
|
@@ -14088,6 +14183,8 @@ var DEFAULT_SOCKET_PATH = "/socket.io";
|
|
|
14088
14183
|
var HANDOFF_EVENT_TURN_ID = "event-handoff";
|
|
14089
14184
|
/** Prefix of a hand-back transcript event's id, suffixed with its ordinal — see `markHandbackToAi`. */
|
|
14090
14185
|
var HANDBACK_EVENT_TURN_ID = "event-handback";
|
|
14186
|
+
/** The one line a failed boot shows: plain words, never a status code (SAA-434). */
|
|
14187
|
+
var BOOT_FAILED = "Could not start the conversation.";
|
|
14091
14188
|
/** Must equal `WIDGET_DESK_MESSAGE_EVENT` in `apps/api/src/realtime/widget-room.ts`. */
|
|
14092
14189
|
var DESK_MESSAGE_EVENT = "desk:message";
|
|
14093
14190
|
/** Must equal `WIDGET_DESK_TYPING_EVENT` in `apps/api/src/realtime/widget-room.ts`. */
|
|
@@ -14389,6 +14486,9 @@ function useChatSession(options) {
|
|
|
14389
14486
|
* `markHandbackToAi`.
|
|
14390
14487
|
*/
|
|
14391
14488
|
const replyInFlightRef = useRef(null);
|
|
14489
|
+
/** Turns sent while a reply streams, posted in order after it (SAA-434). */
|
|
14490
|
+
const queuedTurnsRef = useRef([]);
|
|
14491
|
+
const captureEventCountRef = useRef(0);
|
|
14392
14492
|
const pollTimerRef = useRef(void 0);
|
|
14393
14493
|
const pollIntervalRef = useRef(pollIntervalMs);
|
|
14394
14494
|
const mountedRef = useRef(true);
|
|
@@ -14597,11 +14697,11 @@ function useChatSession(options) {
|
|
|
14597
14697
|
for (const seq of returned) seqGapsRef.current.delete(seq);
|
|
14598
14698
|
lastSeqRef.current = top;
|
|
14599
14699
|
}
|
|
14600
|
-
const fresh = sorted.filter((t) => !seenSeqRef.current.has(t.seq));
|
|
14601
|
-
const repeats = sorted.filter((t) => seenSeqRef.current.has(t.seq));
|
|
14700
|
+
const fresh = sorted.filter((t) => t.role === "event" || !seenSeqRef.current.has(t.seq));
|
|
14701
|
+
const repeats = sorted.filter((t) => t.role !== "event" && seenSeqRef.current.has(t.seq));
|
|
14602
14702
|
if (fresh.length === 0 && repeats.length === 0) return;
|
|
14603
14703
|
if (fresh.some((t) => speakerFor(t.role) === "agent")) clearDeskTyping();
|
|
14604
|
-
for (const t of fresh) seenSeqRef.current.add(t.seq);
|
|
14704
|
+
for (const t of fresh) if (t.role !== "event") seenSeqRef.current.add(t.seq);
|
|
14605
14705
|
setTurns((prev) => {
|
|
14606
14706
|
const baseId = (id) => {
|
|
14607
14707
|
const colon = id.indexOf(":");
|
|
@@ -14624,7 +14724,14 @@ function useChatSession(options) {
|
|
|
14624
14724
|
});
|
|
14625
14725
|
if (unseen.length === 0) return corrected ? patched : prev;
|
|
14626
14726
|
const next = [...patched];
|
|
14627
|
-
for (const turn of unseen.map((t) =>
|
|
14727
|
+
for (const turn of unseen.map((t) => t.role === "event" ? {
|
|
14728
|
+
id: t.id,
|
|
14729
|
+
speaker: "event",
|
|
14730
|
+
event: t.event,
|
|
14731
|
+
text: "",
|
|
14732
|
+
final: true,
|
|
14733
|
+
seq: t.seq
|
|
14734
|
+
} : {
|
|
14628
14735
|
id: t.id,
|
|
14629
14736
|
speaker: speakerFor(t.role),
|
|
14630
14737
|
text: t.text ?? "",
|
|
@@ -14633,7 +14740,7 @@ function useChatSession(options) {
|
|
|
14633
14740
|
...t.attachments && t.attachments.length > 0 ? { attachments: t.attachments } : {},
|
|
14634
14741
|
...t.cards && Array.isArray(t.cards.items) && t.cards.items.length > 0 ? { cards: t.cards } : {},
|
|
14635
14742
|
...typeof t.operatorName === "string" && t.operatorName !== "" ? { operatorName: t.operatorName } : {}
|
|
14636
|
-
}))
|
|
14743
|
+
})) insertBySeq(next, turn);
|
|
14637
14744
|
return next;
|
|
14638
14745
|
});
|
|
14639
14746
|
}, [clearDeskTyping]);
|
|
@@ -14735,7 +14842,19 @@ function useChatSession(options) {
|
|
|
14735
14842
|
}
|
|
14736
14843
|
clearDeskTyping();
|
|
14737
14844
|
}, [clearDeskTyping]);
|
|
14738
|
-
|
|
14845
|
+
/** See {@link UseChatSessionResult.markCaptureAnswered}. */
|
|
14846
|
+
const markCaptureAnswered = useCallback((outcome) => {
|
|
14847
|
+
if (!mountedRef.current) return;
|
|
14848
|
+
const id = `event-capture-${captureEventCountRef.current += 1}`;
|
|
14849
|
+
setTurns((prev) => [...prev, {
|
|
14850
|
+
id,
|
|
14851
|
+
speaker: "event",
|
|
14852
|
+
event: outcome === "saved" ? "capture_saved" : "capture_declined",
|
|
14853
|
+
text: "",
|
|
14854
|
+
final: true
|
|
14855
|
+
}]);
|
|
14856
|
+
}, []);
|
|
14857
|
+
const poll = useCallback(async (detectHandoff, events) => {
|
|
14739
14858
|
const chatToken = chatTokenRef.current;
|
|
14740
14859
|
if (chatToken === void 0) return;
|
|
14741
14860
|
let afterSeq = lastSeqRef.current;
|
|
@@ -14743,11 +14862,15 @@ function useChatSession(options) {
|
|
|
14743
14862
|
for (const [seq, missedAt] of seqGapsRef.current) if (seenSeqRef.current.has(seq) || now - missedAt > SEQ_GAP_HOLD_MS) seqGapsRef.current.delete(seq);
|
|
14744
14863
|
else afterSeq = Math.min(afterSeq, seq - 1);
|
|
14745
14864
|
try {
|
|
14746
|
-
const res = await fetchImpl(withEmbedKeyParam(`${apiBase}/messages?afterSeq=${afterSeq}`, embedKey), { headers: { authorization: `Bearer ${chatToken}` } });
|
|
14865
|
+
const res = await fetchImpl(withEmbedKeyParam(`${apiBase}/messages?afterSeq=${afterSeq}${events ? "&events=1" : ""}`, embedKey), { headers: { authorization: `Bearer ${chatToken}` } });
|
|
14747
14866
|
if (!res.ok) return;
|
|
14748
14867
|
const body = await res.json();
|
|
14749
14868
|
const rows = body.messages ?? body.turns ?? [];
|
|
14750
14869
|
if (detectHandoff && Array.isArray(rows) && rows.some((t) => t.role === "human" && !seenSeqRef.current.has(t.seq))) markHandoffToHuman();
|
|
14870
|
+
if (events && Array.isArray(rows)) {
|
|
14871
|
+
const last = rows.filter((t) => t.event === "handoff" || t.event === "handback").pop();
|
|
14872
|
+
if (last) handoffEventAppendedRef.current = last.event === "handoff";
|
|
14873
|
+
}
|
|
14751
14874
|
mergeIncoming(rows, "poll");
|
|
14752
14875
|
} catch {}
|
|
14753
14876
|
}, [
|
|
@@ -14898,7 +15021,7 @@ function useChatSession(options) {
|
|
|
14898
15021
|
...hostRoutes !== void 0 ? { hostRoutes } : {}
|
|
14899
15022
|
})
|
|
14900
15023
|
});
|
|
14901
|
-
if (!res.ok) throw new Error(
|
|
15024
|
+
if (!res.ok) throw new Error(BOOT_FAILED);
|
|
14902
15025
|
const body = await res.json();
|
|
14903
15026
|
if (isStale?.() || !mountedRef.current) return;
|
|
14904
15027
|
const receivedAt = now();
|
|
@@ -14979,7 +15102,7 @@ function useChatSession(options) {
|
|
|
14979
15102
|
if (isMount && body.resumed === true) {
|
|
14980
15103
|
lastSeqRef.current = 0;
|
|
14981
15104
|
seqGapsRef.current.clear();
|
|
14982
|
-
poll();
|
|
15105
|
+
poll(false, true);
|
|
14983
15106
|
}
|
|
14984
15107
|
setStatus((prev) => prev === "escalated" ? prev : "idle");
|
|
14985
15108
|
scheduleRefresh(ttlMs);
|
|
@@ -15010,10 +15133,10 @@ function useChatSession(options) {
|
|
|
15010
15133
|
phase: "mount",
|
|
15011
15134
|
isStale: () => cancelled
|
|
15012
15135
|
});
|
|
15013
|
-
} catch
|
|
15136
|
+
} catch {
|
|
15014
15137
|
if (cancelled) return;
|
|
15015
15138
|
setStatus("error");
|
|
15016
|
-
setError(
|
|
15139
|
+
setError(BOOT_FAILED);
|
|
15017
15140
|
} finally {
|
|
15018
15141
|
if (!cancelled) setReady(true);
|
|
15019
15142
|
}
|
|
@@ -15035,10 +15158,10 @@ function useChatSession(options) {
|
|
|
15035
15158
|
const rebootSession = useCallback(async () => {
|
|
15036
15159
|
try {
|
|
15037
15160
|
await bootSession({ phase: "recovery" });
|
|
15038
|
-
} catch
|
|
15161
|
+
} catch {
|
|
15039
15162
|
if (!mountedRef.current) return;
|
|
15040
15163
|
setStatus("error");
|
|
15041
|
-
setError(
|
|
15164
|
+
setError(BOOT_FAILED);
|
|
15042
15165
|
}
|
|
15043
15166
|
}, [bootSession]);
|
|
15044
15167
|
/**
|
|
@@ -15308,14 +15431,32 @@ function useChatSession(options) {
|
|
|
15308
15431
|
*/
|
|
15309
15432
|
const postTurn = useCallback(async (payload, options) => {
|
|
15310
15433
|
const chatToken = chatTokenRef.current;
|
|
15311
|
-
if (chatToken === void 0
|
|
15434
|
+
if (chatToken === void 0) return false;
|
|
15312
15435
|
const text = "message" in payload ? payload.message : "";
|
|
15313
15436
|
const silent = options?.silent === true || !("message" in payload);
|
|
15314
|
-
const callerTurnId = `caller-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
15437
|
+
const callerTurnId = options?.queuedId ?? `caller-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
15315
15438
|
const agentTurnId = `agent-${callerTurnId}`;
|
|
15439
|
+
if (status === "streaming" || replyInFlightRef.current !== null && status !== "escalated") {
|
|
15440
|
+
if (options?.quietOnHttpError === true) return false;
|
|
15441
|
+
queuedTurnsRef.current.push({
|
|
15442
|
+
payload,
|
|
15443
|
+
options: {
|
|
15444
|
+
...options,
|
|
15445
|
+
...silent ? {} : { queuedId: callerTurnId }
|
|
15446
|
+
}
|
|
15447
|
+
});
|
|
15448
|
+
if (!silent) setTurns((prev) => [...prev, {
|
|
15449
|
+
id: callerTurnId,
|
|
15450
|
+
speaker: "caller",
|
|
15451
|
+
text,
|
|
15452
|
+
final: true,
|
|
15453
|
+
delivery: "sending"
|
|
15454
|
+
}]);
|
|
15455
|
+
return true;
|
|
15456
|
+
}
|
|
15316
15457
|
setTurns((prev) => [
|
|
15317
15458
|
...prev,
|
|
15318
|
-
...silent ? [] : [{
|
|
15459
|
+
...silent || options?.queuedId !== void 0 ? [] : [{
|
|
15319
15460
|
id: callerTurnId,
|
|
15320
15461
|
speaker: "caller",
|
|
15321
15462
|
text,
|
|
@@ -15330,9 +15471,15 @@ function useChatSession(options) {
|
|
|
15330
15471
|
}
|
|
15331
15472
|
]);
|
|
15332
15473
|
setStatus((prev) => prev === "escalated" ? prev : "streaming");
|
|
15333
|
-
|
|
15334
|
-
|
|
15474
|
+
const inFlight = [callerTurnId, agentTurnId];
|
|
15475
|
+
replyInFlightRef.current = inFlight;
|
|
15476
|
+
const release = () => {
|
|
15477
|
+
if (replyInFlightRef.current !== inFlight) return false;
|
|
15335
15478
|
replyInFlightRef.current = null;
|
|
15479
|
+
return true;
|
|
15480
|
+
};
|
|
15481
|
+
const rollBack = () => {
|
|
15482
|
+
release();
|
|
15336
15483
|
setTurns((prev) => prev.filter((t) => t.id !== callerTurnId && t.id !== agentTurnId));
|
|
15337
15484
|
};
|
|
15338
15485
|
const postChat = (cart) => fetchImpl(withEmbedKeyParam(`${apiBase}/chat`, embedKey), {
|
|
@@ -15368,7 +15515,7 @@ function useChatSession(options) {
|
|
|
15368
15515
|
if (!res.ok || res.body === null) {
|
|
15369
15516
|
rollBack();
|
|
15370
15517
|
setStatus("error");
|
|
15371
|
-
setError(
|
|
15518
|
+
setError(res.status === 400 ? "That message could not be sent. Please shorten it and try again." : "That message could not be sent. Please try again.");
|
|
15372
15519
|
return false;
|
|
15373
15520
|
}
|
|
15374
15521
|
if (mountedRef.current) setTurns((prev) => prev.map((t) => t.id === callerTurnId ? {
|
|
@@ -15401,7 +15548,7 @@ function useChatSession(options) {
|
|
|
15401
15548
|
});
|
|
15402
15549
|
},
|
|
15403
15550
|
onDone: (turnId) => {
|
|
15404
|
-
|
|
15551
|
+
release();
|
|
15405
15552
|
if (!mountedRef.current) return;
|
|
15406
15553
|
setTurns((prev) => prev.filter((t) => t.id !== turnId || t.id === agentTurnId).map((t) => t.id === agentTurnId ? {
|
|
15407
15554
|
...t,
|
|
@@ -15411,7 +15558,7 @@ function useChatSession(options) {
|
|
|
15411
15558
|
setStatus((prev) => prev === "escalated" ? prev : "idle");
|
|
15412
15559
|
},
|
|
15413
15560
|
onError: (message) => {
|
|
15414
|
-
|
|
15561
|
+
release();
|
|
15415
15562
|
if (!mountedRef.current) return;
|
|
15416
15563
|
setTurns((prev) => prev.map((t) => t.id === agentTurnId ? {
|
|
15417
15564
|
...t,
|
|
@@ -15422,7 +15569,12 @@ function useChatSession(options) {
|
|
|
15422
15569
|
},
|
|
15423
15570
|
isMounted: () => mountedRef.current
|
|
15424
15571
|
}).finally(() => {
|
|
15425
|
-
|
|
15572
|
+
if (!release() || !mountedRef.current) return;
|
|
15573
|
+
setTurns((prev) => prev.map((t) => t.id === agentTurnId ? {
|
|
15574
|
+
...t,
|
|
15575
|
+
final: true
|
|
15576
|
+
} : t));
|
|
15577
|
+
setStatus((prev) => prev === "streaming" ? "idle" : prev);
|
|
15426
15578
|
});
|
|
15427
15579
|
return true;
|
|
15428
15580
|
}, [
|
|
@@ -15433,6 +15585,21 @@ function useChatSession(options) {
|
|
|
15433
15585
|
markHandoffToHuman,
|
|
15434
15586
|
markHandbackToAi
|
|
15435
15587
|
]);
|
|
15588
|
+
useEffect(() => {
|
|
15589
|
+
if (status === "streaming" || replyInFlightRef.current !== null) return;
|
|
15590
|
+
if (status === "error") {
|
|
15591
|
+
const dropped = new Set(queuedTurnsRef.current.map((q) => q.options.queuedId));
|
|
15592
|
+
queuedTurnsRef.current = [];
|
|
15593
|
+
if (dropped.size > 0) setTurns((prev) => prev.filter((t) => !dropped.has(t.id)));
|
|
15594
|
+
return;
|
|
15595
|
+
}
|
|
15596
|
+
const next = queuedTurnsRef.current.shift();
|
|
15597
|
+
if (next) postTurn(next.payload, next.options);
|
|
15598
|
+
}, [
|
|
15599
|
+
status,
|
|
15600
|
+
turns,
|
|
15601
|
+
postTurn
|
|
15602
|
+
]);
|
|
15436
15603
|
const send = useCallback(async (text, options) => postTurn({ message: text }, options), [postTurn]);
|
|
15437
15604
|
const sendReport = useCallback(async (report, options) => postTurn({ report }, options?.quietOnHttpError === true ? { quietOnHttpError: true } : void 0), [postTurn]);
|
|
15438
15605
|
/**
|
|
@@ -15839,7 +16006,8 @@ function useChatSession(options) {
|
|
|
15839
16006
|
notifyTyping,
|
|
15840
16007
|
checkout,
|
|
15841
16008
|
sendAttachment,
|
|
15842
|
-
markHandoffToHuman
|
|
16009
|
+
markHandoffToHuman,
|
|
16010
|
+
markCaptureAnswered
|
|
15843
16011
|
};
|
|
15844
16012
|
}
|
|
15845
16013
|
/**
|
|
@@ -18559,6 +18727,8 @@ function ConciergeHost({ renderer, embedKey, apiBase, socketUrl, socketPath, bri
|
|
|
18559
18727
|
autoFocus: !inCallRef.current,
|
|
18560
18728
|
submit: session.submitCapture,
|
|
18561
18729
|
onAnswered: (outcome) => {
|
|
18730
|
+
setCaptureCard(null);
|
|
18731
|
+
session.markCaptureAnswered(outcome);
|
|
18562
18732
|
if (!inCallRef.current) session.sendReport({
|
|
18563
18733
|
kind: "capture_card",
|
|
18564
18734
|
field: event.field,
|
|
@@ -19661,4 +19831,4 @@ function ConciergeHost({ renderer, embedKey, apiBase, socketUrl, socketPath, bri
|
|
|
19661
19831
|
});
|
|
19662
19832
|
}
|
|
19663
19833
|
//#endregion
|
|
19664
|
-
export {
|
|
19834
|
+
export { DOCK_STATES as $, WIDGET_THEME_TOKENS as $t, stripBidiControls as A, BotFace as An, SHEET_EXPANDED_VH as At, edgeOf as B, persistAlign as Bt, readsAsCartViewIntent as C, widgetMessagesFromCopy as Cn, MOBILE_MARGIN as Ct, WidgetCardList as D, isWidgetAvatar as Dn, RADII as Dt, WidgetCartSummary as E, WIDGET_AVATARS as En, PROACTIVE_NUDGE_MS as Et, ConciergeShell as F, SHORT_VIEWPORT as Ft, IDLE_SNAPSHOT as G, readStoredMinimised as Gt, panelClasses as H, pillAnchor as Ht, ConciergeLauncher as I, Z_INDEX as It, SESSION_EVENTS as J, snapAlign as Jt, botStateFor as K, rowWidthLen as Kt, CONCIERGE_POSITIONS as L, bottomLen as Lt, DockRenderer as M, cn as Mn, SHEET_PEEK_MAX as Mt, ShellRenderer as N, SHEET_TOP_CLEARANCE as Nt, WidgetMarkdown as O, KNOT_PATH as On, ROW_H as Ot, deriveWidgetView as P, SHEET_TUCK as Pt, Dock as Q, SYSTEM_FONT_STACK as Qt, DEFAULT_CONCIERGE_POSITION as R, containerAnchor as Rt, basketIntentFromTurns as S, resolveWidgetMessages as Sn, MARK as St, textDirectionFor as T, DEFAULT_WIDGET_AVATAR as Tn, PILL_MARK as Tt, positionClasses as U, readStored as Ut, nearestPosition as V, persistMinimised as Vt, positionForArrow as W, readStoredAlign as Wt, formatMs as X, CARD_RADIUS_MAX_PX as Xt, SessionLog as Y, writeStored as Yt, latencyBetween as Z, SHEET_RADIUS_MAX_PX as Zt, isSameOriginPath as _, rotateHue as _n, DRAG_CLICK_WINDOW_MS as _t, MAX_REPORTED_CART_LINES as a, hexToOklab as an, idleConciergeInput as at, VoiceWidget as b, defaultWidgetMessages as bn, FLOAT_GAP as bt, deriveCallPhase as c, linearToSrgb as cn, ACTIVITY_W as ct, resolveCheckoutUrl as d, oklabToLinearRgb as dn, DESKTOP_BOTTOM as dt, deriveTheme as en, deriveDockState as et, toChatCart as f, oklabToOklch as fn, DESKTOP_BREAKPOINT as ft, CHECKOUT_CAPTURE_REQUIRED as g, relativeLuminance as gn, DOCK_MINIMISED_STORAGE_KEY as gt, useVoiceSession as h, parseHex as hn, DOCK_ALIGN_STORAGE_KEY as ht, ConciergeWidget as i, formatHex as in, deriveConciergeState as it, rendererFor as j, labelProps as jn, SHEET_GAP as jt, parseBlocks as k, RopeKnot as kn, SHEET_EXPANDED_DESKTOP_MAX as kt, mergeAddedCartLine as l, mixToward as ln, BOTTOM_FLOOR as lt, createWidgetVoiceTokenFetcher as m, oklchToOklab as mn, DESKTOP_WIDTHS as mt, CART_LINE_VARIANT_ID_SHAPE as n, themeToInlineStyle as nn, idleDockInput as nt, cartLinesFromSnapshot as o, hexToOklch as on, formatMoney as ot, ROOM_EVENTS as p, oklchToHex as pn, DESKTOP_GUTTER as pt, SseFrameParser as q, sheetMaxHeightLen as qt, ConciergeHost as r, contrastRatio as rn, CONCIERGE_STATES as rt, chooseOptionsAction as s, linearRgbToOklab as sn, WIDGET_MESSAGE_MAX_LENGTH as st, CART_LINE_PLATFORM_VARIANT_ID_SHAPE as t, themeToCss as tn, deriveDockView as tt, resolveAddToCartHandler as u, oklabToHex as un, CONTROL as ut, useChatSession as v, srgbToLinear as vn, DRAG_TAP_SLOP_PX as vt, readsAsCheckoutIntent as w, MorphingLoader as wn, PILL_H as wt, VoiceWidgetWithRenderer as x, formatMessage as xn, GLASS_IDLE_MS as xt, detectPage as y, withAlpha as yn, FLOAT_DUCK_DISMISS_MS as yt, alignOf as z, geometryVars as zt };
|