From 01ffafadec6ef03bb6e5b09a8fe18b18e7f2c807 Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 28 Sep 2026 10:28:20 +0800 Subject: [PATCH] =?UTF-8?q?providers:=20ClinePass=20is=20a=20preset=20?= =?UTF-8?q?=E2=80=94=20Cline's=20$9.99=20plan=20for=20open=20coding=20mode?= =?UTF-8?q?ls=20(GLM,=20Kimi,=20DeepSeek,=20MiMo,=20MiniMax,=20Qwen),=20se?= =?UTF-8?q?rved=20at=20the=20Cline=20API=20with=20a=20Cline=20key;=20the?= =?UTF-8?q?=20API=20lists=20its=20pay-as-you-go=20models=20and=20not=20the?= =?UTF-8?q?=20plan's,=20so=20a=20preset=20can=20say=20what=20its=20plan's?= =?UTF-8?q?=20ids=20start=20with=20(only=20those=20of=20the=20list=20are?= =?UTF-8?q?=20kept)=20and=20which=20they=20are=20(given=20when=20the=20lis?= =?UTF-8?q?t=20has=20none)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/provider/clinepass_test.go | 28 ++++++++++++++++++ internal/provider/models.go | 44 +++++++++++++++++++++++++++-- internal/provider/presets.go | 15 ++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 internal/provider/clinepass_test.go diff --git a/internal/provider/clinepass_test.go b/internal/provider/clinepass_test.go new file mode 100644 index 000000000..99adfc849 --- /dev/null +++ b/internal/provider/clinepass_test.go @@ -0,0 +1,28 @@ +package provider + +import ( + "testing" + + "github.com/yetone/magpie/internal/catalog" +) + +func TestPlanModels(t *testing.T) { + p, err := FromPreset("clinepass") + if err != nil { + t.Fatal(err) + } + // the Cline API's list: its paid models, one of the plan's among them + got := p.planModels([]catalog.Model{{ID: "anthropic/claude-opus-5-5"}, {ID: "cline-pass/glm-5.3"}}) + if len(got) != 1 || got[0].ID != "cline-pass/glm-5.3" { + t.Fatalf("kept: %+v", got) + } + // none of the plan's listed: the plan's own + if got := p.planModels([]catalog.Model{{ID: "x/y"}}); len(got) != len(Preset("clinepass").Models) || got[0].ID != "cline-pass/glm-5.3" { + t.Fatalf("plan's: %+v", got) + } + // another provider's list is left as it is + o, _ := FromPreset("opencode-go") + if got := o.planModels([]catalog.Model{{ID: "a"}, {ID: "b"}}); len(got) != 2 { + t.Fatalf("other: %+v", got) + } +} diff --git a/internal/provider/models.go b/internal/provider/models.go index 79e0adddc..14793b7b5 100644 --- a/internal/provider/models.go +++ b/internal/provider/models.go @@ -51,6 +51,12 @@ func (p Provider) Available() []catalog.Model { if signedIn { return known } + if len(known) == 0 { + // a plan's models, before its list was fetched + if ms := p.planModels(nil); len(ms) > 0 { + return ms + } + } var out []catalog.Model for _, m := range known { if !strings.Contains(m.ID, "-exp") && !strings.Contains(m.ID, "preview") { @@ -99,7 +105,10 @@ func (p Provider) fetchOne(ctx context.Context) ([]catalog.Model, string, error) // asked where the user said, and nowhere else: the base URLs // list nothing, or the wrong thing ms, err := catalog.FetchURL(ctx, u, p.Key, p.Chat == "" && p.Responses == "", p.Headers) - return ms, u, err + if err != nil { + return nil, u, err + } + return p.planModels(ms), u, nil } var lastErr error for _, proto := range p.Speaks() { @@ -109,7 +118,7 @@ func (p Provider) fetchOne(ctx context.Context) ([]catalog.Model, string, error) if proto != Anthropic { base = p.fixV1(base, at) } - return ms, base, nil + return p.planModels(ms), base, nil } lastErr = err } @@ -119,6 +128,37 @@ func (p Provider) fetchOne(ctx context.Context) ([]catalog.Model, string, error) return nil, "", lastErr } +// planModels keeps a plan's own models of a vendor's list (PresetDef.Only), +// or gives the plan's when the list has none; any other provider's list is +// as it came. +func (p Provider) planModels(ms []catalog.Model) []catalog.Model { + pr := Preset(p.Preset) + if pr == nil || pr.Only == "" { + return ms + } + var out []catalog.Model + for _, m := range ms { + if strings.HasPrefix(m.ID, pr.Only) { + out = append(out, m) + } + } + if len(out) == 0 { + for _, id := range pr.Models { + out = append(out, catalog.Model{ID: id, Name: id}) + } + } + for i, m := range out { + // the vendor's window for its model, as models.dev has it + if m.Context == 0 { + out[i].Context = catalog.ContextOf(strings.TrimPrefix(m.ID, pr.Only)) + } + if m.Output == 0 { + out[i].Output = catalog.OutputOf(strings.TrimPrefix(m.ID, pr.Only)) + } + } + return out +} + // fixV1 adds the /v1 an OpenAI-style base URL was given without, when // the models were found only under it: base/models didn't answer and // base/v1/models did. The list is asked for at both, but a request goes diff --git a/internal/provider/presets.go b/internal/provider/presets.go index a6e634761..a3f81c0b8 100644 --- a/internal/provider/presets.go +++ b/internal/provider/presets.go @@ -33,6 +33,11 @@ type PresetDef struct { // HeaderHints name optional request headers the vendor documents, which // the editor offers to add; their values are the user's to fill in. HeaderHints []string `json:"headerHints,omitempty"` + // Only, for a plan behind a key that also buys much else, is what its + // models' ids start with: the rest of the vendor's list is left out. + // Models are the plan's, for when the list has none of them. + Only string `json:"only,omitempty"` + Models []string `json:"models,omitempty"` } // Region is one base-URL option of a preset that offers several. The first @@ -148,6 +153,16 @@ var presets = []PresetDef{ Chat: "https://opencode.ai/zen/go/v1", Responses: "https://opencode.ai/zen/go/v1", Anthropic: "https://opencode.ai/zen/go", Note: "open coding models, $10/month", Website: "https://opencode.ai/docs/go", KeysURL: "https://opencode.ai/auth"}, + // Cline's plan for open models, at the Cline API with a Cline key: the + // API lists only its paid models, not the plan's + {ID: "clinepass", Name: "ClinePass", Icon: "cline", Kind: KindRelay, + Chat: "https://api.cline.bot/api/v1", + Note: "open coding models, $9.99/month", + Website: "https://docs.cline.bot/getting-started/clinepass", KeysURL: "https://app.cline.bot", + Only: "cline-pass/", + Models: []string{"cline-pass/glm-5.3", "cline-pass/glm-5.3-flash", "cline-pass/kimi-k3", "cline-pass/deepseek-v4-pro", + "cline-pass/deepseek-v4.1-flash", "cline-pass/mimo-v2.5", "cline-pass/mimo-v2.5-pro", "cline-pass/minimax-m3", + "cline-pass/muse-spark-1.3-contributor", "cline-pass/qwen3.8-max", "cline-pass/qwen3.7-max", "cline-pass/qwen3.7-plus"}}, {ID: "opencode-zen", Name: "OpenCode Zen", Icon: "opencode", Kind: KindRelay, Catalog: "opencode", Chat: "https://opencode.ai/zen/v1", Responses: "https://opencode.ai/zen/v1", Anthropic: "https://opencode.ai/zen", Website: "https://opencode.ai/docs/zen", KeysURL: "https://opencode.ai/auth"},