exa-js 2.18.1 → 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/README.md +64 -0
- package/dist/index.d.mts +246 -8
- package/dist/index.d.ts +246 -8
- package/dist/index.js +481 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +471 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -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.21.0",
|
|
8
8
|
description: "Exa SDK for Node.js and the browser",
|
|
9
9
|
publishConfig: {
|
|
10
10
|
access: "public"
|
|
@@ -45,6 +45,7 @@ var package_default = {
|
|
|
45
45
|
},
|
|
46
46
|
license: "MIT",
|
|
47
47
|
devDependencies: {
|
|
48
|
+
"@anthropic-ai/sdk": "^0.115.0",
|
|
48
49
|
"@types/node": "~22.14.0",
|
|
49
50
|
"cross-env": "~7.0.3",
|
|
50
51
|
"openapi-typescript": "~7.6.1",
|
|
@@ -476,6 +477,10 @@ var AgentMonitorsClient = class extends AgentMonitorsBaseClient {
|
|
|
476
477
|
}
|
|
477
478
|
};
|
|
478
479
|
|
|
480
|
+
// src/agent/types.ts
|
|
481
|
+
var AGENT_BETA_HEADER = "agent-2026-05-07";
|
|
482
|
+
var AGENT_MAX_EFFORT_BETA = "agent-max-effort-2026-07-27";
|
|
483
|
+
|
|
479
484
|
// src/agent/client.ts
|
|
480
485
|
var DEFAULT_AGENT_POLL_INTERVAL_MS = 1e3;
|
|
481
486
|
var DEFAULT_AGENT_POLL_TIMEOUT_MS = 60 * 60 * 1e3;
|
|
@@ -817,6 +822,19 @@ var AgentBetaRunsClient = class extends AgentRunsClient {
|
|
|
817
822
|
headersForBetas(options?.betas)
|
|
818
823
|
);
|
|
819
824
|
}
|
|
825
|
+
/**
|
|
826
|
+
* Stop a running Agent run, completing it early with the results
|
|
827
|
+
* gathered so far. Only supported for `max` effort runs.
|
|
828
|
+
*/
|
|
829
|
+
async stop(runId, options) {
|
|
830
|
+
return this.request(
|
|
831
|
+
`/${runId}/stop`,
|
|
832
|
+
"POST",
|
|
833
|
+
void 0,
|
|
834
|
+
void 0,
|
|
835
|
+
headersForBetas(options?.betas ?? [AGENT_MAX_EFFORT_BETA])
|
|
836
|
+
);
|
|
837
|
+
}
|
|
820
838
|
async delete(runId, options) {
|
|
821
839
|
return this.request(
|
|
822
840
|
`/${runId}`,
|
|
@@ -2300,14 +2318,412 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
2300
2318
|
}
|
|
2301
2319
|
};
|
|
2302
2320
|
|
|
2303
|
-
// src/
|
|
2304
|
-
|
|
2305
|
-
var
|
|
2321
|
+
// src/tools/core.ts
|
|
2322
|
+
import { z } from "zod";
|
|
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
|
+
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) {
|
|
2326
|
+
const formatted = response.results.map((result) => {
|
|
2327
|
+
const lines = [
|
|
2328
|
+
`Title: ${result.title || "N/A"}`,
|
|
2329
|
+
`URL: ${result.url || "N/A"}`,
|
|
2330
|
+
`Published: ${result.publishedDate || "N/A"}`,
|
|
2331
|
+
`Author: ${result.author || "N/A"}`
|
|
2332
|
+
];
|
|
2333
|
+
if (result.summary) {
|
|
2334
|
+
lines.push(`Summary: ${result.summary}`);
|
|
2335
|
+
}
|
|
2336
|
+
if (result.highlights && result.highlights.length > 0) {
|
|
2337
|
+
lines.push(`Highlights:
|
|
2338
|
+
${result.highlights.join("\n")}`);
|
|
2339
|
+
} else if (result.text) {
|
|
2340
|
+
lines.push(`Text: ${result.text}`);
|
|
2341
|
+
}
|
|
2342
|
+
return lines.join("\n");
|
|
2343
|
+
}).join("\n\n---\n\n");
|
|
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.");
|
|
2351
|
+
}
|
|
2352
|
+
function registerTool(registry, tool) {
|
|
2353
|
+
registry.register(tool);
|
|
2354
|
+
return tool;
|
|
2355
|
+
}
|
|
2356
|
+
function createTool(registry, params) {
|
|
2357
|
+
const tool = {
|
|
2358
|
+
name: params.name,
|
|
2359
|
+
description: params.description,
|
|
2360
|
+
inputSchema: params.inputSchema,
|
|
2361
|
+
jsonSchema: params.jsonSchema,
|
|
2362
|
+
execute: params.execute,
|
|
2363
|
+
format: params.format,
|
|
2364
|
+
definition: params.definition,
|
|
2365
|
+
async run(args) {
|
|
2366
|
+
try {
|
|
2367
|
+
const parsed = params.inputSchema.parse(args);
|
|
2368
|
+
const result = await params.execute(parsed);
|
|
2369
|
+
return params.format(result);
|
|
2370
|
+
} catch (error) {
|
|
2371
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2372
|
+
return `Error: ${message}`;
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
};
|
|
2376
|
+
return registerTool(registry, tool);
|
|
2377
|
+
}
|
|
2378
|
+
function createWebSearchTool(exa, registry, config = {}) {
|
|
2379
|
+
const {
|
|
2380
|
+
name = "web_search",
|
|
2381
|
+
description = DEFAULT_WEB_SEARCH_TOOL_DESCRIPTION,
|
|
2382
|
+
...searchOptions
|
|
2383
|
+
} = config;
|
|
2384
|
+
const inputSchema = z.object({
|
|
2385
|
+
query: z.string().describe(
|
|
2386
|
+
"Natural language search query. Should be a semantically rich description of the ideal page, not just keywords."
|
|
2387
|
+
)
|
|
2388
|
+
});
|
|
2389
|
+
const jsonSchema = zodToJsonSchema(inputSchema);
|
|
2390
|
+
delete jsonSchema.$schema;
|
|
2391
|
+
return createTool(registry, {
|
|
2392
|
+
name,
|
|
2393
|
+
description,
|
|
2394
|
+
inputSchema,
|
|
2395
|
+
jsonSchema,
|
|
2396
|
+
definition: {
|
|
2397
|
+
name,
|
|
2398
|
+
description,
|
|
2399
|
+
parameters: jsonSchema
|
|
2400
|
+
},
|
|
2401
|
+
execute: ({ query }) => {
|
|
2402
|
+
const options = {
|
|
2403
|
+
type: "auto",
|
|
2404
|
+
numResults: 10,
|
|
2405
|
+
contents: { highlights: true },
|
|
2406
|
+
...searchOptions
|
|
2407
|
+
};
|
|
2408
|
+
return exa.search(query, options);
|
|
2409
|
+
},
|
|
2410
|
+
format: formatSearchResponse
|
|
2411
|
+
});
|
|
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
|
+
}
|
|
2440
|
+
var ToolRegistry = class {
|
|
2441
|
+
constructor() {
|
|
2442
|
+
this.registry = /* @__PURE__ */ new Map();
|
|
2443
|
+
}
|
|
2444
|
+
register(tool) {
|
|
2445
|
+
this.registry.set(tool.name, tool);
|
|
2446
|
+
}
|
|
2447
|
+
resolve(tools) {
|
|
2448
|
+
return tools ? new Map(tools.map((tool) => [tool.name, tool])) : new Map(this.registry);
|
|
2449
|
+
}
|
|
2450
|
+
};
|
|
2451
|
+
function getTool(tools, name) {
|
|
2452
|
+
return tools.get(name);
|
|
2453
|
+
}
|
|
2454
|
+
function unknownToolError(name) {
|
|
2455
|
+
return `Error: unknown tool "${name}"`;
|
|
2456
|
+
}
|
|
2457
|
+
|
|
2458
|
+
// src/tools/anthropic.ts
|
|
2459
|
+
var AnthropicTools = class {
|
|
2460
|
+
constructor(exa, registry) {
|
|
2461
|
+
this.exa = exa;
|
|
2462
|
+
this.registry = registry;
|
|
2463
|
+
}
|
|
2464
|
+
/** Anthropic `web_search` tool. Defaults to `auto` + highlights. */
|
|
2465
|
+
webSearch(config) {
|
|
2466
|
+
return runnable(createWebSearchTool(this.exa, this.registry, config));
|
|
2467
|
+
}
|
|
2468
|
+
/** Anthropic `get_contents` tool for reading pages by URL. */
|
|
2469
|
+
getContents(config) {
|
|
2470
|
+
return runnable(createGetContentsTool(this.exa, this.registry, config));
|
|
2471
|
+
}
|
|
2472
|
+
/**
|
|
2473
|
+
* Run the `tool_use` blocks in an assistant message and return the matching
|
|
2474
|
+
* `tool_result` blocks. Every `tool_use` block is answered so the follow-up
|
|
2475
|
+
* request never omits a required result: a block whose name doesn't match a
|
|
2476
|
+
* known tool gets an `Error: unknown tool "<name>"` result. When handling
|
|
2477
|
+
* some tools yourself, replace those error results with your own before
|
|
2478
|
+
* sending the next request.
|
|
2479
|
+
*/
|
|
2480
|
+
async handleToolUse(message, options) {
|
|
2481
|
+
const tools = this.registry.resolve(options?.tools);
|
|
2482
|
+
const blocks = (message.content ?? []).filter(isAnthropicToolUse);
|
|
2483
|
+
return Promise.all(
|
|
2484
|
+
blocks.map(async (block) => {
|
|
2485
|
+
const tool = getTool(tools, block.name);
|
|
2486
|
+
return {
|
|
2487
|
+
type: "tool_result",
|
|
2488
|
+
tool_use_id: block.id,
|
|
2489
|
+
content: tool ? await tool.run(block.input) : unknownToolError(block.name)
|
|
2490
|
+
};
|
|
2491
|
+
})
|
|
2492
|
+
);
|
|
2493
|
+
}
|
|
2494
|
+
};
|
|
2495
|
+
function isAnthropicToolUse(value) {
|
|
2496
|
+
if (!value || typeof value !== "object") return false;
|
|
2497
|
+
const block = value;
|
|
2498
|
+
return block.type === "tool_use" && typeof block.id === "string" && typeof block.name === "string";
|
|
2499
|
+
}
|
|
2500
|
+
function runnable(tool) {
|
|
2501
|
+
const definition = {
|
|
2502
|
+
type: "custom",
|
|
2503
|
+
name: tool.name,
|
|
2504
|
+
description: tool.description,
|
|
2505
|
+
input_schema: tool.jsonSchema,
|
|
2506
|
+
parse: (input) => tool.inputSchema.parse(input),
|
|
2507
|
+
run: (args) => tool.run(args)
|
|
2508
|
+
};
|
|
2509
|
+
Object.defineProperties(definition, {
|
|
2510
|
+
parse: { enumerable: false },
|
|
2511
|
+
run: { enumerable: false }
|
|
2512
|
+
});
|
|
2513
|
+
Object.defineProperties(
|
|
2514
|
+
definition,
|
|
2515
|
+
Object.fromEntries(
|
|
2516
|
+
Object.entries(tool).filter(([key]) => !["name", "description"].includes(key)).map(([key, value]) => [
|
|
2517
|
+
key,
|
|
2518
|
+
{ value, enumerable: false, configurable: true }
|
|
2519
|
+
])
|
|
2520
|
+
)
|
|
2521
|
+
);
|
|
2522
|
+
Object.defineProperty(definition, "type", {
|
|
2523
|
+
value: "custom",
|
|
2524
|
+
enumerable: false,
|
|
2525
|
+
configurable: true
|
|
2526
|
+
});
|
|
2527
|
+
Object.defineProperty(definition, "definition", {
|
|
2528
|
+
value: {
|
|
2529
|
+
name: tool.name,
|
|
2530
|
+
description: tool.description,
|
|
2531
|
+
input_schema: tool.jsonSchema
|
|
2532
|
+
},
|
|
2533
|
+
enumerable: false
|
|
2534
|
+
});
|
|
2535
|
+
return definition;
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
// src/tools/openai.ts
|
|
2539
|
+
function runnable2(tool) {
|
|
2540
|
+
const functionDefinition = {
|
|
2541
|
+
...tool.definition,
|
|
2542
|
+
parse: (input) => JSON.parse(input),
|
|
2543
|
+
function: (args) => tool.run(args)
|
|
2544
|
+
};
|
|
2545
|
+
Object.defineProperties(functionDefinition, {
|
|
2546
|
+
parse: { enumerable: false },
|
|
2547
|
+
function: { enumerable: false }
|
|
2548
|
+
});
|
|
2549
|
+
const definition = {
|
|
2550
|
+
type: "function",
|
|
2551
|
+
function: functionDefinition
|
|
2552
|
+
};
|
|
2553
|
+
Object.defineProperties(
|
|
2554
|
+
definition,
|
|
2555
|
+
Object.fromEntries(
|
|
2556
|
+
Object.entries(tool).filter(([key]) => !["name", "description"].includes(key)).map(([key, value]) => [
|
|
2557
|
+
key,
|
|
2558
|
+
{ value, enumerable: false, configurable: true }
|
|
2559
|
+
])
|
|
2560
|
+
)
|
|
2561
|
+
);
|
|
2562
|
+
Object.defineProperties(definition, {
|
|
2563
|
+
name: {
|
|
2564
|
+
value: tool.name,
|
|
2565
|
+
enumerable: false,
|
|
2566
|
+
configurable: true
|
|
2567
|
+
},
|
|
2568
|
+
description: {
|
|
2569
|
+
value: tool.description,
|
|
2570
|
+
enumerable: false,
|
|
2571
|
+
configurable: true
|
|
2572
|
+
}
|
|
2573
|
+
});
|
|
2574
|
+
Object.defineProperty(definition, "definition", {
|
|
2575
|
+
value: {
|
|
2576
|
+
type: "function",
|
|
2577
|
+
function: {
|
|
2578
|
+
name: tool.name,
|
|
2579
|
+
description: tool.description,
|
|
2580
|
+
parameters: tool.jsonSchema
|
|
2581
|
+
}
|
|
2582
|
+
},
|
|
2583
|
+
enumerable: false,
|
|
2584
|
+
configurable: true
|
|
2585
|
+
});
|
|
2586
|
+
return definition;
|
|
2587
|
+
}
|
|
2588
|
+
var OpenAIResponsesTools = class {
|
|
2589
|
+
constructor(exa, registry, handleResponses) {
|
|
2590
|
+
this.exa = exa;
|
|
2591
|
+
this.registry = registry;
|
|
2592
|
+
this.handleResponses = handleResponses;
|
|
2593
|
+
}
|
|
2594
|
+
/** Responses API `web_search` tool. Defaults to `auto` + highlights. */
|
|
2595
|
+
webSearch(config) {
|
|
2596
|
+
return responsesRunnable(
|
|
2597
|
+
createWebSearchTool(this.exa, this.registry, config)
|
|
2598
|
+
);
|
|
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
|
+
}
|
|
2606
|
+
/**
|
|
2607
|
+
* Run the function calls in a Responses API response (or output item array)
|
|
2608
|
+
* and return `function_call_output` items. Every function call is answered
|
|
2609
|
+
* so the follow-up request never omits a required output: a call whose name
|
|
2610
|
+
* doesn't match a known tool gets an `Error: unknown tool "<name>"` output.
|
|
2611
|
+
* When handling some tools yourself, replace those error outputs with your
|
|
2612
|
+
* own results before sending the next request.
|
|
2613
|
+
*/
|
|
2614
|
+
async handleToolCalls(responseOrOutputItems, options) {
|
|
2615
|
+
return this.handleResponses(responseOrOutputItems, options);
|
|
2616
|
+
}
|
|
2617
|
+
};
|
|
2618
|
+
function responsesRunnable(tool) {
|
|
2619
|
+
const definition = {
|
|
2620
|
+
type: "function",
|
|
2621
|
+
name: tool.name,
|
|
2622
|
+
description: tool.description,
|
|
2623
|
+
parameters: tool.jsonSchema,
|
|
2624
|
+
strict: false
|
|
2625
|
+
};
|
|
2626
|
+
Object.defineProperties(
|
|
2627
|
+
definition,
|
|
2628
|
+
Object.fromEntries(
|
|
2629
|
+
Object.entries(tool).filter(([key]) => !["name", "description"].includes(key)).map(([key, value]) => [
|
|
2630
|
+
key,
|
|
2631
|
+
{ value, enumerable: false, configurable: true }
|
|
2632
|
+
])
|
|
2633
|
+
)
|
|
2634
|
+
);
|
|
2635
|
+
Object.defineProperty(definition, "definition", {
|
|
2636
|
+
value: {
|
|
2637
|
+
...tool.definition,
|
|
2638
|
+
type: "function",
|
|
2639
|
+
parameters: tool.jsonSchema,
|
|
2640
|
+
strict: false
|
|
2641
|
+
},
|
|
2642
|
+
enumerable: false
|
|
2643
|
+
});
|
|
2644
|
+
return definition;
|
|
2645
|
+
}
|
|
2646
|
+
var OpenAITools = class {
|
|
2647
|
+
constructor(exa, registry) {
|
|
2648
|
+
this.exa = exa;
|
|
2649
|
+
this.registry = registry;
|
|
2650
|
+
this.responses = new OpenAIResponsesTools(
|
|
2651
|
+
exa,
|
|
2652
|
+
registry,
|
|
2653
|
+
(responseOrOutputItems, options) => this.handleResponsesToolCalls(responseOrOutputItems, options)
|
|
2654
|
+
);
|
|
2655
|
+
}
|
|
2656
|
+
/** Chat Completions `web_search` tool. Defaults to `auto` + highlights. */
|
|
2657
|
+
webSearch(config) {
|
|
2658
|
+
return runnable2(createWebSearchTool(this.exa, this.registry, config));
|
|
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
|
+
}
|
|
2664
|
+
async handleToolCalls(assistantMessage, options) {
|
|
2665
|
+
if (isResponsesInput(assistantMessage)) {
|
|
2666
|
+
return this.handleResponsesToolCalls(assistantMessage, options);
|
|
2667
|
+
}
|
|
2668
|
+
return this.handleChatToolCalls(assistantMessage, options);
|
|
2669
|
+
}
|
|
2670
|
+
async handleChatToolCalls(assistantMessage, options) {
|
|
2671
|
+
const tools = this.registry.resolve(options?.tools);
|
|
2672
|
+
const calls = (assistantMessage.tool_calls ?? []).filter(isOpenAIToolCall);
|
|
2673
|
+
return Promise.all(
|
|
2674
|
+
calls.map(async (call) => {
|
|
2675
|
+
const tool = getTool(tools, call.function.name);
|
|
2676
|
+
return {
|
|
2677
|
+
role: "tool",
|
|
2678
|
+
tool_call_id: call.id,
|
|
2679
|
+
content: tool ? await tool.run(parseArguments(call.function.arguments)) : unknownToolError(call.function.name)
|
|
2680
|
+
};
|
|
2681
|
+
})
|
|
2682
|
+
);
|
|
2683
|
+
}
|
|
2684
|
+
async handleResponsesToolCalls(responseOrOutputItems, options) {
|
|
2685
|
+
const tools = this.registry.resolve(options?.tools);
|
|
2686
|
+
const rawItems = !Array.isArray(responseOrOutputItems) && "output" in responseOrOutputItems ? responseOrOutputItems.output ?? [] : responseOrOutputItems;
|
|
2687
|
+
const items = rawItems.filter(isResponsesFunctionCall);
|
|
2688
|
+
return Promise.all(
|
|
2689
|
+
items.map(async (call) => {
|
|
2690
|
+
const tool = getTool(tools, call.name);
|
|
2691
|
+
return {
|
|
2692
|
+
type: "function_call_output",
|
|
2693
|
+
call_id: call.call_id,
|
|
2694
|
+
output: tool ? await tool.run(parseArguments(call.arguments)) : unknownToolError(call.name)
|
|
2695
|
+
};
|
|
2696
|
+
})
|
|
2697
|
+
);
|
|
2698
|
+
}
|
|
2699
|
+
};
|
|
2700
|
+
function parseArguments(argumentsText) {
|
|
2701
|
+
try {
|
|
2702
|
+
return JSON.parse(argumentsText);
|
|
2703
|
+
} catch {
|
|
2704
|
+
return argumentsText;
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
function isOpenAIToolCall(value) {
|
|
2708
|
+
if (!value || typeof value !== "object") return false;
|
|
2709
|
+
const call = value;
|
|
2710
|
+
return typeof call.id === "string" && !!call.function && typeof call.function.name === "string" && typeof call.function.arguments === "string";
|
|
2711
|
+
}
|
|
2712
|
+
function isResponsesFunctionCall(value) {
|
|
2713
|
+
if (!value || typeof value !== "object") return false;
|
|
2714
|
+
const call = value;
|
|
2715
|
+
return call.type === "function_call" && typeof call.call_id === "string" && typeof call.name === "string" && typeof call.arguments === "string";
|
|
2716
|
+
}
|
|
2717
|
+
function isResponsesInput(value) {
|
|
2718
|
+
if (Array.isArray(value)) return value.some(isResponsesFunctionCall);
|
|
2719
|
+
return "output" in value;
|
|
2720
|
+
}
|
|
2306
2721
|
|
|
2307
2722
|
// src/index.ts
|
|
2308
2723
|
var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : fetch2;
|
|
2309
2724
|
var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : Headers;
|
|
2310
2725
|
var DEFAULT_MAX_CHARACTERS = 1e4;
|
|
2726
|
+
var DYNAMIC_HIGHLIGHTS_BETA = "dynamic-highlights-2026-08-28";
|
|
2311
2727
|
var NON_JSON_BODY_SNIPPET_LENGTH = 500;
|
|
2312
2728
|
async function readResponseBody(response) {
|
|
2313
2729
|
const text = await response.text();
|
|
@@ -2325,6 +2741,40 @@ function truncateResponseBody(text) {
|
|
|
2325
2741
|
return collapsed.length > NON_JSON_BODY_SNIPPET_LENGTH ? `${collapsed.slice(0, NON_JSON_BODY_SNIPPET_LENGTH)}\u2026` : collapsed;
|
|
2326
2742
|
}
|
|
2327
2743
|
var Exa2 = class {
|
|
2744
|
+
/**
|
|
2745
|
+
* Constructs the Exa API client.
|
|
2746
|
+
* @param {string} apiKey - The API key for authentication.
|
|
2747
|
+
* @param {string} [baseURL] - The base URL of the Exa API.
|
|
2748
|
+
*/
|
|
2749
|
+
constructor(apiKey, baseURL = "https://api.exa.ai") {
|
|
2750
|
+
this.toolRegistry = new ToolRegistry();
|
|
2751
|
+
this.baseURL = baseURL;
|
|
2752
|
+
if (!apiKey) {
|
|
2753
|
+
apiKey = process.env.EXA_API_KEY;
|
|
2754
|
+
if (!apiKey) {
|
|
2755
|
+
throw new ExaError(
|
|
2756
|
+
"API key must be provided as an argument or as an environment variable (EXA_API_KEY)",
|
|
2757
|
+
401 /* Unauthorized */
|
|
2758
|
+
);
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
this.headers = new HeadersImpl({
|
|
2762
|
+
"x-api-key": apiKey,
|
|
2763
|
+
"Content-Type": "application/json",
|
|
2764
|
+
"User-Agent": `exa-node ${package_default.version}`
|
|
2765
|
+
});
|
|
2766
|
+
this.websets = new WebsetsClient(this);
|
|
2767
|
+
this.research = new ResearchClient(this);
|
|
2768
|
+
this.monitors = new SearchMonitorsClient(this);
|
|
2769
|
+
this.agent = new AgentClient(this);
|
|
2770
|
+
this.beta = new BetaClient(this.agent);
|
|
2771
|
+
this.tools = {
|
|
2772
|
+
webSearch: (options) => createWebSearchTool(this, this.toolRegistry, options),
|
|
2773
|
+
getContents: (options) => createGetContentsTool(this, this.toolRegistry, options)
|
|
2774
|
+
};
|
|
2775
|
+
this.openai = new OpenAITools(this, this.toolRegistry);
|
|
2776
|
+
this.anthropic = new AnthropicTools(this, this.toolRegistry);
|
|
2777
|
+
}
|
|
2328
2778
|
/**
|
|
2329
2779
|
* Helper method to separate out the contents-specific options from the rest.
|
|
2330
2780
|
*/
|
|
@@ -2376,6 +2826,7 @@ var Exa2 = class {
|
|
|
2376
2826
|
buildSearchRequestBody(query, options) {
|
|
2377
2827
|
const requestOptions = { ...options ?? {} };
|
|
2378
2828
|
delete requestOptions.stream;
|
|
2829
|
+
delete requestOptions.betas;
|
|
2379
2830
|
if (options === void 0 || !("contents" in options)) {
|
|
2380
2831
|
return {
|
|
2381
2832
|
query,
|
|
@@ -2389,33 +2840,6 @@ var Exa2 = class {
|
|
|
2389
2840
|
}
|
|
2390
2841
|
return { query, ...requestOptions };
|
|
2391
2842
|
}
|
|
2392
|
-
/**
|
|
2393
|
-
* Constructs the Exa API client.
|
|
2394
|
-
* @param {string} apiKey - The API key for authentication.
|
|
2395
|
-
* @param {string} [baseURL] - The base URL of the Exa API.
|
|
2396
|
-
*/
|
|
2397
|
-
constructor(apiKey, baseURL = "https://api.exa.ai") {
|
|
2398
|
-
this.baseURL = baseURL;
|
|
2399
|
-
if (!apiKey) {
|
|
2400
|
-
apiKey = process.env.EXA_API_KEY;
|
|
2401
|
-
if (!apiKey) {
|
|
2402
|
-
throw new ExaError(
|
|
2403
|
-
"API key must be provided as an argument or as an environment variable (EXA_API_KEY)",
|
|
2404
|
-
401 /* Unauthorized */
|
|
2405
|
-
);
|
|
2406
|
-
}
|
|
2407
|
-
}
|
|
2408
|
-
this.headers = new HeadersImpl({
|
|
2409
|
-
"x-api-key": apiKey,
|
|
2410
|
-
"Content-Type": "application/json",
|
|
2411
|
-
"User-Agent": `exa-node ${package_default.version}`
|
|
2412
|
-
});
|
|
2413
|
-
this.websets = new WebsetsClient(this);
|
|
2414
|
-
this.research = new ResearchClient(this);
|
|
2415
|
-
this.monitors = new SearchMonitorsClient(this);
|
|
2416
|
-
this.agent = new AgentClient(this);
|
|
2417
|
-
this.beta = new BetaClient(this.agent);
|
|
2418
|
-
}
|
|
2419
2843
|
/**
|
|
2420
2844
|
* Makes a request to the Exa API.
|
|
2421
2845
|
* @param {string} endpoint - The API endpoint to call.
|
|
@@ -2556,11 +2980,9 @@ var Exa2 = class {
|
|
|
2556
2980
|
400 /* BadRequest */
|
|
2557
2981
|
);
|
|
2558
2982
|
}
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
this.buildSearchRequestBody(query, options)
|
|
2563
|
-
);
|
|
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);
|
|
2564
2986
|
}
|
|
2565
2987
|
/**
|
|
2566
2988
|
* Stream a search response as an async generator of OpenAI-style chat completion chunks.
|
|
@@ -2667,11 +3089,13 @@ var Exa2 = class {
|
|
|
2667
3089
|
} else {
|
|
2668
3090
|
requestUrls = urls.map((result) => result.url);
|
|
2669
3091
|
}
|
|
3092
|
+
const { betas, ...contentsOptions } = options ?? {};
|
|
2670
3093
|
const payload = {
|
|
2671
3094
|
urls: requestUrls,
|
|
2672
|
-
...
|
|
3095
|
+
...contentsOptions
|
|
2673
3096
|
};
|
|
2674
|
-
|
|
3097
|
+
const betaHeaders = headersForBetas(betas);
|
|
3098
|
+
return betaHeaders ? await this.request("/contents", "POST", payload, void 0, betaHeaders) : await this.request("/contents", "POST", payload);
|
|
2675
3099
|
}
|
|
2676
3100
|
async answer(query, options) {
|
|
2677
3101
|
if (options?.stream) {
|
|
@@ -2875,9 +3299,13 @@ export {
|
|
|
2875
3299
|
AgentRunEventsClient,
|
|
2876
3300
|
AgentRunFailedError,
|
|
2877
3301
|
AgentRunsClient,
|
|
3302
|
+
AnthropicTools,
|
|
2878
3303
|
BetaClient,
|
|
2879
3304
|
CreateEnrichmentParametersFormat,
|
|
2880
3305
|
CreateImportParametersFormat,
|
|
3306
|
+
DEFAULT_GET_CONTENTS_TOOL_DESCRIPTION,
|
|
3307
|
+
DEFAULT_WEB_SEARCH_TOOL_DESCRIPTION,
|
|
3308
|
+
DYNAMIC_HIGHLIGHTS_BETA,
|
|
2881
3309
|
EventType,
|
|
2882
3310
|
EventsClient,
|
|
2883
3311
|
Exa2 as Exa,
|
|
@@ -2893,8 +3321,11 @@ export {
|
|
|
2893
3321
|
MonitorRunStatus,
|
|
2894
3322
|
MonitorRunType,
|
|
2895
3323
|
MonitorStatus,
|
|
3324
|
+
OpenAIResponsesTools,
|
|
3325
|
+
OpenAITools,
|
|
2896
3326
|
SearchMonitorRunsClient,
|
|
2897
3327
|
SearchMonitorsClient,
|
|
3328
|
+
ToolRegistry,
|
|
2898
3329
|
UpdateMonitorStatus,
|
|
2899
3330
|
WebhookStatus,
|
|
2900
3331
|
WebsetEnrichmentFormat,
|
|
@@ -2914,6 +3345,8 @@ export {
|
|
|
2914
3345
|
WebsetStatus,
|
|
2915
3346
|
WebsetWebhooksClient,
|
|
2916
3347
|
WebsetsClient,
|
|
3348
|
+
createGetContentsTool,
|
|
3349
|
+
createWebSearchTool,
|
|
2917
3350
|
index_default as default
|
|
2918
3351
|
};
|
|
2919
3352
|
//# sourceMappingURL=index.mjs.map
|