@marketrix.ai/widget 3.8.492 → 3.8.494

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 (67) hide show
  1. package/README.md +4 -4
  2. package/dist/loader.js +8 -1
  3. package/dist/src/components/WidgetRoot.d.ts +19 -0
  4. package/dist/src/components/base/Avatar.d.ts +5 -2
  5. package/dist/src/components/base/Button.d.ts +1 -1
  6. package/dist/src/components/base/ErrorBoundary.d.ts +19 -0
  7. package/dist/src/components/base/Flex.d.ts +14 -0
  8. package/dist/src/components/base/Icon.d.ts +12 -1
  9. package/dist/src/components/base/IconButton.d.ts +4 -0
  10. package/dist/src/components/base/Spinner.d.ts +4 -0
  11. package/dist/src/components/base/Surface.d.ts +22 -5
  12. package/dist/src/components/base/Text.d.ts +17 -1
  13. package/dist/src/components/base/icons.d.ts +16 -0
  14. package/dist/src/components/base/layoutProps.d.ts +20 -6
  15. package/dist/src/components/blocks/ChatInput.d.ts +9 -0
  16. package/dist/src/components/blocks/HeaderBar.d.ts +4 -0
  17. package/dist/src/components/blocks/Notifications.d.ts +20 -10
  18. package/dist/src/components/blocks/WidgetDialog.d.ts +0 -5
  19. package/dist/src/components/blocks/WidgetFab.d.ts +10 -0
  20. package/dist/src/components/chat/MessageItem.d.ts +13 -0
  21. package/dist/src/components/chat/MessageList.d.ts +20 -0
  22. package/dist/src/components/chat/VideoStreamDisplay.d.ts +20 -0
  23. package/dist/src/components/navigation/ShellTabBar.d.ts +0 -1
  24. package/dist/src/components/views/ChatView.d.ts +20 -0
  25. package/dist/src/components/views/HomeView.d.ts +9 -0
  26. package/dist/src/context/ChatContext.d.ts +20 -0
  27. package/dist/src/context/UIStateContext.d.ts +5 -0
  28. package/dist/src/context/WidgetProviders.d.ts +20 -1
  29. package/dist/src/context/sseReducer.d.ts +20 -9
  30. package/dist/src/design-system/component-tokens.d.ts +27 -1
  31. package/dist/src/design-system/semantic-tokens.d.ts +18 -0
  32. package/dist/src/hooks/useDragSnap.d.ts +13 -0
  33. package/dist/src/hooks/useFocusTrap.d.ts +20 -0
  34. package/dist/src/hooks/useWidget.d.ts +11 -1
  35. package/dist/src/index.d.ts +20 -0
  36. package/dist/src/sdk/contracts/common.d.ts +0 -16
  37. package/dist/src/sdk/index.d.ts +0 -1
  38. package/dist/src/services/BrowserToolService.d.ts +26 -5
  39. package/dist/src/services/ChatService.d.ts +15 -1
  40. package/dist/src/services/ChatSessionManager.d.ts +0 -2
  41. package/dist/src/services/DomService.d.ts +18 -3
  42. package/dist/src/services/RrwebSessionRecorder.d.ts +0 -1
  43. package/dist/src/services/ShowModeService.d.ts +22 -5
  44. package/dist/src/services/StorageService.d.ts +20 -1
  45. package/dist/src/services/StreamClient.d.ts +21 -1
  46. package/dist/src/services/keySimulation.d.ts +3 -0
  47. package/dist/src/test/fixtures.d.ts +13 -2
  48. package/dist/src/test/renderWidget.d.ts +6 -0
  49. package/dist/src/test/setup.d.ts +14 -0
  50. package/dist/src/types/index.d.ts +20 -7
  51. package/dist/src/utils/chat.d.ts +21 -4
  52. package/dist/src/utils/color.d.ts +21 -0
  53. package/dist/src/utils/dom.d.ts +21 -0
  54. package/dist/src/utils/errors.d.ts +12 -0
  55. package/dist/src/utils/suggestedActions.d.ts +11 -0
  56. package/dist/src/utils/validation.d.ts +20 -7
  57. package/dist/src/utils/widgetPositioning.d.ts +20 -0
  58. package/dist/widget.mjs +63 -64
  59. package/package.json +6 -6
  60. package/dist/src/components/base/Stack.d.ts +0 -3
  61. package/dist/src/components/chat/MessageContent.d.ts +0 -8
  62. package/dist/src/components/chat/SuggestedActions.d.ts +0 -8
  63. package/dist/src/components/chat/TaskStatusIcon.d.ts +0 -5
  64. package/dist/src/components/chat/ThinkingIndicator.d.ts +0 -6
  65. package/dist/src/components/navigation/ResizeHandle.d.ts +0 -7
  66. package/dist/src/design-system/layers.d.ts +0 -7
  67. package/dist/src/design-system/shadows.d.ts +0 -9
@@ -1,3 +1,23 @@
1
+ /**
2
+ * Colour handling for tenant widget settings: the one home for reading a settings colour into channels,
3
+ * picking text that reads over it, and re-emitting it with an alpha.
4
+ *
5
+ * `toRgb` parses a hex (3- or 6-digit, leading `#` optional — the dashboard accepts both spellings) or an
6
+ * `rgb()`/`rgba()` string into channels, and returns null for anything else. Only those two notations are
7
+ * read: a named colour, `hsl()` or a `var(--…)` custom property is unreadable here by design, and a channel
8
+ * above 255 is refused rather than clamped, so a malformed setting never silently becomes a valid colour.
9
+ * `getContrastingColor` picks the black or white foreground for a background from that colour's WCAG
10
+ * relative luminance — sRGB gamma-decoded per channel, weighted .2126/.7152/.0722, split at 0.5. An
11
+ * unreadable background falls back to BLACK, never white: tenant surfaces skew light, so black stays
12
+ * legible where white would vanish. `addOpacity` re-emits a colour as `rgba()` at the given alpha and
13
+ * passes an unreadable one through UNCHANGED — it stays a CSS value the browser can still resolve, where
14
+ * an `rgba(NaN, …)` would render nothing.
15
+ *
16
+ * `backgroundGradient` is the one home for `widget_background_color` as a `backgroundImage`: the setting may
17
+ * already be a gradient, which is legal only as `backgroundImage`, so a flat colour is emitted as a same-stop
18
+ * gradient and one declaration covers both spellings. Panel and transcript both paint through it, so there is
19
+ * no second expansion to drift from.
20
+ */
1
21
  type Rgb = {
2
22
  r: number;
3
23
  g: number;
@@ -6,4 +26,5 @@ type Rgb = {
6
26
  export declare function toRgb(color: string): Rgb | null;
7
27
  export declare function getContrastingColor(color: string): string;
8
28
  export declare function addOpacity(color: string, opacity: number): string;
29
+ export declare function backgroundGradient(color: string): string;
9
30
  export {};
@@ -1,3 +1,24 @@
1
+ /**
2
+ * Predicates the agent's element index runs against the HOST page's DOM — what counts as a control and
3
+ * whether it is reachable — plus `WIDGET_SHADOW_HOST_CLASS`, set by `bootstrap` on the shadow host so
4
+ * `DomService` can recognise its own overlay chrome instead of reporting it as obscuring the host page, and
5
+ * `TABBABLE_SELECTOR`, the one tab-order candidate query: `send_keys`' Tab simulation walks the host page
6
+ * with it and `useFocusTrap` the widget's own tree, and they must agree on what the browser would focus next.
7
+ *
8
+ * `ancestry` walks element → `parentElement`, crossing each shadow boundary at its host; a bare
9
+ * `parentElement` walk stops dead at a `ShadowRoot`, so a control inside a host-page web component
10
+ * would read as top-level. `disabledReason` names why an element cannot be operated (disabled control,
11
+ * `aria-disabled`, or an `inert` ancestor) as a sentence fragment completing `DomService`'s
12
+ * `Element <n> …` message — reword both together; `disabled` is read duck-typed since it sits on
13
+ * several unrelated control interfaces. `isIndexable`, checked against `INTERACTIVE_ROLES`, is
14
+ * `DomService`'s geometry-aware fallback after its cheap selector/handler checks. Visibility there is more
15
+ * than computed style: an element scrolled out of an `overflow: hidden|clip` ancestor is unreachable despite
16
+ * a non-zero rect (that walk stops at `document.body`), and a zero-size shadow host hides its whole tree, so
17
+ * both chains are climbed. Its one `try` is deliberate — the host page owns this DOM and may have patched
18
+ * anything on it, so a poisoned element is logged with the real error and skipped rather than aborting the
19
+ * whole indexing pass.
20
+ */
1
21
  export declare const WIDGET_SHADOW_HOST_CLASS = "marketrix-widget-container";
22
+ export declare const TABBABLE_SELECTOR = "a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
2
23
  export declare function disabledReason(el: Element): string | null;
3
24
  export declare function isIndexable(el: Element | null): boolean;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The one home for turning an unknown throw into something a caller can read. `errorMessage` returns an
3
+ * `Error`'s message, a thrown string as-is, and `fallback` for anything else — the fallback is a parameter
4
+ * because a widget-init failure names itself on the host page while a tool failure has nothing better than
5
+ * "Unknown error". `withCause` wraps a caller-facing message around a throw while retaining the original as
6
+ * `cause`, so nothing that reports a failure swallows the one underneath it.
7
+ *
8
+ * `cause` is assigned rather than passed to the constructor because this package targets es2020, whose
9
+ * `Error` signature has no options argument.
10
+ */
11
+ export declare function errorMessage(error: unknown, fallback?: string): string;
12
+ export declare function withCause(message: string, cause: unknown): Error;
@@ -1,3 +1,14 @@
1
+ /**
2
+ * The suggested-action chips the home view offers a visitor: one per tenant-configured `widget_chips`
3
+ * entry, or the built-in `DEFAULT_CHIPS` when the tenant configured none. `SuggestedActionItem` is what a
4
+ * chip renders and dispatches as; `getSuggestedActionsFromConfig` maps a `MarketrixConfig`'s chips onto it.
5
+ *
6
+ * A chip's caption doubles as the instruction dispatched on click, so a `show`/`do` caption missing its
7
+ * mode prefix is given one. The strip patterns demand whitespace after the mode word so re-prefixing
8
+ * cannot eat letters from a caption that merely begins with it ("Download…" stays "Do Download…", not
9
+ * "Do wnload…"). `tell` captions are free text and take no prefix. The id carries the chip's index
10
+ * because two chips may share a caption and the slug alone would collide.
11
+ */
1
12
  import type { InstructionType, MarketrixConfig } from '../types';
2
13
  export interface SuggestedActionItem {
3
14
  id: string;
@@ -1,8 +1,27 @@
1
+ /**
2
+ * Runtime validation of the widget's untrusted inputs: two DOM type guards (`isHTMLElement`, `isHTMLScriptElement`,
3
+ * narrowing a possibly-null `Element` off a host-page lookup), and the one home for settings validation —
4
+ * `parseWidgetSettings`, checking a value against the widget audience's `WidgetSettingsData` and returning either
5
+ * the picked settings or the offending field names, via the per-field predicates behind `FIELD_GUARDS` /
6
+ * `FIELD_NAMES`. `RENDER_CONSTANT_NAMES` / `RENDER_CONSTANT_SET` name the fields the widget renders from its own
7
+ * constants; `WidgetRenderedSettings` is the wire shape minus those, `WidgetSettingsResult` the
8
+ * settings-or-invalidFields union returned, and `invalidSettingsMessage` folds invalid field names into one message.
9
+ *
10
+ * Hand-written rather than a zod `safeParse` because importing a schema as a VALUE anywhere reachable from
11
+ * `src/index.tsx` pulls zod's whole runtime into every host page: rolldown cannot prove `z.object(...)` pure, so
12
+ * one value import retains the entire mirror's schema graph. `satisfies Record<keyof WidgetSettingsData, …>` keeps
13
+ * the table honest — a field added api-side fails to compile here until guarded, one removed fails as an unknown
14
+ * key — and `RENDER_CONSTANT_NAMES` mirrors api's `WIDGET_RENDER_CONSTANTS` by hand under the same check.
15
+ *
16
+ * `parseWidgetSettings` PICKS as well as validates: `widgetDefaultGet` returns the render constants too and the
17
+ * result is spread into the widget config, so unknown keys passing through would leak them where zod used to drop
18
+ * them. Render constants stay guarded, since a legacy bundle's stored value must keep passing, but are dropped
19
+ * from the picked result, since nothing renders them.
20
+ */
1
21
  import type { WidgetSettingsData } from '../sdk';
2
22
  export declare function isHTMLElement(element: Element | null): element is HTMLElement;
3
23
  export declare function isHTMLScriptElement(element: Element | null): element is HTMLScriptElement;
4
24
  declare const RENDER_CONSTANT_NAMES: readonly ["widget_border_radius", "widget_font_size", "widget_animation_duration", "widget_fade_duration"];
5
- /** The wire shape minus the fields the widget renders from its own constants — see WIDGET_RENDER_CONSTANTS. */
6
25
  export type WidgetRenderedSettings = Omit<WidgetSettingsData, (typeof RENDER_CONSTANT_NAMES)[number]>;
7
26
  export type WidgetSettingsResult = {
8
27
  settings: WidgetRenderedSettings;
@@ -11,12 +30,6 @@ export type WidgetSettingsResult = {
11
30
  settings?: undefined;
12
31
  invalidFields: string[];
13
32
  };
14
- /**
15
- * Validates and PICKS, because stripping is load-bearing: `widgetDefaultGet` returns the render
16
- * constants too, and the settings object is spread into the widget config — passing unknown keys
17
- * through would leak them where zod used to drop them. The render constants are guarded (a legacy
18
- * bundle's stored value must still pass) but dropped from the picked result, since nothing renders them.
19
- */
20
33
  export declare function parseWidgetSettings(value: unknown): WidgetSettingsResult;
21
34
  export declare const invalidSettingsMessage: (invalidFields: string[]) => string;
22
35
  export {};
@@ -1,3 +1,23 @@
1
+ /**
2
+ * Corner geometry for the widget: the four pinnable corners, the CSS offsets that place launcher and
3
+ * panel at one, the resize grip each corner implies, and the drag-snap math.
4
+ *
5
+ * `getCorner` maps a `WidgetPosition` to its `{vertical, horizontal}` CSS sides. `isWidgetPosition`
6
+ * narrows an unknown — a value read back out of localStorage — to one of the four, testing a list of
7
+ * names rather than `in CORNERS`, so the keys every object inherits (`toString`, `__proto__`) are
8
+ * rejected. `getPanelPositionStyle` turns a corner into the inline style pinning an element to it.
9
+ * `getResizeGrip`, whose return type is exported as `ResizeGrip`, describes the handle on the corner
10
+ * diagonally OPPOSITE the pinned one — the panel grows away from its anchor, so that is the only
11
+ * corner free to move; `growX`/`growY` are the signs converting pointer delta into size delta, and
12
+ * `cursor` is the diagonal the grip itself lies on. `getAnchorTopLeft` resolves a corner to viewport
13
+ * top-left pixels so drag math runs in one coordinate space, and `getNearestCornerByTranslation` adds
14
+ * a drag's translation to that anchor and returns the corner whose own anchor is nearest by
15
+ * straight-line distance — proximity, never per-axis resolution.
16
+ *
17
+ * EDGE_OFFSET_PX is the one edge offset: launcher and panel both position through
18
+ * `getPanelPositionStyle`, so there is no second declaration to drift from — it used to be pinned
19
+ * against a Tailwind class string.
20
+ */
1
21
  import type React from 'react';
2
22
  import type { WidgetPosition } from '../types';
3
23
  export declare const getCorner: (position: WidgetPosition) => {