Add full monorepo: virtual-banker, backend, frontend, docs, scripts, deployment
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
73
backend/tools/registry.go
Normal file
73
backend/tools/registry.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Tool represents an executable tool
|
||||
type Tool interface {
|
||||
Name() string
|
||||
Description() string
|
||||
Execute(ctx context.Context, params map[string]interface{}) (*ToolResult, error)
|
||||
}
|
||||
|
||||
// ToolResult represents the result of tool execution
|
||||
type ToolResult struct {
|
||||
Success bool
|
||||
Data interface{}
|
||||
Error string
|
||||
RequiresConfirmation bool
|
||||
}
|
||||
|
||||
// Registry manages available tools
|
||||
type Registry struct {
|
||||
tools map[string]Tool
|
||||
}
|
||||
|
||||
// NewRegistry creates a new tool registry
|
||||
func NewRegistry() *Registry {
|
||||
return &Registry{
|
||||
tools: make(map[string]Tool),
|
||||
}
|
||||
}
|
||||
|
||||
// Register registers a tool
|
||||
func (r *Registry) Register(tool Tool) {
|
||||
r.tools[tool.Name()] = tool
|
||||
}
|
||||
|
||||
// Get gets a tool by name
|
||||
func (r *Registry) Get(name string) (Tool, error) {
|
||||
tool, ok := r.tools[name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("tool not found: %s", name)
|
||||
}
|
||||
return tool, nil
|
||||
}
|
||||
|
||||
// List returns all registered tools
|
||||
func (r *Registry) List() []Tool {
|
||||
tools := make([]Tool, 0, len(r.tools))
|
||||
for _, tool := range r.tools {
|
||||
tools = append(tools, tool)
|
||||
}
|
||||
return tools
|
||||
}
|
||||
|
||||
// GetAllowedTools returns tools allowed for a tenant
|
||||
func (r *Registry) GetAllowedTools(allowedNames []string) []Tool {
|
||||
allowedSet := make(map[string]bool)
|
||||
for _, name := range allowedNames {
|
||||
allowedSet[name] = true
|
||||
}
|
||||
|
||||
var tools []Tool
|
||||
for _, tool := range r.tools {
|
||||
if allowedSet[tool.Name()] {
|
||||
tools = append(tools, tool)
|
||||
}
|
||||
}
|
||||
return tools
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user