@magpie-community/opencode-agy-tui-auth 0.1.9 → 0.1.11
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 +2 -2
- package/README.md +2 -2
- package/agy-version.mjs +16 -0
- package/index.mjs +60 -3
- package/login.mjs +7 -3
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -6,9 +6,9 @@ Antigravity's models through agy's own interactive mode (its TUI). Each request
|
|
|
6
6
|
|
|
7
7
|
## Use
|
|
8
8
|
|
|
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".
|
|
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
|
-
3. The models are the ones `agy models` lists.
|
|
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
12
|
|
|
13
13
|
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
14
|
|
package/README.md
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
|
|
7
7
|
## 用法
|
|
8
8
|
|
|
9
|
-
1. 安装 [Antigravity CLI](https://antigravity.google/docs/cli)(`agy`),需要 1.5.19 或更新;更旧的 agy 会被拒绝,并提示「Update agy
|
|
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
|
-
3. 模型列表来自 `agy models
|
|
11
|
+
3. 模型列表来自 `agy models`:登录时问一次,存在账号目录里,之后只在你刷新列表时再问。
|
|
12
12
|
|
|
13
13
|
每个账号都有自己的 home(`~/.local/state/magpie-agy-tui/accounts/<id>`),agy 的登录信息以文件形式存在那里。你自己的 `~/.gemini`、skills 和 MCP 服务器都不会被用到,也不会被改动。
|
|
14
14
|
|
package/agy-version.mjs
CHANGED
|
@@ -14,3 +14,19 @@ export function agyTooOld(version) {
|
|
|
14
14
|
}
|
|
15
15
|
return null
|
|
16
16
|
}
|
|
17
|
+
|
|
18
|
+
// agy 1.5.0 added `agy acp --login`, the Google sign-in magpie runs. An
|
|
19
|
+
// agy before it has no acp and takes "acp" for a prompt: `Error: unexpected
|
|
20
|
+
// argument "acp".` then `Prompts are read only from -p/--print,
|
|
21
|
+
// -i/--prompt-interactive, or stdin, so this argument would have been
|
|
22
|
+
// ignored.` (wangmaoning on X, Intel Mac).
|
|
23
|
+
export const LOGIN_AGY_VERSION = "1.5.0"
|
|
24
|
+
|
|
25
|
+
// oldAgyError is what a sign-in on an agy too old for this plugin says:
|
|
26
|
+
// which agy, the version it needs, and the command that updates it. why is
|
|
27
|
+
// what was tried already, if anything.
|
|
28
|
+
export function oldAgyError(version = "", file = "", why = "") {
|
|
29
|
+
const which = `${version ? `agy ${version}` : "this agy"}${file ? ` (${file})` : ""}`
|
|
30
|
+
return `${which} is too old to sign in from magpie: the sign-in runs "agy acp --login", which came in agy ${LOGIN_AGY_VERSION}, ` +
|
|
31
|
+
`and this plugin needs agy ${MIN_AGY_VERSION} or newer.${why ? ` ${why}.` : ""} Run "agy update" in a terminal, then sign in again.`
|
|
32
|
+
}
|
package/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import os from "node:os"
|
|
|
5
5
|
import path from "node:path"
|
|
6
6
|
import { startLogin } from "./login.mjs"
|
|
7
7
|
import { writeDefaultAgentFiles } from "./default-agent.mjs"
|
|
8
|
-
import { agyTooOld, MIN_AGY_VERSION } from "./agy-version.mjs"
|
|
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
11
|
|
|
@@ -261,6 +261,58 @@ async function listModels(agy, home) {
|
|
|
261
261
|
return models
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
+
// The account's list, as `agy models` gave it last (Discord, 12-03: an
|
|
265
|
+
// Antigravity account was banned with no agent using it). An idle account
|
|
266
|
+
// sends Google nothing of its own, so the list is asked at the sign-in, on
|
|
267
|
+
// the user's refresh (ctx.refresh), or when there is none, and kept in the
|
|
268
|
+
// account's home across restarts (magpie-models.json, written to a temp
|
|
269
|
+
// file renamed over it). A file that can't be read keeps the last good read.
|
|
270
|
+
const MODELS_FILE = "magpie-models.json"
|
|
271
|
+
const modelLists = new Map()
|
|
272
|
+
|
|
273
|
+
function readModelList(home) {
|
|
274
|
+
try {
|
|
275
|
+
const saved = JSON.parse(fs.readFileSync(path.join(home, MODELS_FILE), "utf8"))
|
|
276
|
+
const list = Array.isArray(saved?.list)
|
|
277
|
+
? saved.list.filter((m) => typeof m?.id === "string" && m.id && typeof m.name === "string").map(({ id, name }) => ({ id, name }))
|
|
278
|
+
: []
|
|
279
|
+
if (!list.length) return modelLists.get(home) ?? null
|
|
280
|
+
const read = { list, fetchedAt: Number.isFinite(saved.fetchedAt) ? saved.fetchedAt : 0 }
|
|
281
|
+
modelLists.set(home, read)
|
|
282
|
+
return read
|
|
283
|
+
} catch {
|
|
284
|
+
return modelLists.get(home) ?? null
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function saveModelList(home, list) {
|
|
289
|
+
const kept = { list, fetchedAt: Date.now() }
|
|
290
|
+
modelLists.set(home, kept)
|
|
291
|
+
const file = path.join(home, MODELS_FILE)
|
|
292
|
+
const temp = `${file}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`
|
|
293
|
+
try {
|
|
294
|
+
fs.writeFileSync(temp, JSON.stringify({ version: 1, ...kept }) + "\n", { mode: 0o600 })
|
|
295
|
+
fs.renameSync(temp, file)
|
|
296
|
+
} catch {
|
|
297
|
+
fs.rmSync(temp, { force: true })
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// cachedModels is the account's list: the one kept, unless refresh (or
|
|
302
|
+
// none is kept) asks agy. A refresh that fails gives the kept list.
|
|
303
|
+
export async function cachedModels(agy, home, { refresh = false } = {}) {
|
|
304
|
+
const kept = modelLists.get(home) ?? readModelList(home)
|
|
305
|
+
if (kept && !refresh) return kept.list
|
|
306
|
+
try {
|
|
307
|
+
const list = await listModels(agy, home)
|
|
308
|
+
saveModelList(home, list)
|
|
309
|
+
return list
|
|
310
|
+
} catch (error) {
|
|
311
|
+
if (kept) return kept.list
|
|
312
|
+
throw error
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
264
316
|
function lastLine(text) {
|
|
265
317
|
return String(text ?? "").split(/\r?\n/).map((l) => l.trim()).filter(Boolean).at(-1) ?? ""
|
|
266
318
|
}
|
|
@@ -1534,7 +1586,7 @@ function signIn(agy) {
|
|
|
1534
1586
|
const done = await login.finish(code, { signal: opts.signal })
|
|
1535
1587
|
if (done.error) return fail(done.error)
|
|
1536
1588
|
try {
|
|
1537
|
-
await listModels(agy, account.home)
|
|
1589
|
+
saveModelList(account.home, await listModels(agy, account.home))
|
|
1538
1590
|
} catch (error) {
|
|
1539
1591
|
return fail(`agy signed in, but ${error.message}`)
|
|
1540
1592
|
}
|
|
@@ -1557,6 +1609,11 @@ export const AgyTuiPlugin = async () => ({
|
|
|
1557
1609
|
authorize: async () => {
|
|
1558
1610
|
const agy = findAgy()
|
|
1559
1611
|
if (!agy) return { type: "failed", error: `agy CLI not found. Install Antigravity CLI: ${AGY_MANUAL}` }
|
|
1612
|
+
// an agy too old for this plugin (one before 1.5.0 has no
|
|
1613
|
+
// `agy acp --login`) says what to run, not agy's own complaint
|
|
1614
|
+
// about the arguments (wangmaoning on X)
|
|
1615
|
+
const version = await agyVersion(agy)
|
|
1616
|
+
if (version && agyTooOld(version)) return { type: "failed", error: oldAgyError(version, agy) }
|
|
1560
1617
|
return signIn(agy)
|
|
1561
1618
|
},
|
|
1562
1619
|
},
|
|
@@ -1584,7 +1641,7 @@ export const AgyTuiPlugin = async () => ({
|
|
|
1584
1641
|
const agy = findAgy()
|
|
1585
1642
|
if (!home || !agy) return {}
|
|
1586
1643
|
const out = {}
|
|
1587
|
-
for (const m of await
|
|
1644
|
+
for (const m of await cachedModels(agy, home, { refresh: ctx?.refresh === true })) out[m.id] = modelEntry(m)
|
|
1588
1645
|
return out
|
|
1589
1646
|
},
|
|
1590
1647
|
},
|
package/login.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { spawn } from "node:child_process"
|
|
2
2
|
import os from "node:os"
|
|
3
|
+
import { oldAgyError } from "./agy-version.mjs"
|
|
3
4
|
|
|
4
5
|
// The Google sign-in, run by agy itself (from the agy-cli plugin's
|
|
5
6
|
// login.mjs): `agy acp --login` prints Google's sign-in link, then reads
|
|
@@ -12,6 +13,9 @@ export const LOGIN_START_MS = 30_000
|
|
|
12
13
|
export const LOGIN_FINISH_MS = 60_000
|
|
13
14
|
|
|
14
15
|
const SIGN_IN_LINK = /https:\/\/accounts\.google\.com\/[^\s"'<>]+/
|
|
16
|
+
// An agy with no `agy acp --login` (before 1.5.0): one older still has no
|
|
17
|
+
// acp and takes "acp" for a prompt, a later one prints acp's usage.
|
|
18
|
+
const NO_LOGIN = /Prompts are read only from|unexpected argument "acp|Usage:/
|
|
15
19
|
|
|
16
20
|
let pending = null
|
|
17
21
|
|
|
@@ -77,9 +81,9 @@ export function startLogin(agy, env, { waitMs = LOGIN_WAIT_MS, startMs = LOGIN_S
|
|
|
77
81
|
if (pending === child) pending = null
|
|
78
82
|
exited = exited ?? { code }
|
|
79
83
|
for (const w of waiters.splice(0)) w()
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
84
|
+
// an agy too old to sign in says so, with what to run, not its own
|
|
85
|
+
// complaint about the arguments
|
|
86
|
+
if (NO_LOGIN.test(out) && !SIGN_IN_LINK.test(out)) settle({ error: oldAgyError("", agy) })
|
|
83
87
|
settle({ error: `agy exited before printing a sign-in link${lastLine(out) ? `: ${lastLine(out)}` : ""}` })
|
|
84
88
|
})
|
|
85
89
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magpie-community/opencode-agy-tui-auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
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",
|