From f98026557e14463cbe364f46d595e53d05fe19e0 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 13 Oct 2026 09:53:12 +0800 Subject: [PATCH] grok 0.1.14: a window offered without a k (grok-4.7@131072) asks Grok for that model at that window (yetone/magpie#1679) labelOf writes a window no multiple of 1000 as its digits alone, so windowsOf offers grok-4.7@131072 beside grok-4.7@500k. modelOf read only "k", so that id went to Grok as an x-grok-model-override of its own ("grok-4.7@131072", a model Grok doesn't list) with no x-grok-context-window. It now reads the digits as the window itself, and a k as thousands, as the built-in's grokWindowed does after yetone/magpie#1679 (ggbdpq's patch). An id with no model before the @, or a window of 0, is no window, as the built-in reads it. Not tried against Grok: today every window xAI lists is a multiple of 1000, so no real model is offered without the k. Run: TMPDIR and HOME set to an empty scratch dir, bun test packages/grok: 41 pass, 0 fail. The new test FAILs with modelOf put back (expected { model: "grok-4.7", window: 131072 }, got the id as a model with window 0). node --check packages/grok/index.mjs, bun scripts/check.mjs grok and git diff --check are clean. --- packages/grok/index.mjs | 9 +++++---- packages/grok/models.test.mjs | 11 +++++++++++ packages/grok/package.json | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/grok/index.mjs b/packages/grok/index.mjs index 87db6ae..207bb0f 100644 --- a/packages/grok/index.mjs +++ b/packages/grok/index.mjs @@ -421,11 +421,12 @@ function windowsOf(d, efforts) { // grok-4.7@500k is grok-4.7 at 500000 tokens. The header is what the CLI // sends as x-grok-context-window. The proxy serves up to its largest // window either way and refuses past it; the header names the window the -// caller asked to compact against. +// caller asked to compact against. A window no multiple of 1000 is named +// by its digits alone (grok-4.7@131072), as labelOf writes it. function modelOf(id) { - const at = typeof id === "string" ? id.match(/^(.*)@(\d+)k$/) : null - if (!at) return { model: id, window: 0 } - return { model: at[1], window: Number(at[2]) * 1000 } + const at = typeof id === "string" ? id.match(/^(.+)@(\d+)(k?)$/) : null + if (!at || !(Number(at[2]) > 0)) return { model: id, window: 0 } + return { model: at[1], window: Number(at[2]) * (at[3] ? 1000 : 1) } } // ---- sign-in ------------------------------------------------------------------ diff --git a/packages/grok/models.test.mjs b/packages/grok/models.test.mjs index 1c1a426..5bb7649 100644 --- a/packages/grok/models.test.mjs +++ b/packages/grok/models.test.mjs @@ -49,6 +49,17 @@ test("an offered window asks Grok for that model and that many tokens", () => { expect(_internal.modelOf(undefined)).toEqual({ model: undefined, window: 0 }) }) +// labelOf writes a window no multiple of 1000 as its digits (magpie +// yetone/magpie#1679): modelOf reads that id back as the same window, not +// as a model of its own sent to Grok as it is. +test("a window offered without a k asks Grok for that model and that many tokens", () => { + const [, odd] = _internal.windowsOf({ id: "grok-4.7", context_window: 256000, context_windows: [256000, 131072] }, []) + expect(odd.id).toBe("grok-4.7@131072") + expect(_internal.modelOf(odd.id)).toEqual({ model: "grok-4.7", window: 131072 }) + expect(_internal.modelOf("grok-4.7@0")).toEqual({ model: "grok-4.7@0", window: 0 }) + expect(_internal.modelOf("@500k")).toEqual({ model: "@500k", window: 0 }) +}) + // A token Grok refuses before its time says the sign-in is gone, as one // past its time does, so magpie's move takes the account along untried; // "Grok models: 401 …" stopped every Grok account's move. diff --git a/packages/grok/package.json b/packages/grok/package.json index 108951c..86a4481 100644 --- a/packages/grok/package.json +++ b/packages/grok/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-grok-auth", - "version": "0.1.13", + "version": "0.1.14", "description": "OpenCode provider plugin: Grok (SuperGrok / X Premium+) through the Grok Build CLI's sign-in", "type": "module", "main": "./index.mjs",