opencode-pollinations-plugin 6.0.0-beta.21 → 6.0.0-beta.23
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 +16 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17,13 +17,12 @@ function log(msg) {
|
|
|
17
17
|
}
|
|
18
18
|
// === PROXY SERVER (Singleton with Fixed Port) ===
|
|
19
19
|
const DEFAULT_PORT = 18888;
|
|
20
|
-
|
|
21
|
-
let existingPort = 0;
|
|
20
|
+
const GLOBAL_SERVER_KEY = '__POLLINATIONS_PROXY_SERVER__';
|
|
22
21
|
const startProxy = () => {
|
|
23
|
-
//
|
|
24
|
-
if (
|
|
25
|
-
log(`[Proxy] Reusing existing server on port ${
|
|
26
|
-
return Promise.resolve(
|
|
22
|
+
// Check if server exists in global scope (survives module reloads)
|
|
23
|
+
if (global[GLOBAL_SERVER_KEY]) {
|
|
24
|
+
log(`[Proxy] Reusing existing global server on port ${DEFAULT_PORT}`);
|
|
25
|
+
return Promise.resolve(DEFAULT_PORT);
|
|
27
26
|
}
|
|
28
27
|
return new Promise((resolve) => {
|
|
29
28
|
const server = http.createServer(async (req, res) => {
|
|
@@ -73,8 +72,7 @@ const startProxy = () => {
|
|
|
73
72
|
server.listen(port, '127.0.0.1', () => {
|
|
74
73
|
// @ts-ignore
|
|
75
74
|
const assignedPort = server.address().port;
|
|
76
|
-
|
|
77
|
-
existingPort = assignedPort;
|
|
75
|
+
global[GLOBAL_SERVER_KEY] = server;
|
|
78
76
|
log(`[Proxy] Started v${require('../package.json').version} on port ${assignedPort}${port === 0 ? ' (dynamic fallback)' : ''}`);
|
|
79
77
|
resolve(assignedPort);
|
|
80
78
|
});
|
|
@@ -178,7 +176,11 @@ export const PollinationsPlugin = async (ctx) => {
|
|
|
178
176
|
const toastHooks = createToastHooks(ctx.client);
|
|
179
177
|
const commandHooks = createCommandHooks();
|
|
180
178
|
// Helper: Refresh provider config (for hot-reload after /connect)
|
|
179
|
+
let isRefreshing = false;
|
|
181
180
|
const refreshProviderConfig = async () => {
|
|
181
|
+
if (isRefreshing)
|
|
182
|
+
return;
|
|
183
|
+
isRefreshing = true;
|
|
182
184
|
try {
|
|
183
185
|
log('[Event] Refreshing provider config after auth update...');
|
|
184
186
|
const modelsArray = await generatePollinationsConfig();
|
|
@@ -210,21 +212,17 @@ export const PollinationsPlugin = async (ctx) => {
|
|
|
210
212
|
catch (e) {
|
|
211
213
|
log(`[Event] Failed to refresh provider config: ${e}`);
|
|
212
214
|
}
|
|
215
|
+
finally {
|
|
216
|
+
// Debounce: prevent another refresh for 5 seconds
|
|
217
|
+
setTimeout(() => { isRefreshing = false; }, 5000);
|
|
218
|
+
}
|
|
213
219
|
};
|
|
214
220
|
return {
|
|
215
221
|
// AUTH HOOK: Native /connect integration
|
|
216
222
|
auth: createAuthHook(),
|
|
217
|
-
// EVENT HOOK: Listen for
|
|
223
|
+
// EVENT HOOK: Listen ONLY for explicit /connect command
|
|
224
|
+
// We removed installation.updated/server.connected because they caused infinite loops
|
|
218
225
|
event: async ({ event }) => {
|
|
219
|
-
// Log only relevant events (auth-related)
|
|
220
|
-
if (event.type === 'installation.updated' ||
|
|
221
|
-
event.type === 'server.connected') {
|
|
222
|
-
log(`[Event] Relevant event: ${event.type}`);
|
|
223
|
-
await refreshProviderConfig();
|
|
224
|
-
}
|
|
225
|
-
// Also watch for tui.command.execute (when user types /connect)
|
|
226
|
-
// Note: This fires at START of /connect, not at completion
|
|
227
|
-
// The AuthHook handles the actual key update
|
|
228
226
|
if (event.type === 'tui.command.execute') {
|
|
229
227
|
const cmd = event.command || event.data?.command;
|
|
230
228
|
if (cmd === 'connect' || cmd === '/connect') {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-pollinations-plugin",
|
|
3
3
|
"displayName": "Pollinations AI (V5.6)",
|
|
4
|
-
"version": "6.0.0-beta.
|
|
4
|
+
"version": "6.0.0-beta.23",
|
|
5
5
|
"description": "Native Pollinations.ai Provider Plugin for OpenCode",
|
|
6
6
|
"publisher": "pollinations",
|
|
7
7
|
"repository": {
|