magpie-gemini-web 0.9.0 → 0.10.0
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 +7 -2
- package/README.md +7 -2
- package/docs/studio-release.md +19 -7
- package/index.mjs +17 -10
- package/lib/backend-release.json +14 -14
- package/lib/cleanup-detached.cjs +61 -0
- package/lib/cleanup.mjs +357 -0
- package/lib/native.mjs +165 -0
- package/lib/studio-native.mjs +276 -8
- package/lib/studio-release.json +19 -19
- package/lib/studio.mjs +18 -13
- package/lib/usage.mjs +23 -13
- package/package.json +4 -1
- package/patches/argon.patch +56 -19
- package/patches/studio-0.2.19-managed-config.patch +13 -10
- package/scripts/backend.mjs +15 -2
- package/scripts/studio-managed-smoke.mjs +3 -1
- package/scripts/studio.mjs +17 -5
package/README.en.md
CHANGED
|
@@ -21,7 +21,7 @@ The plugin provides two independent providers that can be used individually or t
|
|
|
21
21
|
| **Image generation** | Nano Banana models, for Magpie's image generation (Magpie v0.1.2075+, see below) | Not supported |
|
|
22
22
|
| **Sign-in method** | Sign in directly in an isolated popup browser window | Copy `cookie` from a private/incognito window |
|
|
23
23
|
| **Usage cards** | Shows models currently on cooldown and recovery times | Syncs **5-hour** & **weekly** usage and reset times from the web |
|
|
24
|
-
| **Local backend** | AIStudio2API (`v0.
|
|
24
|
+
| **Local backend** | AIStudio2API (`v0.3.0`) | gemini-web2api-go (`4.27.0-magpie.2` optimized build) |
|
|
25
25
|
|
|
26
26
|
---
|
|
27
27
|
|
|
@@ -152,6 +152,7 @@ When a plugin error asks you to run a command, it includes the full ready-to-cop
|
|
|
152
152
|
| :--- | :--- |
|
|
153
153
|
| `npm run studio:status` | Show local service and account status |
|
|
154
154
|
| `npm run studio:start` / `studio:stop` | Start / stop the local service |
|
|
155
|
+
| `npm run studio:clean` | Stop the service and remove downloaded binaries & Camoufox (keeps accounts & config) |
|
|
155
156
|
| `npm run studio:login` | Add a Google account |
|
|
156
157
|
| `npm run studio:relogin -- [<account>]` | Re-authenticate an expired account (argument optional if only one) |
|
|
157
158
|
| `npm run studio:install -- --archive <file>` | Offline install from a pre-downloaded archive |
|
|
@@ -169,6 +170,9 @@ When a plugin error asks you to run a command, it includes the full ready-to-cop
|
|
|
169
170
|
- Both backends listen on `127.0.0.1` only. Cookies and sessions remain on your machine; Magpie stores only a locally generated API key.
|
|
170
171
|
- **Gemini Web data directory:** `~/.local/share/magpie-gemini-web` (override with `GEMINI_WEB_DATA_DIR`), logs at `backend.log`. Supports macOS, Linux, and Windows (x64 / arm64).
|
|
171
172
|
- **AI Studio data directory:** `~/.local/share/magpie-ai-studio` (override with `AI_STUDIO_DATA_DIR`), logs at `backend.log` (rotated on next start after exceeding 10 MB). Uses port 2048 by default (or picks a free port and saves it in `config.json`). Supports macOS, Linux (x64 / arm64), and Windows x64.
|
|
173
|
+
- **Uninstalling & cleaning downloaded assets:** Removing the plugin in Magpie (or running `npm run studio:clean` / `npm run backend:clean`) stops the local services and deletes the downloaded `AIStudio2API`, `Camoufox`, and `gemini-web2api-go` binaries and archives.
|
|
174
|
+
- `auth/`, `gemini.db`, `config.json`, `.env`, and `secrets.json` are kept so reinstalling the plugin or sending a new request restores the backend on demand without signing in or importing cookies again; to prevent automatic reinstallation permanently, remove the sign-in in Magpie or delete `config.json` / `secrets.json`.
|
|
175
|
+
- Default data directories are shared per OS user; set separate `AI_STUDIO_DATA_DIR` and `GEMINI_WEB_DATA_DIR` when running multiple isolated Magpie config directories so removing the plugin in one does not clean another's shared binaries.
|
|
172
176
|
- Gemini Web takes at most 2 requests at once per sign-in (AI Studio 1), adjustable in Magpie's provider settings. Google account rate-limiting or flagging cannot be completely ruled out—use at your own risk.
|
|
173
177
|
|
|
174
178
|
**AI Studio upgrades and model selection:**
|
|
@@ -181,10 +185,11 @@ When a plugin error asks you to run a command, it includes the full ready-to-cop
|
|
|
181
185
|
- When stopped, a replaced executable is restored from the verified pinned archive; failed verification never launches the replacement. Existing account and runtime data files are kept, but **an older backend may not read data migrated by a newer version**. Before manually downgrading, stop the service and back up the entire data directory, including `auth/` and `runtime/requests.db`. If data migration is known to have occurred, update the plugin to match the newer backend.
|
|
182
186
|
- The backend's base request deadline and the plugin's default response/stream-idle timeout are 30 minutes (override via `studio.requestTimeoutMs`). This allows long non-streaming replies to finish collecting on the server. A stalled backend can also take 30 minutes to time out, and its single worker can hold up later requests. Cancel a request or choose a shorter timeout when needed; shorter limits can interrupt valid long replies. Upstream controls deadline scaling for automatic continuation.
|
|
183
187
|
- Source review of the locally installed Magpie `v0.1.1285` (`d783df46`) found no shorter fixed total timeout on this plugin's generation path: `Provider.Do → plugin.Fetch → loader.fetch` bypasses the ordinary HTTP transport's 10-minute response-header timeout. The gateway's 5-minute `IdleTimeout` applies between requests. Clients or reverse proxies can impose shorter limits; this was not a 30-minute end-to-end waiting test.
|
|
188
|
+
- Deep Research models (`deep-research-preview-04-2026`, `deep-research-max-preview-04-2026`) are supported: listed when signed in with a Google AI Pro / Ultra account; the backend adapts asynchronous Interactions tasks onto `/v1/chat/completions` streaming (including reasoning and built-in server-side search), without client `tool_call` (Function Calling) or `temperature`.
|
|
184
189
|
- Models with `-build` or `assistant_route` are filtered out: they inject the Build coding assistant's own system prompt and are not offered as ordinary Agent models. Refresh with `magpie provider models ai-studio` after upgrading.
|
|
185
190
|
|
|
186
191
|
**Gemini Web optimized backend upgrades & rollback:**
|
|
187
|
-
- One-click setup uses [4.27.0-magpie.
|
|
192
|
+
- One-click setup uses [4.27.0-magpie.2](https://github.com/BUKOWSKIREAL/magpie-gemini-web/releases/tag/backend-v4.27.0-magpie.2) by default (built from pinned upstream v4.27.0 with XSRF caching, request cancellation propagation, early tool-call completion, and Argon model verification). Chat requests are timed by silence: while Google queues a request it sends a heartbeat every 60 s, and the backend waits through it for the first words. A try is given up, and retried, only after Google has sent nothing for `request_timeout_sec` (180 s by default), so a long reply that keeps coming is never cut off either.
|
|
188
193
|
- **Upgrading:** Running backends are not interrupted automatically. Stop the existing process (PID in `backend.pid` inside the data directory); the next Magpie launch or request will upgrade the binary while preserving config and cookies.
|
|
189
194
|
- **Rollback to upstream / restore optimized build** (run in the plugin directory after stopping the backend):
|
|
190
195
|
```bash
|
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
| **图片生成** | Nano Banana 系列模型,供 Magpie 的图片生成使用(需要 Magpie v0.1.2075+,见下文) | 不支持 |
|
|
22
22
|
| **登录方式** | 弹出独立浏览器窗口直接登录 Google | 用无痕窗口登录并复制 `cookie` |
|
|
23
23
|
| **额度卡片** | 显示冷却中的模型与恢复时间 | 同步网页版 **5 小时** 与 **每周** 用量及重置时间 |
|
|
24
|
-
| **本地后端** | AIStudio2API (`v0.
|
|
24
|
+
| **本地后端** | AIStudio2API (`v0.3.0`) | gemini-web2api-go (`4.27.0-magpie.2` 优化版) |
|
|
25
25
|
|
|
26
26
|
---
|
|
27
27
|
|
|
@@ -152,6 +152,7 @@ magpie plugin options magpie-gemini-web '{"studio":{"proxy":"http://127.0.0.1:78
|
|
|
152
152
|
| :--- | :--- |
|
|
153
153
|
| `npm run studio:status` | 查看本地服务与账号状态 |
|
|
154
154
|
| `npm run studio:start` / `studio:stop` | 启动 / 停止本地服务 |
|
|
155
|
+
| `npm run studio:clean` | 停止服务并清理已下载的后端与 Camoufox 浏览器(保留账号与配置) |
|
|
155
156
|
| `npm run studio:login` | 添加 Google 账号 |
|
|
156
157
|
| `npm run studio:relogin -- [<账号>]` | 重新登录过期账号(仅一个账号时可省略参数) |
|
|
157
158
|
| `npm run studio:install -- --archive <文件>` | 使用已下载的安装包离线安装 |
|
|
@@ -169,6 +170,9 @@ magpie plugin options magpie-gemini-web '{"studio":{"proxy":"http://127.0.0.1:78
|
|
|
169
170
|
- 两个后端均只监听 `127.0.0.1`,Cookie 与登录态仅保存在本机,Magpie 仅保存本地生成的随机 API Key。
|
|
170
171
|
- **Gemini Web 数据目录**:`~/.local/share/magpie-gemini-web`(可通过 `GEMINI_WEB_DATA_DIR` 修改),日志位于 `backend.log`。支持 macOS、Linux、Windows(x64 / arm64)。
|
|
171
172
|
- **AI Studio 数据目录**:`~/.local/share/magpie-ai-studio`(可通过 `AI_STUDIO_DATA_DIR` 修改),日志位于 `backend.log`(超 10 MB 下次启动自动轮转)。默认使用 2048 端口,被占用时自动顺延并记录在 `config.json`。支持 macOS、Linux(x64 / arm64)与 Windows x64。
|
|
173
|
+
- **卸载与清理下载资产**:在 Magpie 中删除插件(或运行 `npm run studio:clean`、`npm run backend:clean`)会停止本地服务并删除 `AIStudio2API`、`Camoufox` 与 `gemini-web2api-go` 二进制及安装包。
|
|
174
|
+
- 清理会保留 `auth/`、`gemini.db`、`config.json`、`.env` 与 `secrets.json`,以便重装插件或下次发起请求时自动按需重装后端、免去重新登录或导 Cookie;若要彻底停用自动重装,请在 Magpie 中删除对应登录卡片或一并删除数据目录中的配置文件。
|
|
175
|
+
- 默认数据目录按当前系统用户共享;若在同一账号下隔离运行多个 Magpie 配置目录,请分别设置 `AI_STUDIO_DATA_DIR` 与 `GEMINI_WEB_DATA_DIR`,避免卸载其一时清理共享资产。
|
|
172
176
|
- Gemini Web 每个登录同时最多 2 个请求(AI Studio 为 1),可在 Magpie 的 provider 设置里调整;仍无法完全排除 Google 账号风控风险,请自行评估使用。
|
|
173
177
|
|
|
174
178
|
**AI Studio 升级与模型范围:**
|
|
@@ -181,10 +185,11 @@ magpie plugin options magpie-gemini-web '{"studio":{"proxy":"http://127.0.0.1:78
|
|
|
181
185
|
- 已停止但文件被替换的后端会从校验通过的固定版本安装包恢复;校验失败不会启动替换文件。安装会保留账号和运行数据文件,但**不保证旧版本能读取新版迁移过的数据**。手动降级前先停止服务并备份整个数据目录(包括 `auth/`、`runtime/requests.db` 等);已知发生数据迁移时应升级插件以匹配新版后端。
|
|
182
186
|
- AI Studio 后端基础请求期限为 30 分钟;插件默认单次响应等待/流空闲超时也是 30 分钟(仍可用 `studio.requestTimeoutMs` 调整)。这允许非流式长回复在服务端完整收集;后端卡死时也可能等满 30 分钟,且单 worker 会拖住后续请求。可主动取消请求或设置更短的等待时间,但较短期限可能中断正常长回复。上游自动续写的期限按其规则计算。
|
|
183
187
|
- 已核对本机 Magpie `v0.1.1285`(`d783df46`)源码:插件请求走 `Provider.Do → plugin.Fetch → loader.fetch`,绕过普通 HTTP transport 的 10 分钟响应头限制;此插件生成路径没有发现更短的固定总超时。网关 5 分钟 `IdleTimeout` 仅针对请求之间的空闲连接。客户端或反向代理仍可设置更短期限;这不是一次实等 30 分钟的端到端验证。
|
|
188
|
+
- 支持 Deep Research 模型(`deep-research-preview-04-2026`、`deep-research-max-preview-04-2026`):需要登录 Google AI Pro / Ultra 账号才会在列表中出现;由后端将异步 Interactions 任务适配到 `/v1/chat/completions` 流式返回(含思考过程与服务端内置联网搜索),不支持客户端 `tool_call`(Function Calling)或 `temperature`。
|
|
184
189
|
- 模型列表过滤 `-build` / `assistant_route` 模型:这类模型附带 Build 写代码助手的系统提示词,不作为普通 Agent 模型提供。升级后可执行 `magpie provider models ai-studio` 刷新列表。
|
|
185
190
|
|
|
186
191
|
**Gemini Web 优化后端升级与回退:**
|
|
187
|
-
- 插件默认使用本仓库发布的 [4.27.0-magpie.
|
|
192
|
+
- 插件默认使用本仓库发布的 [4.27.0-magpie.2](https://github.com/BUKOWSKIREAL/magpie-gemini-web/releases/tag/backend-v4.27.0-magpie.2)(基于上游 v4.27.0 集成 XSRF 缓存、请求取消传播、工具调用提前收尾与 Argon 校验补丁)。对话请求按上游沉默计时:Google 让请求排队时每 60 秒发一次心跳,后端会一直等到出字;连续 `request_timeout_sec`(默认 180 秒)没有任何数据才放弃这一次并重试,还在出字的长回复也不会被截断。
|
|
188
193
|
- **旧版升级**:插件不会打断运行中的后端。先停止旧进程(PID 见数据目录 `backend.pid`),下次启动 Magpie 或发请求时会自动更新二进制并保留原有配置与账号。
|
|
189
194
|
- **回退官方版 / 恢复优化版**(停止后端后在插件目录执行):
|
|
190
195
|
```bash
|
package/docs/studio-release.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# AI Studio 托管后端构建
|
|
2
2
|
|
|
3
|
-
插件使用 `0.
|
|
3
|
+
插件使用 `0.3.0-magpie.1`,基于 AIStudio2API `v0.3.0` 及其后续修复 commit `48f75fa722b25d22a493e75f6d4e5f9d5035d7e3`。上游版本、commit、Go 版本、C/C++ 工具链与 SpiderMonkey 静态库(`toolchains`)、补丁列表、安装包及二进制 SHA-256 均记录在 `lib/studio-release.json`。`upstream.camoufox` 是这个 commit 要求的 Camoufox 版本(上游 `internal/camoufoxnative/download.go` 里的 `camoufoxRelease`),更新上游 commit 时要一起核对,构建脚本发现不一致会报错。MIT 许可见 `LICENSE-AISTUDIO`。
|
|
4
|
+
|
|
5
|
+
## 0.3.0 升级兼容
|
|
6
|
+
|
|
7
|
+
- 基线为上游 `v0.3.0` 加 PR #109(`48f75fa722b25d22a493e75f6d4e5f9d5035d7e3`)。包含账号异步任务流、本机 Chrome / Cookie / CDP 浏览器账号导入、超过 63 字符的工具函数名自动压缩还原、`STRIP_THOUGHT_SIGNATURES`、Responses / Interactions / 音频状态持久化(`runtime/states.db`)、`gemini-live-2.5-flash` 与 `gemini-2.5-pro-tts` 等模型更新,以及上游默认 `WAA_BACKEND=spidermonkey`。Camoufox、SpiderMonkey 静态库和固定工具链沿用上一版。
|
|
8
|
+
- 后台账户任务适配:上游 `POST /api/accounts` 与 `POST /api/accounts/{id}/login` 改为启动不随 HTTP 请求取消的后台任务(返回 `202 Accepted` 与 `{ task }`)。插件与 CLI 通过 `studioLogin` 轮询 `GET /api/accounts/tasks` 等待完成,再从 `GET /api/accounts` 读取账号,并在结束或超时退出时调用 `DELETE /api/accounts/tasks/{id}` 清理或取消后台任务(超时会自动关闭弹出的 Camoufox 登录窗口)。
|
|
9
|
+
- 配置项变更:上游移除了废弃的 `TEMPORARY_CHAT`,新增 `STRIP_THOUGHT_SIGNATURES`(默认 `false`)。插件移除 `TEMPORARY_CHAT` 默认项,保留管理页保存的 `STRIP_THOUGHT_SIGNATURES`,并隔离宿主环境的同名变量。
|
|
10
|
+
- `patches/studio-0.2.19-managed-config.patch` 同步适配上游 `v0.3.0` 新增的 `workerDefaultKeys`(`WARM_WORKER_LIMIT`、`MAX_ACTIVE_WORKERS`)分支:托管构建(`internal/config.managedBy=magpie-gemini-web`)继续完整写出全部非环境变量控制项,避免插件默认并发设置覆盖管理页保存的上游默认值。
|
|
4
11
|
|
|
5
12
|
## 0.2.19 升级兼容
|
|
6
13
|
|
|
@@ -29,7 +36,7 @@
|
|
|
29
36
|
|
|
30
37
|
上游从 v0.2.14 起原生支持分发方管理更新。构建时通过 `-ldflags` 写入以下值:
|
|
31
38
|
|
|
32
|
-
- `internal/app.version=v0.
|
|
39
|
+
- `internal/app.version=v0.3.0-magpie.1`:明确的版本标识。同基线或更旧的官方版、以及更旧的托管版需要升级;更新的官方版、更新的托管版或不认识的定制版仍提示冲突。
|
|
33
40
|
- `internal/app.managedBy=magpie-gemini-web`:`GET /api/update`(包括 `?refresh=1`)只返回本地版本、`mode: managed` 和 `managed_by`,不访问 GitHub;`POST /api/update` 返回 HTTP 409,不下载、不替换文件、不重启。管理页显示“更新由 magpie-gemini-web 管理”。
|
|
34
41
|
|
|
35
42
|
`internal/config.managedBy=magpie-gemini-web` 同时启用上面的配置兼容补丁。
|
|
@@ -106,7 +113,12 @@ AI_STUDIO_TEST_ARCHIVE=/absolute/path/to/archive.tar.gz npm test
|
|
|
106
113
|
|
|
107
114
|
真实安装验证检查旧版请求正文迁移及重启后可读、管理页保存的备用请求设置、启动、版本、GET 更新状态、POST 更新返回 409、二进制及 PID 不变、管理页面显示托管提示、停止与状态。`.github/workflows/studio.yml` 在五种系统/架构的原生 runner 上重新构建、对比 SHA-256 并运行该验证;本机交叉编译不能代替 Linux/Windows 真机验证。
|
|
108
115
|
|
|
109
|
-
## 0.
|
|
116
|
+
## 0.3.0 升级验证(2026-11-05)
|
|
117
|
+
|
|
118
|
+
- 五个平台的候选构建([run 41976798432](https://github.com/BUKOWSKIREAL/magpie-gemini-web/actions/runs/41976798432))一次性通过上游测试、真实安装冒烟验证(含 `strip_thought_signatures=false`、`/api/accounts/tasks` 接口与管理页配置持久化)及插件测试;安装包和二进制 pin 来自该次构建。
|
|
119
|
+
- 随后的严格验证构建([run 41977975873](https://github.com/BUKOWSKIREAL/magpie-gemini-web/actions/runs/41977975873))在五个平台的全新 runner 上重新构建,哈希与 pin 完全一致,真实安装冒烟验证与插件测试全部通过。
|
|
120
|
+
|
|
121
|
+
## 0.2.19 升级验证(2026-11-02,历史记录)
|
|
110
122
|
|
|
111
123
|
- 五个平台的候选构建([run 41378024737](https://github.com/BUKOWSKIREAL/magpie-gemini-web/actions/runs/41378024737))通过上游测试、真实安装冒烟验证及插件测试;安装包和二进制 pin 来自该次构建。Windows 首次在安装前的 PowerShell 进程查询超时,失败作业重跑通过,未修改测试或放宽超时。提交 pin 后仍需由严格验证工作流在新 runner 上重建并逐一比对哈希,结果见升级 PR。
|
|
112
124
|
- 本地使用 CI 的 darwin-arm64 安装包运行完整插件测试:212 项通过、无跳过;Python bridge 测试 41 项通过。打包检查包含配置补丁,不包含本地构建和账号数据。
|
|
@@ -137,14 +149,14 @@ AI_STUDIO_TEST_ARCHIVE=/absolute/path/to/archive.tar.gz npm test
|
|
|
137
149
|
- 新版 Google 登录/生成端到端验证尚未完成。
|
|
138
150
|
- 此分支未发布后端 release 或 npm 包。本机日常后端仍使用 `0.2.16-magpie.1`,新版仅在临时数据目录运行。
|
|
139
151
|
|
|
140
|
-
发布前必须审查各平台 CI 与构建记录,再将安装包及许可证上传到本仓库 `studio-v0.
|
|
152
|
+
发布前必须审查各平台 CI 与构建记录,再将安装包及许可证上传到本仓库 `studio-v0.3.0-magpie.1` release。该 release 的安装包可公开下载后,才能发布对应 npm 版本,否则新安装会遇到 404。合并 PR 不代表已经满足发布条件;构建脚本及验证 CI 不自动发布 release 或 npm 包。
|
|
141
153
|
|
|
142
154
|
本地试用建议使用独立数据目录:
|
|
143
155
|
|
|
144
156
|
```bash
|
|
145
|
-
node scripts/studio.mjs install --data-dir /path/to/studio-
|
|
146
|
-
node scripts/studio.mjs start --data-dir /path/to/studio-
|
|
147
|
-
node scripts/studio.mjs stop --data-dir /path/to/studio-
|
|
157
|
+
node scripts/studio.mjs install --data-dir /path/to/studio-030-trial --archive /absolute/path/to/archive
|
|
158
|
+
node scripts/studio.mjs start --data-dir /path/to/studio-030-trial
|
|
159
|
+
node scripts/studio.mjs stop --data-dir /path/to/studio-030-trial
|
|
148
160
|
```
|
|
149
161
|
|
|
150
162
|
使用现有账号数据测试前,先停止旧服务并备份;不要让两个进程同时写同一个数据目录。
|
package/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { normalizeBaseURL, settings, credentials, listModels, forward, UNREACHABLE_HEADER, PLUGIN_ICON } from './lib/backend.mjs';
|
|
2
|
-
import { ensureBackend, localBackend } from './lib/native.mjs';
|
|
2
|
+
import { ensureBackend, localBackend, localSetup } from './lib/native.mjs';
|
|
3
|
+
import { registerMagpieCleanup, isPluginRemovedInActiveMagpie } from './lib/cleanup.mjs';
|
|
3
4
|
import { parseCookieInput, importCookie, ensureProxy, validateProxyURL, requireLoginBackend } from './lib/setup.mjs';
|
|
4
5
|
import { usage, poolChoices, poolAccounts, accountEmail } from './lib/usage.mjs';
|
|
5
6
|
import { taskSupported, taskMethod, taskLoader, taskModels, isTaskAuth } from './lib/task.mjs';
|
|
@@ -31,14 +32,19 @@ async function signInFor(local, account) {
|
|
|
31
32
|
return {
|
|
32
33
|
type: 'success',
|
|
33
34
|
key: local.apiKey,
|
|
34
|
-
metadata: {
|
|
35
|
+
metadata: {
|
|
36
|
+
baseURL: local.baseURL, account: account.id, ...(email ? { email } : {}),
|
|
37
|
+
// The account index (/u/N) the email is for; usage takes the email only while it holds.
|
|
38
|
+
...(email && account.authuser > 0 ? { authuser: account.authuser } : {})
|
|
39
|
+
}
|
|
35
40
|
};
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
// managedBackend is the local backend this plugin set up, when baseURL points at it.
|
|
39
|
-
function managedBackend(baseURL) {
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
function managedBackend(baseURL, key) {
|
|
45
|
+
if (isPluginRemovedInActiveMagpie()) return null;
|
|
46
|
+
const local = localBackend() || (key ? localSetup() : null);
|
|
47
|
+
return local && local.baseURL === baseURL && (!key || local.apiKey === key) ? local : null;
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
// forwardManaged is forward(), but when the backend this plugin manages can't be reached it
|
|
@@ -53,7 +59,7 @@ async function forwardManaged(input, init, getAuth, opts) {
|
|
|
53
59
|
} catch {
|
|
54
60
|
return res;
|
|
55
61
|
}
|
|
56
|
-
if (!managedBackend(c.baseURL)) return res;
|
|
62
|
+
if (!managedBackend(c.baseURL, c.key)) return res;
|
|
57
63
|
try {
|
|
58
64
|
await ensureBackend({ proxy: opts.proxy });
|
|
59
65
|
} catch {
|
|
@@ -68,6 +74,7 @@ export const GeminiWebPlugin = async (_input, options = {}) => {
|
|
|
68
74
|
}
|
|
69
75
|
const { studio: _studio, ...webOptions } = options;
|
|
70
76
|
const opts = settings(webOptions);
|
|
77
|
+
registerMagpieCleanup(_input);
|
|
71
78
|
const proxyPrompt = {
|
|
72
79
|
type: 'text',
|
|
73
80
|
key: 'proxy',
|
|
@@ -222,11 +229,11 @@ export const GeminiWebPlugin = async (_input, options = {}) => {
|
|
|
222
229
|
} catch (err) {
|
|
223
230
|
return { error: err.message, windows: [], signIn: 'kept' };
|
|
224
231
|
}
|
|
225
|
-
if (!managedBackend(c.baseURL)) {
|
|
232
|
+
if (!managedBackend(c.baseURL, c.key)) {
|
|
226
233
|
return { error: '只能读取插件自己管理的本地后端的额度(连接已有后端时读不到)', windows: [], signIn: 'kept' };
|
|
227
234
|
}
|
|
228
|
-
const { account, email } = auth.metadata || {};
|
|
229
|
-
return { ...(await usage(Number.isInteger(account) ? { account, email } : {})), signIn: 'kept' };
|
|
235
|
+
const { account, email, authuser } = auth.metadata || {};
|
|
236
|
+
return { ...(await usage(Number.isInteger(account) ? { account, email, authuser } : {})), signIn: 'kept' };
|
|
230
237
|
}
|
|
231
238
|
},
|
|
232
239
|
provider: {
|
|
@@ -238,7 +245,7 @@ export const GeminiWebPlugin = async (_input, options = {}) => {
|
|
|
238
245
|
try {
|
|
239
246
|
return await listModels(c, opts);
|
|
240
247
|
} catch (err) {
|
|
241
|
-
if (!err.unreachable || !managedBackend(c.baseURL)) throw err;
|
|
248
|
+
if (!err.unreachable || !managedBackend(c.baseURL, c.key)) throw err;
|
|
242
249
|
await ensureBackend({ proxy: opts.proxy });
|
|
243
250
|
return listModels(c, opts);
|
|
244
251
|
}
|
package/lib/backend-release.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.27.0-magpie.
|
|
2
|
+
"version": "4.27.0-magpie.2",
|
|
3
3
|
"repository": "BUKOWSKIREAL/magpie-gemini-web",
|
|
4
|
-
"tag": "backend-v4.27.0-magpie.
|
|
4
|
+
"tag": "backend-v4.27.0-magpie.2",
|
|
5
5
|
"upstream": {
|
|
6
6
|
"repository": "https://github.com/zexadev/gemini-web2api-go.git",
|
|
7
7
|
"commit": "e97cfccc7e68e356ac504ba220e0b004382029a8"
|
|
@@ -9,28 +9,28 @@
|
|
|
9
9
|
"goVersion": "1.27.1",
|
|
10
10
|
"binaries": {
|
|
11
11
|
"darwin-arm64": {
|
|
12
|
-
"asset": "gemini-web2api-go_v4.27.0-magpie.
|
|
13
|
-
"sha256": "
|
|
12
|
+
"asset": "gemini-web2api-go_v4.27.0-magpie.2_darwin_arm64",
|
|
13
|
+
"sha256": "45c01d9a99142957eadf30b75ee17da13ea468ca9b4b0d342b9e7b2b440a9072"
|
|
14
14
|
},
|
|
15
15
|
"darwin-x64": {
|
|
16
|
-
"asset": "gemini-web2api-go_v4.27.0-magpie.
|
|
17
|
-
"sha256": "
|
|
16
|
+
"asset": "gemini-web2api-go_v4.27.0-magpie.2_darwin_amd64",
|
|
17
|
+
"sha256": "4739f96c703f08ac8c21a7b699564bb26f80298a0ea8c30b126de501fc61d451"
|
|
18
18
|
},
|
|
19
19
|
"linux-x64": {
|
|
20
|
-
"asset": "gemini-web2api-go_v4.27.0-magpie.
|
|
21
|
-
"sha256": "
|
|
20
|
+
"asset": "gemini-web2api-go_v4.27.0-magpie.2_linux_amd64",
|
|
21
|
+
"sha256": "837d5416507daf628984dd7e32aba69380f54d3385e8fd0b478af9b5a0c3dc1b"
|
|
22
22
|
},
|
|
23
23
|
"linux-arm64": {
|
|
24
|
-
"asset": "gemini-web2api-go_v4.27.0-magpie.
|
|
25
|
-
"sha256": "
|
|
24
|
+
"asset": "gemini-web2api-go_v4.27.0-magpie.2_linux_arm64",
|
|
25
|
+
"sha256": "8c070298efb4db79839b214c113cc486a4693cc3d144fc17c30daa4b96d9a99b"
|
|
26
26
|
},
|
|
27
27
|
"win32-x64": {
|
|
28
|
-
"asset": "gemini-web2api-go_v4.27.0-magpie.
|
|
29
|
-
"sha256": "
|
|
28
|
+
"asset": "gemini-web2api-go_v4.27.0-magpie.2_windows_amd64.exe",
|
|
29
|
+
"sha256": "ec9550617a73aa9e17847dd511edc9b64425fa980a5024ea385d6fd28ccb7d2d"
|
|
30
30
|
},
|
|
31
31
|
"win32-arm64": {
|
|
32
|
-
"asset": "gemini-web2api-go_v4.27.0-magpie.
|
|
33
|
-
"sha256": "
|
|
32
|
+
"asset": "gemini-web2api-go_v4.27.0-magpie.2_windows_arm64.exe",
|
|
33
|
+
"sha256": "7cb9d2a47fd2106da4db8e5e4983547b962d3e03dd3ed5f0ac529b2eab31f97a"
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
process.title = 'magpie-gemini-web-cleanup';
|
|
4
|
+
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
|
|
7
|
+
const cfg = JSON.parse(process.env.MAGPIE_CLEANUP_CFG || '{}');
|
|
8
|
+
const {
|
|
9
|
+
magpieDir,
|
|
10
|
+
pluginRoot,
|
|
11
|
+
studioDir,
|
|
12
|
+
webDir,
|
|
13
|
+
pidFile,
|
|
14
|
+
mode = 'watch',
|
|
15
|
+
pollMs = 2000
|
|
16
|
+
} = cfg;
|
|
17
|
+
|
|
18
|
+
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
19
|
+
|
|
20
|
+
function removePidFile() {
|
|
21
|
+
if (!pidFile) return;
|
|
22
|
+
try {
|
|
23
|
+
const recorded = Number(fs.readFileSync(pidFile, 'utf8').trim());
|
|
24
|
+
if (recorded === process.pid) {
|
|
25
|
+
fs.rmSync(pidFile, { force: true });
|
|
26
|
+
}
|
|
27
|
+
} catch {}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
(async () => {
|
|
31
|
+
try {
|
|
32
|
+
// Load the cleanup module into memory immediately on startup so the watcher still has all
|
|
33
|
+
// code in memory even after `bun remove` deletes node_modules/magpie-gemini-web from disk.
|
|
34
|
+
const {
|
|
35
|
+
isPluginInMagpie,
|
|
36
|
+
hasDownloadedAssets,
|
|
37
|
+
cleanDownloadedAssets
|
|
38
|
+
} = await import('./cleanup.mjs');
|
|
39
|
+
|
|
40
|
+
if (mode === 'immediate') {
|
|
41
|
+
await cleanDownloadedAssets({ studioDir, webDir });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
for (;;) {
|
|
46
|
+
const state = isPluginInMagpie(magpieDir, { pluginRoot });
|
|
47
|
+
if (state === false) {
|
|
48
|
+
await cleanDownloadedAssets({ studioDir, webDir });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!hasDownloadedAssets({ studioDir, webDir })) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
await sleep(pollMs);
|
|
55
|
+
}
|
|
56
|
+
} catch {
|
|
57
|
+
// Best-effort background cleanup
|
|
58
|
+
} finally {
|
|
59
|
+
removePidFile();
|
|
60
|
+
}
|
|
61
|
+
})();
|