Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PROXY_API_KEY=
# 各 key 可用的账户,每项写成 key:账户|账户,逗号分隔多项;未列出的 key 可用全部账户
API_KEY_ACCOUNTS=

# 管理程序启动后自动启动生成服务,修改后重启程序生效
# 管理程序启动后自动启动生成服务,下次启动程序时生效
AUTO_START=false

# macOS 桌面版只在菜单栏显示图标、不显示 Dock 图标,在设置页修改立即生效
Expand All @@ -28,7 +28,7 @@ LOG_FILE=true
# 日志目录总量上限(MB),超出时删除最旧的文件,不小于 20
LOG_MAX_TOTAL_MB=500

# 管理控制台登录,修改后重启程序生效
# 管理控制台登录,在设置页保存后立即生效(关闭登录仅限本机访问)
ADMIN_AUTH_ENABLED=false
ADMIN_USERNAME=admin
ADMIN_PASSWORD=
Expand Down Expand Up @@ -63,6 +63,12 @@ ACCOUNT_ORDER=
# 上游返回 403、5xx 等非额度错误时一个请求最多换几次账户重试,0 为不换号;登录失效与额度用尽不计入
MAX_ACCOUNT_SWITCHES=3

# 同一请求内账户失败后切往下一个账户(含冷备账户启动 Worker)前的最短等待秒数;off 为不等待,正整数为秒数
ACCOUNT_SWITCH_INTERVAL=off

# 同一请求内因额度用尽(429)切换账户的次数上限;off 为不限制,0 为不换号,正整数为最多换号次数
MAX_QUOTA_SWITCHES=off

# 生成请求使用的上游通道:playground、build(旧通道,上游已停用其生成),逗号分隔
UPSTREAM_CHANNELS=playground

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ jobs:
run: |
flags=()
if [[ "$RELEASE_TAG" == *-* ]]; then flags+=(--prerelease); fi
rm -f dist/SHA256SUMS
(cd dist && sha256sum -- * > ../SHA256SUMS && mv ../SHA256SUMS SHA256SUMS)
gh release create "$RELEASE_TAG" dist/* --verify-tag --generate-notes --title "$RELEASE_TAG" "${flags[@]}"

docker:
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,10 @@ docker compose up -d

设置的生效时机:

- 保存后立即生效:账户选择策略、Worker 容量、换号次数上限、模型映射、非流式保活、假流式、搜索型号、全模型搜索、回复工具防截断、简体转繁体改写与媒体输出;进行中的请求沿用开始时的设置
- 停止再启动生成服务后生效:其余生成服务配置,启动时读取最新 `.env`
- 重启管理进程后生效:管理页面地址、预览地址和 `PROXY_API_KEY`
- 绝大多数设置保存后对下一次请求立即生效(包括本地 API 密钥、管理登录、默认代理与代理池、上游通道、隐藏模型探测、超时、首字对冲、换号策略、请求改写与日志设置);进行中的请求沿用开始时的设置,默认代理变更会在各账户在途请求结束后自动切换 Worker
- 重启生成服务后生效:`WAA_BACKEND` 与 `AISTUDIO_AUTH_STATES`(生成服务运行时可在设置页直接点击重启生成服务)
- 重启管理进程后生效:`LISTEN_ADDR` 与 `PREVIEW_LISTEN_ADDR`
- 下次启动程序时生效:`AUTO_START`

退出程序:

Expand Down Expand Up @@ -681,6 +682,8 @@ cp .env.example .env
| `ROUTING_STRATEGY` | `round-robin` | `round-robin` 轮询;`fill-first` 账号粘性优先 |
| `ACCOUNT_ORDER` | 空 | `fill-first` 依次使用的账户,逗号分隔,未列出的账户排在后面并按 ID 排序;也可在设置页调整,保存后立即生效 |
| `MAX_ACCOUNT_SWITCHES` | `3` | 上游返回 403、5xx 等非额度错误时一个请求最多换几次账户重试,`0` 为不换号 |
| `ACCOUNT_SWITCH_INTERVAL` | `off` | 同一请求内前一个账户失败后,下一个账户向 Google 发出请求(或启动冷备 Worker)前从上次失败起等待的最短秒数;`off` 为不等待,正整数为秒数 |
| `MAX_QUOTA_SWITCHES` | `off` | 同一请求内因额度用尽(429)切换账户的次数上限;`off` 为不限制,依次尝试全部账户,`0` 为不换号,正整数为最多换号次数,超出后返回最后一次 429 |
| `UPSTREAM_CHANNELS` | `playground` | 生成请求使用的上游通道,`playground`、`build` 逗号分隔;`build` 为旧通道,上游已停用其生成 |
| `MODEL_MAPPING` | 空 | 客户端模型名到目录模型的映射,每项写成 `别名:模型 ID`,逗号分隔多项 |
| `MODEL_CHANNELS` | 空 | 限定模型只走一个通道,每项写成 `模型 ID:playground` 或 `模型 ID:build`;也可在“模型目录”的模型详情中选择,保存后立即生效 |
Expand Down Expand Up @@ -709,13 +712,14 @@ cp .env.example .env

- `PREVIEW_LISTEN_ADDR`:无法监听时改用同一主机上的空闲端口;页面以当前访问的主机名加实际端口打开预览
- `AUTO_START`:网络等原因启动失败时按 5 秒起、翻倍至 5 分钟的间隔重试,手动启动或停止后不再重试
- `MAX_ACCOUNT_SWITCHES`:登录失效与额度用尽不计入,照常依次尝试其余账户
- `MAX_ACCOUNT_SWITCHES`:登录失效与额度用尽不计入;额度用尽的换号次数由 `MAX_QUOTA_SWITCHES` 单独控制(默认不限)
- `ACCOUNT_SWITCH_INTERVAL`:切往冷备账户时先等满间隔再启动 Worker,就绪后直接发送,不重复等待;等待期间客户端断开即结束
- `NONSTREAM_KEEPALIVE`:返回 200 后每 10 秒写出一个换行直到写出 JSON 正文,经 Cloudflare 等反向代理时连接不会因长时间无数据断开;此后才出现的错误以协议错误正文返回
- `STRIP_THOUGHT_SIGNATURES`:函数调用带 `skip_thought_signature_validator`;之前各轮的思考内容不随签名发给模型,长对话的输入 token 较少
- `DISCOVER_HIDDEN_MODELS`:
- 在同步账户模型目录时探测:启动、每 24 小时与账户页“刷新全部”
- 确认账户能用的模型加入目录,可直接用于各协议请求并列在 `/v1/models` 中,“模型目录”页标为“官网隐藏”
- 官网公开后改用官网的模型信息;关闭后下一次启动生成服务时从目录中移除
- 官网公开后改用官网的模型信息;关闭后立即从目录中移除,开启后在后台自动探测
- `FIRST_EVENT_HEDGE`:
- 备用请求优先用其他账户,没有时用原账户的空闲槽位;先出首字的一方继续,另一方取消
- `auto` 按各模型与通道近 24 小时首字等待的 p95,请求少于 20 次的模型与通道不发起
Expand All @@ -741,13 +745,13 @@ cp .env.example .env

管理控制台默认通过本机回环地址免密访问。远程管理时:

- 设置 `ADMIN_AUTH_ENABLED=true`、管理员账号和密码,重启程序后通过独立 `/login` 页面登录
- 设置 `ADMIN_AUTH_ENABLED=true`、管理员账号和密码后通过独立 `/login` 页面登录(在设置页保存后立即生效,并为当前浏览器自动保持登录)
- 登录会话有效期为 12 小时;勾选“30 天内保持登录”时为 30 天,程序重启后仍有效
- 支持退出登录,管理员共享同一个账户池、配置与日志

公开 API 使用独立的 `PROXY_API_KEY`。

反向代理使用 HTTPS,并保留原始 `Host`、设置 `X-Forwarded-Proto: https`。管理页“服务配置”可调整登录开关及凭据,保存后重启程序生效。
反向代理使用 HTTPS,并保留原始 `Host`、设置 `X-Forwarded-Proto: https`。管理页“服务配置”可调整登录开关及凭据,保存后立即生效(关闭登录仅限本机访问操作)。

API 试用页的 HTML 预览运行在 `PREVIEW_LISTEN_ADDR` 提供的独立来源,页面以当前访问的主机名加该端口打开预览:

Expand Down
18 changes: 11 additions & 7 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,10 @@ Add more accounts on the same page; [Account Management](#account-management) co

When settings take effect:

- As soon as they are saved: the account selection strategy, worker capacity, max account switches, model mapping, non-streaming keepalive, fake streaming, search model variants, Google Search for all models, reply tool anti-truncation, Simplified to Traditional Chinese rewrite, and media output; requests already in progress keep the settings they started with
- After stopping and starting the generation service: the other data-plane settings, read from the latest `.env` at start
- After restarting the management process: `LISTEN_ADDR`, `PREVIEW_LISTEN_ADDR`, and `PROXY_API_KEY`
- On the next request as soon as they are saved: almost all settings (including `PROXY_API_KEY`, console login, default proxy and proxy pool, upstream channels, hidden model discovery, timeouts, first-event hedge, account switching policy, request rewrites, and logging); requests already in progress keep the settings they started with, and proxy changes drain and rebind affected account workers once their in-flight requests finish
- After restarting the generation service: `WAA_BACKEND` and `AISTUDIO_AUTH_STATES` (when the generation service is running, Settings offers a button to restart it)
- After restarting the management process: `LISTEN_ADDR` and `PREVIEW_LISTEN_ADDR`
- On the next program start: `AUTO_START`

Exiting:

Expand Down Expand Up @@ -681,6 +682,8 @@ Process environment variables override the same keys in `.env`, and those settin
| `ROUTING_STRATEGY` | `round-robin` | `round-robin` rotates accounts; `fill-first` reuses the first available account |
| `ACCOUNT_ORDER` | empty | Accounts `fill-first` uses in order, comma-separated; unlisted accounts follow in ID order. Also adjustable on the Settings page, applied on save |
| `MAX_ACCOUNT_SWITCHES` | `3` | How many times a request moves to another account after a non-quota upstream error such as 403 or 5xx; `0` disables switching |
| `ACCOUNT_SWITCH_INTERVAL` | `off` | Minimum wait in seconds from a failed account attempt before the next account sends any request to Google (or cold-starts a standby worker); `off` disables waiting |
| `MAX_QUOTA_SWITCHES` | `off` | Maximum account switches for quota exhaustion (429) within one request; `off` tries all remaining accounts, `0` disables quota switching, and a positive integer returns the last 429 once exceeded |
| `UPSTREAM_CHANNELS` | `playground` | Upstream channels for generation requests, `playground` and `build` comma separated; `build` is the legacy channel whose generation upstream has disabled |
| `MODEL_MAPPING` | empty | Client model names mapped to catalog models, each item `alias:model ID`, comma separated |
| `MODEL_CHANNELS` | empty | Limit a model to one channel, each item `model ID:playground` or `model ID:build`; also selectable in model details on the Model catalog page, applied on save |
Expand Down Expand Up @@ -709,13 +712,14 @@ Notes:

- `PREVIEW_LISTEN_ADDR`: when it cannot be bound, a free port on the same host is used; the page opens previews at the current host name with the port in use
- `AUTO_START`: if startup fails for reasons such as the network, it retries at intervals starting at 5 seconds and doubling up to 5 minutes, until the service is started or stopped manually
- `MAX_ACCOUNT_SWITCHES`: expired sessions and quota errors do not count, and the remaining accounts are still tried in turn
- `MAX_ACCOUNT_SWITCHES`: expired sessions and quota errors do not count; quota-exhaustion switches are controlled separately by `MAX_QUOTA_SWITCHES` (unlimited by default)
- `ACCOUNT_SWITCH_INTERVAL`: when moving to a standby account, waits for the interval before starting the worker and sends immediately once ready without waiting again; stops immediately if the client disconnects
- `NONSTREAM_KEEPALIVE`: after returning 200, a newline is written every 10 seconds until the JSON body, so reverse proxies such as Cloudflare keep the connection open; errors after that point come back as the protocol error body
- `STRIP_THOUGHT_SIGNATURES`: function calls are sent with `skip_thought_signature_validator`; earlier turns' thinking is not passed to the model with the signatures, so long conversations use fewer input tokens
- `DISCOVER_HIDDEN_MODELS`:
- Discovery runs when account model catalogs sync: at startup, every 24 hours, and on Refresh all in Accounts
- Models the account is confirmed to be able to use are added to the catalog; they can be used through every protocol, appear in `/v1/models`, and are marked Hidden in AI Studio on the Model catalog page
- Once AI Studio lists a model, its official details are used; turning this off removes them the next time the generation service starts
- Once AI Studio lists a model, its official details are used; turning this off removes hidden models immediately, and turning it on discovers them in the background
- `FIRST_EVENT_HEDGE`:
- The backup request uses another account first, otherwise a free slot on the same account; the first to answer continues and the other is cancelled
- `auto` waits for the p95 of each model and channel over the last 24 hours, and models with fewer than 20 requests are not hedged
Expand All @@ -741,13 +745,13 @@ The service loads every account from `AISTUDIO_AUTH_STATES`. Four settings contr

The console allows passwordless loopback access by default. For remote management:

- Set `ADMIN_AUTH_ENABLED=true`, configure the administrator username and password, restart the process, and sign in on the separate `/login` page
- Set `ADMIN_AUTH_ENABLED=true`, configure the administrator username and password, and sign in on the separate `/login` page (saving in Settings takes effect immediately and keeps the current browser signed in)
- A session lasts 12 hours; with "Stay signed in for 30 days" checked it lasts 30 days and survives restarts
- Sign-out is supported; administrators share the instance's account pool, configuration, and logs

Public APIs use the separate `PROXY_API_KEY`.

Use an HTTPS reverse proxy that preserves `Host` and sets `X-Forwarded-Proto: https`. Console login settings can also be saved from the settings page and take effect after restarting the process.
Use an HTTPS reverse proxy that preserves `Host` and sets `X-Forwarded-Proto: https`. Console login settings saved from the Settings page take effect immediately (disabling login is only allowed from loopback).

HTML previews in the API playground run on a separate origin served at `PREVIEW_LISTEN_ADDR`, and the page opens them at the current host name with that port:

Expand Down
18 changes: 10 additions & 8 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ Camoufox 运行中与服务的 WebDriver BiDi 连接断开时,服务最多等
| `first_event_hedge`、`first_event_hedge_models`、`first_event_timeout` | 下一次启动生成服务时使用的首字超时备用请求与单次首字超时设置 |
| `strip_thought_signatures` | 下一次启动生成服务时使用的思考签名去除开关 |
| `routing_strategy`、`account_order` | 保存后立即作用于账户选择的策略与 `fill-first` 顺序 |
| `max_account_switches` | 保存后立即作用于换号判断的次数上限 |
| `max_account_switches`、`account_switch_interval`、`max_quota_switches` | 保存后立即作用于换号次数上限、换号间隔与额度用尽换号上限 |
| `api_key_accounts` | 保存后立即作用于新请求的 API key 账户绑定 |
| `model_channels`、`model_accounts` | 保存后立即作用于新请求的按模型通道与账户限定 |
| `media_output`、`media_base_url` | 保存后立即作用于新请求的媒体引用方式与媒体服务地址 |
Expand All @@ -457,17 +457,19 @@ Camoufox 运行中与服务的 WebDriver BiDi 连接断开时,服务最多等
| `hide_dock_icon` | macOS 桌面版是否隐藏 Dock 图标,保存后立即生效 |
| `request_body_log` | 保存后立即决定是否保存请求与响应正文 |
| `log_file`、`log_max_total_mb` | 保存后立即开关日志文件并按新的总量上限轮转 |
| `admin_auth_enabled`、`admin_username`、`admin_password` | 保存的管理登录配置;省略密码保留现值,密码只接受写入 |
| `admin_auth_enabled`、`admin_username`、`admin_password` | 管理登录配置,保存后立即生效;省略密码保留现值,密码只接受写入;本机启用或改密时自动为当前请求签发新会话 Cookie 并撤销其余会话,非回环请求禁止关闭登录 |
| `admin_password_set` | 是否已配置管理密码 |
| `listen_addr`、`proxy_api_key` | 保存的管理监听配置 |
| `listen_addr` | 保存的管理监听地址,管理进程重启后生效 |
| `proxy_api_key` | 本机 API key,保存后立即作用于新请求 |
| `preview_listen_addr` | 保存的 API 试用页预览来源监听地址,管理进程重启后生效 |
| `active_preview_listen_addr` | 当前管理进程实际使用的预览来源地址 |
| `active_listen_addr`、`active_proxy_api_key` | 当前管理进程固定使用的值 |
| `active_listen_addr` | 当前管理进程实际使用的监听地址 |
| `reserved_listen_addr` | 被 Windows 保留而改用 `active_listen_addr` 的监听地址,没有改用时为空 |
| `active_proxy` | 当前生成服务使用的出口,代理池为逗号分隔的全部代理,`proxy` 为空时为系统代理,没有系统代理时为空 |
| `proxy_pool` | 当前生成服务的代理池:每个代理的地址、是否可用、绑定账户数、最近检测时间与最近错误 |
| `management_restart_required` | 保存的监听地址、API key 或管理登录配置与当前管理进程不同 |
| `service_restart_required` | 保存的生成服务配置与当前生成服务实例不同 |
| `active_requests` | 当前生成服务进行中的请求数 |
| `management_restart_required` | 保存的 `listen_addr` 或 `preview_listen_addr` 与当前管理进程不同 |
| `service_restart_required` | 生成服务运行中,且保存的 `waa_backend` 或 `auth_states` 与当前生成服务实例不同 |
| `environment` | 取自进程环境变量、覆盖 `.env` 的配置键 |
| `invalid` | 取值无效而按默认值运行的项,每项为 `key`、`value` 与 `reason` |

Expand Down Expand Up @@ -639,15 +641,15 @@ Worker 容量由热池目标、活动上限和单账户并发共同约束。
- 先用 Worker 已就绪且没有活动请求的其他账户,没有时用原账户的其余并发槽位
- 引用已上传文件或指定账户的请求只用原账户的其余并发槽位
- 都没有时每秒复查;同时进行的备用请求最多 4 个
- 后台 Responses 与 Interaction、Deep Research 与 Antigravity 等经后台任务生成的 agent(`interaction_task`)与 `-build` 写代码助手请求不发起备用请求
- 后台 Responses 与 Interaction、Deep Research 与 Antigravity 等 agent(`interaction_agent`)与 `-build` 写代码助手请求不发起备用请求

结果:

- 先出首事件的一方继续,另一方取消上游请求、清理临时文件并释放租约
- 被取消的请求同样计入上游的每日与每分钟请求额度
- 账本的 `attempts` 以 `hedge` 标记备用请求,以 `superseded` 标记被取代的一方

`FIRST_EVENT_TIMEOUT` 不为 `off` 时,除后台 Responses、后台 Interactions 与经后台任务生成的 agent(`interaction_task`)外,每次生成尝试(含 `-build` 写代码助手)从取得账户起等待首个语义事件达到阈值后,取消该尝试并换号:
`FIRST_EVENT_TIMEOUT` 不为 `off` 时,除后台 Responses、后台 Interactions 与 agent(`interaction_agent`)外,每次生成尝试(含 `-build` 写代码助手)从取得账户起等待首个语义事件达到阈值后,取消该尝试并换号:

- 计入 `MAX_ACCOUNT_SWITCHES`,不冷却账户、不改账户状态、不重建 Worker;没有可换账户或换号用尽时返回 504 并写明 `FIRST_EVENT_TIMEOUT`
- 与 `FIRST_EVENT_HEDGE` 同开时原请求与备用请求各自计时,一方到期取消不影响另一方继续等待;`REQUEST_TIMEOUT` 管整个请求,更早到期时直接结束请求不换号
Expand Down
Loading