SPB Git

Repository Public MIT

types.ts 14.2 KB 312 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : VQuant8 * File             : client/src/lib/research/types.ts9 * Module           : lib10 * Repository       : https://git.spboucher.ai/vquant11 * Project Website  : https://vquant.spboucher.ai12 * Created          : 2026-11-2013 * Last Modified    : 2026-11-2014 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * SPDX Identifier  : MIT34 * License          : MIT License35 * License File     : LICENSE36 *37 * Do not embed credentials, private keys, access tokens,38 * certificates or confidential personal information.39 *40 * =============================================================================41 * END OF SP BOUCHER SOURCE HEADER42 * =============================================================================43 */4445/**46 * Types of the autonomous-research view (CONTRACT §9).47 *48 * Two sources feed ONE view model (`ResearchState`):49 *   - the generation stream (`reduceResearch` in ./reducer) while a study runs or is replayed;50 *   - the research REST + the stored conversation (`stateFromSnapshot` in ./snapshot) once it is over.51 * Components only read `ResearchState`; they never look at raw events or REST payloads.52 */5354/**55 * A stream event (`/api/chat`, `/api/generations/:id/stream`). Unknown types are ignored by the reducer.56 * Every event written by a generation carries `at`, the server time in epoch ms (only `job` has none).57 */58export interface StreamEvent { type: string; at?: number; [key: string]: unknown }5960export type ExecutionStatus = "running" | "ok" | "failed" | "timeout" | "killed" | "interrupted";61export type ExperimentStatus = ExecutionStatus | "inconclusive" | "abandoned";62export type RunStatus = "running" | "done" | "failed" | "timeout" | "killed" | "cancelled" | "interrupted";63export type ApprovalStatus = "pending" | "approved" | "denied" | "expired";64export type ApprovalAction = "open_network" | "send_data" | "raise_budget" | "other";6566export interface PlanStep { title: string; status: "pending" | "in_progress" | "done" }6768export interface DatasetRef { path: string; rows: number | null; columns: number | null; bytes: number | null }6970export interface FileChange { action: "write" | "patch" | "delete" | "library"; path: string; bytes: number | null; agent: string | null }7172/** One notebook cell the agent executed (successful or not). */73export interface Execution {74  /** stable key inside the view: the ledger id when known, a local counter before that */75  key: string;76  /** ledger id (`experimentId` of the event, `id` of the REST entry) */77  id: string | null;78  seq: number | null;79  agent: string;80  title: string | null;81  codeHash: string | null;82  /** workspace path of the code (`logs/cells/<hash>.py`) */83  codePath: string | null;84  /** the code itself when the stream carried it (tool_start); otherwise it is fetched from `codePath` */85  code: string | null;86  lines: number | null;87  status: ExecutionStatus;88  durationMs: number | null;89  error: string | null;90  /** console output (stream `tool_result`, or the stored conversation); null = not kept */91  output: string | null;92  envHash: string | null;93  generationId: string | null;94  startedAt: number | null;95  /** stream id of the tool call, to pair `tool_start` / `tool_error` / `tool_result` */96  toolId: string | null;97  figureKeys: string[];98}99100export interface Run {101  id: string;102  label: string | null;103  /** workspace path of the script */104  code: string | null;105  codeHash: string | null;106  args: string[];107  status: RunStatus;108  progress: number | null;109  exitCode: number | null;110  error: string | null;111  network: "default" | "open";112  startedAt: number | null;113  finishedAt: number | null;114  generationId: string | null;115}116117export interface Experiment {118  id: string;119  seq: number | null;120  title: string;121  hypothesis: string | null;122  method: string | null;123  status: ExperimentStatus;124  metrics: Record<string, unknown> | null;125  diagnostics: unknown;126  artifacts: string[];127  codeRef: string | null;128  runId: string | null;129  codeHash: string | null;130  /** the agent's own account of the entry: the reason of a failed / inconclusive / abandoned experiment is here */131  notes: string | null;132  error: string | null;133  envHash: string | null;134  generationId: string | null;135  startedAt: number | null;136  finishedAt: number | null;137  durationMs: number | null;138}139140export type NoteKind = "dataset" | "model" | "decision" | "implementation" | "failure" | "hypothesis" | "finding" | "workflow";141export interface Note { id: string; kind: NoteKind | string; title: string; body: string; createdAt: number | null }142143export interface LintIssue { code: string; severity: "info" | "warning" | "error" | string; message: string; fixed: boolean }144145/** Verdict of the visual linter: nothing to say, repaired by itself (the usual case), or a defect is left. */146export type LintStatus = "passed" | "fixed" | "issues";147148export interface Figure {149  key: string;150  title: string | null;151  /** the title drawn on the figure: the text the report uses under it */152  caption: string | null;153  /** linter verdict; null only for a study recorded before verdicts were stored */154  status: LintStatus | null;155  /** repaired automatically */156  fixes: LintIssue[];157  /** left as they are (information-level ones included) */158  findings: LintIssue[];159  /** stream id of the cell that drew it, and its position among that cell's figures */160  toolId: string | null;161  at: number | null;162  /** workspace paths of the durable exports */163  files: { png?: string; svg?: string; pdf?: string } | null;164  /** address of the image as served to the report (`/figures/…png`) */165  url: string | null;166  execKey: string | null;167  generationId: string | null;168}169170export interface Approval {171  id: string;172  action: ApprovalAction | string;173  reason: string | null;174  detail: Record<string, unknown> | null;175  status: ApprovalStatus;176  createdAt: number | null;177  resolvedAt: number | null;178}179180export interface GateFinding { id: string; severity: "info" | "warning" | "error" | string; finding: string; evidence: string | null }181export interface QualityGate { generationId: string | null; passed: boolean; findings: GateFinding[] }182183export interface PackageInstall { key: string; spec: string; ok: boolean }184185export type TimelineKind = "workspace" | "dataset" | "plan" | "file" | "execution" | "install" | "run" | "experiment" | "note" | "figure" | "approval" | "gate" | "budget";186/** One entry of the activity feed. It points at an entity of the state by key, so an update re-renders in place. */187export interface TimelineItem {188  /** unique and stable: `<kind>:<ref>` */189  key: string;190  kind: TimelineKind;191  ref: string;192  /** epoch ms when the server said it; null when the stream gave no time (never invented) */193  at: number | null;194  generationId: string | null;195}196197export interface BudgetHit { kind: "cost" | "minutes" | string; spent: number; limit: number }198/** The limits in force for a generation and where they come from (`budget_applied`, CONTRACT §2.4). */199export interface BudgetApplied { maxCostUsd: number | null; maxMinutes: number | null; source: "request" | "preference" | "default" | string }200/** One analysis run in the workspace (REST `generations`). `interrupted` = cut by a server restart. */201export interface GenerationInfo { generationId: string; status: "running" | "done" | "error" | "cancelled" | "interrupted" | string; startedAt: number | null; finishedAt: number | null; mode: string | null; model: string | null; budgetApplied: BudgetApplied | null }202203export interface ResearchState {204  /** highest stream index applied (-1 before the first); events at or below it are ignored (replay from N) */205  lastIndex: number;206  workspace: { id: string; kind: "session" | "project" | string } | null;207  generationId: string | null;208  sessionId: string | null;209  /** the question of the study */210  objective: string | null;211  plan: PlanStep[];212  /** how many times the agent rewrote its plan */213  planRevisions: number;214  datasets: DatasetRef[];215  files: FileChange[];216  executions: Execution[];217  installs: PackageInstall[];218  runs: Run[];219  experiments: Experiment[];220  notes: Note[];221  figures: Figure[];222  approvals: Approval[];223  gates: QualityGate[];224  budgetHits: BudgetHit[];225  /** limits of the generation on screen (or of the latest one of a reopened study); null before the server said */226  budgetApplied: BudgetApplied | null;227  /** the analyses run in the workspace, oldest first (a reopened study) */228  generations: GenerationInfo[];229  timeline: TimelineItem[];230  /** the generation ended (done or error) */231  finished: boolean;232  /** internal counters and pairing memory of the reducer */233  counter: number;234  /** only for streams recorded before `tool_result` carried its `toolId` */235  lastCompletedToolId: string | null;236}237238// ─── REST payloads (`/api/v2/research/*`) ────────────────────────────────────239240export interface RestSession { id: string; kind: "session" | "project" | string; ref: string; title: string | null; createdAt: number; updatedAt: number; sessionIds: string[] }241export interface RestFile { path: string; type: "file" | "dir" | string; bytes: number; modifiedAt: number }242export interface RestExperiment {243  id: string; workspaceId?: string; sessionId?: string | null; generationId?: string | null; seq: number; kind: "experiment" | "execution";244  title: string | null; hypothesis: string | null; method: string | null; codeRef: string | null; codeHash: string | null; envHash: string | null;245  runId: string | null; status: ExperimentStatus; metrics: Record<string, unknown> | null; diagnostics: unknown; artifacts: string[] | null;246  notes: string | null; error: string | null; startedAt: number | null; finishedAt: number | null; durationMs: number | null;247}248export interface RestRun {249  id: string; workspaceId?: string; sessionId?: string | null; generationId?: string | null; label: string | null; codeRef?: string | null; code?: string | null;250  codeHash?: string | null; args?: string[]; network?: "default" | "open"; status: RunStatus; pid?: number | null; progress: number | null; exitCode: number | null;251  error: string | null; startedAt: number | null; finishedAt: number | null;252}253export interface RestNote { id: string; kind: string; title: string; body: string; sessionId?: string | null; createdAt?: number; updatedAt?: number }254export interface RestLibraryEntry { name: string; description: string | null; savedAt: number; sha256: string; bytes: number; exports: string[] }255export interface RestEnvironment { hash: string | null; packages: number | null; overlay: string[]; lockfile: string | null }256export interface RestFigure {257  id: string; generationId?: string | null; sessionId?: string | null; toolId?: string | null; at?: number | null; title: string | null; caption: string | null; url: string | null;258  files: { png?: string; svg?: string; pdf?: string } | null; status: LintStatus; fixes: LintIssue[]; findings: LintIssue[]; codeHash?: string | null;259}260export interface RestGeneration {261  generationId: string; sessionId?: string | null; status: string; startedAt: number | null; finishedAt: number | null; mode?: string | null; model?: string | null;262  plan?: PlanStep[] | null; budgetApplied?: BudgetApplied | null; budget?: BudgetHit[] | null;263}264export interface RestApproval { id: string; action: string; reason: string | null; detail: Record<string, unknown> | null; status: ApprovalStatus; createdAt: number | null; resolvedAt: number | null }265export interface SessionDetail {266  session: RestSession;267  files: RestFile[];268  experiments: RestExperiment[];269  executions: RestExperiment[];270  runs: RestRun[];271  notes: RestNote[];272  library: RestLibraryEntry[];273  environment: RestEnvironment;274  approvals: RestApproval[];275  /** absent on a server older than the "reopening a study" contract */276  generations?: RestGeneration[];277  plan?: PlanStep[] | null;278  figures?: RestFigure[];279}280281export interface DatasetColumn {282  name: string; dtype: string; missing: number; missingShare: number; distinct?: number; examples?: unknown[];283  summary?: Record<string, number>; range?: [string, string]; parsesAsDate?: boolean; zeros?: number;284}285export interface DatasetInspection {286  path: string; format: string; bytes: number; rows: number; rowsProfiled?: number; truncated?: boolean; columnCount?: number;287  columns: DatasetColumn[]; duplicatedRows?: number; timeColumns?: string[]; memoryMb?: number;288  head?: Array<Record<string, unknown>> | unknown[][]; sheets?: string[];289}290291export interface SandboxStatus {292  sandbox: { enforced: boolean; mechanism: string | null; note: string | null };293  limits: { cpuSeconds?: number; memoryMb?: number; wallMs?: number; maxProcesses?: number; fileMb?: number; diskMb?: number } & Record<string, number | undefined>;294  network: { default: string[]; open: string };295  uploadMaxBytes: number;296}297298/** A message of a stored conversation (`GET /api/sessions/:id`), reduced to what the research view reads. */299export interface StoredMessage {300  question?: string;301  answer?: string;302  generationId?: string | null;303  toolResults?: Array<{ tool: string; result: unknown }> | null;304  customPythonFigures?: Array<{ id: string; figures?: string[]; figureUrls?: string[]; output?: string; description?: string }> | null;305  research?: {306    workspaceId: string;307    experiments?: Array<{ id: string; seq: number; title: string; status: ExperimentStatus; metrics: Record<string, unknown> | null; error: string | null }>;308    executions?: { total: number; failed: number };309    qualityGate?: GateFinding[] | null;310  } | null;311}312
Files main
Menu

Theme