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
This commit is contained in:
Josh Lehman
2026-04-01 13:07:17 -07:00
committed by GitHub
parent 711c9e7249
commit 90eb5b073f
11 changed files with 118 additions and 44 deletions

View File

@@ -385,4 +385,40 @@ describe("registerPluginCommand", () => {
expectUnsupportedBindingApiResult(result);
});
it("passes host session identity through to the plugin command context", async () => {
let receivedCtx:
| {
sessionKey?: string;
sessionId?: string;
}
| undefined;
const handler = async (ctx: { sessionKey?: string; sessionId?: string }) => {
receivedCtx = ctx;
return { text: "ok" };
};
const result = await executePluginCommand({
command: {
name: "sessioncheck",
description: "Demo command",
acceptsArgs: false,
handler,
pluginId: "demo-plugin",
},
channel: "whatsapp",
senderId: "U123",
isAuthorizedSender: true,
sessionKey: "agent:main:whatsapp:direct:123",
sessionId: "session-123",
commandBody: "/sessioncheck",
config: {} as never,
});
expect(result).toEqual({ text: "ok" });
expect(receivedCtx).toMatchObject({
sessionKey: "agent:main:whatsapp:direct:123",
sessionId: "session-123",
});
});
});

View File

@@ -219,6 +219,8 @@ export async function executePluginCommand(params: {
channelId?: PluginCommandContext["channelId"];
isAuthorizedSender: boolean;
gatewayClientScopes?: PluginCommandContext["gatewayClientScopes"];
sessionKey?: PluginCommandContext["sessionKey"];
sessionId?: PluginCommandContext["sessionId"];
commandBody: string;
config: OpenClawConfig;
from?: PluginCommandContext["from"];
@@ -255,6 +257,8 @@ export async function executePluginCommand(params: {
channelId: params.channelId,
isAuthorizedSender,
gatewayClientScopes: params.gatewayClientScopes,
sessionKey: params.sessionKey,
sessionId: params.sessionId,
args: sanitizedArgs,
commandBody,
config,

View File

@@ -1302,6 +1302,10 @@ export type PluginCommandContext = {
isAuthorizedSender: boolean;
/** Gateway client scopes for internal control-plane callers */
gatewayClientScopes?: string[];
/** Stable host session key for the active conversation when available. */
sessionKey?: string;
/** Ephemeral host session id for the active conversation when available. */
sessionId?: string;
/** Raw command arguments after the command name */
args?: string;
/** The full normalized command body */