valyu-js 2.3.3 → 2.4.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
@@ -59,6 +59,7 @@ interface ContentsOptions {
59
59
  extractEffort?: ExtractEffort;
60
60
  responseLength?: ContentResponseLength;
61
61
  maxPriceDollars?: number;
62
+ screenshot?: boolean;
62
63
  }
63
64
  interface ContentResult {
64
65
  url: string;
@@ -66,10 +67,13 @@ interface ContentResult {
66
67
  content: string | number;
67
68
  length: number;
68
69
  source: string;
70
+ price: number;
71
+ description?: string;
69
72
  summary?: string | object;
70
73
  summary_success?: boolean;
71
74
  data_type?: string;
72
75
  image_url?: Record<string, string>;
76
+ screenshot_url?: string | null;
73
77
  citation?: string;
74
78
  }
75
79
  interface ContentsResponse {
@@ -154,7 +158,7 @@ interface AnswerStreamChunk {
154
158
  }
155
159
  type DeepResearchMode = "fast" | "standard" | "lite" | "heavy";
156
160
  type DeepResearchStatus = "queued" | "running" | "completed" | "failed" | "cancelled";
157
- type DeepResearchOutputFormat = "markdown" | "pdf" | Record<string, any>;
161
+ type DeepResearchOutputFormat = "markdown" | "pdf" | "toon" | Record<string, any>;
158
162
  type DeepResearchOutputType = "markdown" | "json";
159
163
  type ImageType = "chart" | "ai_generated";
160
164
  type ChartType = "line" | "bar" | "area";
@@ -203,6 +207,10 @@ interface DeliverableResult {
203
207
  interface DeepResearchSearchConfig {
204
208
  searchType?: "all" | "web" | "proprietary";
205
209
  includedSources?: string[];
210
+ excludedSources?: string[];
211
+ startDate?: string;
212
+ endDate?: string;
213
+ category?: string;
206
214
  }
207
215
  interface DeepResearchCreateOptions {
208
216
  input: string;
@@ -393,10 +401,7 @@ interface CreateBatchOptions {
393
401
  name?: string;
394
402
  model?: DeepResearchMode;
395
403
  outputFormats?: DeepResearchOutputFormat[];
396
- search?: {
397
- searchType?: "all" | "web" | "proprietary";
398
- includedSources?: string[];
399
- };
404
+ search?: DeepResearchSearchConfig;
400
405
  webhookUrl?: string;
401
406
  metadata?: Record<string, string | number | boolean>;
402
407
  }
@@ -535,14 +540,22 @@ declare class Valyu {
535
540
  * @param urls - Array of URLs to process (max 10)
536
541
  * @param options - Content extraction configuration options
537
542
  * @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema
538
- * @param options.extractEffort - Extraction thoroughness: "normal" or "high"
543
+ * @param options.extractEffort - Extraction thoroughness: "normal", "high", or "auto"
539
544
  * @param options.responseLength - Content length per URL
540
545
  * @param options.maxPriceDollars - Maximum cost limit in USD
546
+ * @param options.screenshot - Request page screenshots (default: false)
541
547
  * @returns Promise resolving to content extraction results
542
548
  */
543
549
  contents(urls: string[], options?: ContentsOptions): Promise<ContentsResponse>;
544
550
  /**
545
551
  * DeepResearch: Create a new research task
552
+ * @param options.search - Search configuration options
553
+ * @param options.search.searchType - Type of search: "all", "web", or "proprietary" (default: "all")
554
+ * @param options.search.includedSources - Array of source types to include (e.g., ["academic", "finance", "web"])
555
+ * @param options.search.excludedSources - Array of source types to exclude (e.g., ["web", "patent"])
556
+ * @param options.search.startDate - Start date filter in ISO format (YYYY-MM-DD)
557
+ * @param options.search.endDate - End date filter in ISO format (YYYY-MM-DD)
558
+ * @param options.search.category - Category filter for search results
546
559
  */
547
560
  private _deepresearchCreate;
548
561
  /**
@@ -584,6 +597,12 @@ declare class Valyu {
584
597
  * @param options.model - DeepResearch mode: "fast", "standard", or "heavy" (default: "standard")
585
598
  * @param options.outputFormats - Output formats for tasks (default: ["markdown"])
586
599
  * @param options.search - Search configuration for all tasks in batch
600
+ * @param options.search.searchType - Type of search: "all", "web", or "proprietary" (default: "all")
601
+ * @param options.search.includedSources - Array of source types to include (e.g., ["academic", "finance", "web"])
602
+ * @param options.search.excludedSources - Array of source types to exclude (e.g., ["web", "patent"])
603
+ * @param options.search.startDate - Start date filter in ISO format (YYYY-MM-DD)
604
+ * @param options.search.endDate - End date filter in ISO format (YYYY-MM-DD)
605
+ * @param options.search.category - Category filter for search results
587
606
  * @param options.webhookUrl - Optional HTTPS URL for completion notification
588
607
  * @param options.metadata - Optional metadata key-value pairs
589
608
  * @returns Promise resolving to batch creation response with batch_id and webhook_secret
package/dist/index.d.ts CHANGED
@@ -59,6 +59,7 @@ interface ContentsOptions {
59
59
  extractEffort?: ExtractEffort;
60
60
  responseLength?: ContentResponseLength;
61
61
  maxPriceDollars?: number;
62
+ screenshot?: boolean;
62
63
  }
63
64
  interface ContentResult {
64
65
  url: string;
@@ -66,10 +67,13 @@ interface ContentResult {
66
67
  content: string | number;
67
68
  length: number;
68
69
  source: string;
70
+ price: number;
71
+ description?: string;
69
72
  summary?: string | object;
70
73
  summary_success?: boolean;
71
74
  data_type?: string;
72
75
  image_url?: Record<string, string>;
76
+ screenshot_url?: string | null;
73
77
  citation?: string;
74
78
  }
75
79
  interface ContentsResponse {
@@ -154,7 +158,7 @@ interface AnswerStreamChunk {
154
158
  }
155
159
  type DeepResearchMode = "fast" | "standard" | "lite" | "heavy";
156
160
  type DeepResearchStatus = "queued" | "running" | "completed" | "failed" | "cancelled";
157
- type DeepResearchOutputFormat = "markdown" | "pdf" | Record<string, any>;
161
+ type DeepResearchOutputFormat = "markdown" | "pdf" | "toon" | Record<string, any>;
158
162
  type DeepResearchOutputType = "markdown" | "json";
159
163
  type ImageType = "chart" | "ai_generated";
160
164
  type ChartType = "line" | "bar" | "area";
@@ -203,6 +207,10 @@ interface DeliverableResult {
203
207
  interface DeepResearchSearchConfig {
204
208
  searchType?: "all" | "web" | "proprietary";
205
209
  includedSources?: string[];
210
+ excludedSources?: string[];
211
+ startDate?: string;
212
+ endDate?: string;
213
+ category?: string;
206
214
  }
207
215
  interface DeepResearchCreateOptions {
208
216
  input: string;
@@ -393,10 +401,7 @@ interface CreateBatchOptions {
393
401
  name?: string;
394
402
  model?: DeepResearchMode;
395
403
  outputFormats?: DeepResearchOutputFormat[];
396
- search?: {
397
- searchType?: "all" | "web" | "proprietary";
398
- includedSources?: string[];
399
- };
404
+ search?: DeepResearchSearchConfig;
400
405
  webhookUrl?: string;
401
406
  metadata?: Record<string, string | number | boolean>;
402
407
  }
@@ -535,14 +540,22 @@ declare class Valyu {
535
540
  * @param urls - Array of URLs to process (max 10)
536
541
  * @param options - Content extraction configuration options
537
542
  * @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema
538
- * @param options.extractEffort - Extraction thoroughness: "normal" or "high"
543
+ * @param options.extractEffort - Extraction thoroughness: "normal", "high", or "auto"
539
544
  * @param options.responseLength - Content length per URL
540
545
  * @param options.maxPriceDollars - Maximum cost limit in USD
546
+ * @param options.screenshot - Request page screenshots (default: false)
541
547
  * @returns Promise resolving to content extraction results
542
548
  */
543
549
  contents(urls: string[], options?: ContentsOptions): Promise<ContentsResponse>;
544
550
  /**
545
551
  * DeepResearch: Create a new research task
552
+ * @param options.search - Search configuration options
553
+ * @param options.search.searchType - Type of search: "all", "web", or "proprietary" (default: "all")
554
+ * @param options.search.includedSources - Array of source types to include (e.g., ["academic", "finance", "web"])
555
+ * @param options.search.excludedSources - Array of source types to exclude (e.g., ["web", "patent"])
556
+ * @param options.search.startDate - Start date filter in ISO format (YYYY-MM-DD)
557
+ * @param options.search.endDate - End date filter in ISO format (YYYY-MM-DD)
558
+ * @param options.search.category - Category filter for search results
546
559
  */
547
560
  private _deepresearchCreate;
548
561
  /**
@@ -584,6 +597,12 @@ declare class Valyu {
584
597
  * @param options.model - DeepResearch mode: "fast", "standard", or "heavy" (default: "standard")
585
598
  * @param options.outputFormats - Output formats for tasks (default: ["markdown"])
586
599
  * @param options.search - Search configuration for all tasks in batch
600
+ * @param options.search.searchType - Type of search: "all", "web", or "proprietary" (default: "all")
601
+ * @param options.search.includedSources - Array of source types to include (e.g., ["academic", "finance", "web"])
602
+ * @param options.search.excludedSources - Array of source types to exclude (e.g., ["web", "patent"])
603
+ * @param options.search.startDate - Start date filter in ISO format (YYYY-MM-DD)
604
+ * @param options.search.endDate - End date filter in ISO format (YYYY-MM-DD)
605
+ * @param options.search.category - Category filter for search results
587
606
  * @param options.webhookUrl - Optional HTTPS URL for completion notification
588
607
  * @param options.metadata - Optional metadata key-value pairs
589
608
  * @returns Promise resolving to batch creation response with batch_id and webhook_secret
package/dist/index.js CHANGED
@@ -359,9 +359,10 @@ var Valyu = class {
359
359
  * @param urls - Array of URLs to process (max 10)
360
360
  * @param options - Content extraction configuration options
361
361
  * @param options.summary - AI summary configuration: false (raw), true (auto), string (custom), or JSON schema
362
- * @param options.extractEffort - Extraction thoroughness: "normal" or "high"
362
+ * @param options.extractEffort - Extraction thoroughness: "normal", "high", or "auto"
363
363
  * @param options.responseLength - Content length per URL
364
364
  * @param options.maxPriceDollars - Maximum cost limit in USD
365
+ * @param options.screenshot - Request page screenshots (default: false)
365
366
  * @returns Promise resolving to content extraction results
366
367
  */
367
368
  async contents(urls, options = {}) {
@@ -456,6 +457,9 @@ var Valyu = class {
456
457
  if (options.maxPriceDollars !== void 0) {
457
458
  payload.max_price_dollars = options.maxPriceDollars;
458
459
  }
460
+ if (options.screenshot !== void 0) {
461
+ payload.screenshot = options.screenshot;
462
+ }
459
463
  const response = await import_axios.default.post(`${this.baseUrl}/contents`, payload, {
460
464
  headers: this.headers
461
465
  });
@@ -487,6 +491,13 @@ var Valyu = class {
487
491
  }
488
492
  /**
489
493
  * DeepResearch: Create a new research task
494
+ * @param options.search - Search configuration options
495
+ * @param options.search.searchType - Type of search: "all", "web", or "proprietary" (default: "all")
496
+ * @param options.search.includedSources - Array of source types to include (e.g., ["academic", "finance", "web"])
497
+ * @param options.search.excludedSources - Array of source types to exclude (e.g., ["web", "patent"])
498
+ * @param options.search.startDate - Start date filter in ISO format (YYYY-MM-DD)
499
+ * @param options.search.endDate - End date filter in ISO format (YYYY-MM-DD)
500
+ * @param options.search.category - Category filter for search results
490
501
  */
491
502
  async _deepresearchCreate(options) {
492
503
  try {
@@ -504,10 +515,25 @@ var Valyu = class {
504
515
  };
505
516
  if (options.strategy) payload.strategy = options.strategy;
506
517
  if (options.search) {
507
- payload.search = {
508
- search_type: options.search.searchType,
509
- included_sources: options.search.includedSources
510
- };
518
+ payload.search = {};
519
+ if (options.search.searchType) {
520
+ payload.search.search_type = options.search.searchType;
521
+ }
522
+ if (options.search.includedSources) {
523
+ payload.search.included_sources = options.search.includedSources;
524
+ }
525
+ if (options.search.excludedSources) {
526
+ payload.search.excluded_sources = options.search.excludedSources;
527
+ }
528
+ if (options.search.startDate) {
529
+ payload.search.start_date = options.search.startDate;
530
+ }
531
+ if (options.search.endDate) {
532
+ payload.search.end_date = options.search.endDate;
533
+ }
534
+ if (options.search.category) {
535
+ payload.search.category = options.search.category;
536
+ }
511
537
  }
512
538
  if (options.urls) payload.urls = options.urls;
513
539
  if (options.files) payload.files = options.files;
@@ -724,6 +750,12 @@ var Valyu = class {
724
750
  * @param options.model - DeepResearch mode: "fast", "standard", or "heavy" (default: "standard")
725
751
  * @param options.outputFormats - Output formats for tasks (default: ["markdown"])
726
752
  * @param options.search - Search configuration for all tasks in batch
753
+ * @param options.search.searchType - Type of search: "all", "web", or "proprietary" (default: "all")
754
+ * @param options.search.includedSources - Array of source types to include (e.g., ["academic", "finance", "web"])
755
+ * @param options.search.excludedSources - Array of source types to exclude (e.g., ["web", "patent"])
756
+ * @param options.search.startDate - Start date filter in ISO format (YYYY-MM-DD)
757
+ * @param options.search.endDate - End date filter in ISO format (YYYY-MM-DD)
758
+ * @param options.search.category - Category filter for search results
727
759
  * @param options.webhookUrl - Optional HTTPS URL for completion notification
728
760
  * @param options.metadata - Optional metadata key-value pairs
729
761
  * @returns Promise resolving to batch creation response with batch_id and webhook_secret
@@ -735,10 +767,25 @@ var Valyu = class {
735
767
  if (options.model) payload.model = options.model;
736
768
  if (options.outputFormats) payload.output_formats = options.outputFormats;
737
769
  if (options.search) {
738
- payload.search = {
739
- search_type: options.search.searchType,
740
- included_sources: options.search.includedSources
741
- };
770
+ payload.search = {};
771
+ if (options.search.searchType) {
772
+ payload.search.search_type = options.search.searchType;
773
+ }
774
+ if (options.search.includedSources) {
775
+ payload.search.included_sources = options.search.includedSources;
776
+ }
777
+ if (options.search.excludedSources) {
778
+ payload.search.excluded_sources = options.search.excludedSources;
779
+ }
780
+ if (options.search.startDate) {
781
+ payload.search.start_date = options.search.startDate;
782
+ }
783
+ if (options.search.endDate) {
784
+ payload.search.end_date = options.search.endDate;
785
+ }
786
+ if (options.search.category) {
787
+ payload.search.category = options.search.category;
788
+ }
742
789
  }
743
790
  if (options.webhookUrl) payload.webhook_url = options.webhookUrl;
744
791
  if (options.metadata) payload.metadata = options.metadata;
@@ -795,9 +842,25 @@ var Valyu = class {
795
842
  error: "tasks array cannot be empty"
796
843
  };
797
844
  }
845
+ if (options.tasks.length > 100) {
846
+ return {
847
+ success: false,
848
+ error: "Maximum 100 tasks allowed per request"
849
+ };
850
+ }
851
+ const tasksPayload = options.tasks.map((task) => {
852
+ const taskPayload = {
853
+ input: task.input
854
+ };
855
+ if (task.id) taskPayload.id = task.id;
856
+ if (task.strategy) taskPayload.strategy = task.strategy;
857
+ if (task.urls) taskPayload.urls = task.urls;
858
+ if (task.metadata) taskPayload.metadata = task.metadata;
859
+ return taskPayload;
860
+ });
798
861
  const response = await import_axios.default.post(
799
862
  `${this.baseUrl}/deepresearch/batches/${batchId}/tasks`,
800
- { tasks: options.tasks },
863
+ { tasks: tasksPayload },
801
864
  { headers: this.headers }
802
865
  );
803
866
  return { success: true, ...response.data };
@@ -853,10 +916,9 @@ var Valyu = class {
853
916
  */
854
917
  async _batchList() {
855
918
  try {
856
- const response = await import_axios.default.get(
857
- `${this.baseUrl}/deepresearch/batches`,
858
- { headers: this.headers }
859
- );
919
+ const response = await import_axios.default.get(`${this.baseUrl}/deepresearch/batches`, {
920
+ headers: this.headers
921
+ });
860
922
  return { success: true, batches: response.data };
861
923
  } catch (e) {
862
924
  return {
@@ -975,7 +1037,9 @@ var Valyu = class {
975
1037
  }
976
1038
  const validation = this.validateSources(options.includedSources);
977
1039
  if (!validation.valid) {
978
- return `Invalid includedSources format. Invalid sources: ${validation.invalidSources.join(", ")}.`;
1040
+ return `Invalid includedSources format. Invalid sources: ${validation.invalidSources.join(
1041
+ ", "
1042
+ )}.`;
979
1043
  }
980
1044
  }
981
1045
  if (options.excludedSources !== void 0) {
@@ -984,7 +1048,9 @@ var Valyu = class {
984
1048
  }
985
1049
  const validation = this.validateSources(options.excludedSources);
986
1050
  if (!validation.valid) {
987
- return `Invalid excludedSources format. Invalid sources: ${validation.invalidSources.join(", ")}.`;
1051
+ return `Invalid excludedSources format. Invalid sources: ${validation.invalidSources.join(
1052
+ ", "
1053
+ )}.`;
988
1054
  }
989
1055
  }
990
1056
  return null;
@@ -1003,12 +1069,18 @@ var Valyu = class {
1003
1069
  query: query.trim(),
1004
1070
  search_type: finalSearchType
1005
1071
  };
1006
- if (options.dataMaxPrice !== void 0) payload.data_max_price = options.dataMaxPrice;
1007
- if (options.structuredOutput !== void 0) payload.structured_output = options.structuredOutput;
1008
- if (options.systemInstructions !== void 0) payload.system_instructions = options.systemInstructions.trim();
1009
- if (options.countryCode !== void 0) payload.country_code = options.countryCode;
1010
- if (options.includedSources !== void 0) payload.included_sources = options.includedSources;
1011
- if (options.excludedSources !== void 0) payload.excluded_sources = options.excludedSources;
1072
+ if (options.dataMaxPrice !== void 0)
1073
+ payload.data_max_price = options.dataMaxPrice;
1074
+ if (options.structuredOutput !== void 0)
1075
+ payload.structured_output = options.structuredOutput;
1076
+ if (options.systemInstructions !== void 0)
1077
+ payload.system_instructions = options.systemInstructions.trim();
1078
+ if (options.countryCode !== void 0)
1079
+ payload.country_code = options.countryCode;
1080
+ if (options.includedSources !== void 0)
1081
+ payload.included_sources = options.includedSources;
1082
+ if (options.excludedSources !== void 0)
1083
+ payload.excluded_sources = options.excludedSources;
1012
1084
  if (options.startDate !== void 0) payload.start_date = options.startDate;
1013
1085
  if (options.endDate !== void 0) payload.end_date = options.endDate;
1014
1086
  if (options.fastMode !== void 0) payload.fast_mode = options.fastMode;
@@ -1023,7 +1095,7 @@ var Valyu = class {
1023
1095
  method: "POST",
1024
1096
  headers: {
1025
1097
  ...this.headers,
1026
- "Accept": "text/event-stream"
1098
+ Accept: "text/event-stream"
1027
1099
  },
1028
1100
  body: JSON.stringify(payload)
1029
1101
  });
@@ -1076,9 +1148,20 @@ var Valyu = class {
1076
1148
  contents: fullContent || finalMetadata.contents || "",
1077
1149
  data_type: finalMetadata.data_type || "unstructured",
1078
1150
  search_results: finalSearchResults,
1079
- search_metadata: finalMetadata.search_metadata || { tx_ids: [], number_of_results: 0, total_characters: 0 },
1080
- ai_usage: finalMetadata.ai_usage || { input_tokens: 0, output_tokens: 0 },
1081
- cost: finalMetadata.cost || { total_deduction_dollars: 0, search_deduction_dollars: 0, ai_deduction_dollars: 0 }
1151
+ search_metadata: finalMetadata.search_metadata || {
1152
+ tx_ids: [],
1153
+ number_of_results: 0,
1154
+ total_characters: 0
1155
+ },
1156
+ ai_usage: finalMetadata.ai_usage || {
1157
+ input_tokens: 0,
1158
+ output_tokens: 0
1159
+ },
1160
+ cost: finalMetadata.cost || {
1161
+ total_deduction_dollars: 0,
1162
+ search_deduction_dollars: 0,
1163
+ ai_deduction_dollars: 0
1164
+ }
1082
1165
  };
1083
1166
  if (finalMetadata.extraction_metadata) {
1084
1167
  response2.extraction_metadata = finalMetadata.extraction_metadata;
@@ -1105,13 +1188,16 @@ var Valyu = class {
1105
1188
  method: "POST",
1106
1189
  headers: {
1107
1190
  ...this.headers,
1108
- "Accept": "text/event-stream"
1191
+ Accept: "text/event-stream"
1109
1192
  },
1110
1193
  body: JSON.stringify(payload)
1111
1194
  });
1112
1195
  if (!response.ok) {
1113
1196
  const errorData = await response.json().catch(() => ({}));
1114
- yield { type: "error", error: errorData.error || `HTTP Error: ${response.status}` };
1197
+ yield {
1198
+ type: "error",
1199
+ error: errorData.error || `HTTP Error: ${response.status}`
1200
+ };
1115
1201
  return;
1116
1202
  }
1117
1203
  const reader = response.body?.getReader();
@@ -1137,7 +1223,10 @@ var Valyu = class {
1137
1223
  try {
1138
1224
  const parsed = JSON.parse(dataStr);
1139
1225
  if (parsed.search_results && parsed.success === void 0) {
1140
- yield { type: "search_results", search_results: parsed.search_results };
1226
+ yield {
1227
+ type: "search_results",
1228
+ search_results: parsed.search_results
1229
+ };
1141
1230
  } else if (parsed.choices) {
1142
1231
  const delta = parsed.choices[0]?.delta || {};
1143
1232
  const content = delta.content || "";