exa-js 2.24.0 → 2.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +131 -7
- package/dist/index.d.mts +846 -348
- package/dist/index.d.ts +846 -348
- package/dist/index.js +1437 -534
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1435 -534
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -54,7 +54,9 @@ __export(index_exports, {
|
|
|
54
54
|
EventType: () => EventType,
|
|
55
55
|
EventsClient: () => EventsClient,
|
|
56
56
|
Exa: () => Exa2,
|
|
57
|
+
ExaAbortError: () => ExaAbortError,
|
|
57
58
|
ExaError: () => ExaError,
|
|
59
|
+
ExaTimeoutError: () => ExaTimeoutError,
|
|
58
60
|
HttpStatusCode: () => HttpStatusCode,
|
|
59
61
|
ImportFailedReason: () => ImportFailedReason,
|
|
60
62
|
ImportFormat: () => ImportFormat,
|
|
@@ -101,7 +103,7 @@ var import_cross_fetch = __toESM(require("cross-fetch"));
|
|
|
101
103
|
// package.json
|
|
102
104
|
var package_default = {
|
|
103
105
|
name: "exa-js",
|
|
104
|
-
version: "2.
|
|
106
|
+
version: "2.26.0",
|
|
105
107
|
description: "Exa SDK for Node.js and the browser",
|
|
106
108
|
publishConfig: {
|
|
107
109
|
access: "public"
|
|
@@ -221,6 +223,99 @@ var ExaError = class extends Error {
|
|
|
221
223
|
}
|
|
222
224
|
}
|
|
223
225
|
};
|
|
226
|
+
var ExaAbortError = class extends Error {
|
|
227
|
+
/**
|
|
228
|
+
* Create a new ExaAbortError
|
|
229
|
+
* @param cause The underlying fetch rejection or abort reason
|
|
230
|
+
*/
|
|
231
|
+
constructor(cause) {
|
|
232
|
+
super("Request was aborted.");
|
|
233
|
+
this.name = "AbortError";
|
|
234
|
+
this.cause = cause;
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
var ExaTimeoutError = class extends ExaError {
|
|
238
|
+
/**
|
|
239
|
+
* Create a new ExaTimeoutError
|
|
240
|
+
* @param timeout The timeout that elapsed, in milliseconds
|
|
241
|
+
* @param path Path of the request that timed out
|
|
242
|
+
* @param cause The underlying fetch rejection
|
|
243
|
+
*/
|
|
244
|
+
constructor(timeout, path, cause) {
|
|
245
|
+
super(
|
|
246
|
+
`Request timed out after ${timeout}ms.`,
|
|
247
|
+
408 /* RequestTimeout */,
|
|
248
|
+
void 0,
|
|
249
|
+
path
|
|
250
|
+
);
|
|
251
|
+
this.name = "TimeoutError";
|
|
252
|
+
this.timeout = timeout;
|
|
253
|
+
this.cause = cause;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// src/error-response.ts
|
|
258
|
+
var NON_JSON_BODY_SNIPPET_LENGTH = 500;
|
|
259
|
+
async function readResponseBody(response) {
|
|
260
|
+
const text = await response.text();
|
|
261
|
+
if (!text) {
|
|
262
|
+
return { json: void 0, text };
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
return { json: JSON.parse(text), text };
|
|
266
|
+
} catch {
|
|
267
|
+
return { json: void 0, text };
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function truncateResponseBody(text) {
|
|
271
|
+
const collapsed = text.replace(/\s+/g, " ").trim();
|
|
272
|
+
return collapsed.length > NON_JSON_BODY_SNIPPET_LENGTH ? `${collapsed.slice(0, NON_JSON_BODY_SNIPPET_LENGTH)}\u2026` : collapsed;
|
|
273
|
+
}
|
|
274
|
+
async function exaErrorFromResponse(response, path) {
|
|
275
|
+
const { json, text } = await readResponseBody(response);
|
|
276
|
+
if (!json || typeof json !== "object") {
|
|
277
|
+
const snippet = truncateResponseBody(text);
|
|
278
|
+
const message2 = snippet ? `Request failed with status ${response.status}. Response body was not valid JSON: ${snippet}` : `Request failed with status ${response.status}.`;
|
|
279
|
+
return new ExaError(
|
|
280
|
+
message2,
|
|
281
|
+
response.status,
|
|
282
|
+
(/* @__PURE__ */ new Date()).toISOString(),
|
|
283
|
+
path
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
const errorData = json;
|
|
287
|
+
if (!errorData.statusCode) {
|
|
288
|
+
errorData.statusCode = response.status;
|
|
289
|
+
}
|
|
290
|
+
if (!errorData.timestamp) {
|
|
291
|
+
errorData.timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
292
|
+
}
|
|
293
|
+
if (!errorData.path) {
|
|
294
|
+
errorData.path = path;
|
|
295
|
+
}
|
|
296
|
+
const envelope = typeof errorData.error === "object" && errorData.error !== null ? errorData.error : void 0;
|
|
297
|
+
let message;
|
|
298
|
+
if (envelope) {
|
|
299
|
+
message = envelope.message || errorData.message || "Unknown error";
|
|
300
|
+
} else {
|
|
301
|
+
message = errorData.error || "Unknown error";
|
|
302
|
+
if (errorData.message) {
|
|
303
|
+
message += (message.length > 0 ? ". " : "") + errorData.message;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return new ExaError(
|
|
307
|
+
message,
|
|
308
|
+
response.status,
|
|
309
|
+
errorData.timestamp,
|
|
310
|
+
errorData.path,
|
|
311
|
+
envelope ? {
|
|
312
|
+
type: envelope.type,
|
|
313
|
+
code: envelope.code,
|
|
314
|
+
detail: envelope.detail,
|
|
315
|
+
requestId: errorData.requestId ?? envelope.requestId
|
|
316
|
+
} : errorData.requestId ? { requestId: errorData.requestId } : void 0
|
|
317
|
+
);
|
|
318
|
+
}
|
|
224
319
|
|
|
225
320
|
// src/zod-utils.ts
|
|
226
321
|
var import_zod = require("zod");
|
|
@@ -234,12 +329,418 @@ function zodToJsonSchema(schema) {
|
|
|
234
329
|
});
|
|
235
330
|
}
|
|
236
331
|
|
|
332
|
+
// src/request-options.ts
|
|
333
|
+
var MAX_TIMEOUT_MS = 2147483647;
|
|
334
|
+
function validateTimeout(timeout) {
|
|
335
|
+
if (!Number.isSafeInteger(timeout) || timeout <= 0 || timeout > MAX_TIMEOUT_MS) {
|
|
336
|
+
throw new RangeError(
|
|
337
|
+
`Request timeout must be an integer from 1 to ${MAX_TIMEOUT_MS} milliseconds (received ${timeout})`
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
return timeout;
|
|
341
|
+
}
|
|
342
|
+
var REQUEST_OPTION_KEYS = ["signal", "timeout"];
|
|
343
|
+
function omitRequestOptions(options) {
|
|
344
|
+
if (options == null) {
|
|
345
|
+
return void 0;
|
|
346
|
+
}
|
|
347
|
+
const rest = { ...options };
|
|
348
|
+
for (const key of REQUEST_OPTION_KEYS) {
|
|
349
|
+
delete rest[key];
|
|
350
|
+
}
|
|
351
|
+
return rest;
|
|
352
|
+
}
|
|
353
|
+
function pickRequestOptions(options) {
|
|
354
|
+
if (options == null) {
|
|
355
|
+
return void 0;
|
|
356
|
+
}
|
|
357
|
+
const picked = {};
|
|
358
|
+
if (options.signal !== void 0) {
|
|
359
|
+
picked.signal = options.signal;
|
|
360
|
+
}
|
|
361
|
+
if (options.timeout !== void 0) {
|
|
362
|
+
picked.timeout = options.timeout;
|
|
363
|
+
}
|
|
364
|
+
return picked.signal !== void 0 || picked.timeout !== void 0 ? picked : void 0;
|
|
365
|
+
}
|
|
366
|
+
function mergeRequestOptions(...sources) {
|
|
367
|
+
const merged = {};
|
|
368
|
+
for (const source of sources) {
|
|
369
|
+
if (source?.signal !== void 0) {
|
|
370
|
+
merged.signal = source.signal;
|
|
371
|
+
}
|
|
372
|
+
if (source?.timeout != null) {
|
|
373
|
+
merged.timeout = source.timeout;
|
|
374
|
+
}
|
|
375
|
+
if (source?.body !== void 0) {
|
|
376
|
+
merged.body = { ...merged.body, ...source.body };
|
|
377
|
+
}
|
|
378
|
+
if (source?.headers !== void 0) {
|
|
379
|
+
merged.headers = { ...merged.headers, ...source.headers };
|
|
380
|
+
}
|
|
381
|
+
if (source?.query !== void 0) {
|
|
382
|
+
merged.query = { ...merged.query, ...source.query };
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return Object.keys(merged).length > 0 ? merged : void 0;
|
|
386
|
+
}
|
|
387
|
+
var BODY_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
|
|
388
|
+
function mergeRequestBody(method, body, extraBody) {
|
|
389
|
+
if (!extraBody || !BODY_METHODS.has(method.toUpperCase())) {
|
|
390
|
+
return body;
|
|
391
|
+
}
|
|
392
|
+
const { stream: _stream, ...extra } = extraBody;
|
|
393
|
+
if (body === void 0 || body === null) {
|
|
394
|
+
return Object.keys(extra).length > 0 ? extra : body;
|
|
395
|
+
}
|
|
396
|
+
if (typeof body !== "object" || Array.isArray(body)) {
|
|
397
|
+
throw new TypeError(
|
|
398
|
+
"Cannot merge the `body` request option into a request body that is not an object"
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
return { ...body, ...extra };
|
|
402
|
+
}
|
|
403
|
+
function mergeRequestQuery(query, extraQuery) {
|
|
404
|
+
const extra = Object.fromEntries(
|
|
405
|
+
Object.entries(extraQuery ?? {}).filter(
|
|
406
|
+
([name, value]) => name !== "stream" && value !== void 0 && value !== null
|
|
407
|
+
)
|
|
408
|
+
);
|
|
409
|
+
return Object.keys(extra).length > 0 ? { ...query, ...extra } : query;
|
|
410
|
+
}
|
|
411
|
+
function acceptsEventStream(headers) {
|
|
412
|
+
return Object.entries(headers).some(
|
|
413
|
+
([name, value]) => name.toLowerCase() === "accept" && value.toLowerCase().includes("text/event-stream")
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
function mergeRequestHeaders(headers, extraHeaders) {
|
|
417
|
+
if (!extraHeaders) {
|
|
418
|
+
return headers;
|
|
419
|
+
}
|
|
420
|
+
const keepsAccept = acceptsEventStream(headers);
|
|
421
|
+
const merged = { ...headers };
|
|
422
|
+
for (const [name, value] of Object.entries(extraHeaders)) {
|
|
423
|
+
const lowerCaseName = name.toLowerCase();
|
|
424
|
+
if (value === void 0 || keepsAccept && lowerCaseName === "accept") {
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
for (const existing of Object.keys(merged)) {
|
|
428
|
+
if (existing.toLowerCase() === lowerCaseName) {
|
|
429
|
+
delete merged[existing];
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (value !== null) {
|
|
433
|
+
merged[name] = value;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return merged;
|
|
437
|
+
}
|
|
438
|
+
var CLIENT_DEFAULTS = /* @__PURE__ */ new WeakMap();
|
|
439
|
+
function setClientDefaults(client, defaults) {
|
|
440
|
+
if (defaults === void 0) {
|
|
441
|
+
CLIENT_DEFAULTS.delete(client);
|
|
442
|
+
} else {
|
|
443
|
+
CLIENT_DEFAULTS.set(client, defaults);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
function withClientDefaults(client, requestOptions) {
|
|
447
|
+
return mergeRequestOptions(CLIENT_DEFAULTS.get(client), requestOptions);
|
|
448
|
+
}
|
|
449
|
+
function streamRequestOptions(client, requestOptions) {
|
|
450
|
+
return asStreamRequestOptions(withClientDefaults(client, requestOptions));
|
|
451
|
+
}
|
|
452
|
+
var STREAM_REQUEST_OPTIONS = /* @__PURE__ */ new WeakSet();
|
|
453
|
+
function asStreamRequestOptions(options) {
|
|
454
|
+
const copy = mergeRequestOptions(options);
|
|
455
|
+
if (copy) {
|
|
456
|
+
STREAM_REQUEST_OPTIONS.add(copy);
|
|
457
|
+
}
|
|
458
|
+
return copy;
|
|
459
|
+
}
|
|
460
|
+
function isStreamRequestOptions(options) {
|
|
461
|
+
return options != null && STREAM_REQUEST_OPTIONS.has(options);
|
|
462
|
+
}
|
|
463
|
+
var NOOP_DISPOSE = () => {
|
|
464
|
+
};
|
|
465
|
+
function createTimeoutSignal(timeoutMs) {
|
|
466
|
+
const controller = new AbortController();
|
|
467
|
+
const timer = setTimeout(() => {
|
|
468
|
+
controller.abort(
|
|
469
|
+
typeof DOMException !== "undefined" ? new DOMException(
|
|
470
|
+
`The operation was aborted due to timeout after ${timeoutMs}ms`,
|
|
471
|
+
"TimeoutError"
|
|
472
|
+
) : void 0
|
|
473
|
+
);
|
|
474
|
+
}, timeoutMs);
|
|
475
|
+
if (typeof timer.unref === "function") {
|
|
476
|
+
timer.unref();
|
|
477
|
+
}
|
|
478
|
+
let disposed = false;
|
|
479
|
+
const dispose = () => {
|
|
480
|
+
if (disposed) return;
|
|
481
|
+
disposed = true;
|
|
482
|
+
clearTimeout(timer);
|
|
483
|
+
};
|
|
484
|
+
controller.signal.addEventListener("abort", dispose, { once: true });
|
|
485
|
+
return { signal: controller.signal, dispose };
|
|
486
|
+
}
|
|
487
|
+
function anySignal(signals) {
|
|
488
|
+
if (signals.length === 1) {
|
|
489
|
+
return { signal: signals[0], dispose: NOOP_DISPOSE };
|
|
490
|
+
}
|
|
491
|
+
const controller = new AbortController();
|
|
492
|
+
const abortHandlers = [];
|
|
493
|
+
let disposed = false;
|
|
494
|
+
const dispose = () => {
|
|
495
|
+
if (disposed) return;
|
|
496
|
+
disposed = true;
|
|
497
|
+
for (const { signal, handler } of abortHandlers) {
|
|
498
|
+
signal.removeEventListener("abort", handler);
|
|
499
|
+
}
|
|
500
|
+
abortHandlers.length = 0;
|
|
501
|
+
};
|
|
502
|
+
for (const signal of signals) {
|
|
503
|
+
if (signal.aborted) {
|
|
504
|
+
controller.abort(signal.reason);
|
|
505
|
+
dispose();
|
|
506
|
+
return { signal: controller.signal, dispose: NOOP_DISPOSE };
|
|
507
|
+
}
|
|
508
|
+
const handler = () => {
|
|
509
|
+
controller.abort(signal.reason);
|
|
510
|
+
};
|
|
511
|
+
signal.addEventListener("abort", handler);
|
|
512
|
+
abortHandlers.push({ signal, handler });
|
|
513
|
+
}
|
|
514
|
+
controller.signal.addEventListener("abort", dispose, { once: true });
|
|
515
|
+
return { signal: controller.signal, dispose };
|
|
516
|
+
}
|
|
517
|
+
function resolveRequestSignal(options) {
|
|
518
|
+
if (options == null) {
|
|
519
|
+
return {
|
|
520
|
+
signal: void 0,
|
|
521
|
+
dispose: () => {
|
|
522
|
+
},
|
|
523
|
+
needsDispose: false,
|
|
524
|
+
stopTimeout: NOOP_DISPOSE,
|
|
525
|
+
toRequestError: (error) => error
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
const { signal, timeout } = options;
|
|
529
|
+
const signals = [];
|
|
530
|
+
const disposers = [];
|
|
531
|
+
let timeoutSignal;
|
|
532
|
+
if (signal) {
|
|
533
|
+
signals.push(signal);
|
|
534
|
+
}
|
|
535
|
+
if (timeout != null) {
|
|
536
|
+
timeoutSignal = createTimeoutSignal(validateTimeout(timeout));
|
|
537
|
+
signals.push(timeoutSignal.signal);
|
|
538
|
+
if (timeoutSignal.dispose !== NOOP_DISPOSE) {
|
|
539
|
+
disposers.push(timeoutSignal.dispose);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (signals.length === 0) {
|
|
543
|
+
return {
|
|
544
|
+
signal: void 0,
|
|
545
|
+
dispose: () => {
|
|
546
|
+
},
|
|
547
|
+
needsDispose: false,
|
|
548
|
+
stopTimeout: NOOP_DISPOSE,
|
|
549
|
+
toRequestError: (error) => error
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
const combined = anySignal(signals);
|
|
553
|
+
if (combined.dispose !== NOOP_DISPOSE) {
|
|
554
|
+
disposers.push(combined.dispose);
|
|
555
|
+
}
|
|
556
|
+
let firstAbort;
|
|
557
|
+
if (signal && timeoutSignal) {
|
|
558
|
+
combined.signal.addEventListener(
|
|
559
|
+
"abort",
|
|
560
|
+
() => {
|
|
561
|
+
firstAbort = signal.aborted ? "signal" : "timeout";
|
|
562
|
+
},
|
|
563
|
+
{ once: true }
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
const toRequestError = (error, path) => {
|
|
567
|
+
if (error instanceof ExaError || error instanceof ExaAbortError) {
|
|
568
|
+
return error;
|
|
569
|
+
}
|
|
570
|
+
const abortedBy = firstAbort ?? (signal?.aborted ? "signal" : timeoutSignal?.signal.aborted ? "timeout" : void 0);
|
|
571
|
+
if (abortedBy === "timeout") {
|
|
572
|
+
return new ExaTimeoutError(timeout, path, error);
|
|
573
|
+
}
|
|
574
|
+
if (abortedBy === "signal") {
|
|
575
|
+
return new ExaAbortError(error);
|
|
576
|
+
}
|
|
577
|
+
return error;
|
|
578
|
+
};
|
|
579
|
+
const stopTimeout = timeoutSignal?.dispose ?? NOOP_DISPOSE;
|
|
580
|
+
if (disposers.length === 0) {
|
|
581
|
+
return {
|
|
582
|
+
signal: combined.signal,
|
|
583
|
+
dispose: () => {
|
|
584
|
+
},
|
|
585
|
+
needsDispose: false,
|
|
586
|
+
stopTimeout,
|
|
587
|
+
toRequestError
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
let disposed = false;
|
|
591
|
+
return {
|
|
592
|
+
signal: combined.signal,
|
|
593
|
+
dispose: () => {
|
|
594
|
+
if (disposed) return;
|
|
595
|
+
disposed = true;
|
|
596
|
+
for (const dispose of disposers) {
|
|
597
|
+
dispose();
|
|
598
|
+
}
|
|
599
|
+
},
|
|
600
|
+
needsDispose: true,
|
|
601
|
+
stopTimeout,
|
|
602
|
+
toRequestError
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
function withDisposeOnBodySettled(response, dispose, mapError = (error) => error) {
|
|
606
|
+
const body = response.body;
|
|
607
|
+
if (!body) {
|
|
608
|
+
dispose();
|
|
609
|
+
return response;
|
|
610
|
+
}
|
|
611
|
+
if (typeof body.getReader !== "function") {
|
|
612
|
+
const nodeBody = body;
|
|
613
|
+
const settle2 = () => {
|
|
614
|
+
nodeBody.removeListener("end", settle2);
|
|
615
|
+
nodeBody.removeListener("close", settle2);
|
|
616
|
+
nodeBody.removeListener("error", settle2);
|
|
617
|
+
dispose();
|
|
618
|
+
};
|
|
619
|
+
nodeBody.once("end", settle2);
|
|
620
|
+
nodeBody.once("close", settle2);
|
|
621
|
+
nodeBody.once("error", settle2);
|
|
622
|
+
return response;
|
|
623
|
+
}
|
|
624
|
+
let settled = false;
|
|
625
|
+
const settle = () => {
|
|
626
|
+
if (settled) return;
|
|
627
|
+
settled = true;
|
|
628
|
+
dispose();
|
|
629
|
+
};
|
|
630
|
+
const reader = body.getReader();
|
|
631
|
+
const stream = new ReadableStream({
|
|
632
|
+
async pull(controller) {
|
|
633
|
+
try {
|
|
634
|
+
const { done, value } = await reader.read();
|
|
635
|
+
if (done) {
|
|
636
|
+
settle();
|
|
637
|
+
controller.close();
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
controller.enqueue(value);
|
|
641
|
+
} catch (error) {
|
|
642
|
+
settle();
|
|
643
|
+
controller.error(mapError(error));
|
|
644
|
+
}
|
|
645
|
+
},
|
|
646
|
+
cancel(reason) {
|
|
647
|
+
settle();
|
|
648
|
+
return reader.cancel(reason);
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
const wrapped = new Response(stream, {
|
|
652
|
+
status: response.status,
|
|
653
|
+
statusText: response.statusText,
|
|
654
|
+
headers: response.headers
|
|
655
|
+
});
|
|
656
|
+
const preserveMetadata = (target) => {
|
|
657
|
+
Object.defineProperties(target, {
|
|
658
|
+
url: { value: response.url },
|
|
659
|
+
redirected: { value: response.redirected },
|
|
660
|
+
type: { value: response.type }
|
|
661
|
+
});
|
|
662
|
+
const clone = target.clone.bind(target);
|
|
663
|
+
Object.defineProperty(target, "clone", {
|
|
664
|
+
value: () => preserveMetadata(clone())
|
|
665
|
+
});
|
|
666
|
+
return target;
|
|
667
|
+
};
|
|
668
|
+
preserveMetadata(wrapped);
|
|
669
|
+
return wrapped;
|
|
670
|
+
}
|
|
671
|
+
function sleep(ms, signal) {
|
|
672
|
+
if (!signal) {
|
|
673
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
674
|
+
}
|
|
675
|
+
return new Promise((resolve, reject) => {
|
|
676
|
+
if (signal.aborted) {
|
|
677
|
+
reject(new ExaAbortError(signal.reason));
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
let timer;
|
|
681
|
+
const onAbort = () => {
|
|
682
|
+
clearTimeout(timer);
|
|
683
|
+
reject(new ExaAbortError(signal.reason));
|
|
684
|
+
};
|
|
685
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
686
|
+
timer = setTimeout(() => {
|
|
687
|
+
signal.removeEventListener("abort", onAbort);
|
|
688
|
+
resolve();
|
|
689
|
+
}, ms);
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
var RequestScopedClient = class {
|
|
693
|
+
/**
|
|
694
|
+
* Returns a view of this client that sends `requestOptions` with every
|
|
695
|
+
* request, on top of any the client already carries. Returns the client
|
|
696
|
+
* itself when there is nothing to add.
|
|
697
|
+
*/
|
|
698
|
+
withRequestOptions(requestOptions) {
|
|
699
|
+
if (mergeRequestOptions(requestOptions) === void 0) {
|
|
700
|
+
return this;
|
|
701
|
+
}
|
|
702
|
+
const view = Object.create(this);
|
|
703
|
+
view.requestOptions = mergeRequestOptions(
|
|
704
|
+
this.requestOptions,
|
|
705
|
+
requestOptions
|
|
706
|
+
);
|
|
707
|
+
return view;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Returns the view a listing fetches its pages with after the first: this
|
|
711
|
+
* one without a `cursor` in the extra `query`. A listing advances the
|
|
712
|
+
* cursor itself; an extra `cursor` selects where it starts and, sent again,
|
|
713
|
+
* would replace every later cursor and fetch that page forever.
|
|
714
|
+
*/
|
|
715
|
+
forNextPage() {
|
|
716
|
+
const query = this.requestOptions?.query;
|
|
717
|
+
if (!query || !("cursor" in query)) {
|
|
718
|
+
return this;
|
|
719
|
+
}
|
|
720
|
+
const { cursor: _cursor, ...remaining } = query;
|
|
721
|
+
const view = Object.create(this);
|
|
722
|
+
view.requestOptions = { ...this.requestOptions, query: remaining };
|
|
723
|
+
return view;
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
|
|
237
727
|
// src/agent/base.ts
|
|
238
|
-
var AgentBaseClient = class {
|
|
728
|
+
var AgentBaseClient = class extends RequestScopedClient {
|
|
239
729
|
constructor(client) {
|
|
730
|
+
super();
|
|
240
731
|
this.client = client;
|
|
241
732
|
}
|
|
242
733
|
async request(endpoint, method = "POST", data, params, headers) {
|
|
734
|
+
if (this.requestOptions) {
|
|
735
|
+
return this.client.request(
|
|
736
|
+
`/agent/runs${endpoint}`,
|
|
737
|
+
method,
|
|
738
|
+
data,
|
|
739
|
+
params,
|
|
740
|
+
headers,
|
|
741
|
+
this.requestOptions
|
|
742
|
+
);
|
|
743
|
+
}
|
|
243
744
|
return this.client.request(
|
|
244
745
|
`/agent/runs${endpoint}`,
|
|
245
746
|
method,
|
|
@@ -248,7 +749,22 @@ var AgentBaseClient = class {
|
|
|
248
749
|
headers
|
|
249
750
|
);
|
|
250
751
|
}
|
|
752
|
+
/**
|
|
753
|
+
* Opens a streamed response. `timeout` covers the wait for the stream to
|
|
754
|
+
* start; the caller's `signal` can cancel it at any point.
|
|
755
|
+
*/
|
|
251
756
|
async rawRequest(endpoint, method = "POST", data, params, headers) {
|
|
757
|
+
const transport = streamRequestOptions(this.client, this.requestOptions);
|
|
758
|
+
if (transport) {
|
|
759
|
+
return this.client.rawRequest(
|
|
760
|
+
`/agent/runs${endpoint}`,
|
|
761
|
+
method,
|
|
762
|
+
data,
|
|
763
|
+
params,
|
|
764
|
+
headers,
|
|
765
|
+
transport
|
|
766
|
+
);
|
|
767
|
+
}
|
|
252
768
|
return this.client.rawRequest(
|
|
253
769
|
`/agent/runs${endpoint}`,
|
|
254
770
|
method,
|
|
@@ -277,8 +793,9 @@ function headersForBetas(betas) {
|
|
|
277
793
|
var AGENT_MONITORS_BETA_HEADER = "agent-monitors-2026-08-04";
|
|
278
794
|
|
|
279
795
|
// src/agent/monitors/base.ts
|
|
280
|
-
var AgentMonitorsBaseClient = class {
|
|
796
|
+
var AgentMonitorsBaseClient = class extends RequestScopedClient {
|
|
281
797
|
constructor(client) {
|
|
798
|
+
super();
|
|
282
799
|
this.client = client;
|
|
283
800
|
}
|
|
284
801
|
async request(endpoint, betas, method = "POST", data, params, headers) {
|
|
@@ -288,15 +805,26 @@ var AgentMonitorsBaseClient = class {
|
|
|
288
805
|
400 /* BadRequest */
|
|
289
806
|
);
|
|
290
807
|
}
|
|
808
|
+
const requestHeaders = {
|
|
809
|
+
...headersForBetas(betas),
|
|
810
|
+
...headers
|
|
811
|
+
};
|
|
812
|
+
if (this.requestOptions) {
|
|
813
|
+
return this.client.request(
|
|
814
|
+
`/agent/monitors${endpoint}`,
|
|
815
|
+
method,
|
|
816
|
+
data,
|
|
817
|
+
params,
|
|
818
|
+
requestHeaders,
|
|
819
|
+
this.requestOptions
|
|
820
|
+
);
|
|
821
|
+
}
|
|
291
822
|
return this.client.request(
|
|
292
823
|
`/agent/monitors${endpoint}`,
|
|
293
824
|
method,
|
|
294
825
|
data,
|
|
295
826
|
params,
|
|
296
|
-
|
|
297
|
-
...headersForBetas(betas),
|
|
298
|
-
...headers
|
|
299
|
-
}
|
|
827
|
+
requestHeaders
|
|
300
828
|
);
|
|
301
829
|
}
|
|
302
830
|
buildPaginationParams(pagination) {
|
|
@@ -326,9 +854,10 @@ var AgentMonitorEntitiesClient = class extends AgentMonitorsBaseClient {
|
|
|
326
854
|
* and backfilled shortly after the request completes, then update on the
|
|
327
855
|
* monitor's regular refresh cadence.
|
|
328
856
|
*/
|
|
329
|
-
async add(monitorId, params) {
|
|
857
|
+
async add(monitorId, params, requestOptions) {
|
|
858
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
330
859
|
const { betas, ...payload } = params;
|
|
331
|
-
return
|
|
860
|
+
return scoped.request(
|
|
332
861
|
`/${monitorId}/entities`,
|
|
333
862
|
betas,
|
|
334
863
|
"POST",
|
|
@@ -339,10 +868,11 @@ var AgentMonitorEntitiesClient = class extends AgentMonitorsBaseClient {
|
|
|
339
868
|
* Page an Agent Monitor's current entities and contents, optionally
|
|
340
869
|
* filtered by update time.
|
|
341
870
|
*/
|
|
342
|
-
async list(monitorId, options) {
|
|
871
|
+
async list(monitorId, options, requestOptions) {
|
|
872
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
343
873
|
const { betas, ...pagination } = options;
|
|
344
874
|
const params = this.buildPaginationParams(pagination);
|
|
345
|
-
return
|
|
875
|
+
return scoped.request(
|
|
346
876
|
`/${monitorId}/entities`,
|
|
347
877
|
betas,
|
|
348
878
|
"GET",
|
|
@@ -354,13 +884,14 @@ var AgentMonitorEntitiesClient = class extends AgentMonitorsBaseClient {
|
|
|
354
884
|
* Iterate through all of a monitor's entities, handling pagination
|
|
355
885
|
* automatically.
|
|
356
886
|
*/
|
|
357
|
-
async *listAll(monitorId, options) {
|
|
887
|
+
async *listAll(monitorId, options, requestOptions) {
|
|
888
|
+
let scoped = this.withRequestOptions(requestOptions);
|
|
358
889
|
let cursor = options.cursor;
|
|
359
890
|
const { betas, ...pagination } = options;
|
|
360
891
|
const pageOptions = { ...pagination };
|
|
361
892
|
while (true) {
|
|
362
893
|
pageOptions.cursor = cursor;
|
|
363
|
-
const response = await
|
|
894
|
+
const response = await scoped.list(monitorId, { ...pageOptions, betas });
|
|
364
895
|
for (const entityView of response.data) {
|
|
365
896
|
yield entityView;
|
|
366
897
|
}
|
|
@@ -368,14 +899,16 @@ var AgentMonitorEntitiesClient = class extends AgentMonitorsBaseClient {
|
|
|
368
899
|
break;
|
|
369
900
|
}
|
|
370
901
|
cursor = response.nextCursor;
|
|
902
|
+
scoped = scoped.forNextPage();
|
|
371
903
|
}
|
|
372
904
|
}
|
|
373
905
|
/**
|
|
374
906
|
* Collect all of a monitor's entities into an array.
|
|
375
907
|
*/
|
|
376
|
-
async getAll(monitorId, options) {
|
|
908
|
+
async getAll(monitorId, options, requestOptions) {
|
|
909
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
377
910
|
const entities = [];
|
|
378
|
-
for await (const entityView of
|
|
911
|
+
for await (const entityView of scoped.listAll(monitorId, options)) {
|
|
379
912
|
entities.push(entityView);
|
|
380
913
|
}
|
|
381
914
|
return entities;
|
|
@@ -385,10 +918,11 @@ var AgentMonitorChangesClient = class extends AgentMonitorsBaseClient {
|
|
|
385
918
|
/**
|
|
386
919
|
* Page an Agent Monitor's content change feed since a cursor or timestamp.
|
|
387
920
|
*/
|
|
388
|
-
async list(monitorId, options) {
|
|
921
|
+
async list(monitorId, options, requestOptions) {
|
|
922
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
389
923
|
const { betas, ...pagination } = options;
|
|
390
924
|
const params = this.buildPaginationParams(pagination);
|
|
391
|
-
return
|
|
925
|
+
return scoped.request(
|
|
392
926
|
`/${monitorId}/changes`,
|
|
393
927
|
betas,
|
|
394
928
|
"GET",
|
|
@@ -400,13 +934,14 @@ var AgentMonitorChangesClient = class extends AgentMonitorsBaseClient {
|
|
|
400
934
|
* Iterate through a monitor's change feed, handling pagination
|
|
401
935
|
* automatically.
|
|
402
936
|
*/
|
|
403
|
-
async *listAll(monitorId, options) {
|
|
937
|
+
async *listAll(monitorId, options, requestOptions) {
|
|
938
|
+
let scoped = this.withRequestOptions(requestOptions);
|
|
404
939
|
let cursor = options.cursor;
|
|
405
940
|
const { betas, ...pagination } = options;
|
|
406
941
|
const pageOptions = { ...pagination };
|
|
407
942
|
while (true) {
|
|
408
943
|
pageOptions.cursor = cursor;
|
|
409
|
-
const response = await
|
|
944
|
+
const response = await scoped.list(monitorId, { ...pageOptions, betas });
|
|
410
945
|
for (const change of response.data) {
|
|
411
946
|
yield change;
|
|
412
947
|
}
|
|
@@ -414,14 +949,16 @@ var AgentMonitorChangesClient = class extends AgentMonitorsBaseClient {
|
|
|
414
949
|
break;
|
|
415
950
|
}
|
|
416
951
|
cursor = response.nextCursor;
|
|
952
|
+
scoped = scoped.forNextPage();
|
|
417
953
|
}
|
|
418
954
|
}
|
|
419
955
|
/**
|
|
420
956
|
* Collect a monitor's change feed into an array.
|
|
421
957
|
*/
|
|
422
|
-
async getAll(monitorId, options) {
|
|
958
|
+
async getAll(monitorId, options, requestOptions) {
|
|
959
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
423
960
|
const changes = [];
|
|
424
|
-
for await (const change of
|
|
961
|
+
for await (const change of scoped.listAll(monitorId, options)) {
|
|
425
962
|
changes.push(change);
|
|
426
963
|
}
|
|
427
964
|
return changes;
|
|
@@ -430,12 +967,13 @@ var AgentMonitorChangesClient = class extends AgentMonitorsBaseClient {
|
|
|
430
967
|
var AgentMonitorBacktestsClient = class extends AgentMonitorsBaseClient {
|
|
431
968
|
/**
|
|
432
969
|
* Start an async backtest of entities × fields over an explicit past news
|
|
433
|
-
* window. Returns a `running` job
|
|
434
|
-
* for the result.
|
|
970
|
+
* window. Returns a `running` job. Poll it with `get`, or use
|
|
971
|
+
* `createAndWait`, for the result.
|
|
435
972
|
*/
|
|
436
|
-
async create(params) {
|
|
973
|
+
async create(params, requestOptions) {
|
|
974
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
437
975
|
const { betas, ...payload } = params;
|
|
438
|
-
return
|
|
976
|
+
return scoped.request(
|
|
439
977
|
"/backtest",
|
|
440
978
|
betas,
|
|
441
979
|
"POST",
|
|
@@ -446,8 +984,9 @@ var AgentMonitorBacktestsClient = class extends AgentMonitorsBaseClient {
|
|
|
446
984
|
* Poll a backtest job for its status and, once completed, its result.
|
|
447
985
|
* Jobs expire and read as 404 after `expiresAt`.
|
|
448
986
|
*/
|
|
449
|
-
async get(backtestId, options) {
|
|
450
|
-
|
|
987
|
+
async get(backtestId, options, requestOptions) {
|
|
988
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
989
|
+
return scoped.request(
|
|
451
990
|
`/backtest/${backtestId}`,
|
|
452
991
|
options.betas,
|
|
453
992
|
"GET"
|
|
@@ -456,12 +995,13 @@ var AgentMonitorBacktestsClient = class extends AgentMonitorsBaseClient {
|
|
|
456
995
|
/**
|
|
457
996
|
* Poll a backtest job until it reaches a terminal status.
|
|
458
997
|
*/
|
|
459
|
-
async pollUntilFinished(backtestId, options) {
|
|
998
|
+
async pollUntilFinished(backtestId, options, requestOptions) {
|
|
999
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
460
1000
|
const pollInterval = options.pollInterval ?? DEFAULT_BACKTEST_POLL_INTERVAL_MS;
|
|
461
1001
|
const timeoutMs = options.timeoutMs ?? DEFAULT_BACKTEST_POLL_TIMEOUT_MS;
|
|
462
1002
|
const startTime = Date.now();
|
|
463
1003
|
while (true) {
|
|
464
|
-
const backtest = await
|
|
1004
|
+
const backtest = await scoped.get(backtestId, { betas: options.betas });
|
|
465
1005
|
if (backtest.status !== "running") {
|
|
466
1006
|
return backtest;
|
|
467
1007
|
}
|
|
@@ -470,16 +1010,17 @@ var AgentMonitorBacktestsClient = class extends AgentMonitorsBaseClient {
|
|
|
470
1010
|
`Polling timeout: Agent monitor backtest ${backtestId} did not complete within ${timeoutMs}ms`
|
|
471
1011
|
);
|
|
472
1012
|
}
|
|
473
|
-
await
|
|
1013
|
+
await sleep(pollInterval, scoped.requestOptions?.signal);
|
|
474
1014
|
}
|
|
475
1015
|
}
|
|
476
1016
|
/**
|
|
477
1017
|
* Start a backtest and wait for its result. Throws
|
|
478
1018
|
* AgentMonitorBacktestFailedError if the backtest fails.
|
|
479
1019
|
*/
|
|
480
|
-
async createAndWait(params, options) {
|
|
481
|
-
const
|
|
482
|
-
const
|
|
1020
|
+
async createAndWait(params, options, requestOptions) {
|
|
1021
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1022
|
+
const backtest = await scoped.create(params);
|
|
1023
|
+
const terminalBacktest = backtest.status === "running" ? await scoped.pollUntilFinished(backtest.id, {
|
|
483
1024
|
...options,
|
|
484
1025
|
betas: params.betas
|
|
485
1026
|
}) : backtest;
|
|
@@ -501,10 +1042,11 @@ var AgentMonitorsClient = class extends AgentMonitorsBaseClient {
|
|
|
501
1042
|
* Creation is async: the monitor is returned with status `creating` and
|
|
502
1043
|
* becomes `active` once its first refresh completes.
|
|
503
1044
|
*/
|
|
504
|
-
async create(params, options) {
|
|
1045
|
+
async create(params, options, requestOptions) {
|
|
1046
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
505
1047
|
const { betas, ...payload } = params;
|
|
506
1048
|
const headers = options?.idempotencyKey ? { "Idempotency-Key": options.idempotencyKey } : void 0;
|
|
507
|
-
return
|
|
1049
|
+
return scoped.request(
|
|
508
1050
|
"",
|
|
509
1051
|
betas,
|
|
510
1052
|
"POST",
|
|
@@ -516,16 +1058,18 @@ var AgentMonitorsClient = class extends AgentMonitorsBaseClient {
|
|
|
516
1058
|
/**
|
|
517
1059
|
* Get an Agent Monitor by ID, including refresh progress.
|
|
518
1060
|
*/
|
|
519
|
-
async get(monitorId, options) {
|
|
520
|
-
|
|
1061
|
+
async get(monitorId, options, requestOptions) {
|
|
1062
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1063
|
+
return scoped.request(`/${monitorId}`, options.betas, "GET");
|
|
521
1064
|
}
|
|
522
1065
|
/**
|
|
523
1066
|
* List the team's Agent Monitors.
|
|
524
1067
|
*/
|
|
525
|
-
async list(options) {
|
|
1068
|
+
async list(options, requestOptions) {
|
|
1069
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
526
1070
|
const { betas, ...pagination } = options;
|
|
527
1071
|
const params = this.buildPaginationParams(pagination);
|
|
528
|
-
return
|
|
1072
|
+
return scoped.request(
|
|
529
1073
|
"",
|
|
530
1074
|
betas,
|
|
531
1075
|
"GET",
|
|
@@ -536,13 +1080,14 @@ var AgentMonitorsClient = class extends AgentMonitorsBaseClient {
|
|
|
536
1080
|
/**
|
|
537
1081
|
* Iterate through all Agent Monitors, handling pagination automatically.
|
|
538
1082
|
*/
|
|
539
|
-
async *listAll(options) {
|
|
1083
|
+
async *listAll(options, requestOptions) {
|
|
1084
|
+
let scoped = this.withRequestOptions(requestOptions);
|
|
540
1085
|
let cursor = options.cursor;
|
|
541
1086
|
const { betas, ...pagination } = options;
|
|
542
1087
|
const pageOptions = { ...pagination };
|
|
543
1088
|
while (true) {
|
|
544
1089
|
pageOptions.cursor = cursor;
|
|
545
|
-
const response = await
|
|
1090
|
+
const response = await scoped.list({ ...pageOptions, betas });
|
|
546
1091
|
for (const monitor of response.data) {
|
|
547
1092
|
yield monitor;
|
|
548
1093
|
}
|
|
@@ -550,14 +1095,16 @@ var AgentMonitorsClient = class extends AgentMonitorsBaseClient {
|
|
|
550
1095
|
break;
|
|
551
1096
|
}
|
|
552
1097
|
cursor = response.nextCursor;
|
|
1098
|
+
scoped = scoped.forNextPage();
|
|
553
1099
|
}
|
|
554
1100
|
}
|
|
555
1101
|
/**
|
|
556
1102
|
* Collect all Agent Monitors into an array.
|
|
557
1103
|
*/
|
|
558
|
-
async getAll(options) {
|
|
1104
|
+
async getAll(options, requestOptions) {
|
|
1105
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
559
1106
|
const monitors = [];
|
|
560
|
-
for await (const monitor of
|
|
1107
|
+
for await (const monitor of scoped.listAll(options)) {
|
|
561
1108
|
monitors.push(monitor);
|
|
562
1109
|
}
|
|
563
1110
|
return monitors;
|
|
@@ -565,8 +1112,9 @@ var AgentMonitorsClient = class extends AgentMonitorsBaseClient {
|
|
|
565
1112
|
/**
|
|
566
1113
|
* Delete an Agent Monitor and stop its refreshes.
|
|
567
1114
|
*/
|
|
568
|
-
async delete(monitorId, options) {
|
|
569
|
-
|
|
1115
|
+
async delete(monitorId, options, requestOptions) {
|
|
1116
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1117
|
+
return scoped.request(
|
|
570
1118
|
`/${monitorId}`,
|
|
571
1119
|
options.betas,
|
|
572
1120
|
"DELETE"
|
|
@@ -688,9 +1236,10 @@ var AgentRunEventsClient = class extends AgentBaseClient {
|
|
|
688
1236
|
/**
|
|
689
1237
|
* List stored events for an Agent run.
|
|
690
1238
|
*/
|
|
691
|
-
async list(runId, options) {
|
|
1239
|
+
async list(runId, options, requestOptions) {
|
|
1240
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
692
1241
|
const params = this.buildPaginationParams(options);
|
|
693
|
-
return
|
|
1242
|
+
return scoped.request(
|
|
694
1243
|
`/${runId}/events`,
|
|
695
1244
|
"GET",
|
|
696
1245
|
void 0,
|
|
@@ -703,47 +1252,45 @@ var AgentRunsClient = class extends AgentBaseClient {
|
|
|
703
1252
|
super(client);
|
|
704
1253
|
this.events = new AgentRunEventsClient(client);
|
|
705
1254
|
}
|
|
706
|
-
async create(params) {
|
|
1255
|
+
async create(params, requestOptions) {
|
|
1256
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
707
1257
|
const { stream, payload } = buildAgentRunPayload(params);
|
|
708
1258
|
if (stream) {
|
|
709
|
-
const response = await
|
|
1259
|
+
const response = await scoped.rawRequest("", "POST", payload, void 0, {
|
|
710
1260
|
Accept: "text/event-stream"
|
|
711
1261
|
});
|
|
712
1262
|
if (!response.ok) {
|
|
713
|
-
|
|
714
|
-
throw new ExaError(
|
|
715
|
-
message || `Request failed with status code ${response.status}`,
|
|
716
|
-
response.status,
|
|
717
|
-
(/* @__PURE__ */ new Date()).toISOString(),
|
|
718
|
-
"/agent/runs"
|
|
719
|
-
);
|
|
1263
|
+
throw await exaErrorFromResponse(response, "/agent/runs");
|
|
720
1264
|
}
|
|
721
1265
|
return streamAgentEvents(response);
|
|
722
1266
|
}
|
|
723
|
-
return
|
|
1267
|
+
return scoped.request("", "POST", payload);
|
|
724
1268
|
}
|
|
725
1269
|
/**
|
|
726
1270
|
* Get an Agent run by ID.
|
|
727
1271
|
*/
|
|
728
|
-
async get(runId) {
|
|
729
|
-
|
|
1272
|
+
async get(runId, requestOptions) {
|
|
1273
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1274
|
+
return scoped.request(`/${runId}`, "GET");
|
|
730
1275
|
}
|
|
731
1276
|
/**
|
|
732
1277
|
* List Agent runs.
|
|
733
1278
|
*/
|
|
734
|
-
async list(options) {
|
|
1279
|
+
async list(options, requestOptions) {
|
|
1280
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
735
1281
|
const params = this.buildPaginationParams(options);
|
|
736
|
-
return
|
|
1282
|
+
return scoped.request("", "GET", void 0, params);
|
|
737
1283
|
}
|
|
738
1284
|
/**
|
|
739
1285
|
* Iterate through all Agent runs, handling pagination automatically.
|
|
740
1286
|
*/
|
|
741
|
-
async *listAll(options) {
|
|
1287
|
+
async *listAll(options, requestOptions) {
|
|
1288
|
+
let scoped = this.withRequestOptions(requestOptions);
|
|
742
1289
|
let cursor = void 0;
|
|
743
1290
|
const pageOptions = options ? { ...options } : {};
|
|
744
1291
|
while (true) {
|
|
745
1292
|
pageOptions.cursor = cursor;
|
|
746
|
-
const response = await
|
|
1293
|
+
const response = await scoped.list(pageOptions);
|
|
747
1294
|
for (const run of response.data) {
|
|
748
1295
|
yield run;
|
|
749
1296
|
}
|
|
@@ -751,14 +1298,16 @@ var AgentRunsClient = class extends AgentBaseClient {
|
|
|
751
1298
|
break;
|
|
752
1299
|
}
|
|
753
1300
|
cursor = response.nextCursor;
|
|
1301
|
+
scoped = scoped.forNextPage();
|
|
754
1302
|
}
|
|
755
1303
|
}
|
|
756
1304
|
/**
|
|
757
1305
|
* Collect all Agent runs into an array.
|
|
758
1306
|
*/
|
|
759
|
-
async getAll(options) {
|
|
1307
|
+
async getAll(options, requestOptions) {
|
|
1308
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
760
1309
|
const runs = [];
|
|
761
|
-
for await (const run of
|
|
1310
|
+
for await (const run of scoped.listAll(options)) {
|
|
762
1311
|
runs.push(run);
|
|
763
1312
|
}
|
|
764
1313
|
return runs;
|
|
@@ -766,31 +1315,35 @@ var AgentRunsClient = class extends AgentBaseClient {
|
|
|
766
1315
|
/**
|
|
767
1316
|
* Cancel a queued or running Agent run.
|
|
768
1317
|
*/
|
|
769
|
-
async cancel(runId) {
|
|
770
|
-
|
|
1318
|
+
async cancel(runId, requestOptions) {
|
|
1319
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1320
|
+
return scoped.request(`/${runId}/cancel`, "POST");
|
|
771
1321
|
}
|
|
772
1322
|
/**
|
|
773
1323
|
* Stop a running Agent run, completing it early with the results
|
|
774
1324
|
* gathered so far. Only supported for `ultra` effort runs.
|
|
775
1325
|
*/
|
|
776
|
-
async stop(runId) {
|
|
777
|
-
|
|
1326
|
+
async stop(runId, requestOptions) {
|
|
1327
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1328
|
+
return scoped.request(`/${runId}/stop`, "POST");
|
|
778
1329
|
}
|
|
779
1330
|
/**
|
|
780
1331
|
* Delete a stored Agent run.
|
|
781
1332
|
*/
|
|
782
|
-
async delete(runId) {
|
|
783
|
-
|
|
1333
|
+
async delete(runId, requestOptions) {
|
|
1334
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1335
|
+
return scoped.request(`/${runId}`, "DELETE");
|
|
784
1336
|
}
|
|
785
1337
|
/**
|
|
786
1338
|
* Poll an Agent run until it reaches a terminal status.
|
|
787
1339
|
*/
|
|
788
|
-
async pollUntilFinished(runId, options) {
|
|
1340
|
+
async pollUntilFinished(runId, options, requestOptions) {
|
|
1341
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
789
1342
|
const pollInterval = options?.pollInterval ?? DEFAULT_AGENT_POLL_INTERVAL_MS;
|
|
790
1343
|
const timeoutMs = options?.timeoutMs ?? DEFAULT_AGENT_POLL_TIMEOUT_MS;
|
|
791
1344
|
const startTime = Date.now();
|
|
792
1345
|
while (true) {
|
|
793
|
-
const run = await
|
|
1346
|
+
const run = await scoped.get(runId);
|
|
794
1347
|
if (isTerminalAgentRunStatus(run.status)) {
|
|
795
1348
|
return run;
|
|
796
1349
|
}
|
|
@@ -799,16 +1352,17 @@ var AgentRunsClient = class extends AgentBaseClient {
|
|
|
799
1352
|
`Polling timeout: Agent run ${runId} did not complete within ${timeoutMs}ms`
|
|
800
1353
|
);
|
|
801
1354
|
}
|
|
802
|
-
await
|
|
1355
|
+
await sleep(pollInterval, scoped.requestOptions?.signal);
|
|
803
1356
|
}
|
|
804
1357
|
}
|
|
805
|
-
async createAndWait(params, options) {
|
|
1358
|
+
async createAndWait(params, options, requestOptions) {
|
|
1359
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
806
1360
|
const { stream: _stream, ...createParams } = params;
|
|
807
|
-
const run = await
|
|
1361
|
+
const run = await scoped.create(
|
|
808
1362
|
createParams
|
|
809
1363
|
);
|
|
810
1364
|
const runId = run.id;
|
|
811
|
-
const terminalRun = await
|
|
1365
|
+
const terminalRun = await scoped.pollUntilFinished(
|
|
812
1366
|
runId,
|
|
813
1367
|
createAndWaitPollOptions(options)
|
|
814
1368
|
);
|
|
@@ -827,10 +1381,11 @@ var AgentBetaRunEventsClient = class extends AgentRunEventsClient {
|
|
|
827
1381
|
*
|
|
828
1382
|
* @deprecated Use exa.agent.runs.events instead.
|
|
829
1383
|
*/
|
|
830
|
-
async list(runId, options) {
|
|
1384
|
+
async list(runId, options, requestOptions) {
|
|
1385
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
831
1386
|
const { betas, ...pagination } = options ?? {};
|
|
832
1387
|
const params = this.buildPaginationParams(pagination);
|
|
833
|
-
return
|
|
1388
|
+
return scoped.request(
|
|
834
1389
|
`/${runId}/events`,
|
|
835
1390
|
"GET",
|
|
836
1391
|
void 0,
|
|
@@ -844,29 +1399,24 @@ var AgentBetaRunsClient = class extends AgentRunsClient {
|
|
|
844
1399
|
super(client);
|
|
845
1400
|
this.events = new AgentBetaRunEventsClient(client);
|
|
846
1401
|
}
|
|
847
|
-
async create(params) {
|
|
1402
|
+
async create(params, requestOptions) {
|
|
1403
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
848
1404
|
const { betas, ...createParams } = params;
|
|
849
1405
|
const { stream, payload } = buildAgentRunPayload(
|
|
850
1406
|
createParams
|
|
851
1407
|
);
|
|
852
1408
|
const headers = headersForBetas(betas);
|
|
853
1409
|
if (stream) {
|
|
854
|
-
const response = await
|
|
1410
|
+
const response = await scoped.rawRequest("", "POST", payload, void 0, {
|
|
855
1411
|
...headers,
|
|
856
1412
|
Accept: "text/event-stream"
|
|
857
1413
|
});
|
|
858
1414
|
if (!response.ok) {
|
|
859
|
-
|
|
860
|
-
throw new ExaError(
|
|
861
|
-
message || `Request failed with status code ${response.status}`,
|
|
862
|
-
response.status,
|
|
863
|
-
(/* @__PURE__ */ new Date()).toISOString(),
|
|
864
|
-
"/agent/runs"
|
|
865
|
-
);
|
|
1415
|
+
throw await exaErrorFromResponse(response, "/agent/runs");
|
|
866
1416
|
}
|
|
867
1417
|
return streamAgentEvents(response);
|
|
868
1418
|
}
|
|
869
|
-
return
|
|
1419
|
+
return scoped.request(
|
|
870
1420
|
"",
|
|
871
1421
|
"POST",
|
|
872
1422
|
payload,
|
|
@@ -875,7 +1425,8 @@ var AgentBetaRunsClient = class extends AgentRunsClient {
|
|
|
875
1425
|
);
|
|
876
1426
|
}
|
|
877
1427
|
async get(runId, options) {
|
|
878
|
-
|
|
1428
|
+
const scoped = this.withRequestOptions(options);
|
|
1429
|
+
return scoped.request(
|
|
879
1430
|
`/${runId}`,
|
|
880
1431
|
"GET",
|
|
881
1432
|
void 0,
|
|
@@ -883,10 +1434,11 @@ var AgentBetaRunsClient = class extends AgentRunsClient {
|
|
|
883
1434
|
headersForBetas(options?.betas)
|
|
884
1435
|
);
|
|
885
1436
|
}
|
|
886
|
-
async list(options) {
|
|
1437
|
+
async list(options, requestOptions) {
|
|
1438
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
887
1439
|
const { betas, ...pagination } = options ?? {};
|
|
888
1440
|
const params = this.buildPaginationParams(pagination);
|
|
889
|
-
return
|
|
1441
|
+
return scoped.request(
|
|
890
1442
|
"",
|
|
891
1443
|
"GET",
|
|
892
1444
|
void 0,
|
|
@@ -894,13 +1446,14 @@ var AgentBetaRunsClient = class extends AgentRunsClient {
|
|
|
894
1446
|
headersForBetas(betas)
|
|
895
1447
|
);
|
|
896
1448
|
}
|
|
897
|
-
async *listAll(options) {
|
|
1449
|
+
async *listAll(options, requestOptions) {
|
|
1450
|
+
let scoped = this.withRequestOptions(requestOptions);
|
|
898
1451
|
let cursor = void 0;
|
|
899
1452
|
const { betas, ...pagination } = options ?? {};
|
|
900
1453
|
const pageOptions = { ...pagination };
|
|
901
1454
|
while (true) {
|
|
902
1455
|
pageOptions.cursor = cursor;
|
|
903
|
-
const response = await
|
|
1456
|
+
const response = await scoped.list({ ...pageOptions, betas });
|
|
904
1457
|
for (const run of response.data) {
|
|
905
1458
|
yield run;
|
|
906
1459
|
}
|
|
@@ -908,17 +1461,20 @@ var AgentBetaRunsClient = class extends AgentRunsClient {
|
|
|
908
1461
|
break;
|
|
909
1462
|
}
|
|
910
1463
|
cursor = response.nextCursor;
|
|
1464
|
+
scoped = scoped.forNextPage();
|
|
911
1465
|
}
|
|
912
1466
|
}
|
|
913
|
-
async getAll(options) {
|
|
1467
|
+
async getAll(options, requestOptions) {
|
|
1468
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
914
1469
|
const runs = [];
|
|
915
|
-
for await (const run of
|
|
1470
|
+
for await (const run of scoped.listAll(options)) {
|
|
916
1471
|
runs.push(run);
|
|
917
1472
|
}
|
|
918
1473
|
return runs;
|
|
919
1474
|
}
|
|
920
1475
|
async cancel(runId, options) {
|
|
921
|
-
|
|
1476
|
+
const scoped = this.withRequestOptions(options);
|
|
1477
|
+
return scoped.request(
|
|
922
1478
|
`/${runId}/cancel`,
|
|
923
1479
|
"POST",
|
|
924
1480
|
void 0,
|
|
@@ -931,7 +1487,8 @@ var AgentBetaRunsClient = class extends AgentRunsClient {
|
|
|
931
1487
|
* gathered so far. Only supported for `ultra` effort runs.
|
|
932
1488
|
*/
|
|
933
1489
|
async stop(runId, options) {
|
|
934
|
-
|
|
1490
|
+
const scoped = this.withRequestOptions(options);
|
|
1491
|
+
return scoped.request(
|
|
935
1492
|
`/${runId}/stop`,
|
|
936
1493
|
"POST",
|
|
937
1494
|
void 0,
|
|
@@ -940,7 +1497,8 @@ var AgentBetaRunsClient = class extends AgentRunsClient {
|
|
|
940
1497
|
);
|
|
941
1498
|
}
|
|
942
1499
|
async delete(runId, options) {
|
|
943
|
-
|
|
1500
|
+
const scoped = this.withRequestOptions(options);
|
|
1501
|
+
return scoped.request(
|
|
944
1502
|
`/${runId}`,
|
|
945
1503
|
"DELETE",
|
|
946
1504
|
void 0,
|
|
@@ -948,13 +1506,14 @@ var AgentBetaRunsClient = class extends AgentRunsClient {
|
|
|
948
1506
|
headersForBetas(options?.betas)
|
|
949
1507
|
);
|
|
950
1508
|
}
|
|
951
|
-
async pollUntilFinished(runId, options) {
|
|
1509
|
+
async pollUntilFinished(runId, options, requestOptions) {
|
|
1510
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
952
1511
|
const pollInterval = options?.pollInterval ?? DEFAULT_AGENT_POLL_INTERVAL_MS;
|
|
953
1512
|
const timeoutMs = options?.timeoutMs ?? DEFAULT_AGENT_POLL_TIMEOUT_MS;
|
|
954
1513
|
const startTime = Date.now();
|
|
955
1514
|
const headers = headersForBetas(options?.betas);
|
|
956
1515
|
while (true) {
|
|
957
|
-
const run = await
|
|
1516
|
+
const run = await scoped.request(
|
|
958
1517
|
`/${runId}`,
|
|
959
1518
|
"GET",
|
|
960
1519
|
void 0,
|
|
@@ -969,21 +1528,22 @@ var AgentBetaRunsClient = class extends AgentRunsClient {
|
|
|
969
1528
|
`Polling timeout: Agent run ${runId} did not complete within ${timeoutMs}ms`
|
|
970
1529
|
);
|
|
971
1530
|
}
|
|
972
|
-
await
|
|
1531
|
+
await sleep(pollInterval, scoped.requestOptions?.signal);
|
|
973
1532
|
}
|
|
974
1533
|
}
|
|
975
|
-
async createAndWait(params, options) {
|
|
1534
|
+
async createAndWait(params, options, requestOptions) {
|
|
1535
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
976
1536
|
const {
|
|
977
1537
|
betas,
|
|
978
1538
|
stream: _stream,
|
|
979
1539
|
...createParams
|
|
980
1540
|
} = params;
|
|
981
|
-
const run = await
|
|
1541
|
+
const run = await scoped.create({
|
|
982
1542
|
...createParams,
|
|
983
1543
|
betas
|
|
984
1544
|
});
|
|
985
1545
|
const runId = run.id;
|
|
986
|
-
const terminalRun = await
|
|
1546
|
+
const terminalRun = await scoped.pollUntilFinished(runId, {
|
|
987
1547
|
...createAndWaitPollOptions(options),
|
|
988
1548
|
betas
|
|
989
1549
|
});
|
|
@@ -1005,17 +1565,23 @@ var BetaClient = class {
|
|
|
1005
1565
|
};
|
|
1006
1566
|
|
|
1007
1567
|
// src/monitors/base.ts
|
|
1008
|
-
var SearchMonitorsBaseClient = class {
|
|
1568
|
+
var SearchMonitorsBaseClient = class extends RequestScopedClient {
|
|
1009
1569
|
constructor(client) {
|
|
1570
|
+
super();
|
|
1010
1571
|
this.client = client;
|
|
1011
1572
|
}
|
|
1012
1573
|
async request(endpoint, method = "POST", data, params) {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1574
|
+
if (this.requestOptions) {
|
|
1575
|
+
return this.client.request(
|
|
1576
|
+
`/monitors${endpoint}`,
|
|
1577
|
+
method,
|
|
1578
|
+
data,
|
|
1579
|
+
params,
|
|
1580
|
+
void 0,
|
|
1581
|
+
this.requestOptions
|
|
1582
|
+
);
|
|
1583
|
+
}
|
|
1584
|
+
return this.client.request(`/monitors${endpoint}`, method, data, params);
|
|
1019
1585
|
}
|
|
1020
1586
|
buildPaginationParams(pagination) {
|
|
1021
1587
|
const params = {};
|
|
@@ -1034,11 +1600,13 @@ var SearchMonitorRunsClient = class extends SearchMonitorsBaseClient {
|
|
|
1034
1600
|
* List all runs for a Search Monitor
|
|
1035
1601
|
* @param monitorId The ID of the Search Monitor
|
|
1036
1602
|
* @param options Pagination options
|
|
1603
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1037
1604
|
* @returns The list of Search Monitor runs
|
|
1038
1605
|
*/
|
|
1039
|
-
async list(monitorId, options) {
|
|
1606
|
+
async list(monitorId, options, requestOptions) {
|
|
1607
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1040
1608
|
const params = this.buildPaginationParams(options);
|
|
1041
|
-
return
|
|
1609
|
+
return scoped.request(
|
|
1042
1610
|
`/${monitorId}/runs`,
|
|
1043
1611
|
"GET",
|
|
1044
1612
|
void 0,
|
|
@@ -1049,10 +1617,12 @@ var SearchMonitorRunsClient = class extends SearchMonitorsBaseClient {
|
|
|
1049
1617
|
* Get a specific Search Monitor run
|
|
1050
1618
|
* @param monitorId The ID of the Search Monitor
|
|
1051
1619
|
* @param runId The ID of the run
|
|
1620
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1052
1621
|
* @returns The Search Monitor run
|
|
1053
1622
|
*/
|
|
1054
|
-
async get(monitorId, runId) {
|
|
1055
|
-
|
|
1623
|
+
async get(monitorId, runId, requestOptions) {
|
|
1624
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1625
|
+
return scoped.request(
|
|
1056
1626
|
`/${monitorId}/runs/${runId}`,
|
|
1057
1627
|
"GET"
|
|
1058
1628
|
);
|
|
@@ -1061,14 +1631,16 @@ var SearchMonitorRunsClient = class extends SearchMonitorsBaseClient {
|
|
|
1061
1631
|
* Iterate through all runs for a Search Monitor, handling pagination automatically
|
|
1062
1632
|
* @param monitorId The ID of the Search Monitor
|
|
1063
1633
|
* @param options Pagination options
|
|
1634
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1064
1635
|
* @returns Async generator of Search Monitor runs
|
|
1065
1636
|
*/
|
|
1066
|
-
async *listAll(monitorId, options) {
|
|
1637
|
+
async *listAll(monitorId, options, requestOptions) {
|
|
1638
|
+
let scoped = this.withRequestOptions(requestOptions);
|
|
1067
1639
|
let cursor = void 0;
|
|
1068
1640
|
const pageOptions = options ? { ...options } : {};
|
|
1069
1641
|
while (true) {
|
|
1070
1642
|
pageOptions.cursor = cursor;
|
|
1071
|
-
const response = await
|
|
1643
|
+
const response = await scoped.list(monitorId, pageOptions);
|
|
1072
1644
|
for (const run of response.data) {
|
|
1073
1645
|
yield run;
|
|
1074
1646
|
}
|
|
@@ -1076,17 +1648,20 @@ var SearchMonitorRunsClient = class extends SearchMonitorsBaseClient {
|
|
|
1076
1648
|
break;
|
|
1077
1649
|
}
|
|
1078
1650
|
cursor = response.nextCursor;
|
|
1651
|
+
scoped = scoped.forNextPage();
|
|
1079
1652
|
}
|
|
1080
1653
|
}
|
|
1081
1654
|
/**
|
|
1082
1655
|
* Collect all runs for a Search Monitor into an array
|
|
1083
1656
|
* @param monitorId The ID of the Search Monitor
|
|
1084
1657
|
* @param options Pagination options
|
|
1658
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1085
1659
|
* @returns Promise resolving to an array of all Search Monitor runs
|
|
1086
1660
|
*/
|
|
1087
|
-
async getAll(monitorId, options) {
|
|
1661
|
+
async getAll(monitorId, options, requestOptions) {
|
|
1662
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1088
1663
|
const runs = [];
|
|
1089
|
-
for await (const run of
|
|
1664
|
+
for await (const run of scoped.listAll(monitorId, options)) {
|
|
1090
1665
|
runs.push(run);
|
|
1091
1666
|
}
|
|
1092
1667
|
return runs;
|
|
@@ -1100,27 +1675,33 @@ var SearchMonitorsClient = class extends SearchMonitorsBaseClient {
|
|
|
1100
1675
|
/**
|
|
1101
1676
|
* Create a Search Monitor
|
|
1102
1677
|
* @param params The monitor creation parameters
|
|
1678
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1103
1679
|
* @returns The created Search Monitor with webhookSecret
|
|
1104
1680
|
*/
|
|
1105
|
-
async create(params) {
|
|
1106
|
-
|
|
1681
|
+
async create(params, requestOptions) {
|
|
1682
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1683
|
+
return scoped.request("", "POST", params);
|
|
1107
1684
|
}
|
|
1108
1685
|
/**
|
|
1109
1686
|
* Get a Search Monitor by ID
|
|
1110
1687
|
* @param id The ID of the Search Monitor
|
|
1688
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1111
1689
|
* @returns The Search Monitor
|
|
1112
1690
|
*/
|
|
1113
|
-
async get(id) {
|
|
1114
|
-
|
|
1691
|
+
async get(id, requestOptions) {
|
|
1692
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1693
|
+
return scoped.request(`/${id}`, "GET");
|
|
1115
1694
|
}
|
|
1116
1695
|
/**
|
|
1117
1696
|
* List Search Monitors
|
|
1118
1697
|
* @param options Pagination and filtering options
|
|
1698
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1119
1699
|
* @returns The list of Search Monitors
|
|
1120
1700
|
*/
|
|
1121
|
-
async list(options) {
|
|
1701
|
+
async list(options, requestOptions) {
|
|
1702
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1122
1703
|
const params = this.buildPaginationParams(options);
|
|
1123
|
-
return
|
|
1704
|
+
return scoped.request(
|
|
1124
1705
|
"",
|
|
1125
1706
|
"GET",
|
|
1126
1707
|
void 0,
|
|
@@ -1131,26 +1712,32 @@ var SearchMonitorsClient = class extends SearchMonitorsBaseClient {
|
|
|
1131
1712
|
* Update a Search Monitor
|
|
1132
1713
|
* @param id The ID of the Search Monitor
|
|
1133
1714
|
* @param params The update parameters
|
|
1715
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1134
1716
|
* @returns The updated Search Monitor
|
|
1135
1717
|
*/
|
|
1136
|
-
async update(id, params) {
|
|
1137
|
-
|
|
1718
|
+
async update(id, params, requestOptions) {
|
|
1719
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1720
|
+
return scoped.request(`/${id}`, "PATCH", params);
|
|
1138
1721
|
}
|
|
1139
1722
|
/**
|
|
1140
1723
|
* Delete a Search Monitor
|
|
1141
1724
|
* @param id The ID of the Search Monitor
|
|
1725
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1142
1726
|
* @returns The deleted Search Monitor
|
|
1143
1727
|
*/
|
|
1144
|
-
async delete(id) {
|
|
1145
|
-
|
|
1728
|
+
async delete(id, requestOptions) {
|
|
1729
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1730
|
+
return scoped.request(`/${id}`, "DELETE");
|
|
1146
1731
|
}
|
|
1147
1732
|
/**
|
|
1148
1733
|
* Trigger a Search Monitor run immediately
|
|
1149
1734
|
* @param id The ID of the Search Monitor
|
|
1735
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1150
1736
|
* @returns Whether the monitor was triggered
|
|
1151
1737
|
*/
|
|
1152
|
-
async trigger(id) {
|
|
1153
|
-
|
|
1738
|
+
async trigger(id, requestOptions) {
|
|
1739
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1740
|
+
return scoped.request(
|
|
1154
1741
|
`/${id}/trigger`,
|
|
1155
1742
|
"POST"
|
|
1156
1743
|
);
|
|
@@ -1158,14 +1745,16 @@ var SearchMonitorsClient = class extends SearchMonitorsBaseClient {
|
|
|
1158
1745
|
/**
|
|
1159
1746
|
* Iterate through all Search Monitors, handling pagination automatically
|
|
1160
1747
|
* @param options Pagination and filtering options
|
|
1748
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1161
1749
|
* @returns Async generator of Search Monitors
|
|
1162
1750
|
*/
|
|
1163
|
-
async *listAll(options) {
|
|
1751
|
+
async *listAll(options, requestOptions) {
|
|
1752
|
+
let scoped = this.withRequestOptions(requestOptions);
|
|
1164
1753
|
let cursor = void 0;
|
|
1165
1754
|
const pageOptions = options ? { ...options } : {};
|
|
1166
1755
|
while (true) {
|
|
1167
1756
|
pageOptions.cursor = cursor;
|
|
1168
|
-
const response = await
|
|
1757
|
+
const response = await scoped.list(pageOptions);
|
|
1169
1758
|
for (const monitor of response.data) {
|
|
1170
1759
|
yield monitor;
|
|
1171
1760
|
}
|
|
@@ -1173,16 +1762,19 @@ var SearchMonitorsClient = class extends SearchMonitorsBaseClient {
|
|
|
1173
1762
|
break;
|
|
1174
1763
|
}
|
|
1175
1764
|
cursor = response.nextCursor;
|
|
1765
|
+
scoped = scoped.forNextPage();
|
|
1176
1766
|
}
|
|
1177
1767
|
}
|
|
1178
1768
|
/**
|
|
1179
1769
|
* Collect all Search Monitors into an array
|
|
1180
1770
|
* @param options Pagination and filtering options
|
|
1771
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1181
1772
|
* @returns Promise resolving to an array of all Search Monitors
|
|
1182
1773
|
*/
|
|
1183
|
-
async getAll(options) {
|
|
1774
|
+
async getAll(options, requestOptions) {
|
|
1775
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1184
1776
|
const monitors = [];
|
|
1185
|
-
for await (const monitor of
|
|
1777
|
+
for await (const monitor of scoped.listAll(options)) {
|
|
1186
1778
|
monitors.push(monitor);
|
|
1187
1779
|
}
|
|
1188
1780
|
return monitors;
|
|
@@ -1190,25 +1782,22 @@ var SearchMonitorsClient = class extends SearchMonitorsBaseClient {
|
|
|
1190
1782
|
};
|
|
1191
1783
|
|
|
1192
1784
|
// src/research/base.ts
|
|
1193
|
-
var
|
|
1785
|
+
var RESEARCH_RETIRED_MESSAGE = "The Exa Research API has been retired and no longer accepts requests. Use the Agent API (exa.agent.runs.create) for asynchronous, multi-step research.";
|
|
1786
|
+
function researchRetiredError() {
|
|
1787
|
+
return new ExaError(RESEARCH_RETIRED_MESSAGE, 410);
|
|
1788
|
+
}
|
|
1789
|
+
var ResearchBaseClient = class extends RequestScopedClient {
|
|
1194
1790
|
constructor(client) {
|
|
1791
|
+
super();
|
|
1195
1792
|
this.client = client;
|
|
1196
1793
|
}
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
method,
|
|
1201
|
-
data,
|
|
1202
|
-
params
|
|
1203
|
-
);
|
|
1794
|
+
/** Rejects with `researchRetiredError()`: the Research API has been retired. */
|
|
1795
|
+
async request(_endpoint, _method = "POST", _data, _params) {
|
|
1796
|
+
throw researchRetiredError();
|
|
1204
1797
|
}
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
method,
|
|
1209
|
-
data,
|
|
1210
|
-
params
|
|
1211
|
-
);
|
|
1798
|
+
/** Rejects with `researchRetiredError()`: the Research API has been retired. */
|
|
1799
|
+
async rawRequest(_endpoint, _method = "POST", _data, _params) {
|
|
1800
|
+
throw researchRetiredError();
|
|
1212
1801
|
}
|
|
1213
1802
|
buildPaginationParams(pagination) {
|
|
1214
1803
|
const params = {};
|
|
@@ -1224,7 +1813,8 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
1224
1813
|
constructor(client) {
|
|
1225
1814
|
super(client);
|
|
1226
1815
|
}
|
|
1227
|
-
async create(params) {
|
|
1816
|
+
async create(params, requestOptions) {
|
|
1817
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1228
1818
|
const { instructions, model, outputSchema } = params;
|
|
1229
1819
|
let schema = outputSchema;
|
|
1230
1820
|
if (schema && isZodSchema(schema)) {
|
|
@@ -1237,21 +1827,25 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
1237
1827
|
if (schema) {
|
|
1238
1828
|
payload.outputSchema = schema;
|
|
1239
1829
|
}
|
|
1240
|
-
return
|
|
1830
|
+
return scoped.request("", "POST", payload);
|
|
1241
1831
|
}
|
|
1242
|
-
get(researchId, options) {
|
|
1832
|
+
get(researchId, options, requestOptions) {
|
|
1833
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1243
1834
|
if (options?.stream) {
|
|
1244
1835
|
const promise = async () => {
|
|
1245
1836
|
const params = { stream: "true" };
|
|
1246
1837
|
if (options.events !== void 0) {
|
|
1247
1838
|
params.events = options.events.toString();
|
|
1248
1839
|
}
|
|
1249
|
-
const resp = await
|
|
1840
|
+
const resp = await scoped.rawRequest(
|
|
1250
1841
|
`/${researchId}`,
|
|
1251
1842
|
"GET",
|
|
1252
1843
|
void 0,
|
|
1253
1844
|
params
|
|
1254
1845
|
);
|
|
1846
|
+
if (!resp.ok) {
|
|
1847
|
+
throw await exaErrorFromResponse(resp, `/research/v1/${researchId}`);
|
|
1848
|
+
}
|
|
1255
1849
|
if (!resp.body) {
|
|
1256
1850
|
throw new Error("No response body for SSE stream");
|
|
1257
1851
|
}
|
|
@@ -1271,23 +1865,30 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
1271
1865
|
}
|
|
1272
1866
|
}
|
|
1273
1867
|
async function* streamEvents() {
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
const
|
|
1868
|
+
try {
|
|
1869
|
+
while (true) {
|
|
1870
|
+
const { done, value } = await reader.read();
|
|
1871
|
+
if (done) break;
|
|
1872
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1873
|
+
let parts = buffer.split("\n\n");
|
|
1874
|
+
buffer = parts.pop() ?? "";
|
|
1875
|
+
for (const part of parts) {
|
|
1876
|
+
const processed = processPart(part);
|
|
1877
|
+
if (processed) {
|
|
1878
|
+
yield processed;
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
if (buffer.trim()) {
|
|
1883
|
+
const processed = processPart(buffer.trim());
|
|
1282
1884
|
if (processed) {
|
|
1283
1885
|
yield processed;
|
|
1284
1886
|
}
|
|
1285
1887
|
}
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
yield processed;
|
|
1888
|
+
} finally {
|
|
1889
|
+
try {
|
|
1890
|
+
await reader.cancel();
|
|
1891
|
+
} catch {
|
|
1291
1892
|
}
|
|
1292
1893
|
}
|
|
1293
1894
|
}
|
|
@@ -1299,7 +1900,7 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
1299
1900
|
if (options?.events !== void 0) {
|
|
1300
1901
|
params.events = options.events.toString();
|
|
1301
1902
|
}
|
|
1302
|
-
return
|
|
1903
|
+
return scoped.request(
|
|
1303
1904
|
`/${researchId}`,
|
|
1304
1905
|
"GET",
|
|
1305
1906
|
void 0,
|
|
@@ -1307,50 +1908,24 @@ var ResearchClient = class extends ResearchBaseClient {
|
|
|
1307
1908
|
);
|
|
1308
1909
|
}
|
|
1309
1910
|
}
|
|
1310
|
-
async list(options) {
|
|
1911
|
+
async list(options, requestOptions) {
|
|
1912
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1311
1913
|
const params = this.buildPaginationParams(options);
|
|
1312
|
-
return
|
|
1914
|
+
return scoped.request("", "GET", void 0, params);
|
|
1313
1915
|
}
|
|
1314
|
-
async pollUntilFinished(
|
|
1315
|
-
|
|
1316
|
-
const timeoutMs = options?.timeoutMs ?? 10 * 60 * 1e3;
|
|
1317
|
-
const maxConsecutiveFailures = 5;
|
|
1318
|
-
const startTime = Date.now();
|
|
1319
|
-
let consecutiveFailures = 0;
|
|
1320
|
-
while (true) {
|
|
1321
|
-
try {
|
|
1322
|
-
const research = await this.get(researchId, {
|
|
1323
|
-
events: options?.events
|
|
1324
|
-
});
|
|
1325
|
-
consecutiveFailures = 0;
|
|
1326
|
-
if (research.status === "completed" || research.status === "failed" || research.status === "canceled") {
|
|
1327
|
-
return research;
|
|
1328
|
-
}
|
|
1329
|
-
} catch (err) {
|
|
1330
|
-
consecutiveFailures += 1;
|
|
1331
|
-
if (consecutiveFailures >= maxConsecutiveFailures) {
|
|
1332
|
-
throw new Error(
|
|
1333
|
-
`Polling failed ${maxConsecutiveFailures} times in a row for research ${researchId}: ${err}`
|
|
1334
|
-
);
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
if (Date.now() - startTime > timeoutMs) {
|
|
1338
|
-
throw new Error(
|
|
1339
|
-
`Polling timeout: Research ${researchId} did not complete within ${timeoutMs}ms`
|
|
1340
|
-
);
|
|
1341
|
-
}
|
|
1342
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1343
|
-
}
|
|
1916
|
+
async pollUntilFinished(_researchId, _options, _requestOptions) {
|
|
1917
|
+
throw researchRetiredError();
|
|
1344
1918
|
}
|
|
1345
1919
|
};
|
|
1346
1920
|
|
|
1347
1921
|
// src/websets/base.ts
|
|
1348
|
-
var WebsetsBaseClient = class {
|
|
1922
|
+
var WebsetsBaseClient = class extends RequestScopedClient {
|
|
1349
1923
|
/**
|
|
1350
1924
|
* Initialize a new Websets base client
|
|
1351
1925
|
* @param client The Exa client instance
|
|
1352
1926
|
*/
|
|
1353
1927
|
constructor(client) {
|
|
1928
|
+
super();
|
|
1354
1929
|
this.client = client;
|
|
1355
1930
|
}
|
|
1356
1931
|
/**
|
|
@@ -1363,6 +1938,16 @@ var WebsetsBaseClient = class {
|
|
|
1363
1938
|
* @throws ExaError with API error details if the request fails
|
|
1364
1939
|
*/
|
|
1365
1940
|
async request(endpoint, method = "POST", data, params, headers) {
|
|
1941
|
+
if (this.requestOptions) {
|
|
1942
|
+
return this.client.request(
|
|
1943
|
+
`/websets${endpoint}`,
|
|
1944
|
+
method,
|
|
1945
|
+
data,
|
|
1946
|
+
params,
|
|
1947
|
+
headers,
|
|
1948
|
+
this.requestOptions
|
|
1949
|
+
);
|
|
1950
|
+
}
|
|
1366
1951
|
return this.client.request(
|
|
1367
1952
|
`/websets${endpoint}`,
|
|
1368
1953
|
method,
|
|
@@ -1391,10 +1976,12 @@ var WebsetEnrichmentsClient = class extends WebsetsBaseClient {
|
|
|
1391
1976
|
* Create an Enrichment for a Webset
|
|
1392
1977
|
* @param websetId The ID of the Webset
|
|
1393
1978
|
* @param params The enrichment parameters
|
|
1979
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1394
1980
|
* @returns The created Webset Enrichment
|
|
1395
1981
|
*/
|
|
1396
|
-
async create(websetId, params) {
|
|
1397
|
-
|
|
1982
|
+
async create(websetId, params, requestOptions) {
|
|
1983
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1984
|
+
return scoped.request(
|
|
1398
1985
|
`/v0/websets/${websetId}/enrichments`,
|
|
1399
1986
|
"POST",
|
|
1400
1987
|
params
|
|
@@ -1404,10 +1991,12 @@ var WebsetEnrichmentsClient = class extends WebsetsBaseClient {
|
|
|
1404
1991
|
* Get an Enrichment by ID
|
|
1405
1992
|
* @param websetId The ID of the Webset
|
|
1406
1993
|
* @param id The ID of the Enrichment
|
|
1994
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1407
1995
|
* @returns The Webset Enrichment
|
|
1408
1996
|
*/
|
|
1409
|
-
async get(websetId, id) {
|
|
1410
|
-
|
|
1997
|
+
async get(websetId, id, requestOptions) {
|
|
1998
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1999
|
+
return scoped.request(
|
|
1411
2000
|
`/v0/websets/${websetId}/enrichments/${id}`,
|
|
1412
2001
|
"GET"
|
|
1413
2002
|
);
|
|
@@ -1416,10 +2005,12 @@ var WebsetEnrichmentsClient = class extends WebsetsBaseClient {
|
|
|
1416
2005
|
* Delete an Enrichment
|
|
1417
2006
|
* @param websetId The ID of the Webset
|
|
1418
2007
|
* @param id The ID of the Enrichment
|
|
2008
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1419
2009
|
* @returns The deleted Webset Enrichment
|
|
1420
2010
|
*/
|
|
1421
|
-
async delete(websetId, id) {
|
|
1422
|
-
|
|
2011
|
+
async delete(websetId, id, requestOptions) {
|
|
2012
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2013
|
+
return scoped.request(
|
|
1423
2014
|
`/v0/websets/${websetId}/enrichments/${id}`,
|
|
1424
2015
|
"DELETE"
|
|
1425
2016
|
);
|
|
@@ -1429,10 +2020,12 @@ var WebsetEnrichmentsClient = class extends WebsetsBaseClient {
|
|
|
1429
2020
|
* @param websetId The ID of the Webset
|
|
1430
2021
|
* @param id The ID of the Enrichment
|
|
1431
2022
|
* @param params The enrichment update parameters
|
|
2023
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1432
2024
|
* @returns Promise that resolves when the update is complete
|
|
1433
2025
|
*/
|
|
1434
|
-
async update(websetId, id, params) {
|
|
1435
|
-
|
|
2026
|
+
async update(websetId, id, params, requestOptions) {
|
|
2027
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2028
|
+
return scoped.request(
|
|
1436
2029
|
`/v0/websets/${websetId}/enrichments/${id}`,
|
|
1437
2030
|
"PATCH",
|
|
1438
2031
|
params
|
|
@@ -1442,10 +2035,12 @@ var WebsetEnrichmentsClient = class extends WebsetsBaseClient {
|
|
|
1442
2035
|
* Cancel a running Enrichment
|
|
1443
2036
|
* @param websetId The ID of the Webset
|
|
1444
2037
|
* @param id The ID of the Enrichment
|
|
2038
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1445
2039
|
* @returns The canceled Webset Enrichment
|
|
1446
2040
|
*/
|
|
1447
|
-
async cancel(websetId, id) {
|
|
1448
|
-
|
|
2041
|
+
async cancel(websetId, id, requestOptions) {
|
|
2042
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2043
|
+
return scoped.request(
|
|
1449
2044
|
`/v0/websets/${websetId}/enrichments/${id}/cancel`,
|
|
1450
2045
|
"POST"
|
|
1451
2046
|
);
|
|
@@ -1464,15 +2059,17 @@ var EventsClient = class extends WebsetsBaseClient {
|
|
|
1464
2059
|
/**
|
|
1465
2060
|
* List all Events
|
|
1466
2061
|
* @param options Optional filtering and pagination options
|
|
2062
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1467
2063
|
* @returns The list of Events
|
|
1468
2064
|
*/
|
|
1469
|
-
async list(options) {
|
|
2065
|
+
async list(options, requestOptions) {
|
|
2066
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1470
2067
|
const params = {
|
|
1471
2068
|
cursor: options?.cursor,
|
|
1472
2069
|
limit: options?.limit,
|
|
1473
2070
|
types: options?.types
|
|
1474
2071
|
};
|
|
1475
|
-
return
|
|
2072
|
+
return scoped.request(
|
|
1476
2073
|
"/v0/events",
|
|
1477
2074
|
"GET",
|
|
1478
2075
|
void 0,
|
|
@@ -1482,22 +2079,26 @@ var EventsClient = class extends WebsetsBaseClient {
|
|
|
1482
2079
|
/**
|
|
1483
2080
|
* Get an Event by ID
|
|
1484
2081
|
* @param id The ID of the Event
|
|
2082
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1485
2083
|
* @returns The Event
|
|
1486
2084
|
*/
|
|
1487
|
-
async get(id) {
|
|
1488
|
-
|
|
2085
|
+
async get(id, requestOptions) {
|
|
2086
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2087
|
+
return scoped.request(`/v0/events/${id}`, "GET");
|
|
1489
2088
|
}
|
|
1490
2089
|
/**
|
|
1491
2090
|
* Iterate through all Events, handling pagination automatically
|
|
1492
2091
|
* @param options Filtering and pagination options
|
|
2092
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1493
2093
|
* @returns Async generator of Events
|
|
1494
2094
|
*/
|
|
1495
|
-
async *listAll(options) {
|
|
2095
|
+
async *listAll(options, requestOptions) {
|
|
2096
|
+
let scoped = this.withRequestOptions(requestOptions);
|
|
1496
2097
|
let cursor = void 0;
|
|
1497
2098
|
const pageOptions = options ? { ...options } : {};
|
|
1498
2099
|
while (true) {
|
|
1499
2100
|
pageOptions.cursor = cursor;
|
|
1500
|
-
const response = await
|
|
2101
|
+
const response = await scoped.list(pageOptions);
|
|
1501
2102
|
for (const event of response.data) {
|
|
1502
2103
|
yield event;
|
|
1503
2104
|
}
|
|
@@ -1505,16 +2106,19 @@ var EventsClient = class extends WebsetsBaseClient {
|
|
|
1505
2106
|
break;
|
|
1506
2107
|
}
|
|
1507
2108
|
cursor = response.nextCursor;
|
|
2109
|
+
scoped = scoped.forNextPage();
|
|
1508
2110
|
}
|
|
1509
2111
|
}
|
|
1510
2112
|
/**
|
|
1511
2113
|
* Collect all Events into an array
|
|
1512
2114
|
* @param options Filtering and pagination options
|
|
2115
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1513
2116
|
* @returns Promise resolving to an array of all Events
|
|
1514
2117
|
*/
|
|
1515
|
-
async getAll(options) {
|
|
2118
|
+
async getAll(options, requestOptions) {
|
|
2119
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1516
2120
|
const events = [];
|
|
1517
|
-
for await (const event of
|
|
2121
|
+
for await (const event of scoped.listAll(options)) {
|
|
1518
2122
|
events.push(event);
|
|
1519
2123
|
}
|
|
1520
2124
|
return events;
|
|
@@ -1688,28 +2292,31 @@ var WebsetSearchCanceledReason = /* @__PURE__ */ ((WebsetSearchCanceledReason2)
|
|
|
1688
2292
|
|
|
1689
2293
|
// src/websets/imports.ts
|
|
1690
2294
|
var ImportsClient = class extends WebsetsBaseClient {
|
|
1691
|
-
async create(params, csv) {
|
|
2295
|
+
async create(params, csv, requestOptions) {
|
|
2296
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1692
2297
|
if (csv === void 0) {
|
|
1693
|
-
return
|
|
2298
|
+
return scoped.request(
|
|
1694
2299
|
"/v0/imports",
|
|
1695
2300
|
"POST",
|
|
1696
2301
|
params
|
|
1697
2302
|
);
|
|
1698
2303
|
}
|
|
1699
|
-
let
|
|
2304
|
+
let csvBytes;
|
|
2305
|
+
let csvText;
|
|
1700
2306
|
if (typeof csv === "string") {
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
2307
|
+
csvBytes = new TextEncoder().encode(csv);
|
|
2308
|
+
csvText = csv;
|
|
2309
|
+
} else if (csv instanceof Uint8Array) {
|
|
2310
|
+
csvBytes = csv;
|
|
2311
|
+
csvText = new TextDecoder().decode(csv);
|
|
1704
2312
|
} else {
|
|
1705
2313
|
throw new ExaError(
|
|
1706
|
-
"Invalid CSV data input. Must be string or Buffer",
|
|
2314
|
+
"Invalid CSV data input. Must be a string or a Uint8Array such as a Buffer",
|
|
1707
2315
|
400 /* BadRequest */
|
|
1708
2316
|
);
|
|
1709
2317
|
}
|
|
1710
|
-
const sizeInBytes =
|
|
2318
|
+
const sizeInBytes = csvBytes.byteLength;
|
|
1711
2319
|
const sizeInMB = Math.max(1, Math.ceil(sizeInBytes / (1024 * 1024)));
|
|
1712
|
-
const csvText = csvBuffer.toString("utf8");
|
|
1713
2320
|
const lines = csvText.split("\n").filter((line) => line.trim().length > 0);
|
|
1714
2321
|
const recordCount = Math.max(0, lines.length - 1);
|
|
1715
2322
|
if (sizeInMB > 50) {
|
|
@@ -1733,15 +2340,19 @@ var ImportsClient = class extends WebsetsBaseClient {
|
|
|
1733
2340
|
metadata: params.metadata,
|
|
1734
2341
|
csv: params.csv
|
|
1735
2342
|
};
|
|
1736
|
-
const importResponse = await
|
|
2343
|
+
const importResponse = await scoped.request(
|
|
1737
2344
|
"/v0/imports",
|
|
1738
2345
|
"POST",
|
|
1739
2346
|
createParams
|
|
1740
2347
|
);
|
|
2348
|
+
const upload = resolveRequestSignal(
|
|
2349
|
+
withClientDefaults(this.client, scoped.requestOptions)
|
|
2350
|
+
);
|
|
1741
2351
|
try {
|
|
1742
2352
|
const uploadResponse = await fetch(importResponse.uploadUrl, {
|
|
1743
2353
|
method: "PUT",
|
|
1744
|
-
body:
|
|
2354
|
+
body: csvBytes,
|
|
2355
|
+
signal: upload.signal
|
|
1745
2356
|
});
|
|
1746
2357
|
if (!uploadResponse.ok) {
|
|
1747
2358
|
const errorText = await uploadResponse.text();
|
|
@@ -1751,32 +2362,39 @@ var ImportsClient = class extends WebsetsBaseClient {
|
|
|
1751
2362
|
);
|
|
1752
2363
|
}
|
|
1753
2364
|
} catch (error) {
|
|
1754
|
-
|
|
1755
|
-
|
|
2365
|
+
const requestError = upload.toRequestError(error);
|
|
2366
|
+
if (requestError instanceof ExaError || requestError instanceof ExaAbortError) {
|
|
2367
|
+
throw requestError;
|
|
1756
2368
|
}
|
|
1757
2369
|
throw new ExaError(
|
|
1758
2370
|
`Failed to upload CSV data: ${error.message}`,
|
|
1759
2371
|
400 /* BadRequest */
|
|
1760
2372
|
);
|
|
2373
|
+
} finally {
|
|
2374
|
+
upload.dispose();
|
|
1761
2375
|
}
|
|
1762
2376
|
return importResponse;
|
|
1763
2377
|
}
|
|
1764
2378
|
/**
|
|
1765
2379
|
* Get an Import by ID
|
|
1766
2380
|
* @param id The ID of the Import
|
|
2381
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1767
2382
|
* @returns The Import
|
|
1768
2383
|
*/
|
|
1769
|
-
async get(id) {
|
|
1770
|
-
|
|
2384
|
+
async get(id, requestOptions) {
|
|
2385
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2386
|
+
return scoped.request(`/v0/imports/${id}`, "GET");
|
|
1771
2387
|
}
|
|
1772
2388
|
/**
|
|
1773
2389
|
* List all Imports
|
|
1774
2390
|
* @param options Pagination options
|
|
2391
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1775
2392
|
* @returns The list of Imports
|
|
1776
2393
|
*/
|
|
1777
|
-
async list(options) {
|
|
2394
|
+
async list(options, requestOptions) {
|
|
2395
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1778
2396
|
const params = this.buildPaginationParams(options);
|
|
1779
|
-
return
|
|
2397
|
+
return scoped.request(
|
|
1780
2398
|
"/v0/imports",
|
|
1781
2399
|
"GET",
|
|
1782
2400
|
void 0,
|
|
@@ -1787,33 +2405,39 @@ var ImportsClient = class extends WebsetsBaseClient {
|
|
|
1787
2405
|
* Update an Import
|
|
1788
2406
|
* @param id The ID of the Import
|
|
1789
2407
|
* @param params The import update parameters
|
|
2408
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1790
2409
|
* @returns The updated Import
|
|
1791
2410
|
*/
|
|
1792
|
-
async update(id, params) {
|
|
1793
|
-
|
|
2411
|
+
async update(id, params, requestOptions) {
|
|
2412
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2413
|
+
return scoped.request(`/v0/imports/${id}`, "PATCH", params);
|
|
1794
2414
|
}
|
|
1795
2415
|
/**
|
|
1796
2416
|
* Delete an Import
|
|
1797
2417
|
* @param id The ID of the Import
|
|
2418
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1798
2419
|
* @returns The deleted Import
|
|
1799
2420
|
*/
|
|
1800
|
-
async delete(id) {
|
|
1801
|
-
|
|
2421
|
+
async delete(id, requestOptions) {
|
|
2422
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2423
|
+
return scoped.request(`/v0/imports/${id}`, "DELETE");
|
|
1802
2424
|
}
|
|
1803
2425
|
/**
|
|
1804
2426
|
* Wait until an Import is completed or failed
|
|
1805
2427
|
* @param id The ID of the Import
|
|
1806
2428
|
* @param options Configuration options for timeout and polling
|
|
2429
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1807
2430
|
* @returns The Import once it reaches a final state (completed or failed)
|
|
1808
2431
|
* @throws Error if the Import does not complete within the timeout or fails
|
|
1809
2432
|
*/
|
|
1810
|
-
async waitUntilCompleted(id, options) {
|
|
2433
|
+
async waitUntilCompleted(id, options, requestOptions) {
|
|
2434
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1811
2435
|
const timeout = options?.timeout ?? 30 * 60 * 1e3;
|
|
1812
2436
|
const pollInterval = options?.pollInterval ?? 2e3;
|
|
1813
2437
|
const onPoll = options?.onPoll;
|
|
1814
2438
|
const startTime = Date.now();
|
|
1815
2439
|
while (true) {
|
|
1816
|
-
const importItem = await
|
|
2440
|
+
const importItem = await scoped.get(id);
|
|
1817
2441
|
if (onPoll) {
|
|
1818
2442
|
onPoll(importItem.status);
|
|
1819
2443
|
}
|
|
@@ -1832,20 +2456,22 @@ var ImportsClient = class extends WebsetsBaseClient {
|
|
|
1832
2456
|
408 /* RequestTimeout */
|
|
1833
2457
|
);
|
|
1834
2458
|
}
|
|
1835
|
-
await
|
|
2459
|
+
await sleep(pollInterval, scoped.requestOptions?.signal);
|
|
1836
2460
|
}
|
|
1837
2461
|
}
|
|
1838
2462
|
/**
|
|
1839
2463
|
* Iterate through all Imports, handling pagination automatically
|
|
1840
2464
|
* @param options Pagination options
|
|
2465
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1841
2466
|
* @returns Async generator of Imports
|
|
1842
2467
|
*/
|
|
1843
|
-
async *listAll(options) {
|
|
2468
|
+
async *listAll(options, requestOptions) {
|
|
2469
|
+
let scoped = this.withRequestOptions(requestOptions);
|
|
1844
2470
|
let cursor = void 0;
|
|
1845
2471
|
const pageOptions = options ? { ...options } : {};
|
|
1846
2472
|
while (true) {
|
|
1847
2473
|
pageOptions.cursor = cursor;
|
|
1848
|
-
const response = await
|
|
2474
|
+
const response = await scoped.list(pageOptions);
|
|
1849
2475
|
for (const importItem of response.data) {
|
|
1850
2476
|
yield importItem;
|
|
1851
2477
|
}
|
|
@@ -1853,16 +2479,19 @@ var ImportsClient = class extends WebsetsBaseClient {
|
|
|
1853
2479
|
break;
|
|
1854
2480
|
}
|
|
1855
2481
|
cursor = response.nextCursor;
|
|
2482
|
+
scoped = scoped.forNextPage();
|
|
1856
2483
|
}
|
|
1857
2484
|
}
|
|
1858
2485
|
/**
|
|
1859
2486
|
* Collect all Imports into an array
|
|
1860
2487
|
* @param options Pagination options
|
|
2488
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1861
2489
|
* @returns Promise resolving to an array of all Imports
|
|
1862
2490
|
*/
|
|
1863
|
-
async getAll(options) {
|
|
2491
|
+
async getAll(options, requestOptions) {
|
|
2492
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1864
2493
|
const imports = [];
|
|
1865
|
-
for await (const importItem of
|
|
2494
|
+
for await (const importItem of scoped.listAll(options)) {
|
|
1866
2495
|
imports.push(importItem);
|
|
1867
2496
|
}
|
|
1868
2497
|
return imports;
|
|
@@ -1875,14 +2504,16 @@ var WebsetItemsClient = class extends WebsetsBaseClient {
|
|
|
1875
2504
|
* List all Items for a Webset
|
|
1876
2505
|
* @param websetId The ID of the Webset
|
|
1877
2506
|
* @param params - Optional pagination and filtering parameters
|
|
2507
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1878
2508
|
* @returns A promise that resolves with the list of Items
|
|
1879
2509
|
*/
|
|
1880
|
-
list(websetId, params) {
|
|
2510
|
+
list(websetId, params, requestOptions) {
|
|
2511
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1881
2512
|
const queryParams = {
|
|
1882
2513
|
...this.buildPaginationParams(params),
|
|
1883
2514
|
sourceId: params?.sourceId
|
|
1884
2515
|
};
|
|
1885
|
-
return
|
|
2516
|
+
return scoped.request(
|
|
1886
2517
|
`/v0/websets/${websetId}/items`,
|
|
1887
2518
|
"GET",
|
|
1888
2519
|
void 0,
|
|
@@ -1893,14 +2524,16 @@ var WebsetItemsClient = class extends WebsetsBaseClient {
|
|
|
1893
2524
|
* Iterate through all Items in a Webset, handling pagination automatically
|
|
1894
2525
|
* @param websetId The ID of the Webset
|
|
1895
2526
|
* @param options Pagination options
|
|
2527
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1896
2528
|
* @returns Async generator of Webset Items
|
|
1897
2529
|
*/
|
|
1898
|
-
async *listAll(websetId, options) {
|
|
2530
|
+
async *listAll(websetId, options, requestOptions) {
|
|
2531
|
+
let scoped = this.withRequestOptions(requestOptions);
|
|
1899
2532
|
let cursor = void 0;
|
|
1900
2533
|
const pageOptions = options ? { ...options } : {};
|
|
1901
2534
|
while (true) {
|
|
1902
2535
|
pageOptions.cursor = cursor;
|
|
1903
|
-
const response = await
|
|
2536
|
+
const response = await scoped.list(websetId, pageOptions);
|
|
1904
2537
|
for (const item of response.data) {
|
|
1905
2538
|
yield item;
|
|
1906
2539
|
}
|
|
@@ -1908,17 +2541,20 @@ var WebsetItemsClient = class extends WebsetsBaseClient {
|
|
|
1908
2541
|
break;
|
|
1909
2542
|
}
|
|
1910
2543
|
cursor = response.nextCursor;
|
|
2544
|
+
scoped = scoped.forNextPage();
|
|
1911
2545
|
}
|
|
1912
2546
|
}
|
|
1913
2547
|
/**
|
|
1914
2548
|
* Collect all items from a Webset into an array
|
|
1915
2549
|
* @param websetId The ID of the Webset
|
|
1916
2550
|
* @param options Pagination options
|
|
2551
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1917
2552
|
* @returns Promise resolving to an array of all Webset Items
|
|
1918
2553
|
*/
|
|
1919
|
-
async getAll(websetId, options) {
|
|
2554
|
+
async getAll(websetId, options, requestOptions) {
|
|
2555
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1920
2556
|
const items = [];
|
|
1921
|
-
for await (const item of
|
|
2557
|
+
for await (const item of scoped.listAll(websetId, options)) {
|
|
1922
2558
|
items.push(item);
|
|
1923
2559
|
}
|
|
1924
2560
|
return items;
|
|
@@ -1927,10 +2563,12 @@ var WebsetItemsClient = class extends WebsetsBaseClient {
|
|
|
1927
2563
|
* Get an Item by ID
|
|
1928
2564
|
* @param websetId The ID of the Webset
|
|
1929
2565
|
* @param id The ID of the Item
|
|
2566
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1930
2567
|
* @returns The Webset Item
|
|
1931
2568
|
*/
|
|
1932
|
-
async get(websetId, id) {
|
|
1933
|
-
|
|
2569
|
+
async get(websetId, id, requestOptions) {
|
|
2570
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2571
|
+
return scoped.request(
|
|
1934
2572
|
`/v0/websets/${websetId}/items/${id}`,
|
|
1935
2573
|
"GET"
|
|
1936
2574
|
);
|
|
@@ -1939,10 +2577,12 @@ var WebsetItemsClient = class extends WebsetsBaseClient {
|
|
|
1939
2577
|
* Delete an Item
|
|
1940
2578
|
* @param websetId The ID of the Webset
|
|
1941
2579
|
* @param id The ID of the Item
|
|
2580
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1942
2581
|
* @returns The deleted Webset Item
|
|
1943
2582
|
*/
|
|
1944
|
-
async delete(websetId, id) {
|
|
1945
|
-
|
|
2583
|
+
async delete(websetId, id, requestOptions) {
|
|
2584
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2585
|
+
return scoped.request(
|
|
1946
2586
|
`/v0/websets/${websetId}/items/${id}`,
|
|
1947
2587
|
"DELETE"
|
|
1948
2588
|
);
|
|
@@ -1955,11 +2595,13 @@ var WebsetMonitorRunsClient = class extends WebsetsBaseClient {
|
|
|
1955
2595
|
* List all runs for a Monitor
|
|
1956
2596
|
* @param monitorId The ID of the Monitor
|
|
1957
2597
|
* @param options Pagination options
|
|
2598
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1958
2599
|
* @returns The list of Monitor runs
|
|
1959
2600
|
*/
|
|
1960
|
-
async list(monitorId, options) {
|
|
2601
|
+
async list(monitorId, options, requestOptions) {
|
|
2602
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
1961
2603
|
const params = this.buildPaginationParams(options);
|
|
1962
|
-
return
|
|
2604
|
+
return scoped.request(
|
|
1963
2605
|
`/v0/monitors/${monitorId}/runs`,
|
|
1964
2606
|
"GET",
|
|
1965
2607
|
void 0,
|
|
@@ -1970,10 +2612,12 @@ var WebsetMonitorRunsClient = class extends WebsetsBaseClient {
|
|
|
1970
2612
|
* Get a specific Monitor run
|
|
1971
2613
|
* @param monitorId The ID of the Monitor
|
|
1972
2614
|
* @param runId The ID of the Monitor run
|
|
2615
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1973
2616
|
* @returns The Monitor run
|
|
1974
2617
|
*/
|
|
1975
|
-
async get(monitorId, runId) {
|
|
1976
|
-
|
|
2618
|
+
async get(monitorId, runId, requestOptions) {
|
|
2619
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2620
|
+
return scoped.request(
|
|
1977
2621
|
`/v0/monitors/${monitorId}/runs/${runId}`,
|
|
1978
2622
|
"GET"
|
|
1979
2623
|
);
|
|
@@ -1987,31 +2631,37 @@ var WebsetMonitorsClient = class extends WebsetsBaseClient {
|
|
|
1987
2631
|
/**
|
|
1988
2632
|
* Create a Monitor
|
|
1989
2633
|
* @param params The monitor parameters
|
|
2634
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1990
2635
|
* @returns The created Monitor
|
|
1991
2636
|
*/
|
|
1992
|
-
async create(params) {
|
|
1993
|
-
|
|
2637
|
+
async create(params, requestOptions) {
|
|
2638
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2639
|
+
return scoped.request("/v0/monitors", "POST", params);
|
|
1994
2640
|
}
|
|
1995
2641
|
/**
|
|
1996
2642
|
* Get a Monitor by ID
|
|
1997
2643
|
* @param id The ID of the Monitor
|
|
2644
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
1998
2645
|
* @returns The Monitor
|
|
1999
2646
|
*/
|
|
2000
|
-
async get(id) {
|
|
2001
|
-
|
|
2647
|
+
async get(id, requestOptions) {
|
|
2648
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2649
|
+
return scoped.request(`/v0/monitors/${id}`, "GET");
|
|
2002
2650
|
}
|
|
2003
2651
|
/**
|
|
2004
2652
|
* List all Monitors
|
|
2005
2653
|
* @param options Pagination and filtering options
|
|
2654
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2006
2655
|
* @returns The list of Monitors
|
|
2007
2656
|
*/
|
|
2008
|
-
async list(options) {
|
|
2657
|
+
async list(options, requestOptions) {
|
|
2658
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2009
2659
|
const params = {
|
|
2010
2660
|
cursor: options?.cursor,
|
|
2011
2661
|
limit: options?.limit,
|
|
2012
2662
|
websetId: options?.websetId
|
|
2013
2663
|
};
|
|
2014
|
-
return
|
|
2664
|
+
return scoped.request(
|
|
2015
2665
|
"/v0/monitors",
|
|
2016
2666
|
"GET",
|
|
2017
2667
|
void 0,
|
|
@@ -2022,30 +2672,36 @@ var WebsetMonitorsClient = class extends WebsetsBaseClient {
|
|
|
2022
2672
|
* Update a Monitor
|
|
2023
2673
|
* @param id The ID of the Monitor
|
|
2024
2674
|
* @param params The monitor update parameters (status, metadata)
|
|
2675
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2025
2676
|
* @returns The updated Monitor
|
|
2026
2677
|
*/
|
|
2027
|
-
async update(id, params) {
|
|
2028
|
-
|
|
2678
|
+
async update(id, params, requestOptions) {
|
|
2679
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2680
|
+
return scoped.request(`/v0/monitors/${id}`, "PATCH", params);
|
|
2029
2681
|
}
|
|
2030
2682
|
/**
|
|
2031
2683
|
* Delete a Monitor
|
|
2032
2684
|
* @param id The ID of the Monitor
|
|
2685
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2033
2686
|
* @returns The deleted Monitor
|
|
2034
2687
|
*/
|
|
2035
|
-
async delete(id) {
|
|
2036
|
-
|
|
2688
|
+
async delete(id, requestOptions) {
|
|
2689
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2690
|
+
return scoped.request(`/v0/monitors/${id}`, "DELETE");
|
|
2037
2691
|
}
|
|
2038
2692
|
/**
|
|
2039
2693
|
* Iterate through all Monitors, handling pagination automatically
|
|
2040
2694
|
* @param options Pagination and filtering options
|
|
2695
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2041
2696
|
* @returns Async generator of Monitors
|
|
2042
2697
|
*/
|
|
2043
|
-
async *listAll(options) {
|
|
2698
|
+
async *listAll(options, requestOptions) {
|
|
2699
|
+
let scoped = this.withRequestOptions(requestOptions);
|
|
2044
2700
|
let cursor = void 0;
|
|
2045
2701
|
const pageOptions = options ? { ...options } : {};
|
|
2046
2702
|
while (true) {
|
|
2047
2703
|
pageOptions.cursor = cursor;
|
|
2048
|
-
const response = await
|
|
2704
|
+
const response = await scoped.list(pageOptions);
|
|
2049
2705
|
for (const monitor of response.data) {
|
|
2050
2706
|
yield monitor;
|
|
2051
2707
|
}
|
|
@@ -2053,16 +2709,19 @@ var WebsetMonitorsClient = class extends WebsetsBaseClient {
|
|
|
2053
2709
|
break;
|
|
2054
2710
|
}
|
|
2055
2711
|
cursor = response.nextCursor;
|
|
2712
|
+
scoped = scoped.forNextPage();
|
|
2056
2713
|
}
|
|
2057
2714
|
}
|
|
2058
2715
|
/**
|
|
2059
2716
|
* Collect all Monitors into an array
|
|
2060
2717
|
* @param options Pagination and filtering options
|
|
2718
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2061
2719
|
* @returns Promise resolving to an array of all Monitors
|
|
2062
2720
|
*/
|
|
2063
|
-
async getAll(options) {
|
|
2721
|
+
async getAll(options, requestOptions) {
|
|
2722
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2064
2723
|
const monitors = [];
|
|
2065
|
-
for await (const monitor of
|
|
2724
|
+
for await (const monitor of scoped.listAll(options)) {
|
|
2066
2725
|
monitors.push(monitor);
|
|
2067
2726
|
}
|
|
2068
2727
|
return monitors;
|
|
@@ -2075,10 +2734,12 @@ var WebsetSearchesClient = class extends WebsetsBaseClient {
|
|
|
2075
2734
|
* Create a new Search for the Webset
|
|
2076
2735
|
* @param websetId The ID of the Webset
|
|
2077
2736
|
* @param params The search parameters
|
|
2737
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2078
2738
|
* @returns The created Webset Search
|
|
2079
2739
|
*/
|
|
2080
|
-
async create(websetId, params, options) {
|
|
2081
|
-
|
|
2740
|
+
async create(websetId, params, options, requestOptions) {
|
|
2741
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2742
|
+
return scoped.request(
|
|
2082
2743
|
`/v0/websets/${websetId}/searches`,
|
|
2083
2744
|
"POST",
|
|
2084
2745
|
params,
|
|
@@ -2090,10 +2751,12 @@ var WebsetSearchesClient = class extends WebsetsBaseClient {
|
|
|
2090
2751
|
* Get a Search by ID
|
|
2091
2752
|
* @param websetId The ID of the Webset
|
|
2092
2753
|
* @param id The ID of the Search
|
|
2754
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2093
2755
|
* @returns The Webset Search
|
|
2094
2756
|
*/
|
|
2095
|
-
async get(websetId, id) {
|
|
2096
|
-
|
|
2757
|
+
async get(websetId, id, requestOptions) {
|
|
2758
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2759
|
+
return scoped.request(
|
|
2097
2760
|
`/v0/websets/${websetId}/searches/${id}`,
|
|
2098
2761
|
"GET"
|
|
2099
2762
|
);
|
|
@@ -2102,10 +2765,12 @@ var WebsetSearchesClient = class extends WebsetsBaseClient {
|
|
|
2102
2765
|
* Cancel a running Search
|
|
2103
2766
|
* @param websetId The ID of the Webset
|
|
2104
2767
|
* @param id The ID of the Search
|
|
2768
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2105
2769
|
* @returns The canceled Webset Search
|
|
2106
2770
|
*/
|
|
2107
|
-
async cancel(websetId, id) {
|
|
2108
|
-
|
|
2771
|
+
async cancel(websetId, id, requestOptions) {
|
|
2772
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2773
|
+
return scoped.request(
|
|
2109
2774
|
`/v0/websets/${websetId}/searches/${id}/cancel`,
|
|
2110
2775
|
"POST"
|
|
2111
2776
|
);
|
|
@@ -2117,27 +2782,33 @@ var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
|
2117
2782
|
/**
|
|
2118
2783
|
* Create a Webhook
|
|
2119
2784
|
* @param params The webhook parameters
|
|
2785
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2120
2786
|
* @returns The created Webhook
|
|
2121
2787
|
*/
|
|
2122
|
-
async create(params) {
|
|
2123
|
-
|
|
2788
|
+
async create(params, requestOptions) {
|
|
2789
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2790
|
+
return scoped.request("/v0/webhooks", "POST", params);
|
|
2124
2791
|
}
|
|
2125
2792
|
/**
|
|
2126
2793
|
* Get a Webhook by ID
|
|
2127
2794
|
* @param id The ID of the Webhook
|
|
2795
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2128
2796
|
* @returns The Webhook
|
|
2129
2797
|
*/
|
|
2130
|
-
async get(id) {
|
|
2131
|
-
|
|
2798
|
+
async get(id, requestOptions) {
|
|
2799
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2800
|
+
return scoped.request(`/v0/webhooks/${id}`, "GET");
|
|
2132
2801
|
}
|
|
2133
2802
|
/**
|
|
2134
2803
|
* List all Webhooks
|
|
2135
2804
|
* @param options Pagination options
|
|
2805
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2136
2806
|
* @returns The list of Webhooks
|
|
2137
2807
|
*/
|
|
2138
|
-
async list(options) {
|
|
2808
|
+
async list(options, requestOptions) {
|
|
2809
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2139
2810
|
const params = this.buildPaginationParams(options);
|
|
2140
|
-
return
|
|
2811
|
+
return scoped.request(
|
|
2141
2812
|
"/v0/webhooks",
|
|
2142
2813
|
"GET",
|
|
2143
2814
|
void 0,
|
|
@@ -2147,14 +2818,16 @@ var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
|
2147
2818
|
/**
|
|
2148
2819
|
* Iterate through all Webhooks, handling pagination automatically
|
|
2149
2820
|
* @param options Pagination options
|
|
2821
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2150
2822
|
* @returns Async generator of Webhooks
|
|
2151
2823
|
*/
|
|
2152
|
-
async *listAll(options) {
|
|
2824
|
+
async *listAll(options, requestOptions) {
|
|
2825
|
+
let scoped = this.withRequestOptions(requestOptions);
|
|
2153
2826
|
let cursor = void 0;
|
|
2154
2827
|
const pageOptions = options ? { ...options } : {};
|
|
2155
2828
|
while (true) {
|
|
2156
2829
|
pageOptions.cursor = cursor;
|
|
2157
|
-
const response = await
|
|
2830
|
+
const response = await scoped.list(pageOptions);
|
|
2158
2831
|
for (const webhook of response.data) {
|
|
2159
2832
|
yield webhook;
|
|
2160
2833
|
}
|
|
@@ -2162,16 +2835,19 @@ var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
|
2162
2835
|
break;
|
|
2163
2836
|
}
|
|
2164
2837
|
cursor = response.nextCursor;
|
|
2838
|
+
scoped = scoped.forNextPage();
|
|
2165
2839
|
}
|
|
2166
2840
|
}
|
|
2167
2841
|
/**
|
|
2168
2842
|
* Collect all Webhooks into an array
|
|
2169
2843
|
* @param options Pagination options
|
|
2844
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2170
2845
|
* @returns Promise resolving to an array of all Webhooks
|
|
2171
2846
|
*/
|
|
2172
|
-
async getAll(options) {
|
|
2847
|
+
async getAll(options, requestOptions) {
|
|
2848
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2173
2849
|
const webhooks = [];
|
|
2174
|
-
for await (const webhook of
|
|
2850
|
+
for await (const webhook of scoped.listAll(options)) {
|
|
2175
2851
|
webhooks.push(webhook);
|
|
2176
2852
|
}
|
|
2177
2853
|
return webhooks;
|
|
@@ -2180,33 +2856,39 @@ var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
|
2180
2856
|
* Update a Webhook
|
|
2181
2857
|
* @param id The ID of the Webhook
|
|
2182
2858
|
* @param params The webhook update parameters (events, metadata, url)
|
|
2859
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2183
2860
|
* @returns The updated Webhook
|
|
2184
2861
|
*/
|
|
2185
|
-
async update(id, params) {
|
|
2186
|
-
|
|
2862
|
+
async update(id, params, requestOptions) {
|
|
2863
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2864
|
+
return scoped.request(`/v0/webhooks/${id}`, "PATCH", params);
|
|
2187
2865
|
}
|
|
2188
2866
|
/**
|
|
2189
2867
|
* Delete a Webhook
|
|
2190
2868
|
* @param id The ID of the Webhook
|
|
2869
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2191
2870
|
* @returns The deleted Webhook
|
|
2192
2871
|
*/
|
|
2193
|
-
async delete(id) {
|
|
2194
|
-
|
|
2872
|
+
async delete(id, requestOptions) {
|
|
2873
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2874
|
+
return scoped.request(`/v0/webhooks/${id}`, "DELETE");
|
|
2195
2875
|
}
|
|
2196
2876
|
/**
|
|
2197
2877
|
* List all attempts for a Webhook
|
|
2198
2878
|
* @param id The ID of the Webhook
|
|
2199
2879
|
* @param options Pagination and filtering options
|
|
2880
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2200
2881
|
* @returns The list of Webhook attempts
|
|
2201
2882
|
*/
|
|
2202
|
-
async listAttempts(id, options) {
|
|
2883
|
+
async listAttempts(id, options, requestOptions) {
|
|
2884
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2203
2885
|
const params = {
|
|
2204
2886
|
cursor: options?.cursor,
|
|
2205
2887
|
limit: options?.limit,
|
|
2206
2888
|
eventType: options?.eventType,
|
|
2207
2889
|
successful: options?.successful
|
|
2208
2890
|
};
|
|
2209
|
-
return
|
|
2891
|
+
return scoped.request(
|
|
2210
2892
|
`/v0/webhooks/${id}/attempts`,
|
|
2211
2893
|
"GET",
|
|
2212
2894
|
void 0,
|
|
@@ -2217,14 +2899,16 @@ var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
|
2217
2899
|
* Iterate through all attempts for a Webhook, handling pagination automatically
|
|
2218
2900
|
* @param id The ID of the Webhook
|
|
2219
2901
|
* @param options Pagination and filtering options
|
|
2902
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2220
2903
|
* @returns Async generator of Webhook attempts
|
|
2221
2904
|
*/
|
|
2222
|
-
async *listAllAttempts(id, options) {
|
|
2905
|
+
async *listAllAttempts(id, options, requestOptions) {
|
|
2906
|
+
let scoped = this.withRequestOptions(requestOptions);
|
|
2223
2907
|
let cursor = void 0;
|
|
2224
2908
|
const pageOptions = options ? { ...options } : {};
|
|
2225
2909
|
while (true) {
|
|
2226
2910
|
pageOptions.cursor = cursor;
|
|
2227
|
-
const response = await
|
|
2911
|
+
const response = await scoped.listAttempts(id, pageOptions);
|
|
2228
2912
|
for (const attempt of response.data) {
|
|
2229
2913
|
yield attempt;
|
|
2230
2914
|
}
|
|
@@ -2232,17 +2916,20 @@ var WebsetWebhooksClient = class extends WebsetsBaseClient {
|
|
|
2232
2916
|
break;
|
|
2233
2917
|
}
|
|
2234
2918
|
cursor = response.nextCursor;
|
|
2919
|
+
scoped = scoped.forNextPage();
|
|
2235
2920
|
}
|
|
2236
2921
|
}
|
|
2237
2922
|
/**
|
|
2238
2923
|
* Collect all attempts for a Webhook into an array
|
|
2239
2924
|
* @param id The ID of the Webhook
|
|
2240
2925
|
* @param options Pagination and filtering options
|
|
2926
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2241
2927
|
* @returns Promise resolving to an array of all Webhook attempts
|
|
2242
2928
|
*/
|
|
2243
|
-
async getAllAttempts(id, options) {
|
|
2929
|
+
async getAllAttempts(id, options, requestOptions) {
|
|
2930
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2244
2931
|
const attempts = [];
|
|
2245
|
-
for await (const attempt of
|
|
2932
|
+
for await (const attempt of scoped.listAllAttempts(id, options)) {
|
|
2246
2933
|
attempts.push(attempt);
|
|
2247
2934
|
}
|
|
2248
2935
|
return attempts;
|
|
@@ -2268,10 +2955,12 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
2268
2955
|
/**
|
|
2269
2956
|
* Create a new Webset
|
|
2270
2957
|
* @param params The Webset creation parameters
|
|
2958
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2271
2959
|
* @returns The created Webset
|
|
2272
2960
|
*/
|
|
2273
|
-
async create(params, options) {
|
|
2274
|
-
|
|
2961
|
+
async create(params, options, requestOptions) {
|
|
2962
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2963
|
+
return scoped.request(
|
|
2275
2964
|
"/v0/websets",
|
|
2276
2965
|
"POST",
|
|
2277
2966
|
params,
|
|
@@ -2283,14 +2972,16 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
2283
2972
|
* Preview a webset
|
|
2284
2973
|
* @param params The preview parameters
|
|
2285
2974
|
* @param options Optional parameters. Search = true allows you to retrieve a preview set of items that could be returned by the webset.
|
|
2286
|
-
* @
|
|
2975
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2976
|
+
* @returns How the query will be interpreted.
|
|
2287
2977
|
*/
|
|
2288
|
-
async preview(params, options) {
|
|
2978
|
+
async preview(params, options, requestOptions) {
|
|
2979
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2289
2980
|
const queryParams = {};
|
|
2290
2981
|
if (options?.search !== void 0) {
|
|
2291
2982
|
queryParams.search = options.search;
|
|
2292
2983
|
}
|
|
2293
|
-
return
|
|
2984
|
+
return scoped.request(
|
|
2294
2985
|
"/v0/websets/preview",
|
|
2295
2986
|
"POST",
|
|
2296
2987
|
params,
|
|
@@ -2301,14 +2992,16 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
2301
2992
|
* Get a Webset by ID
|
|
2302
2993
|
* @param id The ID of the Webset
|
|
2303
2994
|
* @param expand Optional array of relations to expand
|
|
2995
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2304
2996
|
* @returns The Webset
|
|
2305
2997
|
*/
|
|
2306
|
-
async get(id, expand) {
|
|
2998
|
+
async get(id, expand, requestOptions) {
|
|
2999
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2307
3000
|
const params = {};
|
|
2308
3001
|
if (expand) {
|
|
2309
3002
|
params.expand = expand;
|
|
2310
3003
|
}
|
|
2311
|
-
return
|
|
3004
|
+
return scoped.request(
|
|
2312
3005
|
`/v0/websets/${id}`,
|
|
2313
3006
|
"GET",
|
|
2314
3007
|
void 0,
|
|
@@ -2318,11 +3011,13 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
2318
3011
|
/**
|
|
2319
3012
|
* List all Websets
|
|
2320
3013
|
* @param options Pagination options (filtering by status is not supported by API)
|
|
3014
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2321
3015
|
* @returns The list of Websets
|
|
2322
3016
|
*/
|
|
2323
|
-
async list(options) {
|
|
3017
|
+
async list(options, requestOptions) {
|
|
3018
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2324
3019
|
const params = this.buildPaginationParams(options);
|
|
2325
|
-
return
|
|
3020
|
+
return scoped.request(
|
|
2326
3021
|
"/v0/websets",
|
|
2327
3022
|
"GET",
|
|
2328
3023
|
void 0,
|
|
@@ -2332,14 +3027,16 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
2332
3027
|
/**
|
|
2333
3028
|
* Iterate through all Websets, handling pagination automatically
|
|
2334
3029
|
* @param options Pagination options
|
|
3030
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2335
3031
|
* @returns Async generator of Websets
|
|
2336
3032
|
*/
|
|
2337
|
-
async *listAll(options) {
|
|
3033
|
+
async *listAll(options, requestOptions) {
|
|
3034
|
+
let scoped = this.withRequestOptions(requestOptions);
|
|
2338
3035
|
let cursor = void 0;
|
|
2339
3036
|
const pageOptions = options ? { ...options } : {};
|
|
2340
3037
|
while (true) {
|
|
2341
3038
|
pageOptions.cursor = cursor;
|
|
2342
|
-
const response = await
|
|
3039
|
+
const response = await scoped.list(pageOptions);
|
|
2343
3040
|
for (const webset of response.data) {
|
|
2344
3041
|
yield webset;
|
|
2345
3042
|
}
|
|
@@ -2347,16 +3044,19 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
2347
3044
|
break;
|
|
2348
3045
|
}
|
|
2349
3046
|
cursor = response.nextCursor;
|
|
3047
|
+
scoped = scoped.forNextPage();
|
|
2350
3048
|
}
|
|
2351
3049
|
}
|
|
2352
3050
|
/**
|
|
2353
3051
|
* Collect all Websets into an array
|
|
2354
3052
|
* @param options Pagination options
|
|
3053
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2355
3054
|
* @returns Promise resolving to an array of all Websets
|
|
2356
3055
|
*/
|
|
2357
|
-
async getAll(options) {
|
|
3056
|
+
async getAll(options, requestOptions) {
|
|
3057
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2358
3058
|
const websets = [];
|
|
2359
|
-
for await (const webset of
|
|
3059
|
+
for await (const webset of scoped.listAll(options)) {
|
|
2360
3060
|
websets.push(webset);
|
|
2361
3061
|
}
|
|
2362
3062
|
return websets;
|
|
@@ -2365,35 +3065,43 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
2365
3065
|
* Update a Webset
|
|
2366
3066
|
* @param id The ID of the Webset
|
|
2367
3067
|
* @param params The Webset update parameters
|
|
3068
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2368
3069
|
* @returns The updated Webset
|
|
2369
3070
|
*/
|
|
2370
|
-
async update(id, params) {
|
|
2371
|
-
|
|
3071
|
+
async update(id, params, requestOptions) {
|
|
3072
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
3073
|
+
return scoped.request(`/v0/websets/${id}`, "POST", params);
|
|
2372
3074
|
}
|
|
2373
3075
|
/**
|
|
2374
3076
|
* Delete a Webset
|
|
2375
3077
|
* @param id The ID of the Webset
|
|
3078
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2376
3079
|
* @returns The deleted Webset
|
|
2377
3080
|
*/
|
|
2378
|
-
async delete(id) {
|
|
2379
|
-
|
|
3081
|
+
async delete(id, requestOptions) {
|
|
3082
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
3083
|
+
return scoped.request(`/v0/websets/${id}`, "DELETE");
|
|
2380
3084
|
}
|
|
2381
3085
|
/**
|
|
2382
3086
|
* Cancel a running Webset
|
|
2383
3087
|
* @param id The ID or external ID of the Webset
|
|
3088
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2384
3089
|
* @returns The canceled Webset (as returned by the API)
|
|
2385
3090
|
*/
|
|
2386
|
-
async cancel(id) {
|
|
2387
|
-
|
|
3091
|
+
async cancel(id, requestOptions) {
|
|
3092
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
3093
|
+
return scoped.request(`/v0/websets/${id}/cancel`, "POST");
|
|
2388
3094
|
}
|
|
2389
3095
|
/**
|
|
2390
3096
|
* Wait until a Webset is idle
|
|
2391
3097
|
* @param id The ID of the Webset
|
|
2392
3098
|
* @param options Configuration options for timeout and polling
|
|
3099
|
+
* @param requestOptions Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`)
|
|
2393
3100
|
* @returns The Webset once it becomes idle
|
|
2394
3101
|
* @throws Error if the Webset does not become idle within the timeout
|
|
2395
3102
|
*/
|
|
2396
|
-
async waitUntilIdle(id, options) {
|
|
3103
|
+
async waitUntilIdle(id, options, requestOptions) {
|
|
3104
|
+
const scoped = this.withRequestOptions(requestOptions);
|
|
2397
3105
|
let timeout;
|
|
2398
3106
|
let pollInterval = 1e3;
|
|
2399
3107
|
let onPoll;
|
|
@@ -2406,7 +3114,7 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
2406
3114
|
}
|
|
2407
3115
|
const startTime = Date.now();
|
|
2408
3116
|
while (true) {
|
|
2409
|
-
const webset = await
|
|
3117
|
+
const webset = await scoped.get(id);
|
|
2410
3118
|
if (onPoll) {
|
|
2411
3119
|
onPoll(webset.status);
|
|
2412
3120
|
}
|
|
@@ -2419,7 +3127,7 @@ var WebsetsClient = class extends WebsetsBaseClient {
|
|
|
2419
3127
|
408 /* RequestTimeout */
|
|
2420
3128
|
);
|
|
2421
3129
|
}
|
|
2422
|
-
await
|
|
3130
|
+
await sleep(pollInterval, scoped.requestOptions?.signal);
|
|
2423
3131
|
}
|
|
2424
3132
|
}
|
|
2425
3133
|
};
|
|
@@ -2451,8 +3159,15 @@ ${result.highlights.join("\n")}`);
|
|
|
2451
3159
|
}).join("\n\n---\n\n");
|
|
2452
3160
|
return formatted || emptyMessage;
|
|
2453
3161
|
}
|
|
3162
|
+
function formatSearchNotices(response) {
|
|
3163
|
+
return (response.notices ?? []).filter((notice) => typeof notice?.message === "string").map((notice) => `Note: ${notice.message}`);
|
|
3164
|
+
}
|
|
2454
3165
|
function formatSearchResponse(response) {
|
|
2455
|
-
|
|
3166
|
+
const text = formatResults(response, "No search results found.");
|
|
3167
|
+
const notes = formatSearchNotices(response);
|
|
3168
|
+
return notes.length === 0 ? text : `${notes.join("\n")}
|
|
3169
|
+
|
|
3170
|
+
${text}`;
|
|
2456
3171
|
}
|
|
2457
3172
|
function formatContentsResponse(response) {
|
|
2458
3173
|
return formatResults(response, "No contents found.");
|
|
@@ -2852,31 +3567,75 @@ var fetchImpl = typeof global !== "undefined" && global.fetch ? global.fetch : i
|
|
|
2852
3567
|
var HeadersImpl = typeof global !== "undefined" && global.Headers ? global.Headers : import_cross_fetch.Headers;
|
|
2853
3568
|
var DEFAULT_MAX_CHARACTERS = 1e4;
|
|
2854
3569
|
var DYNAMIC_HIGHLIGHTS_BETA = "dynamic-highlights-2026-08-28";
|
|
2855
|
-
var
|
|
2856
|
-
|
|
2857
|
-
const
|
|
2858
|
-
|
|
2859
|
-
|
|
3570
|
+
var loggedWarnings = /* @__PURE__ */ new Set();
|
|
3571
|
+
function logWarningOnce(warning, context) {
|
|
3572
|
+
const request = `${context.method} ${context.endpoint}`;
|
|
3573
|
+
const key = `${request} ${warning.code} ${warning.path}`;
|
|
3574
|
+
if (loggedWarnings.has(key)) {
|
|
3575
|
+
return;
|
|
3576
|
+
}
|
|
3577
|
+
loggedWarnings.add(key);
|
|
3578
|
+
console.warn(
|
|
3579
|
+
`[exa] ${request} ${warning.code} at ${warning.path}: ${warning.message}`
|
|
3580
|
+
);
|
|
3581
|
+
}
|
|
3582
|
+
function warningHandlerFor(option) {
|
|
3583
|
+
if (option === void 0 || option === "log") {
|
|
3584
|
+
return logWarningOnce;
|
|
2860
3585
|
}
|
|
2861
|
-
|
|
2862
|
-
return
|
|
2863
|
-
}
|
|
2864
|
-
|
|
3586
|
+
if (option === "silent") {
|
|
3587
|
+
return void 0;
|
|
3588
|
+
}
|
|
3589
|
+
if (typeof option === "function") {
|
|
3590
|
+
return option;
|
|
2865
3591
|
}
|
|
3592
|
+
throw new TypeError(
|
|
3593
|
+
`options.warnings must be "log", "silent" or a function, got ${JSON.stringify(option)}`
|
|
3594
|
+
);
|
|
2866
3595
|
}
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
3596
|
+
var BODY_WARNING_ENDPOINTS = /* @__PURE__ */ new Set(["/search"]);
|
|
3597
|
+
function isApiWarning(value) {
|
|
3598
|
+
if (typeof value !== "object" || value === null) {
|
|
3599
|
+
return false;
|
|
3600
|
+
}
|
|
3601
|
+
const { code, path, message } = value;
|
|
3602
|
+
return typeof code === "string" && typeof path === "string" && typeof message === "string";
|
|
3603
|
+
}
|
|
3604
|
+
function bodyWarnings(endpoint, body) {
|
|
3605
|
+
if (!BODY_WARNING_ENDPOINTS.has(endpoint) || typeof body !== "object" || body === null) {
|
|
3606
|
+
return [];
|
|
3607
|
+
}
|
|
3608
|
+
const { warnings } = body;
|
|
3609
|
+
return Array.isArray(warnings) ? warnings.filter(isApiWarning) : [];
|
|
3610
|
+
}
|
|
3611
|
+
function withJsonSummarySchema(contents) {
|
|
3612
|
+
if (typeof contents !== "object" || contents === null) return contents;
|
|
3613
|
+
const summary = contents.summary;
|
|
3614
|
+
if (typeof summary !== "object" || summary === null) return contents;
|
|
3615
|
+
const schema = summary.schema;
|
|
3616
|
+
if (!isZodSchema(schema)) return contents;
|
|
3617
|
+
return {
|
|
3618
|
+
...contents,
|
|
3619
|
+
summary: { ...summary, schema: zodToJsonSchema(schema) }
|
|
3620
|
+
};
|
|
2870
3621
|
}
|
|
2871
3622
|
var Exa2 = class {
|
|
2872
3623
|
/**
|
|
2873
3624
|
* Constructs the Exa API client.
|
|
2874
3625
|
* @param {string} apiKey - The API key for authentication.
|
|
2875
3626
|
* @param {string} [baseURL] - The base URL of the Exa API.
|
|
3627
|
+
* @param {ExaClientOptions} [options] - Client-wide settings (`timeout`, `warnings`).
|
|
3628
|
+
* @throws {RangeError} When `options.timeout` is not an integer from 1 to 2147483647.
|
|
3629
|
+
* @throws {TypeError} When `options.warnings` is not `"log"`, `"silent"` or a function.
|
|
2876
3630
|
*/
|
|
2877
|
-
constructor(apiKey, baseURL = "https://api.exa.ai") {
|
|
3631
|
+
constructor(apiKey, baseURL = "https://api.exa.ai", options) {
|
|
2878
3632
|
this.toolRegistry = new ToolRegistry();
|
|
2879
3633
|
this.baseURL = baseURL;
|
|
3634
|
+
this.warningHandler = warningHandlerFor(options?.warnings);
|
|
3635
|
+
setClientDefaults(
|
|
3636
|
+
this,
|
|
3637
|
+
options?.timeout === void 0 ? void 0 : { timeout: validateTimeout(options.timeout) }
|
|
3638
|
+
);
|
|
2880
3639
|
if (!apiKey) {
|
|
2881
3640
|
apiKey = process.env.EXA_API_KEY;
|
|
2882
3641
|
if (!apiKey) {
|
|
@@ -2897,12 +3656,37 @@ var Exa2 = class {
|
|
|
2897
3656
|
this.agent = new AgentClient(this);
|
|
2898
3657
|
this.beta = new BetaClient(this.agent);
|
|
2899
3658
|
this.tools = {
|
|
2900
|
-
webSearch: (
|
|
2901
|
-
getContents: (
|
|
3659
|
+
webSearch: (options2) => createWebSearchTool(this, this.toolRegistry, options2),
|
|
3660
|
+
getContents: (options2) => createGetContentsTool(this, this.toolRegistry, options2)
|
|
2902
3661
|
};
|
|
2903
3662
|
this.openai = new OpenAITools(this, this.toolRegistry);
|
|
2904
3663
|
this.anthropic = new AnthropicTools(this, this.toolRegistry);
|
|
2905
3664
|
}
|
|
3665
|
+
/**
|
|
3666
|
+
* Hands each warning in a response body or stream payload to the `warnings`
|
|
3667
|
+
* option's handler. `request` calls it for every JSON response and
|
|
3668
|
+
* `streamChatCompletions` for every stream payload, so every endpoint
|
|
3669
|
+
* reports through here.
|
|
3670
|
+
*/
|
|
3671
|
+
reportWarnings(endpoint, method, body, requestIdHeader) {
|
|
3672
|
+
if (!this.warningHandler) {
|
|
3673
|
+
return;
|
|
3674
|
+
}
|
|
3675
|
+
const warnings = bodyWarnings(endpoint, body);
|
|
3676
|
+
if (warnings.length === 0) {
|
|
3677
|
+
return;
|
|
3678
|
+
}
|
|
3679
|
+
const bodyRequestId = body.requestId;
|
|
3680
|
+
const requestId = typeof bodyRequestId === "string" ? bodyRequestId : requestIdHeader ?? void 0;
|
|
3681
|
+
const context = {
|
|
3682
|
+
endpoint,
|
|
3683
|
+
method: method.toUpperCase(),
|
|
3684
|
+
...requestId !== void 0 && { requestId }
|
|
3685
|
+
};
|
|
3686
|
+
for (const warning of warnings) {
|
|
3687
|
+
this.warningHandler(warning, context);
|
|
3688
|
+
}
|
|
3689
|
+
}
|
|
2906
3690
|
/**
|
|
2907
3691
|
* Helper method to separate out the contents-specific options from the rest.
|
|
2908
3692
|
*/
|
|
@@ -2918,6 +3702,7 @@ var Exa2 = class {
|
|
|
2918
3702
|
livecrawlTimeout,
|
|
2919
3703
|
maxAgeHours,
|
|
2920
3704
|
snapshotAsOf,
|
|
3705
|
+
filterEmptyResults,
|
|
2921
3706
|
// DEPRECATED FIELD: preserve legacy `context` only for backward compatibility.
|
|
2922
3707
|
context,
|
|
2923
3708
|
...rest
|
|
@@ -2928,16 +3713,7 @@ var Exa2 = class {
|
|
|
2928
3713
|
}
|
|
2929
3714
|
if (text !== void 0) contentsOptions.text = text;
|
|
2930
3715
|
if (highlights !== void 0) contentsOptions.highlights = highlights;
|
|
2931
|
-
if (summary !== void 0)
|
|
2932
|
-
if (typeof summary === "object" && summary !== null && "schema" in summary && summary.schema && isZodSchema(summary.schema)) {
|
|
2933
|
-
contentsOptions.summary = {
|
|
2934
|
-
...summary,
|
|
2935
|
-
schema: zodToJsonSchema(summary.schema)
|
|
2936
|
-
};
|
|
2937
|
-
} else {
|
|
2938
|
-
contentsOptions.summary = summary;
|
|
2939
|
-
}
|
|
2940
|
-
}
|
|
3716
|
+
if (summary !== void 0) contentsOptions.summary = summary;
|
|
2941
3717
|
if (subpages !== void 0) contentsOptions.subpages = subpages;
|
|
2942
3718
|
if (subpageTarget !== void 0)
|
|
2943
3719
|
contentsOptions.subpageTarget = subpageTarget;
|
|
@@ -2946,30 +3722,27 @@ var Exa2 = class {
|
|
|
2946
3722
|
if (livecrawlTimeout !== void 0)
|
|
2947
3723
|
contentsOptions.livecrawlTimeout = livecrawlTimeout;
|
|
2948
3724
|
if (maxAgeHours !== void 0) contentsOptions.maxAgeHours = maxAgeHours;
|
|
2949
|
-
if (snapshotAsOf !== void 0)
|
|
2950
|
-
|
|
3725
|
+
if (snapshotAsOf !== void 0) contentsOptions.snapshotAsOf = snapshotAsOf;
|
|
3726
|
+
if (filterEmptyResults !== void 0)
|
|
3727
|
+
contentsOptions.filterEmptyResults = filterEmptyResults;
|
|
2951
3728
|
if (context !== void 0) contentsOptions.context = context;
|
|
2952
3729
|
return {
|
|
2953
|
-
contentsOptions,
|
|
3730
|
+
contentsOptions: withJsonSummarySchema(contentsOptions),
|
|
2954
3731
|
restOptions: rest
|
|
2955
3732
|
};
|
|
2956
3733
|
}
|
|
2957
3734
|
buildSearchRequestBody(query, options) {
|
|
2958
|
-
const
|
|
2959
|
-
delete
|
|
2960
|
-
delete
|
|
3735
|
+
const body = { ...omitRequestOptions(options) };
|
|
3736
|
+
delete body.betas;
|
|
3737
|
+
delete body.stream;
|
|
2961
3738
|
if (options === void 0 || !("contents" in options)) {
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
}
|
|
2968
|
-
if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
2969
|
-
delete requestOptions.contents;
|
|
2970
|
-
return { query, ...requestOptions };
|
|
3739
|
+
body.contents = { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } };
|
|
3740
|
+
} else if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
3741
|
+
delete body.contents;
|
|
3742
|
+
} else {
|
|
3743
|
+
body.contents = withJsonSummarySchema(options.contents);
|
|
2971
3744
|
}
|
|
2972
|
-
return { query, ...
|
|
3745
|
+
return { query, ...body };
|
|
2973
3746
|
}
|
|
2974
3747
|
/**
|
|
2975
3748
|
* Makes a request to the Exa API.
|
|
@@ -2977,10 +3750,16 @@ var Exa2 = class {
|
|
|
2977
3750
|
* @param {string} method - The HTTP method to use.
|
|
2978
3751
|
* @param {any} [body] - The request body for POST requests.
|
|
2979
3752
|
* @param {Record<string, any>} [params] - The query parameters.
|
|
3753
|
+
* @param {Record<string, string>} [headers] - Additional request headers.
|
|
3754
|
+
* @param {RequestOptions} [requestOptions] - Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`).
|
|
2980
3755
|
* @returns {Promise<any>} The response from the API.
|
|
2981
3756
|
* @throws {ExaError} When any API request fails with structured error information
|
|
3757
|
+
* @throws {ExaTimeoutError} When the request exceeds its `timeout`
|
|
3758
|
+
* @throws {ExaAbortError} When the caller's `signal` aborts the request
|
|
2982
3759
|
*/
|
|
2983
|
-
async request(endpoint, method, body, params, headers) {
|
|
3760
|
+
async request(endpoint, method, body, params, headers, requestOptions) {
|
|
3761
|
+
body = mergeRequestBody(method, body, requestOptions?.body);
|
|
3762
|
+
params = mergeRequestQuery(params, requestOptions?.query);
|
|
2984
3763
|
let url = this.baseURL + endpoint;
|
|
2985
3764
|
if (params && Object.keys(params).length > 0) {
|
|
2986
3765
|
const searchParams = new URLSearchParams();
|
|
@@ -3006,72 +3785,64 @@ var Exa2 = class {
|
|
|
3006
3785
|
if (headers) {
|
|
3007
3786
|
combinedHeaders = { ...combinedHeaders, ...headers };
|
|
3008
3787
|
}
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
headers
|
|
3012
|
-
|
|
3013
|
-
}
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3788
|
+
combinedHeaders = mergeRequestHeaders(
|
|
3789
|
+
combinedHeaders,
|
|
3790
|
+
requestOptions?.headers
|
|
3791
|
+
);
|
|
3792
|
+
const { signal, dispose, toRequestError } = resolveRequestSignal(
|
|
3793
|
+
withClientDefaults(this, requestOptions)
|
|
3794
|
+
);
|
|
3795
|
+
try {
|
|
3796
|
+
const response = await fetchImpl(url, {
|
|
3797
|
+
method,
|
|
3798
|
+
headers: combinedHeaders,
|
|
3799
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
3800
|
+
signal
|
|
3801
|
+
});
|
|
3802
|
+
if (!response.ok) {
|
|
3803
|
+
throw await exaErrorFromResponse(response, endpoint);
|
|
3804
|
+
}
|
|
3805
|
+
const contentType = response.headers.get("content-type") || "";
|
|
3806
|
+
if (contentType.includes("text/event-stream")) {
|
|
3807
|
+
return await this.parseSSEStream(response);
|
|
3808
|
+
}
|
|
3809
|
+
const { json, text } = await readResponseBody(response);
|
|
3810
|
+
if (json === void 0 && text) {
|
|
3019
3811
|
throw new ExaError(
|
|
3020
|
-
|
|
3812
|
+
`Expected a JSON response but received a non-JSON body (status ${response.status}): ${truncateResponseBody(text)}`,
|
|
3021
3813
|
response.status,
|
|
3022
3814
|
(/* @__PURE__ */ new Date()).toISOString(),
|
|
3023
3815
|
endpoint
|
|
3024
3816
|
);
|
|
3025
3817
|
}
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
errorData.timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
3032
|
-
}
|
|
3033
|
-
if (!errorData.path) {
|
|
3034
|
-
errorData.path = endpoint;
|
|
3035
|
-
}
|
|
3036
|
-
const envelope = typeof errorData.error === "object" && errorData.error !== null ? errorData.error : void 0;
|
|
3037
|
-
let message;
|
|
3038
|
-
if (envelope) {
|
|
3039
|
-
message = envelope.message || errorData.message || "Unknown error";
|
|
3040
|
-
} else {
|
|
3041
|
-
message = errorData.error || "Unknown error";
|
|
3042
|
-
if (errorData.message) {
|
|
3043
|
-
message += (message.length > 0 ? ". " : "") + errorData.message;
|
|
3044
|
-
}
|
|
3045
|
-
}
|
|
3046
|
-
throw new ExaError(
|
|
3047
|
-
message,
|
|
3048
|
-
response.status,
|
|
3049
|
-
errorData.timestamp,
|
|
3050
|
-
errorData.path,
|
|
3051
|
-
envelope ? {
|
|
3052
|
-
type: envelope.type,
|
|
3053
|
-
code: envelope.code,
|
|
3054
|
-
detail: envelope.detail,
|
|
3055
|
-
requestId: errorData.requestId ?? envelope.requestId
|
|
3056
|
-
} : errorData.requestId ? { requestId: errorData.requestId } : void 0
|
|
3057
|
-
);
|
|
3058
|
-
}
|
|
3059
|
-
const contentType = response.headers.get("content-type") || "";
|
|
3060
|
-
if (contentType.includes("text/event-stream")) {
|
|
3061
|
-
return await this.parseSSEStream(response);
|
|
3062
|
-
}
|
|
3063
|
-
const { json, text } = await readResponseBody(response);
|
|
3064
|
-
if (json === void 0 && text) {
|
|
3065
|
-
throw new ExaError(
|
|
3066
|
-
`Expected a JSON response but received a non-JSON body (status ${response.status}): ${truncateResponseBody(text)}`,
|
|
3067
|
-
response.status,
|
|
3068
|
-
(/* @__PURE__ */ new Date()).toISOString(),
|
|
3069
|
-
endpoint
|
|
3818
|
+
this.reportWarnings(
|
|
3819
|
+
endpoint,
|
|
3820
|
+
method,
|
|
3821
|
+
json,
|
|
3822
|
+
response.headers.get("x-request-id")
|
|
3070
3823
|
);
|
|
3824
|
+
return json;
|
|
3825
|
+
} catch (error) {
|
|
3826
|
+
throw toRequestError(error, endpoint);
|
|
3827
|
+
} finally {
|
|
3828
|
+
dispose();
|
|
3071
3829
|
}
|
|
3072
|
-
return json;
|
|
3073
3830
|
}
|
|
3074
|
-
|
|
3831
|
+
/**
|
|
3832
|
+
* Makes a request to the Exa API and returns the raw `Response`.
|
|
3833
|
+
*
|
|
3834
|
+
* `timeout` keeps running until the response body is consumed or cancelled,
|
|
3835
|
+
* and a body read it or the `signal` interrupts rejects with the platform's
|
|
3836
|
+
* own error. The SDK's streaming methods instead stop the timeout once the
|
|
3837
|
+
* response headers arrive. `body`, `headers` and `query` in
|
|
3838
|
+
* `requestOptions` are added to the request as they are in `request`.
|
|
3839
|
+
*
|
|
3840
|
+
* @throws {ExaTimeoutError} When no response arrives within `timeout`
|
|
3841
|
+
* @throws {ExaAbortError} When the caller's `signal` aborts before a response arrives
|
|
3842
|
+
*/
|
|
3843
|
+
async rawRequest(endpoint, method = "POST", body, queryParams, headers, requestOptions) {
|
|
3844
|
+
body = mergeRequestBody(method, body, requestOptions?.body);
|
|
3845
|
+
queryParams = mergeRequestQuery(queryParams, requestOptions?.query);
|
|
3075
3846
|
let url = this.baseURL + endpoint;
|
|
3076
3847
|
if (queryParams) {
|
|
3077
3848
|
const searchParams = new URLSearchParams();
|
|
@@ -3097,14 +3868,68 @@ var Exa2 = class {
|
|
|
3097
3868
|
if (headers) {
|
|
3098
3869
|
combinedHeaders = { ...combinedHeaders, ...headers };
|
|
3099
3870
|
}
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
headers
|
|
3103
|
-
|
|
3104
|
-
});
|
|
3105
|
-
|
|
3871
|
+
combinedHeaders = mergeRequestHeaders(
|
|
3872
|
+
combinedHeaders,
|
|
3873
|
+
requestOptions?.headers
|
|
3874
|
+
);
|
|
3875
|
+
const { signal, dispose, needsDispose, stopTimeout, toRequestError } = resolveRequestSignal(withClientDefaults(this, requestOptions));
|
|
3876
|
+
try {
|
|
3877
|
+
const response = await fetchImpl(url, {
|
|
3878
|
+
method,
|
|
3879
|
+
headers: combinedHeaders,
|
|
3880
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
3881
|
+
signal
|
|
3882
|
+
});
|
|
3883
|
+
if (isStreamRequestOptions(requestOptions)) {
|
|
3884
|
+
const mapError = (error) => toRequestError(error, endpoint);
|
|
3885
|
+
if (!response.ok) {
|
|
3886
|
+
return withDisposeOnBodySettled(response, dispose, mapError);
|
|
3887
|
+
}
|
|
3888
|
+
stopTimeout();
|
|
3889
|
+
if (!requestOptions?.signal) {
|
|
3890
|
+
dispose();
|
|
3891
|
+
return response;
|
|
3892
|
+
}
|
|
3893
|
+
return withDisposeOnBodySettled(response, dispose, mapError);
|
|
3894
|
+
}
|
|
3895
|
+
if (!needsDispose) {
|
|
3896
|
+
return response;
|
|
3897
|
+
}
|
|
3898
|
+
return withDisposeOnBodySettled(response, dispose);
|
|
3899
|
+
} catch (error) {
|
|
3900
|
+
dispose();
|
|
3901
|
+
throw toRequestError(error, endpoint);
|
|
3902
|
+
}
|
|
3903
|
+
}
|
|
3904
|
+
requestWithOptions(endpoint, method, body, requestOptions) {
|
|
3905
|
+
const transport = mergeRequestOptions(requestOptions);
|
|
3906
|
+
if (transport) {
|
|
3907
|
+
return this.request(
|
|
3908
|
+
endpoint,
|
|
3909
|
+
method,
|
|
3910
|
+
body,
|
|
3911
|
+
void 0,
|
|
3912
|
+
void 0,
|
|
3913
|
+
transport
|
|
3914
|
+
);
|
|
3915
|
+
}
|
|
3916
|
+
return this.request(endpoint, method, body);
|
|
3917
|
+
}
|
|
3918
|
+
streamRequestWithOptions(endpoint, method, body, requestOptions) {
|
|
3919
|
+
const transport = streamRequestOptions(this, requestOptions);
|
|
3920
|
+
if (transport) {
|
|
3921
|
+
return this.rawRequest(
|
|
3922
|
+
endpoint,
|
|
3923
|
+
method,
|
|
3924
|
+
body,
|
|
3925
|
+
void 0,
|
|
3926
|
+
void 0,
|
|
3927
|
+
transport
|
|
3928
|
+
);
|
|
3929
|
+
}
|
|
3930
|
+
return this.rawRequest(endpoint, method, body);
|
|
3106
3931
|
}
|
|
3107
|
-
async search(query, options) {
|
|
3932
|
+
async search(query, options, requestOptions) {
|
|
3108
3933
|
if (options?.stream) {
|
|
3109
3934
|
throw new ExaError(
|
|
3110
3935
|
"For streaming responses, please use streamSearch() instead:\n\nfor await (const chunk of exa.streamSearch(query)) {\n // Handle chunks\n}",
|
|
@@ -3113,23 +3938,42 @@ var Exa2 = class {
|
|
|
3113
3938
|
}
|
|
3114
3939
|
const body = this.buildSearchRequestBody(query, options);
|
|
3115
3940
|
const betaHeaders = headersForBetas(options?.betas);
|
|
3941
|
+
const transport = mergeRequestOptions(
|
|
3942
|
+
pickRequestOptions(options),
|
|
3943
|
+
requestOptions
|
|
3944
|
+
);
|
|
3945
|
+
if (transport) {
|
|
3946
|
+
return await this.request(
|
|
3947
|
+
"/search",
|
|
3948
|
+
"POST",
|
|
3949
|
+
body,
|
|
3950
|
+
void 0,
|
|
3951
|
+
betaHeaders,
|
|
3952
|
+
transport
|
|
3953
|
+
);
|
|
3954
|
+
}
|
|
3116
3955
|
return betaHeaders ? await this.request("/search", "POST", body, void 0, betaHeaders) : await this.request("/search", "POST", body);
|
|
3117
3956
|
}
|
|
3118
3957
|
/**
|
|
3119
3958
|
* Stream a search response as an async generator of OpenAI-style chat completion chunks.
|
|
3120
3959
|
*
|
|
3121
3960
|
* Each iteration yields a chunk with partial text (`content`) or new citations.
|
|
3961
|
+
* When the API returns `warnings` about the request, one chunk after the text
|
|
3962
|
+
* carries them.
|
|
3122
3963
|
* Use this if you'd like to read synthesized search output incrementally.
|
|
3964
|
+
* The `lite` search type does not support streaming.
|
|
3965
|
+
* @param {RequestOptions} [requestOptions] - Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`).
|
|
3123
3966
|
*/
|
|
3124
|
-
streamSearch(query, options) {
|
|
3125
|
-
return this.streamChatCompletions(
|
|
3126
|
-
|
|
3127
|
-
stream: true
|
|
3128
|
-
|
|
3967
|
+
streamSearch(query, options, requestOptions) {
|
|
3968
|
+
return this.streamChatCompletions(
|
|
3969
|
+
"/search",
|
|
3970
|
+
{ ...this.buildSearchRequestBody(query, options), stream: true },
|
|
3971
|
+
mergeRequestOptions(pickRequestOptions(options), requestOptions)
|
|
3972
|
+
);
|
|
3129
3973
|
}
|
|
3130
3974
|
/**
|
|
3131
|
-
*
|
|
3132
|
-
*
|
|
3975
|
+
* @deprecated Use `search()`, which returns text contents by default. Pass
|
|
3976
|
+
* content options inside `contents`.
|
|
3133
3977
|
*
|
|
3134
3978
|
* Migration examples:
|
|
3135
3979
|
* - `searchAndContents(query)` → `search(query)`
|
|
@@ -3140,41 +3984,72 @@ var Exa2 = class {
|
|
|
3140
3984
|
*
|
|
3141
3985
|
* @param {string} query - The query string.
|
|
3142
3986
|
* @param {RegularSearchOptions & T} [options] - Additional search + contents options
|
|
3987
|
+
* @param {RequestOptions} [requestOptions] - Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`).
|
|
3143
3988
|
* @returns {Promise<SearchResponse<T>>} A list of relevant search results with requested contents.
|
|
3144
3989
|
*/
|
|
3145
|
-
async searchAndContents(query, options) {
|
|
3990
|
+
async searchAndContents(query, options, requestOptions) {
|
|
3146
3991
|
const { contentsOptions, restOptions } = options === void 0 ? {
|
|
3147
3992
|
contentsOptions: {
|
|
3148
3993
|
text: { maxCharacters: DEFAULT_MAX_CHARACTERS }
|
|
3149
3994
|
},
|
|
3150
3995
|
restOptions: {}
|
|
3151
3996
|
} : this.extractContentsOptions(options);
|
|
3152
|
-
|
|
3997
|
+
const body = {
|
|
3153
3998
|
query,
|
|
3154
3999
|
contents: contentsOptions,
|
|
3155
|
-
...restOptions
|
|
3156
|
-
}
|
|
4000
|
+
...omitRequestOptions(restOptions)
|
|
4001
|
+
};
|
|
4002
|
+
delete body.stream;
|
|
4003
|
+
return await this.requestWithOptions(
|
|
4004
|
+
"/search",
|
|
4005
|
+
"POST",
|
|
4006
|
+
body,
|
|
4007
|
+
mergeRequestOptions(pickRequestOptions(options), requestOptions)
|
|
4008
|
+
);
|
|
3157
4009
|
}
|
|
3158
|
-
async findSimilar(url, options) {
|
|
4010
|
+
async findSimilar(url, options, requestOptions) {
|
|
4011
|
+
const transport = mergeRequestOptions(
|
|
4012
|
+
pickRequestOptions(options),
|
|
4013
|
+
requestOptions
|
|
4014
|
+
);
|
|
4015
|
+
const bodyOptions = omitRequestOptions(options);
|
|
3159
4016
|
if (options === void 0 || !("contents" in options)) {
|
|
3160
|
-
return await this.
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
4017
|
+
return await this.requestWithOptions(
|
|
4018
|
+
"/findSimilar",
|
|
4019
|
+
"POST",
|
|
4020
|
+
{
|
|
4021
|
+
url,
|
|
4022
|
+
...bodyOptions,
|
|
4023
|
+
contents: { text: { maxCharacters: DEFAULT_MAX_CHARACTERS } }
|
|
4024
|
+
},
|
|
4025
|
+
transport
|
|
4026
|
+
);
|
|
3165
4027
|
}
|
|
3166
4028
|
if (options.contents === false || options.contents === null || options.contents === void 0) {
|
|
3167
|
-
const { contents, ...restOptions } =
|
|
3168
|
-
return await this.
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
4029
|
+
const { contents: _contents, ...restOptions } = bodyOptions ?? {};
|
|
4030
|
+
return await this.requestWithOptions(
|
|
4031
|
+
"/findSimilar",
|
|
4032
|
+
"POST",
|
|
4033
|
+
{
|
|
4034
|
+
url,
|
|
4035
|
+
...restOptions
|
|
4036
|
+
},
|
|
4037
|
+
transport
|
|
4038
|
+
);
|
|
3172
4039
|
}
|
|
3173
|
-
return await this.
|
|
4040
|
+
return await this.requestWithOptions(
|
|
4041
|
+
"/findSimilar",
|
|
4042
|
+
"POST",
|
|
4043
|
+
{
|
|
4044
|
+
url,
|
|
4045
|
+
...bodyOptions,
|
|
4046
|
+
contents: withJsonSummarySchema(options.contents)
|
|
4047
|
+
},
|
|
4048
|
+
transport
|
|
4049
|
+
);
|
|
3174
4050
|
}
|
|
3175
4051
|
/**
|
|
3176
|
-
*
|
|
3177
|
-
* @deprecated Use `search()` for new discovery flows instead. There is no direct replacement for URL-based similarity.
|
|
4052
|
+
* @deprecated Use `search()` instead. There is no direct replacement for URL-based similarity.
|
|
3178
4053
|
*
|
|
3179
4054
|
* Migration examples:
|
|
3180
4055
|
* - `findSimilarAndContents(url)` → `search(query)`
|
|
@@ -3186,26 +4061,28 @@ var Exa2 = class {
|
|
|
3186
4061
|
* @param {FindSimilarOptions & T} [options] - Additional options for finding similar links + contents.
|
|
3187
4062
|
* @returns {Promise<SearchResponse<T>>} A list of similar search results, including requested contents.
|
|
3188
4063
|
*/
|
|
3189
|
-
async findSimilarAndContents(url, options) {
|
|
4064
|
+
async findSimilarAndContents(url, options, requestOptions) {
|
|
3190
4065
|
const { contentsOptions, restOptions } = options === void 0 ? {
|
|
3191
4066
|
contentsOptions: {
|
|
3192
4067
|
text: { maxCharacters: DEFAULT_MAX_CHARACTERS }
|
|
3193
4068
|
},
|
|
3194
4069
|
restOptions: {}
|
|
3195
4070
|
} : this.extractContentsOptions(options);
|
|
3196
|
-
return await this.
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
...restOptions
|
|
3200
|
-
|
|
4071
|
+
return await this.requestWithOptions(
|
|
4072
|
+
"/findSimilar",
|
|
4073
|
+
"POST",
|
|
4074
|
+
{ url, contents: contentsOptions, ...omitRequestOptions(restOptions) },
|
|
4075
|
+
mergeRequestOptions(pickRequestOptions(options), requestOptions)
|
|
4076
|
+
);
|
|
3201
4077
|
}
|
|
3202
4078
|
/**
|
|
3203
4079
|
* Retrieves contents of documents based on URLs.
|
|
3204
4080
|
* @param {string | string[] | SearchResult[]} urls - A URL or array of URLs, or an array of SearchResult objects.
|
|
3205
|
-
* @param {ContentsOptions} [options] - Additional options for retrieving document contents.
|
|
4081
|
+
* @param {ContentsOptions & BetaOptions & UserIdentifierOptions & TransportRequestOptions} [options] - Additional options for retrieving document contents.
|
|
4082
|
+
* @param {RequestOptions} [requestOptions] - Per-call request options (`signal`, `timeout`, `body`, `headers`, `query`).
|
|
3206
4083
|
* @returns {Promise<SearchResponse<T>>} A list of document contents for the requested URLs.
|
|
3207
4084
|
*/
|
|
3208
|
-
async getContents(urls, options) {
|
|
4085
|
+
async getContents(urls, options, requestOptions) {
|
|
3209
4086
|
if (!urls || Array.isArray(urls) && urls.length === 0) {
|
|
3210
4087
|
throw new ExaError(
|
|
3211
4088
|
"Must provide at least one URL",
|
|
@@ -3223,12 +4100,26 @@ var Exa2 = class {
|
|
|
3223
4100
|
const { betas, ...contentsOptions } = options ?? {};
|
|
3224
4101
|
const payload = {
|
|
3225
4102
|
urls: requestUrls,
|
|
3226
|
-
...contentsOptions
|
|
4103
|
+
...withJsonSummarySchema(omitRequestOptions(contentsOptions))
|
|
3227
4104
|
};
|
|
3228
4105
|
const betaHeaders = headersForBetas(betas);
|
|
4106
|
+
const transport = mergeRequestOptions(
|
|
4107
|
+
pickRequestOptions(options),
|
|
4108
|
+
requestOptions
|
|
4109
|
+
);
|
|
4110
|
+
if (transport) {
|
|
4111
|
+
return await this.request(
|
|
4112
|
+
"/contents",
|
|
4113
|
+
"POST",
|
|
4114
|
+
payload,
|
|
4115
|
+
void 0,
|
|
4116
|
+
betaHeaders,
|
|
4117
|
+
transport
|
|
4118
|
+
);
|
|
4119
|
+
}
|
|
3229
4120
|
return betaHeaders ? await this.request("/contents", "POST", payload, void 0, betaHeaders) : await this.request("/contents", "POST", payload);
|
|
3230
4121
|
}
|
|
3231
|
-
async answer(query, options) {
|
|
4122
|
+
async answer(query, options, requestOptions) {
|
|
3232
4123
|
if (options?.stream) {
|
|
3233
4124
|
throw new ExaError(
|
|
3234
4125
|
"For streaming responses, please use streamAnswer() instead:\n\nfor await (const chunk of exa.streamAnswer(query)) {\n // Handle chunks\n}",
|
|
@@ -3246,11 +4137,17 @@ var Exa2 = class {
|
|
|
3246
4137
|
model: options?.model ?? "exa",
|
|
3247
4138
|
systemPrompt: options?.systemPrompt,
|
|
3248
4139
|
outputSchema,
|
|
3249
|
-
userLocation: options?.userLocation
|
|
4140
|
+
userLocation: options?.userLocation,
|
|
4141
|
+
userIdentifier: options?.userIdentifier
|
|
3250
4142
|
};
|
|
3251
|
-
return await this.
|
|
4143
|
+
return await this.requestWithOptions(
|
|
4144
|
+
"/answer",
|
|
4145
|
+
"POST",
|
|
4146
|
+
requestBody,
|
|
4147
|
+
mergeRequestOptions(pickRequestOptions(options), requestOptions)
|
|
4148
|
+
);
|
|
3252
4149
|
}
|
|
3253
|
-
async *streamAnswer(query, options) {
|
|
4150
|
+
async *streamAnswer(query, options, requestOptions) {
|
|
3254
4151
|
let outputSchema = options?.outputSchema;
|
|
3255
4152
|
if (outputSchema && isZodSchema(outputSchema)) {
|
|
3256
4153
|
outputSchema = zodToJsonSchema(outputSchema);
|
|
@@ -3262,16 +4159,26 @@ var Exa2 = class {
|
|
|
3262
4159
|
model: options?.model ?? "exa",
|
|
3263
4160
|
systemPrompt: options?.systemPrompt,
|
|
3264
4161
|
outputSchema,
|
|
3265
|
-
userLocation: options?.userLocation
|
|
4162
|
+
userLocation: options?.userLocation,
|
|
4163
|
+
userIdentifier: options?.userIdentifier
|
|
3266
4164
|
};
|
|
3267
|
-
yield* this.streamChatCompletions(
|
|
4165
|
+
yield* this.streamChatCompletions(
|
|
4166
|
+
"/answer",
|
|
4167
|
+
body,
|
|
4168
|
+
mergeRequestOptions(pickRequestOptions(options), requestOptions)
|
|
4169
|
+
);
|
|
3268
4170
|
}
|
|
3269
|
-
async *streamChatCompletions(endpoint, body) {
|
|
3270
|
-
const response = await this.
|
|
4171
|
+
async *streamChatCompletions(endpoint, body, requestOptions) {
|
|
4172
|
+
const response = await this.streamRequestWithOptions(
|
|
4173
|
+
endpoint,
|
|
4174
|
+
"POST",
|
|
4175
|
+
body,
|
|
4176
|
+
requestOptions
|
|
4177
|
+
);
|
|
3271
4178
|
if (!response.ok) {
|
|
3272
|
-
|
|
3273
|
-
throw new ExaError(message, response.status, (/* @__PURE__ */ new Date()).toISOString());
|
|
4179
|
+
throw await exaErrorFromResponse(response, endpoint);
|
|
3274
4180
|
}
|
|
4181
|
+
const requestIdHeader = response.headers.get("x-request-id");
|
|
3275
4182
|
const reader = response.body?.getReader();
|
|
3276
4183
|
if (!reader) {
|
|
3277
4184
|
throw new ExaError(
|
|
@@ -3302,7 +4209,8 @@ var Exa2 = class {
|
|
|
3302
4209
|
continue;
|
|
3303
4210
|
}
|
|
3304
4211
|
const chunk = this.processChunk(chunkData);
|
|
3305
|
-
|
|
4212
|
+
this.reportWarnings(endpoint, "POST", chunkData, requestIdHeader);
|
|
4213
|
+
if (chunk.content || chunk.citations || chunk.warnings) {
|
|
3306
4214
|
yield chunk;
|
|
3307
4215
|
}
|
|
3308
4216
|
}
|
|
@@ -3313,7 +4221,8 @@ var Exa2 = class {
|
|
|
3313
4221
|
try {
|
|
3314
4222
|
const chunkData = JSON.parse(leftover);
|
|
3315
4223
|
const chunk = this.processChunk(chunkData);
|
|
3316
|
-
|
|
4224
|
+
this.reportWarnings(endpoint, "POST", chunkData, requestIdHeader);
|
|
4225
|
+
if (chunk.content || chunk.citations || chunk.warnings) {
|
|
3317
4226
|
yield chunk;
|
|
3318
4227
|
}
|
|
3319
4228
|
} catch (e) {
|
|
@@ -3321,9 +4230,17 @@ var Exa2 = class {
|
|
|
3321
4230
|
}
|
|
3322
4231
|
}
|
|
3323
4232
|
} finally {
|
|
3324
|
-
|
|
4233
|
+
try {
|
|
4234
|
+
await reader.cancel();
|
|
4235
|
+
} catch {
|
|
4236
|
+
}
|
|
3325
4237
|
}
|
|
3326
4238
|
}
|
|
4239
|
+
/**
|
|
4240
|
+
* Parses one stream payload into a chunk. `warnings` is set only when the
|
|
4241
|
+
* payload carries a non-empty `warnings` array, which `/search` sends on its
|
|
4242
|
+
* `results` event.
|
|
4243
|
+
*/
|
|
3327
4244
|
processChunk(chunkData) {
|
|
3328
4245
|
let content;
|
|
3329
4246
|
let citations;
|
|
@@ -3340,6 +4257,10 @@ var Exa2 = class {
|
|
|
3340
4257
|
text: c.text
|
|
3341
4258
|
}));
|
|
3342
4259
|
}
|
|
4260
|
+
if (Array.isArray(chunkData.warnings) && chunkData.warnings.length > 0) {
|
|
4261
|
+
const warnings = chunkData.warnings;
|
|
4262
|
+
return { content, citations, warnings };
|
|
4263
|
+
}
|
|
3343
4264
|
return { content, citations };
|
|
3344
4265
|
}
|
|
3345
4266
|
async parseSSEStream(response) {
|
|
@@ -3353,65 +4274,45 @@ var Exa2 = class {
|
|
|
3353
4274
|
}
|
|
3354
4275
|
const decoder = new TextDecoder();
|
|
3355
4276
|
let buffer = "";
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
return;
|
|
3381
|
-
case "error": {
|
|
3382
|
-
const message = chunk.error?.message || "Unknown error";
|
|
3383
|
-
reader.releaseLock();
|
|
3384
|
-
reject(
|
|
3385
|
-
new ExaError(
|
|
3386
|
-
message,
|
|
3387
|
-
500 /* InternalServerError */,
|
|
3388
|
-
(/* @__PURE__ */ new Date()).toISOString()
|
|
3389
|
-
)
|
|
3390
|
-
);
|
|
3391
|
-
return;
|
|
3392
|
-
}
|
|
3393
|
-
// 'progress' and any other tags are ignored for the blocking variant
|
|
3394
|
-
default:
|
|
3395
|
-
break;
|
|
3396
|
-
}
|
|
4277
|
+
try {
|
|
4278
|
+
while (true) {
|
|
4279
|
+
const { done, value } = await reader.read();
|
|
4280
|
+
if (done) break;
|
|
4281
|
+
buffer += decoder.decode(value, { stream: true });
|
|
4282
|
+
const lines = buffer.split("\n");
|
|
4283
|
+
buffer = lines.pop() || "";
|
|
4284
|
+
for (const line of lines) {
|
|
4285
|
+
if (!line.startsWith("data: ")) continue;
|
|
4286
|
+
const jsonStr = line.replace(/^data:\s*/, "").trim();
|
|
4287
|
+
if (!jsonStr || jsonStr === "[DONE]") continue;
|
|
4288
|
+
let chunk;
|
|
4289
|
+
try {
|
|
4290
|
+
chunk = JSON.parse(jsonStr);
|
|
4291
|
+
} catch {
|
|
4292
|
+
continue;
|
|
4293
|
+
}
|
|
4294
|
+
if (chunk.tag === "complete") return chunk.data;
|
|
4295
|
+
if (chunk.tag === "error") {
|
|
4296
|
+
throw new ExaError(
|
|
4297
|
+
chunk.error?.message || "Unknown error",
|
|
4298
|
+
500 /* InternalServerError */,
|
|
4299
|
+
(/* @__PURE__ */ new Date()).toISOString()
|
|
4300
|
+
);
|
|
3397
4301
|
}
|
|
3398
|
-
}
|
|
3399
|
-
reject(
|
|
3400
|
-
new ExaError(
|
|
3401
|
-
"Stream ended without a completion event.",
|
|
3402
|
-
500 /* InternalServerError */,
|
|
3403
|
-
(/* @__PURE__ */ new Date()).toISOString()
|
|
3404
|
-
)
|
|
3405
|
-
);
|
|
3406
|
-
} catch (err) {
|
|
3407
|
-
reject(err);
|
|
3408
|
-
} finally {
|
|
3409
|
-
try {
|
|
3410
|
-
reader.releaseLock();
|
|
3411
|
-
} catch {
|
|
3412
4302
|
}
|
|
3413
4303
|
}
|
|
3414
|
-
|
|
4304
|
+
throw new ExaError(
|
|
4305
|
+
"Stream ended without a completion event.",
|
|
4306
|
+
500 /* InternalServerError */,
|
|
4307
|
+
(/* @__PURE__ */ new Date()).toISOString()
|
|
4308
|
+
);
|
|
4309
|
+
} finally {
|
|
4310
|
+
try {
|
|
4311
|
+
await reader.cancel();
|
|
4312
|
+
} catch {
|
|
4313
|
+
}
|
|
4314
|
+
reader.releaseLock();
|
|
4315
|
+
}
|
|
3415
4316
|
}
|
|
3416
4317
|
};
|
|
3417
4318
|
var index_default = Exa2;
|
|
@@ -3441,7 +4342,9 @@ var index_default = Exa2;
|
|
|
3441
4342
|
EventType,
|
|
3442
4343
|
EventsClient,
|
|
3443
4344
|
Exa,
|
|
4345
|
+
ExaAbortError,
|
|
3444
4346
|
ExaError,
|
|
4347
|
+
ExaTimeoutError,
|
|
3445
4348
|
HttpStatusCode,
|
|
3446
4349
|
ImportFailedReason,
|
|
3447
4350
|
ImportFormat,
|