Refactor syscall modules to use async/await patterns

- Updated `DisplaySyscall` to use `tokio::io::AsyncWriteExt` for asynchronous text output.
- Refactored `FsSyscall` to read files asynchronously with offset and length handling.
- Modified `MemorySyscall` to use `tokio::task::spawn_blocking` for database operations, allowing async access to SQLite.
- Enhanced `NetworkSyscall` to utilize `reqwest` for HTTP requests, replacing the previous `curl` command execution.
- Improved `ProcessSyscall` to manage subprocesses with async tasks for stdin, stdout, and stderr handling.
- Updated `TimerSyscall` to simplify timer management.
- Adjusted plugin implementations for better async support and error handling.
- Added `tokio-stream` and `tracing-subscriber` dependencies to `Cargo.toml` for enhanced async stream handling and logging.
This commit is contained in:
2026-06-10 01:26:46 +08:00
parent f7919eca40
commit d533d0a30e
21 changed files with 1950 additions and 436 deletions

View File

@@ -44,7 +44,9 @@ impl PluginBridge for HermesPlugin {
&self,
_req: Request<PluginInfo>,
) -> std::result::Result<Response<RegisterResponse>, Status> {
Err(Status::unimplemented("hermes plugin is not an agentsd bridge"))
Err(Status::unimplemented(
"hermes plugin is not an agentsd bridge",
))
}
async fn call(
@@ -62,13 +64,16 @@ impl PluginBridge for HermesPlugin {
Ok(Response::new(response))
}
type StreamCallStream = tokio_stream::wrappers::ReceiverStream<std::result::Result<CallResponse, Status>>;
type StreamCallStream =
tokio_stream::wrappers::ReceiverStream<std::result::Result<CallResponse, Status>>;
async fn stream_call(
&self,
_req: Request<CallRequest>,
) -> std::result::Result<Response<Self::StreamCallStream>, Status> {
Err(Status::unimplemented("stream_call is not implemented for hermes"))
Err(Status::unimplemented(
"stream_call is not implemented for hermes",
))
}
async fn heartbeat(
@@ -110,7 +115,7 @@ async fn main() -> Result<()> {
println!("Hermes PluginBridge server listening on {}", listen_addr);
Server::builder()
.add_service(PluginBridgeServer::new(HermesPlugin::default()))
.add_service(PluginBridgeServer::new(HermesPlugin))
.serve_with_incoming(incoming)
.await?;
Ok(())