copilot-api-plus 1.2.42 → 1.2.44
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/dist/main.js +32 -4
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1861,6 +1861,16 @@ function isToolChoiceForced(toolChoice) {
|
|
|
1861
1861
|
* /models endpoint doesn't expose thinking budget fields.
|
|
1862
1862
|
*/
|
|
1863
1863
|
function injectThinking(payload, resolvedModel) {
|
|
1864
|
+
if (isToolChoiceForced(payload.tool_choice)) {
|
|
1865
|
+
if (payload.reasoning_effort || payload.thinking_budget) {
|
|
1866
|
+
const stripped = { ...payload };
|
|
1867
|
+
delete stripped.reasoning_effort;
|
|
1868
|
+
delete stripped.thinking_budget;
|
|
1869
|
+
consola.debug(`Thinking: stripped reasoning params for "${resolvedModel}" because tool_choice forces tool use`);
|
|
1870
|
+
return stripped;
|
|
1871
|
+
}
|
|
1872
|
+
return payload;
|
|
1873
|
+
}
|
|
1864
1874
|
if (payload.reasoning_effort || payload.thinking_budget) {
|
|
1865
1875
|
if (payload.reasoning_effort && payload.reasoning_effort !== "medium" && payload.reasoning_effort !== "low") {
|
|
1866
1876
|
const cap = reasoningEffortCap.get(resolvedModel);
|
|
@@ -1871,7 +1881,6 @@ function injectThinking(payload, resolvedModel) {
|
|
|
1871
1881
|
}
|
|
1872
1882
|
return payload;
|
|
1873
1883
|
}
|
|
1874
|
-
if (isToolChoiceForced(payload.tool_choice)) return payload;
|
|
1875
1884
|
const budget = getThinkingBudget(findModel(resolvedModel));
|
|
1876
1885
|
if (budget) return {
|
|
1877
1886
|
...payload,
|
|
@@ -2013,7 +2022,8 @@ async function createWithSingleAccount(payload) {
|
|
|
2013
2022
|
}
|
|
2014
2023
|
if (!response.ok) {
|
|
2015
2024
|
const errorBody = await response.text();
|
|
2016
|
-
if (response.status === 400) consola.
|
|
2025
|
+
if (response.status === 400) if (errorBody.includes("reasoning_effort") || errorBody.includes("invalid_reasoning_effort") || errorBody.includes("does not support reasoning")) consola.debug(`400 (auto-handled): ${errorBody}`);
|
|
2026
|
+
else consola.warn(`400: ${errorBody}`);
|
|
2017
2027
|
else consola.error("Failed to create chat completions", {
|
|
2018
2028
|
status: response.status,
|
|
2019
2029
|
statusText: response.statusText,
|
|
@@ -2061,6 +2071,15 @@ async function tryDowngradeReasoningEffort(errMsg, retryContext, accountId) {
|
|
|
2061
2071
|
}
|
|
2062
2072
|
}
|
|
2063
2073
|
/**
|
|
2074
|
+
* Whether a 400 error is caused by the request itself (model unavailable,
|
|
2075
|
+
* invalid params, etc.) rather than the account. These should NOT trigger
|
|
2076
|
+
* account disabling or rotation — rotating to another account would just
|
|
2077
|
+
* waste credits hitting the same error.
|
|
2078
|
+
*/
|
|
2079
|
+
function isNonAccountError(errMsg) {
|
|
2080
|
+
return errMsg.includes("model_not_supported") || errMsg.includes("The requested model is not supported") || errMsg.includes("invalid_request_body") || errMsg.includes("invalid_request_error") || errMsg.includes("invalid_reasoning_effort") || errMsg.includes("reasoning_effort") || errMsg.includes("tool_choice");
|
|
2081
|
+
}
|
|
2082
|
+
/**
|
|
2064
2083
|
* Handle an HTTP error from a multi-account request attempt.
|
|
2065
2084
|
*
|
|
2066
2085
|
* For 401 errors, attempts token refresh and retry.
|
|
@@ -2083,7 +2102,14 @@ async function handleMultiAccountHttpError(error, account, retryContext) {
|
|
|
2083
2102
|
accountManager.markAccountStatus(account.id, "error", `HTTP ${error.response.status}`);
|
|
2084
2103
|
return null;
|
|
2085
2104
|
}
|
|
2086
|
-
if (error.response.status === 400)
|
|
2105
|
+
if (error.response.status === 400) {
|
|
2106
|
+
const downgraded = await tryDowngradeReasoningEffort(error.message, retryContext, account.id);
|
|
2107
|
+
if (downgraded !== null) return downgraded;
|
|
2108
|
+
if (isNonAccountError(error.message)) {
|
|
2109
|
+
error.__nonAccountError = true;
|
|
2110
|
+
return null;
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2087
2113
|
accountManager.markAccountStatus(account.id, "error", `HTTP ${error.response.status}`);
|
|
2088
2114
|
return null;
|
|
2089
2115
|
}
|
|
@@ -2142,6 +2168,7 @@ async function createWithMultiAccount(payload) {
|
|
|
2142
2168
|
tokenSource
|
|
2143
2169
|
});
|
|
2144
2170
|
if (retryResult) return retryResult;
|
|
2171
|
+
if (error.__nonAccountError) throw error;
|
|
2145
2172
|
} else accountManager.markAccountStatus(account.id, "error", error.message);
|
|
2146
2173
|
consola.warn(`Account ${account.label} failed (attempt ${attempt + 1}), trying next...`);
|
|
2147
2174
|
}
|
|
@@ -2183,7 +2210,8 @@ async function doFetch(payload, source, accountId) {
|
|
|
2183
2210
|
});
|
|
2184
2211
|
if (!response.ok) {
|
|
2185
2212
|
const errorBody = await response.text();
|
|
2186
|
-
if (response.status === 400) consola.
|
|
2213
|
+
if (response.status === 400) if (errorBody.includes("reasoning_effort") || errorBody.includes("invalid_reasoning_effort") || errorBody.includes("does not support reasoning")) consola.debug(`400 (auto-handled): ${errorBody}`);
|
|
2214
|
+
else consola.warn(`400: ${errorBody}`);
|
|
2187
2215
|
else consola.error("Failed to create chat completions", {
|
|
2188
2216
|
status: response.status,
|
|
2189
2217
|
statusText: response.statusText,
|