exa-js 2.27.0 → 2.29.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 +59 -4
- package/dist/index.d.mts +167 -48
- package/dist/index.d.ts +167 -48
- package/dist/index.js +312 -464
- package/dist/index.mjs +304 -456
- package/package.json +6 -11
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -103,7 +103,7 @@ var import_cross_fetch = __toESM(require("cross-fetch"));
|
|
|
103
103
|
// package.json
|
|
104
104
|
var package_default = {
|
|
105
105
|
name: "exa-js",
|
|
106
|
-
version: "2.
|
|
106
|
+
version: "2.29.0",
|
|
107
107
|
description: "Exa SDK for Node.js and the browser",
|
|
108
108
|
publishConfig: {
|
|
109
109
|
access: "public"
|
|
@@ -141,7 +141,6 @@ var package_default = {
|
|
|
141
141
|
"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",
|
|
142
142
|
format: 'prettier --write "src/**/*.ts"',
|
|
143
143
|
"format:websets": "prettier --write src/websets/openapi.ts",
|
|
144
|
-
"generate-docs": "npx tsx scripts/generate-docs.ts",
|
|
145
144
|
"build:beta": "cross-env NPM_CONFIG_TAG=beta npm run build",
|
|
146
145
|
"version:beta": "npm version prerelease --preid=beta",
|
|
147
146
|
"version:stable": "npm version patch",
|
|
@@ -152,23 +151,19 @@ var package_default = {
|
|
|
152
151
|
license: "MIT",
|
|
153
152
|
devDependencies: {
|
|
154
153
|
"@anthropic-ai/sdk": "^0.115.0",
|
|
155
|
-
"@types/node": "~22.14.
|
|
154
|
+
"@types/node": "~22.14.1",
|
|
156
155
|
"cross-env": "~7.0.3",
|
|
156
|
+
openai: "^6.49.0",
|
|
157
157
|
"openapi-typescript": "~7.6.1",
|
|
158
158
|
prettier: "~3.5.3",
|
|
159
|
-
"ts-morph": "^27.0.2",
|
|
160
|
-
"ts-node": "~10.9.2",
|
|
161
159
|
tsup: "~8.4.0",
|
|
162
|
-
tsx: "^4.21.0",
|
|
163
160
|
typescript: "~5.8.3",
|
|
164
|
-
vitest: "~
|
|
161
|
+
vitest: "~4.1.12"
|
|
165
162
|
},
|
|
166
163
|
dependencies: {
|
|
167
164
|
"cross-fetch": "~4.1.0",
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
zod: "^3.22.0",
|
|
171
|
-
"zod-to-json-schema": "^3.20.0"
|
|
165
|
+
zod: "^3.25.28 || ^4.6.6",
|
|
166
|
+
"zod-to-json-schema": "^3.25.2"
|
|
172
167
|
},
|
|
173
168
|
directories: {
|
|
174
169
|
test: "test"
|
|
@@ -227,6 +222,7 @@ var ExaError = class extends Error {
|
|
|
227
222
|
this.code = envelope.code;
|
|
228
223
|
this.detail = envelope.detail;
|
|
229
224
|
this.requestId = envelope.requestId;
|
|
225
|
+
this.tag = envelope.tag;
|
|
230
226
|
}
|
|
231
227
|
}
|
|
232
228
|
};
|
|
@@ -326,6 +322,7 @@ async function exaErrorFromResponse(response, path) {
|
|
|
326
322
|
message += (message.length > 0 ? ". " : "") + errorData.message;
|
|
327
323
|
}
|
|
328
324
|
}
|
|
325
|
+
const tag = typeof errorData.tag === "string" ? errorData.tag : void 0;
|
|
329
326
|
return new ExaError(
|
|
330
327
|
message,
|
|
331
328
|
response.status,
|
|
@@ -335,16 +332,17 @@ async function exaErrorFromResponse(response, path) {
|
|
|
335
332
|
type: envelope.type,
|
|
336
333
|
code: envelope.code,
|
|
337
334
|
detail: envelope.detail,
|
|
338
|
-
requestId: errorData.requestId ?? envelope.requestId
|
|
339
|
-
|
|
335
|
+
requestId: errorData.requestId ?? envelope.requestId,
|
|
336
|
+
tag
|
|
337
|
+
} : errorData.requestId || tag ? { requestId: errorData.requestId, tag } : void 0
|
|
340
338
|
);
|
|
341
339
|
}
|
|
342
340
|
|
|
343
341
|
// src/zod-utils.ts
|
|
344
|
-
var
|
|
342
|
+
var import_v3 = require("zod/v3");
|
|
345
343
|
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
346
344
|
function isZodSchema(obj) {
|
|
347
|
-
return obj instanceof
|
|
345
|
+
return obj instanceof import_v3.ZodType;
|
|
348
346
|
}
|
|
349
347
|
function zodToJsonSchema(schema) {
|
|
350
348
|
return (0, import_zod_to_json_schema.zodToJsonSchema)(schema, {
|
|
@@ -458,6 +456,12 @@ function mergeRequestHeaders(headers, extraHeaders) {
|
|
|
458
456
|
}
|
|
459
457
|
return merged;
|
|
460
458
|
}
|
|
459
|
+
function setsHeader(headers, name) {
|
|
460
|
+
const lowerCaseName = name.toLowerCase();
|
|
461
|
+
return Object.entries(headers ?? {}).some(
|
|
462
|
+
([key, value]) => key.toLowerCase() === lowerCaseName && value !== void 0
|
|
463
|
+
);
|
|
464
|
+
}
|
|
461
465
|
var CLIENT_DEFAULTS = /* @__PURE__ */ new WeakMap();
|
|
462
466
|
function setClientDefaults(client, defaults) {
|
|
463
467
|
if (defaults === void 0) {
|
|
@@ -712,6 +716,26 @@ function sleep(ms, signal) {
|
|
|
712
716
|
}, ms);
|
|
713
717
|
});
|
|
714
718
|
}
|
|
719
|
+
function untilAborted(promise, signal) {
|
|
720
|
+
return new Promise((resolve, reject) => {
|
|
721
|
+
const onAbort = () => reject(signal.reason);
|
|
722
|
+
if (signal.aborted) {
|
|
723
|
+
onAbort();
|
|
724
|
+
} else {
|
|
725
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
726
|
+
}
|
|
727
|
+
promise.then(
|
|
728
|
+
(value) => {
|
|
729
|
+
signal.removeEventListener("abort", onAbort);
|
|
730
|
+
resolve(value);
|
|
731
|
+
},
|
|
732
|
+
(error) => {
|
|
733
|
+
signal.removeEventListener("abort", onAbort);
|
|
734
|
+
reject(error);
|
|
735
|
+
}
|
|
736
|
+
);
|
|
737
|
+
});
|
|
738
|
+
}
|
|
715
739
|
var RequestScopedClient = class {
|
|
716
740
|
/**
|
|
717
741
|
* Returns a view of this client that sends `requestOptions` with every
|
|
@@ -745,7 +769,35 @@ var RequestScopedClient = class {
|
|
|
745
769
|
view.requestOptions = { ...this.requestOptions, query: remaining };
|
|
746
770
|
return view;
|
|
747
771
|
}
|
|
772
|
+
/**
|
|
773
|
+
* Yields every item of a cursor-paginated listing. `fetchPage` fetches the
|
|
774
|
+
* page at `cursor` with the view it is given: this one for the first page,
|
|
775
|
+
* `forNextPage()` for the rest. Stops after a page without `hasMore` or
|
|
776
|
+
* without a `nextCursor`.
|
|
777
|
+
*/
|
|
778
|
+
async *paginate(firstCursor, fetchPage) {
|
|
779
|
+
let view = this;
|
|
780
|
+
let cursor = firstCursor;
|
|
781
|
+
while (true) {
|
|
782
|
+
const page = await fetchPage(view, cursor);
|
|
783
|
+
for (const item of page.data) {
|
|
784
|
+
yield item;
|
|
785
|
+
}
|
|
786
|
+
if (!page.hasMore || !page.nextCursor) {
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
cursor = page.nextCursor;
|
|
790
|
+
view = view.forNextPage();
|
|
791
|
+
}
|
|
792
|
+
}
|
|
748
793
|
};
|
|
794
|
+
async function collectAll(items) {
|
|
795
|
+
const all = [];
|
|
796
|
+
for await (const item of items) {
|
|
797
|
+
all.push(item);
|
|
798
|
+
}
|
|
799
|
+
return all;
|
|
800
|
+
}
|
|
749
801
|
|
|
750
802
|
// src/agent/base.ts
|
|
751
803
|
var AgentBaseClient = class extends RequestScopedClient {
|
|
@@ -908,33 +960,19 @@ var AgentMonitorEntitiesClient = class extends AgentMonitorsBaseClient {
|
|
|
908
960
|
* automatically.
|
|
909
961
|
*/
|
|
910
962
|
async *listAll(monitorId, options, requestOptions) {
|
|
911
|
-
let scoped = this.withRequestOptions(requestOptions);
|
|
912
|
-
let cursor = options.cursor;
|
|
913
963
|
const { betas, ...pagination } = options;
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
for (const entityView of response.data) {
|
|
919
|
-
yield entityView;
|
|
920
|
-
}
|
|
921
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
922
|
-
break;
|
|
923
|
-
}
|
|
924
|
-
cursor = response.nextCursor;
|
|
925
|
-
scoped = scoped.forNextPage();
|
|
926
|
-
}
|
|
964
|
+
yield* this.withRequestOptions(requestOptions).paginate(
|
|
965
|
+
options.cursor,
|
|
966
|
+
(view, cursor) => view.list(monitorId, { ...pagination, cursor, betas })
|
|
967
|
+
);
|
|
927
968
|
}
|
|
928
969
|
/**
|
|
929
970
|
* Collect all of a monitor's entities into an array.
|
|
930
971
|
*/
|
|
931
972
|
async getAll(monitorId, options, requestOptions) {
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
entities.push(entityView);
|
|
936
|
-
}
|
|
937
|
-
return entities;
|
|
973
|
+
return collectAll(
|
|
974
|
+
this.withRequestOptions(requestOptions).listAll(monitorId, options)
|
|
975
|
+
);
|
|
938
976
|
}
|
|
939
977
|
};
|
|
940
978
|
var AgentMonitorChangesClient = class extends AgentMonitorsBaseClient {
|
|
@@ -958,33 +996,19 @@ var AgentMonitorChangesClient = class extends AgentMonitorsBaseClient {
|
|
|
958
996
|
* automatically.
|
|
959
997
|
*/
|
|
960
998
|
async *listAll(monitorId, options, requestOptions) {
|
|
961
|
-
let scoped = this.withRequestOptions(requestOptions);
|
|
962
|
-
let cursor = options.cursor;
|
|
963
999
|
const { betas, ...pagination } = options;
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
for (const change of response.data) {
|
|
969
|
-
yield change;
|
|
970
|
-
}
|
|
971
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
972
|
-
break;
|
|
973
|
-
}
|
|
974
|
-
cursor = response.nextCursor;
|
|
975
|
-
scoped = scoped.forNextPage();
|
|
976
|
-
}
|
|
1000
|
+
yield* this.withRequestOptions(requestOptions).paginate(
|
|
1001
|
+
options.cursor,
|
|
1002
|
+
(view, cursor) => view.list(monitorId, { ...pagination, cursor, betas })
|
|
1003
|
+
);
|
|
977
1004
|
}
|
|
978
1005
|
/**
|
|
979
1006
|
* Collect a monitor's change feed into an array.
|
|
980
1007
|
*/
|
|
981
1008
|
async getAll(monitorId, options, requestOptions) {
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
changes.push(change);
|
|
986
|
-
}
|
|
987
|
-
return changes;
|
|
1009
|
+
return collectAll(
|
|
1010
|
+
this.withRequestOptions(requestOptions).listAll(monitorId, options)
|
|
1011
|
+
);
|
|
988
1012
|
}
|
|
989
1013
|
};
|
|
990
1014
|
var AgentMonitorBacktestsClient = class extends AgentMonitorsBaseClient {
|
|
@@ -1104,33 +1128,19 @@ var AgentMonitorsClient = class extends AgentMonitorsBaseClient {
|
|
|
1104
1128
|
* Iterate through all Agent Monitors, handling pagination automatically.
|
|
1105
1129
|
*/
|
|
1106
1130
|
async *listAll(options, requestOptions) {
|
|
1107
|
-
let scoped = this.withRequestOptions(requestOptions);
|
|
1108
|
-
let cursor = options.cursor;
|
|
1109
1131
|
const { betas, ...pagination } = options;
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
for (const monitor of response.data) {
|
|
1115
|
-
yield monitor;
|
|
1116
|
-
}
|
|
1117
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
1118
|
-
break;
|
|
1119
|
-
}
|
|
1120
|
-
cursor = response.nextCursor;
|
|
1121
|
-
scoped = scoped.forNextPage();
|
|
1122
|
-
}
|
|
1132
|
+
yield* this.withRequestOptions(requestOptions).paginate(
|
|
1133
|
+
options.cursor,
|
|
1134
|
+
(view, cursor) => view.list({ ...pagination, cursor, betas })
|
|
1135
|
+
);
|
|
1123
1136
|
}
|
|
1124
1137
|
/**
|
|
1125
1138
|
* Collect all Agent Monitors into an array.
|
|
1126
1139
|
*/
|
|
1127
1140
|
async getAll(options, requestOptions) {
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
monitors.push(monitor);
|
|
1132
|
-
}
|
|
1133
|
-
return monitors;
|
|
1141
|
+
return collectAll(
|
|
1142
|
+
this.withRequestOptions(requestOptions).listAll(options)
|
|
1143
|
+
);
|
|
1134
1144
|
}
|
|
1135
1145
|
/**
|
|
1136
1146
|
* Delete an Agent Monitor and stop its refreshes.
|
|
@@ -1308,32 +1318,18 @@ var AgentRunsClient = class extends AgentBaseClient {
|
|
|
1308
1318
|
* Iterate through all Agent runs, handling pagination automatically.
|
|
1309
1319
|
*/
|
|
1310
1320
|
async *listAll(options, requestOptions) {
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
pageOptions.cursor = cursor;
|
|
1316
|
-
const response = await scoped.list(pageOptions);
|
|
1317
|
-
for (const run of response.data) {
|
|
1318
|
-
yield run;
|
|
1319
|
-
}
|
|
1320
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
1321
|
-
break;
|
|
1322
|
-
}
|
|
1323
|
-
cursor = response.nextCursor;
|
|
1324
|
-
scoped = scoped.forNextPage();
|
|
1325
|
-
}
|
|
1321
|
+
yield* this.withRequestOptions(requestOptions).paginate(
|
|
1322
|
+
options?.cursor,
|
|
1323
|
+
(view, cursor) => view.list({ ...options, cursor })
|
|
1324
|
+
);
|
|
1326
1325
|
}
|
|
1327
1326
|
/**
|
|
1328
1327
|
* Collect all Agent runs into an array.
|
|
1329
1328
|
*/
|
|
1330
1329
|
async getAll(options, requestOptions) {
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
runs.push(run);
|
|
1335
|
-
}
|
|
1336
|
-
return runs;
|
|
1330
|
+
return collectAll(
|
|
1331
|
+
this.withRequestOptions(requestOptions).listAll(options)
|
|
1332
|
+
);
|
|
1337
1333
|
}
|
|
1338
1334
|
/**
|
|
1339
1335
|
* Cancel a queued or running Agent run.
|
|
@@ -1470,30 +1466,16 @@ var AgentBetaRunsClient = class extends AgentRunsClient {
|
|
|
1470
1466
|
);
|
|
1471
1467
|
}
|
|
1472
1468
|
async *listAll(options, requestOptions) {
|
|
1473
|
-
let scoped = this.withRequestOptions(requestOptions);
|
|
1474
|
-
let cursor = void 0;
|
|
1475
1469
|
const { betas, ...pagination } = options ?? {};
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
for (const run of response.data) {
|
|
1481
|
-
yield run;
|
|
1482
|
-
}
|
|
1483
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
1484
|
-
break;
|
|
1485
|
-
}
|
|
1486
|
-
cursor = response.nextCursor;
|
|
1487
|
-
scoped = scoped.forNextPage();
|
|
1488
|
-
}
|
|
1470
|
+
yield* this.withRequestOptions(requestOptions).paginate(
|
|
1471
|
+
pagination?.cursor,
|
|
1472
|
+
(view, cursor) => view.list({ ...pagination, cursor, betas })
|
|
1473
|
+
);
|
|
1489
1474
|
}
|
|
1490
1475
|
async getAll(options, requestOptions) {
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
runs.push(run);
|
|
1495
|
-
}
|
|
1496
|
-
return runs;
|
|
1476
|
+
return collectAll(
|
|
1477
|
+
this.withRequestOptions(requestOptions).listAll(options)
|
|
1478
|
+
);
|
|
1497
1479
|
}
|
|
1498
1480
|
async cancel(runId, options) {
|
|
1499
1481
|
const scoped = this.withRequestOptions(options);
|
|
@@ -1658,21 +1640,10 @@ var SearchMonitorRunsClient = class extends SearchMonitorsBaseClient {
|
|
|
1658
1640
|
* @returns Async generator of Search Monitor runs
|
|
1659
1641
|
*/
|
|
1660
1642
|
async *listAll(monitorId, options, requestOptions) {
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
pageOptions.cursor = cursor;
|
|
1666
|
-
const response = await scoped.list(monitorId, pageOptions);
|
|
1667
|
-
for (const run of response.data) {
|
|
1668
|
-
yield run;
|
|
1669
|
-
}
|
|
1670
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
1671
|
-
break;
|
|
1672
|
-
}
|
|
1673
|
-
cursor = response.nextCursor;
|
|
1674
|
-
scoped = scoped.forNextPage();
|
|
1675
|
-
}
|
|
1643
|
+
yield* this.withRequestOptions(requestOptions).paginate(
|
|
1644
|
+
options?.cursor,
|
|
1645
|
+
(view, cursor) => view.list(monitorId, { ...options, cursor })
|
|
1646
|
+
);
|
|
1676
1647
|
}
|
|
1677
1648
|
/**
|
|
1678
1649
|
* Collect all runs for a Search Monitor into an array
|
|
@@ -1682,12 +1653,9 @@ var SearchMonitorRunsClient = class extends SearchMonitorsBaseClient {
|
|
|
1682
1653
|
* @returns Promise resolving to an array of all Search Monitor runs
|
|
1683
1654
|
*/
|
|
1684
1655
|
async getAll(monitorId, options, requestOptions) {
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
runs.push(run);
|
|
1689
|
-
}
|
|
1690
|
-
return runs;
|
|
1656
|
+
return collectAll(
|
|
1657
|
+
this.withRequestOptions(requestOptions).listAll(monitorId, options)
|
|
1658
|
+
);
|
|
1691
1659
|
}
|
|
1692
1660
|
};
|
|
1693
1661
|
var SearchMonitorsClient = class extends SearchMonitorsBaseClient {
|
|
@@ -1772,21 +1740,10 @@ var SearchMonitorsClient = class extends SearchMonitorsBaseClient {
|
|
|
1772
1740
|
* @returns Async generator of Search Monitors
|
|
1773
1741
|
*/
|
|
1774
1742
|
async *listAll(options, requestOptions) {
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
pageOptions.cursor = cursor;
|
|
1780
|
-
const response = await scoped.list(pageOptions);
|
|
1781
|
-
for (const monitor of response.data) {
|
|
1782
|
-
yield monitor;
|
|
1783
|
-
}
|
|
1784
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
1785
|
-
break;
|
|
1786
|
-
}
|
|
1787
|
-
cursor = response.nextCursor;
|
|
1788
|
-
scoped = scoped.forNextPage();
|
|
1789
|
-
}
|
|
1743
|
+
yield* this.withRequestOptions(requestOptions).paginate(
|
|
1744
|
+
options?.cursor,
|
|
1745
|
+
(view, cursor) => view.list({ ...options, cursor })
|
|
1746
|
+
);
|
|
1790
1747
|
}
|
|
1791
1748
|
/**
|
|
1792
1749
|
* Collect all Search Monitors into an array
|
|
@@ -1795,12 +1752,9 @@ var SearchMonitorsClient = class extends SearchMonitorsBaseClient {
|
|
|
1795
1752
|
* @returns Promise resolving to an array of all Search Monitors
|
|
1796
1753
|
*/
|
|
1797
1754
|
async getAll(options, requestOptions) {
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
monitors.push(monitor);
|
|
1802
|
-
}
|
|
1803
|
-
return monitors;
|
|
1755
|
+
return collectAll(
|
|
1756
|
+
this.withRequestOptions(requestOptions).listAll(options)
|
|
1757
|
+
);
|
|
1804
1758
|
}
|
|
1805
1759
|
};
|
|
1806
1760
|
|
|
@@ -1814,21 +1768,6 @@ var ResearchBaseClient = class extends RequestScopedClient {
|
|
|
1814
1768
|
super();
|
|
1815
1769
|
this.client = client;
|
|
1816
1770
|
}
|
|
1817
|
-
/** Rejects with `researchRetiredError()`: the Research API has been retired. */
|
|
1818
|
-
async request(_endpoint, _method = "POST", _data, _params) {
|
|
1819
|
-
throw researchRetiredError();
|
|
1820
|
-
}
|
|
1821
|
-
/** Rejects with `researchRetiredError()`: the Research API has been retired. */
|
|
1822
|
-
async rawRequest(_endpoint, _method = "POST", _data, _params) {
|
|
1823
|
-
throw researchRetiredError();
|
|
1824
|
-
}
|
|
1825
|
-
buildPaginationParams(pagination) {
|
|
1826
|
-
const params = {};
|
|
1827
|
-
if (!pagination) return params;
|
|
1828
|
-
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
1829
|
-
if (pagination.limit) params.limit = pagination.limit;
|
|
1830
|
-
return params;
|
|
1831
|
-
}
|
|
1832
1771
|
};
|
|
1833
1772
|
|
|
1834
1773
|
// src/research/client.ts
|
|
@@ -1836,105 +1775,14 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
1836
1775
|
constructor(client) {
|
|
1837
1776
|
super(client);
|
|
1838
1777
|
}
|
|
1839
|
-
async create(
|
|
1840
|
-
|
|
1841
|
-
const { instructions, model, outputSchema } = params;
|
|
1842
|
-
let schema = outputSchema;
|
|
1843
|
-
if (schema && isZodSchema(schema)) {
|
|
1844
|
-
schema = zodToJsonSchema(schema);
|
|
1845
|
-
}
|
|
1846
|
-
const payload = {
|
|
1847
|
-
instructions,
|
|
1848
|
-
model: model ?? "exa-research-fast"
|
|
1849
|
-
};
|
|
1850
|
-
if (schema) {
|
|
1851
|
-
payload.outputSchema = schema;
|
|
1852
|
-
}
|
|
1853
|
-
return scoped.request("", "POST", payload);
|
|
1778
|
+
async create(_params, _requestOptions) {
|
|
1779
|
+
throw researchRetiredError();
|
|
1854
1780
|
}
|
|
1855
|
-
get(
|
|
1856
|
-
|
|
1857
|
-
if (options?.stream) {
|
|
1858
|
-
const promise = async () => {
|
|
1859
|
-
const params = { stream: "true" };
|
|
1860
|
-
if (options.events !== void 0) {
|
|
1861
|
-
params.events = options.events.toString();
|
|
1862
|
-
}
|
|
1863
|
-
const resp = await scoped.rawRequest(
|
|
1864
|
-
`/${researchId}`,
|
|
1865
|
-
"GET",
|
|
1866
|
-
void 0,
|
|
1867
|
-
params
|
|
1868
|
-
);
|
|
1869
|
-
if (!resp.ok) {
|
|
1870
|
-
throw await exaErrorFromResponse(resp, `/research/v1/${researchId}`);
|
|
1871
|
-
}
|
|
1872
|
-
if (!resp.body) {
|
|
1873
|
-
throw new Error("No response body for SSE stream");
|
|
1874
|
-
}
|
|
1875
|
-
const reader = resp.body.getReader();
|
|
1876
|
-
const decoder = new TextDecoder();
|
|
1877
|
-
let buffer = "";
|
|
1878
|
-
function processPart(part) {
|
|
1879
|
-
const lines = part.split("\n");
|
|
1880
|
-
let data = lines.slice(1).join("\n");
|
|
1881
|
-
if (data.startsWith("data:")) {
|
|
1882
|
-
data = data.slice(5).trimStart();
|
|
1883
|
-
}
|
|
1884
|
-
try {
|
|
1885
|
-
return JSON.parse(data);
|
|
1886
|
-
} catch (e) {
|
|
1887
|
-
return null;
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
async function* streamEvents() {
|
|
1891
|
-
try {
|
|
1892
|
-
while (true) {
|
|
1893
|
-
const { done, value } = await reader.read();
|
|
1894
|
-
if (done) break;
|
|
1895
|
-
buffer += decoder.decode(value, { stream: true });
|
|
1896
|
-
let parts = buffer.split("\n\n");
|
|
1897
|
-
buffer = parts.pop() ?? "";
|
|
1898
|
-
for (const part of parts) {
|
|
1899
|
-
const processed = processPart(part);
|
|
1900
|
-
if (processed) {
|
|
1901
|
-
yield processed;
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
}
|
|
1905
|
-
if (buffer.trim()) {
|
|
1906
|
-
const processed = processPart(buffer.trim());
|
|
1907
|
-
if (processed) {
|
|
1908
|
-
yield processed;
|
|
1909
|
-
}
|
|
1910
|
-
}
|
|
1911
|
-
} finally {
|
|
1912
|
-
try {
|
|
1913
|
-
await reader.cancel();
|
|
1914
|
-
} catch {
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
}
|
|
1918
|
-
return streamEvents();
|
|
1919
|
-
};
|
|
1920
|
-
return promise();
|
|
1921
|
-
} else {
|
|
1922
|
-
const params = { stream: "false" };
|
|
1923
|
-
if (options?.events !== void 0) {
|
|
1924
|
-
params.events = options.events.toString();
|
|
1925
|
-
}
|
|
1926
|
-
return scoped.request(
|
|
1927
|
-
`/${researchId}`,
|
|
1928
|
-
"GET",
|
|
1929
|
-
void 0,
|
|
1930
|
-
params
|
|
1931
|
-
);
|
|
1932
|
-
}
|
|
1781
|
+
get(_researchId, _options, _requestOptions) {
|
|
1782
|
+
return Promise.reject(researchRetiredError());
|
|
1933
1783
|
}
|
|
1934
|
-
async list(
|
|
1935
|
-
|
|
1936
|
-
const params = this.buildPaginationParams(options);
|
|
1937
|
-
return scoped.request("", "GET", void 0, params);
|
|
1784
|
+
async list(_options, _requestOptions) {
|
|
1785
|
+
throw researchRetiredError();
|
|
1938
1786
|
}
|
|
1939
1787
|
async pollUntilFinished(_researchId, _options, _requestOptions) {
|
|
1940
1788
|
throw researchRetiredError();
|
|
@@ -2116,21 +1964,10 @@ var EventsClient = class extends WebsetsBaseClient {
|
|
|
2116
1964
|
* @returns Async generator of Events
|
|
2117
1965
|
*/
|
|
2118
1966
|
async *listAll(options, requestOptions) {
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
pageOptions.cursor = cursor;
|
|
2124
|
-
const response = await scoped.list(pageOptions);
|
|
2125
|
-
for (const event of response.data) {
|
|
2126
|
-
yield event;
|
|
2127
|
-
}
|
|
2128
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
2129
|
-
break;
|
|
2130
|
-
}
|
|
2131
|
-
cursor = response.nextCursor;
|
|
2132
|
-
scoped = scoped.forNextPage();
|
|
2133
|
-
}
|
|
1967
|
+
yield* this.withRequestOptions(requestOptions).paginate(
|
|
1968
|
+
options?.cursor,
|
|
1969
|
+
(view, cursor) => view.list({ ...options, cursor })
|
|
1970
|
+
);
|
|
2134
1971
|
}
|
|
2135
1972
|
/**
|
|
2136
1973
|
* Collect all Events into an array
|
|
@@ -2139,12 +1976,9 @@ var EventsClient = class extends WebsetsBaseClient {
|
|
|
2139
1976
|
* @returns Promise resolving to an array of all Events
|
|
2140
1977
|
*/
|
|
2141
1978
|
async getAll(options, requestOptions) {
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
events.push(event);
|
|
2146
|
-
}
|
|
2147
|
-
return events;
|
|
1979
|
+
return collectAll(
|
|
1980
|
+
this.withRequestOptions(requestOptions).listAll(options)
|
|
1981
|
+
);
|
|
2148
1982
|
}
|
|
2149
1983
|
};
|
|
2150
1984
|
|
|
@@ -2489,21 +2323,10 @@ var ImportsClient = class extends WebsetsBaseClient {
|
|
|
2489
2323
|
* @returns Async generator of Imports
|
|
2490
2324
|
*/
|
|
2491
2325
|
async *listAll(options, requestOptions) {
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
pageOptions.cursor = cursor;
|
|
2497
|
-
const response = await scoped.list(pageOptions);
|
|
2498
|
-
for (const importItem of response.data) {
|
|
2499
|
-
yield importItem;
|
|
2500
|
-
}
|
|
2501
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
2502
|
-
break;
|
|
2503
|
-
}
|
|
2504
|
-
cursor = response.nextCursor;
|
|
2505
|
-
scoped = scoped.forNextPage();
|
|
2506
|
-
}
|
|
2326
|
+
yield* this.withRequestOptions(requestOptions).paginate(
|
|
2327
|
+
options?.cursor,
|
|
2328
|
+
(view, cursor) => view.list({ ...options, cursor })
|
|
2329
|
+
);
|
|
2507
2330
|
}
|
|
2508
2331
|
/**
|
|
2509
2332
|
* Collect all Imports into an array
|
|
@@ -2512,12 +2335,9 @@ var ImportsClient = class extends WebsetsBaseClient {
|
|
|
2512
2335
|
* @returns Promise resolving to an array of all Imports
|
|
2513
2336
|
*/
|
|
2514
2337
|
async getAll(options, requestOptions) {
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
imports.push(importItem);
|
|
2519
|
-
}
|
|
2520
|
-
return imports;
|
|
2338
|
+
return collectAll(
|
|
2339
|
+
this.withRequestOptions(requestOptions).listAll(options)
|
|
2340
|
+
);
|
|
2521
2341
|
}
|
|
2522
2342
|
};
|
|
2523
2343
|
|
|
@@ -2551,21 +2371,10 @@ var WebsetItemsClient = class extends WebsetsBaseClient {
|
|
|
2551
2371
|
* @returns Async generator of Webset Items
|
|
2552
2372
|
*/
|
|
2553
2373
|
async *listAll(websetId, options, requestOptions) {
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
pageOptions.cursor = cursor;
|
|
2559
|
-
const response = await scoped.list(websetId, pageOptions);
|
|
2560
|
-
for (const item of response.data) {
|
|
2561
|
-
yield item;
|
|
2562
|
-
}
|
|
2563
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
2564
|
-
break;
|
|
2565
|
-
}
|
|
2566
|
-
cursor = response.nextCursor;
|
|
2567
|
-
scoped = scoped.forNextPage();
|
|
2568
|
-
}
|
|
2374
|
+
yield* this.withRequestOptions(requestOptions).paginate(
|
|
2375
|
+
options?.cursor,
|
|
2376
|
+
(view, cursor) => view.list(websetId, { ...options, cursor })
|
|
2377
|
+
);
|
|
2569
2378
|
}
|
|
2570
2379
|
/**
|
|
2571
2380
|
* Collect all items from a Webset into an array
|
|
@@ -2575,12 +2384,9 @@ var WebsetItemsClient = class extends WebsetsBaseClient {
|
|
|
2575
2384
|
* @returns Promise resolving to an array of all Webset Items
|
|
2576
2385
|
*/
|
|
2577
2386
|
async getAll(websetId, options, requestOptions) {
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
items.push(item);
|
|
2582
|
-
}
|
|
2583
|
-
return items;
|
|
2387
|
+
return collectAll(
|
|
2388
|
+
this.withRequestOptions(requestOptions).listAll(websetId, options)
|
|
2389
|
+
);
|
|
2584
2390
|
}
|
|
2585
2391
|
/**
|
|
2586
2392
|
* Get an Item by ID
|
|
@@ -2719,21 +2525,10 @@ var WebsetMonitorsClient = class extends WebsetsBaseClient {
|
|
|
2719
2525
|
* @returns Async generator of Monitors
|
|
2720
2526
|
*/
|
|
2721
2527
|
async *listAll(options, requestOptions) {
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
pageOptions.cursor = cursor;
|
|
2727
|
-
const response = await scoped.list(pageOptions);
|
|
2728
|
-
for (const monitor of response.data) {
|
|
2729
|
-
yield monitor;
|
|
2730
|
-
}
|
|
2731
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
2732
|
-
break;
|
|
2733
|
-
}
|
|
2734
|
-
cursor = response.nextCursor;
|
|
2735
|
-
scoped = scoped.forNextPage();
|
|
2736
|
-
}
|
|
2528
|
+
yield* this.withRequestOptions(requestOptions).paginate(
|
|
2529
|
+
options?.cursor,
|
|
2530
|
+
(view, cursor) => view.list({ ...options, cursor })
|
|
2531
|
+
);
|
|
2737
2532
|
}
|
|
2738
2533
|
/**
|
|
2739
2534
|
* Collect all Monitors into an array
|
|
@@ -2742,12 +2537,9 @@ var WebsetMonitorsClient = class extends WebsetsBaseClient {
|
|
|
2742
2537
|
* @returns Promise resolving to an array of all Monitors
|
|
2743
2538
|
*/
|
|
2744
2539
|
async getAll(options, requestOptions) {
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
monitors.push(monitor);
|
|
2749
|
-
}
|
|
2750
|
-
return monitors;
|
|
2540
|
+
return collectAll(
|
|
2541
|
+
this.withRequestOptions(requestOptions).listAll(options)
|
|
2542
|
+
);
|
|
2751
2543
|
}
|
|
2752
2544
|
};
|
|
2753
2545
|
|
|
@@ -2845,21 +2637,10 @@ var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
|
2845
2637
|
* @returns Async generator of Webhooks
|
|
2846
2638
|
*/
|
|
2847
2639
|
async *listAll(options, requestOptions) {
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
pageOptions.cursor = cursor;
|
|
2853
|
-
const response = await scoped.list(pageOptions);
|
|
2854
|
-
for (const webhook of response.data) {
|
|
2855
|
-
yield webhook;
|
|
2856
|
-
}
|
|
2857
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
2858
|
-
break;
|
|
2859
|
-
}
|
|
2860
|
-
cursor = response.nextCursor;
|
|
2861
|
-
scoped = scoped.forNextPage();
|
|
2862
|
-
}
|
|
2640
|
+
yield* this.withRequestOptions(requestOptions).paginate(
|
|
2641
|
+
options?.cursor,
|
|
2642
|
+
(view, cursor) => view.list({ ...options, cursor })
|
|
2643
|
+
);
|
|
2863
2644
|
}
|
|
2864
2645
|
/**
|
|
2865
2646
|
* Collect all Webhooks into an array
|
|
@@ -2868,12 +2649,9 @@ var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
|
2868
2649
|
* @returns Promise resolving to an array of all Webhooks
|
|
2869
2650
|
*/
|
|
2870
2651
|
async getAll(options, requestOptions) {
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
webhooks.push(webhook);
|
|
2875
|
-
}
|
|
2876
|
-
return webhooks;
|
|
2652
|
+
return collectAll(
|
|
2653
|
+
this.withRequestOptions(requestOptions).listAll(options)
|
|
2654
|
+
);
|
|
2877
2655
|
}
|
|
2878
2656
|
/**
|
|
2879
2657
|
* Update a Webhook
|
|
@@ -2926,21 +2704,10 @@ var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
|
2926
2704
|
* @returns Async generator of Webhook attempts
|
|
2927
2705
|
*/
|
|
2928
2706
|
async *listAllAttempts(id, options, requestOptions) {
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
pageOptions.cursor = cursor;
|
|
2934
|
-
const response = await scoped.listAttempts(id, pageOptions);
|
|
2935
|
-
for (const attempt of response.data) {
|
|
2936
|
-
yield attempt;
|
|
2937
|
-
}
|
|
2938
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
2939
|
-
break;
|
|
2940
|
-
}
|
|
2941
|
-
cursor = response.nextCursor;
|
|
2942
|
-
scoped = scoped.forNextPage();
|
|
2943
|
-
}
|
|
2707
|
+
yield* this.withRequestOptions(requestOptions).paginate(
|
|
2708
|
+
options?.cursor,
|
|
2709
|
+
(view, cursor) => view.listAttempts(id, { ...options, cursor })
|
|
2710
|
+
);
|
|
2944
2711
|
}
|
|
2945
2712
|
/**
|
|
2946
2713
|
* Collect all attempts for a Webhook into an array
|
|
@@ -2950,12 +2717,9 @@ var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
|
2950
2717
|
* @returns Promise resolving to an array of all Webhook attempts
|
|
2951
2718
|
*/
|
|
2952
2719
|
async getAllAttempts(id, options, requestOptions) {
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
attempts.push(attempt);
|
|
2957
|
-
}
|
|
2958
|
-
return attempts;
|
|
2720
|
+
return collectAll(
|
|
2721
|
+
this.withRequestOptions(requestOptions).listAllAttempts(id, options)
|
|
2722
|
+
);
|
|
2959
2723
|
}
|
|
2960
2724
|
};
|
|
2961
2725
|
|
|
@@ -3054,21 +2818,10 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
3054
2818
|
* @returns Async generator of Websets
|
|
3055
2819
|
*/
|
|
3056
2820
|
async *listAll(options, requestOptions) {
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
pageOptions.cursor = cursor;
|
|
3062
|
-
const response = await scoped.list(pageOptions);
|
|
3063
|
-
for (const webset of response.data) {
|
|
3064
|
-
yield webset;
|
|
3065
|
-
}
|
|
3066
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
3067
|
-
break;
|
|
3068
|
-
}
|
|
3069
|
-
cursor = response.nextCursor;
|
|
3070
|
-
scoped = scoped.forNextPage();
|
|
3071
|
-
}
|
|
2821
|
+
yield* this.withRequestOptions(requestOptions).paginate(
|
|
2822
|
+
options?.cursor,
|
|
2823
|
+
(view, cursor) => view.list({ ...options, cursor })
|
|
2824
|
+
);
|
|
3072
2825
|
}
|
|
3073
2826
|
/**
|
|
3074
2827
|
* Collect all Websets into an array
|
|
@@ -3077,12 +2830,9 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
3077
2830
|
* @returns Promise resolving to an array of all Websets
|
|
3078
2831
|
*/
|
|
3079
2832
|
async getAll(options, requestOptions) {
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
websets.push(webset);
|
|
3084
|
-
}
|
|
3085
|
-
return websets;
|
|
2833
|
+
return collectAll(
|
|
2834
|
+
this.withRequestOptions(requestOptions).listAll(options)
|
|
2835
|
+
);
|
|
3086
2836
|
}
|
|
3087
2837
|
/**
|
|
3088
2838
|
* Update a Webset
|
|
@@ -3156,7 +2906,7 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
3156
2906
|
};
|
|
3157
2907
|
|
|
3158
2908
|
// src/tools/core.ts
|
|
3159
|
-
var
|
|
2909
|
+
var import_v32 = require("zod/v3");
|
|
3160
2910
|
var DEFAULT_WEB_SEARCH_TOOL_DESCRIPTION = "Search the web for up-to-date, relevant information. Describe the ideal page rather than listing keywords.";
|
|
3161
2911
|
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.";
|
|
3162
2912
|
var SEARCH_OBJECTIVE_TOOL_DESCRIPTION = "Goal for this search turn; say which documents should rank first, which should be excluded, and what specific facts or figures to pull from them.";
|
|
@@ -3221,7 +2971,7 @@ function createTool(registry, params) {
|
|
|
3221
2971
|
};
|
|
3222
2972
|
return registerTool(registry, tool);
|
|
3223
2973
|
}
|
|
3224
|
-
var AdvertisedRequiredOptional = class extends
|
|
2974
|
+
var AdvertisedRequiredOptional = class extends import_v32.z.ZodOptional {
|
|
3225
2975
|
isOptional() {
|
|
3226
2976
|
return false;
|
|
3227
2977
|
}
|
|
@@ -3229,7 +2979,7 @@ var AdvertisedRequiredOptional = class extends import_zod2.z.ZodOptional {
|
|
|
3229
2979
|
function advertisedRequired(inner) {
|
|
3230
2980
|
return new AdvertisedRequiredOptional({
|
|
3231
2981
|
innerType: inner,
|
|
3232
|
-
typeName:
|
|
2982
|
+
typeName: import_v32.z.ZodFirstPartyTypeKind.ZodOptional
|
|
3233
2983
|
});
|
|
3234
2984
|
}
|
|
3235
2985
|
function createWebSearchTool(exa, registry, config = {}) {
|
|
@@ -3238,14 +2988,14 @@ function createWebSearchTool(exa, registry, config = {}) {
|
|
|
3238
2988
|
description = DEFAULT_WEB_SEARCH_TOOL_DESCRIPTION,
|
|
3239
2989
|
...searchOptions
|
|
3240
2990
|
} = config;
|
|
3241
|
-
const inputSchema =
|
|
3242
|
-
query:
|
|
2991
|
+
const inputSchema = import_v32.z.object({
|
|
2992
|
+
query: import_v32.z.string().describe(
|
|
3243
2993
|
"Natural language search query. Should be a semantically rich description of the ideal page, not just keywords."
|
|
3244
2994
|
),
|
|
3245
2995
|
// Length limits are validated but not advertised: strict tool use on some
|
|
3246
2996
|
// providers rejects `minLength`/`maxLength` in the schema.
|
|
3247
2997
|
objective: advertisedRequired(
|
|
3248
|
-
|
|
2998
|
+
import_v32.z.string().trim().refine((value) => value.length > 0, "objective must not be empty").refine(
|
|
3249
2999
|
(value) => value.length <= MAX_OBJECTIVE_LENGTH,
|
|
3250
3000
|
`objective must be at most ${MAX_OBJECTIVE_LENGTH} characters`
|
|
3251
3001
|
)
|
|
@@ -3282,8 +3032,8 @@ function createGetContentsTool(exa, registry, config = {}) {
|
|
|
3282
3032
|
description = DEFAULT_GET_CONTENTS_TOOL_DESCRIPTION,
|
|
3283
3033
|
...contentsOptions
|
|
3284
3034
|
} = config;
|
|
3285
|
-
const inputSchema =
|
|
3286
|
-
urls:
|
|
3035
|
+
const inputSchema = import_v32.z.object({
|
|
3036
|
+
urls: import_v32.z.array(import_v32.z.string()).describe(
|
|
3287
3037
|
"Absolute URLs of the pages to read, including the scheme. Pass several URLs to read them in a single call."
|
|
3288
3038
|
)
|
|
3289
3039
|
});
|
|
@@ -3589,7 +3339,47 @@ function isResponsesInput(value) {
|
|
|
3589
3339
|
var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : import_cross_fetch.default;
|
|
3590
3340
|
var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : import_cross_fetch.Headers;
|
|
3591
3341
|
var DEFAULT_MAX_CHARACTERS = 1e4;
|
|
3342
|
+
var DEFAULT_BASE_URL = "https://api.exa.ai";
|
|
3343
|
+
function resolveBaseURL(baseURL) {
|
|
3344
|
+
if (baseURL === void 0) {
|
|
3345
|
+
const fromEnvironment = typeof process === "undefined" ? void 0 : process.env?.EXA_BASE_URL?.trim();
|
|
3346
|
+
baseURL = fromEnvironment || DEFAULT_BASE_URL;
|
|
3347
|
+
}
|
|
3348
|
+
return baseURL.replace(/\/+$/, "");
|
|
3349
|
+
}
|
|
3350
|
+
function clientArguments(second, third) {
|
|
3351
|
+
if (typeof URL !== "undefined" && second instanceof URL) {
|
|
3352
|
+
second = String(second);
|
|
3353
|
+
}
|
|
3354
|
+
if (typeof second === "object" && second !== null) {
|
|
3355
|
+
if (third !== void 0) {
|
|
3356
|
+
throw new TypeError(
|
|
3357
|
+
"Pass the client options once, as the second argument or as the third after a base URL"
|
|
3358
|
+
);
|
|
3359
|
+
}
|
|
3360
|
+
return { baseURL: second.baseURL, options: second };
|
|
3361
|
+
}
|
|
3362
|
+
if (second != null && third?.baseURL !== void 0) {
|
|
3363
|
+
throw new TypeError(
|
|
3364
|
+
"Pass the base URL once, as the second argument or as options.baseURL"
|
|
3365
|
+
);
|
|
3366
|
+
}
|
|
3367
|
+
return { baseURL: second ?? third?.baseURL, options: third };
|
|
3368
|
+
}
|
|
3592
3369
|
var DYNAMIC_HIGHLIGHTS_BETA = "dynamic-highlights-2026-08-28";
|
|
3370
|
+
async function resolveApiKey(apiKey, signal) {
|
|
3371
|
+
if (signal?.aborted) {
|
|
3372
|
+
throw signal.reason;
|
|
3373
|
+
}
|
|
3374
|
+
const pending = Promise.resolve(apiKey({ signal }));
|
|
3375
|
+
const key = await (signal ? untilAborted(pending, signal) : pending);
|
|
3376
|
+
if (typeof key !== "string" || !/^[\x21-\x7E]+$/.test(key)) {
|
|
3377
|
+
throw new TypeError(
|
|
3378
|
+
"apiKey must return a non-empty string of visible ASCII characters"
|
|
3379
|
+
);
|
|
3380
|
+
}
|
|
3381
|
+
return key;
|
|
3382
|
+
}
|
|
3593
3383
|
var loggedWarnings = /* @__PURE__ */ new Set();
|
|
3594
3384
|
function logWarningOnce(warning, context) {
|
|
3595
3385
|
const request = `${context.method} ${context.endpoint}`;
|
|
@@ -3641,6 +3431,24 @@ function costDollarsOf(payload) {
|
|
|
3641
3431
|
}
|
|
3642
3432
|
return costDollars;
|
|
3643
3433
|
}
|
|
3434
|
+
function streamErrorOf(payload, path, requestIdHeader) {
|
|
3435
|
+
const event = payload?.type === "error" ? payload : payload?.tag === "ERROR" ? payload.payload : void 0;
|
|
3436
|
+
if (typeof event !== "object" || event === null) {
|
|
3437
|
+
return void 0;
|
|
3438
|
+
}
|
|
3439
|
+
const { code, message, tag } = event.error ?? {};
|
|
3440
|
+
const requestId = typeof event.requestId === "string" ? event.requestId : requestIdHeader;
|
|
3441
|
+
return new ExaError(
|
|
3442
|
+
typeof message === "string" && message ? message : "Unknown error",
|
|
3443
|
+
typeof code === "number" ? code : 500 /* InternalServerError */,
|
|
3444
|
+
void 0,
|
|
3445
|
+
path,
|
|
3446
|
+
{
|
|
3447
|
+
requestId: requestId ?? void 0,
|
|
3448
|
+
tag: typeof tag === "string" ? tag : void 0
|
|
3449
|
+
}
|
|
3450
|
+
);
|
|
3451
|
+
}
|
|
3644
3452
|
function citationsFromResults(results) {
|
|
3645
3453
|
if (!Array.isArray(results)) {
|
|
3646
3454
|
return void 0;
|
|
@@ -3667,36 +3475,47 @@ function withJsonSummarySchema(contents) {
|
|
|
3667
3475
|
};
|
|
3668
3476
|
}
|
|
3669
3477
|
var Exa2 = class {
|
|
3670
|
-
|
|
3671
|
-
* Constructs the Exa API client.
|
|
3672
|
-
* @param {string} apiKey - The API key for authentication.
|
|
3673
|
-
* @param {string} [baseURL] - The base URL of the Exa API.
|
|
3674
|
-
* @param {ExaClientOptions} [options] - Client-wide settings (`timeout`, `warnings`).
|
|
3675
|
-
* @throws {RangeError} When `options.timeout` is not an integer from 1 to 2147483647.
|
|
3676
|
-
* @throws {TypeError} When `options.warnings` is not `"log"`, `"silent"` or a function.
|
|
3677
|
-
*/
|
|
3678
|
-
constructor(apiKey, baseURL = "https://api.exa.ai", options) {
|
|
3478
|
+
constructor(apiKey, baseURLOrOptions, maybeOptions) {
|
|
3679
3479
|
this.toolRegistry = new ToolRegistry();
|
|
3680
|
-
|
|
3480
|
+
const { baseURL, options } = clientArguments(
|
|
3481
|
+
baseURLOrOptions,
|
|
3482
|
+
maybeOptions
|
|
3483
|
+
);
|
|
3484
|
+
this.baseURL = resolveBaseURL(baseURL);
|
|
3681
3485
|
this.warningHandler = warningHandlerFor(options?.warnings);
|
|
3682
3486
|
setClientDefaults(
|
|
3683
3487
|
this,
|
|
3684
3488
|
options?.timeout === void 0 ? void 0 : { timeout: validateTimeout(options.timeout) }
|
|
3685
3489
|
);
|
|
3686
|
-
|
|
3687
|
-
|
|
3490
|
+
const customFetch = options?.fetch;
|
|
3491
|
+
if (customFetch !== void 0 && typeof customFetch !== "function") {
|
|
3492
|
+
throw new TypeError("options.fetch must be a function");
|
|
3493
|
+
}
|
|
3494
|
+
const send = customFetch ?? fetchImpl;
|
|
3495
|
+
this.fetcher = (input, init) => send(input, init);
|
|
3496
|
+
if (typeof apiKey === "function") {
|
|
3497
|
+
this.apiKeySource = apiKey;
|
|
3498
|
+
this.headers = new HeadersImpl({
|
|
3499
|
+
"Content-Type": "application/json",
|
|
3500
|
+
"User-Agent": `exa-node ${package_default.version}`
|
|
3501
|
+
});
|
|
3502
|
+
} else {
|
|
3503
|
+
this.apiKeySource = void 0;
|
|
3688
3504
|
if (!apiKey) {
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3505
|
+
apiKey = process.env.EXA_API_KEY;
|
|
3506
|
+
if (!apiKey) {
|
|
3507
|
+
throw new ExaError(
|
|
3508
|
+
"API key must be provided as an argument or as an environment variable (EXA_API_KEY)",
|
|
3509
|
+
401 /* Unauthorized */
|
|
3510
|
+
);
|
|
3511
|
+
}
|
|
3693
3512
|
}
|
|
3513
|
+
this.headers = new HeadersImpl({
|
|
3514
|
+
"x-api-key": apiKey,
|
|
3515
|
+
"Content-Type": "application/json",
|
|
3516
|
+
"User-Agent": `exa-node ${package_default.version}`
|
|
3517
|
+
});
|
|
3694
3518
|
}
|
|
3695
|
-
this.headers = new HeadersImpl({
|
|
3696
|
-
"x-api-key": apiKey,
|
|
3697
|
-
"Content-Type": "application/json",
|
|
3698
|
-
"User-Agent": `exa-node ${package_default.version}`
|
|
3699
|
-
});
|
|
3700
3519
|
this.websets = new WebsetsClient(this);
|
|
3701
3520
|
this.research = new ResearchClient(this);
|
|
3702
3521
|
this.monitors = new SearchMonitorsClient(this);
|
|
@@ -3791,6 +3610,22 @@ var Exa2 = class {
|
|
|
3791
3610
|
}
|
|
3792
3611
|
return { query, ...body };
|
|
3793
3612
|
}
|
|
3613
|
+
/**
|
|
3614
|
+
* Returns the headers a request sends, which are `headers` with the call's
|
|
3615
|
+
* `extraHeaders` on top and, when `apiKey` is a function, the key it returns
|
|
3616
|
+
* as `x-api-key` beneath them. The function is called only when neither
|
|
3617
|
+
* sets `x-api-key` nor removes it with `null`, whatever its case. Called
|
|
3618
|
+
* inside each request's lifecycle, so the request's `signal` and `timeout`
|
|
3619
|
+
* also bound the wait for the key.
|
|
3620
|
+
*/
|
|
3621
|
+
async requestHeaders(headers, extraHeaders, signal) {
|
|
3622
|
+
const merged = mergeRequestHeaders(headers, extraHeaders);
|
|
3623
|
+
if (!this.apiKeySource || setsHeader(headers, "x-api-key") || setsHeader(extraHeaders, "x-api-key")) {
|
|
3624
|
+
return merged;
|
|
3625
|
+
}
|
|
3626
|
+
const apiKey = await resolveApiKey(this.apiKeySource, signal);
|
|
3627
|
+
return mergeRequestHeaders({ "x-api-key": apiKey }, merged);
|
|
3628
|
+
}
|
|
3794
3629
|
/**
|
|
3795
3630
|
* Makes a request to the Exa API.
|
|
3796
3631
|
* @param {string} endpoint - The API endpoint to call.
|
|
@@ -3832,17 +3667,17 @@ var Exa2 = class {
|
|
|
3832
3667
|
if (headers) {
|
|
3833
3668
|
combinedHeaders = { ...combinedHeaders, ...headers };
|
|
3834
3669
|
}
|
|
3835
|
-
combinedHeaders = mergeRequestHeaders(
|
|
3836
|
-
combinedHeaders,
|
|
3837
|
-
requestOptions?.headers
|
|
3838
|
-
);
|
|
3839
3670
|
const { signal, dispose, toRequestError } = resolveRequestSignal(
|
|
3840
3671
|
withClientDefaults(this, requestOptions)
|
|
3841
3672
|
);
|
|
3842
3673
|
try {
|
|
3843
|
-
const response = await
|
|
3674
|
+
const response = await this.fetcher(url, {
|
|
3844
3675
|
method,
|
|
3845
|
-
headers:
|
|
3676
|
+
headers: await this.requestHeaders(
|
|
3677
|
+
combinedHeaders,
|
|
3678
|
+
requestOptions?.headers,
|
|
3679
|
+
signal
|
|
3680
|
+
),
|
|
3846
3681
|
body: body ? JSON.stringify(body) : void 0,
|
|
3847
3682
|
signal
|
|
3848
3683
|
});
|
|
@@ -3907,15 +3742,15 @@ var Exa2 = class {
|
|
|
3907
3742
|
if (headers) {
|
|
3908
3743
|
combinedHeaders = { ...combinedHeaders, ...headers };
|
|
3909
3744
|
}
|
|
3910
|
-
combinedHeaders = mergeRequestHeaders(
|
|
3911
|
-
combinedHeaders,
|
|
3912
|
-
requestOptions?.headers
|
|
3913
|
-
);
|
|
3914
3745
|
const { signal, dispose, needsDispose, stopTimeout, toRequestError } = resolveRequestSignal(withClientDefaults(this, requestOptions));
|
|
3915
3746
|
try {
|
|
3916
|
-
const response = await
|
|
3747
|
+
const response = await this.fetcher(url, {
|
|
3917
3748
|
method,
|
|
3918
|
-
headers:
|
|
3749
|
+
headers: await this.requestHeaders(
|
|
3750
|
+
combinedHeaders,
|
|
3751
|
+
requestOptions?.headers,
|
|
3752
|
+
signal
|
|
3753
|
+
),
|
|
3919
3754
|
body: body ? JSON.stringify(body) : void 0,
|
|
3920
3755
|
signal
|
|
3921
3756
|
});
|
|
@@ -4006,6 +3841,9 @@ var Exa2 = class {
|
|
|
4006
3841
|
* A search without `outputSchema` has no text to stream. Its stream yields
|
|
4007
3842
|
* one chunk with the results as `citations`, then the warnings chunk when
|
|
4008
3843
|
* the API returns warnings. Call `search()` for every field of the results.
|
|
3844
|
+
*
|
|
3845
|
+
* If the API reports an error partway through, the stream yields the chunks
|
|
3846
|
+
* before it and then rejects with an `ExaError`.
|
|
4009
3847
|
* @param {RequestOptions} [requestOptions] - Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`).
|
|
4010
3848
|
*/
|
|
4011
3849
|
streamSearch(query, options, requestOptions) {
|
|
@@ -4259,18 +4097,29 @@ var Exa2 = class {
|
|
|
4259
4097
|
continue;
|
|
4260
4098
|
}
|
|
4261
4099
|
this.reportWarnings(endpoint, "POST", chunkData, requestIdHeader);
|
|
4100
|
+
const error = streamErrorOf(chunkData, endpoint, requestIdHeader);
|
|
4101
|
+
if (error) {
|
|
4102
|
+
throw error;
|
|
4103
|
+
}
|
|
4262
4104
|
yield* this.payloadChunks(chunkData);
|
|
4263
4105
|
}
|
|
4264
4106
|
}
|
|
4265
4107
|
if (buffer.startsWith("data: ")) {
|
|
4266
4108
|
const leftover = buffer.replace(/^data:\s*/, "").trim();
|
|
4267
4109
|
if (leftover && leftover !== "[DONE]") {
|
|
4110
|
+
let error;
|
|
4268
4111
|
try {
|
|
4269
4112
|
const chunkData = JSON.parse(leftover);
|
|
4270
4113
|
this.reportWarnings(endpoint, "POST", chunkData, requestIdHeader);
|
|
4271
|
-
|
|
4114
|
+
error = streamErrorOf(chunkData, endpoint, requestIdHeader);
|
|
4115
|
+
if (!error) {
|
|
4116
|
+
yield* this.payloadChunks(chunkData);
|
|
4117
|
+
}
|
|
4272
4118
|
} catch (e) {
|
|
4273
4119
|
}
|
|
4120
|
+
if (error) {
|
|
4121
|
+
throw error;
|
|
4122
|
+
}
|
|
4274
4123
|
}
|
|
4275
4124
|
}
|
|
4276
4125
|
} finally {
|
|
@@ -4461,4 +4310,3 @@ var index_default = Exa2;
|
|
|
4461
4310
|
createGetContentsTool,
|
|
4462
4311
|
createWebSearchTool
|
|
4463
4312
|
});
|
|
4464
|
-
//# sourceMappingURL=index.js.map
|