/** * Durable inference queue ledger — store port + validation (3.0.0 foundation). * * One ledger file per shared inference resource. The ledger is the * cross-process scheduling authority: QUEUED requests are durable across * restart, RUNNING requests carry a fencing lease, and terminal requests are * folded into a bounded history ring with aggregate counters. * * The ledger NEVER contains prompts, message bodies, or credentials — only * correlation ids, estimates, and lifecycle metadata. The surrounding durable * AgentSession owns the virtualized context; a queued logical agent is cold, * not a duplicated hot prompt. */ import type { InferenceRequestRecord, InferenceRequestSummary } from "./types.js"; export declare const INFERENCE_LEDGER_SCHEMA_VERSION: 1; /** Bounded history ring size (terminal request summaries). */ export declare const INFERENCE_HISTORY_LIMIT = 1000; /** * Per-resource durable ledger. * * `running` and `queue` are ordered collections. `running` is ordered by slot * (index = slot). `queue` is kept in deterministic admission order; the * scheduler re-sorts on promotion using the deterministic priority comparator. */ export interface InferenceResourceLedger { schemaVersion: 1; resourceId: string; capacity: number; /** Running (admitted) requests. Length must equal busySlots. */ running: InferenceRequestRecord[]; /** Queued requests awaiting admission. */ queue: InferenceRequestRecord[]; /** Most-recent-first bounded terminal summaries. */ history: InferenceRequestSummary[]; /** Monotonic request sequence for deterministic tiebreak ids. */ nextSeq: number; /** Monotonic ownership epoch for slot leases. */ fencingToken: number; completedCount: number; cancelledCount: number; failedCount: number; interruptedCount: number; totalQueueWaitMs: number; totalInferenceMs: number; totalInputTokens: number; totalOutputTokens: number; maxQueueDepth: number; updatedAtMs: number; revision: number; } export type InferenceLedgerCreateResult = { status: "created"; } | { status: "idempotent"; ledger: InferenceResourceLedger; } | { status: "conflict"; error: string; }; export type InferenceLedgerLoadResult = { status: "ok"; ledger: InferenceResourceLedger; } | { status: "missing"; } | { status: "corrupt"; resourceId: string; diagnostic: string; }; export type InferenceLedgerMutation = { kind: "write"; next: InferenceResourceLedger; value: T; } | { kind: "noop"; value: T; }; export type InferenceLedgerMutateResult = { status: "ok"; value: T; } | { status: "missing"; } | { status: "corrupt"; resourceId: string; diagnostic: string; }; export interface InferenceQueueStore { readonly storeId: string; create(resourceId: string, ledger: InferenceResourceLedger): Promise; load(resourceId: string): Promise; mutate(resourceId: string, mutation: (current: InferenceResourceLedger) => InferenceLedgerMutation): Promise>; listResources(): Promise; } /** A resourceId is a path component; reject traversal/injection. */ export declare function isSafeResourceId(value: string): boolean; export declare function createEmptyInferenceLedger(options: { resourceId: string; capacity: number; now?: number; }): InferenceResourceLedger; /** * Validate an untrusted persisted ledger. Corruption is surfaced structurally * and never fabricated into a free slot or a completed inference. */ export declare function parseInferenceResourceLedger(value: unknown): { ok: true; ledger: InferenceResourceLedger; } | { ok: false; diagnostic: string; }; //# sourceMappingURL=inference-queue.d.ts.map