opencode-pollinations-plugin 6.1.0-beta.7 → 6.1.0-beta.9

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.
@@ -124,7 +124,9 @@ function sanitizeForBedrock(body) {
124
124
  if (!body)
125
125
  return body;
126
126
  const sanitized = JSON.parse(JSON.stringify(body)); // Deep clone
127
- // 1. Sanitize toolUseId in all messages
127
+ // 1. Sanitize toolUseId in all messages AND detect tool history
128
+ let hasToolHistory = false;
129
+ const toolNamesFromHistory = [];
128
130
  if (sanitized.messages && Array.isArray(sanitized.messages)) {
129
131
  for (const msg of sanitized.messages) {
130
132
  if (msg.content && Array.isArray(msg.content)) {
@@ -132,31 +134,44 @@ function sanitizeForBedrock(body) {
132
134
  // Handle toolUse blocks
133
135
  if (block.toolUse && block.toolUse.toolUseId) {
134
136
  block.toolUse.toolUseId = sanitizeToolUseId(block.toolUse.toolUseId);
137
+ hasToolHistory = true;
138
+ if (block.toolUse.name)
139
+ toolNamesFromHistory.push(block.toolUse.name);
135
140
  }
136
141
  // Handle toolResult blocks
137
142
  if (block.toolResult && block.toolResult.toolUseId) {
138
143
  block.toolResult.toolUseId = sanitizeToolUseId(block.toolResult.toolUseId);
144
+ hasToolHistory = true;
139
145
  }
140
- // Handle OpenAI-style tool_calls
146
+ // Handle OpenAI-style tool_use in content array
141
147
  if (block.type === 'tool_use' && block.id) {
142
148
  block.id = sanitizeToolUseId(block.id);
149
+ hasToolHistory = true;
150
+ if (block.name)
151
+ toolNamesFromHistory.push(block.name);
143
152
  }
144
153
  }
145
154
  }
146
155
  // Handle assistant tool_calls array (OpenAI format)
147
156
  if (msg.tool_calls && Array.isArray(msg.tool_calls)) {
157
+ hasToolHistory = true;
148
158
  for (const tc of msg.tool_calls) {
149
159
  if (tc.id)
150
160
  tc.id = sanitizeToolUseId(tc.id);
161
+ if (tc.function?.name)
162
+ toolNamesFromHistory.push(tc.function.name);
151
163
  }
152
164
  }
153
165
  // Handle tool role message (OpenAI format)
154
- if (msg.role === 'tool' && msg.tool_call_id) {
155
- msg.tool_call_id = sanitizeToolUseId(msg.tool_call_id);
166
+ if (msg.role === 'tool') {
167
+ hasToolHistory = true;
168
+ if (msg.tool_call_id) {
169
+ msg.tool_call_id = sanitizeToolUseId(msg.tool_call_id);
170
+ }
156
171
  }
157
172
  }
158
173
  }
159
- // 2. Add toolConfig if tools present but toolConfig missing
174
+ // 2. Add toolConfig if tools present
160
175
  if (sanitized.tools && Array.isArray(sanitized.tools) && sanitized.tools.length > 0) {
161
176
  if (!sanitized.tool_config && !sanitized.toolConfig) {
162
177
  // Build toolConfig from tools array (Bedrock Converse format)
@@ -179,6 +194,44 @@ function sanitizeForBedrock(body) {
179
194
  };
180
195
  }
181
196
  }
197
+ // 3. CRITICAL: If no tools BUT history has tool calls, inject shim tools array
198
+ else if (hasToolHistory) {
199
+ // Bedrock requires toolConfig when history contains toolUse/toolResult
200
+ // Pollinations builds toolConfig from the 'tools' array, not from our 'tool_config'
201
+ // So we MUST inject 'tools' in OpenAI format, not just 'tool_config'
202
+ const uniqueToolNames = [...new Set(toolNamesFromHistory)];
203
+ // Build OpenAI-format tools array (this is what Pollinations actually uses!)
204
+ const shimTools = uniqueToolNames.length > 0
205
+ ? uniqueToolNames.map(name => ({
206
+ type: 'function',
207
+ function: {
208
+ name: name,
209
+ description: 'Tool inferred from conversation history (Bedrock compatibility shim)',
210
+ parameters: { type: 'object', properties: {} }
211
+ }
212
+ }))
213
+ : [{
214
+ type: 'function',
215
+ function: {
216
+ name: '_bedrock_shim_tool',
217
+ description: 'Internal shim to satisfy Bedrock toolConfig requirement',
218
+ parameters: { type: 'object', properties: {} }
219
+ }
220
+ }];
221
+ // Inject the tools array (Pollinations format)
222
+ sanitized.tools = shimTools;
223
+ // Also set tool_config for direct Bedrock passthrough (belt & suspenders)
224
+ sanitized.tool_config = {
225
+ tools: shimTools.map(t => ({
226
+ toolSpec: {
227
+ name: t.function.name,
228
+ description: t.function.description,
229
+ inputSchema: { json: t.function.parameters }
230
+ }
231
+ }))
232
+ };
233
+ log(`[Bedrock Shim] Injected ${shimTools.length} shim tool(s) for history compatibility: [${uniqueToolNames.join(', ') || '_bedrock_shim_tool'}]`);
234
+ }
182
235
  return sanitized;
183
236
  }
184
237
  const MAX_RETRIES = 3;
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.1.0-beta.7",
4
+ "version": "6.1.0-beta.9",
5
5
  "description": "Native Pollinations.ai Provider Plugin for OpenCode",
6
6
  "publisher": "pollinations",
7
7
  "repository": {