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
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ sudo docker compose down

#### 🌐 代理配置

| 变量名 | 描述 | 默认值 |
| :------------------------------ | :---------------------------------------------------------------------------------------------------------- | :-------- |
| `INITIAL_AUTH_INDEX` | 启动时使用的初始身份验证索引。 | `0` |
| `ENABLE_AUTH_UPDATE` | 是否启用自动保存凭证更新。设为 `true` 启用后,将在每次登录/切换账号成功时以及每 24 小时自动更新 auth 文件。 | `false` |
| `MAX_RETRIES` | 请求失败后的最大重试次数(仅对假流式和非流式生效)。 | `3` |
| `RETRY_DELAY` | 两次重试之间的间隔(毫秒)。 | `2000` |
| `SWITCH_ON_USES` | 自动切换帐户前允许的请求次数(设为 `0` 禁用)。 | `40` |
| `FAILURE_THRESHOLD` | 切换帐户前允许的连续失败次数(设为 `0` 禁用)。 | `3` |
| `IMMEDIATE_SWITCH_STATUS_CODES` | 触发立即切换帐户的 HTTP 状态码(逗号分隔)。 | `429,503` |
| 变量名 | 描述 | 默认值 |
| :------------------------------ | :------------------------------------------------------------------------------------------------------------------------- | :-------- |
| `INITIAL_AUTH_INDEX` | 启动时使用的初始身份验证索引。 | `0` |
| `ENABLE_AUTH_UPDATE` | 是否启用自动保存凭证更新。默认为启用状态,将在每次登录/切换账号成功时以及每 24 小时自动更新 auth 文件。设为 `false` 禁用。 | `true` |
| `MAX_RETRIES` | 请求失败后的最大重试次数(仅对假流式和非流式生效)。 | `3` |
| `RETRY_DELAY` | 两次重试之间的间隔(毫秒)。 | `2000` |
| `SWITCH_ON_USES` | 自动切换帐户前允许的请求次数(设为 `0` 禁用)。 | `40` |
| `FAILURE_THRESHOLD` | 切换帐户前允许的连续失败次数(设为 `0` 禁用)。 | `3` |
| `IMMEDIATE_SWITCH_STATUS_CODES` | 触发立即切换帐户的 HTTP 状态码(逗号分隔)。 | `429,503` |

#### 🗒️ 其他配置

Expand Down
18 changes: 9 additions & 9 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ This endpoint is forwarded to the official Gemini API format endpoint.

#### 🌐 Proxy Configuration

| Variable | Description | Default |
| :------------------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------- |
| `INITIAL_AUTH_INDEX` | Initial authentication index to use on startup. | `0` |
| `ENABLE_AUTH_UPDATE` | Whether to enable automatic auth credential updates. If set to `true`, the auth file will be automatically updated upon successful login/account switch and every 24 hours. | `false` |
| `MAX_RETRIES` | Maximum number of retries for failed requests (only effective for fake streaming and non-streaming). | `3` |
| `RETRY_DELAY` | Delay between retries in milliseconds. | `2000` |
| `SWITCH_ON_USES` | Number of requests before automatically switching accounts (`0` to disable). | `40` |
| `FAILURE_THRESHOLD` | Number of consecutive failures before switching accounts (`0` to disable). | `3` |
| `IMMEDIATE_SWITCH_STATUS_CODES` | HTTP status codes that trigger immediate account switching (comma-separated). | `429,503` |
| Variable | Description | Default |
| :------------------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------- |
| `INITIAL_AUTH_INDEX` | Initial authentication index to use on startup. | `0` |
| `ENABLE_AUTH_UPDATE` | Whether to enable automatic auth credential updates. Defaults to enabled. The auth file will be automatically updated upon successful login/account switch and every 24 hours. Set to `false` to disable. | `true` |
| `MAX_RETRIES` | Maximum number of retries for failed requests (only effective for fake streaming and non-streaming). | `3` |
| `RETRY_DELAY` | Delay between retries in milliseconds. | `2000` |
| `SWITCH_ON_USES` | Number of requests before automatically switching accounts (`0` to disable). | `40` |
| `FAILURE_THRESHOLD` | Number of consecutive failures before switching accounts (`0` to disable). | `3` |
| `IMMEDIATE_SWITCH_STATUS_CODES` | HTTP status codes that trigger immediate account switching (comma-separated). | `429,503` |

#### 🗒️ Other Configuration

Expand Down
12 changes: 11 additions & 1 deletion src/core/BrowserManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class BrowserManager {

// 3. Auto-Save Auth: Every ~24 hours (21600 ticks * 4s = 86400s)
if (tickCount % 21600 === 0) {
if (this._currentAuthIndex !== -1) {
if (this._currentAuthIndex >= 0) {
try {
this.logger.info("[HealthMonitor] 💾 Triggering daily periodic auth file update...");
await this._updateAuthFile(this._currentAuthIndex);
Expand Down Expand Up @@ -609,6 +609,16 @@ class BrowserManager {
this._currentAuthIndex = -1;
throw new Error(`Invalid authIndex: ${authIndex}. Must be >= 0.`);
}

// [Auth Switch] Save current auth data before switching
if (this.browser && this._currentAuthIndex >= 0) {
try {
await this._updateAuthFile(this._currentAuthIndex);
} catch (e) {
this.logger.warn(`[Browser] Failed to save current auth during switch: ${e.message}`);
}
}

if (!this.browser) {
this.logger.info("🚀 [Browser] Main browser instance not running, performing first-time launch...");
if (!fs.existsSync(this.browserExecutablePath)) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/FormatConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class FormatConverter {
/**
* Convert OpenAI request format to Google Gemini format
* @param {object} openaiBody - OpenAI format request body
* @returns {{ googleRequest: object, cleanModelName: string }} - Converted request and cleaned model name
* @returns {Promise<{ googleRequest: object, cleanModelName: string }>} - Converted request and cleaned model name
*/
async translateOpenAIToGoogle(openaiBody) {
// eslint-disable-line no-unused-vars
Expand Down
4 changes: 2 additions & 2 deletions src/utils/ConfigLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ConfigLoader {
apiKeys: [],
apiKeySource: "Not set",
browserExecutablePath: null,
enableAuthUpdate: false,
enableAuthUpdate: true,
failureThreshold: 3,
forceThinking: false,
forceUrlContext: false,
Expand Down Expand Up @@ -61,7 +61,7 @@ class ConfigLoader {
if (process.env.FORCE_URL_CONTEXT)
config.forceUrlContext = process.env.FORCE_URL_CONTEXT.toLowerCase() === "true";
if (process.env.ENABLE_AUTH_UPDATE)
config.enableAuthUpdate = process.env.ENABLE_AUTH_UPDATE.toLowerCase() === "true";
config.enableAuthUpdate = process.env.ENABLE_AUTH_UPDATE.toLowerCase() !== "false";

let rawCodes = process.env.IMMEDIATE_SWITCH_STATUS_CODES;
let codesSource = "environment variable";
Expand Down
Loading