dsh-fish-soul 0.16.5 → 0.16.6

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.16.5**。
5
+ DSH 插件(单角色 `feiyu`)。版本 **0.16.6**。
6
6
 
7
7
  QQ 交流群:**1125962189**
8
8
 
@@ -472,6 +472,12 @@ export class Browser {
472
472
  if (msg.error) p.reject(new Error(msg.error.message || JSON.stringify(msg.error)))
473
473
  else p.resolve(msg.result)
474
474
  } else if (msg.method) {
475
+ // 原生确认框(beforeunload 的「是否离开网站?」,发布页 / 编辑器常见)会一直挡住页面:
476
+ // Page.navigate 的响应被它挂着,后续所有取页面状态的动作都跟着等,看起来就是「卡死不动」。
477
+ // 这里统一代点「确定」,把页面放走;真没人弹框也不会多做什么。
478
+ if (msg.method === 'Page.javascriptDialogOpening') {
479
+ this.send('Page.handleJavaScriptDialog', { accept: true }, msg.sessionId || this.sessionId).catch(() => {})
480
+ }
475
481
  // fish-soul:事件旁听(判断「用户自己把窗口 / 标签页关了」)
476
482
  if (typeof this.onEvent === 'function') { try { this.onEvent(msg) } catch { /* 上层出错不影响连接 */ } }
477
483
  // 🔴 每个事件带一个**单调递增的序号**(`seq`),调用方用它当游标。
@@ -537,14 +543,14 @@ export class Browser {
537
543
  })
538
544
  }
539
545
 
540
- send(method, params = {}, sessionId) {
546
+ send(method, params = {}, sessionId, timeoutMs = 60000) {
541
547
  return new Promise((resolve, reject) => {
542
548
  if (!this.ws || this.ws.readyState !== 1) return reject(new Error('CDP 连接已断'))
543
549
  const id = ++this.nextId
544
550
  const t = setTimeout(() => {
545
551
  this.pending.delete(id)
546
552
  reject(new Error(`CDP ${method} 超时`))
547
- }, 60000)
553
+ }, timeoutMs)
548
554
  this.pending.set(id, {
549
555
  resolve: (v) => { clearTimeout(t); resolve(v) },
550
556
  reject: (e) => { clearTimeout(t); reject(e) },
@@ -590,9 +596,14 @@ export class Browser {
590
596
  let lastHref = ''
591
597
  for (let attempt = 0; attempt <= retries; attempt++) {
592
598
  try {
593
- await this.send('Page.navigate', { url }, this.sessionId)
599
+ // 导航卡死时不能无限等:CDP 的 Page.navigate 要等对话框被处理才会回包,
600
+ // 对话框一旦没人点,这里会挂满 send() 默认的 60 秒才报错,重试也跟着等。
601
+ // 导航单独给 15 秒上限(超时由 send 自己清 pending 和计时器,不会空挂),
602
+ // 超时当这次失败,走下面的重试 / 报错。
603
+ await this.send('Page.navigate', { url }, this.sessionId, 15000)
594
604
  } catch (e) {
595
- if (attempt >= retries) throw new Error(`导航请求失败:${e.message}`)
605
+ const timedOut = /超时/.test(e.message)
606
+ if (attempt >= retries) throw new Error(timedOut ? '导航请求超时(15 秒):页面可能被原生确认框挡住' : `导航请求失败:${e.message}`)
596
607
  await sleep(800)
597
608
  continue
598
609
  }
package/lib/diag-log.js CHANGED
@@ -90,14 +90,15 @@ export class DiagLog {
90
90
  add(key, detail = {}, level = 'info') {
91
91
  const at = this.now();
92
92
  const k = String(key);
93
- // 同一个 key 在窗口内重复:合并成一条 + count,别把缓冲冲干净
93
+ // 同一个 key 在窗口内重复:合并成一条 + count,别把缓冲冲干净。
94
+ // 不能只看队尾。两个会话交替打日志时,队尾一直是另一个 key,60 秒窗口会被拆开。
94
95
  const lastAt = this.lastKeyAt.get(k) ?? 0;
95
- if (at - lastAt < DEDUPE_MS && this.entries.length > 0) {
96
- const tail = this.entries[this.entries.length - 1];
97
- if (tail.key === k) {
98
- tail.count += 1;
99
- tail.at = at;
100
- tail.detail = detail;
96
+ if (at - lastAt < DEDUPE_MS) {
97
+ for (let i = this.entries.length - 1; i >= 0; i--) {
98
+ if (this.entries[i].key !== k) continue;
99
+ this.entries[i].count += 1;
100
+ this.entries[i].at = at;
101
+ this.entries[i].detail = detail;
101
102
  this.lastKeyAt.set(k, at);
102
103
  return;
103
104
  }
@@ -168,7 +168,7 @@ const MUSIC_DOM_JS = String.raw`
168
168
  `;
169
169
  const MUSIC_OPEN_JS = `(() => { ${MUSIC_DOM_JS} return Boolean(panel); })()`;
170
170
  const MUSIC_ROWS_JS = `(() => { ${MUSIC_DOM_JS}
171
- return [...new Set(rows.map(nameOf).filter(Boolean))].slice(0, 10);
171
+ return rows.map(nameOf).map(s => String(s || '').trim()).filter(Boolean).slice(0, 20);
172
172
  })()`;
173
173
  const MUSIC_TAB_JS = `(() => { ${MUSIC_DOM_JS}
174
174
  if (!panel) return false;
@@ -259,7 +259,9 @@ async function grabRecommendedMusic(br) {
259
259
  return Array.isArray(list) && list.length ? list : null;
260
260
  }, { tries: 12, gapMs: 800 });
261
261
  if (!songs) return { ok: false, error: '音乐面板没有加载出推荐歌曲' };
262
- return { ok: true, songs };
262
+ const counts = {};
263
+ for (const name of songs) counts[name] = (counts[name] ?? 0) + 1;
264
+ return { ok: true, songs: [...new Set(songs)].slice(0, 10), counts };
263
265
  }
264
266
 
265
267
  /** 关掉音乐面板,避免失败后影响下一次操作。 */
@@ -278,22 +280,27 @@ async function shutMusicPanel(br) {
278
280
  })()`).catch(() => false);
279
281
  }
280
282
 
281
- /** 仅点击匹配歌曲卡片内的「使用」,并在编辑区确认歌名后才允许发布。 */
282
- async function pickNoteMusic(br, music) {
283
+ /** 仅点击匹配歌曲卡片内的「使用」,并在编辑区确认歌名后才允许发布。
284
+ * allowDuplicate:推荐里同名卡不止一张时点第一张。编辑页仍要确认歌名,确认不了就不发布。 */
285
+ async function pickNoteMusic(br, music, { allowDuplicate = false } = {}) {
283
286
  if (!music) return { ok: false, error: '模型没有选出推荐歌曲' };
284
287
  try {
285
288
  const card = await br.eval(`(() => { ${MUSIC_DOM_JS}
286
289
  const matches = rows.filter(row => nameOf(row) === ${JSON.stringify(music)});
287
- if (matches.length !== 1) return { count: matches.length };
288
- matches[0].scrollIntoView({ block: 'center' });
289
- const r = matches[0].getBoundingClientRect();
290
- return { count: 1, x: Math.round(r.left + r.width / 2), y: Math.round(r.top + r.height / 2) };
290
+ if (!matches.length) return { count: 0 };
291
+ const target = matches.length === 1 || ${allowDuplicate ? 'true' : 'false'} ? matches[0] : null;
292
+ if (!target) return { count: matches.length };
293
+ target.scrollIntoView({ block: 'center' });
294
+ const r = target.getBoundingClientRect();
295
+ return { count: matches.length, x: Math.round(r.left + r.width / 2), y: Math.round(r.top + r.height / 2) };
291
296
  })()`);
292
- if (card?.count !== 1) return { ok: false, error: card?.count ? '推荐列表里有同名歌曲,无法确定选哪首' : '选中的歌曲已不在推荐列表' };
297
+ if (!card?.count) return { ok: false, error: '选中的歌曲已不在推荐列表' };
298
+ // 同名(剪辑版 / 合集版)不整单作废。点第一张,后面仍要编辑页确认歌名。
299
+ if (card.count !== 1 && !allowDuplicate) return { ok: false, error: '推荐列表里有同名歌曲,无法确定选哪首' };
293
300
  await br.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: card.x, y: card.y }, br.sessionId);
294
301
  const btn = await waitFor(() => br.eval(`(() => { ${MUSIC_DOM_JS}
295
302
  const matches = rows.filter(row => nameOf(row) === ${JSON.stringify(music)});
296
- if (matches.length !== 1) return null;
303
+ if (!matches.length || (matches.length !== 1 && !${allowDuplicate ? 'true' : 'false'})) return null;
297
304
  const b = [...matches[0].querySelectorAll('button, [class*="apply-btn"]')].find(x => /^(使用(歌曲)?|配乐|选它)$/.test((x.innerText || '').trim()) && visible(x));
298
305
  if (!b) return null;
299
306
  const r = b.getBoundingClientRect();
@@ -385,9 +392,9 @@ export function douyinSocialDriver(host) {
385
392
  async closeMusicPanel() { await shutMusicPanel(b()); },
386
393
 
387
394
  /** 配乐确认成功后才能点发布。 */
388
- async publishNote({ music, beforeSubmit }) {
395
+ async publishNote({ music, beforeSubmit, allowDuplicate = false }) {
389
396
  const br = b();
390
- const picked = await pickNoteMusic(br, String(music ?? ''));
397
+ const picked = await pickNoteMusic(br, String(music ?? ''), { allowDuplicate });
391
398
  if (!picked.ok) return { ok: false, code: 'MUSIC_FAILED', error: `配乐失败,未发布:${picked.error}` };
392
399
  if (beforeSubmit) await beforeSubmit(); // 在可能产生平台副作用之前持久化
393
400
  const clicked = await br.eval(String.raw`(() => {
@@ -718,10 +725,11 @@ export class DouyinSocial extends SocialBase {
718
725
  try {
719
726
  const list = await this.driver.listRecommendedMusic();
720
727
  if (!list?.ok) return { ok: false, error: `配乐失败,未发布:${list?.error ?? '无法读取推荐歌曲'}` };
721
- song = await this.chooseMusic(text, list.songs);
728
+ const choice = await this.chooseMusic(text, list.songs, list.counts);
729
+ song = choice.song;
722
730
  if (!song) return { ok: false, error: '配乐失败,未发布:模型没有选出推荐歌曲' };
723
731
  this.postJobs.prepared(jobId, file, song);
724
- return await this.driver.publishNote({ music: song, beforeSubmit: () => this.postJobs.submitting(jobId) });
732
+ return await this.driver.publishNote({ music: song, allowDuplicate: choice.duplicate, beforeSubmit: () => this.postJobs.submitting(jobId) });
725
733
  } finally {
726
734
  // 自定义 driver(testHooks.douyinSocial)可能没这个方法;它挂在 finally 里,
727
735
  // 抛出去会盖掉真正的失败原因。
@@ -737,14 +745,16 @@ export class DouyinSocial extends SocialBase {
737
745
  return '';
738
746
  }
739
747
 
740
- /** 从抖音推荐的歌里挑一首配这条图文;挑不出来返回空。 */
741
- async chooseMusic(text, songs) {
742
- const list = (Array.isArray(songs) ? songs : []).map((s) => String(s ?? '').trim()).filter(Boolean).slice(0, 10);
743
- if (!list.length) return '';
748
+ /** 从抖音推荐的歌里挑一首。挑不出来 song 为空。duplicate 表示这个名字在推荐里不止一张卡。 */
749
+ async chooseMusic(text, songs, counts = null) {
750
+ const names = (Array.isArray(songs) ? songs : []).map((s) => String(s ?? '').trim()).filter(Boolean);
751
+ const list = [...new Set(names)].slice(0, 10);
752
+ if (!list.length) return { song: '', duplicate: false };
744
753
  try {
745
754
  const raw = String((await this.callLlm(`给这条抖音图文配背景音乐。从下面这些抖音推荐歌里挑一首最适合的(歌名原样照抄),不适合就回空串。\n\n图文正文:\n${text}\n\n推荐歌:\n${list.map((s) => `- ${s}`).join('\n')}\n\n只输出歌名,不要别的。`)) ?? '').trim();
746
- const picked = pickRecommendedSong(raw, list);
747
- return picked;
755
+ const song = pickRecommendedSong(raw, list);
756
+ const n = counts && typeof counts === 'object' ? Number(counts[song]) || 0 : names.filter((s) => s === song).length;
757
+ return { song, duplicate: song !== '' && n > 1 };
748
758
  } catch { throw new Error('配乐失败,未发布:模型选歌调用出错'); }
749
759
  }
750
760
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-fish-soul",
3
- "version": "0.16.5",
3
+ "version": "0.16.6",
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-send-exclusive.mjs && node test/douyin-gap-dedupe.mjs && node test/douyin-message-id-dedupe.mjs && node test/douyin-read-fail-retry.mjs && node test/douyin-read-cache.mjs && node test/douyin-dm-media-conv.mjs && node test/douyin-read-fail-retry-poll.mjs && node test/douyin-inbox-contract.mjs && node test/person-attribution.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-person-merge.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/douyin-cdp-cursor.mjs && node test/persona-isolation.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/issue-98-self-archive.mjs && node test/issue-99-memory-order.mjs && node test/issue-78-diagnostic.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/group-mention-only.mjs && node test/issue-59-interject.mjs && node test/issue-59-diagnose.mjs && node test/sticker-backfill.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-stranger-dm.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/issue-101-voice-files.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/release-workflow.mjs && node test/sticker-import-gif.mjs && node test/sticker-real-gif.mjs && node test/sticker-upload-binary.mjs && node test/sticker-vision-tags.mjs && node test/sticker-manual-tags.mjs && node test/sticker-auto-name.mjs && node test/self-update.mjs && node test/group-list.mjs && node test/douyin-inbox-noise.mjs && node test/douyin-inbox-diag.mjs && node test/douyin-inbox-stuck.mjs && node test/reply-window.mjs && node test/douyin-sticker-heuristic.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-send-exclusive.mjs && node test/douyin-gap-dedupe.mjs && node test/douyin-message-id-dedupe.mjs && node test/douyin-read-fail-retry.mjs && node test/douyin-read-cache.mjs && node test/douyin-dm-media-conv.mjs && node test/douyin-read-fail-retry-poll.mjs && node test/douyin-inbox-contract.mjs && node test/person-attribution.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-person-merge.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/douyin-cdp-cursor.mjs && node test/douyin-nav-timeout.mjs && node test/persona-isolation.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/issue-98-self-archive.mjs && node test/issue-99-memory-order.mjs && node test/issue-78-diagnostic.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/group-mention-only.mjs && node test/issue-59-interject.mjs && node test/issue-59-diagnose.mjs && node test/sticker-backfill.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-stranger-dm.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/issue-101-voice-files.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/release-workflow.mjs && node test/sticker-import-gif.mjs && node test/sticker-real-gif.mjs && node test/sticker-upload-binary.mjs && node test/sticker-vision-tags.mjs && node test/sticker-manual-tags.mjs && node test/sticker-auto-name.mjs && node test/self-update.mjs && node test/group-list.mjs && node test/douyin-inbox-noise.mjs && node test/douyin-inbox-diag.mjs && node test/douyin-inbox-stuck.mjs && node test/reply-window.mjs && node test/douyin-sticker-heuristic.mjs",
68
68
  "eval": "node test/eval/persona-eval.mjs"
69
69
  }
70
70
  }