opencode-pollinations-plugin 5.2.4 → 5.3.1

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/bin/setup.js CHANGED
File without changes
package/dist/index.js CHANGED
@@ -15,19 +15,61 @@ function log(msg) {
15
15
  catch (e) { }
16
16
  }
17
17
  const TRACKING_PORT = 10001;
18
- // === ANTI-ZOMBIE ATOMIC CLEANUP ===
19
- try {
20
- log(`[Init] Checking port ${TRACKING_PORT} for zombies...`);
21
- execSync(`fuser -k ${TRACKING_PORT}/tcp || true`);
22
- log(`[Init] Port ${TRACKING_PORT} cleaned.`);
23
- }
24
- catch (e) {
25
- log(`[Init] Zombie cleanup warning: ${e}`);
26
- }
18
+ // === PORT MANAGEMENT (CROSS-PLATFORM) ===
19
+ // We MUST kill the previous instance to ensure a fresh state.
20
+ // Sticky ports = Zombies = Buggy Behavior.
21
+ const freePort = (port) => {
22
+ try {
23
+ if (process.platform === 'win32') {
24
+ // Windows: Find PID -> TaskKing
25
+ try {
26
+ const output = execSync(`netstat -ano | findstr :${port}`).toString();
27
+ const lines = output.trim().split('\n');
28
+ for (const line of lines) {
29
+ const parts = line.trim().split(/\s+/);
30
+ const pid = parts[parts.length - 1];
31
+ if (pid && /^\d+$/.test(pid) && pid !== '0') {
32
+ try {
33
+ execSync(`taskkill /PID ${pid} /F`);
34
+ log(`[Init] Killed Windows PID ${pid} on port ${port}`);
35
+ }
36
+ catch (e) { }
37
+ }
38
+ }
39
+ }
40
+ catch (e) { }
41
+ }
42
+ else {
43
+ // Linux / macOS: lsof or fuser
44
+ try {
45
+ // Try lsof first (Cleaner)
46
+ const pid = execSync(`lsof -t -i:${port}`).toString().trim();
47
+ if (pid) {
48
+ execSync(`kill -9 ${pid}`);
49
+ log(`[Init] Killed PID ${pid} via lsof`);
50
+ }
51
+ }
52
+ catch (e) {
53
+ // Fallback to fuser (Linux specific but very effective)
54
+ if (process.platform === 'linux') {
55
+ try {
56
+ execSync(`fuser -k ${port}/tcp`);
57
+ log(`[Init] Cleaned port ${port} via fuser`);
58
+ }
59
+ catch (e2) { }
60
+ }
61
+ }
62
+ }
63
+ }
64
+ catch (e) {
65
+ // Ignored: Port likely already free
66
+ }
67
+ };
27
68
  // === GESTION DU CYCLE DE VIE PROXY ===
28
69
  const startProxy = () => {
29
- return new Promise((resolve) => {
70
+ return new Promise(async (resolve) => {
30
71
  const server = http.createServer(async (req, res) => {
72
+ // ... (Request Handling - Unchanged) ...
31
73
  log(`[Proxy] Request: ${req.method} ${req.url}`);
32
74
  res.setHeader('Access-Control-Allow-Origin', '*');
33
75
  res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
@@ -42,7 +84,7 @@ const startProxy = () => {
42
84
  res.writeHead(200, { 'Content-Type': 'application/json' });
43
85
  res.end(JSON.stringify({
44
86
  status: "ok",
45
- version: "v5.2.0",
87
+ version: "v5.3.0",
46
88
  mode: config.mode
47
89
  }));
48
90
  return;
@@ -69,20 +111,29 @@ const startProxy = () => {
69
111
  res.writeHead(404);
70
112
  res.end("Not Found");
71
113
  });
72
- server.listen(TRACKING_PORT, '127.0.0.1', () => {
73
- log(`[Proxy] Started V5.2 on port ${TRACKING_PORT}`);
74
- resolve(TRACKING_PORT);
75
- });
76
- server.on('error', (e) => {
77
- log(`[Proxy] Fatal Error: ${e}`);
114
+ // Robust Startup Logic
115
+ try {
116
+ server.listen(TRACKING_PORT, '127.0.0.1', () => {
117
+ log(`[Proxy] Started V5.3.1 on port ${TRACKING_PORT}`);
118
+ resolve(TRACKING_PORT);
119
+ });
120
+ server.on('error', (e) => {
121
+ log(`[Proxy] Fatal Bind Error: ${e}`);
122
+ resolve(0);
123
+ });
124
+ }
125
+ catch (e) {
78
126
  resolve(0);
79
- });
127
+ }
80
128
  });
81
129
  };
82
130
  // === PLUGIN EXPORT ===
83
131
  export const PollinationsPlugin = async (ctx) => {
84
132
  log("Plugin Initializing V5.2.0 (Stable)...");
85
133
  // START PROXY
134
+ // 1. Force Clean Port
135
+ freePort(TRACKING_PORT);
136
+ // 2. Start
86
137
  const port = await startProxy();
87
138
  const localBaseUrl = `http://127.0.0.1:${port}/v1`;
88
139
  setGlobalClient(ctx.client);
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.2.4",
4
+ "version": "5.3.1",
5
5
  "description": "Native Pollinations.ai Provider Plugin for OpenCode",
6
6
  "publisher": "pollinations",
7
7
  "repository": {