mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-21 05:32:53 +00:00
fix(hooks): propagate sessionKey in after_tool_call context
The after_tool_call hook in handleToolExecutionEnd was passing `sessionKey: undefined` in the ToolContext, even though the value is available on ctx.params. This broke plugins that need session context in after_tool_call handlers (e.g., for per-session audit trails or security logging). - Add `sessionKey` to the `ToolHandlerParams` Pick type - Pass `ctx.params.sessionKey` through to the hook context - Add test assertion to prevent regression Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -427,7 +427,7 @@ export async function handleToolExecutionEnd(
|
||||
.runAfterToolCall(hookEvent, {
|
||||
toolName,
|
||||
agentId: undefined,
|
||||
sessionKey: undefined,
|
||||
sessionKey: ctx.params.sessionKey,
|
||||
})
|
||||
.catch((err) => {
|
||||
ctx.log.warn(`after_tool_call hook failed: tool=${toolName} error=${String(err)}`);
|
||||
|
||||
@@ -132,7 +132,7 @@ export type EmbeddedPiSubscribeContext = {
|
||||
*/
|
||||
export type ToolHandlerParams = Pick<
|
||||
SubscribeEmbeddedPiSessionParams,
|
||||
"runId" | "onBlockReplyFlush" | "onAgentEvent" | "onToolResult"
|
||||
"runId" | "onBlockReplyFlush" | "onAgentEvent" | "onToolResult" | "sessionKey"
|
||||
>;
|
||||
|
||||
export type ToolHandlerState = Pick<
|
||||
|
||||
@@ -114,7 +114,9 @@ describe("after_tool_call hook wiring", () => {
|
||||
const event = firstCall?.[0] as
|
||||
| { toolName?: string; params?: unknown; error?: unknown; durationMs?: unknown }
|
||||
| undefined;
|
||||
const context = firstCall?.[1] as { toolName?: string } | undefined;
|
||||
const context = firstCall?.[1] as
|
||||
| { toolName?: string; agentId?: string; sessionKey?: string }
|
||||
| undefined;
|
||||
expect(event).toBeDefined();
|
||||
expect(context).toBeDefined();
|
||||
if (!event || !context) {
|
||||
@@ -125,6 +127,7 @@ describe("after_tool_call hook wiring", () => {
|
||||
expect(event.error).toBeUndefined();
|
||||
expect(typeof event.durationMs).toBe("number");
|
||||
expect(context.toolName).toBe("read");
|
||||
expect(context.sessionKey).toBe("test-session");
|
||||
});
|
||||
|
||||
it("includes error in after_tool_call event on tool failure", async () => {
|
||||
|
||||
Reference in New Issue
Block a user