From 67fb12584a9469e78c4b853293824a6f889fd1fb Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 19 Nov 2026 13:08:52 +0800 Subject: [PATCH] antigravity 0.2.4: a reply names the id it went out under (x-magpie-sent-model) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit daoche_wuzui on X asked how to tell whether a request was routed to a model with a suffix. The plugin sends a family (gemini-3.7-flash) as the variant the effort picks from the account's list (gemini-3.7-flash-high), and nothing told magpie which. complete()'s replies now carry x-magpie-sent-model with that id, on the stream, the whole reply and a failed reply passed through. magpie keeps it in its ledger and shows it on Usage › Requests and the Routing page (yetone/magpie, same day), and takes the header off before the agent. OpenCode ignores it. Run (mote, HOME=$(mktemp -d)) at this tree: bun test packages/antigravity 136 pass, 0 fail; bun scripts/check.mjs ok. Broken by hand: 0.2.3's index.mjs with the new test: requests.test.mjs 31 pass, 1 fail (the new test). Not tried: a real account. The change adds one response header and sends Google nothing new. --- packages/antigravity/README.md | 4 ++++ packages/antigravity/index.mjs | 10 +++++++--- packages/antigravity/package.json | 2 +- packages/antigravity/requests.test.mjs | 20 ++++++++++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/packages/antigravity/README.md b/packages/antigravity/README.md index 5cfb80c..9e5e214 100644 --- a/packages/antigravity/README.md +++ b/packages/antigravity/README.md @@ -74,6 +74,10 @@ A request picks the level in this order: Asking for a level the model lacks picks the nearest one, and a tie goes up. +The reply's `x-magpie-sent-model` header names the id the request went +out under (`gemini-3.7-flash-high`), so magpie can show it beside the +model. OpenCode ignores the header. + ## Requests The plugin sends every request to `v1internal:streamGenerateContent`, diff --git a/packages/antigravity/index.mjs b/packages/antigravity/index.mjs index ddb1ef5..75a7155 100644 --- a/packages/antigravity/index.mjs +++ b/packages/antigravity/index.mjs @@ -76,6 +76,10 @@ const VERSION_TIMEOUT = 15 * 1000 const EFFORT = "x-magpie-effort" const SESSION = "x-magpie-session" const SUBAGENT = "x-magpie-subagent" +// SENT is how magpie is told the model id a request went out under: the +// variant the effort picked (gemini-3.1-pro-high for gemini-3.1-pro at high), +// for its ledger and Routing page. magpie takes it off; OpenCode ignores it. +const SENT = "x-magpie-sent-model" // ---- small helpers ------------------------------------------------------------------ @@ -1679,10 +1683,10 @@ async function complete(s, url, init, magpie) { const note = left > 0 ? quotaLeftNote(left) : CREDITS_NOTE return new Response(withNote(text, note), { status: 429, headers: { "content-type": "application/json" } }) } - return new Response(text, { status: res.status, headers: { "content-type": res.headers.get("content-type") ?? "application/json" } }) + return new Response(text, { status: res.status, headers: { "content-type": res.headers.get("content-type") ?? "application/json", [SENT]: sent } }) } - if (stream) return new Response(unwrap(res.body, again400 ? badCallSaid(sent, asks) : undefined), { status: 200, headers: RESPONSE_HEADERS }) - return new Response(JSON.stringify(await whole(res)), { status: 200, headers: { "content-type": "application/json" } }) + if (stream) return new Response(unwrap(res.body, again400 ? badCallSaid(sent, asks) : undefined), { status: 200, headers: { ...RESPONSE_HEADERS, [SENT]: sent } }) + return new Response(JSON.stringify(await whole(res)), { status: 200, headers: { "content-type": "application/json", [SENT]: sent } }) } // ---- Google AI credits ---------------------------------------------------------------------- diff --git a/packages/antigravity/package.json b/packages/antigravity/package.json index 8858232..3f9dcc2 100644 --- a/packages/antigravity/package.json +++ b/packages/antigravity/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-antigravity-auth", - "version": "0.2.3", + "version": "0.2.4", "description": "Sign in to Antigravity with a Google account from OpenCode or magpie: Gemini, and the Claude and GPT-OSS models Google hosts for it", "type": "module", "main": "./opencode.mjs", diff --git a/packages/antigravity/requests.test.mjs b/packages/antigravity/requests.test.mjs index f4df78d..cfabdd7 100644 --- a/packages/antigravity/requests.test.mjs +++ b/packages/antigravity/requests.test.mjs @@ -58,6 +58,26 @@ test("OpenCode's variant names the level", async () => { expect(seen.find((s) => s.name === "streamGenerateContent").json.model).toBe("gemini-3.7-flash-low") }) +test("the reply names the id it went out under, for magpie's ledger", async () => { + fake({ fetchAvailableModels: models, streamGenerateContent: () => sse({ candidates: [{ content: { role: "model", parts: [{ text: "hi" }] }, finishReason: "STOP" }] }) }) + const f = await loaderFetch(auth()) + for (const [model, effort, method, want] of [ + ["gemini-3.7-flash", "high", "streamGenerateContent", "gemini-3.7-flash-high"], + ["gemini-3.7-flash", "low", "generateContent", "gemini-3.7-flash-low"], + ["gemini-3-flash", "", "streamGenerateContent", "gemini-3-flash"], + ]) { + const res = await f(URL_(model, method), { method: "POST", headers: effort ? { "x-magpie-effort": effort } : {}, body: ask() }) + expect(res.status).toBe(200) + expect(res.headers.get("x-magpie-sent-model")).toBe(want) + await res.text() + } + fake({ fetchAvailableModels: models, streamGenerateContent: () => new Response(JSON.stringify({ error: { code: 500, message: "boom" } }), { status: 500 }) }) + const g = await loaderFetch(auth()) + const bad = await g(URL_("gemini-3.7-flash"), { method: "POST", headers: { "x-magpie-effort": "high" }, body: ask() }) + expect(bad.status).toBe(500) + expect(bad.headers.get("x-magpie-sent-model")).toBe("gemini-3.7-flash-high") +}) + test("a level in capitals, as Gemini's own clients write it, names the level too (#1169)", async () => { const seen = fake({ fetchAvailableModels: models, streamGenerateContent: () => sse({ candidates: [] }) }) const f = await loaderFetch(auth())