Skip to main content

Crate switchyard_translation

Crate switchyard_translation 

Source
Expand description

Pure Rust translation engine for Switchyard.

The crate translates provider wire formats through a neutral Switchyard conversation IR. It intentionally has no dependency on provider SDKs, HTTP servers, Python objects, or FFI bindings.

Re-exports§

pub use util::PRESERVATION_METADATA_KEY;
pub use util::normalize_anthropic_tool_use_ids;
pub use util::sanitize_anthropic_tool_use_id;
pub use diagnostic::*;
pub use engine::*;
pub use error::*;
pub use policy::*;
pub use stream::*;

Modules§

codecs
Buffered wire-format codecs that translate between provider JSON and IR.
diagnostic
Diagnostics emitted when translation preserves, drops, or degrades data.
engine
Registry-backed translation engine for buffered requests and responses.
error
Error types for request, response, and streaming translation.
format
Wire-format identifiers carried by the shared protocol types.
llm
Provider-neutral conversation types shared by routing, clients, and translation.
policy
Policy knobs that control translation strictness and target capabilities.
stream
Public compatibility module for streaming translation APIs.
util
Shared helpers for codec validation, diagnostics, and preservation metadata.

Structs§

AggLlmResponse
Normalized, fully-buffered response — the aggregate of a completed generation. This is the terminal form of a streamed LlmResponse.
FormatId
Extensible wire-format identifier used by codec registries.
InputCacheUsage
Optional cache-token detail kept out of the common, cache-free usage allocation.
InstructionBlock
Instruction content separated from normal conversation messages.
LlmRequest
Normalized request representation shared by Switchyard components.
LlmResponseStreamEvent
One streaming item crossing the host/algorithm boundary.
Message
One normalized conversation message.
OutputParams
Output budget and structured-output options.
PreservationMetadata
Exact source payloads retained for lossless same-format round trips.
ProviderExtensions
Provider-specific fields that do not have first-class conversation fields.
ProviderStreamEvent
Parsed provider event retained for same-format replay.
ReasoningParams
Provider reasoning controls preserved by translation.
ResponseOutput
One assistant output item in a normalized response.
SamplingParams
Provider sampling parameters with common cross-provider names.
ToolCall
Normalized assistant tool call.
ToolDefinition
Normalized tool definition.
ToolResult
Normalized tool result message content.
Usage
Normalized token usage counts.

Enums§

ContentBlock
Normalized content block variants carried by messages and tool results.
FileSource
File payload forms supported by the conversation model.
ImageSource
Image payload forms supported by the conversation model.
LlmResponseChunk
One provider-neutral streaming response chunk.
MediaSource
Audio and video payload forms supported by the conversation model.
Role
Actor role normalized across provider APIs.
StopReason
Normalized reason a model stopped producing output.
ToolChoice
Normalized tool choice policy.
WireFormat
Built-in provider API formats.

Functions§

decode_aggregated_response
Decodes a buffered wire_format response body into the neutral aggregate.
decode_request
Decodes a wire_format request body into the neutral IR.
decode_stream
Decodes a byte stream of source-format SSE frames into neutral IR chunks.
encode_aggregated_response
Encodes a buffered aggregate into wire_format’s JSON body, stamping served_model over the encoded id so the caller sees which model answered. Passing None leaves the id the upstream reported.
encode_request
Encodes a normalized request into wire_format’s JSON body.
encode_stream
Encodes a stream of IR chunks into a stream of target-format wire events.

Type Aliases§

LlmResponseStream
A boxed, Send stream of response events. Each item may fail independently mid-stream.
RawEventStream
A stream of wire-format event objects in one format — the unframed body of an SSE response. The serving layer frames each Value (e.g. as an SSE data:/event: block).