ryugyosoft commited on
Commit
7aaa9f8
·
verified ·
1 Parent(s): 71b2248

onwx' (onwx-dash) 1.2.3: live speeds while an answer runs, animated 2-PC link, model picker without the path (part 2)

Browse files
Files changed (5) hide show
  1. onwx/chat.py +21 -0
  2. onwx/i18n.json +6 -2
  3. onwx/manager.py +18 -1
  4. onwx/server.py +11 -0
  5. onwx/web/manage.html +65 -14
onwx/chat.py CHANGED
@@ -541,6 +541,23 @@ class ChatEngine:
541
  x = y
542
 
543
  # ---- API ----
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
544
  def stream_chat(self, messages, max_new_tokens=512, temperature=0.0, top_p=1.0, stop=(), seed=None,
545
  think=None, should_stop=None, top_k=0, repetition_penalty=1.0, presence_penalty=0.0,
546
  frequency_penalty=0.0, tools=None, split_reasoning=False, show_thinking=None):
@@ -607,6 +624,9 @@ class ChatEngine:
607
  # the client may leave during a long prompt (minutes on a big one, every other request waiting): stopped between
608
  # blocks. The checkpoint stays right - its rows are below where this prompt writes (a fresh prompt dropped it)
609
  self._cancel = should_stop
 
 
 
610
  self.model.feeding = True # ([MTP] the MTP layer's rows go along with the prompt)
611
  w = int(os.environ.get("ONWX_MTP_ROWS", "128") or 0) # ([MTP] rows of the last w prompt tokens only (~3.5 ms a row); 0: all)
612
  self.model.mtp_from = max(0, n - w) if w > 0 else 0
@@ -679,6 +699,7 @@ class ChatEngine:
679
  stop = [x for x in stop if x]
680
  limit = min(max_new_tokens, self.max_context - n - 16)
681
  t1 = time.time()
 
682
 
683
  def deltas(final=False):
684
  """Send what is new. Held back until the next token (or the end): a tail that may still become a stop
 
541
  x = y
542
 
543
  # ---- API ----
544
+ live = None # [1.2.3] the request in progress (see live_now)
545
+
546
+ def live_now(self):
547
+ """[1.2.3] the request in progress for the window, read from another thread: {"phase": "prompt", "new"
548
+ (tokens to read), "done" (read so far, where the model's state grows by chunk), "tok_s" (0 until a chunk is
549
+ done), "s"} or {"phase": "gen", "tokens", "tok_s", "s", "pre" (that prompt's tok/s)}, or None."""
550
+ lv, now = self.live, time.time()
551
+ if not lv:
552
+ return None
553
+ if lv["phase"] == "prompt":
554
+ s = now - lv["t0"]
555
+ done = max(0, min(lv["new"], len(getattr(self.model, "held", None) or []) - lv["h0"]))
556
+ return {"phase": "prompt", "new": lv["new"], "done": done, "tok_s": done / s if done and s > 0 else 0,
557
+ "s": s}
558
+ s, k = now - lv["t1"], len(lv["out"])
559
+ return {"phase": "gen", "tokens": k, "tok_s": k / s if k and s > 0.2 else 0, "s": s, "pre": lv["pre"]}
560
+
561
  def stream_chat(self, messages, max_new_tokens=512, temperature=0.0, top_p=1.0, stop=(), seed=None,
562
  think=None, should_stop=None, top_k=0, repetition_penalty=1.0, presence_penalty=0.0,
563
  frequency_penalty=0.0, tools=None, split_reasoning=False, show_thinking=None):
 
624
  # the client may leave during a long prompt (minutes on a big one, every other request waiting): stopped between
625
  # blocks. The checkpoint stays right - its rows are below where this prompt writes (a fresh prompt dropped it)
626
  self._cancel = should_stop
627
+ # [1.2.3] what the window shows live (server /api/live): reading the prompt, then generating
628
+ h0 = len(getattr(self.model, "held", None) or [])
629
+ self.live = {"phase": "prompt", "t0": time.time(), "new": n - reuse, "h0": h0}
630
  self.model.feeding = True # ([MTP] the MTP layer's rows go along with the prompt)
631
  w = int(os.environ.get("ONWX_MTP_ROWS", "128") or 0) # ([MTP] rows of the last w prompt tokens only (~3.5 ms a row); 0: all)
632
  self.model.mtp_from = max(0, n - w) if w > 0 else 0
 
699
  stop = [x for x in stop if x]
700
  limit = min(max_new_tokens, self.max_context - n - 16)
701
  t1 = time.time()
702
+ self.live = {"phase": "gen", "t1": t1, "out": out, "pre": (n - reuse) / max(t_pre, 1e-9) if n - reuse >= 16 else 0}
703
 
704
  def deltas(final=False):
705
  """Send what is new. Held back until the next token (or the end): a tail that may still become a stop
onwx/i18n.json CHANGED
@@ -545,7 +545,9 @@
545
  "メモリに読み込み中": "Loading into memory",
546
  "{0} / 約 {1} GB": "{0} / about {1} GB",
547
  "メイン PC からモデルの半分を受け取って、メモリに読み込んでいます": "Receiving half of the model from the main PC and loading it into memory",
548
- "自分のモデルファイルからモデルの半分を読み込んでいます": "Loading half of the model from its own model file"
 
 
549
  },
550
  "zh": {
551
  "2 台の PC を USB4(Thunderbolt)のケーブルでつなぎ、1 つのモデルを半分ずつ持って動かします。モデルのメモリが半分になり、1 台では載らないモデルも動き、生成も速くなります(Ryzen AI 9 HX のミニ PC 2 台で、Nemotron 3.5 Bolt 74B-A9B は生成が 1 台の約 1.55 倍・プロンプトの読み込みが約 1.4〜1.5 倍、Qwen3.8 27B は生成が約 1.7 倍、Qwen3.6 35B-A3B は約 1.4 倍)。モデルはメイン PC にあれば動きます。使えるのは Nemotron 3.5 Bolt、Qwen3.6 35B-A3B、Qwen3.8 27B の GGUF で、GPU だけで動かします(NPU の手伝いと画像はこのモードでは使えません)。2 台とも Linux で使ってください。": "用 USB4(Thunderbolt)线连接两台电脑,每台各持模型的一半来运行一个模型。每台所需内存减半,一台装不下的模型也能运行,生成也更快(两台 Ryzen AI 9 HX 迷你电脑:Nemotron 3.5 Bolt 74B-A9B 的生成约为一台的 1.55 倍、读取提示词约 1.4〜1.5 倍,Qwen3.8 27B 生成约 1.7 倍,Qwen3.6 35B-A3B 约 1.4 倍)。模型只需放在主电脑上。可用的是 Nemotron 3.5 Bolt、Qwen3.6 35B-A3B、Qwen3.8 27B 的 GGUF,只用 GPU 运行(此模式下不能使用 NPU 协助和图片)。两台都请使用 Linux。",
@@ -1046,6 +1048,8 @@
1046
  "メモリに読み込み中": "正在载入内存",
1047
  "{0} / 約 {1} GB": "{0} / 约 {1} GB",
1048
  "メイン PC からモデルの半分を受け取って、メモリに読み込んでいます": "正在从主电脑接收一半模型并载入内存",
1049
- "自分のモデルファイルからモデルの半分を読み込んでいます": "正在从自己的模型文件载入一半模型"
 
 
1050
  }
1051
  }
 
545
  "メモリに読み込み中": "Loading into memory",
546
  "{0} / 約 {1} GB": "{0} / about {1} GB",
547
  "メイン PC からモデルの半分を受け取って、メモリに読み込んでいます": "Receiving half of the model from the main PC and loading it into memory",
548
+ "自分のモデルファイルからモデルの半分を読み込んでいます": "Loading half of the model from its own model file",
549
+ "● 生成中 {0}": "● generating {0}",
550
+ "● 読み込み中 {0} 秒": "● reading {0} s"
551
  },
552
  "zh": {
553
  "2 台の PC を USB4(Thunderbolt)のケーブルでつなぎ、1 つのモデルを半分ずつ持って動かします。モデルのメモリが半分になり、1 台では載らないモデルも動き、生成も速くなります(Ryzen AI 9 HX のミニ PC 2 台で、Nemotron 3.5 Bolt 74B-A9B は生成が 1 台の約 1.55 倍・プロンプトの読み込みが約 1.4〜1.5 倍、Qwen3.8 27B は生成が約 1.7 倍、Qwen3.6 35B-A3B は約 1.4 倍)。モデルはメイン PC にあれば動きます。使えるのは Nemotron 3.5 Bolt、Qwen3.6 35B-A3B、Qwen3.8 27B の GGUF で、GPU だけで動かします(NPU の手伝いと画像はこのモードでは使えません)。2 台とも Linux で使ってください。": "用 USB4(Thunderbolt)线连接两台电脑,每台各持模型的一半来运行一个模型。每台所需内存减半,一台装不下的模型也能运行,生成也更快(两台 Ryzen AI 9 HX 迷你电脑:Nemotron 3.5 Bolt 74B-A9B 的生成约为一台的 1.55 倍、读取提示词约 1.4〜1.5 倍,Qwen3.8 27B 生成约 1.7 倍,Qwen3.6 35B-A3B 约 1.4 倍)。模型只需放在主电脑上。可用的是 Nemotron 3.5 Bolt、Qwen3.6 35B-A3B、Qwen3.8 27B 的 GGUF,只用 GPU 运行(此模式下不能使用 NPU 协助和图片)。两台都请使用 Linux。",
 
1048
  "メモリに読み込み中": "正在载入内存",
1049
  "{0} / 約 {1} GB": "{0} / 约 {1} GB",
1050
  "メイン PC からモデルの半分を受け取って、メモリに読み込んでいます": "正在从主电脑接收一半模型并载入内存",
1051
+ "自分のモデルファイルからモデルの半分を読み込んでいます": "正在从自己的模型文件载入一半模型",
1052
+ "● 生成中 {0}": "● 生成中 {0}",
1053
+ "● 読み込み中 {0} 秒": "● 读取中 {0} 秒"
1054
  }
1055
  }
onwx/manager.py CHANGED
@@ -251,6 +251,20 @@ class Manager:
251
  return {"error": T("インストールの途中です")}
252
  return {}
253
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  SPEED = [0, []] # (speed.json's time, its content)
255
 
256
  @classmethod
@@ -716,7 +730,10 @@ class _Handler(BaseHTTPRequestHandler):
716
  if u.path == "/api/state":
717
  if not self._authed(q):
718
  return self._send(403, {"error": T("この画面は onwx-dash のウィンドウかトレイから開いてください")})
719
- return self._send(200, self.manager.state())
 
 
 
720
  self._send(404, {"error": "not found"})
721
 
722
  def do_POST(self):
 
251
  return {"error": T("インストールの途中です")}
252
  return {}
253
 
254
+ @staticmethod
255
+ def live(st):
256
+ """[1.2.3] the running server's request in progress (its /api/live), or None - asked only while the window's
257
+ server page shows (once a second)."""
258
+ sv = st.get("server") or {}
259
+ if sv.get("status") != "running" or not sv.get("port"):
260
+ return None
261
+ try:
262
+ import urllib.request
263
+ with urllib.request.urlopen(f"http://127.0.0.1:{sv['port']}/api/live", timeout=0.4) as r:
264
+ return json.load(r).get("live")
265
+ except Exception:
266
+ return None
267
+
268
  SPEED = [0, []] # (speed.json's time, its content)
269
 
270
  @classmethod
 
730
  if u.path == "/api/state":
731
  if not self._authed(q):
732
  return self._send(403, {"error": T("この画面は onwx-dash のウィンドウかトレイから開いてください")})
733
+ st = self.manager.state()
734
+ if (q.get("live") or [""])[0] == "1": # [1.2.3] the server page shows: the answer in progress
735
+ st["live"] = self.manager.live(st)
736
+ return self._send(200, st)
737
  self._send(404, {"error": "not found"})
738
 
739
  def do_POST(self):
onwx/server.py CHANGED
@@ -263,6 +263,7 @@ def start_generation(msgs, kw):
263
  put(d)
264
  finally:
265
  set_priority(False)
 
266
  except Exception as e: # surfaced to the client
267
  put(e)
268
  finally:
@@ -529,6 +530,16 @@ def bench_text(tokens: int = 2048):
529
  return {"text": pipe.tok.decode(ids, skip_special_tokens=True), "tokens": len(ids)}
530
 
531
 
 
 
 
 
 
 
 
 
 
 
532
  @app.get("/api/info")
533
  def api_info():
534
  # the window's defaults for this model, read now (they change without a restart)
 
263
  put(d)
264
  finally:
265
  set_priority(False)
266
+ pipe.live = None # [1.2.3] (nothing in progress for the window)
267
  except Exception as e: # surfaced to the client
268
  put(e)
269
  finally:
 
530
  return {"text": pipe.tok.decode(ids, skip_special_tokens=True), "tokens": len(ids)}
531
 
532
 
533
+ @app.get("/api/live")
534
+ def api_live():
535
+ """[1.2.3] the request in progress, for the window's speed tiles (polled once a second while its server page
536
+ shows): {"live": None | {"phase": "prompt" | "gen", ...}} (ChatEngine.live_now)."""
537
+ try:
538
+ return {"live": pipe.live_now() if pipe is not None and hasattr(pipe, "live_now") else None}
539
+ except Exception:
540
+ return {"live": None}
541
+
542
+
543
  @app.get("/api/info")
544
  def api_info():
545
  # the window's defaults for this model, read now (they change without a restart)
onwx/web/manage.html CHANGED
@@ -105,6 +105,32 @@
105
  .wire.on::after { background: repeating-linear-gradient(90deg, #c44dff 0 8px, transparent 8px 12px); }
106
  .wire.wait::after { background: repeating-linear-gradient(90deg, #f0c060 0 4px, transparent 4px 12px); }
107
  .wire span { position: relative; z-index: 1; background: var(--solid); padding: 0 8px; font: 10px var(--mono); letter-spacing: .12em; color: var(--muted); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  .kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; align-items: center; }
109
  .kv .k { color: var(--muted); }
110
  .kv code { font-family: var(--mono); font-size: 12px; background: var(--panel2); color: #a9b8ff; padding: 1px 6px; border-radius: 2px; }
@@ -212,9 +238,9 @@
212
  <section class="page on" id="page-server">
213
  <!-- [1.2] the telemetry strip: the last answers' speeds, memory, the NPU's load (or the context length) -->
214
  <div class="strip">
215
- <div class="cell main" id="c-gen"><span class="lab"><i>01</i><span>生成</span></span><span class="num g off" id="t-gen">—</span><span class="unit">tok/s</span>
216
  <svg class="spark" viewBox="0 0 100 22" preserveAspectRatio="none" aria-hidden="true"><defs><linearGradient id="sg" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="100" y2="0"><stop offset="0" stop-color="#ff4d5e"/><stop offset=".55" stop-color="#c44dff"/><stop offset="1" stop-color="#4d7dff"/></linearGradient></defs><polyline id="sp-gen" fill="none" stroke="url(#sg)" stroke-width="1.5" stroke-linejoin="round" vector-effect="non-scaling-stroke"/></svg></div>
217
- <div class="cell" id="c-pre"><span class="lab"><i>02</i><span>プロンプト</span></span><span class="num off" id="t-pre">—</span><span class="unit">tok/s</span>
218
  <svg class="spark" viewBox="0 0 100 22" preserveAspectRatio="none" aria-hidden="true"><polyline id="sp-pre" fill="none" stroke="#8fb0ff" stroke-width="1.5" stroke-linejoin="round" vector-effect="non-scaling-stroke"/></svg></div>
219
  <div class="cell" id="c-mem"><span class="lab"><i>03</i><span>メモリ</span></span><span class="num off" id="t-mem">—</span><span class="unit" id="t-memu">GB</span>
220
  <span class="gauge" title="onwx-dash(サーバーと、NPU が使うメモリ)・ほかのアプリ・空き"><i class="u-onwx" id="u-onwx"></i><i class="u-oth" id="u-oth"></i></span>
@@ -250,9 +276,9 @@
250
  <button class="primary" id="b-tp" onclick="tpToggle()">補助を開始</button>
251
  </div>
252
  <div class="link">
253
- <div class="pc me"><span class="lab" id="tp-me-role">—</span><b id="tp-me">—</b></div>
254
- <div class="wire" id="tp-wire"><span id="tp-addr">—</span></div>
255
- <div class="pc"><span class="lab" id="tp-peer-role">—</span><b id="tp-peer">—</b></div>
256
  </div>
257
  <div class="kv small" id="tp-modelrow">
258
  <span class="k">モデル</span><span class="mono ellipsis" id="tp-model">—</span>
@@ -465,7 +491,7 @@
465
  const cur = loadedNow && inst.some(m => m.key === sv.model) ? sv.model
466
  : (pick.value && inst.some(m => m.key === pick.value)) ? pick.value
467
  : (sv.model && inst.some(m => m.key === sv.model) ? sv.model : (inst.find(m => m.key === s.config.model) || inst[0] || {}).key);
468
- const pickHtml = inst.map(m => `<option value="${esc(m.key)}"${m.key === cur ? " selected" : ""}>${esc(m.title)} — ${esc(m.path)}${m.key === sv.model ? T("(ロード済み)") : ""}</option>`).join("");
469
  if (pickHtml !== lastPick) { pick.innerHTML = pickHtml; lastPick = pickHtml; } // rebuild only on change: a rebuild eats clicks
470
  if (loadedNow && cur && pick.value !== cur) pick.value = cur;
471
  const same = sv.model && pick.value === sv.model;
@@ -538,7 +564,7 @@
538
  $("f-tp_enabled").checked = !!t.enabled; $("f-tp_role").value = t.role; $("f-tp_listener").value = t.listener;
539
  $("f-tp_mode").value = t.ip === "auto" ? "auto" : tpRing(t.ip) ? "ring" : "manual"; $("f-tp_ip").value = t.ip === "auto" || tpRing(t.ip) ? "" : t.ip; $("f-tp_port").value = t.port; $("f-tp_streams").value = t.streams;
540
  const opts = [`<option value="">${esc(T("自動(選んでいるモデルか、最初に見つかったもの)"))}</option>`]
541
- .concat((s.tp.models || []).map(m => `<option value="${esc(m.key)}">${esc(m.title)} — ${esc(m.path)}</option>`));
542
  if (t.model && !(s.tp.models || []).some(m => m.key === t.model)) opts.push(`<option value="${esc(t.model)}">${esc(t.model)}</option>`);
543
  const html = opts.join("");
544
  if ($("f-tp_model").dataset.html !== html) { $("f-tp_model").innerHTML = html; $("f-tp_model").dataset.html = html; }
@@ -559,13 +585,21 @@
559
  function setNum(id, text, on) { const e = $(id); if (e.textContent !== text) e.textContent = text; e.classList.toggle("off", !on); }
560
  function renderStrip() {
561
  const s = S, sv = s.server, live = sv.status === "running";
562
- const sp = (live && s.speed) || [], key = JSON.stringify(sp) + live;
563
  if (key !== lastSpeed) {
564
  lastSpeed = key;
565
  const gen = sp.map(x => x[0]).filter(x => x > 0), pre = sp.map(x => x[1]).filter(x => x > 0);
566
- setNum("t-gen", gen.length ? gen[gen.length - 1].toFixed(1) : "—", gen.length > 0);
567
- setNum("t-pre", pre.length ? Math.round(pre[pre.length - 1]).toLocaleString() : "—", pre.length > 0);
568
- spark("sp-gen", gen); spark("sp-pre", pre);
 
 
 
 
 
 
 
 
569
  $("c-gen").title = $("c-pre").title = T("直近の回答の速さ。線は最近の回答の移り変わり");
570
  }
571
  // memory: onwx (the server and what the NPU holds for it) / other programs / free
@@ -676,7 +710,11 @@
676
  : stg === "load" ? ["warn", T("メモリに読み込み中 {0}", pc(ld.gpu, ld.main_total))]
677
  : stg === "helper" ? ["warn", T("接続しました")] : ["warn", T("補助 PC を待っています")];
678
  $("tp-pill").className = "pill " + pl[0]; $("tp-pill").textContent = pl[1];
679
- $("tp-wire").className = "wire" + (on || (tw && stg !== "wait") ? " on" : tw ? " wait" : "");
 
 
 
 
680
  $("tp-me-role").textContent = T("この PC ・ メイン"); $("tp-peer-role").textContent = T("補助 PC");
681
  $("tp-me").textContent = on || tw ? (sv.title || "—") : "—";
682
  $("tp-addr").textContent = tpShow(t.ip, t.port); $("tp-wire").title = tpAddr(t.listener === "main", t.ip, t.port);
@@ -694,7 +732,10 @@
694
  const pl = {waiting: ["warn", T("メイン PC を待っています")], serving: ["ok", T("メイン PC とつながっています")],
695
  failed: ["danger", T("補助が止まりました")], stopped: ["", T("補助は停止中")]}[h.status] || ["", h.status];
696
  $("tp-pill").className = "pill " + pl[0]; $("tp-pill").textContent = pl[1];
697
- $("tp-wire").className = "wire" + (h.status === "serving" ? " on" : h.status === "waiting" ? " wait" : "");
 
 
 
698
  $("tp-me-role").textContent = T("この PC ・ 補助"); $("tp-peer-role").textContent = T("メイン PC");
699
  const hl = h.status === "serving" && h.loading; // [1.2.2] the helper's half still loading
700
  if (hl) { $("tp-pill").className = "pill warn";
@@ -715,6 +756,14 @@
715
  : T("「補助を開始」を押すと、この PC のモデルを閉じてメイン PC を待ちます");
716
  $("tp-msg").textContent = msg; $("tp-msg").className = "small grow " + (h.error ? "err" : "muted");
717
  }
 
 
 
 
 
 
 
 
718
  async function tpToggle() {
719
  const h = S && S.tp && S.tp.helper, up = h && (h.status === "waiting" || h.status === "serving");
720
  if (!up && S.server.model && !await ask(T("補助を開始すると、読み込まれているモデル({0})を閉じます。よろしいですか?", S.server.title || S.server.model))) return;
@@ -939,7 +988,9 @@
939
  async function refresh() {
940
  const n = ++REQ;
941
  try {
942
- const r = await fetch("/api/state?token=" + encodeURIComponent(TOKEN), {cache: "no-store"});
 
 
943
  if (r.status === 403) { $("env").textContent = T("この画面は onwx-dash のウィンドウかトレイから開いてください"); return; }
944
  const j = await r.json();
945
  if (n <= STALE) return; // (asked before the last save: shows the old values)
 
105
  .wire.on::after { background: repeating-linear-gradient(90deg, #c44dff 0 8px, transparent 8px 12px); }
106
  .wire.wait::after { background: repeating-linear-gradient(90deg, #f0c060 0 4px, transparent 4px 12px); }
107
  .wire span { position: relative; z-index: 1; background: var(--solid); padding: 0 8px; font: 10px var(--mono); letter-spacing: .12em; color: var(--muted); }
108
+ /* [1.2.3] the link alive: packets along the wire (both ways while the pair works, one way while the model is sent),
109
+ an amber scanner while waiting; the two PCs glow while joined, a bar while their half loads */
110
+ .wire { overflow: hidden; }
111
+ .wire.on::after { box-shadow: 0 0 6px #c44dff88; }
112
+ .wire .pk { position: absolute; top: 50%; left: -24px; width: 22px; height: 4px; margin-top: -2px; border-radius: 2px; opacity: 0;
113
+ background: linear-gradient(90deg, transparent, #c44dff 60%, #fff); box-shadow: 0 0 8px #c44dffaa; }
114
+ .wire .pk.b { background: linear-gradient(270deg, transparent, #4d7dff 60%, #fff); box-shadow: 0 0 8px #4d7dffaa; }
115
+ @keyframes pk-f { 0% { left: -24px; opacity: 0 } 12% { opacity: 1 } 88% { opacity: 1 } 100% { left: 100%; opacity: 0 } }
116
+ @keyframes pk-b { 0% { left: 100%; opacity: 0 } 12% { opacity: 1 } 88% { opacity: 1 } 100% { left: -24px; opacity: 0 } }
117
+ @keyframes pk-scan { 0% { left: 0; opacity: .25 } 50% { opacity: 1 } 100% { left: calc(100% - 22px); opacity: .25 } }
118
+ .wire.on .pk.f { animation: pk-f 2.8s linear var(--d) infinite; } .wire.on .pk.b { animation: pk-b 2.8s linear var(--d) infinite; }
119
+ .wire.on.busy .pk.f, .wire.on.busy .pk.b { animation-duration: .75s; }
120
+ .wire.on.send .pk.f { animation-duration: .7s; } .wire.on.send .pk.b { animation: none; }
121
+ .wire.on.recv .pk.b { animation-duration: .7s; } .wire.on.recv .pk.f { animation: none; }
122
+ .wire.wait .pk.f.s0 { animation: pk-scan 1.6s ease-in-out infinite alternate; background: radial-gradient(closest-side, #ffd27a, #f0c06000); box-shadow: none; height: 6px; margin-top: -3px; }
123
+ @keyframes pc-glow { 0%, 100% { box-shadow: 0 0 0 1px #c44dff22, 0 0 6px #c44dff22 } 50% { box-shadow: 0 0 0 1px #c44dff55, 0 0 16px #c44dff55 } }
124
+ .pc { position: relative; transition: border-color .4s; }
125
+ .pc.lit { border-color: #8a4dd0; animation: pc-glow 2.8s ease-in-out infinite; }
126
+ .pc.wait { border-style: dashed; }
127
+ .pc .bar { display: none; height: 3px; margin-top: 4px; background: var(--panel2); overflow: hidden; }
128
+ .pc .bar.on { display: block; } .pc .bar i { display: block; height: 100%; width: 0; background: var(--g); transition: width .9s linear; }
129
+ /* [1.2.3] a speed tile while an answer is in progress */
130
+ .lab .lv { display: none; font-weight: 400; color: #ff4d5e; margin-left: 6px; letter-spacing: .08em; }
131
+ .cell.live .lab .lv { display: inline; animation: lv-blink 1.2s ease-in-out infinite; }
132
+ @keyframes lv-blink { 50% { opacity: .35 } }
133
+ @media (prefers-reduced-motion: reduce) { .wire .pk, .pc.lit, .cell.live .lab .lv { animation: none !important; } }
134
  .kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; align-items: center; }
135
  .kv .k { color: var(--muted); }
136
  .kv code { font-family: var(--mono); font-size: 12px; background: var(--panel2); color: #a9b8ff; padding: 1px 6px; border-radius: 2px; }
 
238
  <section class="page on" id="page-server">
239
  <!-- [1.2] the telemetry strip: the last answers' speeds, memory, the NPU's load (or the context length) -->
240
  <div class="strip">
241
+ <div class="cell main" id="c-gen"><span class="lab"><i>01</i><span>生成</span><b class="lv" id="lv-gen"></b></span><span class="num g off" id="t-gen">—</span><span class="unit">tok/s</span>
242
  <svg class="spark" viewBox="0 0 100 22" preserveAspectRatio="none" aria-hidden="true"><defs><linearGradient id="sg" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="100" y2="0"><stop offset="0" stop-color="#ff4d5e"/><stop offset=".55" stop-color="#c44dff"/><stop offset="1" stop-color="#4d7dff"/></linearGradient></defs><polyline id="sp-gen" fill="none" stroke="url(#sg)" stroke-width="1.5" stroke-linejoin="round" vector-effect="non-scaling-stroke"/></svg></div>
243
+ <div class="cell" id="c-pre"><span class="lab"><i>02</i><span>プロンプト</span><b class="lv" id="lv-pre"></b></span><span class="num off" id="t-pre">—</span><span class="unit">tok/s</span>
244
  <svg class="spark" viewBox="0 0 100 22" preserveAspectRatio="none" aria-hidden="true"><polyline id="sp-pre" fill="none" stroke="#8fb0ff" stroke-width="1.5" stroke-linejoin="round" vector-effect="non-scaling-stroke"/></svg></div>
245
  <div class="cell" id="c-mem"><span class="lab"><i>03</i><span>メモリ</span></span><span class="num off" id="t-mem">—</span><span class="unit" id="t-memu">GB</span>
246
  <span class="gauge" title="onwx-dash(サーバーと、NPU が使うメモリ)・ほかのアプリ・空き"><i class="u-onwx" id="u-onwx"></i><i class="u-oth" id="u-oth"></i></span>
 
276
  <button class="primary" id="b-tp" onclick="tpToggle()">補助を開始</button>
277
  </div>
278
  <div class="link">
279
+ <div class="pc me" id="tp-mebox"><span class="lab" id="tp-me-role">—</span><b id="tp-me">—</b><span class="bar" id="tp-mebar"><i></i></span></div>
280
+ <div class="wire" id="tp-wire"><i class="pk f s0" style="--d:0s"></i><i class="pk f" style="--d:-.93s"></i><i class="pk f" style="--d:-1.86s"></i><i class="pk b" style="--d:-.45s"></i><i class="pk b" style="--d:-1.4s"></i><i class="pk b" style="--d:-2.33s"></i><span id="tp-addr">—</span></div>
281
+ <div class="pc" id="tp-peerbox"><span class="lab" id="tp-peer-role">—</span><b id="tp-peer">—</b><span class="bar" id="tp-peerbar"><i></i></span></div>
282
  </div>
283
  <div class="kv small" id="tp-modelrow">
284
  <span class="k">モデル</span><span class="mono ellipsis" id="tp-model">—</span>
 
491
  const cur = loadedNow && inst.some(m => m.key === sv.model) ? sv.model
492
  : (pick.value && inst.some(m => m.key === pick.value)) ? pick.value
493
  : (sv.model && inst.some(m => m.key === sv.model) ? sv.model : (inst.find(m => m.key === s.config.model) || inst[0] || {}).key);
494
+ const pickHtml = inst.map(m => `<option value="${esc(m.key)}"${m.key === cur ? " selected" : ""} title="${esc(m.path)}">${esc(m.title)}${m.key === sv.model ? T("(ロード済み)") : ""}</option>`).join("");
495
  if (pickHtml !== lastPick) { pick.innerHTML = pickHtml; lastPick = pickHtml; } // rebuild only on change: a rebuild eats clicks
496
  if (loadedNow && cur && pick.value !== cur) pick.value = cur;
497
  const same = sv.model && pick.value === sv.model;
 
564
  $("f-tp_enabled").checked = !!t.enabled; $("f-tp_role").value = t.role; $("f-tp_listener").value = t.listener;
565
  $("f-tp_mode").value = t.ip === "auto" ? "auto" : tpRing(t.ip) ? "ring" : "manual"; $("f-tp_ip").value = t.ip === "auto" || tpRing(t.ip) ? "" : t.ip; $("f-tp_port").value = t.port; $("f-tp_streams").value = t.streams;
566
  const opts = [`<option value="">${esc(T("自動(選んでいるモデルか、最初に見つかったもの)"))}</option>`]
567
+ .concat((s.tp.models || []).map(m => `<option value="${esc(m.key)}" title="${esc(m.path)}">${esc(m.title)}</option>`));
568
  if (t.model && !(s.tp.models || []).some(m => m.key === t.model)) opts.push(`<option value="${esc(t.model)}">${esc(t.model)}</option>`);
569
  const html = opts.join("");
570
  if ($("f-tp_model").dataset.html !== html) { $("f-tp_model").innerHTML = html; $("f-tp_model").dataset.html = html; }
 
585
  function setNum(id, text, on) { const e = $(id); if (e.textContent !== text) e.textContent = text; e.classList.toggle("off", !on); }
586
  function renderStrip() {
587
  const s = S, sv = s.server, live = sv.status === "running";
588
+ const sp = (live && s.speed) || [], lv = live && s.live || null, key = JSON.stringify(sp) + live + JSON.stringify(lv);
589
  if (key !== lastSpeed) {
590
  lastSpeed = key;
591
  const gen = sp.map(x => x[0]).filter(x => x > 0), pre = sp.map(x => x[1]).filter(x => x > 0);
592
+ // [1.2.3] an answer in progress (asked once a second while this page shows): its speed now, the line moving
593
+ const g = !!lv && lv.phase === "gen", p = !!lv && lv.phase === "prompt";
594
+ const genNow = g && lv.tok_s > 0 ? gen.concat([lv.tok_s]) : gen;
595
+ const preNow = g && lv.pre > 0 ? pre.concat([lv.pre]) : p && lv.tok_s > 0 ? pre.concat([lv.tok_s]) : pre;
596
+ setNum("t-gen", g ? (lv.tok_s > 0 ? lv.tok_s.toFixed(1) : "…") : gen.length ? gen[gen.length - 1].toFixed(1) : "—", g || gen.length > 0);
597
+ setNum("t-pre", p ? (lv.tok_s > 0 ? Math.round(lv.tok_s).toLocaleString() : "…")
598
+ : preNow.length ? Math.round(preNow[preNow.length - 1]).toLocaleString() : "—", p || preNow.length > 0);
599
+ $("c-gen").classList.toggle("live", g); $("c-pre").classList.toggle("live", p);
600
+ $("lv-gen").textContent = g ? T("● 生成中 {0}", lv.tokens) : "";
601
+ $("lv-pre").textContent = p ? T("● 読み込み中 {0} 秒", Math.floor(lv.s)) : "";
602
+ spark("sp-gen", genNow); spark("sp-pre", preNow);
603
  $("c-gen").title = $("c-pre").title = T("直近の回答の速さ。線は最近の回答の移り変わり");
604
  }
605
  // memory: onwx (the server and what the NPU holds for it) / other programs / free
 
710
  : stg === "load" ? ["warn", T("メモリに読み込み中 {0}", pc(ld.gpu, ld.main_total))]
711
  : stg === "helper" ? ["warn", T("接続しました")] : ["warn", T("補助 PC を待っています")];
712
  $("tp-pill").className = "pill " + pl[0]; $("tp-pill").textContent = pl[1];
713
+ const busy = on && S.live && (S.live.phase === "gen" || S.live.phase === "prompt");
714
+ $("tp-wire").className = "wire" + (on || (tw && stg !== "wait") ? " on" : tw ? " wait" : "") + (busy ? " busy" : "") + (stg === "send" ? " send" : "");
715
+ tpBoxes(on || (tw && stg !== "wait"), tw && stg === "wait",
716
+ stg === "load" && ld.main_total ? ld.gpu / ld.main_total : null,
717
+ (stg === "send" || stg === "load") && ld.sent_total ? ld.sent / ld.sent_total : null);
718
  $("tp-me-role").textContent = T("この PC ・ メイン"); $("tp-peer-role").textContent = T("補助 PC");
719
  $("tp-me").textContent = on || tw ? (sv.title || "—") : "—";
720
  $("tp-addr").textContent = tpShow(t.ip, t.port); $("tp-wire").title = tpAddr(t.listener === "main", t.ip, t.port);
 
732
  const pl = {waiting: ["warn", T("メイン PC を待っています")], serving: ["ok", T("メイン PC とつながっています")],
733
  failed: ["danger", T("補助が止まりました")], stopped: ["", T("補助は停止中")]}[h.status] || ["", h.status];
734
  $("tp-pill").className = "pill " + pl[0]; $("tp-pill").textContent = pl[1];
735
+ $("tp-wire").className = "wire" + (h.status === "serving" ? " on" : h.status === "waiting" ? " wait" : "") +
736
+ (h.status === "serving" && h.loading && h.loading.stage === "recv" ? " recv" : "");
737
+ tpBoxes(h.status === "serving", h.status === "waiting",
738
+ h.status === "serving" && h.loading && h.loading.total ? h.loading.done / h.loading.total : null, null);
739
  $("tp-me-role").textContent = T("この PC ・ 補助"); $("tp-peer-role").textContent = T("メイン PC");
740
  const hl = h.status === "serving" && h.loading; // [1.2.2] the helper's half still loading
741
  if (hl) { $("tp-pill").className = "pill warn";
 
756
  : T("「補助を開始」を押すと、この PC のモデルを閉じてメイン PC を待ちます");
757
  $("tp-msg").textContent = msg; $("tp-msg").className = "small grow " + (h.error ? "err" : "muted");
758
  }
759
+ // [1.2.3] the two PC boxes: glowing while joined, dashed while waiting, a bar while a half loads (0..1 or null)
760
+ function tpBoxes(lit, wait, me, peer) {
761
+ for (const [box, bar, f] of [["tp-mebox", "tp-mebar", me], ["tp-peerbox", "tp-peerbar", peer]]) {
762
+ $(box).classList.toggle("lit", !!lit); $(box).classList.toggle("wait", !!wait);
763
+ $(bar).classList.toggle("on", f != null);
764
+ $(bar).firstChild.style.width = f != null ? Math.min(100, 100 * f).toFixed(1) + "%" : "0";
765
+ }
766
+ }
767
  async function tpToggle() {
768
  const h = S && S.tp && S.tp.helper, up = h && (h.status === "waiting" || h.status === "serving");
769
  if (!up && S.server.model && !await ask(T("補助を開始すると、読み込まれているモデル({0})を閉じます。よろしいですか?", S.server.title || S.server.model))) return;
 
988
  async function refresh() {
989
  const n = ++REQ;
990
  try {
991
+ // [1.2.3] the answer in progress only while the server page shows
992
+ const lv = $("page-server").classList.contains("on") && !document.hidden ? "&live=1" : "";
993
+ const r = await fetch("/api/state?token=" + encodeURIComponent(TOKEN) + lv, {cache: "no-store"});
994
  if (r.status === 403) { $("env").textContent = T("この画面は onwx-dash のウィンドウかトレイから開いてください"); return; }
995
  const j = await r.json();
996
  if (n <= STALE) return; // (asked before the last save: shows the old values)