From 7b2697bd4dddbd19dbaa8570507a9fe92e365e3f Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 18 Feb 2026 17:29:30 +0000 Subject: [PATCH] refactor(auto-reply): reuse native command spec mapping --- src/auto-reply/commands-registry.ts | 39 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/auto-reply/commands-registry.ts b/src/auto-reply/commands-registry.ts index 6abbc1bf9..dbfc789e7 100644 --- a/src/auto-reply/commands-registry.ts +++ b/src/auto-reply/commands-registry.ts @@ -137,32 +137,39 @@ function resolveNativeName(command: ChatCommandDefinition, provider?: string): s return command.nativeName; } +function toNativeCommandSpec(command: ChatCommandDefinition, provider?: string): NativeCommandSpec { + return { + name: resolveNativeName(command, provider) ?? command.key, + description: command.description, + acceptsArgs: Boolean(command.acceptsArgs), + args: command.args, + }; +} + +function listNativeSpecsFromCommands( + commands: ChatCommandDefinition[], + provider?: string, +): NativeCommandSpec[] { + return commands + .filter((command) => command.scope !== "text" && command.nativeName) + .map((command) => toNativeCommandSpec(command, provider)); +} + export function listNativeCommandSpecs(params?: { skillCommands?: SkillCommandSpec[]; provider?: string; }): NativeCommandSpec[] { - return listChatCommands({ skillCommands: params?.skillCommands }) - .filter((command) => command.scope !== "text" && command.nativeName) - .map((command) => ({ - name: resolveNativeName(command, params?.provider) ?? command.key, - description: command.description, - acceptsArgs: Boolean(command.acceptsArgs), - args: command.args, - })); + return listNativeSpecsFromCommands( + listChatCommands({ skillCommands: params?.skillCommands }), + params?.provider, + ); } export function listNativeCommandSpecsForConfig( cfg: OpenClawConfig, params?: { skillCommands?: SkillCommandSpec[]; provider?: string }, ): NativeCommandSpec[] { - return listChatCommandsForConfig(cfg, params) - .filter((command) => command.scope !== "text" && command.nativeName) - .map((command) => ({ - name: resolveNativeName(command, params?.provider) ?? command.key, - description: command.description, - acceptsArgs: Boolean(command.acceptsArgs), - args: command.args, - })); + return listNativeSpecsFromCommands(listChatCommandsForConfig(cfg, params), params?.provider); } export function findCommandByNativeName(