mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-29 04:00:36 +00:00
implement PreTooUse PostToolUse PostToolUseFailure and test
This commit is contained in:
parent
f0cc28f80f
commit
a5212123dc
12 changed files with 1539 additions and 79 deletions
|
|
@ -17,8 +17,8 @@ import { createHookOutput } from './types.js';
|
|||
import type {
|
||||
SessionStartSource,
|
||||
SessionEndReason,
|
||||
PermissionMode,
|
||||
AgentType,
|
||||
PermissionMode,
|
||||
} from './types.js';
|
||||
|
||||
const debugLogger = createDebugLogger('TRUSTED_HOOKS');
|
||||
|
|
@ -132,4 +132,70 @@ export class HookSystem {
|
|||
? createHookOutput('SessionEnd', result.finalOutput)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire a PreToolUse event - called before tool execution
|
||||
*/
|
||||
async firePreToolUseEvent(
|
||||
toolName: string,
|
||||
toolInput: Record<string, unknown>,
|
||||
toolUseId: string,
|
||||
permissionMode: PermissionMode,
|
||||
): Promise<DefaultHookOutput | undefined> {
|
||||
const result = await this.hookEventHandler.firePreToolUseEvent(
|
||||
toolName,
|
||||
toolInput,
|
||||
toolUseId,
|
||||
permissionMode,
|
||||
);
|
||||
return result.finalOutput
|
||||
? createHookOutput('PreToolUse', result.finalOutput)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire a PostToolUse event - called after successful tool execution
|
||||
*/
|
||||
async firePostToolUseEvent(
|
||||
toolName: string,
|
||||
toolInput: Record<string, unknown>,
|
||||
toolResponse: Record<string, unknown>,
|
||||
toolUseId: string,
|
||||
permissionMode: PermissionMode,
|
||||
): Promise<DefaultHookOutput | undefined> {
|
||||
const result = await this.hookEventHandler.firePostToolUseEvent(
|
||||
toolName,
|
||||
toolInput,
|
||||
toolResponse,
|
||||
toolUseId,
|
||||
permissionMode,
|
||||
);
|
||||
return result.finalOutput
|
||||
? createHookOutput('PostToolUse', result.finalOutput)
|
||||
: undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire a PostToolUseFailure event - called when tool execution fails
|
||||
*/
|
||||
async firePostToolUseFailureEvent(
|
||||
toolUseId: string,
|
||||
toolName: string,
|
||||
toolInput: Record<string, unknown>,
|
||||
errorMessage: string,
|
||||
isInterrupt?: boolean,
|
||||
permissionMode?: PermissionMode,
|
||||
): Promise<DefaultHookOutput | undefined> {
|
||||
const result = await this.hookEventHandler.firePostToolUseFailureEvent(
|
||||
toolUseId,
|
||||
toolName,
|
||||
toolInput,
|
||||
errorMessage,
|
||||
isInterrupt,
|
||||
permissionMode,
|
||||
);
|
||||
return result.finalOutput
|
||||
? createHookOutput('PostToolUseFailure', result.finalOutput)
|
||||
: undefined;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue