@helpai/elements 1.8.0 → 1.9.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.
package/index.d.ts CHANGED
@@ -93,8 +93,8 @@ type Position = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
93
93
  type Mode = 'floating' | 'inline' | 'standalone' | 'page' | 'modal' | 'drawer';
94
94
  /** End-user text-size preference — scales the whole type ramp. */
95
95
  type TextSize = 'small' | 'normal' | 'large';
96
- /** Theme preference. `auto` follows `prefers-color-scheme`. */
97
- type ThemePreference = 'auto' | 'light' | 'dark';
96
+ /** Theme preference. `auto` follows `prefers-color-scheme`; `host` follows the page's own light/dark. */
97
+ type ThemePreference = 'auto' | 'light' | 'dark' | 'host';
98
98
  /**
99
99
  * How the assistant's reply is delivered.
100
100
  *
@@ -591,6 +591,8 @@ interface ResolvedModules {
591
591
  }
592
592
  /** CSS-custom-property overrides applied as inline styles on the host. */
593
593
  interface ThemeOverrides {
594
+ /** Light/dark beside the overrides — `host` keeps a deployment's accent while the page sets the mode. */
595
+ mode?: ThemePreference;
594
596
  accent?: string;
595
597
  accentText?: string;
596
598
  radius?: string;
@@ -1211,8 +1213,15 @@ declare const widgetSettingsSchema: z.ZodObject<{
1211
1213
  theme: z.ZodDefault<z.ZodUnion<readonly [z.ZodEnum<{
1212
1214
  auto: "auto";
1213
1215
  dark: "dark";
1216
+ host: "host";
1214
1217
  light: "light";
1215
1218
  }>, z.ZodObject<{
1219
+ mode: z.ZodOptional<z.ZodEnum<{
1220
+ auto: "auto";
1221
+ dark: "dark";
1222
+ host: "host";
1223
+ light: "light";
1224
+ }>>;
1216
1225
  accent: z.ZodOptional<z.ZodString>;
1217
1226
  accentText: z.ZodOptional<z.ZodString>;
1218
1227
  radius: z.ZodOptional<z.ZodString>;
@@ -1546,8 +1555,15 @@ declare const widgetConfigSchema: z.ZodObject<{
1546
1555
  theme: z.ZodDefault<z.ZodUnion<readonly [z.ZodEnum<{
1547
1556
  auto: "auto";
1548
1557
  dark: "dark";
1558
+ host: "host";
1549
1559
  light: "light";
1550
1560
  }>, z.ZodObject<{
1561
+ mode: z.ZodOptional<z.ZodEnum<{
1562
+ auto: "auto";
1563
+ dark: "dark";
1564
+ host: "host";
1565
+ light: "light";
1566
+ }>>;
1551
1567
  accent: z.ZodOptional<z.ZodString>;
1552
1568
  accentText: z.ZodOptional<z.ZodString>;
1553
1569
  radius: z.ZodOptional<z.ZodString>;
@@ -1882,8 +1898,15 @@ declare const widgetConfigPartialSchema: z.ZodObject<{
1882
1898
  theme: z.ZodOptional<z.ZodDefault<z.ZodUnion<readonly [z.ZodEnum<{
1883
1899
  auto: "auto";
1884
1900
  dark: "dark";
1901
+ host: "host";
1885
1902
  light: "light";
1886
1903
  }>, z.ZodObject<{
1904
+ mode: z.ZodOptional<z.ZodEnum<{
1905
+ auto: "auto";
1906
+ dark: "dark";
1907
+ host: "host";
1908
+ light: "light";
1909
+ }>>;
1887
1910
  accent: z.ZodOptional<z.ZodString>;
1888
1911
  accentText: z.ZodOptional<z.ZodString>;
1889
1912
  radius: z.ZodOptional<z.ZodString>;
@@ -2180,8 +2203,15 @@ declare const widgetSettingsPartialSchema: z.ZodObject<{
2180
2203
  theme: z.ZodOptional<z.ZodDefault<z.ZodUnion<readonly [z.ZodEnum<{
2181
2204
  auto: "auto";
2182
2205
  dark: "dark";
2206
+ host: "host";
2183
2207
  light: "light";
2184
2208
  }>, z.ZodObject<{
2209
+ mode: z.ZodOptional<z.ZodEnum<{
2210
+ auto: "auto";
2211
+ dark: "dark";
2212
+ host: "host";
2213
+ light: "light";
2214
+ }>>;
2185
2215
  accent: z.ZodOptional<z.ZodString>;
2186
2216
  accentText: z.ZodOptional<z.ZodString>;
2187
2217
  radius: z.ZodOptional<z.ZodString>;
@@ -2532,8 +2562,15 @@ declare const serverConfigSchema: z.ZodObject<{
2532
2562
  theme: z.ZodOptional<z.ZodDefault<z.ZodUnion<readonly [z.ZodEnum<{
2533
2563
  auto: "auto";
2534
2564
  dark: "dark";
2565
+ host: "host";
2535
2566
  light: "light";
2536
2567
  }>, z.ZodObject<{
2568
+ mode: z.ZodOptional<z.ZodEnum<{
2569
+ auto: "auto";
2570
+ dark: "dark";
2571
+ host: "host";
2572
+ light: "light";
2573
+ }>>;
2537
2574
  accent: z.ZodOptional<z.ZodString>;
2538
2575
  accentText: z.ZodOptional<z.ZodString>;
2539
2576
  radius: z.ZodOptional<z.ZodString>;
@@ -2820,8 +2857,15 @@ declare const handshakeResponseSchema: z.ZodObject<{
2820
2857
  theme: z.ZodOptional<z.ZodDefault<z.ZodUnion<readonly [z.ZodEnum<{
2821
2858
  auto: "auto";
2822
2859
  dark: "dark";
2860
+ host: "host";
2823
2861
  light: "light";
2824
2862
  }>, z.ZodObject<{
2863
+ mode: z.ZodOptional<z.ZodEnum<{
2864
+ auto: "auto";
2865
+ dark: "dark";
2866
+ host: "host";
2867
+ light: "light";
2868
+ }>>;
2825
2869
  accent: z.ZodOptional<z.ZodString>;
2826
2870
  accentText: z.ZodOptional<z.ZodString>;
2827
2871
  radius: z.ZodOptional<z.ZodString>;
@@ -3174,6 +3218,24 @@ interface EventMap {
3174
3218
  previous: string;
3175
3219
  current: string;
3176
3220
  };
3221
+ /** The widget's state changed — open, ready, unread or the conversation. Payload is the whole new state. */
3222
+ state: WidgetState;
3223
+ /** How many conversations have replies the visitor hasn't read changed. Payload is the new count. */
3224
+ unread: number;
3225
+ }
3226
+ /** What a page can read about the widget at any moment (`chat.state`), and the `state` event's payload. */
3227
+ interface WidgetState {
3228
+ /** The panel is showing. Always `true` for `inline`, `page` and `standalone`. */
3229
+ open: boolean;
3230
+ /** The widget has connected (its first handshake settled) and takes commands right away. */
3231
+ ready: boolean;
3232
+ /**
3233
+ * Conversations with replies the visitor hasn't read. Known once the widget has been opened in this page load
3234
+ * (a closed widget makes no requests beyond the handshake), and kept live from then on.
3235
+ */
3236
+ unread: number;
3237
+ /** The visitor's current conversation, once there is one. */
3238
+ conversationId?: string;
3177
3239
  }
3178
3240
  type EventName = keyof EventMap;
3179
3241
  /**
@@ -3302,6 +3364,25 @@ export interface ChatWidgetInstance {
3302
3364
  * ```
3303
3365
  */
3304
3366
  ask: (text: string, options?: AskOptions) => void;
3367
+ /**
3368
+ * The widget's state right now: `open`, `ready`, `unread` (conversations with unread replies) and the current
3369
+ * `conversationId`. The `state` event delivers each change; `unread` fires when the count changes.
3370
+ *
3371
+ * @example
3372
+ * ```ts
3373
+ * helpLink.dataset.unread = String(chat.state.unread);
3374
+ * chat.on('unread', (count) => (helpLink.dataset.unread = String(count)));
3375
+ * ```
3376
+ */
3377
+ readonly state: WidgetState;
3378
+ /** Resolves once the widget has connected; commands sent after it act at once. Resolves once, never rejects. */
3379
+ readonly ready: Promise<void>;
3380
+ /**
3381
+ * Start over as a new anonymous visitor — call it when your user logs out. Forgets the stored visitor, their current
3382
+ * conversation, preferences and the user context set with `setUserContext`, then reconnects as a first visit.
3383
+ * Listeners added with `on()` stay.
3384
+ */
3385
+ reset: () => void;
3305
3386
  /**
3306
3387
  * Subscribe to a lifecycle event. Returns an `off` function. See
3307
3388
  * {@link EventMap} for the full set + payload shapes — currently
@@ -3445,4 +3526,4 @@ export declare const brand: {
3445
3526
  readonly domain: string;
3446
3527
  readonly siteUrl: string;
3447
3528
  };
3448
- export type { AskOptions, Asset, BlocksConfig, ChatWidgetOptions, ConnectionConfig, ConnectionConfigPartial, EventMap, EventName, HandshakeResponse, HookListener, Link, LogEntry, LogLevel, OpenTarget, ResolvedOptions, ServerConfig, SiteConfig, WidgetConfig, WidgetConfigPartial, WidgetSettings, WidgetSettingsPartial };
3529
+ export type { AskOptions, Asset, BlocksConfig, ChatWidgetOptions, ConnectionConfig, ConnectionConfigPartial, EventMap, EventName, HandshakeResponse, HookListener, Link, LogEntry, LogLevel, OpenTarget, ResolvedOptions, ServerConfig, SiteConfig, WidgetConfig, WidgetConfigPartial, WidgetSettings, WidgetSettingsPartial, WidgetState };