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