@librechat/agents 2.4.31 → 2.4.34

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 (115) hide show
  1. package/dist/cjs/events.cjs +3 -3
  2. package/dist/cjs/events.cjs.map +1 -1
  3. package/dist/cjs/graphs/Graph.cjs +2 -1
  4. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  5. package/dist/cjs/main.cjs +5 -2
  6. package/dist/cjs/main.cjs.map +1 -1
  7. package/dist/cjs/messages/ids.cjs +23 -0
  8. package/dist/cjs/messages/ids.cjs.map +1 -0
  9. package/dist/cjs/splitStream.cjs +2 -1
  10. package/dist/cjs/splitStream.cjs.map +1 -1
  11. package/dist/cjs/stream.cjs +87 -154
  12. package/dist/cjs/stream.cjs.map +1 -1
  13. package/dist/cjs/tools/ToolNode.cjs +14 -3
  14. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  15. package/dist/cjs/tools/handlers.cjs +144 -0
  16. package/dist/cjs/tools/handlers.cjs.map +1 -0
  17. package/dist/cjs/tools/search/content.cjs +140 -0
  18. package/dist/cjs/tools/search/content.cjs.map +1 -0
  19. package/dist/cjs/tools/search/firecrawl.cjs +23 -41
  20. package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
  21. package/dist/cjs/tools/search/format.cjs +161 -74
  22. package/dist/cjs/tools/search/format.cjs.map +1 -1
  23. package/dist/cjs/tools/search/highlights.cjs +64 -12
  24. package/dist/cjs/tools/search/highlights.cjs.map +1 -1
  25. package/dist/cjs/tools/search/rerankers.cjs +35 -50
  26. package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
  27. package/dist/cjs/tools/search/schema.cjs +70 -0
  28. package/dist/cjs/tools/search/schema.cjs.map +1 -0
  29. package/dist/cjs/tools/search/search.cjs +153 -69
  30. package/dist/cjs/tools/search/search.cjs.map +1 -1
  31. package/dist/cjs/tools/search/tool.cjs +247 -58
  32. package/dist/cjs/tools/search/tool.cjs.map +1 -1
  33. package/dist/cjs/tools/search/utils.cjs +66 -0
  34. package/dist/cjs/tools/search/utils.cjs.map +1 -0
  35. package/dist/esm/events.mjs +1 -1
  36. package/dist/esm/events.mjs.map +1 -1
  37. package/dist/esm/graphs/Graph.mjs +2 -1
  38. package/dist/esm/graphs/Graph.mjs.map +1 -1
  39. package/dist/esm/main.mjs +3 -1
  40. package/dist/esm/main.mjs.map +1 -1
  41. package/dist/esm/messages/ids.mjs +21 -0
  42. package/dist/esm/messages/ids.mjs.map +1 -0
  43. package/dist/esm/splitStream.mjs +2 -1
  44. package/dist/esm/splitStream.mjs.map +1 -1
  45. package/dist/esm/stream.mjs +87 -152
  46. package/dist/esm/stream.mjs.map +1 -1
  47. package/dist/esm/tools/ToolNode.mjs +14 -3
  48. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  49. package/dist/esm/tools/handlers.mjs +141 -0
  50. package/dist/esm/tools/handlers.mjs.map +1 -0
  51. package/dist/esm/tools/search/content.mjs +119 -0
  52. package/dist/esm/tools/search/content.mjs.map +1 -0
  53. package/dist/esm/tools/search/firecrawl.mjs +24 -41
  54. package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
  55. package/dist/esm/tools/search/format.mjs +161 -74
  56. package/dist/esm/tools/search/format.mjs.map +1 -1
  57. package/dist/esm/tools/search/highlights.mjs +64 -12
  58. package/dist/esm/tools/search/highlights.mjs.map +1 -1
  59. package/dist/esm/tools/search/rerankers.mjs +35 -50
  60. package/dist/esm/tools/search/rerankers.mjs.map +1 -1
  61. package/dist/esm/tools/search/schema.mjs +61 -0
  62. package/dist/esm/tools/search/schema.mjs.map +1 -0
  63. package/dist/esm/tools/search/search.mjs +153 -69
  64. package/dist/esm/tools/search/search.mjs.map +1 -1
  65. package/dist/esm/tools/search/tool.mjs +246 -57
  66. package/dist/esm/tools/search/tool.mjs.map +1 -1
  67. package/dist/esm/tools/search/utils.mjs +61 -0
  68. package/dist/esm/tools/search/utils.mjs.map +1 -0
  69. package/dist/types/graphs/Graph.d.ts +1 -1
  70. package/dist/types/index.d.ts +1 -0
  71. package/dist/types/messages/ids.d.ts +3 -0
  72. package/dist/types/messages/index.d.ts +1 -0
  73. package/dist/types/stream.d.ts +0 -8
  74. package/dist/types/tools/ToolNode.d.ts +6 -0
  75. package/dist/types/tools/example.d.ts +23 -3
  76. package/dist/types/tools/handlers.d.ts +8 -0
  77. package/dist/types/tools/search/content.d.ts +4 -0
  78. package/dist/types/tools/search/firecrawl.d.ts +7 -86
  79. package/dist/types/tools/search/format.d.ts +4 -1
  80. package/dist/types/tools/search/highlights.d.ts +1 -1
  81. package/dist/types/tools/search/rerankers.d.ts +8 -5
  82. package/dist/types/tools/search/schema.d.ts +16 -0
  83. package/dist/types/tools/search/search.d.ts +2 -2
  84. package/dist/types/tools/search/test.d.ts +1 -0
  85. package/dist/types/tools/search/tool.d.ts +25 -4
  86. package/dist/types/tools/search/types.d.ts +443 -53
  87. package/dist/types/tools/search/utils.d.ts +10 -0
  88. package/package.json +9 -7
  89. package/src/events.ts +49 -15
  90. package/src/graphs/Graph.ts +6 -2
  91. package/src/index.ts +1 -0
  92. package/src/messages/ids.ts +26 -0
  93. package/src/messages/index.ts +1 -0
  94. package/src/scripts/search.ts +8 -3
  95. package/src/splitStream.test.ts +132 -71
  96. package/src/splitStream.ts +2 -1
  97. package/src/stream.ts +94 -183
  98. package/src/tools/ToolNode.ts +37 -14
  99. package/src/tools/handlers.ts +167 -0
  100. package/src/tools/search/content.test.ts +173 -0
  101. package/src/tools/search/content.ts +147 -0
  102. package/src/tools/search/firecrawl.ts +36 -148
  103. package/src/tools/search/format.ts +205 -74
  104. package/src/tools/search/highlights.ts +99 -16
  105. package/src/tools/search/output.md +2775 -0
  106. package/src/tools/search/rerankers.ts +50 -62
  107. package/src/tools/search/schema.ts +63 -0
  108. package/src/tools/search/search.ts +232 -116
  109. package/src/tools/search/test.html +884 -0
  110. package/src/tools/search/test.md +643 -0
  111. package/src/tools/search/test.ts +159 -0
  112. package/src/tools/search/tool.ts +363 -87
  113. package/src/tools/search/types.ts +503 -61
  114. package/src/tools/search/utils.ts +79 -0
  115. package/src/utils/llmConfig.ts +1 -1
@@ -1,75 +1,50 @@
1
+ import { z } from 'zod';
2
+ import type { Logger as WinstonLogger } from 'winston';
1
3
  import type { RunnableConfig } from '@langchain/core/runnables';
2
4
  import type { BaseReranker } from './rerankers';
5
+ import { DATE_RANGE } from './schema';
3
6
 
4
7
  export type SearchProvider = 'serper' | 'searxng';
5
8
  export type RerankerType = 'infinity' | 'jina' | 'cohere' | 'none';
6
9
 
7
- export interface OrganicResult {
8
- position?: number;
9
- title?: string;
10
- link: string;
11
- snippet?: string;
12
- date?: string;
13
- }
14
-
15
- export interface TopStoryResult {
16
- title?: string;
17
- link: string;
18
- source?: string;
19
- date?: string;
20
- imageUrl?: string;
21
- }
22
-
23
- export interface ImageResult {
24
- title?: string;
25
- imageUrl?: string;
26
- }
27
-
28
- export interface KnowledgeGraphResult {
29
- title?: string;
30
- type?: string;
31
- description?: string;
32
- attributes?: Record<string, string>;
33
- imageUrl?: string;
34
- }
35
-
36
- export interface AnswerBoxResult {
37
- title?: string;
38
- answer?: string;
39
- snippet?: string;
40
- date?: string;
41
- }
42
-
43
- export interface PeopleAlsoAskResult {
44
- question?: string;
45
- answer?: string;
46
- }
47
-
48
10
  export interface Highlight {
49
11
  score: number;
50
12
  text: string;
13
+ references?: UsedReferences;
51
14
  }
52
15
 
53
- export interface ValidSource {
54
- link: string;
55
- position?: number;
56
- title?: string;
57
- snippet?: string;
58
- date?: string;
16
+ export type ProcessedSource = {
59
17
  content?: string;
60
18
  attribution?: string;
19
+ references?: References;
61
20
  highlights?: Highlight[];
62
- }
21
+ processed?: boolean;
22
+ };
23
+
24
+ export type ProcessedOrganic = OrganicResult & ProcessedSource;
25
+ export type ProcessedTopStory = TopStoryResult & ProcessedSource;
26
+ export type ValidSource = ProcessedOrganic | ProcessedTopStory;
63
27
 
28
+ export type ResultReference = {
29
+ link: string;
30
+ type: 'link' | 'image' | 'video';
31
+ title?: string;
32
+ attribution?: string;
33
+ };
64
34
  export interface SearchResultData {
65
- organic?: ValidSource[];
66
- topStories?: ValidSource[];
35
+ turn?: number;
36
+ organic?: ProcessedOrganic[];
37
+ topStories?: ProcessedTopStory[];
67
38
  images?: ImageResult[];
39
+ videos?: VideoResult[];
40
+ places?: PlaceResult[];
41
+ news?: NewsResult[];
42
+ shopping?: ShoppingResult[];
68
43
  knowledgeGraph?: KnowledgeGraphResult;
69
44
  answerBox?: AnswerBoxResult;
70
45
  peopleAlsoAsk?: PeopleAlsoAskResult[];
71
- relatedSearches?: string[];
72
- suggestions?: string[];
46
+ relatedSearches?: Array<{ query: string }>;
47
+ references?: ResultReference[];
73
48
  error?: string;
74
49
  }
75
50
 
@@ -94,11 +69,17 @@ export interface SearchConfig {
94
69
  searxngApiKey?: string;
95
70
  }
96
71
 
72
+ export type References = {
73
+ links: MediaReference[];
74
+ images: MediaReference[];
75
+ videos: MediaReference[];
76
+ };
97
77
  export interface ScrapeResult {
98
78
  url: string;
99
79
  error?: boolean;
100
80
  content: string;
101
81
  attribution?: string;
82
+ references?: References;
102
83
  highlights?: Highlight[];
103
84
  }
104
85
 
@@ -107,6 +88,7 @@ export interface ProcessSourcesConfig {
107
88
  strategies?: string[];
108
89
  filterContent?: boolean;
109
90
  reranker?: BaseReranker;
91
+ logger?: Logger;
110
92
  }
111
93
 
112
94
  export interface FirecrawlConfig {
@@ -123,15 +105,6 @@ export interface ScraperExtractionResult {
123
105
  no_extraction: ScraperContentResult;
124
106
  }
125
107
 
126
- // Define type for SearXNG result
127
- export interface SearXNGResult {
128
- title?: string;
129
- url?: string;
130
- content?: string;
131
- publishedDate?: string;
132
- img_src?: string;
133
- }
134
-
135
108
  export interface JinaRerankerResult {
136
109
  index: number;
137
110
  relevance_score: number;
@@ -165,10 +138,15 @@ export interface CohereRerankerResponse {
165
138
  };
166
139
  }
167
140
 
141
+ export type SafeSearchLevel = 0 | 1 | 2;
142
+
143
+ export type Logger = WinstonLogger;
168
144
  export interface SearchToolConfig
169
145
  extends SearchConfig,
170
146
  ProcessSourcesConfig,
171
147
  FirecrawlConfig {
148
+ logger?: Logger;
149
+ safeSearch?: SafeSearchLevel;
172
150
  jinaApiKey?: string;
173
151
  cohereApiKey?: string;
174
152
  rerankerType?: RerankerType;
@@ -176,4 +154,468 @@ export interface SearchToolConfig
176
154
  results: SearchResult,
177
155
  runnableConfig?: RunnableConfig
178
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;
179
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,