exa-js 2.5.1-beta.1 → 2.5.1-beta.3
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 +86 -27
- package/dist/index.d.ts +86 -27
- package/dist/index.js +1845 -1640
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1870 -1665
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -33,16 +33,16 @@ __export(index_exports, {
|
|
|
33
33
|
CreateEnrichmentParametersFormat: () => CreateEnrichmentParametersFormat,
|
|
34
34
|
CreateImportParametersFormat: () => CreateImportParametersFormat,
|
|
35
35
|
EventType: () => EventType,
|
|
36
|
-
EventsClient: () =>
|
|
36
|
+
EventsClient: () => EventsClient2,
|
|
37
37
|
Exa: () => Exa3,
|
|
38
38
|
ExaError: () => ExaError,
|
|
39
|
-
ExaNova: () =>
|
|
39
|
+
ExaNova: () => Exa,
|
|
40
40
|
HttpStatusCode: () => HttpStatusCode,
|
|
41
41
|
ImportFailedReason: () => ImportFailedReason,
|
|
42
42
|
ImportFormat: () => ImportFormat,
|
|
43
43
|
ImportObject: () => ImportObject,
|
|
44
44
|
ImportStatus: () => ImportStatus,
|
|
45
|
-
ImportsClient: () =>
|
|
45
|
+
ImportsClient: () => ImportsClient2,
|
|
46
46
|
MonitorObject: () => MonitorObject,
|
|
47
47
|
MonitorRunObject: () => MonitorRunObject,
|
|
48
48
|
MonitorRunStatus: () => MonitorRunStatus,
|
|
@@ -52,21 +52,21 @@ __export(index_exports, {
|
|
|
52
52
|
WebhookStatus: () => WebhookStatus,
|
|
53
53
|
WebsetEnrichmentFormat: () => WebsetEnrichmentFormat,
|
|
54
54
|
WebsetEnrichmentStatus: () => WebsetEnrichmentStatus,
|
|
55
|
-
WebsetEnrichmentsClient: () =>
|
|
55
|
+
WebsetEnrichmentsClient: () => WebsetEnrichmentsClient2,
|
|
56
56
|
WebsetExcludeSource: () => WebsetExcludeSource,
|
|
57
57
|
WebsetImportSource: () => WebsetImportSource,
|
|
58
58
|
WebsetItemEvaluationSatisfied: () => WebsetItemEvaluationSatisfied,
|
|
59
59
|
WebsetItemSource: () => WebsetItemSource,
|
|
60
|
-
WebsetItemsClient: () =>
|
|
61
|
-
WebsetMonitorsClient: () =>
|
|
60
|
+
WebsetItemsClient: () => WebsetItemsClient2,
|
|
61
|
+
WebsetMonitorsClient: () => WebsetMonitorsClient2,
|
|
62
62
|
WebsetSearchBehavior: () => WebsetSearchBehavior,
|
|
63
63
|
WebsetSearchCanceledReason: () => WebsetSearchCanceledReason,
|
|
64
64
|
WebsetSearchScopeSource: () => WebsetSearchScopeSource,
|
|
65
65
|
WebsetSearchStatus: () => WebsetSearchStatus,
|
|
66
|
-
WebsetSearchesClient: () =>
|
|
66
|
+
WebsetSearchesClient: () => WebsetSearchesClient2,
|
|
67
67
|
WebsetStatus: () => WebsetStatus,
|
|
68
|
-
WebsetWebhooksClient: () =>
|
|
69
|
-
WebsetsClient: () =>
|
|
68
|
+
WebsetWebhooksClient: () => WebsetWebhooksClient2,
|
|
69
|
+
WebsetsClient: () => WebsetsClient2,
|
|
70
70
|
default: () => index_default
|
|
71
71
|
});
|
|
72
72
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -75,7 +75,7 @@ var import_cross_fetch = __toESM(require("cross-fetch"));
|
|
|
75
75
|
// package.json
|
|
76
76
|
var package_default = {
|
|
77
77
|
name: "exa-js",
|
|
78
|
-
version: "2.5.1-beta.
|
|
78
|
+
version: "2.5.1-beta.3",
|
|
79
79
|
description: "Exa SDK for Node.js and the browser",
|
|
80
80
|
publishConfig: {
|
|
81
81
|
access: "public"
|
|
@@ -159,67 +159,14 @@ var package_default = {
|
|
|
159
159
|
homepage: "https://github.com/exa-labs/exa-js#readme"
|
|
160
160
|
};
|
|
161
161
|
|
|
162
|
-
// src/
|
|
163
|
-
var
|
|
164
|
-
HttpStatusCode2[HttpStatusCode2["BadRequest"] = 400] = "BadRequest";
|
|
165
|
-
HttpStatusCode2[HttpStatusCode2["NotFound"] = 404] = "NotFound";
|
|
166
|
-
HttpStatusCode2[HttpStatusCode2["Unauthorized"] = 401] = "Unauthorized";
|
|
167
|
-
HttpStatusCode2[HttpStatusCode2["Forbidden"] = 403] = "Forbidden";
|
|
168
|
-
HttpStatusCode2[HttpStatusCode2["TooManyRequests"] = 429] = "TooManyRequests";
|
|
169
|
-
HttpStatusCode2[HttpStatusCode2["RequestTimeout"] = 408] = "RequestTimeout";
|
|
170
|
-
HttpStatusCode2[HttpStatusCode2["InternalServerError"] = 500] = "InternalServerError";
|
|
171
|
-
HttpStatusCode2[HttpStatusCode2["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
172
|
-
return HttpStatusCode2;
|
|
173
|
-
})(HttpStatusCode || {});
|
|
174
|
-
var ExaError = class extends Error {
|
|
175
|
-
/**
|
|
176
|
-
* Create a new ExaError
|
|
177
|
-
* @param message Error message
|
|
178
|
-
* @param statusCode HTTP status code
|
|
179
|
-
* @param timestamp ISO timestamp from API
|
|
180
|
-
* @param path Path that caused the error
|
|
181
|
-
*/
|
|
182
|
-
constructor(message, statusCode, timestamp, path) {
|
|
183
|
-
super(message);
|
|
184
|
-
this.name = "ExaError";
|
|
185
|
-
this.statusCode = statusCode;
|
|
186
|
-
this.timestamp = timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
187
|
-
this.path = path;
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
// src/zod-utils.ts
|
|
192
|
-
var import_zod = require("zod");
|
|
193
|
-
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
194
|
-
function isZodSchema(obj) {
|
|
195
|
-
return obj instanceof import_zod.ZodType;
|
|
196
|
-
}
|
|
197
|
-
function zodToJsonSchema(schema) {
|
|
198
|
-
return (0, import_zod_to_json_schema.zodToJsonSchema)(schema, {
|
|
199
|
-
$refStrategy: "none"
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// src/research/base.ts
|
|
204
|
-
var ResearchBaseClient = class {
|
|
162
|
+
// src/nova/websets-client.ts
|
|
163
|
+
var WebsetsBaseClient = class {
|
|
205
164
|
constructor(client) {
|
|
206
165
|
this.client = client;
|
|
207
166
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
method,
|
|
212
|
-
data,
|
|
213
|
-
params
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
async rawRequest(endpoint, method = "POST", data, params) {
|
|
217
|
-
return this.client.rawRequest(
|
|
218
|
-
`/research/v1${endpoint}`,
|
|
219
|
-
method,
|
|
220
|
-
data,
|
|
221
|
-
params
|
|
222
|
-
);
|
|
167
|
+
/** Make a request to the API, prepending `/websets` to the path. */
|
|
168
|
+
async request(endpoint, method = "POST", data, params, headers) {
|
|
169
|
+
return this.client.request(`/websets${endpoint}`, method, data, params, headers);
|
|
223
170
|
}
|
|
224
171
|
buildPaginationParams(pagination) {
|
|
225
172
|
const params = {};
|
|
@@ -229,286 +176,83 @@ var ResearchBaseClient = class {
|
|
|
229
176
|
return params;
|
|
230
177
|
}
|
|
231
178
|
};
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
constructor(client) {
|
|
236
|
-
super(client);
|
|
237
|
-
}
|
|
238
|
-
async create(params) {
|
|
239
|
-
const { instructions, model, outputSchema } = params;
|
|
240
|
-
let schema = outputSchema;
|
|
241
|
-
if (schema && isZodSchema(schema)) {
|
|
242
|
-
schema = zodToJsonSchema(schema);
|
|
243
|
-
}
|
|
244
|
-
const payload = {
|
|
245
|
-
instructions,
|
|
246
|
-
model: model ?? "exa-research-fast"
|
|
247
|
-
};
|
|
248
|
-
if (schema) {
|
|
249
|
-
payload.outputSchema = schema;
|
|
250
|
-
}
|
|
251
|
-
return this.request("", "POST", payload);
|
|
179
|
+
var WebsetItemsClient = class extends WebsetsBaseClient {
|
|
180
|
+
async get(websetId, id) {
|
|
181
|
+
return this.request(`/v0/websets/${websetId}/items/${id}`, "GET");
|
|
252
182
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const promise = async () => {
|
|
256
|
-
const params = { stream: "true" };
|
|
257
|
-
if (options.events !== void 0) {
|
|
258
|
-
params.events = options.events.toString();
|
|
259
|
-
}
|
|
260
|
-
const resp = await this.rawRequest(
|
|
261
|
-
`/${researchId}`,
|
|
262
|
-
"GET",
|
|
263
|
-
void 0,
|
|
264
|
-
params
|
|
265
|
-
);
|
|
266
|
-
if (!resp.body) {
|
|
267
|
-
throw new Error("No response body for SSE stream");
|
|
268
|
-
}
|
|
269
|
-
const reader = resp.body.getReader();
|
|
270
|
-
const decoder = new TextDecoder();
|
|
271
|
-
let buffer = "";
|
|
272
|
-
function processPart(part) {
|
|
273
|
-
const lines = part.split("\n");
|
|
274
|
-
let data = lines.slice(1).join("\n");
|
|
275
|
-
if (data.startsWith("data:")) {
|
|
276
|
-
data = data.slice(5).trimStart();
|
|
277
|
-
}
|
|
278
|
-
try {
|
|
279
|
-
return JSON.parse(data);
|
|
280
|
-
} catch (e) {
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
async function* streamEvents() {
|
|
285
|
-
while (true) {
|
|
286
|
-
const { done, value } = await reader.read();
|
|
287
|
-
if (done) break;
|
|
288
|
-
buffer += decoder.decode(value, { stream: true });
|
|
289
|
-
let parts = buffer.split("\n\n");
|
|
290
|
-
buffer = parts.pop() ?? "";
|
|
291
|
-
for (const part of parts) {
|
|
292
|
-
const processed = processPart(part);
|
|
293
|
-
if (processed) {
|
|
294
|
-
yield processed;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
if (buffer.trim()) {
|
|
299
|
-
const processed = processPart(buffer.trim());
|
|
300
|
-
if (processed) {
|
|
301
|
-
yield processed;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
return streamEvents();
|
|
306
|
-
};
|
|
307
|
-
return promise();
|
|
308
|
-
} else {
|
|
309
|
-
const params = { stream: "false" };
|
|
310
|
-
if (options?.events !== void 0) {
|
|
311
|
-
params.events = options.events.toString();
|
|
312
|
-
}
|
|
313
|
-
return this.request(
|
|
314
|
-
`/${researchId}`,
|
|
315
|
-
"GET",
|
|
316
|
-
void 0,
|
|
317
|
-
params
|
|
318
|
-
);
|
|
319
|
-
}
|
|
183
|
+
async delete(websetId, id) {
|
|
184
|
+
return this.request(`/v0/websets/${websetId}/items/${id}`, "DELETE");
|
|
320
185
|
}
|
|
321
|
-
async list(options) {
|
|
322
|
-
const
|
|
323
|
-
return this.request(
|
|
186
|
+
async list(websetId, options) {
|
|
187
|
+
const queryParams = { ...this.buildPaginationParams(options), sourceId: options?.sourceId };
|
|
188
|
+
return this.request(`/v0/websets/${websetId}/items`, "GET", void 0, queryParams);
|
|
324
189
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
const
|
|
329
|
-
const startTime = Date.now();
|
|
330
|
-
let consecutiveFailures = 0;
|
|
190
|
+
/** Iterate through all items in a Webset, handling pagination automatically. */
|
|
191
|
+
async *listAll(websetId, options) {
|
|
192
|
+
let cursor = void 0;
|
|
193
|
+
const pageOptions = options ? { ...options } : {};
|
|
331
194
|
while (true) {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
});
|
|
336
|
-
consecutiveFailures = 0;
|
|
337
|
-
if (research.status === "completed" || research.status === "failed" || research.status === "canceled") {
|
|
338
|
-
return research;
|
|
339
|
-
}
|
|
340
|
-
} catch (err) {
|
|
341
|
-
consecutiveFailures += 1;
|
|
342
|
-
if (consecutiveFailures >= maxConsecutiveFailures) {
|
|
343
|
-
throw new Error(
|
|
344
|
-
`Polling failed ${maxConsecutiveFailures} times in a row for research ${researchId}: ${err}`
|
|
345
|
-
);
|
|
346
|
-
}
|
|
195
|
+
const response = await this.list(websetId, { ...pageOptions, cursor });
|
|
196
|
+
for (const item of response.data) {
|
|
197
|
+
yield item;
|
|
347
198
|
}
|
|
348
|
-
if (
|
|
349
|
-
|
|
350
|
-
`Polling timeout: Research ${researchId} did not complete within ${timeoutMs}ms`
|
|
351
|
-
);
|
|
199
|
+
if (!response.hasMore || !response.nextCursor) {
|
|
200
|
+
break;
|
|
352
201
|
}
|
|
353
|
-
|
|
202
|
+
cursor = response.nextCursor;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/** Collect all items from a Webset into an array. */
|
|
206
|
+
async getAll(websetId, options) {
|
|
207
|
+
const items = [];
|
|
208
|
+
for await (const item of this.listAll(websetId, options)) {
|
|
209
|
+
items.push(item);
|
|
354
210
|
}
|
|
211
|
+
return items;
|
|
355
212
|
}
|
|
356
213
|
};
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
/**
|
|
361
|
-
* Initialize a new Websets base client
|
|
362
|
-
* @param client The Exa client instance
|
|
363
|
-
*/
|
|
364
|
-
constructor(client) {
|
|
365
|
-
this.client = client;
|
|
214
|
+
var WebsetSearchesClient = class extends WebsetsBaseClient {
|
|
215
|
+
async create(websetId, params, options) {
|
|
216
|
+
return this.request(`/v0/websets/${websetId}/searches`, "POST", { ...params }, void 0, options?.headers);
|
|
366
217
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
* @param endpoint The endpoint path
|
|
370
|
-
* @param method The HTTP method
|
|
371
|
-
* @param data Optional request body data
|
|
372
|
-
* @param params Optional query parameters
|
|
373
|
-
* @returns The response JSON
|
|
374
|
-
* @throws ExaError with API error details if the request fails
|
|
375
|
-
*/
|
|
376
|
-
async request(endpoint, method = "POST", data, params, headers) {
|
|
377
|
-
return this.client.request(
|
|
378
|
-
`/websets${endpoint}`,
|
|
379
|
-
method,
|
|
380
|
-
data,
|
|
381
|
-
params,
|
|
382
|
-
headers
|
|
383
|
-
);
|
|
218
|
+
async get(websetId, id) {
|
|
219
|
+
return this.request(`/v0/websets/${websetId}/searches/${id}`, "GET");
|
|
384
220
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
* @param pagination The pagination parameters
|
|
388
|
-
* @returns QueryParams object with pagination parameters
|
|
389
|
-
*/
|
|
390
|
-
buildPaginationParams(pagination) {
|
|
391
|
-
const params = {};
|
|
392
|
-
if (!pagination) return params;
|
|
393
|
-
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
394
|
-
if (pagination.limit) params.limit = pagination.limit;
|
|
395
|
-
return params;
|
|
221
|
+
async cancel(websetId, id) {
|
|
222
|
+
return this.request(`/v0/websets/${websetId}/searches/${id}/cancel`, "POST");
|
|
396
223
|
}
|
|
397
224
|
};
|
|
398
|
-
|
|
399
|
-
// src/websets/enrichments.ts
|
|
400
225
|
var WebsetEnrichmentsClient = class extends WebsetsBaseClient {
|
|
401
|
-
/**
|
|
402
|
-
* Create an Enrichment for a Webset
|
|
403
|
-
* @param websetId The ID of the Webset
|
|
404
|
-
* @param params The enrichment parameters
|
|
405
|
-
* @returns The created Webset Enrichment
|
|
406
|
-
*/
|
|
407
226
|
async create(websetId, params) {
|
|
408
|
-
return this.request(
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
);
|
|
227
|
+
return this.request(`/v0/websets/${websetId}/enrichments`, "POST", { ...params });
|
|
228
|
+
}
|
|
229
|
+
async update(websetId, id, params) {
|
|
230
|
+
return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "PATCH", { ...params });
|
|
413
231
|
}
|
|
414
|
-
/**
|
|
415
|
-
* Get an Enrichment by ID
|
|
416
|
-
* @param websetId The ID of the Webset
|
|
417
|
-
* @param id The ID of the Enrichment
|
|
418
|
-
* @returns The Webset Enrichment
|
|
419
|
-
*/
|
|
420
232
|
async get(websetId, id) {
|
|
421
|
-
return this.request(
|
|
422
|
-
`/v0/websets/${websetId}/enrichments/${id}`,
|
|
423
|
-
"GET"
|
|
424
|
-
);
|
|
233
|
+
return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "GET");
|
|
425
234
|
}
|
|
426
|
-
/**
|
|
427
|
-
* Delete an Enrichment
|
|
428
|
-
* @param websetId The ID of the Webset
|
|
429
|
-
* @param id The ID of the Enrichment
|
|
430
|
-
* @returns The deleted Webset Enrichment
|
|
431
|
-
*/
|
|
432
235
|
async delete(websetId, id) {
|
|
433
|
-
return this.request(
|
|
434
|
-
`/v0/websets/${websetId}/enrichments/${id}`,
|
|
435
|
-
"DELETE"
|
|
436
|
-
);
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* Update an Enrichment
|
|
440
|
-
* @param websetId The ID of the Webset
|
|
441
|
-
* @param id The ID of the Enrichment
|
|
442
|
-
* @param params The enrichment update parameters
|
|
443
|
-
* @returns Promise that resolves when the update is complete
|
|
444
|
-
*/
|
|
445
|
-
async update(websetId, id, params) {
|
|
446
|
-
return this.request(
|
|
447
|
-
`/v0/websets/${websetId}/enrichments/${id}`,
|
|
448
|
-
"PATCH",
|
|
449
|
-
params
|
|
450
|
-
);
|
|
236
|
+
return this.request(`/v0/websets/${websetId}/enrichments/${id}`, "DELETE");
|
|
451
237
|
}
|
|
452
|
-
/**
|
|
453
|
-
* Cancel a running Enrichment
|
|
454
|
-
* @param websetId The ID of the Webset
|
|
455
|
-
* @param id The ID of the Enrichment
|
|
456
|
-
* @returns The canceled Webset Enrichment
|
|
457
|
-
*/
|
|
458
238
|
async cancel(websetId, id) {
|
|
459
|
-
return this.request(
|
|
460
|
-
`/v0/websets/${websetId}/enrichments/${id}/cancel`,
|
|
461
|
-
"POST"
|
|
462
|
-
);
|
|
239
|
+
return this.request(`/v0/websets/${websetId}/enrichments/${id}/cancel`, "POST");
|
|
463
240
|
}
|
|
464
241
|
};
|
|
465
|
-
|
|
466
|
-
// src/websets/events.ts
|
|
467
242
|
var EventsClient = class extends WebsetsBaseClient {
|
|
468
|
-
/**
|
|
469
|
-
* Initialize a new Events client
|
|
470
|
-
* @param client The Exa client instance
|
|
471
|
-
*/
|
|
472
|
-
constructor(client) {
|
|
473
|
-
super(client);
|
|
474
|
-
}
|
|
475
|
-
/**
|
|
476
|
-
* List all Events
|
|
477
|
-
* @param options Optional filtering and pagination options
|
|
478
|
-
* @returns The list of Events
|
|
479
|
-
*/
|
|
480
243
|
async list(options) {
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
limit: options?.limit,
|
|
484
|
-
types: options?.types
|
|
485
|
-
};
|
|
486
|
-
return this.request(
|
|
487
|
-
"/v0/events",
|
|
488
|
-
"GET",
|
|
489
|
-
void 0,
|
|
490
|
-
params
|
|
491
|
-
);
|
|
244
|
+
const queryParams = { ...this.buildPaginationParams(options), types: options?.types, createdBefore: options?.createdBefore, createdAfter: options?.createdAfter };
|
|
245
|
+
return this.request("/v0/events", "GET", void 0, queryParams);
|
|
492
246
|
}
|
|
493
|
-
/**
|
|
494
|
-
* Get an Event by ID
|
|
495
|
-
* @param id The ID of the Event
|
|
496
|
-
* @returns The Event
|
|
497
|
-
*/
|
|
498
247
|
async get(id) {
|
|
499
248
|
return this.request(`/v0/events/${id}`, "GET");
|
|
500
249
|
}
|
|
501
|
-
/**
|
|
502
|
-
* Iterate through all Events, handling pagination automatically
|
|
503
|
-
* @param options Filtering and pagination options
|
|
504
|
-
* @returns Async generator of Events
|
|
505
|
-
*/
|
|
250
|
+
/** Iterate through all events, handling pagination automatically. */
|
|
506
251
|
async *listAll(options) {
|
|
507
252
|
let cursor = void 0;
|
|
508
253
|
const pageOptions = options ? { ...options } : {};
|
|
509
254
|
while (true) {
|
|
510
|
-
|
|
511
|
-
const response = await this.list(pageOptions);
|
|
255
|
+
const response = await this.list({ ...pageOptions, cursor });
|
|
512
256
|
for (const event of response.data) {
|
|
513
257
|
yield event;
|
|
514
258
|
}
|
|
@@ -518,11 +262,7 @@ var EventsClient = class extends WebsetsBaseClient {
|
|
|
518
262
|
cursor = response.nextCursor;
|
|
519
263
|
}
|
|
520
264
|
}
|
|
521
|
-
/**
|
|
522
|
-
* Collect all Events into an array
|
|
523
|
-
* @param options Filtering and pagination options
|
|
524
|
-
* @returns Promise resolving to an array of all Events
|
|
525
|
-
*/
|
|
265
|
+
/** Collect all events into an array. */
|
|
526
266
|
async getAll(options) {
|
|
527
267
|
const events = [];
|
|
528
268
|
for await (const event of this.listAll(options)) {
|
|
@@ -531,330 +271,172 @@ var EventsClient = class extends WebsetsBaseClient {
|
|
|
531
271
|
return events;
|
|
532
272
|
}
|
|
533
273
|
};
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
})(EventType || {});
|
|
577
|
-
var ImportFailedReason = /* @__PURE__ */ ((ImportFailedReason2) => {
|
|
578
|
-
ImportFailedReason2["invalid_format"] = "invalid_format";
|
|
579
|
-
ImportFailedReason2["invalid_file_content"] = "invalid_file_content";
|
|
580
|
-
ImportFailedReason2["missing_identifier"] = "missing_identifier";
|
|
581
|
-
return ImportFailedReason2;
|
|
582
|
-
})(ImportFailedReason || {});
|
|
583
|
-
var ImportFormat = /* @__PURE__ */ ((ImportFormat2) => {
|
|
584
|
-
ImportFormat2["csv"] = "csv";
|
|
585
|
-
ImportFormat2["webset"] = "webset";
|
|
586
|
-
return ImportFormat2;
|
|
587
|
-
})(ImportFormat || {});
|
|
588
|
-
var ImportObject = /* @__PURE__ */ ((ImportObject2) => {
|
|
589
|
-
ImportObject2["import"] = "import";
|
|
590
|
-
return ImportObject2;
|
|
591
|
-
})(ImportObject || {});
|
|
592
|
-
var ImportStatus = /* @__PURE__ */ ((ImportStatus2) => {
|
|
593
|
-
ImportStatus2["pending"] = "pending";
|
|
594
|
-
ImportStatus2["processing"] = "processing";
|
|
595
|
-
ImportStatus2["completed"] = "completed";
|
|
596
|
-
ImportStatus2["failed"] = "failed";
|
|
597
|
-
return ImportStatus2;
|
|
598
|
-
})(ImportStatus || {});
|
|
599
|
-
var MonitorObject = /* @__PURE__ */ ((MonitorObject2) => {
|
|
600
|
-
MonitorObject2["monitor"] = "monitor";
|
|
601
|
-
return MonitorObject2;
|
|
602
|
-
})(MonitorObject || {});
|
|
603
|
-
var MonitorStatus = /* @__PURE__ */ ((MonitorStatus2) => {
|
|
604
|
-
MonitorStatus2["enabled"] = "enabled";
|
|
605
|
-
MonitorStatus2["disabled"] = "disabled";
|
|
606
|
-
return MonitorStatus2;
|
|
607
|
-
})(MonitorStatus || {});
|
|
608
|
-
var MonitorRunObject = /* @__PURE__ */ ((MonitorRunObject2) => {
|
|
609
|
-
MonitorRunObject2["monitor_run"] = "monitor_run";
|
|
610
|
-
return MonitorRunObject2;
|
|
611
|
-
})(MonitorRunObject || {});
|
|
612
|
-
var MonitorRunStatus = /* @__PURE__ */ ((MonitorRunStatus2) => {
|
|
613
|
-
MonitorRunStatus2["created"] = "created";
|
|
614
|
-
MonitorRunStatus2["running"] = "running";
|
|
615
|
-
MonitorRunStatus2["completed"] = "completed";
|
|
616
|
-
MonitorRunStatus2["canceled"] = "canceled";
|
|
617
|
-
MonitorRunStatus2["failed"] = "failed";
|
|
618
|
-
return MonitorRunStatus2;
|
|
619
|
-
})(MonitorRunStatus || {});
|
|
620
|
-
var MonitorRunType = /* @__PURE__ */ ((MonitorRunType2) => {
|
|
621
|
-
MonitorRunType2["search"] = "search";
|
|
622
|
-
MonitorRunType2["refresh"] = "refresh";
|
|
623
|
-
return MonitorRunType2;
|
|
624
|
-
})(MonitorRunType || {});
|
|
625
|
-
var UpdateMonitorStatus = /* @__PURE__ */ ((UpdateMonitorStatus2) => {
|
|
626
|
-
UpdateMonitorStatus2["enabled"] = "enabled";
|
|
627
|
-
UpdateMonitorStatus2["disabled"] = "disabled";
|
|
628
|
-
return UpdateMonitorStatus2;
|
|
629
|
-
})(UpdateMonitorStatus || {});
|
|
630
|
-
var WebhookStatus = /* @__PURE__ */ ((WebhookStatus2) => {
|
|
631
|
-
WebhookStatus2["active"] = "active";
|
|
632
|
-
WebhookStatus2["inactive"] = "inactive";
|
|
633
|
-
return WebhookStatus2;
|
|
634
|
-
})(WebhookStatus || {});
|
|
635
|
-
var WebsetStatus = /* @__PURE__ */ ((WebsetStatus2) => {
|
|
636
|
-
WebsetStatus2["idle"] = "idle";
|
|
637
|
-
WebsetStatus2["pending"] = "pending";
|
|
638
|
-
WebsetStatus2["running"] = "running";
|
|
639
|
-
WebsetStatus2["paused"] = "paused";
|
|
640
|
-
return WebsetStatus2;
|
|
641
|
-
})(WebsetStatus || {});
|
|
642
|
-
var WebsetEnrichmentStatus = /* @__PURE__ */ ((WebsetEnrichmentStatus2) => {
|
|
643
|
-
WebsetEnrichmentStatus2["pending"] = "pending";
|
|
644
|
-
WebsetEnrichmentStatus2["canceled"] = "canceled";
|
|
645
|
-
WebsetEnrichmentStatus2["completed"] = "completed";
|
|
646
|
-
return WebsetEnrichmentStatus2;
|
|
647
|
-
})(WebsetEnrichmentStatus || {});
|
|
648
|
-
var WebsetEnrichmentFormat = /* @__PURE__ */ ((WebsetEnrichmentFormat2) => {
|
|
649
|
-
WebsetEnrichmentFormat2["text"] = "text";
|
|
650
|
-
WebsetEnrichmentFormat2["date"] = "date";
|
|
651
|
-
WebsetEnrichmentFormat2["number"] = "number";
|
|
652
|
-
WebsetEnrichmentFormat2["options"] = "options";
|
|
653
|
-
WebsetEnrichmentFormat2["email"] = "email";
|
|
654
|
-
WebsetEnrichmentFormat2["phone"] = "phone";
|
|
655
|
-
WebsetEnrichmentFormat2["url"] = "url";
|
|
656
|
-
return WebsetEnrichmentFormat2;
|
|
657
|
-
})(WebsetEnrichmentFormat || {});
|
|
658
|
-
var WebsetItemSource = /* @__PURE__ */ ((WebsetItemSource2) => {
|
|
659
|
-
WebsetItemSource2["search"] = "search";
|
|
660
|
-
WebsetItemSource2["import"] = "import";
|
|
661
|
-
return WebsetItemSource2;
|
|
662
|
-
})(WebsetItemSource || {});
|
|
663
|
-
var WebsetItemEvaluationSatisfied = /* @__PURE__ */ ((WebsetItemEvaluationSatisfied2) => {
|
|
664
|
-
WebsetItemEvaluationSatisfied2["yes"] = "yes";
|
|
665
|
-
WebsetItemEvaluationSatisfied2["no"] = "no";
|
|
666
|
-
WebsetItemEvaluationSatisfied2["unclear"] = "unclear";
|
|
667
|
-
return WebsetItemEvaluationSatisfied2;
|
|
668
|
-
})(WebsetItemEvaluationSatisfied || {});
|
|
669
|
-
var WebsetExcludeSource = /* @__PURE__ */ ((WebsetExcludeSource2) => {
|
|
670
|
-
WebsetExcludeSource2["import"] = "import";
|
|
671
|
-
WebsetExcludeSource2["webset"] = "webset";
|
|
672
|
-
return WebsetExcludeSource2;
|
|
673
|
-
})(WebsetExcludeSource || {});
|
|
674
|
-
var WebsetSearchScopeSource = /* @__PURE__ */ ((WebsetSearchScopeSource2) => {
|
|
675
|
-
WebsetSearchScopeSource2["import"] = "import";
|
|
676
|
-
WebsetSearchScopeSource2["webset"] = "webset";
|
|
677
|
-
return WebsetSearchScopeSource2;
|
|
678
|
-
})(WebsetSearchScopeSource || {});
|
|
679
|
-
var WebsetSearchStatus = /* @__PURE__ */ ((WebsetSearchStatus2) => {
|
|
680
|
-
WebsetSearchStatus2["created"] = "created";
|
|
681
|
-
WebsetSearchStatus2["pending"] = "pending";
|
|
682
|
-
WebsetSearchStatus2["running"] = "running";
|
|
683
|
-
WebsetSearchStatus2["completed"] = "completed";
|
|
684
|
-
WebsetSearchStatus2["canceled"] = "canceled";
|
|
685
|
-
return WebsetSearchStatus2;
|
|
686
|
-
})(WebsetSearchStatus || {});
|
|
687
|
-
var WebsetSearchBehavior = /* @__PURE__ */ ((WebsetSearchBehavior2) => {
|
|
688
|
-
WebsetSearchBehavior2["override"] = "override";
|
|
689
|
-
WebsetSearchBehavior2["append"] = "append";
|
|
690
|
-
return WebsetSearchBehavior2;
|
|
691
|
-
})(WebsetSearchBehavior || {});
|
|
692
|
-
var WebsetSearchCanceledReason = /* @__PURE__ */ ((WebsetSearchCanceledReason2) => {
|
|
693
|
-
WebsetSearchCanceledReason2["webset_deleted"] = "webset_deleted";
|
|
694
|
-
WebsetSearchCanceledReason2["webset_canceled"] = "webset_canceled";
|
|
695
|
-
return WebsetSearchCanceledReason2;
|
|
696
|
-
})(WebsetSearchCanceledReason || {});
|
|
697
|
-
|
|
698
|
-
// src/websets/imports.ts
|
|
699
|
-
var ImportsClient = class extends WebsetsBaseClient {
|
|
700
|
-
async create(params, csv) {
|
|
701
|
-
if (csv === void 0) {
|
|
702
|
-
return this.request(
|
|
703
|
-
"/v0/imports",
|
|
704
|
-
"POST",
|
|
705
|
-
params
|
|
706
|
-
);
|
|
274
|
+
var WebsetMonitorRunsClient = class extends WebsetsBaseClient {
|
|
275
|
+
async list(monitorId) {
|
|
276
|
+
return this.request(`/v0/monitors/${monitorId}/runs`, "GET");
|
|
277
|
+
}
|
|
278
|
+
async get(monitorId, id) {
|
|
279
|
+
return this.request(`/v0/monitors/${monitorId}/runs/${id}`, "GET");
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
var WebsetMonitorsClient = class extends WebsetsBaseClient {
|
|
283
|
+
constructor(client) {
|
|
284
|
+
super(client);
|
|
285
|
+
this.runs = new WebsetMonitorRunsClient(client);
|
|
286
|
+
}
|
|
287
|
+
async create(params) {
|
|
288
|
+
return this.request("/v0/monitors", "POST", { ...params });
|
|
289
|
+
}
|
|
290
|
+
async list(options) {
|
|
291
|
+
const queryParams = { ...this.buildPaginationParams(options), websetId: options?.websetId };
|
|
292
|
+
return this.request("/v0/monitors", "GET", void 0, queryParams);
|
|
293
|
+
}
|
|
294
|
+
async get(id) {
|
|
295
|
+
return this.request(`/v0/monitors/${id}`, "GET");
|
|
296
|
+
}
|
|
297
|
+
async update(id, params) {
|
|
298
|
+
return this.request(`/v0/monitors/${id}`, "PATCH", { ...params });
|
|
299
|
+
}
|
|
300
|
+
async delete(id) {
|
|
301
|
+
return this.request(`/v0/monitors/${id}`, "DELETE");
|
|
302
|
+
}
|
|
303
|
+
/** Iterate through all monitors, handling pagination automatically. */
|
|
304
|
+
async *listAll(options) {
|
|
305
|
+
let cursor = void 0;
|
|
306
|
+
const pageOptions = options ? { ...options } : {};
|
|
307
|
+
while (true) {
|
|
308
|
+
const response = await this.list({ ...pageOptions, cursor });
|
|
309
|
+
for (const monitor of response.data) {
|
|
310
|
+
yield monitor;
|
|
311
|
+
}
|
|
312
|
+
if (!response.hasMore || !response.nextCursor) {
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
cursor = response.nextCursor;
|
|
707
316
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
throw new ExaError(
|
|
715
|
-
"Invalid CSV data input. Must be string or Buffer",
|
|
716
|
-
400 /* BadRequest */
|
|
717
|
-
);
|
|
317
|
+
}
|
|
318
|
+
/** Collect all monitors into an array. */
|
|
319
|
+
async getAll(options) {
|
|
320
|
+
const monitors = [];
|
|
321
|
+
for await (const monitor of this.listAll(options)) {
|
|
322
|
+
monitors.push(monitor);
|
|
718
323
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
324
|
+
return monitors;
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
328
|
+
async create(params) {
|
|
329
|
+
return this.request("/v0/webhooks", "POST", { ...params });
|
|
330
|
+
}
|
|
331
|
+
async list(options) {
|
|
332
|
+
const queryParams = this.buildPaginationParams(options);
|
|
333
|
+
return this.request("/v0/webhooks", "GET", void 0, queryParams);
|
|
334
|
+
}
|
|
335
|
+
async get(id) {
|
|
336
|
+
return this.request(`/v0/webhooks/${id}`, "GET");
|
|
337
|
+
}
|
|
338
|
+
async update(id, params) {
|
|
339
|
+
return this.request(`/v0/webhooks/${id}`, "PATCH", { ...params });
|
|
340
|
+
}
|
|
341
|
+
async delete(id) {
|
|
342
|
+
return this.request(`/v0/webhooks/${id}`, "DELETE");
|
|
343
|
+
}
|
|
344
|
+
async listAttempts(id, options) {
|
|
345
|
+
const queryParams = { ...this.buildPaginationParams(options), eventType: options?.eventType, successful: options?.successful };
|
|
346
|
+
return this.request(`/v0/webhooks/${id}/attempts`, "GET", void 0, queryParams);
|
|
347
|
+
}
|
|
348
|
+
/** Iterate through all webhooks, handling pagination automatically. */
|
|
349
|
+
async *listAll(options) {
|
|
350
|
+
let cursor = void 0;
|
|
351
|
+
const pageOptions = options ? { ...options } : {};
|
|
352
|
+
while (true) {
|
|
353
|
+
const response = await this.list({ ...pageOptions, cursor });
|
|
354
|
+
for (const webhook of response.data) {
|
|
355
|
+
yield webhook;
|
|
356
|
+
}
|
|
357
|
+
if (!response.hasMore || !response.nextCursor) {
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
cursor = response.nextCursor;
|
|
729
361
|
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
362
|
+
}
|
|
363
|
+
/** Collect all webhooks into an array. */
|
|
364
|
+
async getAll(options) {
|
|
365
|
+
const webhooks = [];
|
|
366
|
+
for await (const webhook of this.listAll(options)) {
|
|
367
|
+
webhooks.push(webhook);
|
|
735
368
|
}
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
"/v0/imports",
|
|
747
|
-
"POST",
|
|
748
|
-
createParams
|
|
749
|
-
);
|
|
750
|
-
try {
|
|
751
|
-
const uploadResponse = await fetch(importResponse.uploadUrl, {
|
|
752
|
-
method: "PUT",
|
|
753
|
-
body: csvBuffer
|
|
754
|
-
});
|
|
755
|
-
if (!uploadResponse.ok) {
|
|
756
|
-
const errorText = await uploadResponse.text();
|
|
757
|
-
throw new ExaError(
|
|
758
|
-
`Upload failed: ${uploadResponse.status} ${uploadResponse.statusText}. ${errorText}`,
|
|
759
|
-
400 /* BadRequest */
|
|
760
|
-
);
|
|
369
|
+
return webhooks;
|
|
370
|
+
}
|
|
371
|
+
/** Iterate through all webhook attempts, handling pagination automatically. */
|
|
372
|
+
async *listAllAttempts(id, options) {
|
|
373
|
+
let cursor = void 0;
|
|
374
|
+
const pageOptions = options ? { ...options } : {};
|
|
375
|
+
while (true) {
|
|
376
|
+
const response = await this.listAttempts(id, { ...pageOptions, cursor });
|
|
377
|
+
for (const attempt of response.data) {
|
|
378
|
+
yield attempt;
|
|
761
379
|
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
throw error;
|
|
380
|
+
if (!response.hasMore || !response.nextCursor) {
|
|
381
|
+
break;
|
|
765
382
|
}
|
|
766
|
-
|
|
767
|
-
`Failed to upload CSV data: ${error.message}`,
|
|
768
|
-
400 /* BadRequest */
|
|
769
|
-
);
|
|
383
|
+
cursor = response.nextCursor;
|
|
770
384
|
}
|
|
771
|
-
return importResponse;
|
|
772
385
|
}
|
|
773
|
-
/**
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
return
|
|
386
|
+
/** Collect all webhook attempts into an array. */
|
|
387
|
+
async getAllAttempts(id, options) {
|
|
388
|
+
const attempts = [];
|
|
389
|
+
for await (const attempt of this.listAllAttempts(id, options)) {
|
|
390
|
+
attempts.push(attempt);
|
|
391
|
+
}
|
|
392
|
+
return attempts;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
var ImportsClient = class extends WebsetsBaseClient {
|
|
396
|
+
async create(params) {
|
|
397
|
+
return this.request("/v0/imports", "POST", { ...params });
|
|
780
398
|
}
|
|
781
|
-
/**
|
|
782
|
-
* List all Imports
|
|
783
|
-
* @param options Pagination options
|
|
784
|
-
* @returns The list of Imports
|
|
785
|
-
*/
|
|
786
399
|
async list(options) {
|
|
787
|
-
const
|
|
788
|
-
return this.request(
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
params
|
|
793
|
-
);
|
|
400
|
+
const queryParams = this.buildPaginationParams(options);
|
|
401
|
+
return this.request("/v0/imports", "GET", void 0, queryParams);
|
|
402
|
+
}
|
|
403
|
+
async get(id) {
|
|
404
|
+
return this.request(`/v0/imports/${id}`, "GET");
|
|
794
405
|
}
|
|
795
|
-
/**
|
|
796
|
-
* Update an Import
|
|
797
|
-
* @param id The ID of the Import
|
|
798
|
-
* @param params The import update parameters
|
|
799
|
-
* @returns The updated Import
|
|
800
|
-
*/
|
|
801
406
|
async update(id, params) {
|
|
802
|
-
return this.request(`/v0/imports/${id}`, "PATCH", params);
|
|
407
|
+
return this.request(`/v0/imports/${id}`, "PATCH", { ...params });
|
|
803
408
|
}
|
|
804
|
-
/**
|
|
805
|
-
* Delete an Import
|
|
806
|
-
* @param id The ID of the Import
|
|
807
|
-
* @returns The deleted Import
|
|
808
|
-
*/
|
|
809
409
|
async delete(id) {
|
|
810
410
|
return this.request(`/v0/imports/${id}`, "DELETE");
|
|
811
411
|
}
|
|
812
|
-
/**
|
|
813
|
-
* Wait until an Import is completed or failed
|
|
814
|
-
* @param id The ID of the Import
|
|
815
|
-
* @param options Configuration options for timeout and polling
|
|
816
|
-
* @returns The Import once it reaches a final state (completed or failed)
|
|
817
|
-
* @throws Error if the Import does not complete within the timeout or fails
|
|
818
|
-
*/
|
|
412
|
+
/** Wait for an import to reach a terminal status. */
|
|
819
413
|
async waitUntilCompleted(id, options) {
|
|
820
414
|
const timeout = options?.timeout ?? 30 * 60 * 1e3;
|
|
821
415
|
const pollInterval = options?.pollInterval ?? 2e3;
|
|
822
|
-
const onPoll = options?.onPoll;
|
|
823
416
|
const startTime = Date.now();
|
|
824
417
|
while (true) {
|
|
825
418
|
const importItem = await this.get(id);
|
|
826
|
-
if (onPoll) {
|
|
827
|
-
onPoll(importItem.status);
|
|
419
|
+
if (options?.onPoll) {
|
|
420
|
+
options.onPoll(importItem.status);
|
|
828
421
|
}
|
|
829
|
-
if (importItem.status === "completed"
|
|
422
|
+
if (importItem.status === "completed") {
|
|
830
423
|
return importItem;
|
|
831
424
|
}
|
|
832
|
-
if (importItem.status === "failed"
|
|
833
|
-
throw new
|
|
834
|
-
`Import ${id} failed: ${importItem.failedMessage || "Unknown error"}`,
|
|
835
|
-
400 /* BadRequest */
|
|
836
|
-
);
|
|
425
|
+
if (importItem.status === "failed") {
|
|
426
|
+
throw new Error(`Import ${id} failed: ${importItem.failedMessage ?? "Unknown error"}`);
|
|
837
427
|
}
|
|
838
428
|
if (Date.now() - startTime > timeout) {
|
|
839
|
-
throw new
|
|
840
|
-
`Import ${id} did not complete within ${timeout}ms. Current status: ${importItem.status}`,
|
|
841
|
-
408 /* RequestTimeout */
|
|
842
|
-
);
|
|
429
|
+
throw new Error(`Import ${id} did not complete within ${timeout}ms. Current status: ${importItem.status}`);
|
|
843
430
|
}
|
|
844
431
|
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
845
432
|
}
|
|
846
433
|
}
|
|
847
|
-
/**
|
|
848
|
-
* Iterate through all Imports, handling pagination automatically
|
|
849
|
-
* @param options Pagination options
|
|
850
|
-
* @returns Async generator of Imports
|
|
851
|
-
*/
|
|
434
|
+
/** Iterate through all imports, handling pagination automatically. */
|
|
852
435
|
async *listAll(options) {
|
|
853
436
|
let cursor = void 0;
|
|
854
437
|
const pageOptions = options ? { ...options } : {};
|
|
855
438
|
while (true) {
|
|
856
|
-
|
|
857
|
-
const response = await this.list(pageOptions);
|
|
439
|
+
const response = await this.list({ ...pageOptions, cursor });
|
|
858
440
|
for (const importItem of response.data) {
|
|
859
441
|
yield importItem;
|
|
860
442
|
}
|
|
@@ -864,11 +446,7 @@ var ImportsClient = class extends WebsetsBaseClient {
|
|
|
864
446
|
cursor = response.nextCursor;
|
|
865
447
|
}
|
|
866
448
|
}
|
|
867
|
-
/**
|
|
868
|
-
* Collect all Imports into an array
|
|
869
|
-
* @param options Pagination options
|
|
870
|
-
* @returns Promise resolving to an array of all Imports
|
|
871
|
-
*/
|
|
449
|
+
/** Collect all imports into an array. */
|
|
872
450
|
async getAll(options) {
|
|
873
451
|
const imports = [];
|
|
874
452
|
for await (const importItem of this.listAll(options)) {
|
|
@@ -877,186 +455,49 @@ var ImportsClient = class extends WebsetsBaseClient {
|
|
|
877
455
|
return imports;
|
|
878
456
|
}
|
|
879
457
|
};
|
|
880
|
-
|
|
881
|
-
// src/websets/items.ts
|
|
882
|
-
var WebsetItemsClient = class extends WebsetsBaseClient {
|
|
883
|
-
/**
|
|
884
|
-
* List all Items for a Webset
|
|
885
|
-
* @param websetId The ID of the Webset
|
|
886
|
-
* @param params - Optional pagination and filtering parameters
|
|
887
|
-
* @returns A promise that resolves with the list of Items
|
|
888
|
-
*/
|
|
889
|
-
list(websetId, params) {
|
|
890
|
-
const queryParams = {
|
|
891
|
-
...this.buildPaginationParams(params),
|
|
892
|
-
sourceId: params?.sourceId
|
|
893
|
-
};
|
|
894
|
-
return this.request(
|
|
895
|
-
`/v0/websets/${websetId}/items`,
|
|
896
|
-
"GET",
|
|
897
|
-
void 0,
|
|
898
|
-
queryParams
|
|
899
|
-
);
|
|
900
|
-
}
|
|
901
|
-
/**
|
|
902
|
-
* Iterate through all Items in a Webset, handling pagination automatically
|
|
903
|
-
* @param websetId The ID of the Webset
|
|
904
|
-
* @param options Pagination options
|
|
905
|
-
* @returns Async generator of Webset Items
|
|
906
|
-
*/
|
|
907
|
-
async *listAll(websetId, options) {
|
|
908
|
-
let cursor = void 0;
|
|
909
|
-
const pageOptions = options ? { ...options } : {};
|
|
910
|
-
while (true) {
|
|
911
|
-
pageOptions.cursor = cursor;
|
|
912
|
-
const response = await this.list(websetId, pageOptions);
|
|
913
|
-
for (const item of response.data) {
|
|
914
|
-
yield item;
|
|
915
|
-
}
|
|
916
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
917
|
-
break;
|
|
918
|
-
}
|
|
919
|
-
cursor = response.nextCursor;
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
/**
|
|
923
|
-
* Collect all items from a Webset into an array
|
|
924
|
-
* @param websetId The ID of the Webset
|
|
925
|
-
* @param options Pagination options
|
|
926
|
-
* @returns Promise resolving to an array of all Webset Items
|
|
927
|
-
*/
|
|
928
|
-
async getAll(websetId, options) {
|
|
929
|
-
const items = [];
|
|
930
|
-
for await (const item of this.listAll(websetId, options)) {
|
|
931
|
-
items.push(item);
|
|
932
|
-
}
|
|
933
|
-
return items;
|
|
934
|
-
}
|
|
935
|
-
/**
|
|
936
|
-
* Get an Item by ID
|
|
937
|
-
* @param websetId The ID of the Webset
|
|
938
|
-
* @param id The ID of the Item
|
|
939
|
-
* @returns The Webset Item
|
|
940
|
-
*/
|
|
941
|
-
async get(websetId, id) {
|
|
942
|
-
return this.request(
|
|
943
|
-
`/v0/websets/${websetId}/items/${id}`,
|
|
944
|
-
"GET"
|
|
945
|
-
);
|
|
946
|
-
}
|
|
947
|
-
/**
|
|
948
|
-
* Delete an Item
|
|
949
|
-
* @param websetId The ID of the Webset
|
|
950
|
-
* @param id The ID of the Item
|
|
951
|
-
* @returns The deleted Webset Item
|
|
952
|
-
*/
|
|
953
|
-
async delete(websetId, id) {
|
|
954
|
-
return this.request(
|
|
955
|
-
`/v0/websets/${websetId}/items/${id}`,
|
|
956
|
-
"DELETE"
|
|
957
|
-
);
|
|
958
|
-
}
|
|
959
|
-
};
|
|
960
|
-
|
|
961
|
-
// src/websets/monitors.ts
|
|
962
|
-
var WebsetMonitorRunsClient = class extends WebsetsBaseClient {
|
|
963
|
-
/**
|
|
964
|
-
* List all runs for a Monitor
|
|
965
|
-
* @param monitorId The ID of the Monitor
|
|
966
|
-
* @param options Pagination options
|
|
967
|
-
* @returns The list of Monitor runs
|
|
968
|
-
*/
|
|
969
|
-
async list(monitorId, options) {
|
|
970
|
-
const params = this.buildPaginationParams(options);
|
|
971
|
-
return this.request(
|
|
972
|
-
`/v0/monitors/${monitorId}/runs`,
|
|
973
|
-
"GET",
|
|
974
|
-
void 0,
|
|
975
|
-
params
|
|
976
|
-
);
|
|
977
|
-
}
|
|
978
|
-
/**
|
|
979
|
-
* Get a specific Monitor run
|
|
980
|
-
* @param monitorId The ID of the Monitor
|
|
981
|
-
* @param runId The ID of the Monitor run
|
|
982
|
-
* @returns The Monitor run
|
|
983
|
-
*/
|
|
984
|
-
async get(monitorId, runId) {
|
|
985
|
-
return this.request(
|
|
986
|
-
`/v0/monitors/${monitorId}/runs/${runId}`,
|
|
987
|
-
"GET"
|
|
988
|
-
);
|
|
989
|
-
}
|
|
990
|
-
};
|
|
991
|
-
var WebsetMonitorsClient = class extends WebsetsBaseClient {
|
|
458
|
+
var WebsetsClient = class extends WebsetsBaseClient {
|
|
992
459
|
constructor(client) {
|
|
993
460
|
super(client);
|
|
994
|
-
this.
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
async create(params) {
|
|
1002
|
-
return this.request("/v0/monitors", "POST", params);
|
|
461
|
+
this.items = new WebsetItemsClient(client);
|
|
462
|
+
this.searches = new WebsetSearchesClient(client);
|
|
463
|
+
this.enrichments = new WebsetEnrichmentsClient(client);
|
|
464
|
+
this.events = new EventsClient(client);
|
|
465
|
+
this.monitors = new WebsetMonitorsClient(client);
|
|
466
|
+
this.webhooks = new WebsetWebhooksClient(client);
|
|
467
|
+
this.imports = new ImportsClient(client);
|
|
1003
468
|
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
* @param id The ID of the Monitor
|
|
1007
|
-
* @returns The Monitor
|
|
1008
|
-
*/
|
|
1009
|
-
async get(id) {
|
|
1010
|
-
return this.request(`/v0/monitors/${id}`, "GET");
|
|
469
|
+
async create(params, options) {
|
|
470
|
+
return this.request("/v0/websets", "POST", { ...params }, void 0, options?.headers);
|
|
1011
471
|
}
|
|
1012
|
-
/**
|
|
1013
|
-
* List all Monitors
|
|
1014
|
-
* @param options Pagination and filtering options
|
|
1015
|
-
* @returns The list of Monitors
|
|
1016
|
-
*/
|
|
1017
472
|
async list(options) {
|
|
1018
|
-
const
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
};
|
|
1023
|
-
return this.request(
|
|
1024
|
-
"/v0/monitors",
|
|
1025
|
-
"GET",
|
|
1026
|
-
void 0,
|
|
1027
|
-
params
|
|
1028
|
-
);
|
|
473
|
+
const queryParams = { ...this.buildPaginationParams(options), search: options?.search };
|
|
474
|
+
return this.request("/v0/websets", "GET", void 0, queryParams);
|
|
475
|
+
}
|
|
476
|
+
async get(id, options) {
|
|
477
|
+
const queryParams = { expand: options?.expand };
|
|
478
|
+
return this.request(`/v0/websets/${id}`, "GET", void 0, queryParams);
|
|
1029
479
|
}
|
|
1030
|
-
/**
|
|
1031
|
-
* Update a Monitor
|
|
1032
|
-
* @param id The ID of the Monitor
|
|
1033
|
-
* @param params The monitor update parameters (status, metadata)
|
|
1034
|
-
* @returns The updated Monitor
|
|
1035
|
-
*/
|
|
1036
480
|
async update(id, params) {
|
|
1037
|
-
return this.request(`/v0/
|
|
481
|
+
return this.request(`/v0/websets/${id}`, "POST", { ...params });
|
|
1038
482
|
}
|
|
1039
|
-
/**
|
|
1040
|
-
* Delete a Monitor
|
|
1041
|
-
* @param id The ID of the Monitor
|
|
1042
|
-
* @returns The deleted Monitor
|
|
1043
|
-
*/
|
|
1044
483
|
async delete(id) {
|
|
1045
|
-
return this.request(`/v0/
|
|
484
|
+
return this.request(`/v0/websets/${id}`, "DELETE");
|
|
1046
485
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
486
|
+
async cancel(id) {
|
|
487
|
+
return this.request(`/v0/websets/${id}/cancel`, "POST");
|
|
488
|
+
}
|
|
489
|
+
async preview(params, options) {
|
|
490
|
+
const queryParams = { search: options?.search };
|
|
491
|
+
return this.request("/v0/websets/preview", "POST", { ...params }, queryParams);
|
|
492
|
+
}
|
|
493
|
+
/** Iterate through all Websets, handling pagination automatically. */
|
|
1052
494
|
async *listAll(options) {
|
|
1053
495
|
let cursor = void 0;
|
|
1054
496
|
const pageOptions = options ? { ...options } : {};
|
|
1055
497
|
while (true) {
|
|
1056
|
-
|
|
1057
|
-
const
|
|
1058
|
-
|
|
1059
|
-
yield monitor;
|
|
498
|
+
const response = await this.list({ ...pageOptions, cursor });
|
|
499
|
+
for (const webset of response.data) {
|
|
500
|
+
yield webset;
|
|
1060
501
|
}
|
|
1061
502
|
if (!response.hasMore || !response.nextCursor) {
|
|
1062
503
|
break;
|
|
@@ -1064,653 +505,559 @@ var WebsetMonitorsClient = class extends WebsetsBaseClient {
|
|
|
1064
505
|
cursor = response.nextCursor;
|
|
1065
506
|
}
|
|
1066
507
|
}
|
|
1067
|
-
/**
|
|
1068
|
-
* Collect all Monitors into an array
|
|
1069
|
-
* @param options Pagination and filtering options
|
|
1070
|
-
* @returns Promise resolving to an array of all Monitors
|
|
1071
|
-
*/
|
|
508
|
+
/** Collect all Websets into an array. */
|
|
1072
509
|
async getAll(options) {
|
|
1073
|
-
const
|
|
1074
|
-
for await (const
|
|
1075
|
-
|
|
510
|
+
const websets = [];
|
|
511
|
+
for await (const webset of this.listAll(options)) {
|
|
512
|
+
websets.push(webset);
|
|
513
|
+
}
|
|
514
|
+
return websets;
|
|
515
|
+
}
|
|
516
|
+
/** Poll until a Webset reaches idle status. */
|
|
517
|
+
async waitUntilIdle(id, options) {
|
|
518
|
+
let timeout;
|
|
519
|
+
let pollInterval = 1e3;
|
|
520
|
+
let onPoll;
|
|
521
|
+
if (typeof options === "number") {
|
|
522
|
+
timeout = options;
|
|
523
|
+
} else if (options) {
|
|
524
|
+
timeout = options.timeout;
|
|
525
|
+
pollInterval = options.pollInterval || 1e3;
|
|
526
|
+
onPoll = options.onPoll;
|
|
527
|
+
}
|
|
528
|
+
const startTime = Date.now();
|
|
529
|
+
while (true) {
|
|
530
|
+
const webset = await this.get(id);
|
|
531
|
+
if (onPoll) onPoll(webset.status);
|
|
532
|
+
if (webset.status === "idle") return webset;
|
|
533
|
+
if (timeout && Date.now() - startTime > timeout) {
|
|
534
|
+
throw new Error(`Webset ${id} did not reach idle state within ${timeout}ms. Current status: ${webset.status}`);
|
|
535
|
+
}
|
|
536
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1076
537
|
}
|
|
1077
|
-
return monitors;
|
|
1078
538
|
}
|
|
1079
539
|
};
|
|
1080
540
|
|
|
1081
|
-
// src/
|
|
1082
|
-
var
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
return this.request(
|
|
1091
|
-
`/v0/websets/${websetId}/searches`,
|
|
1092
|
-
"POST",
|
|
1093
|
-
params,
|
|
1094
|
-
void 0,
|
|
1095
|
-
options?.headers
|
|
1096
|
-
);
|
|
541
|
+
// src/nova/research-client.ts
|
|
542
|
+
var import_zod = require("zod");
|
|
543
|
+
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
544
|
+
function zodToJsonSchema(schema) {
|
|
545
|
+
return (0, import_zod_to_json_schema.zodToJsonSchema)(schema, { $refStrategy: "none" });
|
|
546
|
+
}
|
|
547
|
+
var ResearchBaseClient = class {
|
|
548
|
+
constructor(client) {
|
|
549
|
+
this.client = client;
|
|
1097
550
|
}
|
|
1098
|
-
/**
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
* @param id The ID of the Search
|
|
1102
|
-
* @returns The Webset Search
|
|
1103
|
-
*/
|
|
1104
|
-
async get(websetId, id) {
|
|
1105
|
-
return this.request(
|
|
1106
|
-
`/v0/websets/${websetId}/searches/${id}`,
|
|
1107
|
-
"GET"
|
|
1108
|
-
);
|
|
551
|
+
/** Make a request to the API, prepending `/research/v1` to the path. */
|
|
552
|
+
async request(endpoint, method = "POST", data, params) {
|
|
553
|
+
return this.client.request(`/research/v1${endpoint}`, method, data, params);
|
|
1109
554
|
}
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
async cancel(websetId, id) {
|
|
1117
|
-
return this.request(
|
|
1118
|
-
`/v0/websets/${websetId}/searches/${id}/cancel`,
|
|
1119
|
-
"POST"
|
|
1120
|
-
);
|
|
555
|
+
buildPaginationParams(pagination) {
|
|
556
|
+
const params = {};
|
|
557
|
+
if (!pagination) return params;
|
|
558
|
+
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
559
|
+
if (pagination.limit) params.limit = pagination.limit;
|
|
560
|
+
return params;
|
|
1121
561
|
}
|
|
1122
562
|
};
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
1126
|
-
/**
|
|
1127
|
-
* Create a Webhook
|
|
1128
|
-
* @param params The webhook parameters
|
|
1129
|
-
* @returns The created Webhook
|
|
1130
|
-
*/
|
|
1131
|
-
async create(params) {
|
|
1132
|
-
return this.request("/v0/webhooks", "POST", params);
|
|
1133
|
-
}
|
|
1134
|
-
/**
|
|
1135
|
-
* Get a Webhook by ID
|
|
1136
|
-
* @param id The ID of the Webhook
|
|
1137
|
-
* @returns The Webhook
|
|
1138
|
-
*/
|
|
1139
|
-
async get(id) {
|
|
1140
|
-
return this.request(`/v0/webhooks/${id}`, "GET");
|
|
1141
|
-
}
|
|
1142
|
-
/**
|
|
1143
|
-
* List all Webhooks
|
|
1144
|
-
* @param options Pagination options
|
|
1145
|
-
* @returns The list of Webhooks
|
|
1146
|
-
*/
|
|
563
|
+
var ResearchClient = class extends ResearchBaseClient {
|
|
564
|
+
/** List research requests. */
|
|
1147
565
|
async list(options) {
|
|
1148
566
|
const params = this.buildPaginationParams(options);
|
|
1149
|
-
return this.request(
|
|
1150
|
-
"/v0/webhooks",
|
|
1151
|
-
"GET",
|
|
1152
|
-
void 0,
|
|
1153
|
-
params
|
|
1154
|
-
);
|
|
567
|
+
return this.client.request("/research/v1", "GET", void 0, params);
|
|
1155
568
|
}
|
|
1156
|
-
/**
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
569
|
+
/** Create a new research request. Defaults model to "exa-research-fast" if not provided. */
|
|
570
|
+
async create(params) {
|
|
571
|
+
let schema = params.outputSchema;
|
|
572
|
+
if (schema instanceof import_zod.ZodType) {
|
|
573
|
+
schema = zodToJsonSchema(schema);
|
|
574
|
+
}
|
|
575
|
+
const payload = {
|
|
576
|
+
instructions: params.instructions,
|
|
577
|
+
model: params.model ?? "exa-research-fast"
|
|
578
|
+
};
|
|
579
|
+
if (schema) {
|
|
580
|
+
payload.outputSchema = schema;
|
|
581
|
+
}
|
|
582
|
+
return this.client.request("/research/v1", "POST", payload, void 0);
|
|
583
|
+
}
|
|
584
|
+
async get(researchId, options) {
|
|
585
|
+
const params = {};
|
|
586
|
+
if (options?.events !== void 0) params.events = options.events.toString();
|
|
587
|
+
if (options?.stream) {
|
|
588
|
+
params.stream = "true";
|
|
589
|
+
const response = await this.client.rawRequest(`/research/v1/${researchId}`, "GET", void 0, params);
|
|
590
|
+
if (!response.ok) {
|
|
591
|
+
const message = await response.text();
|
|
592
|
+
throw new Error(`Research stream request failed (${response.status}): ${message}`);
|
|
1169
593
|
}
|
|
1170
|
-
|
|
1171
|
-
|
|
594
|
+
const reader = response.body?.getReader();
|
|
595
|
+
if (!reader) {
|
|
596
|
+
throw new Error("No response body for SSE stream");
|
|
1172
597
|
}
|
|
1173
|
-
|
|
598
|
+
const streamReader = reader;
|
|
599
|
+
const decoder = new TextDecoder();
|
|
600
|
+
let buffer = "";
|
|
601
|
+
const parseSseChunk = (chunk) => {
|
|
602
|
+
const lines = chunk.split("\n");
|
|
603
|
+
const dataLines = [];
|
|
604
|
+
for (const line of lines) {
|
|
605
|
+
if (line.startsWith("data:")) {
|
|
606
|
+
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
const payload = dataLines.join("\n").trim();
|
|
610
|
+
if (payload.length === 0 || payload === "[DONE]") {
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
try {
|
|
614
|
+
const parsed = JSON.parse(payload);
|
|
615
|
+
if (parsed == null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
616
|
+
return null;
|
|
617
|
+
}
|
|
618
|
+
const event = {};
|
|
619
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
620
|
+
event[key] = value;
|
|
621
|
+
}
|
|
622
|
+
return event;
|
|
623
|
+
} catch {
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
async function* streamEvents() {
|
|
628
|
+
while (true) {
|
|
629
|
+
const { done, value } = await streamReader.read();
|
|
630
|
+
if (done) break;
|
|
631
|
+
buffer += decoder.decode(value, { stream: true });
|
|
632
|
+
const parts = buffer.split("\n\n");
|
|
633
|
+
buffer = parts.pop() ?? "";
|
|
634
|
+
for (const part of parts) {
|
|
635
|
+
const event = parseSseChunk(part);
|
|
636
|
+
if (event != null) {
|
|
637
|
+
yield event;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
if (buffer.trim().length > 0) {
|
|
642
|
+
const event = parseSseChunk(buffer.trim());
|
|
643
|
+
if (event != null) {
|
|
644
|
+
yield event;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
return streamEvents();
|
|
1174
649
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
* Collect all Webhooks into an array
|
|
1178
|
-
* @param options Pagination options
|
|
1179
|
-
* @returns Promise resolving to an array of all Webhooks
|
|
1180
|
-
*/
|
|
1181
|
-
async getAll(options) {
|
|
1182
|
-
const webhooks = [];
|
|
1183
|
-
for await (const webhook of this.listAll(options)) {
|
|
1184
|
-
webhooks.push(webhook);
|
|
650
|
+
if (options?.stream === false) {
|
|
651
|
+
params.stream = "false";
|
|
1185
652
|
}
|
|
1186
|
-
return
|
|
1187
|
-
}
|
|
1188
|
-
/**
|
|
1189
|
-
* Update a Webhook
|
|
1190
|
-
* @param id The ID of the Webhook
|
|
1191
|
-
* @param params The webhook update parameters (events, metadata, url)
|
|
1192
|
-
* @returns The updated Webhook
|
|
1193
|
-
*/
|
|
1194
|
-
async update(id, params) {
|
|
1195
|
-
return this.request(`/v0/webhooks/${id}`, "PATCH", params);
|
|
1196
|
-
}
|
|
1197
|
-
/**
|
|
1198
|
-
* Delete a Webhook
|
|
1199
|
-
* @param id The ID of the Webhook
|
|
1200
|
-
* @returns The deleted Webhook
|
|
1201
|
-
*/
|
|
1202
|
-
async delete(id) {
|
|
1203
|
-
return this.request(`/v0/webhooks/${id}`, "DELETE");
|
|
1204
|
-
}
|
|
1205
|
-
/**
|
|
1206
|
-
* List all attempts for a Webhook
|
|
1207
|
-
* @param id The ID of the Webhook
|
|
1208
|
-
* @param options Pagination and filtering options
|
|
1209
|
-
* @returns The list of Webhook attempts
|
|
1210
|
-
*/
|
|
1211
|
-
async listAttempts(id, options) {
|
|
1212
|
-
const params = {
|
|
1213
|
-
cursor: options?.cursor,
|
|
1214
|
-
limit: options?.limit,
|
|
1215
|
-
eventType: options?.eventType,
|
|
1216
|
-
successful: options?.successful
|
|
1217
|
-
};
|
|
1218
|
-
return this.request(
|
|
1219
|
-
`/v0/webhooks/${id}/attempts`,
|
|
1220
|
-
"GET",
|
|
1221
|
-
void 0,
|
|
1222
|
-
params
|
|
1223
|
-
);
|
|
653
|
+
return this.client.request(`/research/v1/${researchId}`, "GET", void 0, params);
|
|
1224
654
|
}
|
|
1225
|
-
/**
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
let cursor = void 0;
|
|
1233
|
-
const pageOptions = options ? { ...options } : {};
|
|
655
|
+
/** Poll a research request until it reaches a terminal state (completed, failed, or canceled). */
|
|
656
|
+
async pollUntilFinished(researchId, options) {
|
|
657
|
+
const pollInterval = options?.pollInterval ?? 1e3;
|
|
658
|
+
const timeoutMs = options?.timeoutMs ?? 10 * 60 * 1e3;
|
|
659
|
+
const maxConsecutiveFailures = 5;
|
|
660
|
+
const startTime = Date.now();
|
|
661
|
+
let consecutiveFailures = 0;
|
|
1234
662
|
while (true) {
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
663
|
+
try {
|
|
664
|
+
const research = await this.get(researchId, { events: options?.events });
|
|
665
|
+
consecutiveFailures = 0;
|
|
666
|
+
if (research.status === "completed" || research.status === "failed" || research.status === "canceled") {
|
|
667
|
+
return research;
|
|
668
|
+
}
|
|
669
|
+
} catch (err) {
|
|
670
|
+
consecutiveFailures += 1;
|
|
671
|
+
if (consecutiveFailures >= maxConsecutiveFailures) {
|
|
672
|
+
throw new Error(`Polling failed ${maxConsecutiveFailures} times in a row for research ${researchId}: ${err}`);
|
|
673
|
+
}
|
|
1239
674
|
}
|
|
1240
|
-
if (
|
|
1241
|
-
|
|
675
|
+
if (Date.now() - startTime > timeoutMs) {
|
|
676
|
+
throw new Error(`Polling timeout: Research ${researchId} did not complete within ${timeoutMs}ms`);
|
|
1242
677
|
}
|
|
1243
|
-
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
/**
|
|
1247
|
-
* Collect all attempts for a Webhook into an array
|
|
1248
|
-
* @param id The ID of the Webhook
|
|
1249
|
-
* @param options Pagination and filtering options
|
|
1250
|
-
* @returns Promise resolving to an array of all Webhook attempts
|
|
1251
|
-
*/
|
|
1252
|
-
async getAllAttempts(id, options) {
|
|
1253
|
-
const attempts = [];
|
|
1254
|
-
for await (const attempt of this.listAllAttempts(id, options)) {
|
|
1255
|
-
attempts.push(attempt);
|
|
678
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1256
679
|
}
|
|
1257
|
-
return attempts;
|
|
1258
680
|
}
|
|
1259
681
|
};
|
|
1260
682
|
|
|
1261
|
-
// src/
|
|
1262
|
-
var
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
this.monitors = new WebsetMonitorsClient(client);
|
|
1275
|
-
this.webhooks = new WebsetWebhooksClient(client);
|
|
683
|
+
// src/nova/client.ts
|
|
684
|
+
var import_zod2 = require("zod");
|
|
685
|
+
var import_zod_to_json_schema2 = require("zod-to-json-schema");
|
|
686
|
+
function isRecord(value) {
|
|
687
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
688
|
+
}
|
|
689
|
+
function isZodSchema(value) {
|
|
690
|
+
return value instanceof import_zod2.ZodType;
|
|
691
|
+
}
|
|
692
|
+
function zodToJsonSchema2(schema) {
|
|
693
|
+
const converted = (0, import_zod_to_json_schema2.zodToJsonSchema)(schema, { $refStrategy: "none" });
|
|
694
|
+
if (!isRecord(converted)) {
|
|
695
|
+
throw new Error("Failed to convert Zod schema to JSON Schema.");
|
|
1276
696
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
void 0,
|
|
1288
|
-
options?.headers
|
|
1289
|
-
);
|
|
697
|
+
return converted;
|
|
698
|
+
}
|
|
699
|
+
var ExaError = class extends Error {
|
|
700
|
+
constructor(message, statusCode, timestamp, path, details) {
|
|
701
|
+
super(message);
|
|
702
|
+
this.name = "ExaError";
|
|
703
|
+
this.statusCode = statusCode;
|
|
704
|
+
this.timestamp = timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
705
|
+
this.path = path;
|
|
706
|
+
this.details = details;
|
|
1290
707
|
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
"POST",
|
|
1305
|
-
params,
|
|
1306
|
-
queryParams
|
|
1307
|
-
);
|
|
1308
|
-
}
|
|
1309
|
-
/**
|
|
1310
|
-
* Get a Webset by ID
|
|
1311
|
-
* @param id The ID of the Webset
|
|
1312
|
-
* @param expand Optional array of relations to expand
|
|
1313
|
-
* @returns The Webset
|
|
1314
|
-
*/
|
|
1315
|
-
async get(id, expand) {
|
|
1316
|
-
const params = {};
|
|
1317
|
-
if (expand) {
|
|
1318
|
-
params.expand = expand;
|
|
1319
|
-
}
|
|
1320
|
-
return this.request(
|
|
1321
|
-
`/v0/websets/${id}`,
|
|
1322
|
-
"GET",
|
|
1323
|
-
void 0,
|
|
1324
|
-
params
|
|
1325
|
-
);
|
|
1326
|
-
}
|
|
1327
|
-
/**
|
|
1328
|
-
* List all Websets
|
|
1329
|
-
* @param options Pagination options (filtering by status is not supported by API)
|
|
1330
|
-
* @returns The list of Websets
|
|
1331
|
-
*/
|
|
1332
|
-
async list(options) {
|
|
1333
|
-
const params = this.buildPaginationParams(options);
|
|
1334
|
-
return this.request(
|
|
1335
|
-
"/v0/websets",
|
|
1336
|
-
"GET",
|
|
1337
|
-
void 0,
|
|
1338
|
-
params
|
|
1339
|
-
);
|
|
1340
|
-
}
|
|
1341
|
-
/**
|
|
1342
|
-
* Iterate through all Websets, handling pagination automatically
|
|
1343
|
-
* @param options Pagination options
|
|
1344
|
-
* @returns Async generator of Websets
|
|
1345
|
-
*/
|
|
1346
|
-
async *listAll(options) {
|
|
1347
|
-
let cursor = void 0;
|
|
1348
|
-
const pageOptions = options ? { ...options } : {};
|
|
1349
|
-
while (true) {
|
|
1350
|
-
pageOptions.cursor = cursor;
|
|
1351
|
-
const response = await this.list(pageOptions);
|
|
1352
|
-
for (const webset of response.data) {
|
|
1353
|
-
yield webset;
|
|
1354
|
-
}
|
|
1355
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
1356
|
-
break;
|
|
708
|
+
};
|
|
709
|
+
var CONTENTS_FIELDS = /* @__PURE__ */ new Set(["text", "highlights", "summary", "subpages", "subpageTarget", "extras", "livecrawl", "livecrawlTimeout", "maxAgeHours", "filterEmptyResults", "context"]);
|
|
710
|
+
var DEFAULT_MAX_CHARACTERS = 1e4;
|
|
711
|
+
var Exa = class {
|
|
712
|
+
constructor(apiKey, baseURL = "https://api.exa.ai") {
|
|
713
|
+
this.baseURL = baseURL;
|
|
714
|
+
if (!apiKey) {
|
|
715
|
+
apiKey = typeof process !== "undefined" ? process.env?.EXA_API_KEY : void 0;
|
|
716
|
+
if (!apiKey) {
|
|
717
|
+
throw new ExaError(
|
|
718
|
+
"API key must be provided as an argument or as an environment variable (EXA_API_KEY)",
|
|
719
|
+
401
|
|
720
|
+
);
|
|
1357
721
|
}
|
|
1358
|
-
cursor = response.nextCursor;
|
|
1359
722
|
}
|
|
723
|
+
this.headers = {
|
|
724
|
+
"x-api-key": apiKey,
|
|
725
|
+
"Content-Type": "application/json"
|
|
726
|
+
};
|
|
727
|
+
this.websets = new WebsetsClient(this);
|
|
728
|
+
this.research = new ResearchClient(this);
|
|
1360
729
|
}
|
|
1361
|
-
/**
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
730
|
+
/** Make a request to the Exa API. Used by sub-clients and available for direct use. */
|
|
731
|
+
async request(endpoint, method, body, params, headers) {
|
|
732
|
+
const url = this.buildRequestUrl(endpoint, params);
|
|
733
|
+
const normalizedBody = this.normalizeCategoryInBody(body);
|
|
734
|
+
const combinedHeaders = headers ? { ...this.headers, ...headers } : this.headers;
|
|
735
|
+
const response = await fetch(url, {
|
|
736
|
+
method,
|
|
737
|
+
headers: combinedHeaders,
|
|
738
|
+
body: normalizedBody ? JSON.stringify(normalizedBody) : void 0
|
|
739
|
+
});
|
|
740
|
+
if (!response.ok) {
|
|
741
|
+
throw await this.toExaError(response, endpoint);
|
|
1370
742
|
}
|
|
1371
|
-
return
|
|
1372
|
-
}
|
|
1373
|
-
/**
|
|
1374
|
-
* Update a Webset
|
|
1375
|
-
* @param id The ID of the Webset
|
|
1376
|
-
* @param params The Webset update parameters
|
|
1377
|
-
* @returns The updated Webset
|
|
1378
|
-
*/
|
|
1379
|
-
async update(id, params) {
|
|
1380
|
-
return this.request(`/v0/websets/${id}`, "POST", params);
|
|
743
|
+
return await response.json();
|
|
1381
744
|
}
|
|
1382
|
-
/**
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
745
|
+
/** Make a raw request returning the Response object directly. */
|
|
746
|
+
async rawRequest(endpoint, method = "POST", body, params) {
|
|
747
|
+
const url = this.buildRequestUrl(endpoint, params);
|
|
748
|
+
const normalizedBody = this.normalizeCategoryInBody(body);
|
|
749
|
+
return fetch(url, {
|
|
750
|
+
method,
|
|
751
|
+
headers: this.headers,
|
|
752
|
+
body: normalizedBody ? JSON.stringify(normalizedBody) : void 0
|
|
753
|
+
});
|
|
1389
754
|
}
|
|
1390
|
-
/**
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
return this.request(`/v0/websets/${id}/cancel`, "POST");
|
|
755
|
+
/** Normalize category values to underscore form. */
|
|
756
|
+
normalizeCategoryInBody(body) {
|
|
757
|
+
if (body == null || typeof body.category !== "string") {
|
|
758
|
+
return body;
|
|
759
|
+
}
|
|
760
|
+
return { ...body, category: body.category.replace(/ /g, "_") };
|
|
1397
761
|
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
* @returns The Webset once it becomes idle
|
|
1403
|
-
* @throws Error if the Webset does not become idle within the timeout
|
|
1404
|
-
*/
|
|
1405
|
-
async waitUntilIdle(id, options) {
|
|
1406
|
-
let timeout;
|
|
1407
|
-
let pollInterval = 1e3;
|
|
1408
|
-
let onPoll;
|
|
1409
|
-
if (typeof options === "number") {
|
|
1410
|
-
timeout = options;
|
|
1411
|
-
} else if (options) {
|
|
1412
|
-
timeout = options.timeout;
|
|
1413
|
-
pollInterval = options.pollInterval || 1e3;
|
|
1414
|
-
onPoll = options.onPoll;
|
|
762
|
+
buildRequestUrl(endpoint, params) {
|
|
763
|
+
let url = `${this.baseURL}${endpoint}`;
|
|
764
|
+
if (params == null || Object.keys(params).length === 0) {
|
|
765
|
+
return url;
|
|
1415
766
|
}
|
|
1416
|
-
const
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
if (
|
|
1423
|
-
|
|
1424
|
-
}
|
|
1425
|
-
if (timeout && Date.now() - startTime > timeout) {
|
|
1426
|
-
throw new ExaError(
|
|
1427
|
-
`Webset ${id} did not reach idle state within ${timeout}ms. Current status: ${webset.status}`,
|
|
1428
|
-
408 /* RequestTimeout */
|
|
1429
|
-
);
|
|
767
|
+
const searchParams = new URLSearchParams();
|
|
768
|
+
for (const [key, value] of Object.entries(params)) {
|
|
769
|
+
if (Array.isArray(value)) {
|
|
770
|
+
for (const item of value) {
|
|
771
|
+
searchParams.append(key, item);
|
|
772
|
+
}
|
|
773
|
+
} else if (value !== void 0) {
|
|
774
|
+
searchParams.append(key, String(value));
|
|
1430
775
|
}
|
|
1431
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1432
776
|
}
|
|
777
|
+
url += `?${searchParams.toString()}`;
|
|
778
|
+
return url;
|
|
1433
779
|
}
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
var WebsetsBaseClient2 = class {
|
|
1438
|
-
constructor(client) {
|
|
1439
|
-
this.client = client;
|
|
1440
|
-
}
|
|
1441
|
-
/** Make a request to the API, prepending `/websets` to the path. */
|
|
1442
|
-
async request(endpoint, method = "POST", data, params, headers) {
|
|
1443
|
-
return this.client.request(`/websets${endpoint}`, method, data, params, headers);
|
|
1444
|
-
}
|
|
1445
|
-
buildPaginationParams(pagination) {
|
|
1446
|
-
const params = {};
|
|
1447
|
-
if (!pagination) return params;
|
|
1448
|
-
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
1449
|
-
if (pagination.limit) params.limit = pagination.limit;
|
|
1450
|
-
return params;
|
|
1451
|
-
}
|
|
1452
|
-
};
|
|
1453
|
-
var WebsetItemsClient2 = class extends WebsetsBaseClient2 {
|
|
1454
|
-
async get(websetId, id) {
|
|
1455
|
-
return this.request(`/v0/websets/${websetId}/items/${id}`, "GET");
|
|
1456
|
-
}
|
|
1457
|
-
async delete(websetId, id) {
|
|
1458
|
-
return this.request(`/v0/websets/${websetId}/items/${id}`, "DELETE");
|
|
1459
|
-
}
|
|
1460
|
-
async list(websetId, options) {
|
|
1461
|
-
const queryParams = { ...this.buildPaginationParams(options), sourceId: options?.sourceId };
|
|
1462
|
-
return this.request(`/v0/websets/${websetId}/items`, "GET", void 0, queryParams);
|
|
1463
|
-
}
|
|
1464
|
-
/** Iterate through all items in a Webset, handling pagination automatically. */
|
|
1465
|
-
async *listAll(websetId, options) {
|
|
1466
|
-
let cursor = void 0;
|
|
1467
|
-
const pageOptions = options ? { ...options } : {};
|
|
1468
|
-
while (true) {
|
|
1469
|
-
const response = await this.list(websetId, { ...pageOptions, cursor });
|
|
1470
|
-
for (const item of response.data) {
|
|
1471
|
-
yield item;
|
|
1472
|
-
}
|
|
1473
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
1474
|
-
break;
|
|
1475
|
-
}
|
|
1476
|
-
cursor = response.nextCursor;
|
|
780
|
+
tryParseJsonRecord(text) {
|
|
781
|
+
if (text.length === 0) {
|
|
782
|
+
return null;
|
|
1477
783
|
}
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
items.push(item);
|
|
784
|
+
try {
|
|
785
|
+
const parsed = JSON.parse(text);
|
|
786
|
+
return isRecord(parsed) ? parsed : null;
|
|
787
|
+
} catch {
|
|
788
|
+
return null;
|
|
1484
789
|
}
|
|
1485
|
-
return items;
|
|
1486
|
-
}
|
|
1487
|
-
};
|
|
1488
|
-
var WebsetSearchesClient2 = class extends WebsetsBaseClient2 {
|
|
1489
|
-
async create(websetId, params, options) {
|
|
1490
|
-
return this.request(`/v0/websets/${websetId}/searches`, "POST", { ...params }, void 0, options?.headers);
|
|
1491
|
-
}
|
|
1492
|
-
async get(websetId, id) {
|
|
1493
|
-
return this.request(`/v0/websets/${websetId}/searches/${id}`, "GET");
|
|
1494
790
|
}
|
|
1495
|
-
async
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
var EventsClient2 = class extends WebsetsBaseClient2 {
|
|
1517
|
-
async list(options) {
|
|
1518
|
-
const queryParams = { ...this.buildPaginationParams(options), types: options?.types, createdBefore: options?.createdBefore, createdAfter: options?.createdAfter };
|
|
1519
|
-
return this.request("/v0/events", "GET", void 0, queryParams);
|
|
1520
|
-
}
|
|
1521
|
-
async get(id) {
|
|
1522
|
-
return this.request(`/v0/events/${id}`, "GET");
|
|
1523
|
-
}
|
|
1524
|
-
};
|
|
1525
|
-
var WebsetMonitorRunsClient2 = class extends WebsetsBaseClient2 {
|
|
1526
|
-
async list(monitorId) {
|
|
1527
|
-
return this.request(`/v0/monitors/${monitorId}/runs`, "GET");
|
|
1528
|
-
}
|
|
1529
|
-
async get(monitorId, id) {
|
|
1530
|
-
return this.request(`/v0/monitors/${monitorId}/runs/${id}`, "GET");
|
|
791
|
+
async toExaError(response, endpoint) {
|
|
792
|
+
const text = await response.text();
|
|
793
|
+
const parsed = this.tryParseJsonRecord(text);
|
|
794
|
+
const statusCode = parsed != null && typeof parsed.statusCode === "number" ? parsed.statusCode : response.status;
|
|
795
|
+
const timestamp = parsed != null && typeof parsed.timestamp === "string" ? parsed.timestamp : void 0;
|
|
796
|
+
const path = parsed != null && typeof parsed.path === "string" ? parsed.path : endpoint;
|
|
797
|
+
const errorMessage = parsed != null && typeof parsed.error === "string" ? parsed.error : void 0;
|
|
798
|
+
const detailMessage = parsed != null && typeof parsed.message === "string" ? parsed.message : void 0;
|
|
799
|
+
let message;
|
|
800
|
+
if (errorMessage != null && detailMessage != null) {
|
|
801
|
+
message = `${errorMessage}. ${detailMessage}`;
|
|
802
|
+
} else if (errorMessage != null) {
|
|
803
|
+
message = errorMessage;
|
|
804
|
+
} else if (detailMessage != null) {
|
|
805
|
+
message = detailMessage;
|
|
806
|
+
} else if (text.length > 0) {
|
|
807
|
+
message = text;
|
|
808
|
+
} else {
|
|
809
|
+
message = `Exa API error ${response.status}`;
|
|
810
|
+
}
|
|
811
|
+
return new ExaError(message, statusCode, timestamp, path, parsed ?? text);
|
|
1531
812
|
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
813
|
+
parseAnswerStreamLine(line) {
|
|
814
|
+
if (!line.startsWith("data:")) {
|
|
815
|
+
return null;
|
|
816
|
+
}
|
|
817
|
+
const jsonStr = line.replace(/^data:\s*/, "").trim();
|
|
818
|
+
if (jsonStr.length === 0 || jsonStr === "[DONE]") {
|
|
819
|
+
return null;
|
|
820
|
+
}
|
|
821
|
+
let parsedChunk;
|
|
822
|
+
try {
|
|
823
|
+
parsedChunk = JSON.parse(jsonStr);
|
|
824
|
+
} catch {
|
|
825
|
+
return null;
|
|
826
|
+
}
|
|
827
|
+
if (!isRecord(parsedChunk)) {
|
|
828
|
+
return null;
|
|
829
|
+
}
|
|
830
|
+
let content;
|
|
831
|
+
const choices = parsedChunk.choices;
|
|
832
|
+
if (Array.isArray(choices) && choices.length > 0 && isRecord(choices[0])) {
|
|
833
|
+
const delta = choices[0].delta;
|
|
834
|
+
if (isRecord(delta) && typeof delta.content === "string") {
|
|
835
|
+
content = delta.content;
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
let citations;
|
|
839
|
+
if (Array.isArray(parsedChunk.citations)) {
|
|
840
|
+
const normalized = [];
|
|
841
|
+
for (const citation of parsedChunk.citations) {
|
|
842
|
+
if (!isRecord(citation)) {
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
845
|
+
const id = typeof citation.id === "string" ? citation.id : void 0;
|
|
846
|
+
const url = typeof citation.url === "string" ? citation.url : void 0;
|
|
847
|
+
const title = typeof citation.title === "string" ? citation.title : void 0;
|
|
848
|
+
const publishedDate = typeof citation.publishedDate === "string" ? citation.publishedDate : void 0;
|
|
849
|
+
const author = typeof citation.author === "string" ? citation.author : void 0;
|
|
850
|
+
const text = typeof citation.text === "string" ? citation.text : void 0;
|
|
851
|
+
normalized.push({
|
|
852
|
+
...id != null ? { id } : {},
|
|
853
|
+
...url != null ? { url } : {},
|
|
854
|
+
...title != null ? { title } : {},
|
|
855
|
+
...publishedDate != null ? { publishedDate } : {},
|
|
856
|
+
...author != null ? { author } : {},
|
|
857
|
+
...text != null ? { text } : {}
|
|
858
|
+
});
|
|
859
|
+
}
|
|
860
|
+
if (normalized.length > 0) {
|
|
861
|
+
citations = normalized;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
if (content == null && (citations == null || citations.length === 0)) {
|
|
865
|
+
return null;
|
|
866
|
+
}
|
|
867
|
+
return { content, citations };
|
|
1537
868
|
}
|
|
1538
|
-
|
|
1539
|
-
|
|
869
|
+
/** Separate content-specific options from search/filter options. */
|
|
870
|
+
extractContentsOptions(options) {
|
|
871
|
+
const contentsOptions = {};
|
|
872
|
+
const restOptions = {};
|
|
873
|
+
let hasContentField = false;
|
|
874
|
+
for (const [key, value] of Object.entries(options)) {
|
|
875
|
+
if (CONTENTS_FIELDS.has(key)) {
|
|
876
|
+
contentsOptions[key] = value;
|
|
877
|
+
hasContentField = true;
|
|
878
|
+
} else {
|
|
879
|
+
restOptions[key] = value;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
if (!hasContentField) {
|
|
883
|
+
contentsOptions.text = { maxCharacters: DEFAULT_MAX_CHARACTERS };
|
|
884
|
+
}
|
|
885
|
+
return { contentsOptions, restOptions };
|
|
1540
886
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
887
|
+
search(query, options) {
|
|
888
|
+
let body;
|
|
889
|
+
if (options === void 0 || !("contents" in options)) {
|
|
890
|
+
body = { query, ...options, contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } } };
|
|
891
|
+
} else if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
892
|
+
const { contents, ...restOptions } = options;
|
|
893
|
+
body = { query, ...restOptions };
|
|
894
|
+
} else {
|
|
895
|
+
body = { query, ...options };
|
|
896
|
+
}
|
|
897
|
+
return this.request("/search", "POST", body);
|
|
1544
898
|
}
|
|
1545
|
-
|
|
1546
|
-
|
|
899
|
+
findSimilar(url, options) {
|
|
900
|
+
let body;
|
|
901
|
+
if (options === void 0 || !("contents" in options)) {
|
|
902
|
+
body = { url, ...options, contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } } };
|
|
903
|
+
} else if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
904
|
+
const { contents, ...restOptions } = options;
|
|
905
|
+
body = { url, ...restOptions };
|
|
906
|
+
} else {
|
|
907
|
+
body = { url, ...options };
|
|
908
|
+
}
|
|
909
|
+
return this.request("/findSimilar", "POST", body);
|
|
1547
910
|
}
|
|
1548
|
-
|
|
1549
|
-
|
|
911
|
+
getContents(urls, options) {
|
|
912
|
+
let requestUrls;
|
|
913
|
+
if (typeof urls === "string") {
|
|
914
|
+
requestUrls = [urls];
|
|
915
|
+
} else if (urls.length === 0) {
|
|
916
|
+
throw new ExaError("Must provide at least one URL", 400);
|
|
917
|
+
} else if (typeof urls[0] === "string") {
|
|
918
|
+
requestUrls = [];
|
|
919
|
+
for (const url of urls) {
|
|
920
|
+
if (typeof url !== "string") {
|
|
921
|
+
throw new ExaError("Expected all URLs to be strings or SearchResult objects with a url field", 400);
|
|
922
|
+
}
|
|
923
|
+
requestUrls.push(url);
|
|
924
|
+
}
|
|
925
|
+
} else {
|
|
926
|
+
requestUrls = [];
|
|
927
|
+
for (const result of urls) {
|
|
928
|
+
if (!isRecord(result) || typeof result.url !== "string") {
|
|
929
|
+
throw new ExaError("Expected all entries to have a string url field", 400);
|
|
930
|
+
}
|
|
931
|
+
requestUrls.push(result.url);
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
if (requestUrls.length === 0) {
|
|
935
|
+
throw new ExaError("Must provide at least one URL", 400);
|
|
936
|
+
}
|
|
937
|
+
return this.request("/contents", "POST", { urls: requestUrls, ...options });
|
|
1550
938
|
}
|
|
1551
|
-
async
|
|
1552
|
-
|
|
939
|
+
async answer(query, options) {
|
|
940
|
+
if (options?.stream) {
|
|
941
|
+
throw new ExaError("For streaming responses, please use streamAnswer() instead:\n\nfor await (const chunk of exa.streamAnswer(query)) {\n // Handle chunks\n}", 400);
|
|
942
|
+
}
|
|
943
|
+
let outputSchema = options?.outputSchema;
|
|
944
|
+
if (outputSchema != null && isZodSchema(outputSchema)) {
|
|
945
|
+
outputSchema = zodToJsonSchema2(outputSchema);
|
|
946
|
+
}
|
|
947
|
+
return this.request("/answer", "POST", { query, model: "exa", stream: false, text: false, ...options, outputSchema });
|
|
1553
948
|
}
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
949
|
+
async *streamAnswer(query, options) {
|
|
950
|
+
let outputSchema = options?.outputSchema;
|
|
951
|
+
if (outputSchema != null && isZodSchema(outputSchema)) {
|
|
952
|
+
outputSchema = zodToJsonSchema2(outputSchema);
|
|
953
|
+
}
|
|
954
|
+
const response = await this.rawRequest("/answer", "POST", { query, model: "exa", text: false, ...options, outputSchema, stream: true });
|
|
955
|
+
if (!response.ok) {
|
|
956
|
+
throw await this.toExaError(response, "/answer");
|
|
957
|
+
}
|
|
958
|
+
const reader = response.body?.getReader();
|
|
959
|
+
if (!reader) {
|
|
960
|
+
throw new ExaError("No response body available for streaming.", 500, (/* @__PURE__ */ new Date()).toISOString(), "/answer");
|
|
961
|
+
}
|
|
962
|
+
const decoder = new TextDecoder();
|
|
963
|
+
let buffer = "";
|
|
964
|
+
try {
|
|
965
|
+
while (true) {
|
|
966
|
+
const { done, value } = await reader.read();
|
|
967
|
+
if (done) break;
|
|
968
|
+
buffer += decoder.decode(value, { stream: true });
|
|
969
|
+
const lines = buffer.split("\n");
|
|
970
|
+
buffer = lines.pop() ?? "";
|
|
971
|
+
for (const line of lines) {
|
|
972
|
+
const chunk = this.parseAnswerStreamLine(line);
|
|
973
|
+
if (chunk != null) {
|
|
974
|
+
yield chunk;
|
|
975
|
+
}
|
|
976
|
+
}
|
|
1562
977
|
}
|
|
1563
|
-
|
|
1564
|
-
|
|
978
|
+
const trailingChunk = this.parseAnswerStreamLine(buffer);
|
|
979
|
+
if (trailingChunk != null) {
|
|
980
|
+
yield trailingChunk;
|
|
1565
981
|
}
|
|
1566
|
-
|
|
982
|
+
} finally {
|
|
983
|
+
reader.releaseLock();
|
|
1567
984
|
}
|
|
1568
985
|
}
|
|
1569
|
-
/**
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
async create(params) {
|
|
1580
|
-
return this.request("/v0/webhooks", "POST", { ...params });
|
|
1581
|
-
}
|
|
1582
|
-
async list(options) {
|
|
1583
|
-
const queryParams = this.buildPaginationParams(options);
|
|
1584
|
-
return this.request("/v0/webhooks", "GET", void 0, queryParams);
|
|
1585
|
-
}
|
|
1586
|
-
async get(id) {
|
|
1587
|
-
return this.request(`/v0/webhooks/${id}`, "GET");
|
|
1588
|
-
}
|
|
1589
|
-
async update(id, params) {
|
|
1590
|
-
return this.request(`/v0/webhooks/${id}`, "PATCH", { ...params });
|
|
1591
|
-
}
|
|
1592
|
-
async delete(id) {
|
|
1593
|
-
return this.request(`/v0/webhooks/${id}`, "DELETE");
|
|
1594
|
-
}
|
|
1595
|
-
async listAttempts(id, options) {
|
|
1596
|
-
const queryParams = { ...this.buildPaginationParams(options), eventType: options?.eventType, successful: options?.successful };
|
|
1597
|
-
return this.request(`/v0/webhooks/${id}/attempts`, "GET", void 0, queryParams);
|
|
1598
|
-
}
|
|
1599
|
-
};
|
|
1600
|
-
var ImportsClient2 = class extends WebsetsBaseClient2 {
|
|
1601
|
-
async create(params) {
|
|
1602
|
-
return this.request("/v0/imports", "POST", { ...params });
|
|
1603
|
-
}
|
|
1604
|
-
async list(options) {
|
|
1605
|
-
const queryParams = this.buildPaginationParams(options);
|
|
1606
|
-
return this.request("/v0/imports", "GET", void 0, queryParams);
|
|
1607
|
-
}
|
|
1608
|
-
async get(id) {
|
|
1609
|
-
return this.request(`/v0/imports/${id}`, "GET");
|
|
1610
|
-
}
|
|
1611
|
-
async update(id, params) {
|
|
1612
|
-
return this.request(`/v0/imports/${id}`, "PATCH", { ...params });
|
|
1613
|
-
}
|
|
1614
|
-
async delete(id) {
|
|
1615
|
-
return this.request(`/v0/imports/${id}`, "DELETE");
|
|
1616
|
-
}
|
|
1617
|
-
};
|
|
1618
|
-
var WebsetsClient2 = class extends WebsetsBaseClient2 {
|
|
1619
|
-
constructor(client) {
|
|
1620
|
-
super(client);
|
|
1621
|
-
this.items = new WebsetItemsClient2(client);
|
|
1622
|
-
this.searches = new WebsetSearchesClient2(client);
|
|
1623
|
-
this.enrichments = new WebsetEnrichmentsClient2(client);
|
|
1624
|
-
this.events = new EventsClient2(client);
|
|
1625
|
-
this.monitors = new WebsetMonitorsClient2(client);
|
|
1626
|
-
this.webhooks = new WebsetWebhooksClient2(client);
|
|
1627
|
-
this.imports = new ImportsClient2(client);
|
|
1628
|
-
}
|
|
1629
|
-
async create(params, options) {
|
|
1630
|
-
return this.request("/v0/websets", "POST", { ...params }, void 0, options?.headers);
|
|
1631
|
-
}
|
|
1632
|
-
async list(options) {
|
|
1633
|
-
const queryParams = { ...this.buildPaginationParams(options), search: options?.search };
|
|
1634
|
-
return this.request("/v0/websets", "GET", void 0, queryParams);
|
|
1635
|
-
}
|
|
1636
|
-
async get(id, options) {
|
|
1637
|
-
const queryParams = { expand: options?.expand };
|
|
1638
|
-
return this.request(`/v0/websets/${id}`, "GET", void 0, queryParams);
|
|
1639
|
-
}
|
|
1640
|
-
async update(id, params) {
|
|
1641
|
-
return this.request(`/v0/websets/${id}`, "POST", { ...params });
|
|
1642
|
-
}
|
|
1643
|
-
async delete(id) {
|
|
1644
|
-
return this.request(`/v0/websets/${id}`, "DELETE");
|
|
1645
|
-
}
|
|
1646
|
-
async cancel(id) {
|
|
1647
|
-
return this.request(`/v0/websets/${id}/cancel`, "POST");
|
|
1648
|
-
}
|
|
1649
|
-
async preview(params, options) {
|
|
1650
|
-
const queryParams = { search: options?.search };
|
|
1651
|
-
return this.request("/v0/websets/preview", "POST", { ...params }, queryParams);
|
|
1652
|
-
}
|
|
1653
|
-
/** Iterate through all Websets, handling pagination automatically. */
|
|
1654
|
-
async *listAll(options) {
|
|
1655
|
-
let cursor = void 0;
|
|
1656
|
-
const pageOptions = options ? { ...options } : {};
|
|
1657
|
-
while (true) {
|
|
1658
|
-
const response = await this.list({ ...pageOptions, cursor });
|
|
1659
|
-
for (const webset of response.data) {
|
|
1660
|
-
yield webset;
|
|
1661
|
-
}
|
|
1662
|
-
if (!response.hasMore || !response.nextCursor) {
|
|
1663
|
-
break;
|
|
1664
|
-
}
|
|
1665
|
-
cursor = response.nextCursor;
|
|
1666
|
-
}
|
|
1667
|
-
}
|
|
1668
|
-
/** Collect all Websets into an array. */
|
|
1669
|
-
async getAll(options) {
|
|
1670
|
-
const websets = [];
|
|
1671
|
-
for await (const webset of this.listAll(options)) {
|
|
1672
|
-
websets.push(webset);
|
|
1673
|
-
}
|
|
1674
|
-
return websets;
|
|
1675
|
-
}
|
|
1676
|
-
/** Poll until a Webset reaches idle status. */
|
|
1677
|
-
async waitUntilIdle(id, options) {
|
|
1678
|
-
let timeout;
|
|
1679
|
-
let pollInterval = 1e3;
|
|
1680
|
-
let onPoll;
|
|
1681
|
-
if (typeof options === "number") {
|
|
1682
|
-
timeout = options;
|
|
1683
|
-
} else if (options) {
|
|
1684
|
-
timeout = options.timeout;
|
|
1685
|
-
pollInterval = options.pollInterval || 1e3;
|
|
1686
|
-
onPoll = options.onPoll;
|
|
1687
|
-
}
|
|
1688
|
-
const startTime = Date.now();
|
|
1689
|
-
while (true) {
|
|
1690
|
-
const webset = await this.get(id);
|
|
1691
|
-
if (onPoll) onPoll(webset.status);
|
|
1692
|
-
if (webset.status === "idle") return webset;
|
|
1693
|
-
if (timeout && Date.now() - startTime > timeout) {
|
|
1694
|
-
throw new Error(`Webset ${id} did not reach idle state within ${timeout}ms. Current status: ${webset.status}`);
|
|
1695
|
-
}
|
|
1696
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
986
|
+
/**
|
|
987
|
+
* @deprecated Use `search()` instead. The search method now returns text contents by default.
|
|
988
|
+
* Search with contents. Extracts content fields (text, highlights, summary, etc.) into a `contents` wrapper.
|
|
989
|
+
*/
|
|
990
|
+
async searchAndContents(query, options) {
|
|
991
|
+
if (options === void 0) {
|
|
992
|
+
return this.request("/search", "POST", {
|
|
993
|
+
query,
|
|
994
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
995
|
+
});
|
|
1697
996
|
}
|
|
997
|
+
const { contentsOptions, restOptions } = this.extractContentsOptions(options);
|
|
998
|
+
return this.request("/search", "POST", { query, contents: contentsOptions, ...restOptions });
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* @deprecated Use `findSimilar()` instead. The findSimilar method now returns text contents by default.
|
|
1002
|
+
* Find similar with contents. Extracts content fields into a `contents` wrapper.
|
|
1003
|
+
*/
|
|
1004
|
+
async findSimilarAndContents(url, options) {
|
|
1005
|
+
if (options === void 0) {
|
|
1006
|
+
return this.request("/findSimilar", "POST", {
|
|
1007
|
+
url,
|
|
1008
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
const { contentsOptions, restOptions } = this.extractContentsOptions(options);
|
|
1012
|
+
return this.request("/findSimilar", "POST", { url, contents: contentsOptions, ...restOptions });
|
|
1698
1013
|
}
|
|
1699
1014
|
};
|
|
1700
1015
|
|
|
1701
|
-
// src/
|
|
1702
|
-
var
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1016
|
+
// src/errors.ts
|
|
1017
|
+
var HttpStatusCode = /* @__PURE__ */ ((HttpStatusCode2) => {
|
|
1018
|
+
HttpStatusCode2[HttpStatusCode2["BadRequest"] = 400] = "BadRequest";
|
|
1019
|
+
HttpStatusCode2[HttpStatusCode2["NotFound"] = 404] = "NotFound";
|
|
1020
|
+
HttpStatusCode2[HttpStatusCode2["Unauthorized"] = 401] = "Unauthorized";
|
|
1021
|
+
HttpStatusCode2[HttpStatusCode2["Forbidden"] = 403] = "Forbidden";
|
|
1022
|
+
HttpStatusCode2[HttpStatusCode2["TooManyRequests"] = 429] = "TooManyRequests";
|
|
1023
|
+
HttpStatusCode2[HttpStatusCode2["RequestTimeout"] = 408] = "RequestTimeout";
|
|
1024
|
+
HttpStatusCode2[HttpStatusCode2["InternalServerError"] = 500] = "InternalServerError";
|
|
1025
|
+
HttpStatusCode2[HttpStatusCode2["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
1026
|
+
return HttpStatusCode2;
|
|
1027
|
+
})(HttpStatusCode || {});
|
|
1028
|
+
|
|
1029
|
+
// src/zod-utils.ts
|
|
1030
|
+
var import_zod3 = require("zod");
|
|
1031
|
+
var import_zod_to_json_schema3 = require("zod-to-json-schema");
|
|
1032
|
+
function isZodSchema2(obj) {
|
|
1033
|
+
return obj instanceof import_zod3.ZodType;
|
|
1034
|
+
}
|
|
1035
|
+
function zodToJsonSchema3(schema) {
|
|
1036
|
+
return (0, import_zod_to_json_schema3.zodToJsonSchema)(schema, {
|
|
1037
|
+
$refStrategy: "none"
|
|
1038
|
+
});
|
|
1706
1039
|
}
|
|
1040
|
+
|
|
1041
|
+
// src/research/base.ts
|
|
1707
1042
|
var ResearchBaseClient2 = class {
|
|
1708
1043
|
constructor(client) {
|
|
1709
1044
|
this.client = client;
|
|
1710
1045
|
}
|
|
1711
|
-
/** Make a request to the API, prepending `/research/v1` to the path. */
|
|
1712
1046
|
async request(endpoint, method = "POST", data, params) {
|
|
1713
|
-
return this.client.request(
|
|
1047
|
+
return this.client.request(
|
|
1048
|
+
`/research/v1${endpoint}`,
|
|
1049
|
+
method,
|
|
1050
|
+
data,
|
|
1051
|
+
params
|
|
1052
|
+
);
|
|
1053
|
+
}
|
|
1054
|
+
async rawRequest(endpoint, method = "POST", data, params) {
|
|
1055
|
+
return this.client.rawRequest(
|
|
1056
|
+
`/research/v1${endpoint}`,
|
|
1057
|
+
method,
|
|
1058
|
+
data,
|
|
1059
|
+
params
|
|
1060
|
+
);
|
|
1714
1061
|
}
|
|
1715
1062
|
buildPaginationParams(pagination) {
|
|
1716
1063
|
const params = {};
|
|
@@ -1720,34 +1067,99 @@ var ResearchBaseClient2 = class {
|
|
|
1720
1067
|
return params;
|
|
1721
1068
|
}
|
|
1722
1069
|
};
|
|
1070
|
+
|
|
1071
|
+
// src/research/client.ts
|
|
1723
1072
|
var ResearchClient2 = class extends ResearchBaseClient2 {
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
const params = this.buildPaginationParams(options);
|
|
1727
|
-
return this.client.request("/research/v1", "GET", void 0, params);
|
|
1073
|
+
constructor(client) {
|
|
1074
|
+
super(client);
|
|
1728
1075
|
}
|
|
1729
|
-
/** Create a new research request. Defaults model to "exa-research-fast" if not provided. */
|
|
1730
1076
|
async create(params) {
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1077
|
+
const { instructions, model, outputSchema } = params;
|
|
1078
|
+
let schema = outputSchema;
|
|
1079
|
+
if (schema && isZodSchema2(schema)) {
|
|
1080
|
+
schema = zodToJsonSchema3(schema);
|
|
1734
1081
|
}
|
|
1735
1082
|
const payload = {
|
|
1736
|
-
instructions
|
|
1737
|
-
model:
|
|
1083
|
+
instructions,
|
|
1084
|
+
model: model ?? "exa-research-fast"
|
|
1738
1085
|
};
|
|
1739
1086
|
if (schema) {
|
|
1740
1087
|
payload.outputSchema = schema;
|
|
1741
1088
|
}
|
|
1742
|
-
return this.
|
|
1089
|
+
return this.request("", "POST", payload);
|
|
1743
1090
|
}
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1091
|
+
get(researchId, options) {
|
|
1092
|
+
if (options?.stream) {
|
|
1093
|
+
const promise = async () => {
|
|
1094
|
+
const params = { stream: "true" };
|
|
1095
|
+
if (options.events !== void 0) {
|
|
1096
|
+
params.events = options.events.toString();
|
|
1097
|
+
}
|
|
1098
|
+
const resp = await this.rawRequest(
|
|
1099
|
+
`/${researchId}`,
|
|
1100
|
+
"GET",
|
|
1101
|
+
void 0,
|
|
1102
|
+
params
|
|
1103
|
+
);
|
|
1104
|
+
if (!resp.body) {
|
|
1105
|
+
throw new Error("No response body for SSE stream");
|
|
1106
|
+
}
|
|
1107
|
+
const reader = resp.body.getReader();
|
|
1108
|
+
const decoder = new TextDecoder();
|
|
1109
|
+
let buffer = "";
|
|
1110
|
+
function processPart(part) {
|
|
1111
|
+
const lines = part.split("\n");
|
|
1112
|
+
let data = lines.slice(1).join("\n");
|
|
1113
|
+
if (data.startsWith("data:")) {
|
|
1114
|
+
data = data.slice(5).trimStart();
|
|
1115
|
+
}
|
|
1116
|
+
try {
|
|
1117
|
+
return JSON.parse(data);
|
|
1118
|
+
} catch (e) {
|
|
1119
|
+
return null;
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
async function* streamEvents() {
|
|
1123
|
+
while (true) {
|
|
1124
|
+
const { done, value } = await reader.read();
|
|
1125
|
+
if (done) break;
|
|
1126
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1127
|
+
let parts = buffer.split("\n\n");
|
|
1128
|
+
buffer = parts.pop() ?? "";
|
|
1129
|
+
for (const part of parts) {
|
|
1130
|
+
const processed = processPart(part);
|
|
1131
|
+
if (processed) {
|
|
1132
|
+
yield processed;
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
if (buffer.trim()) {
|
|
1137
|
+
const processed = processPart(buffer.trim());
|
|
1138
|
+
if (processed) {
|
|
1139
|
+
yield processed;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
return streamEvents();
|
|
1144
|
+
};
|
|
1145
|
+
return promise();
|
|
1146
|
+
} else {
|
|
1147
|
+
const params = { stream: "false" };
|
|
1148
|
+
if (options?.events !== void 0) {
|
|
1149
|
+
params.events = options.events.toString();
|
|
1150
|
+
}
|
|
1151
|
+
return this.request(
|
|
1152
|
+
`/${researchId}`,
|
|
1153
|
+
"GET",
|
|
1154
|
+
void 0,
|
|
1155
|
+
params
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
async list(options) {
|
|
1160
|
+
const params = this.buildPaginationParams(options);
|
|
1161
|
+
return this.request("", "GET", void 0, params);
|
|
1749
1162
|
}
|
|
1750
|
-
/** Poll a research request until it reaches a terminal state (completed, failed, or canceled). */
|
|
1751
1163
|
async pollUntilFinished(researchId, options) {
|
|
1752
1164
|
const pollInterval = options?.pollInterval ?? 1e3;
|
|
1753
1165
|
const timeoutMs = options?.timeoutMs ?? 10 * 60 * 1e3;
|
|
@@ -1756,313 +1168,1106 @@ var ResearchClient2 = class extends ResearchBaseClient2 {
|
|
|
1756
1168
|
let consecutiveFailures = 0;
|
|
1757
1169
|
while (true) {
|
|
1758
1170
|
try {
|
|
1759
|
-
const research = await this.get(researchId, {
|
|
1760
|
-
|
|
1171
|
+
const research = await this.get(researchId, {
|
|
1172
|
+
events: options?.events
|
|
1173
|
+
});
|
|
1174
|
+
consecutiveFailures = 0;
|
|
1761
1175
|
if (research.status === "completed" || research.status === "failed" || research.status === "canceled") {
|
|
1762
1176
|
return research;
|
|
1763
1177
|
}
|
|
1764
1178
|
} catch (err) {
|
|
1765
1179
|
consecutiveFailures += 1;
|
|
1766
1180
|
if (consecutiveFailures >= maxConsecutiveFailures) {
|
|
1767
|
-
throw new Error(
|
|
1181
|
+
throw new Error(
|
|
1182
|
+
`Polling failed ${maxConsecutiveFailures} times in a row for research ${researchId}: ${err}`
|
|
1183
|
+
);
|
|
1768
1184
|
}
|
|
1769
1185
|
}
|
|
1770
1186
|
if (Date.now() - startTime > timeoutMs) {
|
|
1771
|
-
throw new Error(
|
|
1187
|
+
throw new Error(
|
|
1188
|
+
`Polling timeout: Research ${researchId} did not complete within ${timeoutMs}ms`
|
|
1189
|
+
);
|
|
1772
1190
|
}
|
|
1773
1191
|
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1774
1192
|
}
|
|
1775
1193
|
}
|
|
1776
1194
|
};
|
|
1777
1195
|
|
|
1778
|
-
// src/
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
this.
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1196
|
+
// src/websets/base.ts
|
|
1197
|
+
var WebsetsBaseClient2 = class {
|
|
1198
|
+
/**
|
|
1199
|
+
* Initialize a new Websets base client
|
|
1200
|
+
* @param client The Exa client instance
|
|
1201
|
+
*/
|
|
1202
|
+
constructor(client) {
|
|
1203
|
+
this.client = client;
|
|
1204
|
+
}
|
|
1205
|
+
/**
|
|
1206
|
+
* Make a request to the Websets API
|
|
1207
|
+
* @param endpoint The endpoint path
|
|
1208
|
+
* @param method The HTTP method
|
|
1209
|
+
* @param data Optional request body data
|
|
1210
|
+
* @param params Optional query parameters
|
|
1211
|
+
* @returns The response JSON
|
|
1212
|
+
* @throws ExaError with API error details if the request fails
|
|
1213
|
+
*/
|
|
1214
|
+
async request(endpoint, method = "POST", data, params, headers) {
|
|
1215
|
+
return this.client.request(
|
|
1216
|
+
`/websets${endpoint}`,
|
|
1217
|
+
method,
|
|
1218
|
+
data,
|
|
1219
|
+
params,
|
|
1220
|
+
headers
|
|
1221
|
+
);
|
|
1222
|
+
}
|
|
1223
|
+
/**
|
|
1224
|
+
* Helper to build pagination parameters
|
|
1225
|
+
* @param pagination The pagination parameters
|
|
1226
|
+
* @returns QueryParams object with pagination parameters
|
|
1227
|
+
*/
|
|
1228
|
+
buildPaginationParams(pagination) {
|
|
1229
|
+
const params = {};
|
|
1230
|
+
if (!pagination) return params;
|
|
1231
|
+
if (pagination.cursor) params.cursor = pagination.cursor;
|
|
1232
|
+
if (pagination.limit) params.limit = pagination.limit;
|
|
1233
|
+
return params;
|
|
1790
1234
|
}
|
|
1791
1235
|
};
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
var
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
"x-api-key": apiKey,
|
|
1808
|
-
"Content-Type": "application/json"
|
|
1809
|
-
};
|
|
1810
|
-
this.websets = new WebsetsClient2(this);
|
|
1811
|
-
this.research = new ResearchClient2(this);
|
|
1236
|
+
|
|
1237
|
+
// src/websets/enrichments.ts
|
|
1238
|
+
var WebsetEnrichmentsClient2 = class extends WebsetsBaseClient2 {
|
|
1239
|
+
/**
|
|
1240
|
+
* Create an Enrichment for a Webset
|
|
1241
|
+
* @param websetId The ID of the Webset
|
|
1242
|
+
* @param params The enrichment parameters
|
|
1243
|
+
* @returns The created Webset Enrichment
|
|
1244
|
+
*/
|
|
1245
|
+
async create(websetId, params) {
|
|
1246
|
+
return this.request(
|
|
1247
|
+
`/v0/websets/${websetId}/enrichments`,
|
|
1248
|
+
"POST",
|
|
1249
|
+
params
|
|
1250
|
+
);
|
|
1812
1251
|
}
|
|
1813
|
-
/**
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
throw await this.toExaError(response, endpoint);
|
|
1825
|
-
}
|
|
1826
|
-
return await response.json();
|
|
1252
|
+
/**
|
|
1253
|
+
* Get an Enrichment by ID
|
|
1254
|
+
* @param websetId The ID of the Webset
|
|
1255
|
+
* @param id The ID of the Enrichment
|
|
1256
|
+
* @returns The Webset Enrichment
|
|
1257
|
+
*/
|
|
1258
|
+
async get(websetId, id) {
|
|
1259
|
+
return this.request(
|
|
1260
|
+
`/v0/websets/${websetId}/enrichments/${id}`,
|
|
1261
|
+
"GET"
|
|
1262
|
+
);
|
|
1827
1263
|
}
|
|
1828
|
-
/**
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1264
|
+
/**
|
|
1265
|
+
* Delete an Enrichment
|
|
1266
|
+
* @param websetId The ID of the Webset
|
|
1267
|
+
* @param id The ID of the Enrichment
|
|
1268
|
+
* @returns The deleted Webset Enrichment
|
|
1269
|
+
*/
|
|
1270
|
+
async delete(websetId, id) {
|
|
1271
|
+
return this.request(
|
|
1272
|
+
`/v0/websets/${websetId}/enrichments/${id}`,
|
|
1273
|
+
"DELETE"
|
|
1274
|
+
);
|
|
1837
1275
|
}
|
|
1838
|
-
/**
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1276
|
+
/**
|
|
1277
|
+
* Update an Enrichment
|
|
1278
|
+
* @param websetId The ID of the Webset
|
|
1279
|
+
* @param id The ID of the Enrichment
|
|
1280
|
+
* @param params The enrichment update parameters
|
|
1281
|
+
* @returns Promise that resolves when the update is complete
|
|
1282
|
+
*/
|
|
1283
|
+
async update(websetId, id, params) {
|
|
1284
|
+
return this.request(
|
|
1285
|
+
`/v0/websets/${websetId}/enrichments/${id}`,
|
|
1286
|
+
"PATCH",
|
|
1287
|
+
params
|
|
1288
|
+
);
|
|
1844
1289
|
}
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1290
|
+
/**
|
|
1291
|
+
* Cancel a running Enrichment
|
|
1292
|
+
* @param websetId The ID of the Webset
|
|
1293
|
+
* @param id The ID of the Enrichment
|
|
1294
|
+
* @returns The canceled Webset Enrichment
|
|
1295
|
+
*/
|
|
1296
|
+
async cancel(websetId, id) {
|
|
1297
|
+
return this.request(
|
|
1298
|
+
`/v0/websets/${websetId}/enrichments/${id}/cancel`,
|
|
1299
|
+
"POST"
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
};
|
|
1303
|
+
|
|
1304
|
+
// src/websets/events.ts
|
|
1305
|
+
var EventsClient2 = class extends WebsetsBaseClient2 {
|
|
1306
|
+
/**
|
|
1307
|
+
* Initialize a new Events client
|
|
1308
|
+
* @param client The Exa client instance
|
|
1309
|
+
*/
|
|
1310
|
+
constructor(client) {
|
|
1311
|
+
super(client);
|
|
1312
|
+
}
|
|
1313
|
+
/**
|
|
1314
|
+
* List all Events
|
|
1315
|
+
* @param options Optional filtering and pagination options
|
|
1316
|
+
* @returns The list of Events
|
|
1317
|
+
*/
|
|
1318
|
+
async list(options) {
|
|
1319
|
+
const params = {
|
|
1320
|
+
cursor: options?.cursor,
|
|
1321
|
+
limit: options?.limit,
|
|
1322
|
+
types: options?.types
|
|
1323
|
+
};
|
|
1324
|
+
return this.request(
|
|
1325
|
+
"/v0/events",
|
|
1326
|
+
"GET",
|
|
1327
|
+
void 0,
|
|
1328
|
+
params
|
|
1329
|
+
);
|
|
1330
|
+
}
|
|
1331
|
+
/**
|
|
1332
|
+
* Get an Event by ID
|
|
1333
|
+
* @param id The ID of the Event
|
|
1334
|
+
* @returns The Event
|
|
1335
|
+
*/
|
|
1336
|
+
async get(id) {
|
|
1337
|
+
return this.request(`/v0/events/${id}`, "GET");
|
|
1338
|
+
}
|
|
1339
|
+
/**
|
|
1340
|
+
* Iterate through all Events, handling pagination automatically
|
|
1341
|
+
* @param options Filtering and pagination options
|
|
1342
|
+
* @returns Async generator of Events
|
|
1343
|
+
*/
|
|
1344
|
+
async *listAll(options) {
|
|
1345
|
+
let cursor = void 0;
|
|
1346
|
+
const pageOptions = options ? { ...options } : {};
|
|
1347
|
+
while (true) {
|
|
1348
|
+
pageOptions.cursor = cursor;
|
|
1349
|
+
const response = await this.list(pageOptions);
|
|
1350
|
+
for (const event of response.data) {
|
|
1351
|
+
yield event;
|
|
1858
1352
|
}
|
|
1353
|
+
if (!response.hasMore || !response.nextCursor) {
|
|
1354
|
+
break;
|
|
1355
|
+
}
|
|
1356
|
+
cursor = response.nextCursor;
|
|
1859
1357
|
}
|
|
1860
|
-
url += `?${searchParams.toString()}`;
|
|
1861
|
-
return url;
|
|
1862
1358
|
}
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1359
|
+
/**
|
|
1360
|
+
* Collect all Events into an array
|
|
1361
|
+
* @param options Filtering and pagination options
|
|
1362
|
+
* @returns Promise resolving to an array of all Events
|
|
1363
|
+
*/
|
|
1364
|
+
async getAll(options) {
|
|
1365
|
+
const events = [];
|
|
1366
|
+
for await (const event of this.listAll(options)) {
|
|
1367
|
+
events.push(event);
|
|
1872
1368
|
}
|
|
1369
|
+
return events;
|
|
1873
1370
|
}
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1371
|
+
};
|
|
1372
|
+
|
|
1373
|
+
// src/websets/openapi.ts
|
|
1374
|
+
var CreateEnrichmentParametersFormat = /* @__PURE__ */ ((CreateEnrichmentParametersFormat2) => {
|
|
1375
|
+
CreateEnrichmentParametersFormat2["text"] = "text";
|
|
1376
|
+
CreateEnrichmentParametersFormat2["date"] = "date";
|
|
1377
|
+
CreateEnrichmentParametersFormat2["number"] = "number";
|
|
1378
|
+
CreateEnrichmentParametersFormat2["options"] = "options";
|
|
1379
|
+
CreateEnrichmentParametersFormat2["email"] = "email";
|
|
1380
|
+
CreateEnrichmentParametersFormat2["phone"] = "phone";
|
|
1381
|
+
CreateEnrichmentParametersFormat2["url"] = "url";
|
|
1382
|
+
return CreateEnrichmentParametersFormat2;
|
|
1383
|
+
})(CreateEnrichmentParametersFormat || {});
|
|
1384
|
+
var CreateImportParametersFormat = /* @__PURE__ */ ((CreateImportParametersFormat2) => {
|
|
1385
|
+
CreateImportParametersFormat2["csv"] = "csv";
|
|
1386
|
+
return CreateImportParametersFormat2;
|
|
1387
|
+
})(CreateImportParametersFormat || {});
|
|
1388
|
+
var WebsetImportSource = /* @__PURE__ */ ((WebsetImportSource2) => {
|
|
1389
|
+
WebsetImportSource2["import"] = "import";
|
|
1390
|
+
WebsetImportSource2["webset"] = "webset";
|
|
1391
|
+
return WebsetImportSource2;
|
|
1392
|
+
})(WebsetImportSource || {});
|
|
1393
|
+
var EventType = /* @__PURE__ */ ((EventType2) => {
|
|
1394
|
+
EventType2["webset_created"] = "webset.created";
|
|
1395
|
+
EventType2["webset_deleted"] = "webset.deleted";
|
|
1396
|
+
EventType2["webset_paused"] = "webset.paused";
|
|
1397
|
+
EventType2["webset_idle"] = "webset.idle";
|
|
1398
|
+
EventType2["webset_search_created"] = "webset.search.created";
|
|
1399
|
+
EventType2["webset_search_canceled"] = "webset.search.canceled";
|
|
1400
|
+
EventType2["webset_search_completed"] = "webset.search.completed";
|
|
1401
|
+
EventType2["webset_search_updated"] = "webset.search.updated";
|
|
1402
|
+
EventType2["import_created"] = "import.created";
|
|
1403
|
+
EventType2["import_completed"] = "import.completed";
|
|
1404
|
+
EventType2["webset_item_created"] = "webset.item.created";
|
|
1405
|
+
EventType2["webset_item_enriched"] = "webset.item.enriched";
|
|
1406
|
+
EventType2["monitor_created"] = "monitor.created";
|
|
1407
|
+
EventType2["monitor_updated"] = "monitor.updated";
|
|
1408
|
+
EventType2["monitor_deleted"] = "monitor.deleted";
|
|
1409
|
+
EventType2["monitor_run_created"] = "monitor.run.created";
|
|
1410
|
+
EventType2["monitor_run_completed"] = "monitor.run.completed";
|
|
1411
|
+
EventType2["webset_export_created"] = "webset.export.created";
|
|
1412
|
+
EventType2["webset_export_completed"] = "webset.export.completed";
|
|
1413
|
+
return EventType2;
|
|
1414
|
+
})(EventType || {});
|
|
1415
|
+
var ImportFailedReason = /* @__PURE__ */ ((ImportFailedReason2) => {
|
|
1416
|
+
ImportFailedReason2["invalid_format"] = "invalid_format";
|
|
1417
|
+
ImportFailedReason2["invalid_file_content"] = "invalid_file_content";
|
|
1418
|
+
ImportFailedReason2["missing_identifier"] = "missing_identifier";
|
|
1419
|
+
return ImportFailedReason2;
|
|
1420
|
+
})(ImportFailedReason || {});
|
|
1421
|
+
var ImportFormat = /* @__PURE__ */ ((ImportFormat2) => {
|
|
1422
|
+
ImportFormat2["csv"] = "csv";
|
|
1423
|
+
ImportFormat2["webset"] = "webset";
|
|
1424
|
+
return ImportFormat2;
|
|
1425
|
+
})(ImportFormat || {});
|
|
1426
|
+
var ImportObject = /* @__PURE__ */ ((ImportObject2) => {
|
|
1427
|
+
ImportObject2["import"] = "import";
|
|
1428
|
+
return ImportObject2;
|
|
1429
|
+
})(ImportObject || {});
|
|
1430
|
+
var ImportStatus = /* @__PURE__ */ ((ImportStatus2) => {
|
|
1431
|
+
ImportStatus2["pending"] = "pending";
|
|
1432
|
+
ImportStatus2["processing"] = "processing";
|
|
1433
|
+
ImportStatus2["completed"] = "completed";
|
|
1434
|
+
ImportStatus2["failed"] = "failed";
|
|
1435
|
+
return ImportStatus2;
|
|
1436
|
+
})(ImportStatus || {});
|
|
1437
|
+
var MonitorObject = /* @__PURE__ */ ((MonitorObject2) => {
|
|
1438
|
+
MonitorObject2["monitor"] = "monitor";
|
|
1439
|
+
return MonitorObject2;
|
|
1440
|
+
})(MonitorObject || {});
|
|
1441
|
+
var MonitorStatus = /* @__PURE__ */ ((MonitorStatus2) => {
|
|
1442
|
+
MonitorStatus2["enabled"] = "enabled";
|
|
1443
|
+
MonitorStatus2["disabled"] = "disabled";
|
|
1444
|
+
return MonitorStatus2;
|
|
1445
|
+
})(MonitorStatus || {});
|
|
1446
|
+
var MonitorRunObject = /* @__PURE__ */ ((MonitorRunObject2) => {
|
|
1447
|
+
MonitorRunObject2["monitor_run"] = "monitor_run";
|
|
1448
|
+
return MonitorRunObject2;
|
|
1449
|
+
})(MonitorRunObject || {});
|
|
1450
|
+
var MonitorRunStatus = /* @__PURE__ */ ((MonitorRunStatus2) => {
|
|
1451
|
+
MonitorRunStatus2["created"] = "created";
|
|
1452
|
+
MonitorRunStatus2["running"] = "running";
|
|
1453
|
+
MonitorRunStatus2["completed"] = "completed";
|
|
1454
|
+
MonitorRunStatus2["canceled"] = "canceled";
|
|
1455
|
+
MonitorRunStatus2["failed"] = "failed";
|
|
1456
|
+
return MonitorRunStatus2;
|
|
1457
|
+
})(MonitorRunStatus || {});
|
|
1458
|
+
var MonitorRunType = /* @__PURE__ */ ((MonitorRunType2) => {
|
|
1459
|
+
MonitorRunType2["search"] = "search";
|
|
1460
|
+
MonitorRunType2["refresh"] = "refresh";
|
|
1461
|
+
return MonitorRunType2;
|
|
1462
|
+
})(MonitorRunType || {});
|
|
1463
|
+
var UpdateMonitorStatus = /* @__PURE__ */ ((UpdateMonitorStatus2) => {
|
|
1464
|
+
UpdateMonitorStatus2["enabled"] = "enabled";
|
|
1465
|
+
UpdateMonitorStatus2["disabled"] = "disabled";
|
|
1466
|
+
return UpdateMonitorStatus2;
|
|
1467
|
+
})(UpdateMonitorStatus || {});
|
|
1468
|
+
var WebhookStatus = /* @__PURE__ */ ((WebhookStatus2) => {
|
|
1469
|
+
WebhookStatus2["active"] = "active";
|
|
1470
|
+
WebhookStatus2["inactive"] = "inactive";
|
|
1471
|
+
return WebhookStatus2;
|
|
1472
|
+
})(WebhookStatus || {});
|
|
1473
|
+
var WebsetStatus = /* @__PURE__ */ ((WebsetStatus2) => {
|
|
1474
|
+
WebsetStatus2["idle"] = "idle";
|
|
1475
|
+
WebsetStatus2["pending"] = "pending";
|
|
1476
|
+
WebsetStatus2["running"] = "running";
|
|
1477
|
+
WebsetStatus2["paused"] = "paused";
|
|
1478
|
+
return WebsetStatus2;
|
|
1479
|
+
})(WebsetStatus || {});
|
|
1480
|
+
var WebsetEnrichmentStatus = /* @__PURE__ */ ((WebsetEnrichmentStatus2) => {
|
|
1481
|
+
WebsetEnrichmentStatus2["pending"] = "pending";
|
|
1482
|
+
WebsetEnrichmentStatus2["canceled"] = "canceled";
|
|
1483
|
+
WebsetEnrichmentStatus2["completed"] = "completed";
|
|
1484
|
+
return WebsetEnrichmentStatus2;
|
|
1485
|
+
})(WebsetEnrichmentStatus || {});
|
|
1486
|
+
var WebsetEnrichmentFormat = /* @__PURE__ */ ((WebsetEnrichmentFormat2) => {
|
|
1487
|
+
WebsetEnrichmentFormat2["text"] = "text";
|
|
1488
|
+
WebsetEnrichmentFormat2["date"] = "date";
|
|
1489
|
+
WebsetEnrichmentFormat2["number"] = "number";
|
|
1490
|
+
WebsetEnrichmentFormat2["options"] = "options";
|
|
1491
|
+
WebsetEnrichmentFormat2["email"] = "email";
|
|
1492
|
+
WebsetEnrichmentFormat2["phone"] = "phone";
|
|
1493
|
+
WebsetEnrichmentFormat2["url"] = "url";
|
|
1494
|
+
return WebsetEnrichmentFormat2;
|
|
1495
|
+
})(WebsetEnrichmentFormat || {});
|
|
1496
|
+
var WebsetItemSource = /* @__PURE__ */ ((WebsetItemSource2) => {
|
|
1497
|
+
WebsetItemSource2["search"] = "search";
|
|
1498
|
+
WebsetItemSource2["import"] = "import";
|
|
1499
|
+
return WebsetItemSource2;
|
|
1500
|
+
})(WebsetItemSource || {});
|
|
1501
|
+
var WebsetItemEvaluationSatisfied = /* @__PURE__ */ ((WebsetItemEvaluationSatisfied2) => {
|
|
1502
|
+
WebsetItemEvaluationSatisfied2["yes"] = "yes";
|
|
1503
|
+
WebsetItemEvaluationSatisfied2["no"] = "no";
|
|
1504
|
+
WebsetItemEvaluationSatisfied2["unclear"] = "unclear";
|
|
1505
|
+
return WebsetItemEvaluationSatisfied2;
|
|
1506
|
+
})(WebsetItemEvaluationSatisfied || {});
|
|
1507
|
+
var WebsetExcludeSource = /* @__PURE__ */ ((WebsetExcludeSource2) => {
|
|
1508
|
+
WebsetExcludeSource2["import"] = "import";
|
|
1509
|
+
WebsetExcludeSource2["webset"] = "webset";
|
|
1510
|
+
return WebsetExcludeSource2;
|
|
1511
|
+
})(WebsetExcludeSource || {});
|
|
1512
|
+
var WebsetSearchScopeSource = /* @__PURE__ */ ((WebsetSearchScopeSource2) => {
|
|
1513
|
+
WebsetSearchScopeSource2["import"] = "import";
|
|
1514
|
+
WebsetSearchScopeSource2["webset"] = "webset";
|
|
1515
|
+
return WebsetSearchScopeSource2;
|
|
1516
|
+
})(WebsetSearchScopeSource || {});
|
|
1517
|
+
var WebsetSearchStatus = /* @__PURE__ */ ((WebsetSearchStatus2) => {
|
|
1518
|
+
WebsetSearchStatus2["created"] = "created";
|
|
1519
|
+
WebsetSearchStatus2["pending"] = "pending";
|
|
1520
|
+
WebsetSearchStatus2["running"] = "running";
|
|
1521
|
+
WebsetSearchStatus2["completed"] = "completed";
|
|
1522
|
+
WebsetSearchStatus2["canceled"] = "canceled";
|
|
1523
|
+
return WebsetSearchStatus2;
|
|
1524
|
+
})(WebsetSearchStatus || {});
|
|
1525
|
+
var WebsetSearchBehavior = /* @__PURE__ */ ((WebsetSearchBehavior2) => {
|
|
1526
|
+
WebsetSearchBehavior2["override"] = "override";
|
|
1527
|
+
WebsetSearchBehavior2["append"] = "append";
|
|
1528
|
+
return WebsetSearchBehavior2;
|
|
1529
|
+
})(WebsetSearchBehavior || {});
|
|
1530
|
+
var WebsetSearchCanceledReason = /* @__PURE__ */ ((WebsetSearchCanceledReason2) => {
|
|
1531
|
+
WebsetSearchCanceledReason2["webset_deleted"] = "webset_deleted";
|
|
1532
|
+
WebsetSearchCanceledReason2["webset_canceled"] = "webset_canceled";
|
|
1533
|
+
return WebsetSearchCanceledReason2;
|
|
1534
|
+
})(WebsetSearchCanceledReason || {});
|
|
1535
|
+
|
|
1536
|
+
// src/websets/imports.ts
|
|
1537
|
+
var ImportsClient2 = class extends WebsetsBaseClient2 {
|
|
1538
|
+
async create(params, csv) {
|
|
1539
|
+
if (csv === void 0) {
|
|
1540
|
+
return this.request(
|
|
1541
|
+
"/v0/imports",
|
|
1542
|
+
"POST",
|
|
1543
|
+
params
|
|
1544
|
+
);
|
|
1545
|
+
}
|
|
1546
|
+
let csvBuffer;
|
|
1547
|
+
if (typeof csv === "string") {
|
|
1548
|
+
csvBuffer = Buffer.from(csv, "utf8");
|
|
1549
|
+
} else if (Buffer.isBuffer(csv)) {
|
|
1550
|
+
csvBuffer = csv;
|
|
1891
1551
|
} else {
|
|
1892
|
-
|
|
1552
|
+
throw new ExaError(
|
|
1553
|
+
"Invalid CSV data input. Must be string or Buffer",
|
|
1554
|
+
400 /* BadRequest */
|
|
1555
|
+
);
|
|
1556
|
+
}
|
|
1557
|
+
const sizeInBytes = csvBuffer.length;
|
|
1558
|
+
const sizeInMB = Math.max(1, Math.ceil(sizeInBytes / (1024 * 1024)));
|
|
1559
|
+
const csvText = csvBuffer.toString("utf8");
|
|
1560
|
+
const lines = csvText.split("\n").filter((line) => line.trim().length > 0);
|
|
1561
|
+
const recordCount = Math.max(0, lines.length - 1);
|
|
1562
|
+
if (sizeInMB > 50) {
|
|
1563
|
+
throw new ExaError(
|
|
1564
|
+
`CSV file too large: ${sizeInMB}MB. Maximum size is 50MB.`,
|
|
1565
|
+
400 /* BadRequest */
|
|
1566
|
+
);
|
|
1567
|
+
}
|
|
1568
|
+
if (recordCount === 0) {
|
|
1569
|
+
throw new ExaError(
|
|
1570
|
+
"CSV file appears to have no data records (only header or empty)",
|
|
1571
|
+
400 /* BadRequest */
|
|
1572
|
+
);
|
|
1573
|
+
}
|
|
1574
|
+
const createParams = {
|
|
1575
|
+
title: params.title,
|
|
1576
|
+
format: "csv" /* csv */,
|
|
1577
|
+
entity: params.entity,
|
|
1578
|
+
size: sizeInBytes,
|
|
1579
|
+
count: recordCount,
|
|
1580
|
+
metadata: params.metadata,
|
|
1581
|
+
csv: params.csv
|
|
1582
|
+
};
|
|
1583
|
+
const importResponse = await this.request(
|
|
1584
|
+
"/v0/imports",
|
|
1585
|
+
"POST",
|
|
1586
|
+
createParams
|
|
1587
|
+
);
|
|
1588
|
+
try {
|
|
1589
|
+
const uploadResponse = await fetch(importResponse.uploadUrl, {
|
|
1590
|
+
method: "PUT",
|
|
1591
|
+
body: csvBuffer
|
|
1592
|
+
});
|
|
1593
|
+
if (!uploadResponse.ok) {
|
|
1594
|
+
const errorText = await uploadResponse.text();
|
|
1595
|
+
throw new ExaError(
|
|
1596
|
+
`Upload failed: ${uploadResponse.status} ${uploadResponse.statusText}. ${errorText}`,
|
|
1597
|
+
400 /* BadRequest */
|
|
1598
|
+
);
|
|
1599
|
+
}
|
|
1600
|
+
} catch (error) {
|
|
1601
|
+
if (error instanceof ExaError) {
|
|
1602
|
+
throw error;
|
|
1603
|
+
}
|
|
1604
|
+
throw new ExaError(
|
|
1605
|
+
`Failed to upload CSV data: ${error.message}`,
|
|
1606
|
+
400 /* BadRequest */
|
|
1607
|
+
);
|
|
1608
|
+
}
|
|
1609
|
+
return importResponse;
|
|
1610
|
+
}
|
|
1611
|
+
/**
|
|
1612
|
+
* Get an Import by ID
|
|
1613
|
+
* @param id The ID of the Import
|
|
1614
|
+
* @returns The Import
|
|
1615
|
+
*/
|
|
1616
|
+
async get(id) {
|
|
1617
|
+
return this.request(`/v0/imports/${id}`, "GET");
|
|
1618
|
+
}
|
|
1619
|
+
/**
|
|
1620
|
+
* List all Imports
|
|
1621
|
+
* @param options Pagination options
|
|
1622
|
+
* @returns The list of Imports
|
|
1623
|
+
*/
|
|
1624
|
+
async list(options) {
|
|
1625
|
+
const params = this.buildPaginationParams(options);
|
|
1626
|
+
return this.request(
|
|
1627
|
+
"/v0/imports",
|
|
1628
|
+
"GET",
|
|
1629
|
+
void 0,
|
|
1630
|
+
params
|
|
1631
|
+
);
|
|
1632
|
+
}
|
|
1633
|
+
/**
|
|
1634
|
+
* Update an Import
|
|
1635
|
+
* @param id The ID of the Import
|
|
1636
|
+
* @param params The import update parameters
|
|
1637
|
+
* @returns The updated Import
|
|
1638
|
+
*/
|
|
1639
|
+
async update(id, params) {
|
|
1640
|
+
return this.request(`/v0/imports/${id}`, "PATCH", params);
|
|
1641
|
+
}
|
|
1642
|
+
/**
|
|
1643
|
+
* Delete an Import
|
|
1644
|
+
* @param id The ID of the Import
|
|
1645
|
+
* @returns The deleted Import
|
|
1646
|
+
*/
|
|
1647
|
+
async delete(id) {
|
|
1648
|
+
return this.request(`/v0/imports/${id}`, "DELETE");
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
* Wait until an Import is completed or failed
|
|
1652
|
+
* @param id The ID of the Import
|
|
1653
|
+
* @param options Configuration options for timeout and polling
|
|
1654
|
+
* @returns The Import once it reaches a final state (completed or failed)
|
|
1655
|
+
* @throws Error if the Import does not complete within the timeout or fails
|
|
1656
|
+
*/
|
|
1657
|
+
async waitUntilCompleted(id, options) {
|
|
1658
|
+
const timeout = options?.timeout ?? 30 * 60 * 1e3;
|
|
1659
|
+
const pollInterval = options?.pollInterval ?? 2e3;
|
|
1660
|
+
const onPoll = options?.onPoll;
|
|
1661
|
+
const startTime = Date.now();
|
|
1662
|
+
while (true) {
|
|
1663
|
+
const importItem = await this.get(id);
|
|
1664
|
+
if (onPoll) {
|
|
1665
|
+
onPoll(importItem.status);
|
|
1666
|
+
}
|
|
1667
|
+
if (importItem.status === "completed" /* completed */) {
|
|
1668
|
+
return importItem;
|
|
1669
|
+
}
|
|
1670
|
+
if (importItem.status === "failed" /* failed */) {
|
|
1671
|
+
throw new ExaError(
|
|
1672
|
+
`Import ${id} failed: ${importItem.failedMessage || "Unknown error"}`,
|
|
1673
|
+
400 /* BadRequest */
|
|
1674
|
+
);
|
|
1675
|
+
}
|
|
1676
|
+
if (Date.now() - startTime > timeout) {
|
|
1677
|
+
throw new ExaError(
|
|
1678
|
+
`Import ${id} did not complete within ${timeout}ms. Current status: ${importItem.status}`,
|
|
1679
|
+
408 /* RequestTimeout */
|
|
1680
|
+
);
|
|
1681
|
+
}
|
|
1682
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
/**
|
|
1686
|
+
* Iterate through all Imports, handling pagination automatically
|
|
1687
|
+
* @param options Pagination options
|
|
1688
|
+
* @returns Async generator of Imports
|
|
1689
|
+
*/
|
|
1690
|
+
async *listAll(options) {
|
|
1691
|
+
let cursor = void 0;
|
|
1692
|
+
const pageOptions = options ? { ...options } : {};
|
|
1693
|
+
while (true) {
|
|
1694
|
+
pageOptions.cursor = cursor;
|
|
1695
|
+
const response = await this.list(pageOptions);
|
|
1696
|
+
for (const importItem of response.data) {
|
|
1697
|
+
yield importItem;
|
|
1698
|
+
}
|
|
1699
|
+
if (!response.hasMore || !response.nextCursor) {
|
|
1700
|
+
break;
|
|
1701
|
+
}
|
|
1702
|
+
cursor = response.nextCursor;
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* Collect all Imports into an array
|
|
1707
|
+
* @param options Pagination options
|
|
1708
|
+
* @returns Promise resolving to an array of all Imports
|
|
1709
|
+
*/
|
|
1710
|
+
async getAll(options) {
|
|
1711
|
+
const imports = [];
|
|
1712
|
+
for await (const importItem of this.listAll(options)) {
|
|
1713
|
+
imports.push(importItem);
|
|
1714
|
+
}
|
|
1715
|
+
return imports;
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
|
|
1719
|
+
// src/websets/items.ts
|
|
1720
|
+
var WebsetItemsClient2 = class extends WebsetsBaseClient2 {
|
|
1721
|
+
/**
|
|
1722
|
+
* List all Items for a Webset
|
|
1723
|
+
* @param websetId The ID of the Webset
|
|
1724
|
+
* @param params - Optional pagination and filtering parameters
|
|
1725
|
+
* @returns A promise that resolves with the list of Items
|
|
1726
|
+
*/
|
|
1727
|
+
list(websetId, params) {
|
|
1728
|
+
const queryParams = {
|
|
1729
|
+
...this.buildPaginationParams(params),
|
|
1730
|
+
sourceId: params?.sourceId
|
|
1731
|
+
};
|
|
1732
|
+
return this.request(
|
|
1733
|
+
`/v0/websets/${websetId}/items`,
|
|
1734
|
+
"GET",
|
|
1735
|
+
void 0,
|
|
1736
|
+
queryParams
|
|
1737
|
+
);
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
* Iterate through all Items in a Webset, handling pagination automatically
|
|
1741
|
+
* @param websetId The ID of the Webset
|
|
1742
|
+
* @param options Pagination options
|
|
1743
|
+
* @returns Async generator of Webset Items
|
|
1744
|
+
*/
|
|
1745
|
+
async *listAll(websetId, options) {
|
|
1746
|
+
let cursor = void 0;
|
|
1747
|
+
const pageOptions = options ? { ...options } : {};
|
|
1748
|
+
while (true) {
|
|
1749
|
+
pageOptions.cursor = cursor;
|
|
1750
|
+
const response = await this.list(websetId, pageOptions);
|
|
1751
|
+
for (const item of response.data) {
|
|
1752
|
+
yield item;
|
|
1753
|
+
}
|
|
1754
|
+
if (!response.hasMore || !response.nextCursor) {
|
|
1755
|
+
break;
|
|
1756
|
+
}
|
|
1757
|
+
cursor = response.nextCursor;
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Collect all items from a Webset into an array
|
|
1762
|
+
* @param websetId The ID of the Webset
|
|
1763
|
+
* @param options Pagination options
|
|
1764
|
+
* @returns Promise resolving to an array of all Webset Items
|
|
1765
|
+
*/
|
|
1766
|
+
async getAll(websetId, options) {
|
|
1767
|
+
const items = [];
|
|
1768
|
+
for await (const item of this.listAll(websetId, options)) {
|
|
1769
|
+
items.push(item);
|
|
1893
1770
|
}
|
|
1894
|
-
return
|
|
1771
|
+
return items;
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* Get an Item by ID
|
|
1775
|
+
* @param websetId The ID of the Webset
|
|
1776
|
+
* @param id The ID of the Item
|
|
1777
|
+
* @returns The Webset Item
|
|
1778
|
+
*/
|
|
1779
|
+
async get(websetId, id) {
|
|
1780
|
+
return this.request(
|
|
1781
|
+
`/v0/websets/${websetId}/items/${id}`,
|
|
1782
|
+
"GET"
|
|
1783
|
+
);
|
|
1784
|
+
}
|
|
1785
|
+
/**
|
|
1786
|
+
* Delete an Item
|
|
1787
|
+
* @param websetId The ID of the Webset
|
|
1788
|
+
* @param id The ID of the Item
|
|
1789
|
+
* @returns The deleted Webset Item
|
|
1790
|
+
*/
|
|
1791
|
+
async delete(websetId, id) {
|
|
1792
|
+
return this.request(
|
|
1793
|
+
`/v0/websets/${websetId}/items/${id}`,
|
|
1794
|
+
"DELETE"
|
|
1795
|
+
);
|
|
1796
|
+
}
|
|
1797
|
+
};
|
|
1798
|
+
|
|
1799
|
+
// src/websets/monitors.ts
|
|
1800
|
+
var WebsetMonitorRunsClient2 = class extends WebsetsBaseClient2 {
|
|
1801
|
+
/**
|
|
1802
|
+
* List all runs for a Monitor
|
|
1803
|
+
* @param monitorId The ID of the Monitor
|
|
1804
|
+
* @param options Pagination options
|
|
1805
|
+
* @returns The list of Monitor runs
|
|
1806
|
+
*/
|
|
1807
|
+
async list(monitorId, options) {
|
|
1808
|
+
const params = this.buildPaginationParams(options);
|
|
1809
|
+
return this.request(
|
|
1810
|
+
`/v0/monitors/${monitorId}/runs`,
|
|
1811
|
+
"GET",
|
|
1812
|
+
void 0,
|
|
1813
|
+
params
|
|
1814
|
+
);
|
|
1815
|
+
}
|
|
1816
|
+
/**
|
|
1817
|
+
* Get a specific Monitor run
|
|
1818
|
+
* @param monitorId The ID of the Monitor
|
|
1819
|
+
* @param runId The ID of the Monitor run
|
|
1820
|
+
* @returns The Monitor run
|
|
1821
|
+
*/
|
|
1822
|
+
async get(monitorId, runId) {
|
|
1823
|
+
return this.request(
|
|
1824
|
+
`/v0/monitors/${monitorId}/runs/${runId}`,
|
|
1825
|
+
"GET"
|
|
1826
|
+
);
|
|
1827
|
+
}
|
|
1828
|
+
};
|
|
1829
|
+
var WebsetMonitorsClient2 = class extends WebsetsBaseClient2 {
|
|
1830
|
+
constructor(client) {
|
|
1831
|
+
super(client);
|
|
1832
|
+
this.runs = new WebsetMonitorRunsClient2(client);
|
|
1833
|
+
}
|
|
1834
|
+
/**
|
|
1835
|
+
* Create a Monitor
|
|
1836
|
+
* @param params The monitor parameters
|
|
1837
|
+
* @returns The created Monitor
|
|
1838
|
+
*/
|
|
1839
|
+
async create(params) {
|
|
1840
|
+
return this.request("/v0/monitors", "POST", params);
|
|
1841
|
+
}
|
|
1842
|
+
/**
|
|
1843
|
+
* Get a Monitor by ID
|
|
1844
|
+
* @param id The ID of the Monitor
|
|
1845
|
+
* @returns The Monitor
|
|
1846
|
+
*/
|
|
1847
|
+
async get(id) {
|
|
1848
|
+
return this.request(`/v0/monitors/${id}`, "GET");
|
|
1849
|
+
}
|
|
1850
|
+
/**
|
|
1851
|
+
* List all Monitors
|
|
1852
|
+
* @param options Pagination and filtering options
|
|
1853
|
+
* @returns The list of Monitors
|
|
1854
|
+
*/
|
|
1855
|
+
async list(options) {
|
|
1856
|
+
const params = {
|
|
1857
|
+
cursor: options?.cursor,
|
|
1858
|
+
limit: options?.limit,
|
|
1859
|
+
websetId: options?.websetId
|
|
1860
|
+
};
|
|
1861
|
+
return this.request(
|
|
1862
|
+
"/v0/monitors",
|
|
1863
|
+
"GET",
|
|
1864
|
+
void 0,
|
|
1865
|
+
params
|
|
1866
|
+
);
|
|
1895
1867
|
}
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
}
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1868
|
+
/**
|
|
1869
|
+
* Update a Monitor
|
|
1870
|
+
* @param id The ID of the Monitor
|
|
1871
|
+
* @param params The monitor update parameters (status, metadata)
|
|
1872
|
+
* @returns The updated Monitor
|
|
1873
|
+
*/
|
|
1874
|
+
async update(id, params) {
|
|
1875
|
+
return this.request(`/v0/monitors/${id}`, "PATCH", params);
|
|
1876
|
+
}
|
|
1877
|
+
/**
|
|
1878
|
+
* Delete a Monitor
|
|
1879
|
+
* @param id The ID of the Monitor
|
|
1880
|
+
* @returns The deleted Monitor
|
|
1881
|
+
*/
|
|
1882
|
+
async delete(id) {
|
|
1883
|
+
return this.request(`/v0/monitors/${id}`, "DELETE");
|
|
1884
|
+
}
|
|
1885
|
+
/**
|
|
1886
|
+
* Iterate through all Monitors, handling pagination automatically
|
|
1887
|
+
* @param options Pagination and filtering options
|
|
1888
|
+
* @returns Async generator of Monitors
|
|
1889
|
+
*/
|
|
1890
|
+
async *listAll(options) {
|
|
1891
|
+
let cursor = void 0;
|
|
1892
|
+
const pageOptions = options ? { ...options } : {};
|
|
1893
|
+
while (true) {
|
|
1894
|
+
pageOptions.cursor = cursor;
|
|
1895
|
+
const response = await this.list(pageOptions);
|
|
1896
|
+
for (const monitor of response.data) {
|
|
1897
|
+
yield monitor;
|
|
1898
|
+
}
|
|
1899
|
+
if (!response.hasMore || !response.nextCursor) {
|
|
1900
|
+
break;
|
|
1919
1901
|
}
|
|
1902
|
+
cursor = response.nextCursor;
|
|
1920
1903
|
}
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1904
|
+
}
|
|
1905
|
+
/**
|
|
1906
|
+
* Collect all Monitors into an array
|
|
1907
|
+
* @param options Pagination and filtering options
|
|
1908
|
+
* @returns Promise resolving to an array of all Monitors
|
|
1909
|
+
*/
|
|
1910
|
+
async getAll(options) {
|
|
1911
|
+
const monitors = [];
|
|
1912
|
+
for await (const monitor of this.listAll(options)) {
|
|
1913
|
+
monitors.push(monitor);
|
|
1914
|
+
}
|
|
1915
|
+
return monitors;
|
|
1916
|
+
}
|
|
1917
|
+
};
|
|
1918
|
+
|
|
1919
|
+
// src/websets/searches.ts
|
|
1920
|
+
var WebsetSearchesClient2 = class extends WebsetsBaseClient2 {
|
|
1921
|
+
/**
|
|
1922
|
+
* Create a new Search for the Webset
|
|
1923
|
+
* @param websetId The ID of the Webset
|
|
1924
|
+
* @param params The search parameters
|
|
1925
|
+
* @returns The created Webset Search
|
|
1926
|
+
*/
|
|
1927
|
+
async create(websetId, params, options) {
|
|
1928
|
+
return this.request(
|
|
1929
|
+
`/v0/websets/${websetId}/searches`,
|
|
1930
|
+
"POST",
|
|
1931
|
+
params,
|
|
1932
|
+
void 0,
|
|
1933
|
+
options?.headers
|
|
1934
|
+
);
|
|
1935
|
+
}
|
|
1936
|
+
/**
|
|
1937
|
+
* Get a Search by ID
|
|
1938
|
+
* @param websetId The ID of the Webset
|
|
1939
|
+
* @param id The ID of the Search
|
|
1940
|
+
* @returns The Webset Search
|
|
1941
|
+
*/
|
|
1942
|
+
async get(websetId, id) {
|
|
1943
|
+
return this.request(
|
|
1944
|
+
`/v0/websets/${websetId}/searches/${id}`,
|
|
1945
|
+
"GET"
|
|
1946
|
+
);
|
|
1947
|
+
}
|
|
1948
|
+
/**
|
|
1949
|
+
* Cancel a running Search
|
|
1950
|
+
* @param websetId The ID of the Webset
|
|
1951
|
+
* @param id The ID of the Search
|
|
1952
|
+
* @returns The canceled Webset Search
|
|
1953
|
+
*/
|
|
1954
|
+
async cancel(websetId, id) {
|
|
1955
|
+
return this.request(
|
|
1956
|
+
`/v0/websets/${websetId}/searches/${id}/cancel`,
|
|
1957
|
+
"POST"
|
|
1958
|
+
);
|
|
1959
|
+
}
|
|
1960
|
+
};
|
|
1961
|
+
|
|
1962
|
+
// src/websets/webhooks.ts
|
|
1963
|
+
var WebsetWebhooksClient2 = class extends WebsetsBaseClient2 {
|
|
1964
|
+
/**
|
|
1965
|
+
* Create a Webhook
|
|
1966
|
+
* @param params The webhook parameters
|
|
1967
|
+
* @returns The created Webhook
|
|
1968
|
+
*/
|
|
1969
|
+
async create(params) {
|
|
1970
|
+
return this.request("/v0/webhooks", "POST", params);
|
|
1971
|
+
}
|
|
1972
|
+
/**
|
|
1973
|
+
* Get a Webhook by ID
|
|
1974
|
+
* @param id The ID of the Webhook
|
|
1975
|
+
* @returns The Webhook
|
|
1976
|
+
*/
|
|
1977
|
+
async get(id) {
|
|
1978
|
+
return this.request(`/v0/webhooks/${id}`, "GET");
|
|
1979
|
+
}
|
|
1980
|
+
/**
|
|
1981
|
+
* List all Webhooks
|
|
1982
|
+
* @param options Pagination options
|
|
1983
|
+
* @returns The list of Webhooks
|
|
1984
|
+
*/
|
|
1985
|
+
async list(options) {
|
|
1986
|
+
const params = this.buildPaginationParams(options);
|
|
1987
|
+
return this.request(
|
|
1988
|
+
"/v0/webhooks",
|
|
1989
|
+
"GET",
|
|
1990
|
+
void 0,
|
|
1991
|
+
params
|
|
1992
|
+
);
|
|
1993
|
+
}
|
|
1994
|
+
/**
|
|
1995
|
+
* Iterate through all Webhooks, handling pagination automatically
|
|
1996
|
+
* @param options Pagination options
|
|
1997
|
+
* @returns Async generator of Webhooks
|
|
1998
|
+
*/
|
|
1999
|
+
async *listAll(options) {
|
|
2000
|
+
let cursor = void 0;
|
|
2001
|
+
const pageOptions = options ? { ...options } : {};
|
|
2002
|
+
while (true) {
|
|
2003
|
+
pageOptions.cursor = cursor;
|
|
2004
|
+
const response = await this.list(pageOptions);
|
|
2005
|
+
for (const webhook of response.data) {
|
|
2006
|
+
yield webhook;
|
|
1942
2007
|
}
|
|
1943
|
-
if (
|
|
1944
|
-
|
|
2008
|
+
if (!response.hasMore || !response.nextCursor) {
|
|
2009
|
+
break;
|
|
1945
2010
|
}
|
|
2011
|
+
cursor = response.nextCursor;
|
|
1946
2012
|
}
|
|
1947
|
-
|
|
1948
|
-
|
|
2013
|
+
}
|
|
2014
|
+
/**
|
|
2015
|
+
* Collect all Webhooks into an array
|
|
2016
|
+
* @param options Pagination options
|
|
2017
|
+
* @returns Promise resolving to an array of all Webhooks
|
|
2018
|
+
*/
|
|
2019
|
+
async getAll(options) {
|
|
2020
|
+
const webhooks = [];
|
|
2021
|
+
for await (const webhook of this.listAll(options)) {
|
|
2022
|
+
webhooks.push(webhook);
|
|
1949
2023
|
}
|
|
1950
|
-
return
|
|
1951
|
-
|
|
1952
|
-
|
|
2024
|
+
return webhooks;
|
|
2025
|
+
}
|
|
2026
|
+
/**
|
|
2027
|
+
* Update a Webhook
|
|
2028
|
+
* @param id The ID of the Webhook
|
|
2029
|
+
* @param params The webhook update parameters (events, metadata, url)
|
|
2030
|
+
* @returns The updated Webhook
|
|
2031
|
+
*/
|
|
2032
|
+
async update(id, params) {
|
|
2033
|
+
return this.request(`/v0/webhooks/${id}`, "PATCH", params);
|
|
2034
|
+
}
|
|
2035
|
+
/**
|
|
2036
|
+
* Delete a Webhook
|
|
2037
|
+
* @param id The ID of the Webhook
|
|
2038
|
+
* @returns The deleted Webhook
|
|
2039
|
+
*/
|
|
2040
|
+
async delete(id) {
|
|
2041
|
+
return this.request(`/v0/webhooks/${id}`, "DELETE");
|
|
2042
|
+
}
|
|
2043
|
+
/**
|
|
2044
|
+
* List all attempts for a Webhook
|
|
2045
|
+
* @param id The ID of the Webhook
|
|
2046
|
+
* @param options Pagination and filtering options
|
|
2047
|
+
* @returns The list of Webhook attempts
|
|
2048
|
+
*/
|
|
2049
|
+
async listAttempts(id, options) {
|
|
2050
|
+
const params = {
|
|
2051
|
+
cursor: options?.cursor,
|
|
2052
|
+
limit: options?.limit,
|
|
2053
|
+
eventType: options?.eventType,
|
|
2054
|
+
successful: options?.successful
|
|
1953
2055
|
};
|
|
2056
|
+
return this.request(
|
|
2057
|
+
`/v0/webhooks/${id}/attempts`,
|
|
2058
|
+
"GET",
|
|
2059
|
+
void 0,
|
|
2060
|
+
params
|
|
2061
|
+
);
|
|
1954
2062
|
}
|
|
1955
|
-
/**
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
2063
|
+
/**
|
|
2064
|
+
* Iterate through all attempts for a Webhook, handling pagination automatically
|
|
2065
|
+
* @param id The ID of the Webhook
|
|
2066
|
+
* @param options Pagination and filtering options
|
|
2067
|
+
* @returns Async generator of Webhook attempts
|
|
2068
|
+
*/
|
|
2069
|
+
async *listAllAttempts(id, options) {
|
|
2070
|
+
let cursor = void 0;
|
|
2071
|
+
const pageOptions = options ? { ...options } : {};
|
|
2072
|
+
while (true) {
|
|
2073
|
+
pageOptions.cursor = cursor;
|
|
2074
|
+
const response = await this.listAttempts(id, pageOptions);
|
|
2075
|
+
for (const attempt of response.data) {
|
|
2076
|
+
yield attempt;
|
|
1966
2077
|
}
|
|
2078
|
+
if (!response.hasMore || !response.nextCursor) {
|
|
2079
|
+
break;
|
|
2080
|
+
}
|
|
2081
|
+
cursor = response.nextCursor;
|
|
1967
2082
|
}
|
|
1968
|
-
if (!hasContentField) {
|
|
1969
|
-
contentsOptions.text = { maxCharacters: DEFAULT_MAX_CHARACTERS };
|
|
1970
|
-
}
|
|
1971
|
-
return { contentsOptions, restOptions };
|
|
1972
2083
|
}
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
2084
|
+
/**
|
|
2085
|
+
* Collect all attempts for a Webhook into an array
|
|
2086
|
+
* @param id The ID of the Webhook
|
|
2087
|
+
* @param options Pagination and filtering options
|
|
2088
|
+
* @returns Promise resolving to an array of all Webhook attempts
|
|
2089
|
+
*/
|
|
2090
|
+
async getAllAttempts(id, options) {
|
|
2091
|
+
const attempts = [];
|
|
2092
|
+
for await (const attempt of this.listAllAttempts(id, options)) {
|
|
2093
|
+
attempts.push(attempt);
|
|
1982
2094
|
}
|
|
1983
|
-
return
|
|
2095
|
+
return attempts;
|
|
1984
2096
|
}
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
2097
|
+
};
|
|
2098
|
+
|
|
2099
|
+
// src/websets/client.ts
|
|
2100
|
+
var WebsetsClient2 = class extends WebsetsBaseClient2 {
|
|
2101
|
+
/**
|
|
2102
|
+
* Initialize a new Websets client
|
|
2103
|
+
* @param client The Exa client instance
|
|
2104
|
+
*/
|
|
2105
|
+
constructor(client) {
|
|
2106
|
+
super(client);
|
|
2107
|
+
this.events = new EventsClient2(client);
|
|
2108
|
+
this.imports = new ImportsClient2(client);
|
|
2109
|
+
this.items = new WebsetItemsClient2(client);
|
|
2110
|
+
this.searches = new WebsetSearchesClient2(client);
|
|
2111
|
+
this.enrichments = new WebsetEnrichmentsClient2(client);
|
|
2112
|
+
this.monitors = new WebsetMonitorsClient2(client);
|
|
2113
|
+
this.webhooks = new WebsetWebhooksClient2(client);
|
|
1996
2114
|
}
|
|
1997
|
-
|
|
1998
|
-
|
|
2115
|
+
/**
|
|
2116
|
+
* Create a new Webset
|
|
2117
|
+
* @param params The Webset creation parameters
|
|
2118
|
+
* @returns The created Webset
|
|
2119
|
+
*/
|
|
2120
|
+
async create(params, options) {
|
|
2121
|
+
return this.request(
|
|
2122
|
+
"/v0/websets",
|
|
2123
|
+
"POST",
|
|
2124
|
+
params,
|
|
2125
|
+
void 0,
|
|
2126
|
+
options?.headers
|
|
2127
|
+
);
|
|
1999
2128
|
}
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2129
|
+
/**
|
|
2130
|
+
* Preview a webset
|
|
2131
|
+
* @param params The preview parameters
|
|
2132
|
+
* @param options Optional parameters. Search = true allows you to retrieve a preview set of items that could be returned by the webset.
|
|
2133
|
+
* @returns The preview response showing how the query will be decomposed
|
|
2134
|
+
*/
|
|
2135
|
+
async preview(params, options) {
|
|
2136
|
+
const queryParams = {};
|
|
2137
|
+
if (options?.search !== void 0) {
|
|
2138
|
+
queryParams.search = options.search;
|
|
2003
2139
|
}
|
|
2004
|
-
return this.request(
|
|
2140
|
+
return this.request(
|
|
2141
|
+
"/v0/websets/preview",
|
|
2142
|
+
"POST",
|
|
2143
|
+
params,
|
|
2144
|
+
queryParams
|
|
2145
|
+
);
|
|
2005
2146
|
}
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2147
|
+
/**
|
|
2148
|
+
* Get a Webset by ID
|
|
2149
|
+
* @param id The ID of the Webset
|
|
2150
|
+
* @param expand Optional array of relations to expand
|
|
2151
|
+
* @returns The Webset
|
|
2152
|
+
*/
|
|
2153
|
+
async get(id, expand) {
|
|
2154
|
+
const params = {};
|
|
2155
|
+
if (expand) {
|
|
2156
|
+
params.expand = expand;
|
|
2014
2157
|
}
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2158
|
+
return this.request(
|
|
2159
|
+
`/v0/websets/${id}`,
|
|
2160
|
+
"GET",
|
|
2161
|
+
void 0,
|
|
2162
|
+
params
|
|
2163
|
+
);
|
|
2164
|
+
}
|
|
2165
|
+
/**
|
|
2166
|
+
* List all Websets
|
|
2167
|
+
* @param options Pagination options (filtering by status is not supported by API)
|
|
2168
|
+
* @returns The list of Websets
|
|
2169
|
+
*/
|
|
2170
|
+
async list(options) {
|
|
2171
|
+
const params = this.buildPaginationParams(options);
|
|
2172
|
+
return this.request(
|
|
2173
|
+
"/v0/websets",
|
|
2174
|
+
"GET",
|
|
2175
|
+
void 0,
|
|
2176
|
+
params
|
|
2177
|
+
);
|
|
2178
|
+
}
|
|
2179
|
+
/**
|
|
2180
|
+
* Iterate through all Websets, handling pagination automatically
|
|
2181
|
+
* @param options Pagination options
|
|
2182
|
+
* @returns Async generator of Websets
|
|
2183
|
+
*/
|
|
2184
|
+
async *listAll(options) {
|
|
2185
|
+
let cursor = void 0;
|
|
2186
|
+
const pageOptions = options ? { ...options } : {};
|
|
2187
|
+
while (true) {
|
|
2188
|
+
pageOptions.cursor = cursor;
|
|
2189
|
+
const response = await this.list(pageOptions);
|
|
2190
|
+
for (const webset of response.data) {
|
|
2191
|
+
yield webset;
|
|
2030
2192
|
}
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
yield trailingChunk;
|
|
2193
|
+
if (!response.hasMore || !response.nextCursor) {
|
|
2194
|
+
break;
|
|
2034
2195
|
}
|
|
2035
|
-
|
|
2036
|
-
reader.releaseLock();
|
|
2196
|
+
cursor = response.nextCursor;
|
|
2037
2197
|
}
|
|
2038
2198
|
}
|
|
2039
2199
|
/**
|
|
2040
|
-
*
|
|
2041
|
-
*
|
|
2200
|
+
* Collect all Websets into an array
|
|
2201
|
+
* @param options Pagination options
|
|
2202
|
+
* @returns Promise resolving to an array of all Websets
|
|
2042
2203
|
*/
|
|
2043
|
-
async
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
2048
|
-
});
|
|
2204
|
+
async getAll(options) {
|
|
2205
|
+
const websets = [];
|
|
2206
|
+
for await (const webset of this.listAll(options)) {
|
|
2207
|
+
websets.push(webset);
|
|
2049
2208
|
}
|
|
2050
|
-
|
|
2051
|
-
return this.request("/search", "POST", { query, contents: contentsOptions, ...restOptions });
|
|
2209
|
+
return websets;
|
|
2052
2210
|
}
|
|
2053
2211
|
/**
|
|
2054
|
-
*
|
|
2055
|
-
*
|
|
2212
|
+
* Update a Webset
|
|
2213
|
+
* @param id The ID of the Webset
|
|
2214
|
+
* @param params The Webset update parameters
|
|
2215
|
+
* @returns The updated Webset
|
|
2056
2216
|
*/
|
|
2057
|
-
async
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2217
|
+
async update(id, params) {
|
|
2218
|
+
return this.request(`/v0/websets/${id}`, "POST", params);
|
|
2219
|
+
}
|
|
2220
|
+
/**
|
|
2221
|
+
* Delete a Webset
|
|
2222
|
+
* @param id The ID of the Webset
|
|
2223
|
+
* @returns The deleted Webset
|
|
2224
|
+
*/
|
|
2225
|
+
async delete(id) {
|
|
2226
|
+
return this.request(`/v0/websets/${id}`, "DELETE");
|
|
2227
|
+
}
|
|
2228
|
+
/**
|
|
2229
|
+
* Cancel a running Webset
|
|
2230
|
+
* @param id The ID or external ID of the Webset
|
|
2231
|
+
* @returns The canceled Webset (as returned by the API)
|
|
2232
|
+
*/
|
|
2233
|
+
async cancel(id) {
|
|
2234
|
+
return this.request(`/v0/websets/${id}/cancel`, "POST");
|
|
2235
|
+
}
|
|
2236
|
+
/**
|
|
2237
|
+
* Wait until a Webset is idle
|
|
2238
|
+
* @param id The ID of the Webset
|
|
2239
|
+
* @param options Configuration options for timeout and polling
|
|
2240
|
+
* @returns The Webset once it becomes idle
|
|
2241
|
+
* @throws Error if the Webset does not become idle within the timeout
|
|
2242
|
+
*/
|
|
2243
|
+
async waitUntilIdle(id, options) {
|
|
2244
|
+
let timeout;
|
|
2245
|
+
let pollInterval = 1e3;
|
|
2246
|
+
let onPoll;
|
|
2247
|
+
if (typeof options === "number") {
|
|
2248
|
+
timeout = options;
|
|
2249
|
+
} else if (options) {
|
|
2250
|
+
timeout = options.timeout;
|
|
2251
|
+
pollInterval = options.pollInterval || 1e3;
|
|
2252
|
+
onPoll = options.onPoll;
|
|
2253
|
+
}
|
|
2254
|
+
const startTime = Date.now();
|
|
2255
|
+
while (true) {
|
|
2256
|
+
const webset = await this.get(id);
|
|
2257
|
+
if (onPoll) {
|
|
2258
|
+
onPoll(webset.status);
|
|
2259
|
+
}
|
|
2260
|
+
if (webset.status === "idle" /* idle */) {
|
|
2261
|
+
return webset;
|
|
2262
|
+
}
|
|
2263
|
+
if (timeout && Date.now() - startTime > timeout) {
|
|
2264
|
+
throw new ExaError(
|
|
2265
|
+
`Webset ${id} did not reach idle state within ${timeout}ms. Current status: ${webset.status}`,
|
|
2266
|
+
408 /* RequestTimeout */
|
|
2267
|
+
);
|
|
2268
|
+
}
|
|
2269
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
2063
2270
|
}
|
|
2064
|
-
const { contentsOptions, restOptions } = this.extractContentsOptions(options);
|
|
2065
|
-
return this.request("/findSimilar", "POST", { url, contents: contentsOptions, ...restOptions });
|
|
2066
2271
|
}
|
|
2067
2272
|
};
|
|
2068
2273
|
|
|
@@ -2095,10 +2300,10 @@ var Exa3 = class {
|
|
|
2095
2300
|
if (text !== void 0) contentsOptions.text = text;
|
|
2096
2301
|
if (highlights !== void 0) contentsOptions.highlights = highlights;
|
|
2097
2302
|
if (summary !== void 0) {
|
|
2098
|
-
if (typeof summary === "object" && summary !== null && "schema" in summary && summary.schema &&
|
|
2303
|
+
if (typeof summary === "object" && summary !== null && "schema" in summary && summary.schema && isZodSchema2(summary.schema)) {
|
|
2099
2304
|
contentsOptions.summary = {
|
|
2100
2305
|
...summary,
|
|
2101
|
-
schema:
|
|
2306
|
+
schema: zodToJsonSchema3(summary.schema)
|
|
2102
2307
|
};
|
|
2103
2308
|
} else {
|
|
2104
2309
|
contentsOptions.summary = summary;
|
|
@@ -2139,8 +2344,8 @@ var Exa3 = class {
|
|
|
2139
2344
|
"Content-Type": "application/json",
|
|
2140
2345
|
"User-Agent": `exa-node ${package_default.version}`
|
|
2141
2346
|
});
|
|
2142
|
-
this.websets = new
|
|
2143
|
-
this.research = new
|
|
2347
|
+
this.websets = new WebsetsClient2(this);
|
|
2348
|
+
this.research = new ResearchClient2(this);
|
|
2144
2349
|
}
|
|
2145
2350
|
/**
|
|
2146
2351
|
* Makes a request to the Exa API.
|
|
@@ -2351,8 +2556,8 @@ var Exa3 = class {
|
|
|
2351
2556
|
);
|
|
2352
2557
|
}
|
|
2353
2558
|
let outputSchema = options?.outputSchema;
|
|
2354
|
-
if (outputSchema &&
|
|
2355
|
-
outputSchema =
|
|
2559
|
+
if (outputSchema && isZodSchema2(outputSchema)) {
|
|
2560
|
+
outputSchema = zodToJsonSchema3(outputSchema);
|
|
2356
2561
|
}
|
|
2357
2562
|
const requestBody = {
|
|
2358
2563
|
query,
|
|
@@ -2367,8 +2572,8 @@ var Exa3 = class {
|
|
|
2367
2572
|
}
|
|
2368
2573
|
async *streamAnswer(query, options) {
|
|
2369
2574
|
let outputSchema = options?.outputSchema;
|
|
2370
|
-
if (outputSchema &&
|
|
2371
|
-
outputSchema =
|
|
2575
|
+
if (outputSchema && isZodSchema2(outputSchema)) {
|
|
2576
|
+
outputSchema = zodToJsonSchema3(outputSchema);
|
|
2372
2577
|
}
|
|
2373
2578
|
const body = {
|
|
2374
2579
|
query,
|