mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-27 00:52:05 +00:00
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:
@@ -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",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user