@saar-ai/web-widget 0.2.0 → 0.4.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 (40) hide show
  1. package/dist/avatar-face.d.ts +33 -0
  2. package/dist/avatar-face.d.ts.map +1 -0
  3. package/dist/avatar.d.ts +17 -0
  4. package/dist/avatar.d.ts.map +1 -0
  5. package/dist/bot-face.d.ts +17 -0
  6. package/dist/bot-face.d.ts.map +1 -1
  7. package/dist/chunks/{chat-ZLxYRTml.js → chat-DfajYOmN.js} +68 -1
  8. package/dist/chunks/{host-widget-iy3qC-1p.js → host-widget-Bt41rE9U.js} +2562 -499
  9. package/dist/concierge-launcher.d.ts +4 -1
  10. package/dist/concierge-launcher.d.ts.map +1 -1
  11. package/dist/concierge-shell.d.ts +68 -6
  12. package/dist/concierge-shell.d.ts.map +1 -1
  13. package/dist/generated/widget-css.d.ts.map +1 -1
  14. package/dist/host-widget.d.ts +138 -4
  15. package/dist/host-widget.d.ts.map +1 -1
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +5 -5
  19. package/dist/messages.d.ts +71 -1
  20. package/dist/messages.d.ts.map +1 -1
  21. package/dist/next/index.js +1 -1
  22. package/dist/rope-knot.d.ts +13 -0
  23. package/dist/rope-knot.d.ts.map +1 -0
  24. package/dist/session-log.d.ts +1 -1
  25. package/dist/session-log.d.ts.map +1 -1
  26. package/dist/transcript-geometry.d.ts +220 -0
  27. package/dist/transcript-geometry.d.ts.map +1 -0
  28. package/dist/use-chat-session.d.ts +151 -10
  29. package/dist/use-chat-session.d.ts.map +1 -1
  30. package/dist/use-voice-session.d.ts +10 -0
  31. package/dist/use-voice-session.d.ts.map +1 -1
  32. package/dist/voice-session-state.d.ts +17 -0
  33. package/dist/voice-session-state.d.ts.map +1 -1
  34. package/dist/voice-widget.d.ts +52 -4
  35. package/dist/voice-widget.d.ts.map +1 -1
  36. package/dist/widget-cards.d.ts +5 -2
  37. package/dist/widget-cards.d.ts.map +1 -1
  38. package/dist/widget.css +1 -1
  39. package/package.json +4 -3
  40. package/src/styles/concierge.css +377 -0
@@ -0,0 +1,33 @@
1
+ import type { WidgetAvatar } from './avatar.js';
2
+ import type { BotState } from './bot-state.js';
3
+ /**
4
+ * Dispatches to whichever avatar a tenant published — `BotFace` (`'orb'`)
5
+ * or `RopeKnot` (`'knot'`) — with one shared, EXHAUSTIVE `switch` over
6
+ * {@link WidgetAvatar}. `concierge-shell.tsx` (the panel's `lg` slot) and
7
+ * `concierge-launcher.tsx` (the pill's `sm` slot) used to each hardcode
8
+ * their own `avatar === 'knot' ? <RopeKnot/> : <BotFace/>` ternary — fine
9
+ * for exactly two avatars, but a duplicated decision with no compiler
10
+ * backstop: a THIRD avatar added to `WIDGET_AVATARS` (`avatar.ts`) would
11
+ * silently fall through to the orb at both call sites instead of failing to
12
+ * build. The `never` branch below is what turns that into a compile error.
13
+ *
14
+ * The two avatars' own trigger props don't line up 1:1 — `BotFace`'s
15
+ * one-shot flourish is `messageArrived` (a boolean, CSS-class-driven);
16
+ * `RopeKnot`'s is `tightenKey` (a number, restarted via `classList` — see
17
+ * that file's own doc comment for why). Both are accepted here and each is
18
+ * forwarded ONLY to the avatar that understands it; the other simply never
19
+ * receives it, exactly as the two duplicated ternaries already did.
20
+ */
21
+ export interface AvatarFaceProps {
22
+ readonly avatar: WidgetAvatar;
23
+ readonly state: BotState;
24
+ readonly size: 'sm' | 'lg';
25
+ /** Accessible name. Omitted ⇒ decorative; see `bot-face.tsx`'s `labelProps`. */
26
+ readonly label?: string;
27
+ /** `BotFace`-only: the orb's one-shot nod when the visitor's own message lands. */
28
+ readonly messageArrived?: boolean;
29
+ /** `RopeKnot`-only: bumped to replay its click/message-arrived tighten pulse. */
30
+ readonly tightenKey?: number;
31
+ }
32
+ export declare function AvatarFace({ avatar, state, size, label, messageArrived, tightenKey, }: AvatarFaceProps): import("react").JSX.Element;
33
+ //# sourceMappingURL=avatar-face.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"avatar-face.d.ts","sourceRoot":"","sources":["../src/avatar-face.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAC3B,gFAAgF;IAChF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,mFAAmF;IACnF,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAClC,iFAAiF;IACjF,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,KAAK,EACL,IAAI,EACJ,KAAK,EACL,cAAc,EACd,UAAU,GACX,EAAE,eAAe,+BAajB"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Which face the widget draws — a per-tenant `appearance.avatar` choice.
3
+ *
4
+ * `'orb'` is `BotFace`, the animated gradient blob this widget has always
5
+ * shipped. `'knot'` is `RopeKnot`, a hand-drawn rope line that ties and
6
+ * unties itself through the same four {@link BotState}s. Kept as data,
7
+ * separate from the components, for the same reason `bot-state.ts` keeps
8
+ * `BotState` separate from `BotFace`: parsing and defaulting have to be
9
+ * assertable without rendering either avatar.
10
+ */
11
+ export declare const WIDGET_AVATARS: readonly ['orb', 'knot'];
12
+ export type WidgetAvatar = (typeof WIDGET_AVATARS)[number];
13
+ /** What every layer in this package falls back to when a tenant never published one. */
14
+ export declare const DEFAULT_WIDGET_AVATAR: WidgetAvatar;
15
+ /** Whether a value is an avatar this widget knows how to render. Mirrors `bot-state.ts`'s `isBotState`. */
16
+ export declare function isWidgetAvatar(value: unknown): value is WidgetAvatar;
17
+ //# sourceMappingURL=avatar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"avatar.d.ts","sourceRoot":"","sources":["../src/avatar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,YAAI,KAAK,EAAE,MAAM,CAAU,CAAC;AAEvD,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3D,wFAAwF;AACxF,eAAO,MAAM,qBAAqB,EAAE,YAAoB,CAAC;AAEzD,2GAA2G;AAC3G,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE"}
@@ -36,4 +36,21 @@ export declare function BotFace({ state, size, messageArrived, label, }: {
36
36
  /** Accessible name. Omitted ⇒ decorative; see this module's doc comment. */
37
37
  label?: string;
38
38
  }): import("react").JSX.Element;
39
+ /**
40
+ * `role="img"` + a name, or nothing at all — never a name we invented.
41
+ *
42
+ * Exported so `rope-knot.tsx` (the 'knot' avatar) shares this exact
43
+ * accessibility contract rather than redeclaring it — both avatars are
44
+ * decorative-by-default for the identical reason (see this module's doc
45
+ * comment), and a second copy would be free to drift.
46
+ */
47
+ export declare function labelProps(label: string | undefined): {
48
+ readonly 'aria-hidden': true;
49
+ readonly role?: undefined;
50
+ readonly 'aria-label'?: undefined;
51
+ } | {
52
+ readonly 'aria-hidden'?: undefined;
53
+ readonly role: 'img';
54
+ readonly 'aria-label': string;
55
+ };
39
56
  //# sourceMappingURL=bot-face.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bot-face.d.ts","sourceRoot":"","sources":["../src/bot-face.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,YAAY,EAAE,QAAQ,EAAE,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,KAAK,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAExB,wBAAgB,OAAO,CAAC,EACtB,KAAc,EACd,IAAW,EACX,cAAsB,EACtB,KAAK,GACN,EAAE;IACD,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,+BAKA"}
1
+ {"version":3,"file":"bot-face.d.ts","sourceRoot":"","sources":["../src/bot-face.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,YAAY,EAAE,QAAQ,EAAE,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,KAAK,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAExB,wBAAgB,OAAO,CAAC,EACtB,KAAc,EACd,IAAW,EACX,cAAsB,EACtB,KAAK,GACN,EAAE;IACD,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,4EAA4E;IAC5E,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,+BAKA;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS;;;;;;mBAGrC,KAAK;;EACnB"}
@@ -161,6 +161,73 @@ var WidgetToolEventSchema = discriminatedUnion("type", [
161
161
  WidgetChatEscalatedEventSchema,
162
162
  WidgetChatCheckoutEventSchema
163
163
  ]);
164
+ /**
165
+ * ## Storefront reports — the OTHER direction, and why they are not messages
166
+ *
167
+ * A chat request carries EITHER a shopper `message` or a `report`: a typed
168
+ * statement of something the STOREFRONT did, which the shopper never typed.
169
+ * Today there is exactly one kind, `cart_add`, sent by
170
+ * `@saar-ai/web-widget`'s `ConciergeWidget` the moment a bridge add resolves,
171
+ * so the concierge can answer with something that goes WITH the item.
172
+ *
173
+ * It replaced a free-text `Added <title> to cart` sentence sent over the
174
+ * ordinary shopper message channel, which had three defects a shape fixes:
175
+ * a shopper who TYPED those words got the storefront's treatment; the
176
+ * synthetic sentence persisted as a shopper line in the operator's
177
+ * transcript; and the server matched it by its exact wording, so any change
178
+ * to how a card renders a title broke the match with nothing failing.
179
+ *
180
+ * **The sentence the model sees is composed SERVER-side** from these fields
181
+ * (`apps/api/src/widget/widget-chat.service.ts`'s
182
+ * `composeStorefrontReportText`) — the client no longer authors any part of
183
+ * the model's input, which is what makes shopper prose and a storefront
184
+ * report structurally impossible to confuse.
185
+ *
186
+ * **Still client-asserted, and that is unchanged.** A report is trusted
187
+ * exactly as far as the chat token that carried it: whoever holds a session
188
+ * can claim an add that never happened, precisely as they could type the old
189
+ * sentence. Cross-verifying a report against the server's own
190
+ * `CheckoutHandoffService.recordCartAdd` record is explicitly out of scope —
191
+ * the win here is typing, non-collision with shopper prose, and a turn the
192
+ * console can tell apart, not a new trust boundary.
193
+ */
194
+ var REPORT_TITLE_MAX = CARD_TEXT_MAX;
195
+ /**
196
+ * The storefront reporting a completed add. `title` is the card's own
197
+ * display title (what the shopper saw); the ids are the catalog's, carried
198
+ * so a later consumer can join the report to a product without re-matching
199
+ * on prose.
200
+ */
201
+ var WidgetCartAddReportSchema = object({
202
+ kind: literal("cart_add"),
203
+ /**
204
+ * Trimmed before it is bounded, so a whitespace-only title is a
205
+ * rejection rather than a report that names nothing: the server trims
206
+ * the title again when it composes its line, and `min(1)` on the raw
207
+ * string would let `" "` through to `added ""`.
208
+ */
209
+ title: string().trim().min(1).max(REPORT_TITLE_MAX),
210
+ quantity: number().int().min(1).max(999),
211
+ /** The INTERNAL catalog UUID — same field, same meaning, as {@link WidgetChatCardSchema}'s. */
212
+ variantId: string().min(1).max(ID_MAX).optional(),
213
+ productId: string().min(1).max(ID_MAX).optional()
214
+ }).strict();
215
+ /**
216
+ * Every report kind a chat request may carry. A discriminated union of one
217
+ * today — the shape a second kind (`cart_removed`, `checkout_started`) slots
218
+ * into without touching either side's parse code.
219
+ */
220
+ var WidgetChatReportSchema = discriminatedUnion("kind", [WidgetCartAddReportSchema]);
221
+ /**
222
+ * Parse a request body's `report` field. Never throws — the caller decides
223
+ * whether `null` means "absent" (no report was sent) or "malformed", which
224
+ * `apps/api`'s widget chat controller distinguishes by checking presence
225
+ * first and rejecting a present-but-unparseable value with a 400.
226
+ */
227
+ function parseWidgetChatReport(value) {
228
+ const parsed = WidgetChatReportSchema.safeParse(value);
229
+ return parsed.success ? parsed.data : null;
230
+ }
164
231
  /** Parse a tool's raw output for an optional, well-shaped `widgetEvent`. Never throws. */
165
232
  function extractWidgetToolEvent(output) {
166
233
  if (typeof output !== "object" || output === null) return null;
@@ -170,4 +237,4 @@ function extractWidgetToolEvent(output) {
170
237
  return parsed.success ? parsed.data : null;
171
238
  }
172
239
  //#endregion
173
- export { WidgetChatCardSchema, WidgetChatCardsEventSchema, WidgetChatCheckoutEventSchema, WidgetChatDoneEventSchema, WidgetChatErrorEventSchema, WidgetChatEscalatedEventSchema, WidgetChatSseEventSchema, WidgetChatTextDeltaEventSchema, WidgetToolEventSchema, extractWidgetToolEvent };
240
+ export { WidgetCartAddReportSchema, WidgetChatCardSchema, WidgetChatCardsEventSchema, WidgetChatCheckoutEventSchema, WidgetChatDoneEventSchema, WidgetChatErrorEventSchema, WidgetChatEscalatedEventSchema, WidgetChatReportSchema, WidgetChatSseEventSchema, WidgetChatTextDeltaEventSchema, WidgetToolEventSchema, extractWidgetToolEvent, parseWidgetChatReport };