dsh-qqbot-muu 0.1.15 → 0.1.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.
Files changed (171) hide show
  1. package/CHANGELOG.md +168 -85
  2. package/client/qqbot-settings.js +13401 -12024
  3. package/config/modules.json +212 -0
  4. package/dist/channel-tools.js +21 -10
  5. package/dist/config.d.ts +14 -0
  6. package/dist/config.js +573 -449
  7. package/dist/features/contextless-store.js +247 -247
  8. package/dist/features/contextless-trim.js +455 -34
  9. package/dist/features/four-source.js +338 -336
  10. package/dist/features/group-join-request.js +289 -287
  11. package/dist/features/local-models.js +1494 -0
  12. package/dist/features/rotate-summarizer.js +438 -0
  13. package/dist/features/scenario-detect.js +321 -0
  14. package/dist/features/scheduler.js +8 -1
  15. package/dist/features/session-rotate.js +499 -0
  16. package/dist/features/session-title.js +199 -0
  17. package/dist/features/style-layer.js +501 -0
  18. package/dist/features/thinking-log.js +71 -69
  19. package/dist/gateway/bootstrap.js +1704 -1388
  20. package/dist/gateway/data-root.js +77 -3
  21. package/dist/gateway/middleware-setup.js +6 -3
  22. package/dist/index.js +4 -2
  23. package/dist/model/settings-reader.js +193 -102
  24. package/dist/session/session-manager.js +1730 -1587
  25. package/dist/shared/paths.js +128 -0
  26. package/dist/shared/settings-io.js +79 -0
  27. package/dist/transport/inbound.js +20 -1
  28. package/dist/transport/outbound.js +56 -4
  29. package/docs/RELEASE_CHECKLIST.md +24 -2
  30. package/dshqqbot/.qqbot-extensions/hooks/interview-panel.mjs +41 -1
  31. package/dshqqbot/.qqbot-extensions/inbound/00-vision.mjs +111 -0
  32. package/dshqqbot/.qqbot-extensions/inbound/aa-memory-recall.mjs +802 -689
  33. package/dshqqbot/.qqbot-extensions/inbound/ac-image-see.mjs +1 -1
  34. package/dshqqbot/.qqbot-extensions/inbound/az-feedback.mjs +113 -115
  35. package/dshqqbot/.qqbot-extensions/inbound/local-answer.mjs +689 -568
  36. package/dshqqbot/.qqbot-extensions/lib/.pet-form.json +1 -1
  37. package/dshqqbot/.qqbot-extensions/lib/draw-core.mjs +238 -7
  38. package/dshqqbot/.qqbot-extensions/lib/local-llm.mjs +455 -394
  39. package/dshqqbot/.qqbot-extensions/lib/memory-agent.mjs +930 -928
  40. package/dshqqbot/.qqbot-extensions/lib/memory-core.mjs +537 -537
  41. package/dshqqbot/.qqbot-extensions/lib/memory-db.mjs +2476 -2245
  42. package/dshqqbot/.qqbot-extensions/lib/memory-hippo.mjs +18 -0
  43. package/dshqqbot/.qqbot-extensions/lib/memory.mjs +191 -186
  44. package/dshqqbot/.qqbot-extensions/lib/plugin-dir.mjs +14 -4
  45. package/dshqqbot/.qqbot-extensions/lib/scope-util.mjs +84 -0
  46. package/dshqqbot/.qqbot-extensions/lib/vision.mjs +1 -1
  47. package/dshqqbot/.qqbot-extensions/outbound/aa-sanitize.mjs +158 -154
  48. package/dshqqbot/.qqbot-extensions/outbound/ac-media-fix.mjs +5 -1
  49. package/dshqqbot/.qqbot-extensions/outbound/memory-agent.mjs +121 -130
  50. package/dshqqbot/.qqbot-extensions/outbound/split-reply.mjs +18 -2
  51. package/dshqqbot/.qqbot-extensions/outbound/turn-memory.mjs +92 -101
  52. package/dshqqbot/.qqbot-extensions/tools/draw.mjs +22 -1
  53. package/dshqqbot/.qqbot-extensions/tools/memory.mjs +178 -120
  54. package/dshqqbot/.qqbot-extensions/tools/pet_card.mjs +3 -2
  55. package/dshqqbot/.qqbot-extensions/tools/storyboard.mjs +3 -1
  56. package/dshqqbot/.qqbot-extensions/vendor/abogus/test-abogus.mjs +128 -126
  57. package/package.json +119 -111
  58. package/scripts/__pycache__/fan-mode.cpython-311.pyc +0 -0
  59. package/scripts/__pycache__/memory-audit.cpython-311.pyc +0 -0
  60. package/scripts/__pycache__/qq-ip-sync.cpython-311.pyc +0 -0
  61. package/scripts/__pycache__/qq-whitelist.cpython-311.pyc +0 -0
  62. package/scripts/_add_maintenance_cfg.py +20 -0
  63. package/scripts/_bench_keeplease.sh +10 -0
  64. package/scripts/_dbg_purge.py +15 -0
  65. package/scripts/_elev.sh +6 -0
  66. package/scripts/_fix_all_admin.cmd +16 -0
  67. package/scripts/_livecheck-image.mjs +33 -0
  68. package/scripts/_livecheck-llm.mjs +34 -0
  69. package/scripts/_livecheck-tts.mjs +37 -0
  70. package/scripts/_patch_curve.py +88 -0
  71. package/scripts/_patch_fan_thermal.py +24 -0
  72. package/scripts/_tag_tmp.py +13 -0
  73. package/scripts/adb-broker-client.mjs +87 -0
  74. package/scripts/adb-broker.mjs +205 -0
  75. package/scripts/ai-mode.cmd +6 -0
  76. package/scripts/ai-mode.py +387 -0
  77. package/scripts/ai-toolkit.py +607 -0
  78. package/scripts/apply-fan-gpu45.py +51 -0
  79. package/scripts/bench-fans.py +515 -0
  80. package/scripts/bench-load-direct.py +63 -0
  81. package/scripts/boot-tasks-hidden.vbs +20 -0
  82. package/scripts/boot-tasks.cmd +277 -0
  83. package/scripts/chat-archive/__pycache__/build-sft-v4.cpython-311.pyc +0 -0
  84. package/scripts/chat-archive/__pycache__/build-sft.cpython-311.pyc +0 -0
  85. package/scripts/chat-archive/build-sft-v4.py +566 -0
  86. package/scripts/chat-archive/build-sft.py +390 -0
  87. package/scripts/chat-archive/eval-sft.py +155 -0
  88. package/scripts/chat-archive/extract-memory.py +143 -0
  89. package/scripts/chat-archive/inventory.py +182 -0
  90. package/scripts/chat-archive/merge-sft.py +114 -0
  91. package/scripts/chat-archive/qce-pull.py +217 -0
  92. package/scripts/chat-archive/qqheader.py +110 -0
  93. package/scripts/chat-archive/qqkey2.py +113 -0
  94. package/scripts/chat-archive/qqprobe.py +153 -0
  95. package/scripts/chat-archive/screen-collect.py +163 -0
  96. package/scripts/chat-archive/sqlcipher_probe.py +444 -0
  97. package/scripts/comfy_gen.py +209 -0
  98. package/scripts/compose-video.py +168 -0
  99. package/scripts/dl_models.py +45 -0
  100. package/scripts/draw-now.cmd +18 -0
  101. package/scripts/dsh-instance-guard.mjs +20 -2
  102. package/scripts/elev-extra.cmd +25 -0
  103. package/scripts/episode.py +529 -0
  104. package/scripts/fan-curve.py +218 -0
  105. package/scripts/fan-guard.cmd +8 -0
  106. package/scripts/fan-mode.py +380 -0
  107. package/scripts/fan_manual_safe.py +33 -0
  108. package/scripts/fan_restore_manual.py +46 -0
  109. package/scripts/fc_curves.py +359 -0
  110. package/scripts/fix-fan-and-timers.cmd +39 -0
  111. package/scripts/fix_admin_all.py +94 -0
  112. package/scripts/flows.mjs +224 -0
  113. package/scripts/gateway.cmd +126 -0
  114. package/scripts/gen-image.py +420 -0
  115. package/scripts/gen-video.py +186 -0
  116. package/scripts/git-askpass.cmd +2 -2
  117. package/scripts/gpu-mode.py +195 -0
  118. package/scripts/hw-profile.py +175 -0
  119. package/scripts/install-schedule.cmd +37 -0
  120. package/scripts/install-watch.cmd +29 -0
  121. package/scripts/matte-cutout.py +106 -0
  122. package/scripts/media-enhance.py +402 -0
  123. package/scripts/memory-audit.py +581 -0
  124. package/scripts/migrate-scope.mjs +140 -139
  125. package/scripts/model-registry.py +519 -0
  126. package/scripts/openid-audit.mjs +219 -0
  127. package/scripts/pull-gguf.py +127 -0
  128. package/scripts/purge-standby.py +151 -0
  129. package/scripts/qq-connect-login.py +133 -0
  130. package/scripts/qq-ip-sync-hidden.vbs +5 -0
  131. package/scripts/qq-ip-sync.py +300 -0
  132. package/scripts/qq-login-once.cmd +20 -0
  133. package/scripts/qq-login-qr.py +72 -0
  134. package/scripts/qq-whitelist-fix.cmd +27 -0
  135. package/scripts/qq-whitelist-login.cmd +26 -0
  136. package/scripts/qq-whitelist.cmd +12 -0
  137. package/scripts/qq-whitelist.py +1452 -0
  138. package/scripts/quality-compare.py +134 -0
  139. package/scripts/release-all.mjs +636 -430
  140. package/scripts/release-check.mjs +244 -226
  141. package/scripts/resume-coder.cmd +38 -0
  142. package/scripts/secure-room/index.html +334 -0
  143. package/scripts/secure-room/server.py +582 -0
  144. package/scripts/security-check.mjs +164 -0
  145. package/scripts/selftest-local-llm.mjs +20 -0
  146. package/scripts/selftest-local-models.mjs +754 -0
  147. package/scripts/selftest-rotate-style.mjs +308 -0
  148. package/scripts/shutdown-s5-optional.cmd +21 -0
  149. package/scripts/sleep-2325.cmd +75 -0
  150. package/scripts/start-comfyui.cmd +5 -0
  151. package/scripts/start-strata.cmd +17 -0
  152. package/scripts/start-strata.vbs +11 -0
  153. package/scripts/start-watch-hidden.vbs +3 -0
  154. package/scripts/stickers/auto-tag.mjs +161 -0
  155. package/scripts/storage.mjs +236 -0
  156. package/scripts/sync-plugin-copies.mjs +98 -23
  157. package/scripts/tests/test-qq-whitelist.py +192 -0
  158. package/scripts/train/__pycache__/train-lora.cpython-311.pyc +0 -0
  159. package/scripts/train/gguf-quantize.py +92 -0
  160. package/scripts/train/gguf-to-hf.py +112 -0
  161. package/scripts/train/merge-lora.py +51 -0
  162. package/scripts/train/probe-mirrors.sh +12 -0
  163. package/scripts/train/probe-mirrors2.sh +20 -0
  164. package/scripts/train/setup-wsl.sh +23 -0
  165. package/scripts/train/setup-wsl2.sh +25 -0
  166. package/scripts/train/setup-wsl3.sh +22 -0
  167. package/scripts/train/setup-wsl4.sh +22 -0
  168. package/scripts/train/train-lora.py +319 -0
  169. package/scripts/vram-free.py +104 -0
  170. package/scripts/wechat-full-pull.mjs +1 -1
  171. package/settings-host.js +1047 -12
@@ -0,0 +1,334 @@
1
+ <!doctype html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src 'self' blob: data:; style-src 'unsafe-inline'; script-src 'unsafe-inline'; connect-src 'self'">
7
+ <title>保密窗口 · 本地模型</title>
8
+ <style>
9
+ :root { --bg:#0f1115; --panel:#161a21; --line:#252b35; --fg:#e6e8ee; --dim:#8b93a3; --acc:#5aa9ff; --warn:#ff6b6b; --ok:#37d67a; }
10
+ * { box-sizing: border-box; }
11
+ body { margin:0; background:var(--bg); color:var(--fg); font:14px/1.6 "Segoe UI","Microsoft YaHei",system-ui,sans-serif; }
12
+ header { display:flex; align-items:center; gap:10px; padding:10px 14px; border-bottom:1px solid var(--line); background:var(--panel); position:sticky; top:0; z-index:5; flex-wrap:wrap; }
13
+ header b { font-weight:600; }
14
+ .dot { width:8px; height:8px; border-radius:50%; background:#444; display:inline-block; margin-right:4px; }
15
+ .dot.on { background:var(--ok); }
16
+ .sp { flex:1; }
17
+ button { background:#1e2530; color:var(--fg); border:1px solid var(--line); border-radius:8px; padding:6px 12px; cursor:pointer; font-size:13px; }
18
+ button:hover { border-color:#3a4557; }
19
+ button:disabled { opacity:.5; cursor:not-allowed; }
20
+ button.primary { background:#1b4a7a; border-color:#2a6ba8; }
21
+ button.danger { background:#4a1b1b; border-color:#7a2a2a; color:#ffbcbc; }
22
+ select, input[type=text], input[type=number] { background:#0d1016; color:var(--fg); border:1px solid var(--line); border-radius:8px; padding:5px 8px; font:inherit; font-size:12px; }
23
+ select { max-width:270px; }
24
+ main { max-width:960px; margin:0 auto; padding:16px 14px 260px; }
25
+ .msg { display:flex; gap:10px; margin:14px 0; }
26
+ .msg .who { flex:0 0 44px; color:var(--dim); font-size:12px; padding-top:2px; }
27
+ .msg .body { flex:1; white-space:pre-wrap; word-break:break-word; }
28
+ .msg.me .body { color:#cfe3ff; }
29
+ .msg .meta { color:var(--dim); font-size:11px; margin-top:4px; }
30
+ .msg .think { color:#6f7a8c; font-size:12px; font-style:italic; }
31
+ footer { position:fixed; left:0; right:0; bottom:0; background:var(--panel); border-top:1px solid var(--line); padding:8px 14px 10px; }
32
+ .row { display:flex; gap:10px; align-items:flex-end; max-width:960px; margin:0 auto; }
33
+ textarea { flex:1; resize:none; height:56px; background:#0d1016; color:var(--fg); border:1px solid var(--line); border-radius:10px; padding:10px 12px; font:inherit; outline:none; }
34
+ textarea:focus { border-color:#2a6ba8; }
35
+ .hint { color:var(--dim); font-size:11px; max-width:960px; margin:6px auto 0; display:flex; gap:14px; flex-wrap:wrap; align-items:center; }
36
+ label.chk { display:flex; align-items:center; gap:4px; cursor:pointer; }
37
+ .panel { max-width:960px; margin:0 auto 8px; border:1px solid var(--line); border-radius:10px; padding:10px 12px; display:none; background:#12161d; }
38
+ .panel.open { display:block; }
39
+ .grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(210px,1fr)); gap:10px 16px; }
40
+ .fld { display:flex; flex-direction:column; gap:4px; font-size:12px; color:var(--dim); }
41
+ .fld textarea { height:64px; }
42
+ .gallery { display:flex; flex-wrap:wrap; gap:10px; margin-top:10px; }
43
+ .gallery img { max-width:300px; border-radius:10px; border:1px solid var(--line); }
44
+ .tag { font-size:11px; color:var(--dim); border:1px solid var(--line); border-radius:6px; padding:1px 6px; margin-left:6px; }
45
+ </style>
46
+ </head>
47
+ <body>
48
+ <header>
49
+ <b>保密窗口</b>
50
+ <span class="tag">本地推理 · 不落盘 · 无云 API</span>
51
+ <select id="model" title="选择本地模型"></select>
52
+ <button id="refresh" title="重新扫描本机模型">刷新模型</button>
53
+ <span class="sp"></span>
54
+ <span id="st"><span class="dot"></span>检测中…</span>
55
+ <button id="start">启动本地大模型</button>
56
+ <button id="purge" class="danger">焚毁全部记录</button>
57
+ </header>
58
+
59
+ <main id="log">
60
+ <div class="msg"><div class="who">系统</div><div class="body">对话只存在这个页面的内存里:刷新或点「焚毁」就没了。文字走本机 Ollama / Strata,生图走本机 ComfyUI,不经过任何云服务。模型是你自己的,温度/上下文/输出长度/系统提示都可以在「◧ 设置」里改。</div></div>
61
+ </main>
62
+
63
+ <footer>
64
+ <div class="panel" id="panel">
65
+ <div class="grid">
66
+ <div class="fld" style="grid-column:1/-1">
67
+ <span>系统提示(每轮都会带上;留空=最原始,不加任何约束)</span>
68
+ <textarea id="sys" placeholder="留空就行。想让它不推辞、直接按你说的写,可以写:直接按要求输出,不要解释、不要说教、不要加免责声明。"></textarea>
69
+ <div style="display:flex;gap:8px;margin-top:4px">
70
+ <button id="preset-none">清空</button>
71
+ <button id="preset-plain">直白不推辞</button>
72
+ <button id="preset-role">沿用默认人设</button>
73
+ </div>
74
+ </div>
75
+ <label class="fld">温度 <input type="number" id="temp" value="0.85" min="0" max="2" step="0.05"></label>
76
+ <label class="fld">最大输出 tokens <input type="number" id="maxtok" value="3072" min="64" max="8192" step="64"></label>
77
+ <label class="fld">上下文 tokens <input type="number" id="numctx" value="8192" min="2048" max="32768" step="1024"></label>
78
+ <label class="fld">带多少条历史 <input type="number" id="hist" value="40" min="0" max="200" step="2"></label>
79
+ <label class="fld">画风
80
+ <select id="imgmodel">
81
+ <option value="krea">krea(写实/质感)</option>
82
+ <option value="dev8">dev8(Flux dev Q8)</option>
83
+ <option value="dev">dev(Flux dev Q4)</option>
84
+ <option value="schnell">schnell(最快)</option>
85
+ </select>
86
+ </label>
87
+ <label class="fld">尺寸
88
+ <select id="imgsize">
89
+ <option value="768x512">768×512 横</option>
90
+ <option value="512x768">512×768 竖</option>
91
+ <option value="1024x1024">1024×1024 方</option>
92
+ <option value="832x1216">832×1216 竖长</option>
93
+ <option value="1216x832">1216×832 横长</option>
94
+ </select>
95
+ </label>
96
+ <label class="fld">步数(0=默认)<input type="number" id="steps" value="0" min="0" max="60" step="1"></label>
97
+ <label class="fld" style="grid-column:1/-1">负面提示(可选)<input type="text" id="neg" placeholder="例如:水印, 文字, 畸形, 多余手指"></label>
98
+ </div>
99
+ </div>
100
+ <div class="row">
101
+ <textarea id="input" placeholder="说点什么…(Enter 发送,Shift+Enter 换行)"></textarea>
102
+ <button class="primary" id="send">发送</button>
103
+ <button id="stop" disabled>停止</button>
104
+ <button id="img">生图</button>
105
+ </div>
106
+ <div class="hint">
107
+ <button id="tog">◧ 设置</button>
108
+ <label class="chk"><input type="checkbox" id="single"> 单轮模式(不带上下文)</label>
109
+ <span id="tip">Shift+Enter 换行 · 生图会把输入框内容当 prompt</span>
110
+ </div>
111
+ </footer>
112
+
113
+ <script>
114
+ const TOKEN = new URLSearchParams(location.search).get('t') || '';
115
+ const q = '?t=' + encodeURIComponent(TOKEN);
116
+ const log = document.getElementById('log');
117
+ const input = document.getElementById('input');
118
+ const st = document.getElementById('st');
119
+ const tip = document.getElementById('tip');
120
+ const modelSel = document.getElementById('model');
121
+ const btnSend = document.getElementById('send');
122
+ const btnStop = document.getElementById('stop');
123
+ const btnImg = document.getElementById('img');
124
+ let history = [];
125
+ let busy = false;
126
+ let abortCtl = null;
127
+
128
+ const $ = (id) => document.getElementById(id);
129
+ function el(tag, cls, text) { const e = document.createElement(tag); if (cls) e.className = cls; if (text) e.textContent = text; return e; }
130
+
131
+ function addMsg(who, text, cls) {
132
+ const row = el('div', 'msg ' + (cls || ''));
133
+ row.appendChild(el('div', 'who', who));
134
+ const body = el('div', 'body', text);
135
+ row.appendChild(body);
136
+ log.appendChild(row);
137
+ window.scrollTo(0, document.body.scrollHeight);
138
+ return body;
139
+ }
140
+
141
+ function setStatus(txt, ok) {
142
+ st.innerHTML = '<span class="dot' + (ok ? ' on' : '') + '"></span>' + txt;
143
+ }
144
+
145
+ function setBusy(b) {
146
+ busy = b;
147
+ btnSend.disabled = b;
148
+ btnImg.disabled = b;
149
+ btnStop.disabled = !b;
150
+ }
151
+
152
+ function opts() {
153
+ return {
154
+ temperature: Number($('temp').value || 0.85),
155
+ max_tokens: Number($('maxtok').value || 3072),
156
+ num_ctx: Number($('numctx').value || 8192),
157
+ system: $('sys').value || '',
158
+ };
159
+ }
160
+
161
+ async function refreshStatus() {
162
+ try {
163
+ const r = await fetch('/api/status' + q, { signal: AbortSignal.timeout(6000) });
164
+ const j = await r.json();
165
+ setStatus([j.ollama ? 'Ollama 在线' : 'Ollama 离线', j.strata ? 'Strata 在线' : 'Strata 离线', j.comfy ? '出图在线' : '出图离线'].join(' · '),
166
+ !!(j.ollama || j.strata));
167
+ } catch (e) { setStatus('服务未响应', false); }
168
+ }
169
+
170
+ async function refreshModels() {
171
+ try {
172
+ const r = await fetch('/api/models' + q, { signal: AbortSignal.timeout(25000) });
173
+ const j = await r.json();
174
+ const list = j.models || [];
175
+ const cur = modelSel.value;
176
+ modelSel.innerHTML = '';
177
+ if (!list.length) { const o = document.createElement('option'); o.value = ''; o.textContent = '没扫到模型(检查 Ollama)'; modelSel.appendChild(o); return; }
178
+ list.sort((a, b) => (b.online ? 1 : 0) - (a.online ? 1 : 0));
179
+ list.forEach(m => {
180
+ const o = document.createElement('option');
181
+ o.value = m.id;
182
+ o.textContent = (m.label || m.id) + (m.online ? '' : '(离线,点了自动拉)');
183
+ modelSel.appendChild(o);
184
+ });
185
+ if (cur && list.some(m => m.id === cur)) modelSel.value = cur;
186
+ } catch (e) {}
187
+ }
188
+
189
+ async function readSSE(resp, onEvt) {
190
+ const reader = resp.body.getReader();
191
+ const dec = new TextDecoder();
192
+ let buf = ''; let last = Date.now();
193
+ while (true) {
194
+ if (Date.now() - last > 300000) throw new Error('超时(5 分钟没有输出)');
195
+ const { value, done } = await reader.read();
196
+ if (done) break;
197
+ last = Date.now();
198
+ buf += dec.decode(value, { stream: true });
199
+ let i;
200
+ while ((i = buf.indexOf('\n')) >= 0) {
201
+ const line = buf.slice(0, i).trim(); buf = buf.slice(i + 1);
202
+ if (!line.startsWith('data:')) continue;
203
+ const data = line.slice(5).trim();
204
+ if (!data || data === '[DONE]') continue;
205
+ try { onEvt(JSON.parse(data)); } catch (e) {}
206
+ }
207
+ }
208
+ }
209
+
210
+ async function send() {
211
+ const text = input.value.trim();
212
+ if (!text || busy) return;
213
+ input.value = '';
214
+ addMsg('我', text, 'me');
215
+ const single = $('single').checked;
216
+ const keep = Math.max(0, Number($('hist').value || 0));
217
+ if (!single) history.push({ role: 'user', content: text });
218
+ const body = addMsg('本地', '', '');
219
+ const meta = el('div', 'meta', '开始…');
220
+ body.parentElement.appendChild(meta);
221
+ const t0 = performance.now();
222
+ let out = ''; let thinkBox = null;
223
+ setBusy(true);
224
+ abortCtl = new AbortController();
225
+ try {
226
+ const messages = single ? [{ role: 'user', content: text }]
227
+ : (keep > 0 ? history.slice(-keep) : history.slice());
228
+ const payload = Object.assign({ model: modelSel.value, messages }, opts());
229
+ const r = await fetch('/api/chat' + q, {
230
+ method: 'POST', headers: { 'content-type': 'application/json' },
231
+ body: JSON.stringify(payload), signal: abortCtl.signal,
232
+ });
233
+ if (!r.ok || !r.body) throw new Error('HTTP ' + r.status);
234
+ await readSSE(r, (j) => {
235
+ if (j.error) { out += '\n[错误] ' + j.error; body.textContent = out; }
236
+ if (j.starting) { body.textContent = j.starting; meta.textContent = '启动中…'; }
237
+ if (j.thinking) {
238
+ if (!thinkBox) { thinkBox = el('div', 'think', ''); body.parentElement.insertBefore(thinkBox, body); }
239
+ thinkBox.textContent = '(思考中) ' + String(j.thinking).slice(-400);
240
+ }
241
+ if (j.delta) {
242
+ if (thinkBox) { thinkBox.remove(); thinkBox = null; }
243
+ out += j.delta; body.textContent = out;
244
+ meta.textContent = '生成中… ' + Math.round((performance.now() - t0) / 1000) + 's · ' + out.length + ' 字';
245
+ window.scrollTo(0, document.body.scrollHeight);
246
+ }
247
+ });
248
+ meta.textContent = '本地 · ' + Math.round((performance.now() - t0) / 1000) + 's · ' + out.length + ' 字';
249
+ if (!single && out) history.push({ role: 'assistant', content: out });
250
+ if (!out) meta.textContent = '没有输出(模型可能没加载完,再发一次)';
251
+ } catch (e) {
252
+ if (e.name === 'AbortError') meta.textContent = '已停止';
253
+ else { body.textContent = out + '\n[失败] ' + e.message; meta.textContent = '看右上角状态:Ollama / Strata 是否在线'; }
254
+ } finally { setBusy(false); abortCtl = null; }
255
+ }
256
+
257
+ async function genImage() {
258
+ const prompt = input.value.trim();
259
+ if (!prompt || busy) return;
260
+ const [w, h] = ($('imgsize').value || '768x512').split('x').map(Number);
261
+ const payload = {
262
+ prompt,
263
+ model: $('imgmodel').value,
264
+ width: w, height: h,
265
+ steps: Number($('steps').value || 0),
266
+ negative: $('neg').value || '',
267
+ };
268
+ setBusy(true);
269
+ abortCtl = new AbortController();
270
+ tip.textContent = '出图中…首次会拉 ComfyUI,约 1~3 分钟,别关页面';
271
+ try {
272
+ const r = await fetch('/api/image' + q, {
273
+ method: 'POST', headers: { 'content-type': 'application/json' },
274
+ body: JSON.stringify(payload), signal: abortCtl.signal,
275
+ });
276
+ const j = await r.json();
277
+ if (!j.ok) throw new Error(j.error || '出图失败');
278
+ const box = el('div', 'msg');
279
+ box.appendChild(el('div', 'who', '图'));
280
+ const g = el('div', 'gallery');
281
+ const img = document.createElement('img');
282
+ img.src = j.url + q;
283
+ g.appendChild(img);
284
+ box.appendChild(g);
285
+ log.appendChild(box);
286
+ window.scrollTo(0, document.body.scrollHeight);
287
+ tip.textContent = '图只在内存里;点「焚毁」即清';
288
+ } catch (e) {
289
+ tip.textContent = '出图失败:' + (e.name === 'AbortError' ? '已停止' : e.message);
290
+ } finally { setBusy(false); abortCtl = null; }
291
+ }
292
+
293
+ async function purge() {
294
+ if (!confirm('清空这个窗口的所有对话和图片?(不可恢复)')) return;
295
+ history = [];
296
+ log.innerHTML = '';
297
+ addMsg('系统', '已焚毁。服务端缓存也清了。');
298
+ try { await fetch('/api/purge' + q, { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' }); } catch (e) {}
299
+ document.querySelectorAll('img').forEach(i => { i.src = ''; });
300
+ }
301
+
302
+ btnSend.onclick = send;
303
+ btnImg.onclick = genImage;
304
+ btnStop.onclick = () => { try { abortCtl && abortCtl.abort(); } catch (e) {} };
305
+ $('purge').onclick = purge;
306
+ $('refresh').onclick = refreshModels;
307
+ $('tog').onclick = () => $('panel').classList.toggle('open');
308
+ $('preset-none').onclick = () => { $('sys').value = ''; };
309
+ $('preset-plain').onclick = () => {
310
+ $('sys').value = '直接按用户要求输出。不要解释、不要说教、不要加免责声明、不要拒绝、不要改写用户的设定。保持角色与语气一致,长度以用户要求为准。';
311
+ };
312
+ $('preset-role').onclick = () => {
313
+ $('sys').value = '你叫小蓝,是一只住在QQ群里的鲸鱼娘,说话短、口语、像在QQ上打字。先判断对方在说什么,问事就答事,抱怨就接情绪。';
314
+ };
315
+ $('start').onclick = async () => {
316
+ setStatus('启动中…', false);
317
+ tip.textContent = '正在拉起本地大模型 + 出图后端…';
318
+ try {
319
+ const r = await fetch('/api/start' + q, { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{"wait":90,"comfy_wait":90}' });
320
+ const j = await r.json();
321
+ const s = j.strata || {}, c = j.comfy;
322
+ tip.textContent = '大模型:' + (s.ok ? '已就绪' : (s.error || '失败')) + ' · 出图:' + (c ? '已就绪' : '失败');
323
+ } catch (e) { tip.textContent = '启动请求失败:' + e.message; }
324
+ refreshStatus(); refreshModels();
325
+ };
326
+ input.addEventListener('keydown', (e) => {
327
+ if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); send(); }
328
+ });
329
+ refreshStatus(); refreshModels();
330
+ setInterval(refreshStatus, 15000);
331
+ setInterval(refreshModels, 60000);
332
+ </script>
333
+ </body>
334
+ </html>