@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,290 @@
1
+ import { c as number, i as discriminatedUnion, l as object, o as literal, r as boolean, s as looseObject, t as _enum, u as string } from "./schemas-Bl_6mxe4.js";
2
+ //#region ../widget-protocol/dist/telemetry.js
3
+ /**
4
+ * The voice call's wire contract, as the CALLER's browser sees it: what the
5
+ * voice worker publishes over the LiveKit data channel, and the one thing the
6
+ * browser itself authors back (a typed message).
7
+ *
8
+ * ## Why this lives in `@saar-ai/widget-protocol`, not `@wesence/voice-protocol`
9
+ *
10
+ * The producer is `apps/voice` (Node) and the consumer is `@saar-ai/web-widget`
11
+ * — a PUBLICLY published npm package, bundled into a merchant's own storefront
12
+ * bundle. `@saar-ai/web-widget`'s `use-voice-session.ts` dynamically imports
13
+ * this module (`loadVoiceProtocol()`), so whatever it resolves to gets
14
+ * bundled whole into the published tarball. This package's home is
15
+ * `@saar-ai/*` — widget-owned, safe to ship — specifically so that dynamic
16
+ * import never resolves to a path under a framework-inherited `@wesence/*`
17
+ * package (docs/PACKAGE_DISTRIBUTION.md "`private: true` — the real publish
18
+ * gate": every `@wesence/*` package is vendored, never published from this fork).
19
+ * `packages/web-widget/src/__tests__/npm-bundle-provenance.build.test.ts`
20
+ * proves this mechanically against the real build output.
21
+ *
22
+ * `@wesence/voice-protocol`'s own `telemetry/index.ts` re-exports everything
23
+ * below (its existing consumers — `apps/voice`, `apps/web` — import it
24
+ * unchanged) and adds only the SERVER-only half: `encodeTelemetry`,
25
+ * `decodeCallerText`, `VOICE_TELEMETRY_TOPIC`. See that file's own doc
26
+ * comment for why it imports from here rather than the reverse, and this
27
+ * package's `AGENTS.md` for the fuller "duplicate vs. import" writeup.
28
+ *
29
+ * ## Deliberately browser-safe
30
+ *
31
+ * Imports nothing but `zod` — no `node:*`, no framework barrel. Every module
32
+ * in this package ends up bundled into a merchant-page browser bundle.
33
+ *
34
+ * ## What the browser does NOT need from this module
35
+ *
36
+ * `VOICE_TELEMETRY_TOPIC` (the outbound topic the WORKER publishes telemetry
37
+ * on) is not exported here: `use-voice-session.ts`'s `onData` handler decodes
38
+ * every `dataReceived` frame unconditionally and lets the payload's own
39
+ * `type` field discriminate it — the LiveKit topic name is never inspected on
40
+ * the receive side. `encodeTelemetry` (the worker encodes, never the browser)
41
+ * and `decodeCallerText` (the worker decodes what the browser sent) are the
42
+ * other two server-only pieces — both stay in `@wesence/voice-protocol`.
43
+ */
44
+ /**
45
+ * The topic a caller who is TYPING publishes on — the one inbound channel on
46
+ * this transport, and the only one that is load-bearing rather than
47
+ * diagnostic. Named here because the browser is the sender: the widget builds
48
+ * the frame with {@link encodeCallerText}, and the worker (via
49
+ * `@wesence/voice-protocol/telemetry`'s re-export) filters incoming data by
50
+ * this exact constant before decoding it.
51
+ */
52
+ var VOICE_CALLER_TEXT_TOPIC = "voice.caller_text";
53
+ /**
54
+ * One typed message from the caller.
55
+ *
56
+ * ## Trust
57
+ *
58
+ * The content is **user input**, exactly like a transcript of what they said,
59
+ * and it is handled the same way — committed as a turn, never interpreted as
60
+ * configuration or instruction by any component between here and the model.
61
+ * The caller's room token is what authorises publishing it, so the sender is
62
+ * already scoped to this one room.
63
+ *
64
+ * Bounded because it is not: a recognizer's output has a natural length and a
65
+ * text box does not.
66
+ */
67
+ var CallerTextPayloadSchema = object({
68
+ type: literal("caller.text"),
69
+ text: string().min(1).max(2e3)
70
+ });
71
+ function encodeCallerText(payload) {
72
+ return new TextEncoder().encode(JSON.stringify(payload));
73
+ }
74
+ /** Per-turn latency, in milliseconds. `null` means the stage never completed. */
75
+ var TurnLatencyPayloadSchema = object({
76
+ type: literal("turn.latency"),
77
+ turnId: string().min(1),
78
+ /** Caller stopped speaking → final transcript. */
79
+ sttMs: number().nullable(),
80
+ /** Caller stopped speaking → turn committed. CONTAINS `sttMs`. */
81
+ eotMs: number().nullable(),
82
+ /** Turn committed → first token from the turn tier (LLM + its overhead). */
83
+ agentMs: number().nullable(),
84
+ /** Synthesis requested → audio in hand. */
85
+ ttsMs: number().nullable(),
86
+ /** Caller stopped speaking → first audio they hear. The felt latency. */
87
+ overallMs: number().nullable(),
88
+ /**
89
+ * The turn tier began generating before the turn was confirmed, so most of
90
+ * `agentMs` hid under `eotMs` and the stages will not sum to `overallMs`.
91
+ */
92
+ speculative: boolean()
93
+ });
94
+ /** One line of conversation, as it is known. */
95
+ var TranscriptPayloadSchema = object({
96
+ type: literal("transcript"),
97
+ speaker: _enum(["caller", "agent"]),
98
+ text: string(),
99
+ /** BCP-47. A conversation can switch language mid-call. */
100
+ locale: string().min(1),
101
+ /** `false` while the recognizer may still revise it. */
102
+ final: boolean(),
103
+ turnId: string().optional(),
104
+ /**
105
+ * Unix ms, stamped by the WORKER when the line was published — the
106
+ * worker's clock, not the browser's, so it lines up with `turn.latency`
107
+ * figures measured on that same clock. Optional so a widget pinned to an
108
+ * older build still parses the frame.
109
+ */
110
+ atMs: number().optional(),
111
+ /**
112
+ * `true` when this line is dead-air cover speech (a §4.9 filler, e.g. "One
113
+ * moment.") rather than the agent's actual reply — always `speaker:
114
+ * 'agent'`, `final: true`.
115
+ *
116
+ * Absent (not `false`) on every other line, including the greeting and the
117
+ * reconnect/apology phrases, which are real agent speech about the call
118
+ * rather than cover for a reply still in flight. Optional so a widget built
119
+ * before this field existed still parses the frame — it renders the filler
120
+ * as an ordinary settled bubble, which is the exact pre-existing behaviour
121
+ * this field lets a NEWER widget improve on, not a break.
122
+ *
123
+ * Mirrors the decision `apps/api`'s `turn-transcript.recorder.ts` makes for
124
+ * the PERSISTED record: a filler is real content the caller heard and must
125
+ * not be dropped, but it is cover speech, not a considered part of the
126
+ * answer, so it is never merged into the reply's own text — there it lands
127
+ * in `metrics.fillers`, a structured sibling field never concatenated onto
128
+ * `generatedText`; here it is this sibling marker on the same `transcript`
129
+ * frame, kept apart from `text` for the identical reason: a consumer that
130
+ * ignores this field must still get exactly the reply, never the reply with
131
+ * "One moment." run into it.
132
+ */
133
+ filler: boolean().optional(),
134
+ /**
135
+ * `true` when this provisional line RESTATES the whole line so far, so a
136
+ * reader must REPLACE what it is holding rather than append to it.
137
+ *
138
+ * ## Why a marker rather than a version bump
139
+ *
140
+ * The agent's provisional frames used to be one INCREMENTAL clause each
141
+ * (one per `say.delta`). They are now the prefix of the reply that has
142
+ * actually been SPOKEN, sampled off the playout clock — cumulative by
143
+ * construction, each one a superset of the last. A reader that
144
+ * CONCATENATES cumulative frames draws "we we ship we ship worldwide", so
145
+ * the two kinds of frame cannot share one folding rule and the wire has to
146
+ * say which it is.
147
+ *
148
+ * ## What a skewed reader actually does — measured, not assumed
149
+ *
150
+ * `@saar-ai/web-widget` ships to merchant sites over a CDN, so a bundle
151
+ * cached before this change WILL meet a worker deployed after it. It is
152
+ * worth being exact about what that costs, because an earlier version of
153
+ * this comment was not: the older bundle does NOT concatenate and does NOT
154
+ * render garbage. `coalesceTranscript` — the only reader that ever
155
+ * concatenates — arrived WITH this change. The reader it replaced is
156
+ * `setTranscript((lines) => [...lines, message].slice(-50))`: every frame
157
+ * becomes its own line, and each line's text is a correct spoken prefix.
158
+ *
159
+ * The damage is to the 50-line ring, and it is silent. The worker now
160
+ * publishes a provisional frame every `REVEAL_MIN_ADVANCE_MS` (100 ms,
161
+ * `apps/voice/src/session/voice-session.ts`) of playout that moves the
162
+ * text — several a second — where it used to publish one per clause. Replayed against that exact reducer: 8 frames
163
+ * for a reply draws 8 near-duplicate bubbles and the conversation still
164
+ * reads; ~60 frames (a ~16-second answer) fills the ring on its own and
165
+ * evicts every earlier turn. Nothing looks broken. The history is just
166
+ * gone.
167
+ *
168
+ * Hypothetical for now, and only for now: `@saar-ai/web-widget` is
169
+ * `0.1.0`, has no `CHANGELOG.md`, and 404s on npm — nothing is cached on a
170
+ * merchant's site yet because nothing has ever been released. That is a
171
+ * fact about today, not a property of the design, and it stops being true
172
+ * on the first publish.
173
+ *
174
+ * Hence an explicit, optional field: a new reader replaces when it is
175
+ * present and concatenates when it is absent, so an old worker's
176
+ * incremental clauses keep folding exactly as they always did and an old
177
+ * widget never sees the marker at all.
178
+ *
179
+ * Only ever set on `speaker: 'agent'`, `final: false`. Caller partials are
180
+ * cumulative too, but they always have been — that leg's reader has
181
+ * replaced since it was written, and marking it now would say nothing new.
182
+ * A settled (`final: true`) line always replaces the run it closes,
183
+ * whatever this field says.
184
+ */
185
+ cumulative: boolean().optional()
186
+ });
187
+ /**
188
+ * What one turn cost, per vendor step. Quantities travel alongside the money:
189
+ * a panel that shows `$0.0004` and nothing else cannot be checked. `usd` is
190
+ * `null` when the vendor has no confirmed rate — distinct from `0`, which
191
+ * would understate the total while looking authoritative.
192
+ */
193
+ var TurnCostPayloadSchema = object({
194
+ type: literal("turn.cost"),
195
+ turnId: string().min(1),
196
+ /** The rate card id each step was charged against. */
197
+ sttRateId: string(),
198
+ llmRateId: string(),
199
+ ttsRateId: string(),
200
+ /** Caller audio streamed to the recognizer, this turn. */
201
+ sttAudioSeconds: number(),
202
+ sttUsd: number().nullable(),
203
+ /** Absent when the turn tier reports no usage — this tier never guesses tokens. */
204
+ llmInputTokens: number().nullable(),
205
+ llmOutputTokens: number().nullable(),
206
+ llmUsd: number().nullable(),
207
+ /** Characters actually sent to the synthesizer, after spoken-output shaping. */
208
+ ttsCharacters: number(),
209
+ ttsUsd: number().nullable(),
210
+ /** Sum of the known steps. Unknown steps are omitted, not counted as zero. */
211
+ totalUsd: number().nullable()
212
+ });
213
+ /** Which vendors and knobs this session actually resolved to, sent once at start. */
214
+ var SessionConfigPayloadSchema = object({
215
+ type: literal("session.config"),
216
+ sttVendor: string(),
217
+ sttModel: string(),
218
+ /** True when the recognizer ends turns itself and our silence flush is off. */
219
+ sttNativeEndOfTurn: boolean(),
220
+ ttsVendor: string(),
221
+ voiceId: string(),
222
+ locale: string(),
223
+ /** `null` on a session whose recognizer owns turn boundaries. */
224
+ flushSilenceMs: number().nullable(),
225
+ eotThreshold: number().nullable(),
226
+ eagerEotThreshold: number().nullable(),
227
+ /**
228
+ * Whether Smart Turn is actually holding turns open on this session — the
229
+ * RESOLVED answer, not what was asked for. Optional so a widget pinned to
230
+ * an older build still parses the frame.
231
+ */
232
+ semanticEot: boolean().optional(),
233
+ /** Ceiling in ms, or `null` when it follows the adaptive window. */
234
+ semanticMaxHoldMs: number().nullable().optional()
235
+ });
236
+ /**
237
+ * Something for the caller's screen, forwarded from the turn tier.
238
+ *
239
+ * Carried opaquely: this module does not own the widget's tool-event schema
240
+ * and must not encode one. The widget validates `event` with this SAME
241
+ * package's `./chat` subpath — `WidgetToolEventSchema` — and drops what
242
+ * fails, the same posture every other frame here takes toward a version skew.
243
+ */
244
+ var WidgetEventPayloadSchema = object({
245
+ type: literal("widget.event"),
246
+ event: looseObject({ type: string().min(1) }),
247
+ turnId: string().optional()
248
+ });
249
+ /**
250
+ * A vendor refused, and the caller is about to experience it as silence.
251
+ *
252
+ * `message` is the vendor's own, already whatever the worker chose to log. It
253
+ * is shown to whoever has the widget open, so it must stay a description of
254
+ * the failure and never carry a key, a token or a request URL.
255
+ */
256
+ var VendorErrorPayloadSchema = object({
257
+ type: literal("vendor.error"),
258
+ /** Which leg went quiet. */
259
+ stage: _enum(["stt", "tts"]),
260
+ /** The vendor this session routed to, for a message that names it. */
261
+ vendor: string().min(1),
262
+ message: string().min(1).max(500)
263
+ });
264
+ var VoiceTelemetryMessageSchema = discriminatedUnion("type", [
265
+ TurnLatencyPayloadSchema,
266
+ TranscriptPayloadSchema,
267
+ TurnCostPayloadSchema,
268
+ SessionConfigPayloadSchema,
269
+ WidgetEventPayloadSchema,
270
+ VendorErrorPayloadSchema
271
+ ]);
272
+ /**
273
+ * Decode one delivery, or `null` when it is not ours to read.
274
+ *
275
+ * Never throws. Anything on that channel may be from another publisher, a
276
+ * newer version of this contract, or malformed — and a widget that crashes on
277
+ * an unexpected frame is worse than one that ignores it.
278
+ */
279
+ function decodeTelemetry(payload) {
280
+ let parsed;
281
+ try {
282
+ parsed = JSON.parse(new TextDecoder().decode(payload));
283
+ } catch {
284
+ return null;
285
+ }
286
+ const result = VoiceTelemetryMessageSchema.safeParse(parsed);
287
+ return result.success ? result.data : null;
288
+ }
289
+ //#endregion
290
+ export { CallerTextPayloadSchema, SessionConfigPayloadSchema, TranscriptPayloadSchema, TurnCostPayloadSchema, TurnLatencyPayloadSchema, VOICE_CALLER_TEXT_TOPIC, VendorErrorPayloadSchema, VoiceTelemetryMessageSchema, WidgetEventPayloadSchema, decodeTelemetry, encodeCallerText };
package/dist/cn.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { type ClassValue } from 'clsx';
2
+ /**
3
+ * Same className helper `@wesence/ui/lib/utils` ships (clsx + tailwind-merge,
4
+ * last-wins conflict resolution for Tailwind utility classes). Copied rather
5
+ * than imported: this package is `publishable` (see package.json distribution class) and
6
+ * `@wesence/ui` is `template`-classified — `check-publishable.mjs` forbids a
7
+ * publishable package from depending on a template one (a template package is
8
+ * scaffold-only source, never resolvable through a real `npm install`). The
9
+ * concierge components moved here needed only this one helper from
10
+ * `@wesence/ui`, so a second one-line definition is cheaper than a fork of the
11
+ * whole design system. See `packages/web-widget/AGENTS.md`.
12
+ */
13
+ export declare function cn(...inputs: ClassValue[]): string;
14
+ //# sourceMappingURL=cn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cn.d.ts","sourceRoot":"","sources":["../src/cn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,MAAM,CAAC;AAG7C;;;;;;;;;;GAUG;AACH,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAElD"}
@@ -0,0 +1,50 @@
1
+ import { alignOf, type ConciergePosition } from './position.js';
2
+ /**
3
+ * The collapsed concierge: a pill the visitor can read, press, and move.
4
+ *
5
+ * ## Why a pill and not a round button
6
+ *
7
+ * A bare orb says "there is a bot here" and nothing else. This product's
8
+ * concierge answers in SPEECH, which is the thing a visitor has to be told —
9
+ * nobody presses an unlabelled circle expecting to talk to it. So the launcher
10
+ * carries the tenant's own words (`label`), beside the face rather than instead
11
+ * of it: the mascot is what the concierge IS, and swapping it for a microphone
12
+ * glyph would trade a personality for an icon that says less.
13
+ *
14
+ * ## Why it is draggable
15
+ *
16
+ * The widget sits on somebody else's page, over content the tenant chose and we
17
+ * have never seen. A fixed corner covers a cookie bar on one site and a "buy"
18
+ * button on another, and no default can be right everywhere. The tenant picks
19
+ * where it starts; the visitor gets the last word.
20
+ *
21
+ * Dragging is the obvious gesture and the inaccessible one, so the grip is a
22
+ * real focusable control and arrow keys move between the same six anchors —
23
+ * see `positionForArrow`. Anyone who cannot drag can still move the thing off
24
+ * the content it is covering.
25
+ *
26
+ * ## What it does NOT do
27
+ *
28
+ * It does not remember anything. Where the widget sits between visits is the
29
+ * host app's business — it owns the storage, the tenant default it falls back
30
+ * to, and the consent posture around keeping anything at all.
31
+ */
32
+ export interface ConciergeLauncherProps {
33
+ /** Visible text. Absent ⇒ the face alone, and `srLabel` names it. */
34
+ readonly label?: string;
35
+ /** Accessible name of the launcher itself. Always required. */
36
+ readonly srLabel: string;
37
+ /** Accessible name of the drag grip, e.g. "Move the assistant". */
38
+ readonly moveLabel: string;
39
+ readonly position: ConciergePosition;
40
+ /** Absent ⇒ the launcher is fixed where the tenant put it, with no grip. */
41
+ readonly onPositionChange?: (position: ConciergePosition) => void;
42
+ readonly onOpen: () => void;
43
+ readonly hidden: boolean;
44
+ readonly id?: string;
45
+ readonly testId?: string;
46
+ }
47
+ export declare function ConciergeLauncher({ label, srLabel, moveLabel, position, onPositionChange, onOpen, hidden, id, testId, }: ConciergeLauncherProps): import("react").JSX.Element;
48
+ /** Re-exported so a host can type its own stored value. */
49
+ export { alignOf };
50
+ //# sourceMappingURL=concierge-launcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concierge-launcher.d.ts","sourceRoot":"","sources":["../src/concierge-launcher.tsx"],"names":[],"mappings":"AAOA,OAAO,EACL,OAAO,EAIP,KAAK,iBAAiB,EACvB,MAAM,eAAe,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,WAAW,sBAAsB;IACrC,qEAAqE;IACrE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IACrC,4EAA4E;IAC5E,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAClE,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,OAAO,EACP,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,MAAM,EACN,MAAM,EACN,EAAE,EACF,MAAM,GACP,EAAE,sBAAsB,+BAoNxB;AAED,2DAA2D;AAC3D,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,194 @@
1
+ import { type CSSProperties, type ReactNode } from 'react';
2
+ import { type BotState } from './bot-face.js';
3
+ import { type ConciergePosition } from './position.js';
4
+ /**
5
+ * The concierge widget's chrome: trigger, backdrop, panel, face, composer.
6
+ *
7
+ * ## Why it is a package and not a component in one app
8
+ *
9
+ * This widget renders in two places — the scripted preview on the marketing
10
+ * site and the real assistant in the product — and the preview's entire claim
11
+ * is that a visitor is looking at what they would get. Two implementations can
12
+ * only agree by hand, and would stop agreeing the first time either was
13
+ * touched. So the chrome is defined once, here, and each app supplies what is
14
+ * genuinely its own: the marketing preview replays a script, the product holds
15
+ * a live session with a microphone, product cards and a cart.
16
+ *
17
+ * What is deliberately NOT here: the transcript. `children` is the whole
18
+ * conversation area, because that is where the two legitimately differ — the
19
+ * preview renders bubbles, the product renders bubbles plus cards, attachments,
20
+ * markdown and a cart summary. A shell that tried to own that would end up with
21
+ * a prop for every feature either app ever grows.
22
+ *
23
+ * ## No i18n, no router, no data
24
+ *
25
+ * Every string arrives in {@link ConciergeShellProps.labels}. The package has
26
+ * no locale of its own, and an app that translates with `next-intl` should not
27
+ * have to reach a translator into a design-system component to render a button.
28
+ *
29
+ * ## It is a modal dialog, and behaves like one
30
+ *
31
+ * `Escape` closes, `Tab` is trapped inside the panel, and focus returns to the
32
+ * trigger on close — focus leaking to the page behind an open dialog leaves a
33
+ * keyboard or screen-reader user navigating content they cannot see.
34
+ *
35
+ * Focus lands on the COMPOSER, not the close button. It is what a visitor
36
+ * opened the panel to use, and a focused close button swallows the space bar:
37
+ * press space to start typing before clicking into the field and the panel
38
+ * shuts instead — a keyboard user's first keystroke dismissing the thing they
39
+ * just opened.
40
+ *
41
+ * ## The animation carries nothing
42
+ *
43
+ * Every flourish below is decorative and stops wholesale under
44
+ * `prefers-reduced-motion`. That is only safe because the state is also
45
+ * announced in text — see {@link ConciergeShellProps.announcement}, which is
46
+ * the live region and not an afterthought.
47
+ */
48
+ export interface ConciergeShellLabels {
49
+ /** Accessible name of the collapsed trigger. */
50
+ readonly open: string;
51
+ /**
52
+ * Visible text ON the collapsed launcher — the tenant's own words for their
53
+ * concierge, from the widget config, in the config's own locale.
54
+ *
55
+ * Absent leaves the face alone with `open` as its accessible name, which is
56
+ * what a host with nothing to say should render rather than a placeholder.
57
+ */
58
+ readonly launcher?: string;
59
+ /** Accessible name of the drag grip, e.g. "Move the assistant". */
60
+ readonly move?: string;
61
+ readonly close: string;
62
+ /** Accessible name of the dialog itself. */
63
+ readonly dialog: string;
64
+ readonly composerPlaceholder: string;
65
+ readonly send: string;
66
+ }
67
+ /**
68
+ * Where a call is, from the caller's point of view.
69
+ *
70
+ * The panel no longer draws a status bar for these — removed on request; the
71
+ * widget reads better without one. The phase still decides which control the
72
+ * composer row offers, and a refused microphone still reaches the caller
73
+ * through the host's own status line rather than a bar of its own.
74
+ */
75
+ export type ConciergeCallPhase = 'idle' | 'connecting' | 'waiting' | 'live' | 'blocked';
76
+ /**
77
+ * The voice leg, as the panel needs to see it.
78
+ *
79
+ * Replaces the old `mic` prop, which could only express "there is a button".
80
+ * A voice-first widget has to express where the call IS: a caller who presses
81
+ * the microphone and sees nothing for four seconds concludes the product is
82
+ * broken, and that is exactly what the transport spends on a good day.
83
+ */
84
+ export interface ConciergeShellVoice {
85
+ readonly phase: ConciergeCallPhase;
86
+ /** Start a call. Only reachable while `phase` is `idle`. */
87
+ readonly onStart: () => void;
88
+ /** Leave the call — a different intention from muting it. */
89
+ readonly onEnd?: () => void;
90
+ /** Ask the browser for the microphone again, after it was refused. */
91
+ readonly onRetryMic?: () => void;
92
+ readonly muted?: boolean;
93
+ readonly onToggleMute?: () => void;
94
+ /** True while the agent is talking, so the bar can offer the interrupt. */
95
+ readonly agentSpeaking?: boolean;
96
+ /** 0..1, drives the level meter. */
97
+ readonly level?: number;
98
+ /**
99
+ * Present and DISABLED rather than hidden, for a surface that has no voice
100
+ * leg but wants to show the product has one — the marketing preview. A host
101
+ * with nothing to offer omits `voice` entirely.
102
+ */
103
+ readonly disabled?: boolean;
104
+ readonly labels: {
105
+ /** Accessible name of the start button, and its tooltip when disabled. */
106
+ readonly start: string;
107
+ readonly end?: string;
108
+ readonly mute?: string;
109
+ readonly unmute?: string;
110
+ /** One line for the call bar: "Connecting…", "You can talk now", a reason. */
111
+ readonly status?: string;
112
+ /** Shown while the agent speaks: "go ahead and interrupt". */
113
+ readonly interrupt?: string;
114
+ /** The retry button, offered only when the microphone was refused. */
115
+ readonly retry?: string;
116
+ };
117
+ }
118
+ export interface ConciergeShellProps {
119
+ readonly open: boolean;
120
+ readonly onOpenChange: (open: boolean) => void;
121
+ /** What the face renders. */
122
+ readonly state: BotState;
123
+ /** One-shot flourish when the visitor's own message lands. */
124
+ readonly messageArrived?: boolean;
125
+ readonly labels: ConciergeShellLabels;
126
+ /**
127
+ * The conversation. Rendered inside the panel's own scroll container, so a
128
+ * caller supplies list items and nothing about scrolling or padding.
129
+ */
130
+ readonly children: ReactNode;
131
+ /** Between the face and the transcript — the preview's "scripted" badge. */
132
+ readonly badge?: ReactNode;
133
+ readonly draft: string;
134
+ readonly onDraftChange: (value: string) => void;
135
+ /** The composer was submitted with a non-empty draft. */
136
+ readonly onSubmit: () => void;
137
+ readonly composerDisabled?: boolean;
138
+ /** Omitted ⇒ no voice control renders at all. */
139
+ readonly voice?: ConciergeShellVoice;
140
+ /**
141
+ * Rendered inside the composer, before the text field.
142
+ *
143
+ * Exists for the product's attachment control, which the marketing preview
144
+ * has nothing to put there. A slot rather than an `onAttach` prop because
145
+ * the widget that owns the file input also owns its label, its accepted
146
+ * types and what "uploading" looks like — none of which belongs in a design
147
+ * system component.
148
+ */
149
+ readonly composerLeading?: ReactNode;
150
+ /**
151
+ * What a screen reader is told, replacing everything the animation conveys.
152
+ * Changing it announces it, so it should be the state or the newest reply —
153
+ * never a value that changes on every frame.
154
+ */
155
+ readonly announcement?: string;
156
+ /** `[data-skin]` on the root, for the brand-token overrides. */
157
+ readonly skin?: string;
158
+ /** Inline brand-token overrides, for a skin computed at runtime. */
159
+ readonly skinStyle?: CSSProperties;
160
+ /**
161
+ * Namespaces this instance's element ids. Two widgets on one page would
162
+ * otherwise share a trigger id and hand focus to each other's.
163
+ */
164
+ readonly idPrefix?: string;
165
+ /** Scrolls the transcript to the newest turn when it changes. */
166
+ readonly scrollKey?: unknown;
167
+ /**
168
+ * Which edge the widget hangs from. Defaults to bottom-centre.
169
+ *
170
+ * The TENANT's default arrives here from the widget config; a visitor may
171
+ * move it, which is what `onPositionChange` reports. Remembering their choice
172
+ * is the host app's business — see `ConciergeLauncher`.
173
+ */
174
+ readonly position?: ConciergePosition;
175
+ /** Absent ⇒ the launcher cannot be moved and renders no grip. */
176
+ readonly onPositionChange?: (position: ConciergePosition) => void;
177
+ /**
178
+ * `data-testid`s for the controls the shell owns.
179
+ *
180
+ * The product's suite drives this widget through its own ids and predates
181
+ * the shell; naming them here keeps those tests asserting behaviour rather
182
+ * than being rewritten into assertions about a design system's markup.
183
+ */
184
+ readonly testIds?: {
185
+ readonly trigger?: string;
186
+ readonly panel?: string;
187
+ readonly input?: string;
188
+ readonly send?: string;
189
+ readonly mic?: string;
190
+ readonly endCall?: string;
191
+ };
192
+ }
193
+ export declare function ConciergeShell({ open, onOpenChange, state, messageArrived, labels, children, badge, draft, onDraftChange, onSubmit, composerDisabled, voice, announcement, skin, skinStyle, idPrefix, scrollKey, composerLeading, testIds, position, onPositionChange, }: ConciergeShellProps): import("react").JSX.Element;
194
+ //# sourceMappingURL=concierge-shell.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concierge-shell.d.ts","sourceRoot":"","sources":["../src/concierge-shell.tsx"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,aAAa,EAElB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAIf,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGvD,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,eAAe,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,WAAW,oBAAoB;IACnC,gDAAgD;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,mEAAmE;IACnE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,YAAY,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;AAoExF;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC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xB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;CACH;AAKD,wBAAgB,cAAc,CAAC,EAC7B,IAAI,EACJ,YAAY,EACZ,KAAK,EACL,cAAsB,EACtB,MAAM,EACN,QAAQ,EACR,KAAK,EACL,KAAK,EACL,aAAa,EACb,QAAQ,EACR,gBAAwB,EACxB,KAAK,EACL,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,QAAsB,EACtB,SAAS,EACT,eAAe,EACf,OAAO,EACP,QAAqC,EACrC,gBAAgB,GACjB,EAAE,mBAAmB,+BAofrB"}
@@ -0,0 +1,34 @@
1
+ import { Component, type ReactNode } from 'react';
2
+ export interface WidgetErrorBoundaryProps {
3
+ readonly children: ReactNode;
4
+ /** Called once, the first time a render throws. Never re-thrown — see the class doc comment. */
5
+ readonly onError?: (error: unknown) => void;
6
+ }
7
+ interface WidgetErrorBoundaryState {
8
+ readonly errored: boolean;
9
+ }
10
+ /**
11
+ * A render error inside this widget must never throw into the host page —
12
+ * docs/WIDGET_EMBED_PLAN.md §4 Phase 3. A merchant's storefront is not code
13
+ * this package controls; an uncaught exception from a third-party script tag
14
+ * can blank the surrounding page or trip the host's own error reporting for a
15
+ * failure that has nothing to do with them.
16
+ *
17
+ * On a caught error the widget unmounts SILENTLY — renders `null` — rather
18
+ * than an inline fallback message, because a fallback is still DOM inside the
19
+ * host page and still something that can look broken next to a merchant's own
20
+ * content. `onError` is the only way to observe the failure; a caller wanting
21
+ * telemetry supplies it.
22
+ *
23
+ * A class component because `getDerivedStateFromError`/`componentDidCatch`
24
+ * have no hook equivalent — this is the one place in the package that is
25
+ * still a class for exactly that reason.
26
+ */
27
+ export declare class WidgetErrorBoundary extends Component<WidgetErrorBoundaryProps, WidgetErrorBoundaryState> {
28
+ state: WidgetErrorBoundaryState;
29
+ static getDerivedStateFromError(): WidgetErrorBoundaryState;
30
+ componentDidCatch(error: unknown): void;
31
+ render(): ReactNode;
32
+ }
33
+ export {};
34
+ //# sourceMappingURL=error-boundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-boundary.d.ts","sourceRoot":"","sources":["../src/error-boundary.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAElD,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,gGAAgG;IAChG,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAC7C;AAED,UAAU,wBAAwB;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,mBAAoB,SAAQ,SAAS,CAChD,wBAAwB,EACxB,wBAAwB,CACzB;IACC,KAAK,EAAE,wBAAwB,CAAsB;IAErD,MAAM,CAAC,wBAAwB,IAAI,wBAAwB,CAE1D;IAED,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAMtC;IAED,MAAM,IAAI,SAAS,CAGlB;CACF"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Formats a minor-unit integer price (cents, paise, ...) as localized
3
+ * currency text.
4
+ *
5
+ * Copied from `apps/web/src/lib/money.ts` rather than imported — this
6
+ * package must not depend on `apps/web`, and the function is small, pure,
7
+ * and `Intl`-only. Same duplication tradeoff `text-direction.ts` documents;
8
+ * keep the two copies in sync by hand.
9
+ *
10
+ * Pure and locale-explicit: every caller (this package's product cards, cart
11
+ * summary) passes its own resolved locale rather than relying on a browser
12
+ * default that could silently disagree with the `dir`/`lang` the widget
13
+ * already committed to.
14
+ *
15
+ * SIMPLIFICATION, stated rather than hidden: this assumes a 2-decimal minor
16
+ * unit (cents → dollars). A zero-decimal currency (JPY) or a 3-decimal one
17
+ * (KWD, BHD) would need a per-currency minor-unit table.
18
+ */
19
+ export declare function formatMoney(priceMinor: number, currency: string, locale: string): string;
20
+ //# sourceMappingURL=format-money.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-money.d.ts","sourceRoot":"","sources":["../src/format-money.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CASxF"}
@@ -0,0 +1,2 @@
1
+ export declare const WIDGET_CSS: string;
2
+ //# sourceMappingURL=widget-css.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget-css.d.ts","sourceRoot":"","sources":["../../src/generated/widget-css.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,EAAE,MAA+24D,CAAC"}