opencode-pollinations-plugin 6.0.0-beta.22 → 6.0.0-beta.24
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 +36 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -176,7 +176,11 @@ export const PollinationsPlugin = async (ctx) => {
|
|
|
176
176
|
const toastHooks = createToastHooks(ctx.client);
|
|
177
177
|
const commandHooks = createCommandHooks();
|
|
178
178
|
// Helper: Refresh provider config (for hot-reload after /connect)
|
|
179
|
+
let isRefreshing = false;
|
|
179
180
|
const refreshProviderConfig = async () => {
|
|
181
|
+
if (isRefreshing)
|
|
182
|
+
return;
|
|
183
|
+
isRefreshing = true;
|
|
180
184
|
try {
|
|
181
185
|
log('[Event] Refreshing provider config after auth update...');
|
|
182
186
|
const modelsArray = await generatePollinationsConfig();
|
|
@@ -185,22 +189,36 @@ export const PollinationsPlugin = async (ctx) => {
|
|
|
185
189
|
modelsObj[m.id] = m;
|
|
186
190
|
}
|
|
187
191
|
const version = require('../package.json').version;
|
|
188
|
-
//
|
|
192
|
+
// CRITICAL: Fetch current config first to avoid overwriting other providers
|
|
193
|
+
let currentConfig = {};
|
|
194
|
+
try {
|
|
195
|
+
// Try to fetch existing config to preserve other providers
|
|
196
|
+
const response = await ctx.client.fetch('/config');
|
|
197
|
+
if (response.ok) {
|
|
198
|
+
currentConfig = await response.json();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
log(`[Event] Warning: Could not fetch current config: ${err}`);
|
|
203
|
+
}
|
|
204
|
+
// Safe Merge
|
|
205
|
+
if (!currentConfig.provider)
|
|
206
|
+
currentConfig.provider = {};
|
|
207
|
+
currentConfig.provider.pollinations = {
|
|
208
|
+
id: 'openai',
|
|
209
|
+
name: `Pollinations AI (v${version})`,
|
|
210
|
+
options: {
|
|
211
|
+
baseURL: localBaseUrl,
|
|
212
|
+
apiKey: 'plugin-managed',
|
|
213
|
+
},
|
|
214
|
+
models: modelsObj
|
|
215
|
+
};
|
|
216
|
+
// Use Server API to update config with the MERGED object
|
|
189
217
|
await ctx.client.fetch('/config', {
|
|
190
218
|
method: 'PATCH',
|
|
191
219
|
headers: { 'Content-Type': 'application/json' },
|
|
192
220
|
body: JSON.stringify({
|
|
193
|
-
provider:
|
|
194
|
-
pollinations: {
|
|
195
|
-
id: 'openai',
|
|
196
|
-
name: `Pollinations AI (v${version})`,
|
|
197
|
-
options: {
|
|
198
|
-
baseURL: localBaseUrl,
|
|
199
|
-
apiKey: 'plugin-managed',
|
|
200
|
-
},
|
|
201
|
-
models: modelsObj
|
|
202
|
-
}
|
|
203
|
-
}
|
|
221
|
+
provider: currentConfig.provider
|
|
204
222
|
})
|
|
205
223
|
});
|
|
206
224
|
log(`[Event] Provider config refreshed with ${Object.keys(modelsObj).length} models.`);
|
|
@@ -208,21 +226,17 @@ export const PollinationsPlugin = async (ctx) => {
|
|
|
208
226
|
catch (e) {
|
|
209
227
|
log(`[Event] Failed to refresh provider config: ${e}`);
|
|
210
228
|
}
|
|
229
|
+
finally {
|
|
230
|
+
// Debounce: prevent another refresh for 5 seconds
|
|
231
|
+
setTimeout(() => { isRefreshing = false; }, 5000);
|
|
232
|
+
}
|
|
211
233
|
};
|
|
212
234
|
return {
|
|
213
235
|
// AUTH HOOK: Native /connect integration
|
|
214
236
|
auth: createAuthHook(),
|
|
215
|
-
// EVENT HOOK: Listen for
|
|
237
|
+
// EVENT HOOK: Listen ONLY for explicit /connect command
|
|
238
|
+
// We removed installation.updated/server.connected because they caused infinite loops
|
|
216
239
|
event: async ({ event }) => {
|
|
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}`);
|
|
221
|
-
await refreshProviderConfig();
|
|
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
240
|
if (event.type === 'tui.command.execute') {
|
|
227
241
|
const cmd = event.command || event.data?.command;
|
|
228
242
|
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.24",
|
|
5
5
|
"description": "Native Pollinations.ai Provider Plugin for OpenCode",
|
|
6
6
|
"publisher": "pollinations",
|
|
7
7
|
"repository": {
|