Files
openclaw/src/plugins/plugin-command-metadata.ts
T
Peter Steinberger d6f70a96cb fix(plugins): native commands execute the selected plugin (#121544)
* fix(plugins): preserve selected command identity

* test(telegram): use scoped command registries

* test(telegram): isolate command runtime fixtures

* test(telegram): warm native command runtime

* refactor(plugins): keep command metadata private

* fix(plugins): accept synchronous command handlers

* fix(plugins): scope command drain bypass to live execution

* test(telegram): use scoped command registry fixtures

* test(telegram): isolate native menu runtime fixtures

* test(telegram): isolate login session store

* test(telegram): surface login flow failures

* test(telegram): preload native login module

* test(telegram): scope native command registries

* fix(plugins): complete command dispatch contracts

* fix(plugins): break command dispatch import cycles

* fix(plugins): stabilize command dispatch contracts

* fix(channels): keep plugin dispatch options internal

* fix(plugins): keep command dispatch carrier opaque

* test(channels): align delivery adapter fixtures

* test(delivery): align custody ownership coverage

* test(delivery): align latest queue reconciliation

* test(channels): drop obsolete delivery wrappers

* fix(plugins): rebind channel reload starts

* fix(plugins): scope command catalog reloads

* fix(ci): align current runtime contracts

* chore(plugin-sdk): refresh API baseline
2026-08-10 19:30:47 -07:00

62 lines
2.3 KiB
TypeScript

import { normalizeOptionalLowercaseString } from "@openclaw/normalization-core/string-coerce";
import type { OpenClawPluginCommandDefinition } from "./types.js";
type PluginCommandNativeMetadata = Readonly<{
name: string;
description: string;
descriptionLocalizations?: Readonly<Record<string, string>>;
acceptsArgs: boolean;
requireAuth: boolean;
progressMessage?: string;
}>;
export function pluginCommandSupportsChannel(
command: OpenClawPluginCommandDefinition,
channel?: string,
): boolean {
if (!command.channels || command.channels.length === 0 || !channel) {
return true;
}
const normalizedChannel = normalizeOptionalLowercaseString(channel);
return command.channels.some(
(entry) => normalizeOptionalLowercaseString(entry) === normalizedChannel,
);
}
/** Projects the safe provider-native metadata shared by catalog and runtime surfaces. */
export function projectPluginCommandNativeMetadata(
command: OpenClawPluginCommandDefinition,
provider?: string,
): PluginCommandNativeMetadata {
const normalizedProvider = normalizeOptionalLowercaseString(provider);
const providerName = normalizedProvider ? command.nativeNames?.[normalizedProvider] : undefined;
const defaultName = command.nativeNames?.default;
const name =
typeof providerName === "string" && providerName.trim()
? providerName.trim()
: typeof defaultName === "string" && defaultName.trim()
? defaultName.trim()
: command.name.trim() || command.name;
const providerProgress = normalizedProvider
? command.nativeProgressMessages?.[normalizedProvider]
: undefined;
const defaultProgress = command.nativeProgressMessages?.default;
const progressMessage =
typeof providerProgress === "string" && providerProgress.trim()
? providerProgress.trim()
: typeof defaultProgress === "string" && defaultProgress.trim()
? defaultProgress.trim()
: undefined;
const descriptionLocalizations = command.descriptionLocalizations
? Object.freeze({ ...command.descriptionLocalizations })
: undefined;
return Object.freeze({
name,
description: command.description.trim(),
...(descriptionLocalizations ? { descriptionLocalizations } : {}),
acceptsArgs: command.acceptsArgs ?? false,
requireAuth: command.requireAuth !== false,
...(progressMessage ? { progressMessage } : {}),
});
}