Skip to content

Commit e6ec8a8

Browse files
Merge pull request #141 from SmythOS/dev
Dev merge : MCP hotfix
2 parents b10b3e6 + b959857 commit e6ec8a8

File tree

21 files changed

+346
-111
lines changed

21 files changed

+346
-111
lines changed

.gitattributes

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,4 @@
1010
# Mark binary files
1111
*.png binary
1212
*.jpg binary
13-
*.gif binary
14-
*.exe binary
15-
*.dll binary
13+
*.gif binary

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@smythos/sre",
3-
"version": "1.5.66",
3+
"version": "1.5.67",
44
"description": "Smyth Runtime Environment",
55
"author": "Alaa-eddine KADDOURI",
66
"license": "MIT",

packages/core/src/Components/ImageGenerator.class.ts

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ const IMAGE_GEN_COST_MAP = {
4444
},
4545
};
4646

47-
// Imagen 4 cost map - fixed cost per image
48-
const IMAGEN_4_COST_MAP = {
49-
'imagen-4': 0.04, // Standard Imagen 4
50-
'imagen-4-ultra': 0.06, // Imagen 4 Ultra
51-
};
52-
5347
export class ImageGenerator extends Component {
5448
protected configSchema = Joi.object({
5549
model: Joi.string().max(100).required(),
@@ -344,11 +338,6 @@ const imageGenerator = {
344338

345339
const files: any[] = parseFiles(input, config);
346340

347-
// Imagen models only support image generation, not image editing
348-
if (files.length > 0) {
349-
throw new Error('Google AI Image Generation Error: Image editing is not supported. Imagen models only support image generation.');
350-
}
351-
352341
let args: GenerateImageConfig & {
353342
aspectRatio?: string;
354343
numberOfImages?: number;
@@ -360,29 +349,21 @@ const imageGenerator = {
360349
personGeneration: config?.data?.personGeneration || 'allow_adult',
361350
};
362351

363-
const response = await llmInference.imageGenRequest({ query: prompt, params: { ...args, agentId: agent.id } });
364-
365-
// Calculate fixed cost for Imagen 4
366-
const modelName = model.replace(BUILT_IN_MODEL_PREFIX, '');
367-
const cost = IMAGEN_4_COST_MAP[modelName];
368-
369-
if (cost && cost > 0) {
370-
// Multiply by number of images generated
371-
const numberOfImages = args.numberOfImages || 1;
372-
const totalCost = cost * numberOfImages;
373-
374-
// Report fixed cost usage
375-
imageGenerator.reportUsage(
376-
{ cost: totalCost },
377-
{
378-
modelEntryName: model,
379-
keySource: model.startsWith(BUILT_IN_MODEL_PREFIX) ? APIKeySource.Smyth : APIKeySource.User,
380-
agentId: agent.id,
381-
teamId: agent.teamId,
382-
}
383-
);
352+
let response;
353+
354+
// Check if files are provided for image editing
355+
if (files.length > 0) {
356+
const validFiles = files.filter((file) => imageGenerator.isValidImageFile('GoogleAI', file.mimetype));
357+
if (validFiles.length === 0) {
358+
throw new Error('Supported image file types are: ' + SUPPORTED_MIME_TYPES_MAP.GoogleAI?.image?.join(', '));
359+
}
360+
response = await llmInference.imageEditRequest({ query: prompt, files: validFiles, params: { ...args, agentId: agent.id } });
361+
} else {
362+
response = await llmInference.imageGenRequest({ query: prompt, params: { ...args, agentId: agent.id } });
384363
}
385364

365+
// Usage reporting is now handled in the GoogleAI connector
366+
386367
let output = response?.data?.[0]?.b64_json;
387368

388369
if (output) {

packages/core/src/helpers/Conversation.helper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ export class Conversation extends EventEmitter {
281281
let _content = '';
282282
const reqMethods = this._reqMethods;
283283
const toolsConfig = this._toolsConfig;
284+
//deduplicate tools
285+
toolsConfig.tools = toolsConfig.tools.filter((tool, index, self) => self.findIndex((t) => t.name === tool.name) === index);
284286
const endpoints = this._endpoints;
285287
const baseUrl = this._baseUrl;
286288
const message_id = 'msg_' + randomUUID();

0 commit comments

Comments
 (0)