nomux-extension 0.1.2

The nomux extension SDK: the daemon part of an extension and the extension manifest
Documentation
// This file is @generated by prost-build.
/// Calls one method.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct CallRequest {
    /// The name of the method.
    ///
    /// From the host: a method that the extension supplies, for example `echo`.
    /// From the extension: a method of a host service in the form
    /// `<service>.<method>`, for example `sessions.list`.
    #[prost(string, tag = "1")]
    pub method: ::prost::alloc::string::String,
    /// The argument of the method. The method specifies the encoding. The Rust
    /// SDK uses an encoded protobuf message.
    #[prost(bytes = "vec", tag = "2")]
    pub payload: ::prost::alloc::vec::Vec<u8>,
}
/// The reply to `CallRequest`.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct CallResponse {
    /// The result of the method. The method specifies the encoding.
    #[prost(bytes = "vec", tag = "1")]
    pub payload: ::prost::alloc::vec::Vec<u8>,
}
/// A version of the extension API. The extension API uses Semantic Versioning
/// 2.0.0 and its version is independent of the product version of nomux.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ApiVersion {
    /// The major version.
    #[prost(uint32, tag = "1")]
    pub major: u32,
    /// The minor version.
    #[prost(uint32, tag = "2")]
    pub minor: u32,
    /// The patch version.
    #[prost(uint32, tag = "3")]
    pub patch: u32,
}
/// The permissions that the user approved for the extension.
///
/// The source is the `\[permissions\]` table of `extension.toml`. The host
/// applies the permissions. The extension reads them to know what it can do.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Permissions {
    /// The directories that the extension can read and write. Each item is an
    /// absolute path. The host replaced each variable of the manifest, for
    /// example `${worktree}`.
    #[prost(string, repeated, tag = "1")]
    pub fs: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
    /// The programs that the extension can start. Each item is a program name.
    #[prost(string, repeated, tag = "2")]
    pub process: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
    /// `true` if the extension can open network connections.
    #[prost(bool, tag = "3")]
    pub network: bool,
    /// The scopes of host services that the extension can use, for example
    /// `sessions:read`.
    #[prost(string, repeated, tag = "4")]
    pub scopes: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
/// The first message from the host.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Hello {
    /// The extension API version that the host supplies.
    #[prost(message, optional, tag = "1")]
    pub api_version: ::core::option::Option<ApiVersion>,
    /// The identifier of the extension in its manifest, for example `nomux.git`.
    #[prost(string, tag = "2")]
    pub extension_id: ::prost::alloc::string::String,
    /// The permissions that the extension has.
    #[prost(message, optional, tag = "3")]
    pub permissions: ::core::option::Option<Permissions>,
}
/// The reply from the extension to `Hello`.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Welcome {
    /// The extension API version that the extension was built for.
    #[prost(message, optional, tag = "1")]
    pub api_version: ::core::option::Option<ApiVersion>,
    /// The identifier that the extension has in its code. The host stops the
    /// extension if the value is different from the identifier in the manifest.
    #[prost(string, tag = "2")]
    pub extension_id: ::prost::alloc::string::String,
    /// The version of the extension, for example `1.0.0`.
    #[prost(string, tag = "3")]
    pub extension_version: ::prost::alloc::string::String,
}
/// Tells the extension to prepare for calls. The host sends it one time, after
/// the handshake and before the first call.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct InitializeRequest {}
/// The reply to `InitializeRequest`. After it, the extension accepts calls.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct InitializeResponse {}
/// Tells the extension to stop. The host sends it when the extension is idle
/// or when the daemon stops.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ShutdownRequest {}
/// The reply to `ShutdownRequest`. The extension sends it and then exits.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct ShutdownResponse {}
/// Asks the extension if it can still read and write messages.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct HealthRequest {}
/// The reply to `HealthRequest`. An extension answers also while a call runs.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct HealthResponse {}
/// The failure result of a request.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Error {
    /// The reason for the failure.
    #[prost(enumeration = "ErrorCode", tag = "1")]
    pub code: i32,
    /// A message in English for the user. The text is not stable: a peer must
    /// not parse it.
    #[prost(string, tag = "2")]
    pub message: ::prost::alloc::string::String,
}
/// A numbered request from one peer to the other peer.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Request {
    /// The request number. The sender selects the value. The value is not 0 and
    /// is different from the `id` of each request of the same sender that has
    /// no response yet. Each peer has its own numbers.
    #[prost(uint64, tag = "1")]
    pub id: u64,
    /// The request body. See the field number plan at the top of this file.
    #[prost(oneof = "request::Body", tags = "100, 200, 201, 202, 300")]
    pub body: ::core::option::Option<request::Body>,
}
/// Nested message and enum types in `Request`.
pub mod request {
    /// The request body. See the field number plan at the top of this file.
    #[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)]
    pub enum Body {
        /// Handshake: the first request. Only the host sends it.
        #[prost(message, tag = "100")]
        Hello(super::Hello),
        /// Life cycle: prepare for calls. Only the host sends it.
        #[prost(message, tag = "200")]
        Initialize(super::InitializeRequest),
        /// Life cycle: stop. Only the host sends it.
        #[prost(message, tag = "201")]
        Shutdown(super::ShutdownRequest),
        /// Life cycle: liveness check. Only the host sends it.
        #[prost(message, tag = "202")]
        Health(super::HealthRequest),
        /// A call. The host calls a method of the extension, or the extension
        /// calls a method of a host service.
        #[prost(message, tag = "300")]
        Call(super::CallRequest),
    }
}
/// The response to one request.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Response {
    /// The `id` of the request that this response answers.
    #[prost(uint64, tag = "1")]
    pub id: u64,
    /// The result of the request. See the field number plan at the top of this
    /// file.
    #[prost(oneof = "response::Result", tags = "2, 100, 200, 201, 202, 300")]
    pub result: ::core::option::Option<response::Result>,
}
/// Nested message and enum types in `Response`.
pub mod response {
    /// The result of the request. See the field number plan at the top of this
    /// file.
    #[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)]
    pub enum Result {
        /// The request failed.
        #[prost(message, tag = "2")]
        Error(super::Error),
        /// Handshake: the reply to `Hello`.
        #[prost(message, tag = "100")]
        Welcome(super::Welcome),
        /// The reply to `InitializeRequest`.
        #[prost(message, tag = "200")]
        Initialize(super::InitializeResponse),
        /// The reply to `ShutdownRequest`.
        #[prost(message, tag = "201")]
        Shutdown(super::ShutdownResponse),
        /// The reply to `HealthRequest`.
        #[prost(message, tag = "202")]
        Health(super::HealthResponse),
        /// The reply to `CallRequest`.
        #[prost(message, tag = "300")]
        Call(super::CallResponse),
    }
}
/// A message from the extension that no request asked for.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Event {
    /// The name of the event. The extension selects the name. The host adds the
    /// identifier of the extension, thus two extensions can use the same name.
    #[prost(string, tag = "1")]
    pub name: ::prost::alloc::string::String,
    /// The data of the event. The host does not read it.
    #[prost(bytes = "vec", tag = "2")]
    pub payload: ::prost::alloc::vec::Vec<u8>,
}
/// Tells the receiver to stop a request.
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Cancel {
    /// The `id` of a request that the sender of this message sent before.
    #[prost(uint64, tag = "1")]
    pub id: u64,
}
/// One message between the host and the extension.
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Envelope {
    /// The content of the envelope.
    #[prost(oneof = "envelope::Kind", tags = "1, 2, 3, 4")]
    pub kind: ::core::option::Option<envelope::Kind>,
}
/// Nested message and enum types in `Envelope`.
pub mod envelope {
    /// The content of the envelope.
    #[derive(Clone, PartialEq, Eq, Hash, ::prost::Oneof)]
    pub enum Kind {
        /// A request.
        #[prost(message, tag = "1")]
        Request(super::Request),
        /// The response to a request of the other peer.
        #[prost(message, tag = "2")]
        Response(super::Response),
        /// An event from the extension.
        #[prost(message, tag = "3")]
        Event(super::Event),
        /// The cancellation of a request.
        #[prost(message, tag = "4")]
        Cancel(super::Cancel),
    }
}
/// The reason for a failed request.
///
/// The values 1 to 5 are equal to the values of `ErrorCode` in the nomux
/// control protocol (package `nomux.wire.v1`).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum ErrorCode {
    /// The sender did not set the field. The receiver treats this as
    /// `ERROR_CODE_FAILED`. The receiver does the same for a value that it does
    /// not know.
    Unspecified = 0,
    /// The request failed, and no other code gives the reason.
    Failed = 1,
    /// The method or the item that the request names does not exist.
    NotFound = 2,
    /// The receiver did not complete the request in the permitted time.
    Timeout = 3,
    /// The extension does not have the permission that the request needs.
    PermissionDenied = 4,
    /// The host does not supply the extension API version that the extension
    /// needs. Only the reply to `Hello` uses this code.
    VersionIncompatible = 5,
    /// The receiver cannot read the payload of the request.
    InvalidArgument = 6,
    /// The receiver stopped the request because the sender sent `Cancel`.
    Cancelled = 7,
}
impl ErrorCode {
    /// String value of the enum field names used in the ProtoBuf definition.
    ///
    /// The values are not transformed in any way and thus are considered stable
    /// (if the ProtoBuf definition does not change) and safe for programmatic use.
    pub fn as_str_name(&self) -> &'static str {
        match self {
            Self::Unspecified => "ERROR_CODE_UNSPECIFIED",
            Self::Failed => "ERROR_CODE_FAILED",
            Self::NotFound => "ERROR_CODE_NOT_FOUND",
            Self::Timeout => "ERROR_CODE_TIMEOUT",
            Self::PermissionDenied => "ERROR_CODE_PERMISSION_DENIED",
            Self::VersionIncompatible => "ERROR_CODE_VERSION_INCOMPATIBLE",
            Self::InvalidArgument => "ERROR_CODE_INVALID_ARGUMENT",
            Self::Cancelled => "ERROR_CODE_CANCELLED",
        }
    }
    /// Creates an enum from field names used in the ProtoBuf definition.
    pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
        match value {
            "ERROR_CODE_UNSPECIFIED" => Some(Self::Unspecified),
            "ERROR_CODE_FAILED" => Some(Self::Failed),
            "ERROR_CODE_NOT_FOUND" => Some(Self::NotFound),
            "ERROR_CODE_TIMEOUT" => Some(Self::Timeout),
            "ERROR_CODE_PERMISSION_DENIED" => Some(Self::PermissionDenied),
            "ERROR_CODE_VERSION_INCOMPATIBLE" => Some(Self::VersionIncompatible),
            "ERROR_CODE_INVALID_ARGUMENT" => Some(Self::InvalidArgument),
            "ERROR_CODE_CANCELLED" => Some(Self::Cancelled),
            _ => None,
        }
    }
}