exa-js 1.7.3 → 1.8.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
@@ -31,13 +31,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  CreateEnrichmentParametersFormat: () => CreateEnrichmentParametersFormat,
34
- CreateWebsetSearchParametersBehaviour: () => CreateWebsetSearchParametersBehaviour,
35
34
  EventType: () => EventType,
36
35
  Exa: () => Exa2,
37
36
  ExaError: () => ExaError,
38
37
  HttpStatusCode: () => HttpStatusCode,
39
38
  ResearchClient: () => ResearchClient,
40
- ResearchStatus: () => ResearchStatus,
39
+ ResearchModel: () => ResearchCreateTaskRequestDtoModel,
40
+ ResearchStatus: () => ResearchTaskDtoStatus,
41
+ UpdateStreamStatus: () => UpdateStreamStatus,
41
42
  WebhookStatus: () => WebhookStatus,
42
43
  WebsetEnrichmentFormat: () => WebsetEnrichmentFormat,
43
44
  WebsetEnrichmentStatus: () => WebsetEnrichmentStatus,
@@ -45,10 +46,12 @@ __export(index_exports, {
45
46
  WebsetItemEvaluationSatisfied: () => WebsetItemEvaluationSatisfied,
46
47
  WebsetItemSource: () => WebsetItemSource,
47
48
  WebsetItemsClient: () => WebsetItemsClient,
49
+ WebsetSearchBehavior: () => WebsetSearchBehavior,
48
50
  WebsetSearchCanceledReason: () => WebsetSearchCanceledReason,
49
51
  WebsetSearchStatus: () => WebsetSearchStatus,
50
52
  WebsetSearchesClient: () => WebsetSearchesClient,
51
53
  WebsetStatus: () => WebsetStatus,
54
+ WebsetStreamsClient: () => WebsetStreamsClient,
52
55
  WebsetWebhooksClient: () => WebsetWebhooksClient,
53
56
  WebsetsClient: () => WebsetsClient,
54
57
  default: () => index_default
@@ -297,10 +300,6 @@ var CreateEnrichmentParametersFormat = /* @__PURE__ */ ((CreateEnrichmentParamet
297
300
  CreateEnrichmentParametersFormat2["phone"] = "phone";
298
301
  return CreateEnrichmentParametersFormat2;
299
302
  })(CreateEnrichmentParametersFormat || {});
300
- var CreateWebsetSearchParametersBehaviour = /* @__PURE__ */ ((CreateWebsetSearchParametersBehaviour2) => {
301
- CreateWebsetSearchParametersBehaviour2["override"] = "override";
302
- return CreateWebsetSearchParametersBehaviour2;
303
- })(CreateWebsetSearchParametersBehaviour || {});
304
303
  var EventType = /* @__PURE__ */ ((EventType2) => {
305
304
  EventType2["webset_created"] = "webset.created";
306
305
  EventType2["webset_deleted"] = "webset.deleted";
@@ -316,6 +315,11 @@ var EventType = /* @__PURE__ */ ((EventType2) => {
316
315
  EventType2["webset_item_enriched"] = "webset.item.enriched";
317
316
  return EventType2;
318
317
  })(EventType || {});
318
+ var UpdateStreamStatus = /* @__PURE__ */ ((UpdateStreamStatus2) => {
319
+ UpdateStreamStatus2["open"] = "open";
320
+ UpdateStreamStatus2["closed"] = "closed";
321
+ return UpdateStreamStatus2;
322
+ })(UpdateStreamStatus || {});
319
323
  var WebhookStatus = /* @__PURE__ */ ((WebhookStatus2) => {
320
324
  WebhookStatus2["active"] = "active";
321
325
  WebhookStatus2["inactive"] = "inactive";
@@ -344,6 +348,7 @@ var WebsetEnrichmentFormat = /* @__PURE__ */ ((WebsetEnrichmentFormat2) => {
344
348
  })(WebsetEnrichmentFormat || {});
345
349
  var WebsetItemSource = /* @__PURE__ */ ((WebsetItemSource2) => {
346
350
  WebsetItemSource2["search"] = "search";
351
+ WebsetItemSource2["import"] = "import";
347
352
  return WebsetItemSource2;
348
353
  })(WebsetItemSource || {});
349
354
  var WebsetItemEvaluationSatisfied = /* @__PURE__ */ ((WebsetItemEvaluationSatisfied2) => {
@@ -352,11 +357,6 @@ var WebsetItemEvaluationSatisfied = /* @__PURE__ */ ((WebsetItemEvaluationSatisf
352
357
  WebsetItemEvaluationSatisfied2["unclear"] = "unclear";
353
358
  return WebsetItemEvaluationSatisfied2;
354
359
  })(WebsetItemEvaluationSatisfied || {});
355
- var WebsetSearchCanceledReason = /* @__PURE__ */ ((WebsetSearchCanceledReason2) => {
356
- WebsetSearchCanceledReason2["webset_deleted"] = "webset_deleted";
357
- WebsetSearchCanceledReason2["webset_canceled"] = "webset_canceled";
358
- return WebsetSearchCanceledReason2;
359
- })(WebsetSearchCanceledReason || {});
360
360
  var WebsetSearchStatus = /* @__PURE__ */ ((WebsetSearchStatus2) => {
361
361
  WebsetSearchStatus2["created"] = "created";
362
362
  WebsetSearchStatus2["running"] = "running";
@@ -364,6 +364,16 @@ var WebsetSearchStatus = /* @__PURE__ */ ((WebsetSearchStatus2) => {
364
364
  WebsetSearchStatus2["canceled"] = "canceled";
365
365
  return WebsetSearchStatus2;
366
366
  })(WebsetSearchStatus || {});
367
+ var WebsetSearchBehavior = /* @__PURE__ */ ((WebsetSearchBehavior2) => {
368
+ WebsetSearchBehavior2["override"] = "override";
369
+ WebsetSearchBehavior2["append"] = "append";
370
+ return WebsetSearchBehavior2;
371
+ })(WebsetSearchBehavior || {});
372
+ var WebsetSearchCanceledReason = /* @__PURE__ */ ((WebsetSearchCanceledReason2) => {
373
+ WebsetSearchCanceledReason2["webset_deleted"] = "webset_deleted";
374
+ WebsetSearchCanceledReason2["webset_canceled"] = "webset_canceled";
375
+ return WebsetSearchCanceledReason2;
376
+ })(WebsetSearchCanceledReason || {});
367
377
 
368
378
  // src/websets/searches.ts
369
379
  var WebsetSearchesClient = class extends WebsetsBaseClient {
@@ -406,6 +416,94 @@ var WebsetSearchesClient = class extends WebsetsBaseClient {
406
416
  }
407
417
  };
408
418
 
419
+ // src/websets/streams.ts
420
+ var WebsetStreamRunsClient = class extends WebsetsBaseClient {
421
+ /**
422
+ * List all runs for a Stream
423
+ * @param streamId The ID of the Stream
424
+ * @param options Pagination options
425
+ * @returns The list of Stream runs
426
+ */
427
+ async list(streamId, options) {
428
+ const params = this.buildPaginationParams(options);
429
+ return this.request(
430
+ `/v0/streams/${streamId}/runs`,
431
+ "GET",
432
+ void 0,
433
+ params
434
+ );
435
+ }
436
+ /**
437
+ * Get a specific Stream run
438
+ * @param streamId The ID of the Stream
439
+ * @param runId The ID of the Stream run
440
+ * @returns The Stream run
441
+ */
442
+ async get(streamId, runId) {
443
+ return this.request(
444
+ `/v0/streams/${streamId}/runs/${runId}`,
445
+ "GET"
446
+ );
447
+ }
448
+ };
449
+ var WebsetStreamsClient = class extends WebsetsBaseClient {
450
+ constructor(client) {
451
+ super(client);
452
+ this.runs = new WebsetStreamRunsClient(client);
453
+ }
454
+ /**
455
+ * Create a Stream
456
+ * @param params The stream parameters
457
+ * @returns The created Stream
458
+ */
459
+ async create(params) {
460
+ return this.request("/v0/streams", "POST", params);
461
+ }
462
+ /**
463
+ * Get a Stream by ID
464
+ * @param id The ID of the Stream
465
+ * @returns The Stream
466
+ */
467
+ async get(id) {
468
+ return this.request(`/v0/streams/${id}`, "GET");
469
+ }
470
+ /**
471
+ * List all Streams
472
+ * @param options Pagination and filtering options
473
+ * @returns The list of Streams
474
+ */
475
+ async list(options) {
476
+ const params = {
477
+ cursor: options?.cursor,
478
+ limit: options?.limit,
479
+ websetId: options?.websetId
480
+ };
481
+ return this.request(
482
+ "/v0/streams",
483
+ "GET",
484
+ void 0,
485
+ params
486
+ );
487
+ }
488
+ /**
489
+ * Update a Stream
490
+ * @param id The ID of the Stream
491
+ * @param params The stream update parameters (status, metadata)
492
+ * @returns The updated Stream
493
+ */
494
+ async update(id, params) {
495
+ return this.request(`/v0/streams/${id}`, "PATCH", params);
496
+ }
497
+ /**
498
+ * Delete a Stream
499
+ * @param id The ID of the Stream
500
+ * @returns The deleted Stream
501
+ */
502
+ async delete(id) {
503
+ return this.request(`/v0/streams/${id}`, "DELETE");
504
+ }
505
+ };
506
+
409
507
  // src/websets/webhooks.ts
410
508
  var WebsetWebhooksClient = class extends WebsetsBaseClient {
411
509
  /**
@@ -554,6 +652,7 @@ var WebsetsClient = class extends WebsetsBaseClient {
554
652
  this.items = new WebsetItemsClient(client);
555
653
  this.searches = new WebsetSearchesClient(client);
556
654
  this.enrichments = new WebsetEnrichmentsClient(client);
655
+ this.streams = new WebsetStreamsClient(client);
557
656
  this.webhooks = new WebsetWebhooksClient(client);
558
657
  }
559
658
  /**
@@ -709,36 +808,66 @@ var ResearchBaseClient = class {
709
808
  * @returns The parsed JSON response
710
809
  */
711
810
  async request(endpoint, method = "POST", data, params) {
712
- return this.client.request(`/research${endpoint}`, method, data, params);
811
+ return this.client.request(
812
+ `/research/v0${endpoint}`,
813
+ method,
814
+ data,
815
+ params
816
+ );
817
+ }
818
+ /**
819
+ * Helper to build pagination parameters.
820
+ * @param pagination The pagination parameters
821
+ * @returns QueryParams object with pagination parameters
822
+ */
823
+ buildPaginationParams(pagination) {
824
+ const params = {};
825
+ if (!pagination) return params;
826
+ if (pagination.cursor) params.cursor = pagination.cursor;
827
+ if (pagination.limit) params.limit = pagination.limit;
828
+ return params;
713
829
  }
714
830
  };
715
831
 
832
+ // src/research/openapi.ts
833
+ var ResearchCreateTaskRequestDtoModel = /* @__PURE__ */ ((ResearchCreateTaskRequestDtoModel2) => {
834
+ ResearchCreateTaskRequestDtoModel2["exa_research"] = "exa-research";
835
+ ResearchCreateTaskRequestDtoModel2["exa_ultra"] = "exa-ultra";
836
+ return ResearchCreateTaskRequestDtoModel2;
837
+ })(ResearchCreateTaskRequestDtoModel || {});
838
+ var ResearchTaskDtoStatus = /* @__PURE__ */ ((ResearchTaskDtoStatus2) => {
839
+ ResearchTaskDtoStatus2["running"] = "running";
840
+ ResearchTaskDtoStatus2["completed"] = "completed";
841
+ ResearchTaskDtoStatus2["failed"] = "failed";
842
+ return ResearchTaskDtoStatus2;
843
+ })(ResearchTaskDtoStatus || {});
844
+
716
845
  // src/research/client.ts
717
846
  var ResearchClient = class extends ResearchBaseClient {
718
847
  constructor(client) {
719
848
  super(client);
720
849
  }
721
850
  /**
722
- * Create a research task.
851
+ * Create a new research task.
723
852
  *
724
- * Both parameters are required and have fixed shapes:
725
- * 1. `input`
726
- * `{ instructions: string }`
727
- * `instructions` High-level guidance that tells the research agent what to do.
728
- * 2. `output`
729
- * defines the exact structure you expect back, and guides the research conducted by the agent.
730
- * `{ schema: JSONSchema }`.
731
- * The agent's response will be validated against this schema.
853
+ * @param params Object containing:
854
+ * - model: The research model to use (e.g., ResearchModel.ExaResearch).
855
+ * - instructions: High-level guidance for the research agent.
856
+ * - output: An object with a `schema` property (JSONSchema) that defines the expected output structure.
732
857
  *
733
- * @param input Object containing high-level research instructions.
734
- * @param output Object containing the expected output schema.
735
- * @returns The ResearchTaskResponse returned by the API.
858
+ * @returns An object containing the unique ID of the created research task.
736
859
  */
737
- async createTask(input, output) {
738
- return this.request("/tasks", "POST", {
739
- input,
740
- output
741
- });
860
+ async createTask(params) {
861
+ const { model, ...rest } = params;
862
+ const payload = {
863
+ model: model ?? "exa-research" /* exa_research */,
864
+ ...rest
865
+ };
866
+ return this.request(
867
+ "/tasks",
868
+ "POST",
869
+ payload
870
+ );
742
871
  }
743
872
  /**
744
873
  * Retrieve a research task by ID.
@@ -749,15 +878,28 @@ var ResearchClient = class extends ResearchBaseClient {
749
878
  /**
750
879
  * Poll a research task until completion or failure.
751
880
  * Polls every 1 second with a maximum timeout of 10 minutes.
881
+ * Resilient to up to 10 consecutive polling failures.
752
882
  */
753
883
  async pollTask(id) {
754
884
  const pollingInterval = 1e3;
755
885
  const maxPollingTime = 10 * 60 * 1e3;
886
+ const maxConsecutiveFailures = 10;
756
887
  const startTime = Date.now();
888
+ let consecutiveFailures = 0;
757
889
  while (true) {
758
- const task = await this.request(`/tasks/${id}`, "GET");
759
- if (task.status === "completed" || task.status === "failed") {
760
- return task;
890
+ try {
891
+ const task = await this.request(`/tasks/${id}`, "GET");
892
+ consecutiveFailures = 0;
893
+ if (task.status === "completed" || task.status === "failed") {
894
+ return task;
895
+ }
896
+ } catch (err) {
897
+ consecutiveFailures += 1;
898
+ if (consecutiveFailures >= maxConsecutiveFailures) {
899
+ throw new Error(
900
+ `Polling failed ${maxConsecutiveFailures} times in a row for task ${id}: ${err}`
901
+ );
902
+ }
761
903
  }
762
904
  if (Date.now() - startTime > maxPollingTime) {
763
905
  throw new Error(
@@ -767,16 +909,22 @@ var ResearchClient = class extends ResearchBaseClient {
767
909
  await new Promise((resolve) => setTimeout(resolve, pollingInterval));
768
910
  }
769
911
  }
912
+ /**
913
+ * List research tasks
914
+ * @param options Pagination options
915
+ * @returns The paginated list of research tasks
916
+ */
917
+ async listTasks(options) {
918
+ const params = this.buildPaginationParams(options);
919
+ return this.request(
920
+ "/tasks",
921
+ "GET",
922
+ void 0,
923
+ params
924
+ );
925
+ }
770
926
  };
771
927
 
772
- // src/research/types.ts
773
- var ResearchStatus = /* @__PURE__ */ ((ResearchStatus2) => {
774
- ResearchStatus2["in_progress"] = "in_progress";
775
- ResearchStatus2["completed"] = "completed";
776
- ResearchStatus2["failed"] = "failed";
777
- return ResearchStatus2;
778
- })(ResearchStatus || {});
779
-
780
928
  // src/index.ts
781
929
  var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : import_cross_fetch.default;
782
930
  var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : import_cross_fetch.Headers;
@@ -1190,13 +1338,14 @@ var index_default = Exa2;
1190
1338
  // Annotate the CommonJS export names for ESM import in node:
1191
1339
  0 && (module.exports = {
1192
1340
  CreateEnrichmentParametersFormat,
1193
- CreateWebsetSearchParametersBehaviour,
1194
1341
  EventType,
1195
1342
  Exa,
1196
1343
  ExaError,
1197
1344
  HttpStatusCode,
1198
1345
  ResearchClient,
1346
+ ResearchModel,
1199
1347
  ResearchStatus,
1348
+ UpdateStreamStatus,
1200
1349
  WebhookStatus,
1201
1350
  WebsetEnrichmentFormat,
1202
1351
  WebsetEnrichmentStatus,
@@ -1204,10 +1353,12 @@ var index_default = Exa2;
1204
1353
  WebsetItemEvaluationSatisfied,
1205
1354
  WebsetItemSource,
1206
1355
  WebsetItemsClient,
1356
+ WebsetSearchBehavior,
1207
1357
  WebsetSearchCanceledReason,
1208
1358
  WebsetSearchStatus,
1209
1359
  WebsetSearchesClient,
1210
1360
  WebsetStatus,
1361
+ WebsetStreamsClient,
1211
1362
  WebsetWebhooksClient,
1212
1363
  WebsetsClient
1213
1364
  });