@@ -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-
5347export 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 ) {
0 commit comments