fix(translator): address PR feedback for tool name sanitization

- Pre-compile sanitization regex for better performance.
- Optimize SanitizeFunctionName for conciseness and correctness.
- Handle 64-char edge cases by truncating before prepending underscore.
- Fix bug in Antigravity translator (incorrect join index).
- Refactor Gemini translators to avoid redundant sanitization calls.
- Add comprehensive unit tests including 64-char edge cases.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
Saboor Hassan
2025-12-31 01:54:41 +05:00
parent f4d4249ba5
commit d241359153
5 changed files with 22 additions and 17 deletions

View File

@@ -100,11 +100,12 @@ func ConvertClaudeRequestToGemini(modelName string, inputRawJSON []byte, _ bool)
if toolCallID == "" {
return true
}
funcName := util.SanitizeFunctionName(toolCallID)
rawFuncName := toolCallID
toolCallIDs := strings.Split(toolCallID, "-")
if len(toolCallIDs) > 1 {
funcName = util.SanitizeFunctionName(strings.Join(toolCallIDs[0:len(toolCallIDs)-1], "-"))
rawFuncName = strings.Join(toolCallIDs[0:len(toolCallIDs)-1], "-")
}
funcName := util.SanitizeFunctionName(rawFuncName)
responseData := contentResult.Get("content").Raw
part := `{"functionResponse":{"name":"","response":{"result":""}}}`
part, _ = sjson.Set(part, "functionResponse.name", funcName)