Skip to main content

AgentResponse

Enum AgentResponse 

Source
pub enum AgentResponse {
    Ok {
        data: Option<Value>,
    },
    Pong {
        version: u32,
    },
    Progress {
        message: String,
        percent: Option<u8>,
        layer: Option<String>,
    },
    Error {
        message: String,
        code: Option<String>,
    },
    Completed {
        exit_code: i32,
        stdout: Vec<u8>,
        stderr: Vec<u8>,
    },
    Started,
    Stdout {
        data: Vec<u8>,
    },
    Stderr {
        data: Vec<u8>,
    },
    Exited {
        exit_code: i32,
    },
    DataChunk {
        data: Vec<u8>,
        done: bool,
    },
}
Expand description

Agent response types.

Variants§

§

Ok

Operation completed successfully.

Fields

§data: Option<Value>

Response data (varies by request type).

§

Pong

Pong response to ping.

Fields

§version: u32

Protocol version.

§

Progress

Progress update (for long operations like pull).

Fields

§message: String

Human-readable message.

§percent: Option<u8>

Completion percentage (0-100).

§layer: Option<String>

Current layer being processed.

§

Error

Operation failed.

Fields

§message: String

Error message.

§code: Option<String>

Error code (for programmatic handling).

§

Completed

Command execution completed (non-interactive mode).

Fields

§exit_code: i32

Exit code from the command.

§stdout: Vec<u8>

Standard output (may be truncated). Vec<u8> preserves binary output (image bytes, tarballs, etc.) that would be truncated by String at the first non-UTF-8 byte. Serialized as base64 JSON string — the same format as the streaming Stdout variant.

§stderr: Vec<u8>

Standard error (may be truncated).

§

Started

Command started (interactive mode). Indicates the command is running and ready to receive stdin.

§

Stdout

Stdout data from a running command (interactive mode).

Fields

§data: Vec<u8>

Output data.

§

Stderr

Stderr data from a running command (interactive mode).

Fields

§data: Vec<u8>

Error output data.

§

Exited

Command exited (interactive mode).

Fields

§exit_code: i32

Exit code from the command.

§

DataChunk

Streaming binary-data chunk.

Used by every streaming download direction: the agent sends one or more DataChunk responses in sequence, with done: true on the final chunk. Current producers: ExportLayer and FileRead.

Payload size per chunk should stay under LAYER_CHUNK_SIZE so the encoded frame (~1.33× after base64) fits inside MAX_FRAME_SIZE with JSON overhead to spare.

Fields

§data: Vec<u8>

Chunk bytes. Empty allowed on the final frame (common for EOF-on-clean-boundary cases).

§done: bool

True on the final chunk of the stream.

Implementations§

Source§

impl AgentResponse

Source

pub fn error(message: impl Into<String>, code: &str) -> Self

Create an error response with the given message and code.

§Example
use smolvm_protocol::{AgentResponse, error_codes};

let response = AgentResponse::error("image not found", error_codes::NOT_FOUND);
Source

pub fn from_err<E: Display>(err: E, code: &str) -> Self

Create an error response from a Result’s error, with the given code.

§Example
let response = some_operation()
    .map(|data| AgentResponse::ok_with_data(data))
    .unwrap_or_else(|e| AgentResponse::from_err(e, error_codes::PULL_FAILED));
Source

pub fn ok(data: Option<Value>) -> Self

Create an Ok response with optional JSON data.

Source

pub fn ok_with_data<T: Serialize>(data: T) -> Self

Create an Ok response with JSON-serializable data.

Returns an error response if serialization fails.

Source

pub fn from_result<T, E>(result: Result<T, E>, error_code: &str) -> Self
where T: Serialize, E: Display,

Convert a Result into an AgentResponse.

On success, serializes the value to JSON. On error, creates an error response.

§Example
let response = AgentResponse::from_result(
    storage::pull_image(image),
    error_codes::PULL_FAILED,
);

Trait Implementations§

Source§

impl Clone for AgentResponse

Source§

fn clone(&self) -> AgentResponse

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AgentResponse

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for AgentResponse

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for AgentResponse

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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