|
6 | 6 | * dispatches the request to the appropriate image provider implementation |
7 | 7 | * (e.g. OpenAI DALL-E, Stability AI, Replicate). |
8 | 8 | */ |
| 9 | +import { createImageProvider } from '../core/images/index.js'; |
| 10 | +import type { |
| 11 | + GeneratedImage, |
| 12 | + ImageGenerationResult, |
| 13 | + ImageProviderOptionBag, |
| 14 | + ImageResponseFormat, |
| 15 | + ImageBackground, |
| 16 | + ImageModality, |
| 17 | + ImageOutputFormat, |
| 18 | +} from '../core/images/IImageProvider.js'; |
9 | 19 | import { parseModelString, resolveMediaProvider } from './model.js'; |
10 | 20 |
|
11 | | -// Inline type stubs — will be replaced by imports from '../core/images/' once that module is implemented |
12 | | -/** A single generated image with optional URL and base64 data. */ |
13 | | -export interface GeneratedImage { url?: string; b64_json?: string; revised_prompt?: string } |
14 | | -/** Result from an image provider. */ |
15 | | -interface ImageGenerationResult { modelId: string; providerId: string; created: number; text?: string; images: GeneratedImage[]; usage?: { promptTokens?: number; totalTokens?: number } } |
16 | | -/** Provider-specific option bag. */ |
17 | | -type ImageProviderOptionBag = Record<string, unknown>; |
18 | | -/** Response format: URL or base64. */ |
19 | | -type ImageResponseFormat = 'url' | 'b64_json'; |
20 | | -/** Background style. */ |
21 | | -type ImageBackground = 'transparent' | 'opaque' | 'auto'; |
22 | | -/** Image modality. */ |
23 | | -type ImageModality = 'image' | 'text'; |
24 | | -/** Output file format. */ |
25 | | -type ImageOutputFormat = 'png' | 'jpeg' | 'webp' | 'gif'; |
26 | | - |
27 | 21 | /** |
28 | 22 | * Options for a {@link generateImage} call. |
29 | 23 | */ |
@@ -111,11 +105,37 @@ export async function generateImage(opts: GenerateImageOptions): Promise<Generat |
111 | 105 | baseUrl: opts.baseUrl, |
112 | 106 | }); |
113 | 107 |
|
114 | | - // TODO: Wire to core/images/ module once implemented. |
115 | | - // For now, throw a descriptive error so callers know the provider layer isn't ready. |
116 | | - throw new Error( |
117 | | - `generateImage() is not yet wired to a provider backend. ` + |
118 | | - `Resolved: ${resolved.providerId}:${resolved.modelId}. ` + |
119 | | - `The core/images/ module needs to be implemented first.` |
120 | | - ); |
| 108 | + const provider = createImageProvider(resolved.providerId); |
| 109 | + await provider.initialize({ |
| 110 | + apiKey: resolved.apiKey, |
| 111 | + baseURL: resolved.baseUrl, |
| 112 | + defaultModelId: resolved.modelId, |
| 113 | + }); |
| 114 | + |
| 115 | + const result = await provider.generateImage({ |
| 116 | + modelId: resolved.modelId, |
| 117 | + prompt: opts.prompt, |
| 118 | + modalities: opts.modalities, |
| 119 | + n: opts.n, |
| 120 | + size: opts.size, |
| 121 | + aspectRatio: opts.aspectRatio, |
| 122 | + quality: opts.quality, |
| 123 | + background: opts.background, |
| 124 | + outputFormat: opts.outputFormat, |
| 125 | + outputCompression: opts.outputCompression, |
| 126 | + responseFormat: opts.responseFormat, |
| 127 | + userId: opts.userId, |
| 128 | + seed: opts.seed, |
| 129 | + negativePrompt: opts.negativePrompt, |
| 130 | + providerOptions: opts.providerOptions, |
| 131 | + }); |
| 132 | + |
| 133 | + return { |
| 134 | + model: result.modelId, |
| 135 | + provider: result.providerId, |
| 136 | + created: result.created, |
| 137 | + text: result.text, |
| 138 | + images: result.images, |
| 139 | + usage: result.usage, |
| 140 | + }; |
121 | 141 | } |
0 commit comments