@dorokuma/magpie-gemini-web 0.18.0 → 0.18.2
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 +21 -0
- package/README.en.md +15 -15
- package/README.md +15 -15
- package/index.mjs +87 -51
- package/lib/backend-release.json +14 -14
- package/lib/backend.mjs +29 -2
- package/lib/native.mjs +119 -10
- package/lib/private-browser.mjs +147 -0
- package/lib/setup.mjs +23 -0
- package/lib/web-connect.mjs +343 -0
- package/package.json +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
本文件按版本倒序记录 `magpie-gemini-web`(0.15.0 起为 `@dorokuma/magpie-gemini-web`)的全部已发布与待发变更,依据本仓 `git log` 与 tag 事实编写。
|
|
4
4
|
|
|
5
|
+
## 0.18.2 - 2026-11-19
|
|
6
|
+
|
|
7
|
+
### 变更
|
|
8
|
+
- Gemini Web 后端 pin 升级至 **`dorokuma/gemini-web2api-go` `v6.2.2`** 官方预编译二进制:task 模型不再注入对话模式专属的平台通知免疫词,所有模型的工具格式锚点保留。
|
|
9
|
+
|
|
10
|
+
### 新增
|
|
11
|
+
- 新增 `per_ip_concurrent` / `per_ip_rpm` / `per_ip_rph` 三个 Magpie 参数区选项(默认 `5` / `30` / `80`,与 gemini-web2api-go 后端默认一致,`0` 表示不限),用于配置本地受管后端的单 IP 限流,解决 `direct IP slot full: rph limit reached (429)`。选项在 `settings()` 中按后端 `validateRuntimeConfig` 范围校验(`0–1000` / `0–10000` / `0–100000`,须为整数);新建 `config.json` 会写入这些字段,存量 `config.json` 仅在值变化时按键合并(`port`、`multi_turn` 等其它字段与 `0600` 权限原样保留),运行中的受管后端经 `GET` + `PUT /admin/api/config` 热生效且值已一致时跳过写入;连接自建外部后端时仅作校验,不触碰外部实例。
|
|
12
|
+
|
|
13
|
+
## 0.18.1 - 2026-11-19
|
|
14
|
+
|
|
15
|
+
### 变更
|
|
16
|
+
- Gemini Web 后端 pin 升级至 **`dorokuma/gemini-web2api-go` `v6.2.1`** 官方预编译二进制:Chat 模式平台工具上限尾注前置免疫,减少工具调用被平台提示打断。
|
|
17
|
+
|
|
18
|
+
### 修复
|
|
19
|
+
- Gemini Web 一键登录不再让 Magpie 直接用系统默认浏览器打开 gemini.google.com:`authorize` 改为打开本机登录向导页(`127.0.0.1` 随机端口 + 随机 token 路径),页内按钮以无痕 / 隐私模式启动检测到的浏览器(Firefox 优先,其次 Chrome / Brave / Chromium / Edge;找不到时给出可手动复制的链接),避免登录会话落在日常窗口被 Google 踢出。
|
|
20
|
+
- Google 账号索引(authuser)不再在浏览器打开前提前询问:向导页在无痕窗口登录后再对照地址栏 `/u/N/app` 填写,与 Cookie、代理同一表单提交;校验或导入失败原地报错可直接改字段重试,不必取消重来。
|
|
21
|
+
- 无痕窗口启动器修复两处隐藏故障:浏览器二进制探测只查存在性,同名目录或无 `+x` 权限的文件会被误判为可用(`resolveBin` 现在校验普通文件与 POSIX 可执行权限);`spawn` 的异步 `'error'`(如 `EACCES`/`ENOENT`)原会以未处理异常击穿宿主进程,`launchPrivateBrowser` 改为 `async`、在 `'spawn'`/`'error'` 间竞速等待,启动失败自动回退下一个候选浏览器,不再假报成功。
|
|
22
|
+
- 向导页 `/submit` 增加单飞互斥:一次验证未结束时并发提交直接返回 `409`,不再允许多个导入管线同时写后端账号池;同时在每次 `await` 后复检会话是否已取消/超时(经 `isEnded()` 传入 `submit` 与 `importCookie`),取消或超时后不再继续写入账号;若取消发生在账号已创建、检测进行中或刚返回之后,`importCookie` 会 `DELETE` 回滚本次新建的账号(不动其它账号)。页面端取消后立即禁用表单,`/submit` 收到 `410` 也不再提示原地重试。
|
|
23
|
+
- `authorize` 不再把首次 `ensureBackend` 的失败 Promise 锁死:首次下载失败(如无代理拿到 503)或用户在向导页改填了代理时,`submit` 会以表单实际代理重新调用 `ensureBackend`,原地重试可成功登录;每代重建跟踪自己的失败状态(代际守卫),旧代迟到的 reject 不会污染新一代,后端就绪后再次检查会话是否已结束,已取消则不再导入 Cookie。
|
|
24
|
+
- 向导页模板替换改为函数 replacer:代理密码中含 `$$`、`$'`、`$&`、`` $` `` 等字符不再被 `String.prototype.replace` 的 `$` 元语法误展开而破坏 DOM;代理输入提示改为准确描述(留空表示不在本次登录指定代理,后端已配置代理池仍按其规则生效),第 1 步常驻展示可复制的 `https://gemini.google.com/app` 手动链接(自动拉起成功时也可见,覆盖 macOS Firefox 已运行锁或窗口未前置场景)。
|
|
25
|
+
|
|
5
26
|
## 0.18.0 - 2026-11-19
|
|
6
27
|
|
|
7
28
|
### 变更
|
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.2`](https://github.com/dorokuma/gemini-web2api-go/releases/tag/v6.2.2), 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.2`, 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.2` 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
|
|
|
@@ -159,6 +158,7 @@ magpie plugin options @dorokuma/magpie-gemini-web '{"studio":{"proxy":"http://12
|
|
|
159
158
|
| `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 |
|
|
160
159
|
| `baseURL` | `http://127.0.0.1:8083/v1` | `gemini-web` only | Default Gemini Web backend URL |
|
|
161
160
|
| `contextLimit` / `outputLimit` | `1000000` / `8192` | `gemini-web` only | Context and output limits reported to clients |
|
|
161
|
+
| `per_ip_concurrent` / `per_ip_rpm` / `per_ip_rph` | `5` / `30` / `80` | `gemini-web` only | Per-IP rate limits of the managed local backend: concurrent, per-minute and per-hour request caps; `0` means unlimited. Set them in Magpie's options area — they are written to `config.json` and hot-synced to a running backend, no restart needed. With a self-hosted backend they are validated only and never change the external instance |
|
|
162
162
|
| `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. When omitted, falls back to AI_STUDIO_PROXY or the proxy saved in the admin page; setting "" disables both (the backend's own system-proxy detection on macOS/Windows may still apply) |
|
|
163
163
|
| `studio.accountOrder` | none | `ai-studio` only | Account priority order (comma-separated string or string array, e.g. `["b@gmail.com","a@gmail.com"]`); seeds `ACCOUNT_ORDER` in `.env` when unset, while preserving any non-empty value saved in the admin page |
|
|
164
164
|
| `studio.modelAccounts` | none | `ai-studio` only | Per-model account bindings (`"model:acc1|acc2"` string or `{ "gemini-3.1-pro-preview": ["acc1", "acc2"] }` object); seeds `MODEL_ACCOUNTS` in `.env` when unset, while preserving any non-empty value saved in the admin page |
|
|
@@ -244,13 +244,13 @@ When a plugin error asks you to run a command, it includes the full ready-to-cop
|
|
|
244
244
|
- 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
245
|
|
|
246
246
|
**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.
|
|
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.2`](https://github.com/dorokuma/gemini-web2api-go/releases/tag/v6.2.2) 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`.
|
|
248
|
+
- One-click setup pins the prebuilt [v6.2.2](https://github.com/dorokuma/gemini-web2api-go/releases/tag/v6.2.2) 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.
|
|
249
|
+
- **Upgrading:** On load the plugin detects a stale managed backend process, stops it and upgrades the binary to the pinned `v6.2.2`, 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
250
|
- **Rollback to upstream / restore the pinned build** (run in the plugin directory after stopping the backend):
|
|
251
251
|
```bash
|
|
252
252
|
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.
|
|
253
|
+
npm run backend:install # Restore the default pinned v6.2.2
|
|
254
254
|
```
|
|
255
255
|
- For pin sync, verification and smoke procedures, see [docs/backend-release.md](docs/backend-release.md).
|
|
256
256
|
|
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.2`](https://github.com/dorokuma/gemini-web2api-go/releases/tag/v6.2.2) 原生支持 `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.2`,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.2` 固定 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
|
|
|
@@ -159,6 +158,7 @@ magpie plugin options @dorokuma/magpie-gemini-web '{"studio":{"proxy":"http://12
|
|
|
159
158
|
| `proxy` | 无 | 仅 `gemini-web` | 一键配置后端访问 Google 的代理(`http` / `https` / `socks5` / `socks5h`),也可用环境变量 `GEMINI_WEB_PROXY` 或在登录第一步填写 |
|
|
160
159
|
| `baseURL` | `http://127.0.0.1:8083/v1` | 仅 `gemini-web` | Gemini Web 默认后端地址 |
|
|
161
160
|
| `contextLimit` / `outputLimit` | `1000000` / `8192` | 仅 `gemini-web` | 向客户端声明的上下文 / 输出上限 |
|
|
161
|
+
| `per_ip_concurrent` / `per_ip_rpm` / `per_ip_rph` | `5` / `30` / `80` | 仅 `gemini-web` | 本地受管后端的单 IP 限流:瞬时并发 / 每分钟 / 每小时请求上限,`0` 表示不限。可在 Magpie 参数区直接配置,保存后写入 `config.json` 并热同步到运行中的后端,无需重启;连接自建后端时仅作校验,不会改动外部实例 |
|
|
162
162
|
| `studio.proxy` | 无 | 仅 `ai-studio` | 访问 Google 的代理(`http` / `https` / `socks5`),也可用环境变量 `AI_STUDIO_PROXY`;设置后优先于管理页里保存的代理。未设置时沿用环境变量或管理页保存的代理;显式设为空字符串 `""` 时不使用环境变量与管理页里保存的代理(macOS/Windows 上后端自身的系统代理检测仍可能生效) |
|
|
163
163
|
| `studio.accountOrder` | 无 | 仅 `ai-studio` | 账号优先顺序(逗号分隔字符串或字符串数组,如 `["b@gmail.com","a@gmail.com"]`);当 `.env` 中未保存或为空时作为初始值写入,管理页保存非空值后优先保留管理页设置 |
|
|
164
164
|
| `studio.modelAccounts` | 无 | 仅 `ai-studio` | 模型专属账号绑定(`"model:acc1|acc2"` 字符串或 `{ "gemini-3.1-pro-preview": ["acc1", "acc2"] }` 对象);当 `.env` 中未保存或为空时作为初始值写入,管理页保存非空值后优先保留管理页设置 |
|
|
@@ -244,13 +244,13 @@ magpie plugin options @dorokuma/magpie-gemini-web '{"studio":{"proxy":"http://12
|
|
|
244
244
|
- 模型列表过滤 `-build` / `assistant_route` 模型:这类模型附带 Build 写代码助手的系统提示词,不作为普通 Agent 模型提供。升级后可执行 `magpie provider models ai-studio` 刷新列表。
|
|
245
245
|
|
|
246
246
|
**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.
|
|
247
|
+
- [#53](https://github.com/dorokuma/magpie-gemini-web/issues/53) 的多账号索引漏传已修复,需重新导入受影响的 Cookie 或在后端账号管理中修正索引。后端 [`dorokuma/gemini-web2api-go` `v6.2.2`](https://github.com/dorokuma/gemini-web2api-go/releases/tag/v6.2.2) 已原生收录 `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`。
|
|
248
|
+
- 插件默认固定使用后端仓发布的 [v6.2.2](https://github.com/dorokuma/gemini-web2api-go/releases/tag/v6.2.2) 预编译二进制(一仓一制品,6 平台 SHA-256 pin 在 `lib/backend-release.json`,不再由插件仓打补丁重编)。对话请求按上游沉默计时:Google 让请求排队时每 60 秒发一次心跳,后端会一直等到出字;连续 `request_timeout_sec`(默认 180 秒)没有任何数据才放弃这一次并重试,还在出字的长回复也不会被截断。
|
|
249
|
+
- **旧版升级**:插件加载时若识别到托管的旧版后端进程,会自动回收并升级到当前 pin 的 `v6.2.2`,这可能中断正在进行的生成请求;建议升级前先等待在途请求结束,或手动停止旧进程(PID 见数据目录 `backend.pid`)。非插件托管或无法识别的实例不保证自动更新。升级后保留原有配置与账号。
|
|
250
250
|
- **回退官方上游版 / 恢复 pin 版**(停止后端后在插件目录执行):
|
|
251
251
|
```bash
|
|
252
252
|
npm run backend:install:upstream # 回退并固定使用上游 zexadev v4.28.0
|
|
253
|
-
npm run backend:install # 恢复默认 pin 的 v6.2.
|
|
253
|
+
npm run backend:install # 恢复默认 pin 的 v6.2.2
|
|
254
254
|
```
|
|
255
255
|
- pin 同步、校验与冒烟流程见 [docs/backend-release.md](docs/backend-release.md)。
|
|
256
256
|
|
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
|
|
|
@@ -71,7 +71,7 @@ async function forwardManaged(input, init, getAuth, opts) {
|
|
|
71
71
|
}
|
|
72
72
|
if (!managedBackend(c.baseURL, c.key)) return res;
|
|
73
73
|
try {
|
|
74
|
-
await ensureBackend({ proxy: opts.proxy });
|
|
74
|
+
await ensureBackend({ proxy: opts.proxy, rateLimit: opts.rateLimit });
|
|
75
75
|
} catch {
|
|
76
76
|
return res;
|
|
77
77
|
}
|
|
@@ -99,24 +99,10 @@ 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()) {
|
|
119
|
-
ensureBackend({ proxy: opts.proxy })
|
|
105
|
+
ensureBackend({ proxy: opts.proxy, rateLimit: opts.rateLimit })
|
|
120
106
|
.then(async local => {
|
|
121
107
|
if (!opts.proxy) return;
|
|
122
108
|
await requireLoginBackend(local);
|
|
@@ -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, rateLimit: opts.rateLimit });
|
|
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
|
}
|
|
@@ -273,7 +309,7 @@ export const GeminiWebPlugin = async (_input, options = {}) => {
|
|
|
273
309
|
return await listModels(c, opts);
|
|
274
310
|
} catch (err) {
|
|
275
311
|
if (!err.unreachable || !managedBackend(c.baseURL, c.key)) throw err;
|
|
276
|
-
await ensureBackend({ proxy: opts.proxy });
|
|
312
|
+
await ensureBackend({ proxy: opts.proxy, rateLimit: opts.rateLimit });
|
|
277
313
|
return listModels(c, opts);
|
|
278
314
|
}
|
|
279
315
|
}
|
package/lib/backend-release.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "6.2.
|
|
2
|
+
"version": "6.2.2",
|
|
3
3
|
"repository": "dorokuma/gemini-web2api-go",
|
|
4
|
-
"tag": "v6.2.
|
|
4
|
+
"tag": "v6.2.2",
|
|
5
5
|
"binaries": {
|
|
6
6
|
"darwin-x64": {
|
|
7
|
-
"asset": "gemini-web2api-go_v6.2.
|
|
8
|
-
"sha256": "
|
|
7
|
+
"asset": "gemini-web2api-go_v6.2.2_darwin_amd64",
|
|
8
|
+
"sha256": "791ceadd5618726ef3de1d2fc56ae9f57d760a97ff1f3af1c82cee6951ffe9b2"
|
|
9
9
|
},
|
|
10
10
|
"darwin-arm64": {
|
|
11
|
-
"asset": "gemini-web2api-go_v6.2.
|
|
12
|
-
"sha256": "
|
|
11
|
+
"asset": "gemini-web2api-go_v6.2.2_darwin_arm64",
|
|
12
|
+
"sha256": "b1191c3c36c96f166e09591c2048c12028c63b56267b8eddfff412eedd758fad"
|
|
13
13
|
},
|
|
14
14
|
"linux-x64": {
|
|
15
|
-
"asset": "gemini-web2api-go_v6.2.
|
|
16
|
-
"sha256": "
|
|
15
|
+
"asset": "gemini-web2api-go_v6.2.2_linux_amd64",
|
|
16
|
+
"sha256": "421c55958a9006754ff8a0bfbd65547a1c1339c538d0c1ccdd2c7cfaafcfeb95"
|
|
17
17
|
},
|
|
18
18
|
"linux-arm64": {
|
|
19
|
-
"asset": "gemini-web2api-go_v6.2.
|
|
20
|
-
"sha256": "
|
|
19
|
+
"asset": "gemini-web2api-go_v6.2.2_linux_arm64",
|
|
20
|
+
"sha256": "7896f25577b00c75fc448a7d663315ee51a3454e4bf5c13b6ccfbfc5ea24df1c"
|
|
21
21
|
},
|
|
22
22
|
"win32-x64": {
|
|
23
|
-
"asset": "gemini-web2api-go_v6.2.
|
|
24
|
-
"sha256": "
|
|
23
|
+
"asset": "gemini-web2api-go_v6.2.2_windows_amd64.exe",
|
|
24
|
+
"sha256": "5abc5d0d9df38af373044da656de9278515ca0f4596a4ac8f3dab51e4679bb3e"
|
|
25
25
|
},
|
|
26
26
|
"win32-arm64": {
|
|
27
|
-
"asset": "gemini-web2api-go_v6.2.
|
|
28
|
-
"sha256": "
|
|
27
|
+
"asset": "gemini-web2api-go_v6.2.2_windows_arm64.exe",
|
|
28
|
+
"sha256": "448dd8b5c1e9c939f730895c60b3c8d7dac4a6f51684f8cab96b2b74fb26aea0"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
}
|
package/lib/backend.mjs
CHANGED
|
@@ -32,9 +32,23 @@ const KNOWN_OPTIONS = new Set([
|
|
|
32
32
|
'outputLimit',
|
|
33
33
|
'requestTimeoutMs',
|
|
34
34
|
'modelTimeoutMs',
|
|
35
|
-
'stripCitations'
|
|
35
|
+
'stripCitations',
|
|
36
|
+
'per_ip_concurrent',
|
|
37
|
+
'per_ip_rpm',
|
|
38
|
+
'per_ip_rph',
|
|
39
|
+
// Tolerated so a settings() result can be passed back in as options (tests do this);
|
|
40
|
+
// it is ignored on input — the per_ip_* keys are what get validated and applied.
|
|
41
|
+
'rateLimit'
|
|
36
42
|
]);
|
|
37
43
|
|
|
44
|
+
// Per-IP rate limits of the managed gemini-web2api-go backend. The bounds mirror its
|
|
45
|
+
// validateRuntimeConfig; 0 disables the limit.
|
|
46
|
+
const RATE_LIMIT_BOUNDS = {
|
|
47
|
+
per_ip_concurrent: [0, 1000],
|
|
48
|
+
per_ip_rpm: [0, 10000],
|
|
49
|
+
per_ip_rph: [0, 100000]
|
|
50
|
+
};
|
|
51
|
+
|
|
38
52
|
export function makeOpenAIError(status, message, extraHeaders = {}) {
|
|
39
53
|
const codeMap = {
|
|
40
54
|
400: 'invalid_request_error',
|
|
@@ -198,6 +212,18 @@ export function settings(options = {}) {
|
|
|
198
212
|
stripCitations = options.stripCitations;
|
|
199
213
|
}
|
|
200
214
|
|
|
215
|
+
// Left unset, a limit stays undefined so an externally managed backend is never
|
|
216
|
+
// overwritten with defaults it never declared.
|
|
217
|
+
const parsedRateLimit = {};
|
|
218
|
+
for (const [name, [min, max]] of Object.entries(RATE_LIMIT_BOUNDS)) {
|
|
219
|
+
const value = options[name];
|
|
220
|
+
if (value === undefined) continue;
|
|
221
|
+
if (!Number.isInteger(value) || value < min || value > max) {
|
|
222
|
+
throw new Error(`Invalid option ${name}: must be an integer between ${min} and ${max} (0 = no limit)`);
|
|
223
|
+
}
|
|
224
|
+
parsedRateLimit[name] = value;
|
|
225
|
+
}
|
|
226
|
+
|
|
201
227
|
return {
|
|
202
228
|
baseURL,
|
|
203
229
|
proxy,
|
|
@@ -207,7 +233,8 @@ export function settings(options = {}) {
|
|
|
207
233
|
outputLimit,
|
|
208
234
|
requestTimeoutMs,
|
|
209
235
|
modelTimeoutMs,
|
|
210
|
-
stripCitations
|
|
236
|
+
stripCitations,
|
|
237
|
+
rateLimit: parsedRateLimit
|
|
211
238
|
};
|
|
212
239
|
}
|
|
213
240
|
|