dsh-fish-soul 0.15.44 → 0.15.46

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  让一个 QQ 小号背后有"同一个人":固定人格、按人记记忆、有自己的生活节奏、会主动开口;同一个"她"同时出现在 QQ、B站、抖音。
4
4
 
5
- DSH 插件(单角色 `feiyu`)。版本 **0.15.44**。
5
+ DSH 插件(单角色 `feiyu`)。版本 **0.15.46**。
6
6
 
7
7
  QQ 交流群:**1125962189**
8
8
 
package/lib/client.js CHANGED
@@ -36,12 +36,17 @@ window.__ModuleLoader__.load({
36
36
  const cx = (...names) => names.filter(Boolean).join(" ");
37
37
 
38
38
  // ── 通信层:fail-open(任何请求失败都不抛到宿主) ──
39
- async function api(method, path, body) {
39
+ // opts.raw:body 直接当原始二进制发(File/Blob/Buffer),不做 JSON 序列化。
40
+ // 大文件上传走这条:base64 有 33% 膨胀 + 客户端 4× 峰值内存,服务端还要再吃 2.4×。
41
+ async function api(method, path, body, opts = {}) {
42
+ const raw = opts?.raw === true;
40
43
  try {
41
44
  const response = await fetch(API + path, {
42
45
  method,
43
- headers: { "content-type": "application/json" },
44
- ...(body !== undefined ? { body: JSON.stringify(body) } : {})
46
+ headers: raw
47
+ ? { "content-type": (body && body.type) || "application/octet-stream" }
48
+ : { "content-type": "application/json" },
49
+ ...(body !== undefined ? { body: raw ? body : JSON.stringify(body) } : {})
45
50
  });
46
51
  const data = await response.json().catch(() => null);
47
52
  if (response.status === 503 && data && (data.starting || data.failed)) {
@@ -555,15 +555,8 @@ window.__ModuleLoader__.load({
555
555
  unconfirmed: ["可能被吞", "warning"],
556
556
  relay: ["转达", "success"]
557
557
  };
558
- /** 读本地图片 → base64(去掉 data: 前缀);读不出来给 null。 */
559
- function readBase64(file) {
560
- return new Promise((resolve) => {
561
- const reader = new FileReader();
562
- reader.onload = () => { const s = String(reader.result ?? ""); resolve(s.includes(",") ? s.slice(s.indexOf(",") + 1) : null); };
563
- reader.onerror = () => resolve(null);
564
- reader.readAsDataURL(file);
565
- });
566
- }
558
+ /** 单张图上限:跟后端 `IMPORT_BYTES_MAX` 对齐(原始二进制上传,不再有 base64 膨胀)。 */
559
+ const IMPORT_MAX_BYTES = 20 * 1024 * 1024;
567
560
 
568
561
  /** 一张表情:名字能直接改(失焦 / 回车保存,Esc 撤销),也能删 */
569
562
  function StickerCard({ x, api, apiBase, notify, refresh, relTime, ui, onRemove }) {
@@ -622,10 +615,13 @@ window.__ModuleLoader__.load({
622
615
  let doneCount = 0; let skipped = 0; let failed = 0; let full = false;
623
616
  const errors = [];
624
617
  for (const f of list) {
625
- if (f.size > 4 * 1024 * 1024) { skipped++; continue; }
626
- const b64 = await readBase64(f);
627
- if (b64 === null) { failed++; errors.push(`${f.name}:读不出来`); continue; }
628
- const r = await api("POST", "/stickers/import", { name: f.name.replace(/\.[a-z]+$/i, ""), mediaType: f.type, base64: b64 });
618
+ if (f.size > IMPORT_MAX_BYTES) { skipped++; continue; }
619
+ // 🔴 直接发 File 本体(原始二进制),不再读成 base64。
620
+ // base64 有 33% 膨胀,而且客户端要 4× 峰值内存(读→切片→stringify→编码),
621
+ // 服务端还要再吃 2.4×;中文文件名更糟(V8 整串升 TwoByte,再翻倍)。
622
+ // 改成流式写盘后,内存几乎不随文件大小增长。
623
+ // 文件名走查询串(放 header 里中文会抛)。
624
+ const r = await api("POST", `/stickers/import?name=${encodeURIComponent(f.name.replace(/\.[a-z]+$/i, ""))}`, f, { raw: true });
629
625
  if (r?.ok) doneCount++;
630
626
  else if (r?.full === true) { failed++; full = true; errors.push(`${f.name}:${r?.error ?? "_stickers 满了"}`); break; }
631
627
  else if (r?.dup === true) { errors.push(`${f.name}:${r?.error ?? "已经有了"}`); }
@@ -634,7 +630,7 @@ window.__ModuleLoader__.load({
634
630
  setBusy(false);
635
631
  const parts = [];
636
632
  if (doneCount > 0) parts.push(`导入了 ${doneCount} 张`);
637
- if (skipped > 0) parts.push(`${skipped} 张超过 4MB 跳过`);
633
+ if (skipped > 0) parts.push(`${skipped} 张超过 ${Math.round(IMPORT_MAX_BYTES / 1024 / 1024)}MB 跳过`);
638
634
  if (failed > 0) parts.push(`${failed} 张没导进去`);
639
635
  if (full) parts.push("_stickers 满了");
640
636
  notify(parts.length > 0 ? parts.join(",") : "没有导入");
package/lib/routes-v07.js CHANGED
@@ -6,8 +6,11 @@
6
6
  * - 群里的说法:每个群学到的梗和说话风格(看 / 改 / 现在学一次);
7
7
  * - 首次引导:检查清单 + 不再显示。
8
8
  */
9
- import { existsSync, readFileSync } from 'node:fs';
9
+ import { existsSync, readFileSync, createWriteStream, unlinkSync, mkdirSync } from 'node:fs';
10
10
  import { join, basename, resolve } from 'node:path';
11
+ import { pipeline } from 'node:stream/promises';
12
+ import { Transform } from 'node:stream';
13
+ import { randomUUID } from 'node:crypto';
11
14
  import { FEATURES } from './llm.js';
12
15
  import { voiceConfig } from './voice.js';
13
16
  import { stickerConfig } from './stickers.js';
@@ -18,8 +21,10 @@ import { previewMaiBotExtras, importMaiBotExtras, sniffImage } from './maibot-ex
18
21
  import { maskKey } from './routes.js';
19
22
 
20
23
  const BODY_MAX = 256 * 1024;
21
- const IMPORT_BODY_MAX = 6 * 1024 * 1024; // 一张图的 base64 + JSON 兜底上限
22
- const IMPORT_BYTES_MAX = 4 * 1024 * 1024; // 解码后的图片上限
24
+ const IMPORT_BODY_MAX = 6 * 1024 * 1024; // 旧路(JSON + base64)的 body 上限
25
+ // 原始二进制上传(新路)的图片上限。流式写盘,内存不随大小增长,所以给得比 base64 那条宽得多。
26
+ // 20MB 足够绝大多数表情包/截图;再大就建议直接放进 _stickers 目录(零上传)。
27
+ const IMPORT_BYTES_MAX = 20 * 1024 * 1024;
23
28
  const MIME = { png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif', webp: 'image/webp' };
24
29
  const MEDIA_TYPES = new Set(Object.values(MIME));
25
30
 
@@ -277,15 +282,79 @@ export async function handleV07Route({ method, path, url, req, res, send, readBo
277
282
  send(200, ok ? { ok: true } : { ok: false, error: '没有这张' });
278
283
  return true;
279
284
  }
280
- // 主人从面板导入本地图片:只进当前工作区,不占每天收藏的额度
285
+ // 主人从面板导入本地图片:只进当前工作区,不占每天收藏的额度。
286
+ //
287
+ // 两种请求体都收:
288
+ // ① 原始二进制(`content-type: image/*`)—— 新前端走这条,流式写盘,内存几乎不随文件增长;
289
+ // ② JSON + base64(`application/json`)—— 老前端兼容,保留但上限小。
290
+ //
291
+ // 为什么改:base64 有 33% 膨胀,客户端读→切片→stringify→编码要 4× 峰值内存,
292
+ // 服务端 `Buffer.concat().toString()` + `JSON.parse` 再吃 2.4×;中文文件名更糟
293
+ // (V8 里含一个非 Latin1 字符就把整串升成 TwoByte,再翻倍)。
294
+ // 之前 965KB 的 GIF(base64 后 1257KB)撞上 256KB 共享上限就是这条路太窄。
281
295
  if (path === '/stickers/import' && post) {
282
296
  if (!guard()) return true;
283
297
  if (!stickers) { send(200, { ok: false, error: '表情包没起来' }); return true; }
284
298
  const ws = gateway?.workspacePath?.() ?? '';
285
299
  if (ws === '') { send(200, { ok: false, error: 'QQ 工作区还没准备好(先连一次 QQ)' }); return true; }
300
+
301
+ const ctype = String(req.headers?.['content-type'] ?? '');
302
+ const isRaw = /^image\//i.test(ctype) || ctype === 'application/octet-stream';
303
+
304
+ if (isRaw) {
305
+ // ── ① 原始二进制:流式写临时文件,边写边数 ──
306
+ // 先按 content-length 快速拒绝(头可能撒谎,流里还要再数一次)。
307
+ const declared = Number(req.headers?.['content-length'] ?? 0);
308
+ if (Number.isFinite(declared) && declared > IMPORT_BYTES_MAX) {
309
+ send(200, { ok: false, error: `图片太大了(超过 ${Math.round(IMPORT_BYTES_MAX / 1024 / 1024)}MB)` });
310
+ return true;
311
+ }
312
+ // _stickers 可能还不存在(第一次导入):先建出来,否则临时文件写不进去。
313
+ const dir = join(ws, '_stickers');
314
+ try { mkdirSync(dir, { recursive: true }); } catch (error) {
315
+ send(200, { ok: false, error: `建不了 _stickers 目录:${String(error instanceof Error ? error.message : error)}` });
316
+ return true;
317
+ }
318
+ const tmp = join(dir, `.upload-${randomUUID()}.tmp`);
319
+ let size = 0;
320
+ try {
321
+ await pipeline(
322
+ req,
323
+ new Transform({
324
+ transform(chunk, _enc, cb) {
325
+ size += chunk.length;
326
+ if (size > IMPORT_BYTES_MAX) { cb(new Error(`图片太大了(超过 ${Math.round(IMPORT_BYTES_MAX / 1024 / 1024)}MB)`)); return; }
327
+ cb(null, chunk);
328
+ }
329
+ }),
330
+ createWriteStream(tmp)
331
+ );
332
+ } catch (error) {
333
+ try { unlinkSync(tmp); } catch { /* 本来就没有 */ }
334
+ send(200, { ok: false, error: String(error instanceof Error ? error.message : error) });
335
+ return true;
336
+ }
337
+ let bytes;
338
+ try { bytes = readFileSync(tmp); } catch (error) {
339
+ try { unlinkSync(tmp); } catch { /* 已删 */ }
340
+ send(200, { ok: false, error: `读不回上传的内容:${String(error instanceof Error ? error.message : error)}` });
341
+ return true;
342
+ }
343
+ try { unlinkSync(tmp); } catch { /* 已删 */ }
344
+ if (bytes.length === 0) { send(200, { ok: false, error: '没有图片内容' }); return true; }
345
+ // 类型以**字节嗅探**为准:浏览器给的 content-type 可能空/撒谎。
346
+ const mediaType = sniffImage(bytes);
347
+ if (mediaType === null) { send(200, { ok: false, error: '不是支持的图片格式' }); return true; }
348
+ // 文件名走查询串(中文放 header 会抛)。
349
+ const name = String(url.searchParams.get('name') ?? '');
350
+ const r = stickers.importImage({ bytes, mediaType, name, workspacePath: ws, from: '主人' });
351
+ send(200, r.ok ? { ok: true, file: r.file } : { ok: false, error: r.reason ?? '导入失败', full: r.full === true, dup: r.dup === true });
352
+ return true;
353
+ }
354
+
355
+ // ── ② 旧路:JSON + base64(保留兼容)──
286
356
  let raw = '';
287
357
  // 这条路单独放大到 6MB:共享的 256KB 是给表单用的,base64 图必被截断。
288
- // readBody 第三参是上限(不传 = 表单默认),日志钩子没有就不传。
289
358
  try { raw = await readBody(req, null, IMPORT_BODY_MAX); } catch { send(200, { ok: false, error: '请求没读完(图片太大,超过 6MB?)' }); return true; }
290
359
  if (raw.length > IMPORT_BODY_MAX) { send(200, { ok: false, error: '图片太大了(超过 4MB)' }); return true; }
291
360
  let b;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-fish-soul",
3
- "version": "0.15.44",
3
+ "version": "0.15.46",
4
4
  "description": "鱼 · 人格、按人记忆(可纠正、有印象、能导入旧聊天记录)、日程自走与主动开口,直连 SnowLuma 收发 QQ(群里会自己插话),B站 / 抖音小号私信与自己刷视频;按功能选模型并统计用量花费,能听会说 QQ 语音、收藏表情包、学群里的梗,可选上网查;心情影响说话、去 AI 味、每个群的设定、按聊天选模型、每晚写日记、每周记忆存档与可选周记(DSH 插件,单角色 feiyu ,v0.15.37)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -64,7 +64,7 @@
64
64
  }
65
65
  },
66
66
  "scripts": {
67
- "test": "node test/safe-download.mjs && node test/douyin-exact-id.mjs && node test/douyin-pb-init.mjs && node test/douyin-conversation.mjs && node test/douyin-inbox.mjs && node test/douyin-quarantine.mjs && node test/douyin-send-target.mjs && node test/douyin-gap-dedupe.mjs && node test/douyin-read-fail-retry.mjs && node test/douyin-read-cache.mjs && node test/douyin-read-fail-retry-poll.mjs && node test/douyin-inbox-contract.mjs && node test/memory-owner-reassign.mjs && node test/douyin-poll-and-timer-safety.mjs && node test/p2-limits.mjs && node test/resource-safety.mjs && node test/leftover-edge-cases.mjs && node test/douyin-master-uid.mjs && node test/douyin-identity-e2e.mjs && node test/douyin-post-jobs.mjs && node test/retrieval-filtered-vectors.mjs && node test/security-boundaries.mjs && node test/smoke.mjs && node test/douyin-browser.mjs && node test/douyin-music.mjs && node test/startup-gate.mjs && node test/outbox.mjs && node test/import-coverage.mjs && node test/update-check.mjs && node test/issue-fixes.mjs && node test/import-resume.mjs && node test/maibot-extras.mjs && node test/worldinfo.mjs && node test/memory-bulk.mjs && node test/memory-tiers.mjs && node test/memory-weekly.mjs && node test/memory-storage.mjs && node test/memory-storage-restore.mjs && node test/backup-restore.mjs && node test/douyin-group.mjs && node test/review-fixes.mjs && node test/at-reads-video.mjs && node test/search-source.mjs && node test/followups.mjs && node test/detail-config.mjs && node test/qq-send-any-image.mjs && node test/qq-read-attachment.mjs && node test/qq-batch-window.mjs && node test/comment-video.mjs && node test/frames.mjs && node test/face-name.mjs && node test/comment-reply.mjs && node test/chat-comment.mjs && node test/at-target.mjs && node test/quota-caps.mjs && node test/client-lint.mjs && node test/client-panels.mjs && node test/dsh-desktop.mjs && node test/issue-59-interject.mjs && node test/issue-59-diagnose.mjs && node test/sticker-manage.mjs && node test/bili-emotes.mjs && node test/qq-outbound-sanitize.mjs && node test/person-delete.mjs && node test/qq-group-admin.mjs && node test/douyin-recovery.mjs && node test/session-preset.mjs && node test/qq-connect-error.mjs && node test/douyin-comment-bridge.mjs && node test/bili-comment-emoji.mjs && node test/douyin-state-echo.mjs && node test/issue-75-proactive.mjs && node test/issue-76-capability.mjs && node test/douyin-http-browse.mjs && node test/douyin-verify-backoff.mjs && node test/douyin-digg-bridge.mjs && node test/memory-evidence-transcript.mjs && node test/chat-archive-default.mjs && node test/dream-transcript-wire.mjs && node test/douyin-frames-collect.mjs && node test/master-qq-uin-rebind.mjs && node test/douyin-session-health.mjs && node test/douyin-delivered.mjs && node test/douyin-card-share.mjs && node test/douyin-push-drop.mjs && node test/douyin-uid-binding.mjs && node test/image-webp-fallback.mjs && node test/douyin-emoji-fallback.mjs && node test/relay-other-platform.mjs && node test/voice-volcengine.mjs && node test/voice-minimax-dashscope.mjs && node test/bili-switch-persist.mjs && node test/cross-channel-context.mjs && node test/reply-target.mjs && node test/shared-session.mjs && node test/memory-source-label.mjs && node test/pending-delivery.mjs && node test/recall-window-78.mjs && node test/client-syntax.mjs && node test/diag-log.mjs && node test/check-rings.mjs && node test/self-update.mjs",
67
+ "test": "node test/safe-download.mjs && node test/douyin-exact-id.mjs && node test/douyin-pb-init.mjs && node test/douyin-conversation.mjs && node test/douyin-inbox.mjs && node test/douyin-quarantine.mjs && node test/douyin-send-target.mjs && node test/douyin-gap-dedupe.mjs && node test/douyin-read-fail-retry.mjs && node test/douyin-read-cache.mjs && node test/douyin-read-fail-retry-poll.mjs && node test/douyin-inbox-contract.mjs && node test/memory-owner-reassign.mjs && node test/douyin-poll-and-timer-safety.mjs && node test/p2-limits.mjs && node test/resource-safety.mjs && node test/leftover-edge-cases.mjs && node test/douyin-master-uid.mjs && node test/douyin-identity-e2e.mjs && node test/douyin-post-jobs.mjs && node test/retrieval-filtered-vectors.mjs && node test/security-boundaries.mjs && node test/smoke.mjs && node test/douyin-browser.mjs && node test/douyin-music.mjs && node test/startup-gate.mjs && node test/outbox.mjs && node test/import-coverage.mjs && node test/update-check.mjs && node test/issue-fixes.mjs && node test/import-resume.mjs && node test/maibot-extras.mjs && node test/worldinfo.mjs && node test/memory-bulk.mjs && node test/memory-tiers.mjs && node test/memory-weekly.mjs && node test/memory-storage.mjs && node test/memory-storage-restore.mjs && node test/backup-restore.mjs && node test/douyin-group.mjs && node test/review-fixes.mjs && node test/at-reads-video.mjs && node test/search-source.mjs && node test/followups.mjs && node test/detail-config.mjs && node test/qq-send-any-image.mjs && node test/qq-read-attachment.mjs && node test/qq-batch-window.mjs && node test/comment-video.mjs && node test/frames.mjs && node test/face-name.mjs && node test/comment-reply.mjs && node test/chat-comment.mjs && node test/at-target.mjs && node test/quota-caps.mjs && node test/client-lint.mjs && node test/client-panels.mjs && node test/dsh-desktop.mjs && node test/issue-59-interject.mjs && node test/issue-59-diagnose.mjs && node test/sticker-manage.mjs && node test/bili-emotes.mjs && node test/qq-outbound-sanitize.mjs && node test/person-delete.mjs && node test/qq-group-admin.mjs && node test/douyin-recovery.mjs && node test/session-preset.mjs && node test/qq-connect-error.mjs && node test/douyin-comment-bridge.mjs && node test/bili-comment-emoji.mjs && node test/douyin-state-echo.mjs && node test/issue-75-proactive.mjs && node test/issue-76-capability.mjs && node test/douyin-http-browse.mjs && node test/douyin-verify-backoff.mjs && node test/douyin-digg-bridge.mjs && node test/memory-evidence-transcript.mjs && node test/chat-archive-default.mjs && node test/dream-transcript-wire.mjs && node test/douyin-frames-collect.mjs && node test/master-qq-uin-rebind.mjs && node test/douyin-session-health.mjs && node test/douyin-delivered.mjs && node test/douyin-card-share.mjs && node test/douyin-push-drop.mjs && node test/douyin-uid-binding.mjs && node test/image-webp-fallback.mjs && node test/douyin-emoji-fallback.mjs && node test/relay-other-platform.mjs && node test/voice-volcengine.mjs && node test/voice-minimax-dashscope.mjs && node test/bili-switch-persist.mjs && node test/cross-channel-context.mjs && node test/reply-target.mjs && node test/shared-session.mjs && node test/memory-source-label.mjs && node test/pending-delivery.mjs && node test/recall-window-78.mjs && node test/client-syntax.mjs && node test/diag-log.mjs && node test/check-rings.mjs && node test/sticker-import-gif.mjs && node test/sticker-real-gif.mjs && node test/sticker-upload-binary.mjs && node test/self-update.mjs",
68
68
  "eval": "node test/eval/persona-eval.mjs"
69
69
  }
70
70
  }