@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
40 lines • 2.09 kB
JavaScript
import { credentialPoolRepository, getCredentialAccounts } from "./credential-accounts.js";
import { emitProviderAccountsChanged } from "./extensions/builtin/anthropic-subscription/account-events.js";
export class CredentialAccountNotFoundError extends Error {
constructor(accountName) {
super(`Provider account not found: ${accountName}`);
this.name = "CredentialAccountNotFoundError";
this.code = "account_not_found";
}
}
function withoutBlock({ blockReason: _reason, blockedUntil: _until, modelBlocks: _models, ...slot }) {
return slot;
}
function clearStoredBlock(credential, name) {
const accounts = credential.accounts?.map((slot) => (slot.name === name ? withoutBlock(slot) : slot));
const { [name]: _cleared, ...slotState } = credential.slotState ?? {};
return {
...credential,
...(accounts === undefined ? {} : { accounts }),
...(credential.slotState === undefined ? {} : { slotState }),
};
}
/**
* Clears one account's cooldown or block so the next request tries it again
* (senpi#3285). Both health sources are cleared: the pool sidecar and a block a
* provider lane stored on the account itself. Nothing else about the account
* changes; if it is still unhealthy, the next request blocks it again.
*/
export async function resetCredentialAccount(storage, provider, name, env = process.env, repository) {
const repo = repository ?? credentialPoolRepository(storage);
const accounts = await getCredentialAccounts(storage, provider, env, repo);
const account = accounts.find((candidate) => candidate.name === name);
if (!account)
throw new CredentialAccountNotFoundError(name);
await repo.mutateSlotState(provider, account.source === "env" ? "env" : "stored", name, () => undefined);
if (storage.get(provider) !== undefined) {
await storage.modify(provider, async (current) => current === undefined ? current : clearStoredBlock(current, name));
}
emitProviderAccountsChanged(provider, "reset");
}
//# sourceMappingURL=credential-account-reset.js.map