/** * Serializes local inference with interactive work ahead of background work and FIFO order * within each lane. Background admission has an explicit wait deadline; expiry occurs before * native work is enqueued. Active decoding is never preempted, and scheduling budgets never * cap model input or output. */ import type { LocalInferencePriority } from "../types/model.js"; /** * Device RAM class used by inference admission policy; hosts supply the probe result. */ export type InferenceRamClass = "constrained" | "standard"; /** * Parses ELIZA_INFERENCE_RAM_CLASS. Unset or invalid values return null so callers can apply * their probe or standard policy. */ export declare function inferenceRamClassFromEnv(env?: NodeJS.ProcessEnv): InferenceRamClass | null; /** * Per-class queue-wait policy for background-priority generation on the single * local lane. It prevents stale scheduled work from piling up without changing * the generation request once the lane is acquired. */ export interface BackgroundInferenceBudget { /** Bounded gate wait before the background request fails without running. */ lockWaitMs: number; } /** Resolve the background generation budget for a device RAM class. */ export declare function resolveBackgroundInferenceBudget(ramClass: InferenceRamClass): BackgroundInferenceBudget; /** Preserves the full background generation request. Device scheduling governs queue admission and never caps model output. */ export declare function applyBackgroundInferenceBudget(args: { prompt: string; maxTokens: number | undefined; }, _budget: BackgroundInferenceBudget): { prompt: string; maxTokens: number | undefined; clamped: string[]; }; /** * Thrown when a background acquisition cannot start within its wait budget. * The request never reached the native lane; the scheduled-task layer's * failure/backoff path handles the re-fire. */ export declare class InferenceBackgroundWaitTimeoutError extends Error { readonly code = "INFERENCE_BACKGROUND_WAIT_TIMEOUT"; constructor(waitedMs: number, holder: string | null); } export interface InferencePriorityGateOptions { now?: () => number; logger?: { info: (msg: string) => void; warn: (msg: string) => void; }; } export interface InferencePriorityGateSnapshot { held: boolean; holderPriority: LocalInferencePriority | null; holderLabel: string | null; holderHeldMs: number; interactiveWaiting: number; backgroundWaiting: number; } export interface RunExclusiveOptions { priority: LocalInferencePriority; /** * Bounded wait for background requests, ms. Ignored for interactive * requests (their own transport timeout governs the total). */ waitMs?: number; /** Abort while WAITING dequeues the request; in-flight work is not cancelled here. */ signal?: AbortSignal; /** Short label for lock telemetry (e.g. "TEXT_LARGE", "bionic-generate"). */ label?: string; } /** * Two-lane priority lock for the single local inference lane. See module doc. */ export declare class InferencePriorityGate { private readonly now; private readonly logger; private holder; private readonly interactiveQueue; private readonly backgroundQueue; constructor(opts?: InferencePriorityGateOptions); snapshot(): InferencePriorityGateSnapshot; /** * Run `fn` while holding the lane. Interactive requests wait indefinitely * (FIFO among themselves, always ahead of background); background requests * start only when the lane is idle with no interactive waiter, and fail * with {@link InferenceBackgroundWaitTimeoutError} after `waitMs`. */ runExclusive(opts: RunExclusiveOptions, fn: () => Promise): Promise; private acquire; private removeWaiter; private release; } export declare function getInferencePriorityGate(): InferencePriorityGate;