providers: ClinePass is a preset — Cline's $9.99 plan for open coding models (GLM, Kimi, DeepSeek, MiMo, MiniMax, Qwen), served at the Cline API with a Cline key; the API lists its pay-as-you-go models and not the plan's, so a preset can say what its plan's ids start with (only those of the list are kept) and which they are (given when the list has none)

This commit is contained in:
yetone
2026-09-28 10:28:20 +08:00
parent b1fa0c5dfa
commit 01ffafadec
3 changed files with 85 additions and 2 deletions
+28
View File
@@ -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)
}
}
+42 -2
View File
@@ -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
+15
View File
@@ -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"},