Skip to content

Commit 1b30972

Browse files
committed
refactor: consolidate JsonRpc trait implementations with macros
- Replace ~890 lines of repetitive trait implementations with concise macros - Add impl_jsonrpc_request! and impl_jsonrpc_notification! macros in schema/mod.rs - Add feature flags for unstable ACP methods (session_model, session_fork, etc.) - All tests pass, no functional changes
1 parent 4be79b7 commit 1b30972

7 files changed

Lines changed: 362 additions & 890 deletions

File tree

src/sacp/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ repository = "https://github.com/symposium-dev/symposium-acp"
88
keywords = ["acp", "agent", "protocol", "ai"]
99
categories = ["development-tools"]
1010

11+
[features]
12+
default = []
13+
14+
# Forward unstable features from agent-client-protocol-schema.
15+
# Enable these to get support for the corresponding unstable ACP methods.
16+
unstable = [
17+
"unstable_session_model",
18+
"unstable_session_fork",
19+
"unstable_session_resume",
20+
"unstable_session_close",
21+
]
22+
unstable_session_model = ["agent-client-protocol-schema/unstable_session_model"]
23+
unstable_session_fork = ["agent-client-protocol-schema/unstable_session_fork"]
24+
unstable_session_resume = ["agent-client-protocol-schema/unstable_session_resume"]
25+
unstable_session_close = ["agent-client-protocol-schema/unstable_session_close"]
26+
1127
[dependencies]
1228
agent-client-protocol-schema.workspace = true
1329
sacp-derive = { version = "11.0.0", path = "../sacp-derive" }
Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,3 @@
11
use crate::schema::SessionNotification;
2-
use serde::Serialize;
32

4-
use crate::jsonrpc::{JsonRpcMessage, JsonRpcNotification};
5-
6-
const METHOD_SESSION_UPDATE: &str = "session/update";
7-
8-
// Agent -> Client notifications
9-
// These are one-way messages that agents send to clients/editors
10-
11-
impl JsonRpcMessage for SessionNotification {
12-
fn matches_method(method: &str) -> bool {
13-
method == METHOD_SESSION_UPDATE
14-
}
15-
16-
fn method(&self) -> &str {
17-
METHOD_SESSION_UPDATE
18-
}
19-
20-
fn to_untyped_message(&self) -> Result<crate::UntypedMessage, crate::Error> {
21-
crate::UntypedMessage::new(self.method(), self)
22-
}
23-
24-
fn parse_message(method: &str, params: &impl Serialize) -> Result<Self, crate::Error> {
25-
if !Self::matches_method(method) {
26-
return Err(crate::Error::method_not_found());
27-
}
28-
crate::util::json_cast(params)
29-
}
30-
}
31-
32-
impl JsonRpcNotification for SessionNotification {}
3+
impl_jsonrpc_notification!(SessionNotification, "session/update");

0 commit comments

Comments
 (0)