From 7194c4945262b9fdae87aaf8283b4545b0f0cd9c Mon Sep 17 00:00:00 2001 From: Jason Xu Date: Wed, 23 Sep 2026 10:00:36 +0800 Subject: [PATCH] fix: drop unsupported tools for Mimo 2.6 Flash --- internal/gateway/gateway.go | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index 310573e..b48a188 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -272,7 +272,11 @@ func (g *Gateway) prepareRouteBodies(from wire.Protocol, route models.Route, inp if tier == config.TierGo { baseURL = g.cfg.Upstream.Go } - upstreamPayload, err := wire.PrepareRequest(from, protocol, input, baseURL) + requestInput := input + if from == wire.Responses && protocol != from && isMimo26Flash(route.ID) { + requestInput = dropNonFunctionResponsesTools(input) + } + upstreamPayload, err := wire.PrepareRequest(from, protocol, requestInput, baseURL) if err != nil { if tier != route.Tier { // A fallback tier may use a stricter wire format than the @@ -295,6 +299,34 @@ func (g *Gateway) prepareRouteBodies(from wire.Protocol, route models.Route, inp return bodies, nil } +func isMimo26Flash(model string) bool { + parts := strings.Split(strings.ToLower(strings.TrimSpace(model)), "/") + return parts[len(parts)-1] == "mimo-v2.6-flash" +} + +func dropNonFunctionResponsesTools(input map[string]any) map[string]any { + tools, ok := input["tools"].([]any) + if !ok { + return input + } + filtered := make([]any, 0, len(tools)) + for _, raw := range tools { + tool, ok := raw.(map[string]any) + if ok && jsonutil.StringAt(tool, "type") == "function" { + filtered = append(filtered, raw) + } + } + if len(filtered) == len(tools) { + return input + } + request := make(map[string]any, len(input)) + for key, value := range input { + request[key] = value + } + request["tools"] = filtered + return request +} + func copyErrorResponse(w http.ResponseWriter, protocol wire.Protocol, resp *http.Response, requestID string) { body, _ := io.ReadAll(io.LimitReader(resp.Body, 4<<20)) if retryAfter := resp.Header.Get("Retry-After"); retryAfter != "" {