dsh-fish-soul 0.19.30 → 0.19.32

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.19.30**。
5
+ DSH 插件(单角色 `feiyu`)。版本 **0.19.32**。
6
6
 
7
7
  QQ 交流群:**1125962189**
8
8
 
@@ -11,6 +11,7 @@ window.__ModuleLoader__.load({
11
11
  const react = require("react");
12
12
  const CUSTOM = "__custom__";
13
13
  const WINDOW_MODES = [{ value: "background", label: "藏在后台" }, { value: "visible", label: "正常显示" }];
14
+ const CLI_BACKENDS = [{ value: "browser", label: "专用浏览器" }, { value: "hybrid", label: "CLI 混合模式" }];
14
15
  // 视频服务商:值必须跟 lib/video-gen.js 的 PROVIDERS 一致(改了那边这里就对不上了)。
15
16
  const VIDEO_PROVIDERS = [
16
17
  { value: "volc", label: "火山方舟" },
@@ -64,6 +65,41 @@ window.__ModuleLoader__.load({
64
65
  shot === null ? Empty(Dot("ongoing")) : h("img", { alt: "抖音浏览器截图", src: shot.image, draggable: false }));
65
66
  }
66
67
 
68
+ /** 抖音开放 CLI 扫码登录视图:展示二维码并自动轮询 /douyin/cli/login/complete。 */
69
+ function CliQrView({ login, api, notify, onDone, onCancel, ui }) {
70
+ const { h, Button, Muted, State } = ui;
71
+ const [statusText, setStatusText] = react.useState("请用抖音 App 扫码并确认授权");
72
+ const aliveRef = react.useRef(true);
73
+ const timerRef = react.useRef(null);
74
+ react.useEffect(() => {
75
+ aliveRef.current = true;
76
+ const pollMs = Math.max(2, Number(login?.retryAfterSeconds) || 3) * 1000;
77
+ const poll = async () => {
78
+ const r = await api("POST", "/douyin/cli/login/complete", {});
79
+ if (!aliveRef.current) return;
80
+ if (r?.ok && r.loggedIn) {
81
+ notify("抖音开放 CLI 扫码授权成功");
82
+ onDone();
83
+ return;
84
+ }
85
+ if (r?.ok && r.status === "pending") {
86
+ const nextMs = Math.max(2, Number(r.retryAfterSeconds) || 3) * 1000;
87
+ timerRef.current = setTimeout(poll, nextMs);
88
+ return;
89
+ }
90
+ setStatusText(r?.error || "扫码已过期或取消,请重新获取二维码");
91
+ };
92
+ timerRef.current = setTimeout(poll, pollMs);
93
+ return () => { aliveRef.current = false; if (timerRef.current) clearTimeout(timerRef.current); };
94
+ }, [login, api, notify, onDone]);
95
+ return h("div", { className: "fs-card", style: { display: "flex", flexDirection: "column", alignItems: "center", gap: 8, padding: 12, marginTop: 8 } },
96
+ login?.qrDataUrl
97
+ ? h("img", { alt: "抖音开放 CLI 登录二维码", src: login.qrDataUrl, draggable: false, style: { width: 180, height: 180, borderRadius: 8 } })
98
+ : (login?.verificationUrl ? h("a", { href: login.verificationUrl, target: "_blank", rel: "noreferrer" }, "打开抖音授权链接") : State("warning", "未返回二维码图片")),
99
+ Muted(statusText),
100
+ Button({ variant: "ghost", onClick: onCancel }, "取消扫码"));
101
+ }
102
+
67
103
  const HOST_STATE = {
68
104
  running: ["done", "运行中"], starting: ["ongoing", "启动中"], checking: ["ongoing", "连接断了,正在检查"], closing: ["ongoing", "正在关闭"],
69
105
  paused: ["idle", "已暂停"], stopped: ["idle", "未运行"], error: ["error", "出错了"]
@@ -81,6 +117,10 @@ window.__ModuleLoader__.load({
81
117
  const [showShot, setShowShot] = react.useState(false);
82
118
  const [framesPerDay, setFramesPerDay] = react.useState("");
83
119
  const [noteText, setNoteText] = react.useState("");
120
+ const [cliStatus, setCliStatus] = react.useState(null);
121
+ const [cliBusy, setCliBusy] = react.useState(false);
122
+ const [cliLogin, setCliLogin] = react.useState(null);
123
+ const [showCliAdv, setShowCliAdv] = react.useState(false);
84
124
  react.useEffect(() => { if (framesPerDay === "" && br.framesPerDay !== undefined) setFramesPerDay(String(br.framesPerDay)); }, [br.framesPerDay]);
85
125
  // 待确认的抖音身份(昵称配了但还没主人确认过)。
86
126
  // 放在面板里而不是自动绑定 —— 主人是唯一能看懂 uid 的人。
@@ -92,6 +132,18 @@ window.__ModuleLoader__.load({
92
132
  } catch { setCandidates([]); }
93
133
  }, [api]);
94
134
  react.useEffect(() => { void loadCandidates(); }, [loadCandidates]);
135
+ const loadCliStatus = react.useCallback(async () => {
136
+ setCliBusy(true);
137
+ try {
138
+ const r = await api("POST", "/douyin/cli/status", {});
139
+ setCliStatus(r ?? { ok: false, error: "无法获取 CLI 状态" });
140
+ } catch {
141
+ setCliStatus({ ok: false, error: "检查 CLI 状态失败" });
142
+ } finally {
143
+ setCliBusy(false);
144
+ }
145
+ }, [api]);
146
+ react.useEffect(() => { void loadCliStatus(); }, [loadCliStatus]);
95
147
  const [form, , patch] = useForm(data, () => ({
96
148
  masterName: d.masterName ?? "", masterUid: d.masterUid ?? "", allowList: (d.allowList ?? []).join("\n"), links: (d.links ?? []).join("\n"),
97
149
  groups: (d.groups ?? []).join("\n"), callNames: (d.callNames ?? []).join("\n"),
@@ -106,11 +158,15 @@ window.__ModuleLoader__.load({
106
158
  videoDurationSec: d.video?.durationSec ?? 5,
107
159
  videoAspect: d.video?.aspectRatio ?? "9:16",
108
160
  videoResolution: d.video?.resolution ?? "768P",
109
- videoPerDay: d.video?.perDay ?? 1
161
+ videoPerDay: d.video?.perDay ?? 1,
162
+ cliBinaryPath: d.cli?.binaryPath ?? "douyin-open-cli",
163
+ cliAuthDir: d.cli?.authDir ?? ""
110
164
  }));
111
165
  const so = d.social ?? {};
112
166
  const post = d.post ?? {};
113
167
  const video = d.video ?? {};
168
+ const cli = d.cli ?? {};
169
+ const cliHybrid = cli.socialBackend === "hybrid";
114
170
  const cm = d.comments ?? {};
115
171
  const socialLog = [
116
172
  ...(so.post?.recent ?? []).map((x, i) => ({ key: `p${i}${x.at}`, tag: Tag("图文", "outline"), text: x.content, at: x.at })),
@@ -149,7 +205,14 @@ window.__ModuleLoader__.load({
149
205
  perDay: Number(form.videoPerDay),
150
206
  ...(p.video ?? {})
151
207
  },
152
- comments: { perHour: Number(form.commentsPerHour), ...(p.comments ?? {}) }
208
+ comments: { perHour: Number(form.commentsPerHour), ...(p.comments ?? {}) },
209
+ cli: {
210
+ socialBackend: cli.socialBackend === "hybrid" ? "hybrid" : "browser",
211
+ binaryPath: String(form.cliBinaryPath ?? "").trim() || "douyin-open-cli",
212
+ authDir: String(form.cliAuthDir ?? "").trim(),
213
+ browseText: cli.browseText === true,
214
+ ...(p.cli ?? {})
215
+ }
153
216
  }, null, "保存失败");
154
217
  if (r?.ok && hadKey) patch({ videoApiKey: "" });
155
218
  return r;
@@ -186,6 +249,28 @@ window.__ModuleLoader__.load({
186
249
  const copy = async () => {
187
250
  try { await navigator.clipboard.writeText(reportText); notify("已复制"); } catch { notify("复制失败,手动选中复制"); }
188
251
  };
252
+ const beginCliLogin = async (force = false) => {
253
+ setCliBusy(true);
254
+ try {
255
+ const r = await api("POST", "/douyin/cli/login/begin", { force });
256
+ if (!r?.ok) { notify(r?.error ?? "发起 CLI 扫码失败"); return; }
257
+ if (r.alreadyLoggedIn) {
258
+ notify("抖音开放 CLI 已处于登录状态");
259
+ setCliLogin(null);
260
+ void loadCliStatus();
261
+ return;
262
+ }
263
+ setCliLogin(r);
264
+ } finally {
265
+ setCliBusy(false);
266
+ }
267
+ };
268
+ const cliStateNode = cliStatus === null ? State("idle", "检查中")
269
+ : !cliStatus.ok ? State("error", cliStatus.code === "CLI_NOT_FOUND" ? "未安装 CLI" : (cliStatus.error || "不可用"))
270
+ : cliStatus.loggedIn && (cliStatus.missingScopes?.length ?? 0) === 0 ? State("done", "已授权")
271
+ : cliStatus.loggedIn ? State("warning", `缺少权限:${cliStatus.missingScopes.join(" / ")}`)
272
+ : cliStatus.tokenExpired && !cliStatus.reauthRequired ? State("warning", "Token 将自动续期")
273
+ : State("warning", "未扫码登录");
189
274
  const recent = d.recent ?? [];
190
275
  const browseOn = br.enabled === true;
191
276
 
@@ -209,6 +294,19 @@ window.__ModuleLoader__.load({
209
294
  running && d.window !== "visible" ? Button({ disabled: busy, onClick: () => act("/douyin/window", { show: !d.windowShown }, null, "窗口挪不动") }, d.windowShown ? "藏起来" : "显示一下") : null,
210
295
  h(Seg, { label: "窗口", value: d.window === "visible" ? "visible" : "background", options: WINDOW_MODES, onChange: (v) => save({ top: { window: v } }) })),
211
296
  running && (host.loggedIn !== true || showShot) ? h(LoginView, { api, notify, refresh, ui }) : null),
297
+ Group({ title: "抖音开放 CLI" },
298
+ Row({ title: "社交后端", desc: cliHybrid ? "发短视频与回评论走官方 douyin-open-cli(免浏览器锁、免创作者中心登录);图文与私信保留浏览器" : "默认全部走专用浏览器;切到 CLI 混合模式可大幅提升发视频和回评论稳定性" },
299
+ h(Seg, { label: "社交后端", value: cliHybrid ? "hybrid" : "browser", options: CLI_BACKENDS, onChange: (v) => save({ cli: { socialBackend: v } }) })),
300
+ Row({ title: "CLI 授权", desc: "扫码一次后双 Token 自动续期;缺权限时可点「重新扫码」补齐" }, cliStateNode,
301
+ IconButton("refresh", "检查 CLI 状态", loadCliStatus, { disabled: cliBusy }),
302
+ Button({ variant: cliStatus?.loggedIn ? "outline" : "primary", disabled: cliBusy, onClick: () => beginCliLogin(Boolean(cliStatus?.loggedIn)) }, cliLogin ? "刷新二维码" : (cliStatus?.loggedIn ? "重新扫码" : "扫码登录"))),
303
+ cliLogin ? h(CliQrView, { login: cliLogin, api, notify, onDone: () => { setCliLogin(null); void loadCliStatus(); refresh(); }, onCancel: () => setCliLogin(null), ui }) : null,
304
+ Row({ title: "刷视频补强口播文本", desc: "刷视频或读分享链接时可选调 CLI video text 获取官方口播/字幕摘要,失败静默降级" },
305
+ sw("刷视频补强口播文本", cli.browseText === true, (v) => save({ cli: { browseText: v } }))),
306
+ Row({ title: "高级路径", desc: "默认从系统 PATH 查找 douyin-open-cli 并使用默认凭证目录" },
307
+ Button({ variant: "ghost", "aria-expanded": showCliAdv, onClick: () => setShowCliAdv(!showCliAdv) }, showCliAdv ? "收起" : "展开")),
308
+ showCliAdv ? Row({ title: "CLI 可执行路径" }, Input({ ...bind("cliBinaryPath"), "aria-label": "CLI 可执行路径", placeholder: "douyin-open-cli" })) : null,
309
+ showCliAdv ? Row({ title: "CLI 凭证目录", desc: "留空使用默认目录;填写时必须为绝对路径" }, Input({ ...bind("cliAuthDir"), "aria-label": "CLI 凭证目录", placeholder: "绝对路径(可选)" })) : null),
212
310
  Group({ title: "私信" },
213
311
  d.channel?.identityBlocked
214
312
  ? Row({ title: "私信身份未就绪", meta: d.channel?.identityState?.disabledByFlag ? "已被 DOUYIN_IDENTITY_BLOCKED 手动停用" : "尚未学到这个抖音号自己的 uid,正常聊过一轮后自动学到" },
@@ -285,9 +383,9 @@ window.__ModuleLoader__.load({
285
383
  Button({ disabled: busy || so.postPending.status !== "unknown", onClick: () => act("/douyin/post-resolve", { jobId: so.postPending.id, outcome: "published" }, "已记录为已发布", "记录失败") }, "已核实已发布")) : null),
286
384
  Group({ title: "AI 视频生成", aside: video.enabled ? Tag(`今天视频 ${so.video?.todayCount ?? 0} / ${video.perDay ?? 1}`, "outline") : null },
287
385
  // 视频:生成要调付费接口(按条计费)—— 开关旁边必须写清楚这是花钱的操作,点击前也要二次确认。
288
- Row({ title: "自己发视频", desc: "生成视频要调用付费接口(按条计费),每发一条都真花钱;创作者中心也要先登录过" },
289
- video.enabled ? Button({ variant: "ghost", disabled: busy || so.video?.running === true || so.post?.running === true || Boolean(so.postPending) || d.enabled !== true || !running, onClick: async () => {
290
- const ok = await confirm({ title: "确认生成并发布视频?", description: "将调用已配置的付费视频接口(按条计费),完成后自动上传到抖音创作者中心并发布。", confirmLabel: "开始生成并发布" });
386
+ Row({ title: "自己发视频", desc: cliHybrid ? "生成视频要调用付费接口(按条计费);当前已切到 CLI 混合模式,无需开启专用浏览器" : "生成视频要调用付费接口(按条计费),每发一条都真花钱;创作者中心也要先登录过" },
387
+ video.enabled ? Button({ variant: "ghost", disabled: busy || so.video?.running === true || so.post?.running === true || Boolean(so.postPending) || d.enabled !== true || (!running && !cliHybrid), onClick: async () => {
388
+ const ok = await confirm({ title: "确认生成并发布视频?", description: cliHybrid ? "将调用已配置的付费视频接口(按条计费),完成后通过 douyin-open-cli 自动上传并发布。" : "将调用已配置的付费视频接口(按条计费),完成后自动上传到抖音创作者中心并发布。", confirmLabel: "开始生成并发布" });
291
389
  if (ok) await act("/douyin/video-now", {}, "已开始生成视频,完成后会自动发布", "没发成");
292
390
  } }, so.video?.running ? "正在发…" : "现在发一条视频") : null,
293
391
  sw("自己发视频", video.enabled === true, (v) => save({ video: { enabled: v } }))),
@@ -310,8 +408,8 @@ window.__ModuleLoader__.load({
310
408
  Button({ disabled: busy || so.postPending.status !== "unknown", onClick: () => act("/douyin/post-resolve", { jobId: so.postPending.id, outcome: "not_published" }, "已记录为未发布", "记录失败") }, "已核实未发布"),
311
409
  Button({ disabled: busy || so.postPending.status !== "unknown", onClick: () => act("/douyin/post-resolve", { jobId: so.postPending.id, outcome: "published" }, "已记录为已发布", "记录失败") }, "已核实已发布")) : null),
312
410
  Group({ title: "评论互动" },
313
- Row({ title: "回评论", desc: "每 20 分钟看看最近 3 个作品的评论区;抖音可能要短信验证,碰到会停下来提醒你" },
314
- cm.enabled ? Button({ disabled: busy || d.enabled !== true || !running, onClick: () => act("/douyin/comments-now", {}, "看完了", "没看成") }, "现在看一眼") : null,
411
+ Row({ title: "回评论", desc: cliHybrid ? "每 20 分钟通过 douyin-open-cli 检查最近 3 个作品的评论区(免浏览器锁)" : "每 20 分钟看看最近 3 个作品的评论区;抖音可能要短信验证,碰到会停下来提醒你" },
412
+ cm.enabled ? Button({ disabled: busy || d.enabled !== true || (!running && !cliHybrid), onClick: () => act("/douyin/comments-now", {}, "看完了", "没看成") }, "现在看一眼") : null,
315
413
  sw("回评论", cm.enabled === true, (v) => save({ comments: { enabled: v } }))),
316
414
  cm.enabled ? Row({ title: "每小时最多" }, Num({ min: 0, max: 30, "aria-label": "每小时最多回几条", ...bind("commentsPerHour") }), Muted("条")) : null,
317
415
  cm.enabled ? Row({ title: "允许发表情", desc: "把抖音的表情码([微笑] 这种)写进提示词,平台会自动渲染成表情图" },
@@ -130,6 +130,12 @@ export function douyinConfigSchema(z) {
130
130
  perHour: z.number().default(4),
131
131
  replyChars: z.number().min(10).max(300).default(40),
132
132
  emoji: z.boolean().default(false)
133
+ }).default({}),
134
+ cli: z.object({ // 抖音开放 CLI(douyin-open-cli)混合驱动配置
135
+ socialBackend: z.string().default('browser'), // browser | hybrid
136
+ binaryPath: z.string().default('douyin-open-cli'),
137
+ authDir: z.string().default(''),
138
+ browseText: z.boolean().default(false)
133
139
  }).default({})
134
140
  }).default({});
135
141
  }
@@ -144,7 +144,7 @@ export class DouyinBrowser {
144
144
  * @param {import('./douyin-http.js').DouyinHttp} [deps.http] 纯 HTTP 客户端(http 模式用)
145
145
  * @param {object} [deps.timing] 页面操作的时间上限(eval / send / next 的总预算)
146
146
  */
147
- constructor({ db, clock, host, getConfig, callLlm, persona, worker, log, dwellMs = [5000, 20000], readDetail = detail, settleMs = 8000, fetchImpl, share, shareFallback, note, http, frames, timing = {} }) {
147
+ constructor({ db, clock, host, getConfig, callLlm, persona, worker, log, dwellMs = [5000, 20000], readDetail = detail, settleMs = 8000, fetchImpl, share, shareFallback, note, http, cli = null, frames, timing = {} }) {
148
148
  this.share = share ?? null;
149
149
  // #133:同上 —— 漏了这个参数兜底就是死代码。
150
150
  this.shareFallback = shareFallback ?? null;
@@ -163,6 +163,7 @@ export class DouyinBrowser {
163
163
  this.settleMs = settleMs;
164
164
  this.fetch = fetchImpl ?? ((...a) => fetch(...a));
165
165
  this.http = http ?? null; // 纯 HTTP 客户端(http 模式用;没有就退回浏览器)
166
+ this.cli = cli ?? null; // 可选:用 douyin-open-cli video text 补强视频口播/高质量文本
166
167
  this.running = false;
167
168
  this.httpBroken = false; // 这轮试过纯 HTTP 不行 → 退回浏览器
168
169
  this.described = new Map();
@@ -464,6 +465,8 @@ export class DouyinBrowser {
464
465
  imageCount: sum.imageCount,
465
466
  comments: (cm.ok ? cm.list : []).map((c) => ({ text: String(c.text ?? ''), author: String(c.user?.nickname ?? '') }))
466
467
  };
468
+ const cliText = await this.cliTextFor(v.id);
469
+ if (cliText !== '') v.ocr = v.ocr ? `${v.ocr};${cliText}` : cliText;
467
470
  // 抽帧看画面(默认关):九宫格 → 再让模型读成一句话,塞进这段感受里。
468
471
  // 和 B站 那条一个套路:拿不到就照旧只看文字,不影响她看完这条。
469
472
  const shot = await this.frameForWatch(d, v.id);
@@ -764,12 +767,25 @@ export class DouyinBrowser {
764
767
  const sum = extractWorkSummary(d, cm.ok ? cm.list : []);
765
768
  // 抽帧看画面(默认关,共用"自己刷视频"那个开关与每日配额):
766
769
  // 私信里分享的视频也该看得见画面,不能只给文案 + 热评(用户反馈 2026-11-25)。
770
+ const cliText = await this.cliTextFor(id);
767
771
  const shot = sum.imageCount > 0 ? '' : await this.frameForWatch(d, id);
768
772
  return `【抖音${sum.imageCount > 0 ? '图文' : '视频'}:${oneLine(sum.title, 120) || '(没有文案)'};作者 ${oneLine(sum.author, 20) || '未知'}`
769
773
  + (sum.imageCount > 0 ? `;共 ${sum.imageCount} 张图` : '')
770
774
  + (sum.music ? `;BGM:${oneLine(sum.music, 40)}` : '')
771
775
  + (sum.ocr ? `;画面文字:${oneLine(sum.ocr, 80)}` : '')
776
+ + (cliText ? `;视频文本:${oneLine(cliText, 120)}` : '')
772
777
  + (shot ? `;画面:${shot}` : '')
773
778
  + (sum.topComments.length ? `;热评:${sum.topComments.join(' / ')}` : '') + '】';
774
779
  }
780
+
781
+ /** 开了 douyin.cli.browseText 时调 CLI 拿官方高质量文本;失败静默退回空串,不阻断看视频。 */
782
+ async cliTextFor(id) {
783
+ if (!this.cli || this.getConfig()?.cli?.browseText !== true) return '';
784
+ try {
785
+ const r = await this.cli.videoText(id);
786
+ return r?.ok ? oneLine(r.text, 200) : '';
787
+ } catch {
788
+ return '';
789
+ }
790
+ }
775
791
  }