oxios_kernel/image_gen/types.rs
1//! Request/result types for image generation.
2//!
3//! Field names align with oxi-ai's dead-code types
4//! (`ImageGenerationRequest`/`ImageGenerationResponse`, `oxi-ai/src/types.rs:335-395`)
5//! so a future oxi-sdk implementation can be swapped in with minimal friction.
6//! Unlike oxi-ai (which returns `Vec<Vec<u8>>` bytes), Oxios returns URLs —
7//! agents consume images as markdown ``.
8
9use serde::{Deserialize, Serialize};
10
11/// A text-to-image generation request.
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct ImageGenRequest {
14 /// The prompt describing the desired image.
15 pub prompt: String,
16 /// Provider model id. `None` → caller (tool/config) must supply a default.
17 pub model: Option<String>,
18 /// Number of images to generate (1-8).
19 #[serde(default = "default_n")]
20 pub n: u8,
21 /// Output dimensions. `None` → provider default.
22 pub size: Option<ImageSize>,
23 /// Quality hint (e.g. `"standard"`, `"hd"`). Provider-specific.
24 pub quality: Option<String>,
25 /// Optional reference image URL for image-to-image (Phase 2).
26 pub reference_image_url: Option<String>,
27}
28
29fn default_n() -> u8 {
30 1
31}
32
33/// Supported image dimensions (OpenAI-compatible size strings).
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
35pub enum ImageSize {
36 /// 1024×1024 square.
37 #[serde(rename = "1024x1024")]
38 Square1024,
39 /// 1792×1024 landscape.
40 #[serde(rename = "1792x1024")]
41 Landscape1792,
42 /// 1024×1792 portrait.
43 #[serde(rename = "1024x1792")]
44 Portrait1792,
45}
46
47impl ImageSize {
48 /// The wire string sent to the provider.
49 pub fn as_str(&self) -> &'static str {
50 match self {
51 Self::Square1024 => "1024x1024",
52 Self::Landscape1792 => "1792x1024",
53 Self::Portrait1792 => "1024x1792",
54 }
55 }
56}
57
58/// A single generated image, normalized to a URL.
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct GeneratedImage {
61 /// A URL the frontend can fetch. Either the provider's CDN URL or a
62 /// locally-served `/api/images/<uuid>.<ext>` (for b64-only providers).
63 pub url: String,
64 /// Pixel width, if reported by the provider.
65 pub width: Option<u32>,
66 /// Pixel height, if reported by the provider.
67 pub height: Option<u32>,
68}
69
70/// The result of an image generation call.
71#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct ImageGenResult {
73 /// Generated images, each normalized to a URL.
74 pub images: Vec<GeneratedImage>,
75 /// Provider that produced the images.
76 pub provider: String,
77 /// Model used (resolved default or explicit).
78 pub model: String,
79 /// Revised prompt, if the provider rewrites it (e.g. dall-e-3).
80 pub revised_prompt: Option<String>,
81}