import type { DecisionAdmissionEstimate, DecisionAdmissionEvidence, DecisionAdmissionLimits, DecisionBreakerTransition, DecisionSchedulerPolicy } from './types.js'; export interface AdmissionRequest { /** Stable invocation/budget scope supplied by the trusted host. */ budgetId: string; principalId: string; workspaceId: string; providerId: string; estimate: DecisionAdmissionEstimate; deadlineEpochMs: number; signal: AbortSignal; } export interface AdmissionLease { evidence: DecisionAdmissionEvidence; release(outcome?: { success: boolean; retryAfterMs?: number; }): void; } export declare class AdmissionError extends Error { readonly evidence: DecisionAdmissionEvidence; readonly retryable: boolean; constructor(evidence: DecisionAdmissionEvidence, retryable: boolean); } export interface AdmissionScopeLimits { principal: DecisionAdmissionLimits; workspace: DecisionAdmissionLimits; provider: DecisionAdmissionLimits; } /** Metadata-only breaker transition. The provider ID is an adapter lane, never a principal. */ export interface AdmissionBreakerTransitionRecord extends DecisionBreakerTransition { providerId: string; atEpochMs: number; failures: number; } export interface AdmissionControllerOptions { /** * Principals whose `reservedConcurrency` is held back from shared pools. The * registry supplies its registered principals; a bare controller otherwise * uses principals it has seen with a reservation. */ principals?: () => Iterable<[string, DecisionAdmissionLimits]>; onBreakerTransition?: (transition: AdmissionBreakerTransitionRecord) => void; } /** Shared, in-process controller. Hosts may share one instance across invocations. */ export declare class DecisionAdmissionController { /** Returns null when the trusted profile has no limits for the request's provider. */ private readonly limits; private readonly now; private readonly options; private active; private readonly activePrincipal; private readonly activeWorkspace; private readonly activeProvider; private readonly activePrincipalProvider; private readonly seenReservations; /** Oldest waiter deferred on each token bucket; later work cannot drain its share. */ private readonly tokenReservations; private readonly breakerHistory; private readonly requestBuckets; private readonly tokenBuckets; private readonly costSpent; private readonly tokensReserved; private readonly attempts; private readonly breakers; private readonly providerPausedUntil; private readonly queues; private laneCursor; private retryPressure; private timer; constructor( /** Returns null when the trusted profile has no limits for the request's provider. */ limits: (request: AdmissionRequest) => AdmissionScopeLimits | null, now?: () => number, options?: AdmissionControllerOptions); /** Host-only counts for load sampling; omitting a scope returns aggregate counts. */ snapshot(scope?: { principalId?: string; providerId?: string; }): { active: number; queued: number; }; /** Bounded, metadata-only breaker transition history, oldest first. */ breakerTransitions(): AdmissionBreakerTransitionRecord[]; /** True when no lease is active and no request is queued, optionally for one principal. */ idle(principalId?: string): boolean; acquire(request: AdmissionRequest): Promise; coordinateRetryAfter(providerId: string, retryAfterMs: number): void; /** Release invocation-scoped counters once every active lease has settled. */ releaseBudget(budgetId: string): void; private preflight; private pump; private tryAdmit; private transition; /** * Other principals' unused `reservedConcurrency` is held back from a shared * pool. A principal still inside its own reservation needs one free permit. */ private withinReservations; private breaker; private queuedCount; private increment; private decrement; private canConsume; private consume; private refill; private remove; private evidence; private error; private jitterHint; private schedulePump; } /** A scheduler profile the registry refuses; the evaluator reports it as an invalid definition. */ export declare class AdmissionProfileError extends Error { } export declare class AdmissionProfileConflictError extends AdmissionProfileError { constructor(); } /** * Audit record for a change of a workspace's current profile revision. It holds * the trusted workspace ID and content digests only, never limits or inputs, and * is meant for the host's audit log rather than for metric labels. */ export interface AdmissionProfileChangeRecord { schema: 'decision-admission-profile-change/v1'; workspaceId: string; kind: 'initial' | 'change' | 'rollback'; previousProfileVersion: string | null; profileVersion: string; /** sha256 over the canonical workspace and provider limits of the new revision. */ digest: string; atEpochMs: number; } /** * Trusted-scope controller registry. Admission state is keyed by the host's * workspace ID, not by the identity of the policy object, so structurally equal * policies built per request share principal, workspace, and provider ceilings. * * The most recently registered `profileVersion` supplies the current limits for * a workspace (queued work is revalidated against it). Registering different * limits under a revision already seen for the same scope fails closed: a * changed profile must carry a new `profileVersion`. Every change of revision * produces an audit record. */ export declare class DecisionAdmissionRegistry { private readonly maxIdleScopes; private readonly scopes; private readonly profileListeners; private readonly breakerListeners; constructor(maxIdleScopes?: number); /** Record the policy as the workspace's current profile and return its controller. */ register(policy: DecisionSchedulerPolicy, now?: () => number): DecisionAdmissionController; /** The workspace's controller, registering the policy only when the scope is unknown. */ controllerFor(policy: DecisionSchedulerPolicy, now?: () => number): DecisionAdmissionController; controller(workspaceId: string): DecisionAdmissionController | undefined; /** Bounded audit history of profile revisions for one workspace, oldest first. */ profileHistory(workspaceId: string): AdmissionProfileChangeRecord[]; /** Subscribe to profile-change audit records. Returns an unsubscribe function. */ onProfileChange(listener: (record: AdmissionProfileChangeRecord) => void): () => void; /** Subscribe to breaker transitions in every workspace scope. Returns an unsubscribe function. */ onBreakerTransition(listener: (transition: AdmissionBreakerTransitionRecord) => void): () => void; private scopeFor; private controllerOf; private remember; } /** Process-wide registry used by the evaluator. */ export declare const decisionAdmissionRegistry: DecisionAdmissionRegistry; //# sourceMappingURL=admission.d.ts.map