dsh-fish-soul 0.18.1 → 0.18.2

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.18.1**。
5
+ DSH 插件(单角色 `feiyu`)。版本 **0.18.2**。
6
6
 
7
7
  QQ 交流群:**1125962189**
8
8
 
@@ -103,8 +103,9 @@ export class DouyinBrowser {
103
103
  * @param {[number, number]} [deps.dwellMs] 推荐页每条看多久(真实毫秒)
104
104
  * @param {(opts: {browser: object, id: string, commentLimit?: number}) => Promise<object>} [deps.readDetail]
105
105
  * @param {import('./douyin-http.js').DouyinHttp} [deps.http] 纯 HTTP 客户端(http 模式用)
106
+ * @param {object} [deps.timing] 页面操作的时间上限(eval / send / next 的总预算)
106
107
  */
107
- constructor({ db, clock, host, getConfig, callLlm, persona, worker, log, dwellMs = [5000, 20000], readDetail = detail, settleMs = 8000, fetchImpl, share, note, http, frames }) {
108
+ constructor({ db, clock, host, getConfig, callLlm, persona, worker, log, dwellMs = [5000, 20000], readDetail = detail, settleMs = 8000, fetchImpl, share, note, http, frames, timing = {} }) {
108
109
  this.share = share ?? null;
109
110
  this.note = note ?? null;
110
111
  this.framesOf = frames ?? null; // 抽九宫格看画面(可缺:没有就只读文字)
@@ -124,6 +125,7 @@ export class DouyinBrowser {
124
125
  this.running = false;
125
126
  this.httpBroken = false; // 这轮试过纯 HTTP 不行 → 退回浏览器
126
127
  this.described = new Map();
128
+ this.tm = { evalTimeoutMs: 12_000, nextBudgetMs: 30_000, ...timing }; // 页面卡死时不能挂死或霸住浏览器锁
127
129
  }
128
130
 
129
131
  cfg() {
@@ -215,32 +217,47 @@ export class DouyinBrowser {
215
217
  return lo + Math.floor(Math.random() * Math.max(0, hi - lo));
216
218
  }
217
219
 
218
- async activeVideo(b) {
219
- const r = await b.eval(ACTIVE_VIDEO_JS).catch(() => null);
220
+ async activeVideo(b, timeoutMs = this.tm.evalTimeoutMs) {
221
+ const r = await b.eval(ACTIVE_VIDEO_JS, { timeoutMs }).catch(() => null);
220
222
  return r && r.ok ? r : null;
221
223
  }
222
224
 
223
225
  /** 划到下一条:先点"下一条"箭头,不行按 ↓,再不行滚轮;确认 id 变了。 */
224
226
  async next(b, prevId) {
227
+ // 页面卡死时 eval 永不回包 ⇒ 每次 eval 都有短超时,整轮还有总预算
228
+ //(只给单次超时不够:8 轮 × 60 秒照样霸着浏览器独占锁)。
229
+ const end = Date.now() + this.tm.nextBudgetMs;
230
+ const left = () => end - Date.now();
231
+ const timeout = () => Math.max(1, Math.min(this.tm.evalTimeoutMs, left()));
232
+ // 预算耗尽后**不能再发起** eval / send / 睡眠:max(1,…) 只防 0,不是通行证。
233
+ // 否则点「下一条」失败后,键盘 / 滚轮分支会各在预算之外再等一次超时,照样霸锁。
234
+ const expired = () => left() <= 0;
225
235
  const changed = async () => {
226
236
  for (let i = 0; i < 8; i++) {
227
- await sleep(400);
228
- const v = await this.activeVideo(b);
237
+ if (expired()) return false;
238
+ await sleep(Math.min(400, Math.max(0, left())));
239
+ if (expired()) return false;
240
+ const v = await this.activeVideo(b, timeout());
229
241
  if (v && v.id && v.id !== prevId) return true;
230
242
  }
231
243
  return false;
232
244
  };
233
- if (await b.eval(CLICK_NEXT_JS).catch(() => false) && await changed()) return true;
245
+ if (expired()) return false;
246
+ if (await b.eval(CLICK_NEXT_JS, { timeoutMs: timeout() }).catch(() => false) && await changed()) return true;
247
+ if (expired()) return false;
234
248
  try {
235
249
  for (const type of ['keyDown', 'keyUp']) {
236
- await b.send('Input.dispatchKeyEvent', { type, key: 'ArrowDown', code: 'ArrowDown', windowsVirtualKeyCode: 40, nativeVirtualKeyCode: 40 }, b.sessionId);
250
+ if (expired()) return false;
251
+ await b.send('Input.dispatchKeyEvent', { type, key: 'ArrowDown', code: 'ArrowDown', windowsVirtualKeyCode: 40, nativeVirtualKeyCode: 40 }, b.sessionId, timeout());
237
252
  }
238
253
  if (await changed()) return true;
239
254
  } catch { /* 换滚轮 */ }
255
+ if (expired()) return false;
240
256
  try {
241
- const m = await b.send('Page.getLayoutMetrics', {}, b.sessionId);
257
+ const m = await b.send('Page.getLayoutMetrics', {}, b.sessionId, timeout());
242
258
  const vp = m?.cssVisualViewport ?? {};
243
- await b.send('Input.dispatchMouseEvent', { type: 'mouseWheel', x: Math.round((vp.clientWidth ?? 800) / 2), y: Math.round((vp.clientHeight ?? 600) / 2), deltaX: 0, deltaY: 600 }, b.sessionId);
259
+ if (expired()) return false;
260
+ await b.send('Input.dispatchMouseEvent', { type: 'mouseWheel', x: Math.round((vp.clientWidth ?? 800) / 2), y: Math.round((vp.clientHeight ?? 600) / 2), deltaX: 0, deltaY: 600 }, b.sessionId, timeout());
244
261
  if (await changed()) return true;
245
262
  } catch { /* 划不动 */ }
246
263
  return false;
@@ -257,13 +274,13 @@ export class DouyinBrowser {
257
274
  const r = el.getBoundingClientRect();
258
275
  if (r.width < 2 || r.height < 2) return null;
259
276
  return { x: r.x + r.width / 2, y: r.y + r.height / 2, w: r.width, h: r.height };
260
- })()`).catch(() => null);
277
+ })()`, { timeoutMs: this.tm.evalTimeoutMs }).catch(() => null);
261
278
  if (!pos || typeof pos.x !== 'number') return false;
262
- const m = await b.send('Page.getLayoutMetrics', {}, b.sessionId).catch(() => null);
279
+ const m = await b.send('Page.getLayoutMetrics', {}, b.sessionId, this.tm.evalTimeoutMs).catch(() => null);
263
280
  const vp = m?.cssVisualViewport ?? m?.cssLayoutViewport ?? {};
264
281
  if (pos.x < 0 || pos.y < 0 || pos.x > (vp.clientWidth ?? 0) || pos.y > (vp.clientHeight ?? 0)) return false;
265
282
  for (const type of ['mouseMoved', 'mousePressed', 'mouseReleased']) {
266
- await b.send('Input.dispatchMouseEvent', { type, x: Math.round(pos.x), y: Math.round(pos.y), button: 'left', clickCount: type === 'mouseMoved' ? 0 : 1 }, b.sessionId);
283
+ await b.send('Input.dispatchMouseEvent', { type, x: Math.round(pos.x), y: Math.round(pos.y), button: 'left', clickCount: type === 'mouseMoved' ? 0 : 1 }, b.sessionId, this.tm.evalTimeoutMs);
267
284
  }
268
285
  await sleep(3000);
269
286
  return await this.activeVideo(b) !== null;
@@ -445,8 +462,8 @@ export class DouyinBrowser {
445
462
  const b = this.host?.running === true ? this.host?.browser : null;
446
463
  if (b && typeof b.eval === 'function') {
447
464
  try {
448
- if (!(await commentBridgeReady(b))) await installCommentBridge(b);
449
- const r = await callBridge(b, 'collect', { awemeId: v.id, collect: true });
465
+ if (!(await commentBridgeReady(b, { timeoutMs: this.tm.evalTimeoutMs }))) await installCommentBridge(b, { timeoutMs: this.tm.evalTimeoutMs });
466
+ const r = await callBridge(b, 'collect', { awemeId: v.id, collect: true }, { timeoutMs: this.tm.evalTimeoutMs });
450
467
  if (r?.ok === true) {
451
468
  collected = r.collected !== false;
452
469
  done = true;
@@ -520,8 +537,8 @@ export class DouyinBrowser {
520
537
  // 两条都走会让同一条视频被赞两次(一个走接口、一个走 UI)。
521
538
  let bridgeRan = false;
522
539
  try {
523
- if (!(await commentBridgeReady(b))) await installCommentBridge(b);
524
- const r = await callBridge(b, 'digg', { awemeId: v.id, diggType: 1 });
540
+ if (!(await commentBridgeReady(b, { timeoutMs: this.tm.evalTimeoutMs }))) await installCommentBridge(b, { timeoutMs: this.tm.evalTimeoutMs });
541
+ const r = await callBridge(b, 'digg', { awemeId: v.id, diggType: 1 }, { timeoutMs: this.tm.evalTimeoutMs });
525
542
  // 这两种「失败」说明的是**这个页面用不了桥**(不是"没赞上"),要退回点按钮:
526
543
  // - 桥没装上(window.__fishComment 不存在)
527
544
  // - 桥发出了请求但拿回的不是 JSON(页面不是真抖音,比如测试用的本地假站)
@@ -540,7 +557,7 @@ export class DouyinBrowser {
540
557
  this.log('warn', `[fish-soul] 抖音点赞接口桥失败:${errText(error)},退回点按钮`);
541
558
  }
542
559
  if (!bridgeRan) {
543
- try { liked = await b.eval(CLICK_LIKE_JS) === true; } catch { liked = false; }
560
+ try { liked = await b.eval(CLICK_LIKE_JS, { timeoutMs: this.tm.evalTimeoutMs }) === true; } catch { liked = false; }
544
561
  }
545
562
  }
546
563
  // 收藏:和点赞同一族(commit/* 写接口,必须页面内发)。
@@ -548,8 +565,8 @@ export class DouyinBrowser {
548
565
  let collected = false;
549
566
  if (wantCollect) {
550
567
  try {
551
- if (!(await commentBridgeReady(b))) await installCommentBridge(b);
552
- const r = await callBridge(b, 'collect', { awemeId: v.id, collect: true });
568
+ if (!(await commentBridgeReady(b, { timeoutMs: this.tm.evalTimeoutMs }))) await installCommentBridge(b, { timeoutMs: this.tm.evalTimeoutMs });
569
+ const r = await callBridge(b, 'collect', { awemeId: v.id, collect: true }, { timeoutMs: this.tm.evalTimeoutMs });
553
570
  if (r?.ok === true) {
554
571
  collected = r.collected !== false;
555
572
  if (r.confirmed === false) this.log('info', '[fish-soul] 抖音收藏提交了(返回里没有 collect_stat,按成功算)');
@@ -652,8 +652,8 @@ export function douyinSocialDriver(host, timing = {}) {
652
652
  async emojiCodes() {
653
653
  const br = b();
654
654
  if (!this._emojiCodes) {
655
- if (!(await commentBridgeReady(br))) await installCommentBridge(br);
656
- const r = await callBridge(br, 'emojiList', {});
655
+ if (!(await commentBridgeReady(br, { timeoutMs: tm.evalTimeoutMs }))) await installCommentBridge(br, { timeoutMs: tm.evalTimeoutMs });
656
+ const r = await callBridge(br, 'emojiList', {}, { timeoutMs: tm.evalTimeoutMs });
657
657
  this._emojiCodes = r.ok ? (r.list || []).map((e) => e.name).filter(Boolean) : [];
658
658
  this._emojiCodesAt = Date.now();
659
659
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-fish-soul",
3
- "version": "0.18.1",
3
+ "version": "0.18.2",
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/douyin-nav-timeout.mjs && node test/persona-isolation.mjs && node test/smoke.mjs && node test/douyin-browser.mjs && node test/douyin-page-alive.mjs && node test/douyin-eval-timeout.mjs && node test/douyin-goto-budget.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-115-memory-date.mjs && node test/issue-119-memory-page.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/qq-private-allowlist.mjs && node test/issue-59-interject.mjs && node test/issue-59-diagnose.mjs && node test/sticker-backfill.mjs && node test/issue-118-sticker-diagnostics.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/douyin-comment-write-unknown.mjs && node test/douyin-reply-verify-status.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/issue-113-desktop-archive.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 && node test/douyin-image-boundary.mjs && node test/media-image-boundary.mjs && node test/douyin-comment-identity-cid.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-page-alive.mjs && node test/douyin-eval-timeout.mjs && node test/douyin-bridge-timeout.mjs && node test/douyin-goto-budget.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-115-memory-date.mjs && node test/issue-119-memory-page.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/qq-private-allowlist.mjs && node test/issue-59-interject.mjs && node test/issue-59-diagnose.mjs && node test/sticker-backfill.mjs && node test/issue-118-sticker-diagnostics.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/douyin-comment-write-unknown.mjs && node test/douyin-reply-verify-status.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/issue-113-desktop-archive.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 && node test/douyin-image-boundary.mjs && node test/media-image-boundary.mjs && node test/douyin-comment-identity-cid.mjs",
68
68
  "eval": "node test/eval/persona-eval.mjs"
69
69
  }
70
70
  }