@magpie-community/opencode-agy-tui-auth 0.1.11 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.en.md CHANGED
@@ -9,6 +9,7 @@ Antigravity's models through agy's own interactive mode (its TUI). Each request
9
9
  1. Install the [Antigravity CLI](https://antigravity.google/docs/cli) (`agy`), version 1.5.19 or newer. An older agy is refused with "Update agy", and its sign-in says to run `agy update` (one before 1.5.0 has no `agy acp --login`).
10
10
  2. Install this plugin from magpie's Plugins page, add **Antigravity (agy TUI)** under Providers and pick "Sign in with Google": magpie opens agy's sign-in link, and you paste back the code the page shows.
11
11
  3. The models are the ones `agy models` lists: asked at sign-in and kept in the account's folder, and asked again only when you refresh the list.
12
+ 4. A model `agy models` lists at several thinking levels (`claude-opus-5-5-low`, `-medium`, `-high`) is listed once, as `claude-opus-5-5`, with its levels as variants. A request runs agy at the level the agent asks for (its reasoning effort or thinking level; the nearest the model has, the higher of two as near), and at `high` when it asks none, which is what Antigravity itself starts a model on (or the highest level, for a model without `high`). A level's own id, picked or set in an agent or routing group before, still works and runs that level. A model at one level, and Orchestrator, are listed as agy lists them. The list folds the next time it is asked (sign-in or refresh).
12
13
 
13
14
  Each account has a home of its own (`~/.local/state/magpie-agy-tui/accounts/<id>`), where agy keeps its sign-in as a file. Your own `~/.gemini`, skills and MCP servers are neither used nor changed.
14
15
 
@@ -27,7 +28,7 @@ A request's tools (`tools`, function tools) are given to the model through magpi
27
28
  - The models say a context of 64K tokens (about what fits in agy's message, with agy's own ~10K of instructions), and each response has the usage agy recorded (`usage`: the call's input, cache read and write, and every call's output and thinking), so an agent compacts its conversation before a request that pastes it whole would be cut.
28
29
  - A streamed request gets the answer as the model writes it: agy commits each piece of the reply to its own conversation store (`conversations/<id>.db`), and the plugin reads what is new, read-only. When the store can't be read, the answer comes whole when the turn ends. The model's thinking (agy asks Gemini for it) comes the same way, as `reasoning_content`, before the answer; not streamed, it is the message's `reasoning_content`. The response ends when the answer is whole, without waiting for agy to exit (it sends its own telemetry on the way out).
29
30
  - agy takes seconds to start (signed in with Google, it asks Google for the account, its plan and its models before it takes a message), so each request leaves an agy started, at its prompt, for the next request with the same account, model and tools, which only types its message into it, and a turn that keeps its conversation leaves one with that conversation for the chat's next request. One waits for each such kind (three at most), for 10 minutes at most; `AGY_TUI_SPARES=0` starts each request's agy when it comes instead.
30
- - It needs magpie 0.1.5217 or newer (with `tui-helper` and its tool server); an older magpie is told to update when a request has tools. Not yet tried on Windows.
31
+ - It needs magpie 0.1.5537 or newer (`tui-helper` and its tool server came in 0.1.5217; 0.1.5537 keeps the old per-level model ids working); an older magpie is told which version the magpie running the plugin needs when a request has tools (as a Remote magpie, the server's; a Docker image never updates itself, while its plugins update every hour). Not yet tried on Windows.
31
32
 
32
33
  ## Options (environment)
33
34
 
package/README.md CHANGED
@@ -9,6 +9,7 @@
9
9
  1. 安装 [Antigravity CLI](https://antigravity.google/docs/cli)(`agy`),需要 1.5.19 或更新;更旧的 agy 会被拒绝,并提示「Update agy」,登录时会提示运行 `agy update`(1.5.0 之前的 agy 没有 `agy acp --login`)。
10
10
  2. 在 magpie 的插件页安装本插件,然后在 Providers 里添加 **Antigravity (agy TUI)**,选「使用 Google 登录」:magpie 打开 agy 的登录链接,把页面上显示的代码粘贴回来即可。
11
11
  3. 模型列表来自 `agy models`:登录时问一次,存在账号目录里,之后只在你刷新列表时再问。
12
+ 4. `agy models` 里按思考档位分成几个的模型(`claude-opus-5-5-low`、`-medium`、`-high`)只列一次,即 `claude-opus-5-5`,档位作为它的 variants。请求按 agent 要的档位(reasoning effort 或 thinking level;模型没有这一档时取最接近的,一样近取高的)运行 agy;没说档位时用 `high`,这是 Antigravity 自己默认的档位(没有 `high` 的模型用最高档)。以前选过、或在 agent、路由组里写的带档位 id 依然可用,跑的还是那一档。只有一个档位的模型和 Orchestrator 照 agy 列出的样子列。下次登录或刷新列表时才会合并。
12
13
 
13
14
  每个账号都有自己的 home(`~/.local/state/magpie-agy-tui/accounts/<id>`),agy 的登录信息以文件形式存在那里。你自己的 `~/.gemini`、skills 和 MCP 服务器都不会被用到,也不会被改动。
14
15
 
@@ -27,7 +28,7 @@ agy 运行的是它的默认 agent,不用自定义 agent(`--agent`):agy
27
28
  - 模型宣告的上下文是 64K token(大约是 agy 一条消息能放下的量,加上 agy 自己约 10K 的指令),每次响应都会带上 agy 记录的用量(`usage`:本次调用的输入、缓存读写,以及所有调用的输出和思考),这样 agent 会在整段粘贴的请求被截断之前压缩对话。
28
29
  - 流式请求边生成边返回:agy 每收到模型的一段回答就写进它自己的对话库(`conversations/<id>.db`),插件只读地读出新增的部分发出去;读不到时在一轮结束后返回完整回答。模型的思考(agy 向 Gemini 要了思考内容)同样边生成边作为 `reasoning_content` 返回,在回答之前;非流式时放在消息的 `reasoning_content` 里。回答写完就结束响应,不等 agy 退出(它退出前会先发完自己的遥测)。
29
30
  - agy 启动要好几秒(用 Google 账号登录时,它先向 Google 查询账号、套餐和模型,然后才接收消息),所以每个请求都会为下一个账号、模型和工具相同的请求预先启动一个 agy,停在输入框;下一个请求来了只需输入消息。保留了会话的一轮,还会为这段对话的下一个请求预先启动一个带着这个会话的 agy。每种组合最多留一个(总共最多三个),最多等 10 分钟;设置 `AGY_TUI_SPARES=0` 就改回请求来了才启动 agy。
30
- - 需要 magpie 0.1.5217 或更新(带 `tui-helper` 及其工具服务器);magpie 太旧时,带工具的请求会提示更新 magpie。Windows 尚未测试。
31
+ - 需要 magpie 0.1.5537 或更新(`tui-helper` 及其工具服务器从 0.1.5217 起有;0.1.5537 让按档位区分的旧模型 id 继续可用);magpie 太旧时,带工具的请求会说明运行这个插件的 magpie 需要哪个版本(作为远程 magpie 使用时是服务器上的那个;Docker 镜像不会自己更新,插件却每小时更新)。Windows 尚未测试。
31
32
 
32
33
  ## 选项(环境变量)
33
34
 
package/efforts.mjs ADDED
@@ -0,0 +1,119 @@
1
+ // One model for each of Antigravity's models, its efforts as variants.
2
+ //
3
+ // `agy models` lists a model once for each thinking level it runs at:
4
+ // claude-opus-5-5-low "Claude Opus 5.5 (Low)" and claude-opus-5-5-high
5
+ // "Claude Opus 5.5 (High)". Listed as they are, a picker showed each model
6
+ // three times over (baranwang on X). So a model agy lists at two levels or
7
+ // more is listed once, by the id without the level (claude-opus-5-5), with
8
+ // the levels as its variants, and a request for it runs agy at the level the
9
+ // agent asks for (foldModels, agyModelOf). The levels' own ids stay the
10
+ // model's (former): a pick, a routing group or an agent left on
11
+ // claude-opus-5-5-low is still served, by agy at that level.
12
+ //
13
+ // A model agy lists at one level (gpt-oss-120b-medium) is listed as it is,
14
+ // and so is one whose id without the level agy lists too, and Orchestrator,
15
+ // whose Carbon and Argon are planners, not levels.
16
+
17
+ export const EFFORT_ORDER = ["minimal", "low", "medium", "high", "xhigh", "max"]
18
+ const LEVEL = /-(minimal|low|medium|high|xhigh|max)$/i
19
+ const LEVEL_NAME = /\s*\((minimal|low|medium|high|xhigh|max)\)\s*$/i
20
+
21
+ function isOrchestrator(m) {
22
+ return /orchestrator/i.test(m.id) || /^Orchestrator\b/i.test(m.name ?? "")
23
+ }
24
+
25
+ // foldModels is list (`agy models`, parseModels) with each model agy lists
26
+ // at two levels or more as one: { id, name, variants, former } where
27
+ // variants are its levels, least first, and former the ids it was listed
28
+ // by. routes says, for each such model, the id of each level and the one
29
+ // run when the request names none (defaultEffort).
30
+ //
31
+ // The default is high, or the highest level there is without it: what
32
+ // Antigravity itself starts on (its model config's defaultAgentModelId is
33
+ // gemini-3.8-flash-high, and its Recommended list leads each model with
34
+ // its -high), and what agy-cli and magpie's own Antigravity ran a model
35
+ // named without its level at.
36
+ export function foldModels(list) {
37
+ const rows = Array.isArray(list) ? list.filter((m) => m && typeof m.id === "string" && m.id) : []
38
+ const ids = new Set(rows.map((m) => m.id))
39
+ const families = new Map()
40
+ for (const m of rows) {
41
+ const level = LEVEL.exec(m.id)
42
+ if (!level || isOrchestrator(m)) continue
43
+ const id = m.id.slice(0, level.index)
44
+ if (!families.has(id)) families.set(id, [])
45
+ families.get(id).push({ ...m, effort: level[1].toLowerCase() })
46
+ }
47
+ // A name that says another level than its id isn't taken for either:
48
+ // Antigravity's own config has gemini-3.5-flash-low named "Gemini 3.5
49
+ // Flash (Medium)" and gemini-3.5-flash-extra-low "(Low)" (magpie's
50
+ // testdata/antigravity-models-2026-10-20.json), so such a model is
51
+ // listed as agy lists it.
52
+ const saysOther = (l) => { const n = LEVEL_NAME.exec(l.name ?? ""); return n && n[1].toLowerCase() !== l.effort }
53
+ for (const [id, levels] of families) {
54
+ if (levels.length < 2 || new Set(levels.map((l) => l.effort)).size !== levels.length || ids.has(id) || levels.some(saysOther)) families.delete(id)
55
+ }
56
+ const models = []
57
+ const routes = new Map()
58
+ const familyOf = new Map()
59
+ for (const [id, levels] of families) for (const l of levels) familyOf.set(l.id, id)
60
+ for (const m of rows) {
61
+ const id = familyOf.get(m.id)
62
+ if (!id) {
63
+ models.push({ id: m.id, name: m.name })
64
+ continue
65
+ }
66
+ if (routes.has(id)) continue
67
+ const levels = [...families.get(id)].sort((a, b) => EFFORT_ORDER.indexOf(a.effort) - EFFORT_ORDER.indexOf(b.effort))
68
+ const efforts = levels.map((l) => l.effort)
69
+ const defaultEffort = efforts.includes("high") ? "high" : efforts.at(-1)
70
+ const named = levels.find((l) => l.effort === defaultEffort)
71
+ const name = String(named.name ?? "").replace(LEVEL_NAME, "").trim()
72
+ models.push({ id, name: name && name !== named.id ? name : id, variants: efforts, former: levels.map((l) => l.id) })
73
+ routes.set(id, { byEffort: new Map(levels.map((l) => [l.effort, l.id])), efforts, defaultEffort })
74
+ }
75
+ return { models, routes }
76
+ }
77
+
78
+ // effortOf is the level a request asks for, "" for none: what magpie says
79
+ // the agent asked for (X-Magpie-Effort, said) first, then the body's own.
80
+ // Thinking turned off ("none", "off", thinking disabled) asks for the
81
+ // least there is.
82
+ export function effortOf(body, said = "") {
83
+ const words = [said, body?.reasoning_effort, body?.reasoningEffort, body?.reasoning?.effort]
84
+ for (const w of words) {
85
+ const e = String(w ?? "").trim().toLowerCase()
86
+ if (!e) continue
87
+ if (e === "none" || e === "off") return "minimal"
88
+ if (e === "ultra") return "max"
89
+ if (EFFORT_ORDER.includes(e)) return e
90
+ }
91
+ if (body?.thinking?.type === "disabled") return "minimal"
92
+ return ""
93
+ }
94
+
95
+ // closestEffort is the level of efforts nearest effort, the higher of two
96
+ // as near.
97
+ export function closestEffort(effort, efforts) {
98
+ const at = EFFORT_ORDER.indexOf(effort)
99
+ let best = efforts[0]
100
+ for (const e of efforts.slice(1)) {
101
+ const d = Math.abs(EFFORT_ORDER.indexOf(e) - at)
102
+ const bd = Math.abs(EFFORT_ORDER.indexOf(best) - at)
103
+ if (d < bd || (d === bd && EFFORT_ORDER.indexOf(e) > EFFORT_ORDER.indexOf(best))) best = e
104
+ }
105
+ return best
106
+ }
107
+
108
+ // agyModelOf is the id agy is run with for a request for model: a level's
109
+ // own id as it is (a pick or setting from before the levels were one
110
+ // model), and a model listed with its levels as variants at the level the
111
+ // request asks for, or its default. list is the account's `agy models` as
112
+ // kept; with none kept, model is run as it is.
113
+ export function agyModelOf(model, list, body, said = "") {
114
+ if (!model || !Array.isArray(list) || list.some((m) => m?.id === model)) return model
115
+ const route = foldModels(list).routes.get(model)
116
+ if (!route) return model
117
+ const asked = effortOf(body, said)
118
+ return route.byEffort.get(asked ? closestEffort(asked, route.efforts) : route.defaultEffort)
119
+ }
package/index.mjs CHANGED
@@ -8,6 +8,7 @@ import { writeDefaultAgentFiles } from "./default-agent.mjs"
8
8
  import { agyTooOld, MIN_AGY_VERSION, oldAgyError } from "./agy-version.mjs"
9
9
  import { liveReply, callsAfter, usageOf, lastStep } from "./live.mjs"
10
10
  import { mcpToolsOf } from "./tools.mjs"
11
+ import { agyModelOf, foldModels } from "./efforts.mjs"
11
12
 
12
13
  // agy-tui: Antigravity's models through agy's own interactive mode. Each
13
14
  // request starts the real `agy` TUI in a terminal magpie gives it (`magpie
@@ -614,6 +615,28 @@ export function screenTail(screen, n = 8) {
614
615
  return lines.slice(-n).join("\n")
615
616
  }
616
617
 
618
+ // The magpie each part of this plugin needs: tui-helper (and MAGPIE_EXE)
619
+ // came in 0.1.5027, its tools line in 0.1.5217 (package.json's
620
+ // engines.magpie). A magpie isn't updated with its plugins everywhere: a
621
+ // Docker image, or a server's `magpie serve`, keeps the version it was
622
+ // started with while plugins update every hour, so the message says which
623
+ // magpie and which version (earayu on X: a server reached as a Remote
624
+ // magpie, told only "update magpie").
625
+ const TUI_HELPER_MAGPIE = "0.1.5027"
626
+ const TOOLS_MAGPIE = "0.1.5217"
627
+
628
+ // noToolsHelper is whether what tui-helper said is a tui-helper from
629
+ // before its tools line: it asks for start first, and names no tools
630
+ export function noToolsHelper(said) {
631
+ return typeof said === "string" && said.includes('the first line is {"start"') && !said.includes('"tools"')
632
+ }
633
+
634
+ // oldMagpie is the error for a magpie older than version, for what that
635
+ // version is the first to do
636
+ export function oldMagpie(version, what) {
637
+ return `the magpie running this plugin is older than ${version}, the first that ${what}: update that magpie (on a server you reach as a Remote magpie, the server's own; in Docker, pull ghcr.io/yetone/magpie:latest and start the container again)`
638
+ }
639
+
617
640
  class Failure extends Error {
618
641
  constructor(status, message, headers) {
619
642
  super(message)
@@ -765,7 +788,7 @@ export async function closeSpares() {
765
788
  // prompt, media, signal, messages }) waits until it is at its prompt,
766
789
  // types the request in and resolves with the turn
767
790
  async function launch({ agy, home, model, tools = [], helper = process.env.MAGPIE_EXE, conversation = null }) {
768
- if (!helper) throw new Failure(501, "this magpie has no tui-helper: update magpie")
791
+ if (!helper) throw new Failure(501, oldMagpie(TUI_HELPER_MAGPIE, "has a terminal for agy"))
769
792
  settleHome(home)
770
793
  const withTools = tools.length > 0
771
794
  const ws = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "agy-tui-")))
@@ -954,6 +977,9 @@ async function launch({ agy, home, model, tools = [], helper = process.env.MAGPI
954
977
  await waitFor("tool server", () => mcp, START_MS)
955
978
  } catch (error) {
956
979
  if (error.status === 499) throw error
980
+ // a tui-helper from before tools turns the tools line away as
981
+ // not its first line: the magpie running this plugin is too old
982
+ if (noToolsHelper(errorLine)) throw new Failure(501, oldMagpie(TOOLS_MAGPIE, "gives agy the agent's tools"))
957
983
  throw new Failure(501, `this magpie's terminal can't give agy tools (${errorLine || error.message}): update magpie`)
958
984
  }
959
985
  fs.writeFileSync(path.join(ownHome, ".gemini", "config", "mcp_config.json"), JSON.stringify(mcpConfig(mcp, tools)), { mode: 0o600 })
@@ -1504,6 +1530,10 @@ export async function handle(home, input, init = {}) {
1504
1530
  const signal = init.signal ?? input?.signal
1505
1531
  const id = `chatcmpl-${randomBytes(12).toString("hex")}`
1506
1532
  const model = String(body.model ?? "")
1533
+ // the level of a model listed with its levels as variants, as the
1534
+ // agent asked (efforts.mjs); a level's own id is run as it is
1535
+ const said = new Headers(init.headers ?? (input instanceof Request ? input.headers : undefined) ?? {}).get("x-magpie-effort") ?? ""
1536
+ const agyModel = home ? agyModelOf(model, (modelLists.get(home) ?? readModelList(home))?.list, body, said) : model
1507
1537
  // the result of a call a turn waits on goes on with that turn
1508
1538
  const last = Array.isArray(body.messages) ? body.messages.at(-1) : null
1509
1539
  if (last?.role === "tool") {
@@ -1536,11 +1566,11 @@ export async function handle(home, input, init = {}) {
1536
1566
  const tools = mcpToolsOf(body)
1537
1567
  // the chat's conversation, kept from its last answer, goes on with the
1538
1568
  // new messages alone; any other is typed in whole
1539
- carried = (await agyHelp(agy)).includes("--conversation") ? await carriedOn(home, body.messages, { agy, model, tools }) : null
1569
+ carried = (await agyHelp(agy)).includes("--conversation") ? await carriedOn(home, body.messages, { agy, model: agyModel, tools }) : null
1540
1570
  const { prompt, media } = carried ?? turnOf(body.messages)
1541
1571
  // agy attaches a video for any model, but only Gemini's see one
1542
1572
  if (media.some((m) => kindOf(m.type) === "video") && !/^gemini-/.test(model)) throw refuse(`${model || "this model"} takes no video; a Gemini model does`)
1543
- turn = await startTurn({ agy, home, model, prompt, media, tools, signal, conversation: carried?.id ?? null, messages: body.messages })
1573
+ turn = await startTurn({ agy, home, model: agyModel, prompt, media, tools, signal, conversation: carried?.id ?? null, messages: body.messages })
1544
1574
  } catch (error) {
1545
1575
  // a conversation taken for a turn that never began is in a state
1546
1576
  // nothing knows
@@ -1552,6 +1582,11 @@ export async function handle(home, input, init = {}) {
1552
1582
 
1553
1583
  // ---- the plugin
1554
1584
 
1585
+ // modelEntry is a model of foldModels': one agy lists at several levels
1586
+ // has them as its variants, and says the ids it was listed by before
1587
+ // (former), so magpie keeps a pick, group or agent setting of one as the
1588
+ // model's and still sends it here under that id. A variant sends its level
1589
+ // as reasoning_effort, for OpenCode, which says no X-Magpie-Effort.
1555
1590
  export function modelEntry(m) {
1556
1591
  return {
1557
1592
  id: m.id,
@@ -1559,6 +1594,7 @@ export function modelEntry(m) {
1559
1594
  npm: NPM,
1560
1595
  api: { id: m.id, url: "agy-tui://local", npm: NPM },
1561
1596
  limit: { context: CONTEXT, output: 65_536 },
1597
+ ...(m.variants?.length ? { reasoning: true, variants: Object.fromEntries(m.variants.map((e) => [e, { reasoningEffort: e }])), former: m.former ?? [] } : {}),
1562
1598
  // Gemini's and Claude's see the images agy attaches, as agy-cli says,
1563
1599
  // and Gemini's the videos too
1564
1600
  ...(/^(?:gemini-|claude-)/.test(m.id) ? { capabilities: { attachment: true, input: { text: true, image: true, video: m.id.startsWith("gemini-"), audio: false, pdf: false }, output: { text: true } } } : {}),
@@ -1641,7 +1677,7 @@ export const AgyTuiPlugin = async () => ({
1641
1677
  const agy = findAgy()
1642
1678
  if (!home || !agy) return {}
1643
1679
  const out = {}
1644
- for (const m of await cachedModels(agy, home, { refresh: ctx?.refresh === true })) out[m.id] = modelEntry(m)
1680
+ for (const m of foldModels(await cachedModels(agy, home, { refresh: ctx?.refresh === true })).models) out[m.id] = modelEntry(m)
1645
1681
  return out
1646
1682
  },
1647
1683
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magpie-community/opencode-agy-tui-auth",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Magpie/OpenCode model provider that runs Antigravity's models through agy's own interactive mode: each request is typed into the real agy TUI and its answer streamed from agy's own conversation store as the model writes it",
5
5
  "type": "module",
6
6
  "main": "./opencode.mjs",
@@ -19,6 +19,7 @@
19
19
  "re2-pattern.mjs",
20
20
  "array-items.mjs",
21
21
  "tool-budget.mjs",
22
+ "efforts.mjs",
22
23
  "opencode.mjs",
23
24
  "opencode2.mjs",
24
25
  "README.md",
@@ -44,7 +45,7 @@
44
45
  "test": "bun test"
45
46
  },
46
47
  "engines": {
47
- "magpie": ">=0.1.5217"
48
+ "magpie": ">=0.1.5537"
48
49
  },
49
50
  "magpie": {
50
51
  "maxConcurrency": 4