opencode-pollinations-plugin 5.9.0 → 6.0.0-beta.1

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.
@@ -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
- }