Skip to main content

PendingServerRequest

Struct PendingServerRequest 

Source
pub struct PendingServerRequest {
    pub request: ServerRequest,
    /* private fields */
}
Expand description

A server->client request the app-server sent us (approvals, elicitation, etc.), paired with a one-shot reply channel. Obtain these from EventStream::recv as an Event::Request.

Every PendingServerRequest gets exactly one reply, no matter what happens to it: call Self::respond or Self::respond_error to send your own, or just let it drop - deliberately, via cancellation, or via a panic unwinding through it - and its Drop impl sends a generic fallback error on your behalf. The app-server is never left permanently unanswered either way. Prefer responding explicitly and promptly when you can; the fallback exists so a bug, an unhandled case, or a task abandoning this value doesn’t turn into a silent hang.

Fields§

§request: ServerRequest

Implementations§

Source§

impl PendingServerRequest

Source

pub fn id(&self) -> &RequestId

The RequestId the app-server expects echoed back in the reply.

Source

pub fn method_name(&self) -> &'static str

The wire method name, e.g. "execCommandApproval".

Source

pub fn expected_response_type_name(&self) -> &'static str

The name of the crate::protocol type Self::respond’s result must serialize to for this specific request, e.g. "ExecCommandApprovalResponse". Prefer this over guessing from Self::method_name - the naming convention (PascalCase(method) + "Response") doesn’t hold for every method (e.g. "item/tool/call" expects DynamicToolCallResponse, not ItemToolCallResponse).

Source

pub fn reply_deadline(&self) -> Instant

Absolute deadline after which the internal forwarding task no longer accepts a reply for this request.

Source

pub fn respond(self, result: impl Serialize) -> Result<()>

Send a successful reply. result must serialize to the response shape the app-server expects for this specific method - see Self::expected_response_type_name for exactly which crate::protocol type that is. Err only means result failed to serialize or the forwarding task already stopped accepting replies.

Source

pub fn respond_error( self, code: i64, message: impl Into<String>, data: Option<Value>, ) -> Result<()>

Send an error reply.

Trait Implementations§

Source§

impl Debug for PendingServerRequest

Source§

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

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

impl Drop for PendingServerRequest

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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