import { type Settings } from "@opengeni/config"; import { CodexAppsCredentialUnavailable, refreshCodexToken } from "@opengeni/codex"; import { type Database } from "./database.js"; import { reserveSubscriptionCoreCodexAppsRequest, settleSubscriptionCoreCodexAppsRequest } from "./subscription-core-codex-requests.js"; /** The designated core connection is no longer usable for Apps. */ export declare class SubscriptionCoreCodexAppsUnavailableError extends CodexAppsCredentialUnavailable { constructor(message?: string); } export type SubscriptionCoreCodexAppsDesignation = { connectionId: string; /** Connection health; only `active` can serve Apps requests. */ status: string; }; /** * The workspace's usable core Apps designation: the designation still names a * shared Codex connection in the workspace's scope, and the cutover is * enabled. Never returns credential material. */ export declare function resolveSubscriptionCoreCodexAppsDesignation(db: Database, input: { accountId: string; workspaceId: string; }): Promise; /** The legacy `CodexAppsSettings` projection of the core designation row. */ export type SubscriptionCoreCodexAppsSettings = { credentialId: string | null; version: number; designatedAt: Date | null; }; export declare function getSubscriptionCoreCodexAppsSettings(db: Database, input: { accountId: string; workspaceId: string; }): Promise; export type DesignateSubscriptionCoreCodexAppsResult = ({ kind: "updated"; } & SubscriptionCoreCodexAppsSettings) | ({ kind: "conflict" | "already_designated"; } & SubscriptionCoreCodexAppsSettings) | { kind: "not_found"; } | { kind: "forbidden"; } | { kind: "unavailable"; }; /** * Designate a shared Codex connection for Apps. Authorization is the * designation table's own policy: an organization administrator, or a * workspace administrator for a connection this workspace manages; the * connection must be active and in the workspace's scope. Legacy account ids * resolve through aliases first. */ export declare function designateSubscriptionCoreCodexApps(db: Database, input: { accountId: string; workspaceId: string; connectionId: string; subjectId: string; expectedVersion: number; }): Promise; export type ClearSubscriptionCoreCodexAppsResult = { kind: "updated" | "unchanged" | "conflict" | "forbidden"; } & SubscriptionCoreCodexAppsSettings; /** * Clear the designation, valid in any inference source mode. The core row is * deleted, so the projected version returns to 0 (no designation); the next * designation's version is greater than every earlier one (see designate). */ export declare function clearSubscriptionCoreCodexApps(db: Database, input: { accountId: string; workspaceId: string; subjectId: string; expectedVersion: number; }): Promise; type AppsTarget = { accountId: string; workspaceId: string; connectionId: string; }; export type SubscriptionCoreCodexAppsDeps = { refresh?: typeof refreshCodexToken; now?: () => Date; resolveToken?: () => Promise; reserveRequest?: typeof reserveSubscriptionCoreCodexAppsRequest; settleRequest?: typeof settleSubscriptionCoreCodexAppsRequest; }; /** * Bearer for the designated core connection: the stored token while fresh, * otherwise one refresh per connection and generation in this process (the * advisory key serializes other replicas). */ export declare function buildSubscriptionCoreCodexAppsTokenResolver(db: Database, settings: Settings, target: AppsTarget, deps?: SubscriptionCoreCodexAppsDeps): () => Promise<{ accessToken: string; chatgptAccountId: string | null; }>; type SubscriptionCoreCodexAppsToken = { accessToken: string; chatgptAccountId: string | null; }; export type SubscriptionCoreCodexAppsRequestAuth = { clientVersion: string; withAuthorization: (use: (token: SubscriptionCoreCodexAppsToken) => Promise) => Promise; /** The runtime must put its physical fetch inside this callback, not extract a bearer. */ withRequest: (use: (token: SubscriptionCoreCodexAppsToken) => Promise, options?: { signal?: AbortSignal | null | undefined; }) => Promise; }; /** * Runtime Apps authentication for one core designation. Physical requests use * withRequest, whose native reservation atomically checks the designation and * disconnect fence before dispatch. withAuthorization is an access-only check; * its callback is not a physical request permit. */ export declare function subscriptionCoreCodexAppsRequestAuth(db: Database, settings: Settings, target: AppsTarget, deps?: SubscriptionCoreCodexAppsDeps): SubscriptionCoreCodexAppsRequestAuth; export {};