opencode-pollinations-plugin 6.4.6 → 6.4.8

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 (34) hide show
  1. package/README.de.md +3 -0
  2. package/README.es.md +3 -0
  3. package/README.fr.md +3 -0
  4. package/README.it.md +3 -0
  5. package/README.md +4 -1
  6. package/README.zh.md +3 -0
  7. package/dist/locales/de.json +17 -2
  8. package/dist/locales/en.json +17 -2
  9. package/dist/locales/es.json +17 -2
  10. package/dist/locales/fr.json +17 -2
  11. package/dist/locales/it.json +17 -2
  12. package/dist/locales/zh.json +17 -2
  13. package/dist/server/quota.js +10 -10
  14. package/dist/server/toast.d.ts +1 -0
  15. package/dist/server/toast.js +7 -2
  16. package/dist/tools/index.js +8 -0
  17. package/dist/tools/pollinations/gen_edit_image_free.js +4 -3
  18. package/dist/tools/pollinations/gen_video_free.js +3 -2
  19. package/dist/tools/pollinations/image_enhancer.d.ts +2 -0
  20. package/dist/tools/pollinations/image_enhancer.js +62 -0
  21. package/dist/tools/pollinations/image_upscaler.d.ts +2 -0
  22. package/dist/tools/pollinations/image_upscaler.js +61 -0
  23. package/dist/tools/pollinations/imgtools/clients.d.ts +11 -0
  24. package/dist/tools/pollinations/imgtools/clients.js +182 -0
  25. package/dist/tools/pollinations/imgtools/config.d.ts +42 -0
  26. package/dist/tools/pollinations/imgtools/config.js +81 -0
  27. package/dist/tools/pollinations/imgtools/crypto.d.ts +4 -0
  28. package/dist/tools/pollinations/imgtools/crypto.js +34 -0
  29. package/dist/tools/pollinations/imgtools/helpers.d.ts +24 -0
  30. package/dist/tools/pollinations/imgtools/helpers.js +111 -0
  31. package/dist/tools/pollinations/object_remover.d.ts +2 -0
  32. package/dist/tools/pollinations/object_remover.js +62 -0
  33. package/dist/tools/power/remove_background.js +16 -60
  34. package/package.json +1 -1
@@ -4,12 +4,11 @@ import * as https from 'https';
4
4
  import * as fs from 'fs';
5
5
  import * as path from 'path';
6
6
  import { resolveOutputDir, formatFileSize, TOOL_DIRS } from '../shared.js';
7
- import { sanitizeFilename } from '../pollinations/shared.js';
7
+ import { sanitizeFilename, httpsGet } from '../pollinations/shared.js';
8
+ import { processTool } from '../pollinations/imgtools/clients.js';
8
9
  import { getConfigDir } from '../../server/config.js';
9
10
  // ─── Provider Defaults ───────────────────────────────────────────────────────
10
- const CUT_API_URL = 'https://cut.esprit-artificiel.com';
11
11
  const BACKGROUNDCUT_API_URL = 'https://backgroundcut.co/api/v1/cut/';
12
- const HMAC_SECRET = "super_secret_community_key_2026"; // Sel caché dans le code transpilé
13
12
  // ─── Key Storage ─────────────────────────────────────────────────────────────
14
13
  const KEYS_FILE = path.join(getConfigDir(), 'backgroundcut_keys.json');
15
14
  function loadKeys() {
@@ -103,56 +102,11 @@ function getImageSize(filePath) {
103
102
  }
104
103
  return null;
105
104
  }
106
- // ─── Provider: cut.esprit-artificiel.com (returns binary PNG directly) ────────
107
- async function removeViaCut(imageData, filename, mimeType) {
108
- const boundary = `----FormBoundary${Date.now()}`;
109
- const parts = [];
110
- parts.push(Buffer.from(`--${boundary}\r\nContent-Disposition: form-data; name="file"; filename="${filename}"\r\nContent-Type: ${mimeType}\r\n\r\n`));
111
- parts.push(imageData);
112
- parts.push(Buffer.from(`\r\n--${boundary}--\r\n`));
113
- const body = Buffer.concat(parts);
114
- const url = new URL(`${CUT_API_URL}/remove-bg`);
115
- const headers = {
116
- 'Content-Type': `multipart/form-data; boundary=${boundary}`,
117
- 'Content-Length': body.length,
118
- 'User-Agent': 'OpenCode-Pollinations-Plugin/6.1',
119
- };
120
- // 1. Vérifier si l'utilisateur (Franck) a configuré une clé VIP localement
121
- let vipKey = null;
122
- try {
123
- const vipPath = path.join(getConfigDir(), 'cut_vip.json');
124
- if (fs.existsSync(vipPath)) {
125
- const data = JSON.parse(fs.readFileSync(vipPath, 'utf-8'));
126
- if (data.vip_key)
127
- vipKey = data.vip_key;
128
- }
129
- }
130
- catch (e) {
131
- console.error(`[Cut VIP] Error loading vip key: ${e}`);
132
- }
133
- if (vipKey) {
134
- // Mode Fast-Lane (VIP) : la requête passe directement en tête de file
135
- headers['X-Api-Key'] = vipKey;
136
- }
137
- else {
138
- // Mode Communauté (Plugin public) : Génération de la signature dynamique courte durée (Anti-leech)
139
- const timestamp = Date.now().toString();
140
- const payloadToSign = `request-rembg-v1:${timestamp}`;
141
- const signature = require('crypto')
142
- .createHmac('sha256', HMAC_SECRET)
143
- .update(payloadToSign)
144
- .digest('hex');
145
- headers['X-Cut-Timestamp'] = timestamp;
146
- headers['Authorization'] = `Bearer community:${signature}`;
147
- }
148
- const res = await httpRequest(url.toString(), {
149
- method: 'POST',
150
- headers
151
- }, body);
152
- if (res.statusCode >= 400) {
153
- throw new Error(`CUT API Error ${res.statusCode}: ${res.body.toString().substring(0, 200)}`);
154
- }
155
- return res.body;
105
+ // ─── Provider: imgtools/rmbg (bgeraser.com) ──────────────────────────────
106
+ async function removeViaImgtools(imageData, mimeType, filename) {
107
+ const result = await processTool('rmbg', { data: imageData, contentType: mimeType, filename });
108
+ const res = await httpsGet(result.imageUrl);
109
+ return res.data;
156
110
  }
157
111
  // ─── Provider: BackgroundCut.co (returns JSON with output_image_url) ─────────
158
112
  async function removeViaBackgroundCut(imageData, filename, mimeType, apiKey, quality = 'medium', returnFormat = 'png', maxResolution) {
@@ -204,11 +158,11 @@ export const removeBackgroundTool = tool({
204
158
  description: `Remove the background from an image, producing a transparent PNG or WebP.
205
159
 
206
160
  **Providers:**
207
- - \`cut\` (default free) — Built-in u2netp AI. Slower. Ignores quality/format/resolution.
161
+ - \`imgtools\` (default) — rmbg via bgeraser.com. Free.
208
162
  - \`backgroundcut\` — Premium API. Requires API key. Supports all parameters.
209
163
 
210
164
  **Setup:** Use \`rmbg_keys\` tool to manage API keys.
211
- **Auto mode:** Uses BackgroundCut if key is available, falls back to cut.`,
165
+ **Auto mode:** Uses imgtools by default, falls back to BackgroundCut if key is available.`,
212
166
  args: {
213
167
  image_path: tool.schema.string().describe('Absolute path to the image file'),
214
168
  filename: tool.schema.string().optional().describe('Custom output filename (e.g. "my_image.png") or name without extension'),
@@ -253,7 +207,7 @@ export const removeBackgroundTool = tool({
253
207
  let effectiveProvider = provider;
254
208
  if (provider === 'auto') {
255
209
  // If we have keys, start with backgroundcut, else cut
256
- effectiveProvider = keysToCheck.length > 0 ? 'backgroundcut' : 'cut';
210
+ effectiveProvider = 'imgtools'; // Default to imgtools (free, no key needed)
257
211
  }
258
212
  // ── Info message when no BackgroundCut key ──
259
213
  if (keysToCheck.length === 0 && (provider === 'auto' || provider === 'backgroundcut')) {
@@ -303,7 +257,7 @@ export const removeBackgroundTool = tool({
303
257
  // ── Execute ──
304
258
  try {
305
259
  let resultBuffer = null;
306
- let usedProvider = 'cut'; // Default
260
+ let usedProvider = 'imgtools'; // Default
307
261
  let fallbackUsed = false;
308
262
  let successKey = '';
309
263
  // 1. Try BackgroundCut loop if applicable
@@ -353,12 +307,13 @@ export const removeBackgroundTool = tool({
353
307
  else {
354
308
  emitStatusToast('info', `Détourage via API Gratuite: ${basename}`, '✂️ Free RMBG');
355
309
  }
356
- resultBuffer = await removeViaCut(imageData, basename, mimeType);
310
+ emitStatusToast('info', `Détourage via rmbg (bgeraser.com): ${basename}`, '✂️ Free RMBG', { freeTool: true });
311
+ resultBuffer = await removeViaImgtools(imageData, mimeType, basename);
357
312
  context.metadata({
358
313
  title: "RMBG (Free)",
359
- metadata: { type: 'success', message: "Détourage Standard réussi" }
314
+ metadata: { type: 'success', message: "Background removed (imgtools/rmbg)" }
360
315
  });
361
- usedProvider = 'cut (free)';
316
+ usedProvider = 'imgtools';
362
317
  }
363
318
  if (!resultBuffer || resultBuffer.length < 100) {
364
319
  return `❌ Background removal returned invalid data.`;
@@ -371,6 +326,7 @@ export const removeBackgroundTool = tool({
371
326
  }
372
327
  const dims = getImageSize(finalPath);
373
328
  const dimStr = dims ? `${dims.width}×${dims.height}` : 'N/A';
329
+ emitStatusToast('success', `✂️ Fond supprimé · ${usedProvider}`, 'remove_background', { filePath: finalPath, freeTool: true });
374
330
  const lines = [
375
331
  `✂️ Background Removed`,
376
332
  `━━━━━━━━━━━━━━━━━━━━━`,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opencode-pollinations-plugin",
3
3
  "displayName": "Pollinations",
4
- "version": "6.4.6",
4
+ "version": "6.4.8",
5
5
  "description": "Native Pollinations.ai Provider Plugin for OpenCode",
6
6
  "publisher": "pollinations",
7
7
  "repository": {