openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
195 lines (194 loc) • 7.37 kB
JavaScript
import { b as uniqueStrings } from "./string-normalization-DLmfYZXI.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 resolvePluginMetadataSnapshot } from "./plugin-metadata-snapshot-By9ySblt.mjs";
import { n as resolvePluginControlPlaneWorkspace } from "./control-plane-workspace-OscAdfLv.mjs";
import { t as listPluginContributionIds } from "./plugin-registry-contributions-iAw3gSDD.mjs";
import "./plugin-registry-BrQav-kR.mjs";
import { n as isChannelVisibleInConfiguredLists } from "./channel-meta-CbOcOgly.mjs";
import { r as theme } from "./theme-BOI0xyRZ.mjs";
import { r as resolveMissingOfficialExternalChannelPluginRepairHints } from "./official-external-plugin-repair-hints-CLGaUsqQ.mjs";
import { t as formatDocsLink } from "./links-41lO3DKP.mjs";
import { r as callGateway } from "./call-DVCK1deJ.mjs";
import { t as listReadOnlyChannelPluginsForConfig } from "./read-only-idsFCBWl.mjs";
import { i as listTrustedChannelPluginCatalogEntries } from "./trusted-catalog-BsRi13Hw.mjs";
import { c as requireValidChannelConfig, s as formatChannelAccountLabel, t as NO_CONFIGURED_CHAT_CHANNELS_LINE } from "./shared-yNot1pgX.mjs";
import { r as resolveChannelAccountSnapshot } from "./status-Dia8exqk.mjs";
import { i as normalizeRuntimeChannelAccountSnapshots } from "./read-model-DxXcJLTF.mjs";
//#region src/commands/channels/list.ts
async function readGatewayChannelStatus() {
try {
return await callGateway({
method: "channels.status",
params: {
probe: false,
timeoutMs: 5e3
},
timeoutMs: 5e3
});
} catch {
return null;
}
}
function formatEnabled(e) {
return e === false ? theme.error("disabled") : theme.success("enabled");
}
function formatPresence(e, t) {
return t ? theme.success(e) : theme.warn(`not ${e}`);
}
function formatSource(e, t, n) {
const r = t || "none";
return `${e}=${r === "none" ? theme.error(r) : n === "configured_unavailable" ? theme.warn(`${r}-unavailable`) : r === "env" ? theme.accent(r) : theme.success(r)}`;
}
function formatAccountLine(e) {
const { plugin: t, snapshot: n, installed: r } = e;
const i = formatChannelAccountLabel({
channel: t.id,
accountId: n.accountId,
name: n.name,
channelLabel: t.meta.label ?? t.id,
channelStyle: theme.accent,
accountStyle: theme.heading
});
const a = [formatPresence("installed", r)];
if (isChannelVisibleInConfiguredLists(t.meta) && typeof n.configured === "boolean") a.push(formatPresence("configured", n.configured));
if (typeof n.enabled === "boolean") a.push(formatEnabled(n.enabled));
if (n.linked !== void 0) a.push(formatPresence("linked", n.linked));
if (n.tokenSource) a.push(formatSource("token", n.tokenSource, n.tokenStatus));
if (n.botTokenSource) a.push(formatSource("bot", n.botTokenSource, n.botTokenStatus));
if (n.appTokenSource) a.push(formatSource("app", n.appTokenSource, n.appTokenStatus));
if (n.baseUrl) a.push(`base=${theme.muted(n.baseUrl)}`);
return `- ${i}: ${a.join(", ")}`;
}
async function channelsListCommand(e, t = defaultRuntime) {
const n = await requireValidChannelConfig(t);
if (!n) return;
const r = e.all === true;
const i = resolvePluginControlPlaneWorkspace({
config: n,
env: process.env
});
const a = i.workspaceDir;
const o = resolvePluginMetadataSnapshot({
config: n,
...a ? { workspaceDir: a } : {},
env: process.env,
allowWorkspaceScopedCurrent: true
});
const s = listReadOnlyChannelPluginsForConfig(n, {
...!e.json ? { includeSetupFallbackPlugins: true } : {},
metadataSnapshot: o
});
const c = listTrustedChannelPluginCatalogEntries({
cfg: n,
...a ? { workspaceDir: a } : {},
...o.discovery ? { discovery: o.discovery } : {},
...o.index.installRecords ? { installRecords: o.index.installRecords } : {}
});
const l = e.json === true ? /* @__PURE__ */ new Map() : normalizeRuntimeChannelAccountSnapshots(await readGatewayChannelStatus());
const u = new Set(listPluginContributionIds({
contribution: "channels",
includeDisabled: true,
lookUpTable: o
}));
const d = new Map(c.map((e) => [e.id, u.has(e.id)]));
const isInstalled = (e) => d.get(e) ?? true;
const f = [];
const p = new Map(s.map((e) => [e.id, e.config.listAccountIds(n) ?? []]));
const m = s.filter((e) => (p.get(e.id)?.length ?? 0) > 0 || r && isChannelVisibleInConfiguredLists(e.meta));
const h = new Set(m.map((e) => e.id));
for (const t of e.json ? [] : m) {
const e = p.get(t.id) ?? [];
let r;
if (e.length > 0) {
const i = l.get(t.id) ?? [];
r = [];
for (const a of uniqueStrings([...e, ...i.map((e) => e.accountId)])) r.push(i.find((e) => e.accountId === a) ?? await resolveChannelAccountSnapshot({
plugin: t,
cfg: n,
accountId: a
}));
} else {
const e = await resolveChannelAccountSnapshot({
plugin: t,
cfg: n,
accountId: "default"
});
r = [l.get(t.id)?.find((e) => e.accountId === "default") ?? e];
}
for (const e of r) f.push({
plugin: t,
snapshot: e,
installed: isInstalled(t.id)
});
}
const g = c.filter((e) => !h.has(e.id));
const _ = new Map(resolveMissingOfficialExternalChannelPluginRepairHints({
config: n,
channelIds: g.map((e) => e.id),
...a ? { workspaceDir: a } : {},
manifestRecords: o.plugins
}).map((e) => [e.channelId, e]));
const v = g.map((e) => {
const t = _.get(e.id);
return {
entry: e,
installed: isInstalled(e.id),
configured: Boolean(t),
repairHint: t ? `run ${t.installCommand} or ${t.doctorFixCommand}` : void 0
};
}).filter((e) => r || e.configured);
if (e.json) {
const e = {};
const n = new Map(c.map((e) => [e.id, e]));
for (const t of m) {
const r = p.get(t.id) ?? [];
const i = isInstalled(t.id);
const a = n.get(t.id);
const o = {
label: a?.meta.label ?? t.meta.label,
...a?.officialDocsPath ? { docsPath: a.officialDocsPath } : {}
};
e[t.id] = {
accounts: r,
...o,
installed: i,
origin: r.length > 0 ? "configured" : "available"
};
}
for (const t of v) e[t.entry.id] = {
accounts: [],
label: t.entry.meta.label,
...t.entry.officialDocsPath ? { docsPath: t.entry.officialDocsPath } : {},
installed: t.installed,
origin: t.configured ? "configured" : t.installed ? "available" : "installable"
};
writeRuntimeJson(t, {
chat: e,
...i.diagnostic ? { diagnostics: [i.diagnostic] } : {}
});
return;
}
const y = [];
y.push(theme.heading("Chat channels:"));
if (i.diagnostic) y.push(theme.warn(`- ${i.diagnostic.message}`));
if (f.length === 0 && v.length === 0) y.push(theme.muted(r ? "- no chat channels found" : NO_CONFIGURED_CHAT_CHANNELS_LINE));
else {
for (const e of f) y.push(formatAccountLine(e));
for (const { entry: e, installed: t, configured: n, repairHint: r } of v) {
const i = [
formatPresence("installed", t),
formatPresence("configured", n),
formatEnabled(false)
];
if (r) i.push(r);
y.push(`- ${theme.accent(sanitizeTerminalText(e.meta.label ?? e.id))}: ${i.join(", ")}`);
}
}
t.log(y.join("\n"));
t.log("");
t.log(theme.muted("Model provider usage moved out of `channels list` — see `openclaw status` or `openclaw models list`."));
t.log(`Docs: ${formatDocsLink("/gateway/configuration", "gateway/configuration")}`);
}
//#endregion
export { channelsListCommand };