feat(tools/basic): 内置基础工具(calculator(注入安全)/datetime/random/text/json/markdown)+ 批量注册
This commit is contained in:
1 parent
b3c61aa1ff
commit
08223c06a5
19 files changed
+2074
No files matched your search
@@ -0,0 +1,37 @@
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user