pub enum StandardRequest<T = Value>{
Confirm {
message: String,
default: Option<bool>,
},
Prompt {
message: String,
default: Option<T>,
placeholder: Option<String>,
},
Select {
message: String,
options: Vec<SelectOption<T>>,
multi_select: bool,
},
Custom {
data: T,
},
}Expand description
Standard request types for common interactive UI patterns.
These request types cover the most common server-to-client interactions:
- Confirm: Yes/no questions before important actions
- Prompt: Free-form text input from the user
- Select: Choose one or more options from a list
- Custom: Domain-specific request payload
The type parameter T defaults to serde_json::Value for backwards compatibility.
Use a custom type for domain-specific interactions.
For domain-specific interactions (e.g., image quality selection, custom
dialogs), define your own request/response enums and use
BidirChannel<YourRequest, YourResponse>.
§Wire Format
Uses internally-tagged JSON (#[serde(tag = "type")]):
// Confirm request
{
"type": "confirm",
"message": "Delete 3 files?",
"default": false
}
// Prompt request
{
"type": "prompt",
"message": "Enter project name:",
"default": "my-project",
"placeholder": "project-name"
}
// Select request
{
"type": "select",
"message": "Choose template:",
"options": [
{ "value": "minimal", "label": "Minimal", "description": "Bare-bones starter" },
{ "value": "full", "label": "Full Featured" }
],
"multiSelect": false
}§Client Implementation
Clients should display appropriate UI for each request type:
| Type | UI Suggestion |
|---|---|
confirm | Yes/No buttons or checkbox |
prompt | Text input field |
select | Dropdown, radio buttons, or checkbox list |
custom | Application-defined |
Variants§
Confirm
Binary yes/no confirmation request.
Use this for important decisions like:
- Confirming destructive operations (“Delete 3 files?”)
- Proceeding with potentially expensive operations
- Accepting terms or conditions
The default field suggests the default choice if the user
doesn’t explicitly respond (e.g., just presses Enter).
Fields
Prompt
Free-form text input request.
Use this for collecting:
- Names, titles, identifiers
- Paths, URLs
- Custom values not in a predefined list
For password/sensitive input, clients should use appropriate input masking.
Fields
Select
Selection request for choosing from options.
Use this when the valid choices are known ahead of time. Supports both single and multiple selection.
§Example
let options = vec![
SelectOption::new("dev", "Development")
.with_description("Local dev environment"),
SelectOption::new("prod", "Production")
.with_description("Live servers"),
];
let selected = ctx.select("Choose environment:", options).await?;Fields
options: Vec<SelectOption<T>>Available options to choose from. Each option has a value (returned) and label (displayed).
Custom
Custom domain-specific request payload.
Use this for application-specific interactions that don’t fit the standard confirm/prompt/select patterns.
Fields
data: TThe custom request data.
Trait Implementations§
Source§impl<T> Clone for StandardRequest<T>
impl<T> Clone for StandardRequest<T>
Source§fn clone(&self) -> StandardRequest<T>
fn clone(&self) -> StandardRequest<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T> Debug for StandardRequest<T>
impl<T> Debug for StandardRequest<T>
Source§impl<'de, T> Deserialize<'de> for StandardRequest<T>
impl<'de, T> Deserialize<'de> for StandardRequest<T>
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<StandardRequest<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<StandardRequest<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<T> JsonSchema for StandardRequest<T>
impl<T> JsonSchema for StandardRequest<T>
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl<T> PartialEq for StandardRequest<T>
impl<T> PartialEq for StandardRequest<T>
Source§impl<T> Serialize for StandardRequest<T>
impl<T> Serialize for StandardRequest<T>
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl<T> StructuralPartialEq for StandardRequest<T>
Auto Trait Implementations§
impl<T> Freeze for StandardRequest<T>where
T: Freeze,
impl<T> RefUnwindSafe for StandardRequest<T>where
T: RefUnwindSafe,
impl<T> Send for StandardRequest<T>where
T: Send,
impl<T> Sync for StandardRequest<T>where
T: Sync,
impl<T> Unpin for StandardRequest<T>where
T: Unpin,
impl<T> UnsafeUnpin for StandardRequest<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for StandardRequest<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more