Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
provider: a new partner provider starts at the region where the user is, Kimi Code's Global plan abroad (Kimi)
yetoneef155a5ca226
diff --git a/internal/provider/partners.go b/internal/provider/partners.goindex a3a470168..163e8a1f6 100644--- a/internal/provider/partners.go+++ b/internal/provider/partners.go@@ -1,6 +1,7 @@package providerimport (+ "cmp""context""encoding/json""errors"@@ -387,9 +388,15 @@ func validPartners(in []Partner) []Partner {p.Regions[i].Decide = ""}if p.Chat == "" && p.Responses == "" && p.Anthropic == "" {- // the first region is the default, as a built-in preset's is- r := p.Regions[0]+ // the first region is the default, as a built-in preset's is,+ // unless it is China's or Global's and the user is in the+ // other (homeRegion): its key page, site and catalog with it+ r := p.Regions[homeRegion(p.Regions, inMainlandChina())]p.Chat, p.Responses, p.Anthropic = r.Chat, r.Responses, r.Anthropic+ p.KeysURL, p.Website, p.Catalog = cmp.Or(r.KeysURL, p.KeysURL), cmp.Or(r.Website, p.Website), cmp.Or(r.Catalog, p.Catalog)+ if r.Website != "" {+ p.SiteHost = r.SiteHost+ }}p.Note = p.Notes["en"]if !strings.HasPrefix(p.Icon, "file:") || IconFile(strings.TrimPrefix(p.Icon, "file:")) == "" {@@ -400,6 +407,66 @@ func validPartners(in []Partner) []Partner {return out}+// homeRegion is the region a new provider of a partner starts at: the+// first, unless the first is China's or Global's and the other is listed+// too, when it is the one where the user is (inChina, from this+// computer's time zone). Unknown (0) keeps the first. Kimi Code lists+// China first, and a user abroad started at a plan that isn't theirs.+// Only a region named for China or Global counts: "Pay as you go ·+// China" is another plan, and "Auto" or "Direct" no place.+func homeRegion(rs []Region, inChina int) int {+ if len(rs) < 2 || inChina == 0 {+ return 0+ }+ first := placeOf(rs[0])+ if first == "" {+ return 0+ }+ want := "global"+ if inChina > 0 {+ want = "china"+ }+ if first == want {+ return 0+ }+ if i := slices.IndexFunc(rs, func(r Region) bool { return placeOf(r) == want }); i > 0 {+ return i+ }+ return 0+}++// placeOf says whether a region is China's ("china"), Global's ("global")+// or neither (""), by its id or its name.+func placeOf(r Region) string {+ id, name := strings.ToLower(r.ID), strings.ToLower(strings.TrimSpace(r.Name))+ switch {+ case id == "cn" || id == "china" || name == "china" || name == "china mainland" || name == "mainland china":+ return "china"+ case id == "global" || id == "intl" || name == "global" || name == "international":+ return "global"+ }+ return ""+}++// inMainlandChina says whether this computer's time zone is mainland+// China's: 1 it is, -1 it isn't, 0 unknown (no zone could be read). A+// var, so a test sets where it is.+var inMainlandChina = func() int { return chinaZone(cmp.Or(LocalZone(), systemZoneName())) }++// chinaZone reads a time zone's name: an IANA name, or Windows' own,+// whose China Standard Time is Beijing's (Hong Kong's too, which Windows+// doesn't tell apart). Hong Kong, Macau and Taipei have zones of their+// own, so they are abroad.+func chinaZone(name string) int {+ switch name {+ case "":+ return 0+ case "Asia/Shanghai", "Asia/Urumqi", "Asia/Chongqing", "Asia/Chungking", "Asia/Harbin", "Asia/Kashgar", "PRC", "China Standard Time":+ return 1+ }+ return -1+}+func checkPartner(p Partner) error {if !partnerID.MatchString(p.ID) {return errors.New("bad id")diff --git a/internal/provider/partners_region_test.go b/internal/provider/partners_region_test.gonew file mode 100644index 000000000..7d61777c0--- /dev/null+++ b/internal/provider/partners_region_test.go@@ -0,0 +1,117 @@+package provider++import (+ "context"+ "os"+ "sync/atomic"+ "testing"+)++// A new provider of a partner whose regions are China's and Global's+// starts at the one where the user is (Kimi, 10-27: "伙伴卡编辑器默认区为+// China,建议按用户区域分流"): Kimi Code's Global plan abroad, its China plan+// in mainland China, with that plan's key page, site and catalog. A zone+// that can't be read keeps the list's first, a partner whose regions are+// no places (APIKEY.FAN's Default and Direct) keeps its own endpoints, and+// a provider added before keeps its region when the user moves. The feed+// is usemagpie.ai/api/partners as served on 2026-10-27.+func TestPartnerStartsAtTheUsersRegion(t *testing.T) {+ feed, err := os.ReadFile("testdata/partners-2026-10-27.json")+ if err != nil {+ t.Fatal(err)+ }+ t.Setenv("XDG_CACHE_HOME", t.TempDir())+ was, wasIcon := inMainlandChina, fetchPartnerIcon+ t.Cleanup(func() { inMainlandChina, fetchPartnerIcon = was, wasIcon; resetPartners() })+ fetchPartnerIcon = func(context.Context, string) (string, error) { return "", os.ErrNotExist }+ var body atomic.Value+ body.Store(string(feed))+ t.Setenv("MAGPIE_PARTNERS", partnerFeedServer(t, &body).URL)++ at := func(where int) Provider {+ t.Helper()+ inMainlandChina = func() int { return where }+ resetPartners()+ fetchPartnersNow()+ p, err := FromPreset("kimi")+ if err != nil {+ t.Fatal(err)+ }+ return p+ }+ type want struct{ chat, anthropic, keys, site, siteHost, catalog string }+ cn := want{"https://api.kimi.com/coding/v1", "https://api.kimi.com/coding", "https://usemagpie.ai/go/kimi/keys/cn", "https://usemagpie.ai/go/kimi/site/cn", "www.kimi.com", "kimi-code-plan-cn"}+ global := want{"https://api.kimi.ai/coding/v1", "https://api.kimi.ai/coding", "https://usemagpie.ai/go/kimi/keys/global", "https://usemagpie.ai/go/kimi/site/global", "www.kimi.ai", "kimi-code-plan-global"}+ for _, c := range []struct {+ name string+ where int+ want want+ }{+ {"abroad", -1, global},+ {"in mainland China", 1, cn},+ {"zone unknown", 0, cn},+ } {+ p := at(c.where)+ pr := Preset("kimi")+ got := want{p.Chat, p.Anthropic, p.KeysURL, p.Website, pr.SiteHost, p.Catalog}+ if got != c.want {+ t.Errorf("%s: a new Kimi Code provider is at %+v, want %+v", c.name, got, c.want)+ }+ // the editor shows the plan picked by the preset's endpoints+ if r := pr.Regions[homeRegion(pr.Regions, c.where)]; r.Chat != pr.Chat {+ t.Errorf("%s: the preset's endpoints %q aren't its home region's %q", c.name, pr.Chat, r.Chat)+ }+ }++ // a provider added in China stays at China's plan once the user is+ // abroad and the list is fetched again+ added := normalize(at(1))+ at(-1)+ if added = normalize(added); added.Chat != cn.chat || added.KeysURL != cn.keys || added.Catalog != cn.catalog {+ t.Errorf("an added provider moved to %q (%s, %s)", added.Chat, added.KeysURL, added.Catalog)+ }++ // regions that are no places: its own endpoints wherever the user is+ for _, where := range []int{-1, 1} {+ at(where)+ if p, _ := FromPreset("apikeyfan"); p.Chat != "https://api.apikey.fan/v1" {+ t.Errorf("APIKEY.FAN (%d) starts at %q", where, p.Chat)+ }+ }+}++// Only a first region that is China's or Global's gives way, and only to+// the other: yylx's Auto first, a plan named "Pay as you go · China", or+// a list without the other place stay at the first.+func TestHomeRegion(t *testing.T) {+ kimi := []Region{{ID: "cn", Name: "China"}, {ID: "global", Name: "Global"}, {ID: "api-cn", Name: "Pay as you go · China"}, {ID: "api", Name: "Pay as you go · Global"}}+ yylx := []Region{{ID: "auto", Name: "Auto"}, {ID: "global", Name: "Global"}, {ID: "cn", Name: "China Mainland"}}+ globalFirst := []Region{{ID: "intl", Name: "International"}, {ID: "cn", Name: "China Mainland"}}+ plans := []Region{{ID: "api-cn", Name: "Pay as you go · China"}, {ID: "api", Name: "Pay as you go · Global"}}+ chinaOnly := []Region{{ID: "cn", Name: "China"}, {ID: "hk", Name: "Hong Kong"}}+ for _, c := range []struct {+ name string+ rs []Region+ inChina int+ want int+ }{+ {"kimi abroad", kimi, -1, 1},+ {"kimi in China", kimi, 1, 0},+ {"kimi unknown", kimi, 0, 0},+ {"yylx abroad", yylx, -1, 0},+ {"yylx in China", yylx, 1, 0},+ {"global first, in China", globalFirst, 1, 1},+ {"global first, abroad", globalFirst, -1, 0},+ {"plans only", plans, -1, 0},+ {"no Global", chinaOnly, -1, 0},+ } {+ if got := homeRegion(c.rs, c.inChina); got != c.want {+ t.Errorf("%s: homeRegion = %d, want %d", c.name, got, c.want)+ }+ }+ for zone, want := range map[string]int{"Asia/Shanghai": 1, "Asia/Urumqi": 1, "PRC": 1, "China Standard Time": 1, "Asia/Hong_Kong": -1, "Asia/Taipei": -1, "Asia/Singapore": -1, "America/New_York": -1, "UTC": -1, "": 0} {+ if got := chinaZone(zone); got != want {+ t.Errorf("chinaZone(%q) = %d, want %d", zone, got, want)+ }+ }+}diff --git a/internal/provider/testdata/partners-2026-10-27.json b/internal/provider/testdata/partners-2026-10-27.jsonnew file mode 100644index 000000000..79b2ecf43--- /dev/null+++ b/internal/provider/testdata/partners-2026-10-27.json@@ -0,0 +1 @@+{"partners":[{"id":"kimi","name":"Kimi Code","regionLabel":"Plan","regions":[{"id":"cn","name":"China","chat":"https://api.kimi.com/coding/v1","anthropic":"https://api.kimi.com/coding","catalog":"kimi-code-plan-cn","keysUrl":"https://usemagpie.ai/go/kimi/keys/cn","website":"https://usemagpie.ai/go/kimi/site/cn","siteHost":"www.kimi.com"},{"id":"global","name":"Global","chat":"https://api.kimi.ai/coding/v1","anthropic":"https://api.kimi.ai/coding","catalog":"kimi-code-plan-global","keysUrl":"https://usemagpie.ai/go/kimi/keys/global","website":"https://usemagpie.ai/go/kimi/site/global","siteHost":"www.kimi.ai"},{"id":"api-cn","name":"Pay as you go · China","chat":"https://api.moonshot.cn/v1","anthropic":"https://api.moonshot.cn/anthropic","catalog":"moonshotai","keysUrl":"https://usemagpie.ai/go/kimi/keys/api-cn","website":"https://usemagpie.ai/go/kimi/site/api-cn","siteHost":"platform.kimi.com"},{"id":"api","name":"Pay as you go · Global","chat":"https://api.moonshot.ai/v1","anthropic":"https://api.moonshot.ai/anthropic","catalog":"moonshotai","keysUrl":"https://usemagpie.ai/go/kimi/keys/api","website":"https://usemagpie.ai/go/kimi/site/api","siteHost":"platform.kimi.ai"}],"catalog":"kimi-code-plan-cn","keysUrl":"https://usemagpie.ai/go/kimi/keys","website":"https://usemagpie.ai/go/kimi/site","iconUrl":"https://usemagpie.ai/img/partner-kimi.png","notes":{"en":"One subscription, one K3 quota shared by every agent","zh":"一份订阅,所有 agent 共享 K3 额度","zh-TW":"一份訂閱,所有 agent 共享 K3 額度","ja":"1つのサブスクリプションで、すべての agent が K3 の枠を共有","de":"Ein Abo, ein K3-Kontingent für alle Agents"},"from":"2026-10-23T00:00:00+08:00","siteHost":"www.kimi.com"},{"id":"apikeyfan","name":"APIKEY.FAN","regions":[{"id":"main","name":"Default","chat":"https://api.apikey.fan/v1","responses":"https://api.apikey.fan/v1","anthropic":"https://api.apikey.fan"},{"id":"slb","name":"Direct","chat":"https://slb.apikey.fan/v1","responses":"https://slb.apikey.fan/v1","anthropic":"https://slb.apikey.fan"}],"chat":"https://api.apikey.fan/v1","responses":"https://api.apikey.fan/v1","anthropic":"https://api.apikey.fan","keysUrl":"https://usemagpie.ai/go/apikeyfan/keys","website":"https://usemagpie.ai/go/apikeyfan/site","iconUrl":"https://usemagpie.ai/img/partner-apikeyfan.png","notes":{"en":"Enterprise-grade AI API gateway to the world's leading models","zh":"企业级 AI 中转站,连接全球主流大模型","zh-TW":"企業級 AI 中轉站,連接全球主流大模型"},"langs":["zh","en"],"from":"2026-10-24T00:00:00+08:00","until":"2026-11-24T00:00:00+08:00","siteHost":"apikey.fan"},{"id":"wandapi","name":"WandAPI","chat":"https://api.wandapi.ai/v1","responses":"https://api.wandapi.ai/v1","anthropic":"https://api.wandapi.ai","keysUrl":"https://usemagpie.ai/go/wandapi/keys","website":"https://usemagpie.ai/go/wandapi/site","iconUrl":"https://usemagpie.ai/img/partner-wandapi.png","notes":{"en":"Enterprise-grade AI gateway, seamless access to global AI models","zh":"企业级 AI 网关,畅连全球 AI 大模型","zh-TW":"企業級 AI 閘道,暢連全球 AI 大模型"},"from":"2026-10-25T00:00:00+08:00","until":"2026-11-25T00:00:00+08:00","siteHost":"wandapi.ai"},{"id":"corecode","name":"CoreCode","anthropic":"https://corecode.live","keysUrl":"https://usemagpie.ai/go/corecode/keys","website":"https://usemagpie.ai/go/corecode/site","iconUrl":"https://usemagpie.ai/img/partner-corecode.png","notes":{"en":"Full-strength Claude, undiluted","zh":"纯血 Claude,一滴不掺","zh-TW":"純血 Claude,一滴不摻"},"from":"2026-10-26T00:00:00+08:00","until":"2026-11-26T00:00:00+08:00","siteHost":"corecode.live"},{"id":"sidrune","name":"Sidrune AI","chat":"https://sidrune.ai/v1","responses":"https://sidrune.ai/v1","anthropic":"https://sidrune.ai","keysUrl":"https://usemagpie.ai/go/sidrune/keys","website":"https://usemagpie.ai/go/sidrune/site","iconUrl":"https://usemagpie.ai/img/partner-sidrune.png","notes":{"en":"Stable Claude API Access with 85% off; $3 free credit upon registration","zh":"低至1.5折,稳定使用满血Claude;注册送$3,可开发票。","zh-TW":"低至1.5折,穩定使用滿血Claude;註冊送$3,可開發票。"},"langs":["zh","en"],"from":"2026-10-26T00:00:00+08:00","until":"2026-11-26T00:00:00+08:00","siteHost":"sidrune.ai"},{"id":"fastai","name":"FastAIToken","chat":"https://www.fastaitoken.com/v1","responses":"https://www.fastaitoken.com/v1","anthropic":"https://www.fastaitoken.com","keysUrl":"https://usemagpie.ai/go/fastai/keys","website":"https://usemagpie.ai/go/fastai/site","iconUrl":"https://usemagpie.ai/img/partner-fastai.png","notes":{"en":"One-stop access to Claude, GPT and DeepSeek, from 6% of list price","zh":"Claude / GPT / Deepseek 一站式接入方案,最低0.6折,支持对公","zh-TW":"Claude / GPT / Deepseek 一站式接入方案,最低0.6折,支援對公"},"from":"2026-10-26T00:00:00+08:00","until":"2026-11-26T00:00:00+08:00","siteHost":"www.fastaitoken.com"}]}\ No newline at end of filediff --git a/internal/provider/zone_other.go b/internal/provider/zone_other.gonew file mode 100644index 000000000..78bc471dd--- /dev/null+++ b/internal/provider/zone_other.go@@ -0,0 +1,6 @@+//go:build !windows++package provider++// systemZoneName is "" off Windows, where LocalZone reads the zone.+func systemZoneName() string { return "" }diff --git a/internal/provider/zone_windows.go b/internal/provider/zone_windows.gonew file mode 100644index 000000000..f09dba19e--- /dev/null+++ b/internal/provider/zone_windows.go@@ -0,0 +1,19 @@+package provider++import "golang.org/x/sys/windows/registry"++// systemZoneName is Windows' name of this computer's time zone ("China+// Standard Time"), which LocalZone can't read there; "" when the registry+// doesn't say.+func systemZoneName() string {+ k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control\TimeZoneInformation`, registry.QUERY_VALUE)+ if err != nil {+ return ""+ }+ defer k.Close()+ name, _, err := k.GetStringValue("TimeZoneKeyName")+ if err != nil {+ return ""+ }+ return name+}