blob: c99fa561e2ea1da6d032c4fb3cd36df4501dab4f [file] [log] [blame]
Sketch🕴️305f8172026-02-27 13:58:43 +04001package tools
2
3import (
4 "github.com/invopop/jsonschema"
5)
6
7type Tool interface {
8 Name() string
9 Description() string
10 InputSchema() *jsonschema.Schema
11 Call(inp string) (string, error)
12}
13
14type Registry interface {
15 All() []Tool
16 Add(tool Tool)
17 Get(name string) Tool
18}
19
20type InMemoryRegistry struct {
21 tools map[string]Tool
22}
23
24func NewInMemoryRegistry() *InMemoryRegistry {
25 return &InMemoryRegistry{
26 make(map[string]Tool),
27 }
28}
29
30func (r *InMemoryRegistry) Add(tool Tool) {
31 r.tools[tool.Name()] = tool
32}
33
34func (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
42func (r *InMemoryRegistry) Get(name string) Tool {
43 return r.tools[name]
44}