changqiu4890 on Discord: the group smart-split has three Codex CPA chat models, DeepSeek-V4.1-Flash and Codex CPA's gpt-image-2.5, and dsh, Codex and Pi are set to it. Image requests went to other providers' image models. Two causes in magpie: - drawingTries tried every member of a group named for a drawing in the order chat routing plans them, so the chat members came first. group/smart-split drew on cpa/gpt-6-astra, which was asked as a chat for an image, before it reached the group's image member. A group with members that make the kind (drawsModel, or servesKind for video) is now tried on those members alone. The fallback between them stays as it was. - Codex's image tool drew on the provider that served the turn, else on Settings' pick. A group's image member was never used: a turn on DeepSeek, or on the relay, drew with Settings' model or with the relay's other GPT Image. codexDrawingProvider now also returns the routing group the turn asked for. When that group draws (GroupDraws), the drawing goes to its image member through resolveDrawing, which keeps the member's provider. The reporter's Routing screenshot also shows explicit requests from a client magpie names "Mozilla": x0-15/gpt-image-2.5, codex/gpt-image-2.5, and bare gpt-image-1 and gpt-image-1.5. magpie routes a request that names a provider to that provider, and a bare id to the first provider whose Drawers list it. Nothing in such a request links it to the agent's group, so this commit leaves those requests alone. Tests: - TestMixedGroupDrawsOnItsImageMemberOnly (new): the reporter's group shape on fake upstreams, with another relay listing gpt-image-2.5 first. Red before the fix (drew on cpa/gpt-6-astra), green after. - TestCodexDrawingTakesItsGroupsImageMember (new): red with the group branch turned off by hand (drew on chat/gpt-image-2), green with it. - TestMixedGroupMakesVideoOnItsVideoMemberOnly (new): a guard for the video sibling. It passes with the filter turned off as well, because video's mediaMembers already keeps only video members (KindGroup). Run on mote (mote-run) at this tree: - gofmt -l - go vet ./internal/gateway on darwin, GOOS=linux -tags nogui and GOOS=windows - go test -count=1 -run 'Group|Draw|Image|Video|Media' ./internal/gateway - go test -count=1 -timeout 45m ./internal/gateway ./internal/provider Not tried: - a real Codex CPA relay or a real dsh session - the image MCP's default for a non-Codex agent set to a group: the MCP call carries no link to the agent's chat route, so it still uses Settings' pick - chat routing to a group's image member when the member's provider has no picks: the member's provider is still the pinned one, and this commit doesn't change it
82 lines
2.4 KiB
Go
82 lines
2.4 KiB
Go
package gateway
|
|
|
|
import (
|
|
"cmp"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
func (server *Server) drawingModel(request *http.Request, id string) (provider.Provider, string, bool) {
|
|
if agentOf(request) != "codex" || strings.Contains(id, "/") {
|
|
return resolveDrawing(id)
|
|
}
|
|
preferred, group := server.codexDrawingProvider(request)
|
|
if group != "" && GroupDraws(group) {
|
|
// the turn's routing group has an image model of its own: Codex
|
|
// draws on it, on the provider the user put it there with, not on
|
|
// a chat member's provider or Settings' pick (changqiu4890 on
|
|
// Discord)
|
|
return resolveDrawing(group)
|
|
}
|
|
if preferred != "" {
|
|
if matched, err := provider.Find(preferred); err == nil && matched.On() && !matched.DecideOnly() {
|
|
for _, model := range Drawers(*matched) {
|
|
if model.ID == id {
|
|
return *matched, id, true
|
|
}
|
|
}
|
|
if drawsFamily(*matched, id) {
|
|
return *matched, drawnAs(*matched, id), true
|
|
}
|
|
}
|
|
}
|
|
if selected, ok := drawer(); ok {
|
|
return resolveDrawing(selected)
|
|
}
|
|
return provider.Provider{}, "", false
|
|
}
|
|
|
|
func drawingTurnID(id string) string {
|
|
id = strings.TrimSpace(id)
|
|
if len(id) > 128 || strings.ContainsAny(id, "\r\n\t") {
|
|
return ""
|
|
}
|
|
return id
|
|
}
|
|
|
|
// codexDrawingProvider is the provider that served the Codex turn an
|
|
// image tool call is of, and the routing group the turn asked for, if it
|
|
// did.
|
|
func (server *Server) codexDrawingProvider(request *http.Request) (string, string) {
|
|
rawTurn := strings.TrimSpace(request.Header.Get("x-codex-image-turn-id"))
|
|
turn := drawingTurnID(rawTurn)
|
|
session := sessionOf(request.Header)
|
|
if rawTurn != "" && turn == "" || turn == "" && session == "" {
|
|
return "", ""
|
|
}
|
|
caller := codexTurnKey(request, callerOf(request).agent)
|
|
server.trace.mu.Lock()
|
|
defer server.trace.mu.Unlock()
|
|
for index := len(server.trace.routes) - 1; index >= 0; index-- {
|
|
route := server.trace.routes[index]
|
|
if route.imageCaller != caller || route.Kind != "" && route.Kind != "luna_reserve" {
|
|
continue
|
|
}
|
|
if turn != "" && route.imageTurn != turn || session != "" && route.Session != session {
|
|
continue
|
|
}
|
|
group := ""
|
|
if route.Group != nil {
|
|
group = cmp.Or(route.Group.Ref, provider.GroupPrefix+route.Group.ID)
|
|
}
|
|
if route.Done && (route.Status >= 400 || route.Error != "") {
|
|
// a failed turn served nothing; its group is still the user's
|
|
return "", group
|
|
}
|
|
return route.imageProvider, group
|
|
}
|
|
return "", ""
|
|
}
|