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
"<n>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.
This commit is contained in:
yetone
2026-10-13 09:53:12 +08:00
parent 86b4760f55
commit f98026557e
3 changed files with 17 additions and 5 deletions
+5 -4
View File
@@ -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 ------------------------------------------------------------------
+11
View File
@@ -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.
+1 -1
View File
@@ -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",