copilot-api-plus 1.2.9 → 1.2.10

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 CHANGED
@@ -46,7 +46,7 @@ English | [简体中文](README.md)
46
46
  | 👥 **Multi-Account** | Multiple GitHub accounts with automatic failover on quota exhaustion/rate limiting/bans |
47
47
  | 🔀 **Model Routing** | Flexible model name mapping and per-model concurrency control |
48
48
  | 📱 **Visual Management** | Web dashboard for account management, model config, and runtime stats |
49
- | 🛡️ **Network Resilience** | 120s connection timeout + smart retry (pool reset + fast-fail) |
49
+ | 🛡️ **Network Resilience** | 120s connection timeout + smart retry (pool reset + HTTP/2 keepalive + proxy optimization) |
50
50
  | ✂️ **Context Passthrough** | Full context passthrough to upstream API; clients (e.g. Claude Code) manage compression |
51
51
  | 🔍 **Smart Model Matching** | Handles model name format differences (date suffixes, dash/dot versions, etc.) |
52
52
  | 🧠 **Thinking Chain** | Automatically enables deep thinking (thinking/reasoning) for supported models, improving code quality |
@@ -582,9 +582,11 @@ Each API request outputs a log line with model name, status code, and duration:
582
582
 
583
583
  Built-in connection timeout and smart retry for upstream API requests, minimizing Copilot request credit consumption:
584
584
 
585
- - **Connection timeout**: 120 seconds for the first attempt, 20 seconds for retries (fail fast)
586
- - **Retry strategy**: Up to 1 retry (2 total attempts), 2-second delay
585
+ - **Connection timeout**: 120 seconds for the first attempt, 90 seconds for retries (enough time for model thinking)
586
+ - **Retry strategy**: Up to 2 retries (3 total attempts), 2-3 second delays
587
587
  - **Connection pool reset**: Automatically destroys all pooled connections on the first network error and creates fresh instances, preventing retries from hitting stale sockets
588
+ - **HTTP/2 keepalive**: Enables HTTP/2 protocol; PING frames traverse proxy tunnels to prevent idle disconnections
589
+ - **TCP keepalive**: Sends TCP probes every 15s to prevent proxies/firewalls from dropping idle connections
588
590
  - Only retries network-layer errors (timeout, TLS disconnect, connection reset, etc.); HTTP error codes (e.g. 400/500) are not retried
589
591
  - SSE stream interruptions gracefully send error events to the client
590
592
 
package/README.md CHANGED
@@ -47,7 +47,7 @@
47
47
  | 👥 **多账号管理** | 支持添加多个 GitHub 账号,额度耗尽/限流/封禁时自动切换下一个 |
48
48
  | 🔀 **模型路由** | 灵活的模型名映射和每模型并发控制 |
49
49
  | 📱 **可视化管理** | Web 仪表盘支持账号管理、模型管理、运行统计 |
50
- | 🛡️ **网络弹性** | 120s 连接超时 + 智能重试(连接池重置 + 短超时快速失败) |
50
+ | 🛡️ **网络弹性** | 120s 连接超时 + 智能重试(连接池重置 + HTTP/2 保活 + 代理穿透优化) |
51
51
  | ✂️ **上下文透传** | 全量透传上下文至上游 API,由客户端(如 Claude Code)自行管理压缩 |
52
52
  | 🔍 **智能模型匹配** | 自动处理模型名格式差异(日期后缀、dash/dot 版本号等) |
53
53
  | 🧠 **Thinking 思维链** | 自动为支持的模型启用深度思考(thinking/reasoning),提升代码质量 |
@@ -745,9 +745,11 @@ Anthropic 格式的模型名(如 `claude-opus-4-6`)和 Copilot 的模型列
745
745
 
746
746
  对上游 API 的请求内置了连接超时和智能重试,以最小化 Copilot 请求次数消耗:
747
747
 
748
- - **连接超时**:首次请求 120 秒,重试请求 20 秒(快速失败,避免白等)
749
- - **重试策略**:最多重试 1 次(共 2 次尝试),间隔 2 秒
748
+ - **连接超时**:首次请求 120 秒,重试请求 90 秒(给模型足够的思考时间)
749
+ - **重试策略**:最多重试 2 次(共 3 次尝试),间隔 2-3
750
750
  - **连接池重置**:首次网络错误后自动销毁所有连接并创建新实例,避免后续请求复用坏连接
751
+ - **HTTP/2 保活**:启用 HTTP/2 协议,PING 帧穿透代理隧道防止空闲断连
752
+ - **TCP 保活**:每 15 秒发送 TCP 探测包,防止代理/防火墙因空闲而断开连接
751
753
  - 仅重试网络层错误(超时、TLS 断开、连接重置等),HTTP 错误码(如 400/500)不重试
752
754
  - SSE 流传输中断时,优雅地向客户端发送错误事件
753
755
 
package/dist/main.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { _ as GITHUB_BASE_URL, a as PATHS, b as copilotHeaders, c as forwardError, d as findModel, f as isNullish, h as state, l as cacheModels, m as sleep, o as ensurePaths, p as rootCause, r as getCopilotUsage, s as HTTPError, t as accountManager, u as cacheVSCodeVersion, v as GITHUB_CLIENT_ID, x as standardHeaders, y as copilotBaseUrl } from "./account-manager-DmXXcFBW.js";
3
- import { a as stopCopilotTokenRefresh, i as setupGitHubToken, n as refreshCopilotToken, o as pollAccessToken, r as setupCopilotToken, s as getDeviceCode, t as clearGithubToken } from "./token-DUSd-gxE.js";
3
+ import { a as stopCopilotTokenRefresh, i as setupGitHubToken, n as refreshCopilotToken, o as pollAccessToken, r as setupCopilotToken, s as getDeviceCode, t as clearGithubToken } from "./token-BRQK8jBj.js";
4
4
  import { createRequire } from "node:module";
5
5
  import { defineCommand, runMain } from "citty";
6
6
  import consola from "consola";
@@ -121,8 +121,9 @@ async function applyProxyConfig() {
121
121
  //#endregion
122
122
  //#region src/lib/proxy.ts
123
123
  const agentOptions = {
124
- keepAliveTimeout: 6e4,
125
- keepAliveMaxTimeout: 3e5,
124
+ keepAliveTimeout: 3e5,
125
+ keepAliveMaxTimeout: 6e5,
126
+ allowH2: true,
126
127
  connect: {
127
128
  timeout: 15e3,
128
129
  keepAlive: true,
@@ -1713,19 +1714,22 @@ async function checkRateLimit(state) {
1713
1714
  const FETCH_TIMEOUT_MS = 12e4;
1714
1715
  /**
1715
1716
  * Retry delays in ms. After the first failure the connection pool is reset
1716
- * (see `resetConnections`), so a single retry with a fresh socket is usually
1717
- * enough. Keeping retries minimal avoids wasting Copilot request credits
1718
- * (billed per request).
1717
+ * (see `resetConnections`), so retries use fresh sockets. We allow up to
1718
+ * 2 retries because SSE streams through HTTP proxies are frequently
1719
+ * interrupted during long model thinking phases (~60 s idle timeout on
1720
+ * many proxy nodes), and each retry may also be cut short by the same
1721
+ * timeout. Keeping the delay short avoids wasting wall-clock time.
1719
1722
  */
1720
- const RETRY_DELAYS = [2e3];
1723
+ const RETRY_DELAYS = [2e3, 3e3];
1721
1724
  /**
1722
- * Shorter timeout for retry attempts. The first request uses the full
1723
- * FETCH_TIMEOUT_MS (120 s) to accommodate slow models. Retries happen
1724
- * after a connection-pool reset, so a fresh socket should connect quickly —
1725
- * if it doesn't respond within 20 s, the upstream is genuinely down and
1726
- * waiting longer just burns time (and possibly credits).
1725
+ * Timeout for retry attempts. The first request uses the full
1726
+ * FETCH_TIMEOUT_MS (120 s) to accommodate slow models. Retries also
1727
+ * need a generous timeout because the model restarts its thinking from
1728
+ * scratch 20 s was too short and caused immediate failures. 90 s
1729
+ * gives the model enough time to produce a response while still failing
1730
+ * faster than the initial attempt if the network is truly down.
1727
1731
  */
1728
- const RETRY_TIMEOUT_MS = 2e4;
1732
+ const RETRY_TIMEOUT_MS = 9e4;
1729
1733
  /**
1730
1734
  * Wrapper around `fetch()` that aborts if the server doesn't respond within
1731
1735
  * `timeoutMs`. The timeout only covers the period until the response headers
@@ -3094,14 +3098,19 @@ async function runServer(options) {
3094
3098
  if (state.apiKeys && state.apiKeys.length > 0) consola.info(`API key authentication enabled with ${state.apiKeys.length} key(s)`);
3095
3099
  await ensurePaths();
3096
3100
  await cacheVSCodeVersion();
3097
- await (options.githubToken ? validateGitHubToken(options.githubToken) : setupGitHubToken());
3101
+ try {
3102
+ await (options.githubToken ? validateGitHubToken(options.githubToken) : setupGitHubToken());
3103
+ } catch (error) {
3104
+ consola.error(`GitHub authentication failed: ${rootCause(error)}`);
3105
+ consola.info("The server will start, but requests may fail until connectivity is restored");
3106
+ }
3098
3107
  try {
3099
3108
  await setupCopilotToken();
3100
3109
  } catch (error) {
3101
3110
  const { HTTPError } = await import("./error-Cc8bY0ph.js");
3102
3111
  if (error instanceof HTTPError && error.response.status === 401) {
3103
3112
  consola.error("Failed to get Copilot token - GitHub token may be invalid or Copilot access revoked");
3104
- const { clearGithubToken } = await import("./token-B_m1icXz.js");
3113
+ const { clearGithubToken } = await import("./token-M99mSdhH.js");
3105
3114
  await clearGithubToken();
3106
3115
  consola.info("Please restart to re-authenticate");
3107
3116
  }