diff --git a/packages/agy-cli/README.en.md b/packages/agy-cli/README.en.md index 6b0c22d..45fe60e 100644 --- a/packages/agy-cli/README.en.md +++ b/packages/agy-cli/README.en.md @@ -315,6 +315,14 @@ off unless you turn it on. on PATH. - **Sign in fails, or agy reports a login problem**: click Sign in again, or run `agy` in a terminal to sign in there. +- **"You do not have a valid license of this product" (#3501)**: Google refuses + this account, and agy in a terminal gets the same answer. The plugin says so + in the model list on the Providers page and in the request's HTTP 403, instead + of offering the static catalog as if the account had those models. Try: + update agy and sign in again (Sign in in Magpie, or run `agy` in a terminal, + then /logout and /login); use a personal Google account (@gmail.com) rather + than a Workspace one; unset `AGY_ADC_AUTH` if it is set; turn off a VPN or + proxy that puts you in a region Antigravity isn't offered in. - **HTTP 503**: the pool is full. Raise `AGY_BRIDGE_MAX_PROCS` and the Providers page Concurrency, or reduce the number of simultaneous sessions. - **Usage shows "Limits not available" or a version error**: that window has no diff --git a/packages/agy-cli/README.md b/packages/agy-cli/README.md index d6de32f..082e2a4 100644 --- a/packages/agy-cli/README.md +++ b/packages/agy-cli/README.md @@ -226,6 +226,11 @@ agy 自己的系统提示词,只剩插件的一行工具说明和客户端的 - **找不到 agy**:在 Magpie 里点 Sign in 让它装一份(需要 Magpie 0.1.4246 起),或设置 `AGY_PATH` 指向可执行文件,或确认 `agy` 在 PATH 里。 - **Sign in 失败或 agy 报登录相关错误**:再点一次 Sign in 重新登录,或在终端运行一次 `agy` 登录。 +- **"You do not have a valid license of this product" (#3501)**:这是 Google 拒绝了这个账号, + 终端里的 agy 本身也会这样答。插件会在 Providers 页的模型列表和请求的 HTTP 403 里写明这个原因, + 不再拿静态目录冒充账号的型号。可以试:升级 agy 后重新登录(Magpie 里点 Sign in,或终端运行 + `agy` 后 /logout 再 /login);用个人 Google 账号(@gmail.com)而不是 Workspace 账号;如设置了 + `AGY_ADC_AUTH` 就去掉;关掉把你放到 Antigravity 未开放地区的 VPN 或代理。 - **HTTP 503**:进程池满。提高 `AGY_BRIDGE_MAX_PROCS` 和 Providers 页的 Concurrency, 或者减少同时进行的会话。 - **额度显示 "Limits not available" 或报版本错误**:该窗口没有可测量的数据;版本错误则 diff --git a/packages/agy-cli/index.mjs b/packages/agy-cli/index.mjs index 9a1a459..29afde8 100644 --- a/packages/agy-cli/index.mjs +++ b/packages/agy-cli/index.mjs @@ -7,7 +7,7 @@ import net from "node:net" import os from "node:os" import path from "node:path" import { fileURLToPath } from "node:url" -import { createUsageReader } from "./usage.mjs" +import { agyRefusal, createUsageReader } from "./usage.mjs" import { storeCatalogRows } from "./model-ids.mjs" import { backgroundBlocked, cannotSignIn, forgetStoredSignIn, storedEmail, storedSignInNow } from "./signin.mjs" import { sanitizePatternFields } from "./re2-pattern.mjs" @@ -349,12 +349,44 @@ async function listAgyModels(agyPath) { // a listing nobody asked for doesn't run an agy that would start its own // Google sign-in (signin.mjs); the catalog it has stays if (await backgroundBlocked()) return null - const { err, stdout, code, timedOut } = await execOnce(agyPath, ["models"], { timeoutMs: 15_000, unrefTimer: true }) + const { err, stdout, stderr, code, timedOut } = await execOnce(agyPath, ["models"], { timeoutMs: 15_000, unrefTimer: true }) // null, not FALLBACK_MODELS: a failed listing must not overwrite a dynamic catalog. - if (err || timedOut || code !== 0) return null + if (err || timedOut || code !== 0) { + if (!err && !timedOut) noteRefusal(agyRefusal(`${stderr}\n${stdout}`)) + return null + } + noteRefusal("") return parseAgyModels(stdout) } +// What the last `agy models` of each account said when Google turned the +// account away at agy's eligibility check (agyRefusal), "" when it listed. +// models() says it instead of serving a fallback list as if agy had +// answered, and a turn that then can't pick its model says it too. +const refusals = new Map() + +function noteRefusal(why) { + const home = currentHome() ?? "" + if (why) refusals.set(home, why) + else refusals.delete(home) +} + +function refusalOf() { + return refusals.get(currentHome() ?? "") || "" +} + +// refusalNow is the account's refusal, asking agy once when no listing of +// it has said yet (a request before the first models()). +async function refusalNow(agyPath) { + if (refusals.has(currentHome() ?? "")) return refusalOf() + if (!agyPath || await backgroundBlocked()) return "" + const { err, stdout, stderr, code, timedOut } = await execOnce(agyPath, ["models"], { timeoutMs: 15_000 }) + if (err || timedOut || code === 0) return "" + const why = agyRefusal(`${stderr}\n${stdout}`) + noteRefusal(why) + return why +} + // parseAgyModels reads `agy models` output: one " " per line. function parseAgyModels(stdout) { const out = [] @@ -397,6 +429,13 @@ async function probeSignedIn(agy) { } return { ok: true } } + // Google turned the account away (#3501): signing in again took, and + // Google still refuses it; say so, not agy's last line alone + const refused = !probe.err && !probe.timedOut ? agyRefusal(`${probe.stderr}\n${probe.stdout}`) : "" + if (refused) { + noteRefusal(refused) + return { ok: false, why: refused } + } const why = probe.timedOut ? "`agy models` timed out after 15s" : `\`agy models\` says: ${(probe.stderr || probe.stdout || "").trim().split(/\r?\n/).filter(Boolean).at(-1) || probe.err?.message || `exit ${probe.code}`}` @@ -961,6 +1000,9 @@ export function streamErrorOf(error) { const type = error?.kind || "api_error" const out = { type, message: String(error?.message ?? error) } if (type === "invalid_request_error") out.status = 400 + // Google refused the account (refusedError): its status, so magpie + // reads it as the account's refusal, not as a failed reply. + if (type === "permission_error") out.status = 403 return out } @@ -972,6 +1014,15 @@ class AgentTurnError extends Error { } } +// Google refused the account (agyRefusal): a 403 no retry of this request +// fixes, the account's and not the model's. +function refusedError(why) { + const error = new AgentTurnError(`agy bridge: ${why}`, "permission_error") + error.statusCode = 403 + error.noRetry = true + return error +} + function shellQuote(value) { return `'${String(value).replace(/'/g, `'\\''`)}'` } @@ -1917,6 +1968,10 @@ class Proc { await this.conn.request("session/set_model", { sessionId: this.sessionId, modelId: model }, 30_000) } } catch (error) { + // Google turned the account away (#3501): agy's session offers no + // model at all, so every model is "unknown". That is the account. + const refused = await refusalNow(this.agyPath).catch(() => "") + if (refused) throw refusedError(refused) const wrapped = new Error(`agy bridge: model ${model} is unavailable to this agy account: ${error.message}`) wrapped.statusCode = 400 throw wrapped @@ -2281,6 +2336,8 @@ class Proc { "rate_limit_error", ) } + const refused = agyRefusal(detail) + if (refused) return refusedError(refused) return new AgentTurnError(`agy bridge: agy stopped the turn because of an error${detail ? ": " + detail : ""}`) } @@ -6331,6 +6388,11 @@ export const AntigravityBridgePlugin = async () => { const agy = findAgy() // Never force a refresh here: Magpie times models() out after about two seconds. const catalog = await loadModelCatalog(agy, { probeOffered: true }) + // Google turned the account away (#3501): agy lists nothing, and a + // fallback list would read as models this account has. magpie + // keeps the list it had and shows why. + const refused = agy ? refusalOf() : "" + if (refused) throw new Error(refused) const out = {} // Not the account's list yet: the static one (no agy, signed out, // or agy hasn't answered), or Gemini alone while agy acp is still @@ -6371,7 +6433,7 @@ function jsonError(status, message, code, { extra, headers, noRetry = false } = return new Response( JSON.stringify({ type: "error", - error: { type: status === 400 ? "invalid_request_error" : "api_error", + error: { type: status === 400 ? "invalid_request_error" : status === 403 ? "permission_error" : "api_error", ...(code ? { code } : {}), message: String(message || "unknown error"), ...(extra ?? {}) }, }), { status, headers: { "Content-Type": "application/json", diff --git a/packages/agy-cli/package.json b/packages/agy-cli/package.json index 9ef888a..821eded 100644 --- a/packages/agy-cli/package.json +++ b/packages/agy-cli/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-agy-cli-auth", - "version": "0.1.69", + "version": "0.1.70", "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", diff --git a/packages/agy-cli/test/catalog.mjs b/packages/agy-cli/test/catalog.mjs index b0b4dd6..c961439 100644 --- a/packages/agy-cli/test/catalog.mjs +++ b/packages/agy-cli/test/catalog.mjs @@ -596,3 +596,58 @@ test("已登录时登录结果用 agy 存的 Google 账号命名,而不是一 await warmed(kit) }) }) + +// agy 1.5.9 when Google answers 403 #3501 at its eligibility check (run +// against a fake Code Assist, 11-16): every command, `agy models` included, +// ends with this and exit 1. Three people on X got a fallback list, "model … +// is unavailable to this agy account" and "not eligible" from the plugin. +const REFUSED_3501 = "Error: Eligibility check failed: PERMISSION_DENIED (code 403): You do not have a valid license of this product. Please contact your administrator to request a license. If you are not an enterprise user and believe you are receiving this message as an error, please try using the latest version and logging in again. (#3501). Please log out (/logout) and log back in (/login).\n" +const REFUSED_LISTING = { code: 1, stderr: "I1116 10:34:03.760516 315 http_helpers.go:876] Failed to make code assist backend request\n" + REFUSED_3501 } + +test("#3501 Google 拒了账号:models() 说出原因,不给静态目录冒充账号的型号", async () => { + await withKit({ modelsBehavior: REFUSED_LISTING }, async (kit) => { + await kit.models().catch(() => {}) + await warmed(kit) + const error = await kit.models().then(() => null, e => e) + assert.ok(error, "Google 拒了账号,models() 仍给了一份列表") + assert.match(error.message, /#3501/) + assert.match(error.message, /valid license/) + assert.match(error.message, /\/logout.*\/login/) + assert.match(error.message, /AGY_ADC_AUTH/) + // agy 又能列出了(重新登录、换了地区):恢复正常目录 + kit.modelsBehavior = DYNAMIC_OK + kit.clock.advance(CATALOG_TTL_MS) + await kit.models().catch(() => {}) + await warmed(kit) + assert.ok((await kit.models())["gemini-9-test"], "agy 能列出后仍报拒绝") + }) +}) + +test("#3501 别的失败(网络、超时、未知输出)仍给静态目录,不说成拒绝", async () => { + await withKit({ modelsBehavior: { code: 1, stderr: "Error: Eligibility check failed: EOF\n" } }, async (kit) => { + await kit.models() + await warmed(kit) + assert.ok((await kit.models())["gemini-4-argon"]) + }) +}) + +test("#3501 请求:会话一个型号都不开放时答 403 和 Google 的原因,不说型号不可用", async () => { + for (const stream of [true, false]) { + await withKit({ modelsBehavior: REFUSED_LISTING, setModelError: { code: -32603, message: "Unknown model ID: gemini-4-argon-high" } }, async (kit) => { + const response = await kit.request(baseBody({ stream, model: "agy-cli/gemini-4-argon", tools: [], messages: [{ role: "user", content: "hi" }] })) + assert.equal(response.status, 403, `stream=${stream}`) + const body = await response.json() + assert.equal(body.error.type, "permission_error") + assert.match(body.error.message, /#3501/) + assert.doesNotMatch(body.error.message, /unavailable to this agy account/) + await settle(kit) + }) + } + // 账号没被拒,型号真的不可用:仍是 400 + await withKit({ modelsBehavior: DYNAMIC_OK, setModelError: { code: -32603, message: "Unknown model ID: gemini-4-argon-high" } }, async (kit) => { + const response = await kit.request(baseBody({ model: "agy-cli/gemini-4-argon", tools: [], messages: [{ role: "user", content: "hi" }] })) + assert.equal(response.status, 400) + assert.match((await response.json()).error.message, /unavailable to this agy account/) + await settle(kit) + }) +}) diff --git a/packages/agy-cli/test/testkit.mjs b/packages/agy-cli/test/testkit.mjs index 8171427..385d792 100644 --- a/packages/agy-cli/test/testkit.mjs +++ b/packages/agy-cli/test/testkit.mjs @@ -198,6 +198,7 @@ function spawnModels(kit, file, args) { return } if (behavior.stdout) child.stdout.emit("data", behavior.stdout) + if (behavior.stderr) child.stderr.emit("data", behavior.stderr) child.finish(behavior.code ?? 0) } if (!behavior.hang) { @@ -275,7 +276,9 @@ class FakeAgy { else this.respond(id, { sessionId: this.sessionId, models }) } else if (method === "session/set_model") { this.kit.setModels.push(params.modelId) - this.respond(id, {}) + // agy whose account Google turned away offers no model: every one is unknown + if (this.kit.setModelError) this.send({ id, error: this.kit.setModelError }) + else this.respond(id, {}) } else if (method === "session/prompt") { this.runPrompt(id, params) } else if (method === "session/cancel") { @@ -434,6 +437,7 @@ export async function createBridgeKit(options = {}) { initialAgyModel: options.initialAgyModel ?? "gemini-3.8-flash-low", offeredModels: options.offeredModels ?? null, sessionNewError: options.sessionNewError ?? null, + setModelError: options.setModelError ?? null, sessionNewDelayMs: options.sessionNewDelayMs ?? 0, sessionResume: options.sessionResume ?? false, agentVersion: options.agentVersion ?? "1.5.0", diff --git a/packages/agy-cli/test/usage.mjs b/packages/agy-cli/test/usage.mjs index 15cff4e..71a971e 100644 --- a/packages/agy-cli/test/usage.mjs +++ b/packages/agy-cli/test/usage.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 { createUsageReader, fetchUsage, parseUsageReport, quotaUserAgent, readQuotaDirect } from "../usage.mjs" +import { agyRefusal, createUsageReader, fetchUsage, parseUsageReport, quotaUserAgent, readQuotaDirect } from "../usage.mjs" import http from "node:http" import { modelsInGroup, storeCatalogRows } from "../model-ids.mjs" import { forgetStoredSignIn } from "../signin.mjs" @@ -587,6 +587,9 @@ test("reports sanitized failures and preserves the bridge sign-in; failures back ["Not logged in secret@example.com https://secret.invalid/token", /sign in again/, "expired"], ["Eligibility check failed: EOF secret@example.com", /eligibility check failed on a network/, "kept"], ["not eligible secret@example.com", /not eligible/, "kept"], + // Google's 403 #3501 (agy 1.5.9's words, three people on X on 11-16): + // the account, with what to do about it, not "not eligible" + ["Eligibility check failed: PERMISSION_DENIED (code 403): You do not have a valid license of this product. Please contact your administrator to request a license. If you are not an enterprise user and believe you are receiving this message as an error, please try using the latest version and logging in again. (#3501). Please log out (/logout) and log back in (/login). secret@example.com", /#3501[\s\S]*\/logout[\s\S]*AGY_ADC_AUTH/, "kept"], ["connection refused: secret@example.com https://secret.invalid", /network or proxy/, "kept"], ["unrecognized secret@example.com", /could not read usage/, "kept"], ]) { @@ -967,3 +970,18 @@ test("only a region refusal reads the quota directly", async t => { assert.equal(asked, 0, error) } }) + +test("agyRefusal: Google turning the account away, never a network failure or agy's own log lines", () => { + const license = "Error: Eligibility check failed: PERMISSION_DENIED (code 403): You do not have a valid license of this product. ... (#3501). Please log out (/logout) and log back in (/login)." + assert.match(agyRefusal(license), /#3501/) + assert.match(agyRefusal("error: something (#3501)"), /#3501/) + assert.match(agyRefusal("Error: Eligibility check failed: Your current account is not eligible for Antigravity, because it is not currently available in your location."), /not currently available in your location[\s\S]*VPN/) + for (const other of [ + "", + "Error: Eligibility check failed: EOF", + "Error: Eligibility check failed: dial tcp: lookup cloudcode-pa.googleapis.com: no such host", + "Error: You are not logged into Antigravity.", + // a background poll agy logged failing, while the command itself failed otherwise + "E1116 10:34:12.084405 248 errorreport.go:307] Failed to poll ListExperiments: PERMISSION_DENIED (code 403): You do not have a valid license of this product. (#3501)\nError: something else", + ]) assert.equal(agyRefusal(other), "", other) +}) diff --git a/packages/agy-cli/usage.mjs b/packages/agy-cli/usage.mjs index 42689ee..209e2b4 100644 --- a/packages/agy-cli/usage.mjs +++ b/packages/agy-cli/usage.mjs @@ -45,10 +45,43 @@ function refusedEligibility(output) { return ELIGIBILITY.test(output) } +// Google's 403 #3501 at agy's eligibility check: Google turns the account +// itself away, and agy refuses every command with it, `agy models`, print +// mode and a turn alike (agy 1.5.9 against a Code Assist answering it): +// Eligibility check failed: PERMISSION_DENIED (code 403): You do not have +// a valid license of this product. ... (#3501). Please log out (/logout) +// and log back in (/login). +// Three people on X (11-16) got only a list of fallback models, "model … +// is unavailable to this agy account" or "not eligible" from the plugin. +const LICENSE_REFUSAL = /valid license of this product|\(#3501\)/i + +export const LICENSE_REFUSED = "Google refuses this Google account for Antigravity " + + "(403 #3501: \"You do not have a valid license of this product\"). agy itself gets the same " + + "answer, so this account can't be used until Google accepts it. Update agy, then sign in to " + + "the account again (in magpie, or run `agy` in a terminal and /logout, then /login); sign in " + + "with a personal Google account (@gmail.com) rather than a Workspace one; unset AGY_ADC_AUTH " + + "if it is set; and turn off a VPN or proxy that puts you in a region Antigravity isn't offered in." + +// agyRefusal is what to tell the user when agy's output says Google turned +// the account away at its eligibility check, or "" when it doesn't: the +// license refusal (#3501), or any other refusal of the check that isn't a +// network failure ("Eligibility check failed: EOF"), in agy's own words. +// agy's diagnostic log lines are not read: a background poll it logs can +// fail on its own. +export function agyRefusal(output) { + const said = withoutDiagnostics(String(output ?? "")) + if (LICENSE_REFUSAL.test(said)) return LICENSE_REFUSED + if (!ELIGIBILITY.test(said) || NETWORK.test(said)) return "" + const line = said.split(/\r?\n/).map(l => l.trim().replace(/^error:\s*/i, "")).find(l => ELIGIBILITY.test(l)) || "" + return `Google refuses this account for Antigravity: ${line.slice(0, 400)}. agy itself gets the same answer. ` + + "Antigravity isn't offered in every region: turn off a VPN or proxy that puts you in another one, or use an account Google serves there." +} + function commandFailure(output) { if (/not (?:logged|signed) in(?:to)?\b|unauthenticated|authentication required|login required|please (?:log|sign) in|sign in again|\binvalid_grant\b/i.test(withoutDiagnostics(output))) { return new UsageError("agy usage needs authentication. Run `agy` in a terminal to sign in again.", { kind: "auth" }) } + if (LICENSE_REFUSAL.test(withoutDiagnostics(output))) return new UsageError(LICENSE_REFUSED) const eligibility = ELIGIBILITY.test(output) const network = NETWORK.test(output) if (network) return new UsageError(`agy usage ${eligibility ? "eligibility check " : ""}failed on a network request. Check network or proxy settings.`)