Skip to content

Commit ee373d3

Browse files
committed
Use maybeundefined
1 parent 3525800 commit ee373d3

File tree

1 file changed

+72
-8
lines changed

1 file changed

+72
-8
lines changed

src/client.rs

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use crate::{
1313
ContentBlock, ExtNotification, ExtRequest, ExtResponse, IntoOption, Meta, Plan, SessionId,
1414
SessionModeId, ToolCall, ToolCallUpdate,
1515
};
16+
#[cfg(feature = "unstable_session_info_update")]
17+
use crate::{IntoMaybeUndefined, MaybeUndefined};
1618

1719
// Session updates
1820

@@ -144,11 +146,11 @@ impl CurrentModeUpdate {
144146
#[non_exhaustive]
145147
pub struct SessionInfoUpdate {
146148
/// Human-readable title for the session. Set to null to clear.
147-
#[serde(skip_serializing_if = "Option::is_none")]
148-
pub title: Option<String>,
149+
#[serde(default, skip_serializing_if = "MaybeUndefined::is_undefined")]
150+
pub title: MaybeUndefined<String>,
149151
/// ISO 8601 timestamp of last activity. Set to null to clear.
150-
#[serde(skip_serializing_if = "Option::is_none")]
151-
pub updated_at: Option<String>,
152+
#[serde(default, skip_serializing_if = "MaybeUndefined::is_undefined")]
153+
pub updated_at: MaybeUndefined<String>,
152154
/// The _meta property is reserved by ACP to allow clients and agents to attach additional
153155
/// metadata to their interactions. Implementations MUST NOT make assumptions about values at
154156
/// these keys.
@@ -167,15 +169,15 @@ impl SessionInfoUpdate {
167169

168170
/// Human-readable title for the session. Set to null to clear.
169171
#[must_use]
170-
pub fn title(mut self, title: impl IntoOption<String>) -> Self {
171-
self.title = title.into_option();
172+
pub fn title(mut self, title: impl IntoMaybeUndefined<String>) -> Self {
173+
self.title = title.into_maybe_undefined();
172174
self
173175
}
174176

175177
/// ISO 8601 timestamp of last activity. Set to null to clear.
176178
#[must_use]
177-
pub fn updated_at(mut self, updated_at: impl IntoOption<String>) -> Self {
178-
self.updated_at = updated_at.into_option();
179+
pub fn updated_at(mut self, updated_at: impl IntoMaybeUndefined<String>) -> Self {
180+
self.updated_at = updated_at.into_maybe_undefined();
179181
self
180182
}
181183

@@ -1647,3 +1649,65 @@ impl AgentNotification {
16471649
}
16481650
}
16491651
}
1652+
1653+
#[cfg(test)]
1654+
mod tests {
1655+
use super::*;
1656+
1657+
#[cfg(feature = "unstable_session_info_update")]
1658+
#[test]
1659+
fn test_serialization_behavior() {
1660+
use serde_json::json;
1661+
1662+
assert_eq!(
1663+
serde_json::from_value::<SessionInfoUpdate>(json!({})).unwrap(),
1664+
SessionInfoUpdate {
1665+
title: MaybeUndefined::Undefined,
1666+
updated_at: MaybeUndefined::Undefined,
1667+
meta: None
1668+
}
1669+
);
1670+
assert_eq!(
1671+
serde_json::from_value::<SessionInfoUpdate>(json!({"title": null, "updatedAt": null}))
1672+
.unwrap(),
1673+
SessionInfoUpdate {
1674+
title: MaybeUndefined::Null,
1675+
updated_at: MaybeUndefined::Null,
1676+
meta: None
1677+
}
1678+
);
1679+
assert_eq!(
1680+
serde_json::from_value::<SessionInfoUpdate>(
1681+
json!({"title": "title", "updatedAt": "timestamp"})
1682+
)
1683+
.unwrap(),
1684+
SessionInfoUpdate {
1685+
title: MaybeUndefined::Value("title".to_string()),
1686+
updated_at: MaybeUndefined::Value("timestamp".to_string()),
1687+
meta: None
1688+
}
1689+
);
1690+
1691+
assert_eq!(
1692+
serde_json::to_value(SessionInfoUpdate::new()).unwrap(),
1693+
json!({})
1694+
);
1695+
assert_eq!(
1696+
serde_json::to_value(SessionInfoUpdate::new().title("title")).unwrap(),
1697+
json!({"title": "title"})
1698+
);
1699+
assert_eq!(
1700+
serde_json::to_value(SessionInfoUpdate::new().title(None)).unwrap(),
1701+
json!({"title": null})
1702+
);
1703+
assert_eq!(
1704+
serde_json::to_value(
1705+
SessionInfoUpdate::new()
1706+
.title("title")
1707+
.title(MaybeUndefined::Undefined)
1708+
)
1709+
.unwrap(),
1710+
json!({})
1711+
);
1712+
}
1713+
}

0 commit comments

Comments
 (0)