From 67b2134d2c68f1a424f7d693479b58250611fba2 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Sun, 25 Jan 2026 09:12:28 +0000 Subject: [PATCH] feat: elevation --- --- a/crates/remowt-link-shared/src/lib.rs +++ b/crates/remowt-link-shared/src/lib.rs @@ -1,39 +1,111 @@ +use bifrostlink::declarative::endpoints; use bifrostlink::error::{ErrorT, ListenerForYourRequestHasBeenDeadError, ResponseError}; -use bifrostlink::AddressT; +use bifrostlink::notification; +use bifrostlink::packet::OpaquePacketWrapper; +use bifrostlink::{AddressT, Config}; +use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; +pub mod editor; + #[derive(Clone, Serialize, Hash, Eq, Debug, PartialEq, Deserialize)] pub enum Address { User, - Agent, + Agent, + AgentPrivileged, } impl AddressT for Address {} +pub use remowt_fs::{Error as FsError, Fs, FsClient}; +pub use remowt_pty::{Error as PtyError, Pty, PtyClient, ShellId}; +pub use remowt_systemd::{Error as SystemdError, Systemd, SystemdClient}; + +#[derive(Serialize, Deserialize, Debug, thiserror::Error)] +pub enum ElevateError { + #[error("elevation failed: {0}")] + Failed(String), +} + +pub trait Elevator: Send + Sync { + fn elevate(&self) -> impl std::future::Future> + Send; +} + +pub struct ElevateEndpoints(pub E); + +#[endpoints(ns = 3)] +impl ElevateEndpoints { + #[endpoints(id = 1)] + async fn elevate(&self) -> Result<(), ElevateError> { + self.0.elevate().await + } +} + #[derive(thiserror::Error, Debug)] pub enum Error { - #[error("listener is dead")] - ListenerDead, - #[error("response: {0}")] - Response(String), + #[error("listener is dead")] + ListenerDead, + #[error("response: {0}")] + Response(String), + + #[error(transparent)] + Ui(#[from] ui_prompt::Error), } + impl From for Error { - fn from(_value: ListenerForYourRequestHasBeenDeadError) -> Self { - Self::ListenerDead - } + fn from(_value: ListenerForYourRequestHasBeenDeadError) -> Self { + Self::ListenerDead + } } impl From for Error { - fn from(_value: serde_json::Error) -> Self { - Self::ListenerDead - } + fn from(_value: serde_json::Error) -> Self { + Self::ListenerDead + } } impl From for ResponseError { - fn from(val: Error) -> Self { - ResponseError(val.to_string()) - } + fn from(val: Error) -> Self { + ResponseError(val.to_string()) + } } impl From for Error { - fn from(value: ResponseError) -> Self { - Self::Response(value.0) - } + fn from(value: ResponseError) -> Self { + Self::Response(value.0) + } } impl ErrorT for Error {} + +#[derive(Serialize, Deserialize, Debug)] +pub struct TestNotification { + pub value: u32, +} +notification!((0x0100) TestNotification); + +pub struct BifConfig; +impl bifrostlink::Config for BifConfig { + type Address = Address; + + type Error = Error; + + type EncodedData = Vec; + + fn decode_headers( + data_with_headers: bytes::Bytes, + ) -> Result<(OpaquePacketWrapper, Self::EncodedData), Self::Error> { + let (header, data): (OpaquePacketWrapper, Vec) = + serde_json::from_slice(&data_with_headers)?; + Ok((header, data)) + } + + fn decode_data(data: Self::EncodedData) -> Result { + let v: T = serde_json::from_slice(&data)?; + Ok(v) + } + + fn encode_data( + headers: OpaquePacketWrapper, + data: T, + ) -> bytes::Bytes { + let data = serde_json::to_vec(&data).expect("serialization shouldn't fail"); + let o = serde_json::to_vec(&(headers, data)).expect("serialization shouldn't fail"); + o.into() + } +} -- gitstuff