opencode-pollinations-plugin 5.5.2 → 5.5.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.
@@ -5,37 +5,34 @@ import { getDetailedUsage } from './pollinations-api.js';
5
5
  import { generatePollinationsConfig } from './generate-config.js';
6
6
  import * as https from 'https';
7
7
  // --- HELPER: STRICT PERMISSION CHECK ---
8
- function checkKeyPermissions(key) {
8
+ function checkEndpoint(ep, key) {
9
9
  return new Promise((resolve) => {
10
- // We need Usage, Profile AND Balance for "Managed Modes"
11
- // If any of these fail (403), the key is Limited.
12
- const endpoints = ['/account/profile', '/account/balance', '/account/usage'];
13
- let successCount = 0;
14
- let completed = 0;
15
- endpoints.forEach(ep => {
16
- const req = https.request({
17
- hostname: 'gen.pollinations.ai',
18
- path: ep,
19
- method: 'GET',
20
- headers: { 'Authorization': `Bearer ${key}` }
21
- }, (res) => {
22
- completed++;
23
- if (res.statusCode === 200)
24
- successCount++;
25
- if (completed === endpoints.length) {
26
- resolve(successCount === endpoints.length);
27
- }
28
- });
29
- req.on('error', () => {
30
- completed++;
31
- if (completed === endpoints.length)
32
- resolve(successCount === endpoints.length);
33
- });
34
- req.setTimeout(5000, () => req.destroy());
35
- req.end();
10
+ const req = https.request({
11
+ hostname: 'gen.pollinations.ai',
12
+ path: ep,
13
+ method: 'GET',
14
+ headers: { 'Authorization': `Bearer ${key}` }
15
+ }, (res) => {
16
+ if (res.statusCode === 200)
17
+ resolve(true);
18
+ else
19
+ resolve(false);
36
20
  });
21
+ req.on('error', () => resolve(false));
22
+ req.setTimeout(5000, () => req.destroy());
23
+ req.end();
37
24
  });
38
25
  }
26
+ async function checkKeyPermissions(key) {
27
+ // SEQUENTIAL CHECK (Avoid Rate Limits on Key Verification)
28
+ const endpoints = ['/account/profile', '/account/balance', '/account/usage'];
29
+ for (const ep of endpoints) {
30
+ const ok = await checkEndpoint(ep, key);
31
+ if (!ok)
32
+ return false; // Fail fast
33
+ }
34
+ return true;
35
+ }
39
36
  // === CONSTANTS & PRICING ===
40
37
  const TIER_LIMITS = {
41
38
  spore: { pollen: 1, emoji: '🦠' },
@@ -211,6 +211,21 @@ export async function handleChatCompletion(req, res, bodyRaw) {
211
211
  // LOAD QUOTA FOR SAFETY CHECKS
212
212
  const { getQuotaStatus, formatQuotaForToast } = await import('./quota.js');
213
213
  const quota = await getQuotaStatus(false);
214
+ // RUNTIME RESTRICTION ENFORCEMENT (V5.5.3)
215
+ // If we are in a Managed Mode (Pro/AlwaysFree) BUT the Quota returns 'error'
216
+ // (meaning Profile/Usage access failed or network issue), we MUST downgrade to Manual
217
+ // to avoid "Quota Unreachable" Fallbacks. The user wants to force Manual.
218
+ if ((config.mode === 'alwaysfree' || config.mode === 'pro') && quota.tier === 'error') {
219
+ log(`[SafetyNet] Runtime: Quota Access Lost (Tier=error). Forcing MANUAL Mode.`);
220
+ // 1. Update In-Memory Config (stops downstream fallbacks)
221
+ config.mode = 'manual';
222
+ config.keyHasAccessToProfile = false;
223
+ // 2. Persist
224
+ const { saveConfig } = await import('./config.js');
225
+ saveConfig({ mode: 'manual', keyHasAccessToProfile: false });
226
+ // 3. Notify
227
+ emitStatusToast('warning', "⚠️ Accès Quota Perdu -> Mode MANUAL forcé", "System");
228
+ }
214
229
  // A. Resolve Base Target
215
230
  if (actualModel.startsWith('enter/')) {
216
231
  isEnterprise = true;
@@ -63,12 +63,11 @@ export async function getQuotaStatus(forceRefresh = false) {
63
63
  }
64
64
  try {
65
65
  logQuota("Fetching Quota Data...");
66
- // Fetch parallèle using HTTPS helper
67
- const [profileRes, balanceRes, usageRes] = await Promise.all([
68
- fetchAPI('/account/profile', config.apiKey),
69
- fetchAPI('/account/balance', config.apiKey),
70
- fetchAPI('/account/usage', config.apiKey)
71
- ]);
66
+ // SEQUENTIAL FETCH (Avoid Rate Limits)
67
+ // We fetch one by one. If one fails, we catch and return fallback.
68
+ const profileRes = await fetchAPI('/account/profile', config.apiKey);
69
+ const balanceRes = await fetchAPI('/account/balance', config.apiKey);
70
+ const usageRes = await fetchAPI('/account/usage', config.apiKey);
72
71
  logQuota(`Fetch Success. Tier: ${profileRes.tier}, Balance: ${balanceRes.balance}`);
73
72
  const profile = profileRes;
74
73
  const balance = balanceRes.balance;
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.5.2",
4
+ "version": "5.5.4",
5
5
  "description": "Native Pollinations.ai Provider Plugin for OpenCode",
6
6
  "publisher": "pollinations",
7
7
  "repository": {