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/README.md +51 -0
- package/dist/index.d.mts +203 -1
- package/dist/index.d.ts +203 -1
- package/dist/index.js +199 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +199 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -38,7 +38,7 @@ var import_crypto = require("crypto");
|
|
|
38
38
|
var import_http = __toESM(require("http"));
|
|
39
39
|
var import_https = __toESM(require("https"));
|
|
40
40
|
var import_axios = __toESM(require("axios"));
|
|
41
|
-
var SDK_VERSION = "2.
|
|
41
|
+
var SDK_VERSION = "2.8.0";
|
|
42
42
|
function normalizeContentsJobResponse(api) {
|
|
43
43
|
return {
|
|
44
44
|
success: api.success ?? true,
|
|
@@ -129,6 +129,15 @@ var Valyu = class {
|
|
|
129
129
|
list: this._datasourcesList.bind(this),
|
|
130
130
|
categories: this._datasourcesCategories.bind(this)
|
|
131
131
|
};
|
|
132
|
+
this.workflows = {
|
|
133
|
+
list: this._workflowsList.bind(this),
|
|
134
|
+
get: this._workflowsGet.bind(this),
|
|
135
|
+
versions: this._workflowsVersions.bind(this),
|
|
136
|
+
preview: this._workflowsPreview.bind(this),
|
|
137
|
+
create: this._workflowsCreate.bind(this),
|
|
138
|
+
update: this._workflowsUpdate.bind(this),
|
|
139
|
+
delete: this._workflowsDelete.bind(this)
|
|
140
|
+
};
|
|
132
141
|
}
|
|
133
142
|
/**
|
|
134
143
|
* Validates date format (YYYY-MM-DD)
|
|
@@ -656,6 +665,41 @@ var Valyu = class {
|
|
|
656
665
|
async _deepresearchCreate(options) {
|
|
657
666
|
try {
|
|
658
667
|
const queryValue = options.query ?? options.input;
|
|
668
|
+
if (options.workflowId) {
|
|
669
|
+
if (queryValue || options.strategy || options.researchStrategy || options.reportFormat) {
|
|
670
|
+
return {
|
|
671
|
+
success: false,
|
|
672
|
+
error: "workflowId is mutually exclusive with query/input/researchStrategy/reportFormat - the workflow template supplies those fields"
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
const payload2 = {
|
|
676
|
+
workflow_id: options.workflowId
|
|
677
|
+
};
|
|
678
|
+
if (options.workflowParams !== void 0) {
|
|
679
|
+
payload2.workflow_params = options.workflowParams;
|
|
680
|
+
}
|
|
681
|
+
if (options.workflowVersion !== void 0) {
|
|
682
|
+
payload2.workflow_version = options.workflowVersion;
|
|
683
|
+
}
|
|
684
|
+
const explicitMode = options.mode ?? options.model;
|
|
685
|
+
if (explicitMode) payload2.mode = explicitMode;
|
|
686
|
+
if (options.outputFormats) payload2.output_formats = options.outputFormats;
|
|
687
|
+
if (options.tools) payload2.tools = options.tools;
|
|
688
|
+
if (options.webhookUrl) payload2.webhook_url = options.webhookUrl;
|
|
689
|
+
if (options.alertEmail) {
|
|
690
|
+
payload2.alert_email = typeof options.alertEmail === "string" ? options.alertEmail : {
|
|
691
|
+
email: options.alertEmail.email,
|
|
692
|
+
custom_url: options.alertEmail.custom_url
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
if (options.metadata) payload2.metadata = options.metadata;
|
|
696
|
+
const response2 = await this.client.post(
|
|
697
|
+
`${this.baseUrl}/deepresearch/tasks`,
|
|
698
|
+
payload2,
|
|
699
|
+
{ headers: this.headers }
|
|
700
|
+
);
|
|
701
|
+
return { success: true, ...response2.data };
|
|
702
|
+
}
|
|
659
703
|
if (!queryValue?.trim()) {
|
|
660
704
|
return {
|
|
661
705
|
success: false,
|
|
@@ -1674,6 +1718,160 @@ var Valyu = class {
|
|
|
1674
1718
|
};
|
|
1675
1719
|
}
|
|
1676
1720
|
}
|
|
1721
|
+
/** Extract the most descriptive error message from a Workflows API error. */
|
|
1722
|
+
workflowError(e) {
|
|
1723
|
+
return e.response?.data?.message || e.response?.data?.error || e.message;
|
|
1724
|
+
}
|
|
1725
|
+
/**
|
|
1726
|
+
* Workflows: List workflows available to your org
|
|
1727
|
+
* @param options - Filters: vertical, scope ("valyu" | "org" | "all"), q, tags, limit, expand
|
|
1728
|
+
*/
|
|
1729
|
+
async _workflowsList(options = {}) {
|
|
1730
|
+
try {
|
|
1731
|
+
const params = new URLSearchParams();
|
|
1732
|
+
if (options.vertical) params.append("vertical", options.vertical);
|
|
1733
|
+
if (options.scope) params.append("scope", options.scope);
|
|
1734
|
+
if (options.q) params.append("q", options.q);
|
|
1735
|
+
if (options.tags?.length) params.append("tags", options.tags.join(","));
|
|
1736
|
+
if (options.limit !== void 0) {
|
|
1737
|
+
params.append("limit", String(options.limit));
|
|
1738
|
+
}
|
|
1739
|
+
if (options.expand) params.append("expand", "true");
|
|
1740
|
+
const url = `${this.baseUrl}/workflows${params.toString() ? `?${params.toString()}` : ""}`;
|
|
1741
|
+
const response = await this.client.get(url, { headers: this.headers });
|
|
1742
|
+
return { success: true, ...response.data };
|
|
1743
|
+
} catch (e) {
|
|
1744
|
+
return { success: false, error: this.workflowError(e) };
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
/**
|
|
1748
|
+
* Workflows: Get a workflow's full detail, including its template
|
|
1749
|
+
* @param slug - Workflow slug
|
|
1750
|
+
* @param version - Specific version to fetch (defaults to the current version)
|
|
1751
|
+
*/
|
|
1752
|
+
async _workflowsGet(slug, version) {
|
|
1753
|
+
try {
|
|
1754
|
+
const url = `${this.baseUrl}/workflows/${encodeURIComponent(slug)}${version !== void 0 ? `?version=${version}` : ""}`;
|
|
1755
|
+
const response = await this.client.get(url, { headers: this.headers });
|
|
1756
|
+
return { success: true, workflow: response.data };
|
|
1757
|
+
} catch (e) {
|
|
1758
|
+
return { success: false, error: this.workflowError(e) };
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
/**
|
|
1762
|
+
* Workflows: List a workflow's version history
|
|
1763
|
+
* @param slug - Workflow slug
|
|
1764
|
+
*/
|
|
1765
|
+
async _workflowsVersions(slug) {
|
|
1766
|
+
try {
|
|
1767
|
+
const response = await this.client.get(
|
|
1768
|
+
`${this.baseUrl}/workflows/${encodeURIComponent(slug)}/versions`,
|
|
1769
|
+
{ headers: this.headers }
|
|
1770
|
+
);
|
|
1771
|
+
return { success: true, ...response.data };
|
|
1772
|
+
} catch (e) {
|
|
1773
|
+
return { success: false, error: this.workflowError(e) };
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
/**
|
|
1777
|
+
* Workflows: Resolve a workflow's template with params without creating a task
|
|
1778
|
+
* @param slug - Workflow slug
|
|
1779
|
+
* @param options - workflowParams (variable values) and optional workflowVersion
|
|
1780
|
+
*/
|
|
1781
|
+
async _workflowsPreview(slug, options = {}) {
|
|
1782
|
+
try {
|
|
1783
|
+
const payload = {};
|
|
1784
|
+
if (options.workflowParams !== void 0) {
|
|
1785
|
+
payload.workflow_params = options.workflowParams;
|
|
1786
|
+
}
|
|
1787
|
+
if (options.workflowVersion !== void 0) {
|
|
1788
|
+
payload.workflow_version = options.workflowVersion;
|
|
1789
|
+
}
|
|
1790
|
+
const response = await this.client.post(
|
|
1791
|
+
`${this.baseUrl}/workflows/${encodeURIComponent(slug)}/preview`,
|
|
1792
|
+
payload,
|
|
1793
|
+
{ headers: this.headers }
|
|
1794
|
+
);
|
|
1795
|
+
return { success: true, ...response.data };
|
|
1796
|
+
} catch (e) {
|
|
1797
|
+
return { success: false, error: this.workflowError(e) };
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
/**
|
|
1801
|
+
* Workflows: Create a new workflow for your org
|
|
1802
|
+
* @param options - slug, title, version (template body), and optional metadata
|
|
1803
|
+
*/
|
|
1804
|
+
async _workflowsCreate(options) {
|
|
1805
|
+
try {
|
|
1806
|
+
const payload = {
|
|
1807
|
+
slug: options.slug,
|
|
1808
|
+
title: options.title,
|
|
1809
|
+
version: options.version
|
|
1810
|
+
};
|
|
1811
|
+
if (options.subtitle !== void 0) payload.subtitle = options.subtitle;
|
|
1812
|
+
if (options.description !== void 0) {
|
|
1813
|
+
payload.description = options.description;
|
|
1814
|
+
}
|
|
1815
|
+
if (options.vertical !== void 0) payload.vertical = options.vertical;
|
|
1816
|
+
if (options.tags !== void 0) payload.tags = options.tags;
|
|
1817
|
+
if (options.icon !== void 0) payload.icon = options.icon;
|
|
1818
|
+
const response = await this.client.post(
|
|
1819
|
+
`${this.baseUrl}/workflows`,
|
|
1820
|
+
payload,
|
|
1821
|
+
{ headers: this.headers }
|
|
1822
|
+
);
|
|
1823
|
+
return { success: true, workflow: response.data };
|
|
1824
|
+
} catch (e) {
|
|
1825
|
+
return { success: false, error: this.workflowError(e) };
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* Workflows: Update a workflow's metadata and/or publish a new template version.
|
|
1830
|
+
* Only workflows owned by your org can be updated; versions are append-only
|
|
1831
|
+
* (a version body requires a changelog).
|
|
1832
|
+
* @param slug - Workflow slug
|
|
1833
|
+
* @param options - Metadata fields and/or a new version body
|
|
1834
|
+
*/
|
|
1835
|
+
async _workflowsUpdate(slug, options) {
|
|
1836
|
+
try {
|
|
1837
|
+
const payload = {};
|
|
1838
|
+
if (options.title !== void 0) payload.title = options.title;
|
|
1839
|
+
if (options.subtitle !== void 0) payload.subtitle = options.subtitle;
|
|
1840
|
+
if (options.description !== void 0) {
|
|
1841
|
+
payload.description = options.description;
|
|
1842
|
+
}
|
|
1843
|
+
if (options.vertical !== void 0) payload.vertical = options.vertical;
|
|
1844
|
+
if (options.tags !== void 0) payload.tags = options.tags;
|
|
1845
|
+
if (options.icon !== void 0) payload.icon = options.icon;
|
|
1846
|
+
if (options.version !== void 0) payload.version = options.version;
|
|
1847
|
+
if (options.setCurrent !== void 0) {
|
|
1848
|
+
payload.set_current = options.setCurrent;
|
|
1849
|
+
}
|
|
1850
|
+
const response = await this.client.patch(
|
|
1851
|
+
`${this.baseUrl}/workflows/${encodeURIComponent(slug)}`,
|
|
1852
|
+
payload,
|
|
1853
|
+
{ headers: this.headers }
|
|
1854
|
+
);
|
|
1855
|
+
return { success: true, workflow: response.data };
|
|
1856
|
+
} catch (e) {
|
|
1857
|
+
return { success: false, error: this.workflowError(e) };
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
/**
|
|
1861
|
+
* Workflows: Delete a workflow owned by your org (soft delete)
|
|
1862
|
+
* @param slug - Workflow slug
|
|
1863
|
+
*/
|
|
1864
|
+
async _workflowsDelete(slug) {
|
|
1865
|
+
try {
|
|
1866
|
+
const response = await this.client.delete(
|
|
1867
|
+
`${this.baseUrl}/workflows/${encodeURIComponent(slug)}`,
|
|
1868
|
+
{ headers: this.headers }
|
|
1869
|
+
);
|
|
1870
|
+
return { success: true, ...response.data };
|
|
1871
|
+
} catch (e) {
|
|
1872
|
+
return { success: false, error: this.workflowError(e) };
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1677
1875
|
};
|
|
1678
1876
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1679
1877
|
0 && (module.exports = {
|