exa-js 2.5.1-beta.3 → 2.6.1
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 +15 -1
- package/dist/index.d.mts +291 -8722
- package/dist/index.d.ts +291 -8722
- package/dist/index.js +69 -909
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -906
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -33,16 +33,15 @@ __export(index_exports, {
|
|
|
33
33
|
CreateEnrichmentParametersFormat: () => CreateEnrichmentParametersFormat,
|
|
34
34
|
CreateImportParametersFormat: () => CreateImportParametersFormat,
|
|
35
35
|
EventType: () => EventType,
|
|
36
|
-
EventsClient: () =>
|
|
37
|
-
Exa: () =>
|
|
36
|
+
EventsClient: () => EventsClient,
|
|
37
|
+
Exa: () => Exa2,
|
|
38
38
|
ExaError: () => ExaError,
|
|
39
|
-
ExaNova: () => Exa,
|
|
40
39
|
HttpStatusCode: () => HttpStatusCode,
|
|
41
40
|
ImportFailedReason: () => ImportFailedReason,
|
|
42
41
|
ImportFormat: () => ImportFormat,
|
|
43
42
|
ImportObject: () => ImportObject,
|
|
44
43
|
ImportStatus: () => ImportStatus,
|
|
45
|
-
ImportsClient: () =>
|
|
44
|
+
ImportsClient: () => ImportsClient,
|
|
46
45
|
MonitorObject: () => MonitorObject,
|
|
47
46
|
MonitorRunObject: () => MonitorRunObject,
|
|
48
47
|
MonitorRunStatus: () => MonitorRunStatus,
|
|
@@ -52,21 +51,21 @@ __export(index_exports, {
|
|
|
52
51
|
WebhookStatus: () => WebhookStatus,
|
|
53
52
|
WebsetEnrichmentFormat: () => WebsetEnrichmentFormat,
|
|
54
53
|
WebsetEnrichmentStatus: () => WebsetEnrichmentStatus,
|
|
55
|
-
WebsetEnrichmentsClient: () =>
|
|
54
|
+
WebsetEnrichmentsClient: () => WebsetEnrichmentsClient,
|
|
56
55
|
WebsetExcludeSource: () => WebsetExcludeSource,
|
|
57
56
|
WebsetImportSource: () => WebsetImportSource,
|
|
58
57
|
WebsetItemEvaluationSatisfied: () => WebsetItemEvaluationSatisfied,
|
|
59
58
|
WebsetItemSource: () => WebsetItemSource,
|
|
60
|
-
WebsetItemsClient: () =>
|
|
61
|
-
WebsetMonitorsClient: () =>
|
|
59
|
+
WebsetItemsClient: () => WebsetItemsClient,
|
|
60
|
+
WebsetMonitorsClient: () => WebsetMonitorsClient,
|
|
62
61
|
WebsetSearchBehavior: () => WebsetSearchBehavior,
|
|
63
62
|
WebsetSearchCanceledReason: () => WebsetSearchCanceledReason,
|
|
64
63
|
WebsetSearchScopeSource: () => WebsetSearchScopeSource,
|
|
65
64
|
WebsetSearchStatus: () => WebsetSearchStatus,
|
|
66
|
-
WebsetSearchesClient: () =>
|
|
65
|
+
WebsetSearchesClient: () => WebsetSearchesClient,
|
|
67
66
|
WebsetStatus: () => WebsetStatus,
|
|
68
|
-
WebsetWebhooksClient: () =>
|
|
69
|
-
WebsetsClient: () =>
|
|
67
|
+
WebsetWebhooksClient: () => WebsetWebhooksClient,
|
|
68
|
+
WebsetsClient: () => WebsetsClient,
|
|
70
69
|
default: () => index_default
|
|
71
70
|
});
|
|
72
71
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -75,7 +74,7 @@ var import_cross_fetch = __toESM(require("cross-fetch"));
|
|
|
75
74
|
// package.json
|
|
76
75
|
var package_default = {
|
|
77
76
|
name: "exa-js",
|
|
78
|
-
version: "2.
|
|
77
|
+
version: "2.6.1",
|
|
79
78
|
description: "Exa SDK for Node.js and the browser",
|
|
80
79
|
publishConfig: {
|
|
81
80
|
access: "public"
|
|
@@ -159,860 +158,6 @@ var package_default = {
|
|
|
159
158
|
homepage: "https://github.com/exa-labs/exa-js#readme"
|
|
160
159
|
};
|
|
161
160
|
|
|
162
|
-
// src/nova/websets-client.ts
|
|
163
|
-
var WebsetsBaseClient = class {
|
|
164
|
-
constructor(client) {
|
|
165
|
-
this.client = client;
|
|
166
|
-
}
|
|
167
|
-
/** Make a request to the API, prepending `/websets` to the path. */
|
|
168
|
-
async request(endpoint, method = "POST", data, params, headers) {
|
|
169
|
-
return this.client.request(`/websets${endpoint}`, method, data, params, headers);
|
|
170
|
-
}
|
|
171
|
-
buildPaginationParams(pagination) {
|
|
172
|
-
const params = {};
|
|
173
|
-
if (!pagination) return params;
|
|
174
|
-
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
175
|
-
if (pagination.limit) params.limit = pagination.limit;
|
|
176
|
-
return params;
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
var WebsetItemsClient = class extends WebsetsBaseClient {
|
|
180
|
-
async get(websetId, id) {
|
|
181
|
-
return this.request(`/v0/websets/${websetId}/items/${id}`, "GET");
|
|
182
|
-
}
|
|
183
|
-
async delete(websetId, id) {
|
|
184
|
-
return this.request(`/v0/websets/${websetId}/items/${id}`, "DELETE");
|
|
185
|
-
}
|
|
186
|
-
async list(websetId, options) {
|
|
187
|
-
const queryParams = { ...this.buildPaginationParams(options), sourceId: options?.sourceId };
|
|
188
|
-
return this.request(`/v0/websets/${websetId}/items`, "GET", void 0, queryParams);
|
|
189
|
-
}
|
|
190
|
-
/** Iterate through all items in a Webset, handling pagination automatically. */
|
|
191
|
-
async *listAll(websetId, options) {
|
|
192
|
-
let cursor = void 0;
|
|
193
|
-
const pageOptions = options ? { ...options } : {};
|
|
194
|
-
while (true) {
|
|
195
|
-
const response = await this.list(websetId, { ...pageOptions, cursor });
|
|
196
|
-
for (const item of response.data) {
|
|
197
|
-
yield item;
|
|
198
|
-
}
|
|
199
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
cursor = response.nextCursor;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
/** Collect all items from a Webset into an array. */
|
|
206
|
-
async getAll(websetId, options) {
|
|
207
|
-
const items = [];
|
|
208
|
-
for await (const item of this.listAll(websetId, options)) {
|
|
209
|
-
items.push(item);
|
|
210
|
-
}
|
|
211
|
-
return items;
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
var WebsetSearchesClient = class extends WebsetsBaseClient {
|
|
215
|
-
async create(websetId, params, options) {
|
|
216
|
-
return this.request(`/v0/websets/${websetId}/searches`, "POST", { ...params }, void 0, options?.headers);
|
|
217
|
-
}
|
|
218
|
-
async get(websetId, id) {
|
|
219
|
-
return this.request(`/v0/websets/${websetId}/searches/${id}`, "GET");
|
|
220
|
-
}
|
|
221
|
-
async cancel(websetId, id) {
|
|
222
|
-
return this.request(`/v0/websets/${websetId}/searches/${id}/cancel`, "POST");
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
var WebsetEnrichmentsClient = class extends WebsetsBaseClient {
|
|
226
|
-
async create(websetId, params) {
|
|
227
|
-
return this.request(`/v0/websets/${websetId}/enrichments`, "POST", { ...params });
|
|
228
|
-
}
|
|
229
|
-
async update(websetId, id, params) {
|
|
230
|
-
return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "PATCH", { ...params });
|
|
231
|
-
}
|
|
232
|
-
async get(websetId, id) {
|
|
233
|
-
return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "GET");
|
|
234
|
-
}
|
|
235
|
-
async delete(websetId, id) {
|
|
236
|
-
return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "DELETE");
|
|
237
|
-
}
|
|
238
|
-
async cancel(websetId, id) {
|
|
239
|
-
return this.request(`/v0/websets/${websetId}/enrichments/${id}/cancel`, "POST");
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
var EventsClient = class extends WebsetsBaseClient {
|
|
243
|
-
async list(options) {
|
|
244
|
-
const queryParams = { ...this.buildPaginationParams(options), types: options?.types, createdBefore: options?.createdBefore, createdAfter: options?.createdAfter };
|
|
245
|
-
return this.request("/v0/events", "GET", void 0, queryParams);
|
|
246
|
-
}
|
|
247
|
-
async get(id) {
|
|
248
|
-
return this.request(`/v0/events/${id}`, "GET");
|
|
249
|
-
}
|
|
250
|
-
/** Iterate through all events, handling pagination automatically. */
|
|
251
|
-
async *listAll(options) {
|
|
252
|
-
let cursor = void 0;
|
|
253
|
-
const pageOptions = options ? { ...options } : {};
|
|
254
|
-
while (true) {
|
|
255
|
-
const response = await this.list({ ...pageOptions, cursor });
|
|
256
|
-
for (const event of response.data) {
|
|
257
|
-
yield event;
|
|
258
|
-
}
|
|
259
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
260
|
-
break;
|
|
261
|
-
}
|
|
262
|
-
cursor = response.nextCursor;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
/** Collect all events into an array. */
|
|
266
|
-
async getAll(options) {
|
|
267
|
-
const events = [];
|
|
268
|
-
for await (const event of this.listAll(options)) {
|
|
269
|
-
events.push(event);
|
|
270
|
-
}
|
|
271
|
-
return events;
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
var WebsetMonitorRunsClient = class extends WebsetsBaseClient {
|
|
275
|
-
async list(monitorId) {
|
|
276
|
-
return this.request(`/v0/monitors/${monitorId}/runs`, "GET");
|
|
277
|
-
}
|
|
278
|
-
async get(monitorId, id) {
|
|
279
|
-
return this.request(`/v0/monitors/${monitorId}/runs/${id}`, "GET");
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
var WebsetMonitorsClient = class extends WebsetsBaseClient {
|
|
283
|
-
constructor(client) {
|
|
284
|
-
super(client);
|
|
285
|
-
this.runs = new WebsetMonitorRunsClient(client);
|
|
286
|
-
}
|
|
287
|
-
async create(params) {
|
|
288
|
-
return this.request("/v0/monitors", "POST", { ...params });
|
|
289
|
-
}
|
|
290
|
-
async list(options) {
|
|
291
|
-
const queryParams = { ...this.buildPaginationParams(options), websetId: options?.websetId };
|
|
292
|
-
return this.request("/v0/monitors", "GET", void 0, queryParams);
|
|
293
|
-
}
|
|
294
|
-
async get(id) {
|
|
295
|
-
return this.request(`/v0/monitors/${id}`, "GET");
|
|
296
|
-
}
|
|
297
|
-
async update(id, params) {
|
|
298
|
-
return this.request(`/v0/monitors/${id}`, "PATCH", { ...params });
|
|
299
|
-
}
|
|
300
|
-
async delete(id) {
|
|
301
|
-
return this.request(`/v0/monitors/${id}`, "DELETE");
|
|
302
|
-
}
|
|
303
|
-
/** Iterate through all monitors, handling pagination automatically. */
|
|
304
|
-
async *listAll(options) {
|
|
305
|
-
let cursor = void 0;
|
|
306
|
-
const pageOptions = options ? { ...options } : {};
|
|
307
|
-
while (true) {
|
|
308
|
-
const response = await this.list({ ...pageOptions, cursor });
|
|
309
|
-
for (const monitor of response.data) {
|
|
310
|
-
yield monitor;
|
|
311
|
-
}
|
|
312
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
313
|
-
break;
|
|
314
|
-
}
|
|
315
|
-
cursor = response.nextCursor;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
/** Collect all monitors into an array. */
|
|
319
|
-
async getAll(options) {
|
|
320
|
-
const monitors = [];
|
|
321
|
-
for await (const monitor of this.listAll(options)) {
|
|
322
|
-
monitors.push(monitor);
|
|
323
|
-
}
|
|
324
|
-
return monitors;
|
|
325
|
-
}
|
|
326
|
-
};
|
|
327
|
-
var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
328
|
-
async create(params) {
|
|
329
|
-
return this.request("/v0/webhooks", "POST", { ...params });
|
|
330
|
-
}
|
|
331
|
-
async list(options) {
|
|
332
|
-
const queryParams = this.buildPaginationParams(options);
|
|
333
|
-
return this.request("/v0/webhooks", "GET", void 0, queryParams);
|
|
334
|
-
}
|
|
335
|
-
async get(id) {
|
|
336
|
-
return this.request(`/v0/webhooks/${id}`, "GET");
|
|
337
|
-
}
|
|
338
|
-
async update(id, params) {
|
|
339
|
-
return this.request(`/v0/webhooks/${id}`, "PATCH", { ...params });
|
|
340
|
-
}
|
|
341
|
-
async delete(id) {
|
|
342
|
-
return this.request(`/v0/webhooks/${id}`, "DELETE");
|
|
343
|
-
}
|
|
344
|
-
async listAttempts(id, options) {
|
|
345
|
-
const queryParams = { ...this.buildPaginationParams(options), eventType: options?.eventType, successful: options?.successful };
|
|
346
|
-
return this.request(`/v0/webhooks/${id}/attempts`, "GET", void 0, queryParams);
|
|
347
|
-
}
|
|
348
|
-
/** Iterate through all webhooks, handling pagination automatically. */
|
|
349
|
-
async *listAll(options) {
|
|
350
|
-
let cursor = void 0;
|
|
351
|
-
const pageOptions = options ? { ...options } : {};
|
|
352
|
-
while (true) {
|
|
353
|
-
const response = await this.list({ ...pageOptions, cursor });
|
|
354
|
-
for (const webhook of response.data) {
|
|
355
|
-
yield webhook;
|
|
356
|
-
}
|
|
357
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
358
|
-
break;
|
|
359
|
-
}
|
|
360
|
-
cursor = response.nextCursor;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
/** Collect all webhooks into an array. */
|
|
364
|
-
async getAll(options) {
|
|
365
|
-
const webhooks = [];
|
|
366
|
-
for await (const webhook of this.listAll(options)) {
|
|
367
|
-
webhooks.push(webhook);
|
|
368
|
-
}
|
|
369
|
-
return webhooks;
|
|
370
|
-
}
|
|
371
|
-
/** Iterate through all webhook attempts, handling pagination automatically. */
|
|
372
|
-
async *listAllAttempts(id, options) {
|
|
373
|
-
let cursor = void 0;
|
|
374
|
-
const pageOptions = options ? { ...options } : {};
|
|
375
|
-
while (true) {
|
|
376
|
-
const response = await this.listAttempts(id, { ...pageOptions, cursor });
|
|
377
|
-
for (const attempt of response.data) {
|
|
378
|
-
yield attempt;
|
|
379
|
-
}
|
|
380
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
381
|
-
break;
|
|
382
|
-
}
|
|
383
|
-
cursor = response.nextCursor;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
/** Collect all webhook attempts into an array. */
|
|
387
|
-
async getAllAttempts(id, options) {
|
|
388
|
-
const attempts = [];
|
|
389
|
-
for await (const attempt of this.listAllAttempts(id, options)) {
|
|
390
|
-
attempts.push(attempt);
|
|
391
|
-
}
|
|
392
|
-
return attempts;
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
var ImportsClient = class extends WebsetsBaseClient {
|
|
396
|
-
async create(params) {
|
|
397
|
-
return this.request("/v0/imports", "POST", { ...params });
|
|
398
|
-
}
|
|
399
|
-
async list(options) {
|
|
400
|
-
const queryParams = this.buildPaginationParams(options);
|
|
401
|
-
return this.request("/v0/imports", "GET", void 0, queryParams);
|
|
402
|
-
}
|
|
403
|
-
async get(id) {
|
|
404
|
-
return this.request(`/v0/imports/${id}`, "GET");
|
|
405
|
-
}
|
|
406
|
-
async update(id, params) {
|
|
407
|
-
return this.request(`/v0/imports/${id}`, "PATCH", { ...params });
|
|
408
|
-
}
|
|
409
|
-
async delete(id) {
|
|
410
|
-
return this.request(`/v0/imports/${id}`, "DELETE");
|
|
411
|
-
}
|
|
412
|
-
/** Wait for an import to reach a terminal status. */
|
|
413
|
-
async waitUntilCompleted(id, options) {
|
|
414
|
-
const timeout = options?.timeout ?? 30 * 60 * 1e3;
|
|
415
|
-
const pollInterval = options?.pollInterval ?? 2e3;
|
|
416
|
-
const startTime = Date.now();
|
|
417
|
-
while (true) {
|
|
418
|
-
const importItem = await this.get(id);
|
|
419
|
-
if (options?.onPoll) {
|
|
420
|
-
options.onPoll(importItem.status);
|
|
421
|
-
}
|
|
422
|
-
if (importItem.status === "completed") {
|
|
423
|
-
return importItem;
|
|
424
|
-
}
|
|
425
|
-
if (importItem.status === "failed") {
|
|
426
|
-
throw new Error(`Import ${id} failed: ${importItem.failedMessage ?? "Unknown error"}`);
|
|
427
|
-
}
|
|
428
|
-
if (Date.now() - startTime > timeout) {
|
|
429
|
-
throw new Error(`Import ${id} did not complete within ${timeout}ms. Current status: ${importItem.status}`);
|
|
430
|
-
}
|
|
431
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
/** Iterate through all imports, handling pagination automatically. */
|
|
435
|
-
async *listAll(options) {
|
|
436
|
-
let cursor = void 0;
|
|
437
|
-
const pageOptions = options ? { ...options } : {};
|
|
438
|
-
while (true) {
|
|
439
|
-
const response = await this.list({ ...pageOptions, cursor });
|
|
440
|
-
for (const importItem of response.data) {
|
|
441
|
-
yield importItem;
|
|
442
|
-
}
|
|
443
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
444
|
-
break;
|
|
445
|
-
}
|
|
446
|
-
cursor = response.nextCursor;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
/** Collect all imports into an array. */
|
|
450
|
-
async getAll(options) {
|
|
451
|
-
const imports = [];
|
|
452
|
-
for await (const importItem of this.listAll(options)) {
|
|
453
|
-
imports.push(importItem);
|
|
454
|
-
}
|
|
455
|
-
return imports;
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
var WebsetsClient = class extends WebsetsBaseClient {
|
|
459
|
-
constructor(client) {
|
|
460
|
-
super(client);
|
|
461
|
-
this.items = new WebsetItemsClient(client);
|
|
462
|
-
this.searches = new WebsetSearchesClient(client);
|
|
463
|
-
this.enrichments = new WebsetEnrichmentsClient(client);
|
|
464
|
-
this.events = new EventsClient(client);
|
|
465
|
-
this.monitors = new WebsetMonitorsClient(client);
|
|
466
|
-
this.webhooks = new WebsetWebhooksClient(client);
|
|
467
|
-
this.imports = new ImportsClient(client);
|
|
468
|
-
}
|
|
469
|
-
async create(params, options) {
|
|
470
|
-
return this.request("/v0/websets", "POST", { ...params }, void 0, options?.headers);
|
|
471
|
-
}
|
|
472
|
-
async list(options) {
|
|
473
|
-
const queryParams = { ...this.buildPaginationParams(options), search: options?.search };
|
|
474
|
-
return this.request("/v0/websets", "GET", void 0, queryParams);
|
|
475
|
-
}
|
|
476
|
-
async get(id, options) {
|
|
477
|
-
const queryParams = { expand: options?.expand };
|
|
478
|
-
return this.request(`/v0/websets/${id}`, "GET", void 0, queryParams);
|
|
479
|
-
}
|
|
480
|
-
async update(id, params) {
|
|
481
|
-
return this.request(`/v0/websets/${id}`, "POST", { ...params });
|
|
482
|
-
}
|
|
483
|
-
async delete(id) {
|
|
484
|
-
return this.request(`/v0/websets/${id}`, "DELETE");
|
|
485
|
-
}
|
|
486
|
-
async cancel(id) {
|
|
487
|
-
return this.request(`/v0/websets/${id}/cancel`, "POST");
|
|
488
|
-
}
|
|
489
|
-
async preview(params, options) {
|
|
490
|
-
const queryParams = { search: options?.search };
|
|
491
|
-
return this.request("/v0/websets/preview", "POST", { ...params }, queryParams);
|
|
492
|
-
}
|
|
493
|
-
/** Iterate through all Websets, handling pagination automatically. */
|
|
494
|
-
async *listAll(options) {
|
|
495
|
-
let cursor = void 0;
|
|
496
|
-
const pageOptions = options ? { ...options } : {};
|
|
497
|
-
while (true) {
|
|
498
|
-
const response = await this.list({ ...pageOptions, cursor });
|
|
499
|
-
for (const webset of response.data) {
|
|
500
|
-
yield webset;
|
|
501
|
-
}
|
|
502
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
503
|
-
break;
|
|
504
|
-
}
|
|
505
|
-
cursor = response.nextCursor;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
/** Collect all Websets into an array. */
|
|
509
|
-
async getAll(options) {
|
|
510
|
-
const websets = [];
|
|
511
|
-
for await (const webset of this.listAll(options)) {
|
|
512
|
-
websets.push(webset);
|
|
513
|
-
}
|
|
514
|
-
return websets;
|
|
515
|
-
}
|
|
516
|
-
/** Poll until a Webset reaches idle status. */
|
|
517
|
-
async waitUntilIdle(id, options) {
|
|
518
|
-
let timeout;
|
|
519
|
-
let pollInterval = 1e3;
|
|
520
|
-
let onPoll;
|
|
521
|
-
if (typeof options === "number") {
|
|
522
|
-
timeout = options;
|
|
523
|
-
} else if (options) {
|
|
524
|
-
timeout = options.timeout;
|
|
525
|
-
pollInterval = options.pollInterval || 1e3;
|
|
526
|
-
onPoll = options.onPoll;
|
|
527
|
-
}
|
|
528
|
-
const startTime = Date.now();
|
|
529
|
-
while (true) {
|
|
530
|
-
const webset = await this.get(id);
|
|
531
|
-
if (onPoll) onPoll(webset.status);
|
|
532
|
-
if (webset.status === "idle") return webset;
|
|
533
|
-
if (timeout && Date.now() - startTime > timeout) {
|
|
534
|
-
throw new Error(`Webset ${id} did not reach idle state within ${timeout}ms. Current status: ${webset.status}`);
|
|
535
|
-
}
|
|
536
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
};
|
|
540
|
-
|
|
541
|
-
// src/nova/research-client.ts
|
|
542
|
-
var import_zod = require("zod");
|
|
543
|
-
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
544
|
-
function zodToJsonSchema(schema) {
|
|
545
|
-
return (0, import_zod_to_json_schema.zodToJsonSchema)(schema, { $refStrategy: "none" });
|
|
546
|
-
}
|
|
547
|
-
var ResearchBaseClient = class {
|
|
548
|
-
constructor(client) {
|
|
549
|
-
this.client = client;
|
|
550
|
-
}
|
|
551
|
-
/** Make a request to the API, prepending `/research/v1` to the path. */
|
|
552
|
-
async request(endpoint, method = "POST", data, params) {
|
|
553
|
-
return this.client.request(`/research/v1${endpoint}`, method, data, params);
|
|
554
|
-
}
|
|
555
|
-
buildPaginationParams(pagination) {
|
|
556
|
-
const params = {};
|
|
557
|
-
if (!pagination) return params;
|
|
558
|
-
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
559
|
-
if (pagination.limit) params.limit = pagination.limit;
|
|
560
|
-
return params;
|
|
561
|
-
}
|
|
562
|
-
};
|
|
563
|
-
var ResearchClient = class extends ResearchBaseClient {
|
|
564
|
-
/** List research requests. */
|
|
565
|
-
async list(options) {
|
|
566
|
-
const params = this.buildPaginationParams(options);
|
|
567
|
-
return this.client.request("/research/v1", "GET", void 0, params);
|
|
568
|
-
}
|
|
569
|
-
/** Create a new research request. Defaults model to "exa-research-fast" if not provided. */
|
|
570
|
-
async create(params) {
|
|
571
|
-
let schema = params.outputSchema;
|
|
572
|
-
if (schema instanceof import_zod.ZodType) {
|
|
573
|
-
schema = zodToJsonSchema(schema);
|
|
574
|
-
}
|
|
575
|
-
const payload = {
|
|
576
|
-
instructions: params.instructions,
|
|
577
|
-
model: params.model ?? "exa-research-fast"
|
|
578
|
-
};
|
|
579
|
-
if (schema) {
|
|
580
|
-
payload.outputSchema = schema;
|
|
581
|
-
}
|
|
582
|
-
return this.client.request("/research/v1", "POST", payload, void 0);
|
|
583
|
-
}
|
|
584
|
-
async get(researchId, options) {
|
|
585
|
-
const params = {};
|
|
586
|
-
if (options?.events !== void 0) params.events = options.events.toString();
|
|
587
|
-
if (options?.stream) {
|
|
588
|
-
params.stream = "true";
|
|
589
|
-
const response = await this.client.rawRequest(`/research/v1/${researchId}`, "GET", void 0, params);
|
|
590
|
-
if (!response.ok) {
|
|
591
|
-
const message = await response.text();
|
|
592
|
-
throw new Error(`Research stream request failed (${response.status}): ${message}`);
|
|
593
|
-
}
|
|
594
|
-
const reader = response.body?.getReader();
|
|
595
|
-
if (!reader) {
|
|
596
|
-
throw new Error("No response body for SSE stream");
|
|
597
|
-
}
|
|
598
|
-
const streamReader = reader;
|
|
599
|
-
const decoder = new TextDecoder();
|
|
600
|
-
let buffer = "";
|
|
601
|
-
const parseSseChunk = (chunk) => {
|
|
602
|
-
const lines = chunk.split("\n");
|
|
603
|
-
const dataLines = [];
|
|
604
|
-
for (const line of lines) {
|
|
605
|
-
if (line.startsWith("data:")) {
|
|
606
|
-
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
const payload = dataLines.join("\n").trim();
|
|
610
|
-
if (payload.length === 0 || payload === "[DONE]") {
|
|
611
|
-
return null;
|
|
612
|
-
}
|
|
613
|
-
try {
|
|
614
|
-
const parsed = JSON.parse(payload);
|
|
615
|
-
if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
616
|
-
return null;
|
|
617
|
-
}
|
|
618
|
-
const event = {};
|
|
619
|
-
for (const [key, value] of Object.entries(parsed)) {
|
|
620
|
-
event[key] = value;
|
|
621
|
-
}
|
|
622
|
-
return event;
|
|
623
|
-
} catch {
|
|
624
|
-
return null;
|
|
625
|
-
}
|
|
626
|
-
};
|
|
627
|
-
async function* streamEvents() {
|
|
628
|
-
while (true) {
|
|
629
|
-
const { done, value } = await streamReader.read();
|
|
630
|
-
if (done) break;
|
|
631
|
-
buffer += decoder.decode(value, { stream: true });
|
|
632
|
-
const parts = buffer.split("\n\n");
|
|
633
|
-
buffer = parts.pop() ?? "";
|
|
634
|
-
for (const part of parts) {
|
|
635
|
-
const event = parseSseChunk(part);
|
|
636
|
-
if (event != null) {
|
|
637
|
-
yield event;
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
if (buffer.trim().length > 0) {
|
|
642
|
-
const event = parseSseChunk(buffer.trim());
|
|
643
|
-
if (event != null) {
|
|
644
|
-
yield event;
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
return streamEvents();
|
|
649
|
-
}
|
|
650
|
-
if (options?.stream === false) {
|
|
651
|
-
params.stream = "false";
|
|
652
|
-
}
|
|
653
|
-
return this.client.request(`/research/v1/${researchId}`, "GET", void 0, params);
|
|
654
|
-
}
|
|
655
|
-
/** Poll a research request until it reaches a terminal state (completed, failed, or canceled). */
|
|
656
|
-
async pollUntilFinished(researchId, options) {
|
|
657
|
-
const pollInterval = options?.pollInterval ?? 1e3;
|
|
658
|
-
const timeoutMs = options?.timeoutMs ?? 10 * 60 * 1e3;
|
|
659
|
-
const maxConsecutiveFailures = 5;
|
|
660
|
-
const startTime = Date.now();
|
|
661
|
-
let consecutiveFailures = 0;
|
|
662
|
-
while (true) {
|
|
663
|
-
try {
|
|
664
|
-
const research = await this.get(researchId, { events: options?.events });
|
|
665
|
-
consecutiveFailures = 0;
|
|
666
|
-
if (research.status === "completed" || research.status === "failed" || research.status === "canceled") {
|
|
667
|
-
return research;
|
|
668
|
-
}
|
|
669
|
-
} catch (err) {
|
|
670
|
-
consecutiveFailures += 1;
|
|
671
|
-
if (consecutiveFailures >= maxConsecutiveFailures) {
|
|
672
|
-
throw new Error(`Polling failed ${maxConsecutiveFailures} times in a row for research ${researchId}: ${err}`);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
if (Date.now() - startTime > timeoutMs) {
|
|
676
|
-
throw new Error(`Polling timeout: Research ${researchId} did not complete within ${timeoutMs}ms`);
|
|
677
|
-
}
|
|
678
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
};
|
|
682
|
-
|
|
683
|
-
// src/nova/client.ts
|
|
684
|
-
var import_zod2 = require("zod");
|
|
685
|
-
var import_zod_to_json_schema2 = require("zod-to-json-schema");
|
|
686
|
-
function isRecord(value) {
|
|
687
|
-
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
688
|
-
}
|
|
689
|
-
function isZodSchema(value) {
|
|
690
|
-
return value instanceof import_zod2.ZodType;
|
|
691
|
-
}
|
|
692
|
-
function zodToJsonSchema2(schema) {
|
|
693
|
-
const converted = (0, import_zod_to_json_schema2.zodToJsonSchema)(schema, { $refStrategy: "none" });
|
|
694
|
-
if (!isRecord(converted)) {
|
|
695
|
-
throw new Error("Failed to convert Zod schema to JSON Schema.");
|
|
696
|
-
}
|
|
697
|
-
return converted;
|
|
698
|
-
}
|
|
699
|
-
var ExaError = class extends Error {
|
|
700
|
-
constructor(message, statusCode, timestamp, path, details) {
|
|
701
|
-
super(message);
|
|
702
|
-
this.name = "ExaError";
|
|
703
|
-
this.statusCode = statusCode;
|
|
704
|
-
this.timestamp = timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
705
|
-
this.path = path;
|
|
706
|
-
this.details = details;
|
|
707
|
-
}
|
|
708
|
-
};
|
|
709
|
-
var CONTENTS_FIELDS = /* @__PURE__ */ new Set(["text", "highlights", "summary", "subpages", "subpageTarget", "extras", "livecrawl", "livecrawlTimeout", "maxAgeHours", "filterEmptyResults", "context"]);
|
|
710
|
-
var DEFAULT_MAX_CHARACTERS = 1e4;
|
|
711
|
-
var Exa = class {
|
|
712
|
-
constructor(apiKey, baseURL = "https://api.exa.ai") {
|
|
713
|
-
this.baseURL = baseURL;
|
|
714
|
-
if (!apiKey) {
|
|
715
|
-
apiKey = typeof process !== "undefined" ? process.env?.EXA_API_KEY : void 0;
|
|
716
|
-
if (!apiKey) {
|
|
717
|
-
throw new ExaError(
|
|
718
|
-
"API key must be provided as an argument or as an environment variable (EXA_API_KEY)",
|
|
719
|
-
401
|
|
720
|
-
);
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
this.headers = {
|
|
724
|
-
"x-api-key": apiKey,
|
|
725
|
-
"Content-Type": "application/json"
|
|
726
|
-
};
|
|
727
|
-
this.websets = new WebsetsClient(this);
|
|
728
|
-
this.research = new ResearchClient(this);
|
|
729
|
-
}
|
|
730
|
-
/** Make a request to the Exa API. Used by sub-clients and available for direct use. */
|
|
731
|
-
async request(endpoint, method, body, params, headers) {
|
|
732
|
-
const url = this.buildRequestUrl(endpoint, params);
|
|
733
|
-
const normalizedBody = this.normalizeCategoryInBody(body);
|
|
734
|
-
const combinedHeaders = headers ? { ...this.headers, ...headers } : this.headers;
|
|
735
|
-
const response = await fetch(url, {
|
|
736
|
-
method,
|
|
737
|
-
headers: combinedHeaders,
|
|
738
|
-
body: normalizedBody ? JSON.stringify(normalizedBody) : void 0
|
|
739
|
-
});
|
|
740
|
-
if (!response.ok) {
|
|
741
|
-
throw await this.toExaError(response, endpoint);
|
|
742
|
-
}
|
|
743
|
-
return await response.json();
|
|
744
|
-
}
|
|
745
|
-
/** Make a raw request returning the Response object directly. */
|
|
746
|
-
async rawRequest(endpoint, method = "POST", body, params) {
|
|
747
|
-
const url = this.buildRequestUrl(endpoint, params);
|
|
748
|
-
const normalizedBody = this.normalizeCategoryInBody(body);
|
|
749
|
-
return fetch(url, {
|
|
750
|
-
method,
|
|
751
|
-
headers: this.headers,
|
|
752
|
-
body: normalizedBody ? JSON.stringify(normalizedBody) : void 0
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
/** Normalize category values to underscore form. */
|
|
756
|
-
normalizeCategoryInBody(body) {
|
|
757
|
-
if (body == null || typeof body.category !== "string") {
|
|
758
|
-
return body;
|
|
759
|
-
}
|
|
760
|
-
return { ...body, category: body.category.replace(/ /g, "_") };
|
|
761
|
-
}
|
|
762
|
-
buildRequestUrl(endpoint, params) {
|
|
763
|
-
let url = `${this.baseURL}${endpoint}`;
|
|
764
|
-
if (params == null || Object.keys(params).length === 0) {
|
|
765
|
-
return url;
|
|
766
|
-
}
|
|
767
|
-
const searchParams = new URLSearchParams();
|
|
768
|
-
for (const [key, value] of Object.entries(params)) {
|
|
769
|
-
if (Array.isArray(value)) {
|
|
770
|
-
for (const item of value) {
|
|
771
|
-
searchParams.append(key, item);
|
|
772
|
-
}
|
|
773
|
-
} else if (value !== void 0) {
|
|
774
|
-
searchParams.append(key, String(value));
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
url += `?${searchParams.toString()}`;
|
|
778
|
-
return url;
|
|
779
|
-
}
|
|
780
|
-
tryParseJsonRecord(text) {
|
|
781
|
-
if (text.length === 0) {
|
|
782
|
-
return null;
|
|
783
|
-
}
|
|
784
|
-
try {
|
|
785
|
-
const parsed = JSON.parse(text);
|
|
786
|
-
return isRecord(parsed) ? parsed : null;
|
|
787
|
-
} catch {
|
|
788
|
-
return null;
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
async toExaError(response, endpoint) {
|
|
792
|
-
const text = await response.text();
|
|
793
|
-
const parsed = this.tryParseJsonRecord(text);
|
|
794
|
-
const statusCode = parsed != null && typeof parsed.statusCode === "number" ? parsed.statusCode : response.status;
|
|
795
|
-
const timestamp = parsed != null && typeof parsed.timestamp === "string" ? parsed.timestamp : void 0;
|
|
796
|
-
const path = parsed != null && typeof parsed.path === "string" ? parsed.path : endpoint;
|
|
797
|
-
const errorMessage = parsed != null && typeof parsed.error === "string" ? parsed.error : void 0;
|
|
798
|
-
const detailMessage = parsed != null && typeof parsed.message === "string" ? parsed.message : void 0;
|
|
799
|
-
let message;
|
|
800
|
-
if (errorMessage != null && detailMessage != null) {
|
|
801
|
-
message = `${errorMessage}. ${detailMessage}`;
|
|
802
|
-
} else if (errorMessage != null) {
|
|
803
|
-
message = errorMessage;
|
|
804
|
-
} else if (detailMessage != null) {
|
|
805
|
-
message = detailMessage;
|
|
806
|
-
} else if (text.length > 0) {
|
|
807
|
-
message = text;
|
|
808
|
-
} else {
|
|
809
|
-
message = `Exa API error ${response.status}`;
|
|
810
|
-
}
|
|
811
|
-
return new ExaError(message, statusCode, timestamp, path, parsed ?? text);
|
|
812
|
-
}
|
|
813
|
-
parseAnswerStreamLine(line) {
|
|
814
|
-
if (!line.startsWith("data:")) {
|
|
815
|
-
return null;
|
|
816
|
-
}
|
|
817
|
-
const jsonStr = line.replace(/^data:\s*/, "").trim();
|
|
818
|
-
if (jsonStr.length === 0 || jsonStr === "[DONE]") {
|
|
819
|
-
return null;
|
|
820
|
-
}
|
|
821
|
-
let parsedChunk;
|
|
822
|
-
try {
|
|
823
|
-
parsedChunk = JSON.parse(jsonStr);
|
|
824
|
-
} catch {
|
|
825
|
-
return null;
|
|
826
|
-
}
|
|
827
|
-
if (!isRecord(parsedChunk)) {
|
|
828
|
-
return null;
|
|
829
|
-
}
|
|
830
|
-
let content;
|
|
831
|
-
const choices = parsedChunk.choices;
|
|
832
|
-
if (Array.isArray(choices) && choices.length > 0 && isRecord(choices[0])) {
|
|
833
|
-
const delta = choices[0].delta;
|
|
834
|
-
if (isRecord(delta) && typeof delta.content === "string") {
|
|
835
|
-
content = delta.content;
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
let citations;
|
|
839
|
-
if (Array.isArray(parsedChunk.citations)) {
|
|
840
|
-
const normalized = [];
|
|
841
|
-
for (const citation of parsedChunk.citations) {
|
|
842
|
-
if (!isRecord(citation)) {
|
|
843
|
-
continue;
|
|
844
|
-
}
|
|
845
|
-
const id = typeof citation.id === "string" ? citation.id : void 0;
|
|
846
|
-
const url = typeof citation.url === "string" ? citation.url : void 0;
|
|
847
|
-
const title = typeof citation.title === "string" ? citation.title : void 0;
|
|
848
|
-
const publishedDate = typeof citation.publishedDate === "string" ? citation.publishedDate : void 0;
|
|
849
|
-
const author = typeof citation.author === "string" ? citation.author : void 0;
|
|
850
|
-
const text = typeof citation.text === "string" ? citation.text : void 0;
|
|
851
|
-
normalized.push({
|
|
852
|
-
...id != null ? { id } : {},
|
|
853
|
-
...url != null ? { url } : {},
|
|
854
|
-
...title != null ? { title } : {},
|
|
855
|
-
...publishedDate != null ? { publishedDate } : {},
|
|
856
|
-
...author != null ? { author } : {},
|
|
857
|
-
...text != null ? { text } : {}
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
if (normalized.length > 0) {
|
|
861
|
-
citations = normalized;
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
if (content == null && (citations == null || citations.length === 0)) {
|
|
865
|
-
return null;
|
|
866
|
-
}
|
|
867
|
-
return { content, citations };
|
|
868
|
-
}
|
|
869
|
-
/** Separate content-specific options from search/filter options. */
|
|
870
|
-
extractContentsOptions(options) {
|
|
871
|
-
const contentsOptions = {};
|
|
872
|
-
const restOptions = {};
|
|
873
|
-
let hasContentField = false;
|
|
874
|
-
for (const [key, value] of Object.entries(options)) {
|
|
875
|
-
if (CONTENTS_FIELDS.has(key)) {
|
|
876
|
-
contentsOptions[key] = value;
|
|
877
|
-
hasContentField = true;
|
|
878
|
-
} else {
|
|
879
|
-
restOptions[key] = value;
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
if (!hasContentField) {
|
|
883
|
-
contentsOptions.text = { maxCharacters: DEFAULT_MAX_CHARACTERS };
|
|
884
|
-
}
|
|
885
|
-
return { contentsOptions, restOptions };
|
|
886
|
-
}
|
|
887
|
-
search(query, options) {
|
|
888
|
-
let body;
|
|
889
|
-
if (options === void 0 || !("contents" in options)) {
|
|
890
|
-
body = { query, ...options, contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } } };
|
|
891
|
-
} else if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
892
|
-
const { contents, ...restOptions } = options;
|
|
893
|
-
body = { query, ...restOptions };
|
|
894
|
-
} else {
|
|
895
|
-
body = { query, ...options };
|
|
896
|
-
}
|
|
897
|
-
return this.request("/search", "POST", body);
|
|
898
|
-
}
|
|
899
|
-
findSimilar(url, options) {
|
|
900
|
-
let body;
|
|
901
|
-
if (options === void 0 || !("contents" in options)) {
|
|
902
|
-
body = { url, ...options, contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } } };
|
|
903
|
-
} else if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
904
|
-
const { contents, ...restOptions } = options;
|
|
905
|
-
body = { url, ...restOptions };
|
|
906
|
-
} else {
|
|
907
|
-
body = { url, ...options };
|
|
908
|
-
}
|
|
909
|
-
return this.request("/findSimilar", "POST", body);
|
|
910
|
-
}
|
|
911
|
-
getContents(urls, options) {
|
|
912
|
-
let requestUrls;
|
|
913
|
-
if (typeof urls === "string") {
|
|
914
|
-
requestUrls = [urls];
|
|
915
|
-
} else if (urls.length === 0) {
|
|
916
|
-
throw new ExaError("Must provide at least one URL", 400);
|
|
917
|
-
} else if (typeof urls[0] === "string") {
|
|
918
|
-
requestUrls = [];
|
|
919
|
-
for (const url of urls) {
|
|
920
|
-
if (typeof url !== "string") {
|
|
921
|
-
throw new ExaError("Expected all URLs to be strings or SearchResult objects with a url field", 400);
|
|
922
|
-
}
|
|
923
|
-
requestUrls.push(url);
|
|
924
|
-
}
|
|
925
|
-
} else {
|
|
926
|
-
requestUrls = [];
|
|
927
|
-
for (const result of urls) {
|
|
928
|
-
if (!isRecord(result) || typeof result.url !== "string") {
|
|
929
|
-
throw new ExaError("Expected all entries to have a string url field", 400);
|
|
930
|
-
}
|
|
931
|
-
requestUrls.push(result.url);
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
if (requestUrls.length === 0) {
|
|
935
|
-
throw new ExaError("Must provide at least one URL", 400);
|
|
936
|
-
}
|
|
937
|
-
return this.request("/contents", "POST", { urls: requestUrls, ...options });
|
|
938
|
-
}
|
|
939
|
-
async answer(query, options) {
|
|
940
|
-
if (options?.stream) {
|
|
941
|
-
throw new ExaError("For streaming responses, please use streamAnswer() instead:\n\nfor await (const chunk of exa.streamAnswer(query)) {\n // Handle chunks\n}", 400);
|
|
942
|
-
}
|
|
943
|
-
let outputSchema = options?.outputSchema;
|
|
944
|
-
if (outputSchema != null && isZodSchema(outputSchema)) {
|
|
945
|
-
outputSchema = zodToJsonSchema2(outputSchema);
|
|
946
|
-
}
|
|
947
|
-
return this.request("/answer", "POST", { query, model: "exa", stream: false, text: false, ...options, outputSchema });
|
|
948
|
-
}
|
|
949
|
-
async *streamAnswer(query, options) {
|
|
950
|
-
let outputSchema = options?.outputSchema;
|
|
951
|
-
if (outputSchema != null && isZodSchema(outputSchema)) {
|
|
952
|
-
outputSchema = zodToJsonSchema2(outputSchema);
|
|
953
|
-
}
|
|
954
|
-
const response = await this.rawRequest("/answer", "POST", { query, model: "exa", text: false, ...options, outputSchema, stream: true });
|
|
955
|
-
if (!response.ok) {
|
|
956
|
-
throw await this.toExaError(response, "/answer");
|
|
957
|
-
}
|
|
958
|
-
const reader = response.body?.getReader();
|
|
959
|
-
if (!reader) {
|
|
960
|
-
throw new ExaError("No response body available for streaming.", 500, (/* @__PURE__ */ new Date()).toISOString(), "/answer");
|
|
961
|
-
}
|
|
962
|
-
const decoder = new TextDecoder();
|
|
963
|
-
let buffer = "";
|
|
964
|
-
try {
|
|
965
|
-
while (true) {
|
|
966
|
-
const { done, value } = await reader.read();
|
|
967
|
-
if (done) break;
|
|
968
|
-
buffer += decoder.decode(value, { stream: true });
|
|
969
|
-
const lines = buffer.split("\n");
|
|
970
|
-
buffer = lines.pop() ?? "";
|
|
971
|
-
for (const line of lines) {
|
|
972
|
-
const chunk = this.parseAnswerStreamLine(line);
|
|
973
|
-
if (chunk != null) {
|
|
974
|
-
yield chunk;
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
const trailingChunk = this.parseAnswerStreamLine(buffer);
|
|
979
|
-
if (trailingChunk != null) {
|
|
980
|
-
yield trailingChunk;
|
|
981
|
-
}
|
|
982
|
-
} finally {
|
|
983
|
-
reader.releaseLock();
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
/**
|
|
987
|
-
* @deprecated Use `search()` instead. The search method now returns text contents by default.
|
|
988
|
-
* Search with contents. Extracts content fields (text, highlights, summary, etc.) into a `contents` wrapper.
|
|
989
|
-
*/
|
|
990
|
-
async searchAndContents(query, options) {
|
|
991
|
-
if (options === void 0) {
|
|
992
|
-
return this.request("/search", "POST", {
|
|
993
|
-
query,
|
|
994
|
-
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
995
|
-
});
|
|
996
|
-
}
|
|
997
|
-
const { contentsOptions, restOptions } = this.extractContentsOptions(options);
|
|
998
|
-
return this.request("/search", "POST", { query, contents: contentsOptions, ...restOptions });
|
|
999
|
-
}
|
|
1000
|
-
/**
|
|
1001
|
-
* @deprecated Use `findSimilar()` instead. The findSimilar method now returns text contents by default.
|
|
1002
|
-
* Find similar with contents. Extracts content fields into a `contents` wrapper.
|
|
1003
|
-
*/
|
|
1004
|
-
async findSimilarAndContents(url, options) {
|
|
1005
|
-
if (options === void 0) {
|
|
1006
|
-
return this.request("/findSimilar", "POST", {
|
|
1007
|
-
url,
|
|
1008
|
-
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
1009
|
-
});
|
|
1010
|
-
}
|
|
1011
|
-
const { contentsOptions, restOptions } = this.extractContentsOptions(options);
|
|
1012
|
-
return this.request("/findSimilar", "POST", { url, contents: contentsOptions, ...restOptions });
|
|
1013
|
-
}
|
|
1014
|
-
};
|
|
1015
|
-
|
|
1016
161
|
// src/errors.ts
|
|
1017
162
|
var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
|
|
1018
163
|
HttpStatusCode2[HttpStatusCode2["BadRequest"] = 400] = "BadRequest";
|
|
@@ -1025,21 +170,37 @@ var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
|
|
|
1025
170
|
HttpStatusCode2[HttpStatusCode2["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
1026
171
|
return HttpStatusCode2;
|
|
1027
172
|
})(HttpStatusCode || {});
|
|
173
|
+
var ExaError = class extends Error {
|
|
174
|
+
/**
|
|
175
|
+
* Create a new ExaError
|
|
176
|
+
* @param message Error message
|
|
177
|
+
* @param statusCode HTTP status code
|
|
178
|
+
* @param timestamp ISO timestamp from API
|
|
179
|
+
* @param path Path that caused the error
|
|
180
|
+
*/
|
|
181
|
+
constructor(message, statusCode, timestamp, path) {
|
|
182
|
+
super(message);
|
|
183
|
+
this.name = "ExaError";
|
|
184
|
+
this.statusCode = statusCode;
|
|
185
|
+
this.timestamp = timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
186
|
+
this.path = path;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
1028
189
|
|
|
1029
190
|
// src/zod-utils.ts
|
|
1030
|
-
var
|
|
1031
|
-
var
|
|
1032
|
-
function
|
|
1033
|
-
return obj instanceof
|
|
191
|
+
var import_zod = require("zod");
|
|
192
|
+
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
193
|
+
function isZodSchema(obj) {
|
|
194
|
+
return obj instanceof import_zod.ZodType;
|
|
1034
195
|
}
|
|
1035
|
-
function
|
|
1036
|
-
return (0,
|
|
196
|
+
function zodToJsonSchema(schema) {
|
|
197
|
+
return (0, import_zod_to_json_schema.zodToJsonSchema)(schema, {
|
|
1037
198
|
$refStrategy: "none"
|
|
1038
199
|
});
|
|
1039
200
|
}
|
|
1040
201
|
|
|
1041
202
|
// src/research/base.ts
|
|
1042
|
-
var
|
|
203
|
+
var ResearchBaseClient = class {
|
|
1043
204
|
constructor(client) {
|
|
1044
205
|
this.client = client;
|
|
1045
206
|
}
|
|
@@ -1069,15 +230,15 @@ var ResearchBaseClient2 = class {
|
|
|
1069
230
|
};
|
|
1070
231
|
|
|
1071
232
|
// src/research/client.ts
|
|
1072
|
-
var
|
|
233
|
+
var ResearchClient = class extends ResearchBaseClient {
|
|
1073
234
|
constructor(client) {
|
|
1074
235
|
super(client);
|
|
1075
236
|
}
|
|
1076
237
|
async create(params) {
|
|
1077
238
|
const { instructions, model, outputSchema } = params;
|
|
1078
239
|
let schema = outputSchema;
|
|
1079
|
-
if (schema &&
|
|
1080
|
-
schema =
|
|
240
|
+
if (schema && isZodSchema(schema)) {
|
|
241
|
+
schema = zodToJsonSchema(schema);
|
|
1081
242
|
}
|
|
1082
243
|
const payload = {
|
|
1083
244
|
instructions,
|
|
@@ -1194,7 +355,7 @@ var ResearchClient2 = class extends ResearchBaseClient2 {
|
|
|
1194
355
|
};
|
|
1195
356
|
|
|
1196
357
|
// src/websets/base.ts
|
|
1197
|
-
var
|
|
358
|
+
var WebsetsBaseClient = class {
|
|
1198
359
|
/**
|
|
1199
360
|
* Initialize a new Websets base client
|
|
1200
361
|
* @param client The Exa client instance
|
|
@@ -1235,7 +396,7 @@ var WebsetsBaseClient2 = class {
|
|
|
1235
396
|
};
|
|
1236
397
|
|
|
1237
398
|
// src/websets/enrichments.ts
|
|
1238
|
-
var
|
|
399
|
+
var WebsetEnrichmentsClient = class extends WebsetsBaseClient {
|
|
1239
400
|
/**
|
|
1240
401
|
* Create an Enrichment for a Webset
|
|
1241
402
|
* @param websetId The ID of the Webset
|
|
@@ -1302,7 +463,7 @@ var WebsetEnrichmentsClient2 = class extends WebsetsBaseClient2 {
|
|
|
1302
463
|
};
|
|
1303
464
|
|
|
1304
465
|
// src/websets/events.ts
|
|
1305
|
-
var
|
|
466
|
+
var EventsClient = class extends WebsetsBaseClient {
|
|
1306
467
|
/**
|
|
1307
468
|
* Initialize a new Events client
|
|
1308
469
|
* @param client The Exa client instance
|
|
@@ -1534,7 +695,7 @@ var WebsetSearchCanceledReason = /* @__PURE__ */ ((WebsetSearchCanceledReason2)
|
|
|
1534
695
|
})(WebsetSearchCanceledReason || {});
|
|
1535
696
|
|
|
1536
697
|
// src/websets/imports.ts
|
|
1537
|
-
var
|
|
698
|
+
var ImportsClient = class extends WebsetsBaseClient {
|
|
1538
699
|
async create(params, csv) {
|
|
1539
700
|
if (csv === void 0) {
|
|
1540
701
|
return this.request(
|
|
@@ -1717,7 +878,7 @@ var ImportsClient2 = class extends WebsetsBaseClient2 {
|
|
|
1717
878
|
};
|
|
1718
879
|
|
|
1719
880
|
// src/websets/items.ts
|
|
1720
|
-
var
|
|
881
|
+
var WebsetItemsClient = class extends WebsetsBaseClient {
|
|
1721
882
|
/**
|
|
1722
883
|
* List all Items for a Webset
|
|
1723
884
|
* @param websetId The ID of the Webset
|
|
@@ -1797,7 +958,7 @@ var WebsetItemsClient2 = class extends WebsetsBaseClient2 {
|
|
|
1797
958
|
};
|
|
1798
959
|
|
|
1799
960
|
// src/websets/monitors.ts
|
|
1800
|
-
var
|
|
961
|
+
var WebsetMonitorRunsClient = class extends WebsetsBaseClient {
|
|
1801
962
|
/**
|
|
1802
963
|
* List all runs for a Monitor
|
|
1803
964
|
* @param monitorId The ID of the Monitor
|
|
@@ -1826,10 +987,10 @@ var WebsetMonitorRunsClient2 = class extends WebsetsBaseClient2 {
|
|
|
1826
987
|
);
|
|
1827
988
|
}
|
|
1828
989
|
};
|
|
1829
|
-
var
|
|
990
|
+
var WebsetMonitorsClient = class extends WebsetsBaseClient {
|
|
1830
991
|
constructor(client) {
|
|
1831
992
|
super(client);
|
|
1832
|
-
this.runs = new
|
|
993
|
+
this.runs = new WebsetMonitorRunsClient(client);
|
|
1833
994
|
}
|
|
1834
995
|
/**
|
|
1835
996
|
* Create a Monitor
|
|
@@ -1917,7 +1078,7 @@ var WebsetMonitorsClient2 = class extends WebsetsBaseClient2 {
|
|
|
1917
1078
|
};
|
|
1918
1079
|
|
|
1919
1080
|
// src/websets/searches.ts
|
|
1920
|
-
var
|
|
1081
|
+
var WebsetSearchesClient = class extends WebsetsBaseClient {
|
|
1921
1082
|
/**
|
|
1922
1083
|
* Create a new Search for the Webset
|
|
1923
1084
|
* @param websetId The ID of the Webset
|
|
@@ -1960,7 +1121,7 @@ var WebsetSearchesClient2 = class extends WebsetsBaseClient2 {
|
|
|
1960
1121
|
};
|
|
1961
1122
|
|
|
1962
1123
|
// src/websets/webhooks.ts
|
|
1963
|
-
var
|
|
1124
|
+
var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
1964
1125
|
/**
|
|
1965
1126
|
* Create a Webhook
|
|
1966
1127
|
* @param params The webhook parameters
|
|
@@ -2097,20 +1258,20 @@ var WebsetWebhooksClient2 = class extends WebsetsBaseClient2 {
|
|
|
2097
1258
|
};
|
|
2098
1259
|
|
|
2099
1260
|
// src/websets/client.ts
|
|
2100
|
-
var
|
|
1261
|
+
var WebsetsClient = class extends WebsetsBaseClient {
|
|
2101
1262
|
/**
|
|
2102
1263
|
* Initialize a new Websets client
|
|
2103
1264
|
* @param client The Exa client instance
|
|
2104
1265
|
*/
|
|
2105
1266
|
constructor(client) {
|
|
2106
1267
|
super(client);
|
|
2107
|
-
this.events = new
|
|
2108
|
-
this.imports = new
|
|
2109
|
-
this.items = new
|
|
2110
|
-
this.searches = new
|
|
2111
|
-
this.enrichments = new
|
|
2112
|
-
this.monitors = new
|
|
2113
|
-
this.webhooks = new
|
|
1268
|
+
this.events = new EventsClient(client);
|
|
1269
|
+
this.imports = new ImportsClient(client);
|
|
1270
|
+
this.items = new WebsetItemsClient(client);
|
|
1271
|
+
this.searches = new WebsetSearchesClient(client);
|
|
1272
|
+
this.enrichments = new WebsetEnrichmentsClient(client);
|
|
1273
|
+
this.monitors = new WebsetMonitorsClient(client);
|
|
1274
|
+
this.webhooks = new WebsetWebhooksClient(client);
|
|
2114
1275
|
}
|
|
2115
1276
|
/**
|
|
2116
1277
|
* Create a new Webset
|
|
@@ -2274,8 +1435,8 @@ var WebsetsClient2 = class extends WebsetsBaseClient2 {
|
|
|
2274
1435
|
// src/index.ts
|
|
2275
1436
|
var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : import_cross_fetch.default;
|
|
2276
1437
|
var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : import_cross_fetch.Headers;
|
|
2277
|
-
var
|
|
2278
|
-
var
|
|
1438
|
+
var DEFAULT_MAX_CHARACTERS = 1e4;
|
|
1439
|
+
var Exa2 = class {
|
|
2279
1440
|
/**
|
|
2280
1441
|
* Helper method to separate out the contents-specific options from the rest.
|
|
2281
1442
|
*/
|
|
@@ -2300,10 +1461,10 @@ var Exa3 = class {
|
|
|
2300
1461
|
if (text !== void 0) contentsOptions.text = text;
|
|
2301
1462
|
if (highlights !== void 0) contentsOptions.highlights = highlights;
|
|
2302
1463
|
if (summary !== void 0) {
|
|
2303
|
-
if (typeof summary === "object" && summary !== null && "schema" in summary && summary.schema &&
|
|
1464
|
+
if (typeof summary === "object" && summary !== null && "schema" in summary && summary.schema && isZodSchema(summary.schema)) {
|
|
2304
1465
|
contentsOptions.summary = {
|
|
2305
1466
|
...summary,
|
|
2306
|
-
schema:
|
|
1467
|
+
schema: zodToJsonSchema(summary.schema)
|
|
2307
1468
|
};
|
|
2308
1469
|
} else {
|
|
2309
1470
|
contentsOptions.summary = summary;
|
|
@@ -2344,8 +1505,8 @@ var Exa3 = class {
|
|
|
2344
1505
|
"Content-Type": "application/json",
|
|
2345
1506
|
"User-Agent": `exa-node ${package_default.version}`
|
|
2346
1507
|
});
|
|
2347
|
-
this.websets = new
|
|
2348
|
-
this.research = new
|
|
1508
|
+
this.websets = new WebsetsClient(this);
|
|
1509
|
+
this.research = new ResearchClient(this);
|
|
2349
1510
|
}
|
|
2350
1511
|
/**
|
|
2351
1512
|
* Makes a request to the Exa API.
|
|
@@ -2442,7 +1603,7 @@ var Exa3 = class {
|
|
|
2442
1603
|
return await this.request("/search", "POST", {
|
|
2443
1604
|
query,
|
|
2444
1605
|
...options,
|
|
2445
|
-
contents: { text: { maxCharacters:
|
|
1606
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
2446
1607
|
});
|
|
2447
1608
|
}
|
|
2448
1609
|
if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
@@ -2468,7 +1629,7 @@ var Exa3 = class {
|
|
|
2468
1629
|
async searchAndContents(query, options) {
|
|
2469
1630
|
const { contentsOptions, restOptions } = options === void 0 ? {
|
|
2470
1631
|
contentsOptions: {
|
|
2471
|
-
text: { maxCharacters:
|
|
1632
|
+
text: { maxCharacters: DEFAULT_MAX_CHARACTERS }
|
|
2472
1633
|
},
|
|
2473
1634
|
restOptions: {}
|
|
2474
1635
|
} : this.extractContentsOptions(options);
|
|
@@ -2483,7 +1644,7 @@ var Exa3 = class {
|
|
|
2483
1644
|
return await this.request("/findSimilar", "POST", {
|
|
2484
1645
|
url,
|
|
2485
1646
|
...options,
|
|
2486
|
-
contents: { text: { maxCharacters:
|
|
1647
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
2487
1648
|
});
|
|
2488
1649
|
}
|
|
2489
1650
|
if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
@@ -2511,7 +1672,7 @@ var Exa3 = class {
|
|
|
2511
1672
|
async findSimilarAndContents(url, options) {
|
|
2512
1673
|
const { contentsOptions, restOptions } = options === void 0 ? {
|
|
2513
1674
|
contentsOptions: {
|
|
2514
|
-
text: { maxCharacters:
|
|
1675
|
+
text: { maxCharacters: DEFAULT_MAX_CHARACTERS }
|
|
2515
1676
|
},
|
|
2516
1677
|
restOptions: {}
|
|
2517
1678
|
} : this.extractContentsOptions(options);
|
|
@@ -2556,8 +1717,8 @@ var Exa3 = class {
|
|
|
2556
1717
|
);
|
|
2557
1718
|
}
|
|
2558
1719
|
let outputSchema = options?.outputSchema;
|
|
2559
|
-
if (outputSchema &&
|
|
2560
|
-
outputSchema =
|
|
1720
|
+
if (outputSchema && isZodSchema(outputSchema)) {
|
|
1721
|
+
outputSchema = zodToJsonSchema(outputSchema);
|
|
2561
1722
|
}
|
|
2562
1723
|
const requestBody = {
|
|
2563
1724
|
query,
|
|
@@ -2572,8 +1733,8 @@ var Exa3 = class {
|
|
|
2572
1733
|
}
|
|
2573
1734
|
async *streamAnswer(query, options) {
|
|
2574
1735
|
let outputSchema = options?.outputSchema;
|
|
2575
|
-
if (outputSchema &&
|
|
2576
|
-
outputSchema =
|
|
1736
|
+
if (outputSchema && isZodSchema(outputSchema)) {
|
|
1737
|
+
outputSchema = zodToJsonSchema(outputSchema);
|
|
2577
1738
|
}
|
|
2578
1739
|
const body = {
|
|
2579
1740
|
query,
|
|
@@ -2735,7 +1896,7 @@ var Exa3 = class {
|
|
|
2735
1896
|
});
|
|
2736
1897
|
}
|
|
2737
1898
|
};
|
|
2738
|
-
var index_default =
|
|
1899
|
+
var index_default = Exa2;
|
|
2739
1900
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2740
1901
|
0 && (module.exports = {
|
|
2741
1902
|
CreateEnrichmentParametersFormat,
|
|
@@ -2744,7 +1905,6 @@ var index_default = Exa3;
|
|
|
2744
1905
|
EventsClient,
|
|
2745
1906
|
Exa,
|
|
2746
1907
|
ExaError,
|
|
2747
|
-
ExaNova,
|
|
2748
1908
|
HttpStatusCode,
|
|
2749
1909
|
ImportFailedReason,
|
|
2750
1910
|
ImportFormat,
|