* First commit

This commit is contained in:
lxowalle
2026-02-04 19:06:13 +08:00
commit e17693b17c
57 changed files with 7994 additions and 0 deletions

50
pkg/tools/registry.go Normal file
View File

@@ -0,0 +1,50 @@
package tools
import (
"context"
"fmt"
"sync"
)
type ToolRegistry struct {
tools map[string]Tool
mu sync.RWMutex
}
func NewToolRegistry() *ToolRegistry {
return &ToolRegistry{
tools: make(map[string]Tool),
}
}
func (r *ToolRegistry) Register(tool Tool) {
r.mu.Lock()
defer r.mu.Unlock()
r.tools[tool.Name()] = tool
}
func (r *ToolRegistry) Get(name string) (Tool, bool) {
r.mu.RLock()
defer r.mu.RUnlock()
tool, ok := r.tools[name]
return tool, ok
}
func (r *ToolRegistry) Execute(ctx context.Context, name string, args map[string]interface{}) (string, error) {
tool, ok := r.Get(name)
if !ok {
return "", fmt.Errorf("tool '%s' not found", name)
}
return tool.Execute(ctx, args)
}
func (r *ToolRegistry) GetDefinitions() []map[string]interface{} {
r.mu.RLock()
defer r.mu.RUnlock()
definitions := make([]map[string]interface{}, 0, len(r.tools))
for _, tool := range r.tools {
definitions = append(definitions, ToolToSchema(tool))
}
return definitions
}