claudius-chat-widget 1.11.0 → 1.13.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/dist/index.d.cts CHANGED
@@ -106,571 +106,663 @@ export declare class ChatApiClient {
106
106
  * @throws {@link ChatApiError} when the request fails after all retries.
107
107
  */
108
108
  sendMessage(messages: ChatMessage[]): Promise<ChatResponse>;
109
- private fetchWithTimeout;
110
- private isRetryable;
111
- private getRetryDelay;
112
- private delay;
113
- }
114
-
115
- /**
116
- * Options for {@link ChatApiClient}.
117
- */
118
- export declare interface ChatApiClientOptions {
119
109
  /**
120
- * Maximum retries after the first attempt, for retryable failures (HTTP
121
- * 429/503, network errors, timeouts).
122
- * @defaultValue `2`
123
- */
124
- maxRetries?: number;
125
- /**
126
- * Minimum gap between sends, in milliseconds. A send inside this window
127
- * rejects with {@link DebounceError}. Set to 0 to disable.
128
- * @defaultValue `300`
129
- */
130
- debounceMs?: number;
131
- /**
132
- * Per-attempt request timeout in milliseconds. Aborts the in-flight fetch
133
- * via `AbortController` and surfaces a retryable {@link ChatApiError} with
134
- * code `"TIMEOUT"`. Set to 0 to disable.
135
- * @defaultValue `30000`
136
- */
137
- timeoutMs?: number;
138
- }
139
-
140
- /**
141
- * Error thrown by {@link ChatApiClient} when a chat request ultimately fails:
142
- * either after exhausting retries, or immediately for a non-retryable status.
143
- */
144
- export declare class ChatApiError extends Error {
145
- /** HTTP status code, or `0` for network and timeout failures. */
146
- readonly status: number;
147
- /** Machine-readable error code, when available (e.g. `"TIMEOUT"`). */
148
- readonly code?: string | undefined;
149
- /** Seconds to wait before retrying, parsed from the `Retry-After` header. */
150
- readonly retryAfter?: number | undefined;
151
- /**
152
- * Create a {@link ChatApiError}.
110
+ * Send the conversation to the streaming chat endpoint and resolve with the
111
+ * assistant's full reply once the stream completes. Text deltas are
112
+ * delivered through {@link ChatStreamOptions.onChunk} as they arrive.
153
113
  *
154
- * @param message - Human-readable error message.
155
- * @param status - HTTP status code, or `0` for network and timeout failures.
156
- * @param code - Optional machine-readable error code (e.g. `"TIMEOUT"`, `"NETWORK_ERROR"`).
157
- * @param retryAfter - Seconds to wait before retrying, from the `Retry-After` header.
158
- */
159
- constructor(message: string,
160
- /** HTTP status code, or `0` for network and timeout failures. */
161
- status: number,
162
- /** Machine-readable error code, when available (e.g. `"TIMEOUT"`). */
163
- code?: string | undefined,
164
- /** Seconds to wait before retrying, parsed from the `Retry-After` header. */
165
- retryAfter?: number | undefined);
166
- }
167
-
168
- /**
169
- * Error response body returned by the Worker when a chat request fails.
170
- */
171
- export declare interface ChatErrorResponse {
172
- /** Human-readable error message. */
173
- error: string;
174
- /** Optional machine-readable error code (e.g. `"RATE_LIMITED"`). */
175
- code?: string;
176
- }
177
-
178
- /**
179
- * A single chat message exchanged between the user and the assistant.
180
- */
181
- export declare interface ChatMessage {
182
- /** Stable unique identifier, used as the React list key. */
183
- id: string;
184
- /** Who authored the message. */
185
- role: "user" | "assistant";
186
- /** Plain-text message body. */
187
- content: string;
188
- /** Sources cited by the assistant for this message, when any. */
189
- sources?: Source[];
190
- }
191
-
192
- /**
193
- * Request payload sent to the Worker `POST /api/chat` endpoint.
194
- */
195
- export declare interface ChatRequest {
196
- /** The full conversation so far, oldest message first. */
197
- messages: ChatMessage[];
198
- }
199
-
200
- /**
201
- * Successful response body from `POST /api/chat`.
202
- */
203
- export declare interface ChatResponse {
204
- /** The assistant's reply text. */
205
- reply: string;
206
- /** Sources the assistant cited, when any. */
207
- sources?: Source[];
208
- }
209
-
210
- /**
211
- * Root Claudius chat widget: a floating toggle button that opens a chat window
212
- * backed by the Worker chat API. Render a single instance on the page.
213
- *
214
- * @param props - See {@link ChatWidgetProps}.
215
- * @example
216
- * ```tsx
217
- * <ChatWidget apiUrl="https://api.example.com" title="Support" />
218
- * ```
219
- */
220
- export declare function ChatWidget({ apiUrl, title, subtitle, welcomeMessage, placeholder, persistMessages, storageKeyPrefix, requestTimeoutMs, theme, accentColor, position, locale, translations: translationOverrides, triggers, plugins, }: ChatWidgetProps): JSX_2.Element;
221
-
222
- /**
223
- * Props for the {@link ChatWidget} component.
224
- */
225
- export declare interface ChatWidgetProps {
226
- /** Absolute URL of the Worker chat endpoint (e.g. `https://api.example.com`). */
227
- apiUrl: string;
228
- /** Header title. Falls back to the active locale's default title. */
229
- title?: string;
230
- /** Header subtitle shown beneath the title. */
231
- subtitle?: string;
232
- /** First assistant message shown when the chat opens. */
233
- welcomeMessage?: string;
234
- /** Placeholder text for the message input. */
235
- placeholder?: string;
236
- /**
237
- * Persist the conversation to storage so it survives reloads.
238
- * @defaultValue `false`
239
- */
240
- persistMessages?: boolean;
241
- /** Prefix for the storage key used when {@link ChatWidgetProps.persistMessages} is enabled. */
242
- storageKeyPrefix?: string;
243
- /** Abort a chat request after this many milliseconds. */
244
- requestTimeoutMs?: number;
245
- /**
246
- * Color-scheme mode ("light" | "dark" | "auto"), a built-in theme name
247
- * ("default" | "minimal" | "playful" | "corporate"), an inline
248
- * ClaudiusTheme object, or a URL to a theme JSON file.
249
- * @defaultValue `"light"`
250
- */
251
- theme?: ClaudiusThemeInput;
252
- /** Accent color override; wins over the theme's accent in both light and dark. */
253
- accentColor?: string;
254
- /**
255
- * Corner of the viewport the widget docks to.
256
- * @defaultValue `"bottom-right"`
257
- */
258
- position?: WidgetPosition;
259
- /** BCP-47 locale used to select built-in translations. */
260
- locale?: LocaleCode;
261
- /** Partial overrides merged over the resolved locale translations. */
262
- translations?: Partial<ClaudiusTranslations>;
263
- /** Proactive open/greeting rules evaluated against the current page. */
264
- triggers?: Trigger[];
265
- /**
266
- * Middleware run around each message: `onBeforeSend`, `onAfterReceive`, and
267
- * `onError`. Hooks run in array order and may modify, replace, or
268
- * short-circuit messages. See {@link ClaudiusPlugin}.
269
- */
270
- plugins?: ClaudiusPlugin[];
271
- }
272
-
273
- /** An analytics event emitted by {@link pluginAnalytics}. */
274
- export declare type ClaudiusAnalyticsEvent = {
275
- /** Event discriminant. */
276
- type: "message_sent";
277
- /** Always `"user"`. */
278
- role: "user";
279
- /** Message text, or `""` when `includeContent` is `false`. */
280
- content: string;
281
- /** Length of the message in characters. */
282
- chars: number;
283
- } | {
284
- /** Event discriminant. */
285
- type: "message_received";
286
- /** Always `"assistant"`. */
287
- role: "assistant";
288
- /** Reply text, or `""` when `includeContent` is `false`. */
289
- content: string;
290
- /** Length of the reply in characters. */
291
- chars: number;
292
- } | {
293
- /** Event discriminant. */
294
- type: "chat_error";
295
- /** The error message. */
296
- message: string;
297
- /** Machine-readable error code, when available (e.g. `"TIMEOUT"`). */
298
- code?: string;
299
- };
300
-
301
- /**
302
- * A client-side middleware that runs around the chat message lifecycle. Pass
303
- * an array of plugins to {@link ChatWidget} via the `plugins` prop; hooks run
304
- * in array order.
305
- *
306
- * Hooks may be async, and may modify, replace, or short-circuit messages. A
307
- * hook that throws is caught and logged — a misbehaving plugin will not break
308
- * the chat — so security-sensitive transforms (e.g. PII redaction) should be
309
- * written defensively.
310
- *
311
- * @example
312
- * ```ts
313
- * const logger: ClaudiusPlugin = {
314
- * name: "logger",
315
- * onBeforeSend: (message) => { console.log("sending", message.content); },
316
- * onAfterReceive: (message) => { console.log("received", message.content); },
317
- * };
318
- * ```
319
- */
320
- export declare interface ClaudiusPlugin {
321
- /** Stable identifier, used in log messages. */
322
- name: string;
323
- /**
324
- * Runs before the user message is sent. Return a {@link ChatMessage} to
325
- * replace it (the returned message is both displayed and sent), return
326
- * nothing to leave it unchanged, or call {@link BeforeSendContext.respondWith}
327
- * / {@link BeforeSendContext.abort} to short-circuit.
328
- */
329
- onBeforeSend?(message: ChatMessage, ctx: BeforeSendContext): MaybePromise<ChatMessage | void>;
330
- /**
331
- * Runs after the assistant reply is received, before it is rendered. Return
332
- * a {@link ChatMessage} to replace it, or nothing to leave it unchanged.
333
- */
334
- onAfterReceive?(message: ChatMessage, ctx: PluginContext): MaybePromise<ChatMessage | void>;
335
- /**
336
- * Runs when a send fails. Observe the error, or call
337
- * {@link ErrorContext.respondWith} to render a fallback reply instead of the
338
- * error UI.
339
- */
340
- onError?(error: Error, ctx: ErrorContext): MaybePromise<void>;
341
- }
342
-
343
- /**
344
- * A Claudius design-token theme. Every value is a CSS string applied via
345
- * --cl-* custom properties. `colors` apply to both light and dark modes
346
- * unless `colorsDark` overrides a token for dark mode specifically.
347
- *
348
- * JSON theme files validate against
349
- * https://claudius-docs.pages.dev/schema/theme.v1.json
350
- */
351
- export declare interface ClaudiusTheme {
352
- /** Optional JSON Schema URL, for editor validation and autocomplete. */
353
- $schema?: string;
354
- /** Human-readable theme name. */
355
- name?: string;
356
- /** Initial color scheme this theme is designed for. Defaults to "light". */
357
- colorScheme?: "light" | "dark" | "auto";
358
- /** Color token overrides applied in both light and dark mode. */
359
- colors?: Partial<Record<ThemeColorToken, string>>;
360
- /** Color token overrides applied only in dark mode, layered over {@link ClaudiusTheme.colors}. */
361
- colorsDark?: Partial<Record<ThemeColorToken, string>>;
362
- /** Border-radius token overrides. */
363
- radii?: Partial<Record<ThemeRadiusToken, string>>;
364
- /** Box-shadow token overrides. */
365
- shadows?: Partial<Record<ThemeShadowToken, string>>;
366
- /** Font-family token overrides. */
367
- fonts?: Partial<Record<ThemeFontToken, string>>;
368
- }
369
-
370
- /**
371
- * Everything the `theme` option accepts: the original color-scheme modes, a
372
- * built-in theme name, an inline theme object, or a URL to a theme JSON file.
373
- * `(string & {})` keeps literal autocomplete while allowing URLs.
374
- */
375
- export declare type ClaudiusThemeInput = "light" | "dark" | "auto" | BuiltinThemeName | ClaudiusTheme | (string & {});
376
-
377
- /**
378
- * Every user-facing string the widget renders. Pass a {@link ClaudiusTranslations}
379
- * (or a partial override) to localize the UI. English is the source of truth;
380
- * see {@link defaultTranslations}.
381
- */
382
- export declare interface ClaudiusTranslations {
383
- /** Chat window header title. */
384
- title: string;
385
- /** Chat window header subtitle. */
386
- subtitle: string;
387
- /** First assistant message shown when the chat opens. */
388
- welcomeMessage: string;
389
- /** Accessible label for the close button. */
390
- closeChat: string;
391
- /** Accessible label for the message list region. */
392
- chatMessages: string;
393
- /** Accessible label for the typing indicator. */
394
- typingIndicator: string;
395
- /** Placeholder text for the message input. */
396
- placeholder: string;
397
- /** Accessible label for the send button. */
398
- sendMessage: string;
399
- /** Accessible label for the message input field. */
400
- typeYourMessage: string;
401
- /** Accessible label for the button that opens the chat. */
402
- openChat: string;
403
- /** Accessible label for dismissing the greeting bubble. */
404
- dismissGreeting: string;
405
- /** Generic fallback error message. */
406
- errorGeneric: string;
407
- /** Error shown when the network request fails. */
408
- errorConnection: string;
409
- /** Error shown when a request times out. */
410
- errorTimeout: string;
411
- /** Error shown when rate-limited (per-minute limit). */
412
- errorRateLimitMinute: string;
413
- /** Error shown when rate-limited (per-hour limit). */
414
- errorRateLimitHour: string;
415
- /** Label for the retry action on a failed message. */
416
- errorRetry: string;
417
- }
418
-
419
- /**
420
- * Build a complete {@link ClaudiusTranslations} from the English defaults,
421
- * applying the given overrides.
422
- *
423
- * @param overrides - Strings to override on top of {@link defaultTranslations}.
424
- * @returns A complete translations object.
425
- */
426
- export declare function createTranslations(overrides?: Partial<ClaudiusTranslations>): ClaudiusTranslations;
427
-
428
- /**
429
- * Error thrown by {@link ChatApiClient.sendMessage} when a send is rejected
430
- * for arriving within the configured debounce window.
431
- */
432
- export declare class DebounceError extends Error {
433
- /** Creates a `DebounceError` with a fixed message. */
434
- constructor();
435
- }
436
-
437
- /**
438
- * Default PII patterns: email addresses, North-American-style phone numbers,
439
- * US Social Security numbers, and 13–16 digit card-like sequences. These are
440
- * intentionally conservative starting points — tune {@link RedactPiiOptions.patterns}
441
- * for your data.
442
- */
443
- export declare const DEFAULT_PII_PATTERNS: readonly RegExp[];
444
-
445
- /** The default (English) translations, used when no locale or override applies. */
446
- export declare const defaultTranslations: ClaudiusTranslations;
447
-
448
- /**
449
- * Detect the best {@link LocaleCode} for the current environment: the document
450
- * `lang` attribute first, then the browser language, falling back to `"en"`.
451
- *
452
- * @returns The detected locale code.
453
- */
454
- export declare function detectLocale(): LocaleCode;
455
-
456
- /**
457
- * Context for {@link ClaudiusPlugin.onError}. Adds the ability to recover from
458
- * a failed send by rendering a reply in place of the error UI.
459
- */
460
- export declare interface ErrorContext extends PluginContext {
461
- /**
462
- * Recover from the failure by rendering this assistant reply instead of the
463
- * error state. Stops the hook chain — later plugins' `onError` hooks do not
464
- * run.
465
- */
466
- respondWith(reply: string | PluginReply): void;
467
- }
468
-
469
- /** BCP-47 primary language subtags the widget ships built-in translations for. */
470
- export declare type LocaleCode = "en" | "es" | "fr" | "de";
471
-
472
- /** Built-in translations keyed by {@link LocaleCode}. */
473
- export declare const locales: Record<LocaleCode, ClaudiusTranslations>;
474
-
475
- /** A value that may be returned synchronously or as a promise. */
476
- export declare type MaybePromise<T> = T | Promise<T>;
477
-
478
- /**
479
- * Reference plugin that emits a structured analytics event for every message
480
- * sent, every reply received, and every error. It never modifies messages.
481
- *
482
- * @example
483
- * ```ts
484
- * <ChatWidget
485
- * apiUrl={url}
486
- * plugins={[pluginAnalytics({ onEvent: (e) => gtag("event", e.type, e) })]}
487
- * />
488
- * ```
489
- */
490
- export declare function pluginAnalytics(options: AnalyticsPluginOptions): ClaudiusPlugin;
491
-
492
- /**
493
- * Reference plugin that answers matching messages locally, without calling the
494
- * API. The first rule whose matcher fires short-circuits the send via
495
- * `ctx.respondWith`, so the network is never hit for that turn.
496
- *
497
- * @example
498
- * ```ts
499
- * <ChatWidget
500
- * apiUrl={url}
501
- * plugins={[pluginCannedResponses({
502
- * rules: [
503
- * { match: "hours", reply: "We're open 9-5, Mon-Fri." },
504
- * { match: /pricing|cost/i, reply: "See https://example.com/pricing." },
505
- * ],
506
- * })]}
507
- * />
508
- * ```
509
- */
510
- export declare function pluginCannedResponses(options: CannedResponsesOptions): ClaudiusPlugin;
511
-
512
- /**
513
- * Read-only context shared by every plugin hook.
514
- *
515
- * `messages` is a snapshot of the conversation at the moment the hook runs:
516
- * in {@link ClaudiusPlugin.onBeforeSend} it excludes the in-flight user
517
- * message; in {@link ClaudiusPlugin.onAfterReceive} and
518
- * {@link ClaudiusPlugin.onError} it includes it.
519
- */
520
- export declare interface PluginContext {
521
- /** Conversation snapshot, oldest message first. Treat as immutable. */
522
- readonly messages: readonly ChatMessage[];
523
- /** The Worker chat endpoint URL the widget posts to. */
524
- readonly apiUrl: string;
525
- }
526
-
527
- /**
528
- * Reference plugin that strips PII from the user's message before it leaves the
529
- * browser. The redacted text is what gets displayed and sent, so the user sees
530
- * that redaction happened. Optionally redacts assistant replies too.
531
- *
532
- * @example
533
- * ```ts
534
- * <ChatWidget apiUrl={url} plugins={[pluginRedactPII()]} />
535
- * ```
536
- */
537
- export declare function pluginRedactPII(options?: RedactPiiOptions): ClaudiusPlugin;
538
-
539
- /**
540
- * A synthesized assistant reply, produced by a plugin instead of (or in
541
- * recovery from) a network round-trip. Passed to
542
- * {@link BeforeSendContext.respondWith} and {@link ErrorContext.respondWith}.
543
- */
544
- export declare interface PluginReply {
545
- /** The assistant reply text to render. */
546
- content: string;
547
- /** Optional sources to attach to the synthesized reply. */
548
- sources?: Source[];
549
- }
550
-
551
- /** Options for {@link pluginRedactPII}. */
552
- export declare interface RedactPiiOptions {
553
- /**
554
- * Patterns to redact. Each must carry the global (`g`) flag.
555
- * @defaultValue {@link DEFAULT_PII_PATTERNS}
556
- */
557
- patterns?: readonly RegExp[];
558
- /**
559
- * Text substituted for each match.
560
- * @defaultValue `"[redacted]"`
561
- */
562
- replacement?: string;
563
- /**
564
- * Also redact the assistant's replies, not just outgoing user messages.
565
- * @defaultValue `false`
566
- */
567
- redactReplies?: boolean;
568
- }
569
-
570
- /** Replace every match of every pattern in `text` with `replacement`. */
571
- export declare function redactText(text: string, patterns: readonly RegExp[], replacement: string): string;
572
-
573
- /**
574
- * Resolve the final translations for a locale, applying any per-string
575
- * overrides on top of the chosen locale's defaults.
576
- *
577
- * @param options - Locale and override settings.
578
- * @returns A complete translations object.
579
- */
580
- export declare function resolveTranslations(options?: ResolveTranslationsOptions): ClaudiusTranslations;
581
-
582
- /** Options for {@link resolveTranslations}. */
583
- export declare interface ResolveTranslationsOptions {
584
- /** Locale to use. Defaults to the result of {@link detectLocale}. */
585
- locale?: LocaleCode;
586
- /** Per-string overrides layered over the chosen locale's translations. */
587
- translations?: Partial<ClaudiusTranslations>;
588
- }
589
-
590
- /**
591
- * A cited source the assistant referenced when answering. Rendered as a link
592
- * in the chat and grouped in the sources sidebar.
593
- */
594
- export declare interface Source {
595
- /** Absolute URL of the source. */
596
- url: string;
597
- /** Human-readable link title shown to the user. */
598
- title: string;
599
- /** Origin category, used to group and label the source. */
600
- type: "blog" | "page" | "external";
601
- }
602
-
603
- declare const THEME_COLOR_TOKENS: readonly ["accent", "accentText", "accentSoft", "accentTextMuted", "surface", "surfaceMuted", "text", "textMuted", "border", "userBubble", "userBubbleText", "assistantBubble", "assistantBubbleText", "field", "error", "errorSurface", "errorText", "link", "scrim"];
604
-
605
- declare const THEME_FONT_TOKENS: readonly ["heading", "body"];
606
-
607
- declare const THEME_RADIUS_TOKENS: readonly ["sm", "md", "lg", "full", "tail"];
608
-
609
- declare const THEME_SHADOW_TOKENS: readonly ["elevated", "floating", "floatingHover"];
610
-
611
- /** Names of the color tokens a theme can override (e.g. `accent`, `surface`, `text`). */
612
- export declare type ThemeColorToken = (typeof THEME_COLOR_TOKENS)[number];
613
-
614
- /** Names of the font-family tokens a theme can override. */
615
- export declare type ThemeFontToken = (typeof THEME_FONT_TOKENS)[number];
616
-
617
- /** Names of the border-radius tokens a theme can override. */
618
- export declare type ThemeRadiusToken = (typeof THEME_RADIUS_TOKENS)[number];
619
-
620
- /** Names of the box-shadow tokens a theme can override. */
621
- export declare type ThemeShadowToken = (typeof THEME_SHADOW_TOKENS)[number];
622
-
623
- /**
624
- * A proactive engagement rule. Each variant fires at most once per page on a
625
- * different signal: elapsed time, scroll depth, exit intent, or URL match.
626
- */
627
- export declare type Trigger = {
628
- /** Fire after a fixed dwell time. */
629
- on: "time";
630
- /** Seconds to wait before firing. */
631
- seconds: number;
632
- /** Only fire when the current URL matches this pattern. */
633
- matchUrl?: UrlPattern;
634
- /** Action to run when the trigger fires. */
635
- action: TriggerAction;
636
- } | {
637
- /** Fire once the user scrolls past a depth threshold. */
638
- on: "scroll";
639
- /** Scroll depth (0-100) that fires the trigger. */
640
- percent: number;
641
- /** Only fire when the current URL matches this pattern. */
642
- matchUrl?: UrlPattern;
643
- /** Action to run when the trigger fires. */
644
- action: TriggerAction;
645
- } | {
646
- /** Fire when the pointer leaves the top of the viewport (exit intent). */
647
- on: "exit-intent";
648
- /** Only fire when the current URL matches this pattern. */
649
- matchUrl?: UrlPattern;
650
- /** Action to run when the trigger fires. */
651
- action: TriggerAction;
652
- } | {
653
- /** Fire immediately when the current URL matches. */
654
- on: "url";
655
- /** URL pattern that must match for the trigger to fire. */
656
- pattern: UrlPattern;
657
- /** Action to run when the trigger fires. */
658
- action: TriggerAction;
659
- };
660
-
661
- /**
662
- * What a {@link Trigger} does when it fires: open the chat, or show a greeting
663
- * bubble with the given message.
664
- */
665
- export declare type TriggerAction = "open" | {
666
- /** Greeting bubble message to display. */
667
- greeting: string;
668
- };
669
-
670
- /** A URL match: a case-insensitive substring, or a regular expression. */
671
- export declare type UrlPattern = string | RegExp;
672
-
673
- /** Corner of the viewport the widget docks to. */
674
- export declare type WidgetPosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
675
-
676
- export { }
114
+ * Falls back to {@link sendMessage} (non-streaming) when the browser can't
115
+ * read response streams or the Worker doesn't expose `/api/chat/stream`
116
+ * (HTTP 404/405), so callers never need their own feature detection.
117
+ *
118
+ * Failures before the first byte follow the same retry policy as
119
+ * {@link sendMessage}; once streaming has begun there are no automatic
120
+ * retries. Aborting via {@link ChatStreamOptions.signal} is not an error:
121
+ * the promise resolves with the partial reply and `aborted: true`.
122
+ *
123
+ * @param messages - The full conversation so far, oldest message first.
124
+ * @param options - Chunk callback and cancellation signal.
125
+ * @throws {@link DebounceError} when called within the debounce window.
126
+ * @throws {@link ChatApiError} when the request fails after all retries, or
127
+ * the stream errors or is interrupted mid-reply (code `"STREAM_ERROR"`).
128
+ */
129
+ streamMessage(messages: ChatMessage[], options?: ChatStreamOptions): Promise<ChatStreamResult>;
130
+ /**
131
+ * Consumes an SSE body, invoking `onChunk` per `chunk` event, resolving on
132
+ * `done`, throwing on `error` events or an interrupted connection, and
133
+ * resolving with the partial text when the caller aborts.
134
+ */
135
+ private readSseStream;
136
+ private fetchStream;
137
+ private fetchWithTimeout;
138
+ private isRetryable;
139
+ private getRetryDelay;
140
+ private delay;
141
+ }
142
+
143
+ /**
144
+ * Options for {@link ChatApiClient}.
145
+ */
146
+ export declare interface ChatApiClientOptions {
147
+ /**
148
+ * Maximum retries after the first attempt, for retryable failures (HTTP
149
+ * 429/503, network errors, timeouts).
150
+ * @defaultValue `2`
151
+ */
152
+ maxRetries?: number;
153
+ /**
154
+ * Minimum gap between sends, in milliseconds. A send inside this window
155
+ * rejects with {@link DebounceError}. Set to 0 to disable.
156
+ * @defaultValue `300`
157
+ */
158
+ debounceMs?: number;
159
+ /**
160
+ * Per-attempt request timeout in milliseconds. Aborts the in-flight fetch
161
+ * via `AbortController` and surfaces a retryable {@link ChatApiError} with
162
+ * code `"TIMEOUT"`. Set to 0 to disable.
163
+ * @defaultValue `30000`
164
+ */
165
+ timeoutMs?: number;
166
+ }
167
+
168
+ /**
169
+ * Error thrown by {@link ChatApiClient} when a chat request ultimately fails:
170
+ * either after exhausting retries, or immediately for a non-retryable status.
171
+ */
172
+ export declare class ChatApiError extends Error {
173
+ /** HTTP status code, or `0` for network and timeout failures. */
174
+ readonly status: number;
175
+ /** Machine-readable error code, when available (e.g. `"TIMEOUT"`). */
176
+ readonly code?: string | undefined;
177
+ /** Seconds to wait before retrying, parsed from the `Retry-After` header. */
178
+ readonly retryAfter?: number | undefined;
179
+ /**
180
+ * Create a {@link ChatApiError}.
181
+ *
182
+ * @param message - Human-readable error message.
183
+ * @param status - HTTP status code, or `0` for network and timeout failures.
184
+ * @param code - Optional machine-readable error code (e.g. `"TIMEOUT"`, `"NETWORK_ERROR"`).
185
+ * @param retryAfter - Seconds to wait before retrying, from the `Retry-After` header.
186
+ */
187
+ constructor(message: string,
188
+ /** HTTP status code, or `0` for network and timeout failures. */
189
+ status: number,
190
+ /** Machine-readable error code, when available (e.g. `"TIMEOUT"`). */
191
+ code?: string | undefined,
192
+ /** Seconds to wait before retrying, parsed from the `Retry-After` header. */
193
+ retryAfter?: number | undefined);
194
+ }
195
+
196
+ /**
197
+ * Error response body returned by the Worker when a chat request fails.
198
+ */
199
+ export declare interface ChatErrorResponse {
200
+ /** Human-readable error message. */
201
+ error: string;
202
+ /** Optional machine-readable error code (e.g. `"RATE_LIMITED"`). */
203
+ code?: string;
204
+ }
205
+
206
+ /**
207
+ * A single chat message exchanged between the user and the assistant.
208
+ */
209
+ export declare interface ChatMessage {
210
+ /** Stable unique identifier, used as the React list key. */
211
+ id: string;
212
+ /** Who authored the message. */
213
+ role: "user" | "assistant";
214
+ /** Plain-text message body. */
215
+ content: string;
216
+ /** Sources cited by the assistant for this message, when any. */
217
+ sources?: Source[];
218
+ /** Tools the assistant called while producing this message, when any. */
219
+ toolUses?: ToolUse[];
220
+ }
221
+
222
+ /**
223
+ * Request payload sent to the Worker `POST /api/chat` endpoint.
224
+ */
225
+ export declare interface ChatRequest {
226
+ /** The full conversation so far, oldest message first. */
227
+ messages: ChatMessage[];
228
+ }
229
+
230
+ /**
231
+ * Successful response body from `POST /api/chat`.
232
+ */
233
+ export declare interface ChatResponse {
234
+ /** The assistant's reply text. */
235
+ reply: string;
236
+ /** Sources the assistant cited, when any. */
237
+ sources?: Source[];
238
+ /** Tools the assistant called while producing the reply, when any. */
239
+ toolUses?: ToolUse[];
240
+ }
241
+
242
+ /**
243
+ * Options for {@link ChatApiClient.streamMessage}.
244
+ */
245
+ export declare interface ChatStreamOptions {
246
+ /**
247
+ * Called once per streamed text delta, as tokens arrive.
248
+ *
249
+ * @param text - The incremental text of this chunk.
250
+ * @param fullText - The full reply accumulated so far, including this chunk.
251
+ */
252
+ onChunk?: (text: string, fullText: string) => void;
253
+ /**
254
+ * Called when the assistant finishes a tool call mid-stream, so the UI can
255
+ * show a "used tool" affordance before the reply completes.
256
+ */
257
+ onToolUse?: (toolUse: ToolUse, allToolUses: ToolUse[]) => void;
258
+ /**
259
+ * Cancels the stream when aborted. Cancellation is not an error: the
260
+ * promise resolves with the partial reply and `aborted: true`.
261
+ */
262
+ signal?: AbortSignal;
263
+ }
264
+
265
+ /**
266
+ * Result of a completed or cancelled streaming chat request.
267
+ */
268
+ export declare interface ChatStreamResult extends ChatResponse {
269
+ /** `true` when the caller cancelled the stream before it finished. */
270
+ aborted?: boolean;
271
+ }
272
+
273
+ /**
274
+ * Root Claudius chat widget: a floating toggle button that opens a chat window
275
+ * backed by the Worker chat API. Render a single instance on the page.
276
+ *
277
+ * @param props - See {@link ChatWidgetProps}.
278
+ * @example
279
+ * ```tsx
280
+ * <ChatWidget apiUrl="https://api.example.com" title="Support" />
281
+ * ```
282
+ */
283
+ export declare function ChatWidget({ apiUrl, title, subtitle, welcomeMessage, placeholder, persistMessages, storageKeyPrefix, requestTimeoutMs, theme, accentColor, position, locale, translations: translationOverrides, triggers, plugins, streaming, }: ChatWidgetProps): JSX_2.Element;
284
+
285
+ /**
286
+ * Props for the {@link ChatWidget} component.
287
+ */
288
+ export declare interface ChatWidgetProps {
289
+ /** Absolute URL of the Worker chat endpoint (e.g. `https://api.example.com`). */
290
+ apiUrl: string;
291
+ /** Header title. Falls back to the active locale's default title. */
292
+ title?: string;
293
+ /** Header subtitle shown beneath the title. */
294
+ subtitle?: string;
295
+ /** First assistant message shown when the chat opens. */
296
+ welcomeMessage?: string;
297
+ /** Placeholder text for the message input. */
298
+ placeholder?: string;
299
+ /**
300
+ * Persist the conversation to storage so it survives reloads.
301
+ * @defaultValue `false`
302
+ */
303
+ persistMessages?: boolean;
304
+ /** Prefix for the storage key used when {@link ChatWidgetProps.persistMessages} is enabled. */
305
+ storageKeyPrefix?: string;
306
+ /** Abort a chat request after this many milliseconds. */
307
+ requestTimeoutMs?: number;
308
+ /**
309
+ * Color-scheme mode ("light" | "dark" | "auto"), a built-in theme name
310
+ * ("default" | "minimal" | "playful" | "corporate"), an inline
311
+ * ClaudiusTheme object, or a URL to a theme JSON file.
312
+ * @defaultValue `"light"`
313
+ */
314
+ theme?: ClaudiusThemeInput;
315
+ /** Accent color override; wins over the theme's accent in both light and dark. */
316
+ accentColor?: string;
317
+ /**
318
+ * Corner of the viewport the widget docks to.
319
+ * @defaultValue `"bottom-right"`
320
+ */
321
+ position?: WidgetPosition;
322
+ /** BCP-47 locale used to select built-in translations. */
323
+ locale?: LocaleCode;
324
+ /** Partial overrides merged over the resolved locale translations. */
325
+ translations?: Partial<ClaudiusTranslations>;
326
+ /** Proactive open/greeting rules evaluated against the current page. */
327
+ triggers?: Trigger[];
328
+ /**
329
+ * Middleware run around each message: `onBeforeSend`, `onAfterReceive`, and
330
+ * `onError`. Hooks run in array order and may modify, replace, or
331
+ * short-circuit messages. See {@link ClaudiusPlugin}.
332
+ */
333
+ plugins?: ClaudiusPlugin[];
334
+ /**
335
+ * Stream assistant replies token-by-token from the Worker's SSE endpoint,
336
+ * with automatic fallback to the non-streaming API on older browsers or
337
+ * Workers without `/api/chat/stream`. Set to `false` to always use the
338
+ * blocking request/response flow.
339
+ * @defaultValue `true`
340
+ */
341
+ streaming?: boolean;
342
+ }
343
+
344
+ /** An analytics event emitted by {@link pluginAnalytics}. */
345
+ export declare type ClaudiusAnalyticsEvent = {
346
+ /** Event discriminant. */
347
+ type: "message_sent";
348
+ /** Always `"user"`. */
349
+ role: "user";
350
+ /** Message text, or `""` when `includeContent` is `false`. */
351
+ content: string;
352
+ /** Length of the message in characters. */
353
+ chars: number;
354
+ } | {
355
+ /** Event discriminant. */
356
+ type: "message_received";
357
+ /** Always `"assistant"`. */
358
+ role: "assistant";
359
+ /** Reply text, or `""` when `includeContent` is `false`. */
360
+ content: string;
361
+ /** Length of the reply in characters. */
362
+ chars: number;
363
+ } | {
364
+ /** Event discriminant. */
365
+ type: "chat_error";
366
+ /** The error message. */
367
+ message: string;
368
+ /** Machine-readable error code, when available (e.g. `"TIMEOUT"`). */
369
+ code?: string;
370
+ };
371
+
372
+ /**
373
+ * A client-side middleware that runs around the chat message lifecycle. Pass
374
+ * an array of plugins to {@link ChatWidget} via the `plugins` prop; hooks run
375
+ * in array order.
376
+ *
377
+ * Hooks may be async, and may modify, replace, or short-circuit messages. A
378
+ * hook that throws is caught and logged — a misbehaving plugin will not break
379
+ * the chat — so security-sensitive transforms (e.g. PII redaction) should be
380
+ * written defensively.
381
+ *
382
+ * @example
383
+ * ```ts
384
+ * const logger: ClaudiusPlugin = {
385
+ * name: "logger",
386
+ * onBeforeSend: (message) => { console.log("sending", message.content); },
387
+ * onAfterReceive: (message) => { console.log("received", message.content); },
388
+ * };
389
+ * ```
390
+ */
391
+ export declare interface ClaudiusPlugin {
392
+ /** Stable identifier, used in log messages. */
393
+ name: string;
394
+ /**
395
+ * Runs before the user message is sent. Return a {@link ChatMessage} to
396
+ * replace it (the returned message is both displayed and sent), return
397
+ * nothing to leave it unchanged, or call {@link BeforeSendContext.respondWith}
398
+ * / {@link BeforeSendContext.abort} to short-circuit.
399
+ */
400
+ onBeforeSend?(message: ChatMessage, ctx: BeforeSendContext): MaybePromise<ChatMessage | void>;
401
+ /**
402
+ * Runs after the assistant reply is received, before it is rendered. Return
403
+ * a {@link ChatMessage} to replace it, or nothing to leave it unchanged.
404
+ */
405
+ onAfterReceive?(message: ChatMessage, ctx: PluginContext): MaybePromise<ChatMessage | void>;
406
+ /**
407
+ * Runs when a send fails. Observe the error, or call
408
+ * {@link ErrorContext.respondWith} to render a fallback reply instead of the
409
+ * error UI.
410
+ */
411
+ onError?(error: Error, ctx: ErrorContext): MaybePromise<void>;
412
+ }
413
+
414
+ /**
415
+ * A Claudius design-token theme. Every value is a CSS string applied via
416
+ * --cl-* custom properties. `colors` apply to both light and dark modes
417
+ * unless `colorsDark` overrides a token for dark mode specifically.
418
+ *
419
+ * JSON theme files validate against
420
+ * https://claudius-docs.pages.dev/schema/theme.v1.json
421
+ */
422
+ export declare interface ClaudiusTheme {
423
+ /** Optional JSON Schema URL, for editor validation and autocomplete. */
424
+ $schema?: string;
425
+ /** Human-readable theme name. */
426
+ name?: string;
427
+ /** Initial color scheme this theme is designed for. Defaults to "light". */
428
+ colorScheme?: "light" | "dark" | "auto";
429
+ /** Color token overrides applied in both light and dark mode. */
430
+ colors?: Partial<Record<ThemeColorToken, string>>;
431
+ /** Color token overrides applied only in dark mode, layered over {@link ClaudiusTheme.colors}. */
432
+ colorsDark?: Partial<Record<ThemeColorToken, string>>;
433
+ /** Border-radius token overrides. */
434
+ radii?: Partial<Record<ThemeRadiusToken, string>>;
435
+ /** Box-shadow token overrides. */
436
+ shadows?: Partial<Record<ThemeShadowToken, string>>;
437
+ /** Font-family token overrides. */
438
+ fonts?: Partial<Record<ThemeFontToken, string>>;
439
+ }
440
+
441
+ /**
442
+ * Everything the `theme` option accepts: the original color-scheme modes, a
443
+ * built-in theme name, an inline theme object, or a URL to a theme JSON file.
444
+ * `(string & {})` keeps literal autocomplete while allowing URLs.
445
+ */
446
+ export declare type ClaudiusThemeInput = "light" | "dark" | "auto" | BuiltinThemeName | ClaudiusTheme | (string & {});
447
+
448
+ /**
449
+ * Every user-facing string the widget renders. Pass a {@link ClaudiusTranslations}
450
+ * (or a partial override) to localize the UI. English is the source of truth;
451
+ * see {@link defaultTranslations}.
452
+ */
453
+ export declare interface ClaudiusTranslations {
454
+ /** Chat window header title. */
455
+ title: string;
456
+ /** Chat window header subtitle. */
457
+ subtitle: string;
458
+ /** First assistant message shown when the chat opens. */
459
+ welcomeMessage: string;
460
+ /** Accessible label for the close button. */
461
+ closeChat: string;
462
+ /** Accessible label for the message list region. */
463
+ chatMessages: string;
464
+ /** Accessible label for the typing indicator. */
465
+ typingIndicator: string;
466
+ /** Placeholder text for the message input. */
467
+ placeholder: string;
468
+ /** Accessible label for the send button. */
469
+ sendMessage: string;
470
+ /** Accessible label for the stop button shown while a reply streams in. */
471
+ stopGenerating: string;
472
+ /** Label prefix for the "used tool" chip on assistant messages. */
473
+ toolUsed: string;
474
+ /** Accessible label for the tool-details disclosure toggle. */
475
+ toolDetails: string;
476
+ /** Accessible label for the message input field. */
477
+ typeYourMessage: string;
478
+ /** Accessible label for the button that opens the chat. */
479
+ openChat: string;
480
+ /** Accessible label for dismissing the greeting bubble. */
481
+ dismissGreeting: string;
482
+ /** Generic fallback error message. */
483
+ errorGeneric: string;
484
+ /** Error shown when the network request fails. */
485
+ errorConnection: string;
486
+ /** Error shown when a request times out. */
487
+ errorTimeout: string;
488
+ /** Error shown when rate-limited (per-minute limit). */
489
+ errorRateLimitMinute: string;
490
+ /** Error shown when rate-limited (per-hour limit). */
491
+ errorRateLimitHour: string;
492
+ /** Label for the retry action on a failed message. */
493
+ errorRetry: string;
494
+ }
495
+
496
+ /**
497
+ * Build a complete {@link ClaudiusTranslations} from the English defaults,
498
+ * applying the given overrides.
499
+ *
500
+ * @param overrides - Strings to override on top of {@link defaultTranslations}.
501
+ * @returns A complete translations object.
502
+ */
503
+ export declare function createTranslations(overrides?: Partial<ClaudiusTranslations>): ClaudiusTranslations;
504
+
505
+ /**
506
+ * Error thrown by {@link ChatApiClient.sendMessage} when a send is rejected
507
+ * for arriving within the configured debounce window.
508
+ */
509
+ export declare class DebounceError extends Error {
510
+ /** Creates a `DebounceError` with a fixed message. */
511
+ constructor();
512
+ }
513
+
514
+ /**
515
+ * Default PII patterns: email addresses, North-American-style phone numbers,
516
+ * US Social Security numbers, and 13–16 digit card-like sequences. These are
517
+ * intentionally conservative starting points — tune {@link RedactPiiOptions.patterns}
518
+ * for your data.
519
+ */
520
+ export declare const DEFAULT_PII_PATTERNS: readonly RegExp[];
521
+
522
+ /** The default (English) translations, used when no locale or override applies. */
523
+ export declare const defaultTranslations: ClaudiusTranslations;
524
+
525
+ /**
526
+ * Detect the best {@link LocaleCode} for the current environment: the document
527
+ * `lang` attribute first, then the browser language, falling back to `"en"`.
528
+ *
529
+ * @returns The detected locale code.
530
+ */
531
+ export declare function detectLocale(): LocaleCode;
532
+
533
+ /**
534
+ * Context for {@link ClaudiusPlugin.onError}. Adds the ability to recover from
535
+ * a failed send by rendering a reply in place of the error UI.
536
+ */
537
+ export declare interface ErrorContext extends PluginContext {
538
+ /**
539
+ * Recover from the failure by rendering this assistant reply instead of the
540
+ * error state. Stops the hook chain — later plugins' `onError` hooks do not
541
+ * run.
542
+ */
543
+ respondWith(reply: string | PluginReply): void;
544
+ }
545
+
546
+ /** BCP-47 primary language subtags the widget ships built-in translations for. */
547
+ export declare type LocaleCode = "en" | "es" | "fr" | "de";
548
+
549
+ /** Built-in translations keyed by {@link LocaleCode}. */
550
+ export declare const locales: Record<LocaleCode, ClaudiusTranslations>;
551
+
552
+ /** A value that may be returned synchronously or as a promise. */
553
+ export declare type MaybePromise<T> = T | Promise<T>;
554
+
555
+ /**
556
+ * Reference plugin that emits a structured analytics event for every message
557
+ * sent, every reply received, and every error. It never modifies messages.
558
+ *
559
+ * @example
560
+ * ```ts
561
+ * <ChatWidget
562
+ * apiUrl={url}
563
+ * plugins={[pluginAnalytics({ onEvent: (e) => gtag("event", e.type, e) })]}
564
+ * />
565
+ * ```
566
+ */
567
+ export declare function pluginAnalytics(options: AnalyticsPluginOptions): ClaudiusPlugin;
568
+
569
+ /**
570
+ * Reference plugin that answers matching messages locally, without calling the
571
+ * API. The first rule whose matcher fires short-circuits the send via
572
+ * `ctx.respondWith`, so the network is never hit for that turn.
573
+ *
574
+ * @example
575
+ * ```ts
576
+ * <ChatWidget
577
+ * apiUrl={url}
578
+ * plugins={[pluginCannedResponses({
579
+ * rules: [
580
+ * { match: "hours", reply: "We're open 9-5, Mon-Fri." },
581
+ * { match: /pricing|cost/i, reply: "See https://example.com/pricing." },
582
+ * ],
583
+ * })]}
584
+ * />
585
+ * ```
586
+ */
587
+ export declare function pluginCannedResponses(options: CannedResponsesOptions): ClaudiusPlugin;
588
+
589
+ /**
590
+ * Read-only context shared by every plugin hook.
591
+ *
592
+ * `messages` is a snapshot of the conversation at the moment the hook runs:
593
+ * in {@link ClaudiusPlugin.onBeforeSend} it excludes the in-flight user
594
+ * message; in {@link ClaudiusPlugin.onAfterReceive} and
595
+ * {@link ClaudiusPlugin.onError} it includes it.
596
+ */
597
+ export declare interface PluginContext {
598
+ /** Conversation snapshot, oldest message first. Treat as immutable. */
599
+ readonly messages: readonly ChatMessage[];
600
+ /** The Worker chat endpoint URL the widget posts to. */
601
+ readonly apiUrl: string;
602
+ }
603
+
604
+ /**
605
+ * Reference plugin that strips PII from the user's message before it leaves the
606
+ * browser. The redacted text is what gets displayed and sent, so the user sees
607
+ * that redaction happened. Optionally redacts assistant replies too.
608
+ *
609
+ * @example
610
+ * ```ts
611
+ * <ChatWidget apiUrl={url} plugins={[pluginRedactPII()]} />
612
+ * ```
613
+ */
614
+ export declare function pluginRedactPII(options?: RedactPiiOptions): ClaudiusPlugin;
615
+
616
+ /**
617
+ * A synthesized assistant reply, produced by a plugin instead of (or in
618
+ * recovery from) a network round-trip. Passed to
619
+ * {@link BeforeSendContext.respondWith} and {@link ErrorContext.respondWith}.
620
+ */
621
+ export declare interface PluginReply {
622
+ /** The assistant reply text to render. */
623
+ content: string;
624
+ /** Optional sources to attach to the synthesized reply. */
625
+ sources?: Source[];
626
+ }
627
+
628
+ /** Options for {@link pluginRedactPII}. */
629
+ export declare interface RedactPiiOptions {
630
+ /**
631
+ * Patterns to redact. Each must carry the global (`g`) flag.
632
+ * @defaultValue {@link DEFAULT_PII_PATTERNS}
633
+ */
634
+ patterns?: readonly RegExp[];
635
+ /**
636
+ * Text substituted for each match.
637
+ * @defaultValue `"[redacted]"`
638
+ */
639
+ replacement?: string;
640
+ /**
641
+ * Also redact the assistant's replies, not just outgoing user messages.
642
+ * @defaultValue `false`
643
+ */
644
+ redactReplies?: boolean;
645
+ }
646
+
647
+ /** Replace every match of every pattern in `text` with `replacement`. */
648
+ export declare function redactText(text: string, patterns: readonly RegExp[], replacement: string): string;
649
+
650
+ /**
651
+ * Resolve the final translations for a locale, applying any per-string
652
+ * overrides on top of the chosen locale's defaults.
653
+ *
654
+ * @param options - Locale and override settings.
655
+ * @returns A complete translations object.
656
+ */
657
+ export declare function resolveTranslations(options?: ResolveTranslationsOptions): ClaudiusTranslations;
658
+
659
+ /** Options for {@link resolveTranslations}. */
660
+ export declare interface ResolveTranslationsOptions {
661
+ /** Locale to use. Defaults to the result of {@link detectLocale}. */
662
+ locale?: LocaleCode;
663
+ /** Per-string overrides layered over the chosen locale's translations. */
664
+ translations?: Partial<ClaudiusTranslations>;
665
+ }
666
+
667
+ /**
668
+ * A cited source the assistant referenced when answering. Rendered as a link
669
+ * in the chat and grouped in the sources sidebar.
670
+ */
671
+ export declare interface Source {
672
+ /** Absolute URL of the source. */
673
+ url: string;
674
+ /** Human-readable link title shown to the user. */
675
+ title: string;
676
+ /** Origin category, used to group and label the source. */
677
+ type: "blog" | "page" | "external";
678
+ }
679
+
680
+ declare const THEME_COLOR_TOKENS: readonly ["accent", "accentText", "accentSoft", "accentTextMuted", "surface", "surfaceMuted", "text", "textMuted", "border", "userBubble", "userBubbleText", "assistantBubble", "assistantBubbleText", "field", "error", "errorSurface", "errorText", "link", "scrim"];
681
+
682
+ declare const THEME_FONT_TOKENS: readonly ["heading", "body"];
683
+
684
+ declare const THEME_RADIUS_TOKENS: readonly ["sm", "md", "lg", "full", "tail"];
685
+
686
+ declare const THEME_SHADOW_TOKENS: readonly ["elevated", "floating", "floatingHover"];
687
+
688
+ /** Names of the color tokens a theme can override (e.g. `accent`, `surface`, `text`). */
689
+ export declare type ThemeColorToken = (typeof THEME_COLOR_TOKENS)[number];
690
+
691
+ /** Names of the font-family tokens a theme can override. */
692
+ export declare type ThemeFontToken = (typeof THEME_FONT_TOKENS)[number];
693
+
694
+ /** Names of the border-radius tokens a theme can override. */
695
+ export declare type ThemeRadiusToken = (typeof THEME_RADIUS_TOKENS)[number];
696
+
697
+ /** Names of the box-shadow tokens a theme can override. */
698
+ export declare type ThemeShadowToken = (typeof THEME_SHADOW_TOKENS)[number];
699
+
700
+ /**
701
+ * One tool call the assistant made while producing a reply. Rendered as a
702
+ * compact "used tool" affordance with an optional details disclosure.
703
+ */
704
+ export declare interface ToolUse {
705
+ /** Tool name (e.g. `"get_current_time"`). */
706
+ name: string;
707
+ /** Input the model supplied to the tool. */
708
+ input?: Record<string, unknown>;
709
+ /** Serialized tool result, as the model saw it. */
710
+ result?: string;
711
+ /** Present when the tool call failed. */
712
+ isError?: boolean;
713
+ }
714
+
715
+ /**
716
+ * A proactive engagement rule. Each variant fires at most once per page on a
717
+ * different signal: elapsed time, scroll depth, exit intent, or URL match.
718
+ */
719
+ export declare type Trigger = {
720
+ /** Fire after a fixed dwell time. */
721
+ on: "time";
722
+ /** Seconds to wait before firing. */
723
+ seconds: number;
724
+ /** Only fire when the current URL matches this pattern. */
725
+ matchUrl?: UrlPattern;
726
+ /** Action to run when the trigger fires. */
727
+ action: TriggerAction;
728
+ } | {
729
+ /** Fire once the user scrolls past a depth threshold. */
730
+ on: "scroll";
731
+ /** Scroll depth (0-100) that fires the trigger. */
732
+ percent: number;
733
+ /** Only fire when the current URL matches this pattern. */
734
+ matchUrl?: UrlPattern;
735
+ /** Action to run when the trigger fires. */
736
+ action: TriggerAction;
737
+ } | {
738
+ /** Fire when the pointer leaves the top of the viewport (exit intent). */
739
+ on: "exit-intent";
740
+ /** Only fire when the current URL matches this pattern. */
741
+ matchUrl?: UrlPattern;
742
+ /** Action to run when the trigger fires. */
743
+ action: TriggerAction;
744
+ } | {
745
+ /** Fire immediately when the current URL matches. */
746
+ on: "url";
747
+ /** URL pattern that must match for the trigger to fire. */
748
+ pattern: UrlPattern;
749
+ /** Action to run when the trigger fires. */
750
+ action: TriggerAction;
751
+ };
752
+
753
+ /**
754
+ * What a {@link Trigger} does when it fires: open the chat, or show a greeting
755
+ * bubble with the given message.
756
+ */
757
+ export declare type TriggerAction = "open" | {
758
+ /** Greeting bubble message to display. */
759
+ greeting: string;
760
+ };
761
+
762
+ /** A URL match: a case-insensitive substring, or a regular expression. */
763
+ export declare type UrlPattern = string | RegExp;
764
+
765
+ /** Corner of the viewport the widget docks to. */
766
+ export declare type WidgetPosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
767
+
768
+ export { }