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 identity;
14pub mod images;
15mod instructions;
16pub mod memory;
17pub mod models;
18pub mod video;
19pub mod web_search;
20
21pub use error::{
22    Diagnostic, DiagnosticKind, Report, TransformError, TransformErrorKind, UpstreamError,
23};
24
25/// An unrepresentable field or item is omitted at its mapping boundary.
26/// Parsing, host and state errors still propagate to the caller.
27pub(crate) fn optional<T>(value: Result<T, TransformError>) -> Result<Option<T>, TransformError> {
28    match value {
29        Ok(value) => Ok(Some(value)),
30        Err(error)
31            if matches!(
32                error.kind(),
33                TransformErrorKind::Unsupported | TransformErrorKind::MissingMetadata
34            ) =>
35        {
36            Ok(None)
37        }
38        Err(error) => Err(error),
39    }
40}
41
42/// A typed target value and out-of-band field diagnostics. This wrapper never
43/// changes or normalizes the payload type into a common content model.
44#[derive(Debug, Clone, PartialEq, Eq)]
45pub struct Converted<T> {
46    pub value: T,
47    pub report: Report,
48}