exa-js 2.5.0 → 2.5.1-beta.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.d.mts +8621 -260
- package/dist/index.d.ts +8621 -260
- package/dist/index.js +559 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +558 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -34,8 +34,9 @@ __export(index_exports, {
|
|
|
34
34
|
CreateImportParametersFormat: () => CreateImportParametersFormat,
|
|
35
35
|
EventType: () => EventType,
|
|
36
36
|
EventsClient: () => EventsClient,
|
|
37
|
-
Exa: () =>
|
|
37
|
+
Exa: () => Exa3,
|
|
38
38
|
ExaError: () => ExaError,
|
|
39
|
+
ExaNova: () => Exa2,
|
|
39
40
|
HttpStatusCode: () => HttpStatusCode,
|
|
40
41
|
ImportFailedReason: () => ImportFailedReason,
|
|
41
42
|
ImportFormat: () => ImportFormat,
|
|
@@ -74,7 +75,7 @@ var import_cross_fetch = __toESM(require("cross-fetch"));
|
|
|
74
75
|
// package.json
|
|
75
76
|
var package_default = {
|
|
76
77
|
name: "exa-js",
|
|
77
|
-
version: "2.5.0",
|
|
78
|
+
version: "2.5.1-beta.0",
|
|
78
79
|
description: "Exa SDK for Node.js and the browser",
|
|
79
80
|
publishConfig: {
|
|
80
81
|
access: "public"
|
|
@@ -1432,11 +1433,559 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
1432
1433
|
}
|
|
1433
1434
|
};
|
|
1434
1435
|
|
|
1436
|
+
// src/nova/websets-client.ts
|
|
1437
|
+
var WebsetsBaseClient2 = class {
|
|
1438
|
+
constructor(client) {
|
|
1439
|
+
this.client = client;
|
|
1440
|
+
}
|
|
1441
|
+
/** Make a request to the API, prepending `/websets` to the path. */
|
|
1442
|
+
async request(endpoint, method = "POST", data, params, headers) {
|
|
1443
|
+
return this.client.request(
|
|
1444
|
+
`/websets${endpoint}`,
|
|
1445
|
+
method,
|
|
1446
|
+
data,
|
|
1447
|
+
params,
|
|
1448
|
+
headers
|
|
1449
|
+
);
|
|
1450
|
+
}
|
|
1451
|
+
buildPaginationParams(pagination) {
|
|
1452
|
+
const params = {};
|
|
1453
|
+
if (!pagination) return params;
|
|
1454
|
+
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
1455
|
+
if (pagination.limit) params.limit = pagination.limit;
|
|
1456
|
+
return params;
|
|
1457
|
+
}
|
|
1458
|
+
};
|
|
1459
|
+
var WebsetItemsClient2 = class extends WebsetsBaseClient2 {
|
|
1460
|
+
async get(websetId, id) {
|
|
1461
|
+
return this.request(`/v0/websets/${websetId}/items/${id}`, "GET");
|
|
1462
|
+
}
|
|
1463
|
+
async delete(websetId, id) {
|
|
1464
|
+
return this.request(`/v0/websets/${websetId}/items/${id}`, "DELETE");
|
|
1465
|
+
}
|
|
1466
|
+
async list(websetId, options) {
|
|
1467
|
+
const queryParams = {
|
|
1468
|
+
...this.buildPaginationParams(options),
|
|
1469
|
+
sourceId: options?.sourceId
|
|
1470
|
+
};
|
|
1471
|
+
return this.request(
|
|
1472
|
+
`/v0/websets/${websetId}/items`,
|
|
1473
|
+
"GET",
|
|
1474
|
+
void 0,
|
|
1475
|
+
queryParams
|
|
1476
|
+
);
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
var WebsetSearchesClient2 = class extends WebsetsBaseClient2 {
|
|
1480
|
+
async create(websetId, params, options) {
|
|
1481
|
+
return this.request(
|
|
1482
|
+
`/v0/websets/${websetId}/searches`,
|
|
1483
|
+
"POST",
|
|
1484
|
+
{ ...params },
|
|
1485
|
+
void 0,
|
|
1486
|
+
options?.headers
|
|
1487
|
+
);
|
|
1488
|
+
}
|
|
1489
|
+
async get(websetId, id) {
|
|
1490
|
+
return this.request(`/v0/websets/${websetId}/searches/${id}`, "GET");
|
|
1491
|
+
}
|
|
1492
|
+
async cancel(websetId, id) {
|
|
1493
|
+
return this.request(
|
|
1494
|
+
`/v0/websets/${websetId}/searches/${id}/cancel`,
|
|
1495
|
+
"POST"
|
|
1496
|
+
);
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
var WebsetEnrichmentsClient2 = class extends WebsetsBaseClient2 {
|
|
1500
|
+
async create(websetId, params) {
|
|
1501
|
+
return this.request(`/v0/websets/${websetId}/enrichments`, "POST", {
|
|
1502
|
+
...params
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
async update(websetId, id, params) {
|
|
1506
|
+
return this.request(
|
|
1507
|
+
`/v0/websets/${websetId}/enrichments/${id}`,
|
|
1508
|
+
"PATCH",
|
|
1509
|
+
{ ...params }
|
|
1510
|
+
);
|
|
1511
|
+
}
|
|
1512
|
+
async get(websetId, id) {
|
|
1513
|
+
return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "GET");
|
|
1514
|
+
}
|
|
1515
|
+
async delete(websetId, id) {
|
|
1516
|
+
return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "DELETE");
|
|
1517
|
+
}
|
|
1518
|
+
async cancel(websetId, id) {
|
|
1519
|
+
return this.request(
|
|
1520
|
+
`/v0/websets/${websetId}/enrichments/${id}/cancel`,
|
|
1521
|
+
"POST"
|
|
1522
|
+
);
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
var EventsClient2 = class extends WebsetsBaseClient2 {
|
|
1526
|
+
async list(options) {
|
|
1527
|
+
const queryParams = {
|
|
1528
|
+
...this.buildPaginationParams(options),
|
|
1529
|
+
types: options?.types,
|
|
1530
|
+
createdBefore: options?.createdBefore,
|
|
1531
|
+
createdAfter: options?.createdAfter
|
|
1532
|
+
};
|
|
1533
|
+
return this.request("/v0/events", "GET", void 0, queryParams);
|
|
1534
|
+
}
|
|
1535
|
+
async get(id) {
|
|
1536
|
+
return this.request(`/v0/events/${id}`, "GET");
|
|
1537
|
+
}
|
|
1538
|
+
};
|
|
1539
|
+
var WebsetMonitorRunsClient2 = class extends WebsetsBaseClient2 {
|
|
1540
|
+
async list(monitorId) {
|
|
1541
|
+
return this.request(`/v0/monitors/${monitorId}/runs`, "GET");
|
|
1542
|
+
}
|
|
1543
|
+
async get(monitorId, id) {
|
|
1544
|
+
return this.request(`/v0/monitors/${monitorId}/runs/${id}`, "GET");
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
var WebsetMonitorsClient2 = class extends WebsetsBaseClient2 {
|
|
1548
|
+
constructor(client) {
|
|
1549
|
+
super(client);
|
|
1550
|
+
this.runs = new WebsetMonitorRunsClient2(client);
|
|
1551
|
+
}
|
|
1552
|
+
async create(params) {
|
|
1553
|
+
return this.request("/v0/monitors", "POST", { ...params });
|
|
1554
|
+
}
|
|
1555
|
+
async list(options) {
|
|
1556
|
+
const queryParams = {
|
|
1557
|
+
...this.buildPaginationParams(options),
|
|
1558
|
+
websetId: options?.websetId
|
|
1559
|
+
};
|
|
1560
|
+
return this.request("/v0/monitors", "GET", void 0, queryParams);
|
|
1561
|
+
}
|
|
1562
|
+
async get(id) {
|
|
1563
|
+
return this.request(`/v0/monitors/${id}`, "GET");
|
|
1564
|
+
}
|
|
1565
|
+
async update(id, params) {
|
|
1566
|
+
return this.request(`/v0/monitors/${id}`, "PATCH", { ...params });
|
|
1567
|
+
}
|
|
1568
|
+
async delete(id) {
|
|
1569
|
+
return this.request(`/v0/monitors/${id}`, "DELETE");
|
|
1570
|
+
}
|
|
1571
|
+
};
|
|
1572
|
+
var WebsetWebhooksClient2 = class extends WebsetsBaseClient2 {
|
|
1573
|
+
async create(params) {
|
|
1574
|
+
return this.request("/v0/webhooks", "POST", { ...params });
|
|
1575
|
+
}
|
|
1576
|
+
async list(options) {
|
|
1577
|
+
const queryParams = this.buildPaginationParams(options);
|
|
1578
|
+
return this.request("/v0/webhooks", "GET", void 0, queryParams);
|
|
1579
|
+
}
|
|
1580
|
+
async get(id) {
|
|
1581
|
+
return this.request(`/v0/webhooks/${id}`, "GET");
|
|
1582
|
+
}
|
|
1583
|
+
async update(id, params) {
|
|
1584
|
+
return this.request(`/v0/webhooks/${id}`, "PATCH", { ...params });
|
|
1585
|
+
}
|
|
1586
|
+
async delete(id) {
|
|
1587
|
+
return this.request(`/v0/webhooks/${id}`, "DELETE");
|
|
1588
|
+
}
|
|
1589
|
+
async listAttempts(id, options) {
|
|
1590
|
+
const queryParams = {
|
|
1591
|
+
...this.buildPaginationParams(options),
|
|
1592
|
+
eventType: options?.eventType,
|
|
1593
|
+
successful: options?.successful
|
|
1594
|
+
};
|
|
1595
|
+
return this.request(
|
|
1596
|
+
`/v0/webhooks/${id}/attempts`,
|
|
1597
|
+
"GET",
|
|
1598
|
+
void 0,
|
|
1599
|
+
queryParams
|
|
1600
|
+
);
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
var ImportsClient2 = class extends WebsetsBaseClient2 {
|
|
1604
|
+
async create(params) {
|
|
1605
|
+
return this.request("/v0/imports", "POST", { ...params });
|
|
1606
|
+
}
|
|
1607
|
+
async list(options) {
|
|
1608
|
+
const queryParams = this.buildPaginationParams(options);
|
|
1609
|
+
return this.request("/v0/imports", "GET", void 0, queryParams);
|
|
1610
|
+
}
|
|
1611
|
+
async get(id) {
|
|
1612
|
+
return this.request(`/v0/imports/${id}`, "GET");
|
|
1613
|
+
}
|
|
1614
|
+
async update(id, params) {
|
|
1615
|
+
return this.request(`/v0/imports/${id}`, "PATCH", { ...params });
|
|
1616
|
+
}
|
|
1617
|
+
async delete(id) {
|
|
1618
|
+
return this.request(`/v0/imports/${id}`, "DELETE");
|
|
1619
|
+
}
|
|
1620
|
+
};
|
|
1621
|
+
var WebsetsClient2 = class extends WebsetsBaseClient2 {
|
|
1622
|
+
constructor(client) {
|
|
1623
|
+
super(client);
|
|
1624
|
+
this.items = new WebsetItemsClient2(client);
|
|
1625
|
+
this.searches = new WebsetSearchesClient2(client);
|
|
1626
|
+
this.enrichments = new WebsetEnrichmentsClient2(client);
|
|
1627
|
+
this.events = new EventsClient2(client);
|
|
1628
|
+
this.monitors = new WebsetMonitorsClient2(client);
|
|
1629
|
+
this.webhooks = new WebsetWebhooksClient2(client);
|
|
1630
|
+
this.imports = new ImportsClient2(client);
|
|
1631
|
+
}
|
|
1632
|
+
async create(params, options) {
|
|
1633
|
+
return this.request(
|
|
1634
|
+
"/v0/websets",
|
|
1635
|
+
"POST",
|
|
1636
|
+
{ ...params },
|
|
1637
|
+
void 0,
|
|
1638
|
+
options?.headers
|
|
1639
|
+
);
|
|
1640
|
+
}
|
|
1641
|
+
async list(options) {
|
|
1642
|
+
const queryParams = {
|
|
1643
|
+
...this.buildPaginationParams(options),
|
|
1644
|
+
search: options?.search
|
|
1645
|
+
};
|
|
1646
|
+
return this.request("/v0/websets", "GET", void 0, queryParams);
|
|
1647
|
+
}
|
|
1648
|
+
async get(id, options) {
|
|
1649
|
+
const queryParams = { expand: options?.expand };
|
|
1650
|
+
return this.request(`/v0/websets/${id}`, "GET", void 0, queryParams);
|
|
1651
|
+
}
|
|
1652
|
+
async update(id, params) {
|
|
1653
|
+
return this.request(`/v0/websets/${id}`, "POST", { ...params });
|
|
1654
|
+
}
|
|
1655
|
+
async delete(id) {
|
|
1656
|
+
return this.request(`/v0/websets/${id}`, "DELETE");
|
|
1657
|
+
}
|
|
1658
|
+
async cancel(id) {
|
|
1659
|
+
return this.request(`/v0/websets/${id}/cancel`, "POST");
|
|
1660
|
+
}
|
|
1661
|
+
async preview(params, options) {
|
|
1662
|
+
const queryParams = { search: options?.search };
|
|
1663
|
+
return this.request(
|
|
1664
|
+
"/v0/websets/preview",
|
|
1665
|
+
"POST",
|
|
1666
|
+
{ ...params },
|
|
1667
|
+
queryParams
|
|
1668
|
+
);
|
|
1669
|
+
}
|
|
1670
|
+
/** Poll until a Webset reaches idle status. */
|
|
1671
|
+
async waitUntilIdle(id, options) {
|
|
1672
|
+
let timeout;
|
|
1673
|
+
let pollInterval = 1e3;
|
|
1674
|
+
let onPoll;
|
|
1675
|
+
if (typeof options === "number") {
|
|
1676
|
+
timeout = options;
|
|
1677
|
+
} else if (options) {
|
|
1678
|
+
timeout = options.timeout;
|
|
1679
|
+
pollInterval = options.pollInterval || 1e3;
|
|
1680
|
+
onPoll = options.onPoll;
|
|
1681
|
+
}
|
|
1682
|
+
const startTime = Date.now();
|
|
1683
|
+
while (true) {
|
|
1684
|
+
const webset = await this.get(id);
|
|
1685
|
+
if (onPoll) onPoll(webset.status);
|
|
1686
|
+
if (webset.status === "idle") return webset;
|
|
1687
|
+
if (timeout && Date.now() - startTime > timeout) {
|
|
1688
|
+
throw new Error(
|
|
1689
|
+
`Webset ${id} did not reach idle state within ${timeout}ms. Current status: ${webset.status}`
|
|
1690
|
+
);
|
|
1691
|
+
}
|
|
1692
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
};
|
|
1696
|
+
|
|
1697
|
+
// src/nova/research-client.ts
|
|
1698
|
+
var import_zod2 = require("zod");
|
|
1699
|
+
var import_zod_to_json_schema2 = require("zod-to-json-schema");
|
|
1700
|
+
function zodToJsonSchema2(schema) {
|
|
1701
|
+
return (0, import_zod_to_json_schema2.zodToJsonSchema)(schema, { $refStrategy: "none" });
|
|
1702
|
+
}
|
|
1703
|
+
var ResearchBaseClient2 = class {
|
|
1704
|
+
constructor(client) {
|
|
1705
|
+
this.client = client;
|
|
1706
|
+
}
|
|
1707
|
+
/** Make a request to the API, prepending `/research/v1` to the path. */
|
|
1708
|
+
async request(endpoint, method = "POST", data, params) {
|
|
1709
|
+
return this.client.request(
|
|
1710
|
+
`/research/v1${endpoint}`,
|
|
1711
|
+
method,
|
|
1712
|
+
data,
|
|
1713
|
+
params
|
|
1714
|
+
);
|
|
1715
|
+
}
|
|
1716
|
+
buildPaginationParams(pagination) {
|
|
1717
|
+
const params = {};
|
|
1718
|
+
if (!pagination) return params;
|
|
1719
|
+
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
1720
|
+
if (pagination.limit) params.limit = pagination.limit;
|
|
1721
|
+
return params;
|
|
1722
|
+
}
|
|
1723
|
+
};
|
|
1724
|
+
var ResearchClient2 = class extends ResearchBaseClient2 {
|
|
1725
|
+
/** List research requests. */
|
|
1726
|
+
async list(options) {
|
|
1727
|
+
const params = this.buildPaginationParams(options);
|
|
1728
|
+
return this.client.request("/research/v1", "GET", void 0, params);
|
|
1729
|
+
}
|
|
1730
|
+
/** Create a new research request. Defaults model to "exa-research-fast" if not provided. */
|
|
1731
|
+
async create(params) {
|
|
1732
|
+
let schema = params.outputSchema;
|
|
1733
|
+
if (schema instanceof import_zod2.ZodType) {
|
|
1734
|
+
schema = zodToJsonSchema2(schema);
|
|
1735
|
+
}
|
|
1736
|
+
const payload = {
|
|
1737
|
+
instructions: params.instructions,
|
|
1738
|
+
model: params.model ?? "exa-research-fast"
|
|
1739
|
+
};
|
|
1740
|
+
if (schema) {
|
|
1741
|
+
payload.outputSchema = schema;
|
|
1742
|
+
}
|
|
1743
|
+
return this.client.request("/research/v1", "POST", payload, void 0);
|
|
1744
|
+
}
|
|
1745
|
+
/** Get a research request by ID. */
|
|
1746
|
+
async get(researchId, options) {
|
|
1747
|
+
const params = {};
|
|
1748
|
+
if (options?.events !== void 0)
|
|
1749
|
+
params.events = options.events.toString();
|
|
1750
|
+
return this.client.request(
|
|
1751
|
+
`/research/v1/${researchId}`,
|
|
1752
|
+
"GET",
|
|
1753
|
+
void 0,
|
|
1754
|
+
params
|
|
1755
|
+
);
|
|
1756
|
+
}
|
|
1757
|
+
/** Poll a research request until it reaches a terminal state (completed, failed, or canceled). */
|
|
1758
|
+
async pollUntilFinished(researchId, options) {
|
|
1759
|
+
const pollInterval = options?.pollInterval ?? 1e3;
|
|
1760
|
+
const timeoutMs = options?.timeoutMs ?? 10 * 60 * 1e3;
|
|
1761
|
+
const maxConsecutiveFailures = 5;
|
|
1762
|
+
const startTime = Date.now();
|
|
1763
|
+
let consecutiveFailures = 0;
|
|
1764
|
+
while (true) {
|
|
1765
|
+
try {
|
|
1766
|
+
const research = await this.get(researchId, {
|
|
1767
|
+
events: options?.events
|
|
1768
|
+
});
|
|
1769
|
+
consecutiveFailures = 0;
|
|
1770
|
+
if (research.status === "completed" || research.status === "failed" || research.status === "canceled") {
|
|
1771
|
+
return research;
|
|
1772
|
+
}
|
|
1773
|
+
} catch (err) {
|
|
1774
|
+
consecutiveFailures += 1;
|
|
1775
|
+
if (consecutiveFailures >= maxConsecutiveFailures) {
|
|
1776
|
+
throw new Error(
|
|
1777
|
+
`Polling failed ${maxConsecutiveFailures} times in a row for research ${researchId}: ${err}`
|
|
1778
|
+
);
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
if (Date.now() - startTime > timeoutMs) {
|
|
1782
|
+
throw new Error(
|
|
1783
|
+
`Polling timeout: Research ${researchId} did not complete within ${timeoutMs}ms`
|
|
1784
|
+
);
|
|
1785
|
+
}
|
|
1786
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1790
|
+
|
|
1791
|
+
// src/nova/client.ts
|
|
1792
|
+
var CONTENTS_FIELDS = /* @__PURE__ */ new Set([
|
|
1793
|
+
"text",
|
|
1794
|
+
"highlights",
|
|
1795
|
+
"summary",
|
|
1796
|
+
"subpages",
|
|
1797
|
+
"subpageTarget",
|
|
1798
|
+
"extras",
|
|
1799
|
+
"livecrawl",
|
|
1800
|
+
"livecrawlTimeout",
|
|
1801
|
+
"maxAgeHours",
|
|
1802
|
+
"filterEmptyResults",
|
|
1803
|
+
"context"
|
|
1804
|
+
]);
|
|
1805
|
+
var DEFAULT_MAX_CHARACTERS = 1e4;
|
|
1806
|
+
var Exa2 = class {
|
|
1807
|
+
constructor(apiKey, baseURL = "https://api.exa.ai") {
|
|
1808
|
+
this.baseURL = baseURL;
|
|
1809
|
+
if (!apiKey) {
|
|
1810
|
+
apiKey = typeof process !== "undefined" ? process.env?.EXA_API_KEY : void 0;
|
|
1811
|
+
if (!apiKey) {
|
|
1812
|
+
throw new Error(
|
|
1813
|
+
"API key must be provided as an argument or as an environment variable (EXA_API_KEY)"
|
|
1814
|
+
);
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
this.headers = {
|
|
1818
|
+
"x-api-key": apiKey,
|
|
1819
|
+
"Content-Type": "application/json"
|
|
1820
|
+
};
|
|
1821
|
+
this.websets = new WebsetsClient2(this);
|
|
1822
|
+
this.research = new ResearchClient2(this);
|
|
1823
|
+
}
|
|
1824
|
+
/** Make a request to the Exa API. Used by sub-clients and available for direct use. */
|
|
1825
|
+
async request(endpoint, method, body, params, headers) {
|
|
1826
|
+
let url = `${this.baseURL}${endpoint}`;
|
|
1827
|
+
const normalizedBody = this.normalizeCategoryInBody(body);
|
|
1828
|
+
if (params && Object.keys(params).length > 0) {
|
|
1829
|
+
const searchParams = new URLSearchParams();
|
|
1830
|
+
for (const [key, value] of Object.entries(params)) {
|
|
1831
|
+
if (Array.isArray(value)) {
|
|
1832
|
+
for (const item of value) {
|
|
1833
|
+
searchParams.append(key, item);
|
|
1834
|
+
}
|
|
1835
|
+
} else if (value !== void 0) {
|
|
1836
|
+
searchParams.append(key, String(value));
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
url += `?${searchParams.toString()}`;
|
|
1840
|
+
}
|
|
1841
|
+
const combinedHeaders = headers ? { ...this.headers, ...headers } : this.headers;
|
|
1842
|
+
const response = await fetch(url, {
|
|
1843
|
+
method,
|
|
1844
|
+
headers: combinedHeaders,
|
|
1845
|
+
body: normalizedBody ? JSON.stringify(normalizedBody) : void 0
|
|
1846
|
+
});
|
|
1847
|
+
if (!response.ok) {
|
|
1848
|
+
const text = await response.text();
|
|
1849
|
+
throw new Error(`Exa API error ${response.status}: ${text}`);
|
|
1850
|
+
}
|
|
1851
|
+
return await response.json();
|
|
1852
|
+
}
|
|
1853
|
+
/** Make a raw request returning the Response object directly. */
|
|
1854
|
+
async rawRequest(endpoint, method = "POST", body, params) {
|
|
1855
|
+
let url = `${this.baseURL}${endpoint}`;
|
|
1856
|
+
const normalizedBody = this.normalizeCategoryInBody(body);
|
|
1857
|
+
if (params && Object.keys(params).length > 0) {
|
|
1858
|
+
const searchParams = new URLSearchParams();
|
|
1859
|
+
for (const [key, value] of Object.entries(params)) {
|
|
1860
|
+
if (Array.isArray(value)) {
|
|
1861
|
+
for (const item of value) {
|
|
1862
|
+
searchParams.append(key, item);
|
|
1863
|
+
}
|
|
1864
|
+
} else if (value !== void 0) {
|
|
1865
|
+
searchParams.append(key, String(value));
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
url += `?${searchParams.toString()}`;
|
|
1869
|
+
}
|
|
1870
|
+
return fetch(url, {
|
|
1871
|
+
method,
|
|
1872
|
+
headers: this.headers,
|
|
1873
|
+
body: normalizedBody ? JSON.stringify(normalizedBody) : void 0
|
|
1874
|
+
});
|
|
1875
|
+
}
|
|
1876
|
+
/** Normalize category values to underscore form. */
|
|
1877
|
+
normalizeCategoryInBody(body) {
|
|
1878
|
+
if (body == null || typeof body.category !== "string") {
|
|
1879
|
+
return body;
|
|
1880
|
+
}
|
|
1881
|
+
return { ...body, category: body.category.replace(/ /g, "_") };
|
|
1882
|
+
}
|
|
1883
|
+
/** Separate content-specific options from search/filter options. */
|
|
1884
|
+
extractContentsOptions(options) {
|
|
1885
|
+
const contentsOptions = {};
|
|
1886
|
+
const restOptions = {};
|
|
1887
|
+
let hasContentField = false;
|
|
1888
|
+
for (const [key, value] of Object.entries(options)) {
|
|
1889
|
+
if (CONTENTS_FIELDS.has(key)) {
|
|
1890
|
+
contentsOptions[key] = value;
|
|
1891
|
+
hasContentField = true;
|
|
1892
|
+
} else {
|
|
1893
|
+
restOptions[key] = value;
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
if (!hasContentField) {
|
|
1897
|
+
contentsOptions.text = { maxCharacters: DEFAULT_MAX_CHARACTERS };
|
|
1898
|
+
}
|
|
1899
|
+
return { contentsOptions, restOptions };
|
|
1900
|
+
}
|
|
1901
|
+
search(query, options) {
|
|
1902
|
+
let body;
|
|
1903
|
+
if (options === void 0 || !("contents" in options)) {
|
|
1904
|
+
body = {
|
|
1905
|
+
query,
|
|
1906
|
+
...options,
|
|
1907
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
1908
|
+
};
|
|
1909
|
+
} else if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
1910
|
+
const { contents, ...restOptions } = options;
|
|
1911
|
+
body = { query, ...restOptions };
|
|
1912
|
+
} else {
|
|
1913
|
+
body = { query, ...options };
|
|
1914
|
+
}
|
|
1915
|
+
return this.request("/search", "POST", body);
|
|
1916
|
+
}
|
|
1917
|
+
findSimilar(url, options) {
|
|
1918
|
+
let body;
|
|
1919
|
+
if (options === void 0 || !("contents" in options)) {
|
|
1920
|
+
body = {
|
|
1921
|
+
url,
|
|
1922
|
+
...options,
|
|
1923
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
1924
|
+
};
|
|
1925
|
+
} else if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
1926
|
+
const { contents, ...restOptions } = options;
|
|
1927
|
+
body = { url, ...restOptions };
|
|
1928
|
+
} else {
|
|
1929
|
+
body = { url, ...options };
|
|
1930
|
+
}
|
|
1931
|
+
return this.request("/findSimilar", "POST", body);
|
|
1932
|
+
}
|
|
1933
|
+
getContents(urls, options) {
|
|
1934
|
+
return this.request("/contents", "POST", { urls, ...options });
|
|
1935
|
+
}
|
|
1936
|
+
answer(query, options) {
|
|
1937
|
+
return this.request("/answer", "POST", { query, ...options });
|
|
1938
|
+
}
|
|
1939
|
+
streamAnswer(query, options) {
|
|
1940
|
+
return this.rawRequest("/answer", "POST", {
|
|
1941
|
+
query,
|
|
1942
|
+
stream: true,
|
|
1943
|
+
...options
|
|
1944
|
+
});
|
|
1945
|
+
}
|
|
1946
|
+
/**
|
|
1947
|
+
* @deprecated Use `search()` instead. The search method now returns text contents by default.
|
|
1948
|
+
* Search with contents. Extracts content fields (text, highlights, summary, etc.) into a `contents` wrapper.
|
|
1949
|
+
*/
|
|
1950
|
+
async searchAndContents(query, options) {
|
|
1951
|
+
if (options === void 0) {
|
|
1952
|
+
return this.request("/search", "POST", {
|
|
1953
|
+
query,
|
|
1954
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
1955
|
+
});
|
|
1956
|
+
}
|
|
1957
|
+
const { contentsOptions, restOptions } = this.extractContentsOptions(options);
|
|
1958
|
+
return this.request("/search", "POST", {
|
|
1959
|
+
query,
|
|
1960
|
+
contents: contentsOptions,
|
|
1961
|
+
...restOptions
|
|
1962
|
+
});
|
|
1963
|
+
}
|
|
1964
|
+
/**
|
|
1965
|
+
* @deprecated Use `findSimilar()` instead. The findSimilar method now returns text contents by default.
|
|
1966
|
+
* Find similar with contents. Extracts content fields into a `contents` wrapper.
|
|
1967
|
+
*/
|
|
1968
|
+
async findSimilarAndContents(url, options) {
|
|
1969
|
+
if (options === void 0) {
|
|
1970
|
+
return this.request("/findSimilar", "POST", {
|
|
1971
|
+
url,
|
|
1972
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
const { contentsOptions, restOptions } = this.extractContentsOptions(options);
|
|
1976
|
+
return this.request("/findSimilar", "POST", {
|
|
1977
|
+
url,
|
|
1978
|
+
contents: contentsOptions,
|
|
1979
|
+
...restOptions
|
|
1980
|
+
});
|
|
1981
|
+
}
|
|
1982
|
+
};
|
|
1983
|
+
|
|
1435
1984
|
// src/index.ts
|
|
1436
1985
|
var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : import_cross_fetch.default;
|
|
1437
1986
|
var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : import_cross_fetch.Headers;
|
|
1438
|
-
var
|
|
1439
|
-
var
|
|
1987
|
+
var DEFAULT_MAX_CHARACTERS2 = 1e4;
|
|
1988
|
+
var Exa3 = class {
|
|
1440
1989
|
/**
|
|
1441
1990
|
* Helper method to separate out the contents-specific options from the rest.
|
|
1442
1991
|
*/
|
|
@@ -1603,7 +2152,7 @@ var Exa2 = class {
|
|
|
1603
2152
|
return await this.request("/search", "POST", {
|
|
1604
2153
|
query,
|
|
1605
2154
|
...options,
|
|
1606
|
-
contents: { text: { maxCharacters:
|
|
2155
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 } }
|
|
1607
2156
|
});
|
|
1608
2157
|
}
|
|
1609
2158
|
if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
@@ -1629,7 +2178,7 @@ var Exa2 = class {
|
|
|
1629
2178
|
async searchAndContents(query, options) {
|
|
1630
2179
|
const { contentsOptions, restOptions } = options === void 0 ? {
|
|
1631
2180
|
contentsOptions: {
|
|
1632
|
-
text: { maxCharacters:
|
|
2181
|
+
text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 }
|
|
1633
2182
|
},
|
|
1634
2183
|
restOptions: {}
|
|
1635
2184
|
} : this.extractContentsOptions(options);
|
|
@@ -1644,7 +2193,7 @@ var Exa2 = class {
|
|
|
1644
2193
|
return await this.request("/findSimilar", "POST", {
|
|
1645
2194
|
url,
|
|
1646
2195
|
...options,
|
|
1647
|
-
contents: { text: { maxCharacters:
|
|
2196
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 } }
|
|
1648
2197
|
});
|
|
1649
2198
|
}
|
|
1650
2199
|
if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
@@ -1672,7 +2221,7 @@ var Exa2 = class {
|
|
|
1672
2221
|
async findSimilarAndContents(url, options) {
|
|
1673
2222
|
const { contentsOptions, restOptions } = options === void 0 ? {
|
|
1674
2223
|
contentsOptions: {
|
|
1675
|
-
text: { maxCharacters:
|
|
2224
|
+
text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 }
|
|
1676
2225
|
},
|
|
1677
2226
|
restOptions: {}
|
|
1678
2227
|
} : this.extractContentsOptions(options);
|
|
@@ -1896,7 +2445,7 @@ var Exa2 = class {
|
|
|
1896
2445
|
});
|
|
1897
2446
|
}
|
|
1898
2447
|
};
|
|
1899
|
-
var index_default =
|
|
2448
|
+
var index_default = Exa3;
|
|
1900
2449
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1901
2450
|
0 && (module.exports = {
|
|
1902
2451
|
CreateEnrichmentParametersFormat,
|
|
@@ -1905,6 +2454,7 @@ var index_default = Exa2;
|
|
|
1905
2454
|
EventsClient,
|
|
1906
2455
|
Exa,
|
|
1907
2456
|
ExaError,
|
|
2457
|
+
ExaNova,
|
|
1908
2458
|
HttpStatusCode,
|
|
1909
2459
|
ImportFailedReason,
|
|
1910
2460
|
ImportFormat,
|