import * as plugins from './plugins.js';
import type { LanguageModelV3 } from '@ai-sdk/provider';

export interface IVisionOptions {
  model: LanguageModelV3;
  image: Buffer | Uint8Array;
  prompt: string;
  mediaType?: 'image/jpeg' | 'image/png' | 'image/webp' | 'image/gif';
}

export async function analyzeImage(options: IVisionOptions): Promise<string> {
  const result = await plugins.generateText({
    model: options.model,
    messages: [
      {
        role: 'user',
        content: [
          { type: 'text', text: options.prompt },
          {
            type: 'image',
            image: options.image,
            mediaType: options.mediaType ?? 'image/jpeg',
          },
        ],
      },
    ],
  });
  return result.text;
}
