hooks

package
v0.4.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApprovalDecision

type ApprovalDecision struct {
	Approved  bool
	Reason    string
	ExpiresAt *int64
}

ApprovalDecision represents the approval decision

type ApprovalHook

type ApprovalHook interface {
	Hook
	ApproveTool(ctx context.Context, req *ToolApprovalRequest) (ApprovalDecision, error)
}

ApprovalHook is called to approve or reject tool execution

type EventHook

type EventHook interface {
	Hook
	OnEvent(ctx context.Context, evt bus.Event) error
}

EventHook observes events without modifying them EventHooks are automatically bridged to the EventBus for monitoring purposes

type Hook

type Hook interface {
	Name() string
}

Hook is the interface for all hooks

type HookAction

type HookAction string

HookAction defines what action to take after a hook runs

const (
	HookActionContinue HookAction = "continue"
	HookActionStop     HookAction = "stop"
	HookActionReject   HookAction = "reject"
	HookActionModify   HookAction = "modify"
)

type HookDecision

type HookDecision struct {
	Action HookAction
	Reason string
}

HookDecision represents the decision made by a hook

type HookManager

type HookManager struct {
	// contains filtered or unexported fields
}

HookManager manages all hooks

func NewHookManager

func NewHookManager() *HookManager

NewHookManager creates a new hook manager

func NewHookManagerWithBus

func NewHookManagerWithBus(eventBus *bus.EventBus) *HookManager

SetEventBus sets the event bus for the hook manager This enables automatic bridging of EventHooks to the EventBus

func (*HookManager) AfterLLM

AfterLLM calls all LLM hooks after an LLM call

func (*HookManager) AfterTool

AfterTool calls all tool hooks after tool execution

func (*HookManager) ApproveTool

ApproveTool calls all approval hooks for tool execution

func (*HookManager) BeforeLLM

BeforeLLM calls all LLM hooks before an LLM call

func (*HookManager) BeforeTool

BeforeTool calls all tool hooks before tool execution

func (*HookManager) OnEvent

func (m *HookManager) OnEvent(ctx context.Context, evt bus.Event) error

OnEvent broadcasts an event to all event hooks

func (*HookManager) Register

func (m *HookManager) Register(reg HookRegistration) error

Register registers a hook

type HookRegistration

type HookRegistration struct {
	Name   string
	Source HookSource
	Hook   interface{} // LLMHook, ToolHook, ApprovalHook, or EventHook
}

HookRegistration holds hook configuration

type HookSource

type HookSource string

HookSource indicates where the hook comes from

const (
	HookSourceBuiltIn HookSource = "built_in"
	HookSourceConfig  HookSource = "config"
	HookSourceProcess HookSource = "process"
)

type LLMHook

type LLMHook interface {
	Hook
	BeforeLLM(ctx context.Context, req *LLMHookRequest) (*LLMHookRequest, HookDecision, error)
	AfterLLM(ctx context.Context, resp *LLMHookResponse) (*LLMHookResponse, HookDecision, error)
}

LLMHook is called before and after LLM calls

type LLMHookRequest

type LLMHookRequest struct {
	Provider string
	Model    string
	Messages []provider.Message
	Tools    []map[string]interface{}
}

LLMHookRequest contains data for LLM-related hooks

type LLMHookResponse

type LLMHookResponse struct {
	Content   string
	ToolCalls []types.ToolCall
	Raw       interface{}
}

LLMHookResponse contains the LLM response for hooks

type MessageFilterHook

type MessageFilterHook struct {
	// contains filtered or unexported fields
}

MessageFilterHook filters messages based on content

func NewMessageFilterHook

func NewMessageFilterHook() *MessageFilterHook

NewMessageFilterHook creates a new message filter hook

func (*MessageFilterHook) AddBlockedPattern

func (h *MessageFilterHook) AddBlockedPattern(pattern string) error

AddBlockedPattern adds a pattern that should be blocked

func (*MessageFilterHook) AddWarnPattern

func (h *MessageFilterHook) AddWarnPattern(pattern string) error

AddWarnPattern adds a pattern that should trigger a warning

func (*MessageFilterHook) AfterLLM

AfterLLM passes through the response

func (*MessageFilterHook) AfterTool

AfterTool passes through results

func (*MessageFilterHook) BeforeLLM

BeforeLLM checks messages for blocked content

func (*MessageFilterHook) BeforeTool

BeforeTool passes through tool calls

func (*MessageFilterHook) Name

func (h *MessageFilterHook) Name() string

type PrivacyHook

type PrivacyHook struct {
	// contains filtered or unexported fields
}

PrivacyHook provides PII detection and redaction

func NewPrivacyHook

func NewPrivacyHook() *PrivacyHook

NewPrivacyHook creates a new privacy hook

func (*PrivacyHook) AfterLLM

AfterLLM passes through the response without modification

func (*PrivacyHook) AfterTool

AfterTool passes through the result without modification

func (*PrivacyHook) BeforeLLM

BeforeLLM redacts PII from messages before sending to LLM

func (*PrivacyHook) BeforeTool

BeforeTool redacts PII from tool arguments before execution

func (*PrivacyHook) Name

func (h *PrivacyHook) Name() string

type RateLimitHook

type RateLimitHook struct {
	// contains filtered or unexported fields
}

RateLimitHook limits the rate of LLM calls

func NewRateLimitHook

func NewRateLimitHook(maxPerMinute int) *RateLimitHook

NewRateLimitHook creates a new rate limit hook

func (*RateLimitHook) AfterLLM

AfterLLM passes through the response

func (*RateLimitHook) AfterTool

AfterTool passes through

func (*RateLimitHook) BeforeLLM

BeforeLLM checks rate limits

func (*RateLimitHook) BeforeTool

BeforeTool passes through

func (*RateLimitHook) Name

func (h *RateLimitHook) Name() string

type RiskLevel

type RiskLevel int

RiskLevel defines the risk level of a command

const (
	RiskLevelSafe RiskLevel = iota
	RiskLevelMedium
	RiskLevelDangerous
	RiskLevelCritical
)

func (RiskLevel) String

func (r RiskLevel) String() string

type ToolApprovalRequest

type ToolApprovalRequest struct {
	ToolName  string
	ToolArgs  map[string]interface{}
	Command   string
	RiskLevel RiskLevel
	SessionID string
}

ToolApprovalRequest contains data for tool approval hooks

type ToolCallHookRequest

type ToolCallHookRequest struct {
	ToolName string
	ToolArgs map[string]interface{}
	Result   interface{}
	Error    error
}

ToolCallHookRequest contains data for tool call hooks

type ToolHook

type ToolHook interface {
	Hook
	BeforeTool(ctx context.Context, call *ToolCallHookRequest) (*ToolCallHookRequest, HookDecision, error)
	AfterTool(ctx context.Context, result *ToolResultHookResponse) (*ToolResultHookResponse, HookDecision, error)
}

ToolHook is called before and after tool execution

type ToolResultHookResponse

type ToolResultHookResponse struct {
	ToolName    string
	ToolArgs    map[string]interface{}
	Result      interface{}
	Error       error
	ExecutionMs int64
}

ToolResultHookResponse contains the result of tool execution

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL