UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

95 lines (94 loc) • 4.18 kB
import { c as normalizeOptionalLowercaseString } from "./string-coerce-CCIiB4H7.mjs"; import { r as truncateUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs"; import { i as getPluginRegistryForContext } from "./gateway-request-scope-BvvDhs5D.mjs"; import { Bf as COMMAND_DESCRIPTION_MAX_LENGTH } from "./src-BX8OAe1J.mjs"; import { t as getChannelPlugin } from "./registry-ByqVE5S3.mjs"; import "./plugins-BoMiRtiY.mjs"; import { m as supportsNativeProvider } from "./commands-registry-CwAxsNJ9.mjs"; import { r as listChatCommandsForConfig } from "./commands-registry-list-6-6JFUDI.mjs"; import { n as getPluginCommandEntrySpecsFromRegistrations, t as getPluginCommandEntrySpecs } from "./command-specs-DkjVj8rG.mjs"; import { i as prepareSkillCommandsForAgents } from "./chat-commands-DfZOScnN.mjs"; //#region src/gateway/server-methods/commands-list-result.ts async function buildCommandsListResult(e) { const t = e.includeArgs !== false; const n = e.scope ?? "both"; const r = n === "text" ? "text" : "native"; const i = normalizeOptionalLowercaseString(e.provider); const a = await prepareSkillCommandsForAgents({ cfg: e.cfg, agentIds: [e.agentId], sessionEntry: e.sessionEntry, sessionKey: e.sessionKey }); const o = listChatCommandsForConfig(e.cfg, { skillCommands: a }); const s = new Map(a.map((e) => [`skill:${e.skillName}`, e])); const c = []; for (const e of o) { if (n !== "both" && e.scope !== "both" && e.scope !== n) continue; if (r === "native" && e.scope !== "text" && i && !supportsNativeProvider(e, i)) continue; const a = s.get(e.key); const o = e.nativeName ?? e.key; const l = e.scope === "text" ? void 0 : i && e.nativeName ? getChannelPlugin(i)?.commands?.resolveNativeCommandName?.({ commandKey: e.key, defaultName: e.nativeName }) ?? o : o; let u; if (e.scope !== "native") { const t = /* @__PURE__ */ new Set(); for (const n of e.textAliases) { const e = n.trim(); if (!e) continue; const r = truncateUtf16Safe(e, 200); t.add(r.startsWith("/") ? r : `/${r}`); if (t.size >= 20) break; } u = t.size > 0 ? [...t] : [`/${truncateUtf16Safe(e.key, 200)}`]; } c.push({ name: truncateUtf16Safe(r === "text" ? u?.[0]?.slice(1) ?? e.key : l ?? e.key, 200), ...l ? { nativeName: truncateUtf16Safe(l, 200) } : {}, ...u ? { textAliases: u } : {}, description: truncateUtf16Safe(e.description ?? "", COMMAND_DESCRIPTION_MAX_LENGTH), ...e.category ? { category: e.category === "docks" ? "tools" : e.category } : {}, source: a ? "skill" : "native", scope: e.scope, acceptsArgs: Boolean(e.acceptsArgs), ...t && e.acceptsArgs && e.args?.length ? { args: e.args.slice(0, 20).map((e) => { const t = { name: truncateUtf16Safe(e.name, 200), description: truncateUtf16Safe(e.description, 500), type: e.type }; if (e.required) t.required = true; if (Array.isArray(e.choices)) t.choices = e.choices.slice(0, 50).map((e) => ({ value: truncateUtf16Safe(typeof e === "string" ? e : e.value, 200), label: truncateUtf16Safe(typeof e === "string" ? e : e.label, 200) })); if (typeof e.choices === "function") t.dynamic = true; return t; }) } : {}, ...a ? { skillDisplayName: truncateUtf16Safe(a.displayName ?? a.skillName, 200), skillModelVisible: a.modelVisible !== false } : {} }); } const l = getPluginRegistryForContext(); const u = l ? getPluginCommandEntrySpecsFromRegistrations(l.commands, i, { config: e.cfg }) : getPluginCommandEntrySpecs(i, { config: e.cfg }); for (const e of u) { if (r === "native" && !e.nativeName) continue; c.push({ name: truncateUtf16Safe(r === "text" ? e.name : e.nativeName ?? e.name, 200), ...e.nativeName ? { nativeName: truncateUtf16Safe(e.nativeName, 200) } : {}, textAliases: [`/${truncateUtf16Safe(e.name, 200)}`], description: truncateUtf16Safe(e.description ?? "", COMMAND_DESCRIPTION_MAX_LENGTH), source: "plugin", scope: "both", acceptsArgs: e.acceptsArgs, ...e.clientPresentation ? { clientPresentation: e.clientPresentation } : {} }); } return { commands: c.slice(0, 500) }; } //#endregion export { buildCommandsListResult as t };