opencode-pollinations-plugin 5.4.8 → 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/dist/server/generate-config.js +26 -1
- package/dist/server/proxy.js +37 -0
- 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;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import * as https from 'https';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
|
+
import * as os from 'os';
|
|
4
|
+
import * as path from 'path';
|
|
3
5
|
import { loadConfig } from './config.js';
|
|
6
|
+
const HOMEDIR = os.homedir();
|
|
7
|
+
const CONFIG_DIR_POLLI = path.join(HOMEDIR, '.pollinations');
|
|
8
|
+
const CONFIG_FILE = path.join(CONFIG_DIR_POLLI, 'config.json');
|
|
4
9
|
// --- LOGGING ---
|
|
5
10
|
const LOG_FILE = '/tmp/opencode_pollinations_config.log';
|
|
6
11
|
function log(msg) {
|
|
@@ -92,18 +97,34 @@ export async function generatePollinationsConfig(forceApiKey) {
|
|
|
92
97
|
'Authorization': `Bearer ${effectiveKey}`
|
|
93
98
|
});
|
|
94
99
|
const enterList = Array.isArray(enterListRaw) ? enterListRaw : (enterListRaw.data || []);
|
|
100
|
+
const paidModels = [];
|
|
95
101
|
enterList.forEach((m) => {
|
|
96
102
|
if (m.tools === false)
|
|
97
103
|
return;
|
|
98
104
|
const mapped = mapModel(m, 'enter/', '[Enter] ');
|
|
99
105
|
modelsOutput.push(mapped);
|
|
106
|
+
if (m.paid_only) {
|
|
107
|
+
paidModels.push(mapped.id.replace('enter/', '')); // Store bare ID "gemini-large"
|
|
108
|
+
}
|
|
100
109
|
});
|
|
101
110
|
log(`Total models (Free+Pro): ${modelsOutput.length}`);
|
|
111
|
+
// Save Paid Models List for Proxy
|
|
112
|
+
try {
|
|
113
|
+
const paidListPath = path.join(config.gui ? path.dirname(CONFIG_FILE) : '/tmp', 'pollinations-paid-models.json');
|
|
114
|
+
// Ensure dir exists (re-use config dir logic from config.ts if possible, or just assume it exists since config loaded)
|
|
115
|
+
if (fs.existsSync(path.dirname(paidListPath))) {
|
|
116
|
+
fs.writeFileSync(paidListPath, JSON.stringify(paidModels));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
log(`Error saving paid models list: ${e}`);
|
|
121
|
+
}
|
|
102
122
|
}
|
|
103
123
|
catch (e) {
|
|
104
124
|
log(`Error fetching Enterprise models: ${e}`);
|
|
105
125
|
// Fallback Robust for Enterprise (User has Key but discovery failed)
|
|
106
126
|
modelsOutput.push({ id: "enter/gpt-4o", name: "[Enter] GPT-4o (Fallback)", object: "model", variants: {} });
|
|
127
|
+
// ...
|
|
107
128
|
modelsOutput.push({ id: "enter/claude-3-5-sonnet", name: "[Enter] Claude 3.5 Sonnet (Fallback)", object: "model", variants: {} });
|
|
108
129
|
modelsOutput.push({ id: "enter/deepseek-reasoner", name: "[Enter] DeepSeek R1 (Fallback)", object: "model", variants: {} });
|
|
109
130
|
}
|
|
@@ -123,7 +144,11 @@ function mapModel(raw, prefix, namePrefix) {
|
|
|
123
144
|
if (baseName && baseName.includes(' - ')) {
|
|
124
145
|
baseName = baseName.split(' - ')[0].trim();
|
|
125
146
|
}
|
|
126
|
-
|
|
147
|
+
let namePrefixFinal = namePrefix;
|
|
148
|
+
if (raw.paid_only) {
|
|
149
|
+
namePrefixFinal = namePrefix.replace('[Enter]', '[💎 Paid]');
|
|
150
|
+
}
|
|
151
|
+
const finalName = `${namePrefixFinal}${baseName}`;
|
|
127
152
|
const modelObj = {
|
|
128
153
|
id: fullId,
|
|
129
154
|
name: finalName,
|
package/dist/server/proxy.js
CHANGED
|
@@ -220,6 +220,43 @@ export async function handleChatCompletion(req, res, bodyRaw) {
|
|
|
220
220
|
isEnterprise = false;
|
|
221
221
|
actualModel = actualModel.replace('free/', '');
|
|
222
222
|
}
|
|
223
|
+
// A.1 PAID MODEL ENFORCEMENT (V5.5 Strategy)
|
|
224
|
+
// Check dynamic list saved by generate-config.ts
|
|
225
|
+
if (isEnterprise) {
|
|
226
|
+
try {
|
|
227
|
+
const paidListPath = path.join(config.gui ? path.dirname(path.join(process.env.HOME || '/tmp', '.config/opencode/pollinations-signature.json')) : '/tmp', 'pollinations-paid-models.json');
|
|
228
|
+
// Wait, logic above for config path is messy. Let's use standard path logic:
|
|
229
|
+
// config.ts uses ~/.pollinations/config.json usually.
|
|
230
|
+
// generate-config uses path.join(config.gui ? path.dirname(CONFIG_FILE) : '/tmp')
|
|
231
|
+
// Let's rely on standard ~/.pollinations location if possible, or try both.
|
|
232
|
+
const homedir = process.env.HOME || '/tmp';
|
|
233
|
+
const standardPaidPath = path.join(homedir, '.pollinations', 'pollinations-paid-models.json');
|
|
234
|
+
if (fs.existsSync(standardPaidPath)) {
|
|
235
|
+
const paidModels = JSON.parse(fs.readFileSync(standardPaidPath, 'utf-8'));
|
|
236
|
+
if (paidModels.includes(actualModel)) {
|
|
237
|
+
// IT IS A PAID ONLY MODEL.
|
|
238
|
+
// STRICT CHECK: Wallet > 0 required. (Not just Tier)
|
|
239
|
+
if (quota.walletBalance <= 0.001) { // Floating point safety
|
|
240
|
+
log(`[SafetyNet] Paid Only Model (${actualModel}) requested but Wallet is Empty ($${quota.walletBalance}). BLOCKING.`);
|
|
241
|
+
// Immediate Block or Fallback?
|
|
242
|
+
// Text says: "💎 Paid Only models require purchased pollen only"
|
|
243
|
+
// Blocking is safer/clearer than falling back to a free model which might not be what the user expects for a "Pro" feature?
|
|
244
|
+
// Actually, Fallback to Free is usually better for UX if configured, BUT for specific "Paid Only" requests, the user explicitly chose a powerful model.
|
|
245
|
+
// Falling back to Mistral might be confusing if they asked for Gemini-Large.
|
|
246
|
+
// BUT we are failing gracefully.
|
|
247
|
+
// Let's Fallback to Free Default and Warn.
|
|
248
|
+
actualModel = config.fallbacks.free.main.replace('free/', '');
|
|
249
|
+
isEnterprise = false;
|
|
250
|
+
isFallbackActive = true;
|
|
251
|
+
fallbackReason = "Paid Only Model requires purchased credits";
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
catch (e) {
|
|
257
|
+
log(`[Proxy] Error checking paid models: ${e}`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
223
260
|
// B. SAFETY NETS (The Core V5 Logic)
|
|
224
261
|
if (config.mode === 'alwaysfree') {
|
|
225
262
|
if (isEnterprise) {
|
package/package.json
CHANGED