exa-js 1.10.1 → 2.0.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.js CHANGED
@@ -74,7 +74,7 @@ var import_cross_fetch = __toESM(require("cross-fetch"));
74
74
  // package.json
75
75
  var package_default = {
76
76
  name: "exa-js",
77
- version: "1.10.1",
77
+ version: "2.0.0",
78
78
  description: "Exa SDK for Node.js and the browser",
79
79
  publishConfig: {
80
80
  access: "public"
@@ -98,8 +98,9 @@ var package_default = {
98
98
  "build-fast": "tsup src/index.ts --format cjs,esm",
99
99
  build: "tsup",
100
100
  test: "vitest run",
101
+ "test:unit": "vitest run --config vitest.unit.config.ts",
102
+ "test:integration": "vitest run --config vitest.integration.config.ts",
101
103
  typecheck: "tsc --noEmit",
102
- "typecheck:src": "tsc --noEmit src/**/*.ts",
103
104
  "typecheck:examples": "tsc --noEmit examples/**/*.ts",
104
105
  "generate:types:websets": "openapi-typescript https://raw.githubusercontent.com/exa-labs/openapi-spec/refs/heads/master/exa-websets-spec.yaml --enum --root-types --alphabetize --root-types-no-schema-prefix --output ./src/websets/openapi.ts && npm run format:websets",
105
106
  format: 'prettier --write "src/**/*.ts" "examples/**/*.ts"',
@@ -238,7 +239,7 @@ var ResearchClient = class extends ResearchBaseClient {
238
239
  }
239
240
  const payload = {
240
241
  instructions,
241
- model: model ?? "exa-research"
242
+ model: model ?? "exa-research-fast"
242
243
  };
243
244
  if (schema) {
244
245
  payload.outputSchema = schema;
@@ -1329,6 +1330,7 @@ var WebsetsClient = class extends WebsetsBaseClient {
1329
1330
  // src/index.ts
1330
1331
  var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : import_cross_fetch.default;
1331
1332
  var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : import_cross_fetch.Headers;
1333
+ var DEFAULT_MAX_CHARACTERS = 1e4;
1332
1334
  var Exa2 = class {
1333
1335
  /**
1334
1336
  * Helper method to separate out the contents-specific options from the rest.
@@ -1336,7 +1338,6 @@ var Exa2 = class {
1336
1338
  extractContentsOptions(options) {
1337
1339
  const {
1338
1340
  text,
1339
- highlights,
1340
1341
  summary,
1341
1342
  subpages,
1342
1343
  subpageTarget,
@@ -1347,7 +1348,7 @@ var Exa2 = class {
1347
1348
  ...rest
1348
1349
  } = options;
1349
1350
  const contentsOptions = {};
1350
- if (text === void 0 && summary === void 0 && highlights === void 0 && extras === void 0) {
1351
+ if (text === void 0 && summary === void 0 && extras === void 0) {
1351
1352
  contentsOptions.text = true;
1352
1353
  }
1353
1354
  if (text !== void 0) contentsOptions.text = text;
@@ -1361,7 +1362,6 @@ var Exa2 = class {
1361
1362
  contentsOptions.summary = summary;
1362
1363
  }
1363
1364
  }
1364
- if (highlights !== void 0) contentsOptions.highlights = highlights;
1365
1365
  if (subpages !== void 0) contentsOptions.subpages = subpages;
1366
1366
  if (subpageTarget !== void 0)
1367
1367
  contentsOptions.subpageTarget = subpageTarget;
@@ -1383,10 +1383,10 @@ var Exa2 = class {
1383
1383
  constructor(apiKey, baseURL = "https://api.exa.ai") {
1384
1384
  this.baseURL = baseURL;
1385
1385
  if (!apiKey) {
1386
- apiKey = process.env.EXASEARCH_API_KEY;
1386
+ apiKey = process.env.EXA_API_KEY;
1387
1387
  if (!apiKey) {
1388
1388
  throw new ExaError(
1389
- "API key must be provided as an argument or as an environment variable (EXASEARCH_API_KEY)",
1389
+ "API key must be provided as an argument or as an environment variable (EXA_API_KEY)",
1390
1390
  401 /* Unauthorized */
1391
1391
  );
1392
1392
  }
@@ -1489,17 +1489,28 @@ var Exa2 = class {
1489
1489
  });
1490
1490
  return response;
1491
1491
  }
1492
- /**
1493
- * Performs a search with an Exa prompt-engineered query.
1494
- *
1495
- * @param {string} query - The query string.
1496
- * @param {RegularSearchOptions} [options] - Additional search options
1497
- * @returns {Promise<SearchResponse<{}>>} A list of relevant search results.
1498
- */
1499
1492
  async search(query, options) {
1493
+ if (options === void 0 || !("contents" in options)) {
1494
+ return await this.request("/search", "POST", {
1495
+ query,
1496
+ ...options,
1497
+ contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
1498
+ });
1499
+ }
1500
+ if (options.contents === false || options.contents === null || options.contents === void 0) {
1501
+ const { contents, ...restOptions } = options;
1502
+ return await this.request("/search", "POST", { query, ...restOptions });
1503
+ }
1500
1504
  return await this.request("/search", "POST", { query, ...options });
1501
1505
  }
1502
1506
  /**
1507
+ * @deprecated Use `search()` instead. The search method now returns text contents by default.
1508
+ *
1509
+ * Migration examples:
1510
+ * - `searchAndContents(query)` → `search(query)`
1511
+ * - `searchAndContents(query, { text: true })` → `search(query, { contents: { text: true } })`
1512
+ * - `searchAndContents(query, { summary: true })` → `search(query, { contents: { summary: true } })`
1513
+ *
1503
1514
  * Performs a search with an Exa prompt-engineered query and returns the contents of the documents.
1504
1515
  *
1505
1516
  * @param {string} query - The query string.
@@ -1507,30 +1518,55 @@ var Exa2 = class {
1507
1518
  * @returns {Promise<SearchResponse<T>>} A list of relevant search results with requested contents.
1508
1519
  */
1509
1520
  async searchAndContents(query, options) {
1510
- const { contentsOptions, restOptions } = options === void 0 ? { contentsOptions: { text: true }, restOptions: {} } : this.extractContentsOptions(options);
1521
+ const { contentsOptions, restOptions } = options === void 0 ? {
1522
+ contentsOptions: {
1523
+ text: { maxCharacters: DEFAULT_MAX_CHARACTERS }
1524
+ },
1525
+ restOptions: {}
1526
+ } : this.extractContentsOptions(options);
1511
1527
  return await this.request("/search", "POST", {
1512
1528
  query,
1513
1529
  contents: contentsOptions,
1514
1530
  ...restOptions
1515
1531
  });
1516
1532
  }
1517
- /**
1518
- * Finds similar links to the provided URL.
1519
- * @param {string} url - The URL for which to find similar links.
1520
- * @param {FindSimilarOptions} [options] - Additional options for finding similar links.
1521
- * @returns {Promise<SearchResponse<{}>>} A list of similar search results.
1522
- */
1523
1533
  async findSimilar(url, options) {
1534
+ if (options === void 0 || !("contents" in options)) {
1535
+ return await this.request("/findSimilar", "POST", {
1536
+ url,
1537
+ ...options,
1538
+ contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
1539
+ });
1540
+ }
1541
+ if (options.contents === false || options.contents === null || options.contents === void 0) {
1542
+ const { contents, ...restOptions } = options;
1543
+ return await this.request("/findSimilar", "POST", {
1544
+ url,
1545
+ ...restOptions
1546
+ });
1547
+ }
1524
1548
  return await this.request("/findSimilar", "POST", { url, ...options });
1525
1549
  }
1526
1550
  /**
1551
+ * @deprecated Use `findSimilar()` instead. The findSimilar method now returns text contents by default.
1552
+ *
1553
+ * Migration examples:
1554
+ * - `findSimilarAndContents(url)` → `findSimilar(url)`
1555
+ * - `findSimilarAndContents(url, { text: true })` → `findSimilar(url, { contents: { text: true } })`
1556
+ * - `findSimilarAndContents(url, { summary: true })` → `findSimilar(url, { contents: { summary: true } })`
1557
+ *
1527
1558
  * Finds similar links to the provided URL and returns the contents of the documents.
1528
1559
  * @param {string} url - The URL for which to find similar links.
1529
1560
  * @param {FindSimilarOptions & T} [options] - Additional options for finding similar links + contents.
1530
1561
  * @returns {Promise<SearchResponse<T>>} A list of similar search results, including requested contents.
1531
1562
  */
1532
1563
  async findSimilarAndContents(url, options) {
1533
- const { contentsOptions, restOptions } = options === void 0 ? { contentsOptions: { text: true }, restOptions: {} } : this.extractContentsOptions(options);
1564
+ const { contentsOptions, restOptions } = options === void 0 ? {
1565
+ contentsOptions: {
1566
+ text: { maxCharacters: DEFAULT_MAX_CHARACTERS }
1567
+ },
1568
+ restOptions: {}
1569
+ } : this.extractContentsOptions(options);
1534
1570
  return await this.request("/findSimilar", "POST", {
1535
1571
  url,
1536
1572
  contents: contentsOptions,