Files
magpie/internal/agent/icons.go
T
yetone 5d126a0db7 agents: Pi's model picker lists the models of its openai-codex sign-in from Pi's own registry, and its Default says it lets Pi pick (#709) — Pi's native options came from models.dev by provider id, and models.dev has no openai-codex (Pi's "OpenAI Codex (legacy)" ChatGPT sign-in), so a Pi signed in to both openai and openai-codex was offered openai/… only. Pi's (and OmO's) own options now come first from the model registry in the package Pi was installed from: the pi command on PATH leads to @earendil-works/pi-coding-agent, and pi-ai's dist/providers/data/<provider>.json (Pi 1.0) is read as is, in its order, chat models only (no gpt-image-2), memoized by the file's stamp — the list Pi's /model offers, which moves with every Pi update. A provider the registry doesn't have keeps models.dev's list; openai-codex with no registry in reach falls back to Codex CLI's models_cache.json (the same ChatGPT backend); models.dev's openai list isn't mapped onto it. The rows are openai-codex/<model> under "OpenAI Codex" with OpenAI's logo, a row each beside openai/<model> of the same name; picking one writes defaultProvider=openai-codex, defaultModel=<model> as before. omp shared the gap for its current model's provider (ownOptions): it now reads omp's own catalog (@oh-my-pi/pi-catalog src/models.json, non-chat kinds left out); omp's signed-in providers that aren't the current one are still #341's. Default in Pi's and OmO's model picker now says "clears the default model; Pi picks one on its own" (zh 清除显式默认模型,由 Pi 自动选择; no ja table exists), other agents' still say what they ship with. TestPiOffersItsOwnOpenAICodexModels (a fake npm-linked Pi 1.0 install, temp HOME and PI_CODING_AGENT_DIR, auth.json with openai and openai-codex oauth test metadata), TestPiOpenAICodexWithoutItsRegistry and TestOmpOffersItsOwnOpenAICodexModels fail on the old code (no openai-codex rows) and pass; pi-default-note.test.cjs (webkit, en/zh) fails on the old app.js and passes; agent-disconnect, agent-models and agent-model-groups GUI tests pass. Read-only against this machine's real installs: Pi 1.0.0 gives openai-codex 9 models and openai 44, omp's catalog openai-codex 8. go vet, builds (darwin, GOOS=linux, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass but TestProvidersAnswerWhileListsComeIn, TestClaudeSignedOut, TestClaudeAccountNamedAsItsLogin and TestClaudeIdentityServedWhileAsked, timing tests that pass alone. Not tried in the GUI with real Pi sign-ins, nor with a Pi older than 1.0 (no data folder: models.dev and Codex CLI's list as before) or a Windows npm shim.
2026-10-04 01:53:58 +08:00

68 lines
2.1 KiB
Go

package agent
import (
"strings"
"github.com/yetone/magpie/internal/provider"
)
// Every model in a picker carries its vendor's real logo. A models.dev
// provider id maps through the presets; a model id the presets do not
// cover is recognised by its family name. Anything else has no icon at
// all, never a made-up one.
// byFamily pairs a model id prefix with the vendor logo it belongs to.
var byFamily = []struct{ prefix, icon string }{
{"claude", "claude-color"},
{"gpt", "openai"}, {"o1", "openai"}, {"o3", "openai"}, {"o4", "openai"}, {"codex", "openai"},
{"gemini", "gemini-color"}, {"gemma", "gemini-color"},
{"deepseek", "deepseek-color"},
{"grok", "xai"},
{"kimi", "kimi"}, {"moonshot", "kimi"},
{"glm", "zhipu-color"},
{"qwen", "qwen-color"}, {"qwq", "qwen-color"},
{"mistral", "mistral-color"}, {"codestral", "mistral-color"}, {"devstral", "mistral-color"}, {"magistral", "mistral-color"},
{"minimax", "minimax-color"},
{"mimo", "mimocode"}, {"xiaomi", "mimocode"},
{"step", "stepfun-color"},
}
// providerIcon is the logo of a models.dev provider itself, which for one
// serving other vendors' models (GitHub Copilot) is none of theirs.
func providerIcon(catalogID string) string {
if ic := provider.IconForCatalog(catalogID); ic != "" {
return ic
}
switch catalogID {
case "github-copilot":
return "githubcopilot"
case "openai-codex": // Pi's and omp's ChatGPT sign-in
return providerIcon("openai")
}
return ""
}
// modelIcon names the bundled logo for a model, given the models.dev
// provider it came from (may be empty) and its id.
func modelIcon(catalogID, modelID string) string {
if catalogID != "" {
if ic := provider.IconForCatalog(catalogID); ic != "" {
return ic
}
}
id := strings.ToLower(modelID)
if _, rest, ok := strings.Cut(id, "/"); ok { // "vendor/model" on relays
id = rest
}
for _, f := range byFamily {
if strings.HasPrefix(id, f.prefix) {
return f.icon
}
}
return ""
}
// ModelIcon is the logo of a model's maker, known by its id's (or name's)
// family alone; "" when it isn't one of them.
func ModelIcon(model string) string { return modelIcon("", model) }