pub struct TranslationEngine { /* private fields */ }Expand description
Stateless request/response translator that routes through the neutral IR.
Implementations§
Source§impl TranslationEngine
impl TranslationEngine
Sourcepub fn new(registry: FormatRegistry) -> Self
pub fn new(registry: FormatRegistry) -> Self
Creates an engine from an explicit buffered codec registry.
Sourcepub fn with_registries(
registry: FormatRegistry,
stream_registry: StreamCodecRegistry,
) -> Self
pub fn with_registries( registry: FormatRegistry, stream_registry: StreamCodecRegistry, ) -> Self
Creates an engine from explicit buffered and streaming codec registries.
Sourcepub fn decode_request(
&self,
source: impl Into<FormatId>,
body: &Value,
policy: &TranslationPolicy,
) -> Result<RequestIrOutput>
pub fn decode_request( &self, source: impl Into<FormatId>, body: &Value, policy: &TranslationPolicy, ) -> Result<RequestIrOutput>
Decodes a request body into the neutral request IR.
Sourcepub fn encode_request(
&self,
target: impl Into<FormatId>,
request: &LlmRequest,
policy: &TranslationPolicy,
) -> Result<TranslationOutput>
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.
Sourcepub fn translate_request(
&self,
source: impl Into<FormatId>,
target: impl Into<FormatId>,
body: &Value,
policy: &TranslationPolicy,
) -> Result<TranslationOutput>
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.
Sourcepub fn decode_response(
&self,
source: impl Into<FormatId>,
body: &Value,
policy: &TranslationPolicy,
) -> Result<ResponseIrOutput>
pub fn decode_response( &self, source: impl Into<FormatId>, body: &Value, policy: &TranslationPolicy, ) -> Result<ResponseIrOutput>
Decodes a response body into the neutral response IR.
Sourcepub fn encode_response(
&self,
target: impl Into<FormatId>,
response: &AggLlmResponse,
policy: &TranslationPolicy,
) -> Result<TranslationOutput>
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.
Sourcepub fn translate_response(
&self,
source: impl Into<FormatId>,
target: impl Into<FormatId>,
body: &Value,
policy: &TranslationPolicy,
) -> Result<TranslationOutput>
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.
Sourcepub fn translate_event(
&self,
state: &mut StreamTranslationState,
source: impl Into<FormatId>,
target: impl Into<FormatId>,
event: &Value,
) -> Result<Vec<Value>>
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.
Sourcepub fn decode_stream_event(
&self,
state: &mut StreamTranslationState,
source: impl Into<FormatId>,
event: Value,
) -> Result<LlmResponseStreamEvent>
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.
Sourcepub fn encode_stream_event(
&self,
state: &mut StreamTranslationState,
target: impl Into<FormatId>,
event: LlmResponseStreamEvent,
) -> Result<Vec<Value>>
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.
Sourcepub fn finish_stream(
&self,
state: &mut StreamTranslationState,
target: impl Into<FormatId>,
) -> Result<Vec<Value>>
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.