@cloudflare/ai-search-snippet 0.0.17

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 ADDED
@@ -0,0 +1,359 @@
1
+ export declare class AISearchClient extends Client {
2
+ private request;
3
+ /**
4
+ * Performs a search query with optional streaming
5
+ */
6
+ search(query: string, options?: Omit<SearchOptions, 'query'>): Promise<SearchResult[]>;
7
+ searchStream(query: string, options?: SearchOptions): AsyncGenerator<SearchResult | SearchError, void, undefined>;
8
+ chat(query: string, options?: SearchOptions): AsyncGenerator<ChatTypes, void, undefined>;
9
+ /**
10
+ * Cancels an active request by ID
11
+ */
12
+ cancelRequest(requestId: string): void;
13
+ /**
14
+ * Cancels all active requests
15
+ */
16
+ cancelAllRequests(): void;
17
+ /**
18
+ * Register an active request
19
+ */
20
+ private registerRequest;
21
+ /**
22
+ * Unregister a completed request
23
+ */
24
+ private unregisterRequest;
25
+ /**
26
+ * Generate unique request ID
27
+ */
28
+ private generateRequestId;
29
+ }
30
+
31
+ /**
32
+ * API error structure
33
+ */
34
+ export declare interface ApiError {
35
+ message: string;
36
+ code?: string;
37
+ status?: number;
38
+ details?: Record<string, unknown>;
39
+ }
40
+
41
+ export declare class ChatBubbleSnippet extends HTMLElement {
42
+ private shadow;
43
+ private client;
44
+ private chatView;
45
+ private container;
46
+ private isExpanded;
47
+ private isMinimized;
48
+ private handleBubbleClick;
49
+ private handleCloseClick;
50
+ private handleMinimizeClick;
51
+ private handleClearClick;
52
+ static get observedAttributes(): readonly ["api-url", "placeholder", "theme", "hide-branding"];
53
+ constructor();
54
+ connectedCallback(): void;
55
+ disconnectedCallback(): void;
56
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
57
+ private getProps;
58
+ private initializeClient;
59
+ private render;
60
+ private getBubbleStyles;
61
+ private getBaseHTML;
62
+ private attachEventListeners;
63
+ private removeEventListeners;
64
+ private toggleChat;
65
+ private closeChat;
66
+ private toggleMinimize;
67
+ private initializeChatView;
68
+ private updateTheme;
69
+ private cleanup;
70
+ clearChat(): void;
71
+ sendMessage(content: string): Promise<void>;
72
+ getMessages(): Message[];
73
+ }
74
+
75
+ declare type ChatError = {
76
+ type: 'error';
77
+ message: string;
78
+ };
79
+
80
+ /**
81
+ * Chat options
82
+ */
83
+ export declare interface ChatOptions {
84
+ stream?: boolean;
85
+ signal?: AbortSignal;
86
+ }
87
+
88
+ export declare class ChatPageSnippet extends HTMLElement {
89
+ private shadow;
90
+ private client;
91
+ private chatView;
92
+ private container;
93
+ private sessions;
94
+ private currentSessionId;
95
+ private sidebarCollapsed;
96
+ private handleClearClick;
97
+ private handleNewChatClick;
98
+ private handleToggleSidebarClick;
99
+ private handleChatListClick;
100
+ private handleMessageEvent;
101
+ static get observedAttributes(): readonly ["api-url", "placeholder", "theme", "hide-branding"];
102
+ constructor();
103
+ connectedCallback(): void;
104
+ disconnectedCallback(): void;
105
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
106
+ private getProps;
107
+ private initializeClient;
108
+ private render;
109
+ private getPageStyles;
110
+ private getBaseHTML;
111
+ private attachEventListeners;
112
+ private removeEventListeners;
113
+ private setupView;
114
+ private generateSessionId;
115
+ private loadSessions;
116
+ private saveSessions;
117
+ private saveCurrentSession;
118
+ private updateSessionTitle;
119
+ private createNewChat;
120
+ private switchToSession;
121
+ private deleteSession;
122
+ private clearCurrentChat;
123
+ private toggleSidebar;
124
+ private onChatListClick;
125
+ private renderChatList;
126
+ private renderChatListItem;
127
+ private formatDate;
128
+ private escapeHTML;
129
+ private updateTheme;
130
+ private cleanup;
131
+ clearChat(): void;
132
+ sendMessage(content: string): Promise<void>;
133
+ getMessages(): Message[];
134
+ getSessions(): ChatSession[];
135
+ getCurrentSession(): ChatSession | null;
136
+ }
137
+
138
+ declare type ChatResult = {
139
+ id: string;
140
+ title: string;
141
+ description: string;
142
+ url?: string;
143
+ metadata?: Record<string, unknown>;
144
+ type: 'result';
145
+ };
146
+
147
+ declare interface ChatSession {
148
+ id: string;
149
+ title: string;
150
+ messages: Message[];
151
+ createdAt: number;
152
+ updatedAt: number;
153
+ }
154
+
155
+ declare type ChatTextResponse = {
156
+ type: 'text';
157
+ message: string;
158
+ };
159
+
160
+ declare type ChatTypes = ChatResult | ChatTextResponse | ChatError;
161
+
162
+ declare class Client {
163
+ activeRequests: Map<string, RequestState>;
164
+ baseUrl: string;
165
+ constructor(baseUrl: string);
166
+ search(_query: string, _options?: SearchOptions): Promise<SearchResult[]>;
167
+ searchStream(_query: string, _options?: SearchOptions): AsyncGenerator<SearchResult | SearchError, void, undefined>;
168
+ chat(_message: string, _options?: SearchOptions): AsyncGenerator<ChatTypes, void, undefined>;
169
+ cancelRequest(_requestId: string): void;
170
+ cancelAllRequests(): void;
171
+ }
172
+
173
+ declare interface Message {
174
+ id: string;
175
+ role: 'user' | 'assistant' | 'system';
176
+ content: string;
177
+ timestamp: number;
178
+ metadata?: Record<string, unknown>;
179
+ }
180
+
181
+ /**
182
+ * Request state
183
+ */
184
+ declare interface RequestState {
185
+ id: string;
186
+ controller: AbortController;
187
+ timestamp: number;
188
+ }
189
+
190
+ /**
191
+ * Search Bar Snippet
192
+ * A search bar with results display
193
+ */
194
+ declare class SearchBarSnippet extends HTMLElement {
195
+ private shadow;
196
+ private client;
197
+ private container;
198
+ private inputElement;
199
+ private resultsContainer;
200
+ private searchButton;
201
+ private isLoading;
202
+ private currentQuery;
203
+ private debouncedSearch;
204
+ private handleInputChange;
205
+ private handleInputKeydownEnter;
206
+ private handleInputKeydownEscape;
207
+ private handleSearchButtonClick;
208
+ static get observedAttributes(): readonly ["api-url", "placeholder", "max-results", "debounce-ms", "theme", "hide-branding"];
209
+ constructor();
210
+ connectedCallback(): void;
211
+ disconnectedCallback(): void;
212
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
213
+ private getProps;
214
+ private initializeClient;
215
+ private render;
216
+ private attachEventListeners;
217
+ private performSearch;
218
+ private displayResults;
219
+ private renderResult;
220
+ private renderResultImage;
221
+ private attachResultHandlers;
222
+ private showLoadingState;
223
+ private showEmptyState;
224
+ private showNoResultsState;
225
+ private showErrorState;
226
+ private updateTheme;
227
+ private cleanup;
228
+ search(query: string): Promise<void>;
229
+ }
230
+ export { SearchBarSnippet }
231
+ export default SearchBarSnippet;
232
+
233
+ declare interface SearchError {
234
+ type: 'error';
235
+ message: string;
236
+ code?: string;
237
+ status?: number;
238
+ details?: Record<string, unknown>;
239
+ }
240
+
241
+ export declare class SearchModalSnippet extends HTMLElement {
242
+ private shadow;
243
+ private client;
244
+ private backdrop;
245
+ private modal;
246
+ private inputElement;
247
+ private resultsContainer;
248
+ private footerCount;
249
+ private isOpen;
250
+ private isLoading;
251
+ private results;
252
+ private activeIndex;
253
+ private debouncedSearch;
254
+ private handleGlobalKeydown;
255
+ private handleInputChange;
256
+ private handleInputKeydown;
257
+ private handleBackdropClick;
258
+ private savedBodyStyles;
259
+ private savedHtmlOverflow;
260
+ static get observedAttributes(): readonly ["api-url", "placeholder", "max-results", "theme", "shortcut", "use-meta-key", "debounce-ms", "hide-branding"];
261
+ constructor();
262
+ connectedCallback(): void;
263
+ disconnectedCallback(): void;
264
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
265
+ private getProps;
266
+ private initializeClient;
267
+ private render;
268
+ private attachGlobalKeyboardShortcut;
269
+ private attachEventListeners;
270
+ private navigateResults;
271
+ private updateActiveResult;
272
+ private selectActiveResult;
273
+ private performSearch;
274
+ private displayResults;
275
+ private renderResult;
276
+ private renderResultImage;
277
+ private attachResultHandlers;
278
+ private renderEmptyState;
279
+ private showEmptyState;
280
+ private showLoadingState;
281
+ private showNoResultsState;
282
+ private showErrorState;
283
+ private updateTheme;
284
+ private lockBodyScroll;
285
+ private unlockBodyScroll;
286
+ private cleanup;
287
+ /**
288
+ * Open the search modal
289
+ */
290
+ open(): void;
291
+ /**
292
+ * Close the search modal
293
+ */
294
+ close(): void;
295
+ /**
296
+ * Toggle the search modal open/closed
297
+ */
298
+ toggle(): void;
299
+ /**
300
+ * Perform a search programmatically
301
+ */
302
+ search(query: string): Promise<void>;
303
+ /**
304
+ * Get current search results
305
+ */
306
+ getResults(): SearchResult[];
307
+ /**
308
+ * Check if modal is currently open
309
+ */
310
+ isModalOpen(): boolean;
311
+ }
312
+
313
+ /**
314
+ * Search options
315
+ */
316
+ export declare interface SearchOptions {
317
+ query?: string;
318
+ streaming?: boolean;
319
+ signal?: AbortSignal;
320
+ maxResults?: number;
321
+ }
322
+
323
+ /**
324
+ * Search result item structure
325
+ */
326
+ export declare interface SearchResult {
327
+ id: string;
328
+ title: string;
329
+ description: string;
330
+ url?: string;
331
+ image?: string;
332
+ metadata?: Record<string, unknown>;
333
+ type: 'result';
334
+ }
335
+
336
+ /**
337
+ * Main component properties
338
+ */
339
+ export declare interface SearchSnippetProps {
340
+ /** Required: AI Search API endpoint */
341
+ apiUrl: string;
342
+ /** Input placeholder text */
343
+ placeholder?: string;
344
+ /** Maximum search results to display (search-bar only) */
345
+ maxResults?: number;
346
+ /** Input debounce delay in milliseconds (search-bar only) */
347
+ debounceMs?: number;
348
+ /** Color scheme */
349
+ theme?: Theme;
350
+ /** Hide the "Powered by Cloudflare AI Search" branding */
351
+ hideBranding?: boolean;
352
+ }
353
+
354
+ /**
355
+ * Core type definitions for the Search Snippet Library
356
+ */
357
+ export declare type Theme = 'light' | 'dark' | 'auto';
358
+
359
+ export { }