Files
openclaw/src/auto-reply/reply/commands-plugin.ts
Josh Lehman 90eb5b073f fix: pass session identity to plugin commands (#59044)
Merged via squash.

Prepared head SHA: 0f7a23f139
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
2026-04-01 13:07:17 -07:00

61 lines
1.7 KiB
TypeScript

/**
* Plugin Command Handler
*
* Handles commands registered by plugins, bypassing the LLM agent.
* This handler is called before built-in command handlers.
*/
import { matchPluginCommand, executePluginCommand } from "../../plugins/commands.js";
import type { CommandHandler, CommandHandlerResult } from "./commands-types.js";
/**
* Handle plugin-registered commands.
* Returns a result if a plugin command was matched and executed,
* or null to continue to the next handler.
*/
export const handlePluginCommand: CommandHandler = async (
params,
allowTextCommands,
): Promise<CommandHandlerResult | null> => {
const { command, cfg } = params;
if (!allowTextCommands) {
return null;
}
// Try to match a plugin command
const match = matchPluginCommand(command.commandBodyNormalized);
if (!match) {
return null;
}
// Execute the plugin command (always returns a result)
const result = await executePluginCommand({
command: match.command,
args: match.args,
senderId: command.senderId,
channel: command.channel,
channelId: command.channelId,
isAuthorizedSender: command.isAuthorizedSender,
gatewayClientScopes: params.ctx.GatewayClientScopes,
sessionKey: params.sessionKey,
sessionId: params.sessionEntry?.sessionId,
commandBody: command.commandBodyNormalized,
config: cfg,
from: command.from,
to: command.to,
accountId: params.ctx.AccountId ?? undefined,
messageThreadId:
typeof params.ctx.MessageThreadId === "string" ||
typeof params.ctx.MessageThreadId === "number"
? params.ctx.MessageThreadId
: undefined,
threadParentId: params.ctx.ThreadParentId?.trim() || undefined,
});
return {
shouldContinue: false,
reply: result,
};
};