illuma-agents 1.0.8 → 1.0.10

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 (250) hide show
  1. package/LICENSE +1 -5
  2. package/dist/cjs/common/enum.cjs +1 -2
  3. package/dist/cjs/common/enum.cjs.map +1 -1
  4. package/dist/cjs/events.cjs +11 -0
  5. package/dist/cjs/events.cjs.map +1 -1
  6. package/dist/cjs/graphs/Graph.cjs +2 -1
  7. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  8. package/dist/cjs/instrumentation.cjs +3 -1
  9. package/dist/cjs/instrumentation.cjs.map +1 -1
  10. package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
  11. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +79 -2
  12. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
  13. package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -1
  14. package/dist/cjs/llm/bedrock/index.cjs +99 -0
  15. package/dist/cjs/llm/bedrock/index.cjs.map +1 -0
  16. package/dist/cjs/llm/fake.cjs.map +1 -1
  17. package/dist/cjs/llm/openai/index.cjs +102 -0
  18. package/dist/cjs/llm/openai/index.cjs.map +1 -1
  19. package/dist/cjs/llm/openai/utils/index.cjs +87 -1
  20. package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
  21. package/dist/cjs/llm/openrouter/index.cjs +175 -1
  22. package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
  23. package/dist/cjs/llm/providers.cjs +13 -16
  24. package/dist/cjs/llm/providers.cjs.map +1 -1
  25. package/dist/cjs/llm/text.cjs.map +1 -1
  26. package/dist/cjs/messages/core.cjs +14 -14
  27. package/dist/cjs/messages/core.cjs.map +1 -1
  28. package/dist/cjs/messages/ids.cjs.map +1 -1
  29. package/dist/cjs/messages/prune.cjs.map +1 -1
  30. package/dist/cjs/run.cjs +18 -1
  31. package/dist/cjs/run.cjs.map +1 -1
  32. package/dist/cjs/splitStream.cjs.map +1 -1
  33. package/dist/cjs/stream.cjs +24 -1
  34. package/dist/cjs/stream.cjs.map +1 -1
  35. package/dist/cjs/tools/ToolNode.cjs +20 -1
  36. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  37. package/dist/cjs/tools/handlers.cjs +29 -25
  38. package/dist/cjs/tools/handlers.cjs.map +1 -1
  39. package/dist/cjs/tools/search/anthropic.cjs.map +1 -1
  40. package/dist/cjs/tools/search/content.cjs.map +1 -1
  41. package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
  42. package/dist/cjs/tools/search/format.cjs.map +1 -1
  43. package/dist/cjs/tools/search/highlights.cjs.map +1 -1
  44. package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
  45. package/dist/cjs/tools/search/schema.cjs +27 -25
  46. package/dist/cjs/tools/search/schema.cjs.map +1 -1
  47. package/dist/cjs/tools/search/search.cjs +6 -1
  48. package/dist/cjs/tools/search/search.cjs.map +1 -1
  49. package/dist/cjs/tools/search/serper-scraper.cjs.map +1 -1
  50. package/dist/cjs/tools/search/tool.cjs +182 -35
  51. package/dist/cjs/tools/search/tool.cjs.map +1 -1
  52. package/dist/cjs/tools/search/utils.cjs.map +1 -1
  53. package/dist/cjs/utils/graph.cjs.map +1 -1
  54. package/dist/cjs/utils/llm.cjs +0 -1
  55. package/dist/cjs/utils/llm.cjs.map +1 -1
  56. package/dist/cjs/utils/misc.cjs.map +1 -1
  57. package/dist/cjs/utils/run.cjs.map +1 -1
  58. package/dist/cjs/utils/title.cjs +7 -7
  59. package/dist/cjs/utils/title.cjs.map +1 -1
  60. package/dist/esm/common/enum.mjs +1 -2
  61. package/dist/esm/common/enum.mjs.map +1 -1
  62. package/dist/esm/events.mjs +11 -0
  63. package/dist/esm/events.mjs.map +1 -1
  64. package/dist/esm/graphs/Graph.mjs +2 -1
  65. package/dist/esm/graphs/Graph.mjs.map +1 -1
  66. package/dist/esm/instrumentation.mjs +3 -1
  67. package/dist/esm/instrumentation.mjs.map +1 -1
  68. package/dist/esm/llm/anthropic/types.mjs.map +1 -1
  69. package/dist/esm/llm/anthropic/utils/message_inputs.mjs +79 -2
  70. package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
  71. package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -1
  72. package/dist/esm/llm/bedrock/index.mjs +97 -0
  73. package/dist/esm/llm/bedrock/index.mjs.map +1 -0
  74. package/dist/esm/llm/fake.mjs.map +1 -1
  75. package/dist/esm/llm/openai/index.mjs +103 -1
  76. package/dist/esm/llm/openai/index.mjs.map +1 -1
  77. package/dist/esm/llm/openai/utils/index.mjs +88 -2
  78. package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
  79. package/dist/esm/llm/openrouter/index.mjs +175 -1
  80. package/dist/esm/llm/openrouter/index.mjs.map +1 -1
  81. package/dist/esm/llm/providers.mjs +2 -5
  82. package/dist/esm/llm/providers.mjs.map +1 -1
  83. package/dist/esm/llm/text.mjs.map +1 -1
  84. package/dist/esm/messages/core.mjs +14 -14
  85. package/dist/esm/messages/core.mjs.map +1 -1
  86. package/dist/esm/messages/ids.mjs.map +1 -1
  87. package/dist/esm/messages/prune.mjs.map +1 -1
  88. package/dist/esm/run.mjs +18 -1
  89. package/dist/esm/run.mjs.map +1 -1
  90. package/dist/esm/splitStream.mjs.map +1 -1
  91. package/dist/esm/stream.mjs +24 -1
  92. package/dist/esm/stream.mjs.map +1 -1
  93. package/dist/esm/tools/ToolNode.mjs +20 -1
  94. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  95. package/dist/esm/tools/handlers.mjs +30 -26
  96. package/dist/esm/tools/handlers.mjs.map +1 -1
  97. package/dist/esm/tools/search/anthropic.mjs.map +1 -1
  98. package/dist/esm/tools/search/content.mjs.map +1 -1
  99. package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
  100. package/dist/esm/tools/search/format.mjs.map +1 -1
  101. package/dist/esm/tools/search/highlights.mjs.map +1 -1
  102. package/dist/esm/tools/search/rerankers.mjs.map +1 -1
  103. package/dist/esm/tools/search/schema.mjs +27 -25
  104. package/dist/esm/tools/search/schema.mjs.map +1 -1
  105. package/dist/esm/tools/search/search.mjs +6 -1
  106. package/dist/esm/tools/search/search.mjs.map +1 -1
  107. package/dist/esm/tools/search/serper-scraper.mjs.map +1 -1
  108. package/dist/esm/tools/search/tool.mjs +182 -35
  109. package/dist/esm/tools/search/tool.mjs.map +1 -1
  110. package/dist/esm/tools/search/utils.mjs.map +1 -1
  111. package/dist/esm/utils/graph.mjs.map +1 -1
  112. package/dist/esm/utils/llm.mjs +0 -1
  113. package/dist/esm/utils/llm.mjs.map +1 -1
  114. package/dist/esm/utils/misc.mjs.map +1 -1
  115. package/dist/esm/utils/run.mjs.map +1 -1
  116. package/dist/esm/utils/title.mjs +7 -7
  117. package/dist/esm/utils/title.mjs.map +1 -1
  118. package/dist/types/common/enum.d.ts +1 -2
  119. package/dist/types/llm/bedrock/index.d.ts +36 -0
  120. package/dist/types/llm/openai/index.d.ts +1 -0
  121. package/dist/types/llm/openai/utils/index.d.ts +10 -1
  122. package/dist/types/llm/openrouter/index.d.ts +4 -1
  123. package/dist/types/tools/search/types.d.ts +2 -0
  124. package/dist/types/types/llm.d.ts +3 -8
  125. package/package.json +16 -12
  126. package/src/common/enum.ts +1 -2
  127. package/src/common/index.ts +1 -1
  128. package/src/events.ts +11 -0
  129. package/src/graphs/Graph.ts +2 -1
  130. package/src/instrumentation.ts +25 -22
  131. package/src/llm/anthropic/llm.spec.ts +1442 -1442
  132. package/src/llm/anthropic/types.ts +140 -140
  133. package/src/llm/anthropic/utils/message_inputs.ts +757 -660
  134. package/src/llm/anthropic/utils/output_parsers.ts +133 -133
  135. package/src/llm/anthropic/utils/tools.ts +29 -29
  136. package/src/llm/bedrock/index.ts +128 -0
  137. package/src/llm/fake.ts +133 -133
  138. package/src/llm/google/llm.spec.ts +3 -1
  139. package/src/llm/google/utils/tools.ts +160 -160
  140. package/src/llm/openai/index.ts +126 -0
  141. package/src/llm/openai/types.ts +24 -24
  142. package/src/llm/openai/utils/index.ts +116 -1
  143. package/src/llm/openai/utils/isReasoningModel.test.ts +90 -90
  144. package/src/llm/openrouter/index.ts +222 -1
  145. package/src/llm/providers.ts +2 -7
  146. package/src/llm/text.ts +94 -94
  147. package/src/messages/core.ts +463 -463
  148. package/src/messages/formatAgentMessages.tools.test.ts +400 -400
  149. package/src/messages/formatMessage.test.ts +693 -693
  150. package/src/messages/ids.ts +26 -26
  151. package/src/messages/prune.ts +567 -567
  152. package/src/messages/shiftIndexTokenCountMap.test.ts +81 -81
  153. package/src/mockStream.ts +98 -98
  154. package/src/prompts/collab.ts +5 -5
  155. package/src/prompts/index.ts +1 -1
  156. package/src/prompts/taskmanager.ts +61 -61
  157. package/src/run.ts +22 -4
  158. package/src/scripts/ant_web_search_edge_case.ts +162 -0
  159. package/src/scripts/ant_web_search_error_edge_case.ts +148 -0
  160. package/src/scripts/args.ts +48 -48
  161. package/src/scripts/caching.ts +123 -123
  162. package/src/scripts/code_exec_files.ts +193 -193
  163. package/src/scripts/empty_input.ts +137 -137
  164. package/src/scripts/memory.ts +97 -97
  165. package/src/scripts/test-tools-before-handoff.ts +1 -5
  166. package/src/scripts/thinking.ts +149 -149
  167. package/src/scripts/tools.ts +1 -4
  168. package/src/specs/anthropic.simple.test.ts +67 -0
  169. package/src/specs/spec.utils.ts +3 -3
  170. package/src/specs/token-distribution-edge-case.test.ts +316 -316
  171. package/src/specs/tool-error.test.ts +193 -193
  172. package/src/splitStream.test.ts +691 -691
  173. package/src/splitStream.ts +234 -234
  174. package/src/stream.test.ts +94 -94
  175. package/src/stream.ts +30 -1
  176. package/src/tools/ToolNode.ts +24 -1
  177. package/src/tools/handlers.ts +32 -28
  178. package/src/tools/search/anthropic.ts +51 -51
  179. package/src/tools/search/content.test.ts +173 -173
  180. package/src/tools/search/content.ts +147 -147
  181. package/src/tools/search/direct-url.test.ts +530 -0
  182. package/src/tools/search/firecrawl.ts +210 -210
  183. package/src/tools/search/format.ts +250 -250
  184. package/src/tools/search/highlights.ts +320 -320
  185. package/src/tools/search/index.ts +2 -2
  186. package/src/tools/search/jina-reranker.test.ts +126 -126
  187. package/src/tools/search/output.md +2775 -2775
  188. package/src/tools/search/rerankers.ts +242 -242
  189. package/src/tools/search/schema.ts +65 -63
  190. package/src/tools/search/search.ts +766 -759
  191. package/src/tools/search/serper-scraper.ts +155 -155
  192. package/src/tools/search/test.html +883 -883
  193. package/src/tools/search/test.md +642 -642
  194. package/src/tools/search/test.ts +159 -159
  195. package/src/tools/search/tool.ts +641 -471
  196. package/src/tools/search/types.ts +689 -687
  197. package/src/tools/search/utils.ts +79 -79
  198. package/src/types/index.ts +6 -6
  199. package/src/types/llm.ts +2 -8
  200. package/src/utils/graph.ts +10 -10
  201. package/src/utils/llm.ts +26 -27
  202. package/src/utils/llmConfig.ts +13 -5
  203. package/src/utils/logging.ts +48 -48
  204. package/src/utils/misc.ts +57 -57
  205. package/src/utils/run.ts +100 -100
  206. package/src/utils/title.ts +165 -165
  207. package/dist/cjs/llm/ollama/index.cjs +0 -70
  208. package/dist/cjs/llm/ollama/index.cjs.map +0 -1
  209. package/dist/cjs/llm/ollama/utils.cjs +0 -158
  210. package/dist/cjs/llm/ollama/utils.cjs.map +0 -1
  211. package/dist/esm/llm/ollama/index.mjs +0 -68
  212. package/dist/esm/llm/ollama/index.mjs.map +0 -1
  213. package/dist/esm/llm/ollama/utils.mjs +0 -155
  214. package/dist/esm/llm/ollama/utils.mjs.map +0 -1
  215. package/dist/types/llm/ollama/index.d.ts +0 -8
  216. package/dist/types/llm/ollama/utils.d.ts +0 -7
  217. package/src/llm/ollama/index.ts +0 -92
  218. package/src/llm/ollama/utils.ts +0 -193
  219. package/src/proto/CollabGraph.ts +0 -269
  220. package/src/proto/TaskManager.ts +0 -243
  221. package/src/proto/collab.ts +0 -200
  222. package/src/proto/collab_design.ts +0 -184
  223. package/src/proto/collab_design_v2.ts +0 -224
  224. package/src/proto/collab_design_v3.ts +0 -255
  225. package/src/proto/collab_design_v4.ts +0 -220
  226. package/src/proto/collab_design_v5.ts +0 -251
  227. package/src/proto/collab_graph.ts +0 -181
  228. package/src/proto/collab_original.ts +0 -123
  229. package/src/proto/example.ts +0 -93
  230. package/src/proto/example_new.ts +0 -68
  231. package/src/proto/example_old.ts +0 -201
  232. package/src/proto/example_test.ts +0 -152
  233. package/src/proto/example_test_anthropic.ts +0 -100
  234. package/src/proto/log_stream.ts +0 -202
  235. package/src/proto/main_collab_community_event.ts +0 -133
  236. package/src/proto/main_collab_design_v2.ts +0 -96
  237. package/src/proto/main_collab_design_v4.ts +0 -100
  238. package/src/proto/main_collab_design_v5.ts +0 -135
  239. package/src/proto/main_collab_global_analysis.ts +0 -122
  240. package/src/proto/main_collab_hackathon_event.ts +0 -153
  241. package/src/proto/main_collab_space_mission.ts +0 -153
  242. package/src/proto/main_philosophy.ts +0 -210
  243. package/src/proto/original_script.ts +0 -126
  244. package/src/proto/standard.ts +0 -100
  245. package/src/proto/stream.ts +0 -56
  246. package/src/proto/tasks.ts +0 -118
  247. package/src/proto/tools/global_analysis_tools.ts +0 -86
  248. package/src/proto/tools/space_mission_tools.ts +0 -60
  249. package/src/proto/vertexai.ts +0 -54
  250. package/src/scripts/image.ts +0 -178
@@ -1,687 +1,689 @@
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 ScraperProvider = 'firecrawl' | 'serper';
9
- export type RerankerType = 'infinity' | 'jina' | 'cohere' | 'none';
10
-
11
- export interface Highlight {
12
- score: number;
13
- text: string;
14
- references?: UsedReferences;
15
- }
16
-
17
- export type ProcessedSource = {
18
- content?: string;
19
- attribution?: string;
20
- references?: References;
21
- highlights?: Highlight[];
22
- processed?: boolean;
23
- };
24
-
25
- export type ProcessedOrganic = OrganicResult & ProcessedSource;
26
- export type ProcessedTopStory = TopStoryResult & ProcessedSource;
27
- export type ValidSource = ProcessedOrganic | ProcessedTopStory;
28
-
29
- export type ResultReference = {
30
- link: string;
31
- type: 'link' | 'image' | 'video';
32
- title?: string;
33
- attribution?: string;
34
- };
35
- export interface SearchResultData {
36
- turn?: number;
37
- organic?: ProcessedOrganic[];
38
- topStories?: ProcessedTopStory[];
39
- images?: ImageResult[];
40
- videos?: VideoResult[];
41
- places?: PlaceResult[];
42
- news?: NewsResult[];
43
- shopping?: ShoppingResult[];
44
- knowledgeGraph?: KnowledgeGraphResult;
45
- answerBox?: AnswerBoxResult;
46
- peopleAlsoAsk?: PeopleAlsoAskResult[];
47
- relatedSearches?: Array<{ query: string }>;
48
- references?: ResultReference[];
49
- error?: string;
50
- }
51
-
52
- export interface SearchResult {
53
- data?: SearchResultData;
54
- error?: string;
55
- success: boolean;
56
- }
57
-
58
- export interface Source {
59
- link: string;
60
- html?: string;
61
- title?: string;
62
- snippet?: string;
63
- date?: string;
64
- }
65
-
66
- export interface SearchConfig {
67
- searchProvider?: SearchProvider;
68
- serperApiKey?: string;
69
- searxngInstanceUrl?: string;
70
- searxngApiKey?: string;
71
- }
72
-
73
- export type References = {
74
- links: MediaReference[];
75
- images: MediaReference[];
76
- videos: MediaReference[];
77
- };
78
- export interface ScrapeResult {
79
- url: string;
80
- error?: boolean;
81
- content: string;
82
- attribution?: string;
83
- references?: References;
84
- highlights?: Highlight[];
85
- }
86
-
87
- export interface ProcessSourcesConfig {
88
- topResults?: number;
89
- strategies?: string[];
90
- filterContent?: boolean;
91
- reranker?: BaseReranker;
92
- logger?: Logger;
93
- }
94
-
95
- export interface FirecrawlConfig {
96
- firecrawlApiKey?: string;
97
- firecrawlApiUrl?: string;
98
- firecrawlVersion?: string;
99
- firecrawlOptions?: FirecrawlScraperConfig;
100
- }
101
-
102
- export interface SerperScraperConfig {
103
- apiKey?: string;
104
- apiUrl?: string;
105
- timeout?: number;
106
- logger?: Logger;
107
- includeMarkdown?: boolean;
108
- }
109
-
110
- export interface ScraperContentResult {
111
- content: string;
112
- }
113
-
114
- export interface ScraperExtractionResult {
115
- no_extraction: ScraperContentResult;
116
- }
117
-
118
- export interface JinaRerankerResult {
119
- index: number;
120
- relevance_score: number;
121
- document?: string | { text: string };
122
- }
123
-
124
- export interface JinaRerankerResponse {
125
- model: string;
126
- usage: {
127
- total_tokens: number;
128
- };
129
- results: JinaRerankerResult[];
130
- }
131
-
132
- export interface CohereRerankerResult {
133
- index: number;
134
- relevance_score: number;
135
- }
136
-
137
- export interface CohereRerankerResponse {
138
- results: CohereRerankerResult[];
139
- id: string;
140
- meta: {
141
- api_version: {
142
- version: string;
143
- is_experimental: boolean;
144
- };
145
- billed_units: {
146
- search_units: number;
147
- };
148
- };
149
- }
150
-
151
- export type SafeSearchLevel = 0 | 1 | 2;
152
-
153
- export type Logger = WinstonLogger;
154
- export interface SearchToolConfig
155
- extends SearchConfig,
156
- ProcessSourcesConfig,
157
- FirecrawlConfig {
158
- logger?: Logger;
159
- safeSearch?: SafeSearchLevel;
160
- jinaApiKey?: string;
161
- jinaApiUrl?: string;
162
- cohereApiKey?: string;
163
- rerankerType?: RerankerType;
164
- scraperProvider?: ScraperProvider;
165
- scraperTimeout?: number;
166
- serperScraperOptions?: SerperScraperConfig;
167
- onSearchResults?: (
168
- results: SearchResult,
169
- runnableConfig?: RunnableConfig
170
- ) => void;
171
- onGetHighlights?: (link: string) => void;
172
- }
173
- export interface MediaReference {
174
- originalUrl: string;
175
- title?: string;
176
- text?: string;
177
- }
178
-
179
- export type UsedReferences = {
180
- type: 'link' | 'image' | 'video';
181
- originalIndex: number;
182
- reference: MediaReference;
183
- }[];
184
-
185
- /** Base Scraper Interface */
186
- export interface BaseScraper {
187
- scrapeUrl(
188
- url: string,
189
- options?: unknown
190
- ): Promise<[string, FirecrawlScrapeResponse | SerperScrapeResponse]>;
191
- extractContent(
192
- response: FirecrawlScrapeResponse | SerperScrapeResponse
193
- ): [string, undefined | References];
194
- extractMetadata(
195
- response: FirecrawlScrapeResponse | SerperScrapeResponse
196
- ):
197
- | ScrapeMetadata
198
- | Record<string, string | number | boolean | null | undefined>;
199
- }
200
-
201
- /** Firecrawl */
202
- export type FirecrawlScrapeOptions = Omit<
203
- FirecrawlScraperConfig,
204
- 'apiKey' | 'apiUrl' | 'version' | 'logger'
205
- >;
206
-
207
- export type SerperScrapeOptions = Omit<
208
- SerperScraperConfig,
209
- 'apiKey' | 'apiUrl' | 'logger'
210
- >;
211
-
212
- export interface ScrapeMetadata {
213
- // Core source information
214
- sourceURL?: string;
215
- url?: string;
216
- scrapeId?: string;
217
- statusCode?: number;
218
- // Basic metadata
219
- title?: string;
220
- description?: string;
221
- language?: string;
222
- favicon?: string;
223
- viewport?: string;
224
- robots?: string;
225
- 'theme-color'?: string;
226
- // Open Graph metadata
227
- 'og:url'?: string;
228
- 'og:title'?: string;
229
- 'og:description'?: string;
230
- 'og:type'?: string;
231
- 'og:image'?: string;
232
- 'og:image:width'?: string;
233
- 'og:image:height'?: string;
234
- 'og:site_name'?: string;
235
- ogUrl?: string;
236
- ogTitle?: string;
237
- ogDescription?: string;
238
- ogImage?: string;
239
- ogSiteName?: string;
240
- // Article metadata
241
- 'article:author'?: string;
242
- 'article:published_time'?: string;
243
- 'article:modified_time'?: string;
244
- 'article:section'?: string;
245
- 'article:tag'?: string;
246
- 'article:publisher'?: string;
247
- publishedTime?: string;
248
- modifiedTime?: string;
249
- // Twitter metadata
250
- 'twitter:site'?: string | boolean | number | null;
251
- 'twitter:creator'?: string;
252
- 'twitter:card'?: string;
253
- 'twitter:image'?: string;
254
- 'twitter:dnt'?: string;
255
- 'twitter:app:name:iphone'?: string;
256
- 'twitter:app:id:iphone'?: string;
257
- 'twitter:app:url:iphone'?: string;
258
- 'twitter:app:name:ipad'?: string;
259
- 'twitter:app:id:ipad'?: string;
260
- 'twitter:app:url:ipad'?: string;
261
- 'twitter:app:name:googleplay'?: string;
262
- 'twitter:app:id:googleplay'?: string;
263
- 'twitter:app:url:googleplay'?: string;
264
- // Facebook metadata
265
- 'fb:app_id'?: string;
266
- // App links
267
- 'al:ios:url'?: string;
268
- 'al:ios:app_name'?: string;
269
- 'al:ios:app_store_id'?: string;
270
- // Allow for additional properties that might be present
271
- [key: string]: string | number | boolean | null | undefined;
272
- }
273
-
274
- export interface FirecrawlScrapeResponse {
275
- success: boolean;
276
- data?: {
277
- markdown?: string;
278
- html?: string;
279
- rawHtml?: string;
280
- screenshot?: string;
281
- links?: string[];
282
- metadata?: ScrapeMetadata;
283
- };
284
- error?: string;
285
- }
286
-
287
- export interface SerperScrapeResponse {
288
- success: boolean;
289
- data?: {
290
- text?: string;
291
- markdown?: string;
292
- metadata?: Record<string, string | number | boolean | null | undefined>;
293
- credits?: number;
294
- };
295
- error?: string;
296
- }
297
-
298
- export interface FirecrawlScraperConfig {
299
- apiKey?: string;
300
- apiUrl?: string;
301
- version?: string;
302
- formats?: string[];
303
- timeout?: number;
304
- logger?: Logger;
305
- includeTags?: string[];
306
- excludeTags?: string[];
307
- waitFor?: number;
308
- maxAge?: number;
309
- mobile?: boolean;
310
- skipTlsVerification?: boolean;
311
- blockAds?: boolean;
312
- removeBase64Images?: boolean;
313
- parsePDF?: boolean;
314
- storeInCache?: boolean;
315
- zeroDataRetention?: boolean;
316
- headers?: Record<string, string>;
317
- location?: { country?: string; languages?: string[] };
318
- onlyMainContent?: boolean;
319
- changeTrackingOptions?: object;
320
- }
321
-
322
- export type GetSourcesParams = {
323
- query: string;
324
- date?: DATE_RANGE;
325
- country?: string;
326
- numResults?: number;
327
- safeSearch?: SearchToolConfig['safeSearch'];
328
- images?: boolean;
329
- videos?: boolean;
330
- news?: boolean;
331
- type?: 'search' | 'images' | 'videos' | 'news';
332
- };
333
-
334
- /** Serper API */
335
- export interface VideoResult {
336
- title?: string;
337
- link?: string;
338
- snippet?: string;
339
- imageUrl?: string;
340
- duration?: string;
341
- source?: string;
342
- channel?: string;
343
- date?: string;
344
- position?: number;
345
- }
346
-
347
- export interface PlaceResult {
348
- position?: number;
349
- name?: string;
350
- address?: string;
351
- latitude?: number;
352
- longitude?: number;
353
- rating?: number;
354
- ratingCount?: number;
355
- category?: string;
356
- identifier?: string;
357
- }
358
-
359
- export interface NewsResult {
360
- title?: string;
361
- link?: string;
362
- snippet?: string;
363
- date?: string;
364
- source?: string;
365
- imageUrl?: string;
366
- position?: number;
367
- }
368
-
369
- export interface ShoppingResult {
370
- title?: string;
371
- source?: string;
372
- link?: string;
373
- price?: string;
374
- delivery?: string;
375
- imageUrl?: string;
376
- rating?: number;
377
- ratingCount?: number;
378
- offers?: string;
379
- productId?: string;
380
- position?: number;
381
- }
382
-
383
- export interface ScholarResult {
384
- title?: string;
385
- link?: string;
386
- publicationInfo?: string;
387
- snippet?: string;
388
- year?: number;
389
- citedBy?: number;
390
- }
391
-
392
- export interface ImageResult {
393
- title?: string;
394
- imageUrl?: string;
395
- imageWidth?: number;
396
- imageHeight?: number;
397
- thumbnailUrl?: string;
398
- thumbnailWidth?: number;
399
- thumbnailHeight?: number;
400
- source?: string;
401
- domain?: string;
402
- link?: string;
403
- googleUrl?: string;
404
- position?: number;
405
- }
406
-
407
- export interface SerperSearchPayload extends SerperSearchInput {
408
- /**
409
- * Search type/vertical
410
- * Options: "search" (web), "images", "news", "places", "videos"
411
- */
412
- type?: 'search' | 'images' | 'news' | 'places' | 'videos';
413
-
414
- /**
415
- * Starting index for search results pagination (used instead of page)
416
- */
417
- start?: number;
418
-
419
- /**
420
- * Filtering for safe search
421
- * Options: "off", "moderate", "active"
422
- */
423
- safe?: 'off' | 'moderate' | 'active';
424
- }
425
-
426
- export type SerperSearchParameters = Pick<SerperSearchPayload, 'q' | 'type'> & {
427
- engine: 'google';
428
- };
429
-
430
- export interface OrganicResult {
431
- position?: number;
432
- title?: string;
433
- link: string;
434
- snippet?: string;
435
- date?: string;
436
- sitelinks?: Array<{
437
- title: string;
438
- link: string;
439
- }>;
440
- }
441
-
442
- export interface TopStoryResult {
443
- title?: string;
444
- link: string;
445
- source?: string;
446
- date?: string;
447
- imageUrl?: string;
448
- }
449
- export interface KnowledgeGraphResult {
450
- title?: string;
451
- type?: string;
452
- imageUrl?: string;
453
- description?: string;
454
- descriptionSource?: string;
455
- descriptionLink?: string;
456
- attributes?: Record<string, string>;
457
- website?: string;
458
- }
459
-
460
- export interface AnswerBoxResult {
461
- title?: string;
462
- snippet?: string;
463
- snippetHighlighted?: string[];
464
- link?: string;
465
- date?: string;
466
- }
467
-
468
- export interface PeopleAlsoAskResult {
469
- question?: string;
470
- snippet?: string;
471
- title?: string;
472
- link?: string;
473
- }
474
-
475
- export type RelatedSearches = Array<{ query: string }>;
476
-
477
- export interface SerperSearchInput {
478
- /**
479
- * The search query string
480
- */
481
- q: string;
482
-
483
- /**
484
- * Country code for localized results
485
- * Examples: "us", "uk", "ca", "de", etc.
486
- */
487
- gl?: string;
488
-
489
- /**
490
- * Interface language
491
- * Examples: "en", "fr", "de", etc.
492
- */
493
- hl?: string;
494
-
495
- /**
496
- * Number of results to return (up to 100)
497
- */
498
- num?: number;
499
- /**
500
- * Specific location for contextual results
501
- * Example: "New York, NY"
502
- */
503
- location?: string;
504
-
505
- /**
506
- * Search autocorrection setting
507
- */
508
- autocorrect?: boolean;
509
- page?: number;
510
- /**
511
- * Date range for search results
512
- * Options: "h" (past hour), "d" (past 24 hours), "w" (past week),
513
- * "m" (past month), "y" (past year)
514
- * `qdr:${DATE_RANGE}`
515
- */
516
- tbs?: string;
517
- }
518
-
519
- export type SerperResultData = {
520
- searchParameters: SerperSearchPayload;
521
- organic?: OrganicResult[];
522
- topStories?: TopStoryResult[];
523
- images?: ImageResult[];
524
- videos?: VideoResult[];
525
- places?: PlaceResult[];
526
- news?: NewsResult[];
527
- shopping?: ShoppingResult[];
528
- peopleAlsoAsk?: PeopleAlsoAskResult[];
529
- relatedSearches?: RelatedSearches;
530
- knowledgeGraph?: KnowledgeGraphResult;
531
- answerBox?: AnswerBoxResult;
532
- credits?: number;
533
- };
534
-
535
- /** SearXNG */
536
-
537
- export interface SearxNGSearchPayload {
538
- /**
539
- * The search query string
540
- * Supports syntax specific to different search engines
541
- * Example: "site:github.com SearXNG"
542
- */
543
- q: string;
544
-
545
- /**
546
- * Comma-separated list of search categories
547
- * Example: "general,images,news"
548
- */
549
- categories?: string;
550
-
551
- /**
552
- * Comma-separated list of search engines to use
553
- * Example: "google,bing,duckduckgo"
554
- */
555
- engines?: string;
556
-
557
- /**
558
- * Code of the language for search results
559
- * Example: "en", "fr", "de", "es"
560
- */
561
- language?: string;
562
-
563
- /**
564
- * Search page number
565
- * Default: 1
566
- */
567
- pageno?: number;
568
-
569
- /**
570
- * Time range filter for search results
571
- * Options: "day", "month", "year"
572
- */
573
- time_range?: 'day' | 'month' | 'year';
574
-
575
- /**
576
- * Output format of results
577
- * Options: "json", "csv", "rss"
578
- */
579
- format?: 'json' | 'csv' | 'rss';
580
-
581
- /**
582
- * Open search results on new tab
583
- * Options: `0` (off), `1` (on)
584
- */
585
- results_on_new_tab?: 0 | 1;
586
-
587
- /**
588
- * Proxy image results through SearxNG
589
- * Options: true, false
590
- */
591
- image_proxy?: boolean;
592
-
593
- /**
594
- * Service for autocomplete suggestions
595
- * Options: "google", "dbpedia", "duckduckgo", "mwmbl",
596
- * "startpage", "wikipedia", "stract", "swisscows", "qwant"
597
- */
598
- autocomplete?: string;
599
-
600
- /**
601
- * Safe search filtering level
602
- * Options: "0" (off), "1" (moderate), "2" (strict)
603
- */
604
- safesearch?: 0 | 1 | 2;
605
-
606
- /**
607
- * Theme to use for results page
608
- * Default: "simple" (other themes may be available per instance)
609
- */
610
- theme?: string;
611
-
612
- /**
613
- * List of enabled plugins
614
- * Default: "Hash_plugin,Self_Information,Tracker_URL_remover,Ahmia_blacklist"
615
- */
616
- enabled_plugins?: string;
617
-
618
- /**
619
- * List of disabled plugins
620
- */
621
- disabled_plugins?: string;
622
-
623
- /**
624
- * List of enabled engines
625
- */
626
- enabled_engines?: string;
627
-
628
- /**
629
- * List of disabled engines
630
- */
631
- disabled_engines?: string;
632
- }
633
-
634
- export interface SearXNGResult {
635
- title?: string;
636
- url?: string;
637
- content?: string;
638
- publishedDate?: string;
639
- img_src?: string;
640
- score?: number;
641
- engine?: string;
642
- category?: string;
643
- thumbnail?: string;
644
- priority?: string;
645
- engines?: string[];
646
- positions?: number[];
647
- template?: string;
648
- parsed_url?: string[];
649
- }
650
-
651
- export type ProcessSourcesFields = {
652
- result: SearchResult;
653
- numElements: number;
654
- query: string;
655
- news: boolean;
656
- proMode: boolean;
657
- onGetHighlights: SearchToolConfig['onGetHighlights'];
658
- };
659
-
660
- export type SearchToolSchema = z.ZodObject<
661
- {
662
- query: z.ZodString;
663
- date: z.ZodOptional<z.ZodNativeEnum<typeof DATE_RANGE>>;
664
- country?: z.ZodOptional<z.ZodString>;
665
- images: z.ZodOptional<z.ZodBoolean>;
666
- videos: z.ZodOptional<z.ZodBoolean>;
667
- news: z.ZodOptional<z.ZodBoolean>;
668
- },
669
- 'strip',
670
- z.ZodTypeAny,
671
- {
672
- query: string;
673
- date?: DATE_RANGE;
674
- country?: unknown;
675
- images?: boolean;
676
- videos?: boolean;
677
- news?: boolean;
678
- },
679
- {
680
- query: string;
681
- date?: DATE_RANGE;
682
- country?: unknown;
683
- images?: boolean;
684
- videos?: boolean;
685
- news?: boolean;
686
- }
687
- >;
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 ScraperProvider = 'firecrawl' | 'serper';
9
+ export type RerankerType = 'infinity' | 'jina' | 'cohere' | 'none';
10
+
11
+ export interface Highlight {
12
+ score: number;
13
+ text: string;
14
+ references?: UsedReferences;
15
+ }
16
+
17
+ export type ProcessedSource = {
18
+ content?: string;
19
+ attribution?: string;
20
+ references?: References;
21
+ highlights?: Highlight[];
22
+ processed?: boolean;
23
+ };
24
+
25
+ export type ProcessedOrganic = OrganicResult & ProcessedSource;
26
+ export type ProcessedTopStory = TopStoryResult & ProcessedSource;
27
+ export type ValidSource = ProcessedOrganic | ProcessedTopStory;
28
+
29
+ export type ResultReference = {
30
+ link: string;
31
+ type: 'link' | 'image' | 'video';
32
+ title?: string;
33
+ attribution?: string;
34
+ };
35
+ export interface SearchResultData {
36
+ turn?: number;
37
+ organic?: ProcessedOrganic[];
38
+ topStories?: ProcessedTopStory[];
39
+ images?: ImageResult[];
40
+ videos?: VideoResult[];
41
+ places?: PlaceResult[];
42
+ news?: NewsResult[];
43
+ shopping?: ShoppingResult[];
44
+ knowledgeGraph?: KnowledgeGraphResult;
45
+ answerBox?: AnswerBoxResult;
46
+ peopleAlsoAsk?: PeopleAlsoAskResult[];
47
+ relatedSearches?: Array<{ query: string }>;
48
+ references?: ResultReference[];
49
+ error?: string;
50
+ }
51
+
52
+ export interface SearchResult {
53
+ data?: SearchResultData;
54
+ error?: string;
55
+ success: boolean;
56
+ }
57
+
58
+ export interface Source {
59
+ link: string;
60
+ html?: string;
61
+ title?: string;
62
+ snippet?: string;
63
+ date?: string;
64
+ }
65
+
66
+ export interface SearchConfig {
67
+ searchProvider?: SearchProvider;
68
+ serperApiKey?: string;
69
+ searxngInstanceUrl?: string;
70
+ searxngApiKey?: string;
71
+ }
72
+
73
+ export type References = {
74
+ links: MediaReference[];
75
+ images: MediaReference[];
76
+ videos: MediaReference[];
77
+ };
78
+ export interface ScrapeResult {
79
+ url: string;
80
+ error?: boolean;
81
+ content: string;
82
+ attribution?: string;
83
+ references?: References;
84
+ highlights?: Highlight[];
85
+ }
86
+
87
+ export interface ProcessSourcesConfig {
88
+ topResults?: number;
89
+ strategies?: string[];
90
+ filterContent?: boolean;
91
+ reranker?: BaseReranker;
92
+ logger?: Logger;
93
+ }
94
+
95
+ export interface FirecrawlConfig {
96
+ firecrawlApiKey?: string;
97
+ firecrawlApiUrl?: string;
98
+ firecrawlVersion?: string;
99
+ firecrawlOptions?: FirecrawlScraperConfig;
100
+ }
101
+
102
+ export interface SerperScraperConfig {
103
+ apiKey?: string;
104
+ apiUrl?: string;
105
+ timeout?: number;
106
+ logger?: Logger;
107
+ includeMarkdown?: boolean;
108
+ }
109
+
110
+ export interface ScraperContentResult {
111
+ content: string;
112
+ }
113
+
114
+ export interface ScraperExtractionResult {
115
+ no_extraction: ScraperContentResult;
116
+ }
117
+
118
+ export interface JinaRerankerResult {
119
+ index: number;
120
+ relevance_score: number;
121
+ document?: string | { text: string };
122
+ }
123
+
124
+ export interface JinaRerankerResponse {
125
+ model: string;
126
+ usage: {
127
+ total_tokens: number;
128
+ };
129
+ results: JinaRerankerResult[];
130
+ }
131
+
132
+ export interface CohereRerankerResult {
133
+ index: number;
134
+ relevance_score: number;
135
+ }
136
+
137
+ export interface CohereRerankerResponse {
138
+ results: CohereRerankerResult[];
139
+ id: string;
140
+ meta: {
141
+ api_version: {
142
+ version: string;
143
+ is_experimental: boolean;
144
+ };
145
+ billed_units: {
146
+ search_units: number;
147
+ };
148
+ };
149
+ }
150
+
151
+ export type SafeSearchLevel = 0 | 1 | 2;
152
+
153
+ export type Logger = WinstonLogger;
154
+ export interface SearchToolConfig
155
+ extends SearchConfig,
156
+ ProcessSourcesConfig,
157
+ FirecrawlConfig {
158
+ logger?: Logger;
159
+ safeSearch?: SafeSearchLevel;
160
+ jinaApiKey?: string;
161
+ jinaApiUrl?: string;
162
+ cohereApiKey?: string;
163
+ rerankerType?: RerankerType;
164
+ scraperProvider?: ScraperProvider;
165
+ scraperTimeout?: number;
166
+ serperScraperOptions?: SerperScraperConfig;
167
+ onSearchResults?: (
168
+ results: SearchResult,
169
+ runnableConfig?: RunnableConfig
170
+ ) => void;
171
+ onGetHighlights?: (link: string) => void;
172
+ }
173
+ export interface MediaReference {
174
+ originalUrl: string;
175
+ title?: string;
176
+ text?: string;
177
+ }
178
+
179
+ export type UsedReferences = {
180
+ type: 'link' | 'image' | 'video';
181
+ originalIndex: number;
182
+ reference: MediaReference;
183
+ }[];
184
+
185
+ /** Base Scraper Interface */
186
+ export interface BaseScraper {
187
+ scrapeUrl(
188
+ url: string,
189
+ options?: unknown
190
+ ): Promise<[string, FirecrawlScrapeResponse | SerperScrapeResponse]>;
191
+ extractContent(
192
+ response: FirecrawlScrapeResponse | SerperScrapeResponse
193
+ ): [string, undefined | References];
194
+ extractMetadata(
195
+ response: FirecrawlScrapeResponse | SerperScrapeResponse
196
+ ):
197
+ | ScrapeMetadata
198
+ | Record<string, string | number | boolean | null | undefined>;
199
+ }
200
+
201
+ /** Firecrawl */
202
+ export type FirecrawlScrapeOptions = Omit<
203
+ FirecrawlScraperConfig,
204
+ 'apiKey' | 'apiUrl' | 'version' | 'logger'
205
+ >;
206
+
207
+ export type SerperScrapeOptions = Omit<
208
+ SerperScraperConfig,
209
+ 'apiKey' | 'apiUrl' | 'logger'
210
+ >;
211
+
212
+ export interface ScrapeMetadata {
213
+ // Core source information
214
+ sourceURL?: string;
215
+ url?: string;
216
+ scrapeId?: string;
217
+ statusCode?: number;
218
+ // Basic metadata
219
+ title?: string;
220
+ description?: string;
221
+ language?: string;
222
+ favicon?: string;
223
+ viewport?: string;
224
+ robots?: string;
225
+ 'theme-color'?: string;
226
+ // Open Graph metadata
227
+ 'og:url'?: string;
228
+ 'og:title'?: string;
229
+ 'og:description'?: string;
230
+ 'og:type'?: string;
231
+ 'og:image'?: string;
232
+ 'og:image:width'?: string;
233
+ 'og:image:height'?: string;
234
+ 'og:site_name'?: string;
235
+ ogUrl?: string;
236
+ ogTitle?: string;
237
+ ogDescription?: string;
238
+ ogImage?: string;
239
+ ogSiteName?: string;
240
+ // Article metadata
241
+ 'article:author'?: string;
242
+ 'article:published_time'?: string;
243
+ 'article:modified_time'?: string;
244
+ 'article:section'?: string;
245
+ 'article:tag'?: string;
246
+ 'article:publisher'?: string;
247
+ publishedTime?: string;
248
+ modifiedTime?: string;
249
+ // Twitter metadata
250
+ 'twitter:site'?: string | boolean | number | null;
251
+ 'twitter:creator'?: string;
252
+ 'twitter:card'?: string;
253
+ 'twitter:image'?: string;
254
+ 'twitter:dnt'?: string;
255
+ 'twitter:app:name:iphone'?: string;
256
+ 'twitter:app:id:iphone'?: string;
257
+ 'twitter:app:url:iphone'?: string;
258
+ 'twitter:app:name:ipad'?: string;
259
+ 'twitter:app:id:ipad'?: string;
260
+ 'twitter:app:url:ipad'?: string;
261
+ 'twitter:app:name:googleplay'?: string;
262
+ 'twitter:app:id:googleplay'?: string;
263
+ 'twitter:app:url:googleplay'?: string;
264
+ // Facebook metadata
265
+ 'fb:app_id'?: string;
266
+ // App links
267
+ 'al:ios:url'?: string;
268
+ 'al:ios:app_name'?: string;
269
+ 'al:ios:app_store_id'?: string;
270
+ // Allow for additional properties that might be present
271
+ [key: string]: string | number | boolean | null | undefined;
272
+ }
273
+
274
+ export interface FirecrawlScrapeResponse {
275
+ success: boolean;
276
+ data?: {
277
+ markdown?: string;
278
+ html?: string;
279
+ rawHtml?: string;
280
+ screenshot?: string;
281
+ links?: string[];
282
+ metadata?: ScrapeMetadata;
283
+ };
284
+ error?: string;
285
+ }
286
+
287
+ export interface SerperScrapeResponse {
288
+ success: boolean;
289
+ data?: {
290
+ text?: string;
291
+ markdown?: string;
292
+ metadata?: Record<string, string | number | boolean | null | undefined>;
293
+ credits?: number;
294
+ };
295
+ error?: string;
296
+ }
297
+
298
+ export interface FirecrawlScraperConfig {
299
+ apiKey?: string;
300
+ apiUrl?: string;
301
+ version?: string;
302
+ formats?: string[];
303
+ timeout?: number;
304
+ logger?: Logger;
305
+ includeTags?: string[];
306
+ excludeTags?: string[];
307
+ waitFor?: number;
308
+ maxAge?: number;
309
+ mobile?: boolean;
310
+ skipTlsVerification?: boolean;
311
+ blockAds?: boolean;
312
+ removeBase64Images?: boolean;
313
+ parsePDF?: boolean;
314
+ storeInCache?: boolean;
315
+ zeroDataRetention?: boolean;
316
+ headers?: Record<string, string>;
317
+ location?: { country?: string; languages?: string[] };
318
+ onlyMainContent?: boolean;
319
+ changeTrackingOptions?: object;
320
+ }
321
+
322
+ export type GetSourcesParams = {
323
+ query: string;
324
+ date?: DATE_RANGE;
325
+ country?: string;
326
+ numResults?: number;
327
+ safeSearch?: SearchToolConfig['safeSearch'];
328
+ images?: boolean;
329
+ videos?: boolean;
330
+ news?: boolean;
331
+ type?: 'search' | 'images' | 'videos' | 'news';
332
+ };
333
+
334
+ /** Serper API */
335
+ export interface VideoResult {
336
+ title?: string;
337
+ link?: string;
338
+ snippet?: string;
339
+ imageUrl?: string;
340
+ duration?: string;
341
+ source?: string;
342
+ channel?: string;
343
+ date?: string;
344
+ position?: number;
345
+ }
346
+
347
+ export interface PlaceResult {
348
+ position?: number;
349
+ name?: string;
350
+ address?: string;
351
+ latitude?: number;
352
+ longitude?: number;
353
+ rating?: number;
354
+ ratingCount?: number;
355
+ category?: string;
356
+ identifier?: string;
357
+ }
358
+
359
+ export interface NewsResult {
360
+ title?: string;
361
+ link?: string;
362
+ snippet?: string;
363
+ date?: string;
364
+ source?: string;
365
+ imageUrl?: string;
366
+ position?: number;
367
+ }
368
+
369
+ export interface ShoppingResult {
370
+ title?: string;
371
+ source?: string;
372
+ link?: string;
373
+ price?: string;
374
+ delivery?: string;
375
+ imageUrl?: string;
376
+ rating?: number;
377
+ ratingCount?: number;
378
+ offers?: string;
379
+ productId?: string;
380
+ position?: number;
381
+ }
382
+
383
+ export interface ScholarResult {
384
+ title?: string;
385
+ link?: string;
386
+ publicationInfo?: string;
387
+ snippet?: string;
388
+ year?: number;
389
+ citedBy?: number;
390
+ }
391
+
392
+ export interface ImageResult {
393
+ title?: string;
394
+ imageUrl?: string;
395
+ imageWidth?: number;
396
+ imageHeight?: number;
397
+ thumbnailUrl?: string;
398
+ thumbnailWidth?: number;
399
+ thumbnailHeight?: number;
400
+ source?: string;
401
+ domain?: string;
402
+ link?: string;
403
+ googleUrl?: string;
404
+ position?: number;
405
+ }
406
+
407
+ export interface SerperSearchPayload extends SerperSearchInput {
408
+ /**
409
+ * Search type/vertical
410
+ * Options: "search" (web), "images", "news", "places", "videos"
411
+ */
412
+ type?: 'search' | 'images' | 'news' | 'places' | 'videos';
413
+
414
+ /**
415
+ * Starting index for search results pagination (used instead of page)
416
+ */
417
+ start?: number;
418
+
419
+ /**
420
+ * Filtering for safe search
421
+ * Options: "off", "moderate", "active"
422
+ */
423
+ safe?: 'off' | 'moderate' | 'active';
424
+ }
425
+
426
+ export type SerperSearchParameters = Pick<SerperSearchPayload, 'q' | 'type'> & {
427
+ engine: 'google';
428
+ };
429
+
430
+ export interface OrganicResult {
431
+ position?: number;
432
+ title?: string;
433
+ link: string;
434
+ snippet?: string;
435
+ date?: string;
436
+ sitelinks?: Array<{
437
+ title: string;
438
+ link: string;
439
+ }>;
440
+ }
441
+
442
+ export interface TopStoryResult {
443
+ title?: string;
444
+ link: string;
445
+ source?: string;
446
+ date?: string;
447
+ imageUrl?: string;
448
+ }
449
+ export interface KnowledgeGraphResult {
450
+ title?: string;
451
+ type?: string;
452
+ imageUrl?: string;
453
+ description?: string;
454
+ descriptionSource?: string;
455
+ descriptionLink?: string;
456
+ attributes?: Record<string, string>;
457
+ website?: string;
458
+ }
459
+
460
+ export interface AnswerBoxResult {
461
+ title?: string;
462
+ snippet?: string;
463
+ snippetHighlighted?: string[];
464
+ link?: string;
465
+ date?: string;
466
+ }
467
+
468
+ export interface PeopleAlsoAskResult {
469
+ question?: string;
470
+ snippet?: string;
471
+ title?: string;
472
+ link?: string;
473
+ }
474
+
475
+ export type RelatedSearches = Array<{ query: string }>;
476
+
477
+ export interface SerperSearchInput {
478
+ /**
479
+ * The search query string
480
+ */
481
+ q: string;
482
+
483
+ /**
484
+ * Country code for localized results
485
+ * Examples: "us", "uk", "ca", "de", etc.
486
+ */
487
+ gl?: string;
488
+
489
+ /**
490
+ * Interface language
491
+ * Examples: "en", "fr", "de", etc.
492
+ */
493
+ hl?: string;
494
+
495
+ /**
496
+ * Number of results to return (up to 100)
497
+ */
498
+ num?: number;
499
+ /**
500
+ * Specific location for contextual results
501
+ * Example: "New York, NY"
502
+ */
503
+ location?: string;
504
+
505
+ /**
506
+ * Search autocorrection setting
507
+ */
508
+ autocorrect?: boolean;
509
+ page?: number;
510
+ /**
511
+ * Date range for search results
512
+ * Options: "h" (past hour), "d" (past 24 hours), "w" (past week),
513
+ * "m" (past month), "y" (past year)
514
+ * `qdr:${DATE_RANGE}`
515
+ */
516
+ tbs?: string;
517
+ }
518
+
519
+ export type SerperResultData = {
520
+ searchParameters: SerperSearchPayload;
521
+ organic?: OrganicResult[];
522
+ topStories?: TopStoryResult[];
523
+ images?: ImageResult[];
524
+ videos?: VideoResult[];
525
+ places?: PlaceResult[];
526
+ news?: NewsResult[];
527
+ shopping?: ShoppingResult[];
528
+ peopleAlsoAsk?: PeopleAlsoAskResult[];
529
+ relatedSearches?: RelatedSearches;
530
+ knowledgeGraph?: KnowledgeGraphResult;
531
+ answerBox?: AnswerBoxResult;
532
+ credits?: number;
533
+ };
534
+
535
+ /** SearXNG */
536
+
537
+ export interface SearxNGSearchPayload {
538
+ /**
539
+ * The search query string
540
+ * Supports syntax specific to different search engines
541
+ * Example: "site:github.com SearXNG"
542
+ */
543
+ q: string;
544
+
545
+ /**
546
+ * Comma-separated list of search categories
547
+ * Example: "general,images,news"
548
+ */
549
+ categories?: string;
550
+
551
+ /**
552
+ * Comma-separated list of search engines to use
553
+ * Example: "google,bing,duckduckgo"
554
+ */
555
+ engines?: string;
556
+
557
+ /**
558
+ * Code of the language for search results
559
+ * Example: "en", "fr", "de", "es"
560
+ */
561
+ language?: string;
562
+
563
+ /**
564
+ * Search page number
565
+ * Default: 1
566
+ */
567
+ pageno?: number;
568
+
569
+ /**
570
+ * Time range filter for search results
571
+ * Options: "day", "month", "year"
572
+ */
573
+ time_range?: 'day' | 'month' | 'year';
574
+
575
+ /**
576
+ * Output format of results
577
+ * Options: "json", "csv", "rss"
578
+ */
579
+ format?: 'json' | 'csv' | 'rss';
580
+
581
+ /**
582
+ * Open search results on new tab
583
+ * Options: `0` (off), `1` (on)
584
+ */
585
+ results_on_new_tab?: 0 | 1;
586
+
587
+ /**
588
+ * Proxy image results through SearxNG
589
+ * Options: true, false
590
+ */
591
+ image_proxy?: boolean;
592
+
593
+ /**
594
+ * Service for autocomplete suggestions
595
+ * Options: "google", "dbpedia", "duckduckgo", "mwmbl",
596
+ * "startpage", "wikipedia", "stract", "swisscows", "qwant"
597
+ */
598
+ autocomplete?: string;
599
+
600
+ /**
601
+ * Safe search filtering level
602
+ * Options: "0" (off), "1" (moderate), "2" (strict)
603
+ */
604
+ safesearch?: 0 | 1 | 2;
605
+
606
+ /**
607
+ * Theme to use for results page
608
+ * Default: "simple" (other themes may be available per instance)
609
+ */
610
+ theme?: string;
611
+
612
+ /**
613
+ * List of enabled plugins
614
+ * Default: "Hash_plugin,Self_Information,Tracker_URL_remover,Ahmia_blacklist"
615
+ */
616
+ enabled_plugins?: string;
617
+
618
+ /**
619
+ * List of disabled plugins
620
+ */
621
+ disabled_plugins?: string;
622
+
623
+ /**
624
+ * List of enabled engines
625
+ */
626
+ enabled_engines?: string;
627
+
628
+ /**
629
+ * List of disabled engines
630
+ */
631
+ disabled_engines?: string;
632
+ }
633
+
634
+ export interface SearXNGResult {
635
+ title?: string;
636
+ url?: string;
637
+ content?: string;
638
+ publishedDate?: string;
639
+ img_src?: string;
640
+ score?: number;
641
+ engine?: string;
642
+ category?: string;
643
+ thumbnail?: string;
644
+ priority?: string;
645
+ engines?: string[];
646
+ positions?: number[];
647
+ template?: string;
648
+ parsed_url?: string[];
649
+ }
650
+
651
+ export type ProcessSourcesFields = {
652
+ result: SearchResult;
653
+ numElements: number;
654
+ query: string;
655
+ news: boolean;
656
+ proMode: boolean;
657
+ onGetHighlights: SearchToolConfig['onGetHighlights'];
658
+ /** Skip scraping if content was already extracted directly (e.g., direct URL extraction) */
659
+ skipScraping?: boolean;
660
+ };
661
+
662
+ export type SearchToolSchema = z.ZodObject<
663
+ {
664
+ query: z.ZodString;
665
+ date: z.ZodOptional<z.ZodNativeEnum<typeof DATE_RANGE>>;
666
+ country?: z.ZodOptional<z.ZodString>;
667
+ images: z.ZodOptional<z.ZodBoolean>;
668
+ videos: z.ZodOptional<z.ZodBoolean>;
669
+ news: z.ZodOptional<z.ZodBoolean>;
670
+ },
671
+ 'strip',
672
+ z.ZodTypeAny,
673
+ {
674
+ query: string;
675
+ date?: DATE_RANGE;
676
+ country?: unknown;
677
+ images?: boolean;
678
+ videos?: boolean;
679
+ news?: boolean;
680
+ },
681
+ {
682
+ query: string;
683
+ date?: DATE_RANGE;
684
+ country?: unknown;
685
+ images?: boolean;
686
+ videos?: boolean;
687
+ news?: boolean;
688
+ }
689
+ >;