mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 01:50:22 +00:00
Plugins: honor native command aliases at dispatch
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
executePluginCommand,
|
||||
getPluginCommandSpecs,
|
||||
listPluginCommands,
|
||||
matchPluginCommand,
|
||||
registerPluginCommand,
|
||||
} from "./commands.js";
|
||||
import { setActivePluginRegistry } from "./runtime.js";
|
||||
@@ -107,6 +108,29 @@ describe("registerPluginCommand", () => {
|
||||
expect(getPluginCommandSpecs("slack")).toEqual([]);
|
||||
});
|
||||
|
||||
it("matches provider-specific native aliases back to the canonical command", () => {
|
||||
const result = registerPluginCommand("demo-plugin", {
|
||||
name: "voice",
|
||||
nativeNames: {
|
||||
default: "talkvoice",
|
||||
discord: "discordvoice",
|
||||
},
|
||||
description: "Demo command",
|
||||
acceptsArgs: true,
|
||||
handler: async () => ({ text: "ok" }),
|
||||
});
|
||||
|
||||
expect(result).toEqual({ ok: true });
|
||||
expect(matchPluginCommand("/talkvoice now")).toMatchObject({
|
||||
command: expect.objectContaining({ name: "voice", pluginId: "demo-plugin" }),
|
||||
args: "now",
|
||||
});
|
||||
expect(matchPluginCommand("/discordvoice now")).toMatchObject({
|
||||
command: expect.objectContaining({ name: "voice", pluginId: "demo-plugin" }),
|
||||
args: "now",
|
||||
});
|
||||
});
|
||||
|
||||
it("resolves Discord DM command bindings with the user target prefix intact", () => {
|
||||
expect(
|
||||
__testing.resolveBindingConversationFromCommand({
|
||||
|
||||
@@ -219,7 +219,11 @@ export function matchPluginCommand(
|
||||
const args = spaceIndex === -1 ? undefined : trimmed.slice(spaceIndex + 1).trim();
|
||||
|
||||
const key = commandName.toLowerCase();
|
||||
const command = pluginCommands.get(key);
|
||||
const command =
|
||||
pluginCommands.get(key) ??
|
||||
Array.from(pluginCommands.values()).find((candidate) =>
|
||||
listPluginInvocationNames(candidate).includes(key),
|
||||
);
|
||||
|
||||
if (!command) {
|
||||
return null;
|
||||
@@ -458,6 +462,24 @@ function resolvePluginNativeName(
|
||||
return command.name;
|
||||
}
|
||||
|
||||
function listPluginInvocationNames(command: OpenClawPluginCommandDefinition): string[] {
|
||||
const names = new Set<string>();
|
||||
const push = (value: string | undefined) => {
|
||||
const normalized = value?.trim().toLowerCase();
|
||||
if (!normalized) {
|
||||
return;
|
||||
}
|
||||
names.add(`/${normalized}`);
|
||||
};
|
||||
|
||||
push(command.name);
|
||||
push(command.nativeNames?.default);
|
||||
push(command.nativeNames?.telegram);
|
||||
push(command.nativeNames?.discord);
|
||||
|
||||
return [...names];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin command specs for native command registration (e.g., Telegram).
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user