UNPKG

@code-yeongyu/senpi

Version:

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

74 lines • 3.71 kB
import { resetCredentialAccount } from "../../../credential-account-reset.js"; import { describeCredentialAccount } from "../../../credential-account-status.js"; import { getCredentialAccounts, pinCredentialAccount, removeCredentialAccount } from "../../../credential-accounts.js"; import { accountDisplayNameCommand } from "../account-display-name.js"; function parseArgs(rawArgs) { return rawArgs.trim().split(/\s+/).filter(Boolean); } function usage(ctx) { ctx.ui.notify("Usage: /account <provider> [list | pin <id> | unpin | reset <id> | remove <id> | rename <id> <display name...> | clear-name <id>]", "error"); } async function showAccounts(ctx, provider) { const accounts = await getCredentialAccounts(ctx.modelRegistry.authStorage, provider); const lines = [`Credential accounts for ${provider}:`]; if (accounts.length === 0) lines.push(" (none)"); for (const account of accounts) lines.push(` ${describeCredentialAccount(account)}`); ctx.ui.notify(lines.join("\n"), "info"); } /** * Provider-neutral `/account` command over the generic credential pool. The * existing `/claude-account` and Cursor account commands stay untouched; this * command is the one surface that works for every provider. Output carries * names and health only, never key material. */ export default function accountExtension(pi) { pi.registerCommand("account", { description: "List and manage credential accounts for any provider.", requiresArguments: true, argumentHint: "<provider> [list | pin <id> | unpin | reset <id> | remove <id> | rename <id> <display name...> | clear-name <id>]", handler: async (rawArgs, ctx) => { const args = parseArgs(rawArgs); const provider = args[0]; if (provider === undefined) { usage(ctx); return; } if (await accountDisplayNameCommand(ctx, provider, rawArgs.trim().replace(/^\S+\s*/, ""))) return; const action = args[1] ?? "list"; try { if (action === "list") { await showAccounts(ctx, provider); return; } if (action === "pin" && args[2] !== undefined) { await pinCredentialAccount(ctx.modelRegistry.authStorage, provider, args[2]); ctx.ui.notify(`Pinned ${provider} account '${args[2]}'.`, "info"); return; } if (action === "unpin") { await pinCredentialAccount(ctx.modelRegistry.authStorage, provider, null); ctx.ui.notify(`Unpinned ${provider} account.`, "info"); return; } if (action === "reset" && args[2] !== undefined) { await resetCredentialAccount(ctx.modelRegistry.authStorage, provider, args[2]); ctx.ui.notify(`Cleared the cooldown on ${provider} account '${args[2]}'; the next request tries it again.`, "info"); return; } if (action === "remove" && args[2] !== undefined) { const { notice } = await removeCredentialAccount(ctx.modelRegistry.authStorage, provider, args[2]); ctx.ui.notify(notice ?? `Removed ${provider} account '${args[2]}'.`, notice ? "warning" : "info"); return; } usage(ctx); } catch (error) { ctx.ui.notify(error instanceof Error ? error.message : String(error), "error"); } }, }); } //# sourceMappingURL=index.js.map