33import { Transport } from '../runtime/transport' ;
44import { TaskHandle } from '../runtime/tasks' ;
55
6+ export type ImageProvider = 'nano-banana' | 'midjourney' | 'flux' | 'seedream' | ( string & { } ) ;
7+
68export class Images {
79 constructor ( private transport : Transport ) { }
810
911 async generate ( opts : {
1012 prompt : string ;
13+ provider ?: ImageProvider ;
1114 model ?: string ;
1215 negativePrompt ?: string ;
1316 imageUrl ?: string ;
@@ -17,19 +20,20 @@ export class Images {
1720 maxWait ?: number ;
1821 [ key : string ] : unknown ;
1922 } ) : Promise < Record < string , unknown > | TaskHandle > {
20- const { prompt, model, negativePrompt, imageUrl, callbackUrl, wait : shouldWait , pollInterval, maxWait, ...rest } = opts ;
23+ const { prompt, provider = 'nano-banana' , model, negativePrompt, imageUrl, callbackUrl, wait : shouldWait , pollInterval, maxWait, ...rest } = opts ;
2124 const body : Record < string , unknown > = { prompt, ...rest } ;
2225 if ( model !== undefined ) body . model = model ;
2326 if ( negativePrompt !== undefined ) body . negative_prompt = negativePrompt ;
2427 if ( imageUrl !== undefined ) body . image_url = imageUrl ;
2528 if ( callbackUrl !== undefined ) body . callback_url = callbackUrl ;
2629
27- const result = await this . transport . request ( 'POST' , '/nano-banana/images' , { json : body } ) ;
30+ const endpoint = provider === 'midjourney' ? '/midjourney/imagine' : `/${ provider } /images` ;
31+ const result = await this . transport . request ( 'POST' , endpoint , { json : body } ) ;
2832 const taskId = result . task_id as string | undefined ;
2933
3034 if ( ! taskId || ( result . data && ! shouldWait ) ) return result ;
3135
32- const handle = new TaskHandle ( taskId , '/nano-banana /tasks' , this . transport ) ;
36+ const handle = new TaskHandle ( taskId , `/ ${ provider } /tasks` , this . transport ) ;
3337 if ( shouldWait ) return handle . wait ( { pollInterval, maxWait } ) ;
3438 return handle ;
3539 }
0 commit comments