exa-js 1.9.0 → 1.9.2
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.d.mts +2444 -3579
- package/dist/index.d.ts +2444 -3579
- package/dist/index.js +293 -215
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +290 -209
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32,10 +32,6 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
CreateEnrichmentParametersFormat: () => CreateEnrichmentParametersFormat,
|
|
34
34
|
CreateImportParametersFormat: () => CreateImportParametersFormat,
|
|
35
|
-
CreateWebsetParametersImportSource: () => CreateWebsetParametersImportSource,
|
|
36
|
-
CreateWebsetParametersSearchExcludeSource: () => CreateWebsetParametersSearchExcludeSource,
|
|
37
|
-
CreateWebsetSearchParametersExcludeSource: () => CreateWebsetSearchParametersExcludeSource,
|
|
38
|
-
CreateWebsetSearchParametersScopeSource: () => CreateWebsetSearchParametersScopeSource,
|
|
39
35
|
EventType: () => EventType,
|
|
40
36
|
EventsClient: () => EventsClient,
|
|
41
37
|
Exa: () => Exa2,
|
|
@@ -51,19 +47,20 @@ __export(index_exports, {
|
|
|
51
47
|
MonitorRunStatus: () => MonitorRunStatus,
|
|
52
48
|
MonitorRunType: () => MonitorRunType,
|
|
53
49
|
MonitorStatus: () => MonitorStatus,
|
|
54
|
-
PreviewWebsetResponseEnrichmentsFormat: () => PreviewWebsetResponseEnrichmentsFormat,
|
|
55
|
-
ScopeSourceType: () => ScopeSourceType,
|
|
56
50
|
UpdateMonitorStatus: () => UpdateMonitorStatus,
|
|
57
51
|
WebhookStatus: () => WebhookStatus,
|
|
58
52
|
WebsetEnrichmentFormat: () => WebsetEnrichmentFormat,
|
|
59
53
|
WebsetEnrichmentStatus: () => WebsetEnrichmentStatus,
|
|
60
54
|
WebsetEnrichmentsClient: () => WebsetEnrichmentsClient,
|
|
55
|
+
WebsetImportSource: () => WebsetImportSource,
|
|
61
56
|
WebsetItemEvaluationSatisfied: () => WebsetItemEvaluationSatisfied,
|
|
62
57
|
WebsetItemSource: () => WebsetItemSource,
|
|
63
58
|
WebsetItemsClient: () => WebsetItemsClient,
|
|
64
59
|
WebsetMonitorsClient: () => WebsetMonitorsClient,
|
|
65
60
|
WebsetSearchBehavior: () => WebsetSearchBehavior,
|
|
66
61
|
WebsetSearchCanceledReason: () => WebsetSearchCanceledReason,
|
|
62
|
+
WebsetSearchExcludeSource: () => WebsetSearchExcludeSource,
|
|
63
|
+
WebsetSearchScopeSource: () => WebsetSearchScopeSource,
|
|
67
64
|
WebsetSearchStatus: () => WebsetSearchStatus,
|
|
68
65
|
WebsetSearchesClient: () => WebsetSearchesClient,
|
|
69
66
|
WebsetStatus: () => WebsetStatus,
|
|
@@ -74,6 +71,89 @@ __export(index_exports, {
|
|
|
74
71
|
module.exports = __toCommonJS(index_exports);
|
|
75
72
|
var import_cross_fetch = __toESM(require("cross-fetch"));
|
|
76
73
|
|
|
74
|
+
// package.json
|
|
75
|
+
var package_default = {
|
|
76
|
+
name: "exa-js",
|
|
77
|
+
version: "1.9.2",
|
|
78
|
+
description: "Exa SDK for Node.js and the browser",
|
|
79
|
+
publishConfig: {
|
|
80
|
+
access: "public"
|
|
81
|
+
},
|
|
82
|
+
files: [
|
|
83
|
+
"dist"
|
|
84
|
+
],
|
|
85
|
+
main: "./dist/index.js",
|
|
86
|
+
module: "./dist/index.mjs",
|
|
87
|
+
exports: {
|
|
88
|
+
".": {
|
|
89
|
+
types: "./dist/index.d.ts",
|
|
90
|
+
require: "./dist/index.js",
|
|
91
|
+
module: "./dist/index.mjs",
|
|
92
|
+
import: "./dist/index.mjs"
|
|
93
|
+
},
|
|
94
|
+
"./package.json": "./package.json"
|
|
95
|
+
},
|
|
96
|
+
types: "./dist/index.d.ts",
|
|
97
|
+
scripts: {
|
|
98
|
+
"build-fast": "tsup src/index.ts --format cjs,esm",
|
|
99
|
+
build: "tsup",
|
|
100
|
+
test: "vitest run",
|
|
101
|
+
typecheck: "tsc --noEmit",
|
|
102
|
+
"typecheck:src": "tsc --noEmit src/**/*.ts",
|
|
103
|
+
"typecheck:examples": "tsc --noEmit examples/**/*.ts",
|
|
104
|
+
"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",
|
|
105
|
+
format: 'prettier --write "src/**/*.ts" "examples/**/*.ts"',
|
|
106
|
+
"format:websets": "prettier --write src/websets/openapi.ts",
|
|
107
|
+
"build:beta": "cross-env NPM_CONFIG_TAG=beta npm run build",
|
|
108
|
+
"version:beta": "npm version prerelease --preid=beta",
|
|
109
|
+
"version:stable": "npm version patch",
|
|
110
|
+
"publish:beta": "npm run version:beta && npm run build:beta && npm publish --tag beta",
|
|
111
|
+
"publish:stable": "npm run version:stable && npm run build && npm publish",
|
|
112
|
+
prepublishOnly: "npm run build"
|
|
113
|
+
},
|
|
114
|
+
license: "MIT",
|
|
115
|
+
devDependencies: {
|
|
116
|
+
"@types/node": "~22.14.0",
|
|
117
|
+
"cross-env": "~7.0.3",
|
|
118
|
+
"openapi-typescript": "~7.6.1",
|
|
119
|
+
prettier: "~3.5.3",
|
|
120
|
+
"ts-node": "~10.9.2",
|
|
121
|
+
tsup: "~8.4.0",
|
|
122
|
+
typescript: "~5.8.3",
|
|
123
|
+
vitest: "~3.1.1"
|
|
124
|
+
},
|
|
125
|
+
dependencies: {
|
|
126
|
+
"cross-fetch": "~4.1.0",
|
|
127
|
+
dotenv: "~16.4.7",
|
|
128
|
+
openai: "^5.0.1",
|
|
129
|
+
zod: "^3.22.0",
|
|
130
|
+
"zod-to-json-schema": "^3.20.0"
|
|
131
|
+
},
|
|
132
|
+
directories: {
|
|
133
|
+
test: "test"
|
|
134
|
+
},
|
|
135
|
+
repository: {
|
|
136
|
+
type: "git",
|
|
137
|
+
url: "git+https://github.com/exa-labs/exa-js.git"
|
|
138
|
+
},
|
|
139
|
+
keywords: [
|
|
140
|
+
"exa",
|
|
141
|
+
"metaphor",
|
|
142
|
+
"search",
|
|
143
|
+
"AI",
|
|
144
|
+
"LLMs",
|
|
145
|
+
"RAG",
|
|
146
|
+
"retrieval",
|
|
147
|
+
"augmented",
|
|
148
|
+
"generation"
|
|
149
|
+
],
|
|
150
|
+
author: "jeffzwang",
|
|
151
|
+
bugs: {
|
|
152
|
+
url: "https://github.com/exa-labs/exa-js/issues"
|
|
153
|
+
},
|
|
154
|
+
homepage: "https://github.com/exa-labs/exa-js#readme"
|
|
155
|
+
};
|
|
156
|
+
|
|
77
157
|
// src/errors.ts
|
|
78
158
|
var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
|
|
79
159
|
HttpStatusCode2[HttpStatusCode2["BadRequest"] = 400] = "BadRequest";
|
|
@@ -103,6 +183,173 @@ var ExaError = class extends Error {
|
|
|
103
183
|
}
|
|
104
184
|
};
|
|
105
185
|
|
|
186
|
+
// src/zod-utils.ts
|
|
187
|
+
var import_zod = require("zod");
|
|
188
|
+
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
189
|
+
function isZodSchema(obj) {
|
|
190
|
+
return obj instanceof import_zod.ZodType;
|
|
191
|
+
}
|
|
192
|
+
function zodToJsonSchema(schema) {
|
|
193
|
+
return (0, import_zod_to_json_schema.zodToJsonSchema)(schema, {
|
|
194
|
+
$refStrategy: "none"
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/research/base.ts
|
|
199
|
+
var ResearchBaseClient = class {
|
|
200
|
+
constructor(client) {
|
|
201
|
+
this.client = client;
|
|
202
|
+
}
|
|
203
|
+
async request(endpoint, method = "POST", data, params) {
|
|
204
|
+
return this.client.request(
|
|
205
|
+
`/research/v1${endpoint}`,
|
|
206
|
+
method,
|
|
207
|
+
data,
|
|
208
|
+
params
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
async rawRequest(endpoint, method = "POST", data, params) {
|
|
212
|
+
return this.client.rawRequest(
|
|
213
|
+
`/research/v1${endpoint}`,
|
|
214
|
+
method,
|
|
215
|
+
data,
|
|
216
|
+
params
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
buildPaginationParams(pagination) {
|
|
220
|
+
const params = {};
|
|
221
|
+
if (!pagination) return params;
|
|
222
|
+
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
223
|
+
if (pagination.limit) params.limit = pagination.limit;
|
|
224
|
+
return params;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// src/research/client.ts
|
|
229
|
+
var ResearchClient = class extends ResearchBaseClient {
|
|
230
|
+
constructor(client) {
|
|
231
|
+
super(client);
|
|
232
|
+
}
|
|
233
|
+
async create(params) {
|
|
234
|
+
const { instructions, model, outputSchema } = params;
|
|
235
|
+
let schema = outputSchema;
|
|
236
|
+
if (schema && isZodSchema(schema)) {
|
|
237
|
+
schema = zodToJsonSchema(schema);
|
|
238
|
+
}
|
|
239
|
+
const payload = {
|
|
240
|
+
instructions,
|
|
241
|
+
model: model ?? "exa-research"
|
|
242
|
+
};
|
|
243
|
+
if (schema) {
|
|
244
|
+
payload.outputSchema = schema;
|
|
245
|
+
}
|
|
246
|
+
return this.request("", "POST", payload);
|
|
247
|
+
}
|
|
248
|
+
get(researchId, options) {
|
|
249
|
+
if (options?.stream) {
|
|
250
|
+
const promise = async () => {
|
|
251
|
+
const params = { stream: "true" };
|
|
252
|
+
if (options.events !== void 0) {
|
|
253
|
+
params.events = options.events.toString();
|
|
254
|
+
}
|
|
255
|
+
const resp = await this.rawRequest(
|
|
256
|
+
`/${researchId}`,
|
|
257
|
+
"GET",
|
|
258
|
+
void 0,
|
|
259
|
+
params
|
|
260
|
+
);
|
|
261
|
+
if (!resp.body) {
|
|
262
|
+
throw new Error("No response body for SSE stream");
|
|
263
|
+
}
|
|
264
|
+
const reader = resp.body.getReader();
|
|
265
|
+
const decoder = new TextDecoder();
|
|
266
|
+
let buffer = "";
|
|
267
|
+
function processPart(part) {
|
|
268
|
+
const lines = part.split("\n");
|
|
269
|
+
let data = lines.slice(1).join("\n");
|
|
270
|
+
if (data.startsWith("data:")) {
|
|
271
|
+
data = data.slice(5).trimStart();
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
return JSON.parse(data);
|
|
275
|
+
} catch (e) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
async function* streamEvents() {
|
|
280
|
+
while (true) {
|
|
281
|
+
const { done, value } = await reader.read();
|
|
282
|
+
if (done) break;
|
|
283
|
+
buffer += decoder.decode(value, { stream: true });
|
|
284
|
+
let parts = buffer.split("\n\n");
|
|
285
|
+
buffer = parts.pop() ?? "";
|
|
286
|
+
for (const part of parts) {
|
|
287
|
+
const processed = processPart(part);
|
|
288
|
+
if (processed) {
|
|
289
|
+
yield processed;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (buffer.trim()) {
|
|
294
|
+
const processed = processPart(buffer.trim());
|
|
295
|
+
if (processed) {
|
|
296
|
+
yield processed;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return streamEvents();
|
|
301
|
+
};
|
|
302
|
+
return promise();
|
|
303
|
+
} else {
|
|
304
|
+
const params = { stream: "false" };
|
|
305
|
+
if (options?.events !== void 0) {
|
|
306
|
+
params.events = options.events.toString();
|
|
307
|
+
}
|
|
308
|
+
return this.request(
|
|
309
|
+
`/${researchId}`,
|
|
310
|
+
"GET",
|
|
311
|
+
void 0,
|
|
312
|
+
params
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
async list(options) {
|
|
317
|
+
const params = this.buildPaginationParams(options);
|
|
318
|
+
return this.request("", "GET", void 0, params);
|
|
319
|
+
}
|
|
320
|
+
async pollUntilFinished(researchId, options) {
|
|
321
|
+
const pollInterval = options?.pollInterval ?? 1e3;
|
|
322
|
+
const timeoutMs = options?.timeoutMs ?? 10 * 60 * 1e3;
|
|
323
|
+
const maxConsecutiveFailures = 5;
|
|
324
|
+
const startTime = Date.now();
|
|
325
|
+
let consecutiveFailures = 0;
|
|
326
|
+
while (true) {
|
|
327
|
+
try {
|
|
328
|
+
const research = await this.get(researchId, {
|
|
329
|
+
events: options?.events
|
|
330
|
+
});
|
|
331
|
+
consecutiveFailures = 0;
|
|
332
|
+
if (research.status === "completed" || research.status === "failed" || research.status === "canceled") {
|
|
333
|
+
return research;
|
|
334
|
+
}
|
|
335
|
+
} catch (err) {
|
|
336
|
+
consecutiveFailures += 1;
|
|
337
|
+
if (consecutiveFailures >= maxConsecutiveFailures) {
|
|
338
|
+
throw new Error(
|
|
339
|
+
`Polling failed ${maxConsecutiveFailures} times in a row for research ${researchId}: ${err}`
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (Date.now() - startTime > timeoutMs) {
|
|
344
|
+
throw new Error(
|
|
345
|
+
`Polling timeout: Research ${researchId} did not complete within ${timeoutMs}ms`
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
106
353
|
// src/websets/base.ts
|
|
107
354
|
var WebsetsBaseClient = class {
|
|
108
355
|
/**
|
|
@@ -183,6 +430,20 @@ var WebsetEnrichmentsClient = class extends WebsetsBaseClient {
|
|
|
183
430
|
"DELETE"
|
|
184
431
|
);
|
|
185
432
|
}
|
|
433
|
+
/**
|
|
434
|
+
* Update an Enrichment
|
|
435
|
+
* @param websetId The ID of the Webset
|
|
436
|
+
* @param id The ID of the Enrichment
|
|
437
|
+
* @param params The enrichment update parameters
|
|
438
|
+
* @returns Promise that resolves when the update is complete
|
|
439
|
+
*/
|
|
440
|
+
async update(websetId, id, params) {
|
|
441
|
+
return this.request(
|
|
442
|
+
`/v0/websets/${websetId}/enrichments/${id}`,
|
|
443
|
+
"PATCH",
|
|
444
|
+
params
|
|
445
|
+
);
|
|
446
|
+
}
|
|
186
447
|
/**
|
|
187
448
|
* Cancel a running Enrichment
|
|
188
449
|
* @param websetId The ID of the Webset
|
|
@@ -242,37 +503,18 @@ var CreateEnrichmentParametersFormat = /* @__PURE__ */ ((CreateEnrichmentParamet
|
|
|
242
503
|
CreateEnrichmentParametersFormat2["options"] = "options";
|
|
243
504
|
CreateEnrichmentParametersFormat2["email"] = "email";
|
|
244
505
|
CreateEnrichmentParametersFormat2["phone"] = "phone";
|
|
506
|
+
CreateEnrichmentParametersFormat2["url"] = "url";
|
|
245
507
|
return CreateEnrichmentParametersFormat2;
|
|
246
508
|
})(CreateEnrichmentParametersFormat || {});
|
|
247
509
|
var CreateImportParametersFormat = /* @__PURE__ */ ((CreateImportParametersFormat2) => {
|
|
248
510
|
CreateImportParametersFormat2["csv"] = "csv";
|
|
249
511
|
return CreateImportParametersFormat2;
|
|
250
512
|
})(CreateImportParametersFormat || {});
|
|
251
|
-
var
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
return
|
|
255
|
-
})(
|
|
256
|
-
var CreateWebsetParametersSearchExcludeSource = /* @__PURE__ */ ((CreateWebsetParametersSearchExcludeSource2) => {
|
|
257
|
-
CreateWebsetParametersSearchExcludeSource2["import"] = "import";
|
|
258
|
-
CreateWebsetParametersSearchExcludeSource2["webset"] = "webset";
|
|
259
|
-
return CreateWebsetParametersSearchExcludeSource2;
|
|
260
|
-
})(CreateWebsetParametersSearchExcludeSource || {});
|
|
261
|
-
var ScopeSourceType = /* @__PURE__ */ ((ScopeSourceType2) => {
|
|
262
|
-
ScopeSourceType2["import"] = "import";
|
|
263
|
-
ScopeSourceType2["webset"] = "webset";
|
|
264
|
-
return ScopeSourceType2;
|
|
265
|
-
})(ScopeSourceType || {});
|
|
266
|
-
var CreateWebsetSearchParametersExcludeSource = /* @__PURE__ */ ((CreateWebsetSearchParametersExcludeSource2) => {
|
|
267
|
-
CreateWebsetSearchParametersExcludeSource2["import"] = "import";
|
|
268
|
-
CreateWebsetSearchParametersExcludeSource2["webset"] = "webset";
|
|
269
|
-
return CreateWebsetSearchParametersExcludeSource2;
|
|
270
|
-
})(CreateWebsetSearchParametersExcludeSource || {});
|
|
271
|
-
var CreateWebsetSearchParametersScopeSource = /* @__PURE__ */ ((CreateWebsetSearchParametersScopeSource2) => {
|
|
272
|
-
CreateWebsetSearchParametersScopeSource2["import"] = "import";
|
|
273
|
-
CreateWebsetSearchParametersScopeSource2["webset"] = "webset";
|
|
274
|
-
return CreateWebsetSearchParametersScopeSource2;
|
|
275
|
-
})(CreateWebsetSearchParametersScopeSource || {});
|
|
513
|
+
var WebsetImportSource = /* @__PURE__ */ ((WebsetImportSource2) => {
|
|
514
|
+
WebsetImportSource2["import"] = "import";
|
|
515
|
+
WebsetImportSource2["webset"] = "webset";
|
|
516
|
+
return WebsetImportSource2;
|
|
517
|
+
})(WebsetImportSource || {});
|
|
276
518
|
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
277
519
|
EventType2["webset_created"] = "webset.created";
|
|
278
520
|
EventType2["webset_deleted"] = "webset.deleted";
|
|
@@ -284,9 +526,13 @@ var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
|
284
526
|
EventType2["webset_search_updated"] = "webset.search.updated";
|
|
285
527
|
EventType2["import_created"] = "import.created";
|
|
286
528
|
EventType2["import_completed"] = "import.completed";
|
|
287
|
-
EventType2["import_processing"] = "import.processing";
|
|
288
529
|
EventType2["webset_item_created"] = "webset.item.created";
|
|
289
530
|
EventType2["webset_item_enriched"] = "webset.item.enriched";
|
|
531
|
+
EventType2["monitor_created"] = "monitor.created";
|
|
532
|
+
EventType2["monitor_updated"] = "monitor.updated";
|
|
533
|
+
EventType2["monitor_deleted"] = "monitor.deleted";
|
|
534
|
+
EventType2["monitor_run_created"] = "monitor.run.created";
|
|
535
|
+
EventType2["monitor_run_completed"] = "monitor.run.completed";
|
|
290
536
|
EventType2["webset_export_created"] = "webset.export.created";
|
|
291
537
|
EventType2["webset_export_completed"] = "webset.export.completed";
|
|
292
538
|
return EventType2;
|
|
@@ -339,15 +585,6 @@ var MonitorRunType = /* @__PURE__ */ ((MonitorRunType2) => {
|
|
|
339
585
|
MonitorRunType2["refresh"] = "refresh";
|
|
340
586
|
return MonitorRunType2;
|
|
341
587
|
})(MonitorRunType || {});
|
|
342
|
-
var PreviewWebsetResponseEnrichmentsFormat = /* @__PURE__ */ ((PreviewWebsetResponseEnrichmentsFormat2) => {
|
|
343
|
-
PreviewWebsetResponseEnrichmentsFormat2["text"] = "text";
|
|
344
|
-
PreviewWebsetResponseEnrichmentsFormat2["date"] = "date";
|
|
345
|
-
PreviewWebsetResponseEnrichmentsFormat2["number"] = "number";
|
|
346
|
-
PreviewWebsetResponseEnrichmentsFormat2["options"] = "options";
|
|
347
|
-
PreviewWebsetResponseEnrichmentsFormat2["email"] = "email";
|
|
348
|
-
PreviewWebsetResponseEnrichmentsFormat2["phone"] = "phone";
|
|
349
|
-
return PreviewWebsetResponseEnrichmentsFormat2;
|
|
350
|
-
})(PreviewWebsetResponseEnrichmentsFormat || {});
|
|
351
588
|
var UpdateMonitorStatus = /* @__PURE__ */ ((UpdateMonitorStatus2) => {
|
|
352
589
|
UpdateMonitorStatus2["enabled"] = "enabled";
|
|
353
590
|
UpdateMonitorStatus2["disabled"] = "disabled";
|
|
@@ -378,6 +615,7 @@ var WebsetEnrichmentFormat = /* @__PURE__ */ ((WebsetEnrichmentFormat2) => {
|
|
|
378
615
|
WebsetEnrichmentFormat2["options"] = "options";
|
|
379
616
|
WebsetEnrichmentFormat2["email"] = "email";
|
|
380
617
|
WebsetEnrichmentFormat2["phone"] = "phone";
|
|
618
|
+
WebsetEnrichmentFormat2["url"] = "url";
|
|
381
619
|
return WebsetEnrichmentFormat2;
|
|
382
620
|
})(WebsetEnrichmentFormat || {});
|
|
383
621
|
var WebsetItemSource = /* @__PURE__ */ ((WebsetItemSource2) => {
|
|
@@ -391,6 +629,16 @@ var WebsetItemEvaluationSatisfied = /* @__PURE__ */ ((WebsetItemEvaluationSatisf
|
|
|
391
629
|
WebsetItemEvaluationSatisfied2["unclear"] = "unclear";
|
|
392
630
|
return WebsetItemEvaluationSatisfied2;
|
|
393
631
|
})(WebsetItemEvaluationSatisfied || {});
|
|
632
|
+
var WebsetSearchExcludeSource = /* @__PURE__ */ ((WebsetSearchExcludeSource2) => {
|
|
633
|
+
WebsetSearchExcludeSource2["import"] = "import";
|
|
634
|
+
WebsetSearchExcludeSource2["webset"] = "webset";
|
|
635
|
+
return WebsetSearchExcludeSource2;
|
|
636
|
+
})(WebsetSearchExcludeSource || {});
|
|
637
|
+
var WebsetSearchScopeSource = /* @__PURE__ */ ((WebsetSearchScopeSource2) => {
|
|
638
|
+
WebsetSearchScopeSource2["import"] = "import";
|
|
639
|
+
WebsetSearchScopeSource2["webset"] = "webset";
|
|
640
|
+
return WebsetSearchScopeSource2;
|
|
641
|
+
})(WebsetSearchScopeSource || {});
|
|
394
642
|
var WebsetSearchStatus = /* @__PURE__ */ ((WebsetSearchStatus2) => {
|
|
395
643
|
WebsetSearchStatus2["created"] = "created";
|
|
396
644
|
WebsetSearchStatus2["pending"] = "pending";
|
|
@@ -1078,173 +1326,6 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
1078
1326
|
}
|
|
1079
1327
|
};
|
|
1080
1328
|
|
|
1081
|
-
// src/zod-utils.ts
|
|
1082
|
-
var import_zod = require("zod");
|
|
1083
|
-
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
1084
|
-
function isZodSchema(obj) {
|
|
1085
|
-
return obj instanceof import_zod.ZodType;
|
|
1086
|
-
}
|
|
1087
|
-
function zodToJsonSchema(schema) {
|
|
1088
|
-
return (0, import_zod_to_json_schema.zodToJsonSchema)(schema, {
|
|
1089
|
-
$refStrategy: "none"
|
|
1090
|
-
});
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
// src/research/base.ts
|
|
1094
|
-
var ResearchBaseClient = class {
|
|
1095
|
-
constructor(client) {
|
|
1096
|
-
this.client = client;
|
|
1097
|
-
}
|
|
1098
|
-
async request(endpoint, method = "POST", data, params) {
|
|
1099
|
-
return this.client.request(
|
|
1100
|
-
`/research/v1${endpoint}`,
|
|
1101
|
-
method,
|
|
1102
|
-
data,
|
|
1103
|
-
params
|
|
1104
|
-
);
|
|
1105
|
-
}
|
|
1106
|
-
async rawRequest(endpoint, method = "POST", data, params) {
|
|
1107
|
-
return this.client.rawRequest(
|
|
1108
|
-
`/research/v1${endpoint}`,
|
|
1109
|
-
method,
|
|
1110
|
-
data,
|
|
1111
|
-
params
|
|
1112
|
-
);
|
|
1113
|
-
}
|
|
1114
|
-
buildPaginationParams(pagination) {
|
|
1115
|
-
const params = {};
|
|
1116
|
-
if (!pagination) return params;
|
|
1117
|
-
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
1118
|
-
if (pagination.limit) params.limit = pagination.limit;
|
|
1119
|
-
return params;
|
|
1120
|
-
}
|
|
1121
|
-
};
|
|
1122
|
-
|
|
1123
|
-
// src/research/client.ts
|
|
1124
|
-
var ResearchClient = class extends ResearchBaseClient {
|
|
1125
|
-
constructor(client) {
|
|
1126
|
-
super(client);
|
|
1127
|
-
}
|
|
1128
|
-
async create(params) {
|
|
1129
|
-
const { instructions, model, outputSchema } = params;
|
|
1130
|
-
let schema = outputSchema;
|
|
1131
|
-
if (schema && isZodSchema(schema)) {
|
|
1132
|
-
schema = zodToJsonSchema(schema);
|
|
1133
|
-
}
|
|
1134
|
-
const payload = {
|
|
1135
|
-
instructions,
|
|
1136
|
-
model: model ?? "exa-research"
|
|
1137
|
-
};
|
|
1138
|
-
if (schema) {
|
|
1139
|
-
payload.outputSchema = schema;
|
|
1140
|
-
}
|
|
1141
|
-
return this.request("", "POST", payload);
|
|
1142
|
-
}
|
|
1143
|
-
get(researchId, options) {
|
|
1144
|
-
if (options?.stream) {
|
|
1145
|
-
const promise = async () => {
|
|
1146
|
-
const params = { stream: "true" };
|
|
1147
|
-
if (options.events !== void 0) {
|
|
1148
|
-
params.events = options.events.toString();
|
|
1149
|
-
}
|
|
1150
|
-
const resp = await this.rawRequest(
|
|
1151
|
-
`/${researchId}`,
|
|
1152
|
-
"GET",
|
|
1153
|
-
void 0,
|
|
1154
|
-
params
|
|
1155
|
-
);
|
|
1156
|
-
if (!resp.body) {
|
|
1157
|
-
throw new Error("No response body for SSE stream");
|
|
1158
|
-
}
|
|
1159
|
-
const reader = resp.body.getReader();
|
|
1160
|
-
const decoder = new TextDecoder();
|
|
1161
|
-
let buffer = "";
|
|
1162
|
-
function processPart(part) {
|
|
1163
|
-
const lines = part.split("\n");
|
|
1164
|
-
let data = lines.slice(1).join("\n");
|
|
1165
|
-
if (data.startsWith("data:")) {
|
|
1166
|
-
data = data.slice(5).trimStart();
|
|
1167
|
-
}
|
|
1168
|
-
try {
|
|
1169
|
-
return JSON.parse(data);
|
|
1170
|
-
} catch (e) {
|
|
1171
|
-
return null;
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
async function* streamEvents() {
|
|
1175
|
-
while (true) {
|
|
1176
|
-
const { done, value } = await reader.read();
|
|
1177
|
-
if (done) break;
|
|
1178
|
-
buffer += decoder.decode(value, { stream: true });
|
|
1179
|
-
let parts = buffer.split("\n\n");
|
|
1180
|
-
buffer = parts.pop() ?? "";
|
|
1181
|
-
for (const part of parts) {
|
|
1182
|
-
const processed = processPart(part);
|
|
1183
|
-
if (processed) {
|
|
1184
|
-
yield processed;
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
if (buffer.trim()) {
|
|
1189
|
-
const processed = processPart(buffer.trim());
|
|
1190
|
-
if (processed) {
|
|
1191
|
-
yield processed;
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
return streamEvents();
|
|
1196
|
-
};
|
|
1197
|
-
return promise();
|
|
1198
|
-
} else {
|
|
1199
|
-
const params = { stream: "false" };
|
|
1200
|
-
if (options?.events !== void 0) {
|
|
1201
|
-
params.events = options.events.toString();
|
|
1202
|
-
}
|
|
1203
|
-
return this.request(
|
|
1204
|
-
`/${researchId}`,
|
|
1205
|
-
"GET",
|
|
1206
|
-
void 0,
|
|
1207
|
-
params
|
|
1208
|
-
);
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
async list(options) {
|
|
1212
|
-
const params = this.buildPaginationParams(options);
|
|
1213
|
-
return this.request("", "GET", void 0, params);
|
|
1214
|
-
}
|
|
1215
|
-
async pollUntilFinished(researchId, options) {
|
|
1216
|
-
const pollInterval = options?.pollInterval ?? 1e3;
|
|
1217
|
-
const timeoutMs = options?.timeoutMs ?? 10 * 60 * 1e3;
|
|
1218
|
-
const maxConsecutiveFailures = 5;
|
|
1219
|
-
const startTime = Date.now();
|
|
1220
|
-
let consecutiveFailures = 0;
|
|
1221
|
-
while (true) {
|
|
1222
|
-
try {
|
|
1223
|
-
const research = await this.get(researchId, {
|
|
1224
|
-
events: options?.events
|
|
1225
|
-
});
|
|
1226
|
-
consecutiveFailures = 0;
|
|
1227
|
-
if (research.status === "completed" || research.status === "failed" || research.status === "canceled") {
|
|
1228
|
-
return research;
|
|
1229
|
-
}
|
|
1230
|
-
} catch (err) {
|
|
1231
|
-
consecutiveFailures += 1;
|
|
1232
|
-
if (consecutiveFailures >= maxConsecutiveFailures) {
|
|
1233
|
-
throw new Error(
|
|
1234
|
-
`Polling failed ${maxConsecutiveFailures} times in a row for research ${researchId}: ${err}`
|
|
1235
|
-
);
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
if (Date.now() - startTime > timeoutMs) {
|
|
1239
|
-
throw new Error(
|
|
1240
|
-
`Polling timeout: Research ${researchId} did not complete within ${timeoutMs}ms`
|
|
1241
|
-
);
|
|
1242
|
-
}
|
|
1243
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
};
|
|
1247
|
-
|
|
1248
1329
|
// src/index.ts
|
|
1249
1330
|
var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : import_cross_fetch.default;
|
|
1250
1331
|
var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : import_cross_fetch.Headers;
|
|
@@ -1313,7 +1394,7 @@ var Exa2 = class {
|
|
|
1313
1394
|
this.headers = new HeadersImpl({
|
|
1314
1395
|
"x-api-key": apiKey,
|
|
1315
1396
|
"Content-Type": "application/json",
|
|
1316
|
-
"User-Agent":
|
|
1397
|
+
"User-Agent": `exa-node ${package_default.version}`
|
|
1317
1398
|
});
|
|
1318
1399
|
this.websets = new WebsetsClient(this);
|
|
1319
1400
|
this.research = new ResearchClient(this);
|
|
@@ -1673,10 +1754,6 @@ var index_default = Exa2;
|
|
|
1673
1754
|
0 && (module.exports = {
|
|
1674
1755
|
CreateEnrichmentParametersFormat,
|
|
1675
1756
|
CreateImportParametersFormat,
|
|
1676
|
-
CreateWebsetParametersImportSource,
|
|
1677
|
-
CreateWebsetParametersSearchExcludeSource,
|
|
1678
|
-
CreateWebsetSearchParametersExcludeSource,
|
|
1679
|
-
CreateWebsetSearchParametersScopeSource,
|
|
1680
1757
|
EventType,
|
|
1681
1758
|
EventsClient,
|
|
1682
1759
|
Exa,
|
|
@@ -1692,19 +1769,20 @@ var index_default = Exa2;
|
|
|
1692
1769
|
MonitorRunStatus,
|
|
1693
1770
|
MonitorRunType,
|
|
1694
1771
|
MonitorStatus,
|
|
1695
|
-
PreviewWebsetResponseEnrichmentsFormat,
|
|
1696
|
-
ScopeSourceType,
|
|
1697
1772
|
UpdateMonitorStatus,
|
|
1698
1773
|
WebhookStatus,
|
|
1699
1774
|
WebsetEnrichmentFormat,
|
|
1700
1775
|
WebsetEnrichmentStatus,
|
|
1701
1776
|
WebsetEnrichmentsClient,
|
|
1777
|
+
WebsetImportSource,
|
|
1702
1778
|
WebsetItemEvaluationSatisfied,
|
|
1703
1779
|
WebsetItemSource,
|
|
1704
1780
|
WebsetItemsClient,
|
|
1705
1781
|
WebsetMonitorsClient,
|
|
1706
1782
|
WebsetSearchBehavior,
|
|
1707
1783
|
WebsetSearchCanceledReason,
|
|
1784
|
+
WebsetSearchExcludeSource,
|
|
1785
|
+
WebsetSearchScopeSource,
|
|
1708
1786
|
WebsetSearchStatus,
|
|
1709
1787
|
WebsetSearchesClient,
|
|
1710
1788
|
WebsetStatus,
|