diff --git a/packages/antigravity/README.md b/packages/antigravity/README.md index c4ebb13..cdc66b1 100644 --- a/packages/antigravity/README.md +++ b/packages/antigravity/README.md @@ -73,7 +73,10 @@ wrapped in the app's envelope (`{model, project, userAgent: "antigravity", requestType: "agent", requestId, request}`): - The User-Agent is `antigravity/hub/ /`. The version is - read from the app's update manifest every 6 hours. + read from the app's update manifest every 6 hours. Google lists Gemini 4 + only to new enough releases, so a manifest that can't be read is asked + again after a minute, and the model list is read again when the version + changes. - The session id is a number made from the host's session header when named, else the conversation's first real user prompt (skipping injected `AGENTS.md` and environment preambles), so unrelated conversations that diff --git a/packages/antigravity/index.mjs b/packages/antigravity/index.mjs index 0a3ad8d..6fc5b45 100644 --- a/packages/antigravity/index.mjs +++ b/packages/antigravity/index.mjs @@ -53,13 +53,18 @@ const BASE = DAILY + "/v1beta" const NPM = "@ai-sdk/google" const VERSION_URL = "https://antigravity-hub-auto-updater-974169037036.us-central1.run.app/manifest/latest-arm64-mac.yml" -const DEFAULT_VERSION = "2.9.1" +// the manifest's version on 2026-11-12; Google serves Gemini 4 only to +// releases about this new (2.9.1 got no Gemini 4, #1057) +const DEFAULT_VERSION = "2.31.2" const SIGN_IN_TIMEOUT = 10 * 60 * 1000 const MODELS_TTL = 10 * 60 * 1000 const TIERS_TTL = 60 * 60 * 1000 const TIER_REFUSED_FOR = 24 * 60 * 60 * 1000 const VERSION_TTL = 6 * 60 * 60 * 1000 +// a manifest that couldn't be read is asked again this soon, not in six hours +const VERSION_RETRY = 60 * 1000 +const VERSION_TIMEOUT = 15 * 1000 // the header magpie names a request's effort in const EFFORT = "x-magpie-effort" @@ -107,25 +112,34 @@ const platform = () => `${GOOS[process.platform] ?? process.platform}/${GOARCH[p const ver = { v: "", at: 0, pending: null } // version is the Antigravity release the requests say they come from, -// read from the app's own update manifest every six hours +// read from the app's own update manifest every six hours. Google lists +// and serves some models (Gemini 4) only to new enough releases, so a +// manifest that can't be read keeps the default for a minute only, and a +// version that changes drops the model lists read under the old one. async function version() { if (ver.v && Date.now() - ver.at < VERSION_TTL) return ver.v if (ver.pending) return ver.pending ver.at = Date.now() if (!ver.v) ver.v = DEFAULT_VERSION ver.pending = (async () => { + let read = "" try { - const res = await fetch(VERSION_URL, { headers: { "User-Agent": "electron-builder" }, signal: AbortSignal.timeout(5000) }) + const res = await fetch(VERSION_URL, { headers: { "User-Agent": "electron-builder" }, signal: AbortSignal.timeout(VERSION_TIMEOUT) }) if (res.ok) { const text = (await res.text()).slice(0, 64 << 10) for (const line of text.split(/\r?\n/)) { if (!line.startsWith("version:")) continue const v = line.slice(8).trim().replace(/^['"]+|['"]+$/g, "") - if (v && /^[0-9.]+$/.test(v)) ver.v = v + if (v && /^[0-9.]+$/.test(v)) read = v break } } } catch {} + if (!read) ver.at = Date.now() - VERSION_TTL + VERSION_RETRY + else if (read !== ver.v) { + ver.v = read + lists.clear() + } ver.pending = null return ver.v })() @@ -1911,4 +1925,8 @@ export const _internal = { lists, refused, ver, + version, + VERSION_TTL, + VERSION_RETRY, + DEFAULT_VERSION, } diff --git a/packages/antigravity/package.json b/packages/antigravity/package.json index 5a8ddc0..8148638 100644 --- a/packages/antigravity/package.json +++ b/packages/antigravity/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-antigravity-auth", - "version": "0.1.7", + "version": "0.1.8", "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/version.test.mjs b/packages/antigravity/version.test.mjs new file mode 100644 index 0000000..2e7bc19 --- /dev/null +++ b/packages/antigravity/version.test.mjs @@ -0,0 +1,61 @@ +// The version the requests name is read from the update manifest (#1057). +import { afterEach, beforeEach, expect, test } from "bun:test" +import { _internal } from "./index.mjs" +import { real } from "./fake.mjs" + +const { ver, version, lists, VERSION_TTL, VERSION_RETRY, DEFAULT_VERSION } = _internal + +beforeEach(() => { + ver.v = "" + ver.at = 0 + ver.pending = null + lists.clear() +}) +afterEach(() => (globalThis.fetch = real)) + +const manifest = (v) => async () => new Response(`version: ${v}\nfiles: []\n`, { status: 200 }) +const down = async () => { throw new TypeError("fetch failed") } + +test("a manifest that can't be read is asked again after a minute, not six hours", async () => { + let asked = 0 + globalThis.fetch = async (...a) => { asked++; return down(...a) } + expect(await version()).toBe(DEFAULT_VERSION) + expect(asked).toBe(1) + expect(await version()).toBe(DEFAULT_VERSION) + expect(asked).toBe(1) + ver.at -= VERSION_RETRY + 1 + globalThis.fetch = async (...a) => { asked++; return manifest("2.40.0")(...a) } + expect(await version()).toBe("2.40.0") + expect(asked).toBe(2) + ver.at -= VERSION_RETRY + 1 + expect(await version()).toBe("2.40.0") + expect(asked).toBe(2) +}) + +test("a read manifest holds for six hours", async () => { + let asked = 0 + globalThis.fetch = async (...a) => { asked++; return manifest("2.40.0")(...a) } + await version() + ver.at -= VERSION_TTL - 1000 + await version() + expect(asked).toBe(1) +}) + +test("a new version drops the model lists read under the old one", async () => { + globalThis.fetch = down + await version() + lists.set("rt", { at: Date.now(), infos: [], project: "p" }) + ver.at -= VERSION_RETRY + 1 + globalThis.fetch = manifest(DEFAULT_VERSION) + await version() + expect(lists.size).toBe(1) + ver.at -= VERSION_TTL + 1 + globalThis.fetch = manifest("2.40.0") + await version() + expect(lists.size).toBe(0) +}) + +test("the default is a release Google serves Gemini 4 to", () => { + const [a, b] = DEFAULT_VERSION.split(".").map(Number) + expect(a > 2 || (a === 2 && b >= 20)).toBe(true) +})