Skip to main content

adk_vision/
traits.rs

1//! The perception traits (spec 3.7 §7.5): [`Detector`], [`Segmenter`], [`DocumentReader`],
2//! [`Embedder`], [`Describer`], [`Tracker`], [`VideoAnalyzer`] and [`Editor`].
3//!
4//! Each image-taking trait is generic over what its backend is handed: on-device backends
5//! implement it for [`SentImage`] (the default), remote backends for
6//! [`ReleasedImage`](crate::ReleasedImage). Backends answer in their descriptor's
7//! [`CoordFrame`](crate::CoordFrame) with [`RawRegion`]s; the runtime maps every answer to
8//! source pixels.
9
10use async_trait::async_trait;
11use serde::{Deserialize, Serialize};
12
13use crate::backend::BackendDescriptor;
14use crate::cx::VisionCx;
15use crate::edit::EditOp;
16use crate::error::Result;
17use crate::geometry::{BBox, EscalatedFrom, Mask, RawRegion, Region, TrackId};
18use crate::media::{DecodedImage, FrameMeta};
19use crate::sent::{SentImage, VisionInput};
20
21/// What to detect.
22#[non_exhaustive]
23#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
24#[serde(rename_all = "camelCase", tag = "kind", content = "values")]
25pub enum DetectQuery {
26    /// Closed-set classes the model was trained on.
27    Classes(Vec<String>),
28    /// Open-vocabulary noun phrases; `sam-3.1` takes one per request.
29    Concepts(Vec<String>),
30}
31
32/// Finds objects as boxes (and masks, for segmenting detectors).
33///
34/// # Example
35///
36/// ```
37/// use adk_vision::{
38///     BackendDescriptor, BBox, CoordFrame, DetectQuery, Detector, Locality, RawRegion,
39///     SentImage, VisionCx,
40/// };
41///
42/// struct Everything(BackendDescriptor);
43///
44/// #[async_trait::async_trait]
45/// impl Detector for Everything {
46///     fn descriptor(&self) -> &BackendDescriptor {
47///         &self.0
48///     }
49///
50///     async fn detect(
51///         &self,
52///         _cx: &VisionCx,
53///         image: &SentImage,
54///         _query: &DetectQuery,
55///     ) -> adk_vision::Result<Vec<RawRegion>> {
56///         let (w, h) = image.size();
57///         Ok(vec![RawRegion::boxed(BBox::new(0.0, 0.0, w as f32, h as f32), "image", 1.0)])
58///     }
59/// }
60///
61/// let detector =
62///     Everything(BackendDescriptor::new("everything", Locality::InProcess, CoordFrame::SentPixels));
63/// assert_eq!(detector.descriptor().id.as_str(), "everything");
64/// ```
65#[async_trait]
66pub trait Detector<I: VisionInput = SentImage>: Send + Sync {
67    /// What the backend is.
68    fn descriptor(&self) -> &BackendDescriptor;
69
70    /// Detects objects in `image`, answering in the descriptor's frame.
71    async fn detect(&self, cx: &VisionCx, image: &I, query: &DetectQuery)
72    -> Result<Vec<RawRegion>>;
73}
74
75/// A segmentation prompt, given to the runtime in source pixels and handed to the backend
76/// in its own frame.
77#[non_exhaustive]
78#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
79#[serde(rename_all = "camelCase", tag = "kind")]
80pub enum SegmentPrompt {
81    /// A noun phrase naming one concept.
82    Concept {
83        /// The phrase.
84        text: String,
85    },
86    /// A point on (or off) the object.
87    Point {
88        /// `[x, y]`.
89        at: [f32; 2],
90        /// `true` for a point on the object.
91        positive: bool,
92    },
93    /// A box around the object.
94    Box {
95        /// The box.
96        bbox: BBox,
97    },
98    /// A rough mask of the object.
99    Mask {
100        /// The mask.
101        mask: Mask,
102    },
103}
104
105/// Segments objects into masks or polygons.
106#[async_trait]
107pub trait Segmenter<I: VisionInput = SentImage>: Send + Sync {
108    /// What the backend is.
109    fn descriptor(&self) -> &BackendDescriptor;
110
111    /// Segments `image` for the prompts, answering in the descriptor's frame.
112    async fn segment(
113        &self,
114        cx: &VisionCx,
115        image: &I,
116        prompts: &[SegmentPrompt],
117    ) -> Result<Vec<RawRegion>>;
118}
119
120/// Options for reading a document page.
121#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
122#[serde(rename_all = "camelCase")]
123#[non_exhaustive]
124pub struct ReadOptions {
125    /// Expected languages, as BCP 47 tags; empty lets the backend decide.
126    #[serde(default)]
127    pub languages: Vec<String>,
128    /// Ask for a Markdown rendering of the page.
129    #[serde(default)]
130    pub markdown: bool,
131}
132
133/// The kind of a document block.
134#[non_exhaustive]
135#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
136#[serde(rename_all = "camelCase")]
137pub enum BlockKind {
138    /// Body text.
139    Text,
140    /// A title or heading.
141    Title,
142    /// A table.
143    Table,
144    /// A formula.
145    Formula,
146    /// A figure.
147    Figure,
148    /// A seal or stamp.
149    Seal,
150    /// A checkbox.
151    Checkbox,
152    /// Handwriting.
153    Handwriting,
154}
155
156/// A recognised word.
157#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
158#[serde(rename_all = "camelCase")]
159pub struct Word<R = Region> {
160    /// Where it is.
161    pub region: R,
162    /// Its text.
163    pub text: String,
164    /// The backend's confidence.
165    #[serde(default, skip_serializing_if = "Option::is_none")]
166    pub confidence: Option<f32>,
167}
168
169/// A table cell.
170#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
171#[serde(rename_all = "camelCase")]
172pub struct TableCell<R = Region> {
173    /// Where it is.
174    pub region: R,
175    /// Row, from 0.
176    pub row: u32,
177    /// Column, from 0.
178    pub col: u32,
179    /// Rows spanned.
180    pub row_span: u32,
181    /// Columns spanned.
182    pub col_span: u32,
183    /// Its text.
184    pub text: String,
185}
186
187/// A block of a document page with its region, text, words and, for tables, cells.
188#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
189#[serde(rename_all = "camelCase")]
190pub struct Block<R = Region> {
191    /// What kind of block.
192    pub kind: BlockKind,
193    /// Where it is.
194    pub region: R,
195    /// Its text.
196    pub text: String,
197    /// The backend's confidence.
198    #[serde(default, skip_serializing_if = "Option::is_none")]
199    pub confidence: Option<f32>,
200    /// Its words.
201    #[serde(default = "Vec::new", skip_serializing_if = "Vec::is_empty")]
202    pub words: Vec<Word<R>>,
203    /// Its cells, for tables.
204    #[serde(default = "Vec::new", skip_serializing_if = "Vec::is_empty")]
205    pub cells: Vec<TableCell<R>>,
206}
207
208/// One page read: blocks with regions, the reading order, and optionally Markdown.
209#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
210#[serde(rename_all = "camelCase")]
211pub struct DocumentPage<R = Region> {
212    /// The blocks.
213    pub blocks: Vec<Block<R>>,
214    /// Indexes into `blocks`, in reading order.
215    pub reading_order: Vec<usize>,
216    /// The page as Markdown, when asked for.
217    #[serde(default, skip_serializing_if = "Option::is_none")]
218    pub markdown: Option<String>,
219}
220
221impl<R> Default for DocumentPage<R> {
222    fn default() -> Self {
223        Self { blocks: Vec::new(), reading_order: Vec::new(), markdown: None }
224    }
225}
226
227/// Reads document pages: layout, text, tables.
228#[async_trait]
229pub trait DocumentReader<I: VisionInput = SentImage>: Send + Sync {
230    /// What the backend is.
231    fn descriptor(&self) -> &BackendDescriptor;
232
233    /// Reads `page`, answering in the descriptor's frame.
234    async fn read(
235        &self,
236        cx: &VisionCx,
237        page: &I,
238        options: &ReadOptions,
239    ) -> Result<DocumentPage<RawRegion>>;
240}
241
242/// The distance an embedding space is searched by.
243#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
244#[serde(rename_all = "camelCase")]
245pub enum Metric {
246    /// Cosine similarity.
247    Cosine,
248    /// Dot product.
249    Dot,
250    /// Euclidean distance.
251    L2,
252}
253
254/// The space an embedder's vectors live in. An index belongs to one space.
255#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
256#[serde(rename_all = "camelCase")]
257pub struct EmbeddingSpace {
258    /// The model.
259    pub model: String,
260    /// The model revision.
261    pub revision: String,
262    /// Vector length.
263    pub dimensions: usize,
264    /// The metric.
265    pub metric: Metric,
266}
267
268/// Embeds images and texts into one space.
269#[async_trait]
270pub trait Embedder<I: VisionInput = SentImage>: Send + Sync {
271    /// What the backend is.
272    fn descriptor(&self) -> &BackendDescriptor;
273
274    /// Model, revision, dimensions and metric.
275    fn space(&self) -> &EmbeddingSpace;
276
277    /// One vector per image.
278    async fn embed_images(&self, cx: &VisionCx, images: &[I]) -> Result<Vec<Vec<f32>>>;
279
280    /// One vector per text.
281    async fn embed_texts(&self, cx: &VisionCx, texts: &[&str]) -> Result<Vec<Vec<f32>>>;
282}
283
284/// What to ask a describer.
285#[derive(Debug)]
286#[non_exhaustive]
287pub struct DescribeRequest<I = SentImage> {
288    /// The images, as the backend may see them.
289    pub images: Vec<I>,
290    /// The question or instruction.
291    pub prompt: String,
292    /// A JSON Schema the answer's `value` must match.
293    pub output_schema: Option<serde_json::Value>,
294    /// Ask for regions; a backend with no region adapter refuses with `Unsupported`.
295    pub want_regions: bool,
296    /// The most output tokens to spend.
297    pub max_output_tokens: Option<u32>,
298}
299
300impl<I> DescribeRequest<I> {
301    pub(crate) fn new(images: Vec<I>, spec: &DescribeSpec) -> Self {
302        Self {
303            images,
304            prompt: spec.prompt.clone(),
305            output_schema: spec.output_schema.clone(),
306            want_regions: spec.want_regions,
307            max_output_tokens: spec.max_output_tokens,
308        }
309    }
310}
311
312/// What a caller asks the runtime to describe, before images are prepared.
313///
314/// # Example
315///
316/// ```
317/// use adk_vision::DescribeSpec;
318///
319/// let spec = DescribeSpec::new("What kind of document is this?").with_regions();
320/// assert!(spec.want_regions);
321/// ```
322#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
323#[serde(rename_all = "camelCase")]
324#[non_exhaustive]
325pub struct DescribeSpec {
326    /// The question or instruction.
327    pub prompt: String,
328    /// A JSON Schema the answer's `value` must match.
329    #[serde(default, skip_serializing_if = "Option::is_none")]
330    pub output_schema: Option<serde_json::Value>,
331    /// Ask for regions.
332    #[serde(default)]
333    pub want_regions: bool,
334    /// The most output tokens to spend.
335    #[serde(default, skip_serializing_if = "Option::is_none")]
336    pub max_output_tokens: Option<u32>,
337}
338
339impl DescribeSpec {
340    /// A prompt.
341    pub fn new(prompt: impl Into<String>) -> Self {
342        Self { prompt: prompt.into(), ..Self::default() }
343    }
344
345    /// Asks for a value matching `schema`.
346    pub fn with_schema(mut self, schema: serde_json::Value) -> Self {
347        self.output_schema = Some(schema);
348        self
349    }
350
351    /// Asks for regions.
352    pub fn with_regions(mut self) -> Self {
353        self.want_regions = true;
354        self
355    }
356
357    /// Caps output tokens.
358    pub fn with_max_output_tokens(mut self, tokens: u32) -> Self {
359        self.max_output_tokens = Some(tokens);
360        self
361    }
362}
363
364/// A region a describer found, with the index of the request image it belongs to.
365#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
366#[serde(rename_all = "camelCase")]
367pub struct ImageRegion {
368    /// Index into the request's images.
369    pub image: usize,
370    /// The region, in the backend's frame.
371    pub region: RawRegion,
372}
373
374/// A describer's answer: free text, a value matching the request's schema, and regions
375/// when asked for.
376#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
377#[serde(rename_all = "camelCase")]
378pub struct Description<R = Region> {
379    /// Free text.
380    #[serde(default, skip_serializing_if = "Option::is_none")]
381    pub text: Option<String>,
382    /// A value matching the request's `output_schema`.
383    #[serde(default, skip_serializing_if = "Option::is_none")]
384    pub value: Option<serde_json::Value>,
385    /// Regions, when asked for.
386    #[serde(default = "Vec::new", skip_serializing_if = "Vec::is_empty")]
387    pub regions: Vec<R>,
388    /// The backend's confidence in the answer, when it gives one.
389    #[serde(default, skip_serializing_if = "Option::is_none")]
390    pub confidence: Option<f32>,
391    /// The primary answer this one replaced, when it came from an escalation. Set by the
392    /// runtime.
393    #[serde(default, skip_serializing_if = "Option::is_none")]
394    pub escalated_from: Option<EscalatedFrom>,
395}
396
397impl<R> Default for Description<R> {
398    fn default() -> Self {
399        Self {
400            text: None,
401            value: None,
402            regions: Vec::new(),
403            confidence: None,
404            escalated_from: None,
405        }
406    }
407}
408
409/// Describes images in text, structured values and regions.
410#[async_trait]
411pub trait Describer<I: VisionInput = SentImage>: Send + Sync {
412    /// What the backend is.
413    fn descriptor(&self) -> &BackendDescriptor;
414
415    /// Free text, a value matching `request.output_schema`, and regions when asked for.
416    async fn describe(
417        &self,
418        cx: &VisionCx,
419        request: &DescribeRequest<I>,
420    ) -> Result<Description<ImageRegion>>;
421}
422
423/// Associates detections across frames. Pure CPU, no model.
424pub trait Tracker: Send {
425    /// Assigns track identifiers to one frame's detections.
426    fn update(&mut self, frame: &FrameMeta, detections: Vec<Region>) -> Vec<Region>;
427
428    /// Forgets every track; identifiers start again. Called when the source session ends.
429    fn reset(&mut self);
430
431    /// The tracks held after the last [`update`](Self::update), seen in that frame or kept
432    /// through a brief miss. A watch condition keeps its state for these, so an object the
433    /// detector misses for a frame does not fire again. None by default.
434    fn live_tracks(&self) -> Vec<TrackId> {
435        Vec::new()
436    }
437}
438
439/// How a video or stream is sampled, which every provider prices by.
440///
441/// # Example
442///
443/// ```
444/// use adk_vision::Sampling;
445///
446/// // Gemini's default: one frame a second at the clip's own resolution.
447/// let sampling = Sampling::at(1.0);
448/// assert_eq!(sampling.max_long_edge, None);
449/// ```
450#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
451#[serde(rename_all = "camelCase")]
452pub struct Sampling {
453    /// Frames per second.
454    pub fps: f32,
455    /// Longest side of each frame, in pixels.
456    #[serde(default, skip_serializing_if = "Option::is_none")]
457    pub max_long_edge: Option<u32>,
458}
459
460impl Sampling {
461    /// `fps` frames a second, at full resolution.
462    pub fn at(fps: f32) -> Self {
463        Self { fps, max_long_edge: None }
464    }
465}
466
467/// What to do with a video.
468#[non_exhaustive]
469#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
470#[serde(rename_all = "camelCase", rename_all_fields = "camelCase", tag = "kind")]
471pub enum VideoRequest {
472    /// Track objects matching the prompts.
473    Track {
474        /// The prompts.
475        prompts: Vec<SegmentPrompt>,
476    },
477    /// Caption the video in chunks of `chunk_ms`, counted from its first frame: one event per
478    /// chunk that holds a frame, whose text is the caption and whose labels name what it
479    /// shows. The video analyst (`adk_vision::analyst`, feature `analyst`) sends one chunk
480    /// per call.
481    Caption {
482        /// Chunk length in milliseconds.
483        chunk_ms: u64,
484    },
485    /// Answer a question.
486    Ask {
487        /// The question.
488        question: String,
489    },
490}
491
492/// What a video backend is handed: sampled frames, a clip, or both, as the backend may see
493/// them — [`SentImage`]s and a [`SentClip`](crate::SentClip) on the device,
494/// [`ReleasedImage`](crate::ReleasedImage)s and a [`ReleasedClip`](crate::ReleasedClip)
495/// off it. Only the runtime constructs one.
496#[non_exhaustive]
497pub struct VideoInput<I: VisionInput = SentImage> {
498    /// `(frame, image)` pairs, in order.
499    pub frames: Vec<(FrameMeta, I)>,
500    /// The clip, for a backend that reads video itself.
501    pub clip: Option<I::Clip>,
502    /// How the frames were sampled, or how a backend that samples the clip itself should.
503    pub sampling: Sampling,
504}
505
506impl<I: VisionInput> VideoInput<I> {
507    pub(crate) fn new(
508        frames: Vec<(FrameMeta, I)>,
509        clip: Option<I::Clip>,
510        sampling: Sampling,
511    ) -> Self {
512        Self { frames, clip, sampling }
513    }
514}
515
516impl<I: VisionInput + std::fmt::Debug> std::fmt::Debug for VideoInput<I> {
517    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
518        f.debug_struct("VideoInput")
519            .field("frames", &self.frames)
520            .field("clip", &self.clip)
521            .field("sampling", &self.sampling)
522            .finish()
523    }
524}
525
526/// What a video call will send, known before anything is prepared or released: for a
527/// backend's frame count and cost estimate.
528#[derive(Clone, Debug, PartialEq)]
529#[non_exhaustive]
530pub struct VideoPlan {
531    /// The clip, when the call sends one.
532    pub clip: Option<crate::video::ClipInfo>,
533    /// The sizes of the sampled frames the call sends, in order.
534    pub frame_sizes: Vec<(u32, u32)>,
535    /// The time the call covers, in milliseconds.
536    pub duration_ms: u64,
537    /// The sampling.
538    pub sampling: Sampling,
539}
540
541impl VideoPlan {
542    /// Frames the call carries: the clip's frames, else the sampled frames.
543    pub fn frames(&self) -> u64 {
544        match &self.clip {
545            Some(clip) => clip.frames,
546            None => self.frame_sizes.len() as u64,
547        }
548    }
549}
550
551/// A time range a video analysis names: an event an `Ask` found, or a chunk a `Caption`
552/// described.
553///
554/// # Example
555///
556/// ```
557/// use adk_vision::VideoEvent;
558///
559/// let chunk = VideoEvent::new(30_000, 60_000, "An orange forklift drives into aisle 2.")
560///     .with_labels(["forklift", "pallet"]);
561/// assert_eq!(chunk.labels, ["forklift", "pallet"]);
562/// ```
563#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
564#[serde(rename_all = "camelCase")]
565pub struct VideoEvent {
566    /// Start, in milliseconds.
567    pub start_ms: u64,
568    /// End, in milliseconds.
569    pub end_ms: u64,
570    /// What happens.
571    pub text: String,
572    /// The people, vehicles and objects a caption names, as short noun phrases.
573    #[serde(default, skip_serializing_if = "Vec::is_empty")]
574    pub labels: Vec<String>,
575}
576
577impl VideoEvent {
578    /// An event from `start_ms` to `end_ms` described by `text`, with no labels.
579    pub fn new(start_ms: u64, end_ms: u64, text: impl Into<String>) -> Self {
580        Self { start_ms, end_ms, text: text.into(), labels: Vec::new() }
581    }
582
583    /// Adds the things the event names.
584    pub fn with_labels<I, S>(mut self, labels: I) -> Self
585    where
586        I: IntoIterator<Item = S>,
587        S: Into<String>,
588    {
589        self.labels.extend(labels.into_iter().map(Into::into));
590        self
591    }
592}
593
594/// The regions found on one frame of a video, each with the track it belongs to.
595#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
596#[serde(rename_all = "camelCase")]
597pub struct VideoFrame<R = Region> {
598    /// The frame's index in the clip, from 0, or the sampled frame's index in its stream.
599    pub index: u64,
600    /// Presentation time in milliseconds, when known.
601    #[serde(default, skip_serializing_if = "Option::is_none")]
602    pub pts_ms: Option<u64>,
603    /// The regions, with their tracks.
604    pub regions: Vec<R>,
605}
606
607/// What one analysis used: frames, tokens and cost, so each path reports its own (S13).
608#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
609#[serde(rename_all = "camelCase")]
610#[non_exhaustive]
611pub struct VideoUsage {
612    /// Frames analysed: billed frames for a per-frame price, sampled frames otherwise.
613    pub frames: u64,
614    /// Input tokens, for a token-billed or local model.
615    #[serde(default, skip_serializing_if = "Option::is_none")]
616    pub input_tokens: Option<u64>,
617    /// Output tokens, for a token-billed or local model.
618    #[serde(default, skip_serializing_if = "Option::is_none")]
619    pub output_tokens: Option<u64>,
620    /// Cost in micro-USD: zero on the device, `None` when the catalog does not price the
621    /// model.
622    #[serde(default, skip_serializing_if = "Option::is_none")]
623    pub cost_micro_usd: Option<u64>,
624    /// Calls made to the model or service.
625    pub requests: u64,
626}
627
628/// What a video analysis found.
629#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
630#[serde(rename_all = "camelCase")]
631#[non_exhaustive]
632pub struct VideoAnalysis<R = Region> {
633    /// The answer to an `Ask`.
634    #[serde(default, skip_serializing_if = "Option::is_none")]
635    pub answer: Option<String>,
636    /// Events or chunk captions.
637    #[serde(default = "Vec::new", skip_serializing_if = "Vec::is_empty")]
638    pub events: Vec<VideoEvent>,
639    /// For a `Track`, the regions on each frame with an object, in frame order.
640    #[serde(default = "Vec::new", skip_serializing_if = "Vec::is_empty")]
641    pub frames: Vec<VideoFrame<R>>,
642    /// Frames, tokens and cost.
643    #[serde(default)]
644    pub usage: VideoUsage,
645}
646
647impl<R> Default for VideoAnalysis<R> {
648    fn default() -> Self {
649        Self { answer: None, events: Vec::new(), frames: Vec::new(), usage: VideoUsage::default() }
650    }
651}
652
653/// Tracks, captions or answers questions over a video, at an explicit sampling rate and
654/// resolution.
655///
656/// A backend answers regions in its descriptor's frame as [`RawRegion`]s; the runtime maps
657/// them to source pixels of the clip or of each sampled frame.
658#[async_trait]
659pub trait VideoAnalyzer<I: VisionInput = SentImage>: Send + Sync {
660    /// What the backend is.
661    fn descriptor(&self) -> &BackendDescriptor;
662
663    /// The frames a call on `plan` analyses, which the runtime records as units and bills
664    /// a per-frame price by: by default every frame the call carries.
665    fn frames(&self, plan: &VideoPlan) -> u64 {
666        plan.frames()
667    }
668
669    /// The most a call on `plan` can cost in micro-USD, which the runtime holds against the
670    /// run's budget before anything is released (V-I6). Token-billed backends estimate it;
671    /// `None` holds no more than a per-unit price.
672    fn max_cost_micro_usd(&self, _plan: &VideoPlan, _request: &VideoRequest) -> Option<u64> {
673        None
674    }
675
676    /// Analyses `video`.
677    async fn analyze(
678        &self,
679        cx: &VisionCx,
680        video: &VideoInput<I>,
681        request: &VideoRequest,
682    ) -> Result<VideoAnalysis<RawRegion>>;
683}
684
685/// Edits an image: crop, redact, annotate, resize, or a generative edit. The runtime stores
686/// the result as a new image with `Provenance::Derived`.
687#[async_trait]
688pub trait Editor<I: VisionInput = SentImage>: Send + Sync {
689    /// What the backend is.
690    fn descriptor(&self) -> &BackendDescriptor;
691
692    /// Applies `operation`, whose coordinates are in source pixels, to `image`.
693    async fn edit(&self, cx: &VisionCx, image: &I, operation: &EditOp) -> Result<DecodedImage>;
694}