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.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: "1.10.1",
7
+ version: "2.0.0",
8
8
  description: "Exa SDK for Node.js and the browser",
9
9
  publishConfig: {
10
10
  access: "public"
@@ -28,8 +28,9 @@ var package_default = {
28
28
  "build-fast": "tsup src/index.ts --format cjs,esm",
29
29
  build: "tsup",
30
30
  test: "vitest run",
31
+ "test:unit": "vitest run --config vitest.unit.config.ts",
32
+ "test:integration": "vitest run --config vitest.integration.config.ts",
31
33
  typecheck: "tsc --noEmit",
32
- "typecheck:src": "tsc --noEmit src/**/*.ts",
33
34
  "typecheck:examples": "tsc --noEmit examples/**/*.ts",
34
35
  "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",
35
36
  format: 'prettier --write "src/**/*.ts" "examples/**/*.ts"',
@@ -168,7 +169,7 @@ var ResearchClient = class extends ResearchBaseClient {
168
169
  }
169
170
  const payload = {
170
171
  instructions,
171
- model: model ?? "exa-research"
172
+ model: model ?? "exa-research-fast"
172
173
  };
173
174
  if (schema) {
174
175
  payload.outputSchema = schema;
@@ -1259,6 +1260,7 @@ var WebsetsClient = class extends WebsetsBaseClient {
1259
1260
  // src/index.ts
1260
1261
  var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : fetch2;
1261
1262
  var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : Headers;
1263
+ var DEFAULT_MAX_CHARACTERS = 1e4;
1262
1264
  var Exa2 = class {
1263
1265
  /**
1264
1266
  * Helper method to separate out the contents-specific options from the rest.
@@ -1266,7 +1268,6 @@ var Exa2 = class {
1266
1268
  extractContentsOptions(options) {
1267
1269
  const {
1268
1270
  text,
1269
- highlights,
1270
1271
  summary,
1271
1272
  subpages,
1272
1273
  subpageTarget,
@@ -1277,7 +1278,7 @@ var Exa2 = class {
1277
1278
  ...rest
1278
1279
  } = options;
1279
1280
  const contentsOptions = {};
1280
- if (text === void 0 && summary === void 0 && highlights === void 0 && extras === void 0) {
1281
+ if (text === void 0 && summary === void 0 && extras === void 0) {
1281
1282
  contentsOptions.text = true;
1282
1283
  }
1283
1284
  if (text !== void 0) contentsOptions.text = text;
@@ -1291,7 +1292,6 @@ var Exa2 = class {
1291
1292
  contentsOptions.summary = summary;
1292
1293
  }
1293
1294
  }
1294
- if (highlights !== void 0) contentsOptions.highlights = highlights;
1295
1295
  if (subpages !== void 0) contentsOptions.subpages = subpages;
1296
1296
  if (subpageTarget !== void 0)
1297
1297
  contentsOptions.subpageTarget = subpageTarget;
@@ -1313,10 +1313,10 @@ var Exa2 = class {
1313
1313
  constructor(apiKey, baseURL = "https://api.exa.ai") {
1314
1314
  this.baseURL = baseURL;
1315
1315
  if (!apiKey) {
1316
- apiKey = process.env.EXASEARCH_API_KEY;
1316
+ apiKey = process.env.EXA_API_KEY;
1317
1317
  if (!apiKey) {
1318
1318
  throw new ExaError(
1319
- "API key must be provided as an argument or as an environment variable (EXASEARCH_API_KEY)",
1319
+ "API key must be provided as an argument or as an environment variable (EXA_API_KEY)",
1320
1320
  401 /* Unauthorized */
1321
1321
  );
1322
1322
  }
@@ -1419,17 +1419,28 @@ var Exa2 = class {
1419
1419
  });
1420
1420
  return response;
1421
1421
  }
1422
- /**
1423
- * Performs a search with an Exa prompt-engineered query.
1424
- *
1425
- * @param {string} query - The query string.
1426
- * @param {RegularSearchOptions} [options] - Additional search options
1427
- * @returns {Promise<SearchResponse<{}>>} A list of relevant search results.
1428
- */
1429
1422
  async search(query, options) {
1423
+ if (options === void 0 || !("contents" in options)) {
1424
+ return await this.request("/search", "POST", {
1425
+ query,
1426
+ ...options,
1427
+ contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
1428
+ });
1429
+ }
1430
+ if (options.contents === false || options.contents === null || options.contents === void 0) {
1431
+ const { contents, ...restOptions } = options;
1432
+ return await this.request("/search", "POST", { query, ...restOptions });
1433
+ }
1430
1434
  return await this.request("/search", "POST", { query, ...options });
1431
1435
  }
1432
1436
  /**
1437
+ * @deprecated Use `search()` instead. The search method now returns text contents by default.
1438
+ *
1439
+ * Migration examples:
1440
+ * - `searchAndContents(query)` → `search(query)`
1441
+ * - `searchAndContents(query, { text: true })` → `search(query, { contents: { text: true } })`
1442
+ * - `searchAndContents(query, { summary: true })` → `search(query, { contents: { summary: true } })`
1443
+ *
1433
1444
  * Performs a search with an Exa prompt-engineered query and returns the contents of the documents.
1434
1445
  *
1435
1446
  * @param {string} query - The query string.
@@ -1437,30 +1448,55 @@ var Exa2 = class {
1437
1448
  * @returns {Promise<SearchResponse<T>>} A list of relevant search results with requested contents.
1438
1449
  */
1439
1450
  async searchAndContents(query, options) {
1440
- const { contentsOptions, restOptions } = options === void 0 ? { contentsOptions: { text: true }, restOptions: {} } : this.extractContentsOptions(options);
1451
+ const { contentsOptions, restOptions } = options === void 0 ? {
1452
+ contentsOptions: {
1453
+ text: { maxCharacters: DEFAULT_MAX_CHARACTERS }
1454
+ },
1455
+ restOptions: {}
1456
+ } : this.extractContentsOptions(options);
1441
1457
  return await this.request("/search", "POST", {
1442
1458
  query,
1443
1459
  contents: contentsOptions,
1444
1460
  ...restOptions
1445
1461
  });
1446
1462
  }
1447
- /**
1448
- * Finds similar links to the provided URL.
1449
- * @param {string} url - The URL for which to find similar links.
1450
- * @param {FindSimilarOptions} [options] - Additional options for finding similar links.
1451
- * @returns {Promise<SearchResponse<{}>>} A list of similar search results.
1452
- */
1453
1463
  async findSimilar(url, options) {
1464
+ if (options === void 0 || !("contents" in options)) {
1465
+ return await this.request("/findSimilar", "POST", {
1466
+ url,
1467
+ ...options,
1468
+ contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
1469
+ });
1470
+ }
1471
+ if (options.contents === false || options.contents === null || options.contents === void 0) {
1472
+ const { contents, ...restOptions } = options;
1473
+ return await this.request("/findSimilar", "POST", {
1474
+ url,
1475
+ ...restOptions
1476
+ });
1477
+ }
1454
1478
  return await this.request("/findSimilar", "POST", { url, ...options });
1455
1479
  }
1456
1480
  /**
1481
+ * @deprecated Use `findSimilar()` instead. The findSimilar method now returns text contents by default.
1482
+ *
1483
+ * Migration examples:
1484
+ * - `findSimilarAndContents(url)` → `findSimilar(url)`
1485
+ * - `findSimilarAndContents(url, { text: true })` → `findSimilar(url, { contents: { text: true } })`
1486
+ * - `findSimilarAndContents(url, { summary: true })` → `findSimilar(url, { contents: { summary: true } })`
1487
+ *
1457
1488
  * Finds similar links to the provided URL and returns the contents of the documents.
1458
1489
  * @param {string} url - The URL for which to find similar links.
1459
1490
  * @param {FindSimilarOptions & T} [options] - Additional options for finding similar links + contents.
1460
1491
  * @returns {Promise<SearchResponse<T>>} A list of similar search results, including requested contents.
1461
1492
  */
1462
1493
  async findSimilarAndContents(url, options) {
1463
- const { contentsOptions, restOptions } = options === void 0 ? { contentsOptions: { text: true }, restOptions: {} } : this.extractContentsOptions(options);
1494
+ const { contentsOptions, restOptions } = options === void 0 ? {
1495
+ contentsOptions: {
1496
+ text: { maxCharacters: DEFAULT_MAX_CHARACTERS }
1497
+ },
1498
+ restOptions: {}
1499
+ } : this.extractContentsOptions(options);
1464
1500
  return await this.request("/findSimilar", "POST", {
1465
1501
  url,
1466
1502
  contents: contentsOptions,