/** * SuperGrok (provider id `xai`) on the shared subscription core: the adapter * that supplies every SuperGrok-specific input to the provider-neutral * runtime (credential codec, OAuth refresh, relogin classification, health * policy, cache facts and capability flags), and the database binding. * * Core credential plaintext (the format the SuperGrok cutover maps legacy * rows to): `credential_encrypted` holds the same `encryptEnvironmentValue` * blob as the legacy `xai_subscription_credentials` table, whose plaintext is * the JSON object `{ version: 1, accessToken, refreshToken? }`. The legacy * shape also allowed `sessionToken` and `cookie`, which no writer ever * stored and no reader uses; the core format drops them. The stored * `credential_format` is `xai_oauth_v1`. `provider_account_id` is the token * identity subject (the bearer's `userId`); SuperGrok has no plan type. * * The binding is not in the provider registry until the SuperGrok drained * cutover adds the SQL registry row with it (design 5.3, X3): until then * every shared runtime refuses it, and the worker never reaches it without * the `xai` cutover receipt. */ import { refreshXaiToken, type XaiFetchLike, type XaiSubscriptionTokenSnapshot } from "@opengeni/xai-subscription"; import type { SubscriptionCoreAdapter, SubscriptionCoreConnectionBearer, SubscriptionQuota } from "@opengeni/subscriptions"; import type { SubscriptionCoreProvider } from "./subscription-core/provider.js"; /** SuperGrok's provider id on the shared core and in the legacy tables. */ export declare const SUBSCRIPTION_CORE_XAI_PROVIDER = "xai"; /** The `credential_format` of a SuperGrok connection: OAuth tokens, which renew. */ export declare const SUBSCRIPTION_CORE_XAI_CREDENTIAL_FORMAT = "xai_oauth_v1"; /** The id of SuperGrok's one quota window (its billing usage), wherever it is written. */ export declare const SUBSCRIPTION_CORE_XAI_QUOTA_WINDOW_ID = "billing"; /** How long a connection SuperGrok refused (forbidden) stays quarantined. */ export declare const SUBSCRIPTION_CORE_XAI_FORBIDDEN_QUARANTINE_MS: number; /** SuperGrok has no plan entitlements; kept equal to Codex for the shared health policy. */ export declare const SUBSCRIPTION_CORE_XAI_ENTITLEMENT_COOLDOWN_MS: number; /** A rate limit without a retry time rests as long as the legacy SuperGrok backpressure delay. */ export declare const SUBSCRIPTION_CORE_XAI_RATE_LIMIT_FALLBACK_MS: number; /** An exhausted connection without a reset is retried after an hour (the quota probe may clear it sooner). */ export declare const SUBSCRIPTION_CORE_XAI_EXHAUSTED_FALLBACK_MS: number; /** * Prompt-cache idle cut-off placement honours (D-30). xAI documents no cache * lifetime, so SuperGrok declares one hour on the same terms as Codex until a * measured cut-off exists: erring long costs some rotation balance, erring * short pays for a cache miss the provider would have avoided. */ export declare const SUBSCRIPTION_CORE_XAI_CACHE_IDLE_CUTOFF_MS: number; /** The decoded SuperGrok credential. */ export type SubscriptionCoreXaiTokens = { accessToken: string; /** Absent for a legacy row stored without one: it cannot renew and needs a new sign-in. */ refreshToken: string | null; }; export type SubscriptionCoreXaiAdapterDeps = { /** The OAuth token refresh call (tests inject a scripted upstream). */ refresh?: typeof refreshXaiToken; }; /** * The SuperGrok bearer of a core connection: the access token and the token * identity subject (`provider_account_id`), which every xAI request sends. */ export declare function subscriptionCoreXaiBearer(bearer: SubscriptionCoreConnectionBearer): XaiSubscriptionTokenSnapshot; /** An xAI request context over a core connection read or operation resolver. */ export declare function subscriptionCoreXaiRequestAuth(source: { getToken(): Promise>; refresh(): Promise>; }): { getToken: () => Promise; refresh: () => Promise; }; /** * The billing endpoint as one quota window (`billing`, the current credit * period) and, at 100 percent, quota exhaustion until the period ends. * Unknown billing is not evidence either way: no observation. */ export declare function decodeSubscriptionCoreXaiQuota(input: { response: unknown; observedAt: number; refreshGeneration: number; }): SubscriptionQuota | null; /** An xAI client's fetch over the core's custody fetch (fixed URLs only, never a Request). */ export declare function subscriptionCoreXaiFetch(fetchImpl: (input: string | URL, init?: RequestInit) => Promise): XaiFetchLike; /** Decode the stored plaintext; fixed texts, never echoing the plaintext. */ export declare function decodeSubscriptionCoreXaiCredential(plaintext: string): SubscriptionCoreXaiTokens; /** Encode a credential as the stored plaintext (the legacy v1 object, OAuth fields only). */ export declare function encodeSubscriptionCoreXaiCredential(tokens: SubscriptionCoreXaiTokens): string; export declare function subscriptionCoreXaiAdapter(deps?: SubscriptionCoreXaiAdapterDeps): SubscriptionCoreAdapter; /** SuperGrok's database binding on the shared core. */ export declare function subscriptionCoreXaiProvider(deps?: SubscriptionCoreXaiAdapterDeps): SubscriptionCoreProvider; /** The SuperGrok binding (the production refresh call). */ export declare const SUBSCRIPTION_CORE_XAI: SubscriptionCoreProvider;