@nestim/koishi-plugin-qqgm-webui 0.2.19 → 0.2.21

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
@@ -115,7 +115,7 @@ function apply(ctx, config) {
115
115
  ctx.server.get(`${route}/api/health`, (koa) => json(koa, {
116
116
  ok: true,
117
117
  name,
118
- version: '0.2.19',
118
+ version: '0.2.21',
119
119
  route,
120
120
  tokenRequired: !!config.token,
121
121
  remoteAllowed: !!config.allowRemote,
@@ -17,6 +17,13 @@ function loadMainPlugin() {
17
17
  }
18
18
  }
19
19
 
20
+ function humanLabel(key, description) {
21
+ const text = String(description || '').replace(/\s+/g, ' ').trim();
22
+ const first = text.split(/[::((]/)[0].trim();
23
+ if (first && first.length >= 2 && first.length <= 28) return first;
24
+ return key;
25
+ }
26
+
20
27
  function fieldInfo(key, field) {
21
28
  const meta = field.meta || {};
22
29
  const type = String(field.type || 'string');
@@ -24,14 +31,22 @@ function fieldInfo(key, field) {
24
31
  if (type === 'union') {
25
32
  for (const match of String(field).matchAll(/"([^"]+)"/g)) options.push(match[1]);
26
33
  }
34
+ const description = meta.description || '';
35
+ const defaultValue = meta.default;
36
+ const long = type === 'string' && (
37
+ /prompt|system|persona|template|greeting|welcome|instruction|rule/i.test(key)
38
+ || (typeof defaultValue === 'string' && defaultValue.length > 60)
39
+ );
27
40
  return {
28
41
  key,
42
+ label: humanLabel(key, description),
29
43
  type,
30
- description: meta.description || '',
31
- default: meta.default,
44
+ description,
45
+ default: defaultValue,
32
46
  options,
33
47
  sensitive: /key|token|secret|password/i.test(key),
34
48
  json: type === 'array' || type === 'object' || type === 'intersect',
49
+ long,
35
50
  };
36
51
  }
37
52
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestim/koishi-plugin-qqgm-webui",
3
- "version": "0.2.19",
3
+ "version": "0.2.21",
4
4
  "description": "QQGM 附属 WebUI:插件识别、监控看板、记忆库、配置与日志。",
5
5
  "main": "index.js",
6
6
  "files": [
package/public/app.js CHANGED
@@ -37,7 +37,11 @@ function go(page) {
37
37
  }
38
38
 
39
39
  $$('.nav-item').forEach((item) => item.addEventListener('click', () => go(item.dataset.page)));
40
- $$('.nav-sub').forEach((item) => item.addEventListener('click', () => go(item.dataset.page)));
40
+ $$('.nav-sub').forEach((item) => item.addEventListener('click', () => {
41
+ const page = item.dataset.page;
42
+ go(page);
43
+ if (page === 'main-schema' && mainSchema) openMainGroup(activeMainGroup || 0);
44
+ }));
41
45
  $$('[data-nav]').forEach((item) => item.addEventListener('click', (event) => {
42
46
  event.preventDefault();
43
47
  go(item.dataset.nav);
@@ -330,8 +334,6 @@ function tokenQuery() {
330
334
  }
331
335
 
332
336
  function openMainGroup(index) {
333
- if (!mainSchema || !mainSchema.groups[index]) return;
334
- go('main-schema');
335
337
  renderMainGroup(index);
336
338
  }
337
339
 
@@ -341,33 +343,44 @@ function renderMainGroup(index) {
341
343
  const group = mainSchema.groups[index];
342
344
  const form = $('#mainSchemaForm');
343
345
  if (!form) return;
344
- const title = $('#mainSchemaTitle');
345
- const subtitle = $('#mainSchemaSubtitle');
346
- if (title) title.textContent = group.title;
347
- if (subtitle) subtitle.textContent = `主插件 · ${group.fields.length} 项 · 来自 Schema`;
348
- $('#pageTitle').textContent = group.title;
349
- $$('#mainSchemaSubnav .nav-sub').forEach((btn, i) => btn.classList.toggle('active', i === index));
346
+ $$('#mainSchemaNav .config-plugin').forEach((btn, i) => btn.classList.toggle('active', i === index));
350
347
  form.innerHTML = `<div class="form-head"><div><h2>${group.title}</h2><p>${group.fields.length} 个字段 · 与 Koishi 配置页同源</p></div><span class="status ok">运行中</span></div>`
351
348
  + group.fields.map((field) => {
352
349
  const value = mainSchema.values[field.key] ?? field.default;
350
+ const esc = (text) => String(text == null ? '' : text).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
353
351
  let control = '';
354
352
  if (field.type === 'boolean') {
355
- control = `<input type="checkbox" data-key="${field.key}" data-kind="boolean" ${value ? 'checked' : ''} />`;
353
+ control = `<label class="switch"><input type="checkbox" data-key="${field.key}" data-kind="boolean" ${value ? 'checked' : ''} /><i></i><span>${value ? '已开启' : '已关闭'}</span></label>`;
356
354
  } else if (field.type === 'union') {
357
355
  const options = (field.options.length ? field.options : [String(value || '')]).map((opt) => `<option ${String(value) === opt ? 'selected' : ''}>${opt}</option>`).join('');
358
356
  control = `<select data-key="${field.key}" data-kind="string">${options}</select>`;
359
357
  } else if (field.type === 'number') {
360
358
  control = `<input type="number" data-key="${field.key}" data-kind="number" value="${value ?? field.default ?? 0}" />`;
361
359
  } else if (field.json) {
362
- control = `<textarea rows="4" data-key="${field.key}" data-kind="json">${JSON.stringify(value ?? field.default ?? (field.type === 'array' ? [] : {}), null, 2)}</textarea>`;
360
+ control = `<textarea rows="5" class="json-input" data-key="${field.key}" data-kind="json">${esc(JSON.stringify(value ?? field.default ?? (field.type === 'array' ? [] : {}), null, 2))}</textarea>`;
361
+ } else if (field.long) {
362
+ control = `<textarea rows="7" data-key="${field.key}" data-kind="string">${esc(value ?? field.default ?? '')}</textarea>`;
363
363
  } else {
364
- control = `<input ${field.sensitive ? 'type="password"' : ''} data-key="${field.key}" data-kind="string" value="${String(value ?? field.default ?? '').replace(/"/g, '&quot;')}" />`;
364
+ control = `<input ${field.sensitive ? 'type="password"' : ''} data-key="${field.key}" data-kind="string" value="${esc(value ?? field.default ?? '')}" />`;
365
365
  }
366
- return `<div class="schema-field"><label class="field"><span>${field.key}</span>${control}</label><p class="form-hint">${field.description || ''}</p></div>`;
366
+ return `<div class="schema-field ${field.long ? 'long' : ''}">
367
+ <div class="schema-field-info">
368
+ <div class="schema-field-title">${esc(field.label || field.key)}</div>
369
+ <p class="schema-field-desc">${esc(field.description || '')}</p>
370
+ <code class="schema-field-key">${field.key}</code>
371
+ </div>
372
+ <div class="schema-field-control">${control}</div>
373
+ </div>`;
367
374
  }).join('')
368
375
  + `<div class="form-foot"><span>保存只改本组字段;写前备份 koishi.yml,重启后生效</span></div>`;
369
376
  const save = $('#saveMainSchemaGroup');
370
377
  if (save) save.onclick = () => saveMainGroup(group);
378
+ $$('#mainSchemaForm .switch input').forEach((input) => {
379
+ input.addEventListener('change', () => {
380
+ const text = input.parentElement?.querySelector('span');
381
+ if (text) text.textContent = input.checked ? '已开启' : '已关闭';
382
+ });
383
+ });
371
384
  }
372
385
 
373
386
  async function saveMainGroup(group) {
@@ -405,10 +418,11 @@ async function initMainSchema() {
405
418
  $('#mainSchemaForm').innerHTML = '<div class="schema-loading">未找到主插件 Config Schema</div>';
406
419
  return;
407
420
  }
408
- const subnav = $('#mainSchemaSubnav');
409
- if (subnav) {
410
- subnav.innerHTML = mainSchema.groups.map((group, index) => `<button class="nav-sub" data-main-group="${index}">${group.title}<span class="sub-count">${group.fields.length}</span></button>`).join('');
411
- $$('#mainSchemaSubnav .nav-sub').forEach((btn) => btn.addEventListener('click', () => openMainGroup(Number(btn.dataset.mainGroup))));
421
+ const nav = $('#mainSchemaNav');
422
+ if (nav) {
423
+ nav.innerHTML = '<div class="config-group-label">配置分组</div>'
424
+ + mainSchema.groups.map((group, index) => `<button class="config-plugin ${index === 0 ? 'active' : ''}" data-main-group="${index}"><span class="plugin-ico slate">${index + 1}</span><div><b>${group.title}</b><small>${group.fields.length} 项</small></div></button>`).join('');
425
+ $$('#mainSchemaNav .config-plugin').forEach((btn) => btn.addEventListener('click', () => openMainGroup(Number(btn.dataset.mainGroup))));
412
426
  }
413
427
  const params = new URLSearchParams(location.search);
414
428
  const groupParam = Number(params.get('group'));
package/public/index.html CHANGED
@@ -37,7 +37,7 @@
37
37
  <span class="nav-badge">128</span>
38
38
  </button>
39
39
  <div class="nav-section">主插件</div>
40
- <div class="main-schema-subnav" id="mainSchemaSubnav"></div>
40
+ <button class="nav-sub" data-page="main-schema">主插件配置</button>
41
41
  <button class="nav-item" data-page="config">
42
42
  <svg viewBox="0 0 24 24"><path d="M12 15.5A3.5 3.5 0 1 0 12 8.5a3.5 3.5 0 0 0 0 7Zm8-3.5c0-.6-.06-1.16-.18-1.7l2.02-1.58-2-3.46-2.38.96a8.2 8.2 0 0 0-2.94-1.7L14.2 2h-4.4l-.32 2.52a8.2 8.2 0 0 0-2.94 1.7L4.16 5.26l-2 3.46 2.02 1.58A8.6 8.6 0 0 0 4 12c0 .6.06 1.16.18 1.7l-2.02 1.58 2 3.46 2.38-.96a8.2 8.2 0 0 0 2.94 1.7L9.8 22h4.4l.32-2.52a8.2 8.2 0 0 0 2.94-1.7l2.38.96 2-3.46-2.02-1.58c.12-.54.18-1.1.18-1.7Z"/></svg>
43
43
  <span>附属配置</span>
@@ -350,8 +350,11 @@
350
350
  </section>
351
351
 
352
352
  <section class="page" id="page-main-schema">
353
- <div class="page-head"><div><h1 id="mainSchemaTitle">主插件配置</h1><p id="mainSchemaSubtitle">按主插件 Schema 分组,每组独立页面</p></div><button class="btn primary" id="saveMainSchemaGroup">保存本组</button></div>
354
- <div class="card config-form" id="mainSchemaForm"><div class="schema-loading">读取 Schema…</div></div>
353
+ <div class="page-head"><div><h1>主插件配置</h1><p>按主插件 Schema 分组,左侧选组、右侧配置;和附属配置同一套布局</p></div><button class="btn primary" id="saveMainSchemaGroup">保存本组</button></div>
354
+ <div class="config-layout">
355
+ <aside class="card config-nav" id="mainSchemaNav"><div class="schema-loading">读取 Schema…</div></aside>
356
+ <div class="card config-form" id="mainSchemaForm"><div class="schema-loading">读取配置…</div></div>
357
+ </div>
355
358
  </section>
356
359
 
357
360
  <section class="page" id="page-config">
package/public/styles.css CHANGED
@@ -304,7 +304,25 @@ code { background: #f2f5f9; color: #55657d; border-radius: 4px; padding: 1px 4px
304
304
  .word-list { display: flex; flex-wrap: wrap; gap: 7px; }
305
305
  .word-list span { display: inline-flex; align-items: center; gap: 5px; background: #f3f6fb; border: 1px solid #e6ecf5; color: #53647b; border-radius: 6px; padding: 5px 8px; font-size: 10.5px; }
306
306
  .word-list button { color: #a6b2c2; font-size: 12px; line-height: 1; }
307
- .schema-field { padding: 11px 0; border-bottom: 1px solid #f1f4f8; }
307
+ .schema-field { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 28px; align-items: start; padding: 18px 2px; border-bottom: 1px solid #f1f4f8; }
308
+ .schema-field.long { grid-template-columns: 1fr; gap: 10px; }
309
+ .schema-field-info { min-width: 0; }
310
+ .schema-field-title { font-size: 12.5px; font-weight: 650; color: #2f4058; margin-bottom: 5px; }
311
+ .schema-field-desc { margin: 0 0 7px; font-size: 10.5px; color: #8a98ab; line-height: 1.6; }
312
+ .schema-field-key { display: inline-block; font-size: 9px; color: #a0adbe; background: #f5f7fa; border: 1px solid #eef2f7; border-radius: 4px; padding: 2px 5px; }
313
+ .schema-field-control { min-width: 0; padding-top: 1px; }
314
+ .schema-field-control > input:not([type=checkbox]), .schema-field-control > select, .schema-field-control > textarea { width: 100%; }
315
+ .schema-field-control > input:not([type=checkbox]), .schema-field-control > select { height: 36px; border: 1px solid #e2e8f1; border-radius: 8px; background: #fbfcfe; padding: 0 10px; font-size: 12px; color: #3b4b61; outline: none; }
316
+ .schema-field-control > textarea { border: 1px solid #e2e8f1; border-radius: 8px; background: #fbfcfe; padding: 9px 10px; font-size: 12px; color: #3b4b61; outline: none; resize: vertical; line-height: 1.65; font-family: inherit; }
317
+ .schema-field-control > textarea:focus, .schema-field-control > input:focus, .schema-field-control > select:focus { border-color: #9ab7ef; background: #fff; }
318
+ .schema-field .json-input { font-family: Consolas, monospace; font-size: 10.5px; }
319
+ .switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; }
320
+ .switch input { display: none; }
321
+ .switch i { width: 34px; height: 19px; border-radius: 20px; background: #dfe5ee; position: relative; transition: .15s; }
322
+ .switch i::after { content: ""; position: absolute; width: 15px; height: 15px; border-radius: 50%; background: #fff; left: 2px; top: 2px; box-shadow: 0 1px 3px rgba(20,35,55,.2); transition: .15s; }
323
+ .switch input:checked + i { background: #4f7df3; }
324
+ .switch input:checked + i::after { transform: translateX(15px); }
325
+ .switch span { font-size: 10.5px; color: #9aa7b8; }
308
326
  .schema-field .field > span { flex: 0 0 200px; font-family: Consolas, monospace; font-size: 10.5px; color: #3f5270; }
309
327
  .schema-field .field input:not([type=checkbox]), .schema-field .field select, .schema-field .field textarea { width: 100%; }
310
328
  .form-hint { margin: 5px 0 0 200px; font-size: 9.5px; color: #9aa7b8; line-height: 1.5; }