copilot-api-plus 1.2.32 → 1.2.34

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 CHANGED
@@ -1890,30 +1890,42 @@ const createChatCompletions = async (payload) => {
1890
1890
  releaseSlot();
1891
1891
  return result;
1892
1892
  } catch (error) {
1893
- if (error instanceof HTTPError && error.response.status === 400) {
1894
- const errMsg = error.message;
1895
- if (wasInjected && (errMsg.includes("Unrecognized request argument") || errMsg.includes("does not support reasoning") || errMsg.includes("invalid_reasoning_effort"))) {
1896
- reasoningUnsupportedModels.add(resolvedModel);
1897
- consola.debug(`Model "${resolvedModel}" does not support reasoning_effort — disabled for future requests`);
1898
- return retryWithModifiedPayload(routedPayload, releaseSlot);
1899
- }
1900
- if (errMsg.includes("is not supported by model")) {
1901
- const currentEffort = thinkingPayload.reasoning_effort;
1902
- if (currentEffort && currentEffort !== "medium" && currentEffort !== "low") {
1903
- reasoningEffortCap.set(resolvedModel, "medium");
1904
- consola.debug(`Model "${resolvedModel}" rejected reasoning_effort="${currentEffort}" — downgrading to "medium" for future requests`);
1905
- return retryWithModifiedPayload({
1906
- ...routedPayload,
1907
- reasoning_effort: "medium"
1908
- }, releaseSlot);
1909
- }
1910
- }
1911
- }
1893
+ const retryResult = handle400ReasoningError(error, {
1894
+ resolvedModel,
1895
+ thinkingPayload,
1896
+ routedPayload,
1897
+ wasInjected
1898
+ }, releaseSlot);
1899
+ if (retryResult !== void 0) return retryResult;
1912
1900
  releaseSlot();
1913
1901
  throw error;
1914
1902
  }
1915
1903
  };
1916
1904
  /**
1905
+ * Handle 400 reasoning_effort errors in the outer createChatCompletions catch.
1906
+ * Returns a Promise (retry result) if handled, or undefined to re-throw.
1907
+ */
1908
+ function handle400ReasoningError(error, ctx, releaseSlot) {
1909
+ if (!(error instanceof HTTPError) || error.response.status !== 400) return void 0;
1910
+ const errMsg = error.message;
1911
+ if (errMsg.includes("supported values") || errMsg.includes("is not supported by model") && errMsg.includes("reasoning_effort")) {
1912
+ const currentEffort = ctx.thinkingPayload.reasoning_effort;
1913
+ if (currentEffort && currentEffort !== "medium" && currentEffort !== "low") {
1914
+ reasoningEffortCap.set(ctx.resolvedModel, "medium");
1915
+ consola.debug(`Model "${ctx.resolvedModel}" rejected reasoning_effort="${currentEffort}" — downgrading to "medium"`);
1916
+ return retryWithModifiedPayload({
1917
+ ...ctx.routedPayload,
1918
+ reasoning_effort: "medium"
1919
+ }, releaseSlot);
1920
+ }
1921
+ }
1922
+ if (ctx.wasInjected && (errMsg.includes("Unrecognized request argument") || errMsg.includes("does not support reasoning") || errMsg.includes("invalid_reasoning_effort"))) {
1923
+ reasoningUnsupportedModels.add(ctx.resolvedModel);
1924
+ consola.debug(`Model "${ctx.resolvedModel}" does not support reasoning_effort — disabled for future requests`);
1925
+ return retryWithModifiedPayload(ctx.routedPayload, releaseSlot);
1926
+ }
1927
+ }
1928
+ /**
1917
1929
  * Retry a request after modifying the payload (e.g. stripping or
1918
1930
  * downgrading reasoning_effort).
1919
1931
  * Handles slot release for both streaming and non-streaming responses.
@@ -2010,6 +2022,22 @@ async function tryRefreshAndRetry(account, payload, tokenSource) {
2010
2022
  return null;
2011
2023
  }
2012
2024
  }
2025
+ /** Try to retry a 400 with downgraded reasoning_effort on the same account. */
2026
+ async function tryDowngradeReasoningEffort(errMsg, retryContext, accountId) {
2027
+ if (!(errMsg.includes("supported values") || errMsg.includes("is not supported by model") && errMsg.includes("reasoning_effort"))) return null;
2028
+ const currentEffort = retryContext.payload.reasoning_effort;
2029
+ if (!currentEffort || currentEffort === "medium" || currentEffort === "low") return null;
2030
+ reasoningEffortCap.set(retryContext.payload.model, "medium");
2031
+ const downgraded = {
2032
+ ...retryContext.payload,
2033
+ reasoning_effort: "medium"
2034
+ };
2035
+ try {
2036
+ return await doFetch(downgraded, retryContext.tokenSource, accountId);
2037
+ } catch {
2038
+ return null;
2039
+ }
2040
+ }
2013
2041
  /**
2014
2042
  * Handle an HTTP error from a multi-account request attempt.
2015
2043
  *
@@ -2033,6 +2061,7 @@ async function handleMultiAccountHttpError(error, account, retryContext) {
2033
2061
  accountManager.markAccountStatus(account.id, "error", `HTTP ${error.response.status}`);
2034
2062
  return null;
2035
2063
  }
2064
+ if (error.response.status === 400) return tryDowngradeReasoningEffort(error.message, retryContext, account.id);
2036
2065
  accountManager.markAccountStatus(account.id, "error", `HTTP ${error.response.status}`);
2037
2066
  return null;
2038
2067
  }