mirror of
https://github.com/router-for-me/CLIProxyAPIPlus.git
synced 2026-04-24 06:30:28 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f81ff16022 | ||
|
|
68cbe20664 | ||
|
|
15353a6b6a | ||
|
|
1b638b3629 | ||
|
|
6f5f81753d | ||
|
|
76af454034 | ||
|
|
e54d2f6b2a | ||
|
|
bfc738b76a | ||
|
|
396899a530 | ||
|
|
04f0070a80 | ||
|
|
f383840cf9 | ||
|
|
edc654edf9 | ||
|
|
08586334af |
@@ -28,6 +28,9 @@ const (
|
|||||||
RouteTypeNoProvider AmpRouteType = "NO_PROVIDER"
|
RouteTypeNoProvider AmpRouteType = "NO_PROVIDER"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// MappedModelContextKey is the Gin context key for passing mapped model names.
|
||||||
|
const MappedModelContextKey = "mapped_model"
|
||||||
|
|
||||||
// logAmpRouting logs the routing decision for an Amp request with structured fields
|
// logAmpRouting logs the routing decision for an Amp request with structured fields
|
||||||
func logAmpRouting(routeType AmpRouteType, requestedModel, resolvedModel, provider, path string) {
|
func logAmpRouting(routeType AmpRouteType, requestedModel, resolvedModel, provider, path string) {
|
||||||
fields := log.Fields{
|
fields := log.Fields{
|
||||||
@@ -141,6 +144,8 @@ func (fh *FallbackHandler) WrapHandler(handler gin.HandlerFunc) gin.HandlerFunc
|
|||||||
// Mapping found - rewrite the model in request body
|
// Mapping found - rewrite the model in request body
|
||||||
bodyBytes = rewriteModelInRequest(bodyBytes, mappedModel)
|
bodyBytes = rewriteModelInRequest(bodyBytes, mappedModel)
|
||||||
c.Request.Body = io.NopCloser(bytes.NewReader(bodyBytes))
|
c.Request.Body = io.NopCloser(bytes.NewReader(bodyBytes))
|
||||||
|
// Store mapped model in context for handlers that check it (like gemini bridge)
|
||||||
|
c.Set(MappedModelContextKey, mappedModel)
|
||||||
resolvedModel = mappedModel
|
resolvedModel = mappedModel
|
||||||
usedMapping = true
|
usedMapping = true
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers/gemini"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// createGeminiBridgeHandler creates a handler that bridges AMP CLI's non-standard Gemini paths
|
// createGeminiBridgeHandler creates a handler that bridges AMP CLI's non-standard Gemini paths
|
||||||
@@ -15,16 +14,31 @@ import (
|
|||||||
//
|
//
|
||||||
// This extracts the model+method from the AMP path and sets it as the :action parameter
|
// This extracts the model+method from the AMP path and sets it as the :action parameter
|
||||||
// so the standard Gemini handler can process it.
|
// so the standard Gemini handler can process it.
|
||||||
func createGeminiBridgeHandler(geminiHandler *gemini.GeminiAPIHandler) gin.HandlerFunc {
|
//
|
||||||
|
// The handler parameter should be a Gemini-compatible handler that expects the :action param.
|
||||||
|
func createGeminiBridgeHandler(handler gin.HandlerFunc) gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
// Get the full path from the catch-all parameter
|
// Get the full path from the catch-all parameter
|
||||||
path := c.Param("path")
|
path := c.Param("path")
|
||||||
|
|
||||||
// Extract model:method from AMP CLI path format
|
// Extract model:method from AMP CLI path format
|
||||||
// Example: /publishers/google/models/gemini-3-pro-preview:streamGenerateContent
|
// Example: /publishers/google/models/gemini-3-pro-preview:streamGenerateContent
|
||||||
if idx := strings.Index(path, "/models/"); idx >= 0 {
|
const modelsPrefix = "/models/"
|
||||||
// Extract everything after "/models/"
|
if idx := strings.Index(path, modelsPrefix); idx >= 0 {
|
||||||
actionPart := path[idx+8:] // Skip "/models/"
|
// Extract everything after modelsPrefix
|
||||||
|
actionPart := path[idx+len(modelsPrefix):]
|
||||||
|
|
||||||
|
// Check if model was mapped by FallbackHandler
|
||||||
|
if mappedModel, exists := c.Get(MappedModelContextKey); exists {
|
||||||
|
if strModel, ok := mappedModel.(string); ok && strModel != "" {
|
||||||
|
// Replace the model part in the action
|
||||||
|
// actionPart is like "model-name:method"
|
||||||
|
if colonIdx := strings.Index(actionPart, ":"); colonIdx > 0 {
|
||||||
|
method := actionPart[colonIdx:] // ":method"
|
||||||
|
actionPart = strModel + method
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set this as the :action parameter that the Gemini handler expects
|
// Set this as the :action parameter that the Gemini handler expects
|
||||||
c.Params = append(c.Params, gin.Param{
|
c.Params = append(c.Params, gin.Param{
|
||||||
@@ -32,8 +46,8 @@ func createGeminiBridgeHandler(geminiHandler *gemini.GeminiAPIHandler) gin.Handl
|
|||||||
Value: actionPart,
|
Value: actionPart,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Call the standard Gemini handler
|
// Call the handler
|
||||||
geminiHandler.GeminiHandler(c)
|
handler(c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
93
internal/api/modules/amp/gemini_bridge_test.go
Normal file
93
internal/api/modules/amp/gemini_bridge_test.go
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
package amp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateGeminiBridgeHandler_ActionParameterExtraction(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
path string
|
||||||
|
mappedModel string // empty string means no mapping
|
||||||
|
expectedAction string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "no_mapping_uses_url_model",
|
||||||
|
path: "/publishers/google/models/gemini-pro:generateContent",
|
||||||
|
mappedModel: "",
|
||||||
|
expectedAction: "gemini-pro:generateContent",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "mapped_model_replaces_url_model",
|
||||||
|
path: "/publishers/google/models/gemini-exp:generateContent",
|
||||||
|
mappedModel: "gemini-2.0-flash",
|
||||||
|
expectedAction: "gemini-2.0-flash:generateContent",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "mapping_preserves_method",
|
||||||
|
path: "/publishers/google/models/gemini-2.5-preview:streamGenerateContent",
|
||||||
|
mappedModel: "gemini-flash",
|
||||||
|
expectedAction: "gemini-flash:streamGenerateContent",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
var capturedAction string
|
||||||
|
|
||||||
|
mockGeminiHandler := func(c *gin.Context) {
|
||||||
|
capturedAction = c.Param("action")
|
||||||
|
c.JSON(http.StatusOK, gin.H{"captured": capturedAction})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the actual createGeminiBridgeHandler function
|
||||||
|
bridgeHandler := createGeminiBridgeHandler(mockGeminiHandler)
|
||||||
|
|
||||||
|
r := gin.New()
|
||||||
|
if tt.mappedModel != "" {
|
||||||
|
r.Use(func(c *gin.Context) {
|
||||||
|
c.Set(MappedModelContextKey, tt.mappedModel)
|
||||||
|
c.Next()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
r.POST("/api/provider/google/v1beta1/*path", bridgeHandler)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/api/provider/google/v1beta1"+tt.path, nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
r.ServeHTTP(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusOK {
|
||||||
|
t.Fatalf("Expected status 200, got %d", w.Code)
|
||||||
|
}
|
||||||
|
if capturedAction != tt.expectedAction {
|
||||||
|
t.Errorf("Expected action '%s', got '%s'", tt.expectedAction, capturedAction)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCreateGeminiBridgeHandler_InvalidPath(t *testing.T) {
|
||||||
|
gin.SetMode(gin.TestMode)
|
||||||
|
|
||||||
|
mockHandler := func(c *gin.Context) {
|
||||||
|
c.JSON(http.StatusOK, gin.H{"ok": true})
|
||||||
|
}
|
||||||
|
bridgeHandler := createGeminiBridgeHandler(mockHandler)
|
||||||
|
|
||||||
|
r := gin.New()
|
||||||
|
r.POST("/api/provider/google/v1beta1/*path", bridgeHandler)
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodPost, "/api/provider/google/v1beta1/invalid/path", nil)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
r.ServeHTTP(w, req)
|
||||||
|
|
||||||
|
if w.Code != http.StatusBadRequest {
|
||||||
|
t.Errorf("Expected status 400 for invalid path, got %d", w.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/logging"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/logging"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/util"
|
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers"
|
"github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers/claude"
|
"github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers/claude"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers/gemini"
|
"github.com/router-for-me/CLIProxyAPI/v6/sdk/api/handlers/gemini"
|
||||||
@@ -169,30 +168,22 @@ func (m *AmpModule) registerManagementRoutes(engine *gin.Engine, baseHandler *ha
|
|||||||
// We bridge these to our standard Gemini handler to enable local OAuth.
|
// We bridge these to our standard Gemini handler to enable local OAuth.
|
||||||
// If no local OAuth is available, falls back to ampcode.com proxy.
|
// If no local OAuth is available, falls back to ampcode.com proxy.
|
||||||
geminiHandlers := gemini.NewGeminiAPIHandler(baseHandler)
|
geminiHandlers := gemini.NewGeminiAPIHandler(baseHandler)
|
||||||
geminiBridge := createGeminiBridgeHandler(geminiHandlers)
|
geminiBridge := createGeminiBridgeHandler(geminiHandlers.GeminiHandler)
|
||||||
geminiV1Beta1Fallback := NewFallbackHandler(func() *httputil.ReverseProxy {
|
geminiV1Beta1Fallback := NewFallbackHandlerWithMapper(func() *httputil.ReverseProxy {
|
||||||
return m.getProxy()
|
return m.getProxy()
|
||||||
})
|
}, m.modelMapper)
|
||||||
geminiV1Beta1Handler := geminiV1Beta1Fallback.WrapHandler(geminiBridge)
|
geminiV1Beta1Handler := geminiV1Beta1Fallback.WrapHandler(geminiBridge)
|
||||||
|
|
||||||
// Route POST model calls through Gemini bridge when a local provider exists, otherwise proxy.
|
// Route POST model calls through Gemini bridge with FallbackHandler.
|
||||||
|
// FallbackHandler checks provider -> mapping -> proxy fallback automatically.
|
||||||
// All other methods (e.g., GET model listing) always proxy to upstream to preserve Amp CLI behavior.
|
// All other methods (e.g., GET model listing) always proxy to upstream to preserve Amp CLI behavior.
|
||||||
ampAPI.Any("/provider/google/v1beta1/*path", func(c *gin.Context) {
|
ampAPI.Any("/provider/google/v1beta1/*path", func(c *gin.Context) {
|
||||||
if c.Request.Method == "POST" {
|
if c.Request.Method == "POST" {
|
||||||
// Attempt to extract the model name from the AMP-style path
|
|
||||||
if path := c.Param("path"); strings.Contains(path, "/models/") {
|
if path := c.Param("path"); strings.Contains(path, "/models/") {
|
||||||
modelPart := path[strings.Index(path, "/models/")+len("/models/"):]
|
// POST with /models/ path -> use Gemini bridge with fallback handler
|
||||||
if colonIdx := strings.Index(modelPart, ":"); colonIdx > 0 {
|
// FallbackHandler will check provider/mapping and proxy if needed
|
||||||
modelPart = modelPart[:colonIdx]
|
geminiV1Beta1Handler(c)
|
||||||
}
|
return
|
||||||
if modelPart != "" {
|
|
||||||
normalized, _ := util.NormalizeGeminiThinkingModel(modelPart)
|
|
||||||
// Only handle locally when we have a provider; otherwise fall back to proxy
|
|
||||||
if providers := util.GetProviderName(normalized); len(providers) > 0 {
|
|
||||||
geminiV1Beta1Handler(c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Non-POST or no local provider available -> proxy upstream
|
// Non-POST or no local provider available -> proxy upstream
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ type Content struct {
|
|||||||
// Part represents a distinct piece of content within a message.
|
// Part represents a distinct piece of content within a message.
|
||||||
// A part can be text, inline data (like an image), a function call, or a function response.
|
// A part can be text, inline data (like an image), a function call, or a function response.
|
||||||
type Part struct {
|
type Part struct {
|
||||||
|
Thought bool `json:"thought,omitempty"`
|
||||||
|
|
||||||
// Text contains plain text content.
|
// Text contains plain text content.
|
||||||
Text string `json:"text,omitempty"`
|
Text string `json:"text,omitempty"`
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"github.com/klauspost/compress/zstd"
|
"github.com/klauspost/compress/zstd"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/buildinfo"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/interfaces"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/interfaces"
|
||||||
"github.com/router-for-me/CLIProxyAPI/v6/internal/util"
|
"github.com/router-for-me/CLIProxyAPI/v6/internal/util"
|
||||||
)
|
)
|
||||||
@@ -603,6 +604,7 @@ func (l *FileRequestLogger) formatRequestInfo(url, method string, headers map[st
|
|||||||
var content strings.Builder
|
var content strings.Builder
|
||||||
|
|
||||||
content.WriteString("=== REQUEST INFO ===\n")
|
content.WriteString("=== REQUEST INFO ===\n")
|
||||||
|
content.WriteString(fmt.Sprintf("Version: %s\n", buildinfo.Version))
|
||||||
content.WriteString(fmt.Sprintf("URL: %s\n", url))
|
content.WriteString(fmt.Sprintf("URL: %s\n", url))
|
||||||
content.WriteString(fmt.Sprintf("Method: %s\n", method))
|
content.WriteString(fmt.Sprintf("Method: %s\n", method))
|
||||||
content.WriteString(fmt.Sprintf("Timestamp: %s\n", time.Now().Format(time.RFC3339Nano)))
|
content.WriteString(fmt.Sprintf("Timestamp: %s\n", time.Now().Format(time.RFC3339Nano)))
|
||||||
|
|||||||
@@ -604,10 +604,22 @@ type kiroHistoryMessage struct {
|
|||||||
AssistantResponseMessage *kiroAssistantResponseMessage `json:"assistantResponseMessage,omitempty"`
|
AssistantResponseMessage *kiroAssistantResponseMessage `json:"assistantResponseMessage,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// kiroImage represents an image in Kiro API format
|
||||||
|
type kiroImage struct {
|
||||||
|
Format string `json:"format"`
|
||||||
|
Source kiroImageSource `json:"source"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// kiroImageSource contains the image data
|
||||||
|
type kiroImageSource struct {
|
||||||
|
Bytes string `json:"bytes"` // base64 encoded image data
|
||||||
|
}
|
||||||
|
|
||||||
type kiroUserInputMessage struct {
|
type kiroUserInputMessage struct {
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
ModelID string `json:"modelId"`
|
ModelID string `json:"modelId"`
|
||||||
Origin string `json:"origin"`
|
Origin string `json:"origin"`
|
||||||
|
Images []kiroImage `json:"images,omitempty"`
|
||||||
UserInputMessageContext *kiroUserInputMessageContext `json:"userInputMessageContext,omitempty"`
|
UserInputMessageContext *kiroUserInputMessageContext `json:"userInputMessageContext,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -824,6 +836,7 @@ func (e *KiroExecutor) buildUserMessageStruct(msg gjson.Result, modelID, origin
|
|||||||
content := msg.Get("content")
|
content := msg.Get("content")
|
||||||
var contentBuilder strings.Builder
|
var contentBuilder strings.Builder
|
||||||
var toolResults []kiroToolResult
|
var toolResults []kiroToolResult
|
||||||
|
var images []kiroImage
|
||||||
|
|
||||||
if content.IsArray() {
|
if content.IsArray() {
|
||||||
for _, part := range content.Array() {
|
for _, part := range content.Array() {
|
||||||
@@ -831,6 +844,25 @@ func (e *KiroExecutor) buildUserMessageStruct(msg gjson.Result, modelID, origin
|
|||||||
switch partType {
|
switch partType {
|
||||||
case "text":
|
case "text":
|
||||||
contentBuilder.WriteString(part.Get("text").String())
|
contentBuilder.WriteString(part.Get("text").String())
|
||||||
|
case "image":
|
||||||
|
// Extract image data from Claude API format
|
||||||
|
mediaType := part.Get("source.media_type").String()
|
||||||
|
data := part.Get("source.data").String()
|
||||||
|
|
||||||
|
// Extract format from media_type (e.g., "image/png" -> "png")
|
||||||
|
format := ""
|
||||||
|
if idx := strings.LastIndex(mediaType, "/"); idx != -1 {
|
||||||
|
format = mediaType[idx+1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
if format != "" && data != "" {
|
||||||
|
images = append(images, kiroImage{
|
||||||
|
Format: format,
|
||||||
|
Source: kiroImageSource{
|
||||||
|
Bytes: data,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
case "tool_result":
|
case "tool_result":
|
||||||
// Extract tool result for API
|
// Extract tool result for API
|
||||||
toolUseID := part.Get("tool_use_id").String()
|
toolUseID := part.Get("tool_use_id").String()
|
||||||
@@ -872,11 +904,18 @@ func (e *KiroExecutor) buildUserMessageStruct(msg gjson.Result, modelID, origin
|
|||||||
contentBuilder.WriteString(content.String())
|
contentBuilder.WriteString(content.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
return kiroUserInputMessage{
|
userMsg := kiroUserInputMessage{
|
||||||
Content: contentBuilder.String(),
|
Content: contentBuilder.String(),
|
||||||
ModelID: modelID,
|
ModelID: modelID,
|
||||||
Origin: origin,
|
Origin: origin,
|
||||||
}, toolResults
|
}
|
||||||
|
|
||||||
|
// Add images to message if present
|
||||||
|
if len(images) > 0 {
|
||||||
|
userMsg.Images = images
|
||||||
|
}
|
||||||
|
|
||||||
|
return userMsg, toolResults
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildAssistantMessageStruct builds an assistant message with tool uses
|
// buildAssistantMessageStruct builds an assistant message with tool uses
|
||||||
|
|||||||
@@ -83,7 +83,15 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _
|
|||||||
for j := 0; j < len(contentResults); j++ {
|
for j := 0; j < len(contentResults); j++ {
|
||||||
contentResult := contentResults[j]
|
contentResult := contentResults[j]
|
||||||
contentTypeResult := contentResult.Get("type")
|
contentTypeResult := contentResult.Get("type")
|
||||||
if contentTypeResult.Type == gjson.String && contentTypeResult.String() == "text" {
|
if contentTypeResult.Type == gjson.String && contentTypeResult.String() == "thinking" {
|
||||||
|
prompt := contentResult.Get("thinking").String()
|
||||||
|
signatureResult := contentResult.Get("signature")
|
||||||
|
signature := geminiCLIClaudeThoughtSignature
|
||||||
|
if signatureResult.Exists() {
|
||||||
|
signature = signatureResult.String()
|
||||||
|
}
|
||||||
|
clientContent.Parts = append(clientContent.Parts, client.Part{Text: prompt, Thought: true, ThoughtSignature: signature})
|
||||||
|
} else if contentTypeResult.Type == gjson.String && contentTypeResult.String() == "text" {
|
||||||
prompt := contentResult.Get("text").String()
|
prompt := contentResult.Get("text").String()
|
||||||
clientContent.Parts = append(clientContent.Parts, client.Part{Text: prompt})
|
clientContent.Parts = append(clientContent.Parts, client.Part{Text: prompt})
|
||||||
} else if contentTypeResult.Type == gjson.String && contentTypeResult.String() == "tool_use" {
|
} else if contentTypeResult.Type == gjson.String && contentTypeResult.String() == "tool_use" {
|
||||||
@@ -92,10 +100,16 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _
|
|||||||
functionID := contentResult.Get("id").String()
|
functionID := contentResult.Get("id").String()
|
||||||
var args map[string]any
|
var args map[string]any
|
||||||
if err := json.Unmarshal([]byte(functionArgs), &args); err == nil {
|
if err := json.Unmarshal([]byte(functionArgs), &args); err == nil {
|
||||||
clientContent.Parts = append(clientContent.Parts, client.Part{
|
if strings.Contains(modelName, "claude") {
|
||||||
FunctionCall: &client.FunctionCall{ID: functionID, Name: functionName, Args: args},
|
clientContent.Parts = append(clientContent.Parts, client.Part{
|
||||||
ThoughtSignature: geminiCLIClaudeThoughtSignature,
|
FunctionCall: &client.FunctionCall{ID: functionID, Name: functionName, Args: args},
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
clientContent.Parts = append(clientContent.Parts, client.Part{
|
||||||
|
FunctionCall: &client.FunctionCall{ID: functionID, Name: functionName, Args: args},
|
||||||
|
ThoughtSignature: geminiCLIClaudeThoughtSignature,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} 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()
|
||||||
|
|||||||
@@ -111,8 +111,11 @@ func ConvertAntigravityResponseToClaude(_ context.Context, _ string, originalReq
|
|||||||
if partTextResult.Exists() {
|
if partTextResult.Exists() {
|
||||||
// Process thinking content (internal reasoning)
|
// Process thinking content (internal reasoning)
|
||||||
if partResult.Get("thought").Bool() {
|
if partResult.Get("thought").Bool() {
|
||||||
// Continue existing thinking block if already in thinking state
|
if thoughtSignature := partResult.Get("thoughtSignature"); thoughtSignature.Exists() && thoughtSignature.String() != "" {
|
||||||
if params.ResponseType == 2 {
|
output = output + "event: content_block_delta\n"
|
||||||
|
data, _ := sjson.Set(fmt.Sprintf(`{"type":"content_block_delta","index":%d,"delta":{"type":"signature_delta","signature":""}}`, params.ResponseIndex), "delta.signature", thoughtSignature.String())
|
||||||
|
output = output + fmt.Sprintf("data: %s\n\n\n", data)
|
||||||
|
} else if params.ResponseType == 2 { // Continue existing thinking block if already in thinking state
|
||||||
output = output + "event: content_block_delta\n"
|
output = output + "event: content_block_delta\n"
|
||||||
data, _ := sjson.Set(fmt.Sprintf(`{"type":"content_block_delta","index":%d,"delta":{"type":"thinking_delta","thinking":""}}`, params.ResponseIndex), "delta.thinking", partTextResult.String())
|
data, _ := sjson.Set(fmt.Sprintf(`{"type":"content_block_delta","index":%d,"delta":{"type":"thinking_delta","thinking":""}}`, params.ResponseIndex), "delta.thinking", partTextResult.String())
|
||||||
output = output + fmt.Sprintf("data: %s\n\n\n", data)
|
output = output + fmt.Sprintf("data: %s\n\n\n", data)
|
||||||
@@ -163,15 +166,16 @@ func ConvertAntigravityResponseToClaude(_ context.Context, _ string, originalReq
|
|||||||
output = output + "\n\n\n"
|
output = output + "\n\n\n"
|
||||||
params.ResponseIndex++
|
params.ResponseIndex++
|
||||||
}
|
}
|
||||||
|
if partTextResult.String() != "" {
|
||||||
// Start a new text content block
|
// Start a new text content block
|
||||||
output = output + "event: content_block_start\n"
|
output = output + "event: content_block_start\n"
|
||||||
output = output + fmt.Sprintf(`data: {"type":"content_block_start","index":%d,"content_block":{"type":"text","text":""}}`, params.ResponseIndex)
|
output = output + fmt.Sprintf(`data: {"type":"content_block_start","index":%d,"content_block":{"type":"text","text":""}}`, params.ResponseIndex)
|
||||||
output = output + "\n\n\n"
|
output = output + "\n\n\n"
|
||||||
output = output + "event: content_block_delta\n"
|
output = output + "event: content_block_delta\n"
|
||||||
data, _ := sjson.Set(fmt.Sprintf(`{"type":"content_block_delta","index":%d,"delta":{"type":"text_delta","text":""}}`, params.ResponseIndex), "delta.text", partTextResult.String())
|
data, _ := sjson.Set(fmt.Sprintf(`{"type":"content_block_delta","index":%d,"delta":{"type":"text_delta","text":""}}`, params.ResponseIndex), "delta.text", partTextResult.String())
|
||||||
output = output + fmt.Sprintf("data: %s\n\n\n", data)
|
output = output + fmt.Sprintf("data: %s\n\n\n", data)
|
||||||
params.ResponseType = 1 // Set state to content
|
params.ResponseType = 1 // Set state to content
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ func ConvertOpenAIRequestToAntigravity(modelName string, inputRawJSON []byte, _
|
|||||||
out, _ = sjson.SetRawBytes(out, "request.contents.-1", node)
|
out, _ = sjson.SetRawBytes(out, "request.contents.-1", node)
|
||||||
|
|
||||||
// Append a single tool content combining name + response per function
|
// Append a single tool content combining name + response per function
|
||||||
toolNode := []byte(`{"role":"tool","parts":[]}`)
|
toolNode := []byte(`{"role":"user","parts":[]}`)
|
||||||
pp := 0
|
pp := 0
|
||||||
for _, fid := range fIDs {
|
for _, fid := range fIDs {
|
||||||
if name, ok := tcID2Name[fid]; ok {
|
if name, ok := tcID2Name[fid]; ok {
|
||||||
|
|||||||
Reference in New Issue
Block a user