A bare grok-imagine-image-2.0 on /v1/images/generations got 404 "magpie knows no model ... to draw with", while grok/grok-imagine-image-2.0 drew: a bare name was looked up only in grokDrawers, a fixed list of two. The same held for a bare video name not in grokVideoModels, though with the provider named videosCreate already took any grok-imagine-video*. What changed - draw.go: resolveDrawing, after an exact match in any provider's Drawers, sends a bare name of a subscription's image family to it (drawsFamily): grok-imagine-image* on a Grok subscription, gpt-image-* on a ChatGPT account (the sibling list, codexDrawers). The vendor draws it or refuses it in its own words. Exact matches still win, so an API key that lists the model keeps it; a name of no family is still 404. - drawing_route.go: Codex's per-turn preferred provider takes the same family match. - video.go: bareVideomaker takes any grok-imagine-video* on a Grok subscription, matching what videosCreate takes with the provider named. - AutoDrawer and AutoVideomaker are unchanged (still the listed models). - A moved Grok user goes through this same gateway code (drawsGrok covers the plugin's provider; the plugin only signs), so the Grok plugin needs no change and the mover's min stays. What was run - New TestGrokDrawsANewerModelByItsBareName (the reporter's request), TestCodexDrawsANewerModelByItsBareName, a bare grok-imagine-image-2.0 in TestGrokPluginDraws (plugin parity) and grok-imagine-video-2.0 in TestVideoModelByItsBareName. With the family match switched off by hand all four fail with the 404 "magpie knows no model"; restored they pass. - gofmt -l clean; go vet ./... on darwin, GOOS=linux -tags nogui, GOOS=windows; go build on darwin, linux (nogui), windows. - go test -tags nogui -count=1 ./internal/gateway/... ./internal/imagemcp/... ./internal/provider/...: ok (sandbox HOME, private GOCACHE). Not run - Not tried against a real Grok or ChatGPT account: the request sent is the one the reporter already drew with as grok/grok-imagine-image-2.0; only which provider a bare name resolves to changed. Whether chatgpt.com serves any other gpt-image-* is the vendor's to answer. - The full go test ./... was not run.
65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package gateway
|
|
|
|
import (
|
|
"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)
|
|
}
|
|
if preferred := server.codexDrawingProvider(request); 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, 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
|
|
}
|
|
|
|
func (server *Server) codexDrawingProvider(request *http.Request) 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
|
|
}
|
|
if route.Done && (route.Status >= 400 || route.Error != "") {
|
|
return ""
|
|
}
|
|
return route.imageProvider
|
|
}
|
|
return ""
|
|
}
|