pub struct V2Session<Link>{ /* private fields */ }unstable_protocol_v2 only.Expand description
Cloneable command handle for a draft protocol v2 session.
Inbound protocol traffic is intentionally not owned by this value. Receive
authoritative v2::UpdateSessionNotification values and interactive
requests such as v2::RequestPermissionRequest through typed handlers
installed on crate::Builder.
Implementations§
Source§impl<Link> V2Session<Link>
impl<Link> V2Session<Link>
Sourcepub fn session_id(&self) -> &SessionId
pub fn session_id(&self) -> &SessionId
Access the session ID.
Sourcepub fn connection(&self) -> &V2ConnectionTo<Link>
pub fn connection(&self) -> &V2ConnectionTo<Link>
Access the underlying connection.
Sourcepub fn send_prompt(&self, prompt: impl ToString) -> SentRequest<PromptResponse>
pub fn send_prompt(&self, prompt: impl ToString) -> SentRequest<PromptResponse>
Submit a text prompt and return its independent acceptance request.
A successful response only acknowledges that the agent accepted the
prompt. The accepted user message, output, state changes, and completion
arrive independently through v2::UpdateSessionNotification.
Sourcepub fn send_prompt_blocks(
&self,
prompt: Vec<ContentBlock>,
) -> SentRequest<PromptResponse>
pub fn send_prompt_blocks( &self, prompt: Vec<ContentBlock>, ) -> SentRequest<PromptResponse>
Submit arbitrary prompt content and return its acceptance request.
The SDK does not track foreground state or gate prompt submission
locally. Wait for an idle state update before another ordinary prompt
unless using a separately defined admission mechanism.
Sourcepub fn cancel_active_work(&self) -> Result<(), Error>
pub fn cancel_active_work(&self) -> Result<(), Error>
Ask the agent to cancel the session’s current foreground work.
This is independent from cancelling a prompt’s SentRequest.
session/cancel covers the session’s foreground work and any prompts
the agent has not yet inserted; those prompt requests fail with
-32800 (request cancelled). A prompt whose user message was already
inserted still succeeds with its messageId. Background activity is
not covered, although the agent may stop it too.
If foreground work was active, cancellation completes when the agent
reports an idle state update with v2::StopReason::Cancelled; no
completion update is required when nothing was running. cancelled is only
reported for work the client cancelled, through this notification or
by closing the session. The client should immediately mark unfinished
tool calls for the active work as cancelled and must resolve every
pending v2::RequestPermissionRequest in the session with the
cancelled outcome.
See https://agentclientprotocol.com/protocol/v2/prompt-lifecycle#cancellation.
Sourcepub fn set_config_option(
&self,
config_id: impl Into<SessionConfigId>,
value: impl Into<SessionConfigOptionValue>,
) -> SentRequest<SetSessionConfigOptionResponse>
pub fn set_config_option( &self, config_id: impl Into<SessionConfigId>, value: impl Into<SessionConfigOptionValue>, ) -> SentRequest<SetSessionConfigOptionResponse>
Set a session configuration option.
Only send a config_id the agent advertised for this session, with a
value from that option. The agent rejects an unknown config_id or an
invalid value with -32602 and leaves the configuration unchanged.
The response contains the full current option set and is authoritative
for the requesting client. A duplicate config_option_update
notification for the same change may arrive before the response. The
response is not cached on this command handle.
See https://agentclientprotocol.com/protocol/v2/session-config-options.
Sourcepub fn close(&self) -> SentRequest<CloseSessionResponse>
pub fn close(&self) -> SentRequest<CloseSessionResponse>
Close the remote session and release its resources.
Existing clones of this local command handle are not invalidated, but the agent should reject subsequent commands for the closed session.