| Sketch🕴️ | 305f817 | 2026-02-27 13:58:43 +0400 | [diff] [blame^] | 1 | package tools |
| 2 | |
| 3 | import ( |
| 4 | "github.com/invopop/jsonschema" |
| 5 | ) |
| 6 | |
| 7 | type Tool interface { |
| 8 | Name() string |
| 9 | Description() string |
| 10 | InputSchema() *jsonschema.Schema |
| 11 | Call(inp string) (string, error) |
| 12 | } |
| 13 | |
| 14 | type Registry interface { |
| 15 | All() []Tool |
| 16 | Add(tool Tool) |
| 17 | Get(name string) Tool |
| 18 | } |
| 19 | |
| 20 | type InMemoryRegistry struct { |
| 21 | tools map[string]Tool |
| 22 | } |
| 23 | |
| 24 | func NewInMemoryRegistry() *InMemoryRegistry { |
| 25 | return &InMemoryRegistry{ |
| 26 | make(map[string]Tool), |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | func (r *InMemoryRegistry) Add(tool Tool) { |
| 31 | r.tools[tool.Name()] = tool |
| 32 | } |
| 33 | |
| 34 | func (r *InMemoryRegistry) All() []Tool { |
| 35 | var ret []Tool |
| 36 | for _, t := range r.tools { |
| 37 | ret = append(ret, t) |
| 38 | } |
| 39 | return ret |
| 40 | } |
| 41 | |
| 42 | func (r *InMemoryRegistry) Get(name string) Tool { |
| 43 | return r.tools[name] |
| 44 | } |