use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResponseFormat {
#[serde(rename = "type")]
pub format_type: String,
pub schema: Value,
}
impl ResponseFormat {
pub fn json_schema(schema: Value) -> Self {
Self {
format_type: "json_schema".to_string(),
schema,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct JsonOptions {
pub prompt: Option<String>,
pub response_format: Option<ResponseFormat>,
}
impl JsonOptions {
pub fn new() -> Self {
Self::default()
}
pub fn with_prompt(mut self, prompt: impl Into<String>) -> Self {
self.prompt = Some(prompt.into());
self
}
pub fn with_response_format(mut self, rf: ResponseFormat) -> Self {
self.response_format = Some(rf);
self
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct SnapshotResult {
pub screenshot: String,
pub content: String,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct CfEnvelope<T> {
pub success: bool,
pub result: Option<T>,
#[serde(default)]
pub errors: Vec<Value>,
#[serde(default)]
pub messages: Vec<Value>,
}
#[derive(Debug, Clone)]
pub enum Output {
Json(Value),
File(PathBuf),
Snapshot {
png: PathBuf,
html: String,
},
}
impl Output {
pub fn display_string(&self) -> String {
match self {
Output::Json(v) => serde_json::to_string_pretty(v).unwrap_or_else(|_| v.to_string()),
Output::File(p) => format!("Saved to {}", p.display()),
Output::Snapshot { png, html } => {
format!("Snapshot PNG: {}\n--- HTML ---\n{}", png.display(), html)
}
}
}
}