Skip to main content

Module v2

Module v2 

Source
Available on crate feature unstable_protocol_v2 only.
Expand description

The SDK API for draft ACP protocol v2.

Start a v2 connection with Client.v2(), Agent.v2() or Proxy.v2(). The protocol v2 message types are in v2::schema.

This module uses the same names as crate::v1 for protocol v2’s connection, builder, request handles and schema. The session APIs differ: ActiveSession here only sends commands, and the session’s updates and the agent’s requests arrive through typed handlers on the connection, while v1::ActiveSession reads them from its own stream. InitializeOutcome and, with unstable_session_fork, ForkSessionBuilder exist only here. v1’s LoadSessionBuilder, SessionMessage and blocking states have no v2 counterpart.

Message types are not tied to a protocol version in the type system: a v2 connection accepts any JsonRpcRequest, so sending a protocol v1 message through it compiles. Send the types from schema.

The request handles here are the crate-root handles with the V2 protocol marker: id() returns a v2::schema::RequestId.

Requires the unstable_protocol_v2 crate feature.

use agent_client_protocol::schema::ProtocolVersion;
use agent_client_protocol::v2::schema::{Implementation, InitializeRequest};
use agent_client_protocol::v2::{ConnectionTo, InitializeOutcome};
use agent_client_protocol::{Agent, Client, ConnectTo};

Client
    .v2()
    .connect_with(transport, async |cx: ConnectionTo<Agent>| {
        let request = InitializeRequest::new(
            ProtocolVersion::V2,
            Implementation::new("my-client", "0.1.0"),
        );
        let InitializeOutcome::Initialized(_response) =
            cx.send_initialize(request).block_task().await?
        else {
            return Err(agent_client_protocol::Error::internal_error());
        };
        Ok(())
    })
    .await

§Stability

Everything in this module is unstable and may change in a minor release. Stabilizing protocol v2 only removes the unstable_protocol_v2 gate. See Stability in the crate docs.

Modules§

schema
The protocol v2 message types: requests, responses, notifications and their supporting types, re-exported from the agent-client-protocol-schema crate’s v2 module.

Structs§

ActiveSession
Cloneable command handle for a draft protocol v2 session.
ConnectionTo
A protocol-v2 connection context.
ForkSessionBuilderunstable_session_fork
Builder for an unstable draft protocol v2 session/fork request.
ResumeSessionBuilder
Builder for a draft protocol v2 session/resume request.
SessionBuilder
Builder for a draft protocol v2 session/new request.
SessionSetup
A protocol v2 session and the response of the request that set it up.

Enums§

InitializeOutcome
The outcome of a v2 client’s send_initialize.

Type Aliases§

Builder
A protocol v2 connection builder, returned by Client.v2(), Agent.v2() and Proxy.v2().
Dispatch
A message received by a typed handler on a v2 Builder: the Dispatch with v2 request handles.
PreparedRequest
A request prepared through a v2 ConnectionTo: the PreparedRequest with a v2 request ID.
Responder
A v2 request’s Responder: id() returns a v2::schema::RequestId.
ResponseRouter
A v2 ResponseRouter: id() returns a v2::schema::RequestId.
SentRequest
A request sent through a v2 ConnectionTo: the SentRequest with a v2 request ID.