feat(app): start Strata from the data folder and point the brain at it
M5 step 4, second part. The services start the LLM first: the installed Strata with the M0 kit's model and normal placement (models in models/llm, parallel 1, or 2 when a chat channel answers every message, pictures off, --restart), wait until /v1/models lists the model, and stop it last. The first start downloads the model; the dashboard shows Strata's last line and percentage, and stop also cancels a start (the server is cleared). llm.url uses a server the app does not start. On every start the app writes config/brain.json (Strata's /v1, the listed model id, memory/jarvis.db) and hands it to the worker as JARVIS_CONFIG_PATH. Loading a config with its own db_path no longer creates ~/.local/share/jarvis. service_start/service_restart run in the background. Settings gain llm.context and llm.port (model screen) and llm.url (file only). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
//! Starts everything the app runs: the voice worker process, the connection to it, and the Discord
|
||||
//! core. Used by the app binary (and the Tauri shell from M5).
|
||||
//! Starts everything the app runs: the LLM (`strata.rs`), the voice worker process, the connection
|
||||
//! to it, and the Discord core. Used by the app binary (and the Tauri shell from M5).
|
||||
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use serde_json::Value;
|
||||
use tokio::sync::mpsc;
|
||||
@@ -9,6 +10,7 @@ use tokio::sync::mpsc;
|
||||
use crate::conversation::{self, Conversation};
|
||||
use crate::discord::{CoreEvent, DiscordCore};
|
||||
use crate::settings::load_settings;
|
||||
use crate::strata::Llm;
|
||||
use crate::worker_client::{WorkerClient, WorkerClientOptions};
|
||||
use crate::worker_process::{ProcessEvent, WorkerProcess, WorkerProcessOptions};
|
||||
|
||||
@@ -19,6 +21,7 @@ pub struct Services {
|
||||
pub worker_process: WorkerProcess,
|
||||
/// The conversation's missed requests, for the dashboard.
|
||||
pub missed: conversation::MissedLog,
|
||||
pub llm: Arc<Llm>,
|
||||
}
|
||||
|
||||
impl Services {
|
||||
@@ -26,10 +29,13 @@ impl Services {
|
||||
self.core.close().await;
|
||||
self.worker.close();
|
||||
self.worker_process.stop().await;
|
||||
self.llm.stop().await;
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn start_services(data_dir: &Path) -> Result<Services, Box<dyn std::error::Error + Send + Sync>> {
|
||||
/// Start the services; the LLM first (its first start downloads the model), so nothing answers
|
||||
/// before the brain can. A failure stops what already started.
|
||||
pub async fn start_services(data_dir: &Path, llm: Arc<Llm>) -> Result<Services, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let settings = load_settings(&data_dir.join("config").join("settings.json"))?;
|
||||
// The stored token (the setup wizard keeps it encrypted, admin.spec.md), else the environment.
|
||||
let stored = crate::secrets::Secrets::new(&data_dir.join("config").join("secrets.dat"))
|
||||
@@ -39,6 +45,15 @@ pub async fn start_services(data_dir: &Path) -> Result<Services, Box<dyn std::er
|
||||
None => std::env::var("JARVIS_DISCORD_TOKEN").map_err(|_| "no bot token: set it in the app or JARVIS_DISCORD_TOKEN")?,
|
||||
};
|
||||
|
||||
let (base_url, model) = llm.start(&settings).await?;
|
||||
let brain_config = match crate::strata::write_brain_config(data_dir, &base_url, &model) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
llm.stop().await;
|
||||
return Err(format!("could not write the brain settings: {e}").into());
|
||||
}
|
||||
};
|
||||
|
||||
let w = &settings.voice_worker;
|
||||
let mut wopts = WorkerProcessOptions::new(&w.python, &w.cwd, w.args.clone());
|
||||
// With the installed runtime, the worker's models, caches and temp files stay in the data folder.
|
||||
@@ -46,7 +61,14 @@ pub async fn start_services(data_dir: &Path) -> Result<Services, Box<dyn std::er
|
||||
if crate::install::Installer::new(layout.clone(), crate::install::steps()).all_done() {
|
||||
wopts.env.extend(layout.env());
|
||||
}
|
||||
let worker_process = WorkerProcess::new(wopts)?;
|
||||
wopts.env.insert("JARVIS_CONFIG_PATH".into(), brain_config.to_string_lossy().into_owned());
|
||||
let worker_process = match WorkerProcess::new(wopts) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
llm.stop().await;
|
||||
return Err(e.into());
|
||||
}
|
||||
};
|
||||
let mut process_events = worker_process.subscribe();
|
||||
worker_process.start();
|
||||
let mut opts = WorkerClientOptions::new(worker_process.url(), worker_process.token.clone());
|
||||
@@ -79,8 +101,9 @@ pub async fn start_services(data_dir: &Path) -> Result<Services, Box<dyn std::er
|
||||
if let Err(e) = core.start().await {
|
||||
worker.close();
|
||||
worker_process.stop().await;
|
||||
llm.stop().await;
|
||||
return Err(Box::new(e));
|
||||
}
|
||||
crate::info_log!("app", "services started");
|
||||
Ok(Services { core, events, worker, worker_process, missed })
|
||||
Ok(Services { core, events, worker, worker_process, missed, llm })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user