Migrate beforeTool and afterTool hooks to hookSystem (#17204)

Co-authored-by: Ishaan Gupta <ishaankone@gmail.com>
Co-authored-by: Tommaso Sciortino <sciortino@gmail.com>
This commit is contained in:
Vedant Mahajan
2026-01-21 22:43:03 +05:30
committed by GitHub
parent 4d77934a83
commit 6b14dc8240
6 changed files with 149 additions and 225 deletions

View File

@@ -22,6 +22,7 @@ import type {
BeforeModelHookOutput,
AfterModelHookOutput,
BeforeToolSelectionHookOutput,
McpToolContext,
} from './types.js';
import type { AggregatedHookResult } from './hookAggregator.js';
import type {
@@ -297,4 +298,46 @@ export class HookSystem {
return {};
}
}
async fireBeforeToolEvent(
toolName: string,
toolInput: Record<string, unknown>,
mcpContext?: McpToolContext,
): Promise<DefaultHookOutput | undefined> {
try {
const result = await this.hookEventHandler.fireBeforeToolEvent(
toolName,
toolInput,
mcpContext,
);
return result.finalOutput;
} catch (error) {
debugLogger.debug(`BeforeTool hook failed for ${toolName}:`, error);
return undefined;
}
}
async fireAfterToolEvent(
toolName: string,
toolInput: Record<string, unknown>,
toolResponse: {
llmContent: unknown;
returnDisplay: unknown;
error: unknown;
},
mcpContext?: McpToolContext,
): Promise<DefaultHookOutput | undefined> {
try {
const result = await this.hookEventHandler.fireAfterToolEvent(
toolName,
toolInput,
toolResponse as Record<string, unknown>,
mcpContext,
);
return result.finalOutput;
} catch (error) {
debugLogger.debug(`AfterTool hook failed for ${toolName}:`, error);
return undefined;
}
}
}