chore: add #[non_exhaustive] and mutation methods to improve compatibility (#715)

* chore: add #[non_exhaustive] to reduce backwards-incompatible changes going forward

* fix: remove ProtocolVersion import

* fix: add a few more with_ mutator methods

---------

Co-authored-by: Alex Hancock <alexhancock@block.xyz>
This commit is contained in:
Jack Amadeo 2026-03-03 10:38:01 -05:00 • committed by GitHub
commit f63718d202
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -28,6 +28,7 @@ pub enum TaskStatus {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub struct Task {
/// Unique task identifier generated by the receiver.
pub task_id: String,
@ -48,14 +49,60 @@ pub struct Task {
pub poll_interval: Option<u64>,
}
impl Task {
/// Create a new Task with required fields.
pub fn new(
task_id: String,
status: TaskStatus,
created_at: String,
last_updated_at: String,
) -> Self {
Self {
task_id,
status,
status_message: None,
created_at,
last_updated_at,
ttl: None,
poll_interval: None,
}
}
/// Set the status message.
pub fn with_status_message(mut self, status_message: impl Into<String>) -> Self {
self.status_message = Some(status_message.into());
self
}
/// Set the TTL in milliseconds. `None` means unlimited retention.
pub fn with_ttl(mut self, ttl: u64) -> Self {
self.ttl = Some(ttl);
self
}
/// Set the poll interval in milliseconds.
pub fn with_poll_interval(mut self, poll_interval: u64) -> Self {
self.poll_interval = Some(poll_interval);
self
}
}
/// Wrapper returned by task-augmented requests (CreateTaskResult in SEP-1686).
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub struct CreateTaskResult {
pub task: Task,
}
impl CreateTaskResult {
/// Create a new CreateTaskResult.
pub fn new(task: Task) -> Self {
Self { task }
}
}
/// Response to a `tasks/get` request.
///
/// Per spec, `GetTaskResult = allOf[Result, Task]` — the Task fields are
@ -78,8 +125,16 @@ pub struct GetTaskResult {
/// serialized as a JSON value.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub struct GetTaskPayloadResult(pub Value);
impl GetTaskPayloadResult {
/// Create a new GetTaskPayloadResult with the given value.
pub fn new(value: Value) -> Self {
Self(value)
}
}
/// Response to a `tasks/cancel` request.
///
/// Per spec, `CancelTaskResult = allOf[Result, Task]` — same shape as `GetTaskResult`.
@ -104,3 +159,14 @@ pub struct TaskList {
#[serde(skip_serializing_if = "Option::is_none")]
pub total: Option<u64>,
}
impl TaskList {
/// Create a new TaskList.
pub fn new(tasks: Vec<Task>) -> Self {
Self {
tasks,
next_cursor: None,
total: None,
}
}
}