[INFRA] migrate active old VPS 193.233.210.184 to 45.133.209.253
This commit is contained in:
1 parent
d2c6a1a51f
commit
c985c0617b
107 files changed
+304
-186
No files matched your search
+94
-16
@@ -2475,29 +2475,104 @@ def prism_requirements(model):
|
||||
|
||||
|
||||
def prism_matrix_db(vendor=""):
|
||||
"""Host-to-device compatibility rows from prism.model_requirements."""
|
||||
vendor = str(vendor or "").strip()
|
||||
where = " and lower(m.vendor)=lower(%s)" % _sqlq(vendor) if vendor else ""
|
||||
"""Curated host-to-device matrix from prism.edges (origin='legacy').
|
||||
|
||||
prism.model_requirements is an LLM draft queue (unverified, mixed with support
|
||||
articles and negative rows), so it must not be rendered as the compatibility
|
||||
matrix. The host list mirrors the curated YAML matrix (/api/matrix) so rows
|
||||
with no verified pairs stay visible instead of silently disappearing.
|
||||
"""
|
||||
vendor = str(vendor or "").strip().lower()
|
||||
show_all = vendor in ("", "all")
|
||||
base = D.matrix()
|
||||
base_rows = {r.get("host"): r for r in (base.get("rows") or [])}
|
||||
base_vendor = str(D.cat.get("vendor") or "yealink").lower()
|
||||
where = ""
|
||||
if not show_all:
|
||||
where = " and lower(h.vendor)=lower(%s)" % _sqlq(vendor)
|
||||
rows = _prism_sql(
|
||||
"select coalesce(json_agg(row_to_json(t)),'[]'::json)::text from ("
|
||||
"select m.name as host, m.vendor, a.name as device, r.group_key, "
|
||||
"r.condition, r.max_qty, r.verified "
|
||||
"from prism.model_requirements r "
|
||||
"join prism.models m on m.id=r.model_id "
|
||||
"join prism.models a on a.id=r.requires_model_id "
|
||||
"where 1=1%s order by m.name,a.name) t" % where
|
||||
"select h.name as host, h.vendor, a.name as device, e.max_qty, "
|
||||
"e.condition, e.verified, e.origin "
|
||||
"from prism.edges e "
|
||||
"join prism.models h on h.id=e.host_model_id "
|
||||
"join prism.models a on a.id=e.accessory_model_id "
|
||||
"where e.origin='legacy' and e.relation='compatible' "
|
||||
"and coalesce(h.quality_status,'product')='product' "
|
||||
"and coalesce(a.quality_status,'product')='product'%s "
|
||||
"order by h.name,a.name) t" % where
|
||||
) or []
|
||||
hosts = []
|
||||
by_host = {}
|
||||
for r in rows:
|
||||
h = r.get("host")
|
||||
if h not in by_host:
|
||||
hosts.append(h)
|
||||
by_host[h] = {"host": h, "vendor": r.get("vendor"), "items": []}
|
||||
by_host[h]["items"].append({"device": r.get("device"), "group_key": r.get("group_key"),
|
||||
"condition": r.get("condition"),
|
||||
"max_qty": r.get("max_qty"), "verified": bool(r.get("verified"))})
|
||||
return {"ok": True, "hosts": hosts, "rows": list(by_host.values())}
|
||||
by_host[h]["items"].append({
|
||||
"device": r.get("device"), "group_key": "",
|
||||
"condition": r.get("condition"), "max_qty": r.get("max_qty"),
|
||||
"verified": bool(r.get("verified")), "origin": r.get("origin") or "legacy",
|
||||
})
|
||||
out_rows = []
|
||||
for name, brow in base_rows.items():
|
||||
if not show_all and base_vendor != vendor:
|
||||
continue
|
||||
items = by_host.get(name, {}).get("items", [])
|
||||
cells = {norm(i["device"]): (i["max_qty"] or 1) for i in items}
|
||||
if not items and not rows:
|
||||
# DB unavailable: fall back to the curated YAML cells, still verified.
|
||||
cells = dict(brow.get("cells") or {})
|
||||
out_rows.append({"host": name, "vendor": base_vendor, "items": items,
|
||||
"cells": cells, "ports": brow.get("ports") or {},
|
||||
"verified": bool(cells)})
|
||||
seen = {r["host"] for r in out_rows}
|
||||
for name, hrow in by_host.items():
|
||||
if name in seen:
|
||||
continue
|
||||
cells = {norm(i["device"]): (i["max_qty"] or 1) for i in hrow["items"]}
|
||||
out_rows.append({"host": name, "vendor": hrow.get("vendor"), "items": hrow["items"],
|
||||
"cells": cells, "ports": {}, "verified": True})
|
||||
out_rows.sort(key=lambda r: r["host"])
|
||||
hosts = [r["host"] for r in out_rows]
|
||||
accessories = sorted({i["device"] for r in out_rows for i in r["items"]})
|
||||
cells_total = sum(len(r["cells"]) for r in out_rows)
|
||||
return {"ok": True, "hosts": hosts, "rows": out_rows, "accessories": accessories,
|
||||
"source": "prism.edges origin=legacy (verified) + curated matrix.yaml hosts",
|
||||
"stats": {"hosts": len(hosts), "cells": cells_total,
|
||||
"verified_cells": cells_total, "llm_cells": 0,
|
||||
"junk_hosts": 0}}
|
||||
|
||||
|
||||
def prism_check_db(host, device=""):
|
||||
"""Check one host/device pair against prism.edges (verified first)."""
|
||||
host = str(host or "").strip()
|
||||
device = str(device or "").strip()
|
||||
if not host or not device:
|
||||
return {"ok": False, "error": "host и device обязательны",
|
||||
"supported": False, "usable": False}
|
||||
rows = _prism_sql(
|
||||
"select coalesce(json_agg(row_to_json(t)),'[]'::json)::text from ("
|
||||
"select h.name as host, a.name as device, e.max_qty, e.condition, "
|
||||
"e.verified, e.origin, e.relation "
|
||||
"from prism.edges e "
|
||||
"join prism.models h on h.id=e.host_model_id "
|
||||
"join prism.models a on a.id=e.accessory_model_id "
|
||||
"where lower(h.name)=lower(%s) and lower(a.name)=lower(%s) "
|
||||
"and e.relation='compatible' "
|
||||
"order by case when e.origin='legacy' then 0 else 1 end, e.verified desc "
|
||||
"limit 1) t" % (_sqlq(host), _sqlq(device))
|
||||
) or []
|
||||
if not rows:
|
||||
return {"ok": True, "host": host, "device": device,
|
||||
"supported": False, "usable": False, "verified": False,
|
||||
"verdict": "нет подтверждённой совместимости в БД", "max_qty": None,
|
||||
"condition": ""}
|
||||
r = rows[0]
|
||||
verified = bool(r.get("verified"))
|
||||
return {"ok": True, "host": host, "device": device,
|
||||
"supported": True, "usable": True, "verified": verified,
|
||||
"origin": r.get("origin"), "max_qty": r.get("max_qty"),
|
||||
"condition": r.get("condition") or "",
|
||||
"verdict": "проверено (curated)" if verified else "LLM, требует проверки"}
|
||||
|
||||
|
||||
def prism_group_models(group):
|
||||
@@ -2698,7 +2773,7 @@ class H(BaseHTTPRequestHandler):
|
||||
if not os.path.exists(f):
|
||||
f = os.path.join(os.path.dirname(__file__), "studio.html")
|
||||
return self._out(open(f, encoding="utf-8").read().encode(), ctype="text/html; charset=utf-8")
|
||||
if p == "/studio":
|
||||
if p in ("/studio", "/studio.html"):
|
||||
f = os.path.join(os.path.dirname(__file__), "studio.html")
|
||||
return self._out(open(f, encoding="utf-8").read().encode(), ctype="text/html; charset=utf-8")
|
||||
if p == "/classic":
|
||||
@@ -2731,6 +2806,9 @@ class H(BaseHTTPRequestHandler):
|
||||
return self._out(prism_matrix_db(q.get("vendor", [""])[0]))
|
||||
if p == "/api/prism/check-db":
|
||||
return self._out(prism_check_db(q.get("host", [""])[0], q.get("device", [""])[0]))
|
||||
if p == "/api/prism/vendors":
|
||||
# alias kept for clients that expect the /api/prism/* namespace
|
||||
return self._out(VENDORS)
|
||||
if p == "/api/prism/requirements":
|
||||
return self._out(prism_requirements(q.get("model", [""])[0]))
|
||||
if p == "/api/prism/dashboard":
|
||||
|
||||
+14
-14
@@ -467,6 +467,7 @@ async function renderMatrix() {
|
||||
<select id="mxHost" style="min-width:260px"><option>загрузка…</option></select>
|
||||
<select id="mxDevice" style="min-width:260px"><option>— сначала выбери хост —</option></select>
|
||||
<button class="primary" id="mxCheck">Проверить</button>
|
||||
<span class="hint" id="mxStats"></span>
|
||||
</div>
|
||||
<div id="mxResult" class="muted">Пара ещё не выбрана.</div></div>
|
||||
<div class="card" style="margin-top:14px"><h2>Совместимые устройства</h2><div id="mxOptions" class="muted">Выбери хост.</div></div>`;
|
||||
@@ -479,29 +480,27 @@ async function renderMatrix() {
|
||||
async function loadMatrixHosts(vendor) {
|
||||
const db = await api(`/api/prism/matrix-db?vendor=${encodeURIComponent(vendor)}`);
|
||||
state.matrixDb = db;
|
||||
let hosts = (db.hosts||[]);
|
||||
if (!hosts.length) {
|
||||
const rows = await api(`/api/prism/catalog?vendor=${encodeURIComponent(vendor)}&status=active&limit=500`);
|
||||
const names = new Set((rows||[]).map(x => String(x.name||"").toLowerCase()));
|
||||
hosts = (state.matrix.hosts||[]).filter(h => !vendor || names.has(String(h).toLowerCase()));
|
||||
if (!hosts.length && vendor === "yealink") hosts = (state.matrix.hosts||[]).slice();
|
||||
}
|
||||
const hosts = (db.hosts||[]);
|
||||
const st = db.stats || {};
|
||||
const stats = $("#mxStats");
|
||||
if (stats) stats.textContent = hosts.length ? `${st.hosts||hosts.length} хостов · ${st.cells||0} проверенных пар` : "нет проверенной матрицы для этого вендора";
|
||||
const sel = $("#mxHost");
|
||||
sel.innerHTML = hosts.map(h=>`<option value="${esc(h)}">${esc(h)}</option>`).join("") || '<option value="">нет матрицы для этого вендора</option>';
|
||||
sel.innerHTML = hosts.map(h=>`<option value="${esc(h)}">${esc(h)}</option>`).join("") || '<option value="">нет проверенной матрицы</option>';
|
||||
await loadMatrixOptions();
|
||||
}
|
||||
async function loadMatrixOptions() {
|
||||
const host = $("#mxHost").value;
|
||||
if (!host) return;
|
||||
if (!host) { $("#mxOptions").innerHTML = '<div class="empty">Нет проверенной матрицы для выбранного вендора</div>'; return; }
|
||||
const dev = $("#mxDevice");
|
||||
const dbRow = state.matrixDb && (state.matrixDb.rows||[]).find(r=>r.host===host);
|
||||
if (dbRow) {
|
||||
const items = dbRow.items || [];
|
||||
dev.innerHTML = items.map(x=>`<option value="${esc(x.device)}">${esc(x.device)}${x.max_qty?` · до ${x.max_qty}`:""}</option>`).join("") || '<option value="">нет устройств</option>';
|
||||
$("#mxOptions").innerHTML = items.length ? `<div class="grid3">${items.map(x=>`<div class="dropitem"><span><b>${esc(x.device)}</b> <span class="muted">${x.max_qty?`до ${x.max_qty}`:""}</span></span><span class="tag ${x.verified?'ok':''}">${x.verified?'проверено':'LLM'}</span></div>`).join("")}</div>` : '<div class="empty">Для хоста нет данных</div>';
|
||||
const items = (dbRow && dbRow.items) || [];
|
||||
if (items.length) {
|
||||
dev.innerHTML = items.map(x=>`<option value="${esc(x.device)}">${esc(x.device)}${x.max_qty?` · до ${x.max_qty}`:""}</option>`).join("");
|
||||
$("#mxOptions").innerHTML = `<div class="grid3">${items.map(x=>`<div class="dropitem"><span><b>${esc(x.device)}</b> <span class="muted">${x.max_qty?`до ${x.max_qty}`:""}</span></span><span class="tag ${x.verified?'ok':''}">${x.verified?'проверено':(x.origin==='llm'?'LLM':'не проверено')}</span></div>`).join("")}</div>`;
|
||||
$("#mxResult").textContent = `Выбрано: ${host} · ${dev.value || "—"}`;
|
||||
return;
|
||||
}
|
||||
// No verified pairs in prism.edges: fall back to the legacy graph (/api/options).
|
||||
const opt = await api(`/api/options?host=${encodeURIComponent(host)}`);
|
||||
const groups = opt.groups || [];
|
||||
const all = [];
|
||||
@@ -517,7 +516,8 @@ async function checkMatrixPair() {
|
||||
out.innerHTML = '<span class="muted">проверяю…</span>';
|
||||
try {
|
||||
const dbRow = state.matrixDb && (state.matrixDb.rows||[]).find(r=>r.host===host);
|
||||
const d = dbRow ? await api(`/api/prism/check-db?host=${encodeURIComponent(host)}&device=${encodeURIComponent(device)}`) : await api(`/api/check?host=${encodeURIComponent(host)}&device=${encodeURIComponent(device)}`);
|
||||
const inDb = !!(dbRow && (dbRow.items||[]).some(x=>x.device===device));
|
||||
const d = inDb ? await api(`/api/prism/check-db?host=${encodeURIComponent(host)}&device=${encodeURIComponent(device)}`) : await api(`/api/check?host=${encodeURIComponent(host)}&device=${encodeURIComponent(device)}`);
|
||||
const ok = d.supported && d.usable;
|
||||
out.innerHTML = `<div class="card" style="margin-top:10px;border-color:${ok?'#1f5c43':'#5d2727'}">
|
||||
<h3>${esc(host)} + ${esc(device)}</h3>
|
||||
|
||||
Reference in new issue
Block a user