@librechat/agents 2.4.30 → 2.4.33

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.
Files changed (124) hide show
  1. package/dist/cjs/common/enum.cjs +1 -0
  2. package/dist/cjs/common/enum.cjs.map +1 -1
  3. package/dist/cjs/events.cjs +3 -3
  4. package/dist/cjs/events.cjs.map +1 -1
  5. package/dist/cjs/graphs/Graph.cjs +2 -1
  6. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  7. package/dist/cjs/main.cjs +7 -2
  8. package/dist/cjs/main.cjs.map +1 -1
  9. package/dist/cjs/messages/ids.cjs +23 -0
  10. package/dist/cjs/messages/ids.cjs.map +1 -0
  11. package/dist/cjs/splitStream.cjs +2 -1
  12. package/dist/cjs/splitStream.cjs.map +1 -1
  13. package/dist/cjs/stream.cjs +87 -154
  14. package/dist/cjs/stream.cjs.map +1 -1
  15. package/dist/cjs/tools/ToolNode.cjs +14 -3
  16. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  17. package/dist/cjs/tools/handlers.cjs +144 -0
  18. package/dist/cjs/tools/handlers.cjs.map +1 -0
  19. package/dist/cjs/tools/search/content.cjs +140 -0
  20. package/dist/cjs/tools/search/content.cjs.map +1 -0
  21. package/dist/cjs/tools/search/firecrawl.cjs +131 -0
  22. package/dist/cjs/tools/search/firecrawl.cjs.map +1 -0
  23. package/dist/cjs/tools/search/format.cjs +203 -0
  24. package/dist/cjs/tools/search/format.cjs.map +1 -0
  25. package/dist/cjs/tools/search/highlights.cjs +245 -0
  26. package/dist/cjs/tools/search/highlights.cjs.map +1 -0
  27. package/dist/cjs/tools/search/rerankers.cjs +194 -0
  28. package/dist/cjs/tools/search/rerankers.cjs.map +1 -0
  29. package/dist/cjs/tools/search/schema.cjs +70 -0
  30. package/dist/cjs/tools/search/schema.cjs.map +1 -0
  31. package/dist/cjs/tools/search/search.cjs +491 -0
  32. package/dist/cjs/tools/search/search.cjs.map +1 -0
  33. package/dist/cjs/tools/search/tool.cjs +292 -0
  34. package/dist/cjs/tools/search/tool.cjs.map +1 -0
  35. package/dist/cjs/tools/search/utils.cjs +66 -0
  36. package/dist/cjs/tools/search/utils.cjs.map +1 -0
  37. package/dist/esm/common/enum.mjs +1 -0
  38. package/dist/esm/common/enum.mjs.map +1 -1
  39. package/dist/esm/events.mjs +1 -1
  40. package/dist/esm/events.mjs.map +1 -1
  41. package/dist/esm/graphs/Graph.mjs +2 -1
  42. package/dist/esm/graphs/Graph.mjs.map +1 -1
  43. package/dist/esm/main.mjs +4 -1
  44. package/dist/esm/main.mjs.map +1 -1
  45. package/dist/esm/messages/ids.mjs +21 -0
  46. package/dist/esm/messages/ids.mjs.map +1 -0
  47. package/dist/esm/splitStream.mjs +2 -1
  48. package/dist/esm/splitStream.mjs.map +1 -1
  49. package/dist/esm/stream.mjs +87 -152
  50. package/dist/esm/stream.mjs.map +1 -1
  51. package/dist/esm/tools/ToolNode.mjs +14 -3
  52. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  53. package/dist/esm/tools/handlers.mjs +141 -0
  54. package/dist/esm/tools/handlers.mjs.map +1 -0
  55. package/dist/esm/tools/search/content.mjs +119 -0
  56. package/dist/esm/tools/search/content.mjs.map +1 -0
  57. package/dist/esm/tools/search/firecrawl.mjs +128 -0
  58. package/dist/esm/tools/search/firecrawl.mjs.map +1 -0
  59. package/dist/esm/tools/search/format.mjs +201 -0
  60. package/dist/esm/tools/search/format.mjs.map +1 -0
  61. package/dist/esm/tools/search/highlights.mjs +243 -0
  62. package/dist/esm/tools/search/highlights.mjs.map +1 -0
  63. package/dist/esm/tools/search/rerankers.mjs +188 -0
  64. package/dist/esm/tools/search/rerankers.mjs.map +1 -0
  65. package/dist/esm/tools/search/schema.mjs +61 -0
  66. package/dist/esm/tools/search/schema.mjs.map +1 -0
  67. package/dist/esm/tools/search/search.mjs +488 -0
  68. package/dist/esm/tools/search/search.mjs.map +1 -0
  69. package/dist/esm/tools/search/tool.mjs +290 -0
  70. package/dist/esm/tools/search/tool.mjs.map +1 -0
  71. package/dist/esm/tools/search/utils.mjs +61 -0
  72. package/dist/esm/tools/search/utils.mjs.map +1 -0
  73. package/dist/types/common/enum.d.ts +1 -0
  74. package/dist/types/graphs/Graph.d.ts +1 -1
  75. package/dist/types/index.d.ts +2 -0
  76. package/dist/types/messages/ids.d.ts +3 -0
  77. package/dist/types/messages/index.d.ts +1 -0
  78. package/dist/types/scripts/search.d.ts +1 -0
  79. package/dist/types/stream.d.ts +0 -8
  80. package/dist/types/tools/ToolNode.d.ts +6 -0
  81. package/dist/types/tools/example.d.ts +23 -3
  82. package/dist/types/tools/handlers.d.ts +8 -0
  83. package/dist/types/tools/search/content.d.ts +4 -0
  84. package/dist/types/tools/search/firecrawl.d.ts +38 -0
  85. package/dist/types/tools/search/format.d.ts +5 -0
  86. package/dist/types/tools/search/highlights.d.ts +13 -0
  87. package/dist/types/tools/search/index.d.ts +2 -0
  88. package/dist/types/tools/search/rerankers.d.ts +36 -0
  89. package/dist/types/tools/search/schema.d.ts +16 -0
  90. package/dist/types/tools/search/search.d.ts +9 -0
  91. package/dist/types/tools/search/test.d.ts +1 -0
  92. package/dist/types/tools/search/tool.d.ts +33 -0
  93. package/dist/types/tools/search/types.d.ts +540 -0
  94. package/dist/types/tools/search/utils.d.ts +10 -0
  95. package/package.json +10 -7
  96. package/src/common/enum.ts +1 -0
  97. package/src/events.ts +49 -15
  98. package/src/graphs/Graph.ts +6 -2
  99. package/src/index.ts +2 -0
  100. package/src/messages/ids.ts +26 -0
  101. package/src/messages/index.ts +1 -0
  102. package/src/scripts/search.ts +146 -0
  103. package/src/splitStream.test.ts +132 -71
  104. package/src/splitStream.ts +2 -1
  105. package/src/stream.ts +94 -183
  106. package/src/tools/ToolNode.ts +37 -14
  107. package/src/tools/handlers.ts +167 -0
  108. package/src/tools/search/content.test.ts +173 -0
  109. package/src/tools/search/content.ts +147 -0
  110. package/src/tools/search/firecrawl.ts +158 -0
  111. package/src/tools/search/format.ts +252 -0
  112. package/src/tools/search/highlights.ts +320 -0
  113. package/src/tools/search/index.ts +2 -0
  114. package/src/tools/search/output.md +2775 -0
  115. package/src/tools/search/rerankers.ts +269 -0
  116. package/src/tools/search/schema.ts +63 -0
  117. package/src/tools/search/search.ts +680 -0
  118. package/src/tools/search/test.html +884 -0
  119. package/src/tools/search/test.md +643 -0
  120. package/src/tools/search/test.ts +159 -0
  121. package/src/tools/search/tool.ts +427 -0
  122. package/src/tools/search/types.ts +621 -0
  123. package/src/tools/search/utils.ts +79 -0
  124. package/src/utils/llmConfig.ts +1 -1
@@ -0,0 +1,621 @@
1
+ import { z } from 'zod';
2
+ import type { Logger as WinstonLogger } from 'winston';
3
+ import type { RunnableConfig } from '@langchain/core/runnables';
4
+ import type { BaseReranker } from './rerankers';
5
+ import { DATE_RANGE } from './schema';
6
+
7
+ export type SearchProvider = 'serper' | 'searxng';
8
+ export type RerankerType = 'infinity' | 'jina' | 'cohere' | 'none';
9
+
10
+ export interface Highlight {
11
+ score: number;
12
+ text: string;
13
+ references?: UsedReferences;
14
+ }
15
+
16
+ export type ProcessedSource = {
17
+ content?: string;
18
+ attribution?: string;
19
+ references?: References;
20
+ highlights?: Highlight[];
21
+ processed?: boolean;
22
+ };
23
+
24
+ export type ProcessedOrganic = OrganicResult & ProcessedSource;
25
+ export type ProcessedTopStory = TopStoryResult & ProcessedSource;
26
+ export type ValidSource = ProcessedOrganic | ProcessedTopStory;
27
+
28
+ export type ResultReference = {
29
+ link: string;
30
+ type: 'link' | 'image' | 'video';
31
+ title?: string;
32
+ attribution?: string;
33
+ };
34
+ export interface SearchResultData {
35
+ turn?: number;
36
+ organic?: ProcessedOrganic[];
37
+ topStories?: ProcessedTopStory[];
38
+ images?: ImageResult[];
39
+ videos?: VideoResult[];
40
+ places?: PlaceResult[];
41
+ news?: NewsResult[];
42
+ shopping?: ShoppingResult[];
43
+ knowledgeGraph?: KnowledgeGraphResult;
44
+ answerBox?: AnswerBoxResult;
45
+ peopleAlsoAsk?: PeopleAlsoAskResult[];
46
+ relatedSearches?: Array<{ query: string }>;
47
+ references?: ResultReference[];
48
+ error?: string;
49
+ }
50
+
51
+ export interface SearchResult {
52
+ data?: SearchResultData;
53
+ error?: string;
54
+ success: boolean;
55
+ }
56
+
57
+ export interface Source {
58
+ link: string;
59
+ html?: string;
60
+ title?: string;
61
+ snippet?: string;
62
+ date?: string;
63
+ }
64
+
65
+ export interface SearchConfig {
66
+ searchProvider?: SearchProvider;
67
+ serperApiKey?: string;
68
+ searxngInstanceUrl?: string;
69
+ searxngApiKey?: string;
70
+ }
71
+
72
+ export type References = {
73
+ links: MediaReference[];
74
+ images: MediaReference[];
75
+ videos: MediaReference[];
76
+ };
77
+ export interface ScrapeResult {
78
+ url: string;
79
+ error?: boolean;
80
+ content: string;
81
+ attribution?: string;
82
+ references?: References;
83
+ highlights?: Highlight[];
84
+ }
85
+
86
+ export interface ProcessSourcesConfig {
87
+ topResults?: number;
88
+ strategies?: string[];
89
+ filterContent?: boolean;
90
+ reranker?: BaseReranker;
91
+ logger?: Logger;
92
+ }
93
+
94
+ export interface FirecrawlConfig {
95
+ firecrawlApiKey?: string;
96
+ firecrawlApiUrl?: string;
97
+ firecrawlFormats?: string[];
98
+ }
99
+
100
+ export interface ScraperContentResult {
101
+ content: string;
102
+ }
103
+
104
+ export interface ScraperExtractionResult {
105
+ no_extraction: ScraperContentResult;
106
+ }
107
+
108
+ export interface JinaRerankerResult {
109
+ index: number;
110
+ relevance_score: number;
111
+ document?: string | { text: string };
112
+ }
113
+
114
+ export interface JinaRerankerResponse {
115
+ model: string;
116
+ usage: {
117
+ total_tokens: number;
118
+ };
119
+ results: JinaRerankerResult[];
120
+ }
121
+
122
+ export interface CohereRerankerResult {
123
+ index: number;
124
+ relevance_score: number;
125
+ }
126
+
127
+ export interface CohereRerankerResponse {
128
+ results: CohereRerankerResult[];
129
+ id: string;
130
+ meta: {
131
+ api_version: {
132
+ version: string;
133
+ is_experimental: boolean;
134
+ };
135
+ billed_units: {
136
+ search_units: number;
137
+ };
138
+ };
139
+ }
140
+
141
+ export type SafeSearchLevel = 0 | 1 | 2;
142
+
143
+ export type Logger = WinstonLogger;
144
+ export interface SearchToolConfig
145
+ extends SearchConfig,
146
+ ProcessSourcesConfig,
147
+ FirecrawlConfig {
148
+ logger?: Logger;
149
+ safeSearch?: SafeSearchLevel;
150
+ jinaApiKey?: string;
151
+ cohereApiKey?: string;
152
+ rerankerType?: RerankerType;
153
+ onSearchResults?: (
154
+ results: SearchResult,
155
+ runnableConfig?: RunnableConfig
156
+ ) => void;
157
+ onGetHighlights?: (link: string) => void;
158
+ }
159
+ export interface MediaReference {
160
+ originalUrl: string;
161
+ title?: string;
162
+ text?: string;
163
+ }
164
+
165
+ export type UsedReferences = {
166
+ type: 'link' | 'image' | 'video';
167
+ originalIndex: number;
168
+ reference: MediaReference;
169
+ }[];
170
+
171
+ /** Firecrawl */
172
+
173
+ export interface FirecrawlScrapeOptions {
174
+ formats?: string[];
175
+ includeTags?: string[];
176
+ excludeTags?: string[];
177
+ headers?: Record<string, string>;
178
+ waitFor?: number;
179
+ timeout?: number;
180
+ }
181
+
182
+ export interface ScrapeMetadata {
183
+ // Core source information
184
+ sourceURL?: string;
185
+ url?: string;
186
+ scrapeId?: string;
187
+ statusCode?: number;
188
+ // Basic metadata
189
+ title?: string;
190
+ description?: string;
191
+ language?: string;
192
+ favicon?: string;
193
+ viewport?: string;
194
+ robots?: string;
195
+ 'theme-color'?: string;
196
+ // Open Graph metadata
197
+ 'og:url'?: string;
198
+ 'og:title'?: string;
199
+ 'og:description'?: string;
200
+ 'og:type'?: string;
201
+ 'og:image'?: string;
202
+ 'og:image:width'?: string;
203
+ 'og:image:height'?: string;
204
+ 'og:site_name'?: string;
205
+ ogUrl?: string;
206
+ ogTitle?: string;
207
+ ogDescription?: string;
208
+ ogImage?: string;
209
+ ogSiteName?: string;
210
+ // Article metadata
211
+ 'article:author'?: string;
212
+ 'article:published_time'?: string;
213
+ 'article:modified_time'?: string;
214
+ 'article:section'?: string;
215
+ 'article:tag'?: string;
216
+ 'article:publisher'?: string;
217
+ publishedTime?: string;
218
+ modifiedTime?: string;
219
+ // Twitter metadata
220
+ 'twitter:site'?: string | boolean | number | null;
221
+ 'twitter:creator'?: string;
222
+ 'twitter:card'?: string;
223
+ 'twitter:image'?: string;
224
+ 'twitter:dnt'?: string;
225
+ 'twitter:app:name:iphone'?: string;
226
+ 'twitter:app:id:iphone'?: string;
227
+ 'twitter:app:url:iphone'?: string;
228
+ 'twitter:app:name:ipad'?: string;
229
+ 'twitter:app:id:ipad'?: string;
230
+ 'twitter:app:url:ipad'?: string;
231
+ 'twitter:app:name:googleplay'?: string;
232
+ 'twitter:app:id:googleplay'?: string;
233
+ 'twitter:app:url:googleplay'?: string;
234
+ // Facebook metadata
235
+ 'fb:app_id'?: string;
236
+ // App links
237
+ 'al:ios:url'?: string;
238
+ 'al:ios:app_name'?: string;
239
+ 'al:ios:app_store_id'?: string;
240
+ // Allow for additional properties that might be present
241
+ [key: string]: string | number | boolean | null | undefined;
242
+ }
243
+
244
+ export interface FirecrawlScrapeResponse {
245
+ success: boolean;
246
+ data?: {
247
+ markdown?: string;
248
+ html?: string;
249
+ rawHtml?: string;
250
+ screenshot?: string;
251
+ links?: string[];
252
+ metadata?: ScrapeMetadata;
253
+ };
254
+ error?: string;
255
+ }
256
+
257
+ export interface FirecrawlScraperConfig {
258
+ apiKey?: string;
259
+ apiUrl?: string;
260
+ formats?: string[];
261
+ timeout?: number;
262
+ logger?: Logger;
263
+ }
264
+
265
+ export type GetSourcesParams = {
266
+ query: string;
267
+ date?: DATE_RANGE;
268
+ country?: string;
269
+ numResults?: number;
270
+ safeSearch?: SearchToolConfig['safeSearch'];
271
+ images?: boolean;
272
+ videos?: boolean;
273
+ news?: boolean;
274
+ type?: 'search' | 'images' | 'videos' | 'news';
275
+ };
276
+
277
+ /** Serper API */
278
+ export interface VideoResult {
279
+ title?: string;
280
+ link?: string;
281
+ snippet?: string;
282
+ imageUrl?: string;
283
+ duration?: string;
284
+ source?: string;
285
+ channel?: string;
286
+ date?: string;
287
+ position?: number;
288
+ }
289
+
290
+ export interface PlaceResult {
291
+ position?: number;
292
+ name?: string;
293
+ address?: string;
294
+ latitude?: number;
295
+ longitude?: number;
296
+ rating?: number;
297
+ ratingCount?: number;
298
+ category?: string;
299
+ identifier?: string;
300
+ }
301
+
302
+ export interface NewsResult {
303
+ title?: string;
304
+ link?: string;
305
+ snippet?: string;
306
+ date?: string;
307
+ source?: string;
308
+ imageUrl?: string;
309
+ position?: number;
310
+ }
311
+
312
+ export interface ShoppingResult {
313
+ title?: string;
314
+ source?: string;
315
+ link?: string;
316
+ price?: string;
317
+ delivery?: string;
318
+ imageUrl?: string;
319
+ rating?: number;
320
+ ratingCount?: number;
321
+ offers?: string;
322
+ productId?: string;
323
+ position?: number;
324
+ }
325
+
326
+ export interface ScholarResult {
327
+ title?: string;
328
+ link?: string;
329
+ publicationInfo?: string;
330
+ snippet?: string;
331
+ year?: number;
332
+ citedBy?: number;
333
+ }
334
+
335
+ export interface ImageResult {
336
+ title?: string;
337
+ imageUrl?: string;
338
+ imageWidth?: number;
339
+ imageHeight?: number;
340
+ thumbnailUrl?: string;
341
+ thumbnailWidth?: number;
342
+ thumbnailHeight?: number;
343
+ source?: string;
344
+ domain?: string;
345
+ link?: string;
346
+ googleUrl?: string;
347
+ position?: number;
348
+ }
349
+
350
+ export interface SerperSearchPayload extends SerperSearchInput {
351
+ /**
352
+ * Search type/vertical
353
+ * Options: "search" (web), "images", "news", "places", "videos"
354
+ */
355
+ type?: 'search' | 'images' | 'news' | 'places' | 'videos';
356
+
357
+ /**
358
+ * Starting index for search results pagination (used instead of page)
359
+ */
360
+ start?: number;
361
+
362
+ /**
363
+ * Filtering for safe search
364
+ * Options: "off", "moderate", "active"
365
+ */
366
+ safe?: 'off' | 'moderate' | 'active';
367
+ }
368
+
369
+ export type SerperSearchParameters = Pick<SerperSearchPayload, 'q' | 'type'> & {
370
+ engine: 'google';
371
+ };
372
+
373
+ export interface OrganicResult {
374
+ position?: number;
375
+ title?: string;
376
+ link: string;
377
+ snippet?: string;
378
+ date?: string;
379
+ sitelinks?: Array<{
380
+ title: string;
381
+ link: string;
382
+ }>;
383
+ }
384
+
385
+ export interface TopStoryResult {
386
+ title?: string;
387
+ link: string;
388
+ source?: string;
389
+ date?: string;
390
+ imageUrl?: string;
391
+ }
392
+ export interface KnowledgeGraphResult {
393
+ title?: string;
394
+ type?: string;
395
+ imageUrl?: string;
396
+ description?: string;
397
+ descriptionSource?: string;
398
+ descriptionLink?: string;
399
+ attributes?: Record<string, string>;
400
+ website?: string;
401
+ }
402
+
403
+ export interface AnswerBoxResult {
404
+ title?: string;
405
+ snippet?: string;
406
+ snippetHighlighted?: string[];
407
+ link?: string;
408
+ date?: string;
409
+ }
410
+
411
+ export interface PeopleAlsoAskResult {
412
+ question?: string;
413
+ snippet?: string;
414
+ title?: string;
415
+ link?: string;
416
+ }
417
+
418
+ export type RelatedSearches = Array<{ query: string }>;
419
+
420
+ export interface SerperSearchInput {
421
+ /**
422
+ * The search query string
423
+ */
424
+ q: string;
425
+
426
+ /**
427
+ * Country code for localized results
428
+ * Examples: "us", "uk", "ca", "de", etc.
429
+ */
430
+ gl?: string;
431
+
432
+ /**
433
+ * Interface language
434
+ * Examples: "en", "fr", "de", etc.
435
+ */
436
+ hl?: string;
437
+
438
+ /**
439
+ * Number of results to return (up to 100)
440
+ */
441
+ num?: number;
442
+ /**
443
+ * Specific location for contextual results
444
+ * Example: "New York, NY"
445
+ */
446
+ location?: string;
447
+
448
+ /**
449
+ * Search autocorrection setting
450
+ */
451
+ autocorrect?: boolean;
452
+ page?: number;
453
+ /**
454
+ * Date range for search results
455
+ * Options: "h" (past hour), "d" (past 24 hours), "w" (past week),
456
+ * "m" (past month), "y" (past year)
457
+ * `qdr:${DATE_RANGE}`
458
+ */
459
+ tbs?: string;
460
+ }
461
+
462
+ export type SerperResultData = {
463
+ searchParameters: SerperSearchPayload;
464
+ organic?: OrganicResult[];
465
+ topStories?: TopStoryResult[];
466
+ images?: ImageResult[];
467
+ videos?: VideoResult[];
468
+ places?: PlaceResult[];
469
+ news?: NewsResult[];
470
+ shopping?: ShoppingResult[];
471
+ peopleAlsoAsk?: PeopleAlsoAskResult[];
472
+ relatedSearches?: RelatedSearches;
473
+ knowledgeGraph?: KnowledgeGraphResult;
474
+ answerBox?: AnswerBoxResult;
475
+ credits?: number;
476
+ };
477
+
478
+ /** SearXNG */
479
+
480
+ export interface SearxNGSearchPayload {
481
+ /**
482
+ * The search query string
483
+ * Supports syntax specific to different search engines
484
+ * Example: "site:github.com SearXNG"
485
+ */
486
+ q: string;
487
+
488
+ /**
489
+ * Comma-separated list of search categories
490
+ * Example: "general,images,news"
491
+ */
492
+ categories?: string;
493
+
494
+ /**
495
+ * Comma-separated list of search engines to use
496
+ * Example: "google,bing,duckduckgo"
497
+ */
498
+ engines?: string;
499
+
500
+ /**
501
+ * Code of the language for search results
502
+ * Example: "en", "fr", "de", "es"
503
+ */
504
+ language?: string;
505
+
506
+ /**
507
+ * Search page number
508
+ * Default: 1
509
+ */
510
+ pageno?: number;
511
+
512
+ /**
513
+ * Time range filter for search results
514
+ * Options: "day", "month", "year"
515
+ */
516
+ time_range?: 'day' | 'month' | 'year';
517
+
518
+ /**
519
+ * Output format of results
520
+ * Options: "json", "csv", "rss"
521
+ */
522
+ format?: 'json' | 'csv' | 'rss';
523
+
524
+ /**
525
+ * Open search results on new tab
526
+ * Options: `0` (off), `1` (on)
527
+ */
528
+ results_on_new_tab?: 0 | 1;
529
+
530
+ /**
531
+ * Proxy image results through SearxNG
532
+ * Options: true, false
533
+ */
534
+ image_proxy?: boolean;
535
+
536
+ /**
537
+ * Service for autocomplete suggestions
538
+ * Options: "google", "dbpedia", "duckduckgo", "mwmbl",
539
+ * "startpage", "wikipedia", "stract", "swisscows", "qwant"
540
+ */
541
+ autocomplete?: string;
542
+
543
+ /**
544
+ * Safe search filtering level
545
+ * Options: "0" (off), "1" (moderate), "2" (strict)
546
+ */
547
+ safesearch?: 0 | 1 | 2;
548
+
549
+ /**
550
+ * Theme to use for results page
551
+ * Default: "simple" (other themes may be available per instance)
552
+ */
553
+ theme?: string;
554
+
555
+ /**
556
+ * List of enabled plugins
557
+ * Default: "Hash_plugin,Self_Information,Tracker_URL_remover,Ahmia_blacklist"
558
+ */
559
+ enabled_plugins?: string;
560
+
561
+ /**
562
+ * List of disabled plugins
563
+ */
564
+ disabled_plugins?: string;
565
+
566
+ /**
567
+ * List of enabled engines
568
+ */
569
+ enabled_engines?: string;
570
+
571
+ /**
572
+ * List of disabled engines
573
+ */
574
+ disabled_engines?: string;
575
+ }
576
+
577
+ export interface SearXNGResult {
578
+ title?: string;
579
+ url?: string;
580
+ content?: string;
581
+ publishedDate?: string;
582
+ img_src?: string;
583
+ }
584
+
585
+ export type ProcessSourcesFields = {
586
+ result: SearchResult;
587
+ numElements: number;
588
+ query: string;
589
+ news: boolean;
590
+ proMode: boolean;
591
+ onGetHighlights: SearchToolConfig['onGetHighlights'];
592
+ };
593
+
594
+ export type SearchToolSchema = z.ZodObject<
595
+ {
596
+ query: z.ZodString;
597
+ date: z.ZodOptional<z.ZodNativeEnum<typeof DATE_RANGE>>;
598
+ country?: z.ZodOptional<z.ZodString>;
599
+ images: z.ZodOptional<z.ZodBoolean>;
600
+ videos: z.ZodOptional<z.ZodBoolean>;
601
+ news: z.ZodOptional<z.ZodBoolean>;
602
+ },
603
+ 'strip',
604
+ z.ZodTypeAny,
605
+ {
606
+ query: string;
607
+ date?: DATE_RANGE;
608
+ country?: unknown;
609
+ images?: boolean;
610
+ videos?: boolean;
611
+ news?: boolean;
612
+ },
613
+ {
614
+ query: string;
615
+ date?: DATE_RANGE;
616
+ country?: unknown;
617
+ images?: boolean;
618
+ videos?: boolean;
619
+ news?: boolean;
620
+ }
621
+ >;
@@ -0,0 +1,79 @@
1
+ /* eslint-disable no-console */
2
+
3
+ import type * as t from './types';
4
+
5
+ /**
6
+ * Singleton instance of the default logger
7
+ */
8
+ let defaultLoggerInstance: t.Logger | null = null;
9
+
10
+ /**
11
+ * Creates a default logger that maps to console methods
12
+ * Uses a singleton pattern to avoid creating multiple instances
13
+ * @returns A default logger that implements the Logger interface
14
+ */
15
+ export const createDefaultLogger = (): t.Logger => {
16
+ if (!defaultLoggerInstance) {
17
+ defaultLoggerInstance = {
18
+ error: console.error,
19
+ warn: console.warn,
20
+ info: console.info,
21
+ debug: console.debug,
22
+ } as t.Logger;
23
+ }
24
+ return defaultLoggerInstance;
25
+ };
26
+
27
+ export const fileExtRegex =
28
+ /\.(pdf|jpe?g|png|gif|svg|webp|bmp|ico|tiff?|avif|heic|doc[xm]?|xls[xm]?|ppt[xm]?|zip|rar|mp[34]|mov|avi|wav)(?:\?.*)?$/i;
29
+
30
+ export const getDomainName = (
31
+ link: string,
32
+ metadata?: t.ScrapeMetadata,
33
+ logger?: t.Logger
34
+ ): string | undefined => {
35
+ try {
36
+ const url = metadata?.sourceURL ?? metadata?.url ?? (link || '');
37
+ const domain = new URL(url).hostname.replace(/^www\./, '');
38
+ if (domain) {
39
+ return domain;
40
+ }
41
+ } catch (e) {
42
+ // URL parsing failed
43
+ if (logger) {
44
+ logger.error('Error parsing URL:', e);
45
+ } else {
46
+ console.error('Error parsing URL:', e);
47
+ }
48
+ }
49
+
50
+ return;
51
+ };
52
+
53
+ export function getAttribution(
54
+ link: string,
55
+ metadata?: t.ScrapeMetadata,
56
+ logger?: t.Logger
57
+ ): string | undefined {
58
+ if (!metadata) return getDomainName(link, metadata, logger);
59
+
60
+ const twitterSite = metadata['twitter:site'];
61
+ const twitterSiteFormatted =
62
+ typeof twitterSite === 'string' ? twitterSite.replace(/^@/, '') : undefined;
63
+
64
+ const possibleAttributions = [
65
+ metadata.ogSiteName,
66
+ metadata['og:site_name'],
67
+ metadata.title?.split('|').pop()?.trim(),
68
+ twitterSiteFormatted,
69
+ ];
70
+
71
+ const attribution = possibleAttributions.find(
72
+ (attr) => attr != null && typeof attr === 'string' && attr.trim() !== ''
73
+ );
74
+ if (attribution != null) {
75
+ return attribution;
76
+ }
77
+
78
+ return getDomainName(link, metadata, logger);
79
+ }
@@ -6,7 +6,7 @@ import type * as t from '@/types';
6
6
  export const llmConfigs: Record<string, t.LLMConfig | undefined> = {
7
7
  [Providers.OPENAI]: {
8
8
  provider: Providers.OPENAI,
9
- model: 'gpt-4o-mini',
9
+ model: 'gpt-4.1',
10
10
  temperature: 0.7,
11
11
  streaming: true,
12
12
  streamUsage: true,