import { type Credential, type OAuthCredential } from "@earendil-works/pi-ai";
import type { AuthStorage } from "./auth-storage.ts";
import { CredentialSlotRepository } from "./credential-pool/state-store.ts";
export type CredentialAccountSource = "login" | "import" | "env";
/**
 * Why a blocked account sits out (senpi#4327): `auth_error` means the key was rejected and is skipped
 * until its re-probe time, `rate_limit` is a cooldown, `disabled` lasts until the credential is replaced.
 */
export type CredentialAccountBlockedReason = "auth_error" | "rate_limit" | "disabled";
/**
 * The accounts no usage reading can bring back, so usage they report must not release a session's hold on the
 * provider (senpi#6536): a slot of the other credential kind (senpi#3486), a signed-out account, and every account
 * blocked for anything but a usage limit. A usage limit is a `rate_limit` block or a `paused` one (a ChatGPT
 * subscription's usage-limit pause, which carries no reason). The Claude lane's billing and organization blocks also
 * reach a summary with no reason but are not paused, so they count as needing the user.
 */
export declare function accountsNeedingUser(summaries: readonly CredentialAccountSummary[]): string[];
/**
 * Whether a pooled account can serve `modelId` now: not blocked, not signed out (the pool skips those slots), and
 * no live block on that model. A block keyed by a family binds the family's models; any other key binds that exact
 * model id only, matched by the pool's own rule (senpi#5590).
 */
export declare function accountCanServe(account: CredentialAccountSummary, modelId: string, now: number): boolean;
/** Account metadata safe to surface: names and health only, never key material. */
export type CredentialAccountSummary = {
    readonly name: string;
    readonly displayName?: string;
    readonly source: CredentialAccountSource;
    readonly blocked: boolean;
    /** Present only while `blocked`; absent when the stored block names no reason. */
    readonly blockedReason?: CredentialAccountBlockedReason;
    /** Epoch ms when the block lifts (the re-probe time for `auth_error`); absent for `disabled`. */
    readonly blockedUntil?: number;
    readonly pinned: boolean;
    /** Usage limits binding one model (family) while the account serves the rest (senpi#2555). */
    readonly blockedModels?: readonly {
        readonly model: string;
        readonly until: number;
    }[];
    /** A slot of the other kind than the stored credential: kept, never used, cannot be pinned (senpi#3486). */
    readonly unused?: true;
    /** ChatGPT registration route; never inferred from token contents. */
    readonly route?: "siwc" | "legacy";
    readonly planUsageEnabled?: boolean;
    readonly signedOut?: boolean;
    /** Set for an account signed in through the bundled `claude` CLI, whose own store holds the login (senpi#4436). */
    readonly store?: "claude-cli";
    readonly signedInAt?: number;
    /** Local-only profile fields of a `claude-cli` account; never logged or sent to telemetry. */
    readonly email?: string;
    readonly orgName?: string;
    readonly subscriptionType?: string;
    /** The sign-in connection test's last result. */
    readonly check?: CredentialAccountCheck;
    readonly signIn?: "signed_in" | "needs_sign_in";
    readonly active?: boolean;
    readonly paused?: true;
    readonly usageUrl?: string;
};
export type CredentialAccountCheck = {
    readonly model: string;
    readonly outcome: "ok" | "failed";
    readonly reason?: string;
    readonly message?: string;
    readonly status?: number;
    readonly at: number;
};
export declare function assertValidAccountName(name: string): void;
/** Resolve the immutable account ID, never its display name or its position in a list. */
export declare function selectedOAuthAccount(storage: AuthStorage, provider: string, name: string): OAuthCredential;
export declare function credentialPoolRepository(storage: AuthStorage): CredentialSlotRepository;
/**
 * Lists a provider's credential accounts for ANY provider, not just one lane.
 * Stored slots own the listing when a credential exists; env slots are listed
 * only when nothing is stored, mirroring resolution precedence exactly. Health
 * comes from the pool sidecar, so a cooldown persisted by a failover shows up
 * here without auth.json ever carrying block state.
 */
export declare function getCredentialAccounts(storage: AuthStorage, provider: string, env?: NodeJS.ProcessEnv, repository?: CredentialSlotRepository, activeName?: string): Promise<CredentialAccountSummary[]>;
/** Storage-free variant for callers that already hold the credential (e.g. auth check). */
export declare function summarizeCredentialAccounts(provider: string, stored: Credential | undefined, env?: NodeJS.ProcessEnv, repository?: CredentialSlotRepository): Promise<CredentialAccountSummary[]>;
/** Atomically rename/clear stored metadata without changing identity, health or environment state. */
export declare function renameCredentialAccount(storage: AuthStorage, provider: string, name: string, displayName: string | null): Promise<void>;
/** Pins one slot, or clears the pin when `name` is null. */
export declare function pinCredentialAccount(storage: AuthStorage, provider: string, name: string | null, env?: NodeJS.ProcessEnv, repository?: CredentialSlotRepository): Promise<void>;
/**
 * Removes one stored slot. Env-backed accounts are refused: they are owned by
 * the environment, and deleting one here would silently disagree with the
 * variable that still defines it.
 */
export declare function removeCredentialAccount(storage: AuthStorage, provider: string, name: string, env?: NodeJS.ProcessEnv, repository?: CredentialSlotRepository): Promise<RemoveCredentialAccountResult>;
/**
 * A provider logout deletes every stored account at once. For Anthropic Subscription each `claude-cli` slot is first
 * signed out of the CLI's own store by its account dir, through the same per-slot path as a single removal (link
 * guard, never stuck on the CLI), so a logout never orphans a CLI sign-in (senpi#4436). Returns the notices of the
 * slots that could not be signed out cleanly; any other provider returns none.
 */
export declare function signOutClaudeCliSlotsForLogout(storage: AuthStorage, provider: string, env?: NodeJS.ProcessEnv, signal?: AbortSignal, 
/** Sign out only this stored account (a one-account logout); every account when absent. */
slotName?: string): Promise<readonly string[]>;
/** `notice`: the account was removed, but something about it could not be cleaned up and the user should know. */
export type RemoveCredentialAccountResult = {
    readonly notice?: string;
};
//# sourceMappingURL=credential-accounts.d.ts.map