@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
127 lines • 6.34 kB
TypeScript
import type { OAuthCredential } from "@earendil-works/pi-ai";
import type { ModelBlocks } from "../../../credential-pool/model-scope.ts";
type SlotBlockState = {
blockedUntil?: number;
blockReason?: string;
/** When the current block was stored, so a turn that started earlier never clears it (senpi#3462). */
blockedAt?: number;
/** Rate limits that bind one model family on this account, not the account (senpi#2555). */
modelBlocks?: ModelBlocks;
};
/**
* A `CLAUDE_CODE_OAUTH_TOKEN[_N]` account. It is never stored: the token is read from the environment for each
* turn, and the token fields are empty placeholders.
*/
export type EnvAccountSlot = SlotBlockState & {
/** Immutable operational identity, including SDK session bindings. */
name: string;
displayName?: string;
store?: undefined;
dirId?: never;
authVerdict?: never;
refresh: string;
access: string;
expires: number;
source: "env";
};
/** The local-only profile `claude auth status` reported; never logged or sent to telemetry. */
export type ClaudeCliAccountProfile = {
email?: string;
orgName?: string;
subscriptionType?: string;
checkedAt: number;
};
/** The sign-in connection test's last result. */
export type ClaudeCliAccountCheck = {
model: string;
outcome: "ok" | "failed";
reason?: string;
/** Provider diagnostics, redacted before they enter the credential store. */
message?: string;
status?: number;
at: number;
};
/**
* An account signed in through the bundled `claude` CLI (senpi#4436). It holds no token: the CLI keeps the
* login in its own credential store, keyed on the account dir `accountDirFor(agentDir, dirId)`.
*/
export type ClaudeCliAccountSlot = SlotBlockState & {
name: string;
displayName?: string;
source: "login";
store: "claude-cli";
/** 32 hex chars, fixed at creation. */
dirId: string;
signedInAt?: number;
profile?: ClaudeCliAccountProfile;
check?: ClaudeCliAccountCheck;
/**
* Never selected for a turn. `login_expired`: a due auth re-probe found the CLI signed out (senpi#5350); the slot
* keeps its `auth_error` block so the probe keeps running, and a `signed_in` probe or `/login` clears it.
*/
signInRequired?: "legacy_sign_in_retired" | "login_expired";
/** Set with an `auth_error` block this engine reached about the sign-in in `dirId` (senpi#5623). */
authVerdict?: ClaudeCliAuthVerdict;
/** A CLI slot never holds token material; declared so reads on an `AccountSlot` see `undefined`, not a missing field. */
access?: never;
refresh?: never;
expires?: never;
};
export type AccountSlot = EnvAccountSlot | ClaudeCliAccountSlot;
/** The sign-in an `auth_error` block on a Claude CLI slot is about: its account dir and the block's `blockedAt`. */
export type ClaudeCliAuthVerdict = {
readonly dirId: string;
readonly at: number;
};
/**
* Whether a Claude CLI slot carries an `auth_error` block that no Claude CLI verdict backs (senpi#5623). An engine from
* before #4436 lists the slot, finds no token in it, and writes `blockReason`/`blockedUntil`/`blockedAt` onto it
* without contacting Claude; such a block says nothing about the login in the slot's dir. Takes `object`: the generic
* listing passes raw pool slots.
*/
export declare function isForeignAuthBlock(slot: object): boolean;
/** Narrows a slot to an env token account; a claude CLI slot's login lives in the CLI's own store. */
export declare function isEnvSlot(slot: AccountSlot): slot is EnvAccountSlot;
export type SlotState = Record<string, {
blockedUntil?: number;
blockReason?: string;
blockedAt?: number;
modelBlocks?: ModelBlocks;
}>;
export type AnthropicSubscriptionCredential = OAuthCredential & {
accounts?: AccountSlot[];
pinned?: string;
order?: string[];
slotState?: SlotState;
};
export declare const SENTINEL_OAUTH_FIELDS: {
readonly access: "claude-sdk-oauth-managed";
readonly refresh: "claude-sdk-oauth-managed";
readonly expires: 4102444800000;
};
export declare function emptyCredential(): AnthropicSubscriptionCredential;
/**
* Whether a stored slot is listed: only a claude CLI account is. A stored account that still holds tokens (one the
* retired senpi-owned login wrote, which the load-time sign-out could not rewrite, or a sentinel projection) is never
* listed, so no turn or usage poll serves or refreshes its token (senpi#4436). Every listing of stored Claude
* accounts (this lane's, the generic one RPC uses, and the configured check) applies this one rule, so none of them
* shows or counts an account the others hide. Takes `object`: the generic listing passes raw pool slots.
*/
export declare function isListedStoredSlot(slot: object): boolean;
/**
* A stored claude CLI account the listing rule drops, so a lane can refuse the turn instead of silently falling back to
* ambient host credentials when every such account is unusable (oh-my-openagent#12228). Accounts of any other shape are
* not counted: a legacy token slot is hidden on purpose (senpi#4436) and is not a broken login this rule can report.
*/
export declare function unusableStoredSlotCount(credential: unknown): number;
/** The listed accounts: every stored claude CLI account (`isListedStoredSlot`), then the env token accounts. */
export declare function listAccounts(credential: AnthropicSubscriptionCredential, env?: (name: string) => string | undefined): AccountSlot[];
export declare function assertValidAccountName(name: string): void;
export declare function addAccount(credential: AnthropicSubscriptionCredential, slot: AccountSlot): AnthropicSubscriptionCredential;
export declare function removeAccount(credential: AnthropicSubscriptionCredential, name: string): AnthropicSubscriptionCredential;
export declare function pinAccount(credential: AnthropicSubscriptionCredential, name: string): AnthropicSubscriptionCredential;
export declare function assertSentinelInvariant(credential: AnthropicSubscriptionCredential): void;
export declare function envSlots(env: (name: string) => string | undefined): EnvAccountSlot[];
export declare function envSlotToken(env: (name: string) => string | undefined, slotName: string): string | undefined;
export {};
//# sourceMappingURL=accounts.d.ts.map