Skip to main content

MessageView

Struct MessageView 

Source
pub struct MessageView<'a> { /* private fields */ }
Expand description

Read-only, zero-copy view over a single content part.

Provides a uniform interface for policy evaluation regardless of content type. Properties are computed on-demand by borrowing the underlying content part and extensions.

Produced by Message::iter_views() or the standalone iter_views().

Implementations§

Source§

impl<'a> MessageView<'a>

Source

pub fn new( part: &'a ContentPart, role: Role, hook: Option<&'a str>, extensions: Option<&'a Extensions>, ) -> Self

Create a new view over a content part.

Source

pub fn kind(&self) -> ViewKind

The kind of content this view represents.

Source

pub fn role(&self) -> Role

The role of the parent message.

Source

pub fn raw(&self) -> &'a ContentPart

The underlying content part.

Source

pub fn hook(&self) -> Option<&str>

The hook location, if set.

Source

pub fn action(&self) -> ViewAction

The action this content represents.

Source

pub fn is_pre(&self) -> bool

Whether this is a pre-execution hook (tool_pre_invoke, prompt_pre_fetch, etc.).

Source

pub fn is_post(&self) -> bool

Whether this is a post-execution hook.

Source

pub fn content(&self) -> Option<&str>

Text content (for text, thinking, tool result content).

Source

pub fn name(&self) -> Option<&str>

Entity name (tool name, resource URI, prompt name).

Source

pub fn uri(&self) -> Option<String>

URI for the entity.

Source

pub fn args(&self) -> Option<&HashMap<String, Value>>

Arguments (for tool calls and prompt requests).

Source

pub fn get_arg(&self, name: &str) -> Option<&Value>

Get a specific argument by name.

Source

pub fn has_arg(&self, name: &str) -> bool

Whether this content has arguments.

Source

pub fn mime_type(&self) -> Option<&str>

MIME type (for resources, media).

Source

pub fn is_error(&self) -> bool

Whether the result is an error (tool results, prompt results).

Source

pub fn is_tool(&self) -> bool

Source

pub fn is_resource(&self) -> bool

Source

pub fn is_prompt(&self) -> bool

Source

pub fn is_media(&self) -> bool

Source

pub fn is_text(&self) -> bool

Source

pub fn extensions(&self) -> Option<&'a Extensions>

Get the extensions, if provided.

Source

pub fn has_label(&self, label: &str) -> bool

Check if a security label exists.

Source

pub fn get_header(&self, name: &str) -> Option<&str>

Get an HTTP header value.

Source

pub fn to_dict(&self, include_content: bool, include_context: bool) -> Value

Serialize the view to a JSON-compatible map.

Includes the view’s properties, arguments, and optionally text content and extension context. Sensitive headers (Authorization, Cookie, X-API-Key) are stripped.

Source

pub fn to_opa_input(&self, include_content: bool) -> Value

Serialize to OPA-compatible input format.

Wraps the view in the standard OPA input envelope: {"input": {...view data...}}.

Trait Implementations§

Source§

impl<'a> Debug for MessageView<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for MessageView<'a>

§

impl<'a> RefUnwindSafe for MessageView<'a>

§

impl<'a> Send for MessageView<'a>

§

impl<'a> Sync for MessageView<'a>

§

impl<'a> Unpin for MessageView<'a>

§

impl<'a> UnsafeUnpin for MessageView<'a>

§

impl<'a> UnwindSafe for MessageView<'a>

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.

Source§

impl<T> Instrument for T

Source§

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

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

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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