opencode-pollinations-plugin 6.0.0-beta.20 → 6.0.0-beta.22

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.
Files changed (2) hide show
  1. package/dist/index.js +22 -13
  2. 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
- let existingServer = null;
21
- let existingPort = 0;
20
+ const GLOBAL_SERVER_KEY = '__POLLINATIONS_PROXY_SERVER__';
22
21
  const startProxy = () => {
23
- // Singleton: reuse existing server if already running
24
- if (existingServer && existingPort > 0) {
25
- log(`[Proxy] Reusing existing server on port ${existingPort}`);
26
- return Promise.resolve(existingPort);
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
- existingServer = server;
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
  });
@@ -214,14 +212,25 @@ export const PollinationsPlugin = async (ctx) => {
214
212
  return {
215
213
  // AUTH HOOK: Native /connect integration
216
214
  auth: createAuthHook(),
217
- // EVENT HOOK: Listen for auth/installation updates (triggered by /connect)
215
+ // EVENT HOOK: Listen for changes that might indicate /connect completed
218
216
  event: async ({ event }) => {
219
- log(`[Event] Received: ${event.type}`);
220
- // React to installation.updated (fired after /connect completes)
221
- if (event.type === 'installation.updated') {
222
- log('[Event] installation.updated detected - triggering hot-reload');
217
+ // Log only relevant events (auth-related)
218
+ if (event.type === 'installation.updated' ||
219
+ event.type === 'server.connected') {
220
+ log(`[Event] Relevant event: ${event.type}`);
223
221
  await refreshProviderConfig();
224
222
  }
223
+ // Also watch for tui.command.execute (when user types /connect)
224
+ // Note: This fires at START of /connect, not at completion
225
+ // The AuthHook handles the actual key update
226
+ if (event.type === 'tui.command.execute') {
227
+ const cmd = event.command || event.data?.command;
228
+ if (cmd === 'connect' || cmd === '/connect') {
229
+ log('[Event] /connect command detected - will refresh after auth hook completes');
230
+ // Small delay to let auth hook complete
231
+ setTimeout(() => refreshProviderConfig(), 2000);
232
+ }
233
+ }
225
234
  },
226
235
  async config(config) {
227
236
  log("[Hook] config() called");
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.20",
4
+ "version": "6.0.0-beta.22",
5
5
  "description": "Native Pollinations.ai Provider Plugin for OpenCode",
6
6
  "publisher": "pollinations",
7
7
  "repository": {