eka toimiva

This commit is contained in:
2026-04-01 22:14:48 +03:00
parent d70fd81f05
commit 02f6684378
8 changed files with 235 additions and 24 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "hub"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
[dependencies]

View File

@@ -245,7 +245,7 @@ impl NodeDb {
en: &serde_json::Value,
fi: &serde_json::Value,
overhead: f64,
duration_ms: u64,
duration_ms: f64,
) {
let conn = self.conn.lock().unwrap();
let now = chrono::Utc::now().to_rfc3339();
@@ -265,7 +265,7 @@ impl NodeDb {
en.get("chars_per_token").and_then(|v| v.as_f64()),
fi.get("chars_per_token").and_then(|v| v.as_f64()),
overhead,
duration_ms as i64,
duration_ms,
],
);
}

View File

@@ -74,7 +74,7 @@ tr:hover td { background:#1c2333; }
</head>
<body>
<h1>Kipina Admin</h1>
<p class="sub">Node-sessiot ja tokenisointivertailut</p>
<p class="sub">Node-sessiot ja tokenisointivertailut · <span id="admin-version" style="color:var(--accent)">-</span></p>
<div id="stats" class="stats-grid"></div>
@@ -140,6 +140,9 @@ async function load() {
const sessions = await sessionsRes.json();
const pairs = await pairsRes.json();
// Versio
if (stats.version) document.getElementById('admin-version').textContent = 'v' + stats.version;
// Stats
document.getElementById('stats').innerHTML = [
{v: stats.total_sessions, l: 'Sessioita'},
@@ -194,7 +197,7 @@ async function load() {
}
load();
setInterval(load, 10000);
setInterval(load, 1000);
</script>
</body>
</html>"##;
@@ -275,7 +278,7 @@ async fn main() {
.with_state(state);
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
tracing::debug!("Kipinä Agent Hub käynnistyy osoitteessa http://localhost:3000");
tracing::info!("Kipinä Agent Hub v{} käynnistyy osoitteessa http://localhost:3000", env!("CARGO_PKG_VERSION"));
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
axum::serve(listener, app.into_make_service_with_connect_info::<SocketAddr>()).await.unwrap();
@@ -296,7 +299,9 @@ async fn api_pairs(
async fn api_stats(
axum::extract::State(state): axum::extract::State<Arc<AppState>>,
) -> impl IntoResponse {
axum::Json(state.db.get_stats())
let mut stats = state.db.get_stats();
stats.as_object_mut().unwrap().insert("version".to_string(), serde_json::json!(env!("CARGO_PKG_VERSION")));
axum::Json(stats)
}
async fn admin_page() -> impl IntoResponse {
@@ -358,6 +363,7 @@ async fn broadcast_stats(state: &Arc<AppState>) {
let completed = *state.total_tasks.lock().unwrap();
let stats_msg = serde_json::json!({
"type": "stats",
"version": env!("CARGO_PKG_VERSION"),
"nodes": total_nodes,
"vram_gb": total_vram,
"tasks": completed
@@ -553,7 +559,7 @@ async fn handle_socket(socket: WebSocket, state: Arc<AppState>, ip: IpAddr) {
let en = obj.get("en").unwrap_or(&empty);
let fi = obj.get("fi").unwrap_or(&empty);
let overhead = obj.get("overhead_pct").and_then(|v| v.as_f64()).unwrap_or(0.0);
let duration = obj.get("duration_ms").and_then(|v| v.as_u64()).unwrap_or(0);
let duration = obj.get("duration_ms").and_then(|v| v.as_f64()).unwrap_or(0.0);
let en_text = en.get("text").and_then(|v| v.as_str()).unwrap_or("");
let en_tokens = en.get("token_count").and_then(|v| v.as_u64()).unwrap_or(0);
@@ -568,7 +574,7 @@ async fn handle_socket(socket: WebSocket, state: Arc<AppState>, ip: IpAddr) {
let overhead_color = if overhead > 10.0 { "\x1b[31m" } else if overhead < -10.0 { "\x1b[32m" } else { "\x1b[33m" };
println!();
println!("\x1b[36m━━━ Solmu {} ━━━ {}ms ━━━\x1b[0m", node_id, duration);
println!("\x1b[36m━━━ Solmu {} ━━━ {:.2}ms ━━━\x1b[0m", node_id, duration);
println!(" \x1b[34mEN\x1b[0m \"{}\"", en_text);
println!(" {} merkkiä → \x1b[35m{} tokenia\x1b[0m | \x1b[32m{:.2} merkkiä/token\x1b[0m", en_chars, en_tokens, en_cpt);
println!(" \x1b[33mFI\x1b[0m \"{}\"", fi_text);