dsh-fish-soul 0.19.31 → 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.31**。
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: "把抖音的表情码([微笑] 这种)写进提示词,平台会自动渲染成表情图" },
@@ -37,7 +37,7 @@ export function douyinSocialCliDriver(cli, { log } = {}) {
37
37
  return { ok: false, code: st.code === 'CLI_NOT_FOUND' ? 'CLI_NOT_FOUND' : 'NOT_LOGGED_IN', error: st.error || '抖音 CLI 未就绪' };
38
38
  }
39
39
  if (!st.loggedIn) {
40
- return { ok: false, code: 'NOT_LOGGED_IN', error: '抖音开放 CLI 还没扫码登录,请先调用 /douyin/cli/login/begin 或在终端运行 douyin-open-cli auth login 完成扫码授权' };
40
+ return { ok: false, code: 'NOT_LOGGED_IN', error: '抖音开放 CLI 还没扫码登录,请先在设置页「抖音 → 抖音开放 CLI」里扫码授权' };
41
41
  }
42
42
  if (!DouyinCli.hasScope(st, 'video.create')) {
43
43
  return { ok: false, code: 'NOT_LOGGED_IN', error: '抖音开放 CLI 缺少 video.create 投稿权限,请重新扫码授权' };
@@ -38,12 +38,20 @@ export async function attachWorkIdImpl(driver, published) {
38
38
  }
39
39
 
40
40
  /**
41
- * 自己占锁读一次最新作品 id。
42
- * 只给「人工核实已发布」那条路径用 —— 它不在发布流程里,占一次锁没有副作用。
41
+ * 读一次最新作品 id。
42
+ * 只给「人工核实已发布」那条路径用 —— 它不在发布流程里。
43
+ *
44
+ * 浏览器 driver(videoNeedsBrowserLock !== false):`listWorks` 要打开创作者中心
45
+ * 作品管理页,必须自己占一把浏览器锁,占一次锁没有副作用。
46
+ * hybrid / CLI driver(videoNeedsBrowserLock === false):`listWorks` 走
47
+ * douyin-open-cli 的 video.list,根本不碰浏览器 —— 这时还去抢 `host.exclusive`
48
+ * 只会白白等锁(浏览器可能压根没启动),直接读就行。
43
49
  */
44
50
  export async function readTopWorkIdImpl(host, driver) {
45
51
  try {
46
- const works = await host.exclusive('读回作品 id', () => driver.listWorks(3), { maxMs: 90_000 });
52
+ const works = driver?.videoNeedsBrowserLock === false
53
+ ? await driver.listWorks(3)
54
+ : await host.exclusive('读回作品 id', () => driver.listWorks(3), { maxMs: 90_000 });
47
55
  return Array.isArray(works) && works[0]?.id ? String(works[0].id) : '';
48
56
  } catch { return ''; }
49
57
  }
@@ -882,7 +882,12 @@ export class DouyinSocial extends SocialBase {
882
882
  ...(song ? { music: song, allowDuplicate } : {}),
883
883
  beforeSubmit: () => this.postJobs.submitting(jobId)
884
884
  });
885
- if (videoNeedsLock) await this.attachWorkId(published);
885
+ // 读回作品 id 的判断看「driver 自己带没带回来」,不看要不要浏览器锁:
886
+ // 浏览器 driver 的 publishVideo 只回 { ok: true }(workId === undefined)→ 锁内补读;
887
+ // CLI driver 的 publishVideo 直接从投稿响应解析出 workId 带回 → 已有值,不必再读。
888
+ // 不能再用 videoNeedsLock 当条件:那把「要不要锁」和「要不要读 id」绑死,
889
+ // hybrid 下(不需要锁)会被误判成「也不用读 id」。
890
+ if (published.workId === undefined) await this.attachWorkId(published);
886
891
  return published;
887
892
  } finally {
888
893
  if (videoNeedsLock) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-fish-soul",
3
- "version": "0.19.31",
3
+ "version": "0.19.32",
4
4
  "description": "鱼 · 人格、按人记忆(可纠正、有印象、能导入旧聊天记录)、日程自走与主动开口,直连 SnowLuma 收发 QQ(群里会自己插话),B站 / 抖音小号私信与自己刷视频;按功能选模型并统计用量花费,能听会说 QQ 语音、收藏表情包、学群里的梗,可选上网查;心情影响说话、去 AI 味、每个群的设定、按聊天选模型、每晚写日记、每周记忆存档与可选周记(DSH 插件,单角色 feiyu)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",