feat: Strata-Adapter (#1038), Release 0.1.6
Strata teilt Servercode und Protokoll mit Maya (docs/m2-strata-messung.md); MayaEngine::strata startet server.py --engine strata, behält den Arbeitsordner des Terminals, nur 127.0.0.1. Scheduler führt Strata als exklusiv. Neu: Abschnitt [strata], nexus model add --engine strata --strata-config. Auf srv04 mit echtem Strata geprüft (client2antwort.1-.3). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GmHhg3bfByVgQ9z7CGCSGc
This commit is contained in:
@ -11,6 +11,14 @@
|
||||
//! - Nach `POST /models/unload` oder einem Leerlauf-Entladen lädt der nächste
|
||||
//! Chat das Modell selbst nach (etwa 66 s).
|
||||
//!
|
||||
//! **Strata** (`serve/server.py` des Strata-Terminals) teilt sich Servercode und
|
||||
//! Protokoll mit Maya (gemessen am 16.11.2026, `docs/m2-strata-messung.md`) und
|
||||
//! läuft deshalb über denselben Adapter: [`MayaEngine::strata`] setzt
|
||||
//! `--engine strata`, behält den Arbeitsordner der Konfiguration (die Engine
|
||||
//! wird über `$XDG_DATA_HOME/strata/components` gefunden, das bei einem anderen
|
||||
//! Benutzer als `svc-scotty` in `[strata.env]` gesetzt werden muss) und nennt
|
||||
//! sich `strata`.
|
||||
//!
|
||||
//! Das Modell ist bei Maya die Konfigurationsdatei (JSON). Der Adapter legt je
|
||||
//! Instanz eine Kopie an, in der er Port, Log, GPUs und Arbeitsordner setzt,
|
||||
//! damit weder die Originaldatei noch der Maya-Ordner verändert werden. Ein
|
||||
@ -85,7 +93,15 @@ struct Managed {
|
||||
port: u16,
|
||||
}
|
||||
|
||||
/// Welcher Server hinter dem Adapter steckt.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
enum Flavor {
|
||||
Maya,
|
||||
Strata,
|
||||
}
|
||||
|
||||
pub struct MayaEngine {
|
||||
flavor: Flavor,
|
||||
config: MayaConfig,
|
||||
ports: PortPool,
|
||||
next_id: AtomicU64,
|
||||
@ -94,8 +110,18 @@ pub struct MayaEngine {
|
||||
|
||||
impl MayaEngine {
|
||||
pub fn new(config: MayaConfig) -> Self {
|
||||
Self::with_flavor(Flavor::Maya, config)
|
||||
}
|
||||
|
||||
/// Derselbe Adapter für den Strata-Server (siehe Moduldokumentation).
|
||||
pub fn strata(config: MayaConfig) -> Self {
|
||||
Self::with_flavor(Flavor::Strata, config)
|
||||
}
|
||||
|
||||
fn with_flavor(flavor: Flavor, config: MayaConfig) -> Self {
|
||||
let ports = PortPool::new(config.port_from, config.port_to);
|
||||
Self {
|
||||
flavor,
|
||||
config,
|
||||
ports,
|
||||
next_id: AtomicU64::new(1),
|
||||
@ -103,6 +129,14 @@ impl MayaEngine {
|
||||
}
|
||||
}
|
||||
|
||||
/// Name der Engine im Gateway und in Dateinamen.
|
||||
fn name(&self) -> &'static str {
|
||||
match self.flavor {
|
||||
Flavor::Maya => "maya",
|
||||
Flavor::Strata => "strata",
|
||||
}
|
||||
}
|
||||
|
||||
fn validate(profile: &ProfileSpec) -> Result<()> {
|
||||
if profile.gpus.is_empty() {
|
||||
return Err(AdapterError::InvalidProfile(
|
||||
@ -125,15 +159,18 @@ impl MayaEngine {
|
||||
|
||||
/// Kommandozeile für einen Start. Der Server lauscht nur auf `127.0.0.1`.
|
||||
pub(crate) fn build_args(&self, config_path: &Path, port: u16) -> Vec<String> {
|
||||
let mut args = vec![
|
||||
self.config.script.display().to_string(),
|
||||
let mut args = vec![self.config.script.display().to_string()];
|
||||
if self.flavor == Flavor::Strata {
|
||||
args.extend(["--engine".to_string(), "strata".to_string()]);
|
||||
}
|
||||
args.extend([
|
||||
"--config".to_string(),
|
||||
config_path.display().to_string(),
|
||||
"--host".to_string(),
|
||||
"127.0.0.1".to_string(),
|
||||
"--port".to_string(),
|
||||
port.to_string(),
|
||||
];
|
||||
]);
|
||||
args.extend(self.config.extra_args.iter().cloned());
|
||||
args
|
||||
}
|
||||
@ -152,7 +189,8 @@ impl MayaEngine {
|
||||
};
|
||||
let log_dir =
|
||||
std::path::absolute(&self.config.log_dir).map_err(io(&self.config.log_dir))?;
|
||||
let workdir = log_dir.join(format!("maya-{id}"));
|
||||
let name = self.name();
|
||||
let workdir = log_dir.join(format!("{name}-{id}"));
|
||||
std::fs::create_dir_all(&workdir).map_err(io(&workdir))?;
|
||||
|
||||
let text = std::fs::read_to_string(&profile.model_path).map_err(io(&profile.model_path))?;
|
||||
@ -162,15 +200,30 @@ impl MayaEngine {
|
||||
profile.model_path.display()
|
||||
))
|
||||
})?;
|
||||
let engine_log = log_dir.join(format!("instance-maya-{id}-engine.log"));
|
||||
let copy = instance_config(template, port, &engine_log, &profile.gpus, profile.context)?;
|
||||
let engine_log = log_dir.join(format!("instance-{name}-{id}-engine.log"));
|
||||
let keep_cwd = self.flavor == Flavor::Strata;
|
||||
let copy = instance_config_for(
|
||||
template,
|
||||
port,
|
||||
&engine_log,
|
||||
&profile.gpus,
|
||||
profile.context,
|
||||
keep_cwd,
|
||||
)?;
|
||||
// Strata braucht seinen Arbeitsordner (Terminal), Maya läuft im eigenen.
|
||||
let process_dir = copy
|
||||
.get("cwd")
|
||||
.and_then(Value::as_str)
|
||||
.map(PathBuf::from)
|
||||
.filter(|p| keep_cwd && p.is_dir())
|
||||
.unwrap_or_else(|| workdir.clone());
|
||||
let config_path = workdir.join("config.json");
|
||||
std::fs::write(
|
||||
&config_path,
|
||||
serde_json::to_vec_pretty(©).unwrap_or_default(),
|
||||
)
|
||||
.map_err(io(&config_path))?;
|
||||
Ok((config_path, workdir))
|
||||
Ok((config_path, process_dir))
|
||||
}
|
||||
|
||||
async fn spawn_and_wait(
|
||||
@ -184,7 +237,10 @@ impl MayaEngine {
|
||||
source,
|
||||
})?;
|
||||
let (config_path, workdir) = self.write_instance_config(id, port, profile)?;
|
||||
let log_path = self.config.log_dir.join(format!("instance-maya-{id}.log"));
|
||||
let log_path = self
|
||||
.config
|
||||
.log_dir
|
||||
.join(format!("instance-{}-{id}.log", self.name()));
|
||||
let io_err = |source| AdapterError::Io {
|
||||
path: log_path.clone(),
|
||||
source,
|
||||
@ -332,12 +388,26 @@ pub(crate) fn parse_health(text: &str) -> Option<HealthState> {
|
||||
|
||||
/// Setzt Port, Log, GPUs und Kontext in der Kopie der Maya-Konfiguration und
|
||||
/// entfernt, was die Instanz stören würde (Arbeitsordner, API-Schlüssel).
|
||||
#[cfg(test)]
|
||||
pub(crate) fn instance_config(
|
||||
template: Value,
|
||||
port: u16,
|
||||
engine_log: &Path,
|
||||
gpus: &[u32],
|
||||
context: Option<u32>,
|
||||
) -> Result<Value> {
|
||||
instance_config_for(template, port, engine_log, gpus, context, false)
|
||||
}
|
||||
|
||||
/// Wie [`instance_config`]; `keep_cwd` behält den Arbeitsordner der Vorlage
|
||||
/// (Strata).
|
||||
pub(crate) fn instance_config_for(
|
||||
template: Value,
|
||||
port: u16,
|
||||
engine_log: &Path,
|
||||
gpus: &[u32],
|
||||
context: Option<u32>,
|
||||
keep_cwd: bool,
|
||||
) -> Result<Value> {
|
||||
let Value::Object(mut map) = template else {
|
||||
return Err(AdapterError::InvalidProfile(
|
||||
@ -349,7 +419,9 @@ pub(crate) fn instance_config(
|
||||
"Maya-Konfiguration ohne \"exe\"".to_string(),
|
||||
));
|
||||
}
|
||||
map.remove("cwd");
|
||||
if !keep_cwd {
|
||||
map.remove("cwd");
|
||||
}
|
||||
// Der Server lauscht nur lokal; ein Schlüssel aus der Vorlage käme beim
|
||||
// Gateway nicht an und würde jede Anfrage mit 401 abweisen.
|
||||
map.remove("api_key");
|
||||
@ -411,7 +483,7 @@ pub(crate) fn parse_pgrp(stat: &str) -> Option<u32> {
|
||||
impl Engine for MayaEngine {
|
||||
fn describe(&self) -> EngineInfo {
|
||||
EngineInfo {
|
||||
name: "maya".to_string(),
|
||||
name: self.name().to_string(),
|
||||
mode: Mode::Managed,
|
||||
// Gemessen: Chat und Streaming. Embeddings, Tool Calling und Bilder
|
||||
// (Maya kann Bilder lesen) sind über das Gateway nicht geprüft.
|
||||
@ -570,7 +642,7 @@ pub(crate) fn scan_configs(roots: &[PathBuf]) -> Vec<DiscoveredArtifact> {
|
||||
.and_then(Value::as_str)
|
||||
.map(str::to_string);
|
||||
let pack = value.get("args").and_then(Value::as_array).and_then(|a| {
|
||||
let i = a.iter().position(|x| x == "--glm-pack")?;
|
||||
let i = a.iter().position(|x| x == "--glm-pack" || x == "--pack")?;
|
||||
a.get(i + 1)?.as_str().map(PathBuf::from)
|
||||
});
|
||||
found.push(DiscoveredArtifact {
|
||||
@ -610,6 +682,37 @@ fn dir_size(dir: &Path, depth: usize) -> u64 {
|
||||
.sum()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod strata_tests {
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn strata_startet_den_server_mit_engine_strata_und_behaelt_den_arbeitsordner() {
|
||||
let engine = MayaEngine::strata(MayaConfig::default());
|
||||
let args = engine.build_args(Path::new("/c.json"), 18500);
|
||||
assert_eq!(args[1..3], ["--engine", "strata"]);
|
||||
assert!(args.windows(2).any(|w| w == ["--host", "127.0.0.1"]));
|
||||
assert_eq!(engine.describe().name, "strata");
|
||||
let maya = MayaEngine::new(MayaConfig::default());
|
||||
assert!(
|
||||
!maya
|
||||
.build_args(Path::new("/c.json"), 1)
|
||||
.contains(&"--engine".to_string())
|
||||
);
|
||||
assert_eq!(maya.describe().name, "maya");
|
||||
|
||||
let template =
|
||||
json!({"exe": "component:strata-engine", "cwd": "/t", "api_key": "x", "args": []});
|
||||
let kept =
|
||||
instance_config_for(template.clone(), 1, Path::new("/l"), &[0, 1], None, true).unwrap();
|
||||
assert_eq!(kept["cwd"], "/t");
|
||||
assert!(kept.get("api_key").is_none());
|
||||
let dropped = instance_config(template, 1, Path::new("/l"), &[0], None).unwrap();
|
||||
assert!(dropped.get("cwd").is_none());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user