rony-llm-agent/pkg/tools/registry.go
Victor Vargas 724a143f90 style: gofmt
Formatting only (struct field alignment, import ordering) across the
files that didn't comply — no semantic changes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 16:14:15 -07:00

65 lines
1.1 KiB
Go

package tools
import (
"sync"
)
// registry is the default implementation of Registry.
type registry struct {
mu sync.RWMutex
tools map[string]Tool
order []string
}
// NewRegistry returns a new empty registry.
func NewRegistry() Registry {
return &registry{
tools: make(map[string]Tool),
}
}
func (r *registry) Register(t Tool) error {
r.mu.Lock()
defer r.mu.Unlock()
if _, exists := r.tools[t.Name]; exists {
return ErrDuplicateTool
}
r.tools[t.Name] = t
r.order = append(r.order, t.Name)
return nil
}
func (r *registry) Get(name string) (Tool, bool) {
r.mu.RLock()
defer r.mu.RUnlock()
t, ok := r.tools[name]
return t, ok
}
func (r *registry) List() []Tool {
r.mu.RLock()
defer r.mu.RUnlock()
out := make([]Tool, len(r.order))
for i, name := range r.order {
out[i] = r.tools[name]
}
return out
}
func (r *registry) Filter(predicate func(Tool) bool) []Tool {
r.mu.RLock()
defer r.mu.RUnlock()
var result []Tool
for _, name := range r.order {
t := r.tools[name]
if predicate(t) {
result = append(result, t)
}
}
return result
}