UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

70 lines • 3.93 kB
import type { CredentialStore } from "@earendil-works/pi-ai"; import type { AccountSlot } from "./accounts.ts"; import { AllAccountsBlockedError } from "./affinity.ts"; import type { SdkErrorClassification } from "./errors.ts"; export declare const MAX_RATE_LIMIT_BLOCK_MS: number; export declare const DEFAULT_RATE_LIMIT_BLOCK_MS = 60000; /** Same-account retries per turn for a transient failure (overload, network, server error); it never rotates. */ export declare const TRANSIENT_RETRIES_PER_TURN = 2; export declare const TRANSIENT_RETRY_DELAY_MS = 1000; export declare const TURN_RETRY_SUPPRESSION_PREFIX = "senpi:no-turn-retry:"; export type FailoverEvent = { account: AccountSlot; nextAccount?: AccountSlot; classification: SdkErrorClassification; attempt: number; visibleDeltaEmitted: boolean; }; export type FailoverOptions<TEvent> = { accounts: readonly AccountSlot[]; /** Shared across this person's turn, including retries; consumed before an account's first attempt. */ recheckedAccounts?: Set<string>; /** When false, only the selected account may be attempted; same-account retries remain enabled. */ readonly accountFallback?: boolean; selectFn: (accounts: readonly AccountSlot[]) => AccountSlot; runAttempt: (slot: AccountSlot) => AsyncIterable<TEvent> | Promise<AsyncIterable<TEvent>>; classify: (error: unknown) => SdkErrorClassification; store: CredentialStore; providerId: string; /** The requested model; a limit naming its family blocks only that family on the account. */ model?: string; now?: () => number; baseBlockMs?: number; onFailover?: (event: FailoverEvent) => void | Promise<void>; errorFromEvent?: (event: TEvent) => unknown | undefined; isVisibleDelta?: (event: TEvent) => boolean; /** Waits before a transient same-account retry; injectable for tests. */ sleep?: (ms: number, signal?: AbortSignal) => Promise<void>; signal?: AbortSignal; /** Records a refused 1M window so the retry, built by `runAttempt`, requests the standard one. */ onLongContextRefused?: (error: unknown) => void; /** The session this turn belongs to: blocks that bind only this session are remembered under it. */ sessionKey?: string; /** * False for a probe (the account connection test): its outcome is reported to the caller and never written as * account state, so it neither stores nor clears a block (senpi#4436). */ persistBlocks?: boolean; }; /** `/claude-account unblock` lifts the account's session-scoped blocks in every session too. Returns whether one was lifted. */ export declare function forgetSessionBlocksFor(name: string): boolean; export declare class ClassifiedSdkError extends Error { readonly classification: SdkErrorClassification; readonly original: unknown; readonly suppressTurnRetry: boolean; /** * The pool's state when this failure left no other account to try (senpi#4671). The failure stays the * error; the pool refusal is context, so a refresh failure or a 401 is never hidden behind "all blocked". */ readonly poolState: AllAccountsBlockedError | undefined; constructor(classification: SdkErrorClassification, original: unknown, suppressTurnRetry: boolean, poolState?: AllAccountsBlockedError); } /** * Runs one attempt per account for account-level failures (a limit, billing, auth), plus at most * TRANSIENT_RETRIES_PER_TURN same-account retries for a transient failure, after which the turn fails on * that account instead of rotating (and one retry on newer stored credentials). A retry is transparent only * before a text, thinking, or tool-call event reaches the caller; post-delta failures are marked so * AgentSession never replays the partial turn. */ export declare function runFailover<TEvent>(options: FailoverOptions<TEvent>): AsyncGenerator<TEvent>; //# sourceMappingURL=failover.d.ts.map