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
//! Bidirectional JSON-RPC 2.0 protocol layer for gate4agent.
//!
//! Sits on top of [`PipeProcess`](crate::pipe::PipeProcess), adding:
//!
//! - **Agent → host requests**: agent asks host to read files, run commands,
//! approve tools — dispatched to a [`HostHandler`] implementation.
//! - **Host → agent requests**: host sends requests and awaits typed responses
//! via [`RpcSession::rpc_call`].
//! - **JSON-RPC notifications** mapped to [`AgentEvent`](crate::core::types::AgentEvent) broadcast.
//! - **Legacy fallback** to per-CLI NDJSON parsing for non-JSON-RPC lines.
//!
//! # Quick start
//!
//! ```rust,no_run
//! use gate4agent::rpc::{RpcSession, RpcSessionOptions, MethodRouter};
//! use gate4agent::{CliTool, PipeProcessOptions};
//! use serde_json::json;
//! use std::time::Duration;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let session = RpcSession::spawn(
//! CliTool::ClaudeCode,
//! PipeProcessOptions::default(),
//! RpcSessionOptions {
//! host_handler: Some(Box::new(
//! MethodRouter::new().on("ping", |_| Ok(json!({"pong": true})))
//! )),
//! ..Default::default()
//! },
//! std::path::Path::new("."),
//! "Hello",
//! ).await?;
//!
//! let result = session
//! .rpc_call("echo", Some(json!({"hello": "world"})), Duration::from_secs(10))
//! .await?;
//!
//! println!("Agent responded: {}", result);
//! # Ok(())
//! # }
//! ```
pub use ;
pub use IdGen;
pub use ;
pub use PendingRequests;
pub use ;