exa-js 2.19.0 → 2.22.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/README.md +14 -1
- package/dist/index.d.mts +50 -6
- package/dist/index.d.ts +50 -6
- package/dist/index.js +74 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +71 -11
- 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.
|
|
7
|
+
version: "2.22.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
|
-
|
|
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 ||
|
|
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);
|
|
@@ -2736,6 +2789,7 @@ var Exa2 = class {
|
|
|
2736
2789
|
livecrawl,
|
|
2737
2790
|
livecrawlTimeout,
|
|
2738
2791
|
maxAgeHours,
|
|
2792
|
+
snapshotAsOf,
|
|
2739
2793
|
// DEPRECATED FIELD: preserve legacy `context` only for backward compatibility.
|
|
2740
2794
|
context,
|
|
2741
2795
|
...rest
|
|
@@ -2764,6 +2818,8 @@ var Exa2 = class {
|
|
|
2764
2818
|
if (livecrawlTimeout !== void 0)
|
|
2765
2819
|
contentsOptions.livecrawlTimeout = livecrawlTimeout;
|
|
2766
2820
|
if (maxAgeHours !== void 0) contentsOptions.maxAgeHours = maxAgeHours;
|
|
2821
|
+
if (snapshotAsOf !== void 0)
|
|
2822
|
+
contentsOptions.snapshotAsOf = snapshotAsOf;
|
|
2767
2823
|
if (context !== void 0) contentsOptions.context = context;
|
|
2768
2824
|
return {
|
|
2769
2825
|
contentsOptions,
|
|
@@ -2773,6 +2829,7 @@ var Exa2 = class {
|
|
|
2773
2829
|
buildSearchRequestBody(query, options) {
|
|
2774
2830
|
const requestOptions = { ...options ?? {} };
|
|
2775
2831
|
delete requestOptions.stream;
|
|
2832
|
+
delete requestOptions.betas;
|
|
2776
2833
|
if (options === void 0 || !("contents" in options)) {
|
|
2777
2834
|
return {
|
|
2778
2835
|
query,
|
|
@@ -2926,11 +2983,9 @@ var Exa2 = class {
|
|
|
2926
2983
|
400 /* BadRequest */
|
|
2927
2984
|
);
|
|
2928
2985
|
}
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
this.buildSearchRequestBody(query, options)
|
|
2933
|
-
);
|
|
2986
|
+
const body = this.buildSearchRequestBody(query, options);
|
|
2987
|
+
const betaHeaders = headersForBetas(options?.betas);
|
|
2988
|
+
return betaHeaders ? await this.request("/search", "POST", body, void 0, betaHeaders) : await this.request("/search", "POST", body);
|
|
2934
2989
|
}
|
|
2935
2990
|
/**
|
|
2936
2991
|
* Stream a search response as an async generator of OpenAI-style chat completion chunks.
|
|
@@ -3037,11 +3092,13 @@ var Exa2 = class {
|
|
|
3037
3092
|
} else {
|
|
3038
3093
|
requestUrls = urls.map((result) => result.url);
|
|
3039
3094
|
}
|
|
3095
|
+
const { betas, ...contentsOptions } = options ?? {};
|
|
3040
3096
|
const payload = {
|
|
3041
3097
|
urls: requestUrls,
|
|
3042
|
-
...
|
|
3098
|
+
...contentsOptions
|
|
3043
3099
|
};
|
|
3044
|
-
|
|
3100
|
+
const betaHeaders = headersForBetas(betas);
|
|
3101
|
+
return betaHeaders ? await this.request("/contents", "POST", payload, void 0, betaHeaders) : await this.request("/contents", "POST", payload);
|
|
3045
3102
|
}
|
|
3046
3103
|
async answer(query, options) {
|
|
3047
3104
|
if (options?.stream) {
|
|
@@ -3249,7 +3306,9 @@ export {
|
|
|
3249
3306
|
BetaClient,
|
|
3250
3307
|
CreateEnrichmentParametersFormat,
|
|
3251
3308
|
CreateImportParametersFormat,
|
|
3309
|
+
DEFAULT_GET_CONTENTS_TOOL_DESCRIPTION,
|
|
3252
3310
|
DEFAULT_WEB_SEARCH_TOOL_DESCRIPTION,
|
|
3311
|
+
DYNAMIC_HIGHLIGHTS_BETA,
|
|
3253
3312
|
EventType,
|
|
3254
3313
|
EventsClient,
|
|
3255
3314
|
Exa2 as Exa,
|
|
@@ -3289,6 +3348,7 @@ export {
|
|
|
3289
3348
|
WebsetStatus,
|
|
3290
3349
|
WebsetWebhooksClient,
|
|
3291
3350
|
WebsetsClient,
|
|
3351
|
+
createGetContentsTool,
|
|
3292
3352
|
createWebSearchTool,
|
|
3293
3353
|
index_default as default
|
|
3294
3354
|
};
|