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/README.md +51 -0
- package/dist/index.d.mts +214 -1
- package/dist/index.d.ts +214 -1
- package/dist/index.js +223 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +223 -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)
|
|
@@ -213,6 +222,7 @@ var Valyu = class {
|
|
|
213
222
|
* @param options.category - Category filter for search results
|
|
214
223
|
* @param options.startDate - Start date filter (YYYY-MM-DD format)
|
|
215
224
|
* @param options.endDate - End date filter (YYYY-MM-DD format)
|
|
225
|
+
* @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)
|
|
216
226
|
* @param options.countryCode - Country code filter for search results
|
|
217
227
|
* @param options.responseLength - Response content length: "short"/"medium"/"large"/"max" or integer character count
|
|
218
228
|
* @param options.fastMode - Fast mode for quicker but shorter results (default: false)
|
|
@@ -368,6 +378,9 @@ var Valyu = class {
|
|
|
368
378
|
if (options.endDate !== void 0) {
|
|
369
379
|
payload.end_date = options.endDate;
|
|
370
380
|
}
|
|
381
|
+
if (options.historicalCache !== void 0) {
|
|
382
|
+
payload.historical_cache = options.historicalCache;
|
|
383
|
+
}
|
|
371
384
|
if (options.countryCode !== void 0) {
|
|
372
385
|
payload.country_code = options.countryCode;
|
|
373
386
|
}
|
|
@@ -423,6 +436,9 @@ var Valyu = class {
|
|
|
423
436
|
* @param options.screenshot - Request page screenshots (default: false)
|
|
424
437
|
* @param options.async - Force async processing (required for >10 URLs)
|
|
425
438
|
* @param options.webhookUrl - HTTPS URL for completion notification (async only)
|
|
439
|
+
* @param options.startDate - Start date filter (YYYY-MM-DD format), inclusive
|
|
440
|
+
* @param options.endDate - End date filter (YYYY-MM-DD format), inclusive
|
|
441
|
+
* @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)
|
|
426
442
|
* @returns Promise resolving to sync results or async job (when async: true or >10 URLs)
|
|
427
443
|
*/
|
|
428
444
|
async contents(urls, options = {}) {
|
|
@@ -539,6 +555,15 @@ var Valyu = class {
|
|
|
539
555
|
if (options.webhookUrl !== void 0) {
|
|
540
556
|
payload.webhook_url = options.webhookUrl;
|
|
541
557
|
}
|
|
558
|
+
if (options.startDate !== void 0) {
|
|
559
|
+
payload.start_date = options.startDate;
|
|
560
|
+
}
|
|
561
|
+
if (options.endDate !== void 0) {
|
|
562
|
+
payload.end_date = options.endDate;
|
|
563
|
+
}
|
|
564
|
+
if (options.historicalCache !== void 0) {
|
|
565
|
+
payload.historical_cache = options.historicalCache;
|
|
566
|
+
}
|
|
542
567
|
const response = await this.client.post(`${this.baseUrl}/contents`, payload, {
|
|
543
568
|
headers: this.headers
|
|
544
569
|
});
|
|
@@ -634,11 +659,47 @@ var Valyu = class {
|
|
|
634
659
|
* @param options.search.excludedSources - Array of source types to exclude (e.g., ["web", "patent"])
|
|
635
660
|
* @param options.search.startDate - Start date filter in ISO format (YYYY-MM-DD)
|
|
636
661
|
* @param options.search.endDate - End date filter in ISO format (YYYY-MM-DD)
|
|
662
|
+
* @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
|
|
637
663
|
* @param options.search.category - Category filter for search results
|
|
638
664
|
*/
|
|
639
665
|
async _deepresearchCreate(options) {
|
|
640
666
|
try {
|
|
641
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
|
+
}
|
|
642
703
|
if (!queryValue?.trim()) {
|
|
643
704
|
return {
|
|
644
705
|
success: false,
|
|
@@ -707,6 +768,9 @@ var Valyu = class {
|
|
|
707
768
|
if (options.search.endDate) {
|
|
708
769
|
payload.search.end_date = options.search.endDate;
|
|
709
770
|
}
|
|
771
|
+
if (options.search.historicalCache !== void 0) {
|
|
772
|
+
payload.search.historical_cache = options.search.historicalCache;
|
|
773
|
+
}
|
|
710
774
|
if (options.search.category) {
|
|
711
775
|
payload.search.category = options.search.category;
|
|
712
776
|
}
|
|
@@ -1065,6 +1129,7 @@ var Valyu = class {
|
|
|
1065
1129
|
* @param options.search.excludedSources - Array of source types to exclude (e.g., ["web", "patent"])
|
|
1066
1130
|
* @param options.search.startDate - Start date filter in ISO format (YYYY-MM-DD)
|
|
1067
1131
|
* @param options.search.endDate - End date filter in ISO format (YYYY-MM-DD)
|
|
1132
|
+
* @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
|
|
1068
1133
|
* @param options.search.category - Category filter for search results
|
|
1069
1134
|
* @param options.webhookUrl - Optional HTTPS URL for completion notification
|
|
1070
1135
|
* @param options.metadata - Optional metadata key-value pairs
|
|
@@ -1097,6 +1162,9 @@ var Valyu = class {
|
|
|
1097
1162
|
if (options.search.endDate) {
|
|
1098
1163
|
payload.search.end_date = options.search.endDate;
|
|
1099
1164
|
}
|
|
1165
|
+
if (options.search.historicalCache !== void 0) {
|
|
1166
|
+
payload.search.historical_cache = options.search.historicalCache;
|
|
1167
|
+
}
|
|
1100
1168
|
if (options.search.category) {
|
|
1101
1169
|
payload.search.category = options.search.category;
|
|
1102
1170
|
}
|
|
@@ -1650,6 +1718,160 @@ var Valyu = class {
|
|
|
1650
1718
|
};
|
|
1651
1719
|
}
|
|
1652
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
|
+
}
|
|
1653
1875
|
};
|
|
1654
1876
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1655
1877
|
0 && (module.exports = {
|