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())