opencode-pollinations-plugin 5.4.9 → 5.4.10
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/commands.js +49 -12
- package/package.json +1 -1
package/dist/server/commands.js
CHANGED
|
@@ -2,6 +2,7 @@ import { loadConfig, saveConfig } from './config.js';
|
|
|
2
2
|
import { getQuotaStatus } from './quota.js';
|
|
3
3
|
import { emitStatusToast } from './toast.js';
|
|
4
4
|
import { getDetailedUsage } from './pollinations-api.js';
|
|
5
|
+
import { generatePollinationsConfig } from './generate-config.js';
|
|
5
6
|
// === CONSTANTS & PRICING ===
|
|
6
7
|
const TIER_LIMITS = {
|
|
7
8
|
spore: { pollen: 1, emoji: '🦠' },
|
|
@@ -204,28 +205,64 @@ function handleFallbackCommand(args) {
|
|
|
204
205
|
response: `✅ Fallback (Free) configuré: main=${main}, agent=${agent || config.fallbacks.free.agent}`
|
|
205
206
|
};
|
|
206
207
|
}
|
|
207
|
-
function handleConnectCommand(args) {
|
|
208
|
+
async function handleConnectCommand(args) {
|
|
208
209
|
const key = args[0];
|
|
209
210
|
if (!key) {
|
|
210
211
|
return {
|
|
211
212
|
handled: true,
|
|
212
|
-
error: `Utilisation: /pollinations connect <
|
|
213
|
+
error: `Utilisation: /pollinations connect <votre_clé_api>`
|
|
213
214
|
};
|
|
214
215
|
}
|
|
215
|
-
|
|
216
|
+
// 1. Universal Validation (No Syntax Check) - Functional Check
|
|
217
|
+
emitStatusToast('info', 'Vérification de la clé...', 'Pollinations Config');
|
|
218
|
+
try {
|
|
219
|
+
const models = await generatePollinationsConfig(key);
|
|
220
|
+
// 2. Check if we got Enterprise models
|
|
221
|
+
const enterpriseModels = models.filter(m => m.id.startsWith('enter/'));
|
|
222
|
+
if (enterpriseModels.length > 0) {
|
|
223
|
+
// SUCCESS
|
|
224
|
+
saveConfig({ apiKey: key, mode: 'pro' });
|
|
225
|
+
const masked = key.substring(0, 6) + '...';
|
|
226
|
+
// Count Paid Only models found
|
|
227
|
+
const diamondCount = enterpriseModels.filter(m => m.name.includes('💎')).length;
|
|
228
|
+
emitStatusToast('success', `Clé Valide! (${enterpriseModels.length} modèles Pro débloqués)`, 'Pollinations Config');
|
|
229
|
+
return {
|
|
230
|
+
handled: true,
|
|
231
|
+
response: `✅ **Connexion Réussie!**\n- Clé: \`${masked}\`\n- Mode: **PRO** (Activé)\n- Modèles Débloqués: ${enterpriseModels.length} (dont ${diamondCount} 💎 Paid)`
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
// FAILURE (Valid JSON but no Enterprise models - likely Invalid Key or Free plan only?)
|
|
236
|
+
// If key is invalid, generatePollinationsConfig usually returns fallback free models BUT
|
|
237
|
+
// we specifically checked 'enter/'. If 0 enterprise models found for a *provided* key, it's suspicious.
|
|
238
|
+
// Actually config generator returns Free models + Enter models if key works.
|
|
239
|
+
// If key is BAD, fetchJson throws/logs error, and returns fallbacks (Enter GPT-4o Fallback).
|
|
240
|
+
// Wait, generate-config falls back to providing a list containing "[Enter] GPT-4o (Fallback)" if fetch failed.
|
|
241
|
+
// So we need to detect if it's a "REAL" fetch or a "FALLBACK" fetch.
|
|
242
|
+
// The fallback models have `variants: {}` usually, but real ones might too.
|
|
243
|
+
// A better check: The fallback list is hardcoded in generate-config.ts catch block.
|
|
244
|
+
// Let's modify generate-config to return EMPTY list on error?
|
|
245
|
+
// Or just check if the returned models work?
|
|
246
|
+
// Simplest: If `generatePollinationsConfig` returns any model starting with `enter/` that includes "(Fallback)" in name, we assume failure?
|
|
247
|
+
// "GPT-4o (Fallback)" is the name.
|
|
248
|
+
const isFallback = models.some(m => m.name.includes('(Fallback)') && m.id.startsWith('enter/'));
|
|
249
|
+
if (isFallback) {
|
|
250
|
+
throw new Error("Clé rejetée par l'API (Accès refusé ou invalide).");
|
|
251
|
+
}
|
|
252
|
+
// If we are here, we got no enter models, or empty list?
|
|
253
|
+
// If key is valid but has no access?
|
|
254
|
+
throw new Error("Aucun modèle Enterprise détecté pour cette clé.");
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
catch (e) {
|
|
258
|
+
// 3. FAILURE HANDLING - Revert to FREE
|
|
259
|
+
saveConfig({ apiKey: undefined, mode: 'manual' }); // Clear Key, Set Manual
|
|
260
|
+
emitStatusToast('error', `Clé Invalide. Retour au mode Gratuit.`, 'Pollinations Config');
|
|
216
261
|
return {
|
|
217
262
|
handled: true,
|
|
218
|
-
error:
|
|
263
|
+
error: `❌ **Échec Connexion**: ${e.message || e}\n\nLa configuration a été réinitialisée (Mode Gratuit/Manuel).`
|
|
219
264
|
};
|
|
220
265
|
}
|
|
221
|
-
// Save API Key only (User decides mode manually)
|
|
222
|
-
saveConfig({ apiKey: key });
|
|
223
|
-
// Confirm
|
|
224
|
-
emitStatusToast('success', 'API Key enregistrée', 'Pollinations Config');
|
|
225
|
-
return {
|
|
226
|
-
handled: true,
|
|
227
|
-
response: `✅ API Key connectée. (Utilisez /pollinations mode pro pour l'activer)`
|
|
228
|
-
};
|
|
229
266
|
}
|
|
230
267
|
function handleConfigCommand(args) {
|
|
231
268
|
const [key, value] = args;
|
package/package.json
CHANGED