exa-js 2.5.1-beta.1 → 2.6.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
@@ -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.1-beta.1",
7
+ version: "2.6.0",
8
8
  description: "Exa SDK for Node.js and the browser",
9
9
  publishConfig: {
10
10
  access: "public"
@@ -1362,644 +1362,11 @@ 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(`/websets${endpoint}`, method, data, params, headers);
1373
- }
1374
- buildPaginationParams(pagination) {
1375
- const params = {};
1376
- if (!pagination) return params;
1377
- if (pagination.cursor) params.cursor = pagination.cursor;
1378
- if (pagination.limit) params.limit = pagination.limit;
1379
- return params;
1380
- }
1381
- };
1382
- var WebsetItemsClient2 = class extends WebsetsBaseClient2 {
1383
- async get(websetId, id) {
1384
- return this.request(`/v0/websets/${websetId}/items/${id}`, "GET");
1385
- }
1386
- async delete(websetId, id) {
1387
- return this.request(`/v0/websets/${websetId}/items/${id}`, "DELETE");
1388
- }
1389
- async list(websetId, options) {
1390
- const queryParams = { ...this.buildPaginationParams(options), sourceId: options?.sourceId };
1391
- return this.request(`/v0/websets/${websetId}/items`, "GET", void 0, queryParams);
1392
- }
1393
- /** Iterate through all items in a Webset, handling pagination automatically. */
1394
- async *listAll(websetId, options) {
1395
- let cursor = void 0;
1396
- const pageOptions = options ? { ...options } : {};
1397
- while (true) {
1398
- const response = await this.list(websetId, { ...pageOptions, cursor });
1399
- for (const item of response.data) {
1400
- yield item;
1401
- }
1402
- if (!response.hasMore || !response.nextCursor) {
1403
- break;
1404
- }
1405
- cursor = response.nextCursor;
1406
- }
1407
- }
1408
- /** Collect all items from a Webset into an array. */
1409
- async getAll(websetId, options) {
1410
- const items = [];
1411
- for await (const item of this.listAll(websetId, options)) {
1412
- items.push(item);
1413
- }
1414
- return items;
1415
- }
1416
- };
1417
- var WebsetSearchesClient2 = class extends WebsetsBaseClient2 {
1418
- async create(websetId, params, options) {
1419
- return this.request(`/v0/websets/${websetId}/searches`, "POST", { ...params }, void 0, options?.headers);
1420
- }
1421
- async get(websetId, id) {
1422
- return this.request(`/v0/websets/${websetId}/searches/${id}`, "GET");
1423
- }
1424
- async cancel(websetId, id) {
1425
- return this.request(`/v0/websets/${websetId}/searches/${id}/cancel`, "POST");
1426
- }
1427
- };
1428
- var WebsetEnrichmentsClient2 = class extends WebsetsBaseClient2 {
1429
- async create(websetId, params) {
1430
- return this.request(`/v0/websets/${websetId}/enrichments`, "POST", { ...params });
1431
- }
1432
- async update(websetId, id, params) {
1433
- return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "PATCH", { ...params });
1434
- }
1435
- async get(websetId, id) {
1436
- return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "GET");
1437
- }
1438
- async delete(websetId, id) {
1439
- return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "DELETE");
1440
- }
1441
- async cancel(websetId, id) {
1442
- return this.request(`/v0/websets/${websetId}/enrichments/${id}/cancel`, "POST");
1443
- }
1444
- };
1445
- var EventsClient2 = class extends WebsetsBaseClient2 {
1446
- async list(options) {
1447
- const queryParams = { ...this.buildPaginationParams(options), types: options?.types, createdBefore: options?.createdBefore, createdAfter: options?.createdAfter };
1448
- return this.request("/v0/events", "GET", void 0, queryParams);
1449
- }
1450
- async get(id) {
1451
- return this.request(`/v0/events/${id}`, "GET");
1452
- }
1453
- };
1454
- var WebsetMonitorRunsClient2 = class extends WebsetsBaseClient2 {
1455
- async list(monitorId) {
1456
- return this.request(`/v0/monitors/${monitorId}/runs`, "GET");
1457
- }
1458
- async get(monitorId, id) {
1459
- return this.request(`/v0/monitors/${monitorId}/runs/${id}`, "GET");
1460
- }
1461
- };
1462
- var WebsetMonitorsClient2 = class extends WebsetsBaseClient2 {
1463
- constructor(client) {
1464
- super(client);
1465
- this.runs = new WebsetMonitorRunsClient2(client);
1466
- }
1467
- async create(params) {
1468
- return this.request("/v0/monitors", "POST", { ...params });
1469
- }
1470
- async list(options) {
1471
- const queryParams = { ...this.buildPaginationParams(options), websetId: options?.websetId };
1472
- return this.request("/v0/monitors", "GET", void 0, queryParams);
1473
- }
1474
- async get(id) {
1475
- return this.request(`/v0/monitors/${id}`, "GET");
1476
- }
1477
- async update(id, params) {
1478
- return this.request(`/v0/monitors/${id}`, "PATCH", { ...params });
1479
- }
1480
- async delete(id) {
1481
- return this.request(`/v0/monitors/${id}`, "DELETE");
1482
- }
1483
- /** Iterate through all monitors, handling pagination automatically. */
1484
- async *listAll(options) {
1485
- let cursor = void 0;
1486
- const pageOptions = options ? { ...options } : {};
1487
- while (true) {
1488
- const response = await this.list({ ...pageOptions, cursor });
1489
- for (const monitor of response.data) {
1490
- yield monitor;
1491
- }
1492
- if (!response.hasMore || !response.nextCursor) {
1493
- break;
1494
- }
1495
- cursor = response.nextCursor;
1496
- }
1497
- }
1498
- /** Collect all monitors into an array. */
1499
- async getAll(options) {
1500
- const monitors = [];
1501
- for await (const monitor of this.listAll(options)) {
1502
- monitors.push(monitor);
1503
- }
1504
- return monitors;
1505
- }
1506
- };
1507
- var WebsetWebhooksClient2 = class extends WebsetsBaseClient2 {
1508
- async create(params) {
1509
- return this.request("/v0/webhooks", "POST", { ...params });
1510
- }
1511
- async list(options) {
1512
- const queryParams = this.buildPaginationParams(options);
1513
- return this.request("/v0/webhooks", "GET", void 0, queryParams);
1514
- }
1515
- async get(id) {
1516
- return this.request(`/v0/webhooks/${id}`, "GET");
1517
- }
1518
- async update(id, params) {
1519
- return this.request(`/v0/webhooks/${id}`, "PATCH", { ...params });
1520
- }
1521
- async delete(id) {
1522
- return this.request(`/v0/webhooks/${id}`, "DELETE");
1523
- }
1524
- async listAttempts(id, options) {
1525
- const queryParams = { ...this.buildPaginationParams(options), eventType: options?.eventType, successful: options?.successful };
1526
- return this.request(`/v0/webhooks/${id}/attempts`, "GET", void 0, queryParams);
1527
- }
1528
- };
1529
- var ImportsClient2 = class extends WebsetsBaseClient2 {
1530
- async create(params) {
1531
- return this.request("/v0/imports", "POST", { ...params });
1532
- }
1533
- async list(options) {
1534
- const queryParams = this.buildPaginationParams(options);
1535
- return this.request("/v0/imports", "GET", void 0, queryParams);
1536
- }
1537
- async get(id) {
1538
- return this.request(`/v0/imports/${id}`, "GET");
1539
- }
1540
- async update(id, params) {
1541
- return this.request(`/v0/imports/${id}`, "PATCH", { ...params });
1542
- }
1543
- async delete(id) {
1544
- return this.request(`/v0/imports/${id}`, "DELETE");
1545
- }
1546
- };
1547
- var WebsetsClient2 = class extends WebsetsBaseClient2 {
1548
- constructor(client) {
1549
- super(client);
1550
- this.items = new WebsetItemsClient2(client);
1551
- this.searches = new WebsetSearchesClient2(client);
1552
- this.enrichments = new WebsetEnrichmentsClient2(client);
1553
- this.events = new EventsClient2(client);
1554
- this.monitors = new WebsetMonitorsClient2(client);
1555
- this.webhooks = new WebsetWebhooksClient2(client);
1556
- this.imports = new ImportsClient2(client);
1557
- }
1558
- async create(params, options) {
1559
- return this.request("/v0/websets", "POST", { ...params }, void 0, options?.headers);
1560
- }
1561
- async list(options) {
1562
- const queryParams = { ...this.buildPaginationParams(options), search: options?.search };
1563
- return this.request("/v0/websets", "GET", void 0, queryParams);
1564
- }
1565
- async get(id, options) {
1566
- const queryParams = { expand: options?.expand };
1567
- return this.request(`/v0/websets/${id}`, "GET", void 0, queryParams);
1568
- }
1569
- async update(id, params) {
1570
- return this.request(`/v0/websets/${id}`, "POST", { ...params });
1571
- }
1572
- async delete(id) {
1573
- return this.request(`/v0/websets/${id}`, "DELETE");
1574
- }
1575
- async cancel(id) {
1576
- return this.request(`/v0/websets/${id}/cancel`, "POST");
1577
- }
1578
- async preview(params, options) {
1579
- const queryParams = { search: options?.search };
1580
- return this.request("/v0/websets/preview", "POST", { ...params }, queryParams);
1581
- }
1582
- /** Iterate through all Websets, handling pagination automatically. */
1583
- async *listAll(options) {
1584
- let cursor = void 0;
1585
- const pageOptions = options ? { ...options } : {};
1586
- while (true) {
1587
- const response = await this.list({ ...pageOptions, cursor });
1588
- for (const webset of response.data) {
1589
- yield webset;
1590
- }
1591
- if (!response.hasMore || !response.nextCursor) {
1592
- break;
1593
- }
1594
- cursor = response.nextCursor;
1595
- }
1596
- }
1597
- /** Collect all Websets into an array. */
1598
- async getAll(options) {
1599
- const websets = [];
1600
- for await (const webset of this.listAll(options)) {
1601
- websets.push(webset);
1602
- }
1603
- return websets;
1604
- }
1605
- /** Poll until a Webset reaches idle status. */
1606
- async waitUntilIdle(id, options) {
1607
- let timeout;
1608
- let pollInterval = 1e3;
1609
- let onPoll;
1610
- if (typeof options === "number") {
1611
- timeout = options;
1612
- } else if (options) {
1613
- timeout = options.timeout;
1614
- pollInterval = options.pollInterval || 1e3;
1615
- onPoll = options.onPoll;
1616
- }
1617
- const startTime = Date.now();
1618
- while (true) {
1619
- const webset = await this.get(id);
1620
- if (onPoll) onPoll(webset.status);
1621
- if (webset.status === "idle") return webset;
1622
- if (timeout && Date.now() - startTime > timeout) {
1623
- throw new Error(`Webset ${id} did not reach idle state within ${timeout}ms. Current status: ${webset.status}`);
1624
- }
1625
- await new Promise((resolve) => setTimeout(resolve, pollInterval));
1626
- }
1627
- }
1628
- };
1629
-
1630
- // src/nova/research-client.ts
1631
- import { ZodType as ZodType2 } from "zod";
1632
- import { zodToJsonSchema as zodToJsonSchemaLib } from "zod-to-json-schema";
1633
- function zodToJsonSchema2(schema) {
1634
- return zodToJsonSchemaLib(schema, { $refStrategy: "none" });
1635
- }
1636
- var ResearchBaseClient2 = class {
1637
- constructor(client) {
1638
- this.client = client;
1639
- }
1640
- /** Make a request to the API, prepending `/research/v1` to the path. */
1641
- async request(endpoint, method = "POST", data, params) {
1642
- return this.client.request(`/research/v1${endpoint}`, method, data, params);
1643
- }
1644
- buildPaginationParams(pagination) {
1645
- const params = {};
1646
- if (!pagination) return params;
1647
- if (pagination.cursor) params.cursor = pagination.cursor;
1648
- if (pagination.limit) params.limit = pagination.limit;
1649
- return params;
1650
- }
1651
- };
1652
- var ResearchClient2 = class extends ResearchBaseClient2 {
1653
- /** List research requests. */
1654
- async list(options) {
1655
- const params = this.buildPaginationParams(options);
1656
- return this.client.request("/research/v1", "GET", void 0, params);
1657
- }
1658
- /** Create a new research request. Defaults model to "exa-research-fast" if not provided. */
1659
- async create(params) {
1660
- let schema = params.outputSchema;
1661
- if (schema instanceof ZodType2) {
1662
- schema = zodToJsonSchema2(schema);
1663
- }
1664
- const payload = {
1665
- instructions: params.instructions,
1666
- model: params.model ?? "exa-research-fast"
1667
- };
1668
- if (schema) {
1669
- payload.outputSchema = schema;
1670
- }
1671
- return this.client.request("/research/v1", "POST", payload, void 0);
1672
- }
1673
- /** Get a research request by ID. */
1674
- async get(researchId, options) {
1675
- const params = {};
1676
- if (options?.events !== void 0) params.events = options.events.toString();
1677
- return this.client.request(`/research/v1/${researchId}`, "GET", void 0, params);
1678
- }
1679
- /** Poll a research request until it reaches a terminal state (completed, failed, or canceled). */
1680
- async pollUntilFinished(researchId, options) {
1681
- const pollInterval = options?.pollInterval ?? 1e3;
1682
- const timeoutMs = options?.timeoutMs ?? 10 * 60 * 1e3;
1683
- const maxConsecutiveFailures = 5;
1684
- const startTime = Date.now();
1685
- let consecutiveFailures = 0;
1686
- while (true) {
1687
- try {
1688
- const research = await this.get(researchId, { events: options?.events });
1689
- consecutiveFailures = 0;
1690
- if (research.status === "completed" || research.status === "failed" || research.status === "canceled") {
1691
- return research;
1692
- }
1693
- } catch (err) {
1694
- consecutiveFailures += 1;
1695
- if (consecutiveFailures >= maxConsecutiveFailures) {
1696
- throw new Error(`Polling failed ${maxConsecutiveFailures} times in a row for research ${researchId}: ${err}`);
1697
- }
1698
- }
1699
- if (Date.now() - startTime > timeoutMs) {
1700
- throw new Error(`Polling timeout: Research ${researchId} did not complete within ${timeoutMs}ms`);
1701
- }
1702
- await new Promise((resolve) => setTimeout(resolve, pollInterval));
1703
- }
1704
- }
1705
- };
1706
-
1707
- // src/nova/client.ts
1708
- function isRecord(value) {
1709
- return value != null && typeof value === "object" && !Array.isArray(value);
1710
- }
1711
- var ExaError2 = class extends Error {
1712
- constructor(message, statusCode, timestamp, path, details) {
1713
- super(message);
1714
- this.name = "ExaError";
1715
- this.statusCode = statusCode;
1716
- this.timestamp = timestamp;
1717
- this.path = path;
1718
- this.details = details;
1719
- }
1720
- };
1721
- var CONTENTS_FIELDS = /* @__PURE__ */ new Set(["text", "highlights", "summary", "subpages", "subpageTarget", "extras", "livecrawl", "livecrawlTimeout", "maxAgeHours", "filterEmptyResults", "context"]);
1722
- var DEFAULT_MAX_CHARACTERS = 1e4;
1723
- var Exa2 = class {
1724
- constructor(apiKey, baseURL = "https://api.exa.ai") {
1725
- this.baseURL = baseURL;
1726
- if (!apiKey) {
1727
- apiKey = typeof process !== "undefined" ? process.env?.EXA_API_KEY : void 0;
1728
- if (!apiKey) {
1729
- throw new ExaError2(
1730
- "API key must be provided as an argument or as an environment variable (EXA_API_KEY)",
1731
- 401
1732
- );
1733
- }
1734
- }
1735
- this.headers = {
1736
- "x-api-key": apiKey,
1737
- "Content-Type": "application/json"
1738
- };
1739
- this.websets = new WebsetsClient2(this);
1740
- this.research = new ResearchClient2(this);
1741
- }
1742
- /** Make a request to the Exa API. Used by sub-clients and available for direct use. */
1743
- async request(endpoint, method, body, params, headers) {
1744
- const url = this.buildRequestUrl(endpoint, params);
1745
- const normalizedBody = this.normalizeCategoryInBody(body);
1746
- const combinedHeaders = headers ? { ...this.headers, ...headers } : this.headers;
1747
- const response = await fetch(url, {
1748
- method,
1749
- headers: combinedHeaders,
1750
- body: normalizedBody ? JSON.stringify(normalizedBody) : void 0
1751
- });
1752
- if (!response.ok) {
1753
- throw await this.toExaError(response, endpoint);
1754
- }
1755
- return await response.json();
1756
- }
1757
- /** Make a raw request returning the Response object directly. */
1758
- async rawRequest(endpoint, method = "POST", body, params) {
1759
- const url = this.buildRequestUrl(endpoint, params);
1760
- const normalizedBody = this.normalizeCategoryInBody(body);
1761
- return fetch(url, {
1762
- method,
1763
- headers: this.headers,
1764
- body: normalizedBody ? JSON.stringify(normalizedBody) : void 0
1765
- });
1766
- }
1767
- /** Normalize category values to underscore form. */
1768
- normalizeCategoryInBody(body) {
1769
- if (body == null || typeof body.category !== "string") {
1770
- return body;
1771
- }
1772
- return { ...body, category: body.category.replace(/ /g, "_") };
1773
- }
1774
- buildRequestUrl(endpoint, params) {
1775
- let url = `${this.baseURL}${endpoint}`;
1776
- if (params == null || Object.keys(params).length === 0) {
1777
- return url;
1778
- }
1779
- const searchParams = new URLSearchParams();
1780
- for (const [key, value] of Object.entries(params)) {
1781
- if (Array.isArray(value)) {
1782
- for (const item of value) {
1783
- searchParams.append(key, item);
1784
- }
1785
- } else if (value !== void 0) {
1786
- searchParams.append(key, String(value));
1787
- }
1788
- }
1789
- url += `?${searchParams.toString()}`;
1790
- return url;
1791
- }
1792
- tryParseJsonRecord(text) {
1793
- if (text.length === 0) {
1794
- return null;
1795
- }
1796
- try {
1797
- const parsed = JSON.parse(text);
1798
- return isRecord(parsed) ? parsed : null;
1799
- } catch {
1800
- return null;
1801
- }
1802
- }
1803
- async toExaError(response, endpoint) {
1804
- const text = await response.text();
1805
- const parsed = this.tryParseJsonRecord(text);
1806
- const statusCode = parsed != null && typeof parsed.statusCode === "number" ? parsed.statusCode : response.status;
1807
- const timestamp = parsed != null && typeof parsed.timestamp === "string" ? parsed.timestamp : void 0;
1808
- const path = parsed != null && typeof parsed.path === "string" ? parsed.path : endpoint;
1809
- const errorMessage = parsed != null && typeof parsed.error === "string" ? parsed.error : void 0;
1810
- const detailMessage = parsed != null && typeof parsed.message === "string" ? parsed.message : void 0;
1811
- let message;
1812
- if (errorMessage != null && detailMessage != null) {
1813
- message = `${errorMessage}. ${detailMessage}`;
1814
- } else if (errorMessage != null) {
1815
- message = errorMessage;
1816
- } else if (detailMessage != null) {
1817
- message = detailMessage;
1818
- } else if (text.length > 0) {
1819
- message = text;
1820
- } else {
1821
- message = `Exa API error ${response.status}`;
1822
- }
1823
- return new ExaError2(message, statusCode, timestamp, path, parsed ?? text);
1824
- }
1825
- parseAnswerStreamLine(line) {
1826
- if (!line.startsWith("data:")) {
1827
- return null;
1828
- }
1829
- const jsonStr = line.replace(/^data:\s*/, "").trim();
1830
- if (jsonStr.length === 0 || jsonStr === "[DONE]") {
1831
- return null;
1832
- }
1833
- let parsedChunk;
1834
- try {
1835
- parsedChunk = JSON.parse(jsonStr);
1836
- } catch {
1837
- return null;
1838
- }
1839
- if (!isRecord(parsedChunk)) {
1840
- return null;
1841
- }
1842
- let content;
1843
- const choices = parsedChunk.choices;
1844
- if (Array.isArray(choices) && choices.length > 0 && isRecord(choices[0])) {
1845
- const delta = choices[0].delta;
1846
- if (isRecord(delta) && typeof delta.content === "string") {
1847
- content = delta.content;
1848
- }
1849
- }
1850
- let citations;
1851
- if (Array.isArray(parsedChunk.citations)) {
1852
- const normalized = [];
1853
- for (const citation of parsedChunk.citations) {
1854
- if (!isRecord(citation)) {
1855
- continue;
1856
- }
1857
- const id = typeof citation.id === "string" ? citation.id : void 0;
1858
- const url = typeof citation.url === "string" ? citation.url : void 0;
1859
- const title = typeof citation.title === "string" ? citation.title : void 0;
1860
- const publishedDate = typeof citation.publishedDate === "string" ? citation.publishedDate : void 0;
1861
- const author = typeof citation.author === "string" ? citation.author : void 0;
1862
- const text = typeof citation.text === "string" ? citation.text : void 0;
1863
- normalized.push({
1864
- ...id != null ? { id } : {},
1865
- ...url != null ? { url } : {},
1866
- ...title != null ? { title } : {},
1867
- ...publishedDate != null ? { publishedDate } : {},
1868
- ...author != null ? { author } : {},
1869
- ...text != null ? { text } : {}
1870
- });
1871
- }
1872
- if (normalized.length > 0) {
1873
- citations = normalized;
1874
- }
1875
- }
1876
- if (content == null && (citations == null || citations.length === 0)) {
1877
- return null;
1878
- }
1879
- return {
1880
- ...content != null ? { content } : {},
1881
- ...citations != null ? { citations } : {}
1882
- };
1883
- }
1884
- /** Separate content-specific options from search/filter options. */
1885
- extractContentsOptions(options) {
1886
- const contentsOptions = {};
1887
- const restOptions = {};
1888
- let hasContentField = false;
1889
- for (const [key, value] of Object.entries(options)) {
1890
- if (CONTENTS_FIELDS.has(key)) {
1891
- contentsOptions[key] = value;
1892
- hasContentField = true;
1893
- } else {
1894
- restOptions[key] = value;
1895
- }
1896
- }
1897
- if (!hasContentField) {
1898
- contentsOptions.text = { maxCharacters: DEFAULT_MAX_CHARACTERS };
1899
- }
1900
- return { contentsOptions, restOptions };
1901
- }
1902
- search(query, options) {
1903
- let body;
1904
- if (options === void 0 || !("contents" in options)) {
1905
- body = { query, ...options, contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } } };
1906
- } else if (options.contents === false || options.contents === null || options.contents === void 0) {
1907
- const { contents, ...restOptions } = options;
1908
- body = { query, ...restOptions };
1909
- } else {
1910
- body = { query, ...options };
1911
- }
1912
- return this.request("/search", "POST", body);
1913
- }
1914
- findSimilar(url, options) {
1915
- let body;
1916
- if (options === void 0 || !("contents" in options)) {
1917
- body = { url, ...options, contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } } };
1918
- } else if (options.contents === false || options.contents === null || options.contents === void 0) {
1919
- const { contents, ...restOptions } = options;
1920
- body = { url, ...restOptions };
1921
- } else {
1922
- body = { url, ...options };
1923
- }
1924
- return this.request("/findSimilar", "POST", body);
1925
- }
1926
- getContents(urls, options) {
1927
- return this.request("/contents", "POST", { urls, ...options });
1928
- }
1929
- answer(query, options) {
1930
- if (options?.stream) {
1931
- throw new ExaError2("For streaming responses, please use streamAnswer() instead:\n\nfor await (const chunk of exa.streamAnswer(query)) {\n // Handle chunks\n}", 400);
1932
- }
1933
- return this.request("/answer", "POST", { query, model: "exa", stream: false, text: false, ...options });
1934
- }
1935
- async *streamAnswer(query, options) {
1936
- const response = await this.rawRequest("/answer", "POST", { query, model: "exa", text: false, ...options, stream: true });
1937
- if (!response.ok) {
1938
- throw await this.toExaError(response, "/answer");
1939
- }
1940
- const reader = response.body?.getReader();
1941
- if (!reader) {
1942
- throw new ExaError2("No response body available for streaming.", 500, (/* @__PURE__ */ new Date()).toISOString(), "/answer");
1943
- }
1944
- const decoder = new TextDecoder();
1945
- let buffer = "";
1946
- try {
1947
- while (true) {
1948
- const { done, value } = await reader.read();
1949
- if (done) break;
1950
- buffer += decoder.decode(value, { stream: true });
1951
- const lines = buffer.split("\n");
1952
- buffer = lines.pop() ?? "";
1953
- for (const line of lines) {
1954
- const chunk = this.parseAnswerStreamLine(line);
1955
- if (chunk != null) {
1956
- yield chunk;
1957
- }
1958
- }
1959
- }
1960
- const trailingChunk = this.parseAnswerStreamLine(buffer);
1961
- if (trailingChunk != null) {
1962
- yield trailingChunk;
1963
- }
1964
- } finally {
1965
- reader.releaseLock();
1966
- }
1967
- }
1968
- /**
1969
- * @deprecated Use `search()` instead. The search method now returns text contents by default.
1970
- * Search with contents. Extracts content fields (text, highlights, summary, etc.) into a `contents` wrapper.
1971
- */
1972
- async searchAndContents(query, options) {
1973
- if (options === void 0) {
1974
- return this.request("/search", "POST", {
1975
- query,
1976
- contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
1977
- });
1978
- }
1979
- const { contentsOptions, restOptions } = this.extractContentsOptions(options);
1980
- return this.request("/search", "POST", { query, contents: contentsOptions, ...restOptions });
1981
- }
1982
- /**
1983
- * @deprecated Use `findSimilar()` instead. The findSimilar method now returns text contents by default.
1984
- * Find similar with contents. Extracts content fields into a `contents` wrapper.
1985
- */
1986
- async findSimilarAndContents(url, options) {
1987
- if (options === void 0) {
1988
- return this.request("/findSimilar", "POST", {
1989
- url,
1990
- contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
1991
- });
1992
- }
1993
- const { contentsOptions, restOptions } = this.extractContentsOptions(options);
1994
- return this.request("/findSimilar", "POST", { url, contents: contentsOptions, ...restOptions });
1995
- }
1996
- };
1997
-
1998
1365
  // src/index.ts
1999
1366
  var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : fetch2;
2000
1367
  var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : Headers;
2001
- var DEFAULT_MAX_CHARACTERS2 = 1e4;
2002
- var Exa3 = class {
1368
+ var DEFAULT_MAX_CHARACTERS = 1e4;
1369
+ var Exa2 = class {
2003
1370
  /**
2004
1371
  * Helper method to separate out the contents-specific options from the rest.
2005
1372
  */
@@ -2166,7 +1533,7 @@ var Exa3 = class {
2166
1533
  return await this.request("/search", "POST", {
2167
1534
  query,
2168
1535
  ...options,
2169
- contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 } }
1536
+ contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
2170
1537
  });
2171
1538
  }
2172
1539
  if (options.contents === false || options.contents === null || options.contents === void 0) {
@@ -2192,7 +1559,7 @@ var Exa3 = class {
2192
1559
  async searchAndContents(query, options) {
2193
1560
  const { contentsOptions, restOptions } = options === void 0 ? {
2194
1561
  contentsOptions: {
2195
- text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 }
1562
+ text: { maxCharacters: DEFAULT_MAX_CHARACTERS }
2196
1563
  },
2197
1564
  restOptions: {}
2198
1565
  } : this.extractContentsOptions(options);
@@ -2207,7 +1574,7 @@ var Exa3 = class {
2207
1574
  return await this.request("/findSimilar", "POST", {
2208
1575
  url,
2209
1576
  ...options,
2210
- contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 } }
1577
+ contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
2211
1578
  });
2212
1579
  }
2213
1580
  if (options.contents === false || options.contents === null || options.contents === void 0) {
@@ -2235,7 +1602,7 @@ var Exa3 = class {
2235
1602
  async findSimilarAndContents(url, options) {
2236
1603
  const { contentsOptions, restOptions } = options === void 0 ? {
2237
1604
  contentsOptions: {
2238
- text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 }
1605
+ text: { maxCharacters: DEFAULT_MAX_CHARACTERS }
2239
1606
  },
2240
1607
  restOptions: {}
2241
1608
  } : this.extractContentsOptions(options);
@@ -2459,15 +1826,14 @@ var Exa3 = class {
2459
1826
  });
2460
1827
  }
2461
1828
  };
2462
- var index_default = Exa3;
1829
+ var index_default = Exa2;
2463
1830
  export {
2464
1831
  CreateEnrichmentParametersFormat,
2465
1832
  CreateImportParametersFormat,
2466
1833
  EventType,
2467
1834
  EventsClient,
2468
- Exa3 as Exa,
1835
+ Exa2 as Exa,
2469
1836
  ExaError,
2470
- Exa2 as ExaNova,
2471
1837
  HttpStatusCode,
2472
1838
  ImportFailedReason,
2473
1839
  ImportFormat,