@cloudflare/ai-search-snippet 0.0.36 → 0.0.38
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/main.d.ts +231 -11
- package/dist/search-snippet.es.js +651 -325
- package/dist/search-snippet.es.js.map +1 -1
- package/dist/search-snippet.umd.js +117 -125
- package/dist/search-snippet.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -48,15 +48,27 @@ export declare class ChatBubbleSnippet extends HTMLElement {
|
|
|
48
48
|
private container;
|
|
49
49
|
private isExpanded;
|
|
50
50
|
private isMinimized;
|
|
51
|
+
private translationsOverride;
|
|
52
|
+
private resolvedTranslations;
|
|
51
53
|
private handleBubbleClick;
|
|
52
54
|
private handleCloseClick;
|
|
53
55
|
private handleMinimizeClick;
|
|
54
56
|
private handleClearClick;
|
|
55
|
-
static get observedAttributes(): readonly ["api-url", "placeholder", "theme", "hide-branding"];
|
|
57
|
+
static get observedAttributes(): readonly ["api-url", "placeholder", "theme", "hide-branding", "translations"];
|
|
56
58
|
constructor();
|
|
57
59
|
connectedCallback(): void;
|
|
58
60
|
disconnectedCallback(): void;
|
|
59
61
|
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
62
|
+
/**
|
|
63
|
+
* Get the current translations object.
|
|
64
|
+
*/
|
|
65
|
+
get translations(): Translations | null;
|
|
66
|
+
/**
|
|
67
|
+
* Override any user-facing string. Omitted keys fall back to English defaults.
|
|
68
|
+
*/
|
|
69
|
+
set translations(value: Translations | null | undefined);
|
|
70
|
+
private syncTranslationsFromAttribute;
|
|
71
|
+
private rerenderAfterTranslationsChange;
|
|
60
72
|
private getProps;
|
|
61
73
|
private initializeClient;
|
|
62
74
|
private render;
|
|
@@ -96,16 +108,34 @@ export declare class ChatPageSnippet extends HTMLElement {
|
|
|
96
108
|
private sessions;
|
|
97
109
|
private currentSessionId;
|
|
98
110
|
private sidebarCollapsed;
|
|
111
|
+
private translationsOverride;
|
|
112
|
+
private resolvedTranslations;
|
|
99
113
|
private handleClearClick;
|
|
100
114
|
private handleNewChatClick;
|
|
101
115
|
private handleToggleSidebarClick;
|
|
102
116
|
private handleChatListClick;
|
|
103
117
|
private handleMessageEvent;
|
|
104
|
-
static get observedAttributes(): readonly ["api-url", "placeholder", "theme", "hide-branding"];
|
|
118
|
+
static get observedAttributes(): readonly ["api-url", "placeholder", "theme", "hide-branding", "translations"];
|
|
105
119
|
constructor();
|
|
106
120
|
connectedCallback(): void;
|
|
107
121
|
disconnectedCallback(): void;
|
|
108
122
|
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
123
|
+
/**
|
|
124
|
+
* Get the current translations object.
|
|
125
|
+
*/
|
|
126
|
+
get translations(): Translations | null;
|
|
127
|
+
/**
|
|
128
|
+
* Override any user-facing string. Omitted keys fall back to English defaults.
|
|
129
|
+
*/
|
|
130
|
+
set translations(value: Translations | null | undefined);
|
|
131
|
+
private syncTranslationsFromAttribute;
|
|
132
|
+
/**
|
|
133
|
+
* Replace the stored title of any still-default-titled session with the
|
|
134
|
+
* current `newChatButton` translation, so the sidebar reflects the active
|
|
135
|
+
* language after a translations change.
|
|
136
|
+
*/
|
|
137
|
+
private refreshDefaultSessionTitles;
|
|
138
|
+
private rerenderAfterTranslationsChange;
|
|
109
139
|
private getProps;
|
|
110
140
|
private initializeClient;
|
|
111
141
|
private render;
|
|
@@ -153,6 +183,14 @@ declare interface ChatSession {
|
|
|
153
183
|
messages: Message[];
|
|
154
184
|
createdAt: number;
|
|
155
185
|
updatedAt: number;
|
|
186
|
+
/**
|
|
187
|
+
* True while the session still carries the default (auto-generated) title.
|
|
188
|
+
* Set to false once auto-titled from the first user message, or explicitly
|
|
189
|
+
* renamed. Absent on sessions persisted before this field existed; those
|
|
190
|
+
* are treated as having a default title iff the title string still matches
|
|
191
|
+
* the current `newChatButton` translation (legacy behavior).
|
|
192
|
+
*/
|
|
193
|
+
titleIsDefault?: boolean;
|
|
156
194
|
}
|
|
157
195
|
|
|
158
196
|
declare type ChatTextResponse = {
|
|
@@ -162,6 +200,16 @@ declare type ChatTextResponse = {
|
|
|
162
200
|
|
|
163
201
|
declare type ChatTypes = ChatResult | ChatTextResponse | ChatError;
|
|
164
202
|
|
|
203
|
+
export declare const DEFAULT_TRANSLATIONS: Required<Translations>;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Merge user-provided translations with built-in defaults.
|
|
207
|
+
*
|
|
208
|
+
* Performs a shallow merge so any omitted keys fall back to English. If
|
|
209
|
+
* `loadingMessages` is provided, it fully replaces the default array.
|
|
210
|
+
*/
|
|
211
|
+
export declare function mergeTranslations(user?: Translations | null): Required<Translations>;
|
|
212
|
+
|
|
165
213
|
declare interface Message {
|
|
166
214
|
id: string;
|
|
167
215
|
role: 'user' | 'assistant' | 'system';
|
|
@@ -179,10 +227,6 @@ declare interface RequestState {
|
|
|
179
227
|
timestamp: number;
|
|
180
228
|
}
|
|
181
229
|
|
|
182
|
-
/**
|
|
183
|
-
* Search Bar Snippet
|
|
184
|
-
* A search bar with results display
|
|
185
|
-
*/
|
|
186
230
|
declare class SearchBarSnippet extends HTMLElement {
|
|
187
231
|
private shadow;
|
|
188
232
|
private client;
|
|
@@ -194,15 +238,31 @@ declare class SearchBarSnippet extends HTMLElement {
|
|
|
194
238
|
private currentSearchController;
|
|
195
239
|
private loadingMessageInterval;
|
|
196
240
|
private loadingMessageIndex;
|
|
241
|
+
private translationsOverride;
|
|
242
|
+
private resolvedTranslations;
|
|
197
243
|
private handleInputChange;
|
|
198
244
|
private handleInputKeydownEnter;
|
|
199
245
|
private handleInputKeydownEscape;
|
|
200
246
|
private handleSearchButtonClick;
|
|
201
|
-
static get observedAttributes(): readonly ["api-url", "placeholder", "max-results", "debounce-ms", "theme", "hide-branding", "show-url", "show-date", "hide-thumbnails", "see-more", "request-options"];
|
|
247
|
+
static get observedAttributes(): readonly ["api-url", "placeholder", "max-results", "max-render-results", "debounce-ms", "theme", "hide-branding", "show-url", "show-date", "hide-thumbnails", "see-more", "request-options", "translations"];
|
|
202
248
|
constructor();
|
|
203
249
|
connectedCallback(): void;
|
|
204
250
|
disconnectedCallback(): void;
|
|
205
251
|
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
252
|
+
/**
|
|
253
|
+
* Get the current translations object. Mirrors the property getter.
|
|
254
|
+
*/
|
|
255
|
+
get translations(): Translations | null;
|
|
256
|
+
/**
|
|
257
|
+
* Override any user-facing string. Omitted keys fall back to English defaults.
|
|
258
|
+
*/
|
|
259
|
+
set translations(value: Translations | null | undefined);
|
|
260
|
+
/**
|
|
261
|
+
* Re-render preserving the current query and re-running the search so
|
|
262
|
+
* results remain visible after a translations change at runtime.
|
|
263
|
+
*/
|
|
264
|
+
private rerender;
|
|
265
|
+
private syncTranslationsFromAttribute;
|
|
206
266
|
private getProps;
|
|
207
267
|
private getRequestOptions;
|
|
208
268
|
private initializeClient;
|
|
@@ -250,17 +310,35 @@ export declare class SearchModalSnippet extends HTMLElement {
|
|
|
250
310
|
private currentSearchController;
|
|
251
311
|
private loadingMessageInterval;
|
|
252
312
|
private loadingMessageIndex;
|
|
313
|
+
private translationsOverride;
|
|
314
|
+
private resolvedTranslations;
|
|
253
315
|
private handleGlobalKeydown;
|
|
254
316
|
private handleInputChange;
|
|
255
317
|
private handleInputKeydown;
|
|
256
318
|
private handleBackdropClick;
|
|
257
319
|
private savedBodyStyles;
|
|
258
320
|
private savedHtmlOverflow;
|
|
259
|
-
static get observedAttributes(): readonly ["api-url", "placeholder", "max-results", "theme", "shortcut", "use-meta-key", "debounce-ms", "hide-branding", "show-url", "show-date", "hide-thumbnails", "see-more", "request-options"];
|
|
321
|
+
static get observedAttributes(): readonly ["api-url", "placeholder", "max-results", "max-render-results", "theme", "shortcut", "use-meta-key", "debounce-ms", "hide-branding", "show-url", "show-date", "hide-thumbnails", "see-more", "request-options", "translations"];
|
|
260
322
|
constructor();
|
|
261
323
|
connectedCallback(): void;
|
|
262
324
|
disconnectedCallback(): void;
|
|
263
325
|
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
326
|
+
/**
|
|
327
|
+
* Get the current translations object.
|
|
328
|
+
*/
|
|
329
|
+
get translations(): Translations | null;
|
|
330
|
+
/**
|
|
331
|
+
* Override any user-facing string. Omitted keys fall back to English defaults.
|
|
332
|
+
*/
|
|
333
|
+
set translations(value: Translations | null | undefined);
|
|
334
|
+
/**
|
|
335
|
+
* Re-render while preserving open state and the current query. Results are
|
|
336
|
+
* re-fetched so the list reflects the updated translation strings around
|
|
337
|
+
* them (counts, footer hints, etc.). Selection resets to none — the same
|
|
338
|
+
* behavior as the immediate post-search state.
|
|
339
|
+
*/
|
|
340
|
+
private rerender;
|
|
341
|
+
private syncTranslationsFromAttribute;
|
|
264
342
|
private getProps;
|
|
265
343
|
private getRequestOptions;
|
|
266
344
|
private initializeClient;
|
|
@@ -360,8 +438,10 @@ export declare interface SearchSnippetProps {
|
|
|
360
438
|
apiUrl: string;
|
|
361
439
|
/** Input placeholder text */
|
|
362
440
|
placeholder?: string;
|
|
363
|
-
/** Maximum search results to
|
|
441
|
+
/** Maximum search results to request from the API */
|
|
364
442
|
maxResults?: number;
|
|
443
|
+
/** Maximum search results to render in the UI (caps the visible list and drives the "see more" affordance) */
|
|
444
|
+
maxRenderResults?: number;
|
|
365
445
|
/** Input debounce delay in milliseconds (search-bar only) */
|
|
366
446
|
debounceMs?: number;
|
|
367
447
|
/** Color scheme */
|
|
@@ -376,11 +456,151 @@ export declare interface SearchSnippetProps {
|
|
|
376
456
|
hideThumbnails?: boolean;
|
|
377
457
|
/** URL template for "See more" link. The search query is appended URL-encoded. Example: "https://example.com/search?q=" */
|
|
378
458
|
seeMore?: string;
|
|
459
|
+
/**
|
|
460
|
+
* Override any user-facing string. Omitted keys fall back to English defaults.
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
* ```ts
|
|
464
|
+
* element.translations = { placeholder: 'Busca aquí...' };
|
|
465
|
+
* ```
|
|
466
|
+
*/
|
|
467
|
+
translations?: Translations;
|
|
379
468
|
}
|
|
380
469
|
|
|
470
|
+
export declare type Theme = 'light' | 'dark' | 'auto';
|
|
471
|
+
|
|
381
472
|
/**
|
|
382
|
-
*
|
|
473
|
+
* Translation utilities for component user-facing strings.
|
|
474
|
+
*
|
|
475
|
+
* Users override any subset of translations via the `translations` attribute
|
|
476
|
+
* (JSON string) or property (plain object). Missing keys fall back to the
|
|
477
|
+
* built-in English defaults.
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* ```html
|
|
481
|
+
* <search-bar-snippet translations='{"placeholder":"Busca aqu\u00ed..."}'></search-bar-snippet>
|
|
482
|
+
* ```
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```ts
|
|
486
|
+
* element.translations = { placeholder: 'Busca aquí...' };
|
|
487
|
+
* ```
|
|
383
488
|
*/
|
|
384
|
-
|
|
489
|
+
/**
|
|
490
|
+
* All user-facing strings rendered by the snippet components.
|
|
491
|
+
*
|
|
492
|
+
* All keys are optional; unspecified keys fall back to English defaults.
|
|
493
|
+
* Strings can contain `{name}` tokens that are interpolated at render time.
|
|
494
|
+
*/
|
|
495
|
+
export declare interface Translations {
|
|
496
|
+
/** Aria label for loading spinners. Default: "Loading" */
|
|
497
|
+
loadingAriaLabel?: string;
|
|
498
|
+
/** Bold prefix for error messages. Default: "Error:" */
|
|
499
|
+
errorPrefix?: string;
|
|
500
|
+
/** Message shown when the `api-url` attribute is missing. */
|
|
501
|
+
missingApiUrlError?: string;
|
|
502
|
+
/** Branding prefix before the product link. Default: "Powered by" */
|
|
503
|
+
poweredBy?: string;
|
|
504
|
+
/** Branding link label. Default: "Cloudflare AI Search" */
|
|
505
|
+
poweredByLinkLabel?: string;
|
|
506
|
+
/** Search input placeholder text. */
|
|
507
|
+
placeholder?: string;
|
|
508
|
+
/** Search submit button text and aria-label. */
|
|
509
|
+
searchButtonLabel?: string;
|
|
510
|
+
/** Aria-label for the search input on the bar variant. */
|
|
511
|
+
searchInputAriaLabel?: string;
|
|
512
|
+
/** Aria-label for the modal results list. */
|
|
513
|
+
searchResultsAriaLabel?: string;
|
|
514
|
+
/** Title shown before a user enters a query (bar variant). */
|
|
515
|
+
emptyStateTitle?: string;
|
|
516
|
+
/** Description shown before a user enters a query (bar variant). */
|
|
517
|
+
emptyStateDescription?: string;
|
|
518
|
+
/** Description shown before a user enters a query (modal variant). */
|
|
519
|
+
modalEmptyStateDescription?: string;
|
|
520
|
+
/** Title shown when a search returns no results (bar variant). */
|
|
521
|
+
noResultsTitle?: string;
|
|
522
|
+
/** Description shown when a search returns no results (bar variant). Supports `{query}`. */
|
|
523
|
+
noResultsDescription?: string;
|
|
524
|
+
/** Title shown when a search returns no results (modal variant). */
|
|
525
|
+
modalNoResultsTitle?: string;
|
|
526
|
+
/** Description shown when a search returns no results (modal variant). Supports `{query}`. */
|
|
527
|
+
modalNoResultsDescription?: string;
|
|
528
|
+
/** Bar results count when exactly 1 result. Supports `{n}`. */
|
|
529
|
+
resultsCount?: string;
|
|
530
|
+
/** Bar results count when multiple results. Supports `{n}`. */
|
|
531
|
+
resultsCountPlural?: string;
|
|
532
|
+
/** Bar/modal results count when truncated. Supports `{n}` and `{total}`. */
|
|
533
|
+
resultsCountOverflow?: string;
|
|
534
|
+
/** Modal footer results count when exactly 1 result. Supports `{n}`. */
|
|
535
|
+
modalResultsCount?: string;
|
|
536
|
+
/** Modal footer results count when multiple results. Supports `{n}`. */
|
|
537
|
+
modalResultsCountPlural?: string;
|
|
538
|
+
/** Modal footer count shown with the zero-results state. */
|
|
539
|
+
modalResultsCountZero?: string;
|
|
540
|
+
/** Modal footer text shown with the error state. */
|
|
541
|
+
modalResultsCountError?: string;
|
|
542
|
+
/** Label for the "see more" link when `see-more` is configured. */
|
|
543
|
+
seeMoreResults?: string;
|
|
544
|
+
/** Modal footer hint next to the ↑ ↓ keys. */
|
|
545
|
+
navigateHint?: string;
|
|
546
|
+
/** Modal footer hint next to the ↵ key. */
|
|
547
|
+
selectHint?: string;
|
|
548
|
+
/** Modal footer hint next to the Esc key. */
|
|
549
|
+
closeHint?: string;
|
|
550
|
+
/** Chat header title. */
|
|
551
|
+
chatTitle?: string;
|
|
552
|
+
/** Chat input placeholder text. */
|
|
553
|
+
chatPlaceholder?: string;
|
|
554
|
+
/** Aria-label for the chat textarea. */
|
|
555
|
+
chatInputAriaLabel?: string;
|
|
556
|
+
/** Chat send button text. */
|
|
557
|
+
sendButtonLabel?: string;
|
|
558
|
+
/** Chat send button aria-label. */
|
|
559
|
+
sendButtonAriaLabel?: string;
|
|
560
|
+
/** Empty chat state title. */
|
|
561
|
+
chatEmptyTitle?: string;
|
|
562
|
+
/** Empty chat state description. */
|
|
563
|
+
chatEmptyDescription?: string;
|
|
564
|
+
/** User message avatar text. Default: "U" */
|
|
565
|
+
userAvatar?: string;
|
|
566
|
+
/** Assistant message avatar text. Default: "AI" */
|
|
567
|
+
assistantAvatar?: string;
|
|
568
|
+
/** Fallback for chat errors with no message. */
|
|
569
|
+
unknownError?: string;
|
|
570
|
+
/** Aria-label for the floating chat bubble button. */
|
|
571
|
+
openChatAriaLabel?: string;
|
|
572
|
+
/** Aria-label for the clear-history icon button. */
|
|
573
|
+
clearHistoryAriaLabel?: string;
|
|
574
|
+
/** Aria-label for the minimize icon button. */
|
|
575
|
+
minimizeAriaLabel?: string;
|
|
576
|
+
/** Aria-label for the close icon button. */
|
|
577
|
+
closeAriaLabel?: string;
|
|
578
|
+
/** Sidebar heading on the chat-page variant. */
|
|
579
|
+
historyTitle?: string;
|
|
580
|
+
/** New-chat button label. */
|
|
581
|
+
newChatButton?: string;
|
|
582
|
+
/** Clear-chat header button label. */
|
|
583
|
+
clearChatButton?: string;
|
|
584
|
+
/** Tooltip for the sidebar toggle button. */
|
|
585
|
+
toggleSidebarTitle?: string;
|
|
586
|
+
/** Tooltip for a per-session delete button. */
|
|
587
|
+
deleteChatTitle?: string;
|
|
588
|
+
/** Empty sessions list message. */
|
|
589
|
+
noChatsYet?: string;
|
|
590
|
+
/** Label for "one day ago" in the sessions list. */
|
|
591
|
+
yesterday?: string;
|
|
592
|
+
/** Relative timestamp for < 1 minute ago. */
|
|
593
|
+
justNow?: string;
|
|
594
|
+
/** Relative timestamp for exactly 1 minute ago. Supports `{n}`. */
|
|
595
|
+
minuteAgo?: string;
|
|
596
|
+
/** Relative timestamp for 2-59 minutes ago. Supports `{n}`. */
|
|
597
|
+
minutesAgo?: string;
|
|
598
|
+
/** Relative timestamp for exactly 1 hour ago. Supports `{n}`. */
|
|
599
|
+
hourAgo?: string;
|
|
600
|
+
/** Relative timestamp for 2-23 hours ago. Supports `{n}`. */
|
|
601
|
+
hoursAgo?: string;
|
|
602
|
+
/** Cycling loading messages shown during search/streaming. Provide the full array to override. */
|
|
603
|
+
loadingMessages?: string[];
|
|
604
|
+
}
|
|
385
605
|
|
|
386
606
|
export { }
|