diff --git a/packages/cline/README.md b/packages/cline/README.md index 8df5cac..147f724 100644 --- a/packages/cline/README.md +++ b/packages/cline/README.md @@ -64,6 +64,13 @@ recommended list, Cline's own default (`anthropic/claude-sonnet-5`) among it. Cline's `clineCloud` group is left out, as Cline's own clients leave it out unless they opt in. +Each model's context window is the cloud catalog's (`context_length`). Its +reply limit is left unsaid: the catalog's `max_completion_tokens` can be most +of the window, and an agent keeps that much free for the reply. The `cline-free/…` +and `cline-pass/…` models aren't in that catalog, so they say none, and magpie +takes the window models.dev gives the model after the prefix +(`cline-free/mimo-v2.6-flash` is `mimo-v2.6-flash`). + - The **free** group (`cline-free/…`, `stealth/…`) costs nothing — the names say "(free)". They are gated on the client surface a request claims; the plugin claims what it is, and the gate takes it. If Cline ever narrows that diff --git a/packages/cline/index.mjs b/packages/cline/index.mjs index 191993e..f373695 100644 --- a/packages/cline/index.mjs +++ b/packages/cline/index.mjs @@ -412,10 +412,20 @@ async function fetchRecommended() { return parseFeed(env && typeof env === "object" && "data" in env ? env.data : env) } +// tokens is a positive whole count of tokens, or undefined +function tokens(...vs) { + for (const v of vs) { + const n = typeof v === "string" ? Number(v) : v + if (Number.isFinite(n) && n > 0) return Math.floor(n) + } + return undefined +} + // fetchCloudModels is Cline's whole cloud catalog, which its clients load // beside the recommended feed (loadCloudModels reads /ai/cline/models): the -// usage-billed models the recommended feed doesn't name. Entries carry an id -// and a display name. +// usage-billed models the recommended feed doesn't name. Entries carry an id, +// a display name and, OpenRouter's way, the window (context_length, or its +// top provider's). async function fetchCloudModels() { let res try { @@ -436,7 +446,12 @@ async function fetchCloudModels() { if (!id) return [] const given = firstOf(e.display_name, e.displayName, e.name) const last = id.split("/").pop() - return [{ id, name: given && given !== id && given !== last ? given : prettify(id), free: false, pass: id.startsWith("cline-pass/") }] + const context = tokens(e.context_length, e.top_provider?.context_length, e.context) + // the reply limit is left out: OpenRouter's max_completion_tokens can + // be most of the window (kimi-k3: 943718 of 1048576), and an agent + // keeps that much of the window free for the reply, so it would + // compact a tenth of the way in + return [{ id, name: given && given !== id && given !== last ? given : prettify(id), free: false, pass: id.startsWith("cline-pass/"), ...(context && { context }) }] }) } @@ -444,7 +459,13 @@ async function fetchCloudModels() { // recommended feed is required, the cloud catalog is what it adds. async function fetchFeed() { const [rec, cloud] = await Promise.all([fetchRecommended(), fetchCloudModels().catch(() => [])]) - const ms = [...rec] + // a recommended model takes the catalog's window for it: the recommended + // feed gives none + const sizes = new Map(cloud.map((m) => [m.id, m])) + const ms = rec.map((m) => { + const c = sizes.get(m.id) + return c?.context ? { ...m, context: c.context } : m + }) const seen = new Set(ms.map((m) => m.id)) for (const m of cloud) { if (seen.has(m.id)) continue @@ -470,6 +491,9 @@ const runtimeModel = (m) => ({ headers: {}, options: {}, cost: { input: 0, output: 0, cache: { read: 0, write: 0 } }, + // 0 where Cline's catalog doesn't list the model (its cline-free/… and + // cline-pass/… ids): magpie then gives the window models.dev has for the + // model after the prefix limit: { context: m.context ?? 0, output: 0 }, capabilities: { temperature: true, diff --git a/packages/cline/index.test.mjs b/packages/cline/index.test.mjs index e1f98e5..3cc2937 100644 --- a/packages/cline/index.test.mjs +++ b/packages/cline/index.test.mjs @@ -699,6 +699,28 @@ test("the models hook merges the cloud catalog with the recommended feed", async expect(out["cline-free/mimo-v2.6-flash"].name).toBe("MiMo V2.6 Flash (free)") }) +test("the models hook gives each model the window Cline's catalog has for it, and no reply limit", async () => { + const { client: c } = client() + const hooks = await ClinePlugin({ client: c }) + serve([ + ["/ai/cline/recommended-models", () => Response.json({ recommended: [{ id: "anthropic/claude-sonnet-5.5" }], free: [{ id: "cline-free/mimo-v2.6-flash" }] })], + ["/ai/cline/models", () => Response.json({ data: [ + { id: "anthropic/claude-sonnet-5.5", context: 0, context_length: 1000000, top_provider: { context_length: 1000000, max_completion_tokens: 128000 } }, + { id: "inclusionai/ling-3.1-flash", context_length: "262144", top_provider: { max_completion_tokens: 32768 } }, + { id: "only/top", top_provider: { context_length: 200000 } }, + { id: "no/size", context_length: null }, + ] })], + ]) + const out = await hooks.provider.models({ models: {} }) + expect(out["anthropic/claude-sonnet-5.5"].limit).toEqual({ context: 1000000, output: 0 }) + expect(out["inclusionai/ling-3.1-flash"].limit).toEqual({ context: 262144, output: 0 }) + expect(out["only/top"].limit).toEqual({ context: 200000, output: 0 }) + // one the catalog doesn't list, or lists without a size, says none: magpie + // gives it models.dev's for the model after its prefix + expect(out["cline-free/mimo-v2.6-flash"].limit).toEqual({ context: 0, output: 0 }) + expect(out["no/size"].limit).toEqual({ context: 0, output: 0 }) +}) + test("prettify reads a model id as a name", () => { expect(prettify("anthropic/claude-sonnet-5.5")).toBe("Claude Sonnet 5.5") expect(prettify("openai/gpt-6-astra")).toBe("GPT 6 Astra") diff --git a/packages/cline/package.json b/packages/cline/package.json index 69fe5f3..021de41 100644 --- a/packages/cline/package.json +++ b/packages/cline/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-cline-auth", - "version": "0.1.1", + "version": "0.1.2", "description": "Cline (cline.bot) on your own account — usage billing, ClinePass and the free models — in OpenCode and magpie", "type": "module", "main": "./index.mjs",