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/claudius.cjs +7 -2
- package/dist/claudius.css +1 -1
- package/dist/claudius.iife.js +18 -13
- package/dist/claudius.js +1091 -676
- package/dist/index.d.cts +658 -566
- package/dist/index.d.ts +658 -566
- package/package.json +10 -1
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
|
-
*
|
|
121
|
-
*
|
|
122
|
-
* @
|
|
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
|
-
* @
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
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 { }
|