valyu-js 2.7.17 → 2.8.0

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.mjs CHANGED
@@ -3,7 +3,7 @@ import { createHmac, timingSafeEqual } from "crypto";
3
3
  import http from "http";
4
4
  import https from "https";
5
5
  import axios from "axios";
6
- var SDK_VERSION = "2.7.17";
6
+ var SDK_VERSION = "2.8.0";
7
7
  function normalizeContentsJobResponse(api) {
8
8
  return {
9
9
  success: api.success ?? true,
@@ -94,6 +94,15 @@ var Valyu = class {
94
94
  list: this._datasourcesList.bind(this),
95
95
  categories: this._datasourcesCategories.bind(this)
96
96
  };
97
+ this.workflows = {
98
+ list: this._workflowsList.bind(this),
99
+ get: this._workflowsGet.bind(this),
100
+ versions: this._workflowsVersions.bind(this),
101
+ preview: this._workflowsPreview.bind(this),
102
+ create: this._workflowsCreate.bind(this),
103
+ update: this._workflowsUpdate.bind(this),
104
+ delete: this._workflowsDelete.bind(this)
105
+ };
97
106
  }
98
107
  /**
99
108
  * Validates date format (YYYY-MM-DD)
@@ -178,6 +187,7 @@ var Valyu = class {
178
187
  * @param options.category - Category filter for search results
179
188
  * @param options.startDate - Start date filter (YYYY-MM-DD format)
180
189
  * @param options.endDate - End date filter (YYYY-MM-DD format)
190
+ * @param options.historicalCache - When true and a date range is set, return the newest cached snapshot inside the range instead of the latest crawl. No-op without a date range (default: false)
181
191
  * @param options.countryCode - Country code filter for search results
182
192
  * @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
183
193
  * @param options.fastMode - Fast mode for quicker but shorter results (default: false)
@@ -333,6 +343,9 @@ var Valyu = class {
333
343
  if (options.endDate !== void 0) {
334
344
  payload.end_date = options.endDate;
335
345
  }
346
+ if (options.historicalCache !== void 0) {
347
+ payload.historical_cache = options.historicalCache;
348
+ }
336
349
  if (options.countryCode !== void 0) {
337
350
  payload.country_code = options.countryCode;
338
351
  }
@@ -388,6 +401,9 @@ var Valyu = class {
388
401
  * @param options.screenshot - Request page screenshots (default: false)
389
402
  * @param options.async - Force async processing (required for >10 URLs)
390
403
  * @param options.webhookUrl - HTTPS URL for completion notification (async only)
404
+ * @param options.startDate - Start date filter (YYYY-MM-DD format), inclusive
405
+ * @param options.endDate - End date filter (YYYY-MM-DD format), inclusive
406
+ * @param options.historicalCache - When true and a date range is set, return the newest cached snapshot inside the range instead of the latest crawl. No-op without a date range (default: false)
391
407
  * @returns Promise resolving to sync results or async job (when async: true or >10 URLs)
392
408
  */
393
409
  async contents(urls, options = {}) {
@@ -504,6 +520,15 @@ var Valyu = class {
504
520
  if (options.webhookUrl !== void 0) {
505
521
  payload.webhook_url = options.webhookUrl;
506
522
  }
523
+ if (options.startDate !== void 0) {
524
+ payload.start_date = options.startDate;
525
+ }
526
+ if (options.endDate !== void 0) {
527
+ payload.end_date = options.endDate;
528
+ }
529
+ if (options.historicalCache !== void 0) {
530
+ payload.historical_cache = options.historicalCache;
531
+ }
507
532
  const response = await this.client.post(`${this.baseUrl}/contents`, payload, {
508
533
  headers: this.headers
509
534
  });
@@ -599,11 +624,47 @@ var Valyu = class {
599
624
  * @param options.search.excludedSources - Array of source types to exclude (e.g., ["web", "patent"])
600
625
  * @param options.search.startDate - Start date filter in ISO format (YYYY-MM-DD)
601
626
  * @param options.search.endDate - End date filter in ISO format (YYYY-MM-DD)
627
+ * @param options.search.historicalCache - When true and a date range is set, searches return the newest cached snapshot inside the range instead of the latest crawl. Locked for the whole research run — the agent cannot toggle it mid-research
602
628
  * @param options.search.category - Category filter for search results
603
629
  */
604
630
  async _deepresearchCreate(options) {
605
631
  try {
606
632
  const queryValue = options.query ?? options.input;
633
+ if (options.workflowId) {
634
+ if (queryValue || options.strategy || options.researchStrategy || options.reportFormat) {
635
+ return {
636
+ success: false,
637
+ error: "workflowId is mutually exclusive with query/input/researchStrategy/reportFormat - the workflow template supplies those fields"
638
+ };
639
+ }
640
+ const payload2 = {
641
+ workflow_id: options.workflowId
642
+ };
643
+ if (options.workflowParams !== void 0) {
644
+ payload2.workflow_params = options.workflowParams;
645
+ }
646
+ if (options.workflowVersion !== void 0) {
647
+ payload2.workflow_version = options.workflowVersion;
648
+ }
649
+ const explicitMode = options.mode ?? options.model;
650
+ if (explicitMode) payload2.mode = explicitMode;
651
+ if (options.outputFormats) payload2.output_formats = options.outputFormats;
652
+ if (options.tools) payload2.tools = options.tools;
653
+ if (options.webhookUrl) payload2.webhook_url = options.webhookUrl;
654
+ if (options.alertEmail) {
655
+ payload2.alert_email = typeof options.alertEmail === "string" ? options.alertEmail : {
656
+ email: options.alertEmail.email,
657
+ custom_url: options.alertEmail.custom_url
658
+ };
659
+ }
660
+ if (options.metadata) payload2.metadata = options.metadata;
661
+ const response2 = await this.client.post(
662
+ `${this.baseUrl}/deepresearch/tasks`,
663
+ payload2,
664
+ { headers: this.headers }
665
+ );
666
+ return { success: true, ...response2.data };
667
+ }
607
668
  if (!queryValue?.trim()) {
608
669
  return {
609
670
  success: false,
@@ -672,6 +733,9 @@ var Valyu = class {
672
733
  if (options.search.endDate) {
673
734
  payload.search.end_date = options.search.endDate;
674
735
  }
736
+ if (options.search.historicalCache !== void 0) {
737
+ payload.search.historical_cache = options.search.historicalCache;
738
+ }
675
739
  if (options.search.category) {
676
740
  payload.search.category = options.search.category;
677
741
  }
@@ -1030,6 +1094,7 @@ var Valyu = class {
1030
1094
  * @param options.search.excludedSources - Array of source types to exclude (e.g., ["web", "patent"])
1031
1095
  * @param options.search.startDate - Start date filter in ISO format (YYYY-MM-DD)
1032
1096
  * @param options.search.endDate - End date filter in ISO format (YYYY-MM-DD)
1097
+ * @param options.search.historicalCache - When true and a date range is set, searches return the newest cached snapshot inside the range instead of the latest crawl
1033
1098
  * @param options.search.category - Category filter for search results
1034
1099
  * @param options.webhookUrl - Optional HTTPS URL for completion notification
1035
1100
  * @param options.metadata - Optional metadata key-value pairs
@@ -1062,6 +1127,9 @@ var Valyu = class {
1062
1127
  if (options.search.endDate) {
1063
1128
  payload.search.end_date = options.search.endDate;
1064
1129
  }
1130
+ if (options.search.historicalCache !== void 0) {
1131
+ payload.search.historical_cache = options.search.historicalCache;
1132
+ }
1065
1133
  if (options.search.category) {
1066
1134
  payload.search.category = options.search.category;
1067
1135
  }
@@ -1615,6 +1683,160 @@ var Valyu = class {
1615
1683
  };
1616
1684
  }
1617
1685
  }
1686
+ /** Extract the most descriptive error message from a Workflows API error. */
1687
+ workflowError(e) {
1688
+ return e.response?.data?.message || e.response?.data?.error || e.message;
1689
+ }
1690
+ /**
1691
+ * Workflows: List workflows available to your org
1692
+ * @param options - Filters: vertical, scope ("valyu" | "org" | "all"), q, tags, limit, expand
1693
+ */
1694
+ async _workflowsList(options = {}) {
1695
+ try {
1696
+ const params = new URLSearchParams();
1697
+ if (options.vertical) params.append("vertical", options.vertical);
1698
+ if (options.scope) params.append("scope", options.scope);
1699
+ if (options.q) params.append("q", options.q);
1700
+ if (options.tags?.length) params.append("tags", options.tags.join(","));
1701
+ if (options.limit !== void 0) {
1702
+ params.append("limit", String(options.limit));
1703
+ }
1704
+ if (options.expand) params.append("expand", "true");
1705
+ const url = `${this.baseUrl}/workflows${params.toString() ? `?${params.toString()}` : ""}`;
1706
+ const response = await this.client.get(url, { headers: this.headers });
1707
+ return { success: true, ...response.data };
1708
+ } catch (e) {
1709
+ return { success: false, error: this.workflowError(e) };
1710
+ }
1711
+ }
1712
+ /**
1713
+ * Workflows: Get a workflow's full detail, including its template
1714
+ * @param slug - Workflow slug
1715
+ * @param version - Specific version to fetch (defaults to the current version)
1716
+ */
1717
+ async _workflowsGet(slug, version) {
1718
+ try {
1719
+ const url = `${this.baseUrl}/workflows/${encodeURIComponent(slug)}${version !== void 0 ? `?version=${version}` : ""}`;
1720
+ const response = await this.client.get(url, { headers: this.headers });
1721
+ return { success: true, workflow: response.data };
1722
+ } catch (e) {
1723
+ return { success: false, error: this.workflowError(e) };
1724
+ }
1725
+ }
1726
+ /**
1727
+ * Workflows: List a workflow's version history
1728
+ * @param slug - Workflow slug
1729
+ */
1730
+ async _workflowsVersions(slug) {
1731
+ try {
1732
+ const response = await this.client.get(
1733
+ `${this.baseUrl}/workflows/${encodeURIComponent(slug)}/versions`,
1734
+ { headers: this.headers }
1735
+ );
1736
+ return { success: true, ...response.data };
1737
+ } catch (e) {
1738
+ return { success: false, error: this.workflowError(e) };
1739
+ }
1740
+ }
1741
+ /**
1742
+ * Workflows: Resolve a workflow's template with params without creating a task
1743
+ * @param slug - Workflow slug
1744
+ * @param options - workflowParams (variable values) and optional workflowVersion
1745
+ */
1746
+ async _workflowsPreview(slug, options = {}) {
1747
+ try {
1748
+ const payload = {};
1749
+ if (options.workflowParams !== void 0) {
1750
+ payload.workflow_params = options.workflowParams;
1751
+ }
1752
+ if (options.workflowVersion !== void 0) {
1753
+ payload.workflow_version = options.workflowVersion;
1754
+ }
1755
+ const response = await this.client.post(
1756
+ `${this.baseUrl}/workflows/${encodeURIComponent(slug)}/preview`,
1757
+ payload,
1758
+ { headers: this.headers }
1759
+ );
1760
+ return { success: true, ...response.data };
1761
+ } catch (e) {
1762
+ return { success: false, error: this.workflowError(e) };
1763
+ }
1764
+ }
1765
+ /**
1766
+ * Workflows: Create a new workflow for your org
1767
+ * @param options - slug, title, version (template body), and optional metadata
1768
+ */
1769
+ async _workflowsCreate(options) {
1770
+ try {
1771
+ const payload = {
1772
+ slug: options.slug,
1773
+ title: options.title,
1774
+ version: options.version
1775
+ };
1776
+ if (options.subtitle !== void 0) payload.subtitle = options.subtitle;
1777
+ if (options.description !== void 0) {
1778
+ payload.description = options.description;
1779
+ }
1780
+ if (options.vertical !== void 0) payload.vertical = options.vertical;
1781
+ if (options.tags !== void 0) payload.tags = options.tags;
1782
+ if (options.icon !== void 0) payload.icon = options.icon;
1783
+ const response = await this.client.post(
1784
+ `${this.baseUrl}/workflows`,
1785
+ payload,
1786
+ { headers: this.headers }
1787
+ );
1788
+ return { success: true, workflow: response.data };
1789
+ } catch (e) {
1790
+ return { success: false, error: this.workflowError(e) };
1791
+ }
1792
+ }
1793
+ /**
1794
+ * Workflows: Update a workflow's metadata and/or publish a new template version.
1795
+ * Only workflows owned by your org can be updated; versions are append-only
1796
+ * (a version body requires a changelog).
1797
+ * @param slug - Workflow slug
1798
+ * @param options - Metadata fields and/or a new version body
1799
+ */
1800
+ async _workflowsUpdate(slug, options) {
1801
+ try {
1802
+ const payload = {};
1803
+ if (options.title !== void 0) payload.title = options.title;
1804
+ if (options.subtitle !== void 0) payload.subtitle = options.subtitle;
1805
+ if (options.description !== void 0) {
1806
+ payload.description = options.description;
1807
+ }
1808
+ if (options.vertical !== void 0) payload.vertical = options.vertical;
1809
+ if (options.tags !== void 0) payload.tags = options.tags;
1810
+ if (options.icon !== void 0) payload.icon = options.icon;
1811
+ if (options.version !== void 0) payload.version = options.version;
1812
+ if (options.setCurrent !== void 0) {
1813
+ payload.set_current = options.setCurrent;
1814
+ }
1815
+ const response = await this.client.patch(
1816
+ `${this.baseUrl}/workflows/${encodeURIComponent(slug)}`,
1817
+ payload,
1818
+ { headers: this.headers }
1819
+ );
1820
+ return { success: true, workflow: response.data };
1821
+ } catch (e) {
1822
+ return { success: false, error: this.workflowError(e) };
1823
+ }
1824
+ }
1825
+ /**
1826
+ * Workflows: Delete a workflow owned by your org (soft delete)
1827
+ * @param slug - Workflow slug
1828
+ */
1829
+ async _workflowsDelete(slug) {
1830
+ try {
1831
+ const response = await this.client.delete(
1832
+ `${this.baseUrl}/workflows/${encodeURIComponent(slug)}`,
1833
+ { headers: this.headers }
1834
+ );
1835
+ return { success: true, ...response.data };
1836
+ } catch (e) {
1837
+ return { success: false, error: this.workflowError(e) };
1838
+ }
1839
+ }
1618
1840
  };
1619
1841
  export {
1620
1842
  Valyu,