feat: add the multiplayer room server and client
A room is one conversation, one ssh sandbox, and one agent. Accounts create rooms; friends join through a single-use invite link and a display name; the agent speaks only through the message tool. The server is Axum and SQLite. It serves the built Nuxt client, streams room events over SSE, and runs one serialized turn loop per room with turn-level steering copied from rhema-code. The client has the chat, preview iframe, read-only file pane, xterm terminal, and presence. Preview URLs are signed wildcard hosts, and the proxy tunnels HTTP over ssh direct-tcpip. HostAgent::step remains deferred in the framework.
This commit is contained in:
1 parent
04dd63c4ca
commit
0035f4e031
69 files changed
+22501
-48
No files matched your search
+122
@@ -0,0 +1,122 @@
|
||||
//! Process configuration: one YAML file, environment overrides.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// The server's settings. Every field has a default that works from the
|
||||
/// repository root, so `cargo run` starts without a config file.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
/// Address the HTTP server binds.
|
||||
pub listen: String,
|
||||
/// The URL browsers use. Cookies and invite links are built from it.
|
||||
pub public_url: String,
|
||||
/// The origin previews are served from. Empty disables the preview
|
||||
/// proxy.
|
||||
#[serde(default)]
|
||||
pub preview_origin: String,
|
||||
/// SQLite file.
|
||||
pub database: PathBuf,
|
||||
/// The 32-byte symmetric key protecting stored provider keys and ssh
|
||||
/// keys, base64 or raw. Created on first start when missing.
|
||||
pub secret_key_file: PathBuf,
|
||||
/// The built Nuxt client.
|
||||
pub web_dir: PathBuf,
|
||||
/// Cap on agent steps in one turn.
|
||||
#[serde(default = "default_steps")]
|
||||
pub max_turn_steps: u32,
|
||||
/// Extra origins allowed to frame the app. Empty is none.
|
||||
#[serde(default)]
|
||||
pub allowed_frame_ancestors: Vec<String>,
|
||||
/// Whether anyone may create an account. Off leaves setup and
|
||||
/// invites as the only doors.
|
||||
#[serde(default = "default_true")]
|
||||
pub allow_registration: bool,
|
||||
}
|
||||
|
||||
fn default_steps() -> u32 {
|
||||
48
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
listen: "127.0.0.1:7800".into(),
|
||||
public_url: "http://localhost:7800".into(),
|
||||
preview_origin: "http://preview.localhost:7800".into(),
|
||||
database: PathBuf::from("data/together.db"),
|
||||
secret_key_file: PathBuf::from("data/secret.key"),
|
||||
web_dir: PathBuf::from("web/.output/public"),
|
||||
max_turn_steps: default_steps(),
|
||||
allowed_frame_ancestors: Vec::new(),
|
||||
allow_registration: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Reads `path` when it exists, then applies the `TOGETHER_*`
|
||||
/// environment variables. A missing file is the defaults.
|
||||
pub fn load(path: &std::path::Path) -> anyhow::Result<Self> {
|
||||
let mut config = if path.exists() {
|
||||
let text = std::fs::read_to_string(path)?;
|
||||
serde_yaml::from_str(&text)?
|
||||
} else {
|
||||
Self::default()
|
||||
};
|
||||
if let Ok(value) = std::env::var("TOGETHER_LISTEN") {
|
||||
config.listen = value;
|
||||
}
|
||||
if let Ok(value) = std::env::var("TOGETHER_PUBLIC_URL") {
|
||||
config.public_url = value;
|
||||
}
|
||||
if let Ok(value) = std::env::var("TOGETHER_PREVIEW_ORIGIN") {
|
||||
config.preview_origin = value;
|
||||
}
|
||||
if let Ok(value) = std::env::var("TOGETHER_DATABASE") {
|
||||
config.database = value.into();
|
||||
}
|
||||
if let Ok(value) = std::env::var("TOGETHER_SECRET_KEY_FILE") {
|
||||
config.secret_key_file = value.into();
|
||||
}
|
||||
if let Ok(value) = std::env::var("TOGETHER_WEB_DIR") {
|
||||
config.web_dir = value.into();
|
||||
}
|
||||
if let Ok(value) = std::env::var("TOGETHER_MAX_TURN_STEPS") {
|
||||
config.max_turn_steps = value.parse()?;
|
||||
}
|
||||
if let Ok(value) = std::env::var("TOGETHER_ALLOW_REGISTRATION") {
|
||||
config.allow_registration = matches!(value.as_str(), "1" | "true" | "yes");
|
||||
}
|
||||
config.public_url = config.public_url.trim_end_matches('/').to_owned();
|
||||
config.preview_origin = config.preview_origin.trim_end_matches('/').to_owned();
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
/// Whether cookies should carry `Secure`.
|
||||
pub fn secure_cookies(&self) -> bool {
|
||||
self.public_url.starts_with("https://")
|
||||
}
|
||||
|
||||
/// `scheme://*.<preview host>`, for the CSP that lets the app frame
|
||||
/// any room's preview. `None` when previews are off.
|
||||
pub fn preview_frame_source(&self) -> Option<String> {
|
||||
let (scheme, rest) = self.preview_origin.split_once("://")?;
|
||||
let host = rest.split('/').next()?;
|
||||
let (name, port) = match host.rsplit_once(':') {
|
||||
Some((name, port)) if port.chars().all(|c| c.is_ascii_digit()) => {
|
||||
(name, format!(":{port}"))
|
||||
}
|
||||
_ => (host, String::new()),
|
||||
};
|
||||
if name.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(format!("{scheme}://*.{name}{port}"))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user