Skip to main content

Module ir

Module ir 

Source
Expand description

The canonical, version-agnostic IR.

§What this is for

Application code and user handlers see these types. They do not see a revision’s wire types, and they never choose a version at compile time. T08 adds per-revision codecs that lift the wire into this IR and lower it back out, so the same handler serves every revision and the bridge between them is pure data.

§The three properties everything here is built around

Superset. Every revision’s types are a subset of these. Fields a newer revision added are Option and absent on older ones, so a 2024-11-05 value and a 2026-07-28 value are both representable, and the difference is visible rather than typed away.

Self-describing requirements. Every value can report what it needs to be expressed through required_features(). Lowering asks that question rather than pattern-matching on a version, so adding a revision does not mean touching every encoder — a new revision turns on the features it defines, and the existing gates do the rest.

Lossless. Unmodelled fields land in an Extensions bag instead of being dropped, and an unparseable value lands as Raw rather than disappearing. The bridge’s lift(v, lower(v, ir)) == ir claim is only meaningful because of this, and it is the property the crate exists for.

§The layering

mod features;    // FeatureSet — what a value needs
mod json;        // JsonObject — arbitrary JSON, validated once
mod extensions;  // Extensions  — the passthrough bag
mod content;     // Content     — content blocks
mod message;     // IrMessage   — the envelope
mod tool;        // ToolResult  — and the downgrade fallback

Each file holds one concern, and the dependency direction is downward: content, tool, codec and lower use features, json and extensions, and nothing uses content. message sits above the rest and is the only place they are assembled. codec and lower are public because the adapter layer implements their traits and a bridge reads the reports those traits produce.

Re-exports§

pub use loglevel::Level as LogLevel;
pub use loglevel::LevelError as LogLevelError;
pub use lower::DegradeRule;
pub use lower::Loss;
pub use lower::LowerError;
pub use lower::Lowering;
pub use lower::TranslationReport;
pub use lower::TranslationStep;

Modules§

loglevel
LogLevel — the severity ladder a notifications/message record carries.
lower
Lowering — making an IR value expressible at a target revision, or refusing.

Structs§

Annotations
Annotations, added in 2025-03-26 (PR #185).
AudioContent
The audio block, 2025-03-26 and later.
Downgrade
A change lowering made to make a value expressible.
EmbeddedResource
A resource’s contents, inline.
Extensions
Unmodelled fields, in serde_json::Map order.
FeatureSet
A set of features.
GetPromptResult
What prompts/get answers with.
ImageContent
{"type": "image", "data": "...", "mimeType": "..."}.
IrError
An error result.
IrNotification
A notification. Never has an id, never gets a reply.
IrParams
The parameters of a request or notification.
IrRequest
A request. Expects exactly one result or error.
IrResult
A successful result.
JsonObject
A JSON object, validated on construction.
MethodName
A method name, validated.
PromptMessage
One message of a prompts/get result.
ResourceContents
One entry of a resources/read result’s contents array.
ResourceIcon
An icon for a resource link. 2025-11-25, SEP-973.
ResourceLinkContent
A link to a resource, 2025-06-18 and later (PR #603).
TextContent
{"type": "text", "text": "..."}.
ToolResult
The result of calling a tool.
UnknownContent
A content block whose type this build does not know.
UnknownRole
A role this build does not recognise.

Enums§

Content
A content block.
EnvelopeError
An envelope this build could not lift.
ExtensionValue
The value of an unmodelled field.
IrErrorCode
A JSON-RPC error code.
IrMessage
Any message in either direction.
JsonObjectError
Why a string is not a JsonObject.
MethodNameError
Why a method name is not a MethodName.
ResourceBody
A resource’s body.
Role
Who a content block is meant for.

Traits§

Codec
Translates between one revision’s wire type and the canonical IR.

Functions§

lift_envelope
Lifts one wire envelope into the IR.
lower_envelope
Re-emits an IR message as a wire envelope.