Files
Cyrene_v2/plugins/tools/basic/register.go
T

38 lines
982 B
Go

package basic
import (
"fmt"
"git.yeij.top/AskaEth/Cyrene_v2/internal/capability/registry"
"git.yeij.top/AskaEth/Cyrene_v2/pkg/plugins/sdk"
)
// Tools returns the built-in basic tools in registration order: calculator,
// datetime, random, text, json and markdown. Each element is a stateless
// sdk.Tool value, safe for concurrent use.
func Tools() []sdk.Tool {
return []sdk.Tool{
calculator{},
datetime{},
random{},
text{},
jsonTool{},
markdown{},
}
}
// Register registers every basic tool with reg. It returns an error wrapping
// sdk.ErrNilRegistrar when reg is nil, and stops at the first failing tool,
// wrapping the registry error so errors.Is can still reach it.
func Register(reg *registry.Registry) error {
if reg == nil {
return fmt.Errorf("basic: register: %w", sdk.ErrNilRegistrar)
}
for _, t := range Tools() {
if err := reg.RegisterTool(t); err != nil {
return fmt.Errorf("basic: register %q: %w", t.Name(), err)
}
}
return nil
}