openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
281 lines (280 loc) • 11.3 kB
JavaScript
import { c as normalizeOptionalLowercaseString } from "./string-coerce-CCIiB4H7.mjs";
import { o as writeRuntimeJson, r as defaultRuntime } from "./runtime-B-SLYP-m.mjs";
import { n as sanitizeTerminalText } from "./safe-text-C80HAQ2e.mjs";
import { p as shortenHomePath } from "./utils-C8YECn2Q.mjs";
import { n as groupPluginRecords } from "./record-groups-DII71OvH.mjs";
import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs";
import { n as normalizeAgentId } from "./agent-id-CQjtp2ft.mjs";
import "./session-key-CqAyZeVk.mjs";
import { n as normalizeAccountId, t as DEFAULT_ACCOUNT_ID } from "./account-id-BqKT3GuY.mjs";
import { u as listExplicitConfiguredChannelIdsForConfig } from "./channel-presence-policy-6XNqNGJr.mjs";
import { n as isChannelVisibleInConfiguredLists } from "./channel-meta-CbOcOgly.mjs";
import { d as evaluateAgentDatabaseAdmissions, p as hasAgentDatabaseAdmissions, w as recordAgentDatabaseAdmissions } from "./agent-database-admission-CL6wHJ_N.mjs";
import { n as listAgentProvenance, r as readAgentProvenanceForDisplay } from "./agent-provenance-BRzUETpY.mjs";
import { t as normalizeAnyChannelId } from "./registry-normalize-guW5_4yo.mjs";
import "./plugins-BoMiRtiY.mjs";
import { i as listRouteBindings } from "./bindings-C2C-UuI7.mjs";
import { n as buildAgentSummaries } from "./agents.config-T4w0h7rr.mjs";
import "./channel-plugin-ids-DZDzcpUB.mjs";
import { r as resolveMissingOfficialExternalChannelPluginRepairHints } from "./official-external-plugin-repair-hints-CLGaUsqQ.mjs";
import { n as describeChannelAccount, r as resolveChannelAccount } from "./account-resolution-D7u1J1M0.mjs";
import { t as listReadOnlyChannelPluginsForConfig } from "./read-only-idsFCBWl.mjs";
import { r as hasConfiguredUnavailableCredentialStatus } from "./account-snapshot-fields-B0Zypjh2.mjs";
import { i as resolveChannelAccountState, n as projectChannelAccountDisplayState, r as resolveChannelAccountLinked } from "./account-state-CG07Qq4V.mjs";
import { t as requireValidConfig } from "./config-validation-Cy6dkTWs.mjs";
import { t as describeBinding } from "./agents.binding-format-DRkepwQw.mjs";
//#region src/commands/agents.commands.list.ts
function formatSummaryHeader(e) {
const t = sanitizeTerminalText;
const n = `${e.isDefault ? " (default)" : ""}${e.status === "degraded" ? " (degraded)" : ""}`;
return e.name && e.name !== e.id ? `${t(e.id)}${n} (${t(e.name)})` : `${t(e.id)}${n}`;
}
function formatSummary(e) {
const t = sanitizeTerminalText;
const n = formatSummaryHeader(e);
const r = [e.identityEmoji, e.identityName].filter((e) => Boolean(e)).map(t);
const i = r.length > 0 ? r.join(" ") : null;
const a = e.identitySource === "identity" ? "IDENTITY.md" : e.identitySource === "config" ? "config" : null;
const o = [`- ${n}`];
if (e.admissionRefusal) {
o.push(` Refused: ${t(e.admissionRefusal.reason)}`);
o.push(` Repair: ${t(e.admissionRefusal.repairHint)}`);
}
if (i) o.push(` Identity: ${i}${a ? ` (${a})` : ""}`);
o.push(` Workspace: ${t(shortenHomePath(e.workspace))}`);
o.push(` Agent dir: ${t(shortenHomePath(e.agentDir))}`);
if (e.model) o.push(` Model: ${t(e.model)}`);
o.push(` Routing rules: ${e.bindings}`);
if (e.routes?.length) o.push(` Routing: ${e.routes.map(t).join(", ")}`);
for (const [n, r] of [[" Providers:", e.providers], [" Routing rules:", e.bindingDetails]]) if (r?.length) {
o.push(n);
for (const e of r) o.push(` - ${t(e)}`);
}
return o.join("\n");
}
function providerAccountKey(e, t) {
return `${e}:${normalizeAccountId(t)}`;
}
function recordProviderAccountStatus(e, t) {
const n = providerAccountKey(t.provider, t.accountId);
if (!e.has(n) || t.accountId === normalizeAccountId(t.accountId)) e.set(n, t);
}
function resolveProviderChannelId(e, t) {
const n = normalizeAnyChannelId(e);
if (n) return n;
const r = normalizeOptionalLowercaseString(e);
return r && t.has(r) ? r : null;
}
function formatChannelAccountLabel(e) {
return `${e.providerLabel ?? e.provider} ${e.name?.trim() ? `${e.accountId} (${e.name.trim()})` : e.accountId}`;
}
function resolveBindingAccountId(e) {
const t = e.match.accountId?.trim();
return t === "*" ? t : normalizeAccountId(t);
}
function formatProviderEntry(e) {
return `${formatChannelAccountLabel(e)}: ${e.state}${e.enabled === false && e.state !== "disabled" ? ", disabled" : ""}`;
}
function formatMissingProviderEntry(e) {
const t = formatChannelAccountLabel({
provider: e.provider,
providerLabel: e.metadata?.label,
accountId: e.accountId
});
if (e.metadata?.repairHint) return `${t}: missing plugin - ${e.metadata.repairHint}`;
return `${t}: unknown`;
}
async function agentsListCommand(e) {
const t = await requireValidConfig(defaultRuntime, { adoptPluginMetadata: true });
if (!t) return;
if (!hasAgentDatabaseAdmissions()) recordAgentDatabaseAdmissions(await evaluateAgentDatabaseAdmissions(t));
const n = await buildAgentSummaries(t);
const r = e.tree ? await listAgentProvenance() : [];
if (e.json) {
const e = await readAgentProvenanceForDisplay(n.map((e) => e.id));
const t = new Map(e.map((e) => [e.agentId, e]));
for (const e of n) {
const n = t.get(e.id);
if (n) {
e.createdVia = n.createdVia;
e.creatorAgentId = n.creatorAgentId;
e.createdAt = n.createdAtMs;
}
}
}
const i = groupPluginRecords(listRouteBindings(t), (e) => normalizeAgentId(e.agentId));
if (e.bindings) for (const e of n) {
const t = i.get(e.id) ?? [];
if (t.length > 0) e.bindingDetails = t.map(describeBinding);
}
if (!e.json && !e.tree || e.bindings === true) {
const e = listReadOnlyChannelPluginsForConfig(t, { includeSetupFallbackPlugins: false }).map((e) => ({
plugin: e,
accountIds: e.config.listAccountIds(t)
}));
const r = /* @__PURE__ */ new Map();
for (const { plugin: n, accountIds: i } of e) for (const e of i) {
let i;
try {
i = n.config.inspectAccount ? await n.config.inspectAccount(t, e) : await resolveChannelAccount({
plugin: n,
cfg: t,
accountId: e
});
} catch (t) {
if (!(t instanceof Error) || !/unresolved SecretRef/i.test(t.message)) throw t;
recordProviderAccountStatus(r, {
provider: n.id,
providerLabel: n.meta.label,
accountId: e,
state: "configured unavailable",
configured: true,
visibleInConfiguredLists: isChannelVisibleInConfiguredLists(n.meta)
});
continue;
}
if (!i) continue;
const a = await describeChannelAccount({
plugin: n,
account: i,
cfg: t
});
const o = n.config.isEnabled ? n.config.isEnabled(i, t) : typeof a?.enabled === "boolean" ? a.enabled : i.enabled;
const s = n.config.isConfigured ? await n.config.isConfigured(i, t) : a?.configured;
const c = typeof o === "boolean" ? o : true;
const l = typeof s === "boolean" ? s : true;
const u = i.configured;
const d = typeof u === "boolean" ? u : a?.configured === true;
const f = !l && d && (hasConfiguredUnavailableCredentialStatus(a) || hasConfiguredUnavailableCredentialStatus(i));
const p = l && n.config.isLinked ? await n.config.isLinked(i, t) : void 0;
const m = resolveChannelAccountLinked(p, a?.linked);
const h = n.status?.resolveAccountState?.({
account: i,
cfg: t,
configured: l,
enabled: c
});
const g = f ? "configured unavailable" : projectChannelAccountDisplayState(resolveChannelAccountState({
enabled: c,
configured: l,
linked: m
}), h);
const _ = a?.name ?? i.name;
recordProviderAccountStatus(r, {
provider: n.id,
providerLabel: n.meta.label,
accountId: e,
name: _,
state: g,
enabled: o,
configured: f || s,
visibleInConfiguredLists: isChannelVisibleInConfiguredLists(n.meta)
});
}
const a = new Map(e.map(({ plugin: e }) => [e.id, {
label: e.meta.label,
visibleInConfiguredLists: isChannelVisibleInConfiguredLists(e.meta)
}]));
const o = listExplicitConfiguredChannelIdsForConfig(t).filter((e) => !a.has(e));
const s = resolveMissingOfficialExternalChannelPluginRepairHints({
config: t,
channelIds: o
});
for (const e of s) a.set(e.channelId, {
label: e.label,
visibleInConfiguredLists: true,
repairHint: e.repairHint
});
let c;
for (const e of n) {
const n = i.get(e.id) ?? [];
const o = /* @__PURE__ */ new Map();
for (const e of n) {
const t = resolveProviderChannelId(e.match.channel, a);
if (!t) continue;
const n = resolveBindingAccountId(e);
const r = `${t}:${n}`;
if (!o.has(r)) {
const e = formatChannelAccountLabel({
provider: t,
providerLabel: a.get(t)?.label,
accountId: n
});
o.set(r, e);
}
}
const s = [...o.values()];
if (s.length > 0) e.routes = s;
else if (e.isDefault) e.routes = ["default (no explicit rules)"];
const l = [];
if (n.length > 0) {
const e = /* @__PURE__ */ new Map();
for (const t of n) {
const n = resolveProviderChannelId(t.match.channel, a);
if (!n) continue;
const i = resolveBindingAccountId(t);
const o = i === "*" ? (c ??= [...r.values()]).filter((e) => e.provider === n) : [r.get(providerAccountKey(n, i))];
for (const t of o.length > 0 ? o : [void 0]) e.set(t ? providerAccountKey(n, t.accountId) : `${n}:${i}`, t ? formatProviderEntry(t) : formatMissingProviderEntry({
provider: n,
accountId: i,
metadata: a.get(n)
}));
}
l.push(...e.values());
} else if (e.isDefault) {
const e = /* @__PURE__ */ new Set();
for (const n of r.values()) {
const r = n.visibleInConfiguredLists ?? a.get(n.provider)?.visibleInConfiguredLists;
if (n.configured || r === false && t[n.provider]) {
l.push(formatProviderEntry(n));
e.add(n.provider);
}
}
for (const [t, n] of a.entries()) {
if (!n.repairHint || e.has(t)) continue;
l.push(formatMissingProviderEntry({
provider: t,
accountId: DEFAULT_ACCOUNT_ID,
metadata: n
}));
}
}
if (l.length > 0) e.providers = l;
}
}
if (e.json) {
writeRuntimeJson(defaultRuntime, n);
return;
}
if (e.tree) {
const e = new Map(n.map((e) => [e.id, e]));
const t = new Map(r.map((e) => [e.agentId, e]));
const i = groupPluginRecords(n, (n) => {
const r = t.get(n.id)?.creatorAgentId;
return r && r !== n.id && e.has(r) ? r : void 0;
});
const a = i.get(void 0) ?? [];
const o = [];
const s = /* @__PURE__ */ new Set();
const append = (e, t) => {
if (s.has(e.id)) return;
s.add(e.id);
o.push(`${" ".repeat(t)}- ${formatSummaryHeader(e)}`);
if (e.bindingDetails?.length) {
o.push(`${" ".repeat(t + 1)}Routing rules:`);
for (const n of e.bindingDetails) o.push(`${" ".repeat(t + 2)}- ${sanitizeTerminalText(n)}`);
}
for (const n of i.get(e.id) ?? []) append(n, t + 1);
};
a.forEach((e) => append(e, 0));
n.forEach((e) => append(e, 0));
defaultRuntime.log(["Agents:", ...o].join("\n"));
return;
}
const a = ["Agents:", ...n.map(formatSummary)];
a.push("Routing rules map channel/account/peer to an agent. Use --bindings for full rules.");
a.push(`Channel status reflects local config/creds. For live health: ${formatCliCommand("openclaw channels status --probe")}.`);
defaultRuntime.log(a.join("\n"));
}
//#endregion
export { agentsListCommand };