@ququ-jiaxk/dsh-groupchat 0.1.13 → 0.1.14

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 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -563,6 +563,36 @@ export function apply(ctx) {
563
563
  */
564
564
  const agentStates = new Map()
565
565
 
566
+ /**
567
+ * 群上下文:sessionId → 过期时间。
568
+ * 只有被「群信号」唤醒的成员才允许向群里写(group_post / group_task_update)。
569
+ * 用户在成员自己的独立会话里直接派活时,没有群上下文——此时成员的进度不应回流到群里,
570
+ * 否则会出现「单独会话派的任务把群里冻结/看板搅乱」的内耗。
571
+ * sAgent 例外:它的职责就是群管理,且心跳/汇报唤醒不经过 wakeTargets。
572
+ */
573
+ const groupContextUntil = new Map()
574
+ const GROUP_CONTEXT_TTL = 2 * 60 * 60 * 1000
575
+
576
+ function markGroupContext(sessionId) {
577
+ if (sessionId) groupContextUntil.set(sessionId, Date.now() + GROUP_CONTEXT_TTL)
578
+ }
579
+
580
+ function hasGroupContext(sessionId) {
581
+ const until = groupContextUntil.get(sessionId)
582
+ if (!until) return false
583
+ if (until < Date.now()) { groupContextUntil.delete(sessionId); return false }
584
+ return true
585
+ }
586
+
587
+ function assertGroupWriteAllowed(group, sessionId) {
588
+ if (!sessionId || sessionId === group.sAgentSessionId) return
589
+ if (hasGroupContext(sessionId)) return
590
+ throw new Error(
591
+ '当前不是群上下文:你是在用户单独会话里被触发的,已阻止向群里发消息/改进度。'
592
+ + '请直接回复当前会话的用户;如果需要参与群协作,等群里发来信号后再动作。'
593
+ )
594
+ }
595
+
566
596
  /**
567
597
  * Agent 工作日志(activity):sessionId → [{ id, ts, kind, title, detail }]
568
598
  * 记录 agent 在做什么:开始思考、写回复、调用哪个工具、工具结果、状态切换。
@@ -696,6 +726,8 @@ export function apply(ctx) {
696
726
  // 只有真正在跑过才记一条「回到空闲」,避免刷屏
697
727
  if (cur && cur.state !== 'idle') pushActivity(agent.id, 'idle', '本轮结束,回到空闲')
698
728
  setAgentState(agent.id, 'idle')
729
+ // 群上下文随这一轮结束失效:之后用户在独立会话里再找它,不算群协作
730
+ groupContextUntil.delete(agent.id)
699
731
  }
700
732
  })
701
733
 
@@ -903,6 +935,8 @@ export function apply(ctx) {
903
935
  }
904
936
  continue
905
937
  }
938
+ // 这条唤醒来自群信号:给这个会话打上群上下文,允许它回群发言/改进度
939
+ markGroupContext(toSessionId)
906
940
  const n = unreadCount(state, toSessionId)
907
941
  // 关键:消息确实派发给了这个会话 —— 标记「已接收」。
908
942
  // 此时 agent 可能还要排队(正在跑上一个 turn),所以不是立刻 thinking。
@@ -1046,6 +1080,7 @@ export function apply(ctx) {
1046
1080
  if (!group) throw new Error(`群 ${args.groupId} 不存在`)
1047
1081
  // UI 操作(sessionId 为 null)不校验成员身份;agent 操作校验
1048
1082
  if (sessionId && !isMember(group, sessionId)) throw new Error('你不是该群成员')
1083
+ if (sessionId) assertGroupWriteAllowed(group, sessionId)
1049
1084
  group.task = group.task || {}
1050
1085
  group.task.subtasks = Array.isArray(group.task.subtasks) ? group.task.subtasks : []
1051
1086
 
@@ -1245,6 +1280,7 @@ export function apply(ctx) {
1245
1280
  const group = state.groups.find(g => g.id === args.groupId)
1246
1281
  if (!group) throw new Error(`群 ${args.groupId} 不存在`)
1247
1282
  if (!isMember(group, sessionId)) throw new Error('你不是该群的成员,无权发言')
1283
+ assertGroupWriteAllowed(group, sessionId)
1248
1284
  const msg = postMessage(group, {
1249
1285
  authorSessionId: sessionId,
1250
1286
  authorName: nameOf(group, sessionId),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ququ-jiaxk/dsh-groupchat",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "type": "module",
5
5
  "description": "DSH 群聊插件:把已有会话作为固定角色的智能体拉进项目群,由项目经理 agent(sAgent)聚合、推进、排人、汇报。",
6
6
  "exports": {