opencode-pollinations-plugin 5.1.15 → 5.1.17

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/index.js CHANGED
@@ -2,29 +2,43 @@ import * as http from 'http';
2
2
  import * as fs from 'fs';
3
3
  import { execSync } from 'child_process';
4
4
  import { generatePollinationsConfig } from './server/generate-config.js';
5
- import { loadConfig } from './server/config.js';
5
+ import { loadConfig, subscribeToConfigChange } from './server/config.js';
6
6
  import { handleChatCompletion } from './server/proxy.js';
7
- import { createToastHooks, setGlobalClient } from './server/toast.js';
7
+ import { createToastHooks, setGlobalClient, emitStatusToast } from './server/toast.js';
8
8
  import { createStatusHooks } from './server/status.js';
9
9
  import { createCommandHooks } from './server/commands.js';
10
- const LOG_FILE = '/tmp/opencode_pollinations_v4.log';
10
+ const LIFE_LOG = '/tmp/POLLI_LIFECYCLE.log';
11
+ const LOC_LOG = '/tmp/POLLI_LOCATION.log';
11
12
  function log(msg) {
12
13
  try {
13
- fs.appendFileSync(LOG_FILE, `[${new Date().toISOString()}] ${msg}\n`);
14
+ fs.appendFileSync(LIFE_LOG, `[${new Date().toISOString()}] ${msg}\n`);
14
15
  }
15
16
  catch (e) { }
16
17
  }
17
18
  const TRACKING_PORT = 10001;
19
+ // IMMEDIATE PROBE
20
+ try {
21
+ fs.writeFileSync(LOC_LOG, `[${new Date().toISOString()}] ENTRY_POINT_RUNNING: ${__filename}\n`);
22
+ log(`[STARTUP] Initializing Plugin v5.1.16...`);
23
+ }
24
+ catch (e) { }
18
25
  // === ANTI-ZOMBIE ATOMIC CLEANUP ===
19
26
  try {
20
27
  log(`[Init] Checking port ${TRACKING_PORT} for zombies...`);
21
28
  execSync(`fuser -k ${TRACKING_PORT}/tcp || true`);
22
29
  log(`[Init] Port ${TRACKING_PORT} cleaned.`);
30
+ execSync('sleep 1');
23
31
  }
24
32
  catch (e) {
25
33
  log(`[Init] Zombie cleanup warning: ${e}`);
26
34
  }
27
35
  // === GESTION DU CYCLE DE VIE PROXY ===
36
+ // CONFIG WATCHER (Hot Reload)
37
+ subscribeToConfigChange(() => {
38
+ const config = loadConfig();
39
+ log(`[HotReload] Config changed. Mode: ${config.mode}`);
40
+ emitStatusToast('info', `Config Reloaded: ${config.mode}`, 'Pollinations');
41
+ });
28
42
  const startProxy = () => {
29
43
  return new Promise((resolve) => {
30
44
  const server = http.createServer(async (req, res) => {
@@ -42,13 +56,29 @@ const startProxy = () => {
42
56
  res.writeHead(200, { 'Content-Type': 'application/json' });
43
57
  res.end(JSON.stringify({
44
58
  status: "ok",
45
- version: "v4.0.5",
46
- mode: config.mode
59
+ version: "v5.1.17",
60
+ mode: config.mode,
61
+ pid: process.pid
47
62
  }));
48
63
  return;
49
64
  }
65
+ // RESTORED: Models Endpoint
66
+ if (req.method === 'GET' && req.url === '/v1/models') {
67
+ try {
68
+ const { getAggregatedModels } = await import('./server/pollinations-api.js');
69
+ const models = await getAggregatedModels();
70
+ res.writeHead(200, { 'Content-Type': 'application/json' });
71
+ res.end(JSON.stringify(models));
72
+ log(`[Proxy] Served ${models.data?.length || 0} models`);
73
+ }
74
+ catch (e) {
75
+ log(`[Proxy] Error fetching models: ${e}`);
76
+ res.writeHead(500);
77
+ res.end(JSON.stringify({ error: String(e) }));
78
+ }
79
+ return;
80
+ }
50
81
  // SUPPORT FLEXIBLE DES PATHS
51
- // Le SDK peut envoyer /v1/chat/completions ou juste /chat/completions
52
82
  if (req.method === 'POST' && (req.url === '/v1/chat/completions' || req.url === '/chat/completions')) {
53
83
  const chunks = [];
54
84
  req.on('data', chunk => chunks.push(chunk));
@@ -56,9 +86,10 @@ const startProxy = () => {
56
86
  try {
57
87
  const bodyRaw = Buffer.concat(chunks).toString();
58
88
  await handleChatCompletion(req, res, bodyRaw);
89
+ log(`[Proxy] Chat Completion Success`);
59
90
  }
60
91
  catch (e) {
61
- log(`Error: ${e}`);
92
+ log(`[Proxy] Chat Error: ${e}`);
62
93
  if (!res.headersSent) {
63
94
  res.writeHead(500);
64
95
  res.end(JSON.stringify({ error: String(e) }));
@@ -72,11 +103,12 @@ const startProxy = () => {
72
103
  res.end("Not Found");
73
104
  });
74
105
  server.listen(TRACKING_PORT, '127.0.0.1', () => {
75
- log(`[Proxy] Started V4 on port ${TRACKING_PORT}`);
106
+ log(`[Proxy] Started V5.1.17 on port ${TRACKING_PORT}`);
76
107
  resolve(TRACKING_PORT);
77
108
  });
78
109
  server.on('error', (e) => {
79
110
  log(`[Proxy] Fatal Error: ${e}`);
111
+ // Retry logic could go here, but for now log is key
80
112
  resolve(0);
81
113
  });
82
114
  });
@@ -119,6 +151,7 @@ export const PollinationsPlugin = async (ctx) => {
119
151
  models: modelsObj
120
152
  };
121
153
  log(`[Hook] Registered ${Object.keys(modelsObj).length} models.`);
154
+ emitStatusToast('info', `${Object.keys(modelsObj).length} Models Loaded`, 'Pollinations');
122
155
  },
123
156
  ...toastHooks,
124
157
  ...createStatusHooks(ctx.client), // New Status Bar Logic
@@ -1,3 +1,5 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
1
3
  import { loadConfig, saveConfig } from './config.js';
2
4
  import { getQuotaStatus } from './quota.js';
3
5
  import { emitStatusToast } from './toast.js';
@@ -93,6 +95,8 @@ export async function handleCommand(command) {
93
95
  return handleFallbackCommand(args);
94
96
  case 'config':
95
97
  return handleConfigCommand(args);
98
+ case 'debug':
99
+ return handleDebugCommand();
96
100
  case 'help':
97
101
  return handleHelpCommand();
98
102
  default:
@@ -267,6 +271,26 @@ function handleConfigCommand(args) {
267
271
  error: `Clé inconnue: ${key}. Clés: status_gui, logs_gui, threshold_tier, threshold_wallet, status_bar`
268
272
  };
269
273
  }
274
+ function handleDebugCommand() {
275
+ const info = {
276
+ pid: process.pid,
277
+ execPath: process.execPath,
278
+ cwd: process.cwd(),
279
+ home: process.env.HOME || 'undefined',
280
+ node: process.version,
281
+ uid: process.getuid ? process.getuid() : 'unknown',
282
+ gid: process.getgid ? process.getgid() : 'unknown',
283
+ tmp: '/tmp',
284
+ port_env: process.env.POLLINATIONS_PORT || 'default(10001)',
285
+ log_file_check: fs.existsSync(path.join(process.env.HOME || '', '.config/opencode/plugins/pollinations-v3.log')),
286
+ tmp_log_check: fs.existsSync('/tmp/POLLI_LIFECYCLE.log')
287
+ };
288
+ return {
289
+ handled: true,
290
+ response: `### 🐞 Debug Probe v5.1.16\n` +
291
+ `\`\`\`json\n${JSON.stringify(info, null, 2)}\n\`\`\``
292
+ };
293
+ }
270
294
  function handleHelpCommand() {
271
295
  const help = `
272
296
  ### 🌸 Pollinations Plugin - Commandes V5
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.1.15",
4
+ "version": "5.1.17",
5
5
  "description": "Native Pollinations.ai Provider Plugin for OpenCode",
6
6
  "publisher": "pollinations",
7
7
  "repository": {