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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! Wire protocol types for the [Agent Host Protocol (AHP)][spec].
//!
//! `ahp-types` is the data-only crate of the AHP family. Every command,
//! action, notification, and state object defined by the protocol has a
//! Rust counterpart here — `Serialize` + `Deserialize`, using the exact
//! same JSON field names as the wire format. There is no I/O, no async
//! runtime, and no transport code; if you only need to parse or
//! construct AHP messages, this is the only crate you need.
//!
//! These types are generated from the TypeScript source of truth in
//! `types/*.ts`, so any change to the protocol surfaces here first.
//!
//! [spec]: https://microsoft.github.io/agent-host-protocol/
//!
//! # Companion crates
//!
//! | Crate | What it adds |
//! |---|---|
//! | [`ahp`](https://docs.rs/ahp) | Async client, reducers, and pluggable [`Transport`](https://docs.rs/ahp/latest/ahp/transport/trait.Transport.html) trait |
//! | [`ahp-ws`](https://docs.rs/ahp-ws) | WebSocket transport built on `tokio-tungstenite` |
//!
//! # Module map
//!
//! | Module | Contents |
//! |---|---|
//! | [`state`] | [`RootState`], [`SessionState`], [`TerminalState`], tool-call lifecycle |
//! | [`actions`] | [`StateAction`] discriminated union and [`ActionEnvelope`] |
//! | [`commands`] | Request/response parameter and result types (`initialize`, `subscribe`, …) |
//! | [`notifications`] | Server-pushed protocol notification params ([`SessionAddedParams`], [`AuthRequiredParams`], …) |
//! | [`messages`] | JSON-RPC wire envelopes ([`JsonRpcMessage`] and friends) |
//! | [`errors`] | AHP and JSON-RPC [error codes][errors::AhpErrorCode] |
//! | [`version`] | Negotiation constants ([`PROTOCOL_VERSION`]) |
//! | [`common`] | Hand-written primitives ([`Uri`], [`StringOrMarkdown`], …) |
//!
//! # Examples
//!
//! ## Parse an action envelope
//!
//! ```
//! use ahp_types::actions::{ActionEnvelope, StateAction};
//!
//! let json = r#"{
//! "channel": "ahp-session:/s1",
//! "action": { "type": "session/titleChanged", "title": "Hi" },
//! "serverSeq": 7
//! }"#;
//! let env: ActionEnvelope = serde_json::from_str(json)?;
//! assert_eq!(env.server_seq, 7);
//! assert_eq!(env.channel, "ahp-session:/s1");
//! match env.action {
//! StateAction::SessionTitleChanged(a) => assert_eq!(a.title, "Hi"),
//! _ => panic!("unexpected variant"),
//! }
//! # Ok::<_, serde_json::Error>(())
//! ```
//!
//! ## Build an `initialize` request
//!
//! ```
//! use ahp_types::commands::InitializeParams;
//! use ahp_types::messages::{JsonRpcMessage, JsonRpcRequest, JsonRpcVersion};
//! use ahp_types::common::AnyValue;
//!
//! let params = InitializeParams {
//! channel: "ahp-root://".into(),
//! protocol_versions: vec![ahp_types::PROTOCOL_VERSION.to_string()],
//! client_id: "my-host/1.0".into(),
//! initial_subscriptions: Some(vec!["ahp-root://".into()]),
//! locale: Some("en".into()),
//! capabilities: None,
//! };
//!
//! let req = JsonRpcMessage::Request(JsonRpcRequest {
//! jsonrpc: JsonRpcVersion::V2,
//! id: 1,
//! method: "initialize".into(),
//! params: Some(AnyValue::from(serde_json::to_value(¶ms)?)),
//! });
//!
//! let wire = serde_json::to_string(&req)?;
//! assert!(wire.contains("\"method\":\"initialize\""));
//! # Ok::<_, serde_json::Error>(())
//! ```
//!
//! ## Inspect a session status bitset
//!
//! [`SessionStatus`](state::SessionStatus) packs activity and metadata
//! flags into a single value — use bitwise checks rather than equality:
//!
//! `SessionStatus` is a `u32` bitset newtype: combine flags with `|`, test
//! membership with [`contains`](state::SessionStatus::contains), and read the
//! raw value (including unknown/forward-compat bits) with
//! [`bits`](state::SessionStatus::bits).
//!
//! ```
//! use ahp_types::state::SessionStatus;
//!
//! let status = SessionStatus::InProgress | SessionStatus::IsArchived;
//! assert!(status.contains(SessionStatus::InProgress));
//! assert!(status.contains(SessionStatus::IsArchived));
//! assert!(!status.contains(SessionStatus::Idle));
//! assert_eq!(status.bits(), 8 | 64);
//! ```
//!
//! # Compatibility
//!
//! - JSON field names match the protocol exactly (`camelCase`); use the
//! provided `Serialize`/`Deserialize` derives rather than manually
//! building JSON.
//! - Unknown enum variants surface as a generic `Unknown` arm where the
//! protocol allows forward-compatible extension (see e.g.
//! [`state::ToolCallState`]).
//! - The protocol version this crate speaks is exposed as
//! [`PROTOCOL_VERSION`].
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;