Files
CLIProxyAPI/internal/runtime/executor/helps/claude_builtin_tools.go
Luis Pater 6e6afab99a refactor: migrate gjson, sjson, and base64 to MoeForge/moego
- Replace tidwall/gjson and tidwall/sjson with github.com/MoeForge/moego/ojson
  and encoding/base64 with github.com/MoeForge/moego/base64 across the main
  module and examples
- Introduce cross-method *ojson.Doc request rewriting pipelines across
  thinking, signature, client/codex, runtime/executor/helps, pluginhost, and
  all provider executors with FinalizePayloadDoc as the final semantic barrier
- Convert all consecutive JSON mutations (>= 2 Set/SetRaw/Delete operations)
  to batch edits on ojson.Doc
- Upgrade read-only byte paths to ojson.GetBytesNoCopy,
  ojson.GetManyBytesNoCopy, and util.ParseGJSONBytesNoCopy with explicit
  strings.Clone ownership protection across streaming and persistent state
- Use base64.StdEncoding.ValidateString for zero-allocation signature checks
  and base64.EncodeDataURL for single-allocation data URL construction
2026-11-03 03:05:04 +08:00

67 lines
1.5 KiB
Go

package helps
import (
"strings"
"github.com/MoeForge/moego/ojson"
)
var defaultClaudeBuiltinToolNames = []string{
"web_search",
"code_execution",
"text_editor",
"computer",
}
func newClaudeBuiltinToolRegistry() map[string]bool {
registry := make(map[string]bool, len(defaultClaudeBuiltinToolNames))
for _, name := range defaultClaudeBuiltinToolNames {
registry[name] = true
}
return registry
}
// IsClaudeServerToolType reports whether a typed declaration is a recognized
// Anthropic-operated tool. Client-defined type:"custom" declarations are not
// server tools and must remain eligible for MCP aliasing.
func IsClaudeServerToolType(toolType string) bool {
toolType = strings.ToLower(strings.TrimSpace(toolType))
for _, prefix := range []string{
"advisor_",
"agent_toolset_",
"bash_",
"code_execution_",
"computer_",
"memory_",
"text_editor_",
"tool_search_tool_",
"web_fetch_",
"web_search_",
} {
if strings.HasPrefix(toolType, prefix) {
return true
}
}
return false
}
func AugmentClaudeBuiltinToolRegistry(body []byte, registry map[string]bool) map[string]bool {
if registry == nil {
registry = newClaudeBuiltinToolRegistry()
}
tools := ojson.GetBytesNoCopy(body, "tools")
if !tools.Exists() || !tools.IsArray() {
return registry
}
tools.ForEach(func(_, tool ojson.Result) bool {
if !IsClaudeServerToolType(tool.Get("type").String()) {
return true
}
if name := tool.Get("name").String(); name != "" {
registry[strings.Clone(name)] = true
}
return true
})
return registry
}