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/README.md +7 -8
- package/dist/index.d.mts +200 -131
- package/dist/index.d.ts +200 -131
- package/dist/index.js +76 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/dist/index.mjs
CHANGED
|
@@ -751,40 +751,65 @@ 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_ultra"] = "exa-ultra";
|
|
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 { model, ...rest } = params;
|
|
804
|
+
const payload = {
|
|
805
|
+
model: model ?? "exa-research" /* exa_research */,
|
|
806
|
+
...rest
|
|
807
|
+
};
|
|
808
|
+
return this.request(
|
|
809
|
+
"/tasks",
|
|
810
|
+
"POST",
|
|
811
|
+
payload
|
|
812
|
+
);
|
|
788
813
|
}
|
|
789
814
|
/**
|
|
790
815
|
* Retrieve a research task by ID.
|
|
@@ -795,15 +820,28 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
795
820
|
/**
|
|
796
821
|
* Poll a research task until completion or failure.
|
|
797
822
|
* Polls every 1 second with a maximum timeout of 10 minutes.
|
|
823
|
+
* Resilient to up to 10 consecutive polling failures.
|
|
798
824
|
*/
|
|
799
825
|
async pollTask(id) {
|
|
800
826
|
const pollingInterval = 1e3;
|
|
801
827
|
const maxPollingTime = 10 * 60 * 1e3;
|
|
828
|
+
const maxConsecutiveFailures = 10;
|
|
802
829
|
const startTime = Date.now();
|
|
830
|
+
let consecutiveFailures = 0;
|
|
803
831
|
while (true) {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
832
|
+
try {
|
|
833
|
+
const task = await this.request(`/tasks/${id}`, "GET");
|
|
834
|
+
consecutiveFailures = 0;
|
|
835
|
+
if (task.status === "completed" || task.status === "failed") {
|
|
836
|
+
return task;
|
|
837
|
+
}
|
|
838
|
+
} catch (err) {
|
|
839
|
+
consecutiveFailures += 1;
|
|
840
|
+
if (consecutiveFailures >= maxConsecutiveFailures) {
|
|
841
|
+
throw new Error(
|
|
842
|
+
`Polling failed ${maxConsecutiveFailures} times in a row for task ${id}: ${err}`
|
|
843
|
+
);
|
|
844
|
+
}
|
|
807
845
|
}
|
|
808
846
|
if (Date.now() - startTime > maxPollingTime) {
|
|
809
847
|
throw new Error(
|
|
@@ -813,16 +851,22 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
813
851
|
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
814
852
|
}
|
|
815
853
|
}
|
|
854
|
+
/**
|
|
855
|
+
* List research tasks
|
|
856
|
+
* @param options Pagination options
|
|
857
|
+
* @returns The paginated list of research tasks
|
|
858
|
+
*/
|
|
859
|
+
async listTasks(options) {
|
|
860
|
+
const params = this.buildPaginationParams(options);
|
|
861
|
+
return this.request(
|
|
862
|
+
"/tasks",
|
|
863
|
+
"GET",
|
|
864
|
+
void 0,
|
|
865
|
+
params
|
|
866
|
+
);
|
|
867
|
+
}
|
|
816
868
|
};
|
|
817
869
|
|
|
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
870
|
// src/index.ts
|
|
827
871
|
var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : fetch;
|
|
828
872
|
var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : Headers;
|
|
@@ -1240,7 +1284,8 @@ export {
|
|
|
1240
1284
|
ExaError,
|
|
1241
1285
|
HttpStatusCode,
|
|
1242
1286
|
ResearchClient,
|
|
1243
|
-
|
|
1287
|
+
ResearchCreateTaskRequestDtoModel as ResearchModel,
|
|
1288
|
+
ResearchTaskDtoStatus as ResearchStatus,
|
|
1244
1289
|
UpdateStreamStatus,
|
|
1245
1290
|
WebhookStatus,
|
|
1246
1291
|
WebsetEnrichmentFormat,
|