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.
@@ -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 if (quota.walletBalance < config.thresholds.wallet && quota.tierRemaining <= 0.1) { // Tier is loose here, wallet is primary
253
- log(`[SafetyNet] Pro Mode: Wallet Critical (<$${config.thresholds.wallet}). Switching to Free Fallback.`);
254
- actualModel = config.fallbacks.free.main.replace('free/', '');
255
- isEnterprise = false;
256
- isFallbackActive = true;
257
- fallbackReason = `Wallet < $${config.thresholds.wallet}`;
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 402 (Payment) or 429 (Rate Limit) IF Enterprise
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
- fallbackReason = fetchRes.status === 402 ? "Insufficient Funds (Upstream 402)" : "Rate Limit (Upstream 429)";
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opencode-pollinations-plugin",
3
3
  "displayName": "Pollinations AI (V5.1)",
4
- "version": "5.2.2",
4
+ "version": "5.2.4",
5
5
  "description": "Native Pollinations.ai Provider Plugin for OpenCode",
6
6
  "publisher": "pollinations",
7
7
  "repository": {