opencode-pollinations-plugin 6.0.0-beta.19 → 6.0.0-beta.21
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 +55 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -171,15 +171,69 @@ const createAuthHook = () => ({
|
|
|
171
171
|
// === PLUGIN EXPORT ===
|
|
172
172
|
export const PollinationsPlugin = async (ctx) => {
|
|
173
173
|
log(`Plugin Initializing v${require('../package.json').version}...`);
|
|
174
|
-
// START PROXY
|
|
174
|
+
// START PROXY on fixed port
|
|
175
175
|
const port = await startProxy();
|
|
176
176
|
const localBaseUrl = `http://127.0.0.1:${port}/v1`;
|
|
177
177
|
setGlobalClient(ctx.client);
|
|
178
178
|
const toastHooks = createToastHooks(ctx.client);
|
|
179
179
|
const commandHooks = createCommandHooks();
|
|
180
|
+
// Helper: Refresh provider config (for hot-reload after /connect)
|
|
181
|
+
const refreshProviderConfig = async () => {
|
|
182
|
+
try {
|
|
183
|
+
log('[Event] Refreshing provider config after auth update...');
|
|
184
|
+
const modelsArray = await generatePollinationsConfig();
|
|
185
|
+
const modelsObj = {};
|
|
186
|
+
for (const m of modelsArray) {
|
|
187
|
+
modelsObj[m.id] = m;
|
|
188
|
+
}
|
|
189
|
+
const version = require('../package.json').version;
|
|
190
|
+
// Use Server API to PATCH the config at runtime
|
|
191
|
+
await ctx.client.fetch('/config', {
|
|
192
|
+
method: 'PATCH',
|
|
193
|
+
headers: { 'Content-Type': 'application/json' },
|
|
194
|
+
body: JSON.stringify({
|
|
195
|
+
provider: {
|
|
196
|
+
pollinations: {
|
|
197
|
+
id: 'openai',
|
|
198
|
+
name: `Pollinations AI (v${version})`,
|
|
199
|
+
options: {
|
|
200
|
+
baseURL: localBaseUrl,
|
|
201
|
+
apiKey: 'plugin-managed',
|
|
202
|
+
},
|
|
203
|
+
models: modelsObj
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
})
|
|
207
|
+
});
|
|
208
|
+
log(`[Event] Provider config refreshed with ${Object.keys(modelsObj).length} models.`);
|
|
209
|
+
}
|
|
210
|
+
catch (e) {
|
|
211
|
+
log(`[Event] Failed to refresh provider config: ${e}`);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
180
214
|
return {
|
|
181
215
|
// AUTH HOOK: Native /connect integration
|
|
182
216
|
auth: createAuthHook(),
|
|
217
|
+
// EVENT HOOK: Listen for changes that might indicate /connect completed
|
|
218
|
+
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
|
+
if (event.type === 'tui.command.execute') {
|
|
229
|
+
const cmd = event.command || event.data?.command;
|
|
230
|
+
if (cmd === 'connect' || cmd === '/connect') {
|
|
231
|
+
log('[Event] /connect command detected - will refresh after auth hook completes');
|
|
232
|
+
// Small delay to let auth hook complete
|
|
233
|
+
setTimeout(() => refreshProviderConfig(), 2000);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
},
|
|
183
237
|
async config(config) {
|
|
184
238
|
log("[Hook] config() called");
|
|
185
239
|
// Generate models based on current auth state
|
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.21",
|
|
5
5
|
"description": "Native Pollinations.ai Provider Plugin for OpenCode",
|
|
6
6
|
"publisher": "pollinations",
|
|
7
7
|
"repository": {
|