magpie-gemini-web 0.7.0 → 0.8.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/README.en.md +33 -10
- package/README.md +33 -10
- package/docs/studio-release.md +33 -13
- package/index.mjs +5 -1
- package/lib/backend-release.json +14 -14
- package/lib/backend.mjs +127 -4
- package/lib/studio-native.mjs +7 -3
- package/lib/studio-release.json +45 -19
- package/lib/studio.mjs +75 -9
- package/lib/usage.mjs +47 -33
- package/package.json +2 -2
- package/patches/argon.patch +690 -53
- package/scripts/studio-managed-smoke.mjs +6 -2
- package/scripts/studio-release.mjs +89 -31
package/README.en.md
CHANGED
|
@@ -17,9 +17,11 @@ The plugin provides two independent providers that can be used individually or t
|
|
|
17
17
|
| **Best for** | **Coding agents (recommended)** | General chat, web-only models & web quota |
|
|
18
18
|
| **Tool calling** | **Native Function Calling**, reliable | Prompt-emulated (experimental; Flash often skips tools) |
|
|
19
19
|
| **Thinking levels** | Supported levels from the model catalog: `minimal` / `low` / `medium` / `high` | `low` (base) / `medium` (`-thinking-medium`, `gemini-4-argon` only) / `high` (`-thinking` extended thinking) |
|
|
20
|
+
| **Image input** | On by default; chat models read images | Off by default; needs a signed-in cookie once on (see below) |
|
|
21
|
+
| **Image generation** | Nano Banana models, for Magpie's image generation (Magpie v0.1.2075+, see below) | Not supported |
|
|
20
22
|
| **Sign-in method** | Sign in directly in an isolated popup browser window | Copy `cookie` from a private/incognito window |
|
|
21
23
|
| **Usage cards** | Shows models currently on cooldown and recovery times | Syncs **5-hour** & **weekly** usage and reset times from the web |
|
|
22
|
-
| **Local backend** | AIStudio2API (`v0.2.
|
|
24
|
+
| **Local backend** | AIStudio2API (`v0.2.18`) | gemini-web2api-go (`4.26.0-magpie.2` optimized build) |
|
|
23
25
|
|
|
24
26
|
---
|
|
25
27
|
|
|
@@ -31,7 +33,7 @@ Install **magpie-gemini-web** from the Magpie plugin market, then sign in to eit
|
|
|
31
33
|
|
|
32
34
|
1. Sign in to **Google AI Studio** in Magpie and choose **「用 Google 账号登录(推荐)」** (Sign in with a Google account).
|
|
33
35
|
2. Sign in to your Google account in the separate login window that opens (your regular browser is unaffected), then close the window.
|
|
34
|
-
> On first run, the local service (~
|
|
36
|
+
> On first run, the local service (~40 MB) and the login browser Camoufox (~300 MB) are downloaded first, so the window may take a few minutes to appear. While they download, Magpie opens a progress page in your browser. Magpie waits at most 10 minutes, downloads included, so finish signing in promptly; if GitHub is unreachable, set `studio.proxy` first (see plugin options and proxy settings below).
|
|
35
37
|
3. **Managing accounts:** Choose "Sign in with a Google account" again at any time to **add a new account**, create a card for an existing local account, or **re-authenticate** an expired account.
|
|
36
38
|
|
|
37
39
|
### Option 2: Gemini Web (`gemini-web`)
|
|
@@ -56,11 +58,28 @@ Install **magpie-gemini-web** from the Magpie plugin market, then sign in to eit
|
|
|
56
58
|
- *Migrating older Gemini Web accounts:* For accounts added in earlier versions, add a Gemini Web account in Magpie and choose **「添加本地后端里已有的 Google 账号」** (Add an existing Google account from the local backend) to create individual cards, then remove the old pooled `API key …` card.
|
|
57
59
|
- **Automatic account rotation:** The local backend selects which Google account serves each request (Gemini Web rotates across the pool; AI Studio uses one account until cooldown and switches to the next). Switching cards in Magpie does not change which account the backend picks.
|
|
58
60
|
- **Usage reporting:**
|
|
59
|
-
- `gemini-web`: Available only with the one-click local backend.
|
|
61
|
+
- `gemini-web`: Available only with the one-click local backend. Usage is read from Google again whenever Magpie asks for it (at most once every 30 seconds per account), so pressing refresh shows the current allowance, including usage from the Gemini app, the website or other devices. On its own, Magpie asks about once a minute while the Usage page or the menu bar's allowances panel is open, whenever it updates allowances shown in the menu bar (every 3 minutes by default), and at most once a minute while it routes requests among accounts; otherwise it doesn't ask. A failed read isn't retried on its own for 10 minutes; pressing refresh in that time retries it at once (press it again if the first press doesn't).
|
|
60
62
|
- `ai-studio`: AI Studio does not report remaining total quota; cards display models currently on cooldown and their recovery times, or prompt when re-authentication is needed.
|
|
61
63
|
|
|
62
64
|
---
|
|
63
65
|
|
|
66
|
+
## Image Generation (AI Studio)
|
|
67
|
+
|
|
68
|
+
`ai-studio` lists the Nano Banana image models your account can use (such as `gemini-3.1-flash-image` and `gemini-3-pro-image`), for Magpie's image generation. **This needs Magpie v0.1.2075 or later**, the first to take a plugin's Gemini image models as models that draw.
|
|
69
|
+
|
|
70
|
+
**Drawing from an agent** (pi, Claude Code, Codex and the rest alike):
|
|
71
|
+
|
|
72
|
+
1. **Pick the model to draw with:** Magpie's Settings list these models under **Images → Image generation**. Pick one (such as `ai-studio/gemini-nano-banana-2.1`), or leave it on Automatic. There's no need to tick them in any model list.
|
|
73
|
+
2. **Give the agent the drawing tool:** click **Give agents Magpie Image…** under that row, tick the agents that should draw in the Library it opens, then start a new session in the agent. With the Library turned off, the row says **Turn on the Library** instead: click that first. From the command line: `magpie library mcp add magpie-image magpie mcp image agents=pi` (several agents separated by commas, as in `agents=pi,claude`).
|
|
74
|
+
3. **Chat as usual:** keep the agent on its usual chat model and ask it to draw something. It calls the `generate_image` tool, which draws with the model from step 1 and saves the image in the project's `generated-images/` folder; reference images make it an edit.
|
|
75
|
+
|
|
76
|
+
- **Don't pick an image model as the chat model:** Magpie still keeps a plugin's models that draw in its chat model lists ([yetone/magpie#2792](https://github.com/yetone/magpie/issues/2792)). Picked there, they show no picture: an agent such as pi has no place for an image in the model's reply, so the image the model draws is dropped, while the model believes it was shown. They take no tool calls either, and have 32K–128K context windows.
|
|
77
|
+
- **Drawing from the command line:** `magpie tool generate_image "a magpie on a branch, watercolour" --size 16:9 -o magpie.png`; add `--model ai-studio/gemini-3-pro-image` to draw with another model this once. If the terminal can't find the `magpie` command (step 2's command too), click **Add to PATH** on the **Command line** row of Magpie's Settings, then open a new terminal.
|
|
78
|
+
- **Size:** `size` gives the aspect ratio. A ratio (such as `16:9` or `1:4`) is used as it is when the model takes it, else the nearest one it does; a size such as `1536x1024` is made the nearest usual ratio by Magpie first. `quality` makes no difference for these models.
|
|
79
|
+
- If you don't want the image models, turn them off with `studio.imageModels` (see the options below).
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
64
83
|
## Configuration & Advanced Usage
|
|
65
84
|
|
|
66
85
|
<details>
|
|
@@ -68,12 +87,15 @@ Install **magpie-gemini-web** from the Magpie plugin market, then sign in to eit
|
|
|
68
87
|
|
|
69
88
|
<br>
|
|
70
89
|
|
|
71
|
-
Tool calling is enabled by default
|
|
90
|
+
Tool calling is enabled by default. Image input is on by default for AI Studio and off for Gemini Web. Configure plugin options via the CLI:
|
|
72
91
|
|
|
73
92
|
```bash
|
|
74
|
-
#
|
|
93
|
+
# Turn image input on for both providers
|
|
75
94
|
magpie plugin options magpie-gemini-web '{"allowImages":true}'
|
|
76
95
|
|
|
96
|
+
# Turn image input off for AI Studio
|
|
97
|
+
magpie plugin options magpie-gemini-web '{"studio":{"allowImages":false}}'
|
|
98
|
+
|
|
77
99
|
# Configure a proxy for AI Studio
|
|
78
100
|
magpie plugin options magpie-gemini-web '{"studio":{"proxy":"http://127.0.0.1:7890"}}'
|
|
79
101
|
```
|
|
@@ -85,8 +107,8 @@ magpie plugin options magpie-gemini-web '{"studio":{"proxy":"http://127.0.0.1:78
|
|
|
85
107
|
| Option | Default | Scope | Description |
|
|
86
108
|
| :--- | :--- | :--- | :--- |
|
|
87
109
|
| `allowTools` | `true` | Shared (override via `studio.allowTools`) | Allow tool calls. When `false`, requests with tools return 400 |
|
|
88
|
-
| `allowImages` | `false` | Shared (override via `studio.allowImages`) | Allow image input |
|
|
89
|
-
| `requestTimeoutMs` / `modelTimeoutMs` | Web: `
|
|
110
|
+
| `allowImages` | Web: `false`; Studio: `true` | Shared (override via `studio.allowImages`) | Allow image input in a chat (an image model's reference images don't need it). Gemini Web reads images only when signed in and returns 400 otherwise; in testing, `gemini-3.6-flash` waited until the timeout on a chat with an image, while `gemini-3.5-flash-lite` and `gemini-3.8-flash` answered |
|
|
111
|
+
| `requestTimeoutMs` / `modelTimeoutMs` | Web: `570000` / `10000`; Studio: `1800000` / `10000` | Shared (override via `studio.*`) | Timeout (ms) per backend wait or model list fetch; resets on stream data, explicit settings take precedence |
|
|
90
112
|
| `stripCitations` | `true` | `gemini-web` only | Strip `[cite: 1]` and `[cite_start]` markers from replies and tool arguments (not supported on AI Studio) |
|
|
91
113
|
| `proxy` | none | `gemini-web` only | Proxy for the managed Gemini Web backend to reach Google (`http` / `https` / `socks5` / `socks5h`), or set `GEMINI_WEB_PROXY` env var / enter during sign-in |
|
|
92
114
|
| `baseURL` | `http://127.0.0.1:8083/v1` | `gemini-web` only | Default Gemini Web backend URL |
|
|
@@ -94,6 +116,7 @@ magpie plugin options magpie-gemini-web '{"studio":{"proxy":"http://127.0.0.1:78
|
|
|
94
116
|
| `studio.proxy` | none | `ai-studio` only | Proxy for reaching Google (`http` / `https` / `socks5`), or set `AI_STUDIO_PROXY` env var; when set, it takes precedence over the proxy saved in the admin page. An empty value counts as unset |
|
|
95
117
|
| `studio.baseURL` | `http://127.0.0.1:2048/v1` | `ai-studio` only | Default URL when connecting an existing AIStudio2API instance |
|
|
96
118
|
| `studio.contextLimit` / `studio.outputLimit` | Model catalog defaults | `ai-studio` only | Limits reported to clients (can only lower the catalog defaults) |
|
|
119
|
+
| `studio.imageModels` | `true` | `ai-studio` only | List the Nano Banana image models, for Magpie's image generation; `false` lists text models only |
|
|
97
120
|
|
|
98
121
|
**Using a proxy to reach Google:**
|
|
99
122
|
- **AI Studio:** Preferably set it in the local admin page. Open the address on the usage card's "管理页" (admin page) line (default `http://127.0.0.1:2048`) and sign in as `magpie` with `adminPassword` from `config.json` in the data directory. Save the proxy, then restart the service from the admin page. The plugin keeps the saved value when it restarts the backend.
|
|
@@ -146,10 +169,10 @@ When a plugin error asks you to run a command, it includes the full ready-to-cop
|
|
|
146
169
|
- Both backends listen on `127.0.0.1` only. Cookies and sessions remain on your machine; Magpie stores only a locally generated API key.
|
|
147
170
|
- **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).
|
|
148
171
|
- **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.
|
|
149
|
-
-
|
|
172
|
+
- 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.
|
|
150
173
|
|
|
151
174
|
**AI Studio upgrades and model selection:**
|
|
152
|
-
- The plugin pins SHA-256-verified `v0.2.
|
|
175
|
+
- The plugin pins SHA-256-verified `v0.2.18-magpie.1`, based on upstream `v0.2.18`. Upgrade the plugin to update the backend. Official releases at or below that upstream version, and managed backends an older plugin installed, are upgraded on the next managed startup, preserving accounts, port and sign-in credentials.
|
|
153
176
|
- **Online updates are disabled in the managed backend on macOS, Linux, and Windows.** The admin page says updates are managed by magpie-gemini-web; the update endpoint returns HTTP 409 and update checks do not contact GitHub. Independently managed external servers are unaffected. See [docs/studio-release.md](docs/studio-release.md) for how the managed build is made and reproduced.
|
|
154
177
|
- Managed Unix installs still attempt to set `package/` to `0555` as additional file protection. Permission failures do not block service, and disabling online updates does not depend on permissions. To reset by manually deleting the data directory, stop the service first, then run `chmod -R u+w "<data-dir>/package"` before deleting it; replace `<data-dir>` with the actual path.
|
|
155
178
|
- If a newer or custom version is installed, the plugin reports a conflict with `stop`, `install`, and `start` commands carrying the correct `--data-dir`. Stop can recover a changed listener PID and verifies its executable path before signaling it. If HTTP is down but the process is still alive, the plugin refuses to reinstall or launch a second process.
|
|
@@ -159,7 +182,7 @@ When a plugin error asks you to run a command, it includes the full ready-to-cop
|
|
|
159
182
|
- 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.
|
|
160
183
|
|
|
161
184
|
**Gemini Web optimized backend upgrades & rollback:**
|
|
162
|
-
- One-click setup uses [4.26.0-magpie.
|
|
185
|
+
- One-click setup uses [4.26.0-magpie.2](https://github.com/BUKOWSKIREAL/magpie-gemini-web/releases/tag/backend-v4.26.0-magpie.2) by default (built from pinned upstream v4.26.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.
|
|
163
186
|
- **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.
|
|
164
187
|
- **Rollback to upstream / restore optimized build** (run in the plugin directory after stopping the backend):
|
|
165
188
|
```bash
|
package/README.md
CHANGED
|
@@ -17,9 +17,11 @@
|
|
|
17
17
|
| **适用场景** | **推荐 Coding Agent 使用** | 日常对话、使用网页版专属模型与额度 |
|
|
18
18
|
| **工具调用** | **原生 Function Calling**,稳定可靠 | 提示词模拟(实验性,Flash 系列常不调工具) |
|
|
19
19
|
| **思考档位** | 按模型目录提供 `minimal` / `low` / `medium` / `high` 中支持的档位 | `low`(普通)/ `medium`(`-thinking-medium`,仅 `gemini-4-argon`)/ `high`(`-thinking` 扩展思考) |
|
|
20
|
+
| **图片输入** | 默认开启,对话模型可以读图 | 默认关闭;开启后需要登录(挂 Cookie),见下文 |
|
|
21
|
+
| **图片生成** | Nano Banana 系列模型,供 Magpie 的图片生成使用(需要 Magpie v0.1.2075+,见下文) | 不支持 |
|
|
20
22
|
| **登录方式** | 弹出独立浏览器窗口直接登录 Google | 用无痕窗口登录并复制 `cookie` |
|
|
21
23
|
| **额度卡片** | 显示冷却中的模型与恢复时间 | 同步网页版 **5 小时** 与 **每周** 用量及重置时间 |
|
|
22
|
-
| **本地后端** | AIStudio2API (`v0.2.
|
|
24
|
+
| **本地后端** | AIStudio2API (`v0.2.18`) | gemini-web2api-go (`4.26.0-magpie.2` 优化版) |
|
|
23
25
|
|
|
24
26
|
---
|
|
25
27
|
|
|
@@ -31,7 +33,7 @@
|
|
|
31
33
|
|
|
32
34
|
1. 在 Magpie 中登录 **Google AI Studio**,选择 **「用 Google 账号登录(推荐)」**。
|
|
33
35
|
2. 在弹出的独立登录窗口中登录 Google 账号(不影响日常浏览器),完成后直接关闭窗口。
|
|
34
|
-
> 首次使用要先下载本地服务(约
|
|
36
|
+
> 首次使用要先下载本地服务(约 40 MB)和登录浏览器 Camoufox(约 300 MB),弹窗可能需要等几分钟才出现。需要下载时,Magpie 会在浏览器里打开一个进度页,显示下载进度。Magpie 最多等 10 分钟(下载的时间也算在内),请尽快完成登录;连不上 GitHub 时,先按下面「插件选项与代理配置」设置 `studio.proxy`。
|
|
35
37
|
3. **后续管理**:再次点击「用 Google 账号登录」,可选择**添加新账号**、为本机已有账号建卡,或为过期账号**重新登录**。
|
|
36
38
|
|
|
37
39
|
### 方式二:Gemini Web (`gemini-web`)
|
|
@@ -56,11 +58,28 @@
|
|
|
56
58
|
- *旧版迁移(Gemini Web)*:若后端里已有早期版本添加的账号,在登录时选 **「添加本地后端里已有的 Google 账号」** 即可生成独立卡片,随后可删掉旧的 `API key …` 汇总卡片。
|
|
57
59
|
- **账号池自动调度**:请求实际使用哪个账号由本地后端决定(Gemini Web 在账号池中轮流挑选;AI Studio 先用一个,进入冷却再切下一个)。在 Magpie 界面切换卡片不会改变后端的账号调度。
|
|
58
60
|
- **用量刷新说明**:
|
|
59
|
-
- `gemini-web
|
|
61
|
+
- `gemini-web`:仅一键配置的本地后端可读取用量。Magpie 每次来查都会向 Google 重新读取(同一账号 30 秒内只读一次),点刷新即显示最新额度,包括在 Gemini 官方 App、网页或其他设备上的用量。Magpie 自己来查的频率:用量页或菜单栏的额度面板开着时约每分钟一次;菜单栏显示任何一家额度时随菜单栏更新(默认每 3 分钟);经 Magpie 转发请求时最多每分钟一次;都没有时不查。读取失败后 10 分钟内不自动重试,这期间点刷新会立即重试,若未生效再点一次。
|
|
60
62
|
- `ai-studio`:AI Studio 不提供剩余总额度,卡片会展示当前账号正在冷却的模型、恢复时间或重新登录提示。
|
|
61
63
|
|
|
62
64
|
---
|
|
63
65
|
|
|
66
|
+
## 图片生成(AI Studio)
|
|
67
|
+
|
|
68
|
+
`ai-studio` 会列出账号可用的 Nano Banana 系列图像模型(如 `gemini-3.1-flash-image`、`gemini-3-pro-image`),供 Magpie 的图片生成使用。**需要 Magpie v0.1.2075 及以上**:从这个版本起,Magpie 才会把插件的 Gemini 图像模型列为出图模型。
|
|
69
|
+
|
|
70
|
+
**让 Agent 出图**(pi、Claude Code、Codex 等都一样):
|
|
71
|
+
|
|
72
|
+
1. **选画图模型**:Magpie 设置的 **Images → Image generation** 会直接列出这些模型,选中一个(如 `ai-studio/gemini-nano-banana-2.1`),或保持 Automatic(自动)。不用在模型列表里勾选它们。
|
|
73
|
+
2. **把画图工具交给 Agent**:点这一行下面的 **Give agents Magpie Image…**,在打开的 Library 里勾选要出图的 Agent,然后新开一个 Agent 会话。Library 被关掉时,这里显示的是 **Turn on the Library**,先点它。也可以用命令行:`magpie library mcp add magpie-image magpie mcp image agents=pi`(多个 Agent 用逗号隔开,如 `agents=pi,claude`)。
|
|
74
|
+
3. **照常对话**:Agent 继续用平常的对话模型,跟它说「画一张……」就行。它会调用 `generate_image` 工具,用第 1 步选的模型出图,图片存进项目的 `generated-images/` 文件夹;带参考图就是改图。
|
|
75
|
+
|
|
76
|
+
- **别把图像模型选成对话模型**:Magpie 目前会把能出图的插件模型也留在对话模型列表里([yetone/magpie#2792](https://github.com/yetone/magpie/issues/2792))。选了也看不到图:pi 等 Agent 的回复里放不下图片,模型画出的图会被直接丢掉,模型却以为已经发出去了。它们也不支持工具调用,上下文只有 32K–128K。
|
|
77
|
+
- **在命令行出图**:`magpie tool generate_image "a magpie on a branch, watercolour" --size 16:9 -o magpie.png`,加 `--model ai-studio/gemini-3-pro-image` 可以临时换模型。终端里找不到 `magpie` 命令时(第 2 步的命令也一样),在 Magpie 设置的 **Command line** 一行点 **Add to PATH**,再开一个新终端。
|
|
78
|
+
- **尺寸**:`size` 决定宽高比:写比例(如 `16:9`、`1:4`)时,模型支持就照用,不支持就取它支持的最接近的比例;写 `1536x1024` 这样的尺寸时,Magpie 先换成最接近的常用比例。`quality` 对这些模型不起作用。
|
|
79
|
+
- 不需要图像模型时,可以用 `studio.imageModels` 关掉(见下方选项)。
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
64
83
|
## 配置与进阶
|
|
65
84
|
|
|
66
85
|
<details>
|
|
@@ -68,12 +87,15 @@
|
|
|
68
87
|
|
|
69
88
|
<br>
|
|
70
89
|
|
|
71
|
-
|
|
90
|
+
工具调用默认开启。图片输入在 AI Studio 默认开启,在 Gemini Web 默认关闭。可通过命令行修改插件配置:
|
|
72
91
|
|
|
73
92
|
```bash
|
|
74
|
-
#
|
|
93
|
+
# 两个 Provider 都开启图片输入
|
|
75
94
|
magpie plugin options magpie-gemini-web '{"allowImages":true}'
|
|
76
95
|
|
|
96
|
+
# 关闭 AI Studio 的图片输入
|
|
97
|
+
magpie plugin options magpie-gemini-web '{"studio":{"allowImages":false}}'
|
|
98
|
+
|
|
77
99
|
# 为 AI Studio 配置代理
|
|
78
100
|
magpie plugin options magpie-gemini-web '{"studio":{"proxy":"http://127.0.0.1:7890"}}'
|
|
79
101
|
```
|
|
@@ -85,8 +107,8 @@ magpie plugin options magpie-gemini-web '{"studio":{"proxy":"http://127.0.0.1:78
|
|
|
85
107
|
| 选项 | 默认值 | 适用范围 | 说明 |
|
|
86
108
|
| :--- | :--- | :--- | :--- |
|
|
87
109
|
| `allowTools` | `true` | 共用(可用 `studio.allowTools` 单独覆盖) | 允许工具调用。设为 `false` 时带工具的请求返回 400 |
|
|
88
|
-
| `allowImages` |
|
|
89
|
-
| `requestTimeoutMs` / `modelTimeoutMs` | Web:`
|
|
110
|
+
| `allowImages` | Web:`false`;Studio:`true` | 共用(可用 `studio.allowImages` 单独覆盖) | 允许对话中的图片输入(图像模型的参考图不受它限制)。Gemini Web 读图需要登录,未登录时返回 400;实测 `gemini-3.6-flash` 带图请求会一直等到超时,`gemini-3.5-flash-lite`、`gemini-3.8-flash` 正常 |
|
|
111
|
+
| `requestTimeoutMs` / `modelTimeoutMs` | Web:`570000` / `10000`;Studio:`1800000` / `10000` | 共用(`studio.*` 可覆盖) | 单次等待后端 / 拉取模型列表的超时(毫秒);收到流数据后重新计时,显式配置优先 |
|
|
90
112
|
| `stripCitations` | `true` | 仅 `gemini-web` | 剥离回复与工具参数中的 `[cite: 1]`、`[cite_start]` 标记(AI Studio 不支持剥离) |
|
|
91
113
|
| `proxy` | 无 | 仅 `gemini-web` | 一键配置后端访问 Google 的代理(`http` / `https` / `socks5` / `socks5h`),也可用环境变量 `GEMINI_WEB_PROXY` 或在登录第一步填写 |
|
|
92
114
|
| `baseURL` | `http://127.0.0.1:8083/v1` | 仅 `gemini-web` | Gemini Web 默认后端地址 |
|
|
@@ -94,6 +116,7 @@ magpie plugin options magpie-gemini-web '{"studio":{"proxy":"http://127.0.0.1:78
|
|
|
94
116
|
| `studio.proxy` | 无 | 仅 `ai-studio` | 访问 Google 的代理(`http` / `https` / `socks5`),也可用环境变量 `AI_STUDIO_PROXY`;设置后优先于管理页里保存的代理,留空等于不设置 |
|
|
95
117
|
| `studio.baseURL` | `http://127.0.0.1:2048/v1` | 仅 `ai-studio` | 连接已有 AIStudio2API 时的默认地址 |
|
|
96
118
|
| `studio.contextLimit` / `studio.outputLimit` | 模型目录默认值 | 仅 `ai-studio` | 向客户端声明的上限(仅支持在目录值基础上调低) |
|
|
119
|
+
| `studio.imageModels` | `true` | 仅 `ai-studio` | 列出 Nano Banana 等图像模型,供 Magpie 的图片生成使用;设为 `false` 时只列文本模型 |
|
|
97
120
|
|
|
98
121
|
**配置代理访问 Google:**
|
|
99
122
|
- **AI Studio**:推荐在本地管理页设置。打开额度卡片「管理页」一行里的地址(默认 `http://127.0.0.1:2048`),用户名 `magpie`,密码是数据目录 `config.json` 里的 `adminPassword`;保存代理后在管理页重启服务即可生效,之后插件重启后端也不会覆盖它。
|
|
@@ -146,10 +169,10 @@ magpie plugin options magpie-gemini-web '{"studio":{"proxy":"http://127.0.0.1:78
|
|
|
146
169
|
- 两个后端均只监听 `127.0.0.1`,Cookie 与登录态仅保存在本机,Magpie 仅保存本地生成的随机 API Key。
|
|
147
170
|
- **Gemini Web 数据目录**:`~/.local/share/magpie-gemini-web`(可通过 `GEMINI_WEB_DATA_DIR` 修改),日志位于 `backend.log`。支持 macOS、Linux、Windows(x64 / arm64)。
|
|
148
171
|
- **AI Studio 数据目录**:`~/.local/share/magpie-ai-studio`(可通过 `AI_STUDIO_DATA_DIR` 修改),日志位于 `backend.log`(超 10 MB 下次启动自动轮转)。默认使用 2048 端口,被占用时自动顺延并记录在 `config.json`。支持 macOS、Linux(x64 / arm64)与 Windows x64。
|
|
149
|
-
-
|
|
172
|
+
- Gemini Web 每个登录同时最多 2 个请求(AI Studio 为 1),可在 Magpie 的 provider 设置里调整;仍无法完全排除 Google 账号风控风险,请自行评估使用。
|
|
150
173
|
|
|
151
174
|
**AI Studio 升级与模型范围:**
|
|
152
|
-
- 插件固定使用经过 SHA-256 校验的 `v0.2.
|
|
175
|
+
- 插件固定使用经过 SHA-256 校验的 `v0.2.18-magpie.1`(基于上游 `v0.2.18`),通过升级插件更新后端。同基线或更旧的官方版、以及旧版插件装的托管后端,在下次管理启动时自动升级,保留账号、端口与登录凭据。
|
|
153
176
|
- **托管后端已在 macOS、Linux、Windows 统一禁用在线更新**:管理页提示“更新由 magpie-gemini-web 管理”,更新接口返回 HTTP 409,检查更新也不会访问 GitHub。用户自行连接的外部服务不受影响。托管构建方式和可复现构建流程见 [docs/studio-release.md](docs/studio-release.md)。
|
|
154
177
|
- Unix 的 `package/` 仍尽力设置为 `0555`,作为额外的文件保护;权限设置失败不阻断服务,在线更新的禁用也不依赖该权限。若要手动删除数据目录来重置,请先停止服务,再运行 `chmod -R u+w "<数据目录>/package"` 恢复可写权限,然后删除;将 `<数据目录>` 替换为实际路径。
|
|
155
178
|
- 若自行更新到更新版或定制版,插件会提示版本冲突,并提供带正确 `--data-dir` 的 `stop`、`install`、`start` 命令。停止时会找回更新后的监听进程 PID,并核对可执行文件路径;无法核实身份就不会发送终止信号。HTTP 端口关闭但进程尚未退出时,插件不会重装或启动第二个进程。
|
|
@@ -159,7 +182,7 @@ magpie plugin options magpie-gemini-web '{"studio":{"proxy":"http://127.0.0.1:78
|
|
|
159
182
|
- 模型列表过滤 `-build` / `assistant_route` 模型:这类模型附带 Build 写代码助手的系统提示词,不作为普通 Agent 模型提供。升级后可执行 `magpie provider models ai-studio` 刷新列表。
|
|
160
183
|
|
|
161
184
|
**Gemini Web 优化后端升级与回退:**
|
|
162
|
-
- 插件默认使用本仓库发布的 [4.26.0-magpie.
|
|
185
|
+
- 插件默认使用本仓库发布的 [4.26.0-magpie.2](https://github.com/BUKOWSKIREAL/magpie-gemini-web/releases/tag/backend-v4.26.0-magpie.2)(基于上游 v4.26.0 集成 XSRF 缓存、请求取消传播、工具调用提前收尾与 Argon 校验补丁)。对话请求按上游沉默计时:Google 让请求排队时每 60 秒发一次心跳,后端会一直等到出字;连续 `request_timeout_sec`(默认 180 秒)没有任何数据才放弃这一次并重试,还在出字的长回复也不会被截断。
|
|
163
186
|
- **旧版升级**:插件不会打断运行中的后端。先停止旧进程(PID 见数据目录 `backend.pid`),下次启动 Magpie 或发请求时会自动更新二进制并保留原有配置与账号。
|
|
164
187
|
- **回退官方版 / 恢复优化版**(停止后端后在插件目录执行):
|
|
165
188
|
```bash
|
package/docs/studio-release.md
CHANGED
|
@@ -1,36 +1,43 @@
|
|
|
1
1
|
# AI Studio 托管后端构建
|
|
2
2
|
|
|
3
|
-
插件使用 `0.2.
|
|
3
|
+
插件使用 `0.2.18-magpie.1`,基于 AIStudio2API `v0.2.18` 的固定 commit。上游版本、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
4
|
|
|
5
5
|
## 升级兼容
|
|
6
6
|
|
|
7
|
+
- 上游 v0.2.18 删除了纯 Go(goja)的 WAA 后端 `go`,改为经 CGO 内嵌 Firefox 的 JS 引擎 SpiderMonkey(`WAA_BACKEND=spidermonkey`)。插件固定使用 `spidermonkey`:生成仍在服务进程内完成,不需要浏览器;Camoufox 仍只用于 Google 登录。上游默认的 `camoufox` 后端未采用。
|
|
8
|
+
- SpiderMonkey 使用上游自己发布时用的预编译静态库(`Mag1cFall/firefox` 的 `v152.0.4-aistudio2api.1` release),每个目标的归档名与 SHA-256 记录在 `toolchains.spidermonkey`,构建时下载到 `studio-build/toolchains/` 并校验。头文件与库经 `CGO_CXXFLAGS` / `CGO_LDFLAGS` 传入,库名由上游 `internal/waa/mozjs` 的 `#cgo` 指令给出,与上游 `.github/actions/spidermonkey` 一致。
|
|
9
|
+
- 新增设置 `SEARCH_MODEL_ALIASES`、`GOOGLE_SEARCH`、`CONTINUATION_REWRITE`、`CONTINUATION_PROMPT` 保留管理页保存的值,并隔离宿主环境同名变量。上游默认开启 `SEARCH_MODEL_ALIASES`,把每个可搜索的对话模型再列一份 `<id>-search`;插件在 `.env` 缺少该项时写入 `false`,避免 Magpie 的模型列表大多重复一遍,用户可在管理页开启。其余三项沿用上游默认。
|
|
10
|
+
- Gemini 原生接口(`/v1beta`,Magpie 画图用)在 v0.2.18 按 Gemini 的方式拒绝密钥:错误密钥返回 400 `API_KEY_INVALID`,缺少密钥返回 403。插件把这两种情况当作 401 处理,提示重新登录;Google 自身返回的 403(如 code 7 “The caller does not have permission”)属于账号问题,原样传回。
|
|
7
11
|
- 上游 v0.2.17 改用需要 CGO 的原生 SQLite。账号和配置沿用原目录;首次打开旧数据库会整理空闲页。降级前应停止服务并备份完整数据目录,旧版不保证能读取迁移后的数据。
|
|
8
|
-
-
|
|
12
|
+
- 上游(v0.2.17 起,v0.2.18 仍然)会删除旧的请求正文 `bodies` 表。`patches/studio-0.2.17-preserve-request-bodies.patch` 改为在事务内压缩并迁移到 `request_bodies`,已有新版同 ID 记录优先,成功后才删除旧表;失败回滚。补丁原样适用于 v0.2.18,供从 0.2.16 及更早版本直接升级的用户使用;它包含旧正文读取、重复打开及迁移失败回滚测试,随上游测试一起运行。
|
|
9
13
|
- 新增的 `FIRST_EVENT_HEDGE` 保留管理页保存的值,同时隔离宿主环境同名变量。默认仍由上游设为 `off`。备用请求需要空闲账号和 Worker;插件默认单 Worker,不自动提高并发。
|
|
10
|
-
- 模型档位优先使用 `/v1/models` 返回的 `thinking_levels`;旧外部服务未返回该字段时沿用四档。Playground
|
|
14
|
+
- 模型档位优先使用 `/v1/models` 返回的 `thinking_levels`;旧外部服务未返回该字段时沿用四档。Playground 通道、托管更新限制及插件默认并发保持原设置。
|
|
11
15
|
- macOS 与 Windows 都可能使用系统代理;显式代理及管理页设置仍优先,宿主的 `HTTP_PROXY` 等变量不传入服务。
|
|
12
16
|
|
|
13
17
|
## 在线更新策略
|
|
14
18
|
|
|
15
19
|
上游从 v0.2.14 起原生支持分发方管理更新。构建时通过 `-ldflags` 写入两个值:
|
|
16
20
|
|
|
17
|
-
- `internal/app.version=v0.2.
|
|
21
|
+
- `internal/app.version=v0.2.18-magpie.1`:明确的版本标识。同基线或更旧的官方版、以及更旧的托管版需要升级;更新的官方版、更新的托管版或不认识的定制版仍提示冲突。
|
|
18
22
|
- `internal/app.managedBy=magpie-gemini-web`:`GET /api/update`(包括 `?refresh=1`)只返回本地版本、`mode: managed` 和 `managed_by`,不访问 GitHub;`POST /api/update` 返回 HTTP 409,不下载、不替换文件、不重启。管理页显示“更新由 magpie-gemini-web 管理”。
|
|
19
23
|
|
|
20
24
|
构建不带 `desktop` 标签,不包含桌面窗口。普通插件升级、账户登录、模型调用及管理功能继续保留,用户自行连接的外部服务不受影响。
|
|
21
25
|
|
|
22
26
|
## 复现构建
|
|
23
27
|
|
|
24
|
-
维护者需要 Git、tar、curl、Node.js 26.8.2、Go 1.27.1,以及 `lib/studio-release.json` 的 `toolchains` 固定的 C 工具链。SQLite 需要
|
|
28
|
+
维护者需要 Git、tar、curl、Node.js 26.8.2、Go 1.27.1,以及 `lib/studio-release.json` 的 `toolchains` 固定的 C/C++ 工具链。SQLite 需要 C、SpiderMonkey 需要 C++,工具链因此也是 pin 的一部分:
|
|
25
29
|
|
|
26
30
|
| 目标 | 工具链 | 跨机器字节一致 |
|
|
27
31
|
|---|---|---|
|
|
28
|
-
| Linux x64/arm64 | Zig `toolchains.zig
|
|
29
|
-
| Windows x64 | llvm-mingw `toolchains.llvmMingw`(Clang + LLD + UCRT),静态链接,PE 时间戳为 0 | 是:同上;构建脚本自动下载并按 SHA-256
|
|
32
|
+
| Linux x64/arm64 | Zig `toolchains.zig`(`zig cc` / `zig c++`),musl 静态链接,不依赖构建机器的 glibc | 是:Zig 是自带 libc 的交叉编译器,任何主机产物相同 |
|
|
33
|
+
| Windows x64 | llvm-mingw `toolchains.llvmMingw`(Clang + LLD + UCRT),静态链接,PE 时间戳为 0 | 是:同上;构建脚本自动下载并按 SHA-256 校验。Windows 的库(含 C++ 运行库)取自 Linux x64 归档,见下 |
|
|
30
34
|
| macOS arm64/x64 | Xcode `toolchains.xcode`,最低目标 macOS 13(与 Go 1.27 一致),只能在 macOS 上构建 | 仅在同一 Xcode 下:Apple 链接器和 SDK 随 Xcode 变化 |
|
|
31
35
|
|
|
32
36
|
- Zig 默认从 PATH 查找,也可用 `STUDIO_ZIG=/absolute/path/to/zig` 指定。
|
|
33
|
-
- llvm-mingw 首次使用时下载到 `studio-build/toolchains/`(macOS、Linux x64、Windows x64 主机各有固定的归档及 SHA-256),之后复用。`STUDIO_MINGW_CC` 可指定其他 `x86_64-w64-mingw32-clang
|
|
37
|
+
- llvm-mingw 首次使用时下载到 `studio-build/toolchains/`(macOS、Linux x64、Windows x64 主机各有固定的归档及 SHA-256),之后复用。`STUDIO_MINGW_CC` 可指定其他 `x86_64-w64-mingw32-clang`(C++ 编译器取同目录的 `clang++`),但 `--verify` / `--write-pins` 要求其版本与 pin 一致。
|
|
38
|
+
- llvm-mingw 的 Linux 与 Windows 归档里 Windows 目标库逐字节相同,macOS 归档里的是另行构建的,其中 C++ 运行库(libc++abi)会把各自的构建路径写进可执行文件。因此在 macOS 上构建 Windows 时,链接 Linux x64 归档(同样固定 SHA-256)里的目标库;各主机都以一个 `-L` 指明目标库目录,因为 cgo 会把每个链接参数写成生成代码的一行,参数个数不同会改变可执行文件里的行号表。
|
|
39
|
+
- SpiderMonkey 静态库同样在首次使用时按目标下载到 `studio-build/toolchains/` 并校验 SHA-256,之后复用。
|
|
40
|
+
- Linux(musl)的 SpiderMonkey 静态库带有 mozglue 的环境变量拦截函数(`libjs_static.a` 的 `Unified_cpp_mozglue_interposers0.o`):除 `getenv` 外,`setenv` 等都经 `dlsym(RTLD_NEXT)` 找 C 库原函数,静态链接的程序找不到,便有意崩溃(`MOZ_CRASH`);Go 的 `os.Setenv` 在 cgo 程序里正走这条路。构建脚本校验下载后用 `zig ar` 删除这个目标文件,改用 musl 自己的函数;找不到该文件时报错,提示核对新版 SpiderMonkey。上游测试只在动态链接的 glibc 库(`linux-amd64-gnu`)上运行,不会遇到这个问题。
|
|
34
41
|
- Xcode 用 `DEVELOPER_DIR=/Applications/Xcode_<版本>.app/Contents/Developer` 选择,不需要改系统默认。不要用 beta 版 Xcode 制作发布包。
|
|
35
42
|
- 所有目标都以 `-trimpath -buildvcs=false -ldflags=-buildid=` 编译:Go 默认的 build ID 会哈希 C 编译器路径等构建输入,导致不同机器上内容相同的程序哈希不同。
|
|
36
43
|
- Windows 使用 Git Bash 执行命令,安装包运行和解压使用 Windows 自带 PowerShell。最终用户不需要构建工具。
|
|
@@ -86,7 +93,20 @@ AI_STUDIO_TEST_ARCHIVE=/absolute/path/to/archive.tar.gz npm test
|
|
|
86
93
|
|
|
87
94
|
真实安装验证检查旧版请求正文迁移及重启后可读、管理页保存的备用请求设置、启动、版本、GET 更新状态、POST 更新返回 409、二进制及 PID 不变、管理页面显示托管提示、停止与状态。`.github/workflows/studio.yml` 在五种系统/架构的原生 runner 上重新构建、对比 SHA-256 并运行该验证;本机交叉编译不能代替 Linux/Windows 真机验证。
|
|
88
95
|
|
|
89
|
-
##
|
|
96
|
+
## 0.2.18 升级验证(2026-10-30)
|
|
97
|
+
|
|
98
|
+
以下为本分支的实际状态,发布前以最新 CI 结果为准。
|
|
99
|
+
|
|
100
|
+
- 首次候选构建(run 41025535280)中,Linux x64/arm64 在上游测试 `TestUserCacheRootWithoutEnvironment` 的 `t.Setenv` 处崩溃(见上文环境变量拦截函数),Windows 的 macOS 本机交叉编译结果与 CI 不同(见上文 C++ 运行库)。两处修复后的候选构建(run 41033635405)五个平台都通过上游测试、真实安装冒烟验证(含 `waa_backend=spidermonkey`、`search_model_aliases=false`)与插件测试。
|
|
101
|
+
- 跨机器一致性:Linux x64/arm64 与 Windows x64 的 CI 候选哈希与 macOS arm64 本机交叉编译完全一致;darwin-arm64 两次 CI 构建得到相同哈希。pin 来自第二次候选构建,随后的严格验证构建(run 41036094948)在五个平台的全新 runner 上重新构建,哈希与 pin 完全一致,冒烟验证与插件测试通过。
|
|
102
|
+
- Linux 二进制为静态链接,不含环境变量拦截函数;Windows 二进制只导入系统 DLL(UCRT、KERNEL32 等),C++ 运行库静态链接,PE 时间戳为 0。
|
|
103
|
+
- 真实账号端到端验证(CI 构建的 darwin-arm64 安装包,一个已登录账号复制到临时数据目录,原服务在验证期间停止、结束后恢复):服务 8 秒就绪,WAA 后端为 spidermonkey,全程未启动 Camoufox;45 个模型中无 `-search` 副本;`gemini-3.8-flash` 文本(4 秒)、流式(3 秒)和图片输入(17 秒,答对左右两半颜色)正常;经插件用 `gemini-3.1-flash-image` 按 16:9 画图得到 1376×768 图片(9 秒);错误密钥在 Gemini 接口上返回 400 `API_KEY_INVALID`,与插件的判断一致。
|
|
104
|
+
- Google 登录(Camoufox 登录窗口)本次未验证:使用的是已登录账号。
|
|
105
|
+
- 此分支未发布后端 release 或 npm 包。
|
|
106
|
+
|
|
107
|
+
## 0.2.17 升级验证(2026-10-29,历史记录)
|
|
108
|
+
|
|
109
|
+
以下为上一版 `0.2.17-magpie.1` 的验证结果,不代表 0.2.18。
|
|
90
110
|
|
|
91
111
|
- 上游前端 lint/build、Go 测试(含迁移补丁测试)通过;插件完整测试 207 项通过,无跳过。
|
|
92
112
|
- Linux 二进制为静态链接,Windows 二进制只导入 UCRT 与 KERNEL32、PE 时间戳为 0;npm 打包检查包含迁移补丁,排除构建产物。
|
|
@@ -95,14 +115,14 @@ AI_STUDIO_TEST_ARCHIVE=/absolute/path/to/archive.tar.gz npm test
|
|
|
95
115
|
- 新版 Google 登录/生成端到端验证尚未完成。
|
|
96
116
|
- 此分支未发布后端 release 或 npm 包。本机日常后端仍使用 `0.2.16-magpie.1`,新版仅在临时数据目录运行。
|
|
97
117
|
|
|
98
|
-
发布前必须审查各平台 CI 与构建记录,再将安装包及许可证上传到本仓库 `studio-v0.2.
|
|
118
|
+
发布前必须审查各平台 CI 与构建记录,再将安装包及许可证上传到本仓库 `studio-v0.2.18-magpie.1` release。该 release 可公开下载后,才能发布引用它的插件版本,否则新安装会遇到 404。构建脚本及验证 CI 不自动发布 release 或 npm 包。
|
|
99
119
|
|
|
100
120
|
本地试用建议使用独立数据目录:
|
|
101
121
|
|
|
102
122
|
```bash
|
|
103
|
-
node scripts/studio.mjs install --data-dir /path/to/studio-
|
|
104
|
-
node scripts/studio.mjs start --data-dir /path/to/studio-
|
|
105
|
-
node scripts/studio.mjs stop --data-dir /path/to/studio-
|
|
123
|
+
node scripts/studio.mjs install --data-dir /path/to/studio-018-trial --archive /absolute/path/to/archive
|
|
124
|
+
node scripts/studio.mjs start --data-dir /path/to/studio-018-trial
|
|
125
|
+
node scripts/studio.mjs stop --data-dir /path/to/studio-018-trial
|
|
106
126
|
```
|
|
107
127
|
|
|
108
128
|
使用现有账号数据测试前,先停止旧服务并备份;不要让两个进程同时写同一个数据目录。
|
package/index.mjs
CHANGED
|
@@ -102,7 +102,11 @@ export const GeminiWebPlugin = async (_input, options = {}) => {
|
|
|
102
102
|
auth: {
|
|
103
103
|
provider: ID,
|
|
104
104
|
icon: PLUGIN_ICON,
|
|
105
|
-
|
|
105
|
+
// Two at once per sign-in, as a person with two Gemini tabs: an agent's first turn and
|
|
106
|
+
// the session title it asks for alongside no longer wait one behind the other, which
|
|
107
|
+
// Gemini Web can take minutes to answer (#33). The backend still caps each way out to
|
|
108
|
+
// Google (per-IP limits), and Magpie's own setting on the provider goes over this.
|
|
109
|
+
maxConcurrency: 2,
|
|
106
110
|
methods: [{
|
|
107
111
|
type: 'oauth',
|
|
108
112
|
label: '一键配置本地 Gemini Web(推荐)',
|
package/lib/backend-release.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.26.0-magpie.
|
|
2
|
+
"version": "4.26.0-magpie.2",
|
|
3
3
|
"repository": "BUKOWSKIREAL/magpie-gemini-web",
|
|
4
|
-
"tag": "backend-v4.26.0-magpie.
|
|
4
|
+
"tag": "backend-v4.26.0-magpie.2",
|
|
5
5
|
"upstream": {
|
|
6
6
|
"repository": "https://github.com/zexadev/gemini-web2api-go.git",
|
|
7
7
|
"commit": "7ce02d89512058b2bd147fb2dc4e40187f5135ad"
|
|
@@ -9,28 +9,28 @@
|
|
|
9
9
|
"goVersion": "1.27.1",
|
|
10
10
|
"binaries": {
|
|
11
11
|
"darwin-arm64": {
|
|
12
|
-
"asset": "gemini-web2api-go_v4.26.0-magpie.
|
|
13
|
-
"sha256": "
|
|
12
|
+
"asset": "gemini-web2api-go_v4.26.0-magpie.2_darwin_arm64",
|
|
13
|
+
"sha256": "2407896cf76917499cca4cc4c932a774ba65cb6ccbf8b6901fb2c47a29c89e41"
|
|
14
14
|
},
|
|
15
15
|
"darwin-x64": {
|
|
16
|
-
"asset": "gemini-web2api-go_v4.26.0-magpie.
|
|
17
|
-
"sha256": "
|
|
16
|
+
"asset": "gemini-web2api-go_v4.26.0-magpie.2_darwin_amd64",
|
|
17
|
+
"sha256": "73774ee8a4687baa5c39cb1911f038e2293326c876e373745385a41378622b3d"
|
|
18
18
|
},
|
|
19
19
|
"linux-x64": {
|
|
20
|
-
"asset": "gemini-web2api-go_v4.26.0-magpie.
|
|
21
|
-
"sha256": "
|
|
20
|
+
"asset": "gemini-web2api-go_v4.26.0-magpie.2_linux_amd64",
|
|
21
|
+
"sha256": "b320b050916090ab34e7025596a1daf8d2cb83880908b38786b24c0d3d621c74"
|
|
22
22
|
},
|
|
23
23
|
"linux-arm64": {
|
|
24
|
-
"asset": "gemini-web2api-go_v4.26.0-magpie.
|
|
25
|
-
"sha256": "
|
|
24
|
+
"asset": "gemini-web2api-go_v4.26.0-magpie.2_linux_arm64",
|
|
25
|
+
"sha256": "9ac7e4feed66a17d1719b2a0057130098640ee0f6cea2d6192e6938bd4f5259d"
|
|
26
26
|
},
|
|
27
27
|
"win32-x64": {
|
|
28
|
-
"asset": "gemini-web2api-go_v4.26.0-magpie.
|
|
29
|
-
"sha256": "
|
|
28
|
+
"asset": "gemini-web2api-go_v4.26.0-magpie.2_windows_amd64.exe",
|
|
29
|
+
"sha256": "16574f5863dae4dc806e1066c9bd515161c9250cbc7e949d8b8e46eca072628a"
|
|
30
30
|
},
|
|
31
31
|
"win32-arm64": {
|
|
32
|
-
"asset": "gemini-web2api-go_v4.26.0-magpie.
|
|
33
|
-
"sha256": "
|
|
32
|
+
"asset": "gemini-web2api-go_v4.26.0-magpie.2_windows_arm64.exe",
|
|
33
|
+
"sha256": "8bcefc92a56d26736651cd009c15bf4c0858e41a04f65a0d83d06df7f94296b3"
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
package/lib/backend.mjs
CHANGED
|
@@ -165,7 +165,13 @@ export function settings(options = {}) {
|
|
|
165
165
|
throw new Error('Invalid option outputLimit: cannot exceed contextLimit');
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
// The backend sends nothing until a reply's first words, and Gemini Web can queue a request
|
|
169
|
+
// for minutes before them (3.6 Flash: 48 s to 6.5 minutes), sending the backend only a heartbeat
|
|
170
|
+
// a minute, which it waits through. The plugin can't tell that queue from a stuck backend, so
|
|
171
|
+
// it waits as long as it may: under the 10 minutes Magpie gives a provider to begin answering,
|
|
172
|
+
// so this timeout reaches the client rather than Magpie's. That also outlasts
|
|
173
|
+
// 4.26.0-magpie.1's three tries of 180 s each, 2 s apart: 544 s (#33).
|
|
174
|
+
let requestTimeoutMs = 570000;
|
|
169
175
|
if (options.requestTimeoutMs !== undefined) {
|
|
170
176
|
if (!Number.isInteger(options.requestTimeoutMs) || options.requestTimeoutMs <= 0) {
|
|
171
177
|
throw new Error('Invalid option requestTimeoutMs: must be a positive integer');
|
|
@@ -426,6 +432,68 @@ function timedBody(body, timer) {
|
|
|
426
432
|
});
|
|
427
433
|
}
|
|
428
434
|
|
|
435
|
+
// keyRefused says whether an error on Gemini's own API is the AI Studio service refusing the key.
|
|
436
|
+
// From 0.2.18 it says so as Gemini does: 400 API_KEY_INVALID for a wrong key, 403 for none. A 403
|
|
437
|
+
// from Google itself ("The caller does not have permission") is about the account, not the key.
|
|
438
|
+
function keyRefused(status, text) {
|
|
439
|
+
let error;
|
|
440
|
+
try {
|
|
441
|
+
const body = JSON.parse(text);
|
|
442
|
+
error = (Array.isArray(body) ? body[0] : body)?.error;
|
|
443
|
+
} catch {
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
if (status === 400) return Array.isArray(error?.details) && error.details.some(detail => detail?.reason === 'API_KEY_INVALID');
|
|
447
|
+
return error?.status === 'PERMISSION_DENIED' && /unregistered callers/.test(error.message);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const GEMINI_CALL = /^\/models\/([^/:]+):(generateContent|streamGenerateContent)$/;
|
|
451
|
+
|
|
452
|
+
// geminiTarget is where a call on Gemini's own API goes at the AI Studio service, with the model
|
|
453
|
+
// it names: the service's /v1beta, beside the /v1 that baseURL always ends in. Magpie draws with
|
|
454
|
+
// an image model there (the model's npm is @ai-sdk/google, see listStudioModels), asking
|
|
455
|
+
// <baseURL>/models/<id>:streamGenerateContent?alt=sse. null for any other request, and for one
|
|
456
|
+
// with any other query.
|
|
457
|
+
function geminiTarget(url, baseURL) {
|
|
458
|
+
const base = new URL(baseURL);
|
|
459
|
+
if (url.origin !== base.origin || !url.pathname.startsWith(base.pathname + '/')) return null;
|
|
460
|
+
const m = GEMINI_CALL.exec(url.pathname.slice(base.pathname.length));
|
|
461
|
+
if (!m || url.hash || (url.search && url.search !== '?alt=sse')) return null;
|
|
462
|
+
let model;
|
|
463
|
+
try {
|
|
464
|
+
model = decodeURIComponent(m[1]);
|
|
465
|
+
} catch {
|
|
466
|
+
return null;
|
|
467
|
+
}
|
|
468
|
+
return { url: `${baseURL}beta/models/${m[1]}:${m[2]}${url.search}`, model };
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// The line Magpie ends a drawing's prompt with when a size is asked for (drawPrompt): a ratio
|
|
472
|
+
// given as one, or the nearest of its usual ones to a WIDTHxHEIGHT size.
|
|
473
|
+
const ASPECT_LINE = /\n\nAspect ratio: (\d+(?:\.\d+)?):(\d+(?:\.\d+)?)\./;
|
|
474
|
+
|
|
475
|
+
// aspectRatio moves the aspect ratio a generateContent request's prompt names to
|
|
476
|
+
// imageConfig.aspectRatio, as one of aspects, the model's: the one named when the model takes it,
|
|
477
|
+
// else the nearest. With the line in its prompt, gemini-3.1-flash-lite-image (seen on
|
|
478
|
+
// AIStudio2API 0.2.17) answered with no image at all, each of three times; with imageConfig it
|
|
479
|
+
// drew. A request that names a ratio in imageConfig already is left as it is.
|
|
480
|
+
function aspectRatio(body, aspects) {
|
|
481
|
+
const config = body.generationConfig && typeof body.generationConfig === 'object' ? body.generationConfig : {};
|
|
482
|
+
if (config.imageConfig?.aspectRatio) return;
|
|
483
|
+
const contents = Array.isArray(body.contents) ? body.contents : [];
|
|
484
|
+
const content = contents.findLast(c => c?.role === 'user' && Array.isArray(c.parts));
|
|
485
|
+
const part = content?.parts.find(p => typeof p?.text === 'string' && ASPECT_LINE.test(p.text));
|
|
486
|
+
if (!part) return;
|
|
487
|
+
const [, w, h] = ASPECT_LINE.exec(part.text);
|
|
488
|
+
const asked = `${w}:${h}`;
|
|
489
|
+
const log = r => Math.log(Number(r.split(':')[0]) / Number(r.split(':')[1]));
|
|
490
|
+
const nearest = aspects.includes(asked)
|
|
491
|
+
? asked
|
|
492
|
+
: aspects.reduce((best, r) => Math.abs(log(r) - log(asked)) < Math.abs(log(best) - log(asked)) ? r : best);
|
|
493
|
+
part.text = part.text.replace(ASPECT_LINE, '');
|
|
494
|
+
body.generationConfig = { ...config, imageConfig: { ...config.imageConfig, aspectRatio: nearest } };
|
|
495
|
+
}
|
|
496
|
+
|
|
429
497
|
export async function forward(input, init, getAuth, opts) {
|
|
430
498
|
const req = new Request(input, init);
|
|
431
499
|
|
|
@@ -454,7 +522,11 @@ export async function forward(input, init, getAuth, opts) {
|
|
|
454
522
|
return makeOpenAIError(400, 'Invalid request URL');
|
|
455
523
|
}
|
|
456
524
|
|
|
457
|
-
|
|
525
|
+
// AI Studio's image models are asked on Gemini's own API (opts.imageModel, see imageModelOf)
|
|
526
|
+
const gemini = opts.imageModel ? geminiTarget(reqUrl, c.baseURL) : null;
|
|
527
|
+
const geminiUrl = gemini?.url;
|
|
528
|
+
|
|
529
|
+
if ((reqUrl.search || reqUrl.hash) && !geminiUrl) {
|
|
458
530
|
return makeOpenAIError(400, 'Query parameters and fragments are not allowed');
|
|
459
531
|
}
|
|
460
532
|
|
|
@@ -462,13 +534,16 @@ export async function forward(input, init, getAuth, opts) {
|
|
|
462
534
|
const modelsUrl = `${c.baseURL}/models`;
|
|
463
535
|
const incomingUrl = `${reqUrl.origin}${reqUrl.pathname}`;
|
|
464
536
|
|
|
465
|
-
if (incomingUrl !== chatUrl && incomingUrl !== modelsUrl) {
|
|
537
|
+
if (incomingUrl !== chatUrl && incomingUrl !== modelsUrl && !geminiUrl) {
|
|
466
538
|
return makeOpenAIError(404, 'Endpoint not found');
|
|
467
539
|
}
|
|
468
540
|
|
|
469
541
|
if (incomingUrl === chatUrl && req.method !== 'POST') {
|
|
470
542
|
return makeOpenAIError(400, 'Method not allowed: /chat/completions requires POST');
|
|
471
543
|
}
|
|
544
|
+
if (geminiUrl && req.method !== 'POST') {
|
|
545
|
+
return makeOpenAIError(400, 'Method not allowed: generateContent requires POST');
|
|
546
|
+
}
|
|
472
547
|
if (incomingUrl === modelsUrl && req.method !== 'GET') {
|
|
473
548
|
return makeOpenAIError(400, 'Method not allowed: /models requires GET');
|
|
474
549
|
}
|
|
@@ -550,6 +625,47 @@ export async function forward(input, init, getAuth, opts) {
|
|
|
550
625
|
body.model = twin;
|
|
551
626
|
rawBody = JSON.stringify(body);
|
|
552
627
|
}
|
|
628
|
+
} else if (geminiUrl) {
|
|
629
|
+
try {
|
|
630
|
+
rawBody = await req.text();
|
|
631
|
+
} catch {
|
|
632
|
+
return makeOpenAIError(400, 'Failed to read request body');
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
let body;
|
|
636
|
+
try {
|
|
637
|
+
body = JSON.parse(rawBody);
|
|
638
|
+
} catch {
|
|
639
|
+
return makeOpenAIError(400, 'Invalid JSON body');
|
|
640
|
+
}
|
|
641
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) {
|
|
642
|
+
return makeOpenAIError(400, 'Request body must be a JSON object');
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
if (!opts.allowTools && Array.isArray(body.tools) && body.tools.length > 0) {
|
|
646
|
+
return makeOpenAIError(400, `Tool calls are turned off for magpie-gemini-web. Turn them on with: magpie plugin options magpie-gemini-web '{"allowTools":true}'`);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// A text model is asked on chat completions, where allowImages holds. One the service's list
|
|
650
|
+
// can't tell of goes no further: an unreachable service is answered as one, for a managed one
|
|
651
|
+
// to be started again (forwardManagedStudio).
|
|
652
|
+
let aspects;
|
|
653
|
+
try {
|
|
654
|
+
aspects = await opts.imageModel(c, gemini.model);
|
|
655
|
+
} catch (err) {
|
|
656
|
+
if (err?.unreachable) {
|
|
657
|
+
return makeOpenAIError(502, 'Bad gateway: failed to reach backend service', { [UNREACHABLE_HEADER]: 'unreachable' });
|
|
658
|
+
}
|
|
659
|
+
if (err?.signIn === 'expired') {
|
|
660
|
+
return makeOpenAIError(401, 'Unauthorized: AI Studio refused the key');
|
|
661
|
+
}
|
|
662
|
+
return makeOpenAIError(503, `Can't tell whether ${gemini.model} is one of AI Studio's image models: ${err?.message || err}`);
|
|
663
|
+
}
|
|
664
|
+
if (!aspects) {
|
|
665
|
+
return makeOpenAIError(400, `${gemini.model} isn't one of AI Studio's image models: generateContent here is for those alone, and a text model is asked on /chat/completions`);
|
|
666
|
+
}
|
|
667
|
+
aspectRatio(body, aspects);
|
|
668
|
+
rawBody = JSON.stringify(body);
|
|
553
669
|
}
|
|
554
670
|
|
|
555
671
|
// requestTimeoutMs bounds each wait on the backend, for the response headers and then for each
|
|
@@ -561,7 +677,7 @@ export async function forward(input, init, getAuth, opts) {
|
|
|
561
677
|
timer.start();
|
|
562
678
|
try {
|
|
563
679
|
// Bun's fetch drops a connection idle for 300 s; the timer sets the deadline instead.
|
|
564
|
-
upstreamRes = await fetch(incomingUrl, {
|
|
680
|
+
upstreamRes = await fetch(geminiUrl || incomingUrl, {
|
|
565
681
|
method: req.method,
|
|
566
682
|
headers,
|
|
567
683
|
body: rawBody,
|
|
@@ -593,6 +709,13 @@ export async function forward(input, init, getAuth, opts) {
|
|
|
593
709
|
|
|
594
710
|
// Gemini's citation markers come out of a chat reply, streamed or whole (see cite.mjs).
|
|
595
711
|
let respBody = upstreamRes.body && timedBody(upstreamRes.body, timer);
|
|
712
|
+
if (geminiUrl && (upstreamRes.status === 400 || upstreamRes.status === 403) && respBody) {
|
|
713
|
+
const text = await new Response(respBody).text();
|
|
714
|
+
if (keyRefused(upstreamRes.status, text)) {
|
|
715
|
+
return makeOpenAIError(401, 'Unauthorized: AI Studio refused the key');
|
|
716
|
+
}
|
|
717
|
+
respBody = text;
|
|
718
|
+
}
|
|
596
719
|
if (opts.stripCitations && incomingUrl === chatUrl && upstreamRes.ok && respBody) {
|
|
597
720
|
const type = upstreamRes.headers.get('content-type') || '';
|
|
598
721
|
if (type.includes('text/event-stream')) respBody = citeStream(respBody);
|