dsh-chat-comprehension 0.3.6 → 0.3.7

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
@@ -3,7 +3,7 @@
3
3
  给 DeepSeek Harness 的一个「一个入口」的陪伴层:**项目人格 + QQ 联动 + 专属记忆 + B站 值班 + 表情包 + 语音**。
4
4
  左侧栏只有一个图标「陪伴」,点开就是一整页设置,不用在好几个插件各自的页面之间来回找。
5
5
 
6
- > 版本 **0.3.6**:人格、B站、记忆、表情包、视频分镜的宿主代码都已随本插件提供,只装这一个包就能用。
6
+ > 版本 **0.3.7**:人格、B站、记忆、表情包、视频分镜的宿主代码都已随本插件提供,只装这一个包就能用。
7
7
  > QQ 网关(`@tencent-connect/dsh-qqbot`)需要单独安装,本插件会自动为它打上联动补丁。
8
8
 
9
9
  ## 安装
@@ -102,6 +102,23 @@ dsh plugin --profile web add @tencent-connect/dsh-qqbot # 需要 QQ 对话时
102
102
  - 本地:自带 Qwen3-TTS 小服务(CUDA / Apple MPS / CPU 自动选),也支持 vLLM-Omni、GPT-SoVITS、CosyVoice、Fish-Speech 和自定义 HTTP。
103
103
  - QQ 回复:语音可用就发语音,失败自动回退文字;没填 Key 或没开语音就发文字。
104
104
 
105
+ ## QQ 分享的视频:卡片能直接用
106
+
107
+ 对方在 QQ 里分享 B站 视频时,QQ 交给机器人的是一张小程序卡片,正文里通常没有链接。
108
+ 本插件会在访问控制之后接管这张卡片:
109
+
110
+ - 从 `content`、`message_scene.ext`、`msg_elements`、附件地址等所有可能出现的位置找链接 / BV 号
111
+ (不只认 `ark_data` 一种形状);
112
+ - `b23.tv` / `bili2233.cn` 这类短链会**只跟随 B站 自己的域名**解开成视频地址;
113
+ - 找到后把「视频链接」补进这条消息,模型可以直接用 `video_storyboard` 打开,**不用再向对方要 BV 号**;
114
+ - 卡片里确实没有链接时,会明确说「这张卡片没有可打开的链接」,不让模型凭标题猜。
115
+
116
+ 「环境」页有「QQ 分享卡片」一行:显示网关补丁版本、最近一张卡片的时间和解析出的链接,
117
+ 「B站」页也能看到最近一张卡片的原始字段(`~/.dsh/agents/qq-last-card.json`,不含 QQ 号)。
118
+
119
+ ⚠️ 卡片解析依赖 QQ 网关补丁(v2 起):**打完补丁要重启一次 DSH** 才会进内存,
120
+ 否则跑的还是没打补丁的旧代码 —— 表现就是「只看到卡片,看不到链接」。
121
+
105
122
  ## 微信 / QQ 里直接发的表情包为什么看不到
106
123
 
107
124
  **看不到,是平台格式限制,不是插件缺工具,也不是模型不支持图片。**
package/lib/index.js CHANGED
@@ -767,6 +767,16 @@ async function doctor(ctx) {
767
767
  '到「环境」页点「一键安装全部依赖」,按顺序自动装;每步进度会显示在下面', '')
768
768
  } catch { /* 拿不到就不显示这一行 */ }
769
769
 
770
+ try {
771
+ const cap = readJson(CARD_CAPTURE, null)
772
+ const lv = Number((qqbotPatchState || {}).level || 0)
773
+ add('qq-cards', 'QQ 分享卡片(小程序 → 视频链接)', lv >= 2,
774
+ lv >= 2
775
+ ? ('网关补丁 v' + lv + ' 已打' + (cap ? ' · 最近一张卡片:' + String(cap.at || '').slice(0, 19).replace('T', ' ') + (cap.results && cap.results[0] && cap.results[0].url ? ' · ' + cap.results[0].url : '') : ' · 还没收到过卡片'))
776
+ : '网关补丁没打到 v2(卡片补不上链接);重启一次 DSH 再试',
777
+ '收到 QQ 小程序卡片时会自动补上 B站 视频链接;补丁要重启后生效', '')
778
+ } catch { /* 拿不到就不显示 */ }
779
+
770
780
  try {
771
781
  const sb = video ? video.storyboard() : { installed: false }
772
782
  const yt = video ? await video.ytdlp() : { found: false }
@@ -1373,3 +1383,5 @@ export async function apply(ctx) {
1373
1383
  // v036 1794026709
1374
1384
 
1375
1385
  // force reload 1794026820
1386
+
1387
+ // cards v037 1794034628
package/lib/qq-cards.mjs CHANGED
@@ -47,7 +47,15 @@ function collectStrings(value, out, key = '', depth = 0) {
47
47
  return out
48
48
  }
49
49
 
50
- /** 收集一条消息里所有卡片(本条 + 引用里的)。 */
50
+ /**
51
+ * 收集一条消息里所有「可能是卡片」的载荷。
52
+ *
53
+ * QQ 官方事件里**没有** ark_data 这个字段(SDK 类型只有 content / msg_elements / attachments /
54
+ * message_scene.ext)。卡片信息可能出现在这些地方,所以全部收进来:
55
+ * - message.raw.ark_data / raw.ark(老样例 / 未来字段)
56
+ * - message_scene.ext[](QQ 把分享场景的扩展信息放这里,常常就是 b23 链接)
57
+ * - msg_elements[].content、attachments[].url
58
+ */
51
59
  export function findArks(message) {
52
60
  const raw = message && typeof message === 'object' ? (message.raw || {}) : {}
53
61
  const arks = []
@@ -62,6 +70,40 @@ export function findArks(message) {
62
70
  return arks
63
71
  }
64
72
 
73
+ /**
74
+ * 把一条消息里所有「可能带链接的文本」摊平:正文、场景扩展、元素、附件地址。
75
+ * 不挑形状 —— 只要有 URL / BV 就捞出来。
76
+ */
77
+ export function collectSources(message) {
78
+ const out = []
79
+ const push = (v, where) => {
80
+ if (typeof v === 'string' && v.trim() !== '') out.push({ where, value: v })
81
+ }
82
+ const raw = message && typeof message === 'object' ? (message.raw || {}) : {}
83
+ push(message && message.content, 'content')
84
+ push(raw.content, 'raw.content')
85
+ const scenes = []
86
+ if (raw.message_scene && typeof raw.message_scene === 'object') scenes.push(raw.message_scene)
87
+ if (message && message.messageScene && typeof message.messageScene === 'object') scenes.push(message.messageScene)
88
+ for (const scene of scenes) {
89
+ if (Array.isArray(scene.ext)) for (const e of scene.ext) push(e, 'message_scene.ext')
90
+ push(scene.source, 'message_scene.source')
91
+ }
92
+ const elements = Array.isArray(message && message.msgElements) ? message.msgElements
93
+ : (Array.isArray(raw.msg_elements) ? raw.msg_elements : [])
94
+ for (const el of elements) {
95
+ if (!el || typeof el !== 'object') continue
96
+ push(el.content, 'msg_elements.content')
97
+ for (const a of Array.isArray(el.attachments) ? el.attachments : []) {
98
+ if (a && typeof a === 'object') { push(a.url, 'attachment.url'); push(a.voice_wav_url, 'attachment.voice') }
99
+ }
100
+ }
101
+ for (const a of Array.isArray(raw.attachments) ? raw.attachments : []) {
102
+ if (a && typeof a === 'object') push(a.url, 'attachment.url')
103
+ }
104
+ return out
105
+ }
106
+
65
107
  function cleanUrl(u) {
66
108
  return String(u).replace(/&/g, '&').replace(/[.,!?]+$/, '')
67
109
  }
@@ -166,50 +208,77 @@ const clip = (s) => {
166
208
  * @param {{ storyboard?: boolean, captureFile?: string, fetchImpl?: Function, now?: () => string }} opts
167
209
  */
168
210
  export async function expandCards(message, opts = {}) {
169
- const arks = findArks(message)
170
- // 有人直接发「【标题】 https://b23.tv/xxx」这种文字分享:正文里有短链但没有卡片
171
211
  const contentText = String((message && message.content) || '')
172
- const textShort = arks.length === 0 ? [...contentText.matchAll(URL_RE)].map((m) => cleanUrl(m[0])).find((u) => {
173
- try { return SHORT_HOSTS.test(new URL(u).hostname) } catch { return false }
174
- }) : ''
175
- if (arks.length === 0 && !textShort) return null
212
+ const sources = collectSources(message)
213
+ const arks = findArks(message)
214
+ const cardish = /卡片|小程序|分享|ark|\[链接\]/i.test(contentText) || arks.length > 0
215
+
216
+ // 从所有来源里捞 URL / BV(卡片正文、message_scene.ext、msg_elements…)
217
+ const urls = []
218
+ let bvid = ''
219
+ const urlOf = []
220
+ for (const { where, value } of sources) {
221
+ for (const m of value.matchAll(URL_RE)) { const u = cleanUrl(m[0]); urls.push(u); urlOf.push({ url: u, where }) }
222
+ if (!bvid) { const b = value.match(BV_RE); if (b) bvid = b[1] }
223
+ }
224
+ for (const ark of arks) {
225
+ const card = parseArk(ark)
226
+ for (const u of card.urls) { urls.push(u); urlOf.push({ url: u, where: 'ark' }) }
227
+ if (!bvid && card.bvid) bvid = card.bvid
228
+ }
229
+ const uniq = [...new Set(urls)]
230
+
231
+ if (uniq.length === 0 && bvid === '' && !cardish) return null
176
232
 
177
233
  const lines = []
178
234
  const results = []
179
- if (textShort) {
180
- const url = await resolveShortLink(textShort, opts)
181
- if (url) {
182
- results.push({ kind: 'text-short-link', url })
183
- lines.push('[B站 短链已解开] ' + url + (opts.storyboard ? '(要看画面可以用 video_storyboard 打开这个链接)' : ''))
184
- }
235
+
236
+ // ① 直接的 B站 地址 / BV 号:不用解短链
237
+ let videoUrl = ''
238
+ for (const u of uniq) {
239
+ const direct = videoUrlFrom(u)
240
+ if (direct) { videoUrl = direct; break }
185
241
  }
186
- for (const ark of arks.slice(0, 3)) {
187
- const card = parseArk(ark)
188
- const title = clip(card.title || card.prompt)
189
- if (card.isBili) {
190
- const url = await biliUrlFromCard(card, opts)
191
- results.push({ kind: 'bili', title, url })
192
- if (url) {
193
- lines.push('[QQ 分享卡片] 哔哩哔哩' + (title ? ':《' + title + '》' : '') + '\n视频链接:' + url
194
- + (opts.storyboard ? '\n(这是对方分享的 B站 视频;要看画面和台词可以用 video_storyboard 打开这个链接。)' : ''))
195
- } else {
196
- lines.push('[QQ 分享卡片] 哔哩哔哩' + (title ? ':《' + title + '》' : '')
197
- + '\n(卡片里没有能打开的视频链接;如果需要看视频,请对方直接发链接或 BV 号,不要凭标题猜内容。)')
198
- }
199
- } else if (title || card.source) {
200
- results.push({ kind: 'other', title, source: clip(card.source) })
201
- lines.push('[QQ 分享卡片]' + (card.source ? ' ' + clip(card.source) : '') + (title ? ':' + title : '')
202
- + (card.desc && card.desc !== card.title ? '\n摘要:' + clip(card.desc) : ''))
242
+ if (videoUrl === '' && bvid !== '') videoUrl = 'https://www.bilibili.com/video/' + bvid
243
+
244
+ // ② 短链(b23.tv 等):解开
245
+ if (videoUrl === '') {
246
+ for (const item of urlOf) {
247
+ let host = ''
248
+ try { host = new URL(item.url).hostname } catch { continue }
249
+ if (!SHORT_HOSTS.test(host) && !BILI_HOSTS.test(host)) continue
250
+ const resolved = await resolveShortLink(item.url, opts)
251
+ if (resolved) { videoUrl = resolved; break }
203
252
  }
204
253
  }
205
254
 
255
+ if (videoUrl !== '') {
256
+ const title = (() => {
257
+ for (const ark of arks) { const t = clip(parseArk(ark).title); if (t) return t }
258
+ return ''
259
+ })()
260
+ results.push({ kind: 'bili', title, url: videoUrl, sources: uniq.slice(0, 5) })
261
+ lines.push('[QQ 分享卡片] 哔哩哔哩' + (title ? ':《' + title + '》' : '') + '\n视频链接:' + videoUrl
262
+ + (opts.storyboard ? '\n(这是对方分享的 B站 视频;要看画面和台词,直接用 video_storyboard 打开这个链接,不需要再向对方要 BV 号。)' : ''))
263
+ } else if (cardish) {
264
+ // 卡片在,但真的没有链接:说清楚,别让模型去猜标题
265
+ const title = (() => {
266
+ for (const ark of arks) { const t = clip(parseArk(ark).title); if (t) return t }
267
+ const t = contentText.replace(/\s+/g, ' ').trim()
268
+ return t.length > 80 ? t.slice(0, 80) + '…' : t
269
+ })()
270
+ results.push({ kind: 'card-no-link', title, sources: uniq.slice(0, 5), where: sources.map((x) => x.where) })
271
+ lines.push('[QQ 分享卡片]' + (title ? ':' + title : '')
272
+ + '\n(这张卡片里没有可打开的视频链接或 BV 号;如果要看内容,请对方直接发链接或 BV 号,不要凭标题猜。)')
273
+ }
274
+
206
275
  if (opts.captureFile) {
207
276
  try {
208
- mkdirSync(join(opts.captureFile, '..'), { recursive: true })
209
277
  const safe = {
210
278
  at: typeof opts.now === 'function' ? opts.now() : new Date().toISOString(),
211
279
  msgType: message && (message.msgType ?? (message.raw && message.raw.message_type)),
212
280
  content: clip(contentText),
281
+ sources: sources.map((x) => ({ where: x.where, value: clip(x.value) })),
213
282
  arks,
214
283
  results,
215
284
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-chat-comprehension",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "DeepSeek Harness 聊天理解/陪伴套件:局部人格 + QQ 联动 + 专属记忆 + B站值班 + 表情包 + 文字转语音,一个入口。",