opencode-pollinations-plugin 5.2.1 → 5.2.3
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 +19 -9
- package/package.json +1 -1
package/dist/server/proxy.js
CHANGED
|
@@ -228,12 +228,15 @@ export async function handleChatCompletion(req, res, bodyRaw) {
|
|
|
228
228
|
isFallbackActive = true;
|
|
229
229
|
fallbackReason = "Quota Unreachable (Safety)";
|
|
230
230
|
}
|
|
231
|
-
else
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
231
|
+
else {
|
|
232
|
+
const tierRatio = quota.tierLimit > 0 ? (quota.tierRemaining / quota.tierLimit) : 0;
|
|
233
|
+
if (tierRatio <= (config.thresholds.tier / 100)) {
|
|
234
|
+
log(`[SafetyNet] AlwaysFree Mode: Tier (${(tierRatio * 100).toFixed(1)}%) <= Threshold (${config.thresholds.tier}%). Switching.`);
|
|
235
|
+
actualModel = config.fallbacks.free.main.replace('free/', '');
|
|
236
|
+
isEnterprise = false;
|
|
237
|
+
isFallbackActive = true;
|
|
238
|
+
fallbackReason = `Daily Tier < ${config.thresholds.tier}% (Wallet Protected)`;
|
|
239
|
+
}
|
|
237
240
|
}
|
|
238
241
|
}
|
|
239
242
|
}
|
|
@@ -443,14 +446,21 @@ export async function handleChatCompletion(req, res, bodyRaw) {
|
|
|
443
446
|
});
|
|
444
447
|
if (!fetchRes.ok) {
|
|
445
448
|
log(`Upstream Error: ${fetchRes.status} ${fetchRes.statusText}`);
|
|
446
|
-
// TRANSPARENT FALLBACK ON
|
|
447
|
-
if ((fetchRes.status === 402 || fetchRes.status === 429) && isEnterprise) {
|
|
449
|
+
// TRANSPARENT FALLBACK ON 4xx Errors (Payment, Rate Limit, Auth) IF Enterprise
|
|
450
|
+
if ((fetchRes.status === 402 || fetchRes.status === 429 || fetchRes.status === 401 || fetchRes.status === 403) && isEnterprise) {
|
|
448
451
|
log(`[SafetyNet] Upstream Rejection (${fetchRes.status}). Triggering Transparent Fallback.`);
|
|
449
452
|
// 1. Switch Config
|
|
450
453
|
actualModel = config.fallbacks.free.main.replace('free/', '');
|
|
451
454
|
isEnterprise = false;
|
|
452
455
|
isFallbackActive = true;
|
|
453
|
-
|
|
456
|
+
if (fetchRes.status === 402)
|
|
457
|
+
fallbackReason = "Insufficient Funds (Upstream 402)";
|
|
458
|
+
else if (fetchRes.status === 429)
|
|
459
|
+
fallbackReason = "Rate Limit (Upstream 429)";
|
|
460
|
+
else if (fetchRes.status === 401)
|
|
461
|
+
fallbackReason = "Invalid API Key (Upstream 401)";
|
|
462
|
+
else
|
|
463
|
+
fallbackReason = `Access Denied (${fetchRes.status})`;
|
|
454
464
|
// 2. Notify
|
|
455
465
|
emitStatusToast('warning', `⚠️ Safety Net: ${actualModel} (${fallbackReason})`, 'Pollinations Safety');
|
|
456
466
|
emitLogToast('warning', `Recovering from ${fetchRes.status} -> Switching to ${actualModel}`, 'Safety Net');
|
package/package.json
CHANGED