Skip to content

Commit 9e5683f

Browse files
tclemCopilot
andcommitted
Make ping message argument optional
Node, Python, and .NET all expose ping with an optional message. Go requires it only because Go has no Option type — Rust has one, so the API should match the languages with the same expressive power rather than the one without. Change ping(&self, message: &str) to ping(&self, message: Option<&str>). When None, the message field is omitted from the request payload rather than sent as an empty string. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b6f65a4 commit 9e5683f

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

rust/src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ impl Client {
726726
/// doesn't report a version, logs a warning and succeeds (backward
727727
/// compatibility with older CLI versions).
728728
pub async fn verify_protocol_version(&self) -> Result<(), Error> {
729-
let response = self.ping("").await?;
729+
let response = self.ping(None).await?;
730730
let server_version = response.protocol_version;
731731

732732
match server_version {
@@ -759,14 +759,17 @@ impl Client {
759759

760760
/// Send a `ping` RPC and return the typed [`PingResponse`].
761761
///
762-
/// The `message` is echoed back by the server. Mirrors Go's
763-
/// `Client.Ping(ctx, message)`.
762+
/// Pass `Some(message)` to have the server echo it back; pass `None` for
763+
/// a bare health check. The response includes a `protocolVersion` when
764+
/// the CLI reports one.
764765
///
765766
/// [`PingResponse`]: crate::types::PingResponse
766-
pub async fn ping(&self, message: &str) -> Result<crate::types::PingResponse, Error> {
767-
let value = self
768-
.call("ping", Some(serde_json::json!({ "message": message })))
769-
.await?;
767+
pub async fn ping(&self, message: Option<&str>) -> Result<crate::types::PingResponse, Error> {
768+
let params = match message {
769+
Some(m) => serde_json::json!({ "message": m }),
770+
None => serde_json::json!({}),
771+
};
772+
let value = self.call("ping", Some(params)).await?;
770773
Ok(serde_json::from_value(value)?)
771774
}
772775

rust/tests/integration_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async fn start_ping_stop() {
2525
.expect("protocol version not negotiated");
2626
assert!((2..=SDK_PROTOCOL_VERSION).contains(&version));
2727

28-
client.ping("").await.expect("ping failed");
28+
client.ping(None).await.expect("ping failed");
2929
client.stop().await.expect("stop failed");
3030
}
3131

@@ -65,7 +65,7 @@ async fn cli_operation_latency() {
6565

6666
// Warm ping: RPC round-trip on an already-running process
6767
let t1 = Instant::now();
68-
client.ping("").await.expect("warm ping failed");
68+
client.ping(None).await.expect("warm ping failed");
6969
let warm_ping = t1.elapsed();
7070

7171
// list_models: RPC that fetches available models from the CLI

0 commit comments

Comments
 (0)