exa-js 1.7.4 → 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
@@ -36,7 +36,8 @@ __export(index_exports, {
36
36
  ExaError: () => ExaError,
37
37
  HttpStatusCode: () => HttpStatusCode,
38
38
  ResearchClient: () => ResearchClient,
39
- ResearchStatus: () => ResearchStatus,
39
+ ResearchModel: () => ResearchCreateTaskRequestDtoModel,
40
+ ResearchStatus: () => ResearchTaskDtoStatus,
40
41
  UpdateStreamStatus: () => UpdateStreamStatus,
41
42
  WebhookStatus: () => WebhookStatus,
42
43
  WebsetEnrichmentFormat: () => WebsetEnrichmentFormat,
@@ -808,40 +809,65 @@ var ResearchBaseClient = class {
808
809
  */
809
810
  async request(endpoint, method = "POST", data, params) {
810
811
  return this.client.request(
811
- `/v0/research${endpoint}`,
812
+ `/research/v0${endpoint}`,
812
813
  method,
813
814
  data,
814
815
  params
815
816
  );
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;
829
+ }
817
830
  };
818
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
+
819
845
  // src/research/client.ts
820
846
  var ResearchClient = class extends ResearchBaseClient {
821
847
  constructor(client) {
822
848
  super(client);
823
849
  }
824
850
  /**
825
- * Create a research task.
851
+ * Create a new research task.
826
852
  *
827
- * Both parameters are required and have fixed shapes:
828
- * 1. `input`
829
- * `{ instructions: string }`
830
- * `instructions` High-level guidance that tells the research agent what to do.
831
- * 2. `output`
832
- * defines the exact structure you expect back, and guides the research conducted by the agent.
833
- * `{ schema: JSONSchema }`.
834
- * 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.
835
857
  *
836
- * @param input Object containing high-level research instructions.
837
- * @param output Object containing the expected output schema.
838
- * @returns The ResearchTaskResponse returned by the API.
858
+ * @returns An object containing the unique ID of the created research task.
839
859
  */
840
- async createTask(input, output) {
841
- return this.request("/tasks", "POST", {
842
- input,
843
- output
844
- });
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
+ );
845
871
  }
846
872
  /**
847
873
  * Retrieve a research task by ID.
@@ -852,15 +878,28 @@ var ResearchClient = class extends ResearchBaseClient {
852
878
  /**
853
879
  * Poll a research task until completion or failure.
854
880
  * Polls every 1 second with a maximum timeout of 10 minutes.
881
+ * Resilient to up to 10 consecutive polling failures.
855
882
  */
856
883
  async pollTask(id) {
857
884
  const pollingInterval = 1e3;
858
885
  const maxPollingTime = 10 * 60 * 1e3;
886
+ const maxConsecutiveFailures = 10;
859
887
  const startTime = Date.now();
888
+ let consecutiveFailures = 0;
860
889
  while (true) {
861
- const task = await this.request(`/tasks/${id}`, "GET");
862
- if (task.status === "completed" || task.status === "failed") {
863
- 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
+ }
864
903
  }
865
904
  if (Date.now() - startTime > maxPollingTime) {
866
905
  throw new Error(
@@ -870,16 +909,22 @@ var ResearchClient = class extends ResearchBaseClient {
870
909
  await new Promise((resolve) => setTimeout(resolve, pollingInterval));
871
910
  }
872
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
+ }
873
926
  };
874
927
 
875
- // src/research/types.ts
876
- var ResearchStatus = /* @__PURE__ */ ((ResearchStatus2) => {
877
- ResearchStatus2["in_progress"] = "in_progress";
878
- ResearchStatus2["completed"] = "completed";
879
- ResearchStatus2["failed"] = "failed";
880
- return ResearchStatus2;
881
- })(ResearchStatus || {});
882
-
883
928
  // src/index.ts
884
929
  var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : import_cross_fetch.default;
885
930
  var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : import_cross_fetch.Headers;
@@ -1298,6 +1343,7 @@ var index_default = Exa2;
1298
1343
  ExaError,
1299
1344
  HttpStatusCode,
1300
1345
  ResearchClient,
1346
+ ResearchModel,
1301
1347
  ResearchStatus,
1302
1348
  UpdateStreamStatus,
1303
1349
  WebhookStatus,