openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
106 lines (105 loc) • 3.99 kB
JavaScript
import { c as normalizeOptionalLowercaseString, l as normalizeOptionalString, o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs";
import { n as groupPluginRecords } from "./record-groups-DII71OvH.mjs";
import { t as dedupeByKey } from "./dedupe-by-key-Cpowmfct.mjs";
import { t as getChannelPlugin } from "./registry-ByqVE5S3.mjs";
import "./plugins-BoMiRtiY.mjs";
import { t as isCommandFlagEnabled } from "./commands.flags-bgyYi4vf.mjs";
import "./commands-registry-CwAxsNJ9.mjs";
import { n as listChatCommands, r as listChatCommandsForConfig } from "./commands-registry-list-6-6JFUDI.mjs";
import { n as listPluginCommands } from "./commands-oVh2_3bU.mjs";
//#region src/auto-reply/command-status-builders.ts
const COMMAND_CATEGORIES = [
["session", "Session"],
["options", "Options"],
["status", "Status"],
["management", "Management"],
["media", "Media"],
["tools", "Tools"]
];
/** Builds the compact slash-command help text shown by `/help`. */
function buildHelpMessage(e) {
const t = [
"/think <level|default>",
"/model <id>",
"/fast status|auto|on|off|ultrafast|default",
"/verbose on|off|full",
"/trace on|off|raw"
];
for (const n of ["config", "debug"]) if (isCommandFlagEnabled(e, n)) t.push(`/${n}`);
return [
"ℹ️ Help",
"",
"Session",
" /new | /reset | /compact [instructions] | /stop",
"",
"Options",
` ${t.join(" | ")}`,
"",
"Status",
" /status | /whoami | /context",
"",
"Skills",
" /skill <name> [input]",
"",
"More: /commands for full list, /tools for available capabilities"
].join("\n");
}
const COMMANDS_PER_PAGE = 8;
function formatCommandEntry(e) {
const t = e.nativeName ? `/${e.nativeName}` : normalizeOptionalString(e.textAliases[0]) || `/${e.key}`;
const n = dedupeByKey(e.textAliases.map((e) => e.trim()).filter(Boolean).filter((e) => normalizeLowercaseStringOrEmpty(e) !== normalizeLowercaseStringOrEmpty(t)), normalizeLowercaseStringOrEmpty);
return `${t}${n.length ? ` (${n.join(", ")})` : ""}${e.scope === "text" ? " [text]" : ""} - ${e.description}`;
}
/** Builds `/commands` text, returning only the rendered message body. */
function buildCommandsMessage(e, t, n) {
return buildCommandsMessagePaginated(e, t, n).text;
}
/** Builds `/commands` text and pagination metadata for surfaces with native list controls. */
function buildCommandsMessagePaginated(e, t, n) {
const r = Math.max(1, n?.page ?? 1);
const i = normalizeOptionalLowercaseString(n?.surface);
const a = n?.forcePaginatedList === true || Boolean(i && getChannelPlugin(i)?.commands?.buildCommandsListChannelData);
const o = e ? listChatCommandsForConfig(e, { skillCommands: t }) : listChatCommands({ skillCommands: t });
const s = listPluginCommands();
const c = groupPluginRecords(o, (e) => e.category === "docks" ? "tools" : e.category ?? "tools");
const l = [];
for (const [e, t] of COMMAND_CATEGORIES) for (const n of c.get(e) ?? []) l.push({
label: t,
text: formatCommandEntry(n)
});
for (const e of s) {
const t = e.pluginId ? ` (${e.pluginId})` : "";
const n = e.name.includes("-") ? `\`/${e.name}\`` : `/${e.name}`;
l.push({
label: "Plugins",
text: `${n}${t} - ${e.description}`
});
}
const u = a ? Math.max(1, Math.ceil(l.length / COMMANDS_PER_PAGE)) : 1;
const d = a ? Math.min(r, u) : 1;
const f = (d - 1) * COMMANDS_PER_PAGE;
const p = a ? l.slice(f, f + COMMANDS_PER_PAGE) : l;
const m = [];
for (const [e, t] of p.entries()) {
if (t.label !== p[e - 1]?.label) {
if (m.length > 0) m.push("");
m.push(t.label);
}
m.push(` ${t.text}`);
}
const h = [
a ? `ℹ️ Commands (${d}/${u})` : "ℹ️ Slash commands",
"",
m.join("\n")
];
if (!a) h.push("", "More: /tools for available capabilities");
return {
text: h.join("\n").trim(),
totalPages: u,
currentPage: d,
hasNext: d < u,
hasPrev: d > 1
};
}
//#endregion
export { buildCommandsMessagePaginated as n, buildHelpMessage as r, buildCommandsMessage as t };