Skip to main content

agent_image_diff/output/
compact.rs

1use serde::Serialize;
2
3use crate::region::{BoundingBox, DiffResult, DimensionMismatch};
4
5/// Compact output for agent consumption — only actionable fields.
6#[derive(Serialize)]
7pub struct CompactDiffResult {
8    #[serde(rename = "match")]
9    pub is_match: bool,
10    pub diff_percentage: f64,
11    pub regions: Vec<CompactRegion>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub dimension_mismatch: Option<DimensionMismatch>,
14}
15
16#[derive(Serialize)]
17pub struct CompactRegion {
18    pub id: u32,
19    pub bounding_box: BoundingBox,
20    pub label: String,
21}
22
23impl From<&DiffResult> for CompactDiffResult {
24    fn from(r: &DiffResult) -> Self {
25        CompactDiffResult {
26            is_match: r.is_match,
27            diff_percentage: (r.stats.diff_percentage * 10.0).round() / 10.0,
28            regions: r
29                .regions
30                .iter()
31                .map(|reg| CompactRegion {
32                    id: reg.id,
33                    bounding_box: reg.bounding_box.clone(),
34                    label: reg.label.clone(),
35                })
36                .collect(),
37            dimension_mismatch: r.dimension_mismatch.clone(),
38        }
39    }
40}