fix: prefer target entry for plugin commands

This commit is contained in:
Tak Hoffman
2026-04-10 20:42:09 -05:00
parent 569751898f
commit 42a4dee8b6
2 changed files with 40 additions and 2 deletions

View File

@@ -72,4 +72,41 @@ describe("handlePluginCommand", () => {
}),
);
});
it("prefers the target session entry from sessionStore for plugin command metadata", async () => {
matchPluginCommandMock.mockReturnValue({
command: { name: "card" },
args: "",
});
executePluginCommandMock.mockResolvedValue({ text: "from plugin" });
const params = buildPluginParams(
"/card",
{
commands: { text: true },
channels: { whatsapp: { allowFrom: ["*"] } },
} as OpenClawConfig,
);
params.sessionEntry = {
sessionId: "wrapper-session",
sessionFile: "/tmp/wrapper-session.jsonl",
updatedAt: Date.now(),
} as HandleCommandsParams["sessionEntry"];
params.sessionStore = {
[params.sessionKey]: {
sessionId: "target-session",
sessionFile: "/tmp/target-session.jsonl",
updatedAt: Date.now(),
},
};
await handlePluginCommand(params, true);
expect(executePluginCommandMock).toHaveBeenCalledWith(
expect.objectContaining({
sessionId: "target-session",
sessionFile: "/tmp/target-session.jsonl",
}),
);
});
});

View File

@@ -19,6 +19,7 @@ export const handlePluginCommand: CommandHandler = async (
allowTextCommands,
): Promise<CommandHandlerResult | null> => {
const { command, cfg } = params;
const targetSessionEntry = params.sessionStore?.[params.sessionKey] ?? params.sessionEntry;
if (!allowTextCommands) {
return null;
@@ -40,8 +41,8 @@ export const handlePluginCommand: CommandHandler = async (
isAuthorizedSender: command.isAuthorizedSender,
gatewayClientScopes: params.ctx.GatewayClientScopes,
sessionKey: params.sessionKey,
sessionId: params.sessionEntry?.sessionId,
sessionFile: params.sessionEntry?.sessionFile,
sessionId: targetSessionEntry?.sessionId,
sessionFile: targetSessionEntry?.sessionFile,
commandBody: command.commandBodyNormalized,
config: cfg,
from: command.from,