Rename setups and add provider reauthentication

This commit is contained in:
iris committed 2026-09-12 22:56:43 -04:00
1 parent e9a0f1b9da
commit 7d9df5d572
36 files changed
+1866 -684

No files matched your search

+23 -13
View File
@@ -14,12 +14,13 @@
mod auth;
mod config;
mod files;
mod machines;
mod media;
mod models;
mod provider_auth;
mod resume;
mod routes;
mod session;
mod setups;
mod ssh;
mod usage;
@@ -143,7 +144,7 @@ async fn main() -> Result<()> {
let config_path = args
.config
.unwrap_or_else(|| config_home("ai-app").join("config.ron"));
// Before the manager exists, on purpose: constructing it and seeding setups
// Before the manager exists, on purpose: constructing it and seeding machines
// touches sessions and subprocesses this invocation has no business with
// while another instance is serving. Only the hash reaches disk, in the
// spool `auth.rs` reads; the link goes to stdout alone.
@@ -188,19 +189,19 @@ async fn main() -> Result<()> {
// After construction rather than inside it: seeding asks this machine what
// it has, and a constructor that quietly runs a subprocess is a surprise to
// every caller including the tests.
manager.seed_setup().await?;
manager.seed_machine().await?;
tracing::info!("config: {}", config_path.display());
tracing::info!("models: {}", models_dir.display());
for setup in manager.setups() {
match &setup.ssh {
Some(ssh) => tracing::info!(" setup \"{}\" -> {}", setup.name, ssh.address),
// No parenthetical naming the local machine: the default setup is
// *called* "this machine", and the line read "setup this machine
// (this machine)".
None => tracing::info!(" setup \"{}\" runs here", setup.name),
for machine in manager.machines() {
match &machine.ssh {
Some(ssh) => tracing::info!(" machine \"{}\" -> {}", machine.name, ssh.address),
// No parenthetical naming the local machine: the default machine is
// *called* "this machine", so repeating a local qualifier read
// like a stutter.
None => tracing::info!(" machine \"{}\" runs here", machine.name),
}
for provider in &setup.providers {
for provider in &machine.providers {
tracing::info!(" provider {} ({:?})", provider.name, provider.kind);
}
}
@@ -263,11 +264,12 @@ async fn main() -> Result<()> {
.context("failed to load TLS cert/key")?;
// No providers listed here any more: which machines can be asked, and about
// what, comes from the setups at the moment the screen is opened -- so a
// what, comes from the machines at the moment the screen is opened -- so a
// machine added from the phone reports its limits without a restart.
// The fixture is the manager's, because that is where the `/usage` command
// that sets it is typed; the monitor is what serves it.
let monitor = Arc::new(usage::UsageMonitor::new(manager.usage_fixture()));
let provider_logins = Arc::new(provider_auth::LoginManager::new(Arc::clone(&monitor)));
// The one thing in here that acts without a request behind it: a session
// switched to auto-resume waits out its account's usage limit and picks
@@ -279,7 +281,14 @@ async fn main() -> Result<()> {
// The bearer-token middleware wraps the entire router -- routes and fallback
// alike -- here and only here, so a new route can't forget auth.
let app = routes::router(Arc::clone(&manager))
.merge(routes::usage_router(monitor, Arc::clone(&manager)))
.merge(routes::usage_router(
Arc::clone(&monitor),
Arc::clone(&manager),
))
.merge(routes::provider_auth_router(
Arc::clone(&provider_logins),
Arc::clone(&manager),
))
.merge(routes::models_router(Arc::clone(&models)))
.layer(axum::middleware::from_fn_with_state(
Arc::clone(&manager),
@@ -322,6 +331,7 @@ async fn main() -> Result<()> {
// above: a throwaway session is one nobody meant to keep, and the whole point
// is that nothing has to remember to clean it up.
manager.stop_throwaway_sessions();
provider_logins.cancel_all();
manager.detach_all();
Ok(())