opencode-pollinations-plugin 5.2.2 → 5.2.4
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/server/proxy.js +24 -9
- package/package.json +1 -1
package/dist/server/proxy.js
CHANGED
|
@@ -249,12 +249,20 @@ export async function handleChatCompletion(req, res, bodyRaw) {
|
|
|
249
249
|
isFallbackActive = true;
|
|
250
250
|
fallbackReason = "Quota Unreachable (Safety)";
|
|
251
251
|
}
|
|
252
|
-
else
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
252
|
+
else {
|
|
253
|
+
const tierRatio = quota.tierLimit > 0 ? (quota.tierRemaining / quota.tierLimit) : 0;
|
|
254
|
+
// Logic: Fallback if Wallet is Low (< Threshold) AND Tier is Exhausted (< Threshold %)
|
|
255
|
+
// Wait, user wants priority to Free Tier.
|
|
256
|
+
// If Free Tier is available (Ratio > Threshold), we usage it (don't fallback).
|
|
257
|
+
// If Free Tier is exhausted (Ratio <= Threshold), THEN check Wallet.
|
|
258
|
+
// If Wallet also Low, THEN Fallback.
|
|
259
|
+
if (quota.walletBalance < config.thresholds.wallet && tierRatio <= (config.thresholds.tier / 100)) {
|
|
260
|
+
log(`[SafetyNet] Pro Mode: Wallet < $${config.thresholds.wallet} AND Tier < ${config.thresholds.tier}%. Switching.`);
|
|
261
|
+
actualModel = config.fallbacks.free.main.replace('free/', '');
|
|
262
|
+
isEnterprise = false;
|
|
263
|
+
isFallbackActive = true;
|
|
264
|
+
fallbackReason = `Wallet & Tier Critical`;
|
|
265
|
+
}
|
|
258
266
|
}
|
|
259
267
|
}
|
|
260
268
|
}
|
|
@@ -446,14 +454,21 @@ export async function handleChatCompletion(req, res, bodyRaw) {
|
|
|
446
454
|
});
|
|
447
455
|
if (!fetchRes.ok) {
|
|
448
456
|
log(`Upstream Error: ${fetchRes.status} ${fetchRes.statusText}`);
|
|
449
|
-
// TRANSPARENT FALLBACK ON
|
|
450
|
-
if ((fetchRes.status === 402 || fetchRes.status === 429) && isEnterprise) {
|
|
457
|
+
// TRANSPARENT FALLBACK ON 4xx Errors (Payment, Rate Limit, Auth) IF Enterprise
|
|
458
|
+
if ((fetchRes.status === 402 || fetchRes.status === 429 || fetchRes.status === 401 || fetchRes.status === 403) && isEnterprise) {
|
|
451
459
|
log(`[SafetyNet] Upstream Rejection (${fetchRes.status}). Triggering Transparent Fallback.`);
|
|
452
460
|
// 1. Switch Config
|
|
453
461
|
actualModel = config.fallbacks.free.main.replace('free/', '');
|
|
454
462
|
isEnterprise = false;
|
|
455
463
|
isFallbackActive = true;
|
|
456
|
-
|
|
464
|
+
if (fetchRes.status === 402)
|
|
465
|
+
fallbackReason = "Insufficient Funds (Upstream 402)";
|
|
466
|
+
else if (fetchRes.status === 429)
|
|
467
|
+
fallbackReason = "Rate Limit (Upstream 429)";
|
|
468
|
+
else if (fetchRes.status === 401)
|
|
469
|
+
fallbackReason = "Invalid API Key (Upstream 401)";
|
|
470
|
+
else
|
|
471
|
+
fallbackReason = `Access Denied (${fetchRes.status})`;
|
|
457
472
|
// 2. Notify
|
|
458
473
|
emitStatusToast('warning', `⚠️ Safety Net: ${actualModel} (${fallbackReason})`, 'Pollinations Safety');
|
|
459
474
|
emitLogToast('warning', `Recovering from ${fetchRes.status} -> Switching to ${actualModel}`, 'Safety Net');
|
package/package.json
CHANGED