diff --git a/packages/zcode/README.md b/packages/zcode/README.md index f6f3eb9..920f148 100644 --- a/packages/zcode/README.md +++ b/packages/zcode/README.md @@ -359,9 +359,13 @@ plans add `-Trial` entries, which are told as read): | GLM-5-Turbo | 200K | 64K | none, high | The Start Plan's config has all of these except GLM-5.3. An account -with no GLM Coding Plan also lists every model its gift plans serve under -the model's own name, as ZCode does (the Start Plan's GLM-5.3 bucket makes -GLM-5.3 a model), since all of its requests go to the gift anyway. +with no GLM Coding Plan lists the models its gift plans' balance names, +under each model's own name, as ZCode does (the Start Plan's GLM-5.3 +bucket makes GLM-5.3 a model), since all of its requests go to the gift +anyway. A config model the balance doesn't name is left out: an account +whose Start Plan holds only GLM-5.3-Flash lists GLM-5.3-Flash (and its +-Trial entry), not GLM-5.2 or GLM-5-Turbo. Only a balance that names no +model leaves the config's list standing. A gift plan's models appear again as `-Trial` entries, so a request can spend the gift's quota on purpose. A trial entry is listed diff --git a/packages/zcode/gift.test.mjs b/packages/zcode/gift.test.mjs index 3533d5a..b90b399 100644 --- a/packages/zcode/gift.test.mjs +++ b/packages/zcode/gift.test.mjs @@ -400,3 +400,37 @@ test("a refused-then-rested gift says why it is refused locally", async () => { expect(sent).toHaveLength(1) expect((await again.json()).error.message).toContain("not asked again for a minute") }) + +// young02036 (Discord, 11-05): two ZCode accounts, one with no GLM Coding +// Plan whose Start Plan holds only GLM-5.3-Flash, one subscribed whose +// gift is GLM-5.3-Flash-Trial. The gift-only account listed every model +// the Start Plan's config names (GLM-5.2, GLM-5-Turbo…), so magpie sent it +// models its balance has no bucket for, which the ZCode app never offers: +// the app lists a Start Plan account's models from its balance alone +// (resolveStartPlanBalanceAvailability). Now the gift-only account lists +// what its balance names, and a request for anything else is never routed +// to it. The config's list stands only when the balance names no model. +test("a gift-only account lists only the models its balance names (young02036)", async () => { + _internal.config({ + revision: 1, + config: { + providerConfigRules: { providerRules: [{ providerId: "account:zai-start-plan", builtinModelIds: ["GLM-5.3-Flash", "GLM-5.2", "GLM-5-Turbo"] }] }, + modelConfigRules: { modelRules: [{ modelMatch: "GLM-5\\.3-Flash", config: { properties: { contextWindow: 1_000_000 }, optionSpecs: { maxOutputTokens: { max: 128_000 }, reasoningLevel: { values: ["low", "high", "max"] } } } }] }, + }, + }) + try { + balance.plans = [{ plan_id: "zcode-v3-start-plan", user_plan_id: "s1", name: "ZCode Start Plan", status: "active", ends_at: now + 7 * 86400 }] + balance.balances = [{ plan_id: "zcode-v3-start-plan", user_plan_id: "s1", show_name: "GLM-5.3-Flash", capabilities: ["model:glm-5.3-flash"], total_units: 5_000_000, used_units: 0, remaining_units: 5_000_000 }] + const only = { type: "oauth", access: jwt, refresh: JSON.stringify({ ...state, key: undefined, plan: undefined }), expires: 0 } + const models = await (await hooks()).provider.models({ models: {} }, { auth: only }) + expect(Object.keys(models).sort()).toEqual(["GLM-5.3-Flash", "GLM-5.3-Flash-Trial"]) + expect(models["GLM-5.3-Flash"].limit.context).toBe(1_000_000) + // a balance that names no model leaves the config's list standing + _internal.routes.clear() + balance.balances = [] + const bare = await (await hooks()).provider.models({ models: {} }, { auth: only }) + expect(Object.keys(bare).sort()).toEqual(["GLM-5-Turbo", "GLM-5.2", "GLM-5.3-Flash"]) + } finally { + _internal.config(undefined) + } +}) diff --git a/packages/zcode/index.mjs b/packages/zcode/index.mjs index be19565..13cbbe3 100644 --- a/packages/zcode/index.mjs +++ b/packages/zcode/index.mjs @@ -2375,6 +2375,11 @@ export async function ZCodeAuthPlugin({ client, magpie } = {}, options = {}) { // the list it was told last, as the built-in keeps the one it fetched last const fell = !ms.length if (fell) ms = start ? START_MODELS : MODELS + // a gift-only account serves what its balance names, as ZCode + // offers it (resolveStartPlanBalanceAvailability): the Start + // Plan's config models the balance lacks would only be refused + // (young02036). A balance naming none leaves the config's list. + if (start && giftNames(gift).length) ms = ms.filter((m) => giftNames(gift).some((x) => x.toLowerCase() === m.id.toLowerCase())) const url = s.base + "/v1" const out = Object.fromEntries(ms.map((m) => [m.id, model(m, url)])) const details = [...ms, ...modelsOf(cfg, planID(START_BASE)), ...modelsOf(cfg, planID(ZAI_BASE)), ...MODELS] diff --git a/packages/zcode/package.json b/packages/zcode/package.json index 2b1ca88..c3cc4c0 100644 --- a/packages/zcode/package.json +++ b/packages/zcode/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-zcode-auth", - "version": "0.1.50", + "version": "0.1.51", "description": "OpenCode provider plugin: signs in to Z.ai's or BigModel's (智谱) GLM Coding Plan as ZCode does, including team seats and ZCode's Start Plan, and claims its gift plans daily", "type": "module", "main": "./opencode.mjs",