move code out to a new signal-cli-jsonrpc-client
this makes it easier to reuse the RPC stuff and the signal trust set stuff
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
"prometheus-http-client",
|
"prometheus-http-client",
|
||||||
|
"signal-cli-jsonrpc-client",
|
||||||
"signal-gateway",
|
"signal-gateway",
|
||||||
"signal-gateway-code-tool",
|
"signal-gateway-code-tool",
|
||||||
"signal-gateway-assistant",
|
"signal-gateway-assistant",
|
||||||
@@ -27,6 +28,7 @@ result_large_err = "allow"
|
|||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
prometheus-http-client = { path = "prometheus-http-client", default-features = false }
|
prometheus-http-client = { path = "prometheus-http-client", default-features = false }
|
||||||
|
signal-cli-jsonrpc-client = { path = "signal-cli-jsonrpc-client" }
|
||||||
signal-gateway = { path = "signal-gateway", default-features = false }
|
signal-gateway = { path = "signal-gateway", default-features = false }
|
||||||
signal-gateway-assistant = { path = "signal-gateway-assistant" }
|
signal-gateway-assistant = { path = "signal-gateway-assistant" }
|
||||||
signal-gateway-assistant-claude = { path = "signal-gateway-assistant/claude" }
|
signal-gateway-assistant-claude = { path = "signal-gateway-assistant/claude" }
|
||||||
@@ -54,6 +56,7 @@ rand = "0.9"
|
|||||||
flate2 = "1"
|
flate2 = "1"
|
||||||
regex = "1"
|
regex = "1"
|
||||||
tar = "0.4"
|
tar = "0.4"
|
||||||
|
prometheus-http-query = { version = "0.8", default-features = false }
|
||||||
reqwest = { version = "0.12", default-features = false, features = ["json"] }
|
reqwest = { version = "0.12", default-features = false, features = ["json"] }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
[package]
|
||||||
|
name = "signal-cli-jsonrpc-client"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition.workspace = true
|
||||||
|
description = "JSON-RPC client for signal-cli daemon"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
futures-util = { workspace = true }
|
||||||
|
jsonrpsee = { workspace = true }
|
||||||
|
serde = { workspace = true }
|
||||||
|
serde_json = { workspace = true }
|
||||||
|
thiserror = { workspace = true }
|
||||||
|
tokio = { workspace = true }
|
||||||
|
tokio-util = { workspace = true }
|
||||||
|
tracing = { workspace = true }
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# signal-cli-jsonrpc-client
|
||||||
|
|
||||||
|
A Rust JSON-RPC client for [signal-cli](https://github.com/AsamK/signal-cli) daemon.
|
||||||
|
|
||||||
|
## Origin
|
||||||
|
|
||||||
|
The RPC interface and transport code in this crate is based on the example client code from the signal-cli repository:
|
||||||
|
|
||||||
|
- <https://github.com/AsamK/signal-cli/blob/master/client/src/jsonrpc.rs>
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```rust
|
||||||
|
use signal_cli_jsonrpc_client::{connect_tcp, RpcClient};
|
||||||
|
|
||||||
|
// Connect to signal-cli daemon via TCP
|
||||||
|
let client = connect_tcp("127.0.0.1:7583").await?;
|
||||||
|
|
||||||
|
// Use the RpcClient trait methods
|
||||||
|
let version = client.version().await?;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- TCP transport for connecting to signal-cli daemon
|
||||||
|
- Unix domain socket transport (on Unix systems)
|
||||||
|
- Full RPC interface matching signal-cli's JSON-RPC API
|
||||||
|
- Helper types for sending messages and handling received messages
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT or Apache 2.0 at your option.
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
//! JSON-RPC client for signal-cli daemon.
|
||||||
|
//!
|
||||||
|
//! This crate provides a Rust client for communicating with [signal-cli](https://github.com/AsamK/signal-cli)
|
||||||
|
//! running in JSON-RPC daemon mode. It supports both TCP and Unix domain socket connections.
|
||||||
|
//!
|
||||||
|
//! The RPC interface and transport code is based on the example client code from the signal-cli repository:
|
||||||
|
//! <https://github.com/AsamK/signal-cli/blob/master/client/src/jsonrpc.rs>
|
||||||
|
|
||||||
|
mod rpc;
|
||||||
|
pub(crate) mod transports;
|
||||||
|
mod trust_set;
|
||||||
|
|
||||||
|
pub use jsonrpsee::core::client::SubscriptionClientT;
|
||||||
|
pub use rpc::{
|
||||||
|
DataMessage, Envelope, GroupInfo, Identity, JsonLink, MessageTarget, RecvMessage, RpcClient,
|
||||||
|
RpcClientError, SignalMessage, TrustLevel, connect_ipc, connect_tcp,
|
||||||
|
};
|
||||||
|
pub use trust_set::{SafetyNumber, SignalTrustSet, Uuid};
|
||||||
@@ -468,7 +468,7 @@ pub struct Identity {
|
|||||||
pub async fn connect_tcp(
|
pub async fn connect_tcp(
|
||||||
tcp: impl ToSocketAddrs,
|
tcp: impl ToSocketAddrs,
|
||||||
) -> Result<impl SubscriptionClientT, std::io::Error> {
|
) -> Result<impl SubscriptionClientT, std::io::Error> {
|
||||||
let (sender, receiver) = super::transports::tcp::connect(tcp).await?;
|
let (sender, receiver) = crate::transports::tcp::connect(tcp).await?;
|
||||||
|
|
||||||
Ok(ClientBuilder::default().build_with_tokio(sender, receiver))
|
Ok(ClientBuilder::default().build_with_tokio(sender, receiver))
|
||||||
}
|
}
|
||||||
@@ -478,7 +478,7 @@ pub async fn connect_tcp(
|
|||||||
pub async fn connect_ipc(
|
pub async fn connect_ipc(
|
||||||
path: impl AsRef<std::path::Path>,
|
path: impl AsRef<std::path::Path>,
|
||||||
) -> Result<impl SubscriptionClientT, std::io::Error> {
|
) -> Result<impl SubscriptionClientT, std::io::Error> {
|
||||||
let (sender, receiver) = super::transports::ipc::connect(path).await?;
|
let (sender, receiver) = crate::transports::ipc::connect(path).await?;
|
||||||
|
|
||||||
Ok(ClientBuilder::default().build_with_tokio(sender, receiver))
|
Ok(ClientBuilder::default().build_with_tokio(sender, receiver))
|
||||||
}
|
}
|
||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
//! - Map: `{"uuid1": ["safety1", "safety2"], "uuid2": []}` - UUIDs with safety numbers
|
//! - Map: `{"uuid1": ["safety1", "safety2"], "uuid2": []}` - UUIDs with safety numbers
|
||||||
//! - Sequence: `["uuid1", "uuid2"]` - UUIDs with no safety numbers (simpler)
|
//! - Sequence: `["uuid1", "uuid2"]` - UUIDs with no safety numbers (simpler)
|
||||||
|
|
||||||
use crate::signal_jsonrpc::{Envelope, Identity, RpcClient};
|
use crate::{Envelope, Identity, RpcClient};
|
||||||
use serde::{
|
use serde::{
|
||||||
Deserialize, Deserializer,
|
Deserialize, Deserializer,
|
||||||
de::{MapAccess, SeqAccess, Visitor},
|
de::{MapAccess, SeqAccess, Visitor},
|
||||||
@@ -13,6 +13,7 @@ rustls-tls = ["prometheus-http-client/rustls-tls", "reqwest/rustls-tls"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
prometheus-http-client = { workspace = true, default-features = false }
|
prometheus-http-client = { workspace = true, default-features = false }
|
||||||
|
signal-cli-jsonrpc-client = { workspace = true }
|
||||||
signal-gateway-assistant = { workspace = true }
|
signal-gateway-assistant = { workspace = true }
|
||||||
|
|
||||||
async-trait = { workspace = true }
|
async-trait = { workspace = true }
|
||||||
@@ -22,7 +23,6 @@ conf-extra = { workspace = true }
|
|||||||
displaydoc = { workspace = true }
|
displaydoc = { workspace = true }
|
||||||
futures-util = { workspace = true }
|
futures-util = { workspace = true }
|
||||||
humantime = { workspace = true }
|
humantime = { workspace = true }
|
||||||
jsonrpsee = { workspace = true }
|
|
||||||
metrics = { workspace = true }
|
metrics = { workspace = true }
|
||||||
regex = { workspace = true }
|
regex = { workspace = true }
|
||||||
reqwest = { workspace = true }
|
reqwest = { workspace = true }
|
||||||
|
|||||||
@@ -1,16 +1,11 @@
|
|||||||
//! Gateway for bridging alerts and logs with Signal messenger.
|
//! Gateway for bridging alerts and logs with Signal messenger.
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
use crate::signal_jsonrpc::connect_ipc;
|
|
||||||
use crate::{
|
use crate::{
|
||||||
alertmanager::AlertPost,
|
alertmanager::AlertPost,
|
||||||
assistant::{AssistantAgent, SentBy, Tool, ToolExecutor, ToolResult},
|
assistant::{AssistantAgent, SentBy, Tool, ToolExecutor, ToolResult},
|
||||||
log_message::{LogMessage, Origin},
|
log_message::{LogMessage, Origin},
|
||||||
message_handler::{AdminMessage, AdminMessageResponse, Context, MessageHandlerResult},
|
message_handler::{AdminMessage, AdminMessageResponse, Context, MessageHandlerResult},
|
||||||
prometheus::{Prometheus, PrometheusConfig},
|
prometheus::{Prometheus, PrometheusConfig},
|
||||||
signal_jsonrpc::{
|
|
||||||
Envelope, MessageTarget, RpcClient, RpcClientError, SignalMessage, connect_tcp,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
@@ -18,6 +13,11 @@ use conf::{Conf, Subcommands};
|
|||||||
use futures_util::FutureExt;
|
use futures_util::FutureExt;
|
||||||
use metrics::counter;
|
use metrics::counter;
|
||||||
use prometheus_http_client::{AlertStatus, ExtractLabels};
|
use prometheus_http_client::{AlertStatus, ExtractLabels};
|
||||||
|
#[cfg(unix)]
|
||||||
|
use signal_cli_jsonrpc_client::connect_ipc;
|
||||||
|
use signal_cli_jsonrpc_client::{
|
||||||
|
Envelope, MessageTarget, RpcClient, RpcClientError, SignalMessage, connect_tcp,
|
||||||
|
};
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Write,
|
fmt::Write,
|
||||||
net::SocketAddr,
|
net::SocketAddr,
|
||||||
@@ -38,11 +38,9 @@ const METRIC_SIGNAL_RECEIVED: &str = "gateway_signal_messages_received_total";
|
|||||||
const METRIC_SIGNAL_SENT: &str = "gateway_signal_messages_sent_total";
|
const METRIC_SIGNAL_SENT: &str = "gateway_signal_messages_sent_total";
|
||||||
const METRIC_ALERTS: &str = "gateway_alerts_total";
|
const METRIC_ALERTS: &str = "gateway_alerts_total";
|
||||||
|
|
||||||
mod signal_trust_set;
|
|
||||||
pub use signal_trust_set::SignalTrustSet;
|
|
||||||
|
|
||||||
mod command_router;
|
mod command_router;
|
||||||
pub use command_router::{CommandRouter, CommandRouterBuilder, Handling};
|
pub use command_router::{CommandRouter, CommandRouterBuilder, Handling};
|
||||||
|
pub use signal_cli_jsonrpc_client::SignalTrustSet;
|
||||||
|
|
||||||
mod log_buffer;
|
mod log_buffer;
|
||||||
mod log_handler;
|
mod log_handler;
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ pub(crate) mod log_format;
|
|||||||
pub(crate) mod log_message;
|
pub(crate) mod log_message;
|
||||||
pub(crate) mod prometheus;
|
pub(crate) mod prometheus;
|
||||||
pub(crate) mod rate_limiter;
|
pub(crate) mod rate_limiter;
|
||||||
pub(crate) mod signal_jsonrpc;
|
|
||||||
pub(crate) mod transports;
|
|
||||||
|
|
||||||
pub use gateway::{CommandRouter, CommandRouterBuilder, Gateway, GatewayConfig, Handling};
|
pub use gateway::{CommandRouter, CommandRouterBuilder, Gateway, GatewayConfig, Handling};
|
||||||
pub use limiter_sequence::Limit;
|
pub use limiter_sequence::Limit;
|
||||||
|
|||||||
Reference in New Issue
Block a user