converse-mcp-server 2.5.1 → 2.5.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.
- package/package.json +1 -1
- package/src/providers/gemini-cli.js +67 -2
package/package.json
CHANGED
|
@@ -202,6 +202,68 @@ function mapFinishReason(finishReason) {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/**
|
|
206
|
+
* Convert messages from Converse internal format to Gemini CLI SDK format
|
|
207
|
+
*
|
|
208
|
+
* Converse format (used by other providers like Anthropic):
|
|
209
|
+
* - Images: { type: 'image', source: { type: 'base64', media_type: '...', data: '...' } }
|
|
210
|
+
*
|
|
211
|
+
* Gemini CLI SDK format (from SDK guide):
|
|
212
|
+
* - Images: { type: 'image', data: '...' } (base64 string)
|
|
213
|
+
* - Text: { type: 'text', text: '...' }
|
|
214
|
+
*
|
|
215
|
+
* @param {Array} messages - Messages in Converse internal format
|
|
216
|
+
* @returns {Array} Messages in Gemini CLI SDK format
|
|
217
|
+
*/
|
|
218
|
+
function convertToGeminiCliMessages(messages) {
|
|
219
|
+
return messages.map((message) => {
|
|
220
|
+
// If content is a string, no conversion needed
|
|
221
|
+
if (typeof message.content === 'string') {
|
|
222
|
+
return message;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// If content is an array, convert each part
|
|
226
|
+
if (Array.isArray(message.content)) {
|
|
227
|
+
const convertedContent = message.content.map((part) => {
|
|
228
|
+
// Text parts are already in correct format
|
|
229
|
+
if (part.type === 'text') {
|
|
230
|
+
return part;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Convert image from Converse format to Gemini CLI SDK format
|
|
234
|
+
if (part.type === 'image' && part.source) {
|
|
235
|
+
return {
|
|
236
|
+
type: 'image',
|
|
237
|
+
data: part.source.data, // Extract base64 data (use 'data' not 'image')
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// If already in Gemini CLI format, return as-is
|
|
242
|
+
if (part.type === 'image' && part.data) {
|
|
243
|
+
return part;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Handle file parts (future-proofing)
|
|
247
|
+
if (part.type === 'file' && part.data) {
|
|
248
|
+
return part;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// Unknown part type, return as-is and let SDK handle it
|
|
252
|
+
debugLog(`[Gemini CLI] Unknown content part type: ${part.type}`);
|
|
253
|
+
return part;
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
return {
|
|
257
|
+
...message,
|
|
258
|
+
content: convertedContent,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Unknown content type, return as-is
|
|
263
|
+
return message;
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
205
267
|
/**
|
|
206
268
|
* Gemini CLI Provider Implementation
|
|
207
269
|
*/
|
|
@@ -264,9 +326,12 @@ export const geminiCliProvider = {
|
|
|
264
326
|
// Create model instance with SDK model name
|
|
265
327
|
const modelInstance = gemini(sdkModelName);
|
|
266
328
|
|
|
329
|
+
// Convert messages from Converse format to Gemini CLI SDK format
|
|
330
|
+
const convertedMessages = convertToGeminiCliMessages(messages);
|
|
331
|
+
|
|
267
332
|
// Build AI SDK options
|
|
268
333
|
const aiOptions = {
|
|
269
|
-
messages,
|
|
334
|
+
messages: convertedMessages,
|
|
270
335
|
};
|
|
271
336
|
|
|
272
337
|
// Add optional parameters
|
|
@@ -291,7 +356,7 @@ export const geminiCliProvider = {
|
|
|
291
356
|
if (stream) {
|
|
292
357
|
return createStreamingGenerator(
|
|
293
358
|
modelInstance,
|
|
294
|
-
|
|
359
|
+
convertedMessages,
|
|
295
360
|
aiOptions,
|
|
296
361
|
signal,
|
|
297
362
|
model, // Pass user-facing model name for metadata
|