agy-cli 0.1.93: a refused account with no project has its quota read under aicode-consumers
IcyLiqu1d on X: agy-cli's usage always failed with "this account is not
eligible for Antigravity" while the account's requests kept working.
agy -p /usage waits for agy's eligibility check; agy acp, which serves
requests, runs none, so a refused account keeps working and its usage
does not. 0.1.69's direct read covers a refusal where loadCodeAssist
names a project. Where it names none, agy itself asks
retrieveUserQuotaSummary with {} and Google answers 403 #3501, and the
plugin's direct read gave up with "names no project" and then showed
only the generic "not eligible" line, hiding why.
- readQuotaDirect: a personal (auth_method consumer, not gcpManaged)
account loadCodeAssist names no project for is asked under
aicode-consumers, the project Google serves every consumer account
under. A Workspace/Cloud account still fails, with Google's
ineligibleTiers reasonMessage when it gave one.
- fetchUsage: when the direct read fails too, the error keeps agy's
refusal and adds why the read failed.
Run (mica, bun 1.4.2, HOME=$(mktemp -d)):
- test/usage.mjs: 44 pass. With origin/main 207880e1's usage.mjs and
the new tests, 3 fail (the two new tests and the no-project case of
"a direct read that fails...").
- bun test ./packages/agy-cli: 41 pass, 0 fail. bun scripts/check.mjs:
exit 0, agy-cli ok.
- Real account (agy 1.5.10, CLOUD_CODE_URL through a recording proxy
that drops currentTier, paidTier and cloudaicompanionProject from
loadCodeAssist): agy's own retrieveUserQuotaSummary {} calls got 403,
onboardUser 403; the plugin's read with project aicode-consumers got
200 and fetchUsage returned both 7-day groups in 7.0s. On 0.1.92 the
same run returned the generic "not eligible" error.
Not tried: a real account Google refuses at the eligibility check (I
have none; the refusal was simulated), and Linux, where the stored
sign-in isn't read from a keyring, so the direct read can't run there.
This commit is contained in:
@@ -240,8 +240,11 @@ Where Antigravity isn't offered, agy refuses `/usage` on its eligibility check
|
||||
made had its answer. The plugin then makes that read itself, the way agy makes
|
||||
it: with agy's stored sign-in it asks Google's Code Assist server
|
||||
(`loadCodeAssist`, then `retrieveUserQuotaSummary`) with agy's own User-Agent.
|
||||
An access token about to end is renewed in memory and never stored. If that
|
||||
read fails too, the account shows agy's refusal and no numbers.
|
||||
An access token about to end is renewed in memory and never stored. When
|
||||
`loadCodeAssist` names no project for a personal Google account, the quota is
|
||||
asked under `aicode-consumers`, the project Google serves every personal account
|
||||
under (agy itself asks with none, and Google refuses that). If that read fails
|
||||
too, the account shows agy's refusal and why the read failed, and no numbers.
|
||||
|
||||
A signed-out agy opens Google's sign-in page in the browser when it runs, so
|
||||
before running agy for usage or the model list, the plugin looks at agy's stored
|
||||
|
||||
@@ -169,8 +169,10 @@ magpie quota refresh agy-cli --json
|
||||
在 Antigravity 未开放的地区,agy 会在资格检查时拒绝 `/usage`("not currently available in
|
||||
your location"),尽管它自己查的额度已经拿到了。这时插件按 agy 的方式自己查:用 agy 存的登录,
|
||||
以 agy 的 User-Agent 依次请求 Google Code Assist 的 `loadCodeAssist` 和
|
||||
`retrieveUserQuotaSummary`。快到期的访问令牌只在内存里续期,不写回。这次查询也失败时,账号显示
|
||||
agy 的拒绝原因,不显示数字。
|
||||
`retrieveUserQuotaSummary`。快到期的访问令牌只在内存里续期,不写回。个人 Google 账号的
|
||||
`loadCodeAssist` 没给项目时,按 Google 给所有个人账号用的 `aicode-consumers` 项目查(agy
|
||||
自己不带项目查,Google 会拒绝)。这次查询也失败时,账号显示 agy 的拒绝原因和查询失败的原因,
|
||||
不显示数字。
|
||||
|
||||
未登录的 agy 一运行就会在浏览器里打开 Google 登录页,所以插件在为额度或模型列表运行 agy 之前,
|
||||
先看系统钥匙串(macOS)或凭据管理器(Windows)里 agy 存的登录,只读有没有、何时到期。没有登录、
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-agy-cli-auth",
|
||||
"version": "0.1.92",
|
||||
"version": "0.1.93",
|
||||
"description": "Magpie/OpenCode model provider that connects your local agy CLI through the Agent Client Protocol (agy acp), so Antigravity subscription models run through the real CLI",
|
||||
"type": "module",
|
||||
"main": "./opencode.mjs",
|
||||
|
||||
@@ -6,7 +6,7 @@ import fs from "node:fs/promises"
|
||||
import os from "node:os"
|
||||
import path from "node:path"
|
||||
import { test } from "node:test"
|
||||
import { agyRefusal, createUsageReader, fetchUsage, parseUsageReport, quotaUserAgent, readQuotaDirect, verifyLinkIn } from "../usage.mjs"
|
||||
import { agyRefusal, CONSUMER_PROJECT, createUsageReader, fetchUsage, parseUsageReport, quotaUserAgent, readQuotaDirect, verifyLinkIn } from "../usage.mjs"
|
||||
import http from "node:http"
|
||||
import { modelsInGroup, storeCatalogRows } from "../model-ids.mjs"
|
||||
import { forgetStoredSignIn } from "../signin.mjs"
|
||||
@@ -987,7 +987,8 @@ test("an access token about to end is renewed in memory for the direct read, nev
|
||||
test("a direct read that fails leaves the region refusal standing: unknown, never zero or full", async t => {
|
||||
for (const [answer, stored] of [
|
||||
[{ retrieveUserQuotaSummary: [403, { error: { code: 403, message: "secret@example.com" } }] }, STORED],
|
||||
[{ loadCodeAssist: [200, { ...LOAD, cloudaicompanionProject: undefined }] }, STORED],
|
||||
// a Workspace or Cloud account with no project of its own
|
||||
[{ loadCodeAssist: [200, { ...LOAD, cloudaicompanionProject: undefined, gcpManaged: true }] }, STORED],
|
||||
[{ retrieveUserQuotaSummary: [200, { groups: [] }] }, STORED],
|
||||
[{}, null],
|
||||
]) {
|
||||
@@ -998,10 +999,37 @@ test("a direct read that fails leaves the region refusal standing: unknown, neve
|
||||
assert.deepEqual(result.windows, [])
|
||||
assert.equal(result.signIn, "kept")
|
||||
assert.match(result.error, /not eligible/)
|
||||
// and why the direct read failed
|
||||
assert.match(result.error, /Reading the quota directly failed too: \S/)
|
||||
assert.doesNotMatch(result.error, /secret/)
|
||||
}
|
||||
})
|
||||
|
||||
// IcyLiqu1d on X (11-18): agy refused /usage as "not eligible" while the
|
||||
// account's requests went on working: agy's ACP sessions run no
|
||||
// eligibility check. When Google's loadCodeAssist names no project, agy
|
||||
// asks retrieveUserQuotaSummary with {} and gets 403 #3501 (agy 1.5.10,
|
||||
// recorded through CLOUD_CODE_URL with loadCodeAssist answered like this;
|
||||
// the 403 and the 200 below were Google's own for a consumer account).
|
||||
test("a consumer account Google names no project for has its quota read under the consumer project", async t => {
|
||||
const api = await codeAssist(t, { loadCodeAssist: [200, { allowedTiers: [], gcpManaged: false, upgradeSubscriptionUri: "https://codeassist.google.com/upgrade", ineligibleTiers: [] }] })
|
||||
const f = await fixture(t, { TEST_MODE: "fail", TEST_ERROR: "", TEST_FAILURE_REPORT: REFUSED, TEST_VERSION: "1.5.10", CLOUD_CODE_URL: api.url })
|
||||
const quota = o => readQuotaDirect({ ...o, stored: async () => STORED })
|
||||
const result = await createUsageReader(() => f.executable, { ...f.options, quota })()
|
||||
assert.equal(result.error, undefined)
|
||||
assert.ok(result.windows.some(w => w.used === 25) && result.windows.some(w => w.used === 50), JSON.stringify(result.windows))
|
||||
assert.deepEqual(api.calls.map(c => c.body), [{ metadata: { ideType: "ANTIGRAVITY" } }, { project: CONSUMER_PROJECT }])
|
||||
await f.assertClean()
|
||||
})
|
||||
|
||||
test("an account with no project and Google's reason for it says that reason", async t => {
|
||||
const why = "Your current account is not eligible for Antigravity, because it is not currently available in your location."
|
||||
const api = await codeAssist(t, { loadCodeAssist: [200, { gcpManaged: true, ineligibleTiers: [{ reasonCode: "UNSUPPORTED_LOCATION", reasonMessage: why }] }] })
|
||||
await assert.rejects(readQuotaDirect({ env: { CLOUD_CODE_URL: api.url }, version: "1.5.10", deadline: Date.now() + 5000, stored: async () => STORED }),
|
||||
e => e.message.includes(why) && /no project/.test(e.message))
|
||||
assert.equal(api.calls.length, 1)
|
||||
})
|
||||
|
||||
// plugins#1234 (qiankun229): agy run for usage with an ended access token
|
||||
// renews it first, and when that failed for a moment (a DNS miss at
|
||||
// Windows startup, a 10s keyring timeout) it opened Google's sign-in in the
|
||||
|
||||
@@ -409,6 +409,16 @@ export function quotaUserAgent(version, authMethod, platform = process.platform,
|
||||
|
||||
const companion = p => typeof p === "string" ? p : typeof p?.id === "string" ? p.id : ""
|
||||
|
||||
// The project Code Assist serves every consumer (personal Google) account
|
||||
// under: loadCodeAssist names it for Free, Pro and Ultra alike. Where
|
||||
// Google refuses the account at agy's eligibility check, loadCodeAssist
|
||||
// can name no project at all, and agy then asks retrieveUserQuotaSummary
|
||||
// with none, which Google answers 403 #3501 (agy 1.5.10, recorded
|
||||
// 2026-11-18), while its ACP sessions, which run no eligibility check,
|
||||
// go on serving the account's requests (IcyLiqu1d on X). Asked with this
|
||||
// project, the same account's quota answers 200.
|
||||
export const CONSUMER_PROJECT = "aicode-consumers"
|
||||
|
||||
// readQuotaDirect is retrieveUserQuotaSummary's reply for agy's stored
|
||||
// sign-in, as agy asks it. An access token with under two minutes left is
|
||||
// renewed in memory only; agy's stored sign-in is never written.
|
||||
@@ -458,8 +468,15 @@ export async function readQuotaDirect({
|
||||
if (res.status !== 200) throw new UsageError(`Antigravity's ${method} answered ${res.status}.`)
|
||||
try { return JSON.parse(reply) } catch { throw new UsageError(`Antigravity's ${method} answered with no JSON.`) }
|
||||
}
|
||||
const project = companion((await call("loadCodeAssist", { metadata: { ideType: "ANTIGRAVITY" } }))?.cloudaicompanionProject)
|
||||
if (!project) throw new UsageError("Antigravity names no project for this account.")
|
||||
const load = await call("loadCodeAssist", { metadata: { ideType: "ANTIGRAVITY" } })
|
||||
let project = companion(load?.cloudaicompanionProject)
|
||||
// a consumer account Google names no project for: the one every consumer
|
||||
// account is served under (a Workspace or Cloud one has its own)
|
||||
if (!project && load?.gcpManaged !== true && (text(sign.auth_method) || "consumer") === "consumer") project = CONSUMER_PROJECT
|
||||
if (!project) {
|
||||
const why = text((load?.ineligibleTiers ?? []).find(x => text(x?.reasonMessage))?.reasonMessage)
|
||||
throw new UsageError(why ? `Antigravity names no project for this account (${why.slice(0, 300)})` : "Antigravity names no project for this account.")
|
||||
}
|
||||
return call("retrieveUserQuotaSummary", { project })
|
||||
}
|
||||
|
||||
@@ -539,17 +556,19 @@ export async function fetchUsage(agy, {
|
||||
// failure of that read leaves agy's own answer standing: unknown,
|
||||
// never zero or full.
|
||||
if (failure.kind !== "auth" && refusedEligibility(said) && !NETWORK.test(said)) {
|
||||
// when that read fails too, the error says why, after agy's refusal
|
||||
const alsoFailed = why => new UsageError(`${failure.message} Reading the quota directly failed too: ${why.replace(/\.$/, "")}.`)
|
||||
let data
|
||||
try {
|
||||
data = await quota({ env, version: version.stdout.trim(), deadline, signal })
|
||||
} catch (error) {
|
||||
if (signal?.aborted) throw new UsageError("agy usage query was cancelled.", { kind: "cancel" })
|
||||
throw failure
|
||||
throw alsoFailed(error instanceof UsageError ? error.message : "a network request failed")
|
||||
}
|
||||
try {
|
||||
return parseUsageReport({ status: "SUCCESS", command: { name: "usage", data } })
|
||||
} catch {
|
||||
throw failure
|
||||
throw alsoFailed("Google's reply had no quota in it")
|
||||
}
|
||||
}
|
||||
throw failure
|
||||
|
||||
Reference in New Issue
Block a user