@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
51 lines • 2.42 kB
JavaScript
import { accountLabel } from "@earendil-works/pi-ai/auth/pool/slots";
/** The local wall-clock time an account block lifts, in the reader's time zone. */
export function formatAccountRetryTime(epochMs) {
return new Date(epochMs).toLocaleString("en-US", {
year: "numeric",
month: "short",
day: "numeric",
hour: "numeric",
minute: "2-digit",
timeZoneName: "short",
});
}
/**
* One account's health in plain words: why it sits out and until when, the cases the desktop account row
* shows (senpi#4092), so no account list says a bare "blocked".
*/
export function describeAccountBlock(block, signInAgain) {
if (!block.blocked)
return "available";
const until = block.blockedUntil === undefined ? undefined : formatAccountRetryTime(block.blockedUntil);
switch (block.blockedReason) {
case "disabled":
return "account disabled; needs attention";
case "auth_error":
// A surface that has an in-place re-login names it, so the row says what to run (senpi#3216).
if (signInAgain !== undefined) {
return until === undefined
? `sign-in rejected; ${signInAgain}`
: `sign-in rejected; next check after ${until}, or ${signInAgain}`;
}
return until === undefined ? "sign-in rejected; sign in again" : `sign-in rejected; next check after ${until}`;
case "rate_limit":
return until === undefined ? "rate limited" : `rate limited; retry after ${until}`;
case undefined:
return until === undefined ? "blocked; reason and retry time unavailable" : `blocked; retry after ${until}`;
}
}
/** One `/account`-style list row: label, source, health, per-model limits and pin. Never key material. */
export function describeCredentialAccount(account, signInAgain) {
const availability = account.unused
? "unused (other login kind; switch with /login)"
: describeAccountBlock(account, signInAgain);
const states = [accountLabel(account), account.source, availability];
for (const { model, until } of account.blockedModels ?? []) {
states.push(`blocked for ${model} until ${formatAccountRetryTime(until)}`);
}
if (account.pinned)
states.push("pinned");
return states.join(" | ");
}
//# sourceMappingURL=credential-account-status.js.map