valyu-js 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -27,6 +27,7 @@ interface SearchOptions {
27
27
  endDate?: string;
28
28
  countryCode?: CountryCode;
29
29
  responseLength?: ResponseLength;
30
+ fastMode?: boolean;
30
31
  }
31
32
  interface SearchResponse {
32
33
  success: boolean;
@@ -46,7 +47,7 @@ interface FeedbackResponse {
46
47
  success: boolean;
47
48
  error?: string;
48
49
  }
49
- type ExtractEffort = "normal" | "high";
50
+ type ExtractEffort = "normal" | "high" | "auto";
50
51
  type ContentResponseLength = "short" | "medium" | "large" | "max" | number;
51
52
  interface ContentsOptions {
52
53
  summary?: boolean | string | object;
@@ -78,6 +79,48 @@ interface ContentsResponse {
78
79
  total_characters?: number;
79
80
  isProvisioning?: boolean;
80
81
  }
82
+ interface AnswerOptions {
83
+ structuredOutput?: Record<string, any>;
84
+ systemInstructions?: string;
85
+ searchType?: SearchType;
86
+ dataMaxPrice?: number;
87
+ countryCode?: CountryCode;
88
+ includedSources?: string[];
89
+ excludedSources?: string[];
90
+ startDate?: string;
91
+ endDate?: string;
92
+ fastMode?: boolean;
93
+ }
94
+ interface SearchMetadata {
95
+ tx_ids: string[];
96
+ number_of_results: number;
97
+ total_characters: number;
98
+ }
99
+ interface AIUsage {
100
+ input_tokens: number;
101
+ output_tokens: number;
102
+ }
103
+ interface Cost {
104
+ total_deduction_dollars: number;
105
+ search_deduction_dollars: number;
106
+ ai_deduction_dollars: number;
107
+ }
108
+ interface AnswerSuccessResponse {
109
+ success: true;
110
+ ai_tx_id: string;
111
+ original_query: string;
112
+ contents: string | Record<string, any>;
113
+ data_type: "structured" | "unstructured";
114
+ search_results: SearchResult[];
115
+ search_metadata: SearchMetadata;
116
+ ai_usage: AIUsage;
117
+ cost: Cost;
118
+ }
119
+ interface AnswerErrorResponse {
120
+ success: false;
121
+ error: string;
122
+ }
123
+ type AnswerResponse = AnswerSuccessResponse | AnswerErrorResponse;
81
124
 
82
125
  declare class Valyu {
83
126
  private baseUrl;
@@ -87,6 +130,26 @@ declare class Valyu {
87
130
  * Validates date format (YYYY-MM-DD)
88
131
  */
89
132
  private validateDateFormat;
133
+ /**
134
+ * Validates if a string is a valid URL
135
+ */
136
+ private validateUrl;
137
+ /**
138
+ * Validates if a string is a valid domain (with optional path)
139
+ */
140
+ private validateDomain;
141
+ /**
142
+ * Validates if a string is a valid dataset identifier (provider/datasetname)
143
+ */
144
+ private validateDatasetId;
145
+ /**
146
+ * Validates source strings (domains, URLs, or dataset IDs)
147
+ */
148
+ private validateSource;
149
+ /**
150
+ * Validates an array of source strings
151
+ */
152
+ private validateSources;
90
153
  /**
91
154
  * Search for information using the Valyu DeepSearch API
92
155
  * @param query - The search query string
@@ -103,6 +166,7 @@ declare class Valyu {
103
166
  * @param options.endDate - End date filter (YYYY-MM-DD format)
104
167
  * @param options.countryCode - Country code filter for search results
105
168
  * @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
169
+ * @param options.fastMode - Fast mode for quicker but shorter results (default: false)
106
170
  * @returns Promise resolving to search results
107
171
  */
108
172
  search(query: string, options?: SearchOptions): Promise<SearchResponse>;
@@ -117,6 +181,23 @@ declare class Valyu {
117
181
  * @returns Promise resolving to content extraction results
118
182
  */
119
183
  contents(urls: string[], options?: ContentsOptions): Promise<ContentsResponse>;
184
+ /**
185
+ * Get AI-powered answers using the Valyu Answer API
186
+ * @param query - The question or query string
187
+ * @param options - Answer configuration options
188
+ * @param options.structuredOutput - JSON Schema object for structured responses
189
+ * @param options.systemInstructions - Custom system-level instructions (max 2000 chars)
190
+ * @param options.searchType - Type of search: "web", "proprietary", or "all"
191
+ * @param options.dataMaxPrice - Maximum spend (USD) for data retrieval
192
+ * @param options.countryCode - Country code filter for search results
193
+ * @param options.includedSources - List of specific sources to include
194
+ * @param options.excludedSources - List of URLs/domains to exclude from search results
195
+ * @param options.startDate - Start date filter (YYYY-MM-DD format)
196
+ * @param options.endDate - End date filter (YYYY-MM-DD format)
197
+ * @param options.fastMode - Fast mode for quicker but shorter results (default: false)
198
+ * @returns Promise resolving to answer response
199
+ */
200
+ answer(query: string, options?: AnswerOptions): Promise<AnswerResponse>;
120
201
  }
121
202
 
122
- export { type ContentResponseLength, type ContentResult, type ContentsOptions, type ContentsResponse, type CountryCode, type ExtractEffort, type FeedbackResponse, type FeedbackSentiment, type ResponseLength, type SearchOptions, type SearchResponse, type SearchType, Valyu };
203
+ export { type AIUsage, type AnswerErrorResponse, type AnswerOptions, type AnswerResponse, type AnswerSuccessResponse, type ContentResponseLength, type ContentResult, type ContentsOptions, type ContentsResponse, type Cost, type CountryCode, type ExtractEffort, type FeedbackResponse, type FeedbackSentiment, type ResponseLength, type SearchMetadata, type SearchOptions, type SearchResponse, type SearchType, Valyu };
package/dist/index.d.ts CHANGED
@@ -27,6 +27,7 @@ interface SearchOptions {
27
27
  endDate?: string;
28
28
  countryCode?: CountryCode;
29
29
  responseLength?: ResponseLength;
30
+ fastMode?: boolean;
30
31
  }
31
32
  interface SearchResponse {
32
33
  success: boolean;
@@ -46,7 +47,7 @@ interface FeedbackResponse {
46
47
  success: boolean;
47
48
  error?: string;
48
49
  }
49
- type ExtractEffort = "normal" | "high";
50
+ type ExtractEffort = "normal" | "high" | "auto";
50
51
  type ContentResponseLength = "short" | "medium" | "large" | "max" | number;
51
52
  interface ContentsOptions {
52
53
  summary?: boolean | string | object;
@@ -78,6 +79,48 @@ interface ContentsResponse {
78
79
  total_characters?: number;
79
80
  isProvisioning?: boolean;
80
81
  }
82
+ interface AnswerOptions {
83
+ structuredOutput?: Record<string, any>;
84
+ systemInstructions?: string;
85
+ searchType?: SearchType;
86
+ dataMaxPrice?: number;
87
+ countryCode?: CountryCode;
88
+ includedSources?: string[];
89
+ excludedSources?: string[];
90
+ startDate?: string;
91
+ endDate?: string;
92
+ fastMode?: boolean;
93
+ }
94
+ interface SearchMetadata {
95
+ tx_ids: string[];
96
+ number_of_results: number;
97
+ total_characters: number;
98
+ }
99
+ interface AIUsage {
100
+ input_tokens: number;
101
+ output_tokens: number;
102
+ }
103
+ interface Cost {
104
+ total_deduction_dollars: number;
105
+ search_deduction_dollars: number;
106
+ ai_deduction_dollars: number;
107
+ }
108
+ interface AnswerSuccessResponse {
109
+ success: true;
110
+ ai_tx_id: string;
111
+ original_query: string;
112
+ contents: string | Record<string, any>;
113
+ data_type: "structured" | "unstructured";
114
+ search_results: SearchResult[];
115
+ search_metadata: SearchMetadata;
116
+ ai_usage: AIUsage;
117
+ cost: Cost;
118
+ }
119
+ interface AnswerErrorResponse {
120
+ success: false;
121
+ error: string;
122
+ }
123
+ type AnswerResponse = AnswerSuccessResponse | AnswerErrorResponse;
81
124
 
82
125
  declare class Valyu {
83
126
  private baseUrl;
@@ -87,6 +130,26 @@ declare class Valyu {
87
130
  * Validates date format (YYYY-MM-DD)
88
131
  */
89
132
  private validateDateFormat;
133
+ /**
134
+ * Validates if a string is a valid URL
135
+ */
136
+ private validateUrl;
137
+ /**
138
+ * Validates if a string is a valid domain (with optional path)
139
+ */
140
+ private validateDomain;
141
+ /**
142
+ * Validates if a string is a valid dataset identifier (provider/datasetname)
143
+ */
144
+ private validateDatasetId;
145
+ /**
146
+ * Validates source strings (domains, URLs, or dataset IDs)
147
+ */
148
+ private validateSource;
149
+ /**
150
+ * Validates an array of source strings
151
+ */
152
+ private validateSources;
90
153
  /**
91
154
  * Search for information using the Valyu DeepSearch API
92
155
  * @param query - The search query string
@@ -103,6 +166,7 @@ declare class Valyu {
103
166
  * @param options.endDate - End date filter (YYYY-MM-DD format)
104
167
  * @param options.countryCode - Country code filter for search results
105
168
  * @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
169
+ * @param options.fastMode - Fast mode for quicker but shorter results (default: false)
106
170
  * @returns Promise resolving to search results
107
171
  */
108
172
  search(query: string, options?: SearchOptions): Promise<SearchResponse>;
@@ -117,6 +181,23 @@ declare class Valyu {
117
181
  * @returns Promise resolving to content extraction results
118
182
  */
119
183
  contents(urls: string[], options?: ContentsOptions): Promise<ContentsResponse>;
184
+ /**
185
+ * Get AI-powered answers using the Valyu Answer API
186
+ * @param query - The question or query string
187
+ * @param options - Answer configuration options
188
+ * @param options.structuredOutput - JSON Schema object for structured responses
189
+ * @param options.systemInstructions - Custom system-level instructions (max 2000 chars)
190
+ * @param options.searchType - Type of search: "web", "proprietary", or "all"
191
+ * @param options.dataMaxPrice - Maximum spend (USD) for data retrieval
192
+ * @param options.countryCode - Country code filter for search results
193
+ * @param options.includedSources - List of specific sources to include
194
+ * @param options.excludedSources - List of URLs/domains to exclude from search results
195
+ * @param options.startDate - Start date filter (YYYY-MM-DD format)
196
+ * @param options.endDate - End date filter (YYYY-MM-DD format)
197
+ * @param options.fastMode - Fast mode for quicker but shorter results (default: false)
198
+ * @returns Promise resolving to answer response
199
+ */
200
+ answer(query: string, options?: AnswerOptions): Promise<AnswerResponse>;
120
201
  }
121
202
 
122
- export { type ContentResponseLength, type ContentResult, type ContentsOptions, type ContentsResponse, type CountryCode, type ExtractEffort, type FeedbackResponse, type FeedbackSentiment, type ResponseLength, type SearchOptions, type SearchResponse, type SearchType, Valyu };
203
+ export { type AIUsage, type AnswerErrorResponse, type AnswerOptions, type AnswerResponse, type AnswerSuccessResponse, type ContentResponseLength, type ContentResult, type ContentsOptions, type ContentsResponse, type Cost, type CountryCode, type ExtractEffort, type FeedbackResponse, type FeedbackSentiment, type ResponseLength, type SearchMetadata, type SearchOptions, type SearchResponse, type SearchType, Valyu };
package/dist/index.js CHANGED
@@ -59,6 +59,64 @@ var Valyu = class {
59
59
  const parsedDate = new Date(date);
60
60
  return parsedDate instanceof Date && !isNaN(parsedDate.getTime());
61
61
  }
62
+ /**
63
+ * Validates if a string is a valid URL
64
+ */
65
+ validateUrl(url) {
66
+ try {
67
+ new URL(url);
68
+ return true;
69
+ } catch {
70
+ return false;
71
+ }
72
+ }
73
+ /**
74
+ * Validates if a string is a valid domain (with optional path)
75
+ */
76
+ validateDomain(domain) {
77
+ const domainRegex = /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\/.+)?$/;
78
+ return domainRegex.test(domain);
79
+ }
80
+ /**
81
+ * Validates if a string is a valid dataset identifier (provider/datasetname)
82
+ */
83
+ validateDatasetId(datasetId) {
84
+ const parts = datasetId.split("/");
85
+ if (parts.length !== 2) return false;
86
+ const providerRegex = /^[a-zA-Z0-9_-]+$/;
87
+ const datasetRegex = /^[a-zA-Z0-9_-]+$/;
88
+ return providerRegex.test(parts[0]) && datasetRegex.test(parts[1]) && parts[0].length > 0 && parts[1].length > 0;
89
+ }
90
+ /**
91
+ * Validates source strings (domains, URLs, or dataset IDs)
92
+ */
93
+ validateSource(source) {
94
+ if (this.validateUrl(source)) {
95
+ return true;
96
+ }
97
+ if (this.validateDomain(source)) {
98
+ return true;
99
+ }
100
+ if (this.validateDatasetId(source)) {
101
+ return true;
102
+ }
103
+ return false;
104
+ }
105
+ /**
106
+ * Validates an array of source strings
107
+ */
108
+ validateSources(sources) {
109
+ const invalidSources = [];
110
+ for (const source of sources) {
111
+ if (!this.validateSource(source)) {
112
+ invalidSources.push(source);
113
+ }
114
+ }
115
+ return {
116
+ valid: invalidSources.length === 0,
117
+ invalidSources
118
+ };
119
+ }
62
120
  /**
63
121
  * Search for information using the Valyu DeepSearch API
64
122
  * @param query - The search query string
@@ -75,6 +133,7 @@ var Valyu = class {
75
133
  * @param options.endDate - End date filter (YYYY-MM-DD format)
76
134
  * @param options.countryCode - Country code filter for search results
77
135
  * @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
136
+ * @param options.fastMode - Fast mode for quicker but shorter results (default: false)
78
137
  * @returns Promise resolving to search results
79
138
  */
80
139
  async search(query, options = {}) {
@@ -141,6 +200,72 @@ var Valyu = class {
141
200
  total_characters: 0
142
201
  };
143
202
  }
203
+ if (options.includedSources !== void 0) {
204
+ if (!Array.isArray(options.includedSources)) {
205
+ return {
206
+ success: false,
207
+ error: "includedSources must be an array",
208
+ tx_id: null,
209
+ query,
210
+ results: [],
211
+ results_by_source: { web: 0, proprietary: 0 },
212
+ total_deduction_pcm: 0,
213
+ total_deduction_dollars: 0,
214
+ total_characters: 0
215
+ };
216
+ }
217
+ const includedSourcesValidation = this.validateSources(
218
+ options.includedSources
219
+ );
220
+ if (!includedSourcesValidation.valid) {
221
+ return {
222
+ success: false,
223
+ error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(
224
+ ", "
225
+ )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,
226
+ tx_id: null,
227
+ query,
228
+ results: [],
229
+ results_by_source: { web: 0, proprietary: 0 },
230
+ total_deduction_pcm: 0,
231
+ total_deduction_dollars: 0,
232
+ total_characters: 0
233
+ };
234
+ }
235
+ }
236
+ if (options.excludeSources !== void 0) {
237
+ if (!Array.isArray(options.excludeSources)) {
238
+ return {
239
+ success: false,
240
+ error: "excludeSources must be an array",
241
+ tx_id: null,
242
+ query,
243
+ results: [],
244
+ results_by_source: { web: 0, proprietary: 0 },
245
+ total_deduction_pcm: 0,
246
+ total_deduction_dollars: 0,
247
+ total_characters: 0
248
+ };
249
+ }
250
+ const excludeSourcesValidation = this.validateSources(
251
+ options.excludeSources
252
+ );
253
+ if (!excludeSourcesValidation.valid) {
254
+ return {
255
+ success: false,
256
+ error: `Invalid excludeSources format. Invalid sources: ${excludeSourcesValidation.invalidSources.join(
257
+ ", "
258
+ )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,
259
+ tx_id: null,
260
+ query,
261
+ results: [],
262
+ results_by_source: { web: 0, proprietary: 0 },
263
+ total_deduction_pcm: 0,
264
+ total_deduction_dollars: 0,
265
+ total_characters: 0
266
+ };
267
+ }
268
+ }
144
269
  const payload = {
145
270
  query,
146
271
  search_type: finalSearchType,
@@ -170,11 +295,12 @@ var Valyu = class {
170
295
  if (options.responseLength !== void 0) {
171
296
  payload.response_length = options.responseLength;
172
297
  }
173
- const response = await import_axios.default.post(
174
- `${this.baseUrl}/deepsearch`,
175
- payload,
176
- { headers: this.headers }
177
- );
298
+ if (options.fastMode !== void 0) {
299
+ payload.fast_mode = options.fastMode;
300
+ }
301
+ const response = await import_axios.default.post(`${this.baseUrl}/deepsearch`, payload, {
302
+ headers: this.headers
303
+ });
178
304
  if (!response.status || response.status < 200 || response.status >= 300) {
179
305
  return {
180
306
  success: false,
@@ -251,10 +377,10 @@ var Valyu = class {
251
377
  total_characters: 0
252
378
  };
253
379
  }
254
- if (options.extractEffort && !["normal", "high"].includes(options.extractEffort)) {
380
+ if (options.extractEffort && !["normal", "high", "auto"].includes(options.extractEffort)) {
255
381
  return {
256
382
  success: false,
257
- error: "extractEffort must be 'normal' or 'high'",
383
+ error: "extractEffort must be 'normal', 'high', or 'auto'",
258
384
  urls_requested: urls.length,
259
385
  urls_processed: 0,
260
386
  urls_failed: urls.length,
@@ -305,11 +431,9 @@ var Valyu = class {
305
431
  if (options.maxPriceDollars !== void 0) {
306
432
  payload.max_price_dollars = options.maxPriceDollars;
307
433
  }
308
- const response = await import_axios.default.post(
309
- `${this.baseUrl}/contents`,
310
- payload,
311
- { headers: this.headers }
312
- );
434
+ const response = await import_axios.default.post(`${this.baseUrl}/contents`, payload, {
435
+ headers: this.headers
436
+ });
313
437
  if (!response.status || response.status < 200 || response.status >= 300) {
314
438
  return {
315
439
  success: false,
@@ -336,6 +460,177 @@ var Valyu = class {
336
460
  };
337
461
  }
338
462
  }
463
+ /**
464
+ * Get AI-powered answers using the Valyu Answer API
465
+ * @param query - The question or query string
466
+ * @param options - Answer configuration options
467
+ * @param options.structuredOutput - JSON Schema object for structured responses
468
+ * @param options.systemInstructions - Custom system-level instructions (max 2000 chars)
469
+ * @param options.searchType - Type of search: "web", "proprietary", or "all"
470
+ * @param options.dataMaxPrice - Maximum spend (USD) for data retrieval
471
+ * @param options.countryCode - Country code filter for search results
472
+ * @param options.includedSources - List of specific sources to include
473
+ * @param options.excludedSources - List of URLs/domains to exclude from search results
474
+ * @param options.startDate - Start date filter (YYYY-MM-DD format)
475
+ * @param options.endDate - End date filter (YYYY-MM-DD format)
476
+ * @param options.fastMode - Fast mode for quicker but shorter results (default: false)
477
+ * @returns Promise resolving to answer response
478
+ */
479
+ async answer(query, options = {}) {
480
+ try {
481
+ const defaultSearchType = "all";
482
+ const defaultDataMaxPrice = 30;
483
+ if (!query || typeof query !== "string" || query.trim().length === 0) {
484
+ return {
485
+ success: false,
486
+ error: "Query is required and must be a non-empty string"
487
+ };
488
+ }
489
+ let finalSearchType = defaultSearchType;
490
+ const providedSearchTypeString = options.searchType?.toLowerCase();
491
+ if (providedSearchTypeString === "web" || providedSearchTypeString === "proprietary" || providedSearchTypeString === "all") {
492
+ finalSearchType = providedSearchTypeString;
493
+ } else if (options.searchType !== void 0) {
494
+ return {
495
+ success: false,
496
+ error: "Invalid searchType provided. Must be one of: all, web, proprietary"
497
+ };
498
+ }
499
+ if (options.systemInstructions !== void 0) {
500
+ if (typeof options.systemInstructions !== "string") {
501
+ return {
502
+ success: false,
503
+ error: "systemInstructions must be a string"
504
+ };
505
+ }
506
+ const trimmed = options.systemInstructions.trim();
507
+ if (trimmed.length === 0) {
508
+ return {
509
+ success: false,
510
+ error: "systemInstructions cannot be empty when provided"
511
+ };
512
+ }
513
+ if (trimmed.length > 2e3) {
514
+ return {
515
+ success: false,
516
+ error: "systemInstructions must be 2000 characters or less"
517
+ };
518
+ }
519
+ }
520
+ if (options.dataMaxPrice !== void 0) {
521
+ if (typeof options.dataMaxPrice !== "number" || options.dataMaxPrice <= 0) {
522
+ return {
523
+ success: false,
524
+ error: "dataMaxPrice must be a positive number"
525
+ };
526
+ }
527
+ }
528
+ if (options.startDate && !this.validateDateFormat(options.startDate)) {
529
+ return {
530
+ success: false,
531
+ error: "Invalid startDate format. Must be YYYY-MM-DD"
532
+ };
533
+ }
534
+ if (options.endDate && !this.validateDateFormat(options.endDate)) {
535
+ return {
536
+ success: false,
537
+ error: "Invalid endDate format. Must be YYYY-MM-DD"
538
+ };
539
+ }
540
+ if (options.startDate && options.endDate) {
541
+ const startDate = new Date(options.startDate);
542
+ const endDate = new Date(options.endDate);
543
+ if (startDate > endDate) {
544
+ return {
545
+ success: false,
546
+ error: "startDate must be before endDate"
547
+ };
548
+ }
549
+ }
550
+ if (options.includedSources !== void 0) {
551
+ if (!Array.isArray(options.includedSources)) {
552
+ return {
553
+ success: false,
554
+ error: "includedSources must be an array"
555
+ };
556
+ }
557
+ const includedSourcesValidation = this.validateSources(
558
+ options.includedSources
559
+ );
560
+ if (!includedSourcesValidation.valid) {
561
+ return {
562
+ success: false,
563
+ error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(
564
+ ", "
565
+ )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`
566
+ };
567
+ }
568
+ }
569
+ if (options.excludedSources !== void 0) {
570
+ if (!Array.isArray(options.excludedSources)) {
571
+ return {
572
+ success: false,
573
+ error: "excludedSources must be an array"
574
+ };
575
+ }
576
+ const excludedSourcesValidation = this.validateSources(
577
+ options.excludedSources
578
+ );
579
+ if (!excludedSourcesValidation.valid) {
580
+ return {
581
+ success: false,
582
+ error: `Invalid excludedSources format. Invalid sources: ${excludedSourcesValidation.invalidSources.join(
583
+ ", "
584
+ )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`
585
+ };
586
+ }
587
+ }
588
+ const payload = {
589
+ query: query.trim(),
590
+ search_type: finalSearchType,
591
+ data_max_price: options.dataMaxPrice ?? defaultDataMaxPrice
592
+ };
593
+ if (options.structuredOutput !== void 0) {
594
+ payload.structured_output = options.structuredOutput;
595
+ }
596
+ if (options.systemInstructions !== void 0) {
597
+ payload.system_instructions = options.systemInstructions.trim();
598
+ }
599
+ if (options.countryCode !== void 0) {
600
+ payload.country_code = options.countryCode;
601
+ }
602
+ if (options.includedSources !== void 0) {
603
+ payload.included_sources = options.includedSources;
604
+ }
605
+ if (options.excludedSources !== void 0) {
606
+ payload.excluded_sources = options.excludedSources;
607
+ }
608
+ if (options.startDate !== void 0) {
609
+ payload.start_date = options.startDate;
610
+ }
611
+ if (options.endDate !== void 0) {
612
+ payload.end_date = options.endDate;
613
+ }
614
+ if (options.fastMode !== void 0) {
615
+ payload.fast_mode = options.fastMode;
616
+ }
617
+ const response = await import_axios.default.post(`${this.baseUrl}/answer`, payload, {
618
+ headers: this.headers
619
+ });
620
+ if (!response.status || response.status < 200 || response.status >= 300) {
621
+ return {
622
+ success: false,
623
+ error: response.data?.error || "Request failed"
624
+ };
625
+ }
626
+ return response.data;
627
+ } catch (e) {
628
+ return {
629
+ success: false,
630
+ error: e.response?.data?.error || e.message
631
+ };
632
+ }
633
+ }
339
634
  };
340
635
  // Annotate the CommonJS export names for ESM import in node:
341
636
  0 && (module.exports = {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from 'axios';\nimport { SearchResponse, SearchType, SearchOptions, ContentsOptions, ContentsResponse } from './types';\n\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(apiKey?: string, baseUrl: string = \"https://api.valyu.network/v1\") {\n if (!apiKey) {\n apiKey = process.env.VALYU_API_KEY;\n if (!apiKey) {\n throw new Error(\"VALYU_API_KEY is not set\");\n }\n }\n this.baseUrl = baseUrl;\n this.headers = {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": apiKey\n };\n }\n\n /**\n * Validates date format (YYYY-MM-DD)\n */\n private validateDateFormat(date: string): boolean {\n const dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n if (!dateRegex.test(date)) {\n return false;\n }\n const parsedDate = new Date(date);\n return parsedDate instanceof Date && !isNaN(parsedDate.getTime());\n }\n\n /**\n * Search for information using the Valyu DeepSearch API\n * @param query - The search query string\n * @param options - Search configuration options\n * @param options.searchType - Type of search: \"web\", \"proprietary\", or \"all\"\n * @param options.maxNumResults - Maximum number of results (1-20)\n * @param options.maxPrice - Maximum price per thousand characters (CPM)\n * @param options.isToolCall - Whether this is a tool call\n * @param options.relevanceThreshold - Minimum relevance score (0-1)\n * @param options.includedSources - List of specific sources to include\n * @param options.excludeSources - List of URLs/domains to exclude from search results\n * @param options.category - Category filter for search results\n * @param options.startDate - Start date filter (YYYY-MM-DD format)\n * @param options.endDate - End date filter (YYYY-MM-DD format)\n * @param options.countryCode - Country code filter for search results\n * @param options.responseLength - Response content length: \"short\"/\"medium\"/\"large\"/\"max\" or integer character count\n * @returns Promise resolving to search results\n */\n async search(query: string, options: SearchOptions = {}): Promise<SearchResponse> {\n try {\n // Default values\n const defaultSearchType: SearchType = \"all\";\n const defaultMaxNumResults = 10;\n const defaultIsToolCall = true;\n const defaultRelevanceThreshold = 0.5;\n const defaultMaxPrice = 30;\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (providedSearchTypeString === \"web\" || providedSearchTypeString === \"proprietary\" || providedSearchTypeString === \"all\") {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error: \"Invalid searchType provided. Must be one of: all, web, proprietary\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate date formats\n if (options.startDate && !this.validateDateFormat(options.startDate)) {\n return {\n success: false,\n error: \"Invalid startDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n if (options.endDate && !this.validateDateFormat(options.endDate)) {\n return {\n success: false,\n error: \"Invalid endDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate maxNumResults range\n const maxNumResults = options.maxNumResults ?? defaultMaxNumResults;\n if (maxNumResults < 1 || maxNumResults > 20) {\n return {\n success: false,\n error: \"maxNumResults must be between 1 and 20\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query,\n search_type: finalSearchType,\n max_num_results: maxNumResults,\n is_tool_call: options.isToolCall ?? defaultIsToolCall,\n relevance_threshold: options.relevanceThreshold ?? defaultRelevanceThreshold,\n max_price: options.maxPrice ?? defaultMaxPrice,\n };\n\n // Add optional parameters only if provided\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.excludeSources !== undefined) {\n payload.exclude_sources = options.excludeSources;\n }\n\n if (options.category !== undefined) {\n payload.category = options.category;\n }\n\n if (options.startDate !== undefined) {\n payload.start_date = options.startDate;\n }\n\n if (options.endDate !== undefined) {\n payload.end_date = options.endDate;\n }\n\n if (options.countryCode !== undefined) {\n payload.country_code = options.countryCode;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\n }\n\n const response = await axios.post(\n `${this.baseUrl}/deepsearch`,\n payload,\n { headers: this.headers }\n );\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n }\n\n /**\n * Extract content from URLs with optional AI processing\n * @param urls - Array of URLs to process (max 10)\n * @param options - Content extraction configuration options\n * @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema\n * @param options.extractEffort - Extraction thoroughness: \"normal\" or \"high\"\n * @param options.responseLength - Content length per URL\n * @param options.maxPriceDollars - Maximum cost limit in USD\n * @returns Promise resolving to content extraction results\n */\n async contents(urls: string[], options: ContentsOptions = {}): Promise<ContentsResponse> {\n try {\n // Validate URLs array\n if (!urls || !Array.isArray(urls)) {\n return {\n success: false,\n error: \"urls must be an array\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n\n if (urls.length === 0) {\n return {\n success: false,\n error: \"urls array cannot be empty\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n\n if (urls.length > 10) {\n return {\n success: false,\n error: \"Maximum 10 URLs allowed per request\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n\n // Validate extractEffort if provided\n if (options.extractEffort && ![\"normal\", \"high\"].includes(options.extractEffort)) {\n return {\n success: false,\n error: \"extractEffort must be 'normal' or 'high'\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n\n // Validate responseLength if provided\n if (options.responseLength !== undefined) {\n const validLengths = [\"short\", \"medium\", \"large\", \"max\"];\n if (typeof options.responseLength === \"string\" && !validLengths.includes(options.responseLength)) {\n return {\n success: false,\n error: \"responseLength must be 'short', 'medium', 'large', 'max', or a number\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n if (typeof options.responseLength === \"number\" && options.responseLength <= 0) {\n return {\n success: false,\n error: \"responseLength number must be positive\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n urls\n };\n\n // Add optional parameters only if provided\n if (options.summary !== undefined) {\n payload.summary = options.summary;\n }\n\n if (options.extractEffort !== undefined) {\n payload.extract_effort = options.extractEffort;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\n }\n\n if (options.maxPriceDollars !== undefined) {\n payload.max_price_dollars = options.maxPriceDollars;\n }\n\n const response = await axios.post(\n `${this.baseUrl}/contents`,\n payload,\n { headers: this.headers }\n );\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error || \"Request failed\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n }\n}\n\nexport type { \n SearchResponse, \n SearchType, \n FeedbackSentiment, \n FeedbackResponse,\n SearchOptions,\n CountryCode,\n ResponseLength,\n ContentsOptions,\n ContentsResponse,\n ContentResult,\n ExtractEffort,\n ContentResponseLength\n} from './types'; "],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAGX,IAAM,QAAN,MAAY;AAAA,EAIjB,YAAY,QAAiB,UAAkB,gCAAgC;AAC7E,QAAI,CAAC,QAAQ;AACX,eAAS,QAAQ,IAAI;AACrB,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AAAA,IACF;AAC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ios"]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from \"axios\";\nimport {\n SearchResponse,\n SearchType,\n SearchOptions,\n ContentsOptions,\n ContentsResponse,\n AnswerOptions,\n AnswerResponse,\n} from \"./types\";\n\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(\n apiKey?: string,\n baseUrl: string = \"https://api.valyu.network/v1\"\n ) {\n if (!apiKey) {\n apiKey = process.env.VALYU_API_KEY;\n if (!apiKey) {\n throw new Error(\"VALYU_API_KEY is not set\");\n }\n }\n this.baseUrl = baseUrl;\n this.headers = {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": apiKey,\n };\n }\n\n /**\n * Validates date format (YYYY-MM-DD)\n */\n private validateDateFormat(date: string): boolean {\n const dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n if (!dateRegex.test(date)) {\n return false;\n }\n const parsedDate = new Date(date);\n return parsedDate instanceof Date && !isNaN(parsedDate.getTime());\n }\n\n /**\n * Validates if a string is a valid URL\n */\n private validateUrl(url: string): boolean {\n try {\n new URL(url);\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * Validates if a string is a valid domain (with optional path)\n */\n private validateDomain(domain: string): boolean {\n // Domain must have at least one dot and valid structure\n // Supports: example.com, example.com/path, subdomain.example.com/path/to/resource\n const domainRegex =\n /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\\/.+)?$/;\n return domainRegex.test(domain);\n }\n\n /**\n * Validates if a string is a valid dataset identifier (provider/datasetname)\n */\n private validateDatasetId(datasetId: string): boolean {\n // Dataset format: provider/datasetname (exactly one slash)\n // Provider and dataset name can contain alphanumeric, hyphens, underscores\n const parts = datasetId.split(\"/\");\n if (parts.length !== 2) return false;\n\n const providerRegex = /^[a-zA-Z0-9_-]+$/;\n const datasetRegex = /^[a-zA-Z0-9_-]+$/;\n\n return (\n providerRegex.test(parts[0]) &&\n datasetRegex.test(parts[1]) &&\n parts[0].length > 0 &&\n parts[1].length > 0\n );\n }\n\n /**\n * Validates source strings (domains, URLs, or dataset IDs)\n */\n private validateSource(source: string): boolean {\n // Check if it's a valid URL\n if (this.validateUrl(source)) {\n return true;\n }\n\n // Check if it's a valid domain (with optional path)\n if (this.validateDomain(source)) {\n return true;\n }\n\n // Check if it's a valid dataset identifier\n if (this.validateDatasetId(source)) {\n return true;\n }\n\n return false;\n }\n\n /**\n * Validates an array of source strings\n */\n private validateSources(sources: string[]): {\n valid: boolean;\n invalidSources: string[];\n } {\n const invalidSources: string[] = [];\n\n for (const source of sources) {\n if (!this.validateSource(source)) {\n invalidSources.push(source);\n }\n }\n\n return {\n valid: invalidSources.length === 0,\n invalidSources,\n };\n }\n\n /**\n * Search for information using the Valyu DeepSearch API\n * @param query - The search query string\n * @param options - Search configuration options\n * @param options.searchType - Type of search: \"web\", \"proprietary\", or \"all\"\n * @param options.maxNumResults - Maximum number of results (1-20)\n * @param options.maxPrice - Maximum price per thousand characters (CPM)\n * @param options.isToolCall - Whether this is a tool call\n * @param options.relevanceThreshold - Minimum relevance score (0-1)\n * @param options.includedSources - List of specific sources to include\n * @param options.excludeSources - List of URLs/domains to exclude from search results\n * @param options.category - Category filter for search results\n * @param options.startDate - Start date filter (YYYY-MM-DD format)\n * @param options.endDate - End date filter (YYYY-MM-DD format)\n * @param options.countryCode - Country code filter for search results\n * @param options.responseLength - Response content length: \"short\"/\"medium\"/\"large\"/\"max\" or integer character count\n * @param options.fastMode - Fast mode for quicker but shorter results (default: false)\n * @returns Promise resolving to search results\n */\n async search(\n query: string,\n options: SearchOptions = {}\n ): Promise<SearchResponse> {\n try {\n // Default values\n const defaultSearchType: SearchType = \"all\";\n const defaultMaxNumResults = 10;\n const defaultIsToolCall = true;\n const defaultRelevanceThreshold = 0.5;\n const defaultMaxPrice = 30;\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (\n providedSearchTypeString === \"web\" ||\n providedSearchTypeString === \"proprietary\" ||\n providedSearchTypeString === \"all\"\n ) {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error:\n \"Invalid searchType provided. Must be one of: all, web, proprietary\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n\n // Validate date formats\n if (options.startDate && !this.validateDateFormat(options.startDate)) {\n return {\n success: false,\n error: \"Invalid startDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n\n if (options.endDate && !this.validateDateFormat(options.endDate)) {\n return {\n success: false,\n error: \"Invalid endDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n\n // Validate maxNumResults range\n const maxNumResults = options.maxNumResults ?? defaultMaxNumResults;\n if (maxNumResults < 1 || maxNumResults > 20) {\n return {\n success: false,\n error: \"maxNumResults must be between 1 and 20\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n\n // Validate includedSources format\n if (options.includedSources !== undefined) {\n if (!Array.isArray(options.includedSources)) {\n return {\n success: false,\n error: \"includedSources must be an array\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n\n const includedSourcesValidation = this.validateSources(\n options.includedSources\n );\n if (!includedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n }\n\n // Validate excludeSources format\n if (options.excludeSources !== undefined) {\n if (!Array.isArray(options.excludeSources)) {\n return {\n success: false,\n error: \"excludeSources must be an array\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n\n const excludeSourcesValidation = this.validateSources(\n options.excludeSources\n );\n if (!excludeSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid excludeSources format. Invalid sources: ${excludeSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query,\n search_type: finalSearchType,\n max_num_results: maxNumResults,\n is_tool_call: options.isToolCall ?? defaultIsToolCall,\n relevance_threshold:\n options.relevanceThreshold ?? defaultRelevanceThreshold,\n max_price: options.maxPrice ?? defaultMaxPrice,\n };\n\n // Add optional parameters only if provided\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.excludeSources !== undefined) {\n payload.exclude_sources = options.excludeSources;\n }\n\n if (options.category !== undefined) {\n payload.category = options.category;\n }\n\n if (options.startDate !== undefined) {\n payload.start_date = options.startDate;\n }\n\n if (options.endDate !== undefined) {\n payload.end_date = options.endDate;\n }\n\n if (options.countryCode !== undefined) {\n payload.country_code = options.countryCode;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\n }\n\n if (options.fastMode !== undefined) {\n payload.fast_mode = options.fastMode;\n }\n\n const response = await axios.post(`${this.baseUrl}/deepsearch`, payload, {\n headers: this.headers,\n });\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n }\n\n /**\n * Extract content from URLs with optional AI processing\n * @param urls - Array of URLs to process (max 10)\n * @param options - Content extraction configuration options\n * @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema\n * @param options.extractEffort - Extraction thoroughness: \"normal\" or \"high\"\n * @param options.responseLength - Content length per URL\n * @param options.maxPriceDollars - Maximum cost limit in USD\n * @returns Promise resolving to content extraction results\n */\n async contents(\n urls: string[],\n options: ContentsOptions = {}\n ): Promise<ContentsResponse> {\n try {\n // Validate URLs array\n if (!urls || !Array.isArray(urls)) {\n return {\n success: false,\n error: \"urls must be an array\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n if (urls.length === 0) {\n return {\n success: false,\n error: \"urls array cannot be empty\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n if (urls.length > 10) {\n return {\n success: false,\n error: \"Maximum 10 URLs allowed per request\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n // Validate extractEffort if provided\n if (\n options.extractEffort &&\n ![\"normal\", \"high\", \"auto\"].includes(options.extractEffort)\n ) {\n return {\n success: false,\n error: \"extractEffort must be 'normal', 'high', or 'auto'\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n // Validate responseLength if provided\n if (options.responseLength !== undefined) {\n const validLengths = [\"short\", \"medium\", \"large\", \"max\"];\n if (\n typeof options.responseLength === \"string\" &&\n !validLengths.includes(options.responseLength)\n ) {\n return {\n success: false,\n error:\n \"responseLength must be 'short', 'medium', 'large', 'max', or a number\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n if (\n typeof options.responseLength === \"number\" &&\n options.responseLength <= 0\n ) {\n return {\n success: false,\n error: \"responseLength number must be positive\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n urls,\n };\n\n // Add optional parameters only if provided\n if (options.summary !== undefined) {\n payload.summary = options.summary;\n }\n\n if (options.extractEffort !== undefined) {\n payload.extract_effort = options.extractEffort;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\n }\n\n if (options.maxPriceDollars !== undefined) {\n payload.max_price_dollars = options.maxPriceDollars;\n }\n\n const response = await axios.post(`${this.baseUrl}/contents`, payload, {\n headers: this.headers,\n });\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error || \"Request failed\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n }\n\n /**\n * Get AI-powered answers using the Valyu Answer API\n * @param query - The question or query string\n * @param options - Answer configuration options\n * @param options.structuredOutput - JSON Schema object for structured responses\n * @param options.systemInstructions - Custom system-level instructions (max 2000 chars)\n * @param options.searchType - Type of search: \"web\", \"proprietary\", or \"all\"\n * @param options.dataMaxPrice - Maximum spend (USD) for data retrieval\n * @param options.countryCode - Country code filter for search results\n * @param options.includedSources - List of specific sources to include\n * @param options.excludedSources - List of URLs/domains to exclude from search results\n * @param options.startDate - Start date filter (YYYY-MM-DD format)\n * @param options.endDate - End date filter (YYYY-MM-DD format)\n * @param options.fastMode - Fast mode for quicker but shorter results (default: false)\n * @returns Promise resolving to answer response\n */\n async answer(\n query: string,\n options: AnswerOptions = {}\n ): Promise<AnswerResponse> {\n try {\n // Default values\n const defaultSearchType: SearchType = \"all\";\n const defaultDataMaxPrice = 30.0;\n\n // Validate query\n if (!query || typeof query !== \"string\" || query.trim().length === 0) {\n return {\n success: false,\n error: \"Query is required and must be a non-empty string\",\n };\n }\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (\n providedSearchTypeString === \"web\" ||\n providedSearchTypeString === \"proprietary\" ||\n providedSearchTypeString === \"all\"\n ) {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error:\n \"Invalid searchType provided. Must be one of: all, web, proprietary\",\n };\n }\n\n // Validate systemInstructions length\n if (options.systemInstructions !== undefined) {\n if (typeof options.systemInstructions !== \"string\") {\n return {\n success: false,\n error: \"systemInstructions must be a string\",\n };\n }\n\n const trimmed = options.systemInstructions.trim();\n if (trimmed.length === 0) {\n return {\n success: false,\n error: \"systemInstructions cannot be empty when provided\",\n };\n }\n\n if (trimmed.length > 2000) {\n return {\n success: false,\n error: \"systemInstructions must be 2000 characters or less\",\n };\n }\n }\n\n // Validate dataMaxPrice\n if (options.dataMaxPrice !== undefined) {\n if (\n typeof options.dataMaxPrice !== \"number\" ||\n options.dataMaxPrice <= 0\n ) {\n return {\n success: false,\n error: \"dataMaxPrice must be a positive number\",\n };\n }\n }\n\n // Validate date formats\n if (options.startDate && !this.validateDateFormat(options.startDate)) {\n return {\n success: false,\n error: \"Invalid startDate format. Must be YYYY-MM-DD\",\n };\n }\n\n if (options.endDate && !this.validateDateFormat(options.endDate)) {\n return {\n success: false,\n error: \"Invalid endDate format. Must be YYYY-MM-DD\",\n };\n }\n\n // Validate date order\n if (options.startDate && options.endDate) {\n const startDate = new Date(options.startDate);\n const endDate = new Date(options.endDate);\n if (startDate > endDate) {\n return {\n success: false,\n error: \"startDate must be before endDate\",\n };\n }\n }\n\n // Validate includedSources format\n if (options.includedSources !== undefined) {\n if (!Array.isArray(options.includedSources)) {\n return {\n success: false,\n error: \"includedSources must be an array\",\n };\n }\n\n const includedSourcesValidation = this.validateSources(\n options.includedSources\n );\n if (!includedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n };\n }\n }\n\n // Validate excludedSources format\n if (options.excludedSources !== undefined) {\n if (!Array.isArray(options.excludedSources)) {\n return {\n success: false,\n error: \"excludedSources must be an array\",\n };\n }\n\n const excludedSourcesValidation = this.validateSources(\n options.excludedSources\n );\n if (!excludedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid excludedSources format. Invalid sources: ${excludedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query: query.trim(),\n search_type: finalSearchType,\n data_max_price: options.dataMaxPrice ?? defaultDataMaxPrice,\n };\n\n // Add optional parameters only if provided\n if (options.structuredOutput !== undefined) {\n payload.structured_output = options.structuredOutput;\n }\n\n if (options.systemInstructions !== undefined) {\n payload.system_instructions = options.systemInstructions.trim();\n }\n\n if (options.countryCode !== undefined) {\n payload.country_code = options.countryCode;\n }\n\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.excludedSources !== undefined) {\n payload.excluded_sources = options.excludedSources;\n }\n\n if (options.startDate !== undefined) {\n payload.start_date = options.startDate;\n }\n\n if (options.endDate !== undefined) {\n payload.end_date = options.endDate;\n }\n\n if (options.fastMode !== undefined) {\n payload.fast_mode = options.fastMode;\n }\n\n const response = await axios.post(`${this.baseUrl}/answer`, payload, {\n headers: this.headers,\n });\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error || \"Request failed\",\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n };\n }\n }\n}\n\nexport type {\n SearchResponse,\n SearchType,\n FeedbackSentiment,\n FeedbackResponse,\n SearchOptions,\n CountryCode,\n ResponseLength,\n ContentsOptions,\n ContentsResponse,\n ContentResult,\n ExtractEffort,\n ContentResponseLength,\n AnswerOptions,\n AnswerResponse,\n AnswerSuccessResponse,\n AnswerErrorResponse,\n SearchMetadata,\n AIUsage,\n Cost,\n} from \"./types\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAWX,IAAM,QAAN,MAAY;AAAA,EAIjB,YACE,QACA,UAAkB,gCAClB;AACA,QAAI,CAAC,QAAQ;AACX,eAAS,QAAQ,IAAI;AACrB,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AAAA,IACF;AACA,SAAK,UAAU;AACf,SAAK,UAAU;AAAA,MACb,gBAAgB;AAAA,MAChB,aAAa;AAAA,IACf;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,mBAAmB,MAAuB;AAChD,UAA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AAEA,UAAI,QAAQ,uBAAuB,QAAW;AAC5C,gBAAQ,sBAAsB,QAAQ,mBAAmB,KAAK;AAAA,MAChE;AAEA,UAAI,QAAQ,gBAAgB,QAAW;AACrC,gBAAQ,eAAe,QAAQ;AAAA,MACjC;AAEA,UAAI,QAAQ,oBAAoB,QAAW;AACzC,gBAAQ,mBAAmB,QAAQ;AAAA,MACrC;AAEA,UAAI,QAAQ,oBAAoB,QAAW;AACzC,gBAAQ,mBAAmB,QAAQ;AAAA,MACrC;AAEA,UAAI,QAAQ,cAAc,QAAW;AACnC,gBAAQ,aAAa,QAAQ;AAAA,MAC/B;AAEA,UAAI,QAAQ,YAAY,QAAW;AACjC,gBAAQ,WAAW,QAAQ;AAAA,MAC7B;AAEA,UAAI,QAAQ,aAAa,QAAW;AAClC,gBAAQ,YAAY,QAAQ;AAAA,MAC9B;AAEA,YAAM,WAAW,MAAM,aAAAA,QAAM,KAAK,GAAG,KAAK,OAAO,WAAW,SAAS;AAAA,QACnE,SAAS,KAAK;AAAA,MAChB,CAAC;AAED,UAAI,CAAC,SAAS,UAAU,SAAS,SAAS,OAAO,SAAS,UAAU,KAAK;AACvE,eAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO,SAAS,MAAM,SAAS;AAAA,QACjC;AAAA,MACF;AAEA,aAAO,SAAS;AAAA,IAClB,SAAS,GAAQ;AACf,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO,EAAE,UAAU,MAAM,SAAS,EAAE;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AACF;","names":["axios"]}
package/dist/index.mjs CHANGED
@@ -25,6 +25,64 @@ var Valyu = class {
25
25
  const parsedDate = new Date(date);
26
26
  return parsedDate instanceof Date && !isNaN(parsedDate.getTime());
27
27
  }
28
+ /**
29
+ * Validates if a string is a valid URL
30
+ */
31
+ validateUrl(url) {
32
+ try {
33
+ new URL(url);
34
+ return true;
35
+ } catch {
36
+ return false;
37
+ }
38
+ }
39
+ /**
40
+ * Validates if a string is a valid domain (with optional path)
41
+ */
42
+ validateDomain(domain) {
43
+ const domainRegex = /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\/.+)?$/;
44
+ return domainRegex.test(domain);
45
+ }
46
+ /**
47
+ * Validates if a string is a valid dataset identifier (provider/datasetname)
48
+ */
49
+ validateDatasetId(datasetId) {
50
+ const parts = datasetId.split("/");
51
+ if (parts.length !== 2) return false;
52
+ const providerRegex = /^[a-zA-Z0-9_-]+$/;
53
+ const datasetRegex = /^[a-zA-Z0-9_-]+$/;
54
+ return providerRegex.test(parts[0]) && datasetRegex.test(parts[1]) && parts[0].length > 0 && parts[1].length > 0;
55
+ }
56
+ /**
57
+ * Validates source strings (domains, URLs, or dataset IDs)
58
+ */
59
+ validateSource(source) {
60
+ if (this.validateUrl(source)) {
61
+ return true;
62
+ }
63
+ if (this.validateDomain(source)) {
64
+ return true;
65
+ }
66
+ if (this.validateDatasetId(source)) {
67
+ return true;
68
+ }
69
+ return false;
70
+ }
71
+ /**
72
+ * Validates an array of source strings
73
+ */
74
+ validateSources(sources) {
75
+ const invalidSources = [];
76
+ for (const source of sources) {
77
+ if (!this.validateSource(source)) {
78
+ invalidSources.push(source);
79
+ }
80
+ }
81
+ return {
82
+ valid: invalidSources.length === 0,
83
+ invalidSources
84
+ };
85
+ }
28
86
  /**
29
87
  * Search for information using the Valyu DeepSearch API
30
88
  * @param query - The search query string
@@ -41,6 +99,7 @@ var Valyu = class {
41
99
  * @param options.endDate - End date filter (YYYY-MM-DD format)
42
100
  * @param options.countryCode - Country code filter for search results
43
101
  * @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
102
+ * @param options.fastMode - Fast mode for quicker but shorter results (default: false)
44
103
  * @returns Promise resolving to search results
45
104
  */
46
105
  async search(query, options = {}) {
@@ -107,6 +166,72 @@ var Valyu = class {
107
166
  total_characters: 0
108
167
  };
109
168
  }
169
+ if (options.includedSources !== void 0) {
170
+ if (!Array.isArray(options.includedSources)) {
171
+ return {
172
+ success: false,
173
+ error: "includedSources must be an array",
174
+ tx_id: null,
175
+ query,
176
+ results: [],
177
+ results_by_source: { web: 0, proprietary: 0 },
178
+ total_deduction_pcm: 0,
179
+ total_deduction_dollars: 0,
180
+ total_characters: 0
181
+ };
182
+ }
183
+ const includedSourcesValidation = this.validateSources(
184
+ options.includedSources
185
+ );
186
+ if (!includedSourcesValidation.valid) {
187
+ return {
188
+ success: false,
189
+ error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(
190
+ ", "
191
+ )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,
192
+ tx_id: null,
193
+ query,
194
+ results: [],
195
+ results_by_source: { web: 0, proprietary: 0 },
196
+ total_deduction_pcm: 0,
197
+ total_deduction_dollars: 0,
198
+ total_characters: 0
199
+ };
200
+ }
201
+ }
202
+ if (options.excludeSources !== void 0) {
203
+ if (!Array.isArray(options.excludeSources)) {
204
+ return {
205
+ success: false,
206
+ error: "excludeSources must be an array",
207
+ tx_id: null,
208
+ query,
209
+ results: [],
210
+ results_by_source: { web: 0, proprietary: 0 },
211
+ total_deduction_pcm: 0,
212
+ total_deduction_dollars: 0,
213
+ total_characters: 0
214
+ };
215
+ }
216
+ const excludeSourcesValidation = this.validateSources(
217
+ options.excludeSources
218
+ );
219
+ if (!excludeSourcesValidation.valid) {
220
+ return {
221
+ success: false,
222
+ error: `Invalid excludeSources format. Invalid sources: ${excludeSourcesValidation.invalidSources.join(
223
+ ", "
224
+ )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,
225
+ tx_id: null,
226
+ query,
227
+ results: [],
228
+ results_by_source: { web: 0, proprietary: 0 },
229
+ total_deduction_pcm: 0,
230
+ total_deduction_dollars: 0,
231
+ total_characters: 0
232
+ };
233
+ }
234
+ }
110
235
  const payload = {
111
236
  query,
112
237
  search_type: finalSearchType,
@@ -136,11 +261,12 @@ var Valyu = class {
136
261
  if (options.responseLength !== void 0) {
137
262
  payload.response_length = options.responseLength;
138
263
  }
139
- const response = await axios.post(
140
- `${this.baseUrl}/deepsearch`,
141
- payload,
142
- { headers: this.headers }
143
- );
264
+ if (options.fastMode !== void 0) {
265
+ payload.fast_mode = options.fastMode;
266
+ }
267
+ const response = await axios.post(`${this.baseUrl}/deepsearch`, payload, {
268
+ headers: this.headers
269
+ });
144
270
  if (!response.status || response.status < 200 || response.status >= 300) {
145
271
  return {
146
272
  success: false,
@@ -217,10 +343,10 @@ var Valyu = class {
217
343
  total_characters: 0
218
344
  };
219
345
  }
220
- if (options.extractEffort && !["normal", "high"].includes(options.extractEffort)) {
346
+ if (options.extractEffort && !["normal", "high", "auto"].includes(options.extractEffort)) {
221
347
  return {
222
348
  success: false,
223
- error: "extractEffort must be 'normal' or 'high'",
349
+ error: "extractEffort must be 'normal', 'high', or 'auto'",
224
350
  urls_requested: urls.length,
225
351
  urls_processed: 0,
226
352
  urls_failed: urls.length,
@@ -271,11 +397,9 @@ var Valyu = class {
271
397
  if (options.maxPriceDollars !== void 0) {
272
398
  payload.max_price_dollars = options.maxPriceDollars;
273
399
  }
274
- const response = await axios.post(
275
- `${this.baseUrl}/contents`,
276
- payload,
277
- { headers: this.headers }
278
- );
400
+ const response = await axios.post(`${this.baseUrl}/contents`, payload, {
401
+ headers: this.headers
402
+ });
279
403
  if (!response.status || response.status < 200 || response.status >= 300) {
280
404
  return {
281
405
  success: false,
@@ -302,6 +426,177 @@ var Valyu = class {
302
426
  };
303
427
  }
304
428
  }
429
+ /**
430
+ * Get AI-powered answers using the Valyu Answer API
431
+ * @param query - The question or query string
432
+ * @param options - Answer configuration options
433
+ * @param options.structuredOutput - JSON Schema object for structured responses
434
+ * @param options.systemInstructions - Custom system-level instructions (max 2000 chars)
435
+ * @param options.searchType - Type of search: "web", "proprietary", or "all"
436
+ * @param options.dataMaxPrice - Maximum spend (USD) for data retrieval
437
+ * @param options.countryCode - Country code filter for search results
438
+ * @param options.includedSources - List of specific sources to include
439
+ * @param options.excludedSources - List of URLs/domains to exclude from search results
440
+ * @param options.startDate - Start date filter (YYYY-MM-DD format)
441
+ * @param options.endDate - End date filter (YYYY-MM-DD format)
442
+ * @param options.fastMode - Fast mode for quicker but shorter results (default: false)
443
+ * @returns Promise resolving to answer response
444
+ */
445
+ async answer(query, options = {}) {
446
+ try {
447
+ const defaultSearchType = "all";
448
+ const defaultDataMaxPrice = 30;
449
+ if (!query || typeof query !== "string" || query.trim().length === 0) {
450
+ return {
451
+ success: false,
452
+ error: "Query is required and must be a non-empty string"
453
+ };
454
+ }
455
+ let finalSearchType = defaultSearchType;
456
+ const providedSearchTypeString = options.searchType?.toLowerCase();
457
+ if (providedSearchTypeString === "web" || providedSearchTypeString === "proprietary" || providedSearchTypeString === "all") {
458
+ finalSearchType = providedSearchTypeString;
459
+ } else if (options.searchType !== void 0) {
460
+ return {
461
+ success: false,
462
+ error: "Invalid searchType provided. Must be one of: all, web, proprietary"
463
+ };
464
+ }
465
+ if (options.systemInstructions !== void 0) {
466
+ if (typeof options.systemInstructions !== "string") {
467
+ return {
468
+ success: false,
469
+ error: "systemInstructions must be a string"
470
+ };
471
+ }
472
+ const trimmed = options.systemInstructions.trim();
473
+ if (trimmed.length === 0) {
474
+ return {
475
+ success: false,
476
+ error: "systemInstructions cannot be empty when provided"
477
+ };
478
+ }
479
+ if (trimmed.length > 2e3) {
480
+ return {
481
+ success: false,
482
+ error: "systemInstructions must be 2000 characters or less"
483
+ };
484
+ }
485
+ }
486
+ if (options.dataMaxPrice !== void 0) {
487
+ if (typeof options.dataMaxPrice !== "number" || options.dataMaxPrice <= 0) {
488
+ return {
489
+ success: false,
490
+ error: "dataMaxPrice must be a positive number"
491
+ };
492
+ }
493
+ }
494
+ if (options.startDate && !this.validateDateFormat(options.startDate)) {
495
+ return {
496
+ success: false,
497
+ error: "Invalid startDate format. Must be YYYY-MM-DD"
498
+ };
499
+ }
500
+ if (options.endDate && !this.validateDateFormat(options.endDate)) {
501
+ return {
502
+ success: false,
503
+ error: "Invalid endDate format. Must be YYYY-MM-DD"
504
+ };
505
+ }
506
+ if (options.startDate && options.endDate) {
507
+ const startDate = new Date(options.startDate);
508
+ const endDate = new Date(options.endDate);
509
+ if (startDate > endDate) {
510
+ return {
511
+ success: false,
512
+ error: "startDate must be before endDate"
513
+ };
514
+ }
515
+ }
516
+ if (options.includedSources !== void 0) {
517
+ if (!Array.isArray(options.includedSources)) {
518
+ return {
519
+ success: false,
520
+ error: "includedSources must be an array"
521
+ };
522
+ }
523
+ const includedSourcesValidation = this.validateSources(
524
+ options.includedSources
525
+ );
526
+ if (!includedSourcesValidation.valid) {
527
+ return {
528
+ success: false,
529
+ error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(
530
+ ", "
531
+ )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`
532
+ };
533
+ }
534
+ }
535
+ if (options.excludedSources !== void 0) {
536
+ if (!Array.isArray(options.excludedSources)) {
537
+ return {
538
+ success: false,
539
+ error: "excludedSources must be an array"
540
+ };
541
+ }
542
+ const excludedSourcesValidation = this.validateSources(
543
+ options.excludedSources
544
+ );
545
+ if (!excludedSourcesValidation.valid) {
546
+ return {
547
+ success: false,
548
+ error: `Invalid excludedSources format. Invalid sources: ${excludedSourcesValidation.invalidSources.join(
549
+ ", "
550
+ )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`
551
+ };
552
+ }
553
+ }
554
+ const payload = {
555
+ query: query.trim(),
556
+ search_type: finalSearchType,
557
+ data_max_price: options.dataMaxPrice ?? defaultDataMaxPrice
558
+ };
559
+ if (options.structuredOutput !== void 0) {
560
+ payload.structured_output = options.structuredOutput;
561
+ }
562
+ if (options.systemInstructions !== void 0) {
563
+ payload.system_instructions = options.systemInstructions.trim();
564
+ }
565
+ if (options.countryCode !== void 0) {
566
+ payload.country_code = options.countryCode;
567
+ }
568
+ if (options.includedSources !== void 0) {
569
+ payload.included_sources = options.includedSources;
570
+ }
571
+ if (options.excludedSources !== void 0) {
572
+ payload.excluded_sources = options.excludedSources;
573
+ }
574
+ if (options.startDate !== void 0) {
575
+ payload.start_date = options.startDate;
576
+ }
577
+ if (options.endDate !== void 0) {
578
+ payload.end_date = options.endDate;
579
+ }
580
+ if (options.fastMode !== void 0) {
581
+ payload.fast_mode = options.fastMode;
582
+ }
583
+ const response = await axios.post(`${this.baseUrl}/answer`, payload, {
584
+ headers: this.headers
585
+ });
586
+ if (!response.status || response.status < 200 || response.status >= 300) {
587
+ return {
588
+ success: false,
589
+ error: response.data?.error || "Request failed"
590
+ };
591
+ }
592
+ return response.data;
593
+ } catch (e) {
594
+ return {
595
+ success: false,
596
+ error: e.response?.data?.error || e.message
597
+ };
598
+ }
599
+ }
305
600
  };
306
601
  export {
307
602
  Valyu
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from 'axios';\nimport { SearchResponse, SearchType, SearchOptions, ContentsOptions, ContentsResponse } from './types';\n\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(apiKey?: string, baseUrl: string = \"https://api.valyu.network/v1\") {\n if (!apiKey) {\n apiKey = process.env.VALYU_API_KEY;\n if (!apiKey) {\n throw new Error(\"VALYU_API_KEY is not set\");\n }\n }\n this.baseUrl = baseUrl;\n this.headers = {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": apiKey\n };\n }\n\n /**\n * Validates date format (YYYY-MM-DD)\n */\n private validateDateFormat(date: string): boolean {\n const dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n if (!dateRegex.test(date)) {\n return false;\n }\n const parsedDate = new Date(date);\n return parsedDate instanceof Date && !isNaN(parsedDate.getTime());\n }\n\n /**\n * Search for information using the Valyu DeepSearch API\n * @param query - The search query string\n * @param options - Search configuration options\n * @param options.searchType - Type of search: \"web\", \"proprietary\", or \"all\"\n * @param options.maxNumResults - Maximum number of results (1-20)\n * @param options.maxPrice - Maximum price per thousand characters (CPM)\n * @param options.isToolCall - Whether this is a tool call\n * @param options.relevanceThreshold - Minimum relevance score (0-1)\n * @param options.includedSources - List of specific sources to include\n * @param options.excludeSources - List of URLs/domains to exclude from search results\n * @param options.category - Category filter for search results\n * @param options.startDate - Start date filter (YYYY-MM-DD format)\n * @param options.endDate - End date filter (YYYY-MM-DD format)\n * @param options.countryCode - Country code filter for search results\n * @param options.responseLength - Response content length: \"short\"/\"medium\"/\"large\"/\"max\" or integer character count\n * @returns Promise resolving to search results\n */\n async search(query: string, options: SearchOptions = {}): Promise<SearchResponse> {\n try {\n // Default values\n const defaultSearchType: SearchType = \"all\";\n const defaultMaxNumResults = 10;\n const defaultIsToolCall = true;\n const defaultRelevanceThreshold = 0.5;\n const defaultMaxPrice = 30;\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (providedSearchTypeString === \"web\" || providedSearchTypeString === \"proprietary\" || providedSearchTypeString === \"all\") {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error: \"Invalid searchType provided. Must be one of: all, web, proprietary\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate date formats\n if (options.startDate && !this.validateDateFormat(options.startDate)) {\n return {\n success: false,\n error: \"Invalid startDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n if (options.endDate && !this.validateDateFormat(options.endDate)) {\n return {\n success: false,\n error: \"Invalid endDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Validate maxNumResults range\n const maxNumResults = options.maxNumResults ?? defaultMaxNumResults;\n if (maxNumResults < 1 || maxNumResults > 20) {\n return {\n success: false,\n error: \"maxNumResults must be between 1 and 20\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query,\n search_type: finalSearchType,\n max_num_results: maxNumResults,\n is_tool_call: options.isToolCall ?? defaultIsToolCall,\n relevance_threshold: options.relevanceThreshold ?? defaultRelevanceThreshold,\n max_price: options.maxPrice ?? defaultMaxPrice,\n };\n\n // Add optional parameters only if provided\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.excludeSources !== undefined) {\n payload.exclude_sources = options.excludeSources;\n }\n\n if (options.category !== undefined) {\n payload.category = options.category;\n }\n\n if (options.startDate !== undefined) {\n payload.start_date = options.startDate;\n }\n\n if (options.endDate !== undefined) {\n payload.end_date = options.endDate;\n }\n\n if (options.countryCode !== undefined) {\n payload.country_code = options.countryCode;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\n }\n\n const response = await axios.post(\n `${this.baseUrl}/deepsearch`,\n payload,\n { headers: this.headers }\n );\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0\n };\n }\n }\n\n /**\n * Extract content from URLs with optional AI processing\n * @param urls - Array of URLs to process (max 10)\n * @param options - Content extraction configuration options\n * @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema\n * @param options.extractEffort - Extraction thoroughness: \"normal\" or \"high\"\n * @param options.responseLength - Content length per URL\n * @param options.maxPriceDollars - Maximum cost limit in USD\n * @returns Promise resolving to content extraction results\n */\n async contents(urls: string[], options: ContentsOptions = {}): Promise<ContentsResponse> {\n try {\n // Validate URLs array\n if (!urls || !Array.isArray(urls)) {\n return {\n success: false,\n error: \"urls must be an array\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n\n if (urls.length === 0) {\n return {\n success: false,\n error: \"urls array cannot be empty\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n\n if (urls.length > 10) {\n return {\n success: false,\n error: \"Maximum 10 URLs allowed per request\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n\n // Validate extractEffort if provided\n if (options.extractEffort && ![\"normal\", \"high\"].includes(options.extractEffort)) {\n return {\n success: false,\n error: \"extractEffort must be 'normal' or 'high'\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n\n // Validate responseLength if provided\n if (options.responseLength !== undefined) {\n const validLengths = [\"short\", \"medium\", \"large\", \"max\"];\n if (typeof options.responseLength === \"string\" && !validLengths.includes(options.responseLength)) {\n return {\n success: false,\n error: \"responseLength must be 'short', 'medium', 'large', 'max', or a number\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n if (typeof options.responseLength === \"number\" && options.responseLength <= 0) {\n return {\n success: false,\n error: \"responseLength number must be positive\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n urls\n };\n\n // Add optional parameters only if provided\n if (options.summary !== undefined) {\n payload.summary = options.summary;\n }\n\n if (options.extractEffort !== undefined) {\n payload.extract_effort = options.extractEffort;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\n }\n\n if (options.maxPriceDollars !== undefined) {\n payload.max_price_dollars = options.maxPriceDollars;\n }\n\n const response = await axios.post(\n `${this.baseUrl}/contents`,\n payload,\n { headers: this.headers }\n );\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error || \"Request failed\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0\n };\n }\n }\n}\n\nexport type { \n SearchResponse, \n SearchType, \n FeedbackSentiment, \n FeedbackResponse,\n SearchOptions,\n CountryCode,\n ResponseLength,\n ContentsOptions,\n ContentsResponse,\n ContentResult,\n ExtractEffort,\n ContentResponseLength\n} from './types'; "],"mappings":";AAAA,OAAO,WAAW;AAGX,IAAM,QAAN,MAAY;AAAA,EAIjB,YAAY,QAAiB,UAAkB,gCAAgC;AAC7E,QAAI,CAAC,QAAQ;AACX,eAAS,QAAQ,IAAI;AACrB,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AAAA,IACF;AACA,SAAK,UAAU;AACf,SAAK,UAAU;AAAA,MACb,gBAAgB;AAAA,MAChB,aAAa;AAAA,IACf;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,mBAAmB,MAAuB;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AA,UACpB;AAAA,QACF;AAAA,MACF;AAGA,YAAM,UAA+B;AAAA,QACnC;AAAA,MACF;AAGA,UAAI,QAAQ,YAAY,QAAW;AACjC,gBAAQ,UAAU,QAAQ;AAAA,MAC5B;AAEA,UAAI,QAAQ,kBAAkB,QAAW;AACvC,gBAAQ,iBAAiB,QAAQ;AAAA,MACnC;AAEA,UAAI,QAAQ,mBAAmB,QAAW;AACxC,gBAAQ,kBAAkB,QAAQ;AAAA,MACpC;AAEA,UAAI,QAAQ,oBAAoB,QAAW;AACzC,gBAAQ,oBAAoB,QAAQ;AAAA,MACtC;AAEA,YAAM,WAAW,MAAM,MAAM;AAAA,QAC3B,GAAG,KAAK,OAAO;AAAA,QACf;AAAA,QACA,EAAE,SAAS,KAAK,QAAQ;AAAA,MAC1B;AAEA,UAAI,CAAC,SAAS,UAAU,SAAS,SAAS,OAAO,SAAS,UAAU,KAAK;AACvE,eAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO,SAAS,MAAM,SAAS;AAAA,UAC/B,gBAAgB,KAAK;AAAA,UACrB,gBAAgB;AAAA,UAChB,aAAa,KAAK;AAAA,UAClB,SAAS,CAAC;AAAA,UACV,oBAAoB;AAAA,UACpB,kBAAkB;AAAA,QACpB;AAAA,MACF;AAEA,aAAO,SAAS;AAAA,IAClB,SAAS,GAAQ;AACf,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO,EAAE,UAAU,MAAM,SAAS,EAAE;AAAA,QACpC,gBAAgB,KAAK;AAAA,QACrB,gBAAgB;AAAA,QAChB,aAAa,KAAK;AAAA,QAClB,SAAS,CAAC;AAAA,QACV,oBAAoB;AAAA,QACpB,kBAAkB;AAAA,MACpB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import axios from \"axios\";\nimport {\n SearchResponse,\n SearchType,\n SearchOptions,\n ContentsOptions,\n ContentsResponse,\n AnswerOptions,\n AnswerResponse,\n} from \"./types\";\n\nexport class Valyu {\n private baseUrl: string;\n private headers: Record<string, string>;\n\n constructor(\n apiKey?: string,\n baseUrl: string = \"https://api.valyu.network/v1\"\n ) {\n if (!apiKey) {\n apiKey = process.env.VALYU_API_KEY;\n if (!apiKey) {\n throw new Error(\"VALYU_API_KEY is not set\");\n }\n }\n this.baseUrl = baseUrl;\n this.headers = {\n \"Content-Type\": \"application/json\",\n \"x-api-key\": apiKey,\n };\n }\n\n /**\n * Validates date format (YYYY-MM-DD)\n */\n private validateDateFormat(date: string): boolean {\n const dateRegex = /^\\d{4}-\\d{2}-\\d{2}$/;\n if (!dateRegex.test(date)) {\n return false;\n }\n const parsedDate = new Date(date);\n return parsedDate instanceof Date && !isNaN(parsedDate.getTime());\n }\n\n /**\n * Validates if a string is a valid URL\n */\n private validateUrl(url: string): boolean {\n try {\n new URL(url);\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * Validates if a string is a valid domain (with optional path)\n */\n private validateDomain(domain: string): boolean {\n // Domain must have at least one dot and valid structure\n // Supports: example.com, example.com/path, subdomain.example.com/path/to/resource\n const domainRegex =\n /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(\\/.+)?$/;\n return domainRegex.test(domain);\n }\n\n /**\n * Validates if a string is a valid dataset identifier (provider/datasetname)\n */\n private validateDatasetId(datasetId: string): boolean {\n // Dataset format: provider/datasetname (exactly one slash)\n // Provider and dataset name can contain alphanumeric, hyphens, underscores\n const parts = datasetId.split(\"/\");\n if (parts.length !== 2) return false;\n\n const providerRegex = /^[a-zA-Z0-9_-]+$/;\n const datasetRegex = /^[a-zA-Z0-9_-]+$/;\n\n return (\n providerRegex.test(parts[0]) &&\n datasetRegex.test(parts[1]) &&\n parts[0].length > 0 &&\n parts[1].length > 0\n );\n }\n\n /**\n * Validates source strings (domains, URLs, or dataset IDs)\n */\n private validateSource(source: string): boolean {\n // Check if it's a valid URL\n if (this.validateUrl(source)) {\n return true;\n }\n\n // Check if it's a valid domain (with optional path)\n if (this.validateDomain(source)) {\n return true;\n }\n\n // Check if it's a valid dataset identifier\n if (this.validateDatasetId(source)) {\n return true;\n }\n\n return false;\n }\n\n /**\n * Validates an array of source strings\n */\n private validateSources(sources: string[]): {\n valid: boolean;\n invalidSources: string[];\n } {\n const invalidSources: string[] = [];\n\n for (const source of sources) {\n if (!this.validateSource(source)) {\n invalidSources.push(source);\n }\n }\n\n return {\n valid: invalidSources.length === 0,\n invalidSources,\n };\n }\n\n /**\n * Search for information using the Valyu DeepSearch API\n * @param query - The search query string\n * @param options - Search configuration options\n * @param options.searchType - Type of search: \"web\", \"proprietary\", or \"all\"\n * @param options.maxNumResults - Maximum number of results (1-20)\n * @param options.maxPrice - Maximum price per thousand characters (CPM)\n * @param options.isToolCall - Whether this is a tool call\n * @param options.relevanceThreshold - Minimum relevance score (0-1)\n * @param options.includedSources - List of specific sources to include\n * @param options.excludeSources - List of URLs/domains to exclude from search results\n * @param options.category - Category filter for search results\n * @param options.startDate - Start date filter (YYYY-MM-DD format)\n * @param options.endDate - End date filter (YYYY-MM-DD format)\n * @param options.countryCode - Country code filter for search results\n * @param options.responseLength - Response content length: \"short\"/\"medium\"/\"large\"/\"max\" or integer character count\n * @param options.fastMode - Fast mode for quicker but shorter results (default: false)\n * @returns Promise resolving to search results\n */\n async search(\n query: string,\n options: SearchOptions = {}\n ): Promise<SearchResponse> {\n try {\n // Default values\n const defaultSearchType: SearchType = \"all\";\n const defaultMaxNumResults = 10;\n const defaultIsToolCall = true;\n const defaultRelevanceThreshold = 0.5;\n const defaultMaxPrice = 30;\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (\n providedSearchTypeString === \"web\" ||\n providedSearchTypeString === \"proprietary\" ||\n providedSearchTypeString === \"all\"\n ) {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error:\n \"Invalid searchType provided. Must be one of: all, web, proprietary\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n\n // Validate date formats\n if (options.startDate && !this.validateDateFormat(options.startDate)) {\n return {\n success: false,\n error: \"Invalid startDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n\n if (options.endDate && !this.validateDateFormat(options.endDate)) {\n return {\n success: false,\n error: \"Invalid endDate format. Must be YYYY-MM-DD\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n\n // Validate maxNumResults range\n const maxNumResults = options.maxNumResults ?? defaultMaxNumResults;\n if (maxNumResults < 1 || maxNumResults > 20) {\n return {\n success: false,\n error: \"maxNumResults must be between 1 and 20\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n\n // Validate includedSources format\n if (options.includedSources !== undefined) {\n if (!Array.isArray(options.includedSources)) {\n return {\n success: false,\n error: \"includedSources must be an array\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n\n const includedSourcesValidation = this.validateSources(\n options.includedSources\n );\n if (!includedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n }\n\n // Validate excludeSources format\n if (options.excludeSources !== undefined) {\n if (!Array.isArray(options.excludeSources)) {\n return {\n success: false,\n error: \"excludeSources must be an array\",\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n\n const excludeSourcesValidation = this.validateSources(\n options.excludeSources\n );\n if (!excludeSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid excludeSources format. Invalid sources: ${excludeSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query,\n search_type: finalSearchType,\n max_num_results: maxNumResults,\n is_tool_call: options.isToolCall ?? defaultIsToolCall,\n relevance_threshold:\n options.relevanceThreshold ?? defaultRelevanceThreshold,\n max_price: options.maxPrice ?? defaultMaxPrice,\n };\n\n // Add optional parameters only if provided\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.excludeSources !== undefined) {\n payload.exclude_sources = options.excludeSources;\n }\n\n if (options.category !== undefined) {\n payload.category = options.category;\n }\n\n if (options.startDate !== undefined) {\n payload.start_date = options.startDate;\n }\n\n if (options.endDate !== undefined) {\n payload.end_date = options.endDate;\n }\n\n if (options.countryCode !== undefined) {\n payload.country_code = options.countryCode;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\n }\n\n if (options.fastMode !== undefined) {\n payload.fast_mode = options.fastMode;\n }\n\n const response = await axios.post(`${this.baseUrl}/deepsearch`, payload, {\n headers: this.headers,\n });\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n tx_id: null,\n query,\n results: [],\n results_by_source: { web: 0, proprietary: 0 },\n total_deduction_pcm: 0.0,\n total_deduction_dollars: 0.0,\n total_characters: 0,\n };\n }\n }\n\n /**\n * Extract content from URLs with optional AI processing\n * @param urls - Array of URLs to process (max 10)\n * @param options - Content extraction configuration options\n * @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema\n * @param options.extractEffort - Extraction thoroughness: \"normal\" or \"high\"\n * @param options.responseLength - Content length per URL\n * @param options.maxPriceDollars - Maximum cost limit in USD\n * @returns Promise resolving to content extraction results\n */\n async contents(\n urls: string[],\n options: ContentsOptions = {}\n ): Promise<ContentsResponse> {\n try {\n // Validate URLs array\n if (!urls || !Array.isArray(urls)) {\n return {\n success: false,\n error: \"urls must be an array\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n if (urls.length === 0) {\n return {\n success: false,\n error: \"urls array cannot be empty\",\n urls_requested: 0,\n urls_processed: 0,\n urls_failed: 0,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n if (urls.length > 10) {\n return {\n success: false,\n error: \"Maximum 10 URLs allowed per request\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n // Validate extractEffort if provided\n if (\n options.extractEffort &&\n ![\"normal\", \"high\", \"auto\"].includes(options.extractEffort)\n ) {\n return {\n success: false,\n error: \"extractEffort must be 'normal', 'high', or 'auto'\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n // Validate responseLength if provided\n if (options.responseLength !== undefined) {\n const validLengths = [\"short\", \"medium\", \"large\", \"max\"];\n if (\n typeof options.responseLength === \"string\" &&\n !validLengths.includes(options.responseLength)\n ) {\n return {\n success: false,\n error:\n \"responseLength must be 'short', 'medium', 'large', 'max', or a number\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n if (\n typeof options.responseLength === \"number\" &&\n options.responseLength <= 0\n ) {\n return {\n success: false,\n error: \"responseLength number must be positive\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n urls,\n };\n\n // Add optional parameters only if provided\n if (options.summary !== undefined) {\n payload.summary = options.summary;\n }\n\n if (options.extractEffort !== undefined) {\n payload.extract_effort = options.extractEffort;\n }\n\n if (options.responseLength !== undefined) {\n payload.response_length = options.responseLength;\n }\n\n if (options.maxPriceDollars !== undefined) {\n payload.max_price_dollars = options.maxPriceDollars;\n }\n\n const response = await axios.post(`${this.baseUrl}/contents`, payload, {\n headers: this.headers,\n });\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error || \"Request failed\",\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n urls_requested: urls.length,\n urls_processed: 0,\n urls_failed: urls.length,\n results: [],\n total_cost_dollars: 0,\n total_characters: 0,\n };\n }\n }\n\n /**\n * Get AI-powered answers using the Valyu Answer API\n * @param query - The question or query string\n * @param options - Answer configuration options\n * @param options.structuredOutput - JSON Schema object for structured responses\n * @param options.systemInstructions - Custom system-level instructions (max 2000 chars)\n * @param options.searchType - Type of search: \"web\", \"proprietary\", or \"all\"\n * @param options.dataMaxPrice - Maximum spend (USD) for data retrieval\n * @param options.countryCode - Country code filter for search results\n * @param options.includedSources - List of specific sources to include\n * @param options.excludedSources - List of URLs/domains to exclude from search results\n * @param options.startDate - Start date filter (YYYY-MM-DD format)\n * @param options.endDate - End date filter (YYYY-MM-DD format)\n * @param options.fastMode - Fast mode for quicker but shorter results (default: false)\n * @returns Promise resolving to answer response\n */\n async answer(\n query: string,\n options: AnswerOptions = {}\n ): Promise<AnswerResponse> {\n try {\n // Default values\n const defaultSearchType: SearchType = \"all\";\n const defaultDataMaxPrice = 30.0;\n\n // Validate query\n if (!query || typeof query !== \"string\" || query.trim().length === 0) {\n return {\n success: false,\n error: \"Query is required and must be a non-empty string\",\n };\n }\n\n // Validate searchType\n let finalSearchType: SearchType = defaultSearchType;\n const providedSearchTypeString = options.searchType?.toLowerCase();\n\n if (\n providedSearchTypeString === \"web\" ||\n providedSearchTypeString === \"proprietary\" ||\n providedSearchTypeString === \"all\"\n ) {\n finalSearchType = providedSearchTypeString as SearchType;\n } else if (options.searchType !== undefined) {\n return {\n success: false,\n error:\n \"Invalid searchType provided. Must be one of: all, web, proprietary\",\n };\n }\n\n // Validate systemInstructions length\n if (options.systemInstructions !== undefined) {\n if (typeof options.systemInstructions !== \"string\") {\n return {\n success: false,\n error: \"systemInstructions must be a string\",\n };\n }\n\n const trimmed = options.systemInstructions.trim();\n if (trimmed.length === 0) {\n return {\n success: false,\n error: \"systemInstructions cannot be empty when provided\",\n };\n }\n\n if (trimmed.length > 2000) {\n return {\n success: false,\n error: \"systemInstructions must be 2000 characters or less\",\n };\n }\n }\n\n // Validate dataMaxPrice\n if (options.dataMaxPrice !== undefined) {\n if (\n typeof options.dataMaxPrice !== \"number\" ||\n options.dataMaxPrice <= 0\n ) {\n return {\n success: false,\n error: \"dataMaxPrice must be a positive number\",\n };\n }\n }\n\n // Validate date formats\n if (options.startDate && !this.validateDateFormat(options.startDate)) {\n return {\n success: false,\n error: \"Invalid startDate format. Must be YYYY-MM-DD\",\n };\n }\n\n if (options.endDate && !this.validateDateFormat(options.endDate)) {\n return {\n success: false,\n error: \"Invalid endDate format. Must be YYYY-MM-DD\",\n };\n }\n\n // Validate date order\n if (options.startDate && options.endDate) {\n const startDate = new Date(options.startDate);\n const endDate = new Date(options.endDate);\n if (startDate > endDate) {\n return {\n success: false,\n error: \"startDate must be before endDate\",\n };\n }\n }\n\n // Validate includedSources format\n if (options.includedSources !== undefined) {\n if (!Array.isArray(options.includedSources)) {\n return {\n success: false,\n error: \"includedSources must be an array\",\n };\n }\n\n const includedSourcesValidation = this.validateSources(\n options.includedSources\n );\n if (!includedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid includedSources format. Invalid sources: ${includedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n };\n }\n }\n\n // Validate excludedSources format\n if (options.excludedSources !== undefined) {\n if (!Array.isArray(options.excludedSources)) {\n return {\n success: false,\n error: \"excludedSources must be an array\",\n };\n }\n\n const excludedSourcesValidation = this.validateSources(\n options.excludedSources\n );\n if (!excludedSourcesValidation.valid) {\n return {\n success: false,\n error: `Invalid excludedSources format. Invalid sources: ${excludedSourcesValidation.invalidSources.join(\n \", \"\n )}. Sources must be valid URLs, domains (with optional paths), or dataset identifiers in 'provider/dataset' format.`,\n };\n }\n }\n\n // Build payload with snake_case for API\n const payload: Record<string, any> = {\n query: query.trim(),\n search_type: finalSearchType,\n data_max_price: options.dataMaxPrice ?? defaultDataMaxPrice,\n };\n\n // Add optional parameters only if provided\n if (options.structuredOutput !== undefined) {\n payload.structured_output = options.structuredOutput;\n }\n\n if (options.systemInstructions !== undefined) {\n payload.system_instructions = options.systemInstructions.trim();\n }\n\n if (options.countryCode !== undefined) {\n payload.country_code = options.countryCode;\n }\n\n if (options.includedSources !== undefined) {\n payload.included_sources = options.includedSources;\n }\n\n if (options.excludedSources !== undefined) {\n payload.excluded_sources = options.excludedSources;\n }\n\n if (options.startDate !== undefined) {\n payload.start_date = options.startDate;\n }\n\n if (options.endDate !== undefined) {\n payload.end_date = options.endDate;\n }\n\n if (options.fastMode !== undefined) {\n payload.fast_mode = options.fastMode;\n }\n\n const response = await axios.post(`${this.baseUrl}/answer`, payload, {\n headers: this.headers,\n });\n\n if (!response.status || response.status < 200 || response.status >= 300) {\n return {\n success: false,\n error: response.data?.error || \"Request failed\",\n };\n }\n\n return response.data;\n } catch (e: any) {\n return {\n success: false,\n error: e.response?.data?.error || e.message,\n };\n }\n }\n}\n\nexport type {\n SearchResponse,\n SearchType,\n FeedbackSentiment,\n FeedbackResponse,\n SearchOptions,\n CountryCode,\n ResponseLength,\n ContentsOptions,\n ContentsResponse,\n ContentResult,\n ExtractEffort,\n ContentResponseLength,\n AnswerOptions,\n AnswerResponse,\n AnswerSuccessResponse,\n AnswerErrorResponse,\n SearchMetadata,\n AIUsage,\n Cost,\n} from \"./types\";\n"],"mappings":";AAAA,OAAO,WAAW;AAWX,IAAM,QAAN,MAAY;AAAA,EAIjB,YACE,QACA,UAAkB,gCAClB;AACA,QAAI,CAAC,QAAQ;AACX,eAAS,QAAQ,IAAI;AACrB,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,MAAM,0BAA0B;AAAA,MAC5C;AAAA,IACF;AACA,SAAK,UAAU;AACf,SAAK,UAAU;AAAA,MACb,gBAAgB;AAAA,MAChB,aAAa;AAAA,IACf;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,mBAAmB,MAAuB;AAChD,UAAM,YAAY;AAClB,QAAI,CAAC,UAAU,KAAK,IAAI,GAAG;AACzB,aAAO;AAAA,IACT;AACA,UAAM,aAAa,IAAI,KAAK,IAAI;AAChC,WAAO,sBAAsB,QAAQ,CAAC,MAAM,WAAW,QAAQ,CAAC;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA,EAKQ,YAAY,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AA,MACrC;AAEA,UAAI,QAAQ,oBAAoB,QAAW;AACzC,gBAAQ,mBAAmB,QAAQ;AAAA,MACrC;AAEA,UAAI,QAAQ,cAAc,QAAW;AACnC,gBAAQ,aAAa,QAAQ;AAAA,MAC/B;AAEA,UAAI,QAAQ,YAAY,QAAW;AACjC,gBAAQ,WAAW,QAAQ;AAAA,MAC7B;AAEA,UAAI,QAAQ,aAAa,QAAW;AAClC,gBAAQ,YAAY,QAAQ;AAAA,MAC9B;AAEA,YAAM,WAAW,MAAM,MAAM,KAAK,GAAG,KAAK,OAAO,WAAW,SAAS;AAAA,QACnE,SAAS,KAAK;AAAA,MAChB,CAAC;AAED,UAAI,CAAC,SAAS,UAAU,SAAS,SAAS,OAAO,SAAS,UAAU,KAAK;AACvE,eAAO;AAAA,UACL,SAAS;AAAA,UACT,OAAO,SAAS,MAAM,SAAS;AAAA,QACjC;AAAA,MACF;AAEA,aAAO,SAAS;AAAA,IAClB,SAAS,GAAQ;AACf,aAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO,EAAE,UAAU,MAAM,SAAS,EAAE;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valyu-js",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "Search for AIs - DeepSearch and Content API.",
5
5
  "files": [
6
6
  "dist"