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.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import fetch2, { Headers } from "cross-fetch";
|
|
|
4
4
|
// package.json
|
|
5
5
|
var package_default = {
|
|
6
6
|
name: "exa-js",
|
|
7
|
-
version: "2.5.0",
|
|
7
|
+
version: "2.5.1-beta.0",
|
|
8
8
|
description: "Exa SDK for Node.js and the browser",
|
|
9
9
|
publishConfig: {
|
|
10
10
|
access: "public"
|
|
@@ -1362,11 +1362,559 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
1362
1362
|
}
|
|
1363
1363
|
};
|
|
1364
1364
|
|
|
1365
|
+
// src/nova/websets-client.ts
|
|
1366
|
+
var WebsetsBaseClient2 = class {
|
|
1367
|
+
constructor(client) {
|
|
1368
|
+
this.client = client;
|
|
1369
|
+
}
|
|
1370
|
+
/** Make a request to the API, prepending `/websets` to the path. */
|
|
1371
|
+
async request(endpoint, method = "POST", data, params, headers) {
|
|
1372
|
+
return this.client.request(
|
|
1373
|
+
`/websets${endpoint}`,
|
|
1374
|
+
method,
|
|
1375
|
+
data,
|
|
1376
|
+
params,
|
|
1377
|
+
headers
|
|
1378
|
+
);
|
|
1379
|
+
}
|
|
1380
|
+
buildPaginationParams(pagination) {
|
|
1381
|
+
const params = {};
|
|
1382
|
+
if (!pagination) return params;
|
|
1383
|
+
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
1384
|
+
if (pagination.limit) params.limit = pagination.limit;
|
|
1385
|
+
return params;
|
|
1386
|
+
}
|
|
1387
|
+
};
|
|
1388
|
+
var WebsetItemsClient2 = class extends WebsetsBaseClient2 {
|
|
1389
|
+
async get(websetId, id) {
|
|
1390
|
+
return this.request(`/v0/websets/${websetId}/items/${id}`, "GET");
|
|
1391
|
+
}
|
|
1392
|
+
async delete(websetId, id) {
|
|
1393
|
+
return this.request(`/v0/websets/${websetId}/items/${id}`, "DELETE");
|
|
1394
|
+
}
|
|
1395
|
+
async list(websetId, options) {
|
|
1396
|
+
const queryParams = {
|
|
1397
|
+
...this.buildPaginationParams(options),
|
|
1398
|
+
sourceId: options?.sourceId
|
|
1399
|
+
};
|
|
1400
|
+
return this.request(
|
|
1401
|
+
`/v0/websets/${websetId}/items`,
|
|
1402
|
+
"GET",
|
|
1403
|
+
void 0,
|
|
1404
|
+
queryParams
|
|
1405
|
+
);
|
|
1406
|
+
}
|
|
1407
|
+
};
|
|
1408
|
+
var WebsetSearchesClient2 = class extends WebsetsBaseClient2 {
|
|
1409
|
+
async create(websetId, params, options) {
|
|
1410
|
+
return this.request(
|
|
1411
|
+
`/v0/websets/${websetId}/searches`,
|
|
1412
|
+
"POST",
|
|
1413
|
+
{ ...params },
|
|
1414
|
+
void 0,
|
|
1415
|
+
options?.headers
|
|
1416
|
+
);
|
|
1417
|
+
}
|
|
1418
|
+
async get(websetId, id) {
|
|
1419
|
+
return this.request(`/v0/websets/${websetId}/searches/${id}`, "GET");
|
|
1420
|
+
}
|
|
1421
|
+
async cancel(websetId, id) {
|
|
1422
|
+
return this.request(
|
|
1423
|
+
`/v0/websets/${websetId}/searches/${id}/cancel`,
|
|
1424
|
+
"POST"
|
|
1425
|
+
);
|
|
1426
|
+
}
|
|
1427
|
+
};
|
|
1428
|
+
var WebsetEnrichmentsClient2 = class extends WebsetsBaseClient2 {
|
|
1429
|
+
async create(websetId, params) {
|
|
1430
|
+
return this.request(`/v0/websets/${websetId}/enrichments`, "POST", {
|
|
1431
|
+
...params
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
async update(websetId, id, params) {
|
|
1435
|
+
return this.request(
|
|
1436
|
+
`/v0/websets/${websetId}/enrichments/${id}`,
|
|
1437
|
+
"PATCH",
|
|
1438
|
+
{ ...params }
|
|
1439
|
+
);
|
|
1440
|
+
}
|
|
1441
|
+
async get(websetId, id) {
|
|
1442
|
+
return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "GET");
|
|
1443
|
+
}
|
|
1444
|
+
async delete(websetId, id) {
|
|
1445
|
+
return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "DELETE");
|
|
1446
|
+
}
|
|
1447
|
+
async cancel(websetId, id) {
|
|
1448
|
+
return this.request(
|
|
1449
|
+
`/v0/websets/${websetId}/enrichments/${id}/cancel`,
|
|
1450
|
+
"POST"
|
|
1451
|
+
);
|
|
1452
|
+
}
|
|
1453
|
+
};
|
|
1454
|
+
var EventsClient2 = class extends WebsetsBaseClient2 {
|
|
1455
|
+
async list(options) {
|
|
1456
|
+
const queryParams = {
|
|
1457
|
+
...this.buildPaginationParams(options),
|
|
1458
|
+
types: options?.types,
|
|
1459
|
+
createdBefore: options?.createdBefore,
|
|
1460
|
+
createdAfter: options?.createdAfter
|
|
1461
|
+
};
|
|
1462
|
+
return this.request("/v0/events", "GET", void 0, queryParams);
|
|
1463
|
+
}
|
|
1464
|
+
async get(id) {
|
|
1465
|
+
return this.request(`/v0/events/${id}`, "GET");
|
|
1466
|
+
}
|
|
1467
|
+
};
|
|
1468
|
+
var WebsetMonitorRunsClient2 = class extends WebsetsBaseClient2 {
|
|
1469
|
+
async list(monitorId) {
|
|
1470
|
+
return this.request(`/v0/monitors/${monitorId}/runs`, "GET");
|
|
1471
|
+
}
|
|
1472
|
+
async get(monitorId, id) {
|
|
1473
|
+
return this.request(`/v0/monitors/${monitorId}/runs/${id}`, "GET");
|
|
1474
|
+
}
|
|
1475
|
+
};
|
|
1476
|
+
var WebsetMonitorsClient2 = class extends WebsetsBaseClient2 {
|
|
1477
|
+
constructor(client) {
|
|
1478
|
+
super(client);
|
|
1479
|
+
this.runs = new WebsetMonitorRunsClient2(client);
|
|
1480
|
+
}
|
|
1481
|
+
async create(params) {
|
|
1482
|
+
return this.request("/v0/monitors", "POST", { ...params });
|
|
1483
|
+
}
|
|
1484
|
+
async list(options) {
|
|
1485
|
+
const queryParams = {
|
|
1486
|
+
...this.buildPaginationParams(options),
|
|
1487
|
+
websetId: options?.websetId
|
|
1488
|
+
};
|
|
1489
|
+
return this.request("/v0/monitors", "GET", void 0, queryParams);
|
|
1490
|
+
}
|
|
1491
|
+
async get(id) {
|
|
1492
|
+
return this.request(`/v0/monitors/${id}`, "GET");
|
|
1493
|
+
}
|
|
1494
|
+
async update(id, params) {
|
|
1495
|
+
return this.request(`/v0/monitors/${id}`, "PATCH", { ...params });
|
|
1496
|
+
}
|
|
1497
|
+
async delete(id) {
|
|
1498
|
+
return this.request(`/v0/monitors/${id}`, "DELETE");
|
|
1499
|
+
}
|
|
1500
|
+
};
|
|
1501
|
+
var WebsetWebhooksClient2 = class extends WebsetsBaseClient2 {
|
|
1502
|
+
async create(params) {
|
|
1503
|
+
return this.request("/v0/webhooks", "POST", { ...params });
|
|
1504
|
+
}
|
|
1505
|
+
async list(options) {
|
|
1506
|
+
const queryParams = this.buildPaginationParams(options);
|
|
1507
|
+
return this.request("/v0/webhooks", "GET", void 0, queryParams);
|
|
1508
|
+
}
|
|
1509
|
+
async get(id) {
|
|
1510
|
+
return this.request(`/v0/webhooks/${id}`, "GET");
|
|
1511
|
+
}
|
|
1512
|
+
async update(id, params) {
|
|
1513
|
+
return this.request(`/v0/webhooks/${id}`, "PATCH", { ...params });
|
|
1514
|
+
}
|
|
1515
|
+
async delete(id) {
|
|
1516
|
+
return this.request(`/v0/webhooks/${id}`, "DELETE");
|
|
1517
|
+
}
|
|
1518
|
+
async listAttempts(id, options) {
|
|
1519
|
+
const queryParams = {
|
|
1520
|
+
...this.buildPaginationParams(options),
|
|
1521
|
+
eventType: options?.eventType,
|
|
1522
|
+
successful: options?.successful
|
|
1523
|
+
};
|
|
1524
|
+
return this.request(
|
|
1525
|
+
`/v0/webhooks/${id}/attempts`,
|
|
1526
|
+
"GET",
|
|
1527
|
+
void 0,
|
|
1528
|
+
queryParams
|
|
1529
|
+
);
|
|
1530
|
+
}
|
|
1531
|
+
};
|
|
1532
|
+
var ImportsClient2 = class extends WebsetsBaseClient2 {
|
|
1533
|
+
async create(params) {
|
|
1534
|
+
return this.request("/v0/imports", "POST", { ...params });
|
|
1535
|
+
}
|
|
1536
|
+
async list(options) {
|
|
1537
|
+
const queryParams = this.buildPaginationParams(options);
|
|
1538
|
+
return this.request("/v0/imports", "GET", void 0, queryParams);
|
|
1539
|
+
}
|
|
1540
|
+
async get(id) {
|
|
1541
|
+
return this.request(`/v0/imports/${id}`, "GET");
|
|
1542
|
+
}
|
|
1543
|
+
async update(id, params) {
|
|
1544
|
+
return this.request(`/v0/imports/${id}`, "PATCH", { ...params });
|
|
1545
|
+
}
|
|
1546
|
+
async delete(id) {
|
|
1547
|
+
return this.request(`/v0/imports/${id}`, "DELETE");
|
|
1548
|
+
}
|
|
1549
|
+
};
|
|
1550
|
+
var WebsetsClient2 = class extends WebsetsBaseClient2 {
|
|
1551
|
+
constructor(client) {
|
|
1552
|
+
super(client);
|
|
1553
|
+
this.items = new WebsetItemsClient2(client);
|
|
1554
|
+
this.searches = new WebsetSearchesClient2(client);
|
|
1555
|
+
this.enrichments = new WebsetEnrichmentsClient2(client);
|
|
1556
|
+
this.events = new EventsClient2(client);
|
|
1557
|
+
this.monitors = new WebsetMonitorsClient2(client);
|
|
1558
|
+
this.webhooks = new WebsetWebhooksClient2(client);
|
|
1559
|
+
this.imports = new ImportsClient2(client);
|
|
1560
|
+
}
|
|
1561
|
+
async create(params, options) {
|
|
1562
|
+
return this.request(
|
|
1563
|
+
"/v0/websets",
|
|
1564
|
+
"POST",
|
|
1565
|
+
{ ...params },
|
|
1566
|
+
void 0,
|
|
1567
|
+
options?.headers
|
|
1568
|
+
);
|
|
1569
|
+
}
|
|
1570
|
+
async list(options) {
|
|
1571
|
+
const queryParams = {
|
|
1572
|
+
...this.buildPaginationParams(options),
|
|
1573
|
+
search: options?.search
|
|
1574
|
+
};
|
|
1575
|
+
return this.request("/v0/websets", "GET", void 0, queryParams);
|
|
1576
|
+
}
|
|
1577
|
+
async get(id, options) {
|
|
1578
|
+
const queryParams = { expand: options?.expand };
|
|
1579
|
+
return this.request(`/v0/websets/${id}`, "GET", void 0, queryParams);
|
|
1580
|
+
}
|
|
1581
|
+
async update(id, params) {
|
|
1582
|
+
return this.request(`/v0/websets/${id}`, "POST", { ...params });
|
|
1583
|
+
}
|
|
1584
|
+
async delete(id) {
|
|
1585
|
+
return this.request(`/v0/websets/${id}`, "DELETE");
|
|
1586
|
+
}
|
|
1587
|
+
async cancel(id) {
|
|
1588
|
+
return this.request(`/v0/websets/${id}/cancel`, "POST");
|
|
1589
|
+
}
|
|
1590
|
+
async preview(params, options) {
|
|
1591
|
+
const queryParams = { search: options?.search };
|
|
1592
|
+
return this.request(
|
|
1593
|
+
"/v0/websets/preview",
|
|
1594
|
+
"POST",
|
|
1595
|
+
{ ...params },
|
|
1596
|
+
queryParams
|
|
1597
|
+
);
|
|
1598
|
+
}
|
|
1599
|
+
/** Poll until a Webset reaches idle status. */
|
|
1600
|
+
async waitUntilIdle(id, options) {
|
|
1601
|
+
let timeout;
|
|
1602
|
+
let pollInterval = 1e3;
|
|
1603
|
+
let onPoll;
|
|
1604
|
+
if (typeof options === "number") {
|
|
1605
|
+
timeout = options;
|
|
1606
|
+
} else if (options) {
|
|
1607
|
+
timeout = options.timeout;
|
|
1608
|
+
pollInterval = options.pollInterval || 1e3;
|
|
1609
|
+
onPoll = options.onPoll;
|
|
1610
|
+
}
|
|
1611
|
+
const startTime = Date.now();
|
|
1612
|
+
while (true) {
|
|
1613
|
+
const webset = await this.get(id);
|
|
1614
|
+
if (onPoll) onPoll(webset.status);
|
|
1615
|
+
if (webset.status === "idle") return webset;
|
|
1616
|
+
if (timeout && Date.now() - startTime > timeout) {
|
|
1617
|
+
throw new Error(
|
|
1618
|
+
`Webset ${id} did not reach idle state within ${timeout}ms. Current status: ${webset.status}`
|
|
1619
|
+
);
|
|
1620
|
+
}
|
|
1621
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
};
|
|
1625
|
+
|
|
1626
|
+
// src/nova/research-client.ts
|
|
1627
|
+
import { ZodType as ZodType2 } from "zod";
|
|
1628
|
+
import { zodToJsonSchema as zodToJsonSchemaLib } from "zod-to-json-schema";
|
|
1629
|
+
function zodToJsonSchema2(schema) {
|
|
1630
|
+
return zodToJsonSchemaLib(schema, { $refStrategy: "none" });
|
|
1631
|
+
}
|
|
1632
|
+
var ResearchBaseClient2 = class {
|
|
1633
|
+
constructor(client) {
|
|
1634
|
+
this.client = client;
|
|
1635
|
+
}
|
|
1636
|
+
/** Make a request to the API, prepending `/research/v1` to the path. */
|
|
1637
|
+
async request(endpoint, method = "POST", data, params) {
|
|
1638
|
+
return this.client.request(
|
|
1639
|
+
`/research/v1${endpoint}`,
|
|
1640
|
+
method,
|
|
1641
|
+
data,
|
|
1642
|
+
params
|
|
1643
|
+
);
|
|
1644
|
+
}
|
|
1645
|
+
buildPaginationParams(pagination) {
|
|
1646
|
+
const params = {};
|
|
1647
|
+
if (!pagination) return params;
|
|
1648
|
+
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
1649
|
+
if (pagination.limit) params.limit = pagination.limit;
|
|
1650
|
+
return params;
|
|
1651
|
+
}
|
|
1652
|
+
};
|
|
1653
|
+
var ResearchClient2 = class extends ResearchBaseClient2 {
|
|
1654
|
+
/** List research requests. */
|
|
1655
|
+
async list(options) {
|
|
1656
|
+
const params = this.buildPaginationParams(options);
|
|
1657
|
+
return this.client.request("/research/v1", "GET", void 0, params);
|
|
1658
|
+
}
|
|
1659
|
+
/** Create a new research request. Defaults model to "exa-research-fast" if not provided. */
|
|
1660
|
+
async create(params) {
|
|
1661
|
+
let schema = params.outputSchema;
|
|
1662
|
+
if (schema instanceof ZodType2) {
|
|
1663
|
+
schema = zodToJsonSchema2(schema);
|
|
1664
|
+
}
|
|
1665
|
+
const payload = {
|
|
1666
|
+
instructions: params.instructions,
|
|
1667
|
+
model: params.model ?? "exa-research-fast"
|
|
1668
|
+
};
|
|
1669
|
+
if (schema) {
|
|
1670
|
+
payload.outputSchema = schema;
|
|
1671
|
+
}
|
|
1672
|
+
return this.client.request("/research/v1", "POST", payload, void 0);
|
|
1673
|
+
}
|
|
1674
|
+
/** Get a research request by ID. */
|
|
1675
|
+
async get(researchId, options) {
|
|
1676
|
+
const params = {};
|
|
1677
|
+
if (options?.events !== void 0)
|
|
1678
|
+
params.events = options.events.toString();
|
|
1679
|
+
return this.client.request(
|
|
1680
|
+
`/research/v1/${researchId}`,
|
|
1681
|
+
"GET",
|
|
1682
|
+
void 0,
|
|
1683
|
+
params
|
|
1684
|
+
);
|
|
1685
|
+
}
|
|
1686
|
+
/** Poll a research request until it reaches a terminal state (completed, failed, or canceled). */
|
|
1687
|
+
async pollUntilFinished(researchId, options) {
|
|
1688
|
+
const pollInterval = options?.pollInterval ?? 1e3;
|
|
1689
|
+
const timeoutMs = options?.timeoutMs ?? 10 * 60 * 1e3;
|
|
1690
|
+
const maxConsecutiveFailures = 5;
|
|
1691
|
+
const startTime = Date.now();
|
|
1692
|
+
let consecutiveFailures = 0;
|
|
1693
|
+
while (true) {
|
|
1694
|
+
try {
|
|
1695
|
+
const research = await this.get(researchId, {
|
|
1696
|
+
events: options?.events
|
|
1697
|
+
});
|
|
1698
|
+
consecutiveFailures = 0;
|
|
1699
|
+
if (research.status === "completed" || research.status === "failed" || research.status === "canceled") {
|
|
1700
|
+
return research;
|
|
1701
|
+
}
|
|
1702
|
+
} catch (err) {
|
|
1703
|
+
consecutiveFailures += 1;
|
|
1704
|
+
if (consecutiveFailures >= maxConsecutiveFailures) {
|
|
1705
|
+
throw new Error(
|
|
1706
|
+
`Polling failed ${maxConsecutiveFailures} times in a row for research ${researchId}: ${err}`
|
|
1707
|
+
);
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
if (Date.now() - startTime > timeoutMs) {
|
|
1711
|
+
throw new Error(
|
|
1712
|
+
`Polling timeout: Research ${researchId} did not complete within ${timeoutMs}ms`
|
|
1713
|
+
);
|
|
1714
|
+
}
|
|
1715
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
};
|
|
1719
|
+
|
|
1720
|
+
// src/nova/client.ts
|
|
1721
|
+
var CONTENTS_FIELDS = /* @__PURE__ */ new Set([
|
|
1722
|
+
"text",
|
|
1723
|
+
"highlights",
|
|
1724
|
+
"summary",
|
|
1725
|
+
"subpages",
|
|
1726
|
+
"subpageTarget",
|
|
1727
|
+
"extras",
|
|
1728
|
+
"livecrawl",
|
|
1729
|
+
"livecrawlTimeout",
|
|
1730
|
+
"maxAgeHours",
|
|
1731
|
+
"filterEmptyResults",
|
|
1732
|
+
"context"
|
|
1733
|
+
]);
|
|
1734
|
+
var DEFAULT_MAX_CHARACTERS = 1e4;
|
|
1735
|
+
var Exa2 = class {
|
|
1736
|
+
constructor(apiKey, baseURL = "https://api.exa.ai") {
|
|
1737
|
+
this.baseURL = baseURL;
|
|
1738
|
+
if (!apiKey) {
|
|
1739
|
+
apiKey = typeof process !== "undefined" ? process.env?.EXA_API_KEY : void 0;
|
|
1740
|
+
if (!apiKey) {
|
|
1741
|
+
throw new Error(
|
|
1742
|
+
"API key must be provided as an argument or as an environment variable (EXA_API_KEY)"
|
|
1743
|
+
);
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
this.headers = {
|
|
1747
|
+
"x-api-key": apiKey,
|
|
1748
|
+
"Content-Type": "application/json"
|
|
1749
|
+
};
|
|
1750
|
+
this.websets = new WebsetsClient2(this);
|
|
1751
|
+
this.research = new ResearchClient2(this);
|
|
1752
|
+
}
|
|
1753
|
+
/** Make a request to the Exa API. Used by sub-clients and available for direct use. */
|
|
1754
|
+
async request(endpoint, method, body, params, headers) {
|
|
1755
|
+
let url = `${this.baseURL}${endpoint}`;
|
|
1756
|
+
const normalizedBody = this.normalizeCategoryInBody(body);
|
|
1757
|
+
if (params && Object.keys(params).length > 0) {
|
|
1758
|
+
const searchParams = new URLSearchParams();
|
|
1759
|
+
for (const [key, value] of Object.entries(params)) {
|
|
1760
|
+
if (Array.isArray(value)) {
|
|
1761
|
+
for (const item of value) {
|
|
1762
|
+
searchParams.append(key, item);
|
|
1763
|
+
}
|
|
1764
|
+
} else if (value !== void 0) {
|
|
1765
|
+
searchParams.append(key, String(value));
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
url += `?${searchParams.toString()}`;
|
|
1769
|
+
}
|
|
1770
|
+
const combinedHeaders = headers ? { ...this.headers, ...headers } : this.headers;
|
|
1771
|
+
const response = await fetch(url, {
|
|
1772
|
+
method,
|
|
1773
|
+
headers: combinedHeaders,
|
|
1774
|
+
body: normalizedBody ? JSON.stringify(normalizedBody) : void 0
|
|
1775
|
+
});
|
|
1776
|
+
if (!response.ok) {
|
|
1777
|
+
const text = await response.text();
|
|
1778
|
+
throw new Error(`Exa API error ${response.status}: ${text}`);
|
|
1779
|
+
}
|
|
1780
|
+
return await response.json();
|
|
1781
|
+
}
|
|
1782
|
+
/** Make a raw request returning the Response object directly. */
|
|
1783
|
+
async rawRequest(endpoint, method = "POST", body, params) {
|
|
1784
|
+
let url = `${this.baseURL}${endpoint}`;
|
|
1785
|
+
const normalizedBody = this.normalizeCategoryInBody(body);
|
|
1786
|
+
if (params && Object.keys(params).length > 0) {
|
|
1787
|
+
const searchParams = new URLSearchParams();
|
|
1788
|
+
for (const [key, value] of Object.entries(params)) {
|
|
1789
|
+
if (Array.isArray(value)) {
|
|
1790
|
+
for (const item of value) {
|
|
1791
|
+
searchParams.append(key, item);
|
|
1792
|
+
}
|
|
1793
|
+
} else if (value !== void 0) {
|
|
1794
|
+
searchParams.append(key, String(value));
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
url += `?${searchParams.toString()}`;
|
|
1798
|
+
}
|
|
1799
|
+
return fetch(url, {
|
|
1800
|
+
method,
|
|
1801
|
+
headers: this.headers,
|
|
1802
|
+
body: normalizedBody ? JSON.stringify(normalizedBody) : void 0
|
|
1803
|
+
});
|
|
1804
|
+
}
|
|
1805
|
+
/** Normalize category values to underscore form. */
|
|
1806
|
+
normalizeCategoryInBody(body) {
|
|
1807
|
+
if (body == null || typeof body.category !== "string") {
|
|
1808
|
+
return body;
|
|
1809
|
+
}
|
|
1810
|
+
return { ...body, category: body.category.replace(/ /g, "_") };
|
|
1811
|
+
}
|
|
1812
|
+
/** Separate content-specific options from search/filter options. */
|
|
1813
|
+
extractContentsOptions(options) {
|
|
1814
|
+
const contentsOptions = {};
|
|
1815
|
+
const restOptions = {};
|
|
1816
|
+
let hasContentField = false;
|
|
1817
|
+
for (const [key, value] of Object.entries(options)) {
|
|
1818
|
+
if (CONTENTS_FIELDS.has(key)) {
|
|
1819
|
+
contentsOptions[key] = value;
|
|
1820
|
+
hasContentField = true;
|
|
1821
|
+
} else {
|
|
1822
|
+
restOptions[key] = value;
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
if (!hasContentField) {
|
|
1826
|
+
contentsOptions.text = { maxCharacters: DEFAULT_MAX_CHARACTERS };
|
|
1827
|
+
}
|
|
1828
|
+
return { contentsOptions, restOptions };
|
|
1829
|
+
}
|
|
1830
|
+
search(query, options) {
|
|
1831
|
+
let body;
|
|
1832
|
+
if (options === void 0 || !("contents" in options)) {
|
|
1833
|
+
body = {
|
|
1834
|
+
query,
|
|
1835
|
+
...options,
|
|
1836
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
1837
|
+
};
|
|
1838
|
+
} else if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
1839
|
+
const { contents, ...restOptions } = options;
|
|
1840
|
+
body = { query, ...restOptions };
|
|
1841
|
+
} else {
|
|
1842
|
+
body = { query, ...options };
|
|
1843
|
+
}
|
|
1844
|
+
return this.request("/search", "POST", body);
|
|
1845
|
+
}
|
|
1846
|
+
findSimilar(url, options) {
|
|
1847
|
+
let body;
|
|
1848
|
+
if (options === void 0 || !("contents" in options)) {
|
|
1849
|
+
body = {
|
|
1850
|
+
url,
|
|
1851
|
+
...options,
|
|
1852
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
1853
|
+
};
|
|
1854
|
+
} else if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
1855
|
+
const { contents, ...restOptions } = options;
|
|
1856
|
+
body = { url, ...restOptions };
|
|
1857
|
+
} else {
|
|
1858
|
+
body = { url, ...options };
|
|
1859
|
+
}
|
|
1860
|
+
return this.request("/findSimilar", "POST", body);
|
|
1861
|
+
}
|
|
1862
|
+
getContents(urls, options) {
|
|
1863
|
+
return this.request("/contents", "POST", { urls, ...options });
|
|
1864
|
+
}
|
|
1865
|
+
answer(query, options) {
|
|
1866
|
+
return this.request("/answer", "POST", { query, ...options });
|
|
1867
|
+
}
|
|
1868
|
+
streamAnswer(query, options) {
|
|
1869
|
+
return this.rawRequest("/answer", "POST", {
|
|
1870
|
+
query,
|
|
1871
|
+
stream: true,
|
|
1872
|
+
...options
|
|
1873
|
+
});
|
|
1874
|
+
}
|
|
1875
|
+
/**
|
|
1876
|
+
* @deprecated Use `search()` instead. The search method now returns text contents by default.
|
|
1877
|
+
* Search with contents. Extracts content fields (text, highlights, summary, etc.) into a `contents` wrapper.
|
|
1878
|
+
*/
|
|
1879
|
+
async searchAndContents(query, options) {
|
|
1880
|
+
if (options === void 0) {
|
|
1881
|
+
return this.request("/search", "POST", {
|
|
1882
|
+
query,
|
|
1883
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
1884
|
+
});
|
|
1885
|
+
}
|
|
1886
|
+
const { contentsOptions, restOptions } = this.extractContentsOptions(options);
|
|
1887
|
+
return this.request("/search", "POST", {
|
|
1888
|
+
query,
|
|
1889
|
+
contents: contentsOptions,
|
|
1890
|
+
...restOptions
|
|
1891
|
+
});
|
|
1892
|
+
}
|
|
1893
|
+
/**
|
|
1894
|
+
* @deprecated Use `findSimilar()` instead. The findSimilar method now returns text contents by default.
|
|
1895
|
+
* Find similar with contents. Extracts content fields into a `contents` wrapper.
|
|
1896
|
+
*/
|
|
1897
|
+
async findSimilarAndContents(url, options) {
|
|
1898
|
+
if (options === void 0) {
|
|
1899
|
+
return this.request("/findSimilar", "POST", {
|
|
1900
|
+
url,
|
|
1901
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1904
|
+
const { contentsOptions, restOptions } = this.extractContentsOptions(options);
|
|
1905
|
+
return this.request("/findSimilar", "POST", {
|
|
1906
|
+
url,
|
|
1907
|
+
contents: contentsOptions,
|
|
1908
|
+
...restOptions
|
|
1909
|
+
});
|
|
1910
|
+
}
|
|
1911
|
+
};
|
|
1912
|
+
|
|
1365
1913
|
// src/index.ts
|
|
1366
1914
|
var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : fetch2;
|
|
1367
1915
|
var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : Headers;
|
|
1368
|
-
var
|
|
1369
|
-
var
|
|
1916
|
+
var DEFAULT_MAX_CHARACTERS2 = 1e4;
|
|
1917
|
+
var Exa3 = class {
|
|
1370
1918
|
/**
|
|
1371
1919
|
* Helper method to separate out the contents-specific options from the rest.
|
|
1372
1920
|
*/
|
|
@@ -1533,7 +2081,7 @@ var Exa2 = class {
|
|
|
1533
2081
|
return await this.request("/search", "POST", {
|
|
1534
2082
|
query,
|
|
1535
2083
|
...options,
|
|
1536
|
-
contents: { text: { maxCharacters:
|
|
2084
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 } }
|
|
1537
2085
|
});
|
|
1538
2086
|
}
|
|
1539
2087
|
if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
@@ -1559,7 +2107,7 @@ var Exa2 = class {
|
|
|
1559
2107
|
async searchAndContents(query, options) {
|
|
1560
2108
|
const { contentsOptions, restOptions } = options === void 0 ? {
|
|
1561
2109
|
contentsOptions: {
|
|
1562
|
-
text: { maxCharacters:
|
|
2110
|
+
text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 }
|
|
1563
2111
|
},
|
|
1564
2112
|
restOptions: {}
|
|
1565
2113
|
} : this.extractContentsOptions(options);
|
|
@@ -1574,7 +2122,7 @@ var Exa2 = class {
|
|
|
1574
2122
|
return await this.request("/findSimilar", "POST", {
|
|
1575
2123
|
url,
|
|
1576
2124
|
...options,
|
|
1577
|
-
contents: { text: { maxCharacters:
|
|
2125
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 } }
|
|
1578
2126
|
});
|
|
1579
2127
|
}
|
|
1580
2128
|
if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
@@ -1602,7 +2150,7 @@ var Exa2 = class {
|
|
|
1602
2150
|
async findSimilarAndContents(url, options) {
|
|
1603
2151
|
const { contentsOptions, restOptions } = options === void 0 ? {
|
|
1604
2152
|
contentsOptions: {
|
|
1605
|
-
text: { maxCharacters:
|
|
2153
|
+
text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 }
|
|
1606
2154
|
},
|
|
1607
2155
|
restOptions: {}
|
|
1608
2156
|
} : this.extractContentsOptions(options);
|
|
@@ -1826,14 +2374,15 @@ var Exa2 = class {
|
|
|
1826
2374
|
});
|
|
1827
2375
|
}
|
|
1828
2376
|
};
|
|
1829
|
-
var index_default =
|
|
2377
|
+
var index_default = Exa3;
|
|
1830
2378
|
export {
|
|
1831
2379
|
CreateEnrichmentParametersFormat,
|
|
1832
2380
|
CreateImportParametersFormat,
|
|
1833
2381
|
EventType,
|
|
1834
2382
|
EventsClient,
|
|
1835
|
-
|
|
2383
|
+
Exa3 as Exa,
|
|
1836
2384
|
ExaError,
|
|
2385
|
+
Exa2 as ExaNova,
|
|
1837
2386
|
HttpStatusCode,
|
|
1838
2387
|
ImportFailedReason,
|
|
1839
2388
|
ImportFormat,
|