exa-js 1.8.6 → 1.8.9
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.d.mts +344 -96
- package/dist/index.d.ts +344 -96
- package/dist/index.js +104 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +104 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -782,6 +782,22 @@ var ResearchBaseClient = class {
|
|
|
782
782
|
params
|
|
783
783
|
);
|
|
784
784
|
}
|
|
785
|
+
/**
|
|
786
|
+
* Make a request to the Research API (prefixes all paths with `/research`).
|
|
787
|
+
* @param endpoint The endpoint path, beginning with a slash (e.g. "/tasks").
|
|
788
|
+
* @param method The HTTP method. Defaults to "POST".
|
|
789
|
+
* @param data Optional request body
|
|
790
|
+
* @param params Optional query parameters
|
|
791
|
+
* @returns The parsed JSON response
|
|
792
|
+
*/
|
|
793
|
+
async rawRequest(endpoint, method = "POST", data, params) {
|
|
794
|
+
return this.client.rawRequest(
|
|
795
|
+
`/research/v0${endpoint}`,
|
|
796
|
+
method,
|
|
797
|
+
data,
|
|
798
|
+
params
|
|
799
|
+
);
|
|
800
|
+
}
|
|
785
801
|
/**
|
|
786
802
|
* Helper to build pagination parameters.
|
|
787
803
|
* @param pagination The pagination parameters
|
|
@@ -796,19 +812,6 @@ var ResearchBaseClient = class {
|
|
|
796
812
|
}
|
|
797
813
|
};
|
|
798
814
|
|
|
799
|
-
// src/research/openapi.ts
|
|
800
|
-
var ResearchCreateTaskRequestDtoModel = /* @__PURE__ */ ((ResearchCreateTaskRequestDtoModel2) => {
|
|
801
|
-
ResearchCreateTaskRequestDtoModel2["exa_research"] = "exa-research";
|
|
802
|
-
ResearchCreateTaskRequestDtoModel2["exa_research_pro"] = "exa-research-pro";
|
|
803
|
-
return ResearchCreateTaskRequestDtoModel2;
|
|
804
|
-
})(ResearchCreateTaskRequestDtoModel || {});
|
|
805
|
-
var ResearchTaskDtoStatus = /* @__PURE__ */ ((ResearchTaskDtoStatus2) => {
|
|
806
|
-
ResearchTaskDtoStatus2["running"] = "running";
|
|
807
|
-
ResearchTaskDtoStatus2["completed"] = "completed";
|
|
808
|
-
ResearchTaskDtoStatus2["failed"] = "failed";
|
|
809
|
-
return ResearchTaskDtoStatus2;
|
|
810
|
-
})(ResearchTaskDtoStatus || {});
|
|
811
|
-
|
|
812
815
|
// src/research/client.ts
|
|
813
816
|
var ResearchClient = class extends ResearchBaseClient {
|
|
814
817
|
constructor(client) {
|
|
@@ -834,19 +837,61 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
834
837
|
inferSchema: output.inferSchema ?? true
|
|
835
838
|
} : { inferSchema: true }
|
|
836
839
|
};
|
|
837
|
-
return this.request(
|
|
838
|
-
"/tasks",
|
|
839
|
-
"POST",
|
|
840
|
-
payload
|
|
841
|
-
);
|
|
840
|
+
return this.request("/tasks", "POST", payload);
|
|
842
841
|
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
842
|
+
getTask(id, options) {
|
|
843
|
+
if (options?.stream) {
|
|
844
|
+
const promise = async () => {
|
|
845
|
+
const resp = await this.rawRequest(`/tasks/${id}?stream=true`, "GET");
|
|
846
|
+
if (!resp.body) {
|
|
847
|
+
throw new Error("No response body for SSE stream");
|
|
848
|
+
}
|
|
849
|
+
const reader = resp.body.getReader();
|
|
850
|
+
const decoder = new TextDecoder();
|
|
851
|
+
let buffer = "";
|
|
852
|
+
function processPart(part) {
|
|
853
|
+
const lines = part.split("\n");
|
|
854
|
+
let data = lines.slice(1).join("\n");
|
|
855
|
+
if (data.startsWith("data:")) {
|
|
856
|
+
data = data.slice(5).trimStart();
|
|
857
|
+
}
|
|
858
|
+
try {
|
|
859
|
+
return JSON.parse(data);
|
|
860
|
+
} catch (e) {
|
|
861
|
+
return null;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
async function* streamEvents() {
|
|
865
|
+
while (true) {
|
|
866
|
+
const { done, value } = await reader.read();
|
|
867
|
+
if (done) break;
|
|
868
|
+
buffer += decoder.decode(value, { stream: true });
|
|
869
|
+
let parts = buffer.split("\n\n");
|
|
870
|
+
buffer = parts.pop() ?? "";
|
|
871
|
+
for (const part of parts) {
|
|
872
|
+
const processed = processPart(part);
|
|
873
|
+
if (processed) {
|
|
874
|
+
yield processed;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
if (buffer.trim()) {
|
|
879
|
+
const processed = processPart(buffer.trim());
|
|
880
|
+
if (processed) {
|
|
881
|
+
yield processed;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
return streamEvents();
|
|
886
|
+
};
|
|
887
|
+
return promise();
|
|
888
|
+
} else {
|
|
889
|
+
return this.request(`/tasks/${id}`, "GET");
|
|
890
|
+
}
|
|
848
891
|
}
|
|
849
892
|
/**
|
|
893
|
+
* @deprecated This method is deprecated and may be removed in a future release.
|
|
894
|
+
* @see getTask(id, {stream: true})
|
|
850
895
|
* Poll a research task until completion or failure.
|
|
851
896
|
* Polls every 1 second with a maximum timeout of 10 minutes.
|
|
852
897
|
* Resilient to up to 10 consecutive polling failures.
|
|
@@ -896,6 +941,19 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
896
941
|
}
|
|
897
942
|
};
|
|
898
943
|
|
|
944
|
+
// src/research/openapi.ts
|
|
945
|
+
var ResearchCreateOpenAIResponseDtoModel = /* @__PURE__ */ ((ResearchCreateOpenAIResponseDtoModel2) => {
|
|
946
|
+
ResearchCreateOpenAIResponseDtoModel2["exa_research"] = "exa-research";
|
|
947
|
+
ResearchCreateOpenAIResponseDtoModel2["exa_research_pro"] = "exa-research-pro";
|
|
948
|
+
return ResearchCreateOpenAIResponseDtoModel2;
|
|
949
|
+
})(ResearchCreateOpenAIResponseDtoModel || {});
|
|
950
|
+
var ResearchTaskDtoStatus = /* @__PURE__ */ ((ResearchTaskDtoStatus2) => {
|
|
951
|
+
ResearchTaskDtoStatus2["running"] = "running";
|
|
952
|
+
ResearchTaskDtoStatus2["completed"] = "completed";
|
|
953
|
+
ResearchTaskDtoStatus2["failed"] = "failed";
|
|
954
|
+
return ResearchTaskDtoStatus2;
|
|
955
|
+
})(ResearchTaskDtoStatus || {});
|
|
956
|
+
|
|
899
957
|
// src/index.ts
|
|
900
958
|
var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : fetch;
|
|
901
959
|
var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : Headers;
|
|
@@ -1017,6 +1075,28 @@ var Exa2 = class {
|
|
|
1017
1075
|
}
|
|
1018
1076
|
return await response.json();
|
|
1019
1077
|
}
|
|
1078
|
+
async rawRequest(endpoint, method = "POST", body, queryParams) {
|
|
1079
|
+
let url = this.baseURL + endpoint;
|
|
1080
|
+
if (queryParams) {
|
|
1081
|
+
const searchParams = new URLSearchParams();
|
|
1082
|
+
for (const [key, value] of Object.entries(queryParams)) {
|
|
1083
|
+
if (Array.isArray(value)) {
|
|
1084
|
+
for (const item of value) {
|
|
1085
|
+
searchParams.append(key, String(item));
|
|
1086
|
+
}
|
|
1087
|
+
} else if (value !== void 0) {
|
|
1088
|
+
searchParams.append(key, String(value));
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
url += `?${searchParams.toString()}`;
|
|
1092
|
+
}
|
|
1093
|
+
const response = await fetchImpl(url, {
|
|
1094
|
+
method,
|
|
1095
|
+
headers: this.headers,
|
|
1096
|
+
body: body ? JSON.stringify(body) : void 0
|
|
1097
|
+
});
|
|
1098
|
+
return response;
|
|
1099
|
+
}
|
|
1020
1100
|
/**
|
|
1021
1101
|
* Performs a search with an Exa prompt-engineered query.
|
|
1022
1102
|
*
|
|
@@ -1324,7 +1404,7 @@ export {
|
|
|
1324
1404
|
MonitorRunType,
|
|
1325
1405
|
MonitorStatus,
|
|
1326
1406
|
ResearchClient,
|
|
1327
|
-
|
|
1407
|
+
ResearchCreateOpenAIResponseDtoModel as ResearchModel,
|
|
1328
1408
|
ResearchTaskDtoStatus as ResearchStatus,
|
|
1329
1409
|
UpdateMonitorStatus,
|
|
1330
1410
|
WebhookStatus,
|