openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
56 lines (55 loc) • 2.69 kB
JavaScript
import { c as normalizeOptionalLowercaseString } from "./string-coerce-CCIiB4H7.mjs";
import { v as requireActivePluginRegistry } from "./runtime-ezCEpumg.mjs";
import { n as getLoadedChannelPlugin } from "./registry-ByqVE5S3.mjs";
import "./plugins-BoMiRtiY.mjs";
import { t as listRegisteredPluginCommands } from "./plugin-command-registry-Djk4s-ty.mjs";
import { n as projectPluginCommandNativeMetadata, t as pluginCommandSupportsChannel } from "./plugin-command-metadata-BYwURRD6.mjs";
import { r as resolveReadOnlyChannelCommandDefaults } from "./read-only-command-defaults-D1X0yxjh.mjs";
//#region src/plugins/command-specs.ts
function pluginNativeCommandsEnabled(e, t) {
if (!e) return true;
const n = t.config ? resolveReadOnlyChannelCommandDefaults(e, {
...t,
config: t.config
}) : void 0;
return (getLoadedChannelPlugin(e)?.commands ?? n)?.nativeCommandsAutoEnabled === true;
}
function getPluginCommandSpecs(e, t = {}) {
const n = normalizeOptionalLowercaseString(e);
if (!pluginNativeCommandsEnabled(n, t)) return [];
return listProviderPluginCommandSpecs(n);
}
function getPluginCommandEntrySpecs(e, t = {}) {
return getPluginCommandEntrySpecsFromRegistrations(requireActivePluginRegistry().commands, e, t);
}
function getPluginCommandEntrySpecsFromRegistrations(e, t, n = {}) {
const r = normalizeOptionalLowercaseString(t);
const i = pluginNativeCommandsEnabled(r, n);
return e.map((e) => serializePluginCommandEntrySpec(e.command, r, i)).filter((e) => e !== null);
}
/** Resolve plugin command specs for a provider's native naming surface without support gating. */
function listProviderPluginCommandSpecs(e) {
return listRegisteredPluginCommands(requireActivePluginRegistry()).filter((t) => pluginCommandSupportsChannel(t, e)).map((t) => serializePluginCommandSpec(t, e));
}
function serializePluginCommandSpec(e, t) {
const n = projectPluginCommandNativeMetadata(e, t);
return {
name: n.name,
description: n.description,
acceptsArgs: n.acceptsArgs,
...n.descriptionLocalizations ? { descriptionLocalizations: { ...n.descriptionLocalizations } } : {}
};
}
function serializePluginCommandEntrySpec(e, t, n) {
if (!pluginCommandSupportsChannel(e, t)) return null;
const r = n ? projectPluginCommandNativeMetadata(e, t).name : void 0;
return {
name: e.name.trim() || e.name,
description: e.description.trim(),
acceptsArgs: e.acceptsArgs ?? false,
...r ? { nativeName: r } : {},
...e.clientPresentation ? { clientPresentation: e.clientPresentation } : {}
};
}
//#endregion
export { listProviderPluginCommandSpecs as i, getPluginCommandEntrySpecsFromRegistrations as n, getPluginCommandSpecs as r, getPluginCommandEntrySpecs as t };