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.mjs
CHANGED
|
@@ -751,40 +751,69 @@ var ResearchBaseClient = class {
|
|
|
751
751
|
*/
|
|
752
752
|
async request(endpoint, method = "POST", data, params) {
|
|
753
753
|
return this.client.request(
|
|
754
|
-
`/v0
|
|
754
|
+
`/research/v0${endpoint}`,
|
|
755
755
|
method,
|
|
756
756
|
data,
|
|
757
757
|
params
|
|
758
758
|
);
|
|
759
759
|
}
|
|
760
|
+
/**
|
|
761
|
+
* Helper to build pagination parameters.
|
|
762
|
+
* @param pagination The pagination parameters
|
|
763
|
+
* @returns QueryParams object with pagination parameters
|
|
764
|
+
*/
|
|
765
|
+
buildPaginationParams(pagination) {
|
|
766
|
+
const params = {};
|
|
767
|
+
if (!pagination) return params;
|
|
768
|
+
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
769
|
+
if (pagination.limit) params.limit = pagination.limit;
|
|
770
|
+
return params;
|
|
771
|
+
}
|
|
760
772
|
};
|
|
761
773
|
|
|
774
|
+
// src/research/openapi.ts
|
|
775
|
+
var ResearchCreateTaskRequestDtoModel = /* @__PURE__ */ ((ResearchCreateTaskRequestDtoModel2) => {
|
|
776
|
+
ResearchCreateTaskRequestDtoModel2["exa_research"] = "exa-research";
|
|
777
|
+
ResearchCreateTaskRequestDtoModel2["exa_research_pro"] = "exa-research-pro";
|
|
778
|
+
return ResearchCreateTaskRequestDtoModel2;
|
|
779
|
+
})(ResearchCreateTaskRequestDtoModel || {});
|
|
780
|
+
var ResearchTaskDtoStatus = /* @__PURE__ */ ((ResearchTaskDtoStatus2) => {
|
|
781
|
+
ResearchTaskDtoStatus2["running"] = "running";
|
|
782
|
+
ResearchTaskDtoStatus2["completed"] = "completed";
|
|
783
|
+
ResearchTaskDtoStatus2["failed"] = "failed";
|
|
784
|
+
return ResearchTaskDtoStatus2;
|
|
785
|
+
})(ResearchTaskDtoStatus || {});
|
|
786
|
+
|
|
762
787
|
// src/research/client.ts
|
|
763
788
|
var ResearchClient = class extends ResearchBaseClient {
|
|
764
789
|
constructor(client) {
|
|
765
790
|
super(client);
|
|
766
791
|
}
|
|
767
792
|
/**
|
|
768
|
-
* Create a research task.
|
|
793
|
+
* Create a new research task.
|
|
769
794
|
*
|
|
770
|
-
*
|
|
771
|
-
*
|
|
772
|
-
*
|
|
773
|
-
*
|
|
774
|
-
* 2. `output`
|
|
775
|
-
* defines the exact structure you expect back, and guides the research conducted by the agent.
|
|
776
|
-
* `{ schema: JSONSchema }`.
|
|
777
|
-
* The agent's response will be validated against this schema.
|
|
795
|
+
* @param params Object containing:
|
|
796
|
+
* - model: The research model to use (e.g., ResearchModel.ExaResearch).
|
|
797
|
+
* - instructions: High-level guidance for the research agent.
|
|
798
|
+
* - output: An object with a `schema` property (JSONSchema) that defines the expected output structure.
|
|
778
799
|
*
|
|
779
|
-
* @
|
|
780
|
-
* @param output Object containing the expected output schema.
|
|
781
|
-
* @returns The ResearchTaskResponse returned by the API.
|
|
800
|
+
* @returns An object containing the unique ID of the created research task.
|
|
782
801
|
*/
|
|
783
|
-
async createTask(
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
802
|
+
async createTask(params) {
|
|
803
|
+
const { instructions, model, output } = params;
|
|
804
|
+
const payload = {
|
|
805
|
+
instructions,
|
|
806
|
+
model: model ?? "exa-research" /* exa_research */,
|
|
807
|
+
output: output ? {
|
|
808
|
+
schema: output.schema,
|
|
809
|
+
inferSchema: output.inferSchema ?? true
|
|
810
|
+
} : { inferSchema: true }
|
|
811
|
+
};
|
|
812
|
+
return this.request(
|
|
813
|
+
"/tasks",
|
|
814
|
+
"POST",
|
|
815
|
+
payload
|
|
816
|
+
);
|
|
788
817
|
}
|
|
789
818
|
/**
|
|
790
819
|
* Retrieve a research task by ID.
|
|
@@ -795,15 +824,28 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
795
824
|
/**
|
|
796
825
|
* Poll a research task until completion or failure.
|
|
797
826
|
* Polls every 1 second with a maximum timeout of 10 minutes.
|
|
827
|
+
* Resilient to up to 10 consecutive polling failures.
|
|
798
828
|
*/
|
|
799
829
|
async pollTask(id) {
|
|
800
830
|
const pollingInterval = 1e3;
|
|
801
831
|
const maxPollingTime = 10 * 60 * 1e3;
|
|
832
|
+
const maxConsecutiveFailures = 10;
|
|
802
833
|
const startTime = Date.now();
|
|
834
|
+
let consecutiveFailures = 0;
|
|
803
835
|
while (true) {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
836
|
+
try {
|
|
837
|
+
const task = await this.request(`/tasks/${id}`, "GET");
|
|
838
|
+
consecutiveFailures = 0;
|
|
839
|
+
if (task.status === "completed" || task.status === "failed") {
|
|
840
|
+
return task;
|
|
841
|
+
}
|
|
842
|
+
} catch (err) {
|
|
843
|
+
consecutiveFailures += 1;
|
|
844
|
+
if (consecutiveFailures >= maxConsecutiveFailures) {
|
|
845
|
+
throw new Error(
|
|
846
|
+
`Polling failed ${maxConsecutiveFailures} times in a row for task ${id}: ${err}`
|
|
847
|
+
);
|
|
848
|
+
}
|
|
807
849
|
}
|
|
808
850
|
if (Date.now() - startTime > maxPollingTime) {
|
|
809
851
|
throw new Error(
|
|
@@ -813,16 +855,22 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
813
855
|
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
814
856
|
}
|
|
815
857
|
}
|
|
858
|
+
/**
|
|
859
|
+
* List research tasks
|
|
860
|
+
* @param options Pagination options
|
|
861
|
+
* @returns The paginated list of research tasks
|
|
862
|
+
*/
|
|
863
|
+
async listTasks(options) {
|
|
864
|
+
const params = this.buildPaginationParams(options);
|
|
865
|
+
return this.request(
|
|
866
|
+
"/tasks",
|
|
867
|
+
"GET",
|
|
868
|
+
void 0,
|
|
869
|
+
params
|
|
870
|
+
);
|
|
871
|
+
}
|
|
816
872
|
};
|
|
817
873
|
|
|
818
|
-
// src/research/types.ts
|
|
819
|
-
var ResearchStatus = /* @__PURE__ */ ((ResearchStatus2) => {
|
|
820
|
-
ResearchStatus2["in_progress"] = "in_progress";
|
|
821
|
-
ResearchStatus2["completed"] = "completed";
|
|
822
|
-
ResearchStatus2["failed"] = "failed";
|
|
823
|
-
return ResearchStatus2;
|
|
824
|
-
})(ResearchStatus || {});
|
|
825
|
-
|
|
826
874
|
// src/index.ts
|
|
827
875
|
var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : fetch;
|
|
828
876
|
var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : Headers;
|
|
@@ -925,7 +973,10 @@ var Exa2 = class {
|
|
|
925
973
|
if (!errorData.path) {
|
|
926
974
|
errorData.path = endpoint;
|
|
927
975
|
}
|
|
928
|
-
|
|
976
|
+
let message = errorData.error || "Unknown error";
|
|
977
|
+
if (errorData.message) {
|
|
978
|
+
message += (message.length > 0 ? ". " : "") + errorData.message;
|
|
979
|
+
}
|
|
929
980
|
throw new ExaError(
|
|
930
981
|
message,
|
|
931
982
|
response.status,
|
|
@@ -1240,7 +1291,8 @@ export {
|
|
|
1240
1291
|
ExaError,
|
|
1241
1292
|
HttpStatusCode,
|
|
1242
1293
|
ResearchClient,
|
|
1243
|
-
|
|
1294
|
+
ResearchCreateTaskRequestDtoModel as ResearchModel,
|
|
1295
|
+
ResearchTaskDtoStatus as ResearchStatus,
|
|
1244
1296
|
UpdateStreamStatus,
|
|
1245
1297
|
WebhookStatus,
|
|
1246
1298
|
WebsetEnrichmentFormat,
|