@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
96 lines • 5.82 kB
TypeScript
import { type AccountStrategy } from "../../../credential-pool/selection-order.ts";
import type { AccountSlot } from "./accounts.ts";
export declare const DEFAULT_AFFINITY_KEY = "claude-sdk-oauth-default";
export type AffinityOptions = {
affinityKey?: string;
sessionId?: string;
pinnedAccount?: string;
/** Where `pinnedAccount` came from, so guidance for an unusable pin says where to change it. */
pinSource?: PinSource;
/**
* The account this session's SDK transcript lives under. It is kept while it can serve, so the
* session does not move accounts and re-send its whole conversation (senpi#2891).
*/
preferredAccount?: string;
/** When false, a blocked pin, resident account, or HRW winner is never skipped. */
readonly accountFallback?: boolean;
/** The user's account order (senpi#3591): tried after the pin and the session's own account, before HRW. */
accountOrder?: readonly string[];
readonly accountStrategy?: AccountStrategy;
now?: number;
/** The requested model; an account blocked only for another model stays eligible for it. */
model?: string;
};
/**
* The one account a request may use when account fallback is off (senpi#3465): its name, and whether it
* is still configured. A pin or a session's resident account can name an account that was later removed.
*/
export type UnavailableAccount = {
readonly name: string;
readonly configured: boolean;
/** Set when the account is a pin: a CLI or settings pin outranks `/claude-account pin`, so that advice would do nothing. */
readonly pinnedBy?: PinSource;
};
/** The origin of an account pin, highest precedence first (`resolveClaudeAccountPin`). */
export type PinSource = "cli" | "settings" | "stored";
/** One pool member's state when the pool refused a request: why it is out, and until when. */
export type BlockedAccountState = {
readonly name: string;
readonly reason: string;
readonly until: number | undefined;
};
export declare class AllAccountsBlockedError extends Error {
readonly soonestUnblockAt: number | undefined;
/**
* Set only when EVERY candidate is auth-blocked, so the guidance asks for a
* re-login (omo#8383). A pool where any account waits on a deadline (a rate
* limit, a usage reset, a model limit) recovers on its own at
* `soonestUnblockAt`, and calling it an auth failure made that temporary
* block look permanent (senpi#2081).
*/
readonly blockReason: "auth_error" | undefined;
/**
* The requested model when a usage limit on that model, not the accounts, is
* what blocks it somewhere: the message then names the model, so the fallback
* chain moves only this model and keeps the provider for the others.
*/
readonly limitedModel: string | undefined;
/** Set only when account fallback is off, so the guidance names that account instead of the whole pool. */
readonly unavailableAccount: UnavailableAccount | undefined;
/** Every candidate's state, so the error names which account needs /login and which waits on a reset (senpi#4671). */
readonly accounts: readonly BlockedAccountState[];
/**
* When the pool waits only on rate limits, the soonest of them; else undefined (senpi#3975). Accounts out
* for billing, organization, or authentication cannot serve until someone acts, so they are not counted;
* every other account must be rate-limited (account-wide or on the requested model), and an unknown block
* is not a rate limit. A billing deadline is a re-probe time, never the pool's reset.
*/
readonly rateLimitedUntil: number | undefined;
constructor(soonestUnblockAt: number | undefined, blockReason?: "auth_error", limitedModel?: string, unavailableAccount?: UnavailableAccount, accounts?: readonly BlockedAccountState[], rateLimitedUntil?: number);
}
export declare function getAffinityKey(options: Pick<AffinityOptions, "affinityKey" | "sessionId">): string;
/**
* Session-stable HRW ordering preserves Claude prompt-cache locality while moving
* only the sessions that rendezvous with a newly added or removed account.
*/
export declare function rendezvousOrder(key: string, accounts: readonly AccountSlot[]): AccountSlot[];
/** Account-level block for selection; an auth block with no deadline or a passed one is re-probed (senpi#3264). */
export declare function isAccountBlocked(account: Pick<AccountSlot, "blockedUntil">, now: number): boolean;
/** Whether the account can serve `model` now: no account-level block and no live block on that model. */
export declare function isBlockedFor(account: AccountSlot, now: number, model?: string): boolean;
/**
* A usage-limit block the account's own usage, read after the block was stored, contradicts: the provider lifted
* the limit before the reset it stated (senpi#6536). Auth, billing and organization blocks need the user, so only
* a rate-limit block lifts this way.
*/
export declare function isLimitLiftedEarly(account: Pick<AccountSlot, "name" | "blockReason" | "blockedAt" | "blockedUntil">, now: number): boolean;
/**
* Removes elapsed blocks, auth blocks included: an auth block lasts until its
* re-probe time (senpi#3264), and one persisted before re-probe times existed
* has no expiry and clears at once, so the next request probes the account.
* A limit block newer usage contradicts is removed too (senpi#6536).
*/
export declare function clearExpiredBlocks(accounts: readonly AccountSlot[], now?: number): AccountSlot[];
/** Selects a pinned, resident, or strategy-ranked account; only round-robin holds a distribution cursor. */
export declare function selectAccount(accounts: readonly AccountSlot[], requestedOptions?: AffinityOptions): AccountSlot;
//# sourceMappingURL=affinity.d.ts.map