/** * Claude (provider id `claude`) on the shared subscription core: the adapter * that supplies every Claude-specific input to the provider-neutral runtime * (credential codec for OAuth and setup tokens, OAuth refresh, relogin * classification, health policy, exact cache lifetime, capability flags), * the decoding of Claude usage into the shared quota model, and the database * binding. * * Core credential plaintext (the format the Claude cutover maps legacy rows * to): the same `ClaudeSubscriptionCredential` JSON object the legacy * `claude_subscription_credentials` table stores, * `{ version: 1, token, identity: { accountUuid, deviceId }, oauth? }`. A * credential with `oauth` has the format `claude_oauth_v1` and renews * through the OAuth refresh; one without it is a pasted setup token * (`claude_setup_token_v1`), which never renews: once Claude refuses it the * shared refresh marks the connection needs-relogin. The format is derived * from the decoded secret (`credential.format`) whenever the core decides * renewal; the stored `credential_format` column is informational only * (the cutover records `claude_oauth_v1` / `claude_setup_token_v1`, the * shared connect and reconnect writers record the envelope version `v1`) * and is never passed to `capabilitiesFor`. `provider_account_id` is * the Claude account UUID, else the `oauth:`/`setup:` HMAC id the writers * already derive; setup tokens report no email or plan. * * The binding is not in the provider registry until the Claude drained * cutover adds the SQL registry row with it (design 5.3, C3): until then * every shared runtime refuses it, and the worker never reaches it without * the `claude` cutover receipt. */ import { ClaudeSubscriptionCredential, type ClaudeUsageObservation } from "@opengeni/config"; import type { z } from "zod"; import type { SubscriptionCoreAdapter, SubscriptionQuota } from "@opengeni/subscriptions"; import type { SubscriptionCoreProvider } from "./subscription-core/provider.js"; /** Claude's provider id on the shared core and in the legacy tables. */ export declare const SUBSCRIPTION_CORE_CLAUDE_PROVIDER = "claude"; /** The credential format of an OAuth sign-in, which renews (derived from the decoded secret). */ export declare const SUBSCRIPTION_CORE_CLAUDE_OAUTH_FORMAT = "claude_oauth_v1"; /** The credential format of a pasted setup token, which never renews. */ export declare const SUBSCRIPTION_CORE_CLAUDE_SETUP_TOKEN_FORMAT = "claude_setup_token_v1"; /** Refresh this long before the OAuth token expires (the legacy resolver's margin). */ export declare const SUBSCRIPTION_CORE_CLAUDE_REFRESH_WINDOW_MS: number; /** An OAuth credential always records its expiry; this bounds one that somehow does not. */ export declare const SUBSCRIPTION_CORE_CLAUDE_REFRESH_FALLBACK_MS: number; /** Claude has no plan entitlements; kept equal to the other providers. */ export declare const SUBSCRIPTION_CORE_CLAUDE_ENTITLEMENT_COOLDOWN_MS: number; /** A 429 without a retry time rests as long as the legacy backpressure delay. */ export declare const SUBSCRIPTION_CORE_CLAUDE_RATE_LIMIT_FALLBACK_MS: number; /** A limit without a known reset is checked again after a minute, as the legacy capacity check does. */ export declare const SUBSCRIPTION_CORE_CLAUDE_UNKNOWN_RESET_MS: number; /** * The prompt-cache lifetime Opengeni sends on Claude requests (`cacheTtl: * "5m"`), declared as an exact TTL (SUB-STICK-04). Anthropic documents the * default cache lifetime as 5 minutes, refreshed each time the cached * content is used (https://platform.claude.com/docs/en/build-with-claude/prompt-caching). */ export declare const SUBSCRIPTION_CORE_CLAUDE_CACHE_TTL_MS: number; /** * The legacy product model id prefixes of Claude subscription models * (`claudeProviderId`), which the catalog still emits. Every Claude * subscription model is also named `claude/`; all forms are one * model (`claudeSubscriptionModelIdForms`). */ export declare const SUBSCRIPTION_CORE_CLAUDE_MODEL_PREFIXES: readonly ["organization-claude-subscription", "workspace-claude-subscription"]; /** The decoded Claude credential (the legacy secret object, unchanged). */ export type SubscriptionCoreClaudeCredential = z.infer; export type SubscriptionCoreClaudeAdapterDeps = { /** The fetch the OAuth refresh uses (tests inject a scripted upstream). */ fetch?: typeof fetch; now?: () => number; }; /** Decode the stored plaintext; fixed texts, never echoing the plaintext. */ export declare function decodeSubscriptionCoreClaudeCredential(plaintext: string): SubscriptionCoreClaudeCredential; /** Encode a credential as the stored plaintext (the legacy object, field order kept). */ export declare function encodeSubscriptionCoreClaudeCredential(credential: SubscriptionCoreClaudeCredential): string; export declare function subscriptionCoreClaudeAdapter(deps?: SubscriptionCoreClaudeAdapterDeps): SubscriptionCoreAdapter; /** * The product model ids a Claude upstream model id is served as: the * canonical `claude/` id and both legacy forms, so a cooldown or allowlist * written under them holds for whichever form a reader names. */ export declare function subscriptionCoreClaudeProductModelIds(upstreamModelId: string): string[]; /** * The workspace-policy provider ids of a Claude product model: every Claude * subscription provider id, which workspace model policy evaluates as one * provider, so the answer is the same for every id form and any form of * accepted policy matches. Other ids get the organization id alone. */ export declare function subscriptionCoreClaudeModelPolicyProviderIds(modelId: string): readonly string[]; /** Window ids that name the same limit (see `FAMILY_WINDOWS`). */ export declare const SUBSCRIPTION_CORE_CLAUDE_WINDOW_ALIASES: Readonly>; /** * The limits a stored Claude block may claim: the plan windows the usage * endpoint reports. Any other representative claim (a newer limit this * build does not know), or none, leaves the block unclaimed (fail closed). */ export declare const SUBSCRIPTION_CORE_CLAUDE_CLAIMABLE_WINDOW_IDS: ReadonlySet; /** * One Claude usage observation (response headers or the usage endpoint) * in the shared quota model, with the legacy capacity rules * (`claudeSubscriptionCapacity`, applied to the one response observed): * * - Paid overage the response allowed covers every plan limit it reports: * a full account window is a `warning`, and no family or request limit * blocks. Overage is the Claude account's own setting, so it covers every * model of the account. * - A rejected request whose overage was refused with a known reset before * its own plan reset is checked again at the overage reset (while its plan * limit still runs): the blocks that response reports for the models it * concerns (its own model; without one, the family its limit names, else * every model) end no later than it. * - The account windows (five hours, seven days) decide the connection's * capacity: `rejected`, or full without a status, is `exhausted` until its * reset (a minute when the reset is unknown). * - A model-family window (Opus, Sonnet, Fable) limits only that family: when full * or rejected it becomes a cooldown of each listed model of the family, and * the window itself is reported with `unknown` status so it never decides * the account's capacity. The paid overage windows never block. * - A rejected request, and each rejected request restriction the * observation carries (unless a later allowance of the same model lifts * it), limits the model it was made for (a cooldown of that model's * product ids); without a model, the family its limit names, else the * whole connection (`exhaustedUntil`, kind `quota`). * - The model a response was allowed for dispatches whatever else that * response reports, until the allowance's reset (a limit outlasting it * limits that model too, from now). * - When some models are judged apart (an allowed model, or a recheck that * concerns only some models), an account limit cools the listed models * one by one instead of exhausting the connection, and the window is a * `warning`. * - Each block carries the plan windows it came from (`QuotaBlockClaim`): * the full window itself, or the representative claim a refusal named. * A block any part of which names no claim, or a limit this build does * not recognize, carries none and never ends before its own reset. * - Reduced service past a limit is neither exhaustion nor plain capacity: * a response served in the grace zone (grace utilization above zero, not * rejected) or in the slow tier (`slow-status: active`) blocks nothing, * reports its full windows as `warning`, and marks the connection * constrained (`constrainedUntil`) until the latest full window resets. * A refusal because the slow tier's slots are busy (`slot_busy`) rests * the connection as a rate limit for the slow tier's retry-after (else * the rate-limit fallback) and is constrained until the plan reset. * - Everything else the observation reported (reset grants, the limit * list, extra usage, service state) is kept as provider details, each * part stamped with the observation time. * * `upstreamModelIds` must list every Claude model the connection can serve * (the organization's catalog when decoded), so a family limit reaches each * of them; the response's own model is always included. */ export declare function decodeSubscriptionCoreClaudeQuota(input: { observation: ClaudeUsageObservation; refreshGeneration: number; upstreamModelIds: readonly string[]; }): Omit; /** Claude's database binding on the shared core. */ export declare function subscriptionCoreClaudeProvider(deps?: SubscriptionCoreClaudeAdapterDeps): SubscriptionCoreProvider; /** The Claude binding (the production refresh call). */ export declare const SUBSCRIPTION_CORE_CLAUDE: SubscriptionCoreProvider;