@nestim/koishi-plugin-qqgm-webui 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -94,7 +94,7 @@ function apply(ctx, config) {
94
94
  ctx.server.get(`${route}/api/health`, (koa) => json(koa, {
95
95
  ok: true,
96
96
  name,
97
- version: '0.2.6',
97
+ version: '0.2.7',
98
98
  route,
99
99
  tokenRequired: !!config.token,
100
100
  remoteAllowed: !!config.allowRemote,
package/lib/data.js CHANGED
@@ -86,6 +86,8 @@ function monitor(ctx) {
86
86
  SELECT COUNT(*) calls,
87
87
  COALESCE(SUM(CASE WHEN status='ok' THEN 1 ELSE 0 END),0) ok,
88
88
  COALESCE(SUM(CASE WHEN status!='ok' THEN 1 ELSE 0 END),0) fail,
89
+ COALESCE(SUM(CASE WHEN error_kind='timeout' THEN 1 ELSE 0 END),0) timeout,
90
+ COALESCE(SUM(CASE WHEN error_kind='empty' THEN 1 ELSE 0 END),0) parse_fail,
89
91
  COALESCE(SUM(prompt_tokens),0) prompt,
90
92
  COALESCE(SUM(completion_tokens),0) completion,
91
93
  COALESCE(SUM(cache_tokens),0) cache,
@@ -119,10 +121,16 @@ function monitor(ctx) {
119
121
  const renders = messages.map((m) => Number(m.rendered_ms) || 0);
120
122
  const sends = messages.map((m) => Number(m.send_ms) || 0);
121
123
  const latestBalance = db.prepare('SELECT currency,total,at FROM balance_snapshots ORDER BY at DESC LIMIT 1').get();
124
+ const recent = db.prepare(`
125
+ SELECT trace_id, kind, group_id, model, prompt_tokens, completion_tokens,
126
+ model_ms, status, error_kind, started_at
127
+ FROM calls ORDER BY started_at DESC LIMIT 8
128
+ `).all();
122
129
  return {
123
130
  installed: true,
124
131
  calls,
125
132
  groups,
133
+ recent,
126
134
  replyMessages: messages.length,
127
135
  latency: { e2e: p3(e2e), model: p3(models), queue: p3(queues), render: p3(renders), send: p3(sends) },
128
136
  balance: latestBalance ? { currency: latestBalance.currency, total: latestBalance.total, at: latestBalance.at } : null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestim/koishi-plugin-qqgm-webui",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "QQGM 附属 WebUI:插件识别、监控看板、记忆库、配置与日志。",
5
5
  "main": "index.js",
6
6
  "files": [
package/public/app.js CHANGED
@@ -88,6 +88,24 @@ async function initRealData() {
88
88
  cards[2].innerHTML = `${(data.monitor.latency.e2e.p95 / 1000).toFixed(1)}<small>s</small>`;
89
89
  }
90
90
  if (cards[3] && data.monitor.balance) cards[3].textContent = `¥${Number(data.monitor.balance.total || 0).toFixed(2)}`;
91
+ const foots = $$('#overview-monitor .metric-foot');
92
+ if (foots[0]) foots[0].textContent = `成功 ${calls.ok || 0} · 失败 ${calls.fail || 0}`;
93
+ if (foots[1] && calls.calls) {
94
+ foots[1].textContent = `失败率 ${((calls.fail || 0) / calls.calls * 100).toFixed(1)}% · 解析 ${calls.parse_fail || 0} · 超时 ${calls.timeout || 0}`;
95
+ }
96
+ const body = $('#recentCallsBody');
97
+ if (body && Array.isArray(data.monitor.recent)) {
98
+ const esc = (value) => String(value == null ? '' : value).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
99
+ body.innerHTML = data.monitor.recent.map((call) => {
100
+ const source = call.kind === 'private' ? '私聊' : call.kind === 'memory' ? '记忆' : call.kind === 'idle' ? '主动话题' : `群 ${call.group_id || '-'}`;
101
+ const token = `${((Number(call.prompt_tokens) || 0) + (Number(call.completion_tokens) || 0)) / 1000}`;
102
+ const time = new Date(call.started_at).toLocaleTimeString('zh-CN', { hour12: false });
103
+ const status = call.status === 'ok'
104
+ ? '<span class="status ok">成功</span>'
105
+ : `<span class="status fail">${esc(call.error_kind || '失败')}</span>`;
106
+ return `<tr><td>${time}</td><td><span class="tag ${call.kind === 'private' ? 'private' : call.kind === 'memory' ? 'memory' : 'group'}">${esc(source)}</span></td><td>${esc(call.model || '-')}</td><td>${token}k</td><td>${((Number(call.model_ms) || 0) / 1000).toFixed(1)}s</td><td>${status}</td></tr>`;
107
+ }).join('');
108
+ }
91
109
  } catch { /* 文件预览或未登录时保留 mock */ }
92
110
  }
93
111
  initRealData();
package/public/index.html CHANGED
@@ -161,7 +161,7 @@
161
161
  </div>
162
162
  <table class="table">
163
163
  <thead><tr><th>时间</th><th>来源</th><th>模型</th><th>Token</th><th>耗时</th><th>状态</th></tr></thead>
164
- <tbody>
164
+ <tbody id="recentCallsBody">
165
165
  <tr><td>19:02:41</td><td><span class="tag group">群 1103369527</span></td><td>deepseek-chat</td><td>2.4k</td><td>3.0s</td><td><span class="status ok">成功</span></td></tr>
166
166
  <tr><td>19:01:58</td><td><span class="tag group">群 1103369527</span></td><td>deepseek-chat</td><td>3.1k</td><td>8.8s</td><td><span class="status ok">成功</span></td></tr>
167
167
  <tr><td>18:58:12</td><td><span class="tag private">私聊</span></td><td>deepseek-chat</td><td>1.2k</td><td>9.9s</td><td><span class="status fail">解析失败</span></td></tr>