/** * Claude limit reset claims on the shared subscription core. * * Claude offers some accounts limit reset grants (the provider's * `cedar_ember` program; the usage read stores them as provider details, * see `subscription-core-claude-usage.ts`). Claiming one is a request to * `POST /api/organizations/{organization}/reset_rate_limits` with * `{ program: "cedar_ember", grant_id, request_id }`, made the way Claude * Code 2.1.322 makes it: Claude Code's CLI surface, the account's * organization from the OAuth profile, and a 25-second deadline. The * provider settles a claim once per request id, so an unsettled claim * (`retryable`) is retried with the same id and can never use two resets. * * After every claim that reached the provider the connection's usage is * read again, past the refresh throttle: an authoritative reading below the * limit ends each stored exhaustion or cooldown whose claimed limits it now * shows below the limit (`subscriptionCoreClaudeUsageEndsClaimedBlock`), so * the limits the claim cleared serve again; the caller wakes waiters when * the read reports a recovery. */ import type { Settings } from "@opengeni/config"; import type { ClaudeLimitResetClaim, ClaudeSubscriptionUsage } from "@opengeni/contracts"; import type { SubscriptionCoreConnectionRead } from "@opengeni/subscriptions"; import type { Database } from "./database.js"; import type { SubscriptionCoreConnectionRow } from "./subscription-core/administration.js"; import { type SubscriptionCoreConnectionProbeDeps } from "./subscription-core/operation-connections.js"; import { type SubscriptionCoreClaudeCredential } from "./subscription-core-claude-adapter.js"; import { type SubscriptionCoreClaudeUsageTarget } from "./subscription-core-claude-reads.js"; /** Claude's account API (the organization a claim names is read from the profile). */ export declare const SUBSCRIPTION_CORE_CLAUDE_ACCOUNT_API = "https://api.anthropic.com"; /** The limit reset program Claude Code claims grants of. */ export declare const SUBSCRIPTION_CORE_CLAUDE_RESET_PROGRAM = "cedar_ember"; export type SubscriptionCoreClaudeLimitResetClaimInput = { grantId: string; /** The caller's idempotency key; retry an unsettled claim with the same one. */ requestId: string; }; /** * One limit reset claim with a connection's read (the adapter-level call). * Nothing is sent for a malformed grant or request id, or for a credential * without the profile scope (a setup token): neither can succeed by * retrying. A profile or transport failure is unsettled and retryable with * the same request id; the provider's own answer is parsed as Claude Code * parses it (`parseClaudeLimitResetClaim`). */ export declare function requestSubscriptionCoreClaudeLimitResetClaim(read: SubscriptionCoreConnectionRead, input: SubscriptionCoreClaudeLimitResetClaimInput): Promise; /** A claim and the connection's usage read after it. */ export type SubscriptionCoreClaudeLimitResetClaimOutcome = { claim: ClaudeLimitResetClaim; usage: ClaudeSubscriptionUsage; /** The read after the claim ended a stored exhaustion or cooldown (wake waiters). */ recovered: boolean; }; /** * Claim a limit reset grant of a Claude connection a workspace usage route * names (`readSubscriptionCoreClaudeWorkspaceUsageTarget`): a shared * connection through the workspace seam, the caller's own personal * connection through the owner seam. The caller has already checked that * the subject may change this connection. Then the usage is read again. */ export declare function claimSubscriptionCoreClaudeWorkspaceLimitReset(db: Database, settings: Settings, input: { accountId: string; workspaceId: string; subjectId: string; target: SubscriptionCoreClaudeUsageTarget; } & SubscriptionCoreClaudeLimitResetClaimInput, deps?: Pick & { now?: () => number; }): Promise; /** * Claim a limit reset grant of an organization-pool Claude connection, for * an organization administrator (the organization usage route's row). Then * the usage is read again. */ export declare function claimSubscriptionCoreClaudeOrganizationLimitReset(db: Database, settings: Settings, input: { organizationId: string; subjectId: string; row: SubscriptionCoreConnectionRow; } & SubscriptionCoreClaudeLimitResetClaimInput, deps?: { fetchImpl?: SubscriptionCoreConnectionProbeDeps["fetchImpl"]; now?: () => number; }): Promise;