fix: resolve retired/preview gemini model routing and test configuration errors
CI / Lint (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Build (push) Has been cancelled

This commit is contained in:
2026-06-18 13:32:34 +00:00
parent 73a82e6175
commit 25e246061f
16 changed files with 227 additions and 43 deletions
+50 -11
View File
@@ -1,12 +1,13 @@
package server
import (
"encoding/json"
"context"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"regexp"
"strings"
"sync"
"time"
@@ -57,7 +58,9 @@ func NewServer(cfg *config.Config, database *db.DB) *Server {
if err != nil {
fmt.Printf("Warning: Failed to fetch initial model registry: %v\n", err)
} else {
s.registryMu.Lock()
s.registry = registry
s.registryMu.Unlock()
}
}()
@@ -976,12 +979,14 @@ func (s *Server) buildRouteContextFromChat(req models.ChatCompletionRequest) *ro
strings.Contains(msgLower, "explain in detail")
routeCtx := &router.RouteContext{
UserMessage: userMessage,
InputTokens: inputTokens,
HasMultimodalInput: hasMultimodal,
RequiresToolCalling: requiresToolCalling,
RequiresReasoning: requiresReasoning,
UserMessage: userMessage,
InputTokens: inputTokens,
HasMultimodalInput: hasMultimodal,
RequiresToolCalling: requiresToolCalling,
RequiresReasoning: requiresReasoning,
IsSoftwareDevelopment: isSoftwareDevelopment(userMessage),
}
log.Printf("[DEBUG] RouteContext built: msg=%q, IsSoftwareDevelopment=%v", userMessage, routeCtx.IsSoftwareDevelopment)
routeCtx.Tags = s.getRouteCtxTags(routeCtx)
return routeCtx
}
@@ -1034,12 +1039,14 @@ func (s *Server) buildRouteContextFromResponses(req models.ResponsesRequest) *ro
strings.Contains(msgLower, "explain in detail")
routeCtx := &router.RouteContext{
UserMessage: userMessage,
InputTokens: inputTokens,
HasMultimodalInput: hasMultimodal,
RequiresToolCalling: requiresToolCalling,
RequiresReasoning: requiresReasoning,
UserMessage: userMessage,
InputTokens: inputTokens,
HasMultimodalInput: hasMultimodal,
RequiresToolCalling: requiresToolCalling,
RequiresReasoning: requiresReasoning,
IsSoftwareDevelopment: isSoftwareDevelopment(userMessage),
}
log.Printf("[DEBUG] RouteContext built: msg=%q, IsSoftwareDevelopment=%v", userMessage, routeCtx.IsSoftwareDevelopment)
routeCtx.Tags = s.getRouteCtxTags(routeCtx)
return routeCtx
}
@@ -1102,3 +1109,35 @@ func (s *Server) getRouteCtxTags(routeCtx *router.RouteContext) []string {
return tags
}
var (
modelStripRegex = regexp.MustCompile(`(?i)\b[a-z0-9/._:-]*(code|coder|codex)[a-z0-9/._:-]*\b`)
memoryContextRegex = regexp.MustCompile(`(?s)<memory-context>.*?</memory-context>`)
softwareDevRegex = regexp.MustCompile(`(?i)\b(code|coding|programmer|programming|software|refactor|refactoring|compile|compiling|compiler|git|github|debug|debugging|repository|repo|unittest|unit test|test suite|test case|test cases|pull request|merge conflict|syntax error|source code|python|golang|javascript|typescript|ruby|php|perl|swift|kotlin|scala|rustlang|bash|powershell|sql|script|snippet|api|endpoint|patch|diff)\b`)
)
func isSoftwareDevelopment(userMessage string) bool {
msgLower := strings.ToLower(userMessage)
sanitized := memoryContextRegex.ReplaceAllString(msgLower, "")
sanitized = modelStripRegex.ReplaceAllString(sanitized, "")
if strings.Contains(sanitized, "script") {
nonCodingScriptTerms := []string{
"speaker script", "dialogue script", "movie script", "theatre script",
"theater script", "script writing", "script writer", "video script",
"audio script", "podcast script", "script for Kayla", "script for the",
}
hasNonCodingScript := false
for _, term := range nonCodingScriptTerms {
if strings.Contains(sanitized, strings.ToLower(term)) {
hasNonCodingScript = true
break
}
}
if hasNonCodingScript {
sanitized = strings.ReplaceAll(sanitized, "script", "")
}
}
return softwareDevRegex.MatchString(sanitized)
}