UNPKG

@code-yeongyu/senpi

Version:

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

63 lines • 3.44 kB
import { isValidAccountDirId } from "./claude-cli-account-dir.js"; /** Every sign-in-required prompt starts with this, whatever the reason; `isSignInAgainError` keys on it. */ const SIGN_IN_LEAD = "Claude sign-in "; const SIGN_IN_AGAIN_TAIL = "Sign in again with Claude to keep using: "; const REASON_WORD = { legacy_sign_in_retired: "changed", login_expired: "expired", }; const REASON_ORDER = ["legacy_sign_in_retired", "login_expired"]; function reasonMessage(reason, names) { return `${SIGN_IN_LEAD}${REASON_WORD[reason]}. ${SIGN_IN_AGAIN_TAIL}${names.join(", ")}. Run /login anthropic-subscription.`; } /** The one prompt every surface shows for accounts from the retired sign-in (senpi#4436): notice, turn error, docs. */ export function signInAgainMessage(names) { return reasonMessage("legacy_sign_in_retired", names); } /** One sentence per reason, the retired sign-in first; an expired CLI login (senpi#5350) says "expired". */ export function signInRequiredMessage(required) { return REASON_ORDER.map((reason) => [reason, required.filter((entry) => entry.reason === reason)]) .filter(([, entries]) => entries.length > 0) .map(([reason, entries]) => reasonMessage(reason, entries.map((entry) => entry.name))) .join(" "); } /** A turn error that is a sign-in-required prompt: no retry or other model can serve it until the user signs in. */ export function isSignInAgainError(errorMessage) { return errorMessage?.includes(`authentication_failed: ${SIGN_IN_LEAD}`) === true; } /** * A slot this engine can serve: nothing to sign in again for, and (on the CLI store) an account dir id that names a * directory. A stored CLI slot whose `dirId` is missing or malformed names no directory, so preparing it fails with an * internal error ("Invalid Claude account dir id") before any model call - that is a sign-in state, not a turn * failure, and it must never reach the SDK (omo#12228). */ export function isServableAccountSlot(slot) { return slot.store !== "claude-cli" || (slot.signInRequired === undefined && isValidAccountDirId(slot.dirId)); } /** * The accounts a turn cannot use until the user signs in again, named so the prompt can say which. A stored slot whose * account dir id is unusable carries no login this engine can read, so it is reported as expired: only a new sign-in * gives it a directory (run `/login anthropic-subscription`). */ export function signInRequiredAccounts(accounts) { return accounts.flatMap((slot) => { if (slot.store !== "claude-cli") return []; if (slot.signInRequired !== undefined) return [{ name: slot.name, reason: slot.signInRequired }]; return isValidAccountDirId(slot.dirId) ? [] : [{ name: slot.name, reason: "login_expired" }]; }); } /** * A turn found only accounts that must sign in again; the message is the prompt, prefixed so it classifies as auth. * A bare name is an account from the retired sign-in. */ export class ClaudeSignInRequiredError extends Error { constructor(accounts) { const required = accounts.map((entry) => typeof entry === "string" ? { name: entry, reason: "legacy_sign_in_retired" } : entry); super(`authentication_failed: ${signInRequiredMessage(required)}`); this.name = "ClaudeSignInRequiredError"; this.accountNames = required.map((entry) => entry.name); } } //# sourceMappingURL=sign-in-again.js.map