@ququ-jiaxk/dsh-groupchat 0.1.11 → 0.1.13

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.
Files changed (2) hide show
  1. package/index.js +36 -10
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -379,9 +379,21 @@ function replyTargetOfRecentMember(state, group, message) {
379
379
  }
380
380
 
381
381
 
382
+ /** 消息在信号/inbox 里的摘要:正文 + 附件名(绝对路径),附件消息不会只剩一个文件名。 */
383
+ function summaryForMessage(message) {
384
+ const attachments = message.attachments || []
385
+ const attachmentText = attachments.length
386
+ ? '[附件] ' + attachments.map(a => `${a.name}(${a.path})`).join('、')
387
+ : ''
388
+ const body = String(message.content || '').trim()
389
+ return [body, attachmentText].filter(Boolean).join('\n') || '(空消息)'
390
+ }
391
+
382
392
  function dispatch(state, group, message) {
383
393
  const targets = new Set()
384
394
  const sAgent = sagentOf(group)
395
+ // 只有附件、没有正文的消息也算「用户发言」,不能落进寒暄分支被静默丢弃
396
+ const hasAttachments = !!(message.attachments && message.attachments.length)
385
397
  // 解析 @ 目标(用户消息和 agent 消息都要用)
386
398
  const addressed = resolveAddressedTo(group, message.addressedTo)
387
399
  const addressedMembers = addressed.filter(t => memberSessionIds(group).has(t) && t !== sAgent)
@@ -396,12 +408,12 @@ function dispatch(state, group, message) {
396
408
  if (addressedMembers.length > 0 && !userAddressedSagent) {
397
409
  // 只 @ 了成员:只发给被点名的人
398
410
  for (const t of addressedMembers) targets.add(t)
399
- } else if (!userAddressedSagent && replyTargetOfRecentMember(state, group, message)) {
411
+ } else if (!userAddressedSagent && !hasAttachments && replyTargetOfRecentMember(state, group, message)) {
400
412
  // 用户在对刚才那位成员说"谢谢/好的":交给**那位成员**回一句「不客气」。
401
413
  // 既不是 PM 代答,也不是谁都不理。
402
414
  const who = replyTargetOfRecentMember(state, group, message)
403
415
  if (who && memberSessionIds(group).has(who)) targets.add(who)
404
- } else if (!userAddressedSagent && isSmallTalkOnly(message.content)) {
416
+ } else if (!userAddressedSagent && !hasAttachments && isSmallTalkOnly(message.content)) {
405
417
  // 没 @ 人、也没有明确对话对象的纯寒暄(如群里第一次说"你好")→ 不惊动任何人
406
418
  } else {
407
419
  targets.add(sAgent)
@@ -456,9 +468,12 @@ function dispatch(state, group, message) {
456
468
  // summary 只是 inbox 预览,真正全文走 group_read_signal;但预览也不能砍半,
457
469
  // 否则 agent 会用不完整的信息决策。仅对极端超长(>4000 字)做折叠,
458
470
  // 并在折叠处明确标注剩余长度。
459
- summary: message.content.length > 4000
460
- ? message.content.slice(0, 4000) + `\n…(后续还有 ${message.content.length - 4000} 字,请用 group_read_signal 读全文后再执行)`
461
- : message.content,
471
+ summary: (() => {
472
+ const base = summaryForMessage(message)
473
+ return base.length > 4000
474
+ ? base.slice(0, 4000) + `\n…(后续还有 ${base.length - 4000} 字,请用 group_read_signal 读全文后再执行)`
475
+ : base
476
+ })(),
462
477
  messageId: message.id,
463
478
  userMentioned,
464
479
  })
@@ -939,6 +954,10 @@ export function apply(ctx) {
939
954
  ? '\n【不要发言】这是用户直接 @ 某位成员的消息,成员会自己答复。你不需要汇总、不需要总结、不需要确认,保持沉默即可。'
940
955
  : ''
941
956
  const latestHint = latest ? `\n最新信号:[${latest.kind}] ${latest.fromName} 说「${latest.summary}」` : ''
957
+ // 带附件的消息:摘要里已经有本地绝对路径,明确让 agent 去读,别只看到文件名就回「拿不到内容」
958
+ const attachmentHint = latest && /\[附件\]/.test(String(latest.summary || ''))
959
+ ? '\n【附件】最新消息带附件,括号里是本地绝对路径。先 group_read_signal 读正文,图片用 read_image 打开、文本用 read 打开,看过内容再回复;不要凭空猜测,也不要说「拿不到附件」。'
960
+ : ''
942
961
 
943
962
  // 寒暄场景:用户只是在道谢/确认。
944
963
  // 注意:这里必须用 + 拼接成【一个】字符串再传给 wakeAgent,
@@ -960,7 +979,7 @@ export function apply(ctx) {
960
979
  : `\n先调用 group_inbox 看完整未读列表,再决定是否响应;与你无关的话题保持沉默即可。`
961
980
  wakeAgent(agents, toSessionId,
962
981
  `[群聊] 群「${group.name}」(群id=${group.id})有 ${n} 条新信号。${latestHint}${fromUserHint}${userMentionedHint}`
963
- + actionHint + `${brief}${orderHint}`, resumer)
982
+ + actionHint + `${attachmentHint}${brief}${orderHint}`, resumer)
964
983
  }
965
984
  }
966
985
 
@@ -1274,6 +1293,9 @@ export function apply(ctx) {
1274
1293
  const tag = i === 0 ? '【最新】' : ''
1275
1294
  lines.push(` ${tag}[${s.kind}] ${s.fromName}: ${s.summary}`)
1276
1295
  })
1296
+ if (sorted.some(s => String(s.summary || '').includes('[附件]'))) {
1297
+ lines.push(' ([附件] 括号里是本地绝对路径:图片用 read_image 打开,文本用 read 打开;也可 group_read_signal 看完整说明)')
1298
+ }
1277
1299
  } else {
1278
1300
  lines.push('没有未读信号。')
1279
1301
  }
@@ -1305,10 +1327,14 @@ export function apply(ctx) {
1305
1327
  if (!g) throw new Error(`你不是群 ${args.groupId} 的成员`)
1306
1328
  const signals = state.signals
1307
1329
  .filter(s => s.groupId === g.id && s.toSessionId === sessionId && !s.read)
1308
- .map(s => ({
1309
- id: s.id, fromName: s.fromName, kind: s.kind,
1310
- summary: s.summary, messageId: s.messageId, ts: s.ts,
1311
- }))
1330
+ .map(s => {
1331
+ const message = state.messages.find(m => m.id === s.messageId)
1332
+ return {
1333
+ id: s.id, fromName: s.fromName, kind: s.kind,
1334
+ summary: message ? summaryForMessage(message) : s.summary,
1335
+ messageId: s.messageId, ts: s.ts,
1336
+ }
1337
+ })
1312
1338
  return {
1313
1339
  groups: [{
1314
1340
  id: g.id, name: g.name, myRole: roleOf(g, sessionId), version: typeof g.version === "number" ? g.version : 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ququ-jiaxk/dsh-groupchat",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "type": "module",
5
5
  "description": "DSH 群聊插件:把已有会话作为固定角色的智能体拉进项目群,由项目经理 agent(sAgent)聚合、推进、排人、汇报。",
6
6
  "exports": {