@magpie-community/opencode-agy-tui-auth 0.1.9 → 0.1.10
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 +1 -1
- package/README.md +1 -1
- package/index.mjs +54 -2
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -8,7 +8,7 @@ Antigravity's models through agy's own interactive mode (its TUI). Each request
|
|
|
8
8
|
|
|
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".
|
|
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
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
1. 安装 [Antigravity CLI](https://antigravity.google/docs/cli)(`agy`),需要 1.5.19 或更新;更旧的 agy 会被拒绝,并提示「Update agy」。
|
|
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/index.mjs
CHANGED
|
@@ -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
|
}
|
|
@@ -1584,7 +1636,7 @@ export const AgyTuiPlugin = async () => ({
|
|
|
1584
1636
|
const agy = findAgy()
|
|
1585
1637
|
if (!home || !agy) return {}
|
|
1586
1638
|
const out = {}
|
|
1587
|
-
for (const m of await
|
|
1639
|
+
for (const m of await cachedModels(agy, home, { refresh: ctx?.refresh === true })) out[m.id] = modelEntry(m)
|
|
1588
1640
|
return out
|
|
1589
1641
|
},
|
|
1590
1642
|
},
|
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.10",
|
|
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",
|