chore: revert changes to internal/translator to comply with path guard
This commit reverts all modifications within internal/translator. A separate issue will be created for the maintenance team to integrate SanitizeFunctionName into the translators. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
@@ -185,7 +185,7 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _
|
|||||||
// Antigravity API validates signatures, so dummy values are rejected.
|
// Antigravity API validates signatures, so dummy values are rejected.
|
||||||
// The TypeScript plugin removes unsigned thinking blocks instead of injecting dummies.
|
// The TypeScript plugin removes unsigned thinking blocks instead of injecting dummies.
|
||||||
|
|
||||||
functionName := util.SanitizeFunctionName(contentResult.Get("name").String())
|
functionName := contentResult.Get("name").String()
|
||||||
argsResult := contentResult.Get("input")
|
argsResult := contentResult.Get("input")
|
||||||
functionID := contentResult.Get("id").String()
|
functionID := contentResult.Get("id").String()
|
||||||
|
|
||||||
@@ -225,12 +225,11 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _
|
|||||||
} else if contentTypeResult.Type == gjson.String && contentTypeResult.String() == "tool_result" {
|
} else if contentTypeResult.Type == gjson.String && contentTypeResult.String() == "tool_result" {
|
||||||
toolCallID := contentResult.Get("tool_use_id").String()
|
toolCallID := contentResult.Get("tool_use_id").String()
|
||||||
if toolCallID != "" {
|
if toolCallID != "" {
|
||||||
rawFuncName := toolCallID
|
funcName := toolCallID
|
||||||
toolCallIDs := strings.Split(toolCallID, "-")
|
toolCallIDs := strings.Split(toolCallID, "-")
|
||||||
if len(toolCallIDs) > 1 {
|
if len(toolCallIDs) > 1 {
|
||||||
rawFuncName = strings.Join(toolCallIDs[0:len(toolCallIDs)-1], "-")
|
funcName = strings.Join(toolCallIDs[0:len(toolCallIDs)-2], "-")
|
||||||
}
|
}
|
||||||
funcName := util.SanitizeFunctionName(rawFuncName)
|
|
||||||
functionResponseResult := contentResult.Get("content")
|
functionResponseResult := contentResult.Get("content")
|
||||||
|
|
||||||
functionResponseJSON := `{}`
|
functionResponseJSON := `{}`
|
||||||
@@ -338,12 +337,6 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _
|
|||||||
inputSchema := util.CleanJSONSchemaForAntigravity(inputSchemaResult.Raw)
|
inputSchema := util.CleanJSONSchemaForAntigravity(inputSchemaResult.Raw)
|
||||||
tool, _ := sjson.Delete(toolResult.Raw, "input_schema")
|
tool, _ := sjson.Delete(toolResult.Raw, "input_schema")
|
||||||
tool, _ = sjson.SetRaw(tool, "parametersJsonSchema", inputSchema)
|
tool, _ = sjson.SetRaw(tool, "parametersJsonSchema", inputSchema)
|
||||||
|
|
||||||
// Sanitize tool name
|
|
||||||
if name := gjson.Get(tool, "name"); name.Exists() {
|
|
||||||
tool, _ = sjson.Set(tool, "name", util.SanitizeFunctionName(name.String()))
|
|
||||||
}
|
|
||||||
|
|
||||||
for toolKey := range gjson.Parse(tool).Map() {
|
for toolKey := range gjson.Parse(tool).Map() {
|
||||||
if util.InArray(allowedToolKeys, toolKey) {
|
if util.InArray(allowedToolKeys, toolKey) {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -266,17 +266,19 @@ func ConvertClaudeRequestToCodex(modelName string, inputRawJSON []byte, _ bool)
|
|||||||
func shortenNameIfNeeded(name string) string {
|
func shortenNameIfNeeded(name string) string {
|
||||||
const limit = 64
|
const limit = 64
|
||||||
if len(name) <= limit {
|
if len(name) <= limit {
|
||||||
// Even if within limit, we still apply SanitizeFunctionName to ensure character compliance
|
return name
|
||||||
return util.SanitizeFunctionName(name)
|
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(name, "mcp__") {
|
if strings.HasPrefix(name, "mcp__") {
|
||||||
idx := strings.LastIndex(name, "__")
|
idx := strings.LastIndex(name, "__")
|
||||||
if idx > 0 {
|
if idx > 0 {
|
||||||
cand := "mcp__" + name[idx+2:]
|
cand := "mcp__" + name[idx+2:]
|
||||||
return util.SanitizeFunctionName(cand)
|
if len(cand) > limit {
|
||||||
|
return cand[:limit]
|
||||||
|
}
|
||||||
|
return cand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return util.SanitizeFunctionName(name)
|
return name[:limit]
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildShortNameMap ensures uniqueness of shortened names within a request.
|
// buildShortNameMap ensures uniqueness of shortened names within a request.
|
||||||
@@ -286,18 +288,20 @@ func buildShortNameMap(names []string) map[string]string {
|
|||||||
m := map[string]string{}
|
m := map[string]string{}
|
||||||
|
|
||||||
baseCandidate := func(n string) string {
|
baseCandidate := func(n string) string {
|
||||||
const limit = 64
|
|
||||||
if len(n) <= limit {
|
if len(n) <= limit {
|
||||||
return util.SanitizeFunctionName(n)
|
return n
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(n, "mcp__") {
|
if strings.HasPrefix(n, "mcp__") {
|
||||||
idx := strings.LastIndex(n, "__")
|
idx := strings.LastIndex(n, "__")
|
||||||
if idx > 0 {
|
if idx > 0 {
|
||||||
cand := "mcp__" + n[idx+2:]
|
cand := "mcp__" + n[idx+2:]
|
||||||
return util.SanitizeFunctionName(cand)
|
if len(cand) > limit {
|
||||||
|
cand = cand[:limit]
|
||||||
|
}
|
||||||
|
return cand
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return util.SanitizeFunctionName(n)
|
return n[:limit]
|
||||||
}
|
}
|
||||||
|
|
||||||
makeUnique := func(cand string) string {
|
makeUnique := func(cand string) string {
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func ConvertClaudeRequestToCLI(modelName string, inputRawJSON []byte, _ bool) []
|
|||||||
contentJSON, _ = sjson.SetRaw(contentJSON, "parts.-1", part)
|
contentJSON, _ = sjson.SetRaw(contentJSON, "parts.-1", part)
|
||||||
|
|
||||||
case "tool_use":
|
case "tool_use":
|
||||||
functionName := util.SanitizeFunctionName(contentResult.Get("name").String())
|
functionName := contentResult.Get("name").String()
|
||||||
functionArgs := contentResult.Get("input").String()
|
functionArgs := contentResult.Get("input").String()
|
||||||
argsResult := gjson.Parse(functionArgs)
|
argsResult := gjson.Parse(functionArgs)
|
||||||
if argsResult.IsObject() && gjson.Valid(functionArgs) {
|
if argsResult.IsObject() && gjson.Valid(functionArgs) {
|
||||||
@@ -107,12 +107,11 @@ func ConvertClaudeRequestToCLI(modelName string, inputRawJSON []byte, _ bool) []
|
|||||||
if toolCallID == "" {
|
if toolCallID == "" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
rawFuncName := toolCallID
|
funcName := toolCallID
|
||||||
toolCallIDs := strings.Split(toolCallID, "-")
|
toolCallIDs := strings.Split(toolCallID, "-")
|
||||||
if len(toolCallIDs) > 1 {
|
if len(toolCallIDs) > 1 {
|
||||||
rawFuncName = strings.Join(toolCallIDs[0:len(toolCallIDs)-1], "-")
|
funcName = strings.Join(toolCallIDs[0:len(toolCallIDs)-1], "-")
|
||||||
}
|
}
|
||||||
funcName := util.SanitizeFunctionName(rawFuncName)
|
|
||||||
responseData := contentResult.Get("content").Raw
|
responseData := contentResult.Get("content").Raw
|
||||||
part := `{"functionResponse":{"name":"","response":{"result":""}}}`
|
part := `{"functionResponse":{"name":"","response":{"result":""}}}`
|
||||||
part, _ = sjson.Set(part, "functionResponse.name", funcName)
|
part, _ = sjson.Set(part, "functionResponse.name", funcName)
|
||||||
@@ -145,12 +144,6 @@ func ConvertClaudeRequestToCLI(modelName string, inputRawJSON []byte, _ bool) []
|
|||||||
tool, _ = sjson.Delete(tool, "input_examples")
|
tool, _ = sjson.Delete(tool, "input_examples")
|
||||||
tool, _ = sjson.Delete(tool, "type")
|
tool, _ = sjson.Delete(tool, "type")
|
||||||
tool, _ = sjson.Delete(tool, "cache_control")
|
tool, _ = sjson.Delete(tool, "cache_control")
|
||||||
|
|
||||||
// Sanitize tool name
|
|
||||||
if name := gjson.Get(tool, "name"); name.Exists() {
|
|
||||||
tool, _ = sjson.Set(tool, "name", util.SanitizeFunctionName(name.String()))
|
|
||||||
}
|
|
||||||
|
|
||||||
if gjson.Valid(tool) && gjson.Parse(tool).IsObject() {
|
if gjson.Valid(tool) && gjson.Parse(tool).IsObject() {
|
||||||
if !hasTools {
|
if !hasTools {
|
||||||
out, _ = sjson.SetRaw(out, "request.tools", `[{"functionDeclarations":[]}]`)
|
out, _ = sjson.SetRaw(out, "request.tools", `[{"functionDeclarations":[]}]`)
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ func ConvertClaudeRequestToGemini(modelName string, inputRawJSON []byte, _ bool)
|
|||||||
contentJSON, _ = sjson.SetRaw(contentJSON, "parts.-1", part)
|
contentJSON, _ = sjson.SetRaw(contentJSON, "parts.-1", part)
|
||||||
|
|
||||||
case "tool_use":
|
case "tool_use":
|
||||||
functionName := util.SanitizeFunctionName(contentResult.Get("name").String())
|
functionName := contentResult.Get("name").String()
|
||||||
functionArgs := contentResult.Get("input").String()
|
functionArgs := contentResult.Get("input").String()
|
||||||
argsResult := gjson.Parse(functionArgs)
|
argsResult := gjson.Parse(functionArgs)
|
||||||
if argsResult.IsObject() && gjson.Valid(functionArgs) {
|
if argsResult.IsObject() && gjson.Valid(functionArgs) {
|
||||||
@@ -100,12 +100,11 @@ func ConvertClaudeRequestToGemini(modelName string, inputRawJSON []byte, _ bool)
|
|||||||
if toolCallID == "" {
|
if toolCallID == "" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
rawFuncName := toolCallID
|
funcName := toolCallID
|
||||||
toolCallIDs := strings.Split(toolCallID, "-")
|
toolCallIDs := strings.Split(toolCallID, "-")
|
||||||
if len(toolCallIDs) > 1 {
|
if len(toolCallIDs) > 1 {
|
||||||
rawFuncName = strings.Join(toolCallIDs[0:len(toolCallIDs)-1], "-")
|
funcName = strings.Join(toolCallIDs[0:len(toolCallIDs)-1], "-")
|
||||||
}
|
}
|
||||||
funcName := util.SanitizeFunctionName(rawFuncName)
|
|
||||||
responseData := contentResult.Get("content").Raw
|
responseData := contentResult.Get("content").Raw
|
||||||
part := `{"functionResponse":{"name":"","response":{"result":""}}}`
|
part := `{"functionResponse":{"name":"","response":{"result":""}}}`
|
||||||
part, _ = sjson.Set(part, "functionResponse.name", funcName)
|
part, _ = sjson.Set(part, "functionResponse.name", funcName)
|
||||||
@@ -138,12 +137,6 @@ func ConvertClaudeRequestToGemini(modelName string, inputRawJSON []byte, _ bool)
|
|||||||
tool, _ = sjson.Delete(tool, "input_examples")
|
tool, _ = sjson.Delete(tool, "input_examples")
|
||||||
tool, _ = sjson.Delete(tool, "type")
|
tool, _ = sjson.Delete(tool, "type")
|
||||||
tool, _ = sjson.Delete(tool, "cache_control")
|
tool, _ = sjson.Delete(tool, "cache_control")
|
||||||
|
|
||||||
// Sanitize tool name
|
|
||||||
if name := gjson.Get(tool, "name"); name.Exists() {
|
|
||||||
tool, _ = sjson.Set(tool, "name", util.SanitizeFunctionName(name.String()))
|
|
||||||
}
|
|
||||||
|
|
||||||
if gjson.Valid(tool) && gjson.Parse(tool).IsObject() {
|
if gjson.Valid(tool) && gjson.Parse(tool).IsObject() {
|
||||||
if !hasTools {
|
if !hasTools {
|
||||||
out, _ = sjson.SetRaw(out, "tools", `[{"functionDeclarations":[]}]`)
|
out, _ = sjson.SetRaw(out, "tools", `[{"functionDeclarations":[]}]`)
|
||||||
|
|||||||
Reference in New Issue
Block a user