copilot-api-plus 1.0.42 → 1.0.43

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
@@ -2957,11 +2957,27 @@ const createChatCompletions = async (payload) => {
2957
2957
  model: payload.model,
2958
2958
  endpoint: `${copilotBaseUrl(state)}/chat/completions`
2959
2959
  });
2960
- const response = await fetch(`${copilotBaseUrl(state)}/chat/completions`, {
2960
+ const url = `${copilotBaseUrl(state)}/chat/completions`;
2961
+ const fetchOptions = {
2961
2962
  method: "POST",
2962
2963
  headers,
2963
2964
  body: JSON.stringify(payload)
2964
- });
2965
+ };
2966
+ const maxRetries = 2;
2967
+ let lastError;
2968
+ let response;
2969
+ for (let attempt = 0; attempt <= maxRetries; attempt++) try {
2970
+ response = await fetch(url, fetchOptions);
2971
+ break;
2972
+ } catch (error) {
2973
+ lastError = error;
2974
+ if (attempt < maxRetries) {
2975
+ const delay = 1e3 * (attempt + 1);
2976
+ consola.warn(`Network error on attempt ${attempt + 1}/${maxRetries + 1}, retrying in ${delay}ms:`, error instanceof Error ? error.message : error);
2977
+ await new Promise((r) => setTimeout(r, delay));
2978
+ }
2979
+ }
2980
+ if (!response) throw lastError;
2965
2981
  if (!response.ok) {
2966
2982
  const errorBody = await response.text();
2967
2983
  consola.error("Failed to create chat completions", {