@cloudflare/ai-search-snippet 0.0.37 → 0.0.39
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 +412 -10
- package/dist/search-snippet.es.js +1203 -458
- package/dist/search-snippet.es.js.map +1 -1
- package/dist/search-snippet.umd.js +144 -127
- package/dist/search-snippet.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -9,6 +9,13 @@ export declare class AISearchClient {
|
|
|
9
9
|
search(query: string, options?: Omit<SearchOptions, 'query'>): Promise<SearchResult[]>;
|
|
10
10
|
searchStream(query: string, options?: Omit<SearchOptions, 'query'>): AsyncGenerator<SearchResult | SearchError, void, undefined>;
|
|
11
11
|
chat(query: string, options?: ChatOptions): AsyncGenerator<ChatTypes, void, undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* Consume an SSE stream from the chat/completions endpoint and yield one
|
|
14
|
+
* ChatTextResponse per non-empty content delta. Discards `event: chunks`
|
|
15
|
+
* (RAG sources) and the `[DONE]` sentinel; tolerates malformed individual
|
|
16
|
+
* frames without aborting the whole stream.
|
|
17
|
+
*/
|
|
18
|
+
private parseChatStream;
|
|
12
19
|
/**
|
|
13
20
|
* Cancels an active request by ID
|
|
14
21
|
*/
|
|
@@ -41,6 +48,23 @@ export declare interface ApiError {
|
|
|
41
48
|
details?: Record<string, unknown>;
|
|
42
49
|
}
|
|
43
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Stats Client
|
|
53
|
+
*
|
|
54
|
+
* Sends search analytics events to the `/stats` endpoint as fire-and-forget
|
|
55
|
+
* POST requests. Events are buffered and flushed in batches to reduce request
|
|
56
|
+
* count, and any remaining events are flushed via `navigator.sendBeacon` (or a
|
|
57
|
+
* keepalive `fetch` fallback) when the page is unloaded.
|
|
58
|
+
*/
|
|
59
|
+
/**
|
|
60
|
+
* Shared fields across every analytics event.
|
|
61
|
+
*/
|
|
62
|
+
declare interface BaseStatsEvent {
|
|
63
|
+
inputQuery: string;
|
|
64
|
+
snippetVersion: string;
|
|
65
|
+
totalResult: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
44
68
|
export declare class ChatBubbleSnippet extends HTMLElement {
|
|
45
69
|
private shadow;
|
|
46
70
|
private client;
|
|
@@ -48,16 +72,36 @@ export declare class ChatBubbleSnippet extends HTMLElement {
|
|
|
48
72
|
private container;
|
|
49
73
|
private isExpanded;
|
|
50
74
|
private isMinimized;
|
|
75
|
+
private translationsOverride;
|
|
76
|
+
private resolvedTranslations;
|
|
77
|
+
private chatQueryRewriteOverride;
|
|
51
78
|
private handleBubbleClick;
|
|
52
79
|
private handleCloseClick;
|
|
53
80
|
private handleMinimizeClick;
|
|
54
81
|
private handleClearClick;
|
|
55
|
-
static get observedAttributes(): readonly ["api-url", "placeholder", "theme", "hide-branding"];
|
|
82
|
+
static get observedAttributes(): readonly ["api-url", "placeholder", "theme", "hide-branding", "translations", "chat-query-rewrite"];
|
|
56
83
|
constructor();
|
|
57
84
|
connectedCallback(): void;
|
|
58
85
|
disconnectedCallback(): void;
|
|
59
86
|
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
87
|
+
/**
|
|
88
|
+
* Get the current translations object.
|
|
89
|
+
*/
|
|
90
|
+
get translations(): Translations | null;
|
|
91
|
+
/**
|
|
92
|
+
* Override AI Search query rewriting on subsequent chat turns. Setting
|
|
93
|
+
* `null` falls back to parsing the `chat-query-rewrite` attribute.
|
|
94
|
+
*/
|
|
95
|
+
get chatQueryRewrite(): SearchSnippetProps['chatQueryRewrite'] | null;
|
|
96
|
+
set chatQueryRewrite(value: SearchSnippetProps['chatQueryRewrite'] | null | undefined);
|
|
97
|
+
/**
|
|
98
|
+
* Override any user-facing string. Omitted keys fall back to English defaults.
|
|
99
|
+
*/
|
|
100
|
+
set translations(value: Translations | null | undefined);
|
|
101
|
+
private syncTranslationsFromAttribute;
|
|
102
|
+
private rerenderAfterTranslationsChange;
|
|
60
103
|
private getProps;
|
|
104
|
+
private resolveChatQueryRewrite;
|
|
61
105
|
private initializeClient;
|
|
62
106
|
private render;
|
|
63
107
|
private getBubbleStyles;
|
|
@@ -80,12 +124,31 @@ declare type ChatError = {
|
|
|
80
124
|
message: string;
|
|
81
125
|
};
|
|
82
126
|
|
|
127
|
+
/**
|
|
128
|
+
* A single chat message in the conversation history.
|
|
129
|
+
*/
|
|
130
|
+
declare interface ChatMessage {
|
|
131
|
+
role: 'user' | 'assistant' | 'system';
|
|
132
|
+
content: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
83
135
|
/**
|
|
84
136
|
* Chat options
|
|
85
137
|
*/
|
|
86
138
|
export declare interface ChatOptions {
|
|
87
139
|
stream?: boolean;
|
|
88
140
|
signal?: AbortSignal;
|
|
141
|
+
/** Prior conversation turns to send before the new user query. */
|
|
142
|
+
history?: ChatMessage[];
|
|
143
|
+
/**
|
|
144
|
+
* Enable AI Search query rewriting. Pass `true` to use built-in defaults,
|
|
145
|
+
* an object to override the model and/or rewrite prompt, or omit / pass
|
|
146
|
+
* `false` to disable.
|
|
147
|
+
*/
|
|
148
|
+
queryRewrite?: boolean | {
|
|
149
|
+
model?: string;
|
|
150
|
+
rewritePrompt?: string;
|
|
151
|
+
};
|
|
89
152
|
}
|
|
90
153
|
|
|
91
154
|
export declare class ChatPageSnippet extends HTMLElement {
|
|
@@ -96,17 +159,43 @@ export declare class ChatPageSnippet extends HTMLElement {
|
|
|
96
159
|
private sessions;
|
|
97
160
|
private currentSessionId;
|
|
98
161
|
private sidebarCollapsed;
|
|
162
|
+
private translationsOverride;
|
|
163
|
+
private resolvedTranslations;
|
|
164
|
+
private chatQueryRewriteOverride;
|
|
99
165
|
private handleClearClick;
|
|
100
166
|
private handleNewChatClick;
|
|
101
167
|
private handleToggleSidebarClick;
|
|
102
168
|
private handleChatListClick;
|
|
103
169
|
private handleMessageEvent;
|
|
104
|
-
static get observedAttributes(): readonly ["api-url", "placeholder", "theme", "hide-branding"];
|
|
170
|
+
static get observedAttributes(): readonly ["api-url", "placeholder", "theme", "hide-branding", "translations", "chat-query-rewrite"];
|
|
105
171
|
constructor();
|
|
106
172
|
connectedCallback(): void;
|
|
107
173
|
disconnectedCallback(): void;
|
|
108
174
|
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
175
|
+
/**
|
|
176
|
+
* Get the current translations object.
|
|
177
|
+
*/
|
|
178
|
+
get translations(): Translations | null;
|
|
179
|
+
/**
|
|
180
|
+
* Override AI Search query rewriting on subsequent chat turns. Setting
|
|
181
|
+
* `null` falls back to parsing the `chat-query-rewrite` attribute.
|
|
182
|
+
*/
|
|
183
|
+
get chatQueryRewrite(): SearchSnippetProps['chatQueryRewrite'] | null;
|
|
184
|
+
set chatQueryRewrite(value: SearchSnippetProps['chatQueryRewrite'] | null | undefined);
|
|
185
|
+
/**
|
|
186
|
+
* Override any user-facing string. Omitted keys fall back to English defaults.
|
|
187
|
+
*/
|
|
188
|
+
set translations(value: Translations | null | undefined);
|
|
189
|
+
private syncTranslationsFromAttribute;
|
|
190
|
+
/**
|
|
191
|
+
* Replace the stored title of any still-default-titled session with the
|
|
192
|
+
* current `newChatButton` translation, so the sidebar reflects the active
|
|
193
|
+
* language after a translations change.
|
|
194
|
+
*/
|
|
195
|
+
private refreshDefaultSessionTitles;
|
|
196
|
+
private rerenderAfterTranslationsChange;
|
|
109
197
|
private getProps;
|
|
198
|
+
private resolveChatQueryRewrite;
|
|
110
199
|
private initializeClient;
|
|
111
200
|
private render;
|
|
112
201
|
private getPageStyles;
|
|
@@ -153,6 +242,14 @@ declare interface ChatSession {
|
|
|
153
242
|
messages: Message[];
|
|
154
243
|
createdAt: number;
|
|
155
244
|
updatedAt: number;
|
|
245
|
+
/**
|
|
246
|
+
* True while the session still carries the default (auto-generated) title.
|
|
247
|
+
* Set to false once auto-titled from the first user message, or explicitly
|
|
248
|
+
* renamed. Absent on sessions persisted before this field existed; those
|
|
249
|
+
* are treated as having a default title iff the title string still matches
|
|
250
|
+
* the current `newChatButton` translation (legacy behavior).
|
|
251
|
+
*/
|
|
252
|
+
titleIsDefault?: boolean;
|
|
156
253
|
}
|
|
157
254
|
|
|
158
255
|
declare type ChatTextResponse = {
|
|
@@ -162,6 +259,25 @@ declare type ChatTextResponse = {
|
|
|
162
259
|
|
|
163
260
|
declare type ChatTypes = ChatResult | ChatTextResponse | ChatError;
|
|
164
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Fired when a user clicks a specific result in the list.
|
|
264
|
+
*/
|
|
265
|
+
export declare interface ClickStatsEvent extends BaseStatsEvent {
|
|
266
|
+
clickedResultId: string;
|
|
267
|
+
clickPosition: number;
|
|
268
|
+
clickViewMore: false;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export declare const DEFAULT_TRANSLATIONS: Required<Translations>;
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Merge user-provided translations with built-in defaults.
|
|
275
|
+
*
|
|
276
|
+
* Performs a shallow merge so any omitted keys fall back to English. If
|
|
277
|
+
* `loadingMessages` is provided, it fully replaces the default array.
|
|
278
|
+
*/
|
|
279
|
+
export declare function mergeTranslations(user?: Translations | null): Required<Translations>;
|
|
280
|
+
|
|
165
281
|
declare interface Message {
|
|
166
282
|
id: string;
|
|
167
283
|
role: 'user' | 'assistant' | 'system';
|
|
@@ -179,13 +295,10 @@ declare interface RequestState {
|
|
|
179
295
|
timestamp: number;
|
|
180
296
|
}
|
|
181
297
|
|
|
182
|
-
/**
|
|
183
|
-
* Search Bar Snippet
|
|
184
|
-
* A search bar with results display
|
|
185
|
-
*/
|
|
186
298
|
declare class SearchBarSnippet extends HTMLElement {
|
|
187
299
|
private shadow;
|
|
188
300
|
private client;
|
|
301
|
+
private stats;
|
|
189
302
|
private container;
|
|
190
303
|
private inputElement;
|
|
191
304
|
private resultsContainer;
|
|
@@ -194,18 +307,39 @@ declare class SearchBarSnippet extends HTMLElement {
|
|
|
194
307
|
private currentSearchController;
|
|
195
308
|
private loadingMessageInterval;
|
|
196
309
|
private loadingMessageIndex;
|
|
310
|
+
private translationsOverride;
|
|
311
|
+
private resolvedTranslations;
|
|
312
|
+
private lastSearchQuery;
|
|
313
|
+
private lastSearchTotal;
|
|
197
314
|
private handleInputChange;
|
|
198
315
|
private handleInputKeydownEnter;
|
|
199
316
|
private handleInputKeydownEscape;
|
|
200
317
|
private handleSearchButtonClick;
|
|
201
|
-
|
|
318
|
+
private handleResultClick;
|
|
319
|
+
private handleSeeMoreClick;
|
|
320
|
+
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", "disable-analytics", "request-options", "translations"];
|
|
202
321
|
constructor();
|
|
203
322
|
connectedCallback(): void;
|
|
204
323
|
disconnectedCallback(): void;
|
|
205
324
|
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
325
|
+
/**
|
|
326
|
+
* Get the current translations object. Mirrors the property getter.
|
|
327
|
+
*/
|
|
328
|
+
get translations(): Translations | null;
|
|
329
|
+
/**
|
|
330
|
+
* Override any user-facing string. Omitted keys fall back to English defaults.
|
|
331
|
+
*/
|
|
332
|
+
set translations(value: Translations | null | undefined);
|
|
333
|
+
/**
|
|
334
|
+
* Re-render preserving the current query and re-running the search so
|
|
335
|
+
* results remain visible after a translations change at runtime.
|
|
336
|
+
*/
|
|
337
|
+
private rerender;
|
|
338
|
+
private syncTranslationsFromAttribute;
|
|
206
339
|
private getProps;
|
|
207
340
|
private getRequestOptions;
|
|
208
341
|
private initializeClient;
|
|
342
|
+
private destroyStatsClient;
|
|
209
343
|
private render;
|
|
210
344
|
private attachEventListeners;
|
|
211
345
|
private performSearch;
|
|
@@ -213,6 +347,7 @@ declare class SearchBarSnippet extends HTMLElement {
|
|
|
213
347
|
private renderResult;
|
|
214
348
|
private renderResultImage;
|
|
215
349
|
private attachResultHandlers;
|
|
350
|
+
private detachResultTrackingHandlers;
|
|
216
351
|
private showLoadingState;
|
|
217
352
|
private startLoadingInterval;
|
|
218
353
|
private clearLoadingInterval;
|
|
@@ -238,6 +373,7 @@ declare interface SearchError {
|
|
|
238
373
|
export declare class SearchModalSnippet extends HTMLElement {
|
|
239
374
|
private shadow;
|
|
240
375
|
private client;
|
|
376
|
+
private stats;
|
|
241
377
|
private backdrop;
|
|
242
378
|
private modal;
|
|
243
379
|
private inputElement;
|
|
@@ -250,20 +386,42 @@ export declare class SearchModalSnippet extends HTMLElement {
|
|
|
250
386
|
private currentSearchController;
|
|
251
387
|
private loadingMessageInterval;
|
|
252
388
|
private loadingMessageIndex;
|
|
389
|
+
private translationsOverride;
|
|
390
|
+
private resolvedTranslations;
|
|
391
|
+
private lastSearchQuery;
|
|
392
|
+
private lastSearchTotal;
|
|
253
393
|
private handleGlobalKeydown;
|
|
254
394
|
private handleInputChange;
|
|
255
395
|
private handleInputKeydown;
|
|
256
396
|
private handleBackdropClick;
|
|
397
|
+
private handleResultsContainerClick;
|
|
257
398
|
private savedBodyStyles;
|
|
258
399
|
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"];
|
|
400
|
+
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", "disable-analytics", "request-options", "translations"];
|
|
260
401
|
constructor();
|
|
261
402
|
connectedCallback(): void;
|
|
262
403
|
disconnectedCallback(): void;
|
|
263
404
|
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
405
|
+
/**
|
|
406
|
+
* Get the current translations object.
|
|
407
|
+
*/
|
|
408
|
+
get translations(): Translations | null;
|
|
409
|
+
/**
|
|
410
|
+
* Override any user-facing string. Omitted keys fall back to English defaults.
|
|
411
|
+
*/
|
|
412
|
+
set translations(value: Translations | null | undefined);
|
|
413
|
+
/**
|
|
414
|
+
* Re-render while preserving open state and the current query. Results are
|
|
415
|
+
* re-fetched so the list reflects the updated translation strings around
|
|
416
|
+
* them (counts, footer hints, etc.). Selection resets to none — the same
|
|
417
|
+
* behavior as the immediate post-search state.
|
|
418
|
+
*/
|
|
419
|
+
private rerender;
|
|
420
|
+
private syncTranslationsFromAttribute;
|
|
264
421
|
private getProps;
|
|
265
422
|
private getRequestOptions;
|
|
266
423
|
private initializeClient;
|
|
424
|
+
private destroyStatsClient;
|
|
267
425
|
private render;
|
|
268
426
|
private attachGlobalKeyboardShortcut;
|
|
269
427
|
private attachEventListeners;
|
|
@@ -275,6 +433,7 @@ export declare class SearchModalSnippet extends HTMLElement {
|
|
|
275
433
|
private renderResult;
|
|
276
434
|
private renderResultImage;
|
|
277
435
|
private attachResultHandlers;
|
|
436
|
+
private detachResultsContainerClick;
|
|
278
437
|
private renderEmptyState;
|
|
279
438
|
private showEmptyState;
|
|
280
439
|
private showLoadingState;
|
|
@@ -360,8 +519,10 @@ export declare interface SearchSnippetProps {
|
|
|
360
519
|
apiUrl: string;
|
|
361
520
|
/** Input placeholder text */
|
|
362
521
|
placeholder?: string;
|
|
363
|
-
/** Maximum search results to
|
|
522
|
+
/** Maximum search results to request from the API */
|
|
364
523
|
maxResults?: number;
|
|
524
|
+
/** Maximum search results to render in the UI (caps the visible list and drives the "see more" affordance) */
|
|
525
|
+
maxRenderResults?: number;
|
|
365
526
|
/** Input debounce delay in milliseconds (search-bar only) */
|
|
366
527
|
debounceMs?: number;
|
|
367
528
|
/** Color scheme */
|
|
@@ -376,11 +537,252 @@ export declare interface SearchSnippetProps {
|
|
|
376
537
|
hideThumbnails?: boolean;
|
|
377
538
|
/** URL template for "See more" link. The search query is appended URL-encoded. Example: "https://example.com/search?q=" */
|
|
378
539
|
seeMore?: string;
|
|
540
|
+
/**
|
|
541
|
+
* Disable sending search / click / view-more analytics events to the
|
|
542
|
+
* `/stats` endpoint. Defaults to `false` (analytics enabled).
|
|
543
|
+
*/
|
|
544
|
+
disableAnalytics?: boolean;
|
|
545
|
+
/**
|
|
546
|
+
* Override any user-facing string. Omitted keys fall back to English defaults.
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* ```ts
|
|
550
|
+
* element.translations = { placeholder: 'Busca aquí...' };
|
|
551
|
+
* ```
|
|
552
|
+
*/
|
|
553
|
+
translations?: Translations;
|
|
554
|
+
/**
|
|
555
|
+
* Customize AI Search query rewriting on subsequent chat turns.
|
|
556
|
+
*
|
|
557
|
+
* Query rewriting is automatically enabled from the second user message
|
|
558
|
+
* onward (the first message has no history to rewrite from). Use this to
|
|
559
|
+
* override the model, the rewrite prompt, or to disable the feature.
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
* ```ts
|
|
563
|
+
* element.chatQueryRewrite = { enabled: false };
|
|
564
|
+
* element.chatQueryRewrite = { model: 'openai/gpt-5-mini' };
|
|
565
|
+
* element.chatQueryRewrite = { rewritePrompt: 'Rewrite the latest user message...' };
|
|
566
|
+
* ```
|
|
567
|
+
*/
|
|
568
|
+
chatQueryRewrite?: {
|
|
569
|
+
/** Override the auto-enable behavior. Defaults to true on subsequent turns. */
|
|
570
|
+
enabled?: boolean;
|
|
571
|
+
/** Override the rewriter model. Defaults to '@cf/meta/llama-3.3-70b-instruct-fp8-fast'. */
|
|
572
|
+
model?: string;
|
|
573
|
+
/** Override the system prompt sent as `rewrite_prompt`. Defaults to a built-in prompt. */
|
|
574
|
+
rewritePrompt?: string;
|
|
575
|
+
};
|
|
379
576
|
}
|
|
380
577
|
|
|
381
578
|
/**
|
|
382
|
-
*
|
|
579
|
+
* Fired after a search completes successfully (or returns zero results).
|
|
580
|
+
* Click-related fields are intentionally omitted.
|
|
383
581
|
*/
|
|
582
|
+
export declare type SearchStatsEvent = BaseStatsEvent;
|
|
583
|
+
|
|
584
|
+
export declare class StatsClient {
|
|
585
|
+
private readonly baseUrl;
|
|
586
|
+
private readonly endpoint;
|
|
587
|
+
private readonly snippetVersion;
|
|
588
|
+
private readonly flushIntervalMs;
|
|
589
|
+
private readonly maxBufferSize;
|
|
590
|
+
private buffer;
|
|
591
|
+
private flushTimer;
|
|
592
|
+
private destroyed;
|
|
593
|
+
private readonly boundUnloadHandler;
|
|
594
|
+
private readonly boundVisibilityHandler;
|
|
595
|
+
constructor(baseUrl: string, options?: StatsClientOptions);
|
|
596
|
+
/**
|
|
597
|
+
* Record a completed search (no click).
|
|
598
|
+
*/
|
|
599
|
+
trackSearch(inputQuery: string, totalResult: number): void;
|
|
600
|
+
/**
|
|
601
|
+
* Record a click on a specific result.
|
|
602
|
+
*/
|
|
603
|
+
trackClick(inputQuery: string, totalResult: number, clickedResultId: string, clickPosition: number): void;
|
|
604
|
+
/**
|
|
605
|
+
* Record a click on the "See more" link.
|
|
606
|
+
*/
|
|
607
|
+
trackViewMore(inputQuery: string, totalResult: number): void;
|
|
608
|
+
/**
|
|
609
|
+
* Buffer a pre-built event. Higher-level `track*` helpers call this.
|
|
610
|
+
*/
|
|
611
|
+
track(event: StatsEvent): void;
|
|
612
|
+
/**
|
|
613
|
+
* Force an immediate flush using `fetch` with `keepalive: true`.
|
|
614
|
+
* Returns synchronously; network errors are swallowed.
|
|
615
|
+
*/
|
|
616
|
+
flush(): void;
|
|
617
|
+
/**
|
|
618
|
+
* Flush path optimized for page-unload. Prefers `navigator.sendBeacon`
|
|
619
|
+
* when available; falls back to `fetch({ keepalive: true })`.
|
|
620
|
+
*/
|
|
621
|
+
private flushBeacon;
|
|
622
|
+
/**
|
|
623
|
+
* Remove unload listeners, clear timers, and flush anything still buffered.
|
|
624
|
+
* Call from the host component's `disconnectedCallback`.
|
|
625
|
+
*/
|
|
626
|
+
destroy(): void;
|
|
627
|
+
private scheduleFlush;
|
|
628
|
+
private drainBuffer;
|
|
629
|
+
private buildUrl;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
export declare interface StatsClientOptions {
|
|
633
|
+
/** Overrides the library version placed on each event. Defaults to the built-in `SNIPPET_VERSION`. */
|
|
634
|
+
snippetVersion?: string;
|
|
635
|
+
/** Milliseconds to wait before auto-flushing a non-empty buffer. Defaults to 1500ms. */
|
|
636
|
+
flushIntervalMs?: number;
|
|
637
|
+
/** Buffer size that triggers an immediate flush. Defaults to 20. */
|
|
638
|
+
maxBufferSize?: number;
|
|
639
|
+
/** Path appended to `baseUrl`. Defaults to `/stats`. */
|
|
640
|
+
endpoint?: string;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
export declare type StatsEvent = SearchStatsEvent | ClickStatsEvent | ViewMoreStatsEvent;
|
|
644
|
+
|
|
384
645
|
export declare type Theme = 'light' | 'dark' | 'auto';
|
|
385
646
|
|
|
647
|
+
/**
|
|
648
|
+
* Translation utilities for component user-facing strings.
|
|
649
|
+
*
|
|
650
|
+
* Users override any subset of translations via the `translations` attribute
|
|
651
|
+
* (JSON string) or property (plain object). Missing keys fall back to the
|
|
652
|
+
* built-in English defaults.
|
|
653
|
+
*
|
|
654
|
+
* @example
|
|
655
|
+
* ```html
|
|
656
|
+
* <search-bar-snippet translations='{"placeholder":"Busca aqu\u00ed..."}'></search-bar-snippet>
|
|
657
|
+
* ```
|
|
658
|
+
*
|
|
659
|
+
* @example
|
|
660
|
+
* ```ts
|
|
661
|
+
* element.translations = { placeholder: 'Busca aquí...' };
|
|
662
|
+
* ```
|
|
663
|
+
*/
|
|
664
|
+
/**
|
|
665
|
+
* All user-facing strings rendered by the snippet components.
|
|
666
|
+
*
|
|
667
|
+
* All keys are optional; unspecified keys fall back to English defaults.
|
|
668
|
+
* Strings can contain `{name}` tokens that are interpolated at render time.
|
|
669
|
+
*/
|
|
670
|
+
export declare interface Translations {
|
|
671
|
+
/** Aria label for loading spinners. Default: "Loading" */
|
|
672
|
+
loadingAriaLabel?: string;
|
|
673
|
+
/** Bold prefix for error messages. Default: "Error:" */
|
|
674
|
+
errorPrefix?: string;
|
|
675
|
+
/** Message shown when the `api-url` attribute is missing. */
|
|
676
|
+
missingApiUrlError?: string;
|
|
677
|
+
/** Branding prefix before the product link. Default: "Powered by" */
|
|
678
|
+
poweredBy?: string;
|
|
679
|
+
/** Branding link label. Default: "Cloudflare AI Search" */
|
|
680
|
+
poweredByLinkLabel?: string;
|
|
681
|
+
/** Search input placeholder text. */
|
|
682
|
+
placeholder?: string;
|
|
683
|
+
/** Search submit button text and aria-label. */
|
|
684
|
+
searchButtonLabel?: string;
|
|
685
|
+
/** Aria-label for the search input on the bar variant. */
|
|
686
|
+
searchInputAriaLabel?: string;
|
|
687
|
+
/** Aria-label for the modal results list. */
|
|
688
|
+
searchResultsAriaLabel?: string;
|
|
689
|
+
/** Title shown before a user enters a query (bar variant). */
|
|
690
|
+
emptyStateTitle?: string;
|
|
691
|
+
/** Description shown before a user enters a query (bar variant). */
|
|
692
|
+
emptyStateDescription?: string;
|
|
693
|
+
/** Description shown before a user enters a query (modal variant). */
|
|
694
|
+
modalEmptyStateDescription?: string;
|
|
695
|
+
/** Title shown when a search returns no results (bar variant). */
|
|
696
|
+
noResultsTitle?: string;
|
|
697
|
+
/** Description shown when a search returns no results (bar variant). Supports `{query}`. */
|
|
698
|
+
noResultsDescription?: string;
|
|
699
|
+
/** Title shown when a search returns no results (modal variant). */
|
|
700
|
+
modalNoResultsTitle?: string;
|
|
701
|
+
/** Description shown when a search returns no results (modal variant). Supports `{query}`. */
|
|
702
|
+
modalNoResultsDescription?: string;
|
|
703
|
+
/** Bar results count when exactly 1 result. Supports `{n}`. */
|
|
704
|
+
resultsCount?: string;
|
|
705
|
+
/** Bar results count when multiple results. Supports `{n}`. */
|
|
706
|
+
resultsCountPlural?: string;
|
|
707
|
+
/** Bar/modal results count when truncated. Supports `{n}` and `{total}`. */
|
|
708
|
+
resultsCountOverflow?: string;
|
|
709
|
+
/** Modal footer results count when exactly 1 result. Supports `{n}`. */
|
|
710
|
+
modalResultsCount?: string;
|
|
711
|
+
/** Modal footer results count when multiple results. Supports `{n}`. */
|
|
712
|
+
modalResultsCountPlural?: string;
|
|
713
|
+
/** Modal footer count shown with the zero-results state. */
|
|
714
|
+
modalResultsCountZero?: string;
|
|
715
|
+
/** Modal footer text shown with the error state. */
|
|
716
|
+
modalResultsCountError?: string;
|
|
717
|
+
/** Label for the "see more" link when `see-more` is configured. */
|
|
718
|
+
seeMoreResults?: string;
|
|
719
|
+
/** Modal footer hint next to the ↑ ↓ keys. */
|
|
720
|
+
navigateHint?: string;
|
|
721
|
+
/** Modal footer hint next to the ↵ key. */
|
|
722
|
+
selectHint?: string;
|
|
723
|
+
/** Modal footer hint next to the Esc key. */
|
|
724
|
+
closeHint?: string;
|
|
725
|
+
/** Chat header title. */
|
|
726
|
+
chatTitle?: string;
|
|
727
|
+
/** Chat input placeholder text. */
|
|
728
|
+
chatPlaceholder?: string;
|
|
729
|
+
/** Aria-label for the chat textarea. */
|
|
730
|
+
chatInputAriaLabel?: string;
|
|
731
|
+
/** Chat send button text. */
|
|
732
|
+
sendButtonLabel?: string;
|
|
733
|
+
/** Chat send button aria-label. */
|
|
734
|
+
sendButtonAriaLabel?: string;
|
|
735
|
+
/** Empty chat state title. */
|
|
736
|
+
chatEmptyTitle?: string;
|
|
737
|
+
/** Empty chat state description. */
|
|
738
|
+
chatEmptyDescription?: string;
|
|
739
|
+
/** User message avatar text. Default: "U" */
|
|
740
|
+
userAvatar?: string;
|
|
741
|
+
/** Assistant message avatar text. Default: "AI" */
|
|
742
|
+
assistantAvatar?: string;
|
|
743
|
+
/** Fallback for chat errors with no message. */
|
|
744
|
+
unknownError?: string;
|
|
745
|
+
/** Aria-label for the floating chat bubble button. */
|
|
746
|
+
openChatAriaLabel?: string;
|
|
747
|
+
/** Aria-label for the clear-history icon button. */
|
|
748
|
+
clearHistoryAriaLabel?: string;
|
|
749
|
+
/** Aria-label for the minimize icon button. */
|
|
750
|
+
minimizeAriaLabel?: string;
|
|
751
|
+
/** Aria-label for the close icon button. */
|
|
752
|
+
closeAriaLabel?: string;
|
|
753
|
+
/** Sidebar heading on the chat-page variant. */
|
|
754
|
+
historyTitle?: string;
|
|
755
|
+
/** New-chat button label. */
|
|
756
|
+
newChatButton?: string;
|
|
757
|
+
/** Clear-chat header button label. */
|
|
758
|
+
clearChatButton?: string;
|
|
759
|
+
/** Tooltip for the sidebar toggle button. */
|
|
760
|
+
toggleSidebarTitle?: string;
|
|
761
|
+
/** Tooltip for a per-session delete button. */
|
|
762
|
+
deleteChatTitle?: string;
|
|
763
|
+
/** Empty sessions list message. */
|
|
764
|
+
noChatsYet?: string;
|
|
765
|
+
/** Label for "one day ago" in the sessions list. */
|
|
766
|
+
yesterday?: string;
|
|
767
|
+
/** Relative timestamp for < 1 minute ago. */
|
|
768
|
+
justNow?: string;
|
|
769
|
+
/** Relative timestamp for exactly 1 minute ago. Supports `{n}`. */
|
|
770
|
+
minuteAgo?: string;
|
|
771
|
+
/** Relative timestamp for 2-59 minutes ago. Supports `{n}`. */
|
|
772
|
+
minutesAgo?: string;
|
|
773
|
+
/** Relative timestamp for exactly 1 hour ago. Supports `{n}`. */
|
|
774
|
+
hourAgo?: string;
|
|
775
|
+
/** Relative timestamp for 2-23 hours ago. Supports `{n}`. */
|
|
776
|
+
hoursAgo?: string;
|
|
777
|
+
/** Cycling loading messages shown during search/streaming. Provide the full array to override. */
|
|
778
|
+
loadingMessages?: string[];
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Fired when a user clicks the "See more" affordance beneath the results.
|
|
783
|
+
*/
|
|
784
|
+
export declare interface ViewMoreStatsEvent extends BaseStatsEvent {
|
|
785
|
+
clickViewMore: true;
|
|
786
|
+
}
|
|
787
|
+
|
|
386
788
|
export { }
|