@@ -27,7 +27,7 @@ import { logger } from 'genkit/logging';
27
27
import { modelRef } from 'genkit/model' ;
28
28
import { genkitPluginV2 , type GenkitPluginV2 } from 'genkit/plugin' ;
29
29
import type { ActionType } from 'genkit/registry' ;
30
- import { getApiKeyFromEnvVar } from './common.js ' ;
30
+ import { ensurePrefixed , getApiKeyFromEnvVar , removePrefix } from './common' ;
31
31
import {
32
32
SUPPORTED_MODELS as EMBEDDER_MODELS ,
33
33
GeminiEmbeddingConfigSchema ,
@@ -227,7 +227,7 @@ export function googleAIPlugin(options?: PluginOptions): GenkitPluginV2 {
227
227
Object . keys ( SUPPORTED_GEMINI_MODELS ) . forEach ( ( name ) => {
228
228
actions . push (
229
229
defineGoogleAIModel ( {
230
- name : `googleai/ ${ name } ` ,
230
+ name : ensurePrefixed ( name ) ,
231
231
apiKey : options ?. apiKey ,
232
232
apiVersion : 'v1beta' ,
233
233
baseUrl : options ?. baseUrl ,
@@ -241,7 +241,7 @@ export function googleAIPlugin(options?: PluginOptions): GenkitPluginV2 {
241
241
Object . keys ( SUPPORTED_GEMINI_MODELS ) . forEach ( ( name ) => {
242
242
actions . push (
243
243
defineGoogleAIModel ( {
244
- name : `googleai/ ${ name } ` ,
244
+ name : ensurePrefixed ( name ) ,
245
245
apiKey : options ?. apiKey ,
246
246
baseUrl : options ?. baseUrl ,
247
247
debugTraces : options ?. experimental_debugTraces ,
@@ -250,7 +250,7 @@ export function googleAIPlugin(options?: PluginOptions): GenkitPluginV2 {
250
250
} ) ;
251
251
Object . keys ( EMBEDDER_MODELS ) . forEach ( ( name ) => {
252
252
actions . push (
253
- defineGoogleAIEmbedder ( `googleai/ ${ name } ` , {
253
+ defineGoogleAIEmbedder ( ensurePrefixed ( name ) , {
254
254
apiKey : options ?. apiKey ,
255
255
} )
256
256
) ;
@@ -267,7 +267,7 @@ export function googleAIPlugin(options?: PluginOptions): GenkitPluginV2 {
267
267
typeof modelOrRef === 'string' ? gemini ( modelOrRef ) : modelOrRef ;
268
268
actions . push (
269
269
defineGoogleAIModel ( {
270
- name : modelName ,
270
+ name : ensurePrefixed ( modelName ) ,
271
271
apiKey : options ?. apiKey ,
272
272
baseUrl : options ?. baseUrl ,
273
273
info : { ...ref . info , label : `Google AI - ${ modelName } ` } ,
@@ -279,21 +279,24 @@ export function googleAIPlugin(options?: PluginOptions): GenkitPluginV2 {
279
279
return actions ;
280
280
} ,
281
281
async resolve ( actionType : ActionType , actionName : string ) {
282
+ const rawActionName = removePrefix ( actionName ) ;
283
+ const fullActionName = ensurePrefixed ( rawActionName ) ;
284
+
282
285
if ( actionType === 'embedder' ) {
283
- return defineGoogleAIEmbedder ( `googleai/ ${ actionName } ` , {
286
+ return defineGoogleAIEmbedder ( fullActionName , {
284
287
apiKey : options ?. apiKey ,
285
288
} ) ;
286
- } else if ( actionName . startsWith ( 'veo' ) ) {
289
+ } else if ( rawActionName . startsWith ( 'veo' ) ) {
287
290
if ( actionType === 'background-model' ) {
288
- return defineVeoModel ( `googleai/ ${ actionName } ` , options ?. apiKey ) ;
291
+ return defineVeoModel ( fullActionName , options ?. apiKey ) ;
289
292
}
290
293
} else if ( actionType === 'model' ) {
291
- if ( actionName . startsWith ( 'imagen' ) ) {
292
- return defineImagenModel ( `googleai/ ${ actionName } ` , options ?. apiKey ) ;
294
+ if ( rawActionName . startsWith ( 'imagen' ) ) {
295
+ return defineImagenModel ( fullActionName , options ?. apiKey ) ;
293
296
}
294
297
// Fallback dynamic Gemini model
295
298
return defineGoogleAIModel ( {
296
- name : `googleai/ ${ actionName } ` ,
299
+ name : fullActionName ,
297
300
apiKey : options ?. apiKey ,
298
301
baseUrl : options ?. baseUrl ,
299
302
debugTraces : options ?. experimental_debugTraces ,
@@ -339,22 +342,23 @@ export const googleAI = googleAIPlugin as GoogleAIPlugin;
339
342
name : string ,
340
343
config ?: any
341
344
) : ModelReference < z . ZodTypeAny > => {
345
+ const fullModelName = ensurePrefixed ( name ) ;
342
346
if ( name . startsWith ( 'imagen' ) ) {
343
347
return modelRef ( {
344
- name : `googleai/ ${ name } ` ,
348
+ name : fullModelName ,
345
349
config,
346
350
configSchema : ImagenConfigSchema ,
347
351
} ) ;
348
352
}
349
353
if ( name . startsWith ( 'veo' ) ) {
350
354
return modelRef ( {
351
- name : `googleai/ ${ name } ` ,
355
+ name : fullModelName ,
352
356
config,
353
357
configSchema : VeoConfigSchema ,
354
358
} ) ;
355
359
}
356
360
return modelRef ( {
357
- name : `googleai/ ${ name } ` ,
361
+ name : fullModelName ,
358
362
config,
359
363
configSchema : GeminiConfigSchema ,
360
364
} ) ;
@@ -363,8 +367,9 @@ googleAI.embedder = (
363
367
name : string ,
364
368
config ?: GeminiEmbeddingConfig
365
369
) : EmbedderReference < typeof GeminiEmbeddingConfigSchema > => {
370
+ const fullEmbedderName = ensurePrefixed ( name ) ;
366
371
return embedderRef ( {
367
- name : `googleai/ ${ name } ` ,
372
+ name : fullEmbedderName ,
368
373
config,
369
374
configSchema : GeminiEmbeddingConfigSchema ,
370
375
} ) ;
0 commit comments