Documentation
¶
Index ¶
- type AskPermissionFunc
- type CheckResult
- type ExecuteResult
- type HookRunner
- type PermissionChecker
- type PermissionMode
- type Registry
- func (r *Registry) All() []Tool
- func (r *Registry) ExecuteBatch(ctx context.Context, calls []*provider.ToolCall, checker PermissionChecker, ...) []ExecuteResult
- func (r *Registry) ExecuteTool(ctx context.Context, call *provider.ToolCall) *Result
- func (r *Registry) ExecuteWithPermission(ctx context.Context, call *provider.ToolCall, checker PermissionChecker, ...) *Result
- func (r *Registry) Get(name string) (Tool, bool)
- func (r *Registry) Register(t Tool)
- func (r *Registry) ToolDefs() []provider.ToolDef
- type Result
- type SimplePermissionChecker
- type Tool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AskPermissionFunc ¶
AskPermissionFunc 权限询问回调(阻塞直到用户回答)
type CheckResult ¶
type CheckResult int
CheckResult 权限检查三态结果
const ( ResultAllow CheckResult = iota // 允许执行 ResultDeny // 拒绝执行 ResultNeedAsk // 需要询问用户 )
type ExecuteResult ¶
ExecuteResult 单个工具执行结果
type HookRunner ¶
type HookRunner interface {
// RunPreToolUse 执行 preToolUse 钩子,返回 false 表示阻止
RunPreToolUse(ctx context.Context, toolName, toolInput string) (bool, error)
// RunPostToolUse 执行 postToolUse 钩子
RunPostToolUse(ctx context.Context, toolName, toolOutput string, isError bool)
}
HookRunner 钩子执行接口(避免循环依赖)
type PermissionChecker ¶
type PermissionChecker interface {
Check(toolName string, isReadOnly bool) (CheckResult, string)
}
PermissionChecker 权限检查接口
type PermissionMode ¶
type PermissionMode string
PermissionMode 权限模式
const ( ModeBypass PermissionMode = "bypass" ModeAcceptEdits PermissionMode = "acceptEdits" ModeDefault PermissionMode = "default" ModePlan PermissionMode = "plan" ModeInteractive PermissionMode = "interactive" )
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry 工具注册表
func (*Registry) ExecuteBatch ¶
func (r *Registry) ExecuteBatch(ctx context.Context, calls []*provider.ToolCall, checker PermissionChecker, askFn AskPermissionFunc, hooks ...HookRunner) []ExecuteResult
ExecuteBatch 批量执行工具调用 只读工具并发执行,写入工具顺序执行
func (*Registry) ExecuteTool ¶
ExecuteTool 执行单个工具调用
func (*Registry) ExecuteWithPermission ¶
func (r *Registry) ExecuteWithPermission(ctx context.Context, call *provider.ToolCall, checker PermissionChecker, askFn AskPermissionFunc, hooks ...HookRunner) *Result
ExecuteWithPermission 执行单个工具调用(带权限检查 + 用户询问 + 钩子)
type SimplePermissionChecker ¶
type SimplePermissionChecker struct {
Mode PermissionMode
}
SimplePermissionChecker 基于模式的权限检查器
func (*SimplePermissionChecker) Check ¶
func (c *SimplePermissionChecker) Check(toolName string, isReadOnly bool) (CheckResult, string)
Click to show internal directories.
Click to hide internal directories.