feat(research): run retained strategies through durable canonical engine

This commit is contained in:
Boki 2026-10-23 21:59:09 -04:00
parent d929db707a
commit 618fb9e33c
58 changed files with 6596 additions and 779 deletions

View file

@ -1,3 +1,8 @@
import type {
CanonicalDatasetCatalogEntry,
CanonicalRunCapability,
ResearchRunResult,
} from '@stock-bot/stock-config/canonical-research';
import type {
BacktestRunDatasetSelection,
BacktestRunResult,
@ -58,6 +63,7 @@ export interface CreateRunRequest {
}
export type RunResult = BacktestRunResult;
export type { ResearchRunResult };
export class RunResultsUnavailableError extends Error {
constructor() {
@ -79,6 +85,38 @@ async function requestError(response: Response, fallback: string): Promise<Error
}
export const backtestApiV2 = {
async canonicalCapability(id: string, signal?: AbortSignal): Promise<CanonicalRunCapability> {
const response = await fetch(
`${API_BASE_URL}/api/v2/backtests/${encodeURIComponent(id)}/canonical-capability`,
{ signal }
);
if (!response.ok) {
throw await requestError(response, 'Could not check canonical execution eligibility');
}
return response.json();
},
async listCanonicalDatasets(signal?: AbortSignal): Promise<CanonicalDatasetCatalogEntry[]> {
const response = await fetch(`${API_BASE_URL}/api/v2/datasets/canonical?limit=50&offset=0`, {
signal,
});
if (!response.ok) {
throw await requestError(response, 'Could not load canonical datasets');
}
return (await response.json()).datasets;
},
async canonicalDataset(
hash: string,
signal?: AbortSignal
): Promise<CanonicalDatasetCatalogEntry> {
const response = await fetch(
`${API_BASE_URL}/api/v2/datasets/canonical/${encodeURIComponent(hash)}`,
{ signal }
);
if (!response.ok) {
throw await requestError(response, 'Could not load canonical dataset');
}
return (await response.json()).dataset;
},
async listDatasets(
limit = 50,
offset = 0,
@ -229,7 +267,7 @@ export const backtestApiV2 = {
return response.json();
},
async getRunResults(runId: string, signal?: AbortSignal): Promise<RunResult> {
async getRunResults(runId: string, signal?: AbortSignal): Promise<ResearchRunResult> {
const response = await fetch(`${API_BASE_URL}/api/v2/runs/${runId}/results`, { signal });
if (response.status === 404) {