opencode-pollinations-plugin 5.8.1 → 5.8.2

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.
@@ -8,6 +8,10 @@ interface OpenCodeModel {
8
8
  context?: number;
9
9
  output?: number;
10
10
  };
11
+ modalities?: {
12
+ input?: string[];
13
+ output?: string[];
14
+ };
11
15
  }
12
16
  export declare function generatePollinationsConfig(forceApiKey?: string, forceStrict?: boolean): Promise<OpenCodeModel[]>;
13
17
  export {};
@@ -61,33 +61,69 @@ function formatName(id, censored = true) {
61
61
  export async function generatePollinationsConfig(forceApiKey, forceStrict = false) {
62
62
  const config = loadConfig();
63
63
  const modelsOutput = [];
64
- log(`Starting Configuration (v5.8.1)...`);
64
+ log(`Starting Configuration (v5.8.2)...`);
65
65
  // Use forced key (from Hook) or cached key
66
66
  const effectiveKey = forceApiKey || config.apiKey;
67
67
  // 1. FREE UNIVERSE
68
68
  try {
69
- // Switch to main models endpoint (User provided curl confirms it has 'description')
69
+ // Switch to main models endpoint
70
70
  const freeList = await fetchJson('https://text.pollinations.ai/models');
71
71
  const list = Array.isArray(freeList) ? freeList : (freeList.data || []);
72
- list.forEach((m) => {
73
- const mapped = mapModel(m, 'free/', '[Free] ');
74
- modelsOutput.push(mapped);
75
- });
76
- log(`Fetched ${modelsOutput.length} Free models.`);
72
+ if (list.length > 0) {
73
+ list.forEach((m) => {
74
+ const mapped = mapModel(m, 'free/', '[Free] ');
75
+ modelsOutput.push(mapped);
76
+ });
77
+ log(`Fetched ${modelsOutput.length} Free models.`);
78
+ }
79
+ else {
80
+ throw new Error('Empty list returned from Free API');
81
+ }
77
82
  }
78
83
  catch (e) {
79
84
  log(`Error fetching Free models: ${e}`);
80
- // Fallback Robust (Offline support)
81
- modelsOutput.push({ id: "free/mistral", name: "[Free] Mistral Nemo (Fallback)", object: "model", variants: {} });
82
- modelsOutput.push({ id: "free/openai", name: "[Free] OpenAI (Fallback)", object: "model", variants: {} });
83
- modelsOutput.push({ id: "free/gemini", name: "[Free] Gemini Flash (Fallback)", object: "model", variants: {} });
85
+ // Fallback Robust (Offline support) - NOW WITH ICONS
86
+ modelsOutput.push({
87
+ id: "free/mistral",
88
+ name: "[Free] Mistral Nemo (Fallback) 💻",
89
+ object: "model",
90
+ variants: { safe_tokens: { options: { maxTokens: 8000 } } },
91
+ modalities: { input: ['text'], output: ['text'] }
92
+ });
93
+ modelsOutput.push({
94
+ id: "free/openai",
95
+ name: "[Free] OpenAI (Fallback) 👁️💻",
96
+ object: "model",
97
+ variants: {},
98
+ modalities: { input: ['text', 'image'], output: ['text'] }
99
+ });
100
+ modelsOutput.push({
101
+ id: "free/gemini",
102
+ name: "[Free] Gemini Flash (Fallback) 👁️💻",
103
+ object: "model",
104
+ variants: { high_reasoning: { options: { reasoningEffort: "high", budgetTokens: 16000 } } },
105
+ modalities: { input: ['text', 'image'], output: ['text'] }
106
+ });
107
+ modelsOutput.push({
108
+ id: "free/searchgpt",
109
+ name: "[Free] SearchGPT (Fallback) 🔍",
110
+ object: "model",
111
+ variants: {},
112
+ modalities: { input: ['text'], output: ['text'] }
113
+ });
84
114
  }
85
115
  // 1.5 FORCE ENSURE CRITICAL MODELS
86
116
  // Sometimes the API list changes or is cached weirdly. We force vital models.
87
117
  const hasGemini = modelsOutput.find(m => m.id === 'free/gemini');
88
118
  if (!hasGemini) {
89
119
  log(`[ConfigGen] Force-injecting free/gemini.`);
90
- modelsOutput.push({ id: "free/gemini", name: "[Free] Gemini Flash (Force)", object: "model", variants: {} });
120
+ modelsOutput.push({
121
+ id: "free/gemini",
122
+ name: "[Free] Gemini Flash (Force) 👁️💻",
123
+ object: "model",
124
+ variants: {},
125
+ modalities: { input: ['text', 'image'], output: ['text'] }
126
+ });
91
127
  }
92
128
  // ALIAS Removed for Clean Config
93
129
  // const hasGeminiAlias = modelsOutput.find(m => m.id === 'pollinations/free/gemini');
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": "5.8.1",
4
+ "version": "5.8.2",
5
5
  "description": "Native Pollinations.ai Provider Plugin for OpenCode",
6
6
  "publisher": "pollinations",
7
7
  "repository": {
@@ -1,36 +0,0 @@
1
- import * as https from 'https';
2
-
3
- function checkEndpoint(ep, key) {
4
- return new Promise((resolve) => {
5
- console.log(`Checking ${ep}...`);
6
- const req = https.request({
7
- hostname: 'gen.pollinations.ai',
8
- path: ep,
9
- method: 'GET',
10
- headers: { 'Authorization': `Bearer ${key}` }
11
- }, (res) => {
12
- console.log(`Status Code: ${res.statusCode}`);
13
- let data = '';
14
- res.on('data', chunk => data += chunk);
15
- res.on('end', () => {
16
- console.log(`Headers:`, res.headers);
17
- console.log(`Body Full: ${data}`);
18
- if (res.statusCode === 200) resolve({ ok: true, body: data });
19
- else resolve({ ok: false, status: res.statusCode, body: data });
20
- });
21
- });
22
- req.on('error', (e) => {
23
- console.log(`Error: ${e.message}`);
24
- resolve({ ok: false, status: e.message || 'Error' });
25
- });
26
- req.setTimeout(10000, () => req.destroy());
27
- req.end();
28
- });
29
- }
30
-
31
- const KEY = "plln_sk_F7a4RcBG4AVCeBSo6lnS36EKwm0nPn1O";
32
-
33
- (async () => {
34
- const res = await checkEndpoint('/account/profile', KEY);
35
- console.log('Result:', res);
36
- })();
@@ -1 +0,0 @@
1
- export declare const createPollinationsFetch: (apiKey: string) => (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
package/dist/provider.js DELETED
@@ -1,135 +0,0 @@
1
- // Removed invalid imports
2
- import * as fs from 'fs';
3
- // --- Sanitization Helpers (Ported from Gateway/Upstream) ---
4
- function safeId(id) {
5
- if (!id)
6
- return id;
7
- if (id.length > 30)
8
- return id.substring(0, 30);
9
- return id;
10
- }
11
- function logDebug(message, data) {
12
- try {
13
- const timestamp = new Date().toISOString();
14
- let logMsg = `[${timestamp}] ${message}`;
15
- if (data) {
16
- logMsg += `\n${JSON.stringify(data, null, 2)}`;
17
- }
18
- fs.appendFileSync('/tmp/opencode_pollinations_debug.log', logMsg + '\n\n');
19
- }
20
- catch (e) {
21
- // ignore logging errors
22
- }
23
- }
24
- function sanitizeTools(tools) {
25
- if (!Array.isArray(tools))
26
- return tools;
27
- const cleanSchema = (schema) => {
28
- if (!schema || typeof schema !== "object")
29
- return;
30
- if (schema.optional !== undefined)
31
- delete schema.optional;
32
- if (schema.ref !== undefined)
33
- delete schema.ref;
34
- if (schema["$ref"] !== undefined)
35
- delete schema["$ref"];
36
- if (schema.properties) {
37
- for (const key in schema.properties)
38
- cleanSchema(schema.properties[key]);
39
- }
40
- if (schema.items)
41
- cleanSchema(schema.items);
42
- };
43
- return tools.map((tool) => {
44
- const newTool = { ...tool };
45
- if (newTool.function && newTool.function.parameters) {
46
- cleanSchema(newTool.function.parameters);
47
- }
48
- return newTool;
49
- });
50
- }
51
- function filterTools(tools, maxCount = 120) {
52
- if (!Array.isArray(tools))
53
- return [];
54
- if (tools.length <= maxCount)
55
- return tools;
56
- const priorities = [
57
- "bash", "read", "write", "edit", "webfetch", "glob", "grep",
58
- "searxng_remote_search", "deepsearch_deep_search", "google_search",
59
- "task", "todowrite"
60
- ];
61
- const priorityTools = tools.filter((t) => priorities.includes(t.function.name));
62
- const otherTools = tools.filter((t) => !priorities.includes(t.function.name));
63
- const slotsLeft = maxCount - priorityTools.length;
64
- const othersKept = otherTools.slice(0, Math.max(0, slotsLeft));
65
- logDebug(`[POLLI-PLUGIN] Filtering tools: ${tools.length} -> ${priorityTools.length + othersKept.length}`);
66
- return [...priorityTools, ...othersKept];
67
- }
68
- // --- Fetch Implementation ---
69
- export const createPollinationsFetch = (apiKey) => async (input, init) => {
70
- let url = input.toString();
71
- const options = init || {};
72
- let body = null;
73
- if (options.body && typeof options.body === "string") {
74
- try {
75
- body = JSON.parse(options.body);
76
- }
77
- catch (e) {
78
- // Not JSON, ignore
79
- }
80
- }
81
- // --- INTERCEPTION & SANITIZATION ---
82
- if (body) {
83
- let model = body.model || "";
84
- // 0. Model Name Normalization
85
- if (typeof model === "string" && model.startsWith("pollinations/enter/")) {
86
- body.model = model.replace("pollinations/enter/", "");
87
- model = body.model;
88
- }
89
- // FIX: Remove stream_options (causes 400 on some OpenAI proxies)
90
- if (body.stream_options) {
91
- delete body.stream_options;
92
- }
93
- // 1. Azure Tool Limit Fix
94
- if ((model.includes("openai") || model.includes("gpt")) && body.tools) {
95
- if (body.tools.length > 120) {
96
- body.tools = filterTools(body.tools, 120);
97
- }
98
- }
99
- // 2. Vertex/Gemini Schema Fix
100
- if (model.includes("gemini") && body.tools) {
101
- body.tools = sanitizeTools(body.tools);
102
- }
103
- // Re-serialize body
104
- options.body = JSON.stringify(body);
105
- }
106
- // Ensure Headers
107
- const headers = new Headers(options.headers || {});
108
- headers.set("Authorization", `Bearer ${apiKey}`);
109
- headers.set("Content-Type", "application/json");
110
- options.headers = headers;
111
- logDebug(`Req: ${url}`, body);
112
- try {
113
- const response = await global.fetch(url, options);
114
- // Log response status
115
- // We clone to read text for debugging errors
116
- if (!response.ok) {
117
- try {
118
- const clone = response.clone();
119
- const text = await clone.text();
120
- logDebug(`Res (Error): ${response.status}`, text);
121
- }
122
- catch (e) {
123
- logDebug(`Res (Error): ${response.status} (Read failed)`);
124
- }
125
- }
126
- else {
127
- logDebug(`Res (OK): ${response.status}`);
128
- }
129
- return response;
130
- }
131
- catch (e) {
132
- logDebug(`Fetch Error: ${e.message}`);
133
- throw e;
134
- }
135
- };
@@ -1 +0,0 @@
1
- export declare const createPollinationsFetch: (apiKey: string) => (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
@@ -1,135 +0,0 @@
1
- // Removed invalid imports
2
- import * as fs from 'fs';
3
- // --- Sanitization Helpers (Ported from Gateway/Upstream) ---
4
- function safeId(id) {
5
- if (!id)
6
- return id;
7
- if (id.length > 30)
8
- return id.substring(0, 30);
9
- return id;
10
- }
11
- function logDebug(message, data) {
12
- try {
13
- const timestamp = new Date().toISOString();
14
- let logMsg = `[${timestamp}] ${message}`;
15
- if (data) {
16
- logMsg += `\n${JSON.stringify(data, null, 2)}`;
17
- }
18
- fs.appendFileSync('/tmp/opencode_pollinations_debug.log', logMsg + '\n\n');
19
- }
20
- catch (e) {
21
- // ignore logging errors
22
- }
23
- }
24
- function sanitizeTools(tools) {
25
- if (!Array.isArray(tools))
26
- return tools;
27
- const cleanSchema = (schema) => {
28
- if (!schema || typeof schema !== "object")
29
- return;
30
- if (schema.optional !== undefined)
31
- delete schema.optional;
32
- if (schema.ref !== undefined)
33
- delete schema.ref;
34
- if (schema["$ref"] !== undefined)
35
- delete schema["$ref"];
36
- if (schema.properties) {
37
- for (const key in schema.properties)
38
- cleanSchema(schema.properties[key]);
39
- }
40
- if (schema.items)
41
- cleanSchema(schema.items);
42
- };
43
- return tools.map((tool) => {
44
- const newTool = { ...tool };
45
- if (newTool.function && newTool.function.parameters) {
46
- cleanSchema(newTool.function.parameters);
47
- }
48
- return newTool;
49
- });
50
- }
51
- function filterTools(tools, maxCount = 120) {
52
- if (!Array.isArray(tools))
53
- return [];
54
- if (tools.length <= maxCount)
55
- return tools;
56
- const priorities = [
57
- "bash", "read", "write", "edit", "webfetch", "glob", "grep",
58
- "searxng_remote_search", "deepsearch_deep_search", "google_search",
59
- "task", "todowrite"
60
- ];
61
- const priorityTools = tools.filter((t) => priorities.includes(t.function.name));
62
- const otherTools = tools.filter((t) => !priorities.includes(t.function.name));
63
- const slotsLeft = maxCount - priorityTools.length;
64
- const othersKept = otherTools.slice(0, Math.max(0, slotsLeft));
65
- logDebug(`[POLLI-PLUGIN] Filtering tools: ${tools.length} -> ${priorityTools.length + othersKept.length}`);
66
- return [...priorityTools, ...othersKept];
67
- }
68
- // --- Fetch Implementation ---
69
- export const createPollinationsFetch = (apiKey) => async (input, init) => {
70
- let url = input.toString();
71
- const options = init || {};
72
- let body = null;
73
- if (options.body && typeof options.body === "string") {
74
- try {
75
- body = JSON.parse(options.body);
76
- }
77
- catch (e) {
78
- // Not JSON, ignore
79
- }
80
- }
81
- // --- INTERCEPTION & SANITIZATION ---
82
- if (body) {
83
- let model = body.model || "";
84
- // 0. Model Name Normalization
85
- if (typeof model === "string" && model.startsWith("pollinations/enter/")) {
86
- body.model = model.replace("pollinations/enter/", "");
87
- model = body.model;
88
- }
89
- // FIX: Remove stream_options (causes 400 on some OpenAI proxies)
90
- if (body.stream_options) {
91
- delete body.stream_options;
92
- }
93
- // 1. Azure Tool Limit Fix
94
- if ((model.includes("openai") || model.includes("gpt")) && body.tools) {
95
- if (body.tools.length > 120) {
96
- body.tools = filterTools(body.tools, 120);
97
- }
98
- }
99
- // 2. Vertex/Gemini Schema Fix
100
- if (model.includes("gemini") && body.tools) {
101
- body.tools = sanitizeTools(body.tools);
102
- }
103
- // Re-serialize body
104
- options.body = JSON.stringify(body);
105
- }
106
- // Ensure Headers
107
- const headers = new Headers(options.headers || {});
108
- headers.set("Authorization", `Bearer ${apiKey}`);
109
- headers.set("Content-Type", "application/json");
110
- options.headers = headers;
111
- logDebug(`Req: ${url}`, body);
112
- try {
113
- const response = await global.fetch(url, options);
114
- // Log response status
115
- // We clone to read text for debugging errors
116
- if (!response.ok) {
117
- try {
118
- const clone = response.clone();
119
- const text = await clone.text();
120
- logDebug(`Res (Error): ${response.status}`, text);
121
- }
122
- catch (e) {
123
- logDebug(`Res (Error): ${response.status} (Read failed)`);
124
- }
125
- }
126
- else {
127
- logDebug(`Res (OK): ${response.status}`);
128
- }
129
- return response;
130
- }
131
- catch (e) {
132
- logDebug(`Fetch Error: ${e.message}`);
133
- throw e;
134
- }
135
- };
@@ -1,9 +0,0 @@
1
- import { createRequire } from 'module';
2
- const require = createRequire(import.meta.url);
3
- try {
4
- const pkg = require('../package.json');
5
- console.log("SUCCESS: Loaded version " + pkg.version);
6
- } catch (e) {
7
- console.error("FAILURE:", e.message);
8
- process.exit(1);
9
- }