feat(antigravity): add function ID to FunctionCall and FunctionResponse models
Browse files- internal/interfaces/client_models.go +6 -0
- internal/translator/antigravity/claude/antigravity_claude_request.go +3 -2
- internal/translator/antigravity/claude/antigravity_claude_response.go +29 -26
- internal/translator/antigravity/openai/chat-completions/antigravity_openai_request.go +2 -0
- internal/translator/codex/gemini/codex_gemini_response.go +1 -1
- internal/translator/gemini/openai/responses/gemini_openai-responses_request.go +2 -0
internal/interfaces/client_models.go
CHANGED
|
@@ -85,6 +85,9 @@ type InlineData struct {
|
|
| 85 |
// FunctionCall represents a tool call requested by the model.
|
| 86 |
// It includes the function name and its arguments that the model wants to execute.
|
| 87 |
type FunctionCall struct {
|
|
|
|
|
|
|
|
|
|
| 88 |
// Name is the identifier of the function to be called.
|
| 89 |
Name string `json:"name"`
|
| 90 |
|
|
@@ -95,6 +98,9 @@ type FunctionCall struct {
|
|
| 95 |
// FunctionResponse represents the result of a tool execution.
|
| 96 |
// This is sent back to the model after a tool call has been processed.
|
| 97 |
type FunctionResponse struct {
|
|
|
|
|
|
|
|
|
|
| 98 |
// Name is the identifier of the function that was called.
|
| 99 |
Name string `json:"name"`
|
| 100 |
|
|
|
|
| 85 |
// FunctionCall represents a tool call requested by the model.
|
| 86 |
// It includes the function name and its arguments that the model wants to execute.
|
| 87 |
type FunctionCall struct {
|
| 88 |
+
// ID is the identifier of the function to be called.
|
| 89 |
+
ID string `json:"id,omitempty"`
|
| 90 |
+
|
| 91 |
// Name is the identifier of the function to be called.
|
| 92 |
Name string `json:"name"`
|
| 93 |
|
|
|
|
| 98 |
// FunctionResponse represents the result of a tool execution.
|
| 99 |
// This is sent back to the model after a tool call has been processed.
|
| 100 |
type FunctionResponse struct {
|
| 101 |
+
// ID is the identifier of the function to be called.
|
| 102 |
+
ID string `json:"id,omitempty"`
|
| 103 |
+
|
| 104 |
// Name is the identifier of the function that was called.
|
| 105 |
Name string `json:"name"`
|
| 106 |
|
internal/translator/antigravity/claude/antigravity_claude_request.go
CHANGED
|
@@ -89,10 +89,11 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _
|
|
| 89 |
} else if contentTypeResult.Type == gjson.String && contentTypeResult.String() == "tool_use" {
|
| 90 |
functionName := contentResult.Get("name").String()
|
| 91 |
functionArgs := contentResult.Get("input").String()
|
|
|
|
| 92 |
var args map[string]any
|
| 93 |
if err := json.Unmarshal([]byte(functionArgs), &args); err == nil {
|
| 94 |
clientContent.Parts = append(clientContent.Parts, client.Part{
|
| 95 |
-
FunctionCall: &client.FunctionCall{Name: functionName, Args: args},
|
| 96 |
ThoughtSignature: geminiCLIClaudeThoughtSignature,
|
| 97 |
})
|
| 98 |
}
|
|
@@ -105,7 +106,7 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _
|
|
| 105 |
funcName = strings.Join(toolCallIDs[0:len(toolCallIDs)-1], "-")
|
| 106 |
}
|
| 107 |
responseData := contentResult.Get("content").Raw
|
| 108 |
-
functionResponse := client.FunctionResponse{Name: funcName, Response: map[string]interface{}{"result": responseData}}
|
| 109 |
clientContent.Parts = append(clientContent.Parts, client.Part{FunctionResponse: &functionResponse})
|
| 110 |
}
|
| 111 |
}
|
|
|
|
| 89 |
} else if contentTypeResult.Type == gjson.String && contentTypeResult.String() == "tool_use" {
|
| 90 |
functionName := contentResult.Get("name").String()
|
| 91 |
functionArgs := contentResult.Get("input").String()
|
| 92 |
+
functionID := contentResult.Get("id").String()
|
| 93 |
var args map[string]any
|
| 94 |
if err := json.Unmarshal([]byte(functionArgs), &args); err == nil {
|
| 95 |
clientContent.Parts = append(clientContent.Parts, client.Part{
|
| 96 |
+
FunctionCall: &client.FunctionCall{ID: functionID, Name: functionName, Args: args},
|
| 97 |
ThoughtSignature: geminiCLIClaudeThoughtSignature,
|
| 98 |
})
|
| 99 |
}
|
|
|
|
| 106 |
funcName = strings.Join(toolCallIDs[0:len(toolCallIDs)-1], "-")
|
| 107 |
}
|
| 108 |
responseData := contentResult.Get("content").Raw
|
| 109 |
+
functionResponse := client.FunctionResponse{ID: toolCallID, Name: funcName, Response: map[string]interface{}{"result": responseData}}
|
| 110 |
clientContent.Parts = append(clientContent.Parts, client.Part{FunctionResponse: &functionResponse})
|
| 111 |
}
|
| 112 |
}
|
internal/translator/antigravity/claude/antigravity_claude_response.go
CHANGED
|
@@ -141,35 +141,38 @@ func ConvertAntigravityResponseToClaude(_ context.Context, _ string, originalReq
|
|
| 141 |
params.ResponseType = 2 // Set state to thinking
|
| 142 |
}
|
| 143 |
} else {
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
}
|
| 159 |
-
|
| 160 |
-
|
|
|
|
|
|
|
| 161 |
output = output + "\n\n\n"
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
| 163 |
}
|
| 164 |
-
|
| 165 |
-
// Start a new text content block
|
| 166 |
-
output = output + "event: content_block_start\n"
|
| 167 |
-
output = output + fmt.Sprintf(`data: {"type":"content_block_start","index":%d,"content_block":{"type":"text","text":""}}`, params.ResponseIndex)
|
| 168 |
-
output = output + "\n\n\n"
|
| 169 |
-
output = output + "event: content_block_delta\n"
|
| 170 |
-
data, _ := sjson.Set(fmt.Sprintf(`{"type":"content_block_delta","index":%d,"delta":{"type":"text_delta","text":""}}`, params.ResponseIndex), "delta.text", partTextResult.String())
|
| 171 |
-
output = output + fmt.Sprintf("data: %s\n\n\n", data)
|
| 172 |
-
params.ResponseType = 1 // Set state to content
|
| 173 |
}
|
| 174 |
}
|
| 175 |
} else if functionCallResult.Exists() {
|
|
|
|
| 141 |
params.ResponseType = 2 // Set state to thinking
|
| 142 |
}
|
| 143 |
} else {
|
| 144 |
+
finishReasonResult := gjson.GetBytes(rawJSON, "response.candidates.0.finishReason")
|
| 145 |
+
if partTextResult.String() != "" || !finishReasonResult.Exists() {
|
| 146 |
+
// Process regular text content (user-visible output)
|
| 147 |
+
// Continue existing text block if already in content state
|
| 148 |
+
if params.ResponseType == 1 {
|
| 149 |
+
output = output + "event: content_block_delta\n"
|
| 150 |
+
data, _ := sjson.Set(fmt.Sprintf(`{"type":"content_block_delta","index":%d,"delta":{"type":"text_delta","text":""}}`, params.ResponseIndex), "delta.text", partTextResult.String())
|
| 151 |
+
output = output + fmt.Sprintf("data: %s\n\n\n", data)
|
| 152 |
+
} else {
|
| 153 |
+
// Transition from another state to text content
|
| 154 |
+
// First, close any existing content block
|
| 155 |
+
if params.ResponseType != 0 {
|
| 156 |
+
if params.ResponseType == 2 {
|
| 157 |
+
// output = output + "event: content_block_delta\n"
|
| 158 |
+
// output = output + fmt.Sprintf(`data: {"type":"content_block_delta","index":%d,"delta":{"type":"signature_delta","signature":null}}`, params.ResponseIndex)
|
| 159 |
+
// output = output + "\n\n\n"
|
| 160 |
+
}
|
| 161 |
+
output = output + "event: content_block_stop\n"
|
| 162 |
+
output = output + fmt.Sprintf(`data: {"type":"content_block_stop","index":%d}`, params.ResponseIndex)
|
| 163 |
+
output = output + "\n\n\n"
|
| 164 |
+
params.ResponseIndex++
|
| 165 |
}
|
| 166 |
+
|
| 167 |
+
// Start a new text content block
|
| 168 |
+
output = output + "event: content_block_start\n"
|
| 169 |
+
output = output + fmt.Sprintf(`data: {"type":"content_block_start","index":%d,"content_block":{"type":"text","text":""}}`, params.ResponseIndex)
|
| 170 |
output = output + "\n\n\n"
|
| 171 |
+
output = output + "event: content_block_delta\n"
|
| 172 |
+
data, _ := sjson.Set(fmt.Sprintf(`{"type":"content_block_delta","index":%d,"delta":{"type":"text_delta","text":""}}`, params.ResponseIndex), "delta.text", partTextResult.String())
|
| 173 |
+
output = output + fmt.Sprintf("data: %s\n\n\n", data)
|
| 174 |
+
params.ResponseType = 1 // Set state to content
|
| 175 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
}
|
| 177 |
}
|
| 178 |
} else if functionCallResult.Exists() {
|
internal/translator/antigravity/openai/chat-completions/antigravity_openai_request.go
CHANGED
|
@@ -251,6 +251,7 @@ func ConvertOpenAIRequestToAntigravity(modelName string, inputRawJSON []byte, _
|
|
| 251 |
fid := tc.Get("id").String()
|
| 252 |
fname := tc.Get("function.name").String()
|
| 253 |
fargs := tc.Get("function.arguments").String()
|
|
|
|
| 254 |
node, _ = sjson.SetBytes(node, "parts."+itoa(p)+".functionCall.name", fname)
|
| 255 |
node, _ = sjson.SetRawBytes(node, "parts."+itoa(p)+".functionCall.args", []byte(fargs))
|
| 256 |
node, _ = sjson.SetBytes(node, "parts."+itoa(p)+".thoughtSignature", geminiCLIFunctionThoughtSignature)
|
|
@@ -266,6 +267,7 @@ func ConvertOpenAIRequestToAntigravity(modelName string, inputRawJSON []byte, _
|
|
| 266 |
pp := 0
|
| 267 |
for _, fid := range fIDs {
|
| 268 |
if name, ok := tcID2Name[fid]; ok {
|
|
|
|
| 269 |
toolNode, _ = sjson.SetBytes(toolNode, "parts."+itoa(pp)+".functionResponse.name", name)
|
| 270 |
resp := toolResponses[fid]
|
| 271 |
if resp == "" {
|
|
|
|
| 251 |
fid := tc.Get("id").String()
|
| 252 |
fname := tc.Get("function.name").String()
|
| 253 |
fargs := tc.Get("function.arguments").String()
|
| 254 |
+
node, _ = sjson.SetBytes(node, "parts."+itoa(p)+".functionCall.id", fid)
|
| 255 |
node, _ = sjson.SetBytes(node, "parts."+itoa(p)+".functionCall.name", fname)
|
| 256 |
node, _ = sjson.SetRawBytes(node, "parts."+itoa(p)+".functionCall.args", []byte(fargs))
|
| 257 |
node, _ = sjson.SetBytes(node, "parts."+itoa(p)+".thoughtSignature", geminiCLIFunctionThoughtSignature)
|
|
|
|
| 267 |
pp := 0
|
| 268 |
for _, fid := range fIDs {
|
| 269 |
if name, ok := tcID2Name[fid]; ok {
|
| 270 |
+
toolNode, _ = sjson.SetBytes(toolNode, "parts."+itoa(pp)+".functionResponse.id", fid)
|
| 271 |
toolNode, _ = sjson.SetBytes(toolNode, "parts."+itoa(pp)+".functionResponse.name", name)
|
| 272 |
resp := toolResponses[fid]
|
| 273 |
if resp == "" {
|
internal/translator/codex/gemini/codex_gemini_response.go
CHANGED
|
@@ -327,7 +327,7 @@ func buildReverseMapFromGeminiOriginal(original []byte) map[string]string {
|
|
| 327 |
func mustMarshalJSON(v interface{}) string {
|
| 328 |
data, err := json.Marshal(v)
|
| 329 |
if err != nil {
|
| 330 |
-
|
| 331 |
}
|
| 332 |
return string(data)
|
| 333 |
}
|
|
|
|
| 327 |
func mustMarshalJSON(v interface{}) string {
|
| 328 |
data, err := json.Marshal(v)
|
| 329 |
if err != nil {
|
| 330 |
+
return ""
|
| 331 |
}
|
| 332 |
return string(data)
|
| 333 |
}
|
internal/translator/gemini/openai/responses/gemini_openai-responses_request.go
CHANGED
|
@@ -249,6 +249,7 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte
|
|
| 249 |
functionCall := `{"functionCall":{"name":"","args":{}}}`
|
| 250 |
functionCall, _ = sjson.Set(functionCall, "functionCall.name", name)
|
| 251 |
functionCall, _ = sjson.Set(functionCall, "thoughtSignature", geminiResponsesThoughtSignature)
|
|
|
|
| 252 |
|
| 253 |
// Parse arguments JSON string and set as args object
|
| 254 |
if arguments != "" {
|
|
@@ -285,6 +286,7 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte
|
|
| 285 |
}
|
| 286 |
|
| 287 |
functionResponse, _ = sjson.Set(functionResponse, "functionResponse.name", functionName)
|
|
|
|
| 288 |
|
| 289 |
// Set the raw JSON output directly (preserves string encoding)
|
| 290 |
if outputRaw != "" && outputRaw != "null" {
|
|
|
|
| 249 |
functionCall := `{"functionCall":{"name":"","args":{}}}`
|
| 250 |
functionCall, _ = sjson.Set(functionCall, "functionCall.name", name)
|
| 251 |
functionCall, _ = sjson.Set(functionCall, "thoughtSignature", geminiResponsesThoughtSignature)
|
| 252 |
+
functionCall, _ = sjson.Set(functionCall, "functionCall.id", item.Get("call_id").String())
|
| 253 |
|
| 254 |
// Parse arguments JSON string and set as args object
|
| 255 |
if arguments != "" {
|
|
|
|
| 286 |
}
|
| 287 |
|
| 288 |
functionResponse, _ = sjson.Set(functionResponse, "functionResponse.name", functionName)
|
| 289 |
+
functionResponse, _ = sjson.Set(functionResponse, "functionResponse.id", callID)
|
| 290 |
|
| 291 |
// Set the raw JSON output directly (preserves string encoding)
|
| 292 |
if outputRaw != "" && outputRaw != "null" {
|