copilot-api-plus 1.2.15 → 1.2.16
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 +3 -3
- package/README.md +3 -3
- package/dist/main.js +13 -6
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -49,7 +49,7 @@ English | [简体中文](README.md)
|
|
|
49
49
|
| 🛡️ **Network Resilience** | 120s timeout + smart retry + instant stream recovery + proxy tunnel keepalive (45s heartbeat) |
|
|
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
|
-
| 🧠 **Thinking Chain** | Automatically enables deep thinking
|
|
52
|
+
| 🧠 **Thinking Chain** | Automatically enables deep thinking for supported models, improving code quality |
|
|
53
53
|
|
|
54
54
|
---
|
|
55
55
|
|
|
@@ -583,12 +583,12 @@ Each API request outputs a log line with model name, status code, and duration:
|
|
|
583
583
|
Built-in connection timeout and smart retry for upstream API requests, minimizing Copilot request credit consumption:
|
|
584
584
|
|
|
585
585
|
- **Connection timeout**: 120 seconds for the first attempt, 30 seconds for retries (headers typically arrive in 3–5s)
|
|
586
|
-
- **Retry strategy**: Up to
|
|
586
|
+
- **Retry strategy**: Up to 1 retry (2 total attempts), 2-second delay. **Timeout errors are never retried** — a timeout means the request likely reached Copilot and a credit was already consumed
|
|
587
587
|
- **Instant stream recovery**: On SSE stream interruption, immediately destroys the connection pool so the next request uses fresh sockets — recovery drops from ~135s to seconds
|
|
588
588
|
- **Connection pool reset**: Automatically destroys all pooled connections on the first network error and creates fresh instances, preventing retries from hitting stale sockets
|
|
589
589
|
- **Proxy tunnel keepalive**: Sends lightweight heartbeat requests every 45s while SSE streams are active, preventing proxy nodes from killing CONNECT tunnels due to inactivity
|
|
590
590
|
- **HTTP/2 support**: Enables HTTP/2 protocol for better multiplexing performance
|
|
591
|
-
- Only retries network-layer errors (
|
|
591
|
+
- Only retries network-layer connection errors (TLS disconnect, connection reset, etc.); timeout and HTTP error codes (e.g. 400/500) are not retried
|
|
592
592
|
- SSE stream interruptions gracefully send error events to the client
|
|
593
593
|
|
|
594
594
|
---
|
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
| 🛡️ **网络弹性** | 120s 连接超时 + 智能重试 + 流中断即时恢复 + 代理隧道保活(45s 心跳) |
|
|
51
51
|
| ✂️ **上下文透传** | 全量透传上下文至上游 API,由客户端(如 Claude Code)自行管理压缩 |
|
|
52
52
|
| 🔍 **智能模型匹配** | 自动处理模型名格式差异(日期后缀、dash/dot 版本号等) |
|
|
53
|
-
| 🧠 **Thinking 思维链** |
|
|
53
|
+
| 🧠 **Thinking 思维链** | 自动为支持的模型启用深度思考,提升代码质量 |
|
|
54
54
|
|
|
55
55
|
---
|
|
56
56
|
|
|
@@ -746,12 +746,12 @@ Anthropic 格式的模型名(如 `claude-opus-4-6`)和 Copilot 的模型列
|
|
|
746
746
|
对上游 API 的请求内置了连接超时和智能重试,以最小化 Copilot 请求次数消耗:
|
|
747
747
|
|
|
748
748
|
- **连接超时**:首次请求 120 秒,重试请求 30 秒(响应头通常 3~5 秒到达)
|
|
749
|
-
- **重试策略**:最多重试
|
|
749
|
+
- **重试策略**:最多重试 1 次(共 2 次尝试),间隔 2 秒,**超时错误不重试**(超时意味着请求已到达 Copilot,额度已消耗)
|
|
750
750
|
- **流中断即时恢复**:SSE 流中断时立刻销毁连接池,下一个请求使用全新连接,恢复时间从 ~135 秒降至几秒
|
|
751
751
|
- **连接池重置**:首次网络错误后自动销毁所有连接并创建新实例,避免后续请求复用坏连接
|
|
752
752
|
- **代理隧道保活**:SSE 流传输期间每 45 秒发送一次轻量心跳请求,防止代理节点因空闲而杀断 CONNECT 隧道
|
|
753
753
|
- **HTTP/2 支持**:启用 HTTP/2 协议,提升多路复用性能
|
|
754
|
-
-
|
|
754
|
+
- 仅重试网络层连接错误(TLS 断开、连接重置等),超时和 HTTP 错误码(如 400/500)不重试
|
|
755
755
|
- SSE 流传输中断时,优雅地向客户端发送错误事件
|
|
756
756
|
|
|
757
757
|
---
|
package/dist/main.js
CHANGED
|
@@ -1768,12 +1768,14 @@ async function checkRateLimit(state) {
|
|
|
1768
1768
|
const FETCH_TIMEOUT_MS = 12e4;
|
|
1769
1769
|
/**
|
|
1770
1770
|
* Retry delays in ms. After the first failure the connection pool is reset
|
|
1771
|
-
* (see `resetConnections`), so retries use fresh sockets.
|
|
1772
|
-
*
|
|
1773
|
-
*
|
|
1774
|
-
*
|
|
1771
|
+
* (see `resetConnections`), so retries use fresh sockets.
|
|
1772
|
+
*
|
|
1773
|
+
* We only allow 1 retry (2 total attempts) to minimize credit waste.
|
|
1774
|
+
* Timeout errors are NOT retried at all — they indicate the request likely
|
|
1775
|
+
* reached Copilot (consuming a credit) and the upstream is slow or the
|
|
1776
|
+
* proxy killed the connection mid-flight.
|
|
1775
1777
|
*/
|
|
1776
|
-
const RETRY_DELAYS = [2e3
|
|
1778
|
+
const RETRY_DELAYS = [2e3];
|
|
1777
1779
|
/**
|
|
1778
1780
|
* Timeout for retry attempts (waiting for response headers only).
|
|
1779
1781
|
* Response headers typically arrive within 3–5 s, even on slow models.
|
|
@@ -1820,6 +1822,11 @@ async function fetchWithRetry(url, buildInit) {
|
|
|
1820
1822
|
return await fetchWithTimeout(url, buildInit(), timeout);
|
|
1821
1823
|
} catch (error) {
|
|
1822
1824
|
lastError = error;
|
|
1825
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
1826
|
+
if (msg.includes("timed out")) {
|
|
1827
|
+
consola.warn(`Request timed out on attempt ${attempt + 1}/${maxAttempts} — not retrying (credit likely consumed):`, msg);
|
|
1828
|
+
break;
|
|
1829
|
+
}
|
|
1823
1830
|
if (attempt === 0) resetConnections();
|
|
1824
1831
|
if (attempt < maxAttempts - 1) {
|
|
1825
1832
|
const delay = RETRY_DELAYS[attempt];
|
|
@@ -1905,7 +1912,7 @@ function injectThinking(payload, resolvedModel) {
|
|
|
1905
1912
|
return payload;
|
|
1906
1913
|
}
|
|
1907
1914
|
function logThinkingInjection(original, injected, resolvedModel) {
|
|
1908
|
-
if (original.reasoning_effort || original.thinking_budget) consola.debug(`Thinking:
|
|
1915
|
+
if (original.reasoning_effort || original.thinking_budget) consola.debug(`Thinking: translated (reasoning_effort=${original.reasoning_effort ?? "none"} / thinking_budget=${original.thinking_budget ?? "none"})`);
|
|
1909
1916
|
else if (injected.thinking_budget && injected.thinking_budget !== original.thinking_budget) consola.debug(`Thinking: injected thinking_budget=${injected.thinking_budget} for "${resolvedModel}"`);
|
|
1910
1917
|
else if (injected.reasoning_effort === "high") consola.debug(`Thinking: injected reasoning_effort=high for "${resolvedModel}"`);
|
|
1911
1918
|
else if (reasoningUnsupportedModels.has(resolvedModel)) consola.debug(`Thinking: skipped — "${resolvedModel}" does not support reasoning`);
|