1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! Optional host features the host opted into at `initialize`.
//!
//! ACP lets an agent send `compaction_update` and `notice` only to clients
//! that advertise `clientCapabilities.session.compaction` and `.notices`,
//! and `elicitation/create` in form mode only to clients that advertise
//! `clientCapabilities.elicitation.form`. Other hosts keep the baseline:
//! `/compact` replies with an agent message, automatic compaction shows only
//! in `usage_update`, notices are agent messages, and Rho offers no
//! questionnaire tool and declines MCP elicitation.
use std::sync::OnceLock;
use agent_client_protocol::schema::v1::InitializeRequest;
/// Features beyond the ACP baseline that the connected host accepts.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(in crate::app) struct HostUpdates {
/// Compaction lifecycle cards (`compaction_update`).
pub(super) compaction: bool,
/// Live, dismissible user notices (`notice`).
pub(super) notices: bool,
/// Form-mode `elicitation/create`: questions put to the user.
pub(super) forms: Forms,
}
/// Whether, and how, the host draws form-mode elicitations.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(super) enum Forms {
/// The host advertised no form support.
#[default]
Unavailable,
Available(FormDialect),
}
/// How a form-capable host draws the schema, which decides how choice
/// questions are shaped.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum FormDialect {
/// A host that draws the ACP form schema as specified.
Standard,
/// T3 Code (`clientInfo.name` "t3-code"). It turns each property into
/// one question listing its top-level `enum` values that also accepts
/// free text, requires every property, and answers each with one string.
T3Code,
}
impl HostUpdates {
pub(super) fn from_initialize(request: &InitializeRequest) -> Self {
let capabilities = &request.client_capabilities;
let session = capabilities.session.as_ref();
let advertises_forms = capabilities
.elicitation
.as_ref()
.is_some_and(|elicitation| elicitation.form.is_some());
let client = request.client_info.as_ref().map(|info| info.name.as_str());
let forms = match (advertises_forms, client) {
(false, _) => Forms::Unavailable,
(true, Some("t3-code")) => Forms::Available(FormDialect::T3Code),
(true, _) => Forms::Available(FormDialect::Standard),
};
Self {
compaction: session.is_some_and(|session| session.compaction.is_some()),
notices: session.is_some_and(|session| session.notices.is_some()),
forms,
}
}
}
/// The host's choice, recorded by `initialize` and read when the first
/// session starts. A host that skips `initialize` gets the baseline.
#[derive(Default)]
pub(super) struct NegotiatedUpdates(OnceLock<HostUpdates>);
impl NegotiatedUpdates {
/// Keeps the first `initialize`; ACP negotiates capabilities once per
/// connection.
pub(super) fn record(&self, request: &InitializeRequest) {
let _ = self.0.set(HostUpdates::from_initialize(request));
}
pub(super) fn get(&self) -> HostUpdates {
self.0.get().copied().unwrap_or_default()
}
}