openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
81 lines (80 loc) • 3.47 kB
JavaScript
import { r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs";
import { n as sanitizeForLog } from "./ansi-CZa2t0Hf.mjs";
import "./session-key-CqAyZeVk.mjs";
import { t as DEFAULT_ACCOUNT_ID } from "./account-id-BqKT3GuY.mjs";
import { r as theme } from "./theme-BOI0xyRZ.mjs";
import { n as formatTimeAgo } from "./format-relative-JG-kbkDF.mjs";
import { r as hasConfiguredUnavailableCredentialStatus } from "./account-snapshot-fields-B0Zypjh2.mjs";
import { a as formatChannelAllowFrom, t as buildChannelAccountNotes } from "./account-summary-RVgW5Dlx.mjs";
import { n as resolveInspectedChannelAccount } from "./account-inspection-BR5sYFpp.mjs";
import { t as formatChannelStatusState } from "./status-state-XssSujDv.mjs";
//#region src/infra/channel-summary.ts
async function buildChannelSummary(e, t) {
const n = [];
const { colorize: r = false, includeAllowFrom: i = false } = t ?? {};
const a = t?.sourceConfig ?? e;
const o = await (await import("./read-only-BeHuWFNs.mjs")).listReadOnlyChannelPluginsForConfigAsync(e, {
activationSourceConfig: a,
includeSetupFallbackPlugins: false
});
for (const t of o) {
const o = t.config.listAccountIds(e);
const s = t.config.defaultAccountId?.(e) ?? o[0] ?? "default";
const c = o.length > 0 ? o : [s];
const l = [];
for (const n of c) {
const r = await resolveInspectedChannelAccount({
plugin: t,
cfg: e,
sourceConfig: a,
accountId: n
});
l.push({
accountId: n,
...r
});
}
const u = l.filter((e) => e.configured);
const d = l.some((e) => e.enabled);
const f = l.some((e) => e.enabled && e.configured === void 0);
const p = l.find((e) => e.accountId === s) ?? l[0];
const m = p?.kind === "resolved" && t.status?.buildChannelSummary ? await t.status.buildChannelSummary({
account: p.account,
cfg: e,
defaultAccountId: s,
snapshot: p.snapshot
}) : p?.snapshot;
const h = asNullableRecord(m);
const g = h && typeof h.statusState === "string" ? h.statusState : null;
const _ = h && typeof h.linked === "boolean" ? h.linked : null;
const v = h && typeof h.configured === "boolean" ? h.configured : u.length > 0;
const y = !d ? "disabled" : f ? "configuration status unavailable" : g ? formatChannelStatusState(g) : _ !== null ? _ ? "linked" : "not linked" : v ? "configured" : "not configured";
const b = y === "linked" || y === "configured" ? theme.success : y === "not linked" || y === "auth stabilizing" ? theme.error : theme.muted;
let x = `${sanitizeForLog(t.meta.label ?? t.id).trim() || t.id}: ${y}`;
const S = h && typeof h.authAgeMs === "number" ? h.authAgeMs : null;
const C = h?.self;
if (C?.e164) x += ` ${C.e164}`;
if (S != null && S >= 0) x += ` auth ${formatTimeAgo(S)}`;
n.push(r ? b(x) : x);
for (const r of u) {
const a = r.snapshot;
const o = buildChannelAccountNotes(a, r.kind === "unavailable" || hasConfiguredUnavailableCredentialStatus(r.account) ? "secret unavailable in this command path" : void 0);
if (i && a.allowFrom?.length) {
const n = formatChannelAllowFrom({
plugin: t,
cfg: e,
accountId: a.accountId,
allowFrom: a.allowFrom
}).slice(0, 2);
if (n.length > 0) o.push(`allow:${n.join(",")}`);
}
const s = r.accountId || "default";
const c = r.snapshot.name?.trim();
const l = c ? `${s} (${c})` : s;
n.push(` - ${l}${o.length ? ` (${o.join(", ")})` : ""}`);
}
}
return n;
}
//#endregion
export { buildChannelSummary as t };