Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 177 additions & 0 deletions agent-client-protocol-schema/src/v1/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,84 @@ impl SetSessionModeResponse {
}
}

/// Request parameters for setting a session title.
#[skip_serializing_none]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_TITLE_METHOD_NAME))]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct SetSessionTitleRequest {
/// The ID of the session to set the title for.
pub session_id: SessionId,
/// The new title for the session.
pub title: String,
/// The _meta property is reserved by ACP to allow clients and agents to attach additional
/// metadata to their interactions. Implementations MUST NOT make assumptions about values at
/// these keys.
///
/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
#[serde(rename = "_meta")]
pub meta: Option<Meta>,
}

impl SetSessionTitleRequest {
/// Builds [`SetSessionTitleRequest`] with the required request fields set; optional fields start unset or empty.
#[must_use]
pub fn new(session_id: impl Into<SessionId>, title: impl Into<String>) -> Self {
Self {
session_id: session_id.into(),
title: title.into(),
meta: None,
}
}

/// The _meta property is reserved by ACP to allow clients and agents to attach additional
/// metadata to their interactions. Implementations MUST NOT make assumptions about values at
/// these keys.
///
/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
#[must_use]
pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
self.meta = meta.into_option();
self
}
}

/// Response to `session/setTitle` method.
#[skip_serializing_none]
#[derive(Default, Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[schemars(extend("x-side" = "agent", "x-method" = SESSION_SET_TITLE_METHOD_NAME))]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct SetSessionTitleResponse {
/// The _meta property is reserved by ACP to allow clients and agents to attach additional
/// metadata to their interactions. Implementations MUST NOT make assumptions about values at
/// these keys.
///
/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
#[serde(rename = "_meta")]
pub meta: Option<Meta>,
}

impl SetSessionTitleResponse {
/// Builds [`SetSessionTitleResponse`] with the required response fields set; optional fields start unset or empty.
#[must_use]
pub fn new() -> Self {
Self::default()
}

/// The _meta property is reserved by ACP to allow clients and agents to attach additional
/// metadata to their interactions. Implementations MUST NOT make assumptions about values at
/// these keys.
///
/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
#[must_use]
pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
self.meta = meta.into_option();
self
}
}

// Session config options

/// Unique identifier for a session configuration option.
Expand Down Expand Up @@ -3941,6 +4019,11 @@ pub struct SessionCapabilities {
#[schemars(extend("x-deserialize-default-on-error" = true))]
#[serde(default)]
pub close: Option<SessionCloseCapabilities>,
/// Whether the agent supports `session/setTitle`.
#[serde_as(deserialize_as = "DefaultOnError")]
#[schemars(extend("x-deserialize-default-on-error" = true))]
#[serde(default)]
pub set_title: Option<SessionSetTitleCapabilities>,
/// The _meta property is reserved by ACP to allow clients and agents to attach additional
/// metadata to their interactions. Implementations MUST NOT make assumptions about values at
/// these keys.
Expand Down Expand Up @@ -4010,6 +4093,13 @@ impl SessionCapabilities {
self
}

/// Whether the agent supports `session/setTitle`.
#[must_use]
pub fn set_title(mut self, set_title: impl IntoOption<SessionSetTitleCapabilities>) -> Self {
self.set_title = set_title.into_option();
self
}

/// The _meta property is reserved by ACP to allow clients and agents to attach additional
/// metadata to their interactions. Implementations MUST NOT make assumptions about values at
/// these keys.
Expand Down Expand Up @@ -4241,6 +4331,41 @@ impl SessionCloseCapabilities {
}
}

/// Capabilities for the `session/setTitle` method.
///
/// By supplying `{}` it means that the agent supports setting session titles.
#[skip_serializing_none]
#[derive(Default, Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
#[non_exhaustive]
pub struct SessionSetTitleCapabilities {
/// The _meta property is reserved by ACP to allow clients and agents to attach additional
/// metadata to their interactions. Implementations MUST NOT make assumptions about values at
/// these keys.
///
/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
#[serde(rename = "_meta")]
pub meta: Option<Meta>,
}

impl SessionSetTitleCapabilities {
/// Builds an empty [`SessionSetTitleCapabilities`]; use builder methods to advertise supported sub-capabilities.
#[must_use]
pub fn new() -> Self {
Self::default()
}

/// The _meta property is reserved by ACP to allow clients and agents to attach additional
/// metadata to their interactions. Implementations MUST NOT make assumptions about values at
/// these keys.
///
/// See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility)
#[must_use]
pub fn meta(mut self, meta: impl IntoOption<Meta>) -> Self {
self.meta = meta.into_option();
self
}
}

/// Prompt capabilities supported by the agent in `session/prompt` requests.
///
/// Baseline agent functionality requires support for [`ContentBlock::Text`]
Expand Down Expand Up @@ -4423,6 +4548,8 @@ pub struct AgentMethodNames {
pub session_load: &'static str,
/// Method for setting the mode for a session.
pub session_set_mode: &'static str,
/// Method for setting the title for a session.
pub session_set_title: &'static str,
/// Method for setting a configuration option for a session.
pub session_set_config_option: &'static str,
/// Method for sending a prompt to the agent.
Expand Down Expand Up @@ -4490,6 +4617,7 @@ pub const AGENT_METHOD_NAMES: AgentMethodNames = AgentMethodNames {
session_new: SESSION_NEW_METHOD_NAME,
session_load: SESSION_LOAD_METHOD_NAME,
session_set_mode: SESSION_SET_MODE_METHOD_NAME,
session_set_title: SESSION_SET_TITLE_METHOD_NAME,
session_set_config_option: SESSION_SET_CONFIG_OPTION_METHOD_NAME,
session_prompt: SESSION_PROMPT_METHOD_NAME,
session_cancel: SESSION_CANCEL_METHOD_NAME,
Expand Down Expand Up @@ -4543,6 +4671,8 @@ pub(crate) const SESSION_NEW_METHOD_NAME: &str = "session/new";
pub(crate) const SESSION_LOAD_METHOD_NAME: &str = "session/load";
/// Method name for setting the mode for a session.
pub(crate) const SESSION_SET_MODE_METHOD_NAME: &str = "session/set_mode";
/// Method name for setting the title for a session.
pub(crate) const SESSION_SET_TITLE_METHOD_NAME: &str = "session/setTitle";
/// Method name for setting a configuration option for a session.
pub(crate) const SESSION_SET_CONFIG_OPTION_METHOD_NAME: &str = "session/set_config_option";
/// Method name for sending a prompt.
Expand Down Expand Up @@ -4697,6 +4827,13 @@ pub enum ClientRequest {
///
/// See protocol docs: [Session Modes](https://agentclientprotocol.com/protocol/session-modes)
SetSessionModeRequest(SetSessionModeRequest),
/// Sets the title for a session.
///
/// Empty titles are valid and request that the agent clear the session title.
///
/// This method can be called at any time during a session, whether the Agent is
/// idle or actively generating a response.
SetSessionTitleRequest(SetSessionTitleRequest),
/// Sets the current value for a session configuration option.
SetSessionConfigOptionRequest(SetSessionConfigOptionRequest),
/// Processes a user prompt within a session.
Expand Down Expand Up @@ -4774,6 +4911,7 @@ impl ClientRequest {
Self::ResumeSessionRequest(_) => AGENT_METHOD_NAMES.session_resume,
Self::CloseSessionRequest(_) => AGENT_METHOD_NAMES.session_close,
Self::SetSessionModeRequest(_) => AGENT_METHOD_NAMES.session_set_mode,
Self::SetSessionTitleRequest(_) => AGENT_METHOD_NAMES.session_set_title,
Self::SetSessionConfigOptionRequest(_) => AGENT_METHOD_NAMES.session_set_config_option,
Self::PromptRequest(_) => AGENT_METHOD_NAMES.session_prompt,
#[cfg(feature = "unstable_nes")]
Expand Down Expand Up @@ -4833,6 +4971,8 @@ pub enum AgentResponse {
CloseSessionResponse(#[serde(default)] CloseSessionResponse),
/// Successful result returned for a `session/set_mode` request.
SetSessionModeResponse(#[serde(default)] SetSessionModeResponse),
/// Successful result returned for a `session/setTitle` request.
SetSessionTitleResponse(#[serde(default)] SetSessionTitleResponse),
/// Successful result returned for a `session/set_config_option` request.
SetSessionConfigOptionResponse(SetSessionConfigOptionResponse),
/// Successful result returned for a `session/prompt` request.
Expand Down Expand Up @@ -5678,6 +5818,43 @@ mod test_serialization {
}
}

#[test]
fn test_set_session_title_request_roundtrip() {
let original = SetSessionTitleRequest::new("sess_1", "A clearer thread title");
let json = serde_json::to_value(&original).unwrap();
assert_eq!(
json,
json!({
"sessionId": "sess_1",
"title": "A clearer thread title"
})
);
let roundtripped: SetSessionTitleRequest = serde_json::from_value(json).unwrap();
assert_eq!(original, roundtripped);
}

#[test]
fn test_set_session_title_response_roundtrip() {
let original = SetSessionTitleResponse::new();
let json = serde_json::to_value(&original).unwrap();
assert_eq!(json, json!({}));
let roundtripped: SetSessionTitleResponse = serde_json::from_value(json).unwrap();
assert_eq!(original, roundtripped);
}

#[test]
fn test_set_session_title_capabilities_serialization() {
assert_eq!(
serde_json::to_value(
SessionCapabilities::new().set_title(SessionSetTitleCapabilities::new())
)
.unwrap(),
json!({
"setTitle": {}
})
);
}

#[cfg(feature = "unstable_boolean_config")]
#[test]
fn test_session_config_option_value_id_serialize() {
Expand Down
Loading