claudius-chat-widget 1.17.0 → 1.18.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
@@ -116,6 +116,7 @@ export declare class ChatApiClient {
116
116
  private readonly maxRetries;
117
117
  private readonly debounceMs;
118
118
  private readonly timeoutMs;
119
+ private readonly citations;
119
120
  private lastSendTime;
120
121
  /**
121
122
  * Create a chat client for the given Worker base URL.
@@ -198,6 +199,12 @@ export declare class ChatApiClient {
198
199
  * @defaultValue `30000`
199
200
  */
200
201
  timeoutMs?: number;
202
+ /**
203
+ * Send `citations: true` with every request, asking the worker to number
204
+ * its retrieved excerpts and have the model cite them as `[n]`.
205
+ * @defaultValue `false`
206
+ */
207
+ citations?: boolean;
201
208
  }
202
209
 
203
210
  /**
@@ -295,6 +302,11 @@ export declare class ChatApiClient {
295
302
  export declare interface ChatRequest {
296
303
  /** The full conversation so far, oldest message first. */
297
304
  messages: ChatMessage[];
305
+ /**
306
+ * Ask the worker to number its retrieved excerpts to match `sources` and
307
+ * to have the model cite them as `[n]`. Sent by widgets with citations on.
308
+ */
309
+ citations?: boolean;
298
310
  }
299
311
 
300
312
  /**
@@ -327,6 +339,12 @@ export declare class ChatApiClient {
327
339
  * show a "used tool" affordance before the reply completes.
328
340
  */
329
341
  onToolUse?: (toolUse: ToolUse, allToolUses: ToolUse[]) => void;
342
+ /**
343
+ * Called when the worker announces the reply's sources ahead of the text,
344
+ * so citation chips can render while the reply streams. The `done` event
345
+ * carries the final list.
346
+ */
347
+ onSources?: (sources: Source[]) => void;
330
348
  /**
331
349
  * Cancels the stream when aborted. Cancellation is not an error: the
332
350
  * promise resolves with the partial reply and `aborted: true`.
@@ -352,7 +370,7 @@ export declare class ChatApiClient {
352
370
  * <ChatWidget apiUrl="https://api.example.com" title="Support" />
353
371
  * ```
354
372
  */
355
- export declare function ChatWidget({ apiUrl, title, subtitle, welcomeMessage, placeholder, persistMessages, storageKeyPrefix, requestTimeoutMs, theme, accentColor, position, locale, translations: translationOverrides, triggers, plugins, streaming, attachments, voice, conversationExport, }: ChatWidgetProps): JSX_2.Element;
373
+ export declare function ChatWidget({ apiUrl, title, subtitle, welcomeMessage, placeholder, persistMessages, storageKeyPrefix, requestTimeoutMs, theme, accentColor, position, locale, translations: translationOverrides, triggers, plugins, streaming, attachments, voice, conversationExport, citations, }: ChatWidgetProps): JSX_2.Element;
356
374
 
357
375
  /**
358
376
  * Props for the {@link ChatWidget} component.
@@ -438,6 +456,36 @@ export declare class ChatApiClient {
438
456
  * @defaultValue `false`
439
457
  */
440
458
  conversationExport?: boolean;
459
+ /**
460
+ * Render `[n]` citations in grounded replies as numbered chips, with a
461
+ * collapsible footer of source cards under the reply. `true` enables the
462
+ * defaults (five cards before "Show all", favicons on); pass a
463
+ * {@link CitationsOptions} to tune them. The widget also asks the worker to
464
+ * number its retrieved excerpts, so this needs a worker from 1.18.0 or
465
+ * later with RAG on to have any effect. Only `true` or an object enables
466
+ * it. See the Inline citations guide.
467
+ * @defaultValue `false`
468
+ */
469
+ citations?: boolean | CitationsOptions;
470
+ }
471
+
472
+ /**
473
+ * Inline citations. Pass to {@link ChatWidget} via the `citations` prop (or
474
+ * `true` for the defaults). `[n]` markers in a grounded reply become chips
475
+ * and its sources become a footer of cards.
476
+ */
477
+ export declare interface CitationsOptions {
478
+ /**
479
+ * Source cards shown before the "Show all" control. Positive integer.
480
+ * @defaultValue `5`
481
+ */
482
+ maxSources?: number;
483
+ /**
484
+ * Show each source's favicon, fetched from `/favicon.ico` on the source's
485
+ * own origin with no referrer. Set to `false` to make no such requests.
486
+ * @defaultValue `true`
487
+ */
488
+ favicons?: boolean;
441
489
  }
442
490
 
443
491
  /** An analytics event emitted by {@link pluginAnalytics}. */
@@ -641,6 +689,16 @@ export declare class ChatApiClient {
641
689
  transcriptAttachments: string;
642
690
  /** Transcript label above a message's citation list, including its colon. */
643
691
  transcriptSources: string;
692
+ /** Label of the sources footer under a cited reply, and of its list. */
693
+ sources: string;
694
+ /** Button that reveals the remaining source cards; supports `{count}`. */
695
+ showAllSources: string;
696
+ /** Button that hides the extra source cards again. */
697
+ showFewerSources: string;
698
+ /** Accessible name of a citation chip; supports `{n}` and `{title}`. */
699
+ citation: string;
700
+ /** Visually hidden hint appended to links that open a new tab. */
701
+ opensInNewTab: string;
644
702
  /** Generic fallback error message. */
645
703
  errorGeneric: string;
646
704
  /** Error shown when the network request fails. */
@@ -680,6 +738,9 @@ export declare class ChatApiClient {
680
738
  /** Defaults applied when attachments are enabled with `true` or a partial config. */
681
739
  export declare const DEFAULT_ATTACHMENT_OPTIONS: ResolvedAttachmentsConfig;
682
740
 
741
+ /** Defaults applied when citations are enabled with `true` or a partial config. */
742
+ export declare const DEFAULT_CITATIONS_OPTIONS: ResolvedCitationsConfig;
743
+
683
744
  /**
684
745
  * Default PII patterns: email addresses, North-American-style phone numbers,
685
746
  * US Social Security numbers, and 13–16 digit card-like sequences. These are
@@ -819,6 +880,9 @@ export declare class ChatApiClient {
819
880
  /** {@link AttachmentsOptions} with every field filled in. */
820
881
  export declare type ResolvedAttachmentsConfig = Required<AttachmentsOptions>;
821
882
 
883
+ /** {@link CitationsOptions} with every field filled in. */
884
+ export declare type ResolvedCitationsConfig = Required<CitationsOptions>;
885
+
822
886
  /** {@link VoiceOptions} with every field filled in. */
823
887
  export declare type ResolvedVoiceConfig = Required<VoiceOptions>;
824
888
 
@@ -850,6 +914,11 @@ export declare class ChatApiClient {
850
914
  title: string;
851
915
  /** Origin category, used to group and label the source. */
852
916
  type: "blog" | "page" | "external";
917
+ /**
918
+ * Short plain-text excerpt of the page, shown on its source card. About
919
+ * 200 characters. Absent from workers that predate citations.
920
+ */
921
+ snippet?: string;
853
922
  }
854
923
 
855
924
  /**
package/dist/index.d.ts CHANGED
@@ -116,6 +116,7 @@ export declare class ChatApiClient {
116
116
  private readonly maxRetries;
117
117
  private readonly debounceMs;
118
118
  private readonly timeoutMs;
119
+ private readonly citations;
119
120
  private lastSendTime;
120
121
  /**
121
122
  * Create a chat client for the given Worker base URL.
@@ -198,6 +199,12 @@ export declare class ChatApiClient {
198
199
  * @defaultValue `30000`
199
200
  */
200
201
  timeoutMs?: number;
202
+ /**
203
+ * Send `citations: true` with every request, asking the worker to number
204
+ * its retrieved excerpts and have the model cite them as `[n]`.
205
+ * @defaultValue `false`
206
+ */
207
+ citations?: boolean;
201
208
  }
202
209
 
203
210
  /**
@@ -295,6 +302,11 @@ export declare class ChatApiClient {
295
302
  export declare interface ChatRequest {
296
303
  /** The full conversation so far, oldest message first. */
297
304
  messages: ChatMessage[];
305
+ /**
306
+ * Ask the worker to number its retrieved excerpts to match `sources` and
307
+ * to have the model cite them as `[n]`. Sent by widgets with citations on.
308
+ */
309
+ citations?: boolean;
298
310
  }
299
311
 
300
312
  /**
@@ -327,6 +339,12 @@ export declare class ChatApiClient {
327
339
  * show a "used tool" affordance before the reply completes.
328
340
  */
329
341
  onToolUse?: (toolUse: ToolUse, allToolUses: ToolUse[]) => void;
342
+ /**
343
+ * Called when the worker announces the reply's sources ahead of the text,
344
+ * so citation chips can render while the reply streams. The `done` event
345
+ * carries the final list.
346
+ */
347
+ onSources?: (sources: Source[]) => void;
330
348
  /**
331
349
  * Cancels the stream when aborted. Cancellation is not an error: the
332
350
  * promise resolves with the partial reply and `aborted: true`.
@@ -352,7 +370,7 @@ export declare class ChatApiClient {
352
370
  * <ChatWidget apiUrl="https://api.example.com" title="Support" />
353
371
  * ```
354
372
  */
355
- export declare function ChatWidget({ apiUrl, title, subtitle, welcomeMessage, placeholder, persistMessages, storageKeyPrefix, requestTimeoutMs, theme, accentColor, position, locale, translations: translationOverrides, triggers, plugins, streaming, attachments, voice, conversationExport, }: ChatWidgetProps): JSX_2.Element;
373
+ export declare function ChatWidget({ apiUrl, title, subtitle, welcomeMessage, placeholder, persistMessages, storageKeyPrefix, requestTimeoutMs, theme, accentColor, position, locale, translations: translationOverrides, triggers, plugins, streaming, attachments, voice, conversationExport, citations, }: ChatWidgetProps): JSX_2.Element;
356
374
 
357
375
  /**
358
376
  * Props for the {@link ChatWidget} component.
@@ -438,6 +456,36 @@ export declare class ChatApiClient {
438
456
  * @defaultValue `false`
439
457
  */
440
458
  conversationExport?: boolean;
459
+ /**
460
+ * Render `[n]` citations in grounded replies as numbered chips, with a
461
+ * collapsible footer of source cards under the reply. `true` enables the
462
+ * defaults (five cards before "Show all", favicons on); pass a
463
+ * {@link CitationsOptions} to tune them. The widget also asks the worker to
464
+ * number its retrieved excerpts, so this needs a worker from 1.18.0 or
465
+ * later with RAG on to have any effect. Only `true` or an object enables
466
+ * it. See the Inline citations guide.
467
+ * @defaultValue `false`
468
+ */
469
+ citations?: boolean | CitationsOptions;
470
+ }
471
+
472
+ /**
473
+ * Inline citations. Pass to {@link ChatWidget} via the `citations` prop (or
474
+ * `true` for the defaults). `[n]` markers in a grounded reply become chips
475
+ * and its sources become a footer of cards.
476
+ */
477
+ export declare interface CitationsOptions {
478
+ /**
479
+ * Source cards shown before the "Show all" control. Positive integer.
480
+ * @defaultValue `5`
481
+ */
482
+ maxSources?: number;
483
+ /**
484
+ * Show each source's favicon, fetched from `/favicon.ico` on the source's
485
+ * own origin with no referrer. Set to `false` to make no such requests.
486
+ * @defaultValue `true`
487
+ */
488
+ favicons?: boolean;
441
489
  }
442
490
 
443
491
  /** An analytics event emitted by {@link pluginAnalytics}. */
@@ -641,6 +689,16 @@ export declare class ChatApiClient {
641
689
  transcriptAttachments: string;
642
690
  /** Transcript label above a message's citation list, including its colon. */
643
691
  transcriptSources: string;
692
+ /** Label of the sources footer under a cited reply, and of its list. */
693
+ sources: string;
694
+ /** Button that reveals the remaining source cards; supports `{count}`. */
695
+ showAllSources: string;
696
+ /** Button that hides the extra source cards again. */
697
+ showFewerSources: string;
698
+ /** Accessible name of a citation chip; supports `{n}` and `{title}`. */
699
+ citation: string;
700
+ /** Visually hidden hint appended to links that open a new tab. */
701
+ opensInNewTab: string;
644
702
  /** Generic fallback error message. */
645
703
  errorGeneric: string;
646
704
  /** Error shown when the network request fails. */
@@ -680,6 +738,9 @@ export declare class ChatApiClient {
680
738
  /** Defaults applied when attachments are enabled with `true` or a partial config. */
681
739
  export declare const DEFAULT_ATTACHMENT_OPTIONS: ResolvedAttachmentsConfig;
682
740
 
741
+ /** Defaults applied when citations are enabled with `true` or a partial config. */
742
+ export declare const DEFAULT_CITATIONS_OPTIONS: ResolvedCitationsConfig;
743
+
683
744
  /**
684
745
  * Default PII patterns: email addresses, North-American-style phone numbers,
685
746
  * US Social Security numbers, and 13–16 digit card-like sequences. These are
@@ -819,6 +880,9 @@ export declare class ChatApiClient {
819
880
  /** {@link AttachmentsOptions} with every field filled in. */
820
881
  export declare type ResolvedAttachmentsConfig = Required<AttachmentsOptions>;
821
882
 
883
+ /** {@link CitationsOptions} with every field filled in. */
884
+ export declare type ResolvedCitationsConfig = Required<CitationsOptions>;
885
+
822
886
  /** {@link VoiceOptions} with every field filled in. */
823
887
  export declare type ResolvedVoiceConfig = Required<VoiceOptions>;
824
888
 
@@ -850,6 +914,11 @@ export declare class ChatApiClient {
850
914
  title: string;
851
915
  /** Origin category, used to group and label the source. */
852
916
  type: "blog" | "page" | "external";
917
+ /**
918
+ * Short plain-text excerpt of the page, shown on its source card. About
919
+ * 200 characters. Absent from workers that predate citations.
920
+ */
921
+ snippet?: string;
853
922
  }
854
923
 
855
924
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claudius-chat-widget",
3
- "version": "1.17.0",
3
+ "version": "1.18.0",
4
4
  "type": "module",
5
5
  "description": "Embeddable AI chat widget powered by Claude. Drop-in React component or standalone script embed, backed by a Cloudflare Worker.",
6
6
  "keywords": [