Skip to main content

respan_gateway/
lib.rs

1//! The respan-gateway application, as a library: its configuration
2//! ([`Config`]) and the HTTP application composed from it ([`App`]), for
3//! the `respan-gateway` binary and any host that embeds it.
4//!
5//! ```no_run
6//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
7//! use respan_gateway::{App, Config};
8//! let app = App::new(Config::discover(None)?)?;
9//! // Its providers' lists, which price and route the first calls.
10//! app.listed().await;
11//! let listener = tokio::net::TcpListener::bind(app.listen()).await?;
12//! println!("{}", app.banner(listener.local_addr()?));
13//! app.serve(listener, respan_gateway::shutdown_signal()).await?;
14//! # Ok(()) }
15//! ```
16//!
17//! A custom gateway, with plugins of its own, builds its own
18//! `respan_gateway_core::Gateway` instead.
19
20mod admin;
21mod app;
22mod auth;
23mod cli;
24mod compose;
25mod config;
26mod formats;
27mod history;
28mod init;
29mod logging;
30mod mcp;
31mod mcp_login;
32mod mcp_oauth;
33mod mcp_tools;
34mod models;
35mod network;
36mod redact;
37mod report;
38mod requests;
39mod rules;
40mod tool_loop;
41mod vendors;
42
43pub use app::{App, DEFAULT_LISTEN, ReloadError, Reloaded, shutdown_signal};
44pub use auth::Trusted;
45pub use cli::{execute, run};
46pub use config::{
47    Auth, Commit, Config, DEFAULT_FILE, Pick, PluginsConfig, Price, ProviderConfig, ProxyVendor,
48    RequestLogConfig, RouteConfig, RouteTarget, RouteWhen, RoutingConfig, Source, no_keys_message,
49};
50pub use init::starter_config;
51pub use logging::LogFormat;
52pub use mcp::McpConfig;
53pub use mcp_oauth::OAuthConfig;
54pub use network::{NetworkConfig, Proxy};
55
56/// This binary's version, the workspace's.
57pub const VERSION: &str = env!("CARGO_PKG_VERSION");
58
59/// A configuration that cannot be read or composed: what is wrong, and
60/// where.
61#[derive(Debug, Clone, PartialEq, Eq)]
62pub struct Error {
63    message: String,
64}
65
66impl Error {
67    pub fn new(message: impl Into<String>) -> Self {
68        Self {
69            message: message.into(),
70        }
71    }
72}
73
74impl std::fmt::Display for Error {
75    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76        f.write_str(&self.message)
77    }
78}
79
80impl std::error::Error for Error {}
81
82impl From<respan_gateway_core::Fault> for Error {
83    fn from(fault: respan_gateway_core::Fault) -> Self {
84        Self::new(fault.message())
85    }
86}