Skip to main content

TranslationEngine

Struct TranslationEngine 

Source
pub struct TranslationEngine { /* private fields */ }
Expand description

Stateless request/response translator that routes through the neutral IR.

Implementations§

Source§

impl TranslationEngine

Source

pub fn new(registry: FormatRegistry) -> Self

Creates an engine from an explicit buffered codec registry.

Source

pub fn with_registries( registry: FormatRegistry, stream_registry: StreamCodecRegistry, ) -> Self

Creates an engine from explicit buffered and streaming codec registries.

Source

pub fn decode_request( &self, source: impl Into<FormatId>, body: &Value, policy: &TranslationPolicy, ) -> Result<RequestIrOutput>

Decodes a request body into the neutral request IR.

Source

pub fn encode_request( &self, target: impl Into<FormatId>, request: &LlmRequest, policy: &TranslationPolicy, ) -> Result<TranslationOutput>

Encodes a neutral request IR into a target wire format.

Preserved target bodies take precedence over normalized fields, including output.is_schema_enforced. Clear the target’s preservation entry or use crate::policy::PreservationPolicy::Disabled to encode IR edits.

Source

pub fn translate_request( &self, source: impl Into<FormatId>, target: impl Into<FormatId>, body: &Value, policy: &TranslationPolicy, ) -> Result<TranslationOutput>

Translates a request body from source format to target format.

Source

pub fn decode_response( &self, source: impl Into<FormatId>, body: &Value, policy: &TranslationPolicy, ) -> Result<ResponseIrOutput>

Decodes a response body into the neutral response IR.

Source

pub fn encode_response( &self, target: impl Into<FormatId>, response: &AggLlmResponse, policy: &TranslationPolicy, ) -> Result<TranslationOutput>

Encodes a neutral response IR into a target wire format.

Source

pub fn encode_response_with_extensions( &self, target: impl Into<FormatId>, response: &AggLlmResponse, request_extensions: &ProviderExtensions, policy: &TranslationPolicy, ) -> Result<TranslationOutput>

Encodes a neutral response IR while applying metadata retained from its request.

Request extensions are used to restore caller-specific response details, such as Codex tool namespaces, without exposing those details to the upstream provider.

Source

pub fn translate_response( &self, source: impl Into<FormatId>, target: impl Into<FormatId>, body: &Value, policy: &TranslationPolicy, ) -> Result<TranslationOutput>

Translates a response body from source format to target format.

Source

pub fn translate_event( &self, state: &mut StreamTranslationState, source: impl Into<FormatId>, target: impl Into<FormatId>, event: &Value, ) -> Result<Vec<Value>>

Translates one streaming source event into zero or more target events.

Source

pub fn decode_stream_event( &self, state: &mut StreamTranslationState, source: impl Into<FormatId>, event: Value, ) -> Result<LlmResponseStreamEvent>

Decodes one provider event while retaining its parsed source JSON value.

Takes ownership of event so preservation does not deep-copy provider JSON on the per-event streaming path.

Source

pub fn encode_stream_event( &self, state: &mut StreamTranslationState, target: impl Into<FormatId>, event: LlmResponseStreamEvent, ) -> Result<Vec<Value>>

Encodes one neutral or preserved stream event for a target provider.

A preserved event replays its retained JSON value unchanged when its source and target formats match. Cross-format encoding intentionally uses only its normalized events.

Source

pub fn finish_stream( &self, state: &mut StreamTranslationState, target: impl Into<FormatId>, ) -> Result<Vec<Value>>

Finishes target-provider stream emission after the source stream closes.

Trait Implementations§

Source§

impl Default for TranslationEngine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more