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

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/README.md CHANGED
@@ -1,6 +1,10 @@
1
- # qqgm-webui(原型 0.1.0)
1
+ # qqgm-webui(0.2.8)
2
2
 
3
- QQGM 附属插件的图形化管理台。**当前是 UI 原型**:数据为 mock,未接真实 API、不写配置、不写记忆库。
3
+ QQGM 附属插件的图形化管理台。
4
+
5
+ - 首页、插件、监控、记忆页已接**真实只读 API**(监控 SQLite、记忆 SQLite、插件扫描);
6
+ - 配置写入、一键安装、完整日志 sink 还没接;
7
+ - 默认只在 `/qqgm` 提供页面,公网访问必须设置 token。
4
8
 
5
9
  ![prototype](./prototype.png)
6
10
 
package/index.js CHANGED
@@ -6,8 +6,11 @@
6
6
  */
7
7
  const fs = require('node:fs');
8
8
  const path = require('node:path');
9
+ const { execFile } = require('node:child_process');
10
+ const { promisify } = require('node:util');
9
11
  const { Schema } = require('koishi');
10
12
  const { pluginList, monitor, memory } = require('./lib/data');
13
+ const run = promisify(execFile);
11
14
 
12
15
  const name = 'qqgm-webui';
13
16
  const inject = ['server'];
@@ -17,6 +20,7 @@ const Config = Schema.object({
17
20
  route: Schema.string().default('/qqgm').description('挂载路径,需以 / 开头。'),
18
21
  token: Schema.string().default('').description('访问令牌;公网必须设置。'),
19
22
  allowRemote: Schema.boolean().default(false).description('是否允许非本机访问。'),
23
+ allowInstall: Schema.boolean().default(true).description('允许一键安装 @nestim 附属插件(npm install)。'),
20
24
  });
21
25
 
22
26
  const TYPES = {
@@ -94,7 +98,7 @@ function apply(ctx, config) {
94
98
  ctx.server.get(`${route}/api/health`, (koa) => json(koa, {
95
99
  ok: true,
96
100
  name,
97
- version: '0.2.7',
101
+ version: '0.2.9',
98
102
  route,
99
103
  tokenRequired: !!config.token,
100
104
  remoteAllowed: !!config.allowRemote,
@@ -128,10 +132,42 @@ function apply(ctx, config) {
128
132
  });
129
133
 
130
134
  // 写操作下一阶段:需要 token + 备份 + schema 校验。
131
- ctx.server.post(`${route}/api/install`, (koa) => json(koa, {
132
- ok: false,
133
- error: 'prototype: install API not enabled',
134
- }, 501));
135
+ ctx.server.post(`${route}/api/install`, async (koa) => {
136
+ if (!guard(koa)) return;
137
+ if (!config.allowInstall) {
138
+ koa.status = 403;
139
+ koa.body = { ok: false, error: 'install disabled' };
140
+ return;
141
+ }
142
+ let body = {};
143
+ try {
144
+ let raw = '';
145
+ for await (const chunk of koa.req) raw += chunk;
146
+ body = raw ? JSON.parse(raw) : {};
147
+ } catch { /* invalid body */ }
148
+ const pkg = String(body.package || '');
149
+ if (!/^@nestim\/koishi-plugin-[a-z0-9-]+$/.test(pkg)) {
150
+ koa.status = 400;
151
+ koa.body = { ok: false, error: 'only @nestim/koishi-plugin-* packages are allowed' };
152
+ return;
153
+ }
154
+ try {
155
+ const result = await run('npm', ['install', pkg, '--no-audit', '--no-fund'], {
156
+ cwd: ctx.baseDir || process.cwd(),
157
+ timeout: 120_000,
158
+ windowsHide: true,
159
+ });
160
+ koa.body = {
161
+ ok: true,
162
+ package: pkg,
163
+ restartRequired: true,
164
+ output: String(result.stdout || '').slice(-2000),
165
+ };
166
+ } catch (error) {
167
+ koa.status = 500;
168
+ koa.body = { ok: false, error: String(error && error.message || error) };
169
+ }
170
+ });
135
171
 
136
172
  logger.info(`WebUI 已挂载:${route}(token=${config.token ? '已设置' : '未设置'})`);
137
173
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestim/koishi-plugin-qqgm-webui",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "QQGM 附属 WebUI:插件识别、监控看板、记忆库、配置与日志。",
5
5
  "main": "index.js",
6
6
  "files": [
package/public/app.js CHANGED
@@ -139,6 +139,24 @@ async function initMemoryData() {
139
139
  }
140
140
  initMemoryData();
141
141
 
142
+ async function installPackage(pkg) {
143
+ const token = new URLSearchParams(location.search).get('token') || '';
144
+ showToast(`正在安装 ${pkg}…`);
145
+ try {
146
+ const res = await fetch(`api/install${token ? `?token=${encodeURIComponent(token)}` : ''}`, {
147
+ method: 'POST',
148
+ headers: { 'content-type': 'application/json' },
149
+ body: JSON.stringify({ package: pkg }),
150
+ });
151
+ const data = await res.json();
152
+ if (!res.ok || !data.ok) throw new Error(data.error || `HTTP ${res.status}`);
153
+ showToast('安装完成,重启/重载插件后生效');
154
+ } catch (error) {
155
+ showToast(`安装失败:${String(error.message || error)}`);
156
+ }
157
+ }
158
+ $('#installMonitor')?.addEventListener('click', () => installPackage('@nestim/koishi-plugin-qqgm-monitor'));
159
+
142
160
  // memory backend note
143
161
  const memoryNote = $('#memoryBackend');
144
162
  if (memoryNote) {
package/public/index.html CHANGED
@@ -80,7 +80,7 @@
80
80
  <div id="overview-monitor">
81
81
  <div class="page-head">
82
82
  <div>
83
- <h1>总览 <span class="proto-tag">原型</span></h1>
83
+ <h1>总览 <span class="proto-tag">只读</span></h1>
84
84
  <p>今天 12-02 · 数据来自 qqgm-monitor SQLite</p>
85
85
  </div>
86
86
  <div class="head-actions">
@@ -191,7 +191,7 @@
191
191
  <h1>欢迎使用 QQGM</h1>
192
192
  <p>主插件已经连上了,但还没有安装监控插件。<br />首页暂时只能看到基础状态;装好监控后,这里会自动变成运行总览。</p>
193
193
  <div class="welcome-actions">
194
- <button class="btn primary" data-toast="一键安装(原型):正式版会调用安装接口">一键安装监控</button>
194
+ <button class="btn primary" id="installMonitor">一键安装监控</button>
195
195
  <a class="btn ghost" href="https://github.com/Miseat/koishi-plugin-qqgm-monitor" target="_blank" rel="noreferrer">GitHub</a>
196
196
  <a class="btn ghost" href="https://www.npmjs.com/package/@nestim/koishi-plugin-qqgm-monitor" target="_blank" rel="noreferrer">npm</a>
197
197
  <button class="link-btn" id="demoMonitor">预览:已装监控 →</button>
@@ -468,8 +468,7 @@
468
468
  <button class="config-plugin" data-config="chat"><span class="plugin-ico orange">S</span><div><b>qqgm-chat-style</b><small>聊天风格 · 已安装</small></div></button>
469
469
  <button class="config-plugin" data-config="private"><span class="plugin-ico purple">P</span><div><b>qqgm-private</b><small>私聊 · 已安装</small></div></button>
470
470
  <button class="config-plugin" data-config="webui"><span class="plugin-ico slate">W</span><div><b>qqgm-webui</b><small>本插件 · 已安装</small></div></button>
471
- <div class="config-group-label">未安装</div>
472
- <button class="config-plugin" data-config="memory"><span class="plugin-ico muted">R</span><div><b>qqgm-memory</b><small>记忆管理 · 未安装</small></div><span class="mini-badge">未安装</span></button>
471
+ <button class="config-plugin" data-config="memory"><span class="plugin-ico muted">R</span><div><b>qqgm-memory</b><small>记忆管理 · 已安装</small></div></button>
473
472
  </aside>
474
473
 
475
474
  <div class="card config-form">
@@ -531,18 +530,16 @@
531
530
  </div>
532
531
 
533
532
  <div class="side-panel" data-panel="memory">
534
- <div class="empty-install">
535
- <div class="empty-icon">+</div>
536
- <h2>未安装插件</h2>
537
- <p><b>qqgm-memory</b> 还没有安装。<br />安装后可以在这里管理记忆库、切换 SQLite、迁移 MD 数据。</p>
538
- <div class="install-actions">
539
- <button class="btn primary" data-toast="一键安装(原型):正式版会调用安装接口">一键安装</button>
540
- <a class="btn ghost" href="https://github.com/Miseat/koishi-plugin-qqgm-memory" target="_blank" rel="noreferrer">GitHub</a>
541
- <a class="btn ghost" href="https://www.npmjs.com/package/@nestim/koishi-plugin-qqgm-memory" target="_blank" rel="noreferrer">npm</a>
542
- </div>
543
- <code class="install-code">npm i @nestim/koishi-plugin-qqgm-memory</code>
544
- <p class="hint">主插件不用改;记忆库默认仍是 MD,装完后可自行切换。</p>
533
+ <div class="form-head"><div><h2>qqgm-memory</h2><p>@nestim/koishi-plugin-qqgm-memory · v1.0.0</p></div><span class="status ok">运行中</span></div>
534
+ <div class="form-section"><h3>数据库</h3>
535
+ <label class="field"><span>SQLite 文件</span><input value="data/qqgm-memory.sqlite" /></label>
536
+ <label class="field"><span>主插件记忆后端</span><input value="md(默认)" disabled /></label>
537
+ <p class="hint">主插件当前是 MD。把主插件 <code>memoryBackend</code> 改为 <code>sqlite</code> 后,本插件才接管数据;迁移前先备份 MD。</p>
545
538
  </div>
539
+ <div class="form-section"><h3>迁移</h3>
540
+ <p class="hint">切到 SQLite 后执行 <code>memdb migrate</code> 导入 Memory_*.md;改回 md 可回滚。当前库 0 条。</p>
541
+ </div>
542
+ <div class="form-foot"><span>和主插件共用同一个 DB 文件</span><div><button class="btn ghost" data-toast="已还原(原型)">还原</button><button class="btn primary" data-toast="记忆配置已保存(原型)">保存</button></div></div>
546
543
  </div>
547
544
  </div>
548
545
  </div>
@@ -568,7 +565,7 @@
568
565
  <span><i class="pulse"></i> 127.0.0.1:5140/qqgm</span>
569
566
  <span>SQLite · WAL</span>
570
567
  <span>21 calls today</span>
571
- <span class="right">Prototype · mock data</span>
568
+ <span class="right">只读数据 · SQLite</span>
572
569
  </footer>
573
570
  </main>
574
571
  </div>