Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
import: OpenCode's ids for vendors magpie has a preset at the same address come in on it (#2405)
ggbdpqeaa71168a223
diff --git a/internal/provider/import_opencode.go b/internal/provider/import_opencode.goindex c3ff93c71..ef03aa170 100644--- a/internal/provider/import_opencode.go+++ b/internal/provider/import_opencode.go@@ -31,6 +31,12 @@ func openCodeAuthPath() string {// openCodePresets are OpenCode's provider ids by the magpie preset at the// same address. An id at a host the preset doesn't serve (SiliconFlow's// .com beside the preset's .cn) is left out: its key would be sent there.+// The ids' hosts are models.dev's api for each, what OpenCode itself sends+// to, and it is the preset's own address, not one of its regions. Where a+// region would be the right target — Zhipu's, Z.ai's, StepFun's and+// Volcengine's pay-as-you-go ids beside plan-first defaults, MiniMax's and+// Tencent's coding plans — auth.json says nothing to pick a region by, so+// those ids stay out and are skipped with a reason that says why.var openCodePresets = map[string]string{"opencode": "opencode-zen", "opencode-go": "opencode-go","openai": "openai", "anthropic": "anthropic", "google": "google", "deepseek": "deepseek",@@ -38,6 +44,12 @@ var openCodePresets = map[string]string{"groq": "groq", "openrouter": "openrouter", "togetherai": "together", "fireworks-ai": "fireworks","siliconflow-cn": "siliconflow", "nvidia": "nvidia", "aihubmix": "aihubmix", "302ai": "302ai","ollama-cloud": "ollama-cloud",+ "zhipuai": "zhipu", "zai": "zai", "alibaba": "qwen", "alibaba-cn": "qwen-cn",+ "minimax": "minimax", "modelscope": "modelscope", "kilo": "kilo", "cline-pass": "clinepass",+ "kimi-code-plan-cn": "kimi-code-cn", "kimi-code-plan-global": "kimi-code",+ "stepfun-step-plan": "stepfun-cn", "stepfun-ai-step-plan": "stepfun",+ "volcengine-coding-plan": "volcengine",+ "alibaba-token-plan-cn": "bailian-token-plan", "tencent-token-plan": "tencent-cloud",}func readOpenCodeAuth(path string) ([]AppImport, error) {diff --git a/internal/provider/import_opencode_test.go b/internal/provider/import_opencode_test.goindex 3a3d2aeff..e8c11939f 100644--- a/internal/provider/import_opencode_test.go+++ b/internal/provider/import_opencode_test.go@@ -1,9 +1,12 @@package providerimport (+ "fmt"+ "maps""os""path/filepath""runtime"+ "slices""testing""time")@@ -203,3 +206,59 @@ func TestImportOpenCodeAuthUnknown(t *testing.T) {t.Fatalf("unreadable folder: %+v", s)}}++// A vendor's key whose OpenCode id is a provider magpie has a preset for+// comes in on that preset: the id's host in models.dev's catalog is the+// preset's own address. Each entry here is api, so a key lands on the+// preset with no skip, the way openai's or deepseek's does.+func TestImportOpenCodeVendorPresets(t *testing.T) {+ home := openCodeHome(t)+ data := filepath.Join(home, "data")+ t.Setenv("XDG_DATA_HOME", data)+ want := map[string]string{+ "zhipuai": "zhipu",+ "zai": "zai",+ "alibaba": "qwen",+ "alibaba-cn": "qwen-cn",+ "minimax": "minimax",+ "modelscope": "modelscope",+ "kilo": "kilo",+ "cline-pass": "clinepass",+ "kimi-code-plan-cn": "kimi-code-cn",+ "kimi-code-plan-global": "kimi-code",+ "stepfun-step-plan": "stepfun-cn",+ "stepfun-ai-step-plan": "stepfun",+ "volcengine-coding-plan": "volcengine",+ "alibaba-token-plan-cn": "bailian-token-plan",+ "tencent-token-plan": "tencent-cloud",+ }+ entries := ""+ for id := range want {+ entries += fmt.Sprintf(",\n %q: {\"type\": \"api\", \"key\": \"sk-oc-%s\"}", id, id)+ }+ p := filepath.Join(data, "opencode", "auth.json")+ if err := os.MkdirAll(filepath.Dir(p), 0o700); err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(p, []byte("{"+entries[1:]+"\n}"), 0o600); err != nil {+ t.Fatal(err)+ }+ items := itemsOf(t, "opencode")+ if len(items) != len(want) {+ t.Fatalf("items: %d, want %d", len(items), len(want))+ }+ for _, id := range slices.Sorted(maps.Keys(want)) {+ it := items[id]+ if it.Skip != "" {+ t.Errorf("%s: skipped: %s", id, it.Skip)+ continue+ }+ pr := Preset(want[id])+ if pr == nil {+ t.Fatalf("preset %s: none", want[id])+ }+ if it.Provider.Preset != pr.ID || it.Provider.Name != pr.Name || it.Provider.Chat != pr.Chat || it.Provider.Key != "sk-oc-"+id {+ t.Errorf("%s: got %+v, want the %s preset", id, it.Provider, pr.ID)+ }+ }+}