win 21325afb33
Some checks failed
CI / test (push) Failing after 10s
CI / frontend (push) Failing after 8s
CI / golangci-lint (push) Failing after 5s
Security Scan / backend-security (push) Failing after 5s
Security Scan / frontend-security (push) Failing after 4s
feat(windsurf): 补全ops日志记录与endpoint派生,对齐其他平台
- windsurf_gateway_service: 添加上游延迟/TTFT/错误上下文记录
- endpoint: DeriveUpstreamEndpoint 添加 PlatformWindsurf 分支
- ops_error_logger: guessPlatformFromPath 添加 /windsurf/ 识别
2026-04-23 20:46:27 +08:00

88 lines
2.0 KiB
Go

package windsurf
import "strings"
var canonicalToolAliases = map[string]string{
"read": "read",
"read_file": "read",
"readfile": "read",
"write": "write",
"write_file": "write",
"writefile": "write",
"edit": "edit",
"apply_patch": "edit",
"applypatch": "edit",
"bash": "bash",
"execute_bash": "bash",
"executebash": "bash",
"exec_bash": "bash",
"execbash": "bash",
"glob": "glob",
"list_files": "glob",
"listfiles": "glob",
"grep": "grep",
"search_files": "grep",
"searchfiles": "grep",
"webfetch": "webfetch",
"web_fetch": "webfetch",
"fetch": "webfetch",
}
// NormalizeToolName canonicalizes known tool aliases while preserving unknown tool names.
func NormalizeToolName(name string) string {
trimmed := strings.TrimSpace(name)
if trimmed == "" {
return ""
}
if canonical, ok := canonicalToolAliases[strings.ToLower(trimmed)]; ok {
return canonical
}
return trimmed
}
func normalizeOpenAITool(tool OpenAITool) OpenAITool {
if tool.Type != "function" {
return tool
}
tool.Function.Name = NormalizeToolName(tool.Function.Name)
return tool
}
func canonicalizeOpenAITools(tools []OpenAITool) []OpenAITool {
if len(tools) == 0 {
return nil
}
out := make([]OpenAITool, 0, len(tools))
seen := make(map[string]int, len(tools))
for _, tool := range tools {
normalized := normalizeOpenAITool(tool)
if normalized.Type != "function" {
out = append(out, normalized)
continue
}
name := strings.TrimSpace(normalized.Function.Name)
if name == "" {
continue
}
key := strings.ToLower(name)
if idx, ok := seen[key]; ok {
if out[idx].Function.Description == "" {
out[idx].Function.Description = normalized.Function.Description
}
if len(out[idx].Function.Parameters) == 0 {
out[idx].Function.Parameters = normalized.Function.Parameters
}
continue
}
seen[key] = len(out)
out = append(out, normalized)
}
return out
}