copilot-api-plus 1.2.8 → 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 +7 -4
- package/README.md +7 -4
- package/dist/main.js +29 -16
- package/dist/main.js.map +1 -1
- package/dist/{token-DUSd-gxE.js → token-BRQK8jBj.js} +19 -1
- package/dist/token-BRQK8jBj.js.map +1 -0
- package/dist/{token-B_m1icXz.js → token-M99mSdhH.js} +1 -1
- package/package.json +1 -1
- package/dist/token-DUSd-gxE.js.map +0 -1
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 +
|
|
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 |
|
|
@@ -580,10 +580,13 @@ Each API request outputs a log line with model name, status code, and duration:
|
|
|
580
580
|
|
|
581
581
|
### Network Resilience
|
|
582
582
|
|
|
583
|
-
Built-in connection timeout and
|
|
583
|
+
Built-in connection timeout and smart retry for upstream API requests, minimizing Copilot request credit consumption:
|
|
584
584
|
|
|
585
|
-
- **Connection timeout**: 120 seconds (
|
|
586
|
-
- **Retry strategy**: Up to
|
|
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
|
+
- **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
|
|
587
590
|
- Only retries network-layer errors (timeout, TLS disconnect, connection reset, etc.); HTTP error codes (e.g. 400/500) are not retried
|
|
588
591
|
- SSE stream interruptions gracefully send error events to the client
|
|
589
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),提升代码质量 |
|
|
@@ -743,10 +743,13 @@ Anthropic 格式的模型名(如 `claude-opus-4-6`)和 Copilot 的模型列
|
|
|
743
743
|
|
|
744
744
|
### 网络弹性
|
|
745
745
|
|
|
746
|
-
对上游 API
|
|
746
|
+
对上游 API 的请求内置了连接超时和智能重试,以最小化 Copilot 请求次数消耗:
|
|
747
747
|
|
|
748
|
-
-
|
|
749
|
-
- **重试策略**:最多重试
|
|
748
|
+
- **连接超时**:首次请求 120 秒,重试请求 90 秒(给模型足够的思考时间)
|
|
749
|
+
- **重试策略**:最多重试 2 次(共 3 次尝试),间隔 2-3 秒
|
|
750
|
+
- **连接池重置**:首次网络错误后自动销毁所有连接并创建新实例,避免后续请求复用坏连接
|
|
751
|
+
- **HTTP/2 保活**:启用 HTTP/2 协议,PING 帧穿透代理隧道防止空闲断连
|
|
752
|
+
- **TCP 保活**:每 15 秒发送 TCP 探测包,防止代理/防火墙因空闲而断开连接
|
|
750
753
|
- 仅重试网络层错误(超时、TLS 断开、连接重置等),HTTP 错误码(如 400/500)不重试
|
|
751
754
|
- SSE 流传输中断时,优雅地向客户端发送错误事件
|
|
752
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-
|
|
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,9 +121,14 @@ async function applyProxyConfig() {
|
|
|
121
121
|
//#endregion
|
|
122
122
|
//#region src/lib/proxy.ts
|
|
123
123
|
const agentOptions = {
|
|
124
|
-
keepAliveTimeout:
|
|
125
|
-
keepAliveMaxTimeout:
|
|
126
|
-
|
|
124
|
+
keepAliveTimeout: 3e5,
|
|
125
|
+
keepAliveMaxTimeout: 6e5,
|
|
126
|
+
allowH2: true,
|
|
127
|
+
connect: {
|
|
128
|
+
timeout: 15e3,
|
|
129
|
+
keepAlive: true,
|
|
130
|
+
keepAliveInitialDelay: 15e3
|
|
131
|
+
}
|
|
127
132
|
};
|
|
128
133
|
let direct;
|
|
129
134
|
let proxies = /* @__PURE__ */ new Map();
|
|
@@ -1709,19 +1714,22 @@ async function checkRateLimit(state) {
|
|
|
1709
1714
|
const FETCH_TIMEOUT_MS = 12e4;
|
|
1710
1715
|
/**
|
|
1711
1716
|
* Retry delays in ms. After the first failure the connection pool is reset
|
|
1712
|
-
* (see `resetConnections`), so
|
|
1713
|
-
*
|
|
1714
|
-
* (
|
|
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.
|
|
1715
1722
|
*/
|
|
1716
|
-
const RETRY_DELAYS = [2e3];
|
|
1723
|
+
const RETRY_DELAYS = [2e3, 3e3];
|
|
1717
1724
|
/**
|
|
1718
|
-
*
|
|
1719
|
-
* FETCH_TIMEOUT_MS (120 s) to accommodate slow models. Retries
|
|
1720
|
-
*
|
|
1721
|
-
*
|
|
1722
|
-
*
|
|
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.
|
|
1723
1731
|
*/
|
|
1724
|
-
const RETRY_TIMEOUT_MS =
|
|
1732
|
+
const RETRY_TIMEOUT_MS = 9e4;
|
|
1725
1733
|
/**
|
|
1726
1734
|
* Wrapper around `fetch()` that aborts if the server doesn't respond within
|
|
1727
1735
|
* `timeoutMs`. The timeout only covers the period until the response headers
|
|
@@ -3090,14 +3098,19 @@ async function runServer(options) {
|
|
|
3090
3098
|
if (state.apiKeys && state.apiKeys.length > 0) consola.info(`API key authentication enabled with ${state.apiKeys.length} key(s)`);
|
|
3091
3099
|
await ensurePaths();
|
|
3092
3100
|
await cacheVSCodeVersion();
|
|
3093
|
-
|
|
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
|
+
}
|
|
3094
3107
|
try {
|
|
3095
3108
|
await setupCopilotToken();
|
|
3096
3109
|
} catch (error) {
|
|
3097
3110
|
const { HTTPError } = await import("./error-Cc8bY0ph.js");
|
|
3098
3111
|
if (error instanceof HTTPError && error.response.status === 401) {
|
|
3099
3112
|
consola.error("Failed to get Copilot token - GitHub token may be invalid or Copilot access revoked");
|
|
3100
|
-
const { clearGithubToken } = await import("./token-
|
|
3113
|
+
const { clearGithubToken } = await import("./token-M99mSdhH.js");
|
|
3101
3114
|
await clearGithubToken();
|
|
3102
3115
|
consola.info("Please restart to re-authenticate");
|
|
3103
3116
|
}
|