import { type ModelDescriptor, type PlacementInput } from "@opengeni/subscriptions"; import { type Database } from "../database.js"; import { type SubscriptionSessionBinding } from "../subscription-core-repository.js"; import { type SubscriptionCoreProvider } from "./provider.js"; import { type SubscriptionCoreTurnIdentity } from "./turns.js"; /** Trusted executable catalog from the caller's deployment configuration. * Tier declarations are read from the registered adapter, not caller guesses. */ export type SubscriptionCoreFailoverModel = ModelDescriptor & { upstreamModelId: string; }; export type SubscriptionCoreFailoverWorldRequest = { identity: SubscriptionCoreTurnIdentity; productModelId: string; reasoningLevel: string; models: readonly SubscriptionCoreFailoverModel[]; crossProviderFailoverEnabled?: boolean; quotaStaleAfterMs?: Readonly>; now?: Date; }; export type SubscriptionCoreFailoverWorld = { input: PlacementInput; providers: ReadonlyMap; bindings: ReadonlyMap; serving: { provider: string; modelId: string; thisTurn: boolean; }; candidateProviders: string[]; noModelMapping: boolean; }; /** Mapping is catalog/configuration, not live readiness, capacity or authority. * A configured empty order intentionally disables fallback. Mapped but denied * targets keep their existing policy/authority diagnostic, never "no mapping". */ export declare function missingCrossProviderModelMapping(input: PlacementInput): boolean; export declare function policyBinding(binding: SubscriptionSessionBinding | null): PlacementInput["session"]["binding"]; /** C1 is the only serving metadata reader. A previous turn with no receipt * ends continuity; never search further back for a more convenient fallback. */ export declare function readSubscriptionCoreServingContinuity(tx: Database, identity: SubscriptionCoreTurnIdentity, homeProvider: string, acceptedModel: string, models: readonly SubscriptionCoreFailoverModel[]): Promise; /** Parity copy of turns.ts until the M4 stacks can share this read. */ export declare function readLastContextReplacedAt(tx: Database, identity: SubscriptionCoreTurnIdentity): Promise; /** D-33/D-46 world. All binding locks precede every connection lock. The * callback may acquire ONE lease, but must NEVER call a serving/pending/event * writer: its turn UPDATE fence inverts reservation's turn SHARE -> binding * order. Those writes belong in a separate transaction after this commits. */ export declare function withSubscriptionCoreFailoverPlacementWorld(db: Database, home: SubscriptionCoreProvider, request: SubscriptionCoreFailoverWorldRequest, lockBindings: boolean, operation: (tx: Database, world: SubscriptionCoreFailoverWorld) => Promise): Promise<{ status: "home_only"; } | { status: "not_visible"; } | { status: "completed"; value: T; }>;