magpie's /v1/audio/transcriptions form (OpenAI's) is sent on to
api.x.ai/v1/stt signed as the CLI signs: the audio byte for byte, language
passed on, OpenAI's model left out (xAI answers 404 to any id but its own),
json/text/verbose_json answered in OpenAI's shapes, srt/vtt and
translations refused. cli-chat-proxy has no stt route (404), api.x.ai takes
the Grok Build token.
Images: an input_image in a Responses request already goes through
unchanged and the models say image input; a real request with a 64x64 PNG
answered "Red" through the plugin's own fetch. A 8x8 one is Grok's own 400
(minimum 512 pixels).
Run: bun test in packages/grok (112 pass), mote. Broke by hand: with the
transcription branch out of fetch, 4 of the 5 new tests go red. Real
account: the plugin's fetch with ~/.grok's sign-in transcribed a say(1)
wav ("Hello world, this is a test.") as verbose_json and described a
red PNG. Not tried: through a built magpie gateway.
A Responses stream from Grok that dies before its first byte (the
connection reset, nothing sent yet) is asked again, up to three times,
before the answer is returned. A retry's own answer is noted, so a 429
or 401 on a retry comes back as itself, not folded into a 200.
Once a byte has arrived, response.created and reasoning included, the
stream is passed on at once, one upstream chunk per pull, and cancelling
it cancels the upstream read. A later cut is not asked again and nothing
is written in its place: the stream ends, and magpie 0.1.3298 or newer
(yetone/magpie 29bfd5dc8) closes it as a whole response.failed with
created_at and sequence_number. The frames 0.2.6's first version wrote
had no sequence_number, and Grok Build failed the turn on them. An
upstream response.failed, error or response.incomplete is passed on
unchanged, and an end with no bytes is not asked again.
Run on mote (macOS 27), at 463afb79, each in a temp HOME:
- packages/grok `bun test`: 107 pass, 0 fail.
- `bun scripts/check.mjs grok`: ok.
- Repo-root `bun test` with HOME=$(mktemp -d): 6878 pass, 20 skip,
0 fail. A first run with HOME under /tmp had 21 reds in devin, zcode
and sap-aicore. Those tests refuse a HOME outside $TMPDIR, and
plugins main ecab8396 had the same reds under that HOME.
- Broken by hand, cut-retry.test.mjs goes red:
- STREAM_TRIES=1: 3 fail;
- the retry's note() removed: the 429 test fails;
- cancel() not passed upstream: the cancel test fails;
- "aborted" counted as a cut: the abort test fails;
- a later cut erroring the stream instead of ending it: 2 fail.
Asking again after a zero-byte clean end is the one break no test
catches.
- Real chain: Grok Build 1.0.67 and 1.0.77 (x.ai's own build, the
reporter's version), then magpie eef99e4bb (`magpie serve`, sandbox
HOME), then this plugin (BASE pointed at a fake), then a fake Grok
upstream:
- ok: "pong".
- Cut before the first byte, then ok: "pong", with the retry inside
the plugin.
- Cut, then 429: magpie logs a 429 from Grok, and Grok Build retries
on "rate limited".
- Always cut before a byte: an empty 200, which magpie reports as a
retryable 502. Grok Build retries it as server_error.
- Cut after response.created, and cut after text: magpie's
response.failed ("the reply ended before it was complete"). Grok
Build reads it and retries it as server_error. No "missing field"
in either version.
- Upstream response.failed: one call, and Grok Build shows the
vendor's own message.
Not tried: a live Grok stream cut by the real vendor.
zane668 got 401 {"error":"Authentication required"} a few times a day on
tokens not near their end. grok models left the same token, so the
plugin said "couldn't renew the sign-in ... add the account in magpie
again", yet the same token answered 2-5 minutes later.
What tells the two apart: cli-chat-proxy answers a token it doesn't take
at once with "Invalid or expired credentials (auth_kind=..., upstream=
Unauthenticated|PermissionDenied, reason=...)" (curl'd 11-07 with made-up
tokens, signed and unsigned, on /models, /responses, /chat/completions,
/billing: each in under 1.5s). "Authentication required" after 78-114s
is not that verdict.
Now, after a 401 on a request, model list or usage read whose renewal
leaves the token as it was:
- the body is not "Invalid or expired credentials", the token is not
past its end, and grok models didn't exit with an error (it ran, or
was still running): a 503 with Retry-After: 60, X-Magpie-Sign-In: kept,
code auth_refused_transient, saying what Grok said, how long it took
to answer, and that no new sign-in is needed. magpie's gateway reads a
503 as before (failOther: a short backoff rest, the next account
asked), so routing is unchanged; only the advice and status change. A
model list or usage read gives the same words, with no sign-in mark.
- otherwise as before: "couldn't renew the sign-in", sign in again.
- the wait on Grok Build's renewal after a 401 is capped at 15s; the run
goes on and the next asker takes what it gave. The message names
grok models' own run time when it is 1s or more.
Where the 78-114s went: the plugin's own part is grok models, capped at
30s by execFile before and at 15s now. grok models "ran" (exit 0) in the
report, so it took under 30s; the rest, at least ~50s, was Grok's answer
to the request. zane668 saw "no first token in 120s" and ECONNRESET on
other vendors in the same windows, so the wait is upstream/network and
the plugin doesn't bound it. The message now says both times, so the
next report shows the split. Not done: the report's suggestion to resend
after a few seconds; the refusal lasted minutes and each try waited
over a minute, so handing over at once is faster.
Left ambiguous: a token xAI revoked but answered with words other than
"Invalid or expired credentials" would now read as passing and keep
being retried with short rests; a revoked real token was not available
to see its words.
Run at this tree:
- packages/grok bun test on mote: 96 pass, 0 fail.
- repo bun test (HOME=$(mktemp -d)) on the Linux VM (wsl-run,
magpie-desktop): 6571 pass, 19 skip, 0 fail. Not on mote: its suite
lock had a 3h GUI run and four Go suites queued.
- bun scripts/check.mjs grok on mote and Linux: ok.
- Real: the plugin against the real cli-chat-proxy with a made-up token
and a fake grok models leaving it: 401 sign_in_unrenewed, Grok's
"Invalid or expired credentials (... upstream=PermissionDenied ...)"
quoted, after 1s.
Broken by hand (renew.test.mjs, 15 tests): old index.mjs fails the 503,
bounded-wait, model-list and usage tests (4); passing() without the
TURNED_AWAY check fails 3 (two old tests and the new verdict test); the
CLI's failure ignored fails the exit-1 test; no 15s bound fails the
bounded-wait test (2013ms); models and usage not passing Grok's words
each fail their test.
Not tried: a real "Authentication required" 401 (it can't be called up),
a revoked real token, a real Grok Build slower than 15s.
Reported-by: zane668
nbczw8750 (#657): trae 0.2.26 on OpenCode 2.2.5 fails with "Plugin
must export a default definition with an id and an effect or setup
function. (cause: SchemaError(Missing key at ["default"]))". 2.x
imports a package's exports["."] (a plugin dir and an npm install
alike) and has no V1 path at all, so every package here that serves
models failed the same way, not only trae.
Every one of the 32 model packages now has:
- opencode2.mjs, exports["."]: a copy of scripts/opencode2.mjs, an
adapter that runs the package's V1 plugins inside 2.x's promise
API. Config providers become 2.x providers (package pinned so the
aisdk sdk hook runs), V1 auth methods become integration methods
(oauth auto/code with forms; api without authorize as a key method),
V1 credentials are kept in metadata.v1, the loader's baseURL,
apiKey, headers and fetch are applied through the sdk hook, an
auth.set renewal is stored per credential, and credential.switched
/updated reload the account's own model list.
- opencode.mjs, main: re-exports the V1 plugin functions only.
OpenCode 1.x and magpie's host.js take main. On 1.x, trae 0.2.26's
main exported a non-plugin (_internal) and 1.19.5 refused it ("Plugin
export is not a function"); the new main fixes that too.
- both files in "files"; patch version bumped. devin already had 2.x
and is unchanged.
scripts/check.mjs fails a model package whose 2.x entry has no default
{id, setup}, whose opencode2.mjs differs from the canonical one, whose
entry is missing from files, or whose main exports a non-plugin.
Run at this head (mote):
- HOME=$(mktemp -d) bun test, as CI runs it: 4900 pass, 0 fail
(4914 tests, 374 files). A first run set globalThis.fetch for the
whole process from opencode2.test and failed 528 tests in other
packages; the block is now set and put back around that file's tests.
- bun scripts/check.mjs: every package passes. With the network
blocked cloudflare-workers-ai fails on its fetched catalog, the same
on origin/main.
- Real OpenCode 2.2.5 (npm opencode-ai), sandbox HOME, packed trae
0.2.27: loads with no error; /api/integration lists trae-cn "Trae CN"
and trae-global "Trae Global" with their browser sign-ins; `auth
login` starts the trae.cn authorization and waits (cancelled there);
with a fake credential POSTed to /api/credential, `opencode models`
lists trae-cn's six models.
- Real 2.2.5 with a fake V1 key plugin through the same adapter
against a local fake server: `auth login` with a key, `models`,
`opencode run` reached /real/v1/chat/completions with the loader's
"Bearer loader-sk-fake" and header, and printed the fake's reply;
with @ai-sdk/anthropic it reached /real/v1/messages with x-api-key
from the loader. This run found the key method missing after 2.x's
second integration transform (a once-only flag outside the
transform); fixed, and opencode2.test checks a rebuild.
- Real OpenCode 1.19.5, sandbox HOME, trae 0.2.27: `opencode models`
lists trae-cn and trae-global models; 0.2.26 failed there.
Broken by hand (scratch copy, bun test scripts/ and check.mjs):
- trae's exports back to "./index.mjs": the trae 2.x test fails
(default.id undefined), check fails trae with "OpenCode 2.x:
./index.mjs has no default {id, setup} (plugins#657)".
- zed's opencode2.mjs changed: the copies test fails, check fails zed
"differs from scripts/opencode2.mjs".
- the key flag back outside the transform: the 1.x plugin test fails
on the rebuilt sign-ins (key missing).
Not tried: a real sign-in with a real account on 2.x; Windows (the
reporter's OS); chat.headers, chat.params, usage and tool hooks, which
the adapter doesn't carry to 2.x; the tools/pages packages (calc,
goanyapi, layerfs, search1api, aelios, agent-console, chat,
fingerprint, nowledge-mem, kimi-desktop), which still load only on 1.x.
Codex asks an OpenAI-named provider for output token replay with
include ["reasoning.encrypted_content", "output.encrypted_content"]
(codex-rs/core/src/client.rs). Grok answers 400 'Argument not
supported: "output.encrypted_content" in "include" field'. rewrite()
now drops that one value (and include when nothing is left), and its
pre-filter also opens a body that names it, so an include-only body is
no longer passed through untouched. reasoning.encrypted_content and the
tool-output values xAI's docs list stay; store is not touched (Grok
takes it).
Tests: packages/grok/include.test.mjs, from the reporter's two bodies
and Codex's include. Red on the old index.mjs (4 of 5; the 5th checks
that accepted values stay). Broken by hand: without the pre-filter
change the include-only case is red.
Run on mote: HOME=$(mktemp -d) bun test (3782 pass, 0 fail) and
bun scripts/check.mjs (exit 0).
Not tried: a real Grok account; no Codex turn sent through Grok.
Sealed copies an OpenAI model wrote earlier in a thread (encrypted_content
on a message) are not stripped here; magpie's forVendor takes those out
before a non-OpenAI provider.
Grok Build 1.0.67 sends `x-grok-doom-loop-check: 1024` and
`x-grok-exact-repetition-check: 64` on every /v1/responses request
(seen in a mitm capture of the real CLI; the strings are in its binary
next to "server reported doom-loop triggers for this response"). The
plugin sent neither. Without them cli-chat-proxy lets a reply that
repeats itself run on: it cut "* " repeated after ~4,265 output tokens,
and a looser loop runs to max_output_tokens (128000 from Pi). That is
the "repeats until max output, ends in Internal error during token
generation" of #3594, seen on Pi -> magpie -> Grok but not in Grok
Build. The fetch now sets both on a Responses request unless the
caller set them already.
Ruled out while diffing the CLI's request against magpie's: the system
prompt. `instructions`, a system message and a developer message in
`input` all reach the model (same input_tokens, 1266 vs 1249 without,
same reply), so magpie's `instructions` is not lost.
Run:
- bun test in packages/grok on mote: 85 pass 0 fail.
- bun run check (whole repo) on mote: exit 0.
- Broken by hand: loop-check.test.mjs against index.mjs at HEAD:
2 of 3 fail (the headers are missing); with the change 3 pass.
- Real account (owner's SuperGrok, sandbox magpie on origin/main with
this plugin from disk, requests through mitm): the same "* " x3000
prompt over /v1/responses, /v1/chat/completions and /v1/messages each
carried both headers upstream and was stopped after ~1,020 deltas
(~1K tokens) with "Internal error during token generation", against
~4,265 tokens without the headers (direct curl, earlier).
Not tried: the CLI's client-side doom-loop recovery (it resamples a
confident tool-call loop with a reminder). The proxy's
response.doom_loop_check event (a soft loop it reports, not stops)
goes through as it came and nothing acts on it yet.
Grok can reject a token hours before its expires_at. A 401 used to be
passed on (requests) or read as "Grok's sign-in has expired; run `grok
login`" (models), with no renewal tried: token(home, expired) was never
called with expired set. And an auth.json caught while the CLI rewrote
it read as "not signed in", which the refresh hook marks as an expired
sign-in.
- token(home, rejected): rejected is the token Grok turned away. A token
on disk other than that one was renewed already and is used; else the
CLI renews it (`grok models` in the home). A run that leaves the same
token throws "Grok Build couldn't renew the sign-in (grok models
<exited N | ran and left the same token>: <its last line>)", never
"not signed in" or "expired".
- What it says helps: for Grok Build's own home (current()), open Grok
Build and send it a message; for a home of the plugin's (a second
device-code account, a CPA import) add the account in magpie again.
No "run `grok login`" where that signs in a different home. A home of
the plugin's with no sign-in left says to add the account again too.
- Requests: a 401 renews once and resends the same body with the new
token. Unrenewable, the 401 carries that message plus Grok's own words
(JSON error), still X-Magpie-Sign-In: kept. Models: a 401 renews once
and lists again; a renewed token also refused says so. Usage: same
retry once. auth.refresh's unrenewed case uses the same message.
- look(): an empty or non-JSON auth.json is torn. read() tries it again
for ~0.5s (6 x 100ms), then keeps the last sign-in read whole there,
as the CLI does ("auth reload: auth.json unreadable, keeping previous
credentials", in its binary's strings). Torn with nothing read before
is an error saying it couldn't be read, with no signIn mark. No
auth.json.lock is taken: it is the CLI's flock around its renewal,
Node can't take a flock, and holding it could only delay a renewal.
Changed tests: signin.test's 401 now has no CLI and expects the no-CLI
message beside Grok's body; usage.test and models.test the same; a
private home's "not signed in" says to add the account again.
Run (worktree at 59990e1, PATH without ~/.grok/bin and ~/.local/bin so
no real grok is found; TMPDIR and HOME in a fresh temp dir):
- packages/grok: bun test, 82 pass 0 fail
- repo: bun test, 2166 pass 0 fail across 189 files; bun scripts/check.mjs ok
Broken by hand (renew.test.mjs, 9 tests):
- old index.mjs: all 9 red
- TORN_TRIES = 1: the mid-write test red
- no last-good fallback: the stays-torn test red
- unchanged token not caught after renewal: the three couldn't-renew
tests (request private home, request shared home, models) red
- shared() always false: the shared-home message test red
Not tried: the real Grok Build CLI or a real Grok account (the fake CLI is
/bin/sh, fetch is a stand-in); a real 401 from Grok before expires_at; a
CLI writing auth.json in place while it is read (the torn file is
written by the test); a body that is a stream (not resent, as before:
only a string or no body is retried); Windows. magpie's mover min for
grok is not raised here.
An option on the grok provider, "Native X search" (auth.options key
x_search, off by default), read through magpie.option on each fetch.
When on, a Responses request whose tool_choice is auto, or absent with
tools declared, is offered Grok's native {"type":"x_search"}. none,
required, a named tool, allowed_tools and an x_search choice add nothing;
an x_search already declared keeps its filters and isn't duplicated; a
request with neither tools nor a tool_choice is left alone.
Reviewed at 99e602006 (vectorisvector). Run at that head:
- HOME and TMPDIR in a scratch dir, bun test: 2040 pass, 0 fail;
bun scripts/check.mjs: ok; PR CI run 39532960081 green (attempt 1 was
only awaiting approval)
- broken by hand, each red: on by default 4 fail, option ignored 2, every
path 1, tool_choice ignored 5, duplicate x_search 1, inject after
tools filtered 1, both no-tools guards removed 1, non-array tools 1,
wrong provider id 1, no injection 10
- magpie gateway at ba319a758 with this plugin loaded (BASE pointed at a
fake upstream), option off/on/off: Chat, Anthropic and Gemini (whole and
streamed) with a function get x_search; their tools-off "none" and
Chat/Anthropic required, named and no-tools requests don't; Responses
auto (whole and streamed) gets it, none doesn't, an existing x_search
is kept once; no upstream body names magpie; an x_search_call item in
the reply doesn't reach Chat/Anthropic/Gemini clients
- one gap on magpie's side: an allowed_tools choice is dropped by the
gateway before the plugin can read it, so it gets x_search; filed as
yetone/magpie#3153
Not tried: a real Grok account.
magpie now hands a request that turned tools off with none declared
(Chat's tool_choice "none", Anthropic's {"type":"none"}, Gemini's
functionCallingConfig NONE) to a Responses plugin as tool_choice "none"
with no tools, so a plugin that adds a server-side tool (x_search, #263)
can tell it from no choice. Grok's backend refuses a tool_choice with no
tools ("A tool_choice was set on the request but no tools were
specified", yetone/magpie#378), which magpie's grokBody used to leave out
for the plugin. rewrite now leaves out any tool_choice with no tools, or
none left after the dropped types, as the built-in's grokBody does.
What was run:
- TMPDIR=<scratch> HOME=<scratch>/home bun test: 2018 pass, 0 fail.
(HOME outside os.tmpdir() trips zcode's isolated-home guard: 19 fail,
2 errors, all that guard; not this change.)
- bun scripts/check.mjs: passes.
- tool-choice.test.mjs against origin/main's index.mjs: 1 pass, 1 fail
(the lone-tool_choice case), green with this change.
Not tried against Grok's live backend.
"magpie里的grok 登录验证 在mac下 似乎每次都会弹两次验证, 在浏览器窗口里":
`grok login --device-auth` (Grok Build 1.0.50, the webbrowser crate)
opens the device page itself, and magpie opened the same URL again.
Reproduced in a sandbox HOME/GROK_HOME on macOS: grok's own device-code
tab appeared in Chrome with magpie not involved, with and without
SSH_CONNECTION set. What decides grok's own open, from the binary's
strings and webbrowser 1.2.4's source:
- macOS: NSWorkspace, $BROWSER never read (the macOS binary has no
"BROWSER" string);
- Windows: ShellExecuteW, no $BROWSER either;
- Linux and the rest: $BROWSER, else xdg-open, skipped with no display.
So the sign-in now says `opened: true` on darwin and win32 (magpie then
opens nothing; magpie >= the commit that raises the grok mover min reads
it), and elsewhere gives grok BROWSER=true, a no-op, so the opener stays
the only one to open the page. OpenCode ignores the extra field.
Tests: login.test.mjs runs the sign-in as darwin/win32 (opened, $BROWSER
untouched) and linux/freebsd (not opened, BROWSER=true reaches grok).
Both fail on 0.1.16's index.mjs (10 pass, 2 fail).
Run: HOME=<scratch> bun test packages/grok: 49 pass, 0 fail;
bun scripts/check.mjs: exit 0.
llllleo9 couldn't add Grok: grok login --device-auth exited 0, and the
sign-in failed with "grok login finished without an account".
Grok Build 1.0.62 was run in a sandbox HOME. The stand-in auth.x.ai sat
behind an HTTPS_PROXY MITM, with its CA passed through
GROK_EXTRA_CA_BUNDLE, and sandbox-exec denied opening a browser. The CLI
takes email and user_id from the id_token's claims alone. With no email
claim (an xAI account signed in through X), it writes "email": null and
still prints "✓ Signed in". When Grok Build's own home is already signed
in, the plugin signs in beside it and demanded an email, so that sign-in
failed.
- An account is now told apart by its email, else its user_id, else the
token's sub. saved() and the refresh path's remember() use the same
account id.
- GROK_AUTH_PATH is now left out of the CLI's run. With it set, 1.0.62
keeps the sign-in at that file, and the home the plugin reads stays
empty (seen in the same sandbox). The login always runs with envFor(home)
now, not process.env.
- A login that finishes with nothing readable now says what grok said,
which file it read and what was there (no file, not JSON, no token,
or no account). It also points to "Use Grok Build's current sign-in".
Run:
- TMPDIR and HOME set to a scratch dir, bun test packages/grok: 47 pass,
0 fail. The six new login tests FAIL with 0.1.15's index.mjs.
- bun scripts/check.mjs grok: ✓.
- node --check and git diff --check are clean.
- The plugin was run against the real grok 1.0.62 and the stand-in x.ai,
with the CLI home already signed in:
- id_token without email: 0.1.16 returns success with accountId
"user-1". 0.1.15 returns "grok login finished without an account",
the reporter's message.
- GROK_AUTH_PATH set: 0.1.16 returns success, 0.1.15 fails the same way.
- login.test's "a login's link is still handed on" timed out at 5s in 2 of
10 runs alone, on 0.1.15's code too. That is #160, which another session
has taken; the data point was added there.
Not tried with a real xAI account: whether xAI's token for llllleo9's
account lacks the email claim, and whether their Grok Build was already
signed in.
In magpie's Docker image there is no curl to run xAI's installer, and a
grok binary dropped on PATH outside a .grok folder isn't taken (isGrokBuild
keeps another program named grok out). GROK_BIN_DIR already took one as it
is; the error now says so, and the README says where the CLI is looked for.
Run: TMPDIR=<scratch> HOME=<scratch home> bun test in packages/grok (41
pass, 0 fail); bun scripts/check.mjs grok (✓). With index.mjs put back to
0.1.14, import.test's "no Grok Build … is refused first" fails on the new
GROK_BIN_DIR assertion. Not tried in a real container from this commit;
magpie's own fix (installing Grok Build before `magpie plugin login grok`)
is in yetone/magpie.
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.
* grok 0.1.13: import a CLIProxyAPI (CPA) xAI account from its file
CPA (CLIProxyAPI) keeps each of its accounts in ~/.cli-proxy-api as a flat
JSON file: {type: "xai", auth_kind: "oauth", access_token, refresh_token,
expired, last_refresh, sub, email, disabled, …}. Its xAI accounts sign in
with the same OAuth client Grok Build does, so such an account is a sign-in
Grok Build can hold — but the plugin could only take the CLI's own sign-in
or make a new one, so an account that lives in CPA could not be used here.
The third sign-in method takes the path to one of those files, reads it and
writes Grok Build's own shape (key, auth_mode: "oidc", create_time,
user_id, email, refresh_token, expires_at, oidc_issuer, oidc_client_id)
into a home of the plugin's own, as a device-code sign-in does. The
imported file is only read, and only the fields above are carried over:
base_url is not honored and expires_in is not turned into a lifetime
measured from the import.
A file is refused, before any home is made, when it is not an enabled
(type xai, auth_kind oauth, not disabled) xAI account with tokens, identity
and timestamps, or when the token's own iss/aud are not the Grok Build
xAI ones. The refresh token rotates and both clients would spend it, so the
prompt and the README say to stop using the account in CPA first. Nothing
here refreshes a live token or touches CPA.
bun test: 39 pass on the grok package (4 new in import.test.mjs: the
translated home, the refusals, no Grok Build, and a home that can't be
made). bun scripts/check.mjs grok and node --check pass.
* grok: string timestamps, and import.test.mjs off POSIX
`Date.parse` coerces, so a `last_refresh` or `expired` that was a list or an
object read as a date: the file must say a string before it is parsed.
The test's fake CLI is named for the platform (`grok.exe` on Windows), PATH
joins with the platform delimiter, and the 0600 file is only checked where
POSIX gives it. The mkdir that fails is what the last test covers, not the
cleanup after a write that fails, and it now says so.
* grok: the import's placeholder names the file CPA writes, xai-<email>.json (review of #92)
CLIProxyAPI's xAI sign-in saves each account as xai-<email>.json
(internal/auth/xai/token.go CredentialFileName), not cpa_*.json.
Text only; import.test.mjs still 5 pass.
---------
Co-authored-by: yetone <yetoneful@gmail.com>
* grok 0.1.12: a model Grok lists at two windows is offered at each
context_window stays the plain id, so a saved grok-4.7 keeps the default
256k window. Each other size in context_windows is listed beside it
(grok-4.7@500k) with that window. A request for it sends the plain model
and x-grok-context-window: 500000, which is the window a client such as
Claude Code compacts against. The proxy serves up to its largest window
either way and refuses past it.
* grok: a window model's api.id keeps its @size, so x-grok-context-window is sent
The models hook gave grok-4.7@500k the api.id grok-4.7. magpie
(internal/provider/plugins.go, modelAPIID + withModel) and OpenCode's AI
SDK both put api.id in the request body, so the plugin's fetch only ever
saw grok-4.7 and never sent x-grok-context-window. api.id is now the
offered id; fetch strips the window (modelOf) before Grok sees the body.
Run: HOME=$(mktemp -d) bun test packages/grok (35 pass);
bun scripts/check.mjs grok. The new round-trip test (models hook ->
api.id -> fetch) is red on f4872fb and red again with the body rewrite
removed by hand. Real use against the owner's Grok account (copied
home): /v1/models lists 4 models at 256k and 500k; grok-4.7 and
grok-4.7@500k each answered 200, the latter with x-grok-context-window:
500000 and model grok-4.7 in the body.
---------
Co-authored-by: chenguoqing <chenguoqing@kemai.cn>
Co-authored-by: yetone <yetoneful@gmail.com>
Releases #61 (13e813d), which merged without a version bump: Grok's
Responses backend turned these requests away with 422 unknown item type
"agent_message". Sealed tasks are still sent as they came.
Verified at #61's head merged onto e1efc3d: bun test packages/grok 31 pass,
the whole repo 1007 pass, bun scripts/check.mjs ok. Without the change in
index.mjs, agent-message.test.mjs fails 2 of 4. Sent through
loader().fetch to a local fake of cli-chat-proxy.grok.com: main gives 422,
this version gives 200.
xiaocui12: Codex on Grok failed every turn with "[invalid_client_tool_schema]
mcp__codex_app__automation_update: tool parameter root must be an object
type (root schema is an anyOf/oneOf union with a non-object branch)".
Codex desktop's codex_app automation_update has an anyOf at its
parameters' root (ChatGPT.app 26.930 builds it with zod 4's toJSONSchema),
and its create and update branches are unions themselves.
rewrite() now folds a function's parameters to an object root as magpie's
built-in provider.ObjectRoot does, nested union branches folded first so
their fields (name, prompt, rrule, kind...) are kept and only "mode" is
required. Before, the plugin sent the union as it came; magpie's grokBody
folded it for requests through magpie, but not for OpenCode's own.
Verified: the real schema (testdata, rebuilt with zod 4.1.8) sent to the
real Grok subscription raw gets 400 with the reporter's exact message;
folded it gets 200 and a correct create call
({"mode":"create","kind":"heartbeat",...,"rrule":"FREQ=MINUTELY;INTERVAL=30"}).
schema.test.mjs: 2 of its 3 tests fail on 0.1.9 and pass now.
HOME=$(mktemp -d) bun test: the rest of the package matches main (login and
refresh tests time out here on main as well; CI runs them on Linux).
Grok's billing (/v1/billing?format=credits) says nothing of a plan's rate
limit: a free account read 0% used, 100 left, while its requests came back
429. The plugin now keeps an account's last 429 (by its CLI home) and
usage shows a "Rate limit" window at 100%, aside, before the period's,
until the reset the 429 named (Retry-After in seconds or as a date, or a
*ratelimit*reset* header), or, with none named, until a request goes
through or 5 minutes have passed. magpie's gateway already rests the
account; this is what the card says.
auth.refresh with refreshLead 5 minutes (the in-fetch margin): the CLI
renews the sign-in in the account's home (grok models), once per home
however many ask, and the token is read back. A token the CLI renewed
already is given without running it; no credential left (grok logout) is
signIn "expired"; a token the CLI couldn't renew throws and is retried.
The check before each request stays for OpenCode, which doesn't call the
hook (magpie 0.1.684+ does). refresh.test.mjs fails without the change;
HOME=$(mktemp -d) bun test passes (396 across the repo).