merge: sync with upstream/main (5xx error fallback feature)

This commit is contained in:
Wha1eChai
2026-01-11 02:57:59 +08:00
2 changed files with 21 additions and 0 deletions

View File

@@ -218,5 +218,15 @@ export async function sendMessage(anthropicRequest, accountManager, fallbackEnab
}
}
// All retries exhausted - try fallback model if enabled
if (fallbackEnabled) {
const fallbackModel = getFallbackModel(model);
if (fallbackModel) {
logger.warn(`[CloudCode] All retries exhausted for ${model}. Attempting fallback to ${fallbackModel}`);
const fallbackRequest = { ...anthropicRequest, model: fallbackModel };
return await sendMessage(fallbackRequest, accountManager, false); // Disable fallback for recursive call
}
}
throw new Error('Max retries exceeded');
}

View File

@@ -285,6 +285,17 @@ export async function* sendMessageStream(anthropicRequest, accountManager, fallb
}
}
// All retries exhausted - try fallback model if enabled
if (fallbackEnabled) {
const fallbackModel = getFallbackModel(model);
if (fallbackModel) {
logger.warn(`[CloudCode] All retries exhausted for ${model}. Attempting fallback to ${fallbackModel} (streaming)`);
const fallbackRequest = { ...anthropicRequest, model: fallbackModel };
yield* sendMessageStream(fallbackRequest, accountManager, false); // Disable fallback for recursive call
return;
}
}
throw new Error('Max retries exceeded');
}