Merge pull request #2696 from QwenLM/feat/hooks-refactor-ui-event

refactor(ui): improve hook event handling with dedicated history items
This commit is contained in:
DennisYu07 2026-04-01 15:56:17 +08:00 committed by GitHub
commit 06a0f4797d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 639 additions and 28 deletions

View file

@ -87,7 +87,7 @@ import {
ExtensionManager,
type Extension,
} from '../extension/extensionManager.js';
import { HookSystem } from '../hooks/index.js';
import { HookSystem, createHookOutput } from '../hooks/index.js';
import { MessageBus } from '../confirmation-bus/message-bus.js';
import {
MessageBusType,
@ -826,6 +826,7 @@ export class Config {
// Execute the appropriate hook based on eventName
let result;
let stopHookCount: number | undefined;
const input = request.input || {};
const signal = request.signal;
switch (request.eventName) {
@ -835,13 +836,18 @@ export class Config {
signal,
);
break;
case 'Stop':
result = await hookSystem.fireStopEvent(
case 'Stop': {
const stopResult = await hookSystem.fireStopEvent(
(input['stop_hook_active'] as boolean) || false,
(input['last_assistant_message'] as string) || '',
signal,
);
result = stopResult.finalOutput
? createHookOutput('Stop', stopResult.finalOutput)
: undefined;
stopHookCount = stopResult.allOutputs.length;
break;
}
case 'PreToolUse': {
result = await hookSystem.firePreToolUseEvent(
(input['tool_name'] as string) || '',
@ -929,6 +935,8 @@ export class Config {
correlationId: request.correlationId,
success: true,
output: result,
// Include stop hook count for Stop events
stopHookCount,
} as HookExecutionResponse);
} catch (error) {
this.debugLogger.warn(`Hook execution failed: ${error}`);