From f531c01817ced3faa2e765a5e0fbbc40e211cf81 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 23:51:37 +0000 Subject: [PATCH] upstream agy-cli 0.1.115 (magpie-community/plugins@970084265aaffe3d6765a616b6a4d37bcc66a1b7) --- README.en.md | 11 +++++++++-- README.md | 5 ++++- index.mjs | 28 ++++++++++++++++++---------- package.json | 2 +- test/repeat-batch.mjs | 43 +++++++++++++++++++++++++++++++++++++++++++ test/smoke.mjs | 2 +- test/usage.mjs | 19 ++++++++++++++++++- usage.mjs | 10 ++++++++-- 8 files changed, 102 insertions(+), 18 deletions(-) diff --git a/README.en.md b/README.en.md index 8b05408..ef4fbfb 100644 --- a/README.en.md +++ b/README.en.md @@ -106,8 +106,10 @@ MCP server. The control port listens on loopback only, with a token per process. (SillyTavern presets, "continue"/"impersonate", bot frameworks) are served instead of rejected; the session ledger stays aligned across turns. See "Assistant prefill" below. -- **Usage visibility**: Magpie shows the agy subscription usage windows. They are - informational only; running out of quota does not block requests automatically. +- **Usage visibility**: Magpie shows the agy subscription usage windows. Each + model's window (its pool's most used one) is what Magpie's routing weighs the + account by for that model, so a routing group puts it by what it has left, + and a model whose pool is used up is passed over for the next member. ## Assistant prefill @@ -391,6 +393,11 @@ off unless you turn it on. account's own quota is used up) ends the turn as a rate limit (`rate_limit_error`, HTTP 429 without streaming) carrying agy's words and reset, so magpie rests the account until then and asks the next one. + The "⚠ Third-party quota reached. Please switch to Gemini models … Resets + in 3h22m19s." ending (the account's Claude and GPT-OSS quota is used up, + Gemini's is not) ends the turn the same way, so magpie rests that model + until then, asks the next account or model, and keeps asking this + account's Gemini models. The "⚠ Our servers are experiencing high traffic right now …" ending (Google has no capacity for the model now, and agy's own retries met the same 503) ends the turn as `overloaded_error` (HTTP 503 without diff --git a/README.md b/README.md index c2403b5..8661c8d 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ agy 连接 `--ide-mcp-port` 时会运行 `nc 127.0.0.1 <端口>`。插件在 agy 都在客户端侧完成。 - **助手预填**:以 assistant 结尾的预填请求(SillyTavern 预设、继续写、bot 框架)不再 400 拒绝:预填留在本轮并渲染为续写载体,会话跨轮保持对齐,见下文「助手预填」。 -- **额度查看**:在 Magpie 里查看 agy 订阅的用量窗口,仅作展示,额度耗尽时不会自动拦截请求。 +- **额度查看**:在 Magpie 里查看 agy 订阅的用量窗口。每个模型的窗口(它所在额度池用得最多的那个)也是 Magpie 路由给这个模型排账号的依据:路由组按剩余额度排它,额度池用完的模型会让给下一个成员。 ## 助手预填(assistant prefill) @@ -276,6 +276,9 @@ agy 自己的系统提示词,只剩插件的一行工具说明和客户端的 结尾是 "⚠ Individual quota reached. … Resets in 1h18m40s."(这个账号自己的额度用完)时, 按额度不足(`rate_limit_error`,非流式为 HTTP 429)结束本轮,原文和重置时间一并带上, magpie 据此让这个账号歇到重置,并改问下一个账号。 + 结尾是 "⚠ Third-party quota reached. Please switch to Gemini models … Resets in 3h22m19s." + (这个账号 Claude 和 GPT-OSS 的额度用完,Gemini 的还在)时也一样结束本轮,magpie 让这个模型 + 歇到重置,改问下一个账号或模型,这个账号的 Gemini 模型照常可用。 结尾是 "⚠ Our servers are experiencing high traffic right now …"(Google 这个模型暂时没有 余量,agy 的重试也都碰上了 503)时,按 `overloaded_error`(非流式为 HTTP 503)结束本轮, 不让账号歇着,magpie 会再试或改问别处。(由 ifccod 发现并移植自他的补丁。) diff --git a/index.mjs b/index.mjs index 033f664..d868382 100644 --- a/index.mjs +++ b/index.mjs @@ -140,8 +140,15 @@ const AGENT_ERROR_CORES = AGENT_ERROR_MARKERS.map((marker) => marker.trim()) // its own that nothing follows. Answered as text, it was the whole reply // and the next account was never asked (@Airan_FS on X, 11-17). const QUOTA_CORE = "⚠ Individual quota reached" -const QUOTA_MARKER = "\n" + QUOTA_CORE -const quotaReached = (detail) => /\bindividual quota reached\b/i.test(detail || "") +// The same ending for the account's quota of the models agy calls third +// party, Claude and GPT-OSS, used up while Gemini's is left: "⚠ Third-party +// quota reached. Please switch to Gemini models or upgrade your subscription +// to increase your limits. Resets in 3h22m19s." It was the whole reply to +// every Claude request once that quota was out (@Airan_FS on X, 11-23). +const THIRD_PARTY_CORE = "⚠ Third-party quota reached" +const QUOTA_CORES = [QUOTA_CORE, THIRD_PARTY_CORE] +const QUOTA_MARKERS = QUOTA_CORES.map((core) => "\n" + core) +const quotaReached = (detail) => /\b(?:individual|third-party) quota reached\b/i.test(detail || "") const CREDITS_CORE = AGENT_ERROR_CORES[2] const VERIFY_CORE = AGENT_ERROR_CORES[5] const DISABLED_CORE = AGENT_ERROR_CORES[6] @@ -202,9 +209,9 @@ const CAP_RETRIES_CORE = "Retries remaining: " const CAP_RETRIES_LINE = /^Retries remaining: ?\d+\.?$/ // agy's lines as they start a reply or a line, with no newline before them: // a chunk that ends on the start of one is held (plugins#1454). -const LINE_CORES = [...AGENT_ERROR_CORES, QUOTA_CORE, BUSY_CORE, ATTEMPT_CORE, RETRY_CORE, NOTICE_CORE] +const LINE_CORES = [...AGENT_ERROR_CORES, ...QUOTA_CORES, BUSY_CORE, ATTEMPT_CORE, RETRY_CORE, NOTICE_CORE] const HOLD_MAX = Math.max( - ...AGENT_ERROR_MARKERS.map((marker) => marker.length), CAP_MARKER.length, CAP_TAIL_CORE.length, QUOTA_MARKER.length, BUSY_MARKER.length, + ...AGENT_ERROR_MARKERS.map((marker) => marker.length), CAP_MARKER.length, CAP_TAIL_CORE.length, ...QUOTA_MARKERS.map((marker) => marker.length), BUSY_MARKER.length, ) - 1 // Opt-in. The minimal agent drops agy's own prompt components (~8,400 input // tokens a model call, against ~500 without them), so the request goes upstream @@ -1853,7 +1860,7 @@ class Turn { if (quota >= 0) return quota for (let keep = Math.min(text.length, HOLD_MAX); keep > 0; keep--) { const tail = text.slice(-keep) - if (AGENT_ERROR_MARKERS.some((marker) => marker.startsWith(tail)) || QUOTA_MARKER.startsWith(tail) || + if (AGENT_ERROR_MARKERS.some((marker) => marker.startsWith(tail)) || QUOTA_MARKERS.some((marker) => marker.startsWith(tail)) || BUSY_MARKER.startsWith(tail) || (keep > 1 && (RETRY_MARKER.startsWith(tail) || ATTEMPT_MARKER.startsWith(tail) || NOTICE_MARKER.startsWith(tail) || CAP_MARKER.startsWith(tail))) || (this.startsLine(text, text.length - keep) && LINE_CORES.some((core) => core.startsWith(tail)))) { @@ -1885,11 +1892,12 @@ class Turn { return at > 0 && text[at - 1] === "\n" && !this.cuts.includes(at) ? at - 1 : at } - // Where agy's quota ending (QUOTA_CORE), or another ending matched by its - // start (BUSY_CORE), starts in text, with the newline before it: a line of - // its own that only whitespace follows, so far. -1 when there is none; one - // more text follows was the model quoting it. - quotaEnding(text, core = QUOTA_CORE) { + // Where agy's quota ending (either of QUOTA_CORES), or another ending + // matched by its start (BUSY_CORE), starts in text, with the newline + // before it: a line of its own that only whitespace follows, so far. -1 + // when there is none; one more text follows was the model quoting it. + quotaEnding(text, core) { + if (!core) return Math.max(...QUOTA_CORES.map((quota) => this.quotaEnding(text, quota))) const at = text.lastIndexOf(core) if (at < 0) return -1 if (!this.startsLine(text, at) || text.slice(at).trimEnd().includes("\n")) return -1 diff --git a/package.json b/package.json index 379a880..6570ea9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-agy-cli-auth", - "version": "0.1.113", + "version": "0.1.115", "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/test/repeat-batch.mjs b/test/repeat-batch.mjs index 1157e58..f5fbdbf 100644 --- a/test/repeat-batch.mjs +++ b/test/repeat-batch.mjs @@ -1494,6 +1494,49 @@ test("the model quoting the Individual quota reached ending with more text after } }) +// @Airan_FS on X (11-23): once the account's Claude quota was used up, +// every Claude request's whole reply was agy's ending for the third-party +// (Claude and GPT-OSS) pool, with Gemini's quota left. +const THIRD_PARTY_LINE = "⚠ Third-party quota reached. Please switch to Gemini models or upgrade your subscription to increase your limits. Resets in 3h22m19s." +const THIRD_PARTY = "\n" + THIRD_PARTY_LINE + "\n" + +test("agy's Third-party quota reached ending fails the turn as a rate limit with its reset", async () => { + for (const chunks of [ + [THIRD_PARTY], + [THIRD_PARTY.slice(0, 9), THIRD_PARTY.slice(9, 33), THIRD_PARTY.slice(33)], + [THIRD_PARTY_LINE], + ]) { + await withKit({}, async (kit) => { + markerAgent(kit, chunks) + const response = await kit.request(baseBody({ metadata: { user_id: "third-party-end" }, + messages: [{ role: "user", content: "hello" }] })) + const text = await response.text() + const error = sseError(text) + assert.equal(error?.type, "rate_limit_error", text) + assert.equal(error.message, "agy bridge: Antigravity quota reached: " + THIRD_PARTY_LINE.replace(/^⚠ /, "")) + assert.ok(!text.includes("⚠"), "no banner reaches the client") + assert.ok(!text.includes("text_delta"), "nothing of it went as the reply") + }) + } + await withKit({}, async (kit) => { + markerAgent(kit, [THIRD_PARTY]) + const response = await kit.request(baseBody({ metadata: { user_id: "third-party-json" }, + messages: [{ role: "user", content: "hello" }], stream: false })) + const body = await response.json() + assert.equal(response.status, 429) + assert.match(body.error.message, /Third-party quota reached\. .*Resets in 3h22m19s\./) + }) + // the model quoting it, with more text after, is the model's + await withKit({}, async (kit) => { + const chunks = ["agy said\n⚠ Third-party quota", " reached. Resets in 1h.\nThat line is agy's, not mine."] + markerAgent(kit, chunks) + const parsed = await readSse(await kit.request(baseBody({ metadata: { user_id: "third-party-quoted" }, + messages: [{ role: "user", content: "what did agy print?" }] }))) + assert.equal(parsed.error, null) + assert.equal(replyText(parsed), chunks.join("")) + }) +}) + // ifccod (opencode-agy-cli-auth FORK.md, 11-18): when every retry met // Google's "no capacity" 503, agy ended the reply with this notice, and the // client got it as the whole answer, a 200 nothing behind magpie retried. diff --git a/test/smoke.mjs b/test/smoke.mjs index 23bb44f..a41b19d 100644 --- a/test/smoke.mjs +++ b/test/smoke.mjs @@ -728,7 +728,7 @@ const legacyModel = "agy-cli/gemini-test-low" const pw = usage.windows?.find(w => !w.model) check("auth.usage exposes measured CLI quota", pw?.used === 40 && pw.pool === "Gemini" && pw.name === "7 days") check("auth.usage preserves explicit cadence and reset", pw?.span === 604800 && pw.resetsAt === "2026-10-27T00:00:00.000Z") - check("auth.usage is display-only and keeps bridge auth", usage.windows?.every(w => w.aside === true) && usage.signIn === "kept") + check("auth.usage sets the pools' windows aside, its models' not, and keeps bridge auth", usage.windows?.every(w => (w.aside === true) === !w.model) && usage.signIn === "kept") check("auth.usage does not invent Google account identity", !usage.user && !usage.plan) const calls = logs().filter(event => event.type === "usage") check("auth.usage uses a separate cleaned workspace", calls.length === 1 && !fs.existsSync(calls[0].cwd)) diff --git a/test/usage.mjs b/test/usage.mjs index d2c3f75..9172fc0 100644 --- a/test/usage.mjs +++ b/test/usage.mjs @@ -88,7 +88,24 @@ test("a live report names on each window the ids the listed catalog serves", () assert.deepEqual(pools.map(w => w.used), [0, 0, 66.394961, 0, 0]) // agy names a family in the description even though it lists no bare id. assert.ok(pools[2].models.includes("gpt-oss-120b")) - assert.ok(result.windows.every(w => w.aside === true)) + // the pools' windows are set aside: they hold their models at a cap + assert.ok(pools.every(w => w.aside === true)) + storeCatalogRows(null) +}) + +// will930128 on X: an Opus 5.5 routing group showed the agy-cli account's +// share as not known, last behind every account known, while its card +// showed Claude & GPT's 5 hours and 7 days. Every window was aside, so +// magpie's routing had none to weigh it by. +test("a model's own window is not set aside, so routing weighs the account by it", () => { + storeCatalogRows(LIVE_MODEL_ROWS) + const result = parseUsageReport(structuredClone(LIVE_REPORT)) + const own = result.windows.filter(w => w.model) + assert.equal(own.length, 6) + assert.ok(own.every(w => !w.aside && w.used !== undefined && w.models.length > 0)) + const opus = own.find(w => w.model === "claude-opus-5-5") + assert.deepEqual([opus.pool, opus.used, opus.aside], ["Claude & GPT", 66.394961, undefined]) + assert.ok(opus.models.includes("claude-opus-5-5-high")) storeCatalogRows(null) }) diff --git a/usage.mjs b/usage.mjs index 59e5ed1..dce8259 100644 --- a/usage.mjs +++ b/usage.mjs @@ -183,6 +183,13 @@ function vendorOf(id, name) { // digit (each Gemini model 1.58104% with Gemini's 7 days). So magpie's // card shows the pools, and "Every model" lists the models, as it did for // the antigravity plugin. +// +// A model's own window is not set aside: it is what routing weighs the +// account by for that model, as the antigravity plugin's were, so a +// routing group of Opus 5.5 reads the account's Claude & GPT share, not +// "not known yet" behind every account known (will930128 on X). The +// pool's own windows stay aside and hold their models at a cap the user +// sets on the pool (magpie's PoolWindow), as the antigravity plugin's did. export function parseUsageReport(value) { let report try { report = typeof value === "string" ? JSON.parse(value) : value } catch { @@ -214,7 +221,7 @@ export function parseUsageReport(value) { const w = { name: period.name, pool, - // This feature displays quota only; it must not change model routing. + // the pool's own: its models' windows stop them (below) aside: true, ...(ids.length ? { models: ids } : {}), ...(known ? { used: Math.round((1 - fraction) * 1e8) / 1e6 } : { display: "Limits not available" }), @@ -234,7 +241,6 @@ export function parseUsageReport(value) { model: f.id, family: vendorOf(f.id, f.name), pool, - aside: true, models: f.ids, used: tightest.used, ...(tightest.span ? { span: tightest.span } : {}),