mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-21 23:04:46 +00:00
chore: fix bad merge
This commit is contained in:
parent
1dd45908a3
commit
94353f7696
205 changed files with 19244 additions and 14866 deletions
50
server/packages/acp-http-adapter/src/lib.rs
Normal file
50
server/packages/acp-http-adapter/src/lib.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use app::build_router;
|
||||
use process::AdapterRuntime;
|
||||
use registry::LaunchSpec;
|
||||
|
||||
pub mod app;
|
||||
pub mod process;
|
||||
pub mod registry;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ServerConfig {
|
||||
pub host: String,
|
||||
pub port: u16,
|
||||
pub registry_json: String,
|
||||
pub registry_agent_id: Option<String>,
|
||||
pub rpc_timeout: Duration,
|
||||
}
|
||||
|
||||
pub async fn run_server(
|
||||
config: ServerConfig,
|
||||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let launch =
|
||||
LaunchSpec::from_registry_blob(&config.registry_json, config.registry_agent_id.as_deref())?;
|
||||
let runtime = Arc::new(AdapterRuntime::start(launch, config.rpc_timeout).await?);
|
||||
run_server_with_runtime(config.host, config.port, runtime).await
|
||||
}
|
||||
|
||||
pub async fn run_server_with_runtime(
|
||||
host: String,
|
||||
port: u16,
|
||||
runtime: Arc<AdapterRuntime>,
|
||||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let app = build_router(runtime.clone());
|
||||
let addr: SocketAddr = format!("{host}:{port}").parse()?;
|
||||
let listener = tokio::net::TcpListener::bind(addr).await?;
|
||||
tracing::info!(addr = %addr, "acp-http-adapter listening");
|
||||
|
||||
axum::serve(listener, app)
|
||||
.with_graceful_shutdown(shutdown_signal(runtime))
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn shutdown_signal(runtime: Arc<AdapterRuntime>) {
|
||||
let _ = tokio::signal::ctrl_c().await;
|
||||
runtime.shutdown().await;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue