mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-12 22:17:29 +08:00
40 lines
999 B
Go
40 lines
999 B
Go
package tools
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// AliasTool exposes OpenClaw-compatible tool names while forwarding to existing implementations.
|
|
type AliasTool struct {
|
|
name string
|
|
description string
|
|
base Tool
|
|
argMap map[string]string
|
|
}
|
|
|
|
func NewAliasTool(name, description string, base Tool, argMap map[string]string) *AliasTool {
|
|
return &AliasTool{name: name, description: description, base: base, argMap: argMap}
|
|
}
|
|
|
|
func (t *AliasTool) Name() string { return t.name }
|
|
func (t *AliasTool) Description() string {
|
|
if t.description != "" {
|
|
return t.description
|
|
}
|
|
return t.base.Description()
|
|
}
|
|
func (t *AliasTool) Parameters() map[string]interface{} { return t.base.Parameters() }
|
|
|
|
func (t *AliasTool) Execute(ctx context.Context, args map[string]interface{}) (string, error) {
|
|
if len(t.argMap) > 0 {
|
|
for from, to := range t.argMap {
|
|
if v, ok := args[from]; ok {
|
|
if _, exists := args[to]; !exists {
|
|
args[to] = v
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return t.base.Execute(ctx, args)
|
|
}
|