Add Mesh Buddy companion window (smiley + tokens-served counter)

Square 320x320 window that opens when Share Compute starts serving
(fresh start and restore-on-launch). Static page polls the read-only
mesh_serving_usage command every 2s and shows completion tokens this
machine has served to the community mesh. Smiley cheers up while
requests are in flight.

Demo/prototype for the buzz-box shared-compute exploration.

Co-authored-by: Thomas Petersen <thomasp@squareup.com>
Signed-off-by: Thomas Petersen <thomasp@squareup.com>
This commit is contained in:
Wintermute
2026-08-23 19:50:08 -04:00
parent 0720f5380c
commit 740380c12d
6 changed files with 118 additions and 1 deletions

View File

@@ -0,0 +1,63 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Mesh Buddy</title>
<style>
html,
body {
margin: 0;
height: 100%;
background: #101014;
color: #f5f5f7;
font-family: -apple-system, "Inter", sans-serif;
display: flex;
align-items: center;
justify-content: center;
user-select: none;
cursor: default;
}
.wrap { text-align: center; }
.face { font-size: 96px; line-height: 1; }
.count {
margin-top: 18px;
font-size: 40px;
font-weight: 700;
font-variant-numeric: tabular-nums;
}
.label {
margin-top: 6px;
font-size: 12px;
color: #9a9aa2;
letter-spacing: 0.04em;
text-transform: uppercase;
}
</style>
</head>
<body>
<div class="wrap">
<div class="face" id="face">🙂</div>
<div class="count" id="count">0</div>
<div class="label">tokens helped compute</div>
</div>
<script>
const invoke =
window.__TAURI__?.core?.invoke || window.__TAURI_INTERNALS__?.invoke;
async function tick() {
if (!invoke) return;
try {
const usage = await invoke("mesh_serving_usage");
const tokens = usage?.tokensServed || 0;
const inflight = usage?.inflight || 0;
document.getElementById("count").textContent = tokens.toLocaleString();
document.getElementById("face").textContent =
inflight > 0 ? "😄" : tokens > 0 ? "😊" : "🙂";
} catch {
// Mesh not running — keep whatever is shown.
}
}
tick();
setInterval(tick, 2000);
</script>
</body>
</html>

View File

@@ -2,7 +2,7 @@
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window and trusted huddle companions",
"windows": ["main", "huddle-*"],
"windows": ["main", "huddle-*", "mesh-buddy"],
"permissions": [
"core:default",
"core:webview:allow-set-webview-zoom",

View File

@@ -0,0 +1,36 @@
//! Mesh Buddy — a small square companion window showing a smiley and how many
//! completion tokens this machine has served to the community mesh.
//!
//! The window is chrome only: it loads the static `mesh-buddy.html` page,
//! which polls the existing read-only `mesh_serving_usage` command. No new
//! trust surface — the page reads the same counters the Share compute card
//! already shows.
use tauri::{Manager, WebviewUrl, WebviewWindowBuilder};
const MESH_BUDDY_LABEL: &str = "mesh-buddy";
/// Open (or re-focus) the Mesh Buddy window.
pub fn open_mesh_buddy_window_impl(app: &tauri::AppHandle) -> Result<(), String> {
if let Some(window) = app.get_webview_window(MESH_BUDDY_LABEL) {
window.show().map_err(|error| error.to_string())?;
window.set_focus().map_err(|error| error.to_string())?;
return Ok(());
}
WebviewWindowBuilder::new(
app,
MESH_BUDDY_LABEL,
WebviewUrl::App("mesh-buddy.html".into()),
)
.title("Mesh Buddy")
.inner_size(320.0, 320.0)
.resizable(false)
.build()
.map_err(|error| error.to_string())?;
Ok(())
}
#[tauri::command]
pub fn open_mesh_buddy_window(app: tauri::AppHandle) -> Result<(), String> {
open_mesh_buddy_window_impl(&app)
}

View File

@@ -399,6 +399,7 @@ pub(crate) async fn restore_mesh_sharing(app: &AppHandle, state: &AppState) -> C
);
}
mesh_llm::publish_current_status_once(app, "restore").await;
open_mesh_buddy_on_main_thread(app);
Ok(())
}
@@ -528,9 +529,24 @@ pub async fn mesh_start_node(
}
}
mesh_llm::publish_current_status_once(&app, "start").await;
if sharing_config.is_some() {
open_mesh_buddy_on_main_thread(&app);
}
Ok(status)
}
/// Pop the Mesh Buddy companion when this machine starts serving. Window
/// creation must not run on an async worker on macOS, so hop to main.
fn open_mesh_buddy_on_main_thread(app: &AppHandle) {
let handle = app.clone();
let _ = app.run_on_main_thread(move || {
if let Err(error) = crate::commands::mesh_buddy_window::open_mesh_buddy_window_impl(&handle)
{
eprintln!("buzz-mesh: failed to open mesh buddy window: {error}");
}
});
}
pub(crate) async fn ensure_client_node_for_model(
state: &AppState,
model_id: impl AsRef<str>,

View File

@@ -35,6 +35,7 @@ mod media_raw;
mod media_snapshot_png;
mod media_transcode;
mod media_upload_progress;
pub(crate) mod mesh_buddy_window;
#[cfg(feature = "mesh-llm")]
pub(crate) mod mesh_llm;
#[cfg(feature = "mesh-llm")]

View File

@@ -717,6 +717,7 @@ pub fn run() {
mesh_serving_usage,
mesh_installed_models,
mesh_model_catalog,
commands::mesh_buddy_window::open_mesh_buddy_window,
update_managed_agent,
discover_backend_providers,
probe_backend_provider,