@dorokuma/magpie-gemini-web 0.18.0 → 0.18.1
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/CHANGELOG.md +13 -0
- package/README.en.md +14 -15
- package/README.md +14 -15
- package/index.mjs +84 -48
- package/lib/backend-release.json +14 -14
- package/lib/private-browser.mjs +147 -0
- package/lib/setup.mjs +23 -0
- package/lib/web-connect.mjs +343 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
本文件按版本倒序记录 `magpie-gemini-web`(0.15.0 起为 `@dorokuma/magpie-gemini-web`)的全部已发布与待发变更,依据本仓 `git log` 与 tag 事实编写。
|
|
4
4
|
|
|
5
|
+
## 0.18.1 - 2026-11-19
|
|
6
|
+
|
|
7
|
+
### 变更
|
|
8
|
+
- Gemini Web 后端 pin 升级至 **`dorokuma/gemini-web2api-go` `v6.2.1`** 官方预编译二进制:Chat 模式平台工具上限尾注前置免疫,减少工具调用被平台提示打断。
|
|
9
|
+
|
|
10
|
+
### 修复
|
|
11
|
+
- Gemini Web 一键登录不再让 Magpie 直接用系统默认浏览器打开 gemini.google.com:`authorize` 改为打开本机登录向导页(`127.0.0.1` 随机端口 + 随机 token 路径),页内按钮以无痕 / 隐私模式启动检测到的浏览器(Firefox 优先,其次 Chrome / Brave / Chromium / Edge;找不到时给出可手动复制的链接),避免登录会话落在日常窗口被 Google 踢出。
|
|
12
|
+
- Google 账号索引(authuser)不再在浏览器打开前提前询问:向导页在无痕窗口登录后再对照地址栏 `/u/N/app` 填写,与 Cookie、代理同一表单提交;校验或导入失败原地报错可直接改字段重试,不必取消重来。
|
|
13
|
+
- 无痕窗口启动器修复两处隐藏故障:浏览器二进制探测只查存在性,同名目录或无 `+x` 权限的文件会被误判为可用(`resolveBin` 现在校验普通文件与 POSIX 可执行权限);`spawn` 的异步 `'error'`(如 `EACCES`/`ENOENT`)原会以未处理异常击穿宿主进程,`launchPrivateBrowser` 改为 `async`、在 `'spawn'`/`'error'` 间竞速等待,启动失败自动回退下一个候选浏览器,不再假报成功。
|
|
14
|
+
- 向导页 `/submit` 增加单飞互斥:一次验证未结束时并发提交直接返回 `409`,不再允许多个导入管线同时写后端账号池;同时在每次 `await` 后复检会话是否已取消/超时(经 `isEnded()` 传入 `submit` 与 `importCookie`),取消或超时后不再继续写入账号;若取消发生在账号已创建、检测进行中或刚返回之后,`importCookie` 会 `DELETE` 回滚本次新建的账号(不动其它账号)。页面端取消后立即禁用表单,`/submit` 收到 `410` 也不再提示原地重试。
|
|
15
|
+
- `authorize` 不再把首次 `ensureBackend` 的失败 Promise 锁死:首次下载失败(如无代理拿到 503)或用户在向导页改填了代理时,`submit` 会以表单实际代理重新调用 `ensureBackend`,原地重试可成功登录;每代重建跟踪自己的失败状态(代际守卫),旧代迟到的 reject 不会污染新一代,后端就绪后再次检查会话是否已结束,已取消则不再导入 Cookie。
|
|
16
|
+
- 向导页模板替换改为函数 replacer:代理密码中含 `$$`、`$'`、`$&`、`` $` `` 等字符不再被 `String.prototype.replace` 的 `$` 元语法误展开而破坏 DOM;代理输入提示改为准确描述(留空表示不在本次登录指定代理,后端已配置代理池仍按其规则生效),第 1 步常驻展示可复制的 `https://gemini.google.com/app` 手动链接(自动拉起成功时也可见,覆盖 macOS Firefox 已运行锁或窗口未前置场景)。
|
|
17
|
+
|
|
5
18
|
## 0.18.0 - 2026-11-19
|
|
6
19
|
|
|
7
20
|
### 变更
|
package/README.en.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
Use **Google AI Studio** and **Gemini on the web** through your Google account in [Magpie](https://usemagpie.ai/). The plugin runs [AIStudio2API](https://github.com/Mag1cFall/AIStudio2API) and [gemini-web2api-go](https://github.com/zexadev/gemini-web2api-go) locally, providing chat, native function calling, Nano Banana image generation, and Deep Research through OpenAI-compatible and Gemini APIs.
|
|
8
8
|
|
|
9
|
-
> **New model support:** **Google AI Studio (`ai-studio`)** automatically follows official stable backend releases and supports **`gemini-4-hydrogen`** (including the `xhigh` thinking tier) and **`gemini-4-carbon`** (requires an eligible account tier such as Google AI Ultra). **Gemini Web (`gemini-web`)** is backed by [`dorokuma/gemini-web2api-go` `v6.2.
|
|
9
|
+
> **New model support:** **Google AI Studio (`ai-studio`)** automatically follows official stable backend releases and supports **`gemini-4-hydrogen`** (including the `xhigh` thinking tier) and **`gemini-4-carbon`** (requires an eligible account tier such as Google AI Ultra). **Gemini Web (`gemini-web`)** is backed by [`dorokuma/gemini-web2api-go` `v6.2.1`](https://github.com/dorokuma/gemini-web2api-go/releases/tag/v6.2.1), which natively supports dedicated `gemini-4-carbon` / `gemini-4-hydrogen` / **`gemini-4-neon`** model IDs (including `-thinking` variants) and mutually recognizes slot upgrades/downgrades under `strict_model`; the `gemini-4-neon` family thinks server-side internally and never emits `reasoning_content`. **Chat and Task modes are separate:** use `gemini-4-neon` / `gemini-4-hydrogen` / `gemini-4-carbon` for everyday conversations (`gemini-4-carbon` and its `-thinking` / `-thinking-medium` variants are chat-only), and the dedicated **`gemini-4-neon-task`** / **`gemini-4-carbon-task`** / **`gemini-4-hydrogen-task`** models for task- and tool-heavy scenarios (they map to Gemini Web's Task mode).
|
|
10
10
|
|
|
11
11
|
## Fork Notice & Acknowledgements
|
|
12
12
|
|
|
@@ -19,7 +19,7 @@ This project is an actively maintained **fork of [BUKOWSKIREAL/magpie-gemini-web
|
|
|
19
19
|
**Key differences from upstream** (full history in [CHANGELOG](CHANGELOG.md)):
|
|
20
20
|
|
|
21
21
|
1. npm package renamed to the scoped **`@dorokuma/magpie-gemini-web`**; the original unscoped `magpie-gemini-web` remains maintained by the upstream author as an independent npm package.
|
|
22
|
-
2. The Gemini Web backend is pinned to the **official Release prebuilt binaries** of `dorokuma/gemini-web2api-go` (currently `v6.2.
|
|
22
|
+
2. The Gemini Web backend is pinned to the **official Release prebuilt binaries** of `dorokuma/gemini-web2api-go` (currently `v6.2.1`, SHA-256 synced one-way by script); the local patch-and-rebuild pipeline was retired.
|
|
23
23
|
3. Gemini Web adds `gemini-4-carbon` / `gemini-4-hydrogen` / `gemini-4-neon` model IDs (plus the dedicated task-mode models `gemini-4-neon-task` / `gemini-4-carbon-task` / `gemini-4-hydrogen-task`) with slot cross-validation; fixes include phantom session cleanup, AI Studio proxy precedence, and atomic publish/self-healing for update locks.
|
|
24
24
|
|
|
25
25
|
|
|
@@ -35,9 +35,9 @@ The plugin provides two independent providers that can be used individually or t
|
|
|
35
35
|
| **Thinking levels** | Supported levels from the model catalog: `minimal` / `low` / `medium` / `high` / `xhigh` (Hydrogen) | `low` (base) / `medium` (`-thinking-medium`, Carbon / Neon families) / `high` (`-thinking` extended thinking) |
|
|
36
36
|
| **Image input** | On by default; chat models read images | On by default; chat models read images (needs a signed-in cookie) |
|
|
37
37
|
| **Image generation** | Nano Banana models, for Magpie's image generation (Magpie v0.1.2075+, see below) | Not supported |
|
|
38
|
-
| **Sign-in method** | Automatic official installation; confirm an imported account |
|
|
38
|
+
| **Sign-in method** | Automatic official installation; confirm an imported account | Local wizard: copy `cookie` from a private/incognito window |
|
|
39
39
|
| **Usage cards** | Shows models currently on cooldown and recovery times | Syncs **5-hour** & **weekly** usage and reset times from the web |
|
|
40
|
-
| **Local backend** | AIStudio2API (automatic installation and stable updates) | gemini-web2api-go (`v6.2.
|
|
40
|
+
| **Local backend** | AIStudio2API (automatic installation and stable updates) | gemini-web2api-go (`v6.2.1` pinned binary) |
|
|
41
41
|
|
|
42
42
|
---
|
|
43
43
|
|
|
@@ -84,13 +84,12 @@ For an independently running service, choose **Connect an existing AIStudio2API
|
|
|
84
84
|
|
|
85
85
|
### Option 2: Gemini Web (`gemini-web`)
|
|
86
86
|
|
|
87
|
-
1. Sign in to **Gemini Web** in Magpie and choose **「一键配置本地 Gemini Web(推荐)」** (One-click local setup). If you need a proxy to reach Google, enter its URL (e.g. `http://127.0.0.1:7890`) when prompted at the start of sign-in, or leave it blank for direct connection / existing proxy pool.
|
|
88
|
-
2.
|
|
89
|
-
1.
|
|
90
|
-
2. Press `F12` (`⌥⌘I` on macOS), switch to the **Network** tab,
|
|
91
|
-
3.
|
|
92
|
-
|
|
93
|
-
3. The plugin verifies the account and completes sign-in. Repeat the steps above to add more accounts.
|
|
87
|
+
1. Sign in to **Gemini Web** in Magpie and choose **「一键配置本地 Gemini Web(推荐)」** (One-click local setup). If you need a proxy to reach Google, enter its URL (e.g. `http://127.0.0.1:7890`) when prompted at the start of sign-in, or leave it blank for direct connection / existing proxy pool—you can also fill or change it on the local sign-in wizard page.
|
|
88
|
+
2. Magpie opens a **local sign-in wizard** (`127.0.0.1`, random port + random path, loopback only) that walks you through three steps:
|
|
89
|
+
1. Click **「打开无痕窗口登录 Gemini」**; the plugin launches the first detected browser in private mode (Firefox preferred, then Chrome / Brave / Chromium / Edge). If no known browser is found the page shows the link—open <https://gemini.google.com/app> in a private window yourself and sign in to your Google account.
|
|
90
|
+
2. Press `F12` (`⌥⌘I` on macOS), switch to the **Network** tab, reload the page, click any `gemini.google.com` request → **Headers** → **Request Headers**, copy the `cookie` value and paste it back into the wizard.
|
|
91
|
+
3. In the same form enter the **Google account index** (the `N` from `/u/N/app` in the private window's address bar—blank means `0` for a single account) and an optional **proxy URL**, then click **「验证并完成登录」**. Failures are shown in place; fix the fields and retry without starting over.
|
|
92
|
+
3. Once the page shows the bound email, sign-in is complete—**close the private window directly, do not sign out** (signing out invalidates the cookie). Repeat the steps above to add more accounts.
|
|
94
93
|
|
|
95
94
|
> **Backend upgrade required during sign-in?** An older background process may still be running. Exit Magpie, stop the matching `gemini-web2api-go` process (Windows: Task Manager → Details → `gemini-web2api-go.exe`), then run the full installation command shown in the error. It preserves accounts and configuration and selects the plugin's managed backend. Set `GEMINI_WEB_PROXY` first if the download needs a proxy. Reopen Magpie and sign in after installation.
|
|
96
95
|
|
|
@@ -244,13 +243,13 @@ When a plugin error asks you to run a command, it includes the full ready-to-cop
|
|
|
244
243
|
- 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.
|
|
245
244
|
|
|
246
245
|
**Gemini Web optimized backend upgrades & rollback:**
|
|
247
|
-
- The missing multi-account index in [#53](https://github.com/dorokuma/magpie-gemini-web/issues/53) is fixed. Reimport affected cookies or correct the index in backend account management. Backend [`dorokuma/gemini-web2api-go` `v6.2.
|
|
248
|
-
- One-click setup pins the prebuilt [v6.2.
|
|
249
|
-
- **Upgrading:** On load the plugin detects a stale managed backend process, stops it and upgrades the binary to the pinned `v6.2.
|
|
246
|
+
- The missing multi-account index in [#53](https://github.com/dorokuma/magpie-gemini-web/issues/53) is fixed. Reimport affected cookies or correct the index in backend account management. Backend [`dorokuma/gemini-web2api-go` `v6.2.1`](https://github.com/dorokuma/gemini-web2api-go/releases/tag/v6.2.1) natively exposes dedicated `gemini-4-carbon`, `gemini-4-hydrogen`, and `gemini-4-neon` model IDs (including `-thinking` variants; the Neon family thinks server-side internally and never emits `reasoning_content`), and drops the public `gemini-4-argon*` models (the old Argon slot was renamed to 4 Carbon in the upstream catalog and Argon is delisted by Google—use `gemini-4-carbon*` or `gemini-4-neon*`); its `strict_model` slot check mutually recognizes display-name upgrades/downgrades, so paid accounts whose `gemini-3.8-flash` calls are routed to `4 Hydrogen` are identified correctly instead of failing with `429 model_downgraded`.
|
|
247
|
+
- One-click setup pins the prebuilt [v6.2.1](https://github.com/dorokuma/gemini-web2api-go/releases/tag/v6.2.1) binaries from the backend repository by default (one repo, one artifact: six-platform SHA-256 pins live in `lib/backend-release.json`; the plugin no longer patches and rebuilds the backend). 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.
|
|
248
|
+
- **Upgrading:** On load the plugin detects a stale managed backend process, stops it and upgrades the binary to the pinned `v6.2.1`, which may interrupt in-flight generation requests. Wait for in-flight requests to finish, or stop the existing process manually (PID in `backend.pid` inside the data directory) before upgrading. Instances not managed or recognizable by the plugin are not guaranteed to auto-update. Config and cookies are preserved.
|
|
250
249
|
- **Rollback to upstream / restore the pinned build** (run in the plugin directory after stopping the backend):
|
|
251
250
|
```bash
|
|
252
251
|
npm run backend:install:upstream # Roll back and pin to upstream zexadev v4.28.0
|
|
253
|
-
npm run backend:install # Restore the default pinned v6.2.
|
|
252
|
+
npm run backend:install # Restore the default pinned v6.2.1
|
|
254
253
|
```
|
|
255
254
|
- For pin sync, verification and smoke procedures, see [docs/backend-release.md](docs/backend-release.md).
|
|
256
255
|
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
让 [Magpie](https://usemagpie.ai/) 通过你的 Google 账号使用 **Google AI Studio** 与 **Gemini 网页版**。插件在本机自动运行 [AIStudio2API](https://github.com/Mag1cFall/AIStudio2API) 与 [gemini-web2api-go](https://github.com/zexadev/gemini-web2api-go),提供对话、原生工具调用、Nano Banana 图片生成与 Deep Research 等能力。
|
|
8
8
|
|
|
9
|
-
> **新模型支持说明**:**Google AI Studio (`ai-studio`)** 默认自动跟随官方最新稳定版后端,现已直接支持 **`gemini-4-hydrogen`**(含 `xhigh` 思考档位)与 **`gemini-4-carbon`**(需账号具备对应权益,如 Google AI Ultra)。**Gemini Web (`gemini-web`)** 由后端 [`dorokuma/gemini-web2api-go` `v6.2.
|
|
9
|
+
> **新模型支持说明**:**Google AI Studio (`ai-studio`)** 默认自动跟随官方最新稳定版后端,现已直接支持 **`gemini-4-hydrogen`**(含 `xhigh` 思考档位)与 **`gemini-4-carbon`**(需账号具备对应权益,如 Google AI Ultra)。**Gemini Web (`gemini-web`)** 由后端 [`dorokuma/gemini-web2api-go` `v6.2.1`](https://github.com/dorokuma/gemini-web2api-go/releases/tag/v6.2.1) 原生支持 `gemini-4-carbon` / `gemini-4-hydrogen` / **`gemini-4-neon`** 专用模型 ID(含 `-thinking` 思考变体),`strict_model` 开启时也能正确互认槽位升降级;`gemini-4-neon` 系列为服务端内部思考模型,回复中不输出 `reasoning_content`。**对话模式与任务模式分离**:日常对话用 `gemini-4-neon` / `gemini-4-hydrogen` / `gemini-4-carbon`(`gemini-4-carbon` 及 `-thinking` / `-thinking-medium` 变体为纯对话模式),任务/工具密集型场景可选独立任务模式模型 **`gemini-4-neon-task`**、**`gemini-4-carbon-task`** 与 **`gemini-4-hydrogen-task`**(对应 Gemini Web 网页端「任务」开关)。
|
|
10
10
|
|
|
11
11
|
## Fork 声明与致谢
|
|
12
12
|
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
**与原版的主要差异**(完整历史见 [CHANGELOG](CHANGELOG.md)):
|
|
20
20
|
|
|
21
21
|
1. npm 包名迁移为作用域包 **`@dorokuma/magpie-gemini-web`**;原版无作用域包 `magpie-gemini-web` 仍由原作者维护,两者在 npm 上是相互独立的包。
|
|
22
|
-
2. Gemini Web 后端固定使用 `dorokuma/gemini-web2api-go` 的**官方 Release 预编译二进制**(当前 `v6.2.
|
|
22
|
+
2. Gemini Web 后端固定使用 `dorokuma/gemini-web2api-go` 的**官方 Release 预编译二进制**(当前 `v6.2.1`,SHA-256 由脚本单向同步、禁止手改),移除本地补丁重编流水线。
|
|
23
23
|
3. Gemini Web 新增 `gemini-4-carbon` / `gemini-4-hydrogen` / `gemini-4-neon` 模型 ID(含独立的任务模式模型 `gemini-4-neon-task` / `gemini-4-carbon-task` / `gemini-4-hydrogen-task`)与互认槽位校验;修复幻影会话、AI Studio 代理优先级、更新锁原子发布与自愈等问题。
|
|
24
24
|
|
|
25
25
|
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
| **思考档位** | 按模型目录提供 `minimal` / `low` / `medium` / `high` / `xhigh`(Hydrogen)中支持的档位 | `low`(普通)/ `medium`(`-thinking-medium`,Carbon / Neon 系列)/ `high`(`-thinking` 扩展思考) |
|
|
36
36
|
| **图片输入** | 默认开启,对话模型可以读图 | 默认开启,对话模型可以读图(需登录态挂 Cookie) |
|
|
37
37
|
| **图片生成** | Nano Banana 系列模型,供 Magpie 的图片生成使用(需要 Magpie v0.1.2075+,见下文) | 不支持 |
|
|
38
|
-
| **登录方式** | 自动安装官方后端,导入账号后确认连接 |
|
|
38
|
+
| **登录方式** | 自动安装官方后端,导入账号后确认连接 | 本机向导页引导:无痕窗口登录并复制 `cookie` |
|
|
39
39
|
| **额度卡片** | 显示冷却中的模型与恢复时间 | 同步网页版 **5 小时** 与 **每周** 用量及重置时间 |
|
|
40
|
-
| **本地后端** | AIStudio2API(自动安装并跟随官方稳定版) | gemini-web2api-go (`v6.2.
|
|
40
|
+
| **本地后端** | AIStudio2API(自动安装并跟随官方稳定版) | gemini-web2api-go (`v6.2.1` 固定 pin 二进制) |
|
|
41
41
|
|
|
42
42
|
---
|
|
43
43
|
|
|
@@ -84,13 +84,12 @@
|
|
|
84
84
|
|
|
85
85
|
### 方式二:Gemini Web (`gemini-web`)
|
|
86
86
|
|
|
87
|
-
1. 在 Magpie 中登录 **Gemini Web**,选择 **「一键配置本地 Gemini Web(推荐)」**(若访问 Google 需要代理,可在第一步提示中直接填写代理地址,例如 `http://127.0.0.1:7890
|
|
88
|
-
2.
|
|
89
|
-
1.
|
|
90
|
-
2. 按 `F12`(macOS 按 `⌥⌘I`)切到 **Network
|
|
91
|
-
3.
|
|
92
|
-
|
|
93
|
-
3. 插件验证账号可用后即完成登录。想添加更多账号,重复上述步骤即可。
|
|
87
|
+
1. 在 Magpie 中登录 **Gemini Web**,选择 **「一键配置本地 Gemini Web(推荐)」**(若访问 Google 需要代理,可在第一步提示中直接填写代理地址,例如 `http://127.0.0.1:7890`,无需代理或已配置代理池可留空,也可稍后在本机登录向导页填写或修改)。
|
|
88
|
+
2. Magpie 打开**本机登录向导页**(`127.0.0.1` 随机端口 + 随机路径,仅本机可访问),按页面三步走:
|
|
89
|
+
1. 点 **「打开无痕窗口登录 Gemini」**,插件会以无痕 / 隐私模式自动启动检测到的浏览器(优先 Firefox,其次 Chrome / Brave / Chromium / Edge);找不到已知浏览器时页面给出链接,请手动开无痕窗口访问 <https://gemini.google.com/app> 登录 Google 账号;
|
|
90
|
+
2. 按 `F12`(macOS 按 `⌥⌘I`)切到 **Network(网络)**,刷新页面,点击任意 `gemini.google.com` 请求 → **Headers** → **Request Headers**,复制 `cookie` 的值粘贴回向导页;
|
|
91
|
+
3. 在同一表单填写 **Google 账号索引**(对照无痕窗口登录后地址栏 `/u/N/app` 的 `N`,单账号留空按 `0`)与可选的**代理地址**,点 **「验证并完成登录」**。校验失败会直接在页内显示原因,可原地修改后重试,无需取消重来。
|
|
92
|
+
3. 页面显示绑定邮箱后即完成登录,此时**直接关闭无痕窗口,不要点退出登录**(点退出会使 Cookie 失效)。想添加更多账号,重复上述步骤即可。
|
|
94
93
|
|
|
95
94
|
> **升级后提示后端不支持登录时绑定代理?** 旧后台进程可能仍在运行。请按提示先退出 Magpie,停止对应的 `gemini-web2api-go` 进程(Windows:任务管理器 → 详细信息 → `gemini-web2api-go.exe`),再运行提示中的完整安装命令。它会保留账号和配置,并切换到插件的托管后端;如下载需要代理,先设置 `GEMINI_WEB_PROXY`。完成后重新打开 Magpie 登录。
|
|
96
95
|
|
|
@@ -244,13 +243,13 @@ magpie plugin options @dorokuma/magpie-gemini-web '{"studio":{"proxy":"http://12
|
|
|
244
243
|
- 模型列表过滤 `-build` / `assistant_route` 模型:这类模型附带 Build 写代码助手的系统提示词,不作为普通 Agent 模型提供。升级后可执行 `magpie provider models ai-studio` 刷新列表。
|
|
245
244
|
|
|
246
245
|
**Gemini Web 优化后端升级与回退:**
|
|
247
|
-
- [#53](https://github.com/dorokuma/magpie-gemini-web/issues/53) 的多账号索引漏传已修复,需重新导入受影响的 Cookie 或在后端账号管理中修正索引。后端 [`dorokuma/gemini-web2api-go` `v6.2.
|
|
248
|
-
- 插件默认固定使用后端仓发布的 [v6.2.
|
|
249
|
-
- **旧版升级**:插件加载时若识别到托管的旧版后端进程,会自动回收并升级到当前 pin 的 `v6.2.
|
|
246
|
+
- [#53](https://github.com/dorokuma/magpie-gemini-web/issues/53) 的多账号索引漏传已修复,需重新导入受影响的 Cookie 或在后端账号管理中修正索引。后端 [`dorokuma/gemini-web2api-go` `v6.2.1`](https://github.com/dorokuma/gemini-web2api-go/releases/tag/v6.2.1) 已原生收录 `gemini-4-carbon`、`gemini-4-hydrogen` 与 `gemini-4-neon` 模型 ID(含 `-thinking` 思考变体,Neon 系列为服务端内部思考、不输出 `reasoning_content`),同时移除了 Gemini Web 对外 `gemini-4-argon*`(原 Argon 槽位在上游目录中原位改名为 4 Carbon,谷歌已下架 Argon,请改用 `gemini-4-carbon*` 或 `gemini-4-neon*`);`strict_model` 槽位校验按显示名家族互认升级/降级,付费账号请求 `gemini-3.8-flash` 被路由至 `4 Hydrogen` 时也能正确识别,不会误报 `429 model_downgraded`。
|
|
247
|
+
- 插件默认固定使用后端仓发布的 [v6.2.1](https://github.com/dorokuma/gemini-web2api-go/releases/tag/v6.2.1) 预编译二进制(一仓一制品,6 平台 SHA-256 pin 在 `lib/backend-release.json`,不再由插件仓打补丁重编)。对话请求按上游沉默计时:Google 让请求排队时每 60 秒发一次心跳,后端会一直等到出字;连续 `request_timeout_sec`(默认 180 秒)没有任何数据才放弃这一次并重试,还在出字的长回复也不会被截断。
|
|
248
|
+
- **旧版升级**:插件加载时若识别到托管的旧版后端进程,会自动回收并升级到当前 pin 的 `v6.2.1`,这可能中断正在进行的生成请求;建议升级前先等待在途请求结束,或手动停止旧进程(PID 见数据目录 `backend.pid`)。非插件托管或无法识别的实例不保证自动更新。升级后保留原有配置与账号。
|
|
250
249
|
- **回退官方上游版 / 恢复 pin 版**(停止后端后在插件目录执行):
|
|
251
250
|
```bash
|
|
252
251
|
npm run backend:install:upstream # 回退并固定使用上游 zexadev v4.28.0
|
|
253
|
-
npm run backend:install # 恢复默认 pin 的 v6.2.
|
|
252
|
+
npm run backend:install # 恢复默认 pin 的 v6.2.1
|
|
254
253
|
```
|
|
255
254
|
- pin 同步、校验与冒烟流程见 [docs/backend-release.md](docs/backend-release.md)。
|
|
256
255
|
|
package/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { normalizeBaseURL, settings, credentials, listModels, forward, UNREACHABLE_HEADER, PLUGIN_ICON } from './lib/backend.mjs';
|
|
2
2
|
import { ensureBackend, localBackend, localSetup } from './lib/native.mjs';
|
|
3
3
|
import { registerMagpieCleanup, isPluginRemovedInActiveMagpie } from './lib/cleanup.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { importCookie, removeAccount, ensureProxy, validateProxyURL, requireLoginBackend } from './lib/setup.mjs';
|
|
5
5
|
import { usage, poolChoices, poolAccounts, accountEmail } from './lib/usage.mjs';
|
|
6
|
+
import { startWebConnect } from './lib/web-connect.mjs';
|
|
6
7
|
|
|
7
8
|
const ID = 'gemini-web';
|
|
8
|
-
const GEMINI_URL = 'https://gemini.google.com/app';
|
|
9
9
|
|
|
10
10
|
// Saved macOS Task sign-ins predate removal of the native bridge. Reject them here so their
|
|
11
11
|
// local key is not sent to the Gemini Web backend.
|
|
@@ -17,17 +17,17 @@ function retiredTaskError() {
|
|
|
17
17
|
return Object.assign(new Error('macOS 原生 Task 已停用,请改用 Gemini Web 登录'), { signIn: 'expired' });
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
// The
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
20
|
+
// The local page authorize opens walks the sign-in in its natural order: a private window to
|
|
21
|
+
// Gemini first (the backend rotates this session, so a shared one would sign the daily browser
|
|
22
|
+
// out of Google), the Cookie copied from it, then the /u/N index that same window shows. Magpie
|
|
23
|
+
// itself would open gemini.google.com in the default browser — wrong window — and ask() would
|
|
24
|
+
// want the index before any window existed.
|
|
25
|
+
const GUIDE_STEPS = [
|
|
26
|
+
'Magpie 会打开本机登录向导页,按页面三步走:',
|
|
27
|
+
'1. 点「打开无痕窗口登录 Gemini」(推荐 Firefox),在无痕窗口登录 Google 账号',
|
|
28
|
+
'2. 按 F12 复制 gemini.google.com 请求的 cookie 值,填回向导页',
|
|
29
|
+
'3. 对照无痕窗口地址栏 /u/N/app 填账号索引(单账号留空),点「验证并完成登录」',
|
|
30
|
+
'为什么必须无痕窗口:后端会定时刷新这份登录保活,和日常浏览器共用会被 Google 踢出登录。',
|
|
31
31
|
'Cookie 只保存在本机的 Gemini Web 后端里,不会发到别处。'
|
|
32
32
|
].join('\n');
|
|
33
33
|
|
|
@@ -99,20 +99,6 @@ export const GeminiWebPlugin = async (_input, options = {}) => {
|
|
|
99
99
|
}
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
-
const authuserPrompt = {
|
|
103
|
-
type: 'text',
|
|
104
|
-
key: 'authuser',
|
|
105
|
-
message: 'Google 账号索引(复制 Cookie 的同一窗口中 /u/N/app 的 N;单账号留空为 0,无痕窗口可能不同)',
|
|
106
|
-
placeholder: '0',
|
|
107
|
-
validate: value => {
|
|
108
|
-
try {
|
|
109
|
-
parseAuthuser(value);
|
|
110
|
-
} catch (e) {
|
|
111
|
-
return e.message;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
102
|
// Bring a backend set up earlier back after Magpie or the computer restarts. Not awaited:
|
|
117
103
|
// requests that arrive first start it themselves through forwardManaged.
|
|
118
104
|
if (localBackend()) {
|
|
@@ -141,37 +127,87 @@ export const GeminiWebPlugin = async (_input, options = {}) => {
|
|
|
141
127
|
methods: [{
|
|
142
128
|
type: 'oauth',
|
|
143
129
|
label: '一键配置本地 Gemini Web(推荐)',
|
|
144
|
-
prompts: [proxyPrompt
|
|
130
|
+
prompts: [proxyPrompt],
|
|
145
131
|
ask(inputs) {
|
|
146
132
|
if (!inputs || !('proxy' in inputs)) return proxyPrompt;
|
|
147
|
-
return
|
|
133
|
+
return null;
|
|
148
134
|
},
|
|
149
|
-
//
|
|
150
|
-
//
|
|
151
|
-
//
|
|
152
|
-
//
|
|
153
|
-
// one
|
|
135
|
+
// Opens the local sign-in wizard instead of gemini.google.com so Magpie's window is the
|
|
136
|
+
// guide, not the wrong browser. The backend install starts now so it downloads while
|
|
137
|
+
// the user signs in; the wizard's submit waits for it, imports the cookie with the
|
|
138
|
+
// window's own authuser index, and resolves wait() with the sign-in result (the
|
|
139
|
+
// backend's own API key, one Magpie sign-in per Google account — see signInFor).
|
|
154
140
|
async authorize(inputs) {
|
|
155
141
|
const proxy = validateProxyURL(inputs?.proxy || opts.proxy || '');
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
142
|
+
// The first ensureBackend runs while the user signs in. Its outcome must not be
|
|
143
|
+
// locked into the submit: when it failed (e.g. a first download without a working
|
|
144
|
+
// proxy), or the wizard sends a different proxy than the prompt's, submit retries
|
|
145
|
+
// ensureBackend with the proxy the form actually carries — a locked-in rejection
|
|
146
|
+
// would make every in-place retry fail the same way forever.
|
|
147
|
+
let initialProxy = proxy;
|
|
148
|
+
let ready;
|
|
149
|
+
let readyFailed = false;
|
|
150
|
+
// Each (re)start is a generation of its own: the catch marks only the generation
|
|
151
|
+
// that still owns `ready`, so a rejection landing after a retry replaced it can
|
|
152
|
+
// never poison the new generation's clean slate.
|
|
153
|
+
const startReady = p => {
|
|
154
|
+
initialProxy = p;
|
|
155
|
+
readyFailed = false;
|
|
156
|
+
const attempt = ensureBackend({ proxy: p });
|
|
157
|
+
ready = attempt;
|
|
158
|
+
attempt.catch(() => { if (ready === attempt) readyFailed = true; });
|
|
159
|
+
};
|
|
160
|
+
startReady(proxy);
|
|
161
|
+
const session = await startWebConnect({
|
|
162
|
+
proxy,
|
|
163
|
+
async submit({ cookie, authuser, proxy: formProxy, isEnded }) {
|
|
164
|
+
if (readyFailed || (formProxy !== undefined && formProxy !== initialProxy)) {
|
|
165
|
+
startReady(formProxy !== undefined ? formProxy : initialProxy);
|
|
166
|
+
}
|
|
167
|
+
const local = await ready;
|
|
168
|
+
// The user may have cancelled or the session timed out while the backend was
|
|
169
|
+
// starting; importing into it now would keep an account nobody signs in to.
|
|
170
|
+
if (isEnded?.()) throw new Error('登录已结束,未导入 Cookie。');
|
|
171
|
+
const bind = formProxy !== undefined ? formProxy : initialProxy;
|
|
172
|
+
const added = await importCookie(local, cookie, {
|
|
173
|
+
authuser,
|
|
174
|
+
isEnded,
|
|
175
|
+
...(bind ? { proxy: bind } : {})
|
|
176
|
+
});
|
|
177
|
+
// importCookie's own rollback ends when it returns. A session that ends during
|
|
178
|
+
// poolAccounts or signInFor (accountEmail waits on Gemini, up to its 15s
|
|
179
|
+
// timeout) still leaves the account it created, so this submit keeps removing
|
|
180
|
+
// exactly added.id whenever isEnded is true once the account exists — never
|
|
181
|
+
// anybody else's.
|
|
182
|
+
const rollback = async () => {
|
|
183
|
+
if (!isEnded?.()) return;
|
|
184
|
+
await removeAccount(local, added.id).catch(() => {});
|
|
185
|
+
throw new Error('登录已取消。');
|
|
186
|
+
};
|
|
187
|
+
let account;
|
|
188
|
+
try {
|
|
189
|
+
account = (await poolAccounts().catch(() => [])).find(a => a.id === added.id);
|
|
190
|
+
await rollback();
|
|
191
|
+
const signIn = await signInFor(local, account || { id: added.id });
|
|
192
|
+
await rollback();
|
|
193
|
+
return { signIn, email: signIn.metadata?.email || '' };
|
|
194
|
+
} catch (err) {
|
|
195
|
+
await rollback();
|
|
196
|
+
throw err;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
});
|
|
160
200
|
return {
|
|
161
|
-
url:
|
|
162
|
-
method: '
|
|
163
|
-
instructions:
|
|
164
|
-
async callback(
|
|
165
|
-
let local, cookie, added;
|
|
201
|
+
url: session.url,
|
|
202
|
+
method: 'auto',
|
|
203
|
+
instructions: GUIDE_STEPS,
|
|
204
|
+
async callback() {
|
|
166
205
|
try {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
added = await importCookie(local, cookie, { authuser, ...(proxy ? { proxy } : {}) });
|
|
206
|
+
const done = await session.wait();
|
|
207
|
+
return done?.signIn || { type: 'failed', error: '登录没有返回结果' };
|
|
170
208
|
} catch (err) {
|
|
171
209
|
return { type: 'failed', error: err.message };
|
|
172
210
|
}
|
|
173
|
-
const account = (await poolAccounts().catch(() => [])).find(a => a.id === added.id);
|
|
174
|
-
return signInFor(local, account || { id: added.id });
|
|
175
211
|
}
|
|
176
212
|
};
|
|
177
213
|
}
|
package/lib/backend-release.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "6.2.
|
|
2
|
+
"version": "6.2.1",
|
|
3
3
|
"repository": "dorokuma/gemini-web2api-go",
|
|
4
|
-
"tag": "v6.2.
|
|
4
|
+
"tag": "v6.2.1",
|
|
5
5
|
"binaries": {
|
|
6
6
|
"darwin-x64": {
|
|
7
|
-
"asset": "gemini-web2api-go_v6.2.
|
|
8
|
-
"sha256": "
|
|
7
|
+
"asset": "gemini-web2api-go_v6.2.1_darwin_amd64",
|
|
8
|
+
"sha256": "e80326f81eb35d0e3055398fe0798f5f80232ce1117e7f42990f24082fd8087c"
|
|
9
9
|
},
|
|
10
10
|
"darwin-arm64": {
|
|
11
|
-
"asset": "gemini-web2api-go_v6.2.
|
|
12
|
-
"sha256": "
|
|
11
|
+
"asset": "gemini-web2api-go_v6.2.1_darwin_arm64",
|
|
12
|
+
"sha256": "f37176a47df928e367bdb6a82b983295670a2d0f710093a2edf6a67b3315f9d4"
|
|
13
13
|
},
|
|
14
14
|
"linux-x64": {
|
|
15
|
-
"asset": "gemini-web2api-go_v6.2.
|
|
16
|
-
"sha256": "
|
|
15
|
+
"asset": "gemini-web2api-go_v6.2.1_linux_amd64",
|
|
16
|
+
"sha256": "75ca02b0d3ca3b97496d79060d40d9826e71129203f368f6539179141ae7a40d"
|
|
17
17
|
},
|
|
18
18
|
"linux-arm64": {
|
|
19
|
-
"asset": "gemini-web2api-go_v6.2.
|
|
20
|
-
"sha256": "
|
|
19
|
+
"asset": "gemini-web2api-go_v6.2.1_linux_arm64",
|
|
20
|
+
"sha256": "fdd9e486409c50d54c16b933ffda16bf4fe7b97a4b12a032054dcf0700180261"
|
|
21
21
|
},
|
|
22
22
|
"win32-x64": {
|
|
23
|
-
"asset": "gemini-web2api-go_v6.2.
|
|
24
|
-
"sha256": "
|
|
23
|
+
"asset": "gemini-web2api-go_v6.2.1_windows_amd64.exe",
|
|
24
|
+
"sha256": "f23aaf60cb957c9d84df6c617baa3997ae33f3e8b31bfd8018588de3b04805ec"
|
|
25
25
|
},
|
|
26
26
|
"win32-arm64": {
|
|
27
|
-
"asset": "gemini-web2api-go_v6.2.
|
|
28
|
-
"sha256": "
|
|
27
|
+
"asset": "gemini-web2api-go_v6.2.1_windows_arm64.exe",
|
|
28
|
+
"sha256": "feb8a5bdf481a720d0587a6d5f53a7f2af453ff766ed37acd3f5691d7448d904"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// Launch the Gemini app in a private/incognito browser window. The sign-in session the backend
|
|
2
|
+
// keeps alive must not be shared with the user's daily browser: Google would revoke it on both
|
|
3
|
+
// sides. Firefox is preferred because Chrome's DBSC can re-bind a copied session to a profile
|
|
4
|
+
// the user already closed.
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { spawn } from 'node:child_process';
|
|
8
|
+
|
|
9
|
+
const GEMINI_HOST = /^(www\.)?gemini\.google\.com$/i;
|
|
10
|
+
// Firefox takes -private-window on macOS/Windows and --private-window on Linux; both spellings
|
|
11
|
+
// work everywhere, but each platform's conventional one is used.
|
|
12
|
+
const privateArg = { darwin: '-private-window', win32: '-private-window', linux: '--private-window' };
|
|
13
|
+
const PRIVATE_ARG = {
|
|
14
|
+
firefox: platform => privateArg[platform] || '--private-window',
|
|
15
|
+
chromium: '--incognito',
|
|
16
|
+
edge: '--inprivate'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// geminiURL restricts launches to the Gemini app: the wizard only ever sends users to Google,
|
|
20
|
+
// and a token-guessed local page must not be turned into an open-anything primitive.
|
|
21
|
+
export function geminiURL(value) {
|
|
22
|
+
let parsed;
|
|
23
|
+
try {
|
|
24
|
+
parsed = new URL(String(value ?? ''));
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
if (parsed.protocol !== 'https:' || !GEMINI_HOST.test(parsed.hostname) ||
|
|
29
|
+
parsed.username || parsed.password) return null;
|
|
30
|
+
return parsed.href;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Per-platform candidate lists, in priority order: Firefox first, then the Chromium family,
|
|
34
|
+
// Edge last. The first binary that exists wins; args never go through a shell.
|
|
35
|
+
function candidates(platform, env) {
|
|
36
|
+
if (platform === 'darwin') {
|
|
37
|
+
const home = env.HOME || '';
|
|
38
|
+
const app = (browser, appName, binary, flag) => [
|
|
39
|
+
{ browser, bin: `/Applications/${appName}.app/Contents/MacOS/${binary}`, flag },
|
|
40
|
+
...(home ? [{ browser, bin: path.join(home, 'Applications', `${appName}.app`, 'Contents', 'MacOS', binary), flag }] : [])
|
|
41
|
+
];
|
|
42
|
+
return [
|
|
43
|
+
...app('Firefox', 'Firefox', 'firefox', PRIVATE_ARG.firefox('darwin')),
|
|
44
|
+
...app('Google Chrome', 'Google Chrome', 'Google Chrome', PRIVATE_ARG.chromium),
|
|
45
|
+
...app('Brave', 'Brave Browser', 'Brave Browser', PRIVATE_ARG.chromium),
|
|
46
|
+
...app('Chromium', 'Chromium', 'Chromium', PRIVATE_ARG.chromium),
|
|
47
|
+
...app('Microsoft Edge', 'Microsoft Edge', 'Microsoft Edge', PRIVATE_ARG.edge)
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
if (platform === 'win32') {
|
|
51
|
+
const dirs = [env['ProgramFiles'], env['ProgramFiles(x86)'], env.LOCALAPPDATA].filter(Boolean);
|
|
52
|
+
const found = (name, rel, flag) => dirs.map(dir => ({ name, bin: path.join(dir, rel), flag }));
|
|
53
|
+
return [
|
|
54
|
+
...found('Firefox', path.join('Mozilla Firefox', 'firefox.exe'), PRIVATE_ARG.firefox('win32')),
|
|
55
|
+
...found('Google Chrome', path.join('Google', 'Chrome', 'Application', 'chrome.exe'), PRIVATE_ARG.chromium),
|
|
56
|
+
...found('Brave', path.join('BraveSoftware', 'Brave-Browser', 'Application', 'brave.exe'), PRIVATE_ARG.chromium),
|
|
57
|
+
...found('Chromium', path.join('Chromium', 'Application', 'chrome.exe'), PRIVATE_ARG.chromium),
|
|
58
|
+
...found('Microsoft Edge', path.join('Microsoft', 'Edge', 'Application', 'msedge.exe'), PRIVATE_ARG.edge)
|
|
59
|
+
].map(c => ({ ...c, browser: c.name }));
|
|
60
|
+
}
|
|
61
|
+
const dirs = (env.PATH || '').split(path.delimiter).filter(Boolean);
|
|
62
|
+
const inPath = (browser, bins, flag) => bins.map(bin => ({ browser, bin, flag, lookup: true, dirs }));
|
|
63
|
+
return [
|
|
64
|
+
...inPath('Firefox', ['firefox', 'firefox-esr'], PRIVATE_ARG.firefox('linux')),
|
|
65
|
+
...inPath('Google Chrome', ['google-chrome', 'google-chrome-stable'], PRIVATE_ARG.chromium),
|
|
66
|
+
...inPath('Chromium', ['chromium', 'chromium-browser'], PRIVATE_ARG.chromium),
|
|
67
|
+
...inPath('Brave', ['brave-browser'], PRIVATE_ARG.chromium),
|
|
68
|
+
...inPath('Microsoft Edge', ['microsoft-edge', 'microsoft-edge-stable'], PRIVATE_ARG.edge)
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function resolveBin(candidate, existsSync, injected) {
|
|
73
|
+
// With the real filesystem an existing path is not enough: a same-named directory cannot
|
|
74
|
+
// be exec'd, and on POSIX a file without +x fails spawn with EACCES. Both are skipped here
|
|
75
|
+
// so the next candidate still gets its turn. An injected existsSync keeps its plain truth
|
|
76
|
+
// table so unit tests needn't emulate stat/access too.
|
|
77
|
+
const usable = p => {
|
|
78
|
+
if (!existsSync(p)) return false;
|
|
79
|
+
if (injected) return true;
|
|
80
|
+
try {
|
|
81
|
+
if (!fs.statSync(p).isFile()) return false;
|
|
82
|
+
if (process.platform !== 'win32') fs.accessSync(p, fs.constants.X_OK);
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
};
|
|
88
|
+
if (!candidate.lookup) return usable(candidate.bin) ? candidate.bin : null;
|
|
89
|
+
for (const dir of candidate.dirs) {
|
|
90
|
+
const full = path.join(dir, candidate.bin);
|
|
91
|
+
if (usable(full)) return full;
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// launchPrivateBrowser spawns the first detected browser detached so the window outlives the
|
|
97
|
+
// plugin process. deps injects platform/env/existsSync/spawn so tests never open a real window.
|
|
98
|
+
// It is async because spawn() reports a bad binary asynchronously ('error' on the next tick):
|
|
99
|
+
// catching it synchronously both crashed the host on an unhandled 'error' and reported a
|
|
100
|
+
// phantom success instead of falling through to the next candidate.
|
|
101
|
+
export async function launchPrivateBrowser(url, deps = {}) {
|
|
102
|
+
const target = geminiURL(url);
|
|
103
|
+
if (!target) return { opened: false, reason: '只允许打开 https://gemini.google.com/ 的链接' };
|
|
104
|
+
const env = deps.env || process.env;
|
|
105
|
+
const injected = typeof deps.existsSync === 'function';
|
|
106
|
+
const existsSync = injected ? deps.existsSync : (p => fs.existsSync(p));
|
|
107
|
+
const spawnFn = deps.spawn || spawn;
|
|
108
|
+
for (const candidate of candidates(deps.platform || process.platform, env)) {
|
|
109
|
+
const bin = resolveBin(candidate, existsSync, injected);
|
|
110
|
+
if (!bin) continue;
|
|
111
|
+
let child;
|
|
112
|
+
try {
|
|
113
|
+
child = spawnFn(bin, [candidate.flag, target], { detached: true, stdio: 'ignore' });
|
|
114
|
+
} catch {
|
|
115
|
+
// A binary that exists but cannot spawn (broken install, permissions) is skipped the
|
|
116
|
+
// same as one that was never found; the next candidate still gets its turn.
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (typeof child?.once !== 'function') {
|
|
120
|
+
child?.unref?.();
|
|
121
|
+
return { opened: true, browser: candidate.browser };
|
|
122
|
+
}
|
|
123
|
+
// 'spawn' and 'error' are attached before yielding, so an async ENOENT/EACCES is claimed
|
|
124
|
+
// here and never reaches the process as an unhandled error.
|
|
125
|
+
const opened = await new Promise(resolve => {
|
|
126
|
+
let settled = false;
|
|
127
|
+
const settle = value => {
|
|
128
|
+
if (settled) return;
|
|
129
|
+
settled = true;
|
|
130
|
+
resolve(value);
|
|
131
|
+
};
|
|
132
|
+
child.once('error', () => settle(false));
|
|
133
|
+
child.once('spawn', () => {
|
|
134
|
+
// Keep an error sink after spawn too: a process that spawned may still emit 'error'
|
|
135
|
+
// later (stream failures etc.) and an unhandled one would crash the host.
|
|
136
|
+
child.on('error', () => {});
|
|
137
|
+
settle(true);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
if (opened) {
|
|
141
|
+
child.unref?.();
|
|
142
|
+
return { opened: true, browser: candidate.browser };
|
|
143
|
+
}
|
|
144
|
+
// This binary failed to spawn (async EACCES/ENOENT); try the next candidate.
|
|
145
|
+
}
|
|
146
|
+
return { opened: false, reason: '没有找到可启动无痕窗口的浏览器' };
|
|
147
|
+
}
|
package/lib/setup.mjs
CHANGED
|
@@ -230,11 +230,13 @@ export async function importCookie(setup, cookie, options = {}) {
|
|
|
230
230
|
const authuser = parseAuthuser(options.authuser);
|
|
231
231
|
const fetchFn = options.fetchFn || globalThis.fetch;
|
|
232
232
|
await requireLoginBackend(setup, options);
|
|
233
|
+
if (options.isEnded?.()) throw new Error('登录已取消。');
|
|
233
234
|
let proxyId = Number.isInteger(options.proxyId) ? options.proxyId : undefined;
|
|
234
235
|
if (options.proxy) {
|
|
235
236
|
const ensured = await ensureProxy(setup, options.proxy, { fetchFn });
|
|
236
237
|
if (ensured && Number.isInteger(ensured.id)) proxyId = ensured.id;
|
|
237
238
|
}
|
|
239
|
+
if (options.isEnded?.()) throw new Error('登录已取消。');
|
|
238
240
|
const label = options.label || `Magpie ${new Date().toISOString().slice(0, 10)}`;
|
|
239
241
|
const added = await adminCall(setup, fetchFn, 'POST', 'cookies', {
|
|
240
242
|
label,
|
|
@@ -245,6 +247,13 @@ export async function importCookie(setup, cookie, options = {}) {
|
|
|
245
247
|
});
|
|
246
248
|
if (!Number.isInteger(added.id)) throw new Error('本地后端没有返回新账号的 id');
|
|
247
249
|
|
|
250
|
+
// The sign-in may have been cancelled or timed out while the account was being created:
|
|
251
|
+
// remove the account this call just added — never anybody else's — then report the cancel.
|
|
252
|
+
if (options.isEnded?.()) {
|
|
253
|
+
await adminCall(setup, fetchFn, 'DELETE', `cookies/${added.id}`).catch(() => {});
|
|
254
|
+
throw new Error('登录已取消。');
|
|
255
|
+
}
|
|
256
|
+
|
|
248
257
|
let check;
|
|
249
258
|
try {
|
|
250
259
|
check = await adminCall(setup, fetchFn, 'POST', `cookies/${added.id}/check`, undefined,
|
|
@@ -253,9 +262,23 @@ export async function importCookie(setup, cookie, options = {}) {
|
|
|
253
262
|
await adminCall(setup, fetchFn, 'DELETE', `cookies/${added.id}`).catch(() => {});
|
|
254
263
|
throw err;
|
|
255
264
|
}
|
|
265
|
+
// A cancel that arrived while the check was in flight gets the same rollback: the session
|
|
266
|
+
// is over, so the verified account would sit in the pool with nobody signed in to it.
|
|
267
|
+
if (options.isEnded?.()) {
|
|
268
|
+
await adminCall(setup, fetchFn, 'DELETE', `cookies/${added.id}`).catch(() => {});
|
|
269
|
+
throw new Error('登录已取消。');
|
|
270
|
+
}
|
|
256
271
|
if (!check.ok) {
|
|
257
272
|
await adminCall(setup, fetchFn, 'DELETE', `cookies/${added.id}`).catch(() => {});
|
|
258
273
|
throw checkFailure(setup, check.detail || '');
|
|
259
274
|
}
|
|
260
275
|
return { id: added.id, detail: check.detail || '' };
|
|
261
276
|
}
|
|
277
|
+
|
|
278
|
+
// removeAccount deletes one account of the backend's pool by id: the rollback step for a
|
|
279
|
+
// sign-in session that ended after importCookie returned. Its caller created the account and
|
|
280
|
+
// is responsible for never naming anybody else's.
|
|
281
|
+
export async function removeAccount(setup, id, options = {}) {
|
|
282
|
+
const fetchFn = options.fetchFn || globalThis.fetch;
|
|
283
|
+
return adminCall(setup, fetchFn, 'DELETE', `cookies/${id}`);
|
|
284
|
+
}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
// Local sign-in wizard for the one-click Gemini Web setup. Magpie opens this page instead of
|
|
2
|
+
// gemini.google.com so the flow unfolds in the right order: open a private window first (the
|
|
3
|
+
// backend rotates this session and a shared one would sign the user's daily browser out of
|
|
4
|
+
// Google), sign in there and copy the Cookie, then tell us the /u/N index that same window
|
|
5
|
+
// shows — asking for the index before the window exists was guesswork.
|
|
6
|
+
import http from 'node:http';
|
|
7
|
+
import crypto from 'node:crypto';
|
|
8
|
+
import { launchPrivateBrowser } from './private-browser.mjs';
|
|
9
|
+
import { parseCookieInput, parseAuthuser, validateProxyURL } from './setup.mjs';
|
|
10
|
+
|
|
11
|
+
const GEMINI_APP = 'https://gemini.google.com/app';
|
|
12
|
+
const LINGER_MS = 2 * 60 * 1000;
|
|
13
|
+
const MAX_BODY = 256 * 1024;
|
|
14
|
+
const TIMEOUT_MS = 10 * 60 * 1000;
|
|
15
|
+
const TIMEOUT_MESSAGE = '本次登录等待已到 10 分钟,页面已失效;请在 Magpie 中重新发起登录。已安装的本地后端会保留。';
|
|
16
|
+
|
|
17
|
+
// esc is the only interpolation into the page template; every user- or config-derived string
|
|
18
|
+
// reaches the DOM through textContent / pre-filled values escaped here, never as markup.
|
|
19
|
+
const esc = s => String(s).replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
20
|
+
|
|
21
|
+
// startWebConnect serves the wizard on 127.0.0.1 behind a random token path. submit() runs the
|
|
22
|
+
// import pipeline (parse → wait for backend → import → sign-in result) injected by index.mjs so
|
|
23
|
+
// this module stays testable without a backend; the resolved value is what wait() hands Magpie.
|
|
24
|
+
export async function startWebConnect({ proxy = '', submit, privateBrowser = launchPrivateBrowser, timeoutMs = TIMEOUT_MS } = {}) {
|
|
25
|
+
if (typeof submit !== 'function') throw new Error('startWebConnect requires a submit handler');
|
|
26
|
+
const token = crypto.randomBytes(24).toString('hex');
|
|
27
|
+
const nonce = crypto.randomBytes(16).toString('base64');
|
|
28
|
+
let origin, ended = false, resultValue, error = '', linger, timer, closing, submitting = false;
|
|
29
|
+
|
|
30
|
+
let resolveResult, rejectResult;
|
|
31
|
+
const result = new Promise((resolve, reject) => { resolveResult = resolve; rejectResult = reject; });
|
|
32
|
+
result.catch(() => {}); // wait() may never be called if Magpie abandons the sign-in
|
|
33
|
+
|
|
34
|
+
function finish(err, value) {
|
|
35
|
+
if (ended) return;
|
|
36
|
+
ended = true;
|
|
37
|
+
clearTimeout(timer);
|
|
38
|
+
error = err?.message || '';
|
|
39
|
+
resultValue = value;
|
|
40
|
+
if (err) rejectResult(err); else resolveResult(value);
|
|
41
|
+
// Leave the page up briefly so the user can read the outcome before it goes away.
|
|
42
|
+
linger = setTimeout(close, LINGER_MS);
|
|
43
|
+
linger.unref();
|
|
44
|
+
}
|
|
45
|
+
function close() {
|
|
46
|
+
if (closing) return closing;
|
|
47
|
+
if (!ended) finish(new Error('登录页面已关闭,请在 Magpie 中重新登录。'));
|
|
48
|
+
clearTimeout(linger);
|
|
49
|
+
server.close();
|
|
50
|
+
server.closeAllConnections?.();
|
|
51
|
+
closing = Promise.resolve();
|
|
52
|
+
return closing;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const headers = { 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff', 'Referrer-Policy': 'no-referrer' };
|
|
56
|
+
const json = (res, status, data) => res.writeHead(status, { ...headers, 'Content-Type': 'application/json' }).end(JSON.stringify(data));
|
|
57
|
+
const server = http.createServer((req, res) => {
|
|
58
|
+
handle(req, res).catch(err => {
|
|
59
|
+
if (!res.headersSent) json(res, 502, { error: err.message });
|
|
60
|
+
else res.end();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
async function handle(req, res) {
|
|
65
|
+
const base = `/${token}`;
|
|
66
|
+
const route = req.url;
|
|
67
|
+
if (req.headers.host !== new URL(origin).host ||
|
|
68
|
+
![base, `${base}/state`, `${base}/open-private`, `${base}/submit`, `${base}/cancel`].includes(route)) {
|
|
69
|
+
res.writeHead(404, headers).end();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (req.method === 'POST' && (req.headers.origin !== origin ||
|
|
73
|
+
(req.headers['sec-fetch-site'] && req.headers['sec-fetch-site'] !== 'same-origin'))) {
|
|
74
|
+
res.writeHead(403, headers).end();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (req.method === 'GET' && route === base) {
|
|
78
|
+
res.writeHead(200, {
|
|
79
|
+
...headers, 'Content-Type': 'text/html; charset=utf-8',
|
|
80
|
+
'Content-Security-Policy': `default-src 'none'; script-src 'nonce-${nonce}'; style-src 'unsafe-inline'; connect-src 'self'; form-action 'none'; base-uri 'none'; frame-ancestors 'none'`
|
|
81
|
+
}).end(PAGE
|
|
82
|
+
// Function replacers: a literal replacement string would re-expand $$ $' $& $` in a
|
|
83
|
+
// proxy password into template metacharacters and corrupt the rendered DOM.
|
|
84
|
+
.replace('NONCE', () => nonce)
|
|
85
|
+
.replace('GEMINI_URL', () => GEMINI_APP)
|
|
86
|
+
.replace('PREFILL_PROXY', () => esc(proxy)));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (req.method === 'GET' && route === `${base}/state`) {
|
|
90
|
+
json(res, 200, { done: ended, error, email: resultValue?.email || '' });
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (req.method !== 'POST') { res.writeHead(405, headers).end(); return; }
|
|
94
|
+
if (route === `${base}/cancel`) {
|
|
95
|
+
finish(new Error('已取消登录。'));
|
|
96
|
+
res.writeHead(204, headers).end();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (route === `${base}/open-private`) {
|
|
100
|
+
// Read (and drain) the small body so the socket state stays clean.
|
|
101
|
+
await readBody(req);
|
|
102
|
+
if (ended) { json(res, 410, { error: error || '登录已经结束,请回到 Magpie。' }); return; }
|
|
103
|
+
json(res, 200, await privateBrowser(GEMINI_APP));
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (route === `${base}/submit`) {
|
|
107
|
+
if (ended) { json(res, 410, { error: error || '登录已经结束,请回到 Magpie。' }); return; }
|
|
108
|
+
// Single-flight, claimed before the first await so a second POST can never race the
|
|
109
|
+
// import pipeline: it gets a 409 while the first submit is still running. The flag is
|
|
110
|
+
// released on failure so the user can fix the fields and retry in place.
|
|
111
|
+
if (submitting) { json(res, 409, { error: '正在验证中,请稍候…' }); return; }
|
|
112
|
+
submitting = true;
|
|
113
|
+
try {
|
|
114
|
+
const body = await readBody(req);
|
|
115
|
+
if (ended) { json(res, 410, { error: error || '登录已经结束,请回到 Magpie。' }); return; }
|
|
116
|
+
let input;
|
|
117
|
+
try {
|
|
118
|
+
input = JSON.parse(body);
|
|
119
|
+
} catch {
|
|
120
|
+
json(res, 400, { error: '请求格式不正确' });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (!input || typeof input !== 'object' || Array.isArray(input)) {
|
|
124
|
+
json(res, 400, { error: '请求格式不正确' });
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
// Parse and validate every field before the backend sees anything: a bad cookie or index
|
|
128
|
+
// is reported in place, and the form keeps its values for a retry.
|
|
129
|
+
let cookie, authuser, proxyURL;
|
|
130
|
+
try {
|
|
131
|
+
cookie = parseCookieInput(input.cookie);
|
|
132
|
+
authuser = parseAuthuser(input.authuser);
|
|
133
|
+
proxyURL = validateProxyURL(input.proxy);
|
|
134
|
+
} catch (err) {
|
|
135
|
+
json(res, 400, { error: err.message });
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const value = await submit({ cookie, authuser, proxy: proxyURL, isEnded: () => ended });
|
|
140
|
+
if (ended) { json(res, 410, { error: error || '登录已经结束,请回到 Magpie。' }); return; }
|
|
141
|
+
finish(null, value || {});
|
|
142
|
+
json(res, 200, { ok: true, email: resultValue?.email || '' });
|
|
143
|
+
} catch (err) {
|
|
144
|
+
// The import failed (bad cookie, backend unreachable, unsupported build): the page
|
|
145
|
+
// shows the message in place and the user can fix the fields and submit again.
|
|
146
|
+
json(res, ended ? 410 : 400, { error: ended ? (error || '登录已经结束,请回到 Magpie。') : err.message });
|
|
147
|
+
}
|
|
148
|
+
return;
|
|
149
|
+
} finally {
|
|
150
|
+
// A session that is still open retries in place after a failed submit; once it has
|
|
151
|
+
// ended the flag no longer matters (the 410 check above runs first).
|
|
152
|
+
if (!ended) submitting = false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
res.writeHead(404, headers).end();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function readBody(req) {
|
|
159
|
+
return new Promise((resolve, reject) => {
|
|
160
|
+
let size = 0, tooBig = false;
|
|
161
|
+
const chunks = [];
|
|
162
|
+
req.on('data', chunk => {
|
|
163
|
+
size += chunk.length;
|
|
164
|
+
if (size > MAX_BODY && !tooBig) {
|
|
165
|
+
// Drain the rest instead of destroying the socket, so the error answer still
|
|
166
|
+
// reaches the client.
|
|
167
|
+
tooBig = true;
|
|
168
|
+
reject(new Error('提交内容过大'));
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (!tooBig) chunks.push(chunk);
|
|
172
|
+
});
|
|
173
|
+
req.on('end', () => { if (!tooBig) resolve(Buffer.concat(chunks).toString('utf8')); });
|
|
174
|
+
req.on('error', () => { if (!tooBig) reject(new Error('请求中断')); });
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
await new Promise((resolve, reject) => {
|
|
179
|
+
server.once('error', reject);
|
|
180
|
+
server.listen(0, '127.0.0.1', resolve);
|
|
181
|
+
});
|
|
182
|
+
server.unref();
|
|
183
|
+
origin = `http://127.0.0.1:${server.address().port}`;
|
|
184
|
+
timer = setTimeout(() => finish(new Error(TIMEOUT_MESSAGE)), Math.max(1, timeoutMs));
|
|
185
|
+
timer.unref();
|
|
186
|
+
return { url: `${origin}/${token}`, wait: () => result, close };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const PAGE = `<!doctype html>
|
|
190
|
+
<html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
191
|
+
<title>登录 Gemini Web</title>
|
|
192
|
+
<style>
|
|
193
|
+
:root { color-scheme: light dark; font: 16px/1.7 system-ui, sans-serif; }
|
|
194
|
+
body { max-width: 640px; margin: 6vh auto; padding: 0 24px 48px; }
|
|
195
|
+
h1 { font-size: 24px; } h2 { font-size: 18px; margin-top: 2em; }
|
|
196
|
+
p, li { opacity: .88; }
|
|
197
|
+
button { font: inherit; padding: 8px 18px; border-radius: 8px; cursor: pointer; }
|
|
198
|
+
textarea, input[type=text] { width: 100%; box-sizing: border-box; font: 13px/1.5 ui-monospace, monospace; padding: 8px; border-radius: 6px; border: 1px solid #8884; background: transparent; color: inherit; }
|
|
199
|
+
textarea { min-height: 96px; resize: vertical; }
|
|
200
|
+
label { display: block; margin: 14px 0 4px; font-weight: 600; }
|
|
201
|
+
.hint { font-size: 13px; opacity: .65; margin-top: 2px; }
|
|
202
|
+
.status { min-height: 1.5em; }
|
|
203
|
+
.error { color: #d33; }
|
|
204
|
+
.ok { color: #187a2e; }
|
|
205
|
+
code { user-select: all; }
|
|
206
|
+
[hidden] { display: none; }
|
|
207
|
+
</style></head><body>
|
|
208
|
+
<h1>登录 Gemini Web</h1>
|
|
209
|
+
|
|
210
|
+
<h2>第 1 步:用无痕窗口打开 Gemini 并登录</h2>
|
|
211
|
+
<p>必须使用无痕 / 隐私窗口(推荐 Firefox),不要用平时登录着 Google 的窗口:本地后端会定时刷新这份登录来保活,和日常浏览器共用同一会话会被 Google 整个踢出登录。无痕窗口关掉后会话只留给后端。</p>
|
|
212
|
+
<p><button id="open">打开无痕窗口登录 Gemini</button> <button id="cancel" type="button">取消登录</button></p>
|
|
213
|
+
<p id="open-status" class="status" role="status" aria-live="polite"></p>
|
|
214
|
+
<p id="manual">也可以手动开一个无痕窗口,访问<br><code>GEMINI_URL</code></p>
|
|
215
|
+
|
|
216
|
+
<h2>第 2 步:复制 Cookie</h2>
|
|
217
|
+
<ol>
|
|
218
|
+
<li>在无痕窗口里登录要使用的 Google 账号。</li>
|
|
219
|
+
<li>按 <kbd>F12</kbd>(macOS 按 <kbd>⌥⌘I</kbd>)打开开发者工具,切到 <b>Network(网络)</b>,刷新页面。</li>
|
|
220
|
+
<li>点列表里任意一个 <code>gemini.google.com</code> 请求 → <b>Headers</b> → <b>Request Headers</b>,复制 <code>cookie</code> 一行的完整值。</li>
|
|
221
|
+
</ol>
|
|
222
|
+
<label for="cookie">Cookie(必填)</label>
|
|
223
|
+
<textarea id="cookie" spellcheck="false" placeholder="cookie 请求头的值;也支持 DevTools 表格复制或 JSON 导出"></textarea>
|
|
224
|
+
<label for="authuser">Google 账号索引(authuser,可选)</label>
|
|
225
|
+
<input type="text" id="authuser" spellcheck="false" placeholder="0">
|
|
226
|
+
<p class="hint">对照无痕窗口登录后的地址栏 <code>/u/N/app</code> 填写 <code>N</code>;单账号留空即可(按 0 处理)。无痕窗口的索引可能和日常窗口不同。</p>
|
|
227
|
+
<label for="proxy">代理地址(可选)</label>
|
|
228
|
+
<input type="text" id="proxy" spellcheck="false" value="PREFILL_PROXY" placeholder="http://127.0.0.1:7890">
|
|
229
|
+
<p class="hint">访问 Google 需要代理时填写(http / https / socks5 / socks5h),会绑定到这个账号;留空则不在本次登录指定代理,若本地后端已配置代理池,仍会按后端规则生效。</p>
|
|
230
|
+
|
|
231
|
+
<h2>第 3 步:验证并完成登录</h2>
|
|
232
|
+
<p><button id="submit">验证并完成登录</button></p>
|
|
233
|
+
<p id="submit-status" class="status" role="status" aria-live="polite"></p>
|
|
234
|
+
<p>Cookie 只保存在本机的 Gemini Web 后端里,不会发到别处。完成后<b>直接关闭无痕窗口,不要点「退出登录」</b>(退出会让这份 Cookie 失效)。</p>
|
|
235
|
+
|
|
236
|
+
<script nonce="NONCE">
|
|
237
|
+
const base = location.pathname;
|
|
238
|
+
const openBtn = document.getElementById('open');
|
|
239
|
+
const openStatus = document.getElementById('open-status');
|
|
240
|
+
const manual = document.getElementById('manual');
|
|
241
|
+
const submitBtn = document.getElementById('submit');
|
|
242
|
+
const submitStatus = document.getElementById('submit-status');
|
|
243
|
+
const cancelBtn = document.getElementById('cancel');
|
|
244
|
+
let done = false;
|
|
245
|
+
|
|
246
|
+
async function post(route, data) {
|
|
247
|
+
const res = await fetch(base + route, {
|
|
248
|
+
method: 'POST',
|
|
249
|
+
headers: { 'Content-Type': 'application/json' },
|
|
250
|
+
body: JSON.stringify(data || {})
|
|
251
|
+
});
|
|
252
|
+
const body = res.status === 204 ? null : await res.json().catch(() => null);
|
|
253
|
+
// 410 means the session is over (cancel, timeout, Magpie gave up): nothing on the page can
|
|
254
|
+
// still change that, and a retried submit would be refused the same way.
|
|
255
|
+
if (res.status === 410) {
|
|
256
|
+
done = true;
|
|
257
|
+
submitBtn.disabled = openBtn.disabled = true;
|
|
258
|
+
throw new Error((body && body.error) || '登录已经结束,请回到 Magpie 重新发起登录。');
|
|
259
|
+
}
|
|
260
|
+
if (!res.ok) throw new Error((body && body.error) || '本地服务暂时不可用,请重试。');
|
|
261
|
+
return body;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
openBtn.onclick = async () => {
|
|
265
|
+
openBtn.disabled = true;
|
|
266
|
+
openStatus.className = 'status';
|
|
267
|
+
try {
|
|
268
|
+
const r = await post('/open-private');
|
|
269
|
+
// The manual link stays visible either way: an opened window may be hidden behind others
|
|
270
|
+
// (or refused by an already-running Firefox on macOS), and 'opened: false' explains itself.
|
|
271
|
+
if (r && r.opened) {
|
|
272
|
+
openStatus.textContent = '已用 ' + r.browser + ' 打开无痕窗口。如果窗口没有弹到最前,请在任务栏 / Dock 里找到它,或使用下方链接手动打开。';
|
|
273
|
+
} else {
|
|
274
|
+
openStatus.textContent = (r && r.reason) || '没有找到可启动无痕窗口的浏览器。';
|
|
275
|
+
}
|
|
276
|
+
} catch (err) {
|
|
277
|
+
openStatus.className = 'status error';
|
|
278
|
+
openStatus.textContent = err.message;
|
|
279
|
+
} finally {
|
|
280
|
+
if (!done) openBtn.disabled = false;
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
submitBtn.onclick = async () => {
|
|
285
|
+
submitBtn.disabled = true;
|
|
286
|
+
submitStatus.className = 'status';
|
|
287
|
+
submitStatus.textContent = '正在验证登录…首次使用会先下载并启动本地后端,可能需要几分钟,请不要关闭本页。';
|
|
288
|
+
try {
|
|
289
|
+
const r = await post('/submit', {
|
|
290
|
+
cookie: document.getElementById('cookie').value,
|
|
291
|
+
authuser: document.getElementById('authuser').value,
|
|
292
|
+
proxy: document.getElementById('proxy').value
|
|
293
|
+
});
|
|
294
|
+
done = true;
|
|
295
|
+
submitStatus.className = 'status ok';
|
|
296
|
+
submitStatus.textContent = '登录成功' + (r && r.email ? ',已绑定 ' + r.email : '') + '。现在可以关闭无痕窗口和本页面,回到 Magpie 使用。';
|
|
297
|
+
submitBtn.hidden = true;
|
|
298
|
+
openBtn.disabled = true;
|
|
299
|
+
} catch (err) {
|
|
300
|
+
// An in-place retry is only offered while the session still lives: once done is set
|
|
301
|
+
// (submit succeeded, cancel clicked, or the server answered 410) the form stays down.
|
|
302
|
+
if (done) {
|
|
303
|
+
submitStatus.className = 'status';
|
|
304
|
+
submitStatus.textContent = err.message;
|
|
305
|
+
} else {
|
|
306
|
+
submitStatus.className = 'status error';
|
|
307
|
+
submitStatus.textContent = err.message + '(可修改上方内容后直接重试)';
|
|
308
|
+
}
|
|
309
|
+
} finally {
|
|
310
|
+
if (!done) submitBtn.disabled = false;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
cancelBtn.onclick = async () => {
|
|
315
|
+
cancelBtn.disabled = true;
|
|
316
|
+
// The session is over the moment the user asks: lock the form now so a submit already in
|
|
317
|
+
// flight cannot light the fields back up or offer a retry that the server would refuse.
|
|
318
|
+
done = true;
|
|
319
|
+
submitBtn.disabled = openBtn.disabled = true;
|
|
320
|
+
try { await post('/cancel'); } catch {}
|
|
321
|
+
submitStatus.className = 'status';
|
|
322
|
+
submitStatus.textContent = '已取消登录,可以关闭本页面。';
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
// If the session ends another way (timeout, Magpie giving up), say so instead of hanging.
|
|
326
|
+
async function poll() {
|
|
327
|
+
if (done) return;
|
|
328
|
+
try {
|
|
329
|
+
const r = await fetch(base + '/state', { cache: 'no-store' });
|
|
330
|
+
if (!r.ok) return;
|
|
331
|
+
const state = await r.json();
|
|
332
|
+
if (state.done) {
|
|
333
|
+
done = true;
|
|
334
|
+
submitBtn.disabled = openBtn.disabled = true;
|
|
335
|
+
submitStatus.className = 'status ' + (state.error ? 'error' : 'ok');
|
|
336
|
+
submitStatus.textContent = state.error || '登录已完成,可以关闭本页面。';
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
} catch { return; }
|
|
340
|
+
setTimeout(poll, 2000);
|
|
341
|
+
}
|
|
342
|
+
poll();
|
|
343
|
+
</script></body></html>`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dorokuma/magpie-gemini-web",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "Google AI Studio and Gemini Web provider for Magpie (Gemini 4 Neon / Carbon / Hydrogen in Chat & Task modes, Nano Banana image generation, Deep Research), backed by AIStudio2API and gemini-web2api-go",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.mjs",
|