exa-js 1.8.27 → 1.9.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.d.mts +1577 -384
- package/dist/index.d.ts +1577 -384
- package/dist/index.js +48 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1019,50 +1019,25 @@ function zodToJsonSchema(schema) {
|
|
|
1019
1019
|
|
|
1020
1020
|
// src/research/base.ts
|
|
1021
1021
|
var ResearchBaseClient = class {
|
|
1022
|
-
/**
|
|
1023
|
-
* Initialize a new Research base client
|
|
1024
|
-
* @param client The Exa client instance
|
|
1025
|
-
*/
|
|
1026
1022
|
constructor(client) {
|
|
1027
1023
|
this.client = client;
|
|
1028
1024
|
}
|
|
1029
|
-
/**
|
|
1030
|
-
* Make a request to the Research API (prefixes all paths with `/research`).
|
|
1031
|
-
* @param endpoint The endpoint path, beginning with a slash (e.g. "/tasks").
|
|
1032
|
-
* @param method The HTTP method. Defaults to "POST".
|
|
1033
|
-
* @param data Optional request body
|
|
1034
|
-
* @param params Optional query parameters
|
|
1035
|
-
* @returns The parsed JSON response
|
|
1036
|
-
*/
|
|
1037
1025
|
async request(endpoint, method = "POST", data, params) {
|
|
1038
1026
|
return this.client.request(
|
|
1039
|
-
`/research/
|
|
1027
|
+
`/research/v1${endpoint}`,
|
|
1040
1028
|
method,
|
|
1041
1029
|
data,
|
|
1042
1030
|
params
|
|
1043
1031
|
);
|
|
1044
1032
|
}
|
|
1045
|
-
/**
|
|
1046
|
-
* Make a request to the Research API (prefixes all paths with `/research`).
|
|
1047
|
-
* @param endpoint The endpoint path, beginning with a slash (e.g. "/tasks").
|
|
1048
|
-
* @param method The HTTP method. Defaults to "POST".
|
|
1049
|
-
* @param data Optional request body
|
|
1050
|
-
* @param params Optional query parameters
|
|
1051
|
-
* @returns The parsed JSON response
|
|
1052
|
-
*/
|
|
1053
1033
|
async rawRequest(endpoint, method = "POST", data, params) {
|
|
1054
1034
|
return this.client.rawRequest(
|
|
1055
|
-
`/research/
|
|
1035
|
+
`/research/v1${endpoint}`,
|
|
1056
1036
|
method,
|
|
1057
1037
|
data,
|
|
1058
1038
|
params
|
|
1059
1039
|
);
|
|
1060
1040
|
}
|
|
1061
|
-
/**
|
|
1062
|
-
* Helper to build pagination parameters.
|
|
1063
|
-
* @param pagination The pagination parameters
|
|
1064
|
-
* @returns QueryParams object with pagination parameters
|
|
1065
|
-
*/
|
|
1066
1041
|
buildPaginationParams(pagination) {
|
|
1067
1042
|
const params = {};
|
|
1068
1043
|
if (!pagination) return params;
|
|
@@ -1077,26 +1052,34 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
1077
1052
|
constructor(client) {
|
|
1078
1053
|
super(client);
|
|
1079
1054
|
}
|
|
1080
|
-
async
|
|
1081
|
-
const { instructions, model,
|
|
1082
|
-
let schema =
|
|
1055
|
+
async create(params) {
|
|
1056
|
+
const { instructions, model, outputSchema } = params;
|
|
1057
|
+
let schema = outputSchema;
|
|
1083
1058
|
if (schema && isZodSchema(schema)) {
|
|
1084
1059
|
schema = zodToJsonSchema(schema);
|
|
1085
1060
|
}
|
|
1086
1061
|
const payload = {
|
|
1087
1062
|
instructions,
|
|
1088
|
-
model: model ?? "exa-research"
|
|
1089
|
-
output: output ? {
|
|
1090
|
-
schema,
|
|
1091
|
-
inferSchema: output.inferSchema ?? true
|
|
1092
|
-
} : { inferSchema: true }
|
|
1063
|
+
model: model ?? "exa-research"
|
|
1093
1064
|
};
|
|
1094
|
-
|
|
1065
|
+
if (schema) {
|
|
1066
|
+
payload.outputSchema = schema;
|
|
1067
|
+
}
|
|
1068
|
+
return this.request("", "POST", payload);
|
|
1095
1069
|
}
|
|
1096
|
-
|
|
1070
|
+
get(researchId, options) {
|
|
1097
1071
|
if (options?.stream) {
|
|
1098
1072
|
const promise = async () => {
|
|
1099
|
-
const
|
|
1073
|
+
const params = { stream: "true" };
|
|
1074
|
+
if (options.events !== void 0) {
|
|
1075
|
+
params.events = options.events.toString();
|
|
1076
|
+
}
|
|
1077
|
+
const resp = await this.rawRequest(
|
|
1078
|
+
`/${researchId}`,
|
|
1079
|
+
"GET",
|
|
1080
|
+
void 0,
|
|
1081
|
+
params
|
|
1082
|
+
);
|
|
1100
1083
|
if (!resp.body) {
|
|
1101
1084
|
throw new Error("No response body for SSE stream");
|
|
1102
1085
|
}
|
|
@@ -1140,59 +1123,53 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
1140
1123
|
};
|
|
1141
1124
|
return promise();
|
|
1142
1125
|
} else {
|
|
1143
|
-
|
|
1126
|
+
const params = { stream: "false" };
|
|
1127
|
+
if (options?.events !== void 0) {
|
|
1128
|
+
params.events = options.events.toString();
|
|
1129
|
+
}
|
|
1130
|
+
return this.request(
|
|
1131
|
+
`/${researchId}`,
|
|
1132
|
+
"GET",
|
|
1133
|
+
void 0,
|
|
1134
|
+
params
|
|
1135
|
+
);
|
|
1144
1136
|
}
|
|
1145
1137
|
}
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
const pollingInterval = 1e3;
|
|
1155
|
-
const maxPollingTime = 10 * 60 * 1e3;
|
|
1156
|
-
const maxConsecutiveFailures = 10;
|
|
1138
|
+
async list(options) {
|
|
1139
|
+
const params = this.buildPaginationParams(options);
|
|
1140
|
+
return this.request("", "GET", void 0, params);
|
|
1141
|
+
}
|
|
1142
|
+
async pollUntilFinished(researchId, options) {
|
|
1143
|
+
const pollInterval = options?.pollInterval ?? 1e3;
|
|
1144
|
+
const timeoutMs = options?.timeoutMs ?? 10 * 60 * 1e3;
|
|
1145
|
+
const maxConsecutiveFailures = 5;
|
|
1157
1146
|
const startTime = Date.now();
|
|
1158
1147
|
let consecutiveFailures = 0;
|
|
1159
1148
|
while (true) {
|
|
1160
1149
|
try {
|
|
1161
|
-
const
|
|
1150
|
+
const research = await this.get(researchId, {
|
|
1151
|
+
events: options?.events
|
|
1152
|
+
});
|
|
1162
1153
|
consecutiveFailures = 0;
|
|
1163
|
-
if (
|
|
1164
|
-
return
|
|
1154
|
+
if (research.status === "completed" || research.status === "failed" || research.status === "canceled") {
|
|
1155
|
+
return research;
|
|
1165
1156
|
}
|
|
1166
1157
|
} catch (err) {
|
|
1167
1158
|
consecutiveFailures += 1;
|
|
1168
1159
|
if (consecutiveFailures >= maxConsecutiveFailures) {
|
|
1169
1160
|
throw new Error(
|
|
1170
|
-
`Polling failed ${maxConsecutiveFailures} times in a row for
|
|
1161
|
+
`Polling failed ${maxConsecutiveFailures} times in a row for research ${researchId}: ${err}`
|
|
1171
1162
|
);
|
|
1172
1163
|
}
|
|
1173
1164
|
}
|
|
1174
|
-
if (Date.now() - startTime >
|
|
1165
|
+
if (Date.now() - startTime > timeoutMs) {
|
|
1175
1166
|
throw new Error(
|
|
1176
|
-
`Polling timeout:
|
|
1167
|
+
`Polling timeout: Research ${researchId} did not complete within ${timeoutMs}ms`
|
|
1177
1168
|
);
|
|
1178
1169
|
}
|
|
1179
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
1170
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1180
1171
|
}
|
|
1181
1172
|
}
|
|
1182
|
-
/**
|
|
1183
|
-
* List research tasks
|
|
1184
|
-
* @param options Pagination options
|
|
1185
|
-
* @returns The paginated list of research tasks
|
|
1186
|
-
*/
|
|
1187
|
-
async listTasks(options) {
|
|
1188
|
-
const params = this.buildPaginationParams(options);
|
|
1189
|
-
return this.request(
|
|
1190
|
-
"/tasks",
|
|
1191
|
-
"GET",
|
|
1192
|
-
void 0,
|
|
1193
|
-
params
|
|
1194
|
-
);
|
|
1195
|
-
}
|
|
1196
1173
|
};
|
|
1197
1174
|
|
|
1198
1175
|
// src/index.ts
|
|
@@ -1642,7 +1619,6 @@ export {
|
|
|
1642
1619
|
MonitorRunType,
|
|
1643
1620
|
MonitorStatus,
|
|
1644
1621
|
PreviewWebsetResponseEnrichmentsFormat,
|
|
1645
|
-
ResearchClient,
|
|
1646
1622
|
ScopeSourceType,
|
|
1647
1623
|
UpdateMonitorStatus,
|
|
1648
1624
|
WebhookStatus,
|