exa-js 2.22.0 → 2.22.1
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 +6 -8
- package/dist/index.d.mts +96 -54
- package/dist/index.d.ts +96 -54
- package/dist/index.js +37 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -35,10 +35,10 @@ __export(index_exports, {
|
|
|
35
35
|
AGENT_MONITORS_BETA_HEADER: () => AGENT_MONITORS_BETA_HEADER,
|
|
36
36
|
AgentBetaClient: () => AgentBetaClient,
|
|
37
37
|
AgentClient: () => AgentClient,
|
|
38
|
+
AgentMonitorBacktestFailedError: () => AgentMonitorBacktestFailedError,
|
|
39
|
+
AgentMonitorBacktestsClient: () => AgentMonitorBacktestsClient,
|
|
38
40
|
AgentMonitorChangesClient: () => AgentMonitorChangesClient,
|
|
39
41
|
AgentMonitorEntitiesClient: () => AgentMonitorEntitiesClient,
|
|
40
|
-
AgentMonitorSnapshotFailedError: () => AgentMonitorSnapshotFailedError,
|
|
41
|
-
AgentMonitorSnapshotsClient: () => AgentMonitorSnapshotsClient,
|
|
42
42
|
AgentMonitorsClient: () => AgentMonitorsClient,
|
|
43
43
|
AgentRunCancelledError: () => AgentRunCancelledError,
|
|
44
44
|
AgentRunEventsClient: () => AgentRunEventsClient,
|
|
@@ -100,7 +100,7 @@ var import_cross_fetch = __toESM(require("cross-fetch"));
|
|
|
100
100
|
// package.json
|
|
101
101
|
var package_default = {
|
|
102
102
|
name: "exa-js",
|
|
103
|
-
version: "2.22.
|
|
103
|
+
version: "2.22.1",
|
|
104
104
|
description: "Exa SDK for Node.js and the browser",
|
|
105
105
|
publishConfig: {
|
|
106
106
|
access: "public"
|
|
@@ -310,13 +310,13 @@ var AgentMonitorsBaseClient = class {
|
|
|
310
310
|
};
|
|
311
311
|
|
|
312
312
|
// src/agent/monitors/client.ts
|
|
313
|
-
var
|
|
314
|
-
var
|
|
315
|
-
var
|
|
316
|
-
constructor(
|
|
317
|
-
super(
|
|
318
|
-
this.name = "
|
|
319
|
-
this.
|
|
313
|
+
var DEFAULT_BACKTEST_POLL_INTERVAL_MS = 2e3;
|
|
314
|
+
var DEFAULT_BACKTEST_POLL_TIMEOUT_MS = 60 * 60 * 1e3;
|
|
315
|
+
var AgentMonitorBacktestFailedError = class extends Error {
|
|
316
|
+
constructor(backtest) {
|
|
317
|
+
super(backtest.error ?? `Agent monitor backtest ${backtest.id} failed`);
|
|
318
|
+
this.name = "AgentMonitorBacktestFailedError";
|
|
319
|
+
this.backtest = backtest;
|
|
320
320
|
}
|
|
321
321
|
};
|
|
322
322
|
var AgentMonitorEntitiesClient = class extends AgentMonitorsBaseClient {
|
|
@@ -426,66 +426,66 @@ var AgentMonitorChangesClient = class extends AgentMonitorsBaseClient {
|
|
|
426
426
|
return changes;
|
|
427
427
|
}
|
|
428
428
|
};
|
|
429
|
-
var
|
|
429
|
+
var AgentMonitorBacktestsClient = class extends AgentMonitorsBaseClient {
|
|
430
430
|
/**
|
|
431
|
-
* Start an async
|
|
432
|
-
*
|
|
433
|
-
*
|
|
431
|
+
* Start an async backtest of entities × fields over an explicit past news
|
|
432
|
+
* window. Returns a `running` job; poll with `get` (or use `createAndWait`)
|
|
433
|
+
* for the result.
|
|
434
434
|
*/
|
|
435
435
|
async create(params) {
|
|
436
436
|
const { betas, ...payload } = params;
|
|
437
437
|
return this.request(
|
|
438
|
-
"/
|
|
438
|
+
"/backtest",
|
|
439
439
|
betas,
|
|
440
440
|
"POST",
|
|
441
441
|
payload
|
|
442
442
|
);
|
|
443
443
|
}
|
|
444
444
|
/**
|
|
445
|
-
* Poll a
|
|
445
|
+
* Poll a backtest job for its status and, once completed, its result.
|
|
446
446
|
* Jobs expire and read as 404 after `expiresAt`.
|
|
447
447
|
*/
|
|
448
|
-
async get(
|
|
448
|
+
async get(backtestId, options) {
|
|
449
449
|
return this.request(
|
|
450
|
-
`/
|
|
450
|
+
`/backtest/${backtestId}`,
|
|
451
451
|
options.betas,
|
|
452
452
|
"GET"
|
|
453
453
|
);
|
|
454
454
|
}
|
|
455
455
|
/**
|
|
456
|
-
* Poll a
|
|
456
|
+
* Poll a backtest job until it reaches a terminal status.
|
|
457
457
|
*/
|
|
458
|
-
async pollUntilFinished(
|
|
459
|
-
const pollInterval = options.pollInterval ??
|
|
460
|
-
const timeoutMs = options.timeoutMs ??
|
|
458
|
+
async pollUntilFinished(backtestId, options) {
|
|
459
|
+
const pollInterval = options.pollInterval ?? DEFAULT_BACKTEST_POLL_INTERVAL_MS;
|
|
460
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_BACKTEST_POLL_TIMEOUT_MS;
|
|
461
461
|
const startTime = Date.now();
|
|
462
462
|
while (true) {
|
|
463
|
-
const
|
|
464
|
-
if (
|
|
465
|
-
return
|
|
463
|
+
const backtest = await this.get(backtestId, { betas: options.betas });
|
|
464
|
+
if (backtest.status !== "running") {
|
|
465
|
+
return backtest;
|
|
466
466
|
}
|
|
467
467
|
if (Date.now() - startTime > timeoutMs) {
|
|
468
468
|
throw new Error(
|
|
469
|
-
`Polling timeout: Agent monitor
|
|
469
|
+
`Polling timeout: Agent monitor backtest ${backtestId} did not complete within ${timeoutMs}ms`
|
|
470
470
|
);
|
|
471
471
|
}
|
|
472
472
|
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
473
473
|
}
|
|
474
474
|
}
|
|
475
475
|
/**
|
|
476
|
-
* Start a
|
|
477
|
-
*
|
|
476
|
+
* Start a backtest and wait for its result. Throws
|
|
477
|
+
* AgentMonitorBacktestFailedError if the backtest fails.
|
|
478
478
|
*/
|
|
479
479
|
async createAndWait(params, options) {
|
|
480
|
-
const
|
|
481
|
-
const
|
|
480
|
+
const backtest = await this.create(params);
|
|
481
|
+
const terminalBacktest = backtest.status === "running" ? await this.pollUntilFinished(backtest.id, {
|
|
482
482
|
...options,
|
|
483
483
|
betas: params.betas
|
|
484
|
-
}) :
|
|
485
|
-
if (
|
|
486
|
-
throw new
|
|
484
|
+
}) : backtest;
|
|
485
|
+
if (terminalBacktest.status === "failed") {
|
|
486
|
+
throw new AgentMonitorBacktestFailedError(terminalBacktest);
|
|
487
487
|
}
|
|
488
|
-
return
|
|
488
|
+
return terminalBacktest;
|
|
489
489
|
}
|
|
490
490
|
};
|
|
491
491
|
var AgentMonitorsClient = class extends AgentMonitorsBaseClient {
|
|
@@ -493,7 +493,7 @@ var AgentMonitorsClient = class extends AgentMonitorsBaseClient {
|
|
|
493
493
|
super(client);
|
|
494
494
|
this.entities = new AgentMonitorEntitiesClient(client);
|
|
495
495
|
this.changes = new AgentMonitorChangesClient(client);
|
|
496
|
-
this.
|
|
496
|
+
this.backtests = new AgentMonitorBacktestsClient(client);
|
|
497
497
|
}
|
|
498
498
|
/**
|
|
499
499
|
* Create an Agent Monitor from its entities, fields, and cadence.
|
|
@@ -3390,10 +3390,10 @@ var index_default = Exa2;
|
|
|
3390
3390
|
AGENT_MONITORS_BETA_HEADER,
|
|
3391
3391
|
AgentBetaClient,
|
|
3392
3392
|
AgentClient,
|
|
3393
|
+
AgentMonitorBacktestFailedError,
|
|
3394
|
+
AgentMonitorBacktestsClient,
|
|
3393
3395
|
AgentMonitorChangesClient,
|
|
3394
3396
|
AgentMonitorEntitiesClient,
|
|
3395
|
-
AgentMonitorSnapshotFailedError,
|
|
3396
|
-
AgentMonitorSnapshotsClient,
|
|
3397
3397
|
AgentMonitorsClient,
|
|
3398
3398
|
AgentRunCancelledError,
|
|
3399
3399
|
AgentRunEventsClient,
|