exa-js 1.7.4 → 1.8.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 +7 -8
- package/dist/index.d.mts +212 -131
- package/dist/index.d.ts +212 -131
- package/dist/index.js +84 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
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
|
-
|
|
39
|
+
ResearchModel: () => ResearchCreateTaskRequestDtoModel,
|
|
40
|
+
ResearchStatus: () => ResearchTaskDtoStatus,
|
|
40
41
|
UpdateStreamStatus: () => UpdateStreamStatus,
|
|
41
42
|
WebhookStatus: () => WebhookStatus,
|
|
42
43
|
WebsetEnrichmentFormat: () => WebsetEnrichmentFormat,
|
|
@@ -808,40 +809,69 @@ var ResearchBaseClient = class {
|
|
|
808
809
|
*/
|
|
809
810
|
async request(endpoint, method = "POST", data, params) {
|
|
810
811
|
return this.client.request(
|
|
811
|
-
`/v0
|
|
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_research_pro"] = "exa-research-pro";
|
|
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
|
-
*
|
|
828
|
-
*
|
|
829
|
-
*
|
|
830
|
-
*
|
|
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
|
-
* @
|
|
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(
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
860
|
+
async createTask(params) {
|
|
861
|
+
const { instructions, model, output } = params;
|
|
862
|
+
const payload = {
|
|
863
|
+
instructions,
|
|
864
|
+
model: model ?? "exa-research" /* exa_research */,
|
|
865
|
+
output: output ? {
|
|
866
|
+
schema: output.schema,
|
|
867
|
+
inferSchema: output.inferSchema ?? true
|
|
868
|
+
} : { inferSchema: true }
|
|
869
|
+
};
|
|
870
|
+
return this.request(
|
|
871
|
+
"/tasks",
|
|
872
|
+
"POST",
|
|
873
|
+
payload
|
|
874
|
+
);
|
|
845
875
|
}
|
|
846
876
|
/**
|
|
847
877
|
* Retrieve a research task by ID.
|
|
@@ -852,15 +882,28 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
852
882
|
/**
|
|
853
883
|
* Poll a research task until completion or failure.
|
|
854
884
|
* Polls every 1 second with a maximum timeout of 10 minutes.
|
|
885
|
+
* Resilient to up to 10 consecutive polling failures.
|
|
855
886
|
*/
|
|
856
887
|
async pollTask(id) {
|
|
857
888
|
const pollingInterval = 1e3;
|
|
858
889
|
const maxPollingTime = 10 * 60 * 1e3;
|
|
890
|
+
const maxConsecutiveFailures = 10;
|
|
859
891
|
const startTime = Date.now();
|
|
892
|
+
let consecutiveFailures = 0;
|
|
860
893
|
while (true) {
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
894
|
+
try {
|
|
895
|
+
const task = await this.request(`/tasks/${id}`, "GET");
|
|
896
|
+
consecutiveFailures = 0;
|
|
897
|
+
if (task.status === "completed" || task.status === "failed") {
|
|
898
|
+
return task;
|
|
899
|
+
}
|
|
900
|
+
} catch (err) {
|
|
901
|
+
consecutiveFailures += 1;
|
|
902
|
+
if (consecutiveFailures >= maxConsecutiveFailures) {
|
|
903
|
+
throw new Error(
|
|
904
|
+
`Polling failed ${maxConsecutiveFailures} times in a row for task ${id}: ${err}`
|
|
905
|
+
);
|
|
906
|
+
}
|
|
864
907
|
}
|
|
865
908
|
if (Date.now() - startTime > maxPollingTime) {
|
|
866
909
|
throw new Error(
|
|
@@ -870,16 +913,22 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
870
913
|
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
871
914
|
}
|
|
872
915
|
}
|
|
916
|
+
/**
|
|
917
|
+
* List research tasks
|
|
918
|
+
* @param options Pagination options
|
|
919
|
+
* @returns The paginated list of research tasks
|
|
920
|
+
*/
|
|
921
|
+
async listTasks(options) {
|
|
922
|
+
const params = this.buildPaginationParams(options);
|
|
923
|
+
return this.request(
|
|
924
|
+
"/tasks",
|
|
925
|
+
"GET",
|
|
926
|
+
void 0,
|
|
927
|
+
params
|
|
928
|
+
);
|
|
929
|
+
}
|
|
873
930
|
};
|
|
874
931
|
|
|
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
932
|
// src/index.ts
|
|
884
933
|
var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : import_cross_fetch.default;
|
|
885
934
|
var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : import_cross_fetch.Headers;
|
|
@@ -982,7 +1031,10 @@ var Exa2 = class {
|
|
|
982
1031
|
if (!errorData.path) {
|
|
983
1032
|
errorData.path = endpoint;
|
|
984
1033
|
}
|
|
985
|
-
|
|
1034
|
+
let message = errorData.error || "Unknown error";
|
|
1035
|
+
if (errorData.message) {
|
|
1036
|
+
message += (message.length > 0 ? ". " : "") + errorData.message;
|
|
1037
|
+
}
|
|
986
1038
|
throw new ExaError(
|
|
987
1039
|
message,
|
|
988
1040
|
response.status,
|
|
@@ -1298,6 +1350,7 @@ var index_default = Exa2;
|
|
|
1298
1350
|
ExaError,
|
|
1299
1351
|
HttpStatusCode,
|
|
1300
1352
|
ResearchClient,
|
|
1353
|
+
ResearchModel,
|
|
1301
1354
|
ResearchStatus,
|
|
1302
1355
|
UpdateStreamStatus,
|
|
1303
1356
|
WebhookStatus,
|