openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
109 lines (108 loc) • 4.85 kB
JavaScript
import { V as timestampMsToIsoString } from "./number-coercion-D6u-4YD8.mjs";
import { o as writeRuntimeJson } from "./runtime-B-SLYP-m.mjs";
import { r as terminalText } from "./safe-text-C80HAQ2e.mjs";
import { p as shortenHomePath } from "./utils-C8YECn2Q.mjs";
import { T as readAuthProfileUsageStats, y as isActiveUnusableWindow } from "./user-model-account-authority-CRj924IP.mjs";
import { i as resolveProviderIdForAuth } from "./provider-auth-aliases-CgGlzANu.mjs";
import { a as buildAuthProfileUnusableHint } from "./oauth-refresh-failure-DxrQiYzV.mjs";
import { n as externalCliDiscoveryForProviderAuth } from "./external-cli-discovery-DZ419koV.mjs";
import { i as ensureAuthProfileStoreAsync } from "./store-runtime-dW0pXLJI.mjs";
import { t as resolveAuthStatePathForDisplay } from "./paths-BSElhsGi.mjs";
import { n as resolveAuthProfileDisplayLabel } from "./display-DA_6g711.mjs";
import "./auth-profiles-VRLhewIH.mjs";
import { l as resolveModelsTargetAgent } from "./shared-jZuoMzdG.mjs";
import { t as loadModelsConfig } from "./load-config-CTxoGQxg.mjs";
//#region src/commands/models/auth-list.ts
async function modelsAuthListCommand(e, t) {
const n = await loadModelsConfig({
commandName: "models auth list",
runtime: t
});
const { agentId: r, agentDir: i } = resolveModelsTargetAgent(n, e.agent, { kind: "read" });
const a = e.provider?.trim() ? resolveProviderIdForAuth(e.provider) : void 0;
const o = await ensureAuthProfileStoreAsync(i, a ? { externalCli: externalCliDiscoveryForProviderAuth({
cfg: n,
provider: a
}) } : void 0);
const s = [];
for (const [e, t] of Object.entries(o.profiles)) {
const r = readAuthProfileUsageStats(o, e);
const i = t.type === "api_key" ? void 0 : timestampMsToIsoString(t.expires);
const a = Date.now();
const c = isActiveUnusableWindow(r?.blockedUntil, a) ? timestampMsToIsoString(r?.blockedUntil) : void 0;
const l = r?.blockedScope === "model" ? r.blockedModel : void 0;
const u = isActiveUnusableWindow(r?.cooldownUntil, a) ? timestampMsToIsoString(r?.cooldownUntil) : void 0;
const d = isActiveUnusableWindow(r?.disabledUntil, a) ? timestampMsToIsoString(r?.disabledUntil) : void 0;
const f = Boolean(d);
const p = f ? r?.disabledReason : u ? r?.cooldownReason : void 0;
const m = d || u ? buildAuthProfileUnusableHint({
kind: f ? "disabled" : "cooldown",
reason: p,
provider: t.provider,
profileId: e
}) : void 0;
s.push({
id: e,
provider: resolveProviderIdForAuth(t.provider),
type: t.type,
label: resolveAuthProfileDisplayLabel({
cfg: n,
store: o,
profileId: e
}),
...t.email ? { email: t.email } : {},
...t.displayName ? { displayName: t.displayName } : {},
...i ? { expiresAt: i } : {},
...c ? {
blockedUntil: c,
...r?.blockedReason ? { blockedReason: r.blockedReason } : {},
...r?.blockedSource ? { blockedSource: r.blockedSource } : {},
blockedScope: l ? "model" : "profile",
...l ? { blockedModel: l } : {}
} : {},
...u ? { cooldownUntil: u } : {},
...d ? { disabledUntil: d } : {},
...u && r?.cooldownReason ? { cooldownReason: r.cooldownReason } : {},
...u && r?.cooldownClassification ? { cooldownClassification: r.cooldownClassification } : {},
...d && r?.disabledReason ? { disabledReason: r.disabledReason } : {},
...m ? { recoveryHint: m } : {}
});
}
const c = s.filter((e) => !a || e.provider === a).toSorted((e, t) => e.provider.localeCompare(t.provider) || e.id.localeCompare(t.id));
if (e.json) {
writeRuntimeJson(t, {
agentId: r,
agentDir: shortenHomePath(i),
authStatePath: shortenHomePath(resolveAuthStatePathForDisplay(i)),
provider: a || null,
profiles: c
});
return;
}
t.log(terminalText`Agent: ${r}`);
t.log(terminalText`Auth state store: ${shortenHomePath(resolveAuthStatePathForDisplay(i))}`);
if (a) t.log(terminalText`Provider: ${a}`);
if (c.length === 0) {
t.log("Profiles: (none)");
return;
}
t.log("Profiles:");
for (const e of c) {
const n = [`${e.provider}/${e.type}`];
if (e.expiresAt) n.push(`expires ${e.expiresAt}`);
if (e.blockedUntil) {
const t = e.blockedReason ? `:${e.blockedReason}` : "";
const r = e.blockedSource ? ` via ${e.blockedSource}` : "";
const i = e.blockedScope === "model" ? ` for model${e.blockedModel ? ` ${e.blockedModel}` : ""}` : " for profile";
n.push(`blocked${t}${r}${i} until ${e.blockedUntil}`);
}
if (e.cooldownUntil) {
const t = e.cooldownClassification ?? e.cooldownReason;
n.push(`cooldown${t ? `:${t}` : ""} until ${e.cooldownUntil}`);
}
if (e.disabledUntil) n.push(`disabled${e.disabledReason ? `:${e.disabledReason}` : ""} until ${e.disabledUntil}`);
t.log(terminalText`- ${e.label} [${n.join("; ")}]${e.recoveryHint ? ` — ${e.recoveryHint}` : ""}`);
}
}
//#endregion
export { modelsAuthListCommand };