Download codex-rs/code-mode-host/src/transport.rs from SaylorTwift/codex: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/code-mode-host/src/transport.rs
- Command line
-
hf download hf://SaylorTwift/codex/codex-rs/code-mode-host/src/transport.rs
-
curl -L -o transport.rs https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/code-mode-host/src/transport.rs
1.28 kB
| use std::net::SocketAddr; | |
| use anyhow::Context; | |
| use anyhow::Result; | |
| use crate::grpc_transport; | |
| /// The default transport retains the standalone host's original stdio behavior. | |
| pub const DEFAULT_LISTEN_URL: &str = "stdio"; | |
| enum ListenTransport { | |
| Stdio, | |
| Grpc(SocketAddr), | |
| } | |
| pub(crate) async fn run_transport(listen_url: &str) -> Result<()> { | |
| match parse_listen_url(listen_url)? { | |
| ListenTransport::Stdio => crate::run_stdio().await, | |
| ListenTransport::Grpc(bind_address) => grpc_transport::run_tcp_listener(bind_address).await, | |
| } | |
| } | |
| fn parse_listen_url(listen_url: &str) -> Result<ListenTransport> { | |
| if matches!(listen_url, "stdio" | "stdio://") { | |
| return Ok(ListenTransport::Stdio); | |
| } | |
| if let Some(socket_addr) = listen_url.strip_prefix("grpc://") { | |
| return socket_addr | |
| .parse::<SocketAddr>() | |
| .map(ListenTransport::Grpc) | |
| .with_context(|| { | |
| format!("invalid gRPC --listen URL `{listen_url}`; expected `grpc://IP:PORT`") | |
| }); | |
| } | |
| anyhow::bail!( | |
| "unsupported --listen URL `{listen_url}`; expected `grpc://IP:PORT`, `stdio`, or `stdio://`" | |
| ); | |
| } | |
| mod tests; | |