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.js
CHANGED
|
@@ -52,7 +52,6 @@ __export(index_exports, {
|
|
|
52
52
|
MonitorRunType: () => MonitorRunType,
|
|
53
53
|
MonitorStatus: () => MonitorStatus,
|
|
54
54
|
PreviewWebsetResponseEnrichmentsFormat: () => PreviewWebsetResponseEnrichmentsFormat,
|
|
55
|
-
ResearchClient: () => ResearchClient,
|
|
56
55
|
ScopeSourceType: () => ScopeSourceType,
|
|
57
56
|
UpdateMonitorStatus: () => UpdateMonitorStatus,
|
|
58
57
|
WebhookStatus: () => WebhookStatus,
|
|
@@ -1093,50 +1092,25 @@ function zodToJsonSchema(schema) {
|
|
|
1093
1092
|
|
|
1094
1093
|
// src/research/base.ts
|
|
1095
1094
|
var ResearchBaseClient = class {
|
|
1096
|
-
/**
|
|
1097
|
-
* Initialize a new Research base client
|
|
1098
|
-
* @param client The Exa client instance
|
|
1099
|
-
*/
|
|
1100
1095
|
constructor(client) {
|
|
1101
1096
|
this.client = client;
|
|
1102
1097
|
}
|
|
1103
|
-
/**
|
|
1104
|
-
* Make a request to the Research API (prefixes all paths with `/research`).
|
|
1105
|
-
* @param endpoint The endpoint path, beginning with a slash (e.g. "/tasks").
|
|
1106
|
-
* @param method The HTTP method. Defaults to "POST".
|
|
1107
|
-
* @param data Optional request body
|
|
1108
|
-
* @param params Optional query parameters
|
|
1109
|
-
* @returns The parsed JSON response
|
|
1110
|
-
*/
|
|
1111
1098
|
async request(endpoint, method = "POST", data, params) {
|
|
1112
1099
|
return this.client.request(
|
|
1113
|
-
`/research/
|
|
1100
|
+
`/research/v1${endpoint}`,
|
|
1114
1101
|
method,
|
|
1115
1102
|
data,
|
|
1116
1103
|
params
|
|
1117
1104
|
);
|
|
1118
1105
|
}
|
|
1119
|
-
/**
|
|
1120
|
-
* Make a request to the Research API (prefixes all paths with `/research`).
|
|
1121
|
-
* @param endpoint The endpoint path, beginning with a slash (e.g. "/tasks").
|
|
1122
|
-
* @param method The HTTP method. Defaults to "POST".
|
|
1123
|
-
* @param data Optional request body
|
|
1124
|
-
* @param params Optional query parameters
|
|
1125
|
-
* @returns The parsed JSON response
|
|
1126
|
-
*/
|
|
1127
1106
|
async rawRequest(endpoint, method = "POST", data, params) {
|
|
1128
1107
|
return this.client.rawRequest(
|
|
1129
|
-
`/research/
|
|
1108
|
+
`/research/v1${endpoint}`,
|
|
1130
1109
|
method,
|
|
1131
1110
|
data,
|
|
1132
1111
|
params
|
|
1133
1112
|
);
|
|
1134
1113
|
}
|
|
1135
|
-
/**
|
|
1136
|
-
* Helper to build pagination parameters.
|
|
1137
|
-
* @param pagination The pagination parameters
|
|
1138
|
-
* @returns QueryParams object with pagination parameters
|
|
1139
|
-
*/
|
|
1140
1114
|
buildPaginationParams(pagination) {
|
|
1141
1115
|
const params = {};
|
|
1142
1116
|
if (!pagination) return params;
|
|
@@ -1151,26 +1125,34 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
1151
1125
|
constructor(client) {
|
|
1152
1126
|
super(client);
|
|
1153
1127
|
}
|
|
1154
|
-
async
|
|
1155
|
-
const { instructions, model,
|
|
1156
|
-
let schema =
|
|
1128
|
+
async create(params) {
|
|
1129
|
+
const { instructions, model, outputSchema } = params;
|
|
1130
|
+
let schema = outputSchema;
|
|
1157
1131
|
if (schema && isZodSchema(schema)) {
|
|
1158
1132
|
schema = zodToJsonSchema(schema);
|
|
1159
1133
|
}
|
|
1160
1134
|
const payload = {
|
|
1161
1135
|
instructions,
|
|
1162
|
-
model: model ?? "exa-research"
|
|
1163
|
-
output: output ? {
|
|
1164
|
-
schema,
|
|
1165
|
-
inferSchema: output.inferSchema ?? true
|
|
1166
|
-
} : { inferSchema: true }
|
|
1136
|
+
model: model ?? "exa-research"
|
|
1167
1137
|
};
|
|
1168
|
-
|
|
1138
|
+
if (schema) {
|
|
1139
|
+
payload.outputSchema = schema;
|
|
1140
|
+
}
|
|
1141
|
+
return this.request("", "POST", payload);
|
|
1169
1142
|
}
|
|
1170
|
-
|
|
1143
|
+
get(researchId, options) {
|
|
1171
1144
|
if (options?.stream) {
|
|
1172
1145
|
const promise = async () => {
|
|
1173
|
-
const
|
|
1146
|
+
const params = { stream: "true" };
|
|
1147
|
+
if (options.events !== void 0) {
|
|
1148
|
+
params.events = options.events.toString();
|
|
1149
|
+
}
|
|
1150
|
+
const resp = await this.rawRequest(
|
|
1151
|
+
`/${researchId}`,
|
|
1152
|
+
"GET",
|
|
1153
|
+
void 0,
|
|
1154
|
+
params
|
|
1155
|
+
);
|
|
1174
1156
|
if (!resp.body) {
|
|
1175
1157
|
throw new Error("No response body for SSE stream");
|
|
1176
1158
|
}
|
|
@@ -1214,59 +1196,53 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
1214
1196
|
};
|
|
1215
1197
|
return promise();
|
|
1216
1198
|
} else {
|
|
1217
|
-
|
|
1199
|
+
const params = { stream: "false" };
|
|
1200
|
+
if (options?.events !== void 0) {
|
|
1201
|
+
params.events = options.events.toString();
|
|
1202
|
+
}
|
|
1203
|
+
return this.request(
|
|
1204
|
+
`/${researchId}`,
|
|
1205
|
+
"GET",
|
|
1206
|
+
void 0,
|
|
1207
|
+
params
|
|
1208
|
+
);
|
|
1218
1209
|
}
|
|
1219
1210
|
}
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
const pollingInterval = 1e3;
|
|
1229
|
-
const maxPollingTime = 10 * 60 * 1e3;
|
|
1230
|
-
const maxConsecutiveFailures = 10;
|
|
1211
|
+
async list(options) {
|
|
1212
|
+
const params = this.buildPaginationParams(options);
|
|
1213
|
+
return this.request("", "GET", void 0, params);
|
|
1214
|
+
}
|
|
1215
|
+
async pollUntilFinished(researchId, options) {
|
|
1216
|
+
const pollInterval = options?.pollInterval ?? 1e3;
|
|
1217
|
+
const timeoutMs = options?.timeoutMs ?? 10 * 60 * 1e3;
|
|
1218
|
+
const maxConsecutiveFailures = 5;
|
|
1231
1219
|
const startTime = Date.now();
|
|
1232
1220
|
let consecutiveFailures = 0;
|
|
1233
1221
|
while (true) {
|
|
1234
1222
|
try {
|
|
1235
|
-
const
|
|
1223
|
+
const research = await this.get(researchId, {
|
|
1224
|
+
events: options?.events
|
|
1225
|
+
});
|
|
1236
1226
|
consecutiveFailures = 0;
|
|
1237
|
-
if (
|
|
1238
|
-
return
|
|
1227
|
+
if (research.status === "completed" || research.status === "failed" || research.status === "canceled") {
|
|
1228
|
+
return research;
|
|
1239
1229
|
}
|
|
1240
1230
|
} catch (err) {
|
|
1241
1231
|
consecutiveFailures += 1;
|
|
1242
1232
|
if (consecutiveFailures >= maxConsecutiveFailures) {
|
|
1243
1233
|
throw new Error(
|
|
1244
|
-
`Polling failed ${maxConsecutiveFailures} times in a row for
|
|
1234
|
+
`Polling failed ${maxConsecutiveFailures} times in a row for research ${researchId}: ${err}`
|
|
1245
1235
|
);
|
|
1246
1236
|
}
|
|
1247
1237
|
}
|
|
1248
|
-
if (Date.now() - startTime >
|
|
1238
|
+
if (Date.now() - startTime > timeoutMs) {
|
|
1249
1239
|
throw new Error(
|
|
1250
|
-
`Polling timeout:
|
|
1240
|
+
`Polling timeout: Research ${researchId} did not complete within ${timeoutMs}ms`
|
|
1251
1241
|
);
|
|
1252
1242
|
}
|
|
1253
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
1243
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1254
1244
|
}
|
|
1255
1245
|
}
|
|
1256
|
-
/**
|
|
1257
|
-
* List research tasks
|
|
1258
|
-
* @param options Pagination options
|
|
1259
|
-
* @returns The paginated list of research tasks
|
|
1260
|
-
*/
|
|
1261
|
-
async listTasks(options) {
|
|
1262
|
-
const params = this.buildPaginationParams(options);
|
|
1263
|
-
return this.request(
|
|
1264
|
-
"/tasks",
|
|
1265
|
-
"GET",
|
|
1266
|
-
void 0,
|
|
1267
|
-
params
|
|
1268
|
-
);
|
|
1269
|
-
}
|
|
1270
1246
|
};
|
|
1271
1247
|
|
|
1272
1248
|
// src/index.ts
|
|
@@ -1717,7 +1693,6 @@ var index_default = Exa2;
|
|
|
1717
1693
|
MonitorRunType,
|
|
1718
1694
|
MonitorStatus,
|
|
1719
1695
|
PreviewWebsetResponseEnrichmentsFormat,
|
|
1720
|
-
ResearchClient,
|
|
1721
1696
|
ScopeSourceType,
|
|
1722
1697
|
UpdateMonitorStatus,
|
|
1723
1698
|
WebhookStatus,
|