Skip to main content

gproxy_protocol/transform/
mod.rs

1//! Direct vendor-wire conversions and the identity rules they share.
2//!
3//! A conversion only reads declared source fields and builds declared target
4//! fields. Unknown `rest` members are neither conversion input nor output.
5//! Conversion state and diagnostics are separate from vendor wire payloads.
6
7pub mod compact;
8pub mod count_tokens;
9pub mod embeddings;
10mod error;
11pub mod files;
12pub mod generate;
13pub mod guardian;
14pub mod identity;
15pub mod images;
16mod instructions;
17pub mod memory;
18pub mod models;
19pub mod video;
20pub mod web_search;
21
22pub use error::{
23    Diagnostic, DiagnosticKind, Report, TransformError, TransformErrorKind, UpstreamError,
24};
25
26/// An unrepresentable field or item is omitted at its mapping boundary.
27/// Parsing, host and state errors still propagate to the caller.
28pub(crate) fn optional<T>(value: Result<T, TransformError>) -> Result<Option<T>, TransformError> {
29    match value {
30        Ok(value) => Ok(Some(value)),
31        Err(error)
32            if matches!(
33                error.kind(),
34                TransformErrorKind::Unsupported | TransformErrorKind::MissingMetadata
35            ) =>
36        {
37            Ok(None)
38        }
39        Err(error) => Err(error),
40    }
41}
42
43/// A typed target value and out-of-band field diagnostics. This wrapper never
44/// changes or normalizes the payload type into a common content model.
45#[derive(Debug, Clone, PartialEq, Eq)]
46pub struct Converted<T> {
47    pub value: T,
48    pub report: Report,
49}