@saar-ai/web-widget 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +209 -0
  2. package/dist/bot-avatar.d.ts +41 -0
  3. package/dist/bot-avatar.d.ts.map +1 -0
  4. package/dist/bot-face.d.ts +39 -0
  5. package/dist/bot-face.d.ts.map +1 -0
  6. package/dist/bot-state.d.ts +39 -0
  7. package/dist/bot-state.d.ts.map +1 -0
  8. package/dist/chunks/chat-ZLxYRTml.js +173 -0
  9. package/dist/chunks/esm-DSxqq2-d.js +3299 -0
  10. package/dist/chunks/host-widget-iy3qC-1p.js +7677 -0
  11. package/dist/chunks/livekit-client.esm-OPuvn_z-.js +26600 -0
  12. package/dist/chunks/schemas-Bl_6mxe4.js +4123 -0
  13. package/dist/chunks/telemetry-Bw-3F_Zk.js +290 -0
  14. package/dist/cn.d.ts +14 -0
  15. package/dist/cn.d.ts.map +1 -0
  16. package/dist/concierge-launcher.d.ts +50 -0
  17. package/dist/concierge-launcher.d.ts.map +1 -0
  18. package/dist/concierge-shell.d.ts +194 -0
  19. package/dist/concierge-shell.d.ts.map +1 -0
  20. package/dist/error-boundary.d.ts +34 -0
  21. package/dist/error-boundary.d.ts.map +1 -0
  22. package/dist/format-money.d.ts +20 -0
  23. package/dist/format-money.d.ts.map +1 -0
  24. package/dist/generated/widget-css.d.ts +2 -0
  25. package/dist/generated/widget-css.d.ts.map +1 -0
  26. package/dist/host-widget.d.ts +165 -0
  27. package/dist/host-widget.d.ts.map +1 -0
  28. package/dist/index.d.ts +28 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +583 -0
  31. package/dist/messages.d.ts +116 -0
  32. package/dist/messages.d.ts.map +1 -0
  33. package/dist/morphing-loader.d.ts +16 -0
  34. package/dist/morphing-loader.d.ts.map +1 -0
  35. package/dist/mount.d.ts +45 -0
  36. package/dist/mount.d.ts.map +1 -0
  37. package/dist/next/index.d.ts +3 -0
  38. package/dist/next/index.d.ts.map +1 -0
  39. package/dist/next/index.js +86 -0
  40. package/dist/next/use-next-bridge.d.ts +113 -0
  41. package/dist/next/use-next-bridge.d.ts.map +1 -0
  42. package/dist/position.d.ts +65 -0
  43. package/dist/position.d.ts.map +1 -0
  44. package/dist/session-log.d.ts +84 -0
  45. package/dist/session-log.d.ts.map +1 -0
  46. package/dist/session-panel.d.ts +15 -0
  47. package/dist/session-panel.d.ts.map +1 -0
  48. package/dist/sse-parser.d.ts +38 -0
  49. package/dist/sse-parser.d.ts.map +1 -0
  50. package/dist/styles.d.ts +19 -0
  51. package/dist/styles.d.ts.map +1 -0
  52. package/dist/text-direction.d.ts +49 -0
  53. package/dist/text-direction.d.ts.map +1 -0
  54. package/dist/use-chat-session.d.ts +344 -0
  55. package/dist/use-chat-session.d.ts.map +1 -0
  56. package/dist/use-voice-session.d.ts +273 -0
  57. package/dist/use-voice-session.d.ts.map +1 -0
  58. package/dist/voice-session-state.d.ts +44 -0
  59. package/dist/voice-session-state.d.ts.map +1 -0
  60. package/dist/voice-widget.d.ts +167 -0
  61. package/dist/voice-widget.d.ts.map +1 -0
  62. package/dist/widget-cards.d.ts +69 -0
  63. package/dist/widget-cards.d.ts.map +1 -0
  64. package/dist/widget-cart-summary.d.ts +66 -0
  65. package/dist/widget-cart-summary.d.ts.map +1 -0
  66. package/dist/widget-markdown.d.ts +33 -0
  67. package/dist/widget-markdown.d.ts.map +1 -0
  68. package/dist/widget.css +2 -0
  69. package/package.json +88 -0
  70. package/src/styles/concierge.css +351 -0
  71. package/src/styles/tokens.css +67 -0
  72. package/src/styles/widget-entry.css +13 -0
@@ -0,0 +1,116 @@
1
+ /**
2
+ * The widget's injected message catalogue — docs/WIDGET_EMBED_PLAN.md §4
3
+ * Phase 3, coupling (1). Replaces the `useTranslations('widget')` calls this
4
+ * package used to make directly against `next-intl`, which dragged Next into
5
+ * a package that must build and ship without it.
6
+ *
7
+ * ## Who supplies what
8
+ *
9
+ * This package owns no locale of its own and never calls `next-intl` (or any
10
+ * i18n library) directly — every component that used to call `t(key)` now
11
+ * reads `messages[key]` from a prop instead. `defaultWidgetMessages` below is
12
+ * the brand-neutral, English fallback shipped WITH the package, for a host
13
+ * that has no translation catalogue of its own (the CDN embed, a bare
14
+ * `ConciergeWidget` usage). `apps/web` — which already has `next-intl` — is a
15
+ * thin adapter: it reads its own `widget` namespace with `t.raw(key)` (raw,
16
+ * NOT pre-interpolated — see `formatMessage` below for why) and passes the
17
+ * result down as `messages`.
18
+ *
19
+ * `PublicWidgetConfig.copy` (`greeting`/`placeholder`/`offlineMessage`) is a
20
+ * SEPARATE, narrower source: tenant-authored strings for the handful of keys
21
+ * that actually exist on that type. `widgetMessagesFromCopy` maps the overlap
22
+ * (`placeholder` → `type_placeholder`); it is not a substitute for a real
23
+ * message catalogue and never claims to translate the rest of the widget.
24
+ *
25
+ * ## No brand literal here
26
+ *
27
+ * `tools/check-branding.mjs` forbids a hardcoded product name outside
28
+ * `@wesence/branding` — the state labels below carry `{product}` as a
29
+ * literal placeholder token, interpolated by the CALLER (see
30
+ * `bot-avatar.tsx`, which passes `{ product: branding.name }`), never baked
31
+ * in here.
32
+ */
33
+ export interface WidgetMessages {
34
+ readonly state_idle: string;
35
+ readonly state_listening: string;
36
+ readonly state_thinking: string;
37
+ readonly state_speaking: string;
38
+ readonly mic_start: string;
39
+ readonly mic_stop: string;
40
+ readonly open: string;
41
+ readonly minimize: string;
42
+ readonly conversation: string;
43
+ readonly empty: string;
44
+ readonly type_placeholder: string;
45
+ readonly send: string;
46
+ readonly move: string;
47
+ readonly call_end: string;
48
+ readonly escalated_banner: string;
49
+ readonly typing: string;
50
+ readonly suggestions_label: string;
51
+ readonly suggestion_1: string;
52
+ readonly suggestion_2: string;
53
+ readonly suggestion_3: string;
54
+ readonly attach_label: string;
55
+ readonly attach_uploading: string;
56
+ readonly attach_error: string;
57
+ readonly attach_image_alt: string;
58
+ readonly attach_download_hint: string;
59
+ readonly add_to_cart: string;
60
+ readonly adding_to_cart: string;
61
+ readonly added_to_cart: string;
62
+ readonly unavailable: string;
63
+ readonly see_all: string;
64
+ readonly cart_summary_title: string;
65
+ readonly cart_summary_total: string;
66
+ readonly checkout_now: string;
67
+ readonly checkout_failed: string;
68
+ }
69
+ /**
70
+ * Message keys that carry a `{product}` placeholder — the avatar's
71
+ * accessible-name states. Kept as a literal template, interpolated at
72
+ * render time, never a brand name baked into this file (see the module doc
73
+ * comment).
74
+ */
75
+ export declare const defaultWidgetMessages: WidgetMessages;
76
+ /**
77
+ * Interpolates `{token}` placeholders in a message template. Deliberately the
78
+ * same `{token}` syntax `next-intl`'s ICU messages use for a plain variable,
79
+ * so `apps/web`'s adapter can hand this package `t.raw(key)` (the
80
+ * UN-interpolated template) and let this one function do the substitution —
81
+ * one interpolation implementation, not two.
82
+ *
83
+ * A token with no matching var, or a var that isn't a string/number, is left
84
+ * as literal text rather than thrown on — a missing translation must degrade
85
+ * to a visibly-odd string, never a broken render.
86
+ */
87
+ export declare function formatMessage(template: string, vars?: Record<string, string | number>): string;
88
+ /**
89
+ * Merges tenant-authored overrides (typically the `widgetMessagesFromCopy`
90
+ * result) over `defaultWidgetMessages`. An override that is `undefined`,
91
+ * empty, or whitespace-only is skipped — a blank tenant string must not blank
92
+ * out a working default, same "absent means unset" contract
93
+ * `PublicWidgetConfig.copy`'s own fields carry.
94
+ */
95
+ export declare function resolveWidgetMessages(overrides?: Partial<WidgetMessages>): WidgetMessages;
96
+ /**
97
+ * The narrow slice of `WidgetMessages` `PublicWidgetConfig.copy` can actually
98
+ * supply — see the module doc comment. Structurally typed (not imported from
99
+ * `apps/api`) so this package never depends on the api app.
100
+ */
101
+ export interface WidgetCopyLike {
102
+ readonly greeting?: string;
103
+ readonly placeholder?: string;
104
+ readonly offlineMessage?: string;
105
+ }
106
+ /**
107
+ * Maps `PublicWidgetConfig.copy`'s fields onto the `WidgetMessages` keys they
108
+ * overlap with. `greeting` is deliberately NOT mapped here — it seeds the
109
+ * first turn (`SessionBootResponse.greeting`), it is not a UI label, so a
110
+ * caller that wants it has it already from the session boot response.
111
+ * `offlineMessage` has no current `WidgetMessages` counterpart (nothing here
112
+ * renders an "offline" state yet) and is likewise omitted rather than
113
+ * guessed onto the nearest-sounding key.
114
+ */
115
+ export declare function widgetMessagesFromCopy(copy: WidgetCopyLike | undefined): Partial<WidgetMessages>;
116
+ //# sourceMappingURL=messages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CAClC;AAED;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,EAAE,cAmCnC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,CAM9F;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,cAAc,CAOzF;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,cAAc,GAAG,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,CAGhG"}
@@ -0,0 +1,16 @@
1
+ interface MorphingLoaderProps {
2
+ size?: 'sm' | 'md' | 'lg' | 'full';
3
+ variant?: 'brand' | 'light';
4
+ className?: string;
5
+ label?: string;
6
+ }
7
+ /**
8
+ * A voice-frequency visualizer loader.
9
+ *
10
+ * Six soft vertical bars rise and fall like a calm voice waveform,
11
+ * using the plum brand family with no amber or yellow tints.
12
+ * Respects prefers-reduced-motion by resting the bars at mid-height.
13
+ */
14
+ export declare function MorphingLoader({ size, variant, className, label, }: MorphingLoaderProps): import("react").JSX.Element;
15
+ export {};
16
+ //# sourceMappingURL=morphing-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"morphing-loader.d.ts","sourceRoot":"","sources":["../src/morphing-loader.tsx"],"names":[],"mappings":"AAEA,UAAU,mBAAmB;IAC3B,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC;IACnC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,EAC7B,IAAW,EACX,OAAiB,EACjB,SAAS,EACT,KAAiB,GAClB,EAAE,mBAAmB,+BAwErB"}
@@ -0,0 +1,45 @@
1
+ import { type ConciergeWidgetProps } from './host-widget.js';
2
+ export interface MountedWidget {
3
+ /** Unmounts the React tree and detaches nothing else — the shadow root stays on `host` (removing it is the caller's own DOM to own). */
4
+ unmount(): void;
5
+ }
6
+ /**
7
+ * Mounts the widget into `host` inside a NEW `attachShadow({ mode: 'open' })`
8
+ * root — docs/WIDGET_EMBED_PLAN.md §4 Phase 3, coupling (6). The CDN embed's
9
+ * mount point; a Next.js host renders `ConciergeWidget` directly instead (no
10
+ * shadow DOM, no `mountConciergeWidget` call — see that component's doc comment).
11
+ *
12
+ * ## Style isolation, precisely
13
+ *
14
+ * A shadow root already stops the HOST page's selectors from matching
15
+ * anything inside it (and vice versa) — that part is free, standard shadow
16
+ * DOM behaviour. What is NOT free is INHERITED properties (`font-family`,
17
+ * `color`, `line-height`, and every custom property): those cross the shadow
18
+ * boundary by the normal CSS inheritance algorithm, shadow root or not. A
19
+ * host page with `* { font-family: "Comic Sans MS" }` would still paint the
20
+ * widget in Comic Sans without this. `all: initial` on `host` resets EVERY
21
+ * inherited (and non-inherited) property back to its initial value at that
22
+ * element — severing the inheritance chain entirely — and this function then
23
+ * sets the widget's own baseline type scale explicitly, so the reset does
24
+ * not also blank out reasonable defaults (a `font-size: medium`/
25
+ * `line-height: normal` UA default is not what this widget wants either).
26
+ *
27
+ * ## Why `adoptedStyleSheets` first, a `<style>` element as fallback
28
+ *
29
+ * `adoptedStyleSheets` shares one parsed `CSSStyleSheet` across every mount
30
+ * on a page (multiple widget instances, or a re-mount) with no re-parse cost
31
+ * and no extra `<style>` node per instance. Not universal — Safari < 16.4
32
+ * lacks `Document.adoptedStyleSheets`/`ShadowRoot.adoptedStyleSheets` (a real
33
+ * install base for a merchant embed) — so a `<style>` element inside the
34
+ * shadow root is the fallback, functionally equivalent, just without the
35
+ * sharing.
36
+ */
37
+ export declare function mountConciergeWidget(host: HTMLElement, props: ConciergeWidgetProps): MountedWidget;
38
+ /**
39
+ * `adoptedStyleSheets` when the browser has it; a `<style>` element otherwise
40
+ * — see `mountConciergeWidget`'s doc comment. Exported (not just used
41
+ * internally) so `cdn/ui.ts` can adopt the same stylesheet into the shadow
42
+ * root `core.ts` already created, without a second `attachShadow` call.
43
+ */
44
+ export declare function adoptWidgetStylesheet(shadow: ShadowRoot): void;
45
+ //# sourceMappingURL=mount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"AAIA,OAAO,EAAmB,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAG9E,MAAM,WAAW,aAAa;IAC5B,wIAAwI;IACxI,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,oBAAoB,GAC1B,aAAa,CAqCf;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAiB9D"}
@@ -0,0 +1,3 @@
1
+ export * from './use-next-bridge.js';
2
+ export { ConciergeWidget, type ConciergeWidgetProps } from '../host-widget.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/next/index.ts"],"names":[],"mappings":"AAcA,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,86 @@
1
+ import { s as detectPage, t as ConciergeWidget } from "../chunks/host-widget-iy3qC-1p.js";
2
+ import { useCallback, useEffect, useMemo, useRef } from "react";
3
+ import { usePathname, useRouter } from "next/navigation";
4
+ //#region src/next/use-next-bridge.ts
5
+ function useNextBridge(options = {}) {
6
+ const router = useRouter();
7
+ const pathname = usePathname();
8
+ const listenersRef = useRef(/* @__PURE__ */ new Set());
9
+ const routerRef = useRef(router);
10
+ routerRef.current = router;
11
+ const pathnameRef = useRef(pathname);
12
+ pathnameRef.current = pathname;
13
+ const readPageKey = useCallback(() => typeof window === "undefined" ? pathnameRef.current : window.location.href, []);
14
+ const lastPageKeyRef = useRef(void 0);
15
+ const notifyIfPageChanged = useCallback(() => {
16
+ const key = readPageKey();
17
+ if (lastPageKeyRef.current === key) return;
18
+ lastPageKeyRef.current = key;
19
+ for (const listener of listenersRef.current) listener();
20
+ }, [readPageKey]);
21
+ useEffect(() => {
22
+ notifyIfPageChanged();
23
+ }, [pathname, notifyIfPageChanged]);
24
+ useEffect(() => {
25
+ if (typeof window === "undefined") return;
26
+ lastPageKeyRef.current ??= readPageKey();
27
+ const history = window.history;
28
+ const originalPush = history.pushState;
29
+ const originalReplace = history.replaceState;
30
+ const onPopState = () => notifyIfPageChanged();
31
+ history.pushState = function patchedPushState(...args) {
32
+ originalPush.apply(history, args);
33
+ notifyIfPageChanged();
34
+ };
35
+ history.replaceState = function patchedReplaceState(...args) {
36
+ originalReplace.apply(history, args);
37
+ notifyIfPageChanged();
38
+ };
39
+ window.addEventListener("popstate", onPopState);
40
+ return () => {
41
+ history.pushState = originalPush;
42
+ history.replaceState = originalReplace;
43
+ window.removeEventListener("popstate", onPopState);
44
+ };
45
+ }, [notifyIfPageChanged, readPageKey]);
46
+ const navigate = useCallback((url) => {
47
+ routerRef.current.push(url);
48
+ }, []);
49
+ const currentPage = useCallback(() => {
50
+ if (typeof document === "undefined" || typeof window === "undefined") return {
51
+ path: pathnameRef.current,
52
+ kind: "other"
53
+ };
54
+ const result = detectPage(document, window.location);
55
+ const entityId = result.product?.productId ?? result.collection?.collectionId;
56
+ return {
57
+ path: window.location.pathname,
58
+ kind: result.pageKind,
59
+ ...entityId !== void 0 ? { entityId } : {}
60
+ };
61
+ }, []);
62
+ const onPageChange = useCallback((cb) => {
63
+ listenersRef.current.add(cb);
64
+ return () => {
65
+ listenersRef.current.delete(cb);
66
+ };
67
+ }, []);
68
+ const { addToCart, applyFilter, readCart } = options;
69
+ return useMemo(() => ({
70
+ currentPage,
71
+ onPageChange,
72
+ navigate,
73
+ ...addToCart ? { addToCart } : {},
74
+ ...applyFilter ? { applyFilter } : {},
75
+ ...readCart ? { readCart } : {}
76
+ }), [
77
+ currentPage,
78
+ onPageChange,
79
+ navigate,
80
+ addToCart,
81
+ applyFilter,
82
+ readCart
83
+ ]);
84
+ }
85
+ //#endregion
86
+ export { ConciergeWidget, useNextBridge };
@@ -0,0 +1,113 @@
1
+ import { type HostBridge } from '@saar-ai/widget-bridge';
2
+ /**
3
+ * The published `HostBridge` for a Next.js host — `@saar-ai/web-widget/next`
4
+ * (docs/WIDGET_EMBED_PLAN.md §4 Phase 5). Moved here from
5
+ * `apps/web/src/components/demo-store/use-next-bridge.ts` (that file's own
6
+ * doc comment called this move out as the Phase 5 plan from the day it was
7
+ * written) — same `navigate`/`onPageChange` wiring, same behaviour for the
8
+ * demo store, with two additions a package-level adapter can make that an
9
+ * app-local one had no reason to:
10
+ *
11
+ * 1. **`currentPage()` delegates to `@saar-ai/widget-bridge`'s detection
12
+ * ladder** (`detectPage`) instead of returning a hardcoded `'other'` —
13
+ * the demo store never needed real classification because its own
14
+ * card/cart wiring never read `currentPage()`, but a generic Next.js host
15
+ * of this package has no such out. Same JSON-LD → microdata → OpenGraph →
16
+ * URL/DOM-heuristics → `'other'` ladder `GenericBridge` runs, called with
17
+ * the real `document`/`window.location` (guarded — see SSR safety below).
18
+ * 2. **`addToCart`/`applyFilter`/`readCart` are accepted as options**, so a
19
+ * host with real cart wiring of its own can hand this bridge a complete
20
+ * `HostBridge` rather than only `navigate`. Absent (the default) ⇒ the
21
+ * widget's own degraded paths apply exactly as documented on `HostBridge`
22
+ * itself (`resolveAddToCartHandler` navigates to the PDP when `addToCart`
23
+ * is missing).
24
+ *
25
+ * ## Stable identity — `useMemo`, not a fresh object every render
26
+ *
27
+ * The documented usage is `const bridge = useNextBridge(); useEffect(() => {
28
+ * const tracker = new PageTracker({ bridge, collector }); tracker.start(...);
29
+ * return () => tracker.destroy(); }, [bridge]);` (`@saar-ai/widget-bridge`'s
30
+ * `PageTracker`). Without `useMemo` below, EVERY render of the component
31
+ * calling this hook handed that effect a new `HostBridge` object — a parent
32
+ * re-render wholly unrelated to navigation was enough to tear down and
33
+ * rebuild the tracker, which re-emits `page.viewed`/`product.viewed` (a
34
+ * fresh `PageViewDeduper` each time has no memory of what it already
35
+ * reported) and re-fires `session.started` on every single re-render: an
36
+ * unbounded event storm, not a page-view count.
37
+ *
38
+ * The fix is `useMemo`, keyed on `currentPage`/`onPageChange`/`navigate`/
39
+ * `addToCart`/`applyFilter`/`readCart` — and each of THOSE is itself held
40
+ * stable (see below) so the memoized bridge's identity survives ordinary
41
+ * re-renders *and* navigation, exactly matching `PageTracker`'s own design:
42
+ * it is not supposed to be re-constructed on every page change, it is
43
+ * supposed to learn about page changes through `onPageChange`'s
44
+ * subscription. `navigate`/`currentPage`/`onPageChange` therefore read
45
+ * `router`/the live pathname through REFS rather than closing over them via
46
+ * a `useCallback` dependency array — a dependency on `pathname` would
47
+ * recreate the callback (and, transitively, the memoized bridge) on every
48
+ * navigation, defeating the entire point of the subscription model this
49
+ * hook is meant to support.
50
+ *
51
+ * ## `currentPage().path` reads the LIVE location, not a captured `pathname`
52
+ *
53
+ * `kind`/`entityId` already come from `detectPage(document, window.location)`
54
+ * — i.e. the live DOM, read fresh on every call. `path` used to come from
55
+ * the `pathname` this hook's own render closed over; once `currentPage` is
56
+ * held referentially stable (necessary for the identity fix above), that
57
+ * closure would freeze `path` at whatever it was on the render that FIRST
58
+ * created the stable callback — permanently, since the callback body never
59
+ * runs again to pick up a new `pathname`. So `path` is read the same way
60
+ * `kind`/`entityId` are: straight off `window.location.pathname` at call
61
+ * time. SSR (no `window`) falls back to `pathnameRef.current`, which is
62
+ * kept current every render via a plain assignment (the same "read a fresh
63
+ * value off a ref rather than depend on it" pattern used for `router`
64
+ * below) — never stale beyond the render in which the SSR fallback path is
65
+ * actually taken.
66
+ *
67
+ * ## Query-only navigations are real page changes too
68
+ *
69
+ * `usePathname()` alone misses `/search?q=mug` → `/search?q=kettle` (the
70
+ * pathname is unchanged) and any facet-filter navigation that only rewrites
71
+ * the query string — `search.performed`'s payload lives entirely in the
72
+ * query.
73
+ *
74
+ * `useSearchParams()` is the obvious reach and is deliberately NOT used:
75
+ * calling it opts the calling page into Next's client-side-rendering
76
+ * bailout, so every host page rendering this widget would have to sit
77
+ * inside its own `<Suspense>` boundary or fail `next build` outright
78
+ * ("useSearchParams() should be wrapped in a suspense boundary"). A library
79
+ * hook must not impose a Suspense boundary on its host's page tree — this
80
+ * was caught by `apps/web`'s own production build, which is exactly the
81
+ * failure a merchant would have hit.
82
+ *
83
+ * Instead the query is watched the way `GenericBridge` already watches it
84
+ * for the CDN embed: `popstate` plus a patched `history.pushState`/
85
+ * `replaceState`, compared on the full `location.href`. Same mechanism,
86
+ * same semantics, no framework bailout — and it also catches a query
87
+ * rewrite performed by non-Next code on the host page, which
88
+ * `useSearchParams()` would have missed anyway.
89
+ *
90
+ * ## SSR safety
91
+ *
92
+ * `useRouter()`/`usePathname()` are real Next.js hooks —
93
+ * this module only ever runs where Next has already set up its App Router
94
+ * context, which means client components. `currentPage()`'s body is the one
95
+ * place that touches `document`/`window` directly (`detectPage` needs a live
96
+ * DOM), and it is guarded: `typeof document === 'undefined'` degrades to
97
+ * `'other'` exactly like `GenericBridge.currentPage()` does when constructed
98
+ * with no `window`/`document`, rather than throwing during a server render
99
+ * that somehow reaches this far. IMPORTING this module never touches the
100
+ * DOM — nothing above module scope references `document`/`window` — which is
101
+ * what makes it safe to import from a server component tree that never
102
+ * calls the hook at all.
103
+ */
104
+ export interface UseNextBridgeOptions {
105
+ /** Host-supplied cart mutation. Absent ⇒ the widget degrades to a PDP `navigate`. */
106
+ readonly addToCart?: HostBridge['addToCart'];
107
+ /** Host-supplied filter application. Absent ⇒ the widget degrades to a filtered-URL `navigate`. */
108
+ readonly applyFilter?: HostBridge['applyFilter'];
109
+ /** Host-supplied cart read. Absent ⇒ the widget has no cart-aware upsell context. */
110
+ readonly readCart?: HostBridge['readCart'];
111
+ }
112
+ export declare function useNextBridge(options?: UseNextBridgeOptions): HostBridge;
113
+ //# sourceMappingURL=use-next-bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-next-bridge.d.ts","sourceRoot":"","sources":["../../src/next/use-next-bridge.ts"],"names":[],"mappings":"AAIA,OAAO,EAAc,KAAK,UAAU,EAAiB,MAAM,wBAAwB,CAAC;AAEpF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqGG;AACH,MAAM,WAAW,oBAAoB;IACnC,qFAAqF;IACrF,QAAQ,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IAC7C,mGAAmG;IACnG,QAAQ,CAAC,WAAW,CAAC,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC;IACjD,qFAAqF;IACrF,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;CAC5C;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,GAAG,UAAU,CA+G5E"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Where the concierge sits on the host page, and how a visitor moves it.
3
+ *
4
+ * Six anchors, not four. The two centres exist because the launcher is a PILL
5
+ * with a label on it now, not a round button: a wide control tucked into a
6
+ * corner reads as an ad, and the middle of an edge is where a host page's own
7
+ * content is least likely to be. The corners remain because they are where a
8
+ * tenant with a fixed footer or a cookie bar needs it.
9
+ *
10
+ * The tenant picks the default in the widget config; a visitor may drag it
11
+ * somewhere else, and where they put it is theirs — see `nearestPosition`.
12
+ */
13
+ export declare const CONCIERGE_POSITIONS: readonly ['top-left', 'top-center', 'top-right', 'bottom-left', 'bottom-center', 'bottom-right'];
14
+ export type ConciergePosition = (typeof CONCIERGE_POSITIONS)[number];
15
+ export declare const DEFAULT_CONCIERGE_POSITION: ConciergePosition;
16
+ /** `top` | `bottom` — which edge the widget hangs from. */
17
+ export type ConciergeEdge = 'top' | 'bottom';
18
+ /** `left` | `center` | `right` — where along that edge. */
19
+ export type ConciergeAlign = 'left' | 'center' | 'right';
20
+ export declare function edgeOf(position: ConciergePosition): ConciergeEdge;
21
+ export declare function alignOf(position: ConciergePosition): ConciergeAlign;
22
+ /**
23
+ * The anchor a dropped widget should snap to.
24
+ *
25
+ * Thirds horizontally, halves vertically, measured on the widget's own CENTRE
26
+ * rather than the pointer: a visitor drags the grip, which sits at one end of
27
+ * the pill, and snapping on the pointer would send a pill they dropped dead
28
+ * centre off to whichever side they happened to be holding.
29
+ *
30
+ * Pure arithmetic on numbers the caller measures, so it is testable without a
31
+ * DOM and cannot disagree with itself across browsers.
32
+ * @param centre the widget's centre point, in viewport pixels
33
+ * @param viewport the viewport's size, in pixels
34
+ */
35
+ export declare function nearestPosition(centre: {
36
+ x: number;
37
+ y: number;
38
+ }, viewport: {
39
+ width: number;
40
+ height: number;
41
+ }): ConciergePosition;
42
+ /**
43
+ * The anchor an arrow key moves to.
44
+ *
45
+ * The keyboard equivalent of dragging, and not a nicety: a pointer-only way to
46
+ * move the widget is unusable for anyone who cannot drag, and the widget can
47
+ * cover a host page's own controls. Left/right walk the three columns and stop
48
+ * at the ends rather than wrapping — a control that jumps from one edge of the
49
+ * screen to the other because a key was held is disorienting. Up/down flip the
50
+ * edge.
51
+ * @param position where it is now
52
+ * @param key the arrow key pressed
53
+ */
54
+ export declare function positionForArrow(position: ConciergePosition, key: 'ArrowLeft' | 'ArrowRight' | 'ArrowUp' | 'ArrowDown'): ConciergePosition;
55
+ /** Tailwind classes pinning a fixed element to one anchor. */
56
+ export declare function positionClasses(position: ConciergePosition): string;
57
+ /**
58
+ * How the open PANEL lines up under (or over) the launcher.
59
+ *
60
+ * The panel is much wider than the pill, so it cannot simply share the
61
+ * launcher's anchor: pinned left it would still be pinned left, but pinned
62
+ * centre it has to centre on the viewport rather than on the pill.
63
+ */
64
+ export declare function panelClasses(position: ConciergePosition): string;
65
+ //# sourceMappingURL=position.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../src/position.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,YAC9B,UAAU,EACV,YAAY,EACZ,WAAW,EACX,aAAa,EACb,eAAe,EACf,cAAc,CACN,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,eAAO,MAAM,0BAA0B,EAAE,iBAAmC,CAAC;AAE7E,2DAA2D;AAC3D,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,QAAQ,CAAC;AAC7C,2DAA2D;AAC3D,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEzD,wBAAgB,MAAM,CAAC,QAAQ,EAAE,iBAAiB,GAAG,aAAa,CAEjE;AAED,wBAAgB,OAAO,CAAC,QAAQ,EAAE,iBAAiB,GAAG,cAAc,CAInE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAChC,QAAQ,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAC1C,iBAAiB,CAMnB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,iBAAiB,EAC3B,GAAG,EAAE,WAAW,GAAG,YAAY,GAAG,SAAS,GAAG,WAAW,GACxD,iBAAiB,CAUnB;AAED,8DAA8D;AAC9D,wBAAgB,eAAe,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAQnE;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAQhE"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * The widget's own account of a call: what happened, when, and how long each
3
+ * step took.
4
+ *
5
+ * ## Why this exists
6
+ *
7
+ * Everything else in this system logs server-side. The browser half — token
8
+ * request, room join, microphone publish, the agent arriving, audio actually
9
+ * playing — was invisible, so "no playback" was indistinguishable from "no
10
+ * agent", "no audio track", "track arrived but muted" and "everything worked
11
+ * and the speakers are off". Each of those has a different fix and none of them
12
+ * shows up in `.voice-logs/`.
13
+ *
14
+ * Kept as data, separate from the panel that renders it, for the same reason
15
+ * `bot-state.ts` is: the interesting part is the SEQUENCE and the gaps between
16
+ * entries, and that has to be assertable without rendering anything.
17
+ *
18
+ * Timestamps come from the injected clock rather than `Date.now()` so a test
19
+ * can state the latencies it expects. In the browser the caller passes
20
+ * `performance.now`, which is monotonic — a wall clock that steps backwards
21
+ * mid-call would produce negative latencies.
22
+ */
23
+ /** Steps worth timing. Ordered roughly as they occur. */
24
+ export declare const SESSION_EVENTS: readonly ['token_requested', 'token_received', 'room_connecting', 'room_connected', 'mic_published', 'mic_denied', 'mic_muted', 'mic_unmuted', 'agent_joined', 'agent_track_subscribed', 'agent_audio_started', 'agent_speaking', 'agent_silent', 'caller_speaking', 'caller_silent', 'agent_left',
25
+ /** A turn's latency breakdown arrived from the worker. */
26
+ 'turn_latency',
27
+ /** The worker reported which vendors this session actually resolved to. */
28
+ 'session_config',
29
+ /** The caller typed a turn instead of speaking it. */
30
+ 'text_sent',
31
+ /** A speech vendor refused — the call is up but a leg of it is silent. */
32
+ 'vendor_error',
33
+ /** A tool rendered something on screen — product cards, a checkout control. */
34
+ 'widget_event',
35
+ /** One arrived that the widget's own schema refuses. Dropped, never rendered. */
36
+ 'widget_event_invalid', 'disconnected', 'stopped', 'error'];
37
+ export type SessionEventKind = (typeof SESSION_EVENTS)[number];
38
+ export interface SessionLogEntry {
39
+ readonly kind: SessionEventKind;
40
+ /** Clock reading when it happened. */
41
+ readonly atMs: number;
42
+ /** Since the FIRST entry — how far into the call this is. */
43
+ readonly sinceStartMs: number;
44
+ /** Since the previous entry — the step's own cost. */
45
+ readonly sinceLastMs: number;
46
+ /** Free-form, shown after the event name. */
47
+ readonly detail?: string;
48
+ }
49
+ export interface SessionLogOptions {
50
+ now: () => number;
51
+ /** Entries retained. A long call must not grow this without bound. */
52
+ limit?: number;
53
+ }
54
+ export declare class SessionLog {
55
+ private entries;
56
+ private readonly now;
57
+ private readonly limit;
58
+ constructor(options: SessionLogOptions);
59
+ /**
60
+ * Record one event.
61
+ *
62
+ * @returns the entry, so a caller can log it onward without re-reading.
63
+ */
64
+ append(kind: SessionEventKind, detail?: string): SessionLogEntry;
65
+ /** Oldest first. */
66
+ list(): readonly SessionLogEntry[];
67
+ /** Drop everything — a new call is a new account, not a continuation. */
68
+ clear(): void;
69
+ }
70
+ /**
71
+ * Time from one event to another, or `null` when the pair never completed.
72
+ *
73
+ * The pairs worth watching are `token_requested → token_received` (is the
74
+ * server minting?), `room_connecting → room_connected` (is LiveKit reachable?)
75
+ * and `room_connected → agent_audio_started`, which is the one that matters to
76
+ * a caller: how long after joining did anything become audible.
77
+ *
78
+ * Uses the FIRST occurrence of each, so a reconnect later in the call cannot
79
+ * rewrite the timing of the original join.
80
+ */
81
+ export declare function latencyBetween(entries: readonly SessionLogEntry[], from: SessionEventKind, to: SessionEventKind): number | null;
82
+ /** `1234` → `1.23s`, `87` → `87ms`. Fixed width matters in a log column. */
83
+ export declare function formatMs(ms: number): string;
84
+ //# sourceMappingURL=session-log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-log.d.ts","sourceRoot":"","sources":["../src/session-log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,yDAAyD;AACzD,eAAO,MAAM,cAAc,YACzB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,WAAW,EACX,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,qBAAqB,EACrB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,YAAY;AACZ,0DAA0D;AAC1D,cAAc;AACd,2EAA2E;AAC3E,gBAAgB;AAChB,sDAAsD;AACtD,WAAW;AACX,0EAA0E;AAC1E,cAAc;AACd,+EAA+E;AAC/E,cAAc;AACd,iFAAiF;AACjF,sBAAsB,EACtB,cAAc,EACd,SAAS,EACT,OAAO,CACC,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/D,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,sCAAsC;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,6DAA6D;IAC7D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,sDAAsD;IACtD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,6CAA6C;IAC7C,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,MAAM,CAAC;IAClB,sEAAsE;IACtE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAE/B,YAAY,OAAO,EAAE,iBAAiB,EAGrC;IAED;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,gBAAgB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,eAAe,CAa/D;IAED,oBAAoB;IACpB,IAAI,IAAI,SAAS,eAAe,EAAE,CAEjC;IAED,yEAAyE;IACzE,KAAK,IAAI,IAAI,CAEZ;CACF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,SAAS,eAAe,EAAE,EACnC,IAAI,EAAE,gBAAgB,EACtB,EAAE,EAAE,gBAAgB,GACnB,MAAM,GAAG,IAAI,CAKf;AAED,4EAA4E;AAC5E,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAG3C"}
@@ -0,0 +1,15 @@
1
+ import type { TranscriptPayload, TurnLatencyPayload } from '@saar-ai/widget-protocol/telemetry';
2
+ import { type SessionLogEntry } from './session-log.js';
3
+ export interface SessionPanelProps {
4
+ readonly events: readonly SessionLogEntry[];
5
+ /** 0..1 RMS of the agent's incoming audio. */
6
+ readonly agentLevel: number;
7
+ readonly phase: string;
8
+ readonly micOpen: boolean;
9
+ readonly error: string | null;
10
+ /** Per-turn latency as the WORKER measured it, newest last. */
11
+ readonly turns: readonly TurnLatencyPayload[];
12
+ readonly transcript: readonly TranscriptPayload[];
13
+ }
14
+ export declare function SessionPanel({ events, agentLevel, phase, micOpen, error, turns, transcript, }: SessionPanelProps): import("react").JSX.Element;
15
+ //# sourceMappingURL=session-panel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-panel.d.ts","sourceRoot":"","sources":["../src/session-panel.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAEhG,OAAO,EAA4B,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAwBlF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,CAAC;IAC5C,8CAA8C;IAC9C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,+DAA+D;IAC/D,QAAQ,CAAC,KAAK,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAC9C,QAAQ,CAAC,UAAU,EAAE,SAAS,iBAAiB,EAAE,CAAC;CACnD;AAWD,wBAAgB,YAAY,CAAC,EAC3B,MAAM,EACN,UAAU,EACV,KAAK,EACL,OAAO,EACP,KAAK,EACL,KAAK,EACL,UAAU,GACX,EAAE,iBAAiB,+BAqInB"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Incremental parser for the widget chat SSE wire format
3
+ * (`apps/web/src/components/widget/use-chat-session.ts`'s only consumer):
4
+ *
5
+ * id:<opaque>
6
+ * event:<type>
7
+ * data:<json>
8
+ * <blank line>
9
+ *
10
+ * `fetch` + a `ReadableStream` reader hands text back in arbitrary byte
11
+ * chunks — decoded UTF-8 text, not lines. A frame can be split across two
12
+ * chunks, and one chunk can carry several frames back to back. This class
13
+ * owns exactly the buffering that requires: feed it decoded text with
14
+ * `push`, get back only the frames that are complete so far; whatever is left
15
+ * (a partial frame) stays buffered for the next `push`.
16
+ *
17
+ * Deliberately tolerant of both `\n\n` and `\r\n\r\n` frame separators, and of
18
+ * a trailing partial frame that never arrives (e.g. the stream is aborted
19
+ * mid-frame) — `push` on the next chunk still completes it correctly; a frame
20
+ * that never completes is simply never returned, not thrown.
21
+ */
22
+ export interface SseEvent {
23
+ readonly id?: string;
24
+ readonly event: string;
25
+ readonly data: unknown;
26
+ }
27
+ export declare class SseFrameParser {
28
+ private buffer;
29
+ /**
30
+ * Feed decoded text (one `TextDecoder.decode` chunk, or any substring of
31
+ * the stream). Returns every frame that became complete as a result —
32
+ * zero, one, or several, in wire order.
33
+ */
34
+ push(chunk: string): SseEvent[];
35
+ /** Whatever text has not yet formed a complete frame. Exposed for tests only. */
36
+ get pending(): string;
37
+ }
38
+ //# sourceMappingURL=sse-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse-parser.d.ts","sourceRoot":"","sources":["../src/sse-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAID,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAM;IAEpB;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,EAAE,CAc9B;IAED,iFAAiF;IACjF,IAAI,OAAO,IAAI,MAAM,CAEpB;CACF"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The widget's compiled CSS, as a string — for `mountConciergeWidget`'s
3
+ * shadow-DOM path (docs/WIDGET_EMBED_PLAN.md §4 Phase 3, coupling (5)).
4
+ *
5
+ * Generated by `pnpm --filter @saar-ai/web-widget build:css`
6
+ * (`scripts/generate-widget-css.mjs`, `@tailwindcss/cli` over
7
+ * `src/styles/widget-entry.css`) into `src/generated/widget-css.ts`, which
8
+ * this file re-exports. See that generated file's own banner, and
9
+ * AGENTS.md's Sharp edges, for why the generated file is checked in rather
10
+ * than gitignored.
11
+ *
12
+ * A host that renders this package's components in LIGHT DOM (apps/web
13
+ * today) does NOT need this — it already compiles the same classes through
14
+ * its own Tailwind `@source` scan (see AGENTS.md's "App CSS wiring"). This
15
+ * export exists only for a host with no Tailwind build of its own — the
16
+ * shadow-DOM mount.
17
+ */
18
+ export { WIDGET_CSS } from './generated/widget-css.js';
19
+ //# sourceMappingURL=styles.d.ts.map