@nlweb-ai/search-components 0.1.9
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/LICENSE +21 -0
- package/README.md +200 -0
- package/dist/index.d.mts +317 -0
- package/dist/index.d.ts +317 -0
- package/dist/index.js +1766 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1766 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +91 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
declare const RecipeSchema: z.ZodObject<{
|
|
6
|
+
"@type": z.ZodUnion<readonly [z.ZodLiteral<"Recipe">, z.ZodArray<z.ZodString>]>;
|
|
7
|
+
"@id": z.ZodString;
|
|
8
|
+
score: z.ZodNumber;
|
|
9
|
+
site: z.ZodString;
|
|
10
|
+
name: z.ZodOptional<z.ZodString>;
|
|
11
|
+
recipeIngredient: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodString]>>;
|
|
12
|
+
recipeInstructions: z.ZodOptional<z.ZodAny>;
|
|
13
|
+
recipeYield: z.ZodOptional<z.ZodAny>;
|
|
14
|
+
cookTime: z.ZodOptional<z.ZodString>;
|
|
15
|
+
prepTime: z.ZodOptional<z.ZodString>;
|
|
16
|
+
totalTime: z.ZodOptional<z.ZodString>;
|
|
17
|
+
description: z.ZodOptional<z.ZodString>;
|
|
18
|
+
image: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
19
|
+
"@type": z.ZodOptional<z.ZodLiteral<"ImageObject">>;
|
|
20
|
+
"@id": z.ZodString;
|
|
21
|
+
url: z.ZodOptional<z.ZodString>;
|
|
22
|
+
contentUrl: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, z.core.$loose>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
24
|
+
"@type": z.ZodOptional<z.ZodLiteral<"ImageObject">>;
|
|
25
|
+
"@id": z.ZodString;
|
|
26
|
+
url: z.ZodOptional<z.ZodString>;
|
|
27
|
+
contentUrl: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, z.core.$loose>]>>]>>;
|
|
29
|
+
}, z.core.$loose>;
|
|
30
|
+
type RecipeResult = z.infer<typeof RecipeSchema>;
|
|
31
|
+
declare const ArticleSchema: z.ZodObject<{
|
|
32
|
+
"@type": z.ZodUnion<readonly [z.ZodLiteral<"Article">, z.ZodLiteral<"NewsArticle">, z.ZodLiteral<"BlogPosting">, z.ZodArray<z.ZodString>]>;
|
|
33
|
+
"@id": z.ZodString;
|
|
34
|
+
score: z.ZodNumber;
|
|
35
|
+
site: z.ZodString;
|
|
36
|
+
headline: z.ZodOptional<z.ZodString>;
|
|
37
|
+
description: z.ZodOptional<z.ZodString>;
|
|
38
|
+
image: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
39
|
+
"@type": z.ZodOptional<z.ZodLiteral<"ImageObject">>;
|
|
40
|
+
"@id": z.ZodString;
|
|
41
|
+
url: z.ZodOptional<z.ZodString>;
|
|
42
|
+
contentUrl: z.ZodOptional<z.ZodString>;
|
|
43
|
+
}, z.core.$loose>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
44
|
+
"@type": z.ZodOptional<z.ZodLiteral<"ImageObject">>;
|
|
45
|
+
"@id": z.ZodString;
|
|
46
|
+
url: z.ZodOptional<z.ZodString>;
|
|
47
|
+
contentUrl: z.ZodOptional<z.ZodString>;
|
|
48
|
+
}, z.core.$loose>]>>]>>;
|
|
49
|
+
author: z.ZodOptional<z.ZodAny>;
|
|
50
|
+
publisher: z.ZodOptional<z.ZodAny>;
|
|
51
|
+
datePublished: z.ZodOptional<z.ZodString>;
|
|
52
|
+
dateModified: z.ZodOptional<z.ZodString>;
|
|
53
|
+
thumbnailUrl: z.ZodOptional<z.ZodString>;
|
|
54
|
+
}, z.core.$loose>;
|
|
55
|
+
type ArticleResult = z.infer<typeof ArticleSchema>;
|
|
56
|
+
declare const MovieSchema: z.ZodObject<{
|
|
57
|
+
"@type": z.ZodUnion<readonly [z.ZodLiteral<"Movie">, z.ZodArray<z.ZodString>]>;
|
|
58
|
+
"@id": z.ZodString;
|
|
59
|
+
score: z.ZodNumber;
|
|
60
|
+
site: z.ZodString;
|
|
61
|
+
name: z.ZodOptional<z.ZodString>;
|
|
62
|
+
description: z.ZodOptional<z.ZodString>;
|
|
63
|
+
image: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
64
|
+
"@type": z.ZodOptional<z.ZodLiteral<"ImageObject">>;
|
|
65
|
+
"@id": z.ZodString;
|
|
66
|
+
url: z.ZodOptional<z.ZodString>;
|
|
67
|
+
contentUrl: z.ZodOptional<z.ZodString>;
|
|
68
|
+
}, z.core.$loose>, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
69
|
+
"@type": z.ZodOptional<z.ZodLiteral<"ImageObject">>;
|
|
70
|
+
"@id": z.ZodString;
|
|
71
|
+
url: z.ZodOptional<z.ZodString>;
|
|
72
|
+
contentUrl: z.ZodOptional<z.ZodString>;
|
|
73
|
+
}, z.core.$loose>]>>]>>;
|
|
74
|
+
url: z.ZodOptional<z.ZodString>;
|
|
75
|
+
genre: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
76
|
+
datePublished: z.ZodOptional<z.ZodString>;
|
|
77
|
+
director: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
78
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Person">>;
|
|
79
|
+
name: z.ZodString;
|
|
80
|
+
url: z.ZodOptional<z.ZodString>;
|
|
81
|
+
}, z.core.$loose>, z.ZodArray<z.ZodObject<{
|
|
82
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Person">>;
|
|
83
|
+
name: z.ZodString;
|
|
84
|
+
url: z.ZodOptional<z.ZodString>;
|
|
85
|
+
}, z.core.$loose>>]>>;
|
|
86
|
+
actor: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
87
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Person">>;
|
|
88
|
+
name: z.ZodString;
|
|
89
|
+
url: z.ZodOptional<z.ZodString>;
|
|
90
|
+
}, z.core.$loose>, z.ZodArray<z.ZodObject<{
|
|
91
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Person">>;
|
|
92
|
+
name: z.ZodString;
|
|
93
|
+
url: z.ZodOptional<z.ZodString>;
|
|
94
|
+
}, z.core.$loose>>]>>;
|
|
95
|
+
aggregateRating: z.ZodOptional<z.ZodObject<{
|
|
96
|
+
"@type": z.ZodOptional<z.ZodLiteral<"AggregateRating">>;
|
|
97
|
+
ratingValue: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
98
|
+
bestRating: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
99
|
+
worstRating: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
100
|
+
ratingCount: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
101
|
+
reviewCount: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
102
|
+
}, z.core.$loose>>;
|
|
103
|
+
duration: z.ZodOptional<z.ZodString>;
|
|
104
|
+
contentRating: z.ZodOptional<z.ZodString>;
|
|
105
|
+
productionCompany: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
106
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Organization">>;
|
|
107
|
+
name: z.ZodString;
|
|
108
|
+
url: z.ZodOptional<z.ZodString>;
|
|
109
|
+
}, z.core.$loose>, z.ZodArray<z.ZodObject<{
|
|
110
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Organization">>;
|
|
111
|
+
name: z.ZodString;
|
|
112
|
+
url: z.ZodOptional<z.ZodString>;
|
|
113
|
+
}, z.core.$loose>>]>>;
|
|
114
|
+
trailer: z.ZodOptional<z.ZodObject<{
|
|
115
|
+
"@type": z.ZodOptional<z.ZodLiteral<"VideoObject">>;
|
|
116
|
+
name: z.ZodOptional<z.ZodString>;
|
|
117
|
+
description: z.ZodOptional<z.ZodString>;
|
|
118
|
+
thumbnailUrl: z.ZodOptional<z.ZodString>;
|
|
119
|
+
uploadDate: z.ZodOptional<z.ZodString>;
|
|
120
|
+
contentUrl: z.ZodOptional<z.ZodString>;
|
|
121
|
+
embedUrl: z.ZodOptional<z.ZodString>;
|
|
122
|
+
duration: z.ZodOptional<z.ZodString>;
|
|
123
|
+
}, z.core.$loose>>;
|
|
124
|
+
review: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
125
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Review">>;
|
|
126
|
+
datePublished: z.ZodOptional<z.ZodString>;
|
|
127
|
+
reviewBody: z.ZodOptional<z.ZodString>;
|
|
128
|
+
reviewRating: z.ZodOptional<z.ZodObject<{
|
|
129
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Rating">>;
|
|
130
|
+
ratingValue: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
131
|
+
bestRating: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
132
|
+
worstRating: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
133
|
+
}, z.core.$loose>>;
|
|
134
|
+
author: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
135
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Person">>;
|
|
136
|
+
name: z.ZodString;
|
|
137
|
+
url: z.ZodOptional<z.ZodString>;
|
|
138
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
139
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Organization">>;
|
|
140
|
+
name: z.ZodString;
|
|
141
|
+
url: z.ZodOptional<z.ZodString>;
|
|
142
|
+
}, z.core.$loose>, z.ZodString]>>;
|
|
143
|
+
}, z.core.$loose>, z.ZodArray<z.ZodObject<{
|
|
144
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Review">>;
|
|
145
|
+
datePublished: z.ZodOptional<z.ZodString>;
|
|
146
|
+
reviewBody: z.ZodOptional<z.ZodString>;
|
|
147
|
+
reviewRating: z.ZodOptional<z.ZodObject<{
|
|
148
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Rating">>;
|
|
149
|
+
ratingValue: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
150
|
+
bestRating: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
151
|
+
worstRating: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
152
|
+
}, z.core.$loose>>;
|
|
153
|
+
author: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
154
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Person">>;
|
|
155
|
+
name: z.ZodString;
|
|
156
|
+
url: z.ZodOptional<z.ZodString>;
|
|
157
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
158
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Organization">>;
|
|
159
|
+
name: z.ZodString;
|
|
160
|
+
url: z.ZodOptional<z.ZodString>;
|
|
161
|
+
}, z.core.$loose>, z.ZodString]>>;
|
|
162
|
+
}, z.core.$loose>>]>>;
|
|
163
|
+
sameAs: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
164
|
+
countryOfOrigin: z.ZodOptional<z.ZodAny>;
|
|
165
|
+
musicBy: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
166
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Person">>;
|
|
167
|
+
name: z.ZodString;
|
|
168
|
+
url: z.ZodOptional<z.ZodString>;
|
|
169
|
+
}, z.core.$loose>, z.ZodArray<z.ZodObject<{
|
|
170
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Person">>;
|
|
171
|
+
name: z.ZodString;
|
|
172
|
+
url: z.ZodOptional<z.ZodString>;
|
|
173
|
+
}, z.core.$loose>>]>>;
|
|
174
|
+
producer: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
|
|
175
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Person">>;
|
|
176
|
+
name: z.ZodString;
|
|
177
|
+
url: z.ZodOptional<z.ZodString>;
|
|
178
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
179
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Organization">>;
|
|
180
|
+
name: z.ZodString;
|
|
181
|
+
url: z.ZodOptional<z.ZodString>;
|
|
182
|
+
}, z.core.$loose>, z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
183
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Person">>;
|
|
184
|
+
name: z.ZodString;
|
|
185
|
+
url: z.ZodOptional<z.ZodString>;
|
|
186
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
187
|
+
"@type": z.ZodOptional<z.ZodLiteral<"Organization">>;
|
|
188
|
+
name: z.ZodString;
|
|
189
|
+
url: z.ZodOptional<z.ZodString>;
|
|
190
|
+
}, z.core.$loose>]>>]>>;
|
|
191
|
+
}, z.core.$loose>;
|
|
192
|
+
type MovieResult = z.infer<typeof MovieSchema>;
|
|
193
|
+
type NlwebResult = RecipeResult | ArticleResult | MovieResult;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Search state
|
|
197
|
+
*/
|
|
198
|
+
interface NLWebSearchState {
|
|
199
|
+
results: NlwebResult[];
|
|
200
|
+
resultOffset?: number;
|
|
201
|
+
streamingIndex: number;
|
|
202
|
+
summary?: string;
|
|
203
|
+
decontextualizedQuery?: string;
|
|
204
|
+
query: string | null;
|
|
205
|
+
loading: boolean;
|
|
206
|
+
error: string | null;
|
|
207
|
+
rawLogs?: object[];
|
|
208
|
+
}
|
|
209
|
+
interface NLWeb extends NLWebSearchState {
|
|
210
|
+
search: (params: NLWebSearchParams) => Promise<SearchResponse>;
|
|
211
|
+
cancelSearch: () => void;
|
|
212
|
+
clearResults: () => void;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Search request parameters
|
|
216
|
+
*/
|
|
217
|
+
interface NLWebSearchParams {
|
|
218
|
+
query: string;
|
|
219
|
+
mode?: "list" | "list,summarize";
|
|
220
|
+
userId?: string;
|
|
221
|
+
remember?: boolean;
|
|
222
|
+
conversationHistory?: string[];
|
|
223
|
+
resultOffset?: number;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Hook configuration
|
|
227
|
+
*/
|
|
228
|
+
interface UseNlWebConfig {
|
|
229
|
+
endpoint: string;
|
|
230
|
+
site: string;
|
|
231
|
+
maxResults?: number;
|
|
232
|
+
numRetrievalResults?: number;
|
|
233
|
+
}
|
|
234
|
+
interface SearchResponse {
|
|
235
|
+
results: NlwebResult[];
|
|
236
|
+
decontextualizedQuery?: string;
|
|
237
|
+
summary?: string;
|
|
238
|
+
rawLogs?: object[];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Custom hook for NLWeb search with SSE streaming support
|
|
242
|
+
*
|
|
243
|
+
* @param config - Hook configuration including endpoint URL
|
|
244
|
+
* @returns Search state and search function
|
|
245
|
+
*/
|
|
246
|
+
declare function useNlWeb(config: UseNlWebConfig): NLWeb;
|
|
247
|
+
|
|
248
|
+
interface QueryResultSet {
|
|
249
|
+
id?: string;
|
|
250
|
+
sessionId: string;
|
|
251
|
+
query: string;
|
|
252
|
+
response: SearchResponse;
|
|
253
|
+
}
|
|
254
|
+
interface Backend {
|
|
255
|
+
site: string;
|
|
256
|
+
endpoint: string;
|
|
257
|
+
}
|
|
258
|
+
interface SearchSession {
|
|
259
|
+
query: string;
|
|
260
|
+
sessionId: string;
|
|
261
|
+
backend: Backend;
|
|
262
|
+
updated: Date;
|
|
263
|
+
created: Date;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
declare function useSearchSessions(): {
|
|
267
|
+
sessions: SearchSession[];
|
|
268
|
+
startSession: (sessionId: string, query: string, backend: Backend) => Promise<void>;
|
|
269
|
+
deleteSession: (sessionId: string) => Promise<void>;
|
|
270
|
+
};
|
|
271
|
+
interface SearchSessionManager {
|
|
272
|
+
searches: QueryResultSet[];
|
|
273
|
+
addSearch: (data: QueryResultSet) => Promise<void>;
|
|
274
|
+
addResults: (id: string, results: NlwebResult[]) => Promise<void>;
|
|
275
|
+
}
|
|
276
|
+
declare function useSearchSession(sessionId: string | null): SearchSessionManager;
|
|
277
|
+
|
|
278
|
+
declare function ChatSearch({ searches, addSearch, addResults, startSession, endSession, nlweb, config, children, sidebar, sessionId, }: {
|
|
279
|
+
sessionId?: string;
|
|
280
|
+
searches: QueryResultSet[];
|
|
281
|
+
addSearch: (r: QueryResultSet) => Promise<void> | void;
|
|
282
|
+
addResults: (id: string, results: NlwebResult[]) => Promise<void>;
|
|
283
|
+
startSession: (query: string) => Promise<string> | void;
|
|
284
|
+
endSession: () => void;
|
|
285
|
+
nlweb: NLWeb;
|
|
286
|
+
config: UseNlWebConfig;
|
|
287
|
+
children?: ReactNode;
|
|
288
|
+
sidebar?: ReactNode;
|
|
289
|
+
}): react_jsx_runtime.JSX.Element;
|
|
290
|
+
|
|
291
|
+
declare function HistorySidebar({ selected, sessions, onSelect, onDelete, onCreate, }: {
|
|
292
|
+
selected?: string;
|
|
293
|
+
sessions: SearchSession[];
|
|
294
|
+
onSelect: (session: SearchSession) => void;
|
|
295
|
+
onDelete: (sessionId: string) => void;
|
|
296
|
+
onCreate: () => void;
|
|
297
|
+
}): react_jsx_runtime.JSX.Element;
|
|
298
|
+
|
|
299
|
+
declare function DebugTool({ searches, streamingState, config, }: {
|
|
300
|
+
searches: QueryResultSet[];
|
|
301
|
+
streamingState: NLWebSearchState;
|
|
302
|
+
config: UseNlWebConfig;
|
|
303
|
+
}): react_jsx_runtime.JSX.Element;
|
|
304
|
+
|
|
305
|
+
interface Site {
|
|
306
|
+
featured?: boolean;
|
|
307
|
+
url: string;
|
|
308
|
+
}
|
|
309
|
+
interface SiteDropdownProps {
|
|
310
|
+
sites: Site[];
|
|
311
|
+
selected: Site;
|
|
312
|
+
onSelect: (url: string | null) => void;
|
|
313
|
+
placeholder?: string;
|
|
314
|
+
}
|
|
315
|
+
declare function SiteDropdown({ sites, selected, onSelect, placeholder, }: SiteDropdownProps): react_jsx_runtime.JSX.Element;
|
|
316
|
+
|
|
317
|
+
export { ChatSearch, DebugTool, HistorySidebar, type QueryResultSet, type SearchSession, type Site, SiteDropdown, useNlWeb, useSearchSession, useSearchSessions };
|