exa-js 2.19.0 → 2.21.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.19.0",
7
+ version: "2.21.0",
8
8
  description: "Exa SDK for Node.js and the browser",
9
9
  publishConfig: {
10
10
  access: "public"
@@ -2321,7 +2321,8 @@ var WebsetsClient = class extends WebsetsBaseClient {
2321
2321
  // src/tools/core.ts
2322
2322
  import { z } from "zod";
2323
2323
  var DEFAULT_WEB_SEARCH_TOOL_DESCRIPTION = "Search the web for up-to-date, relevant information. Describe the ideal page rather than listing keywords.";
2324
- function formatSearchResponse(response) {
2324
+ var DEFAULT_GET_CONTENTS_TOOL_DESCRIPTION = "Read the full contents of web pages you already have URLs for, such as pages returned by a search or mentioned by the user.";
2325
+ function formatResults(response, emptyMessage) {
2325
2326
  const formatted = response.results.map((result) => {
2326
2327
  const lines = [
2327
2328
  `Title: ${result.title || "N/A"}`,
@@ -2329,6 +2330,9 @@ function formatSearchResponse(response) {
2329
2330
  `Published: ${result.publishedDate || "N/A"}`,
2330
2331
  `Author: ${result.author || "N/A"}`
2331
2332
  ];
2333
+ if (result.summary) {
2334
+ lines.push(`Summary: ${result.summary}`);
2335
+ }
2332
2336
  if (result.highlights && result.highlights.length > 0) {
2333
2337
  lines.push(`Highlights:
2334
2338
  ${result.highlights.join("\n")}`);
@@ -2337,7 +2341,13 @@ ${result.highlights.join("\n")}`);
2337
2341
  }
2338
2342
  return lines.join("\n");
2339
2343
  }).join("\n\n---\n\n");
2340
- return formatted || "No search results found.";
2344
+ return formatted || emptyMessage;
2345
+ }
2346
+ function formatSearchResponse(response) {
2347
+ return formatResults(response, "No search results found.");
2348
+ }
2349
+ function formatContentsResponse(response) {
2350
+ return formatResults(response, "No contents found.");
2341
2351
  }
2342
2352
  function registerTool(registry, tool) {
2343
2353
  registry.register(tool);
@@ -2400,6 +2410,33 @@ function createWebSearchTool(exa, registry, config = {}) {
2400
2410
  format: formatSearchResponse
2401
2411
  });
2402
2412
  }
2413
+ function createGetContentsTool(exa, registry, config = {}) {
2414
+ const {
2415
+ name = "get_contents",
2416
+ description = DEFAULT_GET_CONTENTS_TOOL_DESCRIPTION,
2417
+ ...contentsOptions
2418
+ } = config;
2419
+ const inputSchema = z.object({
2420
+ urls: z.array(z.string()).describe(
2421
+ "Absolute URLs of the pages to read, including the scheme. Pass several URLs to read them in a single call."
2422
+ )
2423
+ });
2424
+ const jsonSchema = zodToJsonSchema(inputSchema);
2425
+ delete jsonSchema.$schema;
2426
+ return createTool(registry, {
2427
+ name,
2428
+ description,
2429
+ inputSchema,
2430
+ jsonSchema,
2431
+ definition: {
2432
+ name,
2433
+ description,
2434
+ parameters: jsonSchema
2435
+ },
2436
+ execute: ({ urls }) => exa.getContents(urls, contentsOptions),
2437
+ format: formatContentsResponse
2438
+ });
2439
+ }
2403
2440
  var ToolRegistry = class {
2404
2441
  constructor() {
2405
2442
  this.registry = /* @__PURE__ */ new Map();
@@ -2428,6 +2465,10 @@ var AnthropicTools = class {
2428
2465
  webSearch(config) {
2429
2466
  return runnable(createWebSearchTool(this.exa, this.registry, config));
2430
2467
  }
2468
+ /** Anthropic `get_contents` tool for reading pages by URL. */
2469
+ getContents(config) {
2470
+ return runnable(createGetContentsTool(this.exa, this.registry, config));
2471
+ }
2431
2472
  /**
2432
2473
  * Run the `tool_use` blocks in an assistant message and return the matching
2433
2474
  * `tool_result` blocks. Every `tool_use` block is answered so the follow-up
@@ -2556,6 +2597,12 @@ var OpenAIResponsesTools = class {
2556
2597
  createWebSearchTool(this.exa, this.registry, config)
2557
2598
  );
2558
2599
  }
2600
+ /** Responses API `get_contents` tool for reading pages by URL. */
2601
+ getContents(config) {
2602
+ return responsesRunnable(
2603
+ createGetContentsTool(this.exa, this.registry, config)
2604
+ );
2605
+ }
2559
2606
  /**
2560
2607
  * Run the function calls in a Responses API response (or output item array)
2561
2608
  * and return `function_call_output` items. Every function call is answered
@@ -2610,6 +2657,10 @@ var OpenAITools = class {
2610
2657
  webSearch(config) {
2611
2658
  return runnable2(createWebSearchTool(this.exa, this.registry, config));
2612
2659
  }
2660
+ /** Chat Completions `get_contents` tool for reading pages by URL. */
2661
+ getContents(config) {
2662
+ return runnable2(createGetContentsTool(this.exa, this.registry, config));
2663
+ }
2613
2664
  async handleToolCalls(assistantMessage, options) {
2614
2665
  if (isResponsesInput(assistantMessage)) {
2615
2666
  return this.handleResponsesToolCalls(assistantMessage, options);
@@ -2672,6 +2723,7 @@ function isResponsesInput(value) {
2672
2723
  var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : fetch2;
2673
2724
  var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : Headers;
2674
2725
  var DEFAULT_MAX_CHARACTERS = 1e4;
2726
+ var DYNAMIC_HIGHLIGHTS_BETA = "dynamic-highlights-2026-08-28";
2675
2727
  var NON_JSON_BODY_SNIPPET_LENGTH = 500;
2676
2728
  async function readResponseBody(response) {
2677
2729
  const text = await response.text();
@@ -2717,7 +2769,8 @@ var Exa2 = class {
2717
2769
  this.agent = new AgentClient(this);
2718
2770
  this.beta = new BetaClient(this.agent);
2719
2771
  this.tools = {
2720
- webSearch: (options) => createWebSearchTool(this, this.toolRegistry, options)
2772
+ webSearch: (options) => createWebSearchTool(this, this.toolRegistry, options),
2773
+ getContents: (options) => createGetContentsTool(this, this.toolRegistry, options)
2721
2774
  };
2722
2775
  this.openai = new OpenAITools(this, this.toolRegistry);
2723
2776
  this.anthropic = new AnthropicTools(this, this.toolRegistry);
@@ -2773,6 +2826,7 @@ var Exa2 = class {
2773
2826
  buildSearchRequestBody(query, options) {
2774
2827
  const requestOptions = { ...options ?? {} };
2775
2828
  delete requestOptions.stream;
2829
+ delete requestOptions.betas;
2776
2830
  if (options === void 0 || !("contents" in options)) {
2777
2831
  return {
2778
2832
  query,
@@ -2926,11 +2980,9 @@ var Exa2 = class {
2926
2980
  400 /* BadRequest */
2927
2981
  );
2928
2982
  }
2929
- return await this.request(
2930
- "/search",
2931
- "POST",
2932
- this.buildSearchRequestBody(query, options)
2933
- );
2983
+ const body = this.buildSearchRequestBody(query, options);
2984
+ const betaHeaders = headersForBetas(options?.betas);
2985
+ return betaHeaders ? await this.request("/search", "POST", body, void 0, betaHeaders) : await this.request("/search", "POST", body);
2934
2986
  }
2935
2987
  /**
2936
2988
  * Stream a search response as an async generator of OpenAI-style chat completion chunks.
@@ -3037,11 +3089,13 @@ var Exa2 = class {
3037
3089
  } else {
3038
3090
  requestUrls = urls.map((result) => result.url);
3039
3091
  }
3092
+ const { betas, ...contentsOptions } = options ?? {};
3040
3093
  const payload = {
3041
3094
  urls: requestUrls,
3042
- ...options
3095
+ ...contentsOptions
3043
3096
  };
3044
- return await this.request("/contents", "POST", payload);
3097
+ const betaHeaders = headersForBetas(betas);
3098
+ return betaHeaders ? await this.request("/contents", "POST", payload, void 0, betaHeaders) : await this.request("/contents", "POST", payload);
3045
3099
  }
3046
3100
  async answer(query, options) {
3047
3101
  if (options?.stream) {
@@ -3249,7 +3303,9 @@ export {
3249
3303
  BetaClient,
3250
3304
  CreateEnrichmentParametersFormat,
3251
3305
  CreateImportParametersFormat,
3306
+ DEFAULT_GET_CONTENTS_TOOL_DESCRIPTION,
3252
3307
  DEFAULT_WEB_SEARCH_TOOL_DESCRIPTION,
3308
+ DYNAMIC_HIGHLIGHTS_BETA,
3253
3309
  EventType,
3254
3310
  EventsClient,
3255
3311
  Exa2 as Exa,
@@ -3289,6 +3345,7 @@ export {
3289
3345
  WebsetStatus,
3290
3346
  WebsetWebhooksClient,
3291
3347
  WebsetsClient,
3348
+ createGetContentsTool,
3292
3349
  createWebSearchTool,
3293
3350
  index_default as default
3294
3351
  };