exa-js 2.5.1-beta.2 → 2.6.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/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: () => EventsClient2,
37
- Exa: () => Exa3,
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: () => ImportsClient2,
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: () => WebsetEnrichmentsClient2,
54
+ WebsetEnrichmentsClient: () => WebsetEnrichmentsClient,
56
55
  WebsetExcludeSource: () => WebsetExcludeSource,
57
56
  WebsetImportSource: () => WebsetImportSource,
58
57
  WebsetItemEvaluationSatisfied: () => WebsetItemEvaluationSatisfied,
59
58
  WebsetItemSource: () => WebsetItemSource,
60
- WebsetItemsClient: () => WebsetItemsClient2,
61
- WebsetMonitorsClient: () => WebsetMonitorsClient2,
59
+ WebsetItemsClient: () => WebsetItemsClient,
60
+ WebsetMonitorsClient: () => WebsetMonitorsClient,
62
61
  WebsetSearchBehavior: () => WebsetSearchBehavior,
63
62
  WebsetSearchCanceledReason: () => WebsetSearchCanceledReason,
64
63
  WebsetSearchScopeSource: () => WebsetSearchScopeSource,
65
64
  WebsetSearchStatus: () => WebsetSearchStatus,
66
- WebsetSearchesClient: () => WebsetSearchesClient2,
65
+ WebsetSearchesClient: () => WebsetSearchesClient,
67
66
  WebsetStatus: () => WebsetStatus,
68
- WebsetWebhooksClient: () => WebsetWebhooksClient2,
69
- WebsetsClient: () => WebsetsClient2,
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.5.1-beta.2",
77
+ version: "2.6.0",
79
78
  description: "Exa SDK for Node.js and the browser",
80
79
  publishConfig: {
81
80
  access: "public"
@@ -159,639 +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
- };
251
- var WebsetMonitorRunsClient = class extends WebsetsBaseClient {
252
- async list(monitorId) {
253
- return this.request(`/v0/monitors/${monitorId}/runs`, "GET");
254
- }
255
- async get(monitorId, id) {
256
- return this.request(`/v0/monitors/${monitorId}/runs/${id}`, "GET");
257
- }
258
- };
259
- var WebsetMonitorsClient = class extends WebsetsBaseClient {
260
- constructor(client) {
261
- super(client);
262
- this.runs = new WebsetMonitorRunsClient(client);
263
- }
264
- async create(params) {
265
- return this.request("/v0/monitors", "POST", { ...params });
266
- }
267
- async list(options) {
268
- const queryParams = { ...this.buildPaginationParams(options), websetId: options?.websetId };
269
- return this.request("/v0/monitors", "GET", void 0, queryParams);
270
- }
271
- async get(id) {
272
- return this.request(`/v0/monitors/${id}`, "GET");
273
- }
274
- async update(id, params) {
275
- return this.request(`/v0/monitors/${id}`, "PATCH", { ...params });
276
- }
277
- async delete(id) {
278
- return this.request(`/v0/monitors/${id}`, "DELETE");
279
- }
280
- /** Iterate through all monitors, handling pagination automatically. */
281
- async *listAll(options) {
282
- let cursor = void 0;
283
- const pageOptions = options ? { ...options } : {};
284
- while (true) {
285
- const response = await this.list({ ...pageOptions, cursor });
286
- for (const monitor of response.data) {
287
- yield monitor;
288
- }
289
- if (!response.hasMore || !response.nextCursor) {
290
- break;
291
- }
292
- cursor = response.nextCursor;
293
- }
294
- }
295
- /** Collect all monitors into an array. */
296
- async getAll(options) {
297
- const monitors = [];
298
- for await (const monitor of this.listAll(options)) {
299
- monitors.push(monitor);
300
- }
301
- return monitors;
302
- }
303
- };
304
- var WebsetWebhooksClient = class extends WebsetsBaseClient {
305
- async create(params) {
306
- return this.request("/v0/webhooks", "POST", { ...params });
307
- }
308
- async list(options) {
309
- const queryParams = this.buildPaginationParams(options);
310
- return this.request("/v0/webhooks", "GET", void 0, queryParams);
311
- }
312
- async get(id) {
313
- return this.request(`/v0/webhooks/${id}`, "GET");
314
- }
315
- async update(id, params) {
316
- return this.request(`/v0/webhooks/${id}`, "PATCH", { ...params });
317
- }
318
- async delete(id) {
319
- return this.request(`/v0/webhooks/${id}`, "DELETE");
320
- }
321
- async listAttempts(id, options) {
322
- const queryParams = { ...this.buildPaginationParams(options), eventType: options?.eventType, successful: options?.successful };
323
- return this.request(`/v0/webhooks/${id}/attempts`, "GET", void 0, queryParams);
324
- }
325
- };
326
- var ImportsClient = class extends WebsetsBaseClient {
327
- async create(params) {
328
- return this.request("/v0/imports", "POST", { ...params });
329
- }
330
- async list(options) {
331
- const queryParams = this.buildPaginationParams(options);
332
- return this.request("/v0/imports", "GET", void 0, queryParams);
333
- }
334
- async get(id) {
335
- return this.request(`/v0/imports/${id}`, "GET");
336
- }
337
- async update(id, params) {
338
- return this.request(`/v0/imports/${id}`, "PATCH", { ...params });
339
- }
340
- async delete(id) {
341
- return this.request(`/v0/imports/${id}`, "DELETE");
342
- }
343
- };
344
- var WebsetsClient = class extends WebsetsBaseClient {
345
- constructor(client) {
346
- super(client);
347
- this.items = new WebsetItemsClient(client);
348
- this.searches = new WebsetSearchesClient(client);
349
- this.enrichments = new WebsetEnrichmentsClient(client);
350
- this.events = new EventsClient(client);
351
- this.monitors = new WebsetMonitorsClient(client);
352
- this.webhooks = new WebsetWebhooksClient(client);
353
- this.imports = new ImportsClient(client);
354
- }
355
- async create(params, options) {
356
- return this.request("/v0/websets", "POST", { ...params }, void 0, options?.headers);
357
- }
358
- async list(options) {
359
- const queryParams = { ...this.buildPaginationParams(options), search: options?.search };
360
- return this.request("/v0/websets", "GET", void 0, queryParams);
361
- }
362
- async get(id, options) {
363
- const queryParams = { expand: options?.expand };
364
- return this.request(`/v0/websets/${id}`, "GET", void 0, queryParams);
365
- }
366
- async update(id, params) {
367
- return this.request(`/v0/websets/${id}`, "POST", { ...params });
368
- }
369
- async delete(id) {
370
- return this.request(`/v0/websets/${id}`, "DELETE");
371
- }
372
- async cancel(id) {
373
- return this.request(`/v0/websets/${id}/cancel`, "POST");
374
- }
375
- async preview(params, options) {
376
- const queryParams = { search: options?.search };
377
- return this.request("/v0/websets/preview", "POST", { ...params }, queryParams);
378
- }
379
- /** Iterate through all Websets, handling pagination automatically. */
380
- async *listAll(options) {
381
- let cursor = void 0;
382
- const pageOptions = options ? { ...options } : {};
383
- while (true) {
384
- const response = await this.list({ ...pageOptions, cursor });
385
- for (const webset of response.data) {
386
- yield webset;
387
- }
388
- if (!response.hasMore || !response.nextCursor) {
389
- break;
390
- }
391
- cursor = response.nextCursor;
392
- }
393
- }
394
- /** Collect all Websets into an array. */
395
- async getAll(options) {
396
- const websets = [];
397
- for await (const webset of this.listAll(options)) {
398
- websets.push(webset);
399
- }
400
- return websets;
401
- }
402
- /** Poll until a Webset reaches idle status. */
403
- async waitUntilIdle(id, options) {
404
- let timeout;
405
- let pollInterval = 1e3;
406
- let onPoll;
407
- if (typeof options === "number") {
408
- timeout = options;
409
- } else if (options) {
410
- timeout = options.timeout;
411
- pollInterval = options.pollInterval || 1e3;
412
- onPoll = options.onPoll;
413
- }
414
- const startTime = Date.now();
415
- while (true) {
416
- const webset = await this.get(id);
417
- if (onPoll) onPoll(webset.status);
418
- if (webset.status === "idle") return webset;
419
- if (timeout && Date.now() - startTime > timeout) {
420
- throw new Error(`Webset ${id} did not reach idle state within ${timeout}ms. Current status: ${webset.status}`);
421
- }
422
- await new Promise((resolve) => setTimeout(resolve, pollInterval));
423
- }
424
- }
425
- };
426
-
427
- // src/nova/research-client.ts
428
- var import_zod = require("zod");
429
- var import_zod_to_json_schema = require("zod-to-json-schema");
430
- function zodToJsonSchema(schema) {
431
- return (0, import_zod_to_json_schema.zodToJsonSchema)(schema, { $refStrategy: "none" });
432
- }
433
- var ResearchBaseClient = class {
434
- constructor(client) {
435
- this.client = client;
436
- }
437
- /** Make a request to the API, prepending `/research/v1` to the path. */
438
- async request(endpoint, method = "POST", data, params) {
439
- return this.client.request(`/research/v1${endpoint}`, method, data, params);
440
- }
441
- buildPaginationParams(pagination) {
442
- const params = {};
443
- if (!pagination) return params;
444
- if (pagination.cursor) params.cursor = pagination.cursor;
445
- if (pagination.limit) params.limit = pagination.limit;
446
- return params;
447
- }
448
- };
449
- var ResearchClient = class extends ResearchBaseClient {
450
- /** List research requests. */
451
- async list(options) {
452
- const params = this.buildPaginationParams(options);
453
- return this.client.request("/research/v1", "GET", void 0, params);
454
- }
455
- /** Create a new research request. Defaults model to "exa-research-fast" if not provided. */
456
- async create(params) {
457
- let schema = params.outputSchema;
458
- if (schema instanceof import_zod.ZodType) {
459
- schema = zodToJsonSchema(schema);
460
- }
461
- const payload = {
462
- instructions: params.instructions,
463
- model: params.model ?? "exa-research-fast"
464
- };
465
- if (schema) {
466
- payload.outputSchema = schema;
467
- }
468
- return this.client.request("/research/v1", "POST", payload, void 0);
469
- }
470
- /** Get a research request by ID. */
471
- async get(researchId, options) {
472
- const params = {};
473
- if (options?.events !== void 0) params.events = options.events.toString();
474
- return this.client.request(`/research/v1/${researchId}`, "GET", void 0, params);
475
- }
476
- /** Poll a research request until it reaches a terminal state (completed, failed, or canceled). */
477
- async pollUntilFinished(researchId, options) {
478
- const pollInterval = options?.pollInterval ?? 1e3;
479
- const timeoutMs = options?.timeoutMs ?? 10 * 60 * 1e3;
480
- const maxConsecutiveFailures = 5;
481
- const startTime = Date.now();
482
- let consecutiveFailures = 0;
483
- while (true) {
484
- try {
485
- const research = await this.get(researchId, { events: options?.events });
486
- consecutiveFailures = 0;
487
- if (research.status === "completed" || research.status === "failed" || research.status === "canceled") {
488
- return research;
489
- }
490
- } catch (err) {
491
- consecutiveFailures += 1;
492
- if (consecutiveFailures >= maxConsecutiveFailures) {
493
- throw new Error(`Polling failed ${maxConsecutiveFailures} times in a row for research ${researchId}: ${err}`);
494
- }
495
- }
496
- if (Date.now() - startTime > timeoutMs) {
497
- throw new Error(`Polling timeout: Research ${researchId} did not complete within ${timeoutMs}ms`);
498
- }
499
- await new Promise((resolve) => setTimeout(resolve, pollInterval));
500
- }
501
- }
502
- };
503
-
504
- // src/nova/client.ts
505
- function isRecord(value) {
506
- return value != null && typeof value === "object" && !Array.isArray(value);
507
- }
508
- var ExaError = class extends Error {
509
- constructor(message, statusCode, timestamp, path, details) {
510
- super(message);
511
- this.name = "ExaError";
512
- this.statusCode = statusCode;
513
- this.timestamp = timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
514
- this.path = path;
515
- this.details = details;
516
- }
517
- };
518
- var CONTENTS_FIELDS = /* @__PURE__ */ new Set(["text", "highlights", "summary", "subpages", "subpageTarget", "extras", "livecrawl", "livecrawlTimeout", "maxAgeHours", "filterEmptyResults", "context"]);
519
- var DEFAULT_MAX_CHARACTERS = 1e4;
520
- var Exa = class {
521
- constructor(apiKey, baseURL = "https://api.exa.ai") {
522
- this.baseURL = baseURL;
523
- if (!apiKey) {
524
- apiKey = typeof process !== "undefined" ? process.env?.EXA_API_KEY : void 0;
525
- if (!apiKey) {
526
- throw new ExaError(
527
- "API key must be provided as an argument or as an environment variable (EXA_API_KEY)",
528
- 401
529
- );
530
- }
531
- }
532
- this.headers = {
533
- "x-api-key": apiKey,
534
- "Content-Type": "application/json"
535
- };
536
- this.websets = new WebsetsClient(this);
537
- this.research = new ResearchClient(this);
538
- }
539
- /** Make a request to the Exa API. Used by sub-clients and available for direct use. */
540
- async request(endpoint, method, body, params, headers) {
541
- const url = this.buildRequestUrl(endpoint, params);
542
- const normalizedBody = this.normalizeCategoryInBody(body);
543
- const combinedHeaders = headers ? { ...this.headers, ...headers } : this.headers;
544
- const response = await fetch(url, {
545
- method,
546
- headers: combinedHeaders,
547
- body: normalizedBody ? JSON.stringify(normalizedBody) : void 0
548
- });
549
- if (!response.ok) {
550
- throw await this.toExaError(response, endpoint);
551
- }
552
- return await response.json();
553
- }
554
- /** Make a raw request returning the Response object directly. */
555
- async rawRequest(endpoint, method = "POST", body, params) {
556
- const url = this.buildRequestUrl(endpoint, params);
557
- const normalizedBody = this.normalizeCategoryInBody(body);
558
- return fetch(url, {
559
- method,
560
- headers: this.headers,
561
- body: normalizedBody ? JSON.stringify(normalizedBody) : void 0
562
- });
563
- }
564
- /** Normalize category values to underscore form. */
565
- normalizeCategoryInBody(body) {
566
- if (body == null || typeof body.category !== "string") {
567
- return body;
568
- }
569
- return { ...body, category: body.category.replace(/ /g, "_") };
570
- }
571
- buildRequestUrl(endpoint, params) {
572
- let url = `${this.baseURL}${endpoint}`;
573
- if (params == null || Object.keys(params).length === 0) {
574
- return url;
575
- }
576
- const searchParams = new URLSearchParams();
577
- for (const [key, value] of Object.entries(params)) {
578
- if (Array.isArray(value)) {
579
- for (const item of value) {
580
- searchParams.append(key, item);
581
- }
582
- } else if (value !== void 0) {
583
- searchParams.append(key, String(value));
584
- }
585
- }
586
- url += `?${searchParams.toString()}`;
587
- return url;
588
- }
589
- tryParseJsonRecord(text) {
590
- if (text.length === 0) {
591
- return null;
592
- }
593
- try {
594
- const parsed = JSON.parse(text);
595
- return isRecord(parsed) ? parsed : null;
596
- } catch {
597
- return null;
598
- }
599
- }
600
- async toExaError(response, endpoint) {
601
- const text = await response.text();
602
- const parsed = this.tryParseJsonRecord(text);
603
- const statusCode = parsed != null && typeof parsed.statusCode === "number" ? parsed.statusCode : response.status;
604
- const timestamp = parsed != null && typeof parsed.timestamp === "string" ? parsed.timestamp : void 0;
605
- const path = parsed != null && typeof parsed.path === "string" ? parsed.path : endpoint;
606
- const errorMessage = parsed != null && typeof parsed.error === "string" ? parsed.error : void 0;
607
- const detailMessage = parsed != null && typeof parsed.message === "string" ? parsed.message : void 0;
608
- let message;
609
- if (errorMessage != null && detailMessage != null) {
610
- message = `${errorMessage}. ${detailMessage}`;
611
- } else if (errorMessage != null) {
612
- message = errorMessage;
613
- } else if (detailMessage != null) {
614
- message = detailMessage;
615
- } else if (text.length > 0) {
616
- message = text;
617
- } else {
618
- message = `Exa API error ${response.status}`;
619
- }
620
- return new ExaError(message, statusCode, timestamp, path, parsed ?? text);
621
- }
622
- parseAnswerStreamLine(line) {
623
- if (!line.startsWith("data:")) {
624
- return null;
625
- }
626
- const jsonStr = line.replace(/^data:\s*/, "").trim();
627
- if (jsonStr.length === 0 || jsonStr === "[DONE]") {
628
- return null;
629
- }
630
- let parsedChunk;
631
- try {
632
- parsedChunk = JSON.parse(jsonStr);
633
- } catch {
634
- return null;
635
- }
636
- if (!isRecord(parsedChunk)) {
637
- return null;
638
- }
639
- let content;
640
- const choices = parsedChunk.choices;
641
- if (Array.isArray(choices) && choices.length > 0 && isRecord(choices[0])) {
642
- const delta = choices[0].delta;
643
- if (isRecord(delta) && typeof delta.content === "string") {
644
- content = delta.content;
645
- }
646
- }
647
- let citations;
648
- if (Array.isArray(parsedChunk.citations)) {
649
- const normalized = [];
650
- for (const citation of parsedChunk.citations) {
651
- if (!isRecord(citation)) {
652
- continue;
653
- }
654
- const id = typeof citation.id === "string" ? citation.id : void 0;
655
- const url = typeof citation.url === "string" ? citation.url : void 0;
656
- const title = typeof citation.title === "string" ? citation.title : void 0;
657
- const publishedDate = typeof citation.publishedDate === "string" ? citation.publishedDate : void 0;
658
- const author = typeof citation.author === "string" ? citation.author : void 0;
659
- const text = typeof citation.text === "string" ? citation.text : void 0;
660
- normalized.push({
661
- ...id != null ? { id } : {},
662
- ...url != null ? { url } : {},
663
- ...title != null ? { title } : {},
664
- ...publishedDate != null ? { publishedDate } : {},
665
- ...author != null ? { author } : {},
666
- ...text != null ? { text } : {}
667
- });
668
- }
669
- if (normalized.length > 0) {
670
- citations = normalized;
671
- }
672
- }
673
- if (content == null && (citations == null || citations.length === 0)) {
674
- return null;
675
- }
676
- return {
677
- ...content != null ? { content } : {},
678
- ...citations != null ? { citations } : {}
679
- };
680
- }
681
- /** Separate content-specific options from search/filter options. */
682
- extractContentsOptions(options) {
683
- const contentsOptions = {};
684
- const restOptions = {};
685
- let hasContentField = false;
686
- for (const [key, value] of Object.entries(options)) {
687
- if (CONTENTS_FIELDS.has(key)) {
688
- contentsOptions[key] = value;
689
- hasContentField = true;
690
- } else {
691
- restOptions[key] = value;
692
- }
693
- }
694
- if (!hasContentField) {
695
- contentsOptions.text = { maxCharacters: DEFAULT_MAX_CHARACTERS };
696
- }
697
- return { contentsOptions, restOptions };
698
- }
699
- search(query, options) {
700
- let body;
701
- if (options === void 0 || !("contents" in options)) {
702
- body = { query, ...options, contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } } };
703
- } else if (options.contents === false || options.contents === null || options.contents === void 0) {
704
- const { contents, ...restOptions } = options;
705
- body = { query, ...restOptions };
706
- } else {
707
- body = { query, ...options };
708
- }
709
- return this.request("/search", "POST", body);
710
- }
711
- findSimilar(url, options) {
712
- let body;
713
- if (options === void 0 || !("contents" in options)) {
714
- body = { url, ...options, contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } } };
715
- } else if (options.contents === false || options.contents === null || options.contents === void 0) {
716
- const { contents, ...restOptions } = options;
717
- body = { url, ...restOptions };
718
- } else {
719
- body = { url, ...options };
720
- }
721
- return this.request("/findSimilar", "POST", body);
722
- }
723
- getContents(urls, options) {
724
- return this.request("/contents", "POST", { urls, ...options });
725
- }
726
- answer(query, options) {
727
- if (options?.stream) {
728
- throw new ExaError("For streaming responses, please use streamAnswer() instead:\n\nfor await (const chunk of exa.streamAnswer(query)) {\n // Handle chunks\n}", 400);
729
- }
730
- return this.request("/answer", "POST", { query, model: "exa", stream: false, text: false, ...options });
731
- }
732
- async *streamAnswer(query, options) {
733
- const response = await this.rawRequest("/answer", "POST", { query, model: "exa", text: false, ...options, stream: true });
734
- if (!response.ok) {
735
- throw await this.toExaError(response, "/answer");
736
- }
737
- const reader = response.body?.getReader();
738
- if (!reader) {
739
- throw new ExaError("No response body available for streaming.", 500, (/* @__PURE__ */ new Date()).toISOString(), "/answer");
740
- }
741
- const decoder = new TextDecoder();
742
- let buffer = "";
743
- try {
744
- while (true) {
745
- const { done, value } = await reader.read();
746
- if (done) break;
747
- buffer += decoder.decode(value, { stream: true });
748
- const lines = buffer.split("\n");
749
- buffer = lines.pop() ?? "";
750
- for (const line of lines) {
751
- const chunk = this.parseAnswerStreamLine(line);
752
- if (chunk != null) {
753
- yield chunk;
754
- }
755
- }
756
- }
757
- const trailingChunk = this.parseAnswerStreamLine(buffer);
758
- if (trailingChunk != null) {
759
- yield trailingChunk;
760
- }
761
- } finally {
762
- reader.releaseLock();
763
- }
764
- }
765
- /**
766
- * @deprecated Use `search()` instead. The search method now returns text contents by default.
767
- * Search with contents. Extracts content fields (text, highlights, summary, etc.) into a `contents` wrapper.
768
- */
769
- async searchAndContents(query, options) {
770
- if (options === void 0) {
771
- return this.request("/search", "POST", {
772
- query,
773
- contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
774
- });
775
- }
776
- const { contentsOptions, restOptions } = this.extractContentsOptions(options);
777
- return this.request("/search", "POST", { query, contents: contentsOptions, ...restOptions });
778
- }
779
- /**
780
- * @deprecated Use `findSimilar()` instead. The findSimilar method now returns text contents by default.
781
- * Find similar with contents. Extracts content fields into a `contents` wrapper.
782
- */
783
- async findSimilarAndContents(url, options) {
784
- if (options === void 0) {
785
- return this.request("/findSimilar", "POST", {
786
- url,
787
- contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
788
- });
789
- }
790
- const { contentsOptions, restOptions } = this.extractContentsOptions(options);
791
- return this.request("/findSimilar", "POST", { url, contents: contentsOptions, ...restOptions });
792
- }
793
- };
794
-
795
161
  // src/errors.ts
796
162
  var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
797
163
  HttpStatusCode2[HttpStatusCode2["BadRequest"] = 400] = "BadRequest";
@@ -804,21 +170,37 @@ var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
804
170
  HttpStatusCode2[HttpStatusCode2["ServiceUnavailable"] = 503] = "ServiceUnavailable";
805
171
  return HttpStatusCode2;
806
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
+ };
807
189
 
808
190
  // src/zod-utils.ts
809
- var import_zod2 = require("zod");
810
- var import_zod_to_json_schema2 = require("zod-to-json-schema");
191
+ var import_zod = require("zod");
192
+ var import_zod_to_json_schema = require("zod-to-json-schema");
811
193
  function isZodSchema(obj) {
812
- return obj instanceof import_zod2.ZodType;
194
+ return obj instanceof import_zod.ZodType;
813
195
  }
814
- function zodToJsonSchema2(schema) {
815
- return (0, import_zod_to_json_schema2.zodToJsonSchema)(schema, {
196
+ function zodToJsonSchema(schema) {
197
+ return (0, import_zod_to_json_schema.zodToJsonSchema)(schema, {
816
198
  $refStrategy: "none"
817
199
  });
818
200
  }
819
201
 
820
202
  // src/research/base.ts
821
- var ResearchBaseClient2 = class {
203
+ var ResearchBaseClient = class {
822
204
  constructor(client) {
823
205
  this.client = client;
824
206
  }
@@ -848,7 +230,7 @@ var ResearchBaseClient2 = class {
848
230
  };
849
231
 
850
232
  // src/research/client.ts
851
- var ResearchClient2 = class extends ResearchBaseClient2 {
233
+ var ResearchClient = class extends ResearchBaseClient {
852
234
  constructor(client) {
853
235
  super(client);
854
236
  }
@@ -856,7 +238,7 @@ var ResearchClient2 = class extends ResearchBaseClient2 {
856
238
  const { instructions, model, outputSchema } = params;
857
239
  let schema = outputSchema;
858
240
  if (schema && isZodSchema(schema)) {
859
- schema = zodToJsonSchema2(schema);
241
+ schema = zodToJsonSchema(schema);
860
242
  }
861
243
  const payload = {
862
244
  instructions,
@@ -973,7 +355,7 @@ var ResearchClient2 = class extends ResearchBaseClient2 {
973
355
  };
974
356
 
975
357
  // src/websets/base.ts
976
- var WebsetsBaseClient2 = class {
358
+ var WebsetsBaseClient = class {
977
359
  /**
978
360
  * Initialize a new Websets base client
979
361
  * @param client The Exa client instance
@@ -1014,7 +396,7 @@ var WebsetsBaseClient2 = class {
1014
396
  };
1015
397
 
1016
398
  // src/websets/enrichments.ts
1017
- var WebsetEnrichmentsClient2 = class extends WebsetsBaseClient2 {
399
+ var WebsetEnrichmentsClient = class extends WebsetsBaseClient {
1018
400
  /**
1019
401
  * Create an Enrichment for a Webset
1020
402
  * @param websetId The ID of the Webset
@@ -1081,7 +463,7 @@ var WebsetEnrichmentsClient2 = class extends WebsetsBaseClient2 {
1081
463
  };
1082
464
 
1083
465
  // src/websets/events.ts
1084
- var EventsClient2 = class extends WebsetsBaseClient2 {
466
+ var EventsClient = class extends WebsetsBaseClient {
1085
467
  /**
1086
468
  * Initialize a new Events client
1087
469
  * @param client The Exa client instance
@@ -1313,7 +695,7 @@ var WebsetSearchCanceledReason = /* @__PURE__ */ ((WebsetSearchCanceledReason2)
1313
695
  })(WebsetSearchCanceledReason || {});
1314
696
 
1315
697
  // src/websets/imports.ts
1316
- var ImportsClient2 = class extends WebsetsBaseClient2 {
698
+ var ImportsClient = class extends WebsetsBaseClient {
1317
699
  async create(params, csv) {
1318
700
  if (csv === void 0) {
1319
701
  return this.request(
@@ -1496,7 +878,7 @@ var ImportsClient2 = class extends WebsetsBaseClient2 {
1496
878
  };
1497
879
 
1498
880
  // src/websets/items.ts
1499
- var WebsetItemsClient2 = class extends WebsetsBaseClient2 {
881
+ var WebsetItemsClient = class extends WebsetsBaseClient {
1500
882
  /**
1501
883
  * List all Items for a Webset
1502
884
  * @param websetId The ID of the Webset
@@ -1576,7 +958,7 @@ var WebsetItemsClient2 = class extends WebsetsBaseClient2 {
1576
958
  };
1577
959
 
1578
960
  // src/websets/monitors.ts
1579
- var WebsetMonitorRunsClient2 = class extends WebsetsBaseClient2 {
961
+ var WebsetMonitorRunsClient = class extends WebsetsBaseClient {
1580
962
  /**
1581
963
  * List all runs for a Monitor
1582
964
  * @param monitorId The ID of the Monitor
@@ -1605,10 +987,10 @@ var WebsetMonitorRunsClient2 = class extends WebsetsBaseClient2 {
1605
987
  );
1606
988
  }
1607
989
  };
1608
- var WebsetMonitorsClient2 = class extends WebsetsBaseClient2 {
990
+ var WebsetMonitorsClient = class extends WebsetsBaseClient {
1609
991
  constructor(client) {
1610
992
  super(client);
1611
- this.runs = new WebsetMonitorRunsClient2(client);
993
+ this.runs = new WebsetMonitorRunsClient(client);
1612
994
  }
1613
995
  /**
1614
996
  * Create a Monitor
@@ -1696,7 +1078,7 @@ var WebsetMonitorsClient2 = class extends WebsetsBaseClient2 {
1696
1078
  };
1697
1079
 
1698
1080
  // src/websets/searches.ts
1699
- var WebsetSearchesClient2 = class extends WebsetsBaseClient2 {
1081
+ var WebsetSearchesClient = class extends WebsetsBaseClient {
1700
1082
  /**
1701
1083
  * Create a new Search for the Webset
1702
1084
  * @param websetId The ID of the Webset
@@ -1739,7 +1121,7 @@ var WebsetSearchesClient2 = class extends WebsetsBaseClient2 {
1739
1121
  };
1740
1122
 
1741
1123
  // src/websets/webhooks.ts
1742
- var WebsetWebhooksClient2 = class extends WebsetsBaseClient2 {
1124
+ var WebsetWebhooksClient = class extends WebsetsBaseClient {
1743
1125
  /**
1744
1126
  * Create a Webhook
1745
1127
  * @param params The webhook parameters
@@ -1876,20 +1258,20 @@ var WebsetWebhooksClient2 = class extends WebsetsBaseClient2 {
1876
1258
  };
1877
1259
 
1878
1260
  // src/websets/client.ts
1879
- var WebsetsClient2 = class extends WebsetsBaseClient2 {
1261
+ var WebsetsClient = class extends WebsetsBaseClient {
1880
1262
  /**
1881
1263
  * Initialize a new Websets client
1882
1264
  * @param client The Exa client instance
1883
1265
  */
1884
1266
  constructor(client) {
1885
1267
  super(client);
1886
- this.events = new EventsClient2(client);
1887
- this.imports = new ImportsClient2(client);
1888
- this.items = new WebsetItemsClient2(client);
1889
- this.searches = new WebsetSearchesClient2(client);
1890
- this.enrichments = new WebsetEnrichmentsClient2(client);
1891
- this.monitors = new WebsetMonitorsClient2(client);
1892
- this.webhooks = new WebsetWebhooksClient2(client);
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);
1893
1275
  }
1894
1276
  /**
1895
1277
  * Create a new Webset
@@ -2053,8 +1435,8 @@ var WebsetsClient2 = class extends WebsetsBaseClient2 {
2053
1435
  // src/index.ts
2054
1436
  var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : import_cross_fetch.default;
2055
1437
  var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : import_cross_fetch.Headers;
2056
- var DEFAULT_MAX_CHARACTERS2 = 1e4;
2057
- var Exa3 = class {
1438
+ var DEFAULT_MAX_CHARACTERS = 1e4;
1439
+ var Exa2 = class {
2058
1440
  /**
2059
1441
  * Helper method to separate out the contents-specific options from the rest.
2060
1442
  */
@@ -2082,7 +1464,7 @@ var Exa3 = class {
2082
1464
  if (typeof summary === "object" && summary !== null && "schema" in summary && summary.schema && isZodSchema(summary.schema)) {
2083
1465
  contentsOptions.summary = {
2084
1466
  ...summary,
2085
- schema: zodToJsonSchema2(summary.schema)
1467
+ schema: zodToJsonSchema(summary.schema)
2086
1468
  };
2087
1469
  } else {
2088
1470
  contentsOptions.summary = summary;
@@ -2123,8 +1505,8 @@ var Exa3 = class {
2123
1505
  "Content-Type": "application/json",
2124
1506
  "User-Agent": `exa-node ${package_default.version}`
2125
1507
  });
2126
- this.websets = new WebsetsClient2(this);
2127
- this.research = new ResearchClient2(this);
1508
+ this.websets = new WebsetsClient(this);
1509
+ this.research = new ResearchClient(this);
2128
1510
  }
2129
1511
  /**
2130
1512
  * Makes a request to the Exa API.
@@ -2221,7 +1603,7 @@ var Exa3 = class {
2221
1603
  return await this.request("/search", "POST", {
2222
1604
  query,
2223
1605
  ...options,
2224
- contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 } }
1606
+ contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
2225
1607
  });
2226
1608
  }
2227
1609
  if (options.contents === false || options.contents === null || options.contents === void 0) {
@@ -2247,7 +1629,7 @@ var Exa3 = class {
2247
1629
  async searchAndContents(query, options) {
2248
1630
  const { contentsOptions, restOptions } = options === void 0 ? {
2249
1631
  contentsOptions: {
2250
- text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 }
1632
+ text: { maxCharacters: DEFAULT_MAX_CHARACTERS }
2251
1633
  },
2252
1634
  restOptions: {}
2253
1635
  } : this.extractContentsOptions(options);
@@ -2262,7 +1644,7 @@ var Exa3 = class {
2262
1644
  return await this.request("/findSimilar", "POST", {
2263
1645
  url,
2264
1646
  ...options,
2265
- contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 } }
1647
+ contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
2266
1648
  });
2267
1649
  }
2268
1650
  if (options.contents === false || options.contents === null || options.contents === void 0) {
@@ -2290,7 +1672,7 @@ var Exa3 = class {
2290
1672
  async findSimilarAndContents(url, options) {
2291
1673
  const { contentsOptions, restOptions } = options === void 0 ? {
2292
1674
  contentsOptions: {
2293
- text: { maxCharacters: DEFAULT_MAX_CHARACTERS2 }
1675
+ text: { maxCharacters: DEFAULT_MAX_CHARACTERS }
2294
1676
  },
2295
1677
  restOptions: {}
2296
1678
  } : this.extractContentsOptions(options);
@@ -2336,7 +1718,7 @@ var Exa3 = class {
2336
1718
  }
2337
1719
  let outputSchema = options?.outputSchema;
2338
1720
  if (outputSchema && isZodSchema(outputSchema)) {
2339
- outputSchema = zodToJsonSchema2(outputSchema);
1721
+ outputSchema = zodToJsonSchema(outputSchema);
2340
1722
  }
2341
1723
  const requestBody = {
2342
1724
  query,
@@ -2352,7 +1734,7 @@ var Exa3 = class {
2352
1734
  async *streamAnswer(query, options) {
2353
1735
  let outputSchema = options?.outputSchema;
2354
1736
  if (outputSchema && isZodSchema(outputSchema)) {
2355
- outputSchema = zodToJsonSchema2(outputSchema);
1737
+ outputSchema = zodToJsonSchema(outputSchema);
2356
1738
  }
2357
1739
  const body = {
2358
1740
  query,
@@ -2514,7 +1896,7 @@ var Exa3 = class {
2514
1896
  });
2515
1897
  }
2516
1898
  };
2517
- var index_default = Exa3;
1899
+ var index_default = Exa2;
2518
1900
  // Annotate the CommonJS export names for ESM import in node:
2519
1901
  0 && (module.exports = {
2520
1902
  CreateEnrichmentParametersFormat,
@@ -2523,7 +1905,6 @@ var index_default = Exa3;
2523
1905
  EventsClient,
2524
1906
  Exa,
2525
1907
  ExaError,
2526
- ExaNova,
2527
1908
  HttpStatusCode,
2528
1909
  ImportFailedReason,
2529
1910
  ImportFormat,