Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Laya: normalize URL, report status at startup, clearer fallback reason

Oleksandr Ivanchenko7de0e9a39c4b
diff --git a/.gitignore b/.gitignore
index f1184311..6c28c69a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ dist/
*.db-wal
*.db-shm
.DS_Store
+.laya-venv/
diff --git a/src/main.rs b/src/main.rs
index 06f17951..688eeefd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -84,6 +84,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let tools = ToolRunner::new(config.data_dir.join("workspace"));
let broker = PermissionBroker::new();
let router = LayaRouter::new(config.laya_url.clone());
+ if router.is_reachable().await {
+ println!("🔮 Laya router online at {}", router.base_url);
+ } else {
+ println!(
+ "⚠️ Laya router not reachable at {} — using keyword routing. Start it with `laya-serve` (pip install \"laya[serve]\").",
+ router.base_url
+ );
+ }
let state = AppState::new(config.clone(), db, tools, broker, router);
let app = create_router(state);
diff --git a/src/router/laya.rs b/src/router/laya.rs
index 052df825..27886420 100644
--- a/src/router/laya.rs
+++ b/src/router/laya.rs
@@ -16,7 +16,18 @@ impl LayaRouter {
.build()
.unwrap_or_else(|_| Client::new());
- Self { base_url, client }
+ Self { base_url: normalize_base_url(&base_url), client }
+ }
+
+ /// Returns true when the Laya sidecar answers on its health endpoint.
+ pub async fn is_reachable(&self) -> bool {
+ self.client
+ .get(format!("{}/health", self.base_url))
+ .timeout(Duration::from_millis(800))
+ .send()
+ .await
+ .map(|r| r.status().is_success())
+ .unwrap_or(false)
}
/// Routes a prompt to the optimal model using Laya (/v1/systemone),
@@ -102,3 +113,16 @@ impl LayaRouter {
}
}
}
+
+/// Accepts either the Laya root (`http://host:8000`) or a full endpoint URL
+/// (`http://host:8000/v1/systemone`) and returns the root, so paths are never doubled.
+pub fn normalize_base_url(url: &str) -> String {
+ let mut base = url.trim().trim_end_matches('/');
+ for suffix in ["/v1/systemone/batch", "/v1/systemone", "/v1"] {
+ if let Some(stripped) = base.strip_suffix(suffix) {
+ base = stripped.trim_end_matches('/');
+ break;
+ }
+ }
+ base.to_string()
+}
diff --git a/src/router/team.rs b/src/router/team.rs
index 4bcec54e..12b84713 100644
--- a/src/router/team.rs
+++ b/src/router/team.rs
@@ -116,7 +116,7 @@ impl LayaRouter {
match self.query_laya_for_kwant(prompt, channel_name, members).await {
Ok(choice) => choice,
Err(e) => {
- tracing::debug!(error = %e, "Laya channel routing unavailable or failed, using heuristic fallback");
+ tracing::warn!(error = %e, url = %self.base_url, "Laya channel routing unavailable, using keyword fallback");
let (kwant, reason) = heuristic_pick_kwant(prompt, lead_kwant_id, members)
.map(|(k, r)| (k.id.clone(), r))
.unwrap_or_else(|| (lead_kwant_id.to_string(), "Routed to channel lead".into()));
@@ -207,7 +207,10 @@ pub fn heuristic_pick_kwant<'a>(
let lead = members.iter().find(|m| m.id == lead_kwant_id).unwrap_or(&members[0]);
Some((
lead,
- format!("No specialist matched; {} ({}) is taking it as channel lead", lead.name, lead.title),
+ format!(
+ "No agent here lists skills matching this request, so {} ({}) is taking it as channel lead",
+ lead.name, lead.title
+ ),
))
}
}
diff --git a/tests/router_test.rs b/tests/router_test.rs
index 65432fa0..74588b14 100644
--- a/tests/router_test.rs
+++ b/tests/router_test.rs
@@ -180,3 +180,13 @@ fn pinned_preferred_model_overrides_laya_but_keeps_effort() {
assert_eq!(apply_preferred_model(laya(), unpinned).selected_model, "claude");
}
}
+
+#[test]
+fn laya_base_url_is_normalized() {
+ use kwnt::router::laya::normalize_base_url;
+ assert_eq!(normalize_base_url("http://127.0.0.1:8000"), "http://127.0.0.1:8000");
+ assert_eq!(normalize_base_url("http://127.0.0.1:8000/"), "http://127.0.0.1:8000");
+ assert_eq!(normalize_base_url("http://127.0.0.1:8000/v1/systemone"), "http://127.0.0.1:8000");
+ assert_eq!(normalize_base_url("http://127.0.0.1:8000/v1/systemone/"), "http://127.0.0.1:8000");
+ assert_eq!(normalize_base_url("http://127.0.0.1:8000/v1"), "http://127.0.0.1:8000");
+}