Overview
Methods
getHooks()
Get all hooks (instances, unordered).getFlowHooks()
Get hooks for a given flow, sorted by priority (descending).getFlowStageHooks()
Get hooks for a specific flow and stage.getFlowHooksForOwner()
Get flow hooks filtered by owner.getClsHooks()
Get hooks defined on a given class.registerHooks()
Register hooks dynamically.| Parameter | Type | Description |
|---|---|---|
embedded | boolean | Whether hooks are class-embedded |
records | HookRecord[] | Hook definitions to register |
Hook Structure
Available Flows
tools:call-tool
Tool execution flow
resources:read-resource
Resource read flow
resources:list-resources
Resource listing flow
prompts:get-prompt
Prompt retrieval flow
Flow Stages
Most flows have these stages:| Stage | Description |
|---|---|
beforeValidation | Before input validation |
afterValidation | After input validation |
beforeExecute | Before execution |
afterExecute | After execution |
onError | On error (for error handling) |
finally | Always runs (cleanup) |
Priority
Hooks are sorted by priority (descending):Embedded vs External Hooks
Embedded Hooks
Defined on tool/resource/prompt classes using@Hooks decorator:
- Are scoped to their class
- Use
getClsHooks()for lookup - Have
embedded: true
External Hooks
Registered via plugins or directly:- Can target any flow
- Use
getFlowHooks()for lookup - Have
embedded: false
Hook Context
Hooks receive a context object with:Index Structure
Unlike other registries, HookRegistry uses specialized indexes:| Index | Key | Description |
|---|---|---|
recordsByCls | Token | Historical records by class |
entriesByCls | Token | Hook instances by class |
hooksByFlow | flow | Hooks indexed by flow |
hooksByFlowStage | flow:stage | Hooks indexed by flow + stage |