valyu-js 2.7.18 → 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)
@@ -621,6 +630,41 @@ var Valyu = class {
621
630
  async _deepresearchCreate(options) {
622
631
  try {
623
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
+ }
624
668
  if (!queryValue?.trim()) {
625
669
  return {
626
670
  success: false,
@@ -1639,6 +1683,160 @@ var Valyu = class {
1639
1683
  };
1640
1684
  }
1641
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
+ }
1642
1840
  };
1643
1841
  export {
1644
1842
  Valyu,