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.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import fetch2, { Headers } from "cross-fetch";
|
|
|
4
4
|
// package.json
|
|
5
5
|
var package_default = {
|
|
6
6
|
name: "exa-js",
|
|
7
|
-
version: "2.22.
|
|
7
|
+
version: "2.22.1",
|
|
8
8
|
description: "Exa SDK for Node.js and the browser",
|
|
9
9
|
publishConfig: {
|
|
10
10
|
access: "public"
|
|
@@ -214,13 +214,13 @@ var AgentMonitorsBaseClient = class {
|
|
|
214
214
|
};
|
|
215
215
|
|
|
216
216
|
// src/agent/monitors/client.ts
|
|
217
|
-
var
|
|
218
|
-
var
|
|
219
|
-
var
|
|
220
|
-
constructor(
|
|
221
|
-
super(
|
|
222
|
-
this.name = "
|
|
223
|
-
this.
|
|
217
|
+
var DEFAULT_BACKTEST_POLL_INTERVAL_MS = 2e3;
|
|
218
|
+
var DEFAULT_BACKTEST_POLL_TIMEOUT_MS = 60 * 60 * 1e3;
|
|
219
|
+
var AgentMonitorBacktestFailedError = class extends Error {
|
|
220
|
+
constructor(backtest) {
|
|
221
|
+
super(backtest.error ?? `Agent monitor backtest ${backtest.id} failed`);
|
|
222
|
+
this.name = "AgentMonitorBacktestFailedError";
|
|
223
|
+
this.backtest = backtest;
|
|
224
224
|
}
|
|
225
225
|
};
|
|
226
226
|
var AgentMonitorEntitiesClient = class extends AgentMonitorsBaseClient {
|
|
@@ -330,66 +330,66 @@ var AgentMonitorChangesClient = class extends AgentMonitorsBaseClient {
|
|
|
330
330
|
return changes;
|
|
331
331
|
}
|
|
332
332
|
};
|
|
333
|
-
var
|
|
333
|
+
var AgentMonitorBacktestsClient = class extends AgentMonitorsBaseClient {
|
|
334
334
|
/**
|
|
335
|
-
* Start an async
|
|
336
|
-
*
|
|
337
|
-
*
|
|
335
|
+
* Start an async backtest of entities × fields over an explicit past news
|
|
336
|
+
* window. Returns a `running` job; poll with `get` (or use `createAndWait`)
|
|
337
|
+
* for the result.
|
|
338
338
|
*/
|
|
339
339
|
async create(params) {
|
|
340
340
|
const { betas, ...payload } = params;
|
|
341
341
|
return this.request(
|
|
342
|
-
"/
|
|
342
|
+
"/backtest",
|
|
343
343
|
betas,
|
|
344
344
|
"POST",
|
|
345
345
|
payload
|
|
346
346
|
);
|
|
347
347
|
}
|
|
348
348
|
/**
|
|
349
|
-
* Poll a
|
|
349
|
+
* Poll a backtest job for its status and, once completed, its result.
|
|
350
350
|
* Jobs expire and read as 404 after `expiresAt`.
|
|
351
351
|
*/
|
|
352
|
-
async get(
|
|
352
|
+
async get(backtestId, options) {
|
|
353
353
|
return this.request(
|
|
354
|
-
`/
|
|
354
|
+
`/backtest/${backtestId}`,
|
|
355
355
|
options.betas,
|
|
356
356
|
"GET"
|
|
357
357
|
);
|
|
358
358
|
}
|
|
359
359
|
/**
|
|
360
|
-
* Poll a
|
|
360
|
+
* Poll a backtest job until it reaches a terminal status.
|
|
361
361
|
*/
|
|
362
|
-
async pollUntilFinished(
|
|
363
|
-
const pollInterval = options.pollInterval ??
|
|
364
|
-
const timeoutMs = options.timeoutMs ??
|
|
362
|
+
async pollUntilFinished(backtestId, options) {
|
|
363
|
+
const pollInterval = options.pollInterval ?? DEFAULT_BACKTEST_POLL_INTERVAL_MS;
|
|
364
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_BACKTEST_POLL_TIMEOUT_MS;
|
|
365
365
|
const startTime = Date.now();
|
|
366
366
|
while (true) {
|
|
367
|
-
const
|
|
368
|
-
if (
|
|
369
|
-
return
|
|
367
|
+
const backtest = await this.get(backtestId, { betas: options.betas });
|
|
368
|
+
if (backtest.status !== "running") {
|
|
369
|
+
return backtest;
|
|
370
370
|
}
|
|
371
371
|
if (Date.now() - startTime > timeoutMs) {
|
|
372
372
|
throw new Error(
|
|
373
|
-
`Polling timeout: Agent monitor
|
|
373
|
+
`Polling timeout: Agent monitor backtest ${backtestId} did not complete within ${timeoutMs}ms`
|
|
374
374
|
);
|
|
375
375
|
}
|
|
376
376
|
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
379
|
/**
|
|
380
|
-
* Start a
|
|
381
|
-
*
|
|
380
|
+
* Start a backtest and wait for its result. Throws
|
|
381
|
+
* AgentMonitorBacktestFailedError if the backtest fails.
|
|
382
382
|
*/
|
|
383
383
|
async createAndWait(params, options) {
|
|
384
|
-
const
|
|
385
|
-
const
|
|
384
|
+
const backtest = await this.create(params);
|
|
385
|
+
const terminalBacktest = backtest.status === "running" ? await this.pollUntilFinished(backtest.id, {
|
|
386
386
|
...options,
|
|
387
387
|
betas: params.betas
|
|
388
|
-
}) :
|
|
389
|
-
if (
|
|
390
|
-
throw new
|
|
388
|
+
}) : backtest;
|
|
389
|
+
if (terminalBacktest.status === "failed") {
|
|
390
|
+
throw new AgentMonitorBacktestFailedError(terminalBacktest);
|
|
391
391
|
}
|
|
392
|
-
return
|
|
392
|
+
return terminalBacktest;
|
|
393
393
|
}
|
|
394
394
|
};
|
|
395
395
|
var AgentMonitorsClient = class extends AgentMonitorsBaseClient {
|
|
@@ -397,7 +397,7 @@ var AgentMonitorsClient = class extends AgentMonitorsBaseClient {
|
|
|
397
397
|
super(client);
|
|
398
398
|
this.entities = new AgentMonitorEntitiesClient(client);
|
|
399
399
|
this.changes = new AgentMonitorChangesClient(client);
|
|
400
|
-
this.
|
|
400
|
+
this.backtests = new AgentMonitorBacktestsClient(client);
|
|
401
401
|
}
|
|
402
402
|
/**
|
|
403
403
|
* Create an Agent Monitor from its entities, fields, and cadence.
|
|
@@ -3293,10 +3293,10 @@ export {
|
|
|
3293
3293
|
AGENT_MONITORS_BETA_HEADER,
|
|
3294
3294
|
AgentBetaClient,
|
|
3295
3295
|
AgentClient,
|
|
3296
|
+
AgentMonitorBacktestFailedError,
|
|
3297
|
+
AgentMonitorBacktestsClient,
|
|
3296
3298
|
AgentMonitorChangesClient,
|
|
3297
3299
|
AgentMonitorEntitiesClient,
|
|
3298
|
-
AgentMonitorSnapshotFailedError,
|
|
3299
|
-
AgentMonitorSnapshotsClient,
|
|
3300
3300
|
AgentMonitorsClient,
|
|
3301
3301
|
AgentRunCancelledError,
|
|
3302
3302
|
AgentRunEventsClient,
|