opencode-pollinations-plugin 5.6.0-beta.3 → 5.6.0-beta.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.
- package/dist/debug_check.js +35 -0
- package/dist/server/commands.js +52 -0
- package/dist/server/quota.js +5 -6
- package/dist/test-require.js +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as https from 'https';
|
|
2
|
+
|
|
3
|
+
function checkEndpoint(ep, key) {
|
|
4
|
+
return new Promise((resolve) => {
|
|
5
|
+
console.log(`Checking ${ep}...`);
|
|
6
|
+
const req = https.request({
|
|
7
|
+
hostname: 'gen.pollinations.ai',
|
|
8
|
+
path: ep,
|
|
9
|
+
method: 'GET',
|
|
10
|
+
headers: { 'Authorization': `Bearer ${key}` }
|
|
11
|
+
}, (res) => {
|
|
12
|
+
console.log(`Status Code: ${res.statusCode}`);
|
|
13
|
+
let data = '';
|
|
14
|
+
res.on('data', chunk => data += chunk);
|
|
15
|
+
res.on('end', () => {
|
|
16
|
+
console.log(`Body Sample: ${data.substring(0, 100)}...`);
|
|
17
|
+
if (res.statusCode === 200) resolve({ ok: true });
|
|
18
|
+
else resolve({ ok: false, status: res.statusCode });
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
req.on('error', (e) => {
|
|
22
|
+
console.log(`Error: ${e.message}`);
|
|
23
|
+
resolve({ ok: false, status: e.message || 'Error' });
|
|
24
|
+
});
|
|
25
|
+
req.setTimeout(10000, () => req.destroy());
|
|
26
|
+
req.end();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const KEY = "plln_sk_F7a4RcBG4AVCeBSo6lnS36EKwm0nPn1O";
|
|
31
|
+
|
|
32
|
+
(async () => {
|
|
33
|
+
const res = await checkEndpoint('/account/profile', KEY);
|
|
34
|
+
console.log('Result:', res);
|
|
35
|
+
})();
|
package/dist/server/commands.js
CHANGED
|
@@ -1,8 +1,60 @@
|
|
|
1
|
+
import * as https from 'https';
|
|
1
2
|
import { loadConfig, saveConfig } from './config.js';
|
|
2
3
|
import { getQuotaStatus } from './quota.js';
|
|
3
4
|
import { emitStatusToast } from './toast.js';
|
|
4
5
|
import { getDetailedUsage } from './pollinations-api.js';
|
|
5
6
|
import { generatePollinationsConfig } from './generate-config.js';
|
|
7
|
+
function checkEndpoint(ep, key) {
|
|
8
|
+
return new Promise((resolve) => {
|
|
9
|
+
const req = https.request({
|
|
10
|
+
hostname: 'gen.pollinations.ai',
|
|
11
|
+
path: ep,
|
|
12
|
+
method: 'GET',
|
|
13
|
+
headers: {
|
|
14
|
+
'Authorization': `Bearer ${key}`,
|
|
15
|
+
'User-Agent': 'Pollinations-Plugin/5.6.0' // Identify cleanly
|
|
16
|
+
}
|
|
17
|
+
}, (res) => {
|
|
18
|
+
const isJson = res.headers['content-type']?.includes('application/json');
|
|
19
|
+
let data = '';
|
|
20
|
+
res.on('data', chunk => data += chunk);
|
|
21
|
+
res.on('end', () => {
|
|
22
|
+
if (res.statusCode === 200 && isJson) {
|
|
23
|
+
// Double Check Check Body for Logical Errors masked as 200
|
|
24
|
+
try {
|
|
25
|
+
const json = JSON.parse(data);
|
|
26
|
+
if (json.error || json.success === false) {
|
|
27
|
+
resolve({ ok: false, reason: "API Logical Error", status: 200 });
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
resolve({ ok: true });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
resolve({ ok: false, reason: "Invalid JSON", status: 200 });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
resolve({ ok: false, status: res.statusCode, reason: isJson ? "API Error" : "Not JSON (Cloudflare?)" });
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
req.on('error', (e) => resolve({ ok: false, status: e.message || 'Error' }));
|
|
43
|
+
req.setTimeout(10000, () => req.destroy()); // 10s Timeout
|
|
44
|
+
req.end();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
async function checkKeyPermissions(key) {
|
|
48
|
+
// SEQUENTIAL CHECK (Avoid Rate Limits on Key Verification)
|
|
49
|
+
const endpoints = ['/account/profile', '/account/balance', '/account/usage'];
|
|
50
|
+
for (const ep of endpoints) {
|
|
51
|
+
const res = await checkEndpoint(ep, key);
|
|
52
|
+
if (!res.ok) {
|
|
53
|
+
return { ok: false, reason: `${ep} (${res.status})` };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { ok: true };
|
|
57
|
+
}
|
|
6
58
|
// === CONSTANTS & PRICING ===
|
|
7
59
|
const TIER_LIMITS = {
|
|
8
60
|
spore: { pollen: 1, emoji: '🦠' },
|
package/dist/server/quota.js
CHANGED
|
@@ -44,12 +44,11 @@ export async function getQuotaStatus(forceRefresh = false) {
|
|
|
44
44
|
}
|
|
45
45
|
try {
|
|
46
46
|
logQuota("Fetching Quota Data...");
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
]);
|
|
47
|
+
// SEQUENTIAL FETCH (Avoid Rate Limits)
|
|
48
|
+
// We fetch one by one. If one fails, we catch and return fallback.
|
|
49
|
+
const profileRes = await fetchAPI('/account/profile', config.apiKey);
|
|
50
|
+
const balanceRes = await fetchAPI('/account/balance', config.apiKey);
|
|
51
|
+
const usageRes = await fetchAPI('/account/usage', config.apiKey);
|
|
53
52
|
logQuota(`Fetch Success. Tier: ${profileRes.tier}, Balance: ${balanceRes.balance}`);
|
|
54
53
|
const profile = profileRes;
|
|
55
54
|
const balance = balanceRes.balance;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
try {
|
|
4
|
+
const pkg = require('../package.json');
|
|
5
|
+
console.log("SUCCESS: Loaded version " + pkg.version);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
console.error("FAILURE:", e.message);
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
package/package.json
CHANGED