import type { Run, RunFeedback, RunQuery, RunTree, TraceStore } from '../types/tracing.js'; import { applyQuery, assembleTree, isAfterCursor, runCursor } from './query.js'; export { applyQuery, assembleTree, isAfterCursor, runCursor }; /** Options for the in-memory trace store. */ export interface MemoryTraceStoreOptions { /** Runs kept before the oldest is dropped. Defaults to 10,000. */ maxRuns?: number; } /** * Traces in process memory. * * Enough for development, tests, and a single-process service that only needs the last few thousand * runs. Bounded, like every other in-memory store here. */ export declare class MemoryTraceStore implements TraceStore { /** Not durable: its runs live only in this process. */ readonly durable = false; private readonly runs; private readonly maxRuns; constructor(options?: MemoryTraceStoreOptions); /** * Stores a run, replacing an earlier version with the same id. Drops the oldest runs beyond * `maxRuns`. */ save(run: Run): void; /** Reads a run. */ get(runId: string): Run | undefined; /** Runs matching a query. */ query(query?: RunQuery): Run[]; /** A trace's runs, assembled into a tree. */ tree(traceId: string): RunTree | undefined; /** Attaches feedback to a run. */ addFeedback(runId: string, feedback: RunFeedback): void; /** Deletes runs started before an ISO-8601 time, returning how many went. */ prune(before: string): number; /** Runs held. */ size(): number; } /** Options for `closeAbandonedRuns()`. */ export interface CloseAbandonedRunsOptions { /** A run still running after this long is taken to belong to a process that ended. */ olderThanMs: number; /** Replaces the system clock, for tests. */ now?: () => Date; } /** * Closes runs a process left running when it ended, so a crash shows as a failure rather than as * work that is still going. * * Only a tracer with `incremental` writes a run before it finishes, so only its runs can be left * behind. Each one older than `olderThanMs` is saved as an error named `RunAbandoned`, with * `metadata.abandoned`, keeping everything it recorded. Call it when a worker starts, or on a * schedule. Returns how many runs it closed. */ export declare function closeAbandonedRuns(store: TraceStore, options: CloseAbandonedRunsOptions): Promise; /** Options for the JSONL trace store. */ export interface JsonlTraceStoreOptions { /** File runs are appended to, one JSON object per line. */ file: string; /** Rewrites the file when it grows past this, keeping the newest runs. Defaults to 64 MB. */ maxBytes?: number; } /** * Traces appended to a JSONL file. * * Durable without a database, greppable with ordinary tools, and directly loadable as an evaluation * dataset. Reads load the file, so this suits a service that writes far more than it queries; a * database-backed store is the answer above that. */ export declare class JsonlTraceStore implements TraceStore { private readonly file; private readonly maxBytes; constructor(options: JsonlTraceStoreOptions); /** Appends a run. Rewrites the file, keeping the newer half, once it passes `maxBytes`. */ save(run: Run): Promise; /** Reads a run. */ get(runId: string): Promise; /** Runs matching a query. */ query(query?: RunQuery): Promise; /** A trace's runs, assembled into a tree. */ tree(traceId: string): Promise; /** Attaches feedback to a run by appending its updated version. */ addFeedback(runId: string, feedback: RunFeedback): Promise; /** * Deletes runs started before an ISO-8601 time by rewriting the file, returning how many went. */ prune(before: string): Promise; /** A later line for the same run replaces an earlier one, which is what makes appends safe. */ private load; private rotate; }