@ai-setting/roy-agent-core 1.7.77 → 1.7.88

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 (155) hide show
  1. package/dist/config/config-protection.d.ts +89 -0
  2. package/dist/config/index.d.ts +1 -0
  3. package/dist/config/index.js +23 -7
  4. package/dist/env/agent/agent-component.d.ts +43 -22
  5. package/dist/env/agent/agent-component.js +13 -12
  6. package/dist/env/agent/index.js +13 -12
  7. package/dist/env/agent/types.d.ts +46 -12
  8. package/dist/env/commands/index.js +7 -7
  9. package/dist/env/context/index.js +3 -3
  10. package/dist/env/debug/index.js +7 -7
  11. package/dist/env/error-reply.d.ts +6 -0
  12. package/dist/env/error-reply.js +1 -1
  13. package/dist/env/event-source/bounty-im-handler.d.ts +8 -0
  14. package/dist/env/event-source/es-command.d.ts +39 -0
  15. package/dist/env/event-source/es-plugins.d.ts +68 -0
  16. package/dist/env/event-source/event-source-component.d.ts +15 -0
  17. package/dist/env/event-source/event-source-handlers.d.ts +84 -0
  18. package/dist/env/event-source/event-source-handlers.js +40 -23
  19. package/dist/env/event-source/event-store.js +2 -2
  20. package/dist/env/event-source/index.d.ts +5 -1
  21. package/dist/env/event-source/index.js +75 -23
  22. package/dist/env/event-source/timer-handler.d.ts +98 -0
  23. package/dist/env/event-source/types.d.ts +154 -2
  24. package/dist/env/event-source/wecom-card-action-handler.d.ts +373 -0
  25. package/dist/env/event-source/wecom-card-builder.d.ts +426 -0
  26. package/dist/env/event-source/wecom-cli-handler.d.ts +291 -0
  27. package/dist/env/event-source/wecom-cli-sender.d.ts +88 -0
  28. package/dist/env/event-source/wecom-media.d.ts +130 -0
  29. package/dist/env/event-source/wecom-respond-registry.d.ts +151 -0
  30. package/dist/env/event-source/wecom-respond-registry.js +33 -0
  31. package/dist/env/event-source/wecom-session-card-sender.d.ts +135 -0
  32. package/dist/env/event-source/wecom-session-card-sender.js +153 -0
  33. package/dist/env/event-source/wecom-ws-bridge.d.ts +213 -0
  34. package/dist/env/hook/index.js +5 -5
  35. package/dist/env/index.js +51 -45
  36. package/dist/env/llm/index.js +9 -8
  37. package/dist/env/log-trace/index.js +7 -7
  38. package/dist/env/log-trace/trace-filters.d.ts +6 -1
  39. package/dist/env/mcp/index.js +7 -7
  40. package/dist/env/memory/index.js +7 -7
  41. package/dist/env/plugin/index.js +7 -7
  42. package/dist/env/prompt/index.js +8 -8
  43. package/dist/env/prompt/prompts-index.d.ts +1 -1
  44. package/dist/env/session/group-session-link.d.ts +99 -0
  45. package/dist/env/session/index.js +11 -10
  46. package/dist/env/session/session-component.d.ts +89 -0
  47. package/dist/env/session/storage/index.js +5 -4
  48. package/dist/env/session/types.d.ts +10 -0
  49. package/dist/env/skill/index.js +7 -7
  50. package/dist/env/task/delegate/delegate-channel-hint.d.ts +39 -0
  51. package/dist/env/task/delegate/delegate-tool.d.ts +132 -7
  52. package/dist/env/task/delegate/delegate-tool.js +13 -9
  53. package/dist/env/task/delegate/index.js +8 -8
  54. package/dist/env/task/index.js +18 -18
  55. package/dist/env/task/mcp/index.js +4 -4
  56. package/dist/env/task/plugins/card-subject.d.ts +117 -0
  57. package/dist/env/task/plugins/index.d.ts +2 -0
  58. package/dist/env/task/plugins/index.js +39 -16
  59. package/dist/env/task/plugins/lark-card-action-handler.d.ts +261 -6
  60. package/dist/env/task/plugins/lark-card-patch-notifier.d.ts +542 -2
  61. package/dist/env/task/plugins/lark-card-patch-notifier.js +12 -2
  62. package/dist/env/task/plugins/lark-card-state-store.d.ts +60 -0
  63. package/dist/env/task/plugins/lark-cli-task-notify-plugin.d.ts +61 -0
  64. package/dist/env/task/plugins/sub-session-activity.d.ts +415 -0
  65. package/dist/env/task/plugins/wecom-card-state-store.d.ts +121 -0
  66. package/dist/env/task/plugins/wecom-session-card-store.d.ts +134 -0
  67. package/dist/env/task/plugins/wecom-session-card-store.js +23 -0
  68. package/dist/env/task/plugins/wecom-task-notify-plugin.d.ts +264 -0
  69. package/dist/env/task/storage/index.js +3 -3
  70. package/dist/env/task/tools/index.js +4 -4
  71. package/dist/env/tool/built-in/index.d.ts +2 -0
  72. package/dist/env/tool/built-in/index.js +9 -2
  73. package/dist/env/tool/index.js +14 -9
  74. package/dist/env/tool/types.d.ts +25 -0
  75. package/dist/env/tool/validator.d.ts +8 -0
  76. package/dist/env/workflow/engine/index.js +12 -12
  77. package/dist/env/workflow/hooks/index.js +7 -7
  78. package/dist/env/workflow/index.js +24 -23
  79. package/dist/env/workflow/nodes/index.js +2 -2
  80. package/dist/env/workflow/plugins/index.js +10 -8
  81. package/dist/env/workflow/service/index.js +2 -2
  82. package/dist/env/workflow/storage/index.js +3 -3
  83. package/dist/env/workflow/tools/index.js +16 -15
  84. package/dist/env/workflow/utils/index.js +4 -4
  85. package/dist/index.d.ts +1 -1
  86. package/dist/index.js +118 -62
  87. package/dist/shared/@ai-setting/{roy-agent-core-dc9zq75z.js → roy-agent-core-0crmsc12.js} +3 -3
  88. package/dist/shared/@ai-setting/{roy-agent-core-aa2j7bk9.js → roy-agent-core-0sbmdz8d.js} +171 -36
  89. package/dist/shared/@ai-setting/{roy-agent-core-87942bw4.js → roy-agent-core-1mhyh4c5.js} +1 -1
  90. package/dist/shared/@ai-setting/{roy-agent-core-v6vr6za7.js → roy-agent-core-1vv4fx15.js} +4 -4
  91. package/dist/shared/@ai-setting/roy-agent-core-2stt4rp5.js +134 -0
  92. package/dist/shared/@ai-setting/{roy-agent-core-nwbfepba.js → roy-agent-core-3e040tc5.js} +1 -1
  93. package/dist/shared/@ai-setting/roy-agent-core-418zc9ha.js +288 -0
  94. package/dist/shared/@ai-setting/{roy-agent-core-r5wt1h3c.js → roy-agent-core-4fkxy2gv.js} +1 -1
  95. package/dist/shared/@ai-setting/{roy-agent-core-na18zwj0.js → roy-agent-core-4t3yskp8.js} +1 -1
  96. package/dist/shared/@ai-setting/{roy-agent-core-5pr4zp88.js → roy-agent-core-5kzhaap1.js} +1 -1
  97. package/dist/shared/@ai-setting/{roy-agent-core-qq96p0tj.js → roy-agent-core-5s2t8z00.js} +22 -1
  98. package/dist/shared/@ai-setting/{roy-agent-core-6rh8k6ba.js → roy-agent-core-6gj1hc5z.js} +7 -7
  99. package/dist/shared/@ai-setting/{roy-agent-core-ezvpreqz.js → roy-agent-core-6k8mb7zx.js} +1 -1
  100. package/dist/shared/@ai-setting/{roy-agent-core-g8htfwxj.js → roy-agent-core-7f10p7m2.js} +1 -1
  101. package/dist/shared/@ai-setting/roy-agent-core-7kvpc0w5.js +177 -0
  102. package/dist/shared/@ai-setting/{roy-agent-core-h21gngxf.js → roy-agent-core-7yh5wps0.js} +1 -1
  103. package/dist/shared/@ai-setting/{roy-agent-core-efkjyh69.js → roy-agent-core-9710zwwz.js} +1 -1
  104. package/dist/shared/@ai-setting/{roy-agent-core-6cy43nss.js → roy-agent-core-9c565frx.js} +49 -9
  105. package/dist/shared/@ai-setting/{roy-agent-core-fghc2m8z.js → roy-agent-core-aa8kv18f.js} +34 -2
  106. package/dist/shared/@ai-setting/{roy-agent-core-ew6qb5yx.js → roy-agent-core-an35dzbf.js} +6 -6
  107. package/dist/shared/@ai-setting/{roy-agent-core-mww0mnd9.js → roy-agent-core-azyz78ky.js} +7 -7
  108. package/dist/shared/@ai-setting/{roy-agent-core-264qexac.js → roy-agent-core-b7h39vrc.js} +4 -4
  109. package/dist/shared/@ai-setting/{roy-agent-core-dqxec05w.js → roy-agent-core-bjtc9d35.js} +2 -2
  110. package/dist/shared/@ai-setting/roy-agent-core-c4ec7k0p.js +426 -0
  111. package/dist/shared/@ai-setting/{roy-agent-core-ddyk1rc0.js → roy-agent-core-cre2y2ct.js} +160 -4
  112. package/dist/shared/@ai-setting/{roy-agent-core-tr3ep81v.js → roy-agent-core-d6zdbgtc.js} +1 -1
  113. package/dist/shared/@ai-setting/{roy-agent-core-0qyrk5k0.js → roy-agent-core-ds6qzmf8.js} +14 -5
  114. package/dist/shared/@ai-setting/{roy-agent-core-cgtq6427.js → roy-agent-core-e08bvpaq.js} +1 -1
  115. package/dist/shared/@ai-setting/{roy-agent-core-12n08pg5.js → roy-agent-core-e69qxdyy.js} +1 -1
  116. package/dist/shared/@ai-setting/{roy-agent-core-rhtdspx6.js → roy-agent-core-fan8g0z1.js} +10 -10
  117. package/dist/shared/@ai-setting/{roy-agent-core-xcp8vwax.js → roy-agent-core-fepm835e.js} +2 -2
  118. package/dist/shared/@ai-setting/{roy-agent-core-6j02sbee.js → roy-agent-core-fhg03v43.js} +1 -1
  119. package/dist/shared/@ai-setting/{roy-agent-core-99nwgj84.js → roy-agent-core-fzw9xzm1.js} +1 -1
  120. package/dist/shared/@ai-setting/{roy-agent-core-dvtg4sn0.js → roy-agent-core-g8yr733d.js} +1 -1
  121. package/dist/shared/@ai-setting/{roy-agent-core-3gpygqcx.js → roy-agent-core-gr5h1dyr.js} +2753 -358
  122. package/dist/shared/@ai-setting/roy-agent-core-h1e1fm9b.js +380 -0
  123. package/dist/shared/@ai-setting/{roy-agent-core-c2gbt68e.js → roy-agent-core-h83zdsrq.js} +2 -2
  124. package/dist/shared/@ai-setting/{roy-agent-core-8ez6mccb.js → roy-agent-core-k3gcvybs.js} +5 -1
  125. package/dist/shared/@ai-setting/{roy-agent-core-pgvcf91v.js → roy-agent-core-m39v7qpx.js} +2 -2
  126. package/dist/shared/@ai-setting/{roy-agent-core-tm1mxttk.js → roy-agent-core-mf5p38yf.js} +2 -2
  127. package/dist/shared/@ai-setting/{roy-agent-core-83bewqx8.js → roy-agent-core-mvh0td7p.js} +2 -2
  128. package/dist/shared/@ai-setting/{roy-agent-core-v85n42ve.js → roy-agent-core-mx855td4.js} +17 -38
  129. package/dist/shared/@ai-setting/{roy-agent-core-v87njmq7.js → roy-agent-core-n197medr.js} +13 -13
  130. package/dist/shared/@ai-setting/{roy-agent-core-cmprygrp.js → roy-agent-core-nqkfkpf4.js} +4 -4
  131. package/dist/shared/@ai-setting/{roy-agent-core-7cbpmk4q.js → roy-agent-core-p31ftgq9.js} +1 -1
  132. package/dist/shared/@ai-setting/{roy-agent-core-vffccgf6.js → roy-agent-core-qwd2dq5q.js} +10 -3
  133. package/dist/shared/@ai-setting/{roy-agent-core-rsn44n9y.js → roy-agent-core-ra66sf50.js} +2526 -942
  134. package/dist/shared/@ai-setting/{roy-agent-core-1v4g0d4x.js → roy-agent-core-rm7seqwb.js} +1 -1
  135. package/dist/shared/@ai-setting/{roy-agent-core-w0qjeq2v.js → roy-agent-core-shb1qsyg.js} +1041 -18
  136. package/dist/shared/@ai-setting/{roy-agent-core-ax9e9szb.js → roy-agent-core-smf94h73.js} +1 -1
  137. package/dist/shared/@ai-setting/{roy-agent-core-acj8ag08.js → roy-agent-core-tjnabyvq.js} +1 -1
  138. package/dist/shared/@ai-setting/{roy-agent-core-qqaak24r.js → roy-agent-core-tkpp1ba0.js} +1 -1
  139. package/dist/shared/@ai-setting/{roy-agent-core-9vhq7fvv.js → roy-agent-core-tpm1dd1g.js} +34 -88
  140. package/dist/shared/@ai-setting/{roy-agent-core-ed233k5z.js → roy-agent-core-v1n0106v.js} +1 -1
  141. package/dist/shared/@ai-setting/{roy-agent-core-zxz5fkwj.js → roy-agent-core-v6yshv0z.js} +1 -1
  142. package/dist/shared/@ai-setting/{roy-agent-core-mcy5apay.js → roy-agent-core-vf9sp6s3.js} +1 -1
  143. package/dist/shared/@ai-setting/{roy-agent-core-q813vafd.js → roy-agent-core-vpcxv1ty.js} +1 -1
  144. package/dist/shared/@ai-setting/{roy-agent-core-bxkjk7zx.js → roy-agent-core-vx8zc847.js} +4 -1
  145. package/dist/shared/@ai-setting/{roy-agent-core-xvt7kf7p.js → roy-agent-core-w9ryeg2p.js} +3 -3
  146. package/dist/shared/@ai-setting/{roy-agent-core-es203w7p.js → roy-agent-core-wqs6yypq.js} +1 -1
  147. package/dist/shared/@ai-setting/{roy-agent-core-hd3n57zs.js → roy-agent-core-wr1qexzq.js} +5 -5
  148. package/dist/shared/@ai-setting/roy-agent-core-wxrkcb17.js +56 -0
  149. package/dist/shared/@ai-setting/{roy-agent-core-0snm5hc5.js → roy-agent-core-y6shd91r.js} +1 -1
  150. package/dist/shared/@ai-setting/{roy-agent-core-9vxh6f8h.js → roy-agent-core-y7fqtzk2.js} +7 -7
  151. package/dist/shared/@ai-setting/{roy-agent-core-cpcd24n2.js → roy-agent-core-yet36q5k.js} +2 -2
  152. package/dist/shared/@ai-setting/{roy-agent-core-3fh1f7s7.js → roy-agent-core-yfpnkc4z.js} +5 -5
  153. package/dist/shared/@ai-setting/{roy-agent-core-0v27y99n.js → roy-agent-core-yh68z1bg.js} +65 -4
  154. package/package.json +18 -1
  155. /package/dist/shared/@ai-setting/{roy-agent-core-b4x6x4k2.js → roy-agent-core-m1fgtnrc.js} +0 -0
@@ -0,0 +1,373 @@
1
+ /**
2
+ * @fileoverview Task #5203 — 企微卡片按钮点击处理
3
+ *
4
+ * ## 触发链路
5
+ *
6
+ * 用户点 button_interaction 卡片按钮
7
+ * → 企微推 `template_card_event`(aibot_event_callback,5 秒窗口)
8
+ * → WecomCliInstance.handleWsFrame 分流(不走 Agent)
9
+ * → 本模块 handleWecomCardAction:
10
+ * 1. 解析 event_key / task_id(反解出 roy 任务号)
11
+ * 2. 触发对应 task 操作(mark_done → taskComponent.updateTask(status=completed))
12
+ * 3. 经 aibot_respond_update_msg(透传回调 req_id)更新卡片按钮态
13
+ *
14
+ * ## 设计原则(对齐 lark-card-action-handler.ts)
15
+ *
16
+ * - 纯函数 + IO 端口注入(markTaskDone / reopenTask / updateCard)
17
+ * - 失败明确返回 ok=false,不静默成功
18
+ * - 并发去重:同 (cardTaskId, action) 处理中 → 后到的拒绝
19
+ * (用户双击会产生两条独立回调)
20
+ *
21
+ * ## task_id 反解
22
+ *
23
+ * 发卡时 task_id 形如 `roy-task-<taskId>-<seq>-<rand>`(wecom-card-builder);
24
+ * 回调原样带回 → 用前缀 `roy-task-` 反解出数字任务号。
25
+ * 非 roy-task 前缀(外部卡片)→ taskId=null,动作不执行。
26
+ */
27
+ import { type WecomActivityLike, type WecomMilestoneLite } from "./wecom-card-builder";
28
+ import type { WecomSessionCardState } from "../task/plugins/wecom-session-card-store";
29
+ import type { ActivityProbeResult } from "../task/plugins/sub-session-activity";
30
+ /**
31
+ * 卡片动作类型
32
+ *
33
+ * ★ Task #5360:新增 `refresh_activity`(刷新 sub-session 活性)。
34
+ *
35
+ * 与 `view`(刷操作时间线)分开,因为企微 `horizontal_content_list` 只有
36
+ * 6 条预算且已被时间线占满 —— 见 wecom-card-builder 的
37
+ * `WecomCardActionKey.REFRESH_ACTIVITY` 注释。
38
+ *
39
+ * ★ Task #5419:新增 `create_lark_group`(建关联飞书群,对齐飞书)。
40
+ */
41
+ export type WecomCardAction = "view" | "mark_done" | "reopen" | "refresh_activity" | "create_lark_group";
42
+ /** 解析出的卡片动作事件 */
43
+ export interface WecomCardActionEvent {
44
+ /** 用户点的按钮 key(WecomCardActionKey 之一或外部自定义) */
45
+ eventKey: string;
46
+ /** 回调带回的原始 task_id(原样回填更新帧) */
47
+ cardTaskId: string;
48
+ /** 反解出的任务号;非 roy-task 前缀 → null */
49
+ taskId: number | null;
50
+ /**
51
+ * ★ 补充需求(22:31):反解出的 sub-session id(`roy-session-` 前缀)。
52
+ * 与 `taskId` 互斥:一张卡要么挂 task,要么挂 session。
53
+ */
54
+ sessionId: string | null;
55
+ /** 操作者 userid */
56
+ userId: string;
57
+ /** 回调帧 req_id(更新帧必须原样透传) */
58
+ reqId: string;
59
+ }
60
+ /** IO 端口(caller 注入;本模块保持纯函数) */
61
+ export interface WecomCardActionPorts {
62
+ /** 标记任务完成(status=completed) */
63
+ markTaskDone: (taskId: number) => Promise<void>;
64
+ /** 重新打开任务(status=active) */
65
+ reopenTask: (taskId: number) => Promise<void>;
66
+ /**
67
+ * 更新卡片(aibot_respond_update_msg,5 秒窗口内)
68
+ * @param cardTaskId 回调带回的原始 task_id
69
+ * @param timeline view 动作时携带的操作时间线(可选)
70
+ * @param action ★ Task #5250:触发动作(决定更新后的按钮:
71
+ * view/reopen → 可点击「刷新详情」;mark_done → 「已处理」)
72
+ */
73
+ updateCard: (reqId: string, cardTaskId: string, statusLabel: string, note?: string, timeline?: WecomMilestoneLite[], action?: WecomCardAction,
74
+ /**
75
+ * ★ Task #5273:任务号+标题(可选,渲染进更新卡 main_title)
76
+ * ★ Task #5360:`activity` —— sub-session 活性
77
+ * (`undefined` = 不渲染;`null` = 查了但没数据,渲染「暂无数据」)
78
+ */
79
+ extra?: {
80
+ taskNumber?: number;
81
+ taskTitle?: string;
82
+ activity?: WecomActivityLike | null;
83
+ /** ★ Task #5360(CV MAJOR-2):任务是否已终态(决定 ⚪已结束 vs 🔴疑似停滞) */
84
+ activityTerminal?: boolean;
85
+ }) => Promise<void>;
86
+ /**
87
+ * ★ Task #5364(B 方案):用**完整快照**刷新 session 卡。
88
+ *
89
+ * 与 `updateCard` 的区别:那个是 task 卡的通用更新(statusLabel/timeline/
90
+ * activity 三个松散参数);本端口接收一次完整的 session 快照,由实现方
91
+ * 调 `buildWecomSessionCardUpdateBody` 渲染「生命周期 + 会话详情 + 任务 +
92
+ * 操作记录 + 活性」一整套。
93
+ *
94
+ * 未注入 ⇒ 自动降级到 `updateCard`(#5360 行为,仅活性)。
95
+ */
96
+ updateSessionCard?: (reqId: string, input: {
97
+ sessionId: string;
98
+ /** 回调带回的原始 task_id(刷新帧必须原样回填) */
99
+ cardTaskId: string;
100
+ /** 持久层快照;undefined = 无记录(降级仅活性) */
101
+ state?: WecomSessionCardState;
102
+ /** 实时活性;null = 查了但没数据 */
103
+ activity: WecomActivityLike | null;
104
+ /**
105
+ * ★ Task #5419:session 关联的任务信息(刷新增强)。
106
+ * undefined = 无任务 / 端口未注入。
107
+ */
108
+ task?: {
109
+ id: number;
110
+ title?: string;
111
+ status?: string;
112
+ progress?: number;
113
+ milestones?: WecomMilestoneLite[];
114
+ };
115
+ /**
116
+ * ★ Task #5419:已关联飞书群 chatId(建群后刷新帧带群链接)。
117
+ */
118
+ perTaskChatId?: string;
119
+ /**
120
+ * ★ CV 5419 MAJOR-3:建群失败提示(渲染进 sub_title)。
121
+ */
122
+ errorHint?: string;
123
+ now?: number;
124
+ }) => Promise<void>;
125
+ /**
126
+ * ★ Task #5203:读任务的操作时间线(milestones + processSteps)。
127
+ *
128
+ * view 动作用它把完整操作记录刷进卡片正文。
129
+ * 无记录 / 读取失败 → 返回 [](降级为简单按钮态更新)。
130
+ */
131
+ loadTimeline?: (taskId: number) => WecomMilestoneLite[];
132
+ /**
133
+ * ★ Task #5273:读任务号+标题(渲染进更新卡 main_title,
134
+ * 修复「卡片缺 Task #ID 和 title」)。
135
+ *
136
+ * ★ CV-B1(Task #5273 返工):生产实现(wecom-cli-handler)
137
+ * 从 taskComponent 读任务,返回 **Promise** —— 端口签名必须
138
+ * 允许 Promise,消费端 doHandle 必须 await。
139
+ * 返回 undefined / reject / 抛错 → 降级为无标题(卡片更新不阻断)。
140
+ */
141
+ loadTaskTitle?: (taskId: number) => {
142
+ title?: string;
143
+ number?: number;
144
+ } | undefined | Promise<{
145
+ title?: string;
146
+ number?: number;
147
+ } | undefined>;
148
+ /**
149
+ * ★ Task #5360:读 sub-session 活性(「刷新活性」动作用)。
150
+ *
151
+ * 与飞书侧 `CardActionPorts.loadSubSessionActivity` **同一个 probe 实现**
152
+ * (`createActivityProbe`),避免两渠道 liveness 阈值漂移。
153
+ *
154
+ * 不注入 / 抛错 / undefined ⇒ 卡片渲染「暂无数据」,绝不阻断更新。
155
+ */
156
+ loadSubSessionActivity?: (taskId: number) => Promise<ActivityProbeResult> | ActivityProbeResult;
157
+ /**
158
+ * ★ 补充需求(22:31):**session-only** 活性读取(无 task 场景)。
159
+ *
160
+ * 与 `loadSubSessionActivity(taskId)` 的区别:后者要从 task 反查 bgTask;
161
+ * 本端口**直达** session store —— 因为回调里直接带着 sessionId,
162
+ * 而这条链上根本没有 task。
163
+ */
164
+ loadSessionActivity?: (sessionId: string) => Promise<ActivityProbeResult> | ActivityProbeResult;
165
+ /**
166
+ * ★ Task #5364(B 方案):读 **session 卡持久层**快照。
167
+ *
168
+ * ## 为什么刷新必须走它(而不是内存 / task)
169
+ *
170
+ * B 方案下「后续 lifecycle 不主动 patch,只写持久层」,所以**刷新是唯一
171
+ * 能看到最新状态的时机**。快照里带着:
172
+ * - `lifecycle`(超时 / 完成 / 失败 / 停止 —— 单靠活性推不出来)
173
+ * - `title` / `agentType` / `startedAt` / `associatedTaskId`(首次发卡的信息)
174
+ * - `milestones`(这一路的状态轨迹)
175
+ * - `cardTaskId`(刷新帧必须原样回填,否则协议拒绝)
176
+ *
177
+ * 读内存 map 的话进程重启就全丢;读 task 的话没有 task 的 session 全丢。
178
+ *
179
+ * 不注入 / 抛错 / undefined ⇒ 降级为「只有活性」的刷新卡(**仍更新卡片**,
180
+ * 用户点了按钮必须有反馈)。
181
+ */
182
+ loadSessionCardState?: (sessionId: string) => WecomSessionCardState | undefined | Promise<WecomSessionCardState | undefined>;
183
+ /**
184
+ * ★ Task #5418:按 roy 任务号反查 session 卡持久层记录。
185
+ *
186
+ * task 卡刷新路径回退 session probe 时需要 sessionId ——
187
+ * `roy-task-` 前缀卡回调里没有 sessionId,唯一持久化来源是
188
+ * `wecom_session_card.associated_task_id`。注入方(wecom-cli-handler)
189
+ * 用 `store.list()` 扫描;缺省 ⇒ 不回退(行为同旧版)。
190
+ */
191
+ findSessionCardByTaskId?: (taskId: number) => WecomSessionCardState | undefined | Promise<WecomSessionCardState | undefined>;
192
+ /**
193
+ * ★ Task #5419:session → task 反查 + 全量任务信息(刷新增强)。
194
+ *
195
+ * 用户 2026-11-13:「有刷新详情按钮可以刷新 subsession 状态
196
+ * (包括是否建任务,以及任务名称和动态,也包括 subsession 的
197
+ * 消息数)」。
198
+ *
199
+ * 生产接线(wecom-cli-handler):`TaskComponent.getTaskIdBySessionId`
200
+ * (task_operation.session_id 反查)+ `getTaskWithOperations`。
201
+ *
202
+ * 返回 undefined = 该 session 没建任务(卡上不渲染任务行);
203
+ * 抛错 = 降级(不阻断刷新)。
204
+ */
205
+ loadSessionTaskInfo?: (sessionId: string) => Promise<{
206
+ id: number;
207
+ title?: string;
208
+ status?: string;
209
+ progress?: number;
210
+ milestones?: WecomMilestoneLite[];
211
+ } | undefined> | {
212
+ id: number;
213
+ title?: string;
214
+ status?: string;
215
+ progress?: number;
216
+ milestones?: WecomMilestoneLite[];
217
+ } | undefined;
218
+ /**
219
+ * ★ Task #5419:建**关联飞书群**(对齐飞书 handleGroupActionSessionOnly)。
220
+ *
221
+ * 生产接线(wecom-cli-handler):lark-cli +chat-create +
222
+ * SessionComponent.attachGroupSession(独立群 session + 1 条
223
+ * user 背景事件 + metadata linkedFromSessionId)。
224
+ *
225
+ * 返回新群 chatId;抛错 = 建群失败(结果翻失败,但卡片仍更新)。
226
+ */
227
+ createLarkGroupForSession?: (sessionId: string) => Promise<string>;
228
+ /**
229
+ * ★ Task #5419:读该 session 已关联的飞书群(幂等防重复建群)。
230
+ *
231
+ * 生产接线:`SessionComponent.findGroupChatForSession`
232
+ * (扫 metadata linkedFromSessionId,与飞书侧同源)。
233
+ * 未注入 / 抛错 ⇒ 当作没有群(可能重复建,但不崩)。
234
+ */
235
+ findGroupChatForSession?: (sessionId: string) => Promise<{
236
+ chatId: string;
237
+ } | undefined> | {
238
+ chatId: string;
239
+ } | undefined;
240
+ /**
241
+ * ★ Task #5419:建群成功后发一条企微消息带飞书群 applink。
242
+ *
243
+ * 用户:「建完可以展示或者发一条企微消息带上飞书群跳转链接哈」。
244
+ * best-effort:抛错不阻断建群结果。
245
+ */
246
+ notifyGroupLink?: (input: {
247
+ sessionId: string;
248
+ chatId: string;
249
+ /** 群名(可选,消息文案用) */
250
+ chatName?: string;
251
+ /**
252
+ * ★ CV 5419 BLOCKER-1:点击按钮的**企微用户** userid。
253
+ *
254
+ * 通知消息必须发给企微侧(不是飞书群 —— chatId 是
255
+ * 飞书群 id,企微 CLI 不认)。缺省时实现方从 session
256
+ * store 的 chatId 兜底。
257
+ */
258
+ userId?: string;
259
+ }) => Promise<void>;
260
+ }
261
+ /** 处理结果 */
262
+ export interface WecomCardActionResult {
263
+ ok: boolean;
264
+ /** 执行的动作(解析失败时缺省) */
265
+ action?: WecomCardAction;
266
+ error?: string;
267
+ /**
268
+ * ★ Task #5419:create_lark_group 成功时的新群 chatId
269
+ * (幂等命中时 = 已有群 chatId)。
270
+ */
271
+ newChatId?: string;
272
+ }
273
+ /** 测试钩子:清空 in-flight 去重表(仅供单测 beforeEach 使用) */
274
+ export declare function __resetWecomCardActionInflightForTest(): void;
275
+ /**
276
+ * 从 WS 帧解析 template_card_event。
277
+ *
278
+ * 非 template_card_event(消息帧 / 其他事件)→ null。
279
+ */
280
+ export declare function extractWecomCardAction(frame: unknown): WecomCardActionEvent | null;
281
+ /**
282
+ * 处理卡片按钮点击。
283
+ *
284
+ * @returns 处理结果(ok=true 表示动作已执行 + 卡片已更新)
285
+ */
286
+ export declare function handleWecomCardAction(frame: unknown, ports: WecomCardActionPorts): Promise<WecomCardActionResult>;
287
+ /**
288
+ * 构造卡片更新帧(aibot_respond_update_msg)。
289
+ *
290
+ * 供 caller(WecomCliInstance)把 ports.updateCard 接到 bridge.respond:
291
+ * bridge.respond(reqId, buildWecomCardUpdateBody(...).body)。
292
+ *
293
+ * 独立导出是为了单测不依赖 bridge。
294
+ */
295
+ export declare function buildWecomCardUpdateBody(input: {
296
+ cardTaskId: string;
297
+ statusLabel: string;
298
+ note?: string;
299
+ /** ★ Task #5203:view 动作携带的操作时间线 */
300
+ timeline?: WecomMilestoneLite[];
301
+ /**
302
+ * ★ Task #5250:触发更新的动作(决定更新后的按钮)。
303
+ *
304
+ * - view / reopen → 保留可点击的「刷新详情」(key=task_view):
305
+ * 用户可**重复点击**刷新最新里程碑/操作记录
306
+ * - mark_done / 缺省(旧调用方)→ 死按钮「已处理」
307
+ * (key=task_done_ack,终态确认,向后兼容 #5203 行为)
308
+ */
309
+ action?: WecomCardAction;
310
+ /**
311
+ * ★ Task #5273:任务号+标题(可选,渲染进 main_title,
312
+ * 修复「更新卡缺 Task #ID 和 title」)
313
+ */
314
+ taskTitle?: string;
315
+ taskNumber?: number;
316
+ /**
317
+ * ★ Task #5360:sub-session 活性
318
+ * (`undefined` = 不渲染;`null` = 暂无数据)
319
+ */
320
+ activity?: WecomActivityLike | null;
321
+ /** ★ Task #5360(CV MAJOR-2):任务是否已终态 */
322
+ activityTerminal?: boolean;
323
+ }): {
324
+ cmd: string;
325
+ body: Record<string, unknown>;
326
+ };
327
+ /**
328
+ * ★ Task #5364(B 方案)—— 构造 **session 卡刷新**的更新帧。
329
+ *
330
+ * 独立导出(不走 ports)是为了:
331
+ * 1. 单测能直接断言渲染结果,不依赖 bridge
332
+ * 2. `WecomCliInstance` 的 `updateSessionCard` 实现只需要两步:
333
+ * `buildWecomSessionCardUpdateBody(...)` → `sendFrameWithReqId`
334
+ *
335
+ * ## 为什么快照允许 `undefined`
336
+ *
337
+ * B 方案里持久层是「刷新时的唯一数据源」,但它可能不存在(进程刚重启 +
338
+ * 首次事件丢了 store / 老卡片)。此时**不能不给反馈** —— 用户点了按钮,
339
+ * 什么都没变比显示「暂无数据」更糟。所以降级路径渲染:状态=「状态未知」+
340
+ * 活性(活性反而是这时最有用的信号)。
341
+ */
342
+ export declare function buildWecomSessionCardUpdateBody(input: {
343
+ /** 回调带回的原始 task_id(原样回填,协议硬约束) */
344
+ cardTaskId: string;
345
+ sessionId: string;
346
+ /**
347
+ * req_id(协议必填)。命名带 ForTest 是历史遗留:生产路径由
348
+ * `updateSessionCard` 端口在 `sendFrameWithReqId` 时注入 headers,
349
+ * 这里仅用于单测直接验证帧结构。
350
+ */
351
+ reqIdForTest?: string;
352
+ /** 持久层快照;undefined = 无记录 */
353
+ state?: WecomSessionCardState;
354
+ /** 活性;undefined = 不渲染该块,null = 暂无数据 */
355
+ activity?: WecomActivityLike | null;
356
+ now?: number;
357
+ /** 关联任务(可选覆盖;缺省从 state.associatedTaskId 推导编号) */
358
+ task?: {
359
+ id: number;
360
+ title?: string;
361
+ status?: string;
362
+ progress?: number;
363
+ };
364
+ /**
365
+ * ★ Task #5419:已关联飞书群 chatId(渲染「飞书群」行)。
366
+ */
367
+ perTaskChatId?: string;
368
+ /** ★ CV 5419 MAJOR-3:建群失败提示(渲染进 sub_title) */
369
+ errorHint?: string;
370
+ }): {
371
+ cmd: string;
372
+ body: Record<string, unknown>;
373
+ };