opencode-pollinations-plugin 5.5.3 → 5.5.5

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.
@@ -4,38 +4,35 @@ import { emitStatusToast } from './toast.js';
4
4
  import { getDetailedUsage } from './pollinations-api.js';
5
5
  import { generatePollinationsConfig } from './generate-config.js';
6
6
  import * as https from 'https';
7
- // --- HELPER: STRICT PERMISSION CHECK ---
8
- function checkKeyPermissions(key) {
7
+ function checkEndpoint(ep, key) {
9
8
  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();
9
+ const req = https.request({
10
+ hostname: 'gen.pollinations.ai',
11
+ path: ep,
12
+ method: 'GET',
13
+ headers: { 'Authorization': `Bearer ${key}` }
14
+ }, (res) => {
15
+ if (res.statusCode === 200)
16
+ resolve({ ok: true });
17
+ else
18
+ resolve({ ok: false, status: res.statusCode });
36
19
  });
20
+ req.on('error', (e) => resolve({ ok: false, status: e.message || 'Error' }));
21
+ req.setTimeout(10000, () => req.destroy()); // 10s Timeout
22
+ req.end();
37
23
  });
38
24
  }
25
+ async function checkKeyPermissions(key) {
26
+ // SEQUENTIAL CHECK (Avoid Rate Limits on Key Verification)
27
+ const endpoints = ['/account/profile', '/account/balance', '/account/usage'];
28
+ for (const ep of endpoints) {
29
+ const res = await checkEndpoint(ep, key);
30
+ if (!res.ok) {
31
+ return { ok: false, reason: `${ep} (${res.status})` };
32
+ }
33
+ }
34
+ return { ok: true };
35
+ }
39
36
  // === CONSTANTS & PRICING ===
40
37
  const TIER_LIMITS = {
41
38
  spore: { pollen: 1, emoji: '🦠' },
@@ -274,18 +271,23 @@ async function handleConnectCommand(args) {
274
271
  // CHECK RESTRICTIONS: Strict Check (Usage + Profile + Balance)
275
272
  let forcedModeMsg = "";
276
273
  let isLimited = false;
274
+ let limitReason = "";
277
275
  try {
278
276
  // Strict Probe: Must be able to read ALL accounting data
279
- const hasFullAccess = await checkKeyPermissions(key);
280
- isLimited = !hasFullAccess;
277
+ const check = await checkKeyPermissions(key);
278
+ if (!check.ok) {
279
+ isLimited = true;
280
+ limitReason = check.reason || "Unknown";
281
+ }
281
282
  }
282
283
  catch (e) {
283
284
  isLimited = true;
285
+ limitReason = e.message;
284
286
  }
285
287
  // If Limited -> FORCE MANUAL
286
288
  if (isLimited) {
287
289
  saveConfig({ apiKey: key, mode: 'manual', keyHasAccessToProfile: false });
288
- forcedModeMsg = "\n⚠️ **Clé Limitée** (Permissions insuffisantes) -> Mode **MANUAL** forcé.\n*Requis pour mode Auto: Profile, Balance & Usage.*";
290
+ forcedModeMsg = `\n⚠️ **Clé Limitée** (Echec: ${limitReason}) -> Mode **MANUAL** forcé.\n*Requis pour mode Auto: Profile, Balance & Usage.*`;
289
291
  }
290
292
  else {
291
293
  saveConfig({ apiKey: key, keyHasAccessToProfile: true }); // Let user keep current mode or default
@@ -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.3",
4
+ "version": "5.5.5",
5
5
  "description": "Native Pollinations.ai Provider Plugin for OpenCode",
6
6
  "publisher": "pollinations",
7
7
  "repository": {