@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,426 @@
1
+ /**
2
+ * @fileoverview Task #5203 — 企微真卡片(template_card)构造器
3
+ *
4
+ * ## 为什么存在
5
+ *
6
+ * #5193 用 markdown 模拟进展卡片(wecom-cli msg_type 无 template_card)。
7
+ * Task #5202 官方文档实锤:aibot WS 长连接协议**原生支持** template_card
8
+ * (aibot_send_msg 直发 + aibot_respond_update_msg 更新)——
9
+ * wecom-cli 只是没封装,走 WecomWsBridge 直发即可。
10
+ *
11
+ * ## 协议依据(官方文档取证,Task #5202/#5203)
12
+ *
13
+ * - 主动推送(101463):`{cmd:"aibot_send_msg", headers:{req_id},
14
+ * body:{chatid, chat_type, msgtype:"template_card", template_card:{...}}}`
15
+ * chat_type:1 单聊(userid)/ 2 群聊 / 0 兼容
16
+ * - 模板卡片类型(101032):
17
+ * - text_notice:main_title / emphasis_content 必填,card_action 必填
18
+ * - button_interaction:main_title / button_list / task_id 必填,
19
+ * button_list ≤6,按钮 key 最长 1024 字节不可重复
20
+ * - task_id:同一个机器人不能重复,只能由数字字母和 "_-@" 组成,≤128 字节
21
+ * - 卡片更新(101463):`{cmd:"aibot_respond_update_msg",
22
+ * headers:{req_id:事件回调透传}, body:{response_type:"update_template_card",
23
+ * template_card:{...}}}` — 仅适用于 template_card_event,5 秒内回复;
24
+ * template_card.task_id 须与回调收到的 task_id 一致
25
+ * - 按钮点击回调:template_card_event,event.event_key = 按钮 key
26
+ *
27
+ * ## task_id 策略
28
+ *
29
+ * 企微的 task_id 是「同一张卡的标识」(更新时用),而我们的任务
30
+ * 生命周期会**多次发卡**(每次进展一张新卡,企微无主动 patch)。
31
+ * ⇒ 发卡时用 `newWecomCardTaskId(taskId)`(带序号/时间戳,保证不重复);
32
+ * 更新时必须用**回调里带回的 task_id**(buildWecomCardUpdateFrame 的
33
+ * taskId 参数 = 回调解析出的原始 task_id)。
34
+ *
35
+ * @see wecom-ws-bridge.ts(帧发送)
36
+ * @see wecom-task-notify-plugin.ts(hook 接线)
37
+ */
38
+ import { type SubSessionActivity } from "../task/plugins/sub-session-activity";
39
+ /** 企微侧活性入参别名(与飞书侧同名类型,语义一致) */
40
+ export type WecomActivityLike = SubSessionActivity;
41
+ /** 标准按钮动作 key(回调 event_key 据此分发) */
42
+ export declare const WecomCardActionKey: {
43
+ /** 查看详情(刷操作时间线) */
44
+ readonly VIEW: "task_view";
45
+ /** 标记完成 */
46
+ readonly MARK_DONE: "task_mark_done";
47
+ /** 重新打开 */
48
+ readonly REOPEN: "task_reopen";
49
+ /**
50
+ * ★ Task #5360:刷新 sub-session 活性(消息数 + 最近一条消息)。
51
+ *
52
+ * ## 为什么与 VIEW 分成两个按钮(而不是把活性塞进「刷新详情」)
53
+ *
54
+ * 企微 `horizontal_content_list` 协议上限 **6 条**(`MAX_HORIZONTAL_ROWS`),
55
+ * 而进展/更新卡的 6 条已经被「状态 + 5 条操作时间线」占满。把活性挤进去
56
+ * 必然挤掉操作时间线 —— 直接违反用户「之前展示的信息一个都不能少」。
57
+ *
58
+ * 所以:`task_view` 管时间线(旧语义零变更),`task_refresh_activity`
59
+ * 管活性(走 quote_area,不占 horizontal 预算)。
60
+ */
61
+ readonly REFRESH_ACTIVITY: "task_refresh_activity";
62
+ /**
63
+ * ★ Task #5419:建**关联飞书群**(对齐飞书 #5403/#5397)。
64
+ *
65
+ * 用户 2026-11-13:「另外也有按钮进行飞书建群哈,功能跟飞书一样,
66
+ * 建关联飞书群,建完可以展示或者发一条企微消息带上飞书群跳转链接哈」
67
+ *
68
+ * ## 为什么企微卡可以有「飞书群」按钮
69
+ *
70
+ * wecom-card-builder 旧注释(#5360)说「企微侧本来就没有 per-task
71
+ * 群概念」—— 那指的是**企微群**。#5403 之后建群的目标是
72
+ * **飞书群**(群 session 独立 + 注入背景事件),与企微群概念
73
+ * 正交:企微只是「遥控器」,群在飞书侧。
74
+ */
75
+ readonly CREATE_LARK_GROUP: "task_create_lark_group";
76
+ };
77
+ export type WecomCardActionKey = (typeof WecomCardActionKey)[keyof typeof WecomCardActionKey];
78
+ /** 企微按钮 style:1 默认蓝 / 2 次要灰 / 3 / 4 强调(官方 1~4) */
79
+ export type WecomButtonStyle = 1 | 2 | 3 | 4;
80
+ export interface WecomCardButton {
81
+ text: string;
82
+ style?: WecomButtonStyle;
83
+ key: string;
84
+ }
85
+ export interface WecomHorizontalContent {
86
+ keyname: string;
87
+ value: string;
88
+ type?: 0 | 1;
89
+ url?: string;
90
+ }
91
+ export interface WecomMilestoneLite {
92
+ title: string;
93
+ timestamp: string;
94
+ description?: string;
95
+ }
96
+ /** text_notice 卡片结构(只声明我们用到的字段) */
97
+ export interface WecomTextNoticeCard {
98
+ card_type: "text_notice";
99
+ main_title: {
100
+ title: string;
101
+ desc?: string;
102
+ };
103
+ emphasis_content: {
104
+ title: string;
105
+ desc: string;
106
+ };
107
+ sub_title_text?: string;
108
+ horizontal_content_list: WecomHorizontalContent[];
109
+ quote_area: {
110
+ type?: number;
111
+ title: string;
112
+ quote_text: string;
113
+ };
114
+ card_action: {
115
+ type: number;
116
+ url?: string;
117
+ };
118
+ }
119
+ /** button_interaction 卡片结构(只声明我们用到的字段) */
120
+ export interface WecomButtonInteractionCard {
121
+ card_type: "button_interaction";
122
+ main_title: {
123
+ title: string;
124
+ desc?: string;
125
+ };
126
+ sub_title_text?: string;
127
+ horizontal_content_list?: WecomHorizontalContent[];
128
+ quote_area?: {
129
+ type?: number;
130
+ title: string;
131
+ quote_text: string;
132
+ };
133
+ button_list: WecomCardButton[];
134
+ card_action?: {
135
+ type: number;
136
+ url?: string;
137
+ };
138
+ /** ★ 必填:同一机器人不能重复;更新时须与回调一致 */
139
+ task_id: string;
140
+ }
141
+ /**
142
+ * 任务的稳定 task_id 前缀:`roy-task-<taskId>`。
143
+ *
144
+ * 用途:
145
+ * - 发卡时作为 `newWecomCardTaskId` 的前缀(可从回调 task_id 反解任务号)
146
+ * - 更新时**不能**用它(发卡用的是带序号的全量 id)——
147
+ * 更新帧的 task_id 必须原样用回调带回的值
148
+ */
149
+ export declare function wecomCardTaskIdForTask(taskId: number): string;
150
+ /**
151
+ * ★ 补充需求(22:31):**session 卡**的稳定 task_id 前缀。
152
+ *
153
+ * 与 `roy-task-` 并列 —— 回调时用它区分「这张卡挂在 task 上」还是
154
+ * 「挂在 sub-session 上」。两种前缀互不包含(`roy-task-` vs `roy-session-`),
155
+ * 反解无歧义。
156
+ */
157
+ export declare const ROY_SESSION_PREFIX = "roy-session-";
158
+ /**
159
+ * 造 session 卡的稳定 task_id。
160
+ *
161
+ * ## 格式(★ 澄清 22:37:session 是主键,task 是附加值)
162
+ *
163
+ * ```
164
+ * roy-session-<sessionId> ← 无关联 task
165
+ * roy-session-<sessionId>@task-<taskId> ← 有关联 task
166
+ * ```
167
+ *
168
+ * 用 `@task-` 而不是再嵌前缀:企微 task_id 字符集限定「数字字母和 `_-@`」,
169
+ * `@` 合法;且 `roy-session-` 与 `roy-task-` 本来就互斥,反解无歧义。
170
+ *
171
+ * ⚠️ 反解时**只取 sessionId 部分**(task 段仅用于诊断/未来扩展)——
172
+ * 刷新永远读 session store,这是本次澄清的核心。
173
+ */
174
+ export declare function wecomCardTaskIdForSession(sessionId: string, taskId?: number): string;
175
+ /** session 卡 task_id 里「附加 task 段」的分隔符 */
176
+ export declare const WECOM_SESSION_TASK_SEP = "@task-";
177
+ /**
178
+ * 生成一张新卡的 task_id:`roy-task-<taskId>-<seq>-<rand>`。
179
+ *
180
+ * 协议硬约束:同一机器人不能重复 → 加序号 + 随机后缀。
181
+ * 字符集:数字字母和 "_-@"(官方 101032)。
182
+ */
183
+ export declare function newWecomCardTaskId(taskId: number): string;
184
+ /**
185
+ * 构造 text_notice 进展卡(任务状态一览)。
186
+ *
187
+ * 信息密度对齐 #5193 markdown 卡:标题+进度+状态+时间线+最新操作。
188
+ */
189
+ export declare function buildWecomTextNoticeCard(input: {
190
+ taskId: number;
191
+ title: string;
192
+ statusLabel: string;
193
+ progress: number;
194
+ description?: string;
195
+ changeSummary?: string;
196
+ milestones: WecomMilestoneLite[];
197
+ /** 终态(completed/cancelled/…)→ sub_title_text 收尾文案 */
198
+ terminal?: boolean;
199
+ }): WecomTextNoticeCard;
200
+ /**
201
+ * 构造 button_interaction 交互卡(可点击按钮更新状态)。
202
+ *
203
+ * @param input.taskId 用于生成 task_id(回调据此反解任务)
204
+ * @param input.buttons 超过 6 个时只取前 6 个(协议上限)
205
+ */
206
+ export declare function buildWecomButtonInteractionCard(input: {
207
+ taskId: number;
208
+ title: string;
209
+ statusLabel: string;
210
+ progress: number;
211
+ description?: string;
212
+ changeSummary?: string;
213
+ milestones?: WecomMilestoneLite[];
214
+ buttons: WecomCardButton[];
215
+ /** 已有的 task_id(更新场景复用;发新卡时不传自动生成) */
216
+ cardTaskId?: string;
217
+ }): WecomButtonInteractionCard;
218
+ /** session 层生命周期(与飞书侧同义) */
219
+ export type WecomSessionLifecycle = "running" | "completed" | "timeout" | "failed" | "stopped";
220
+ /**
221
+ * ★ Task #5364(DS review R1 MAJOR-2)—— **刷新帧**用的生命周期。
222
+ *
223
+ * 比 `WecomSessionLifecycle` 多一个 `unknown`:刷新时若持久层没有该
224
+ * session 的记录(进程重启 / store 读失败 / 更早版本发的卡),我们
225
+ * **不知道**它是什么状态。此时必须如实说「未知」而不是乐观地报
226
+ * 「运行中」—— 后者会和活性侧的 🔴 疑似停滞 同时出现在一张卡上,
227
+ * 给用户两个互相矛盾的信号。
228
+ */
229
+ export type WecomSessionUpdateLifecycle = WecomSessionLifecycle | "unknown";
230
+ /**
231
+ * ★ Task #5360(用户明令「企微也是这个逻辑」)—— 构造**企微 session 卡**。
232
+ *
233
+ * ## 与 task 卡的关系:并列,共用零件
234
+ *
235
+ * 不复用 `buildWecomButtonInteractionCard` 的原因:那个签名是
236
+ * `taskId: number`(必填)+ `buildWecomTextNoticeCard` 的进度百分比语义,
237
+ * session 没有 task 号也没有「进度 %」。硬塞会渲染出 `Task #0` / `0%` 这类噪音。
238
+ *
239
+ * 共用的是:`WecomButtonInteractionCard` 结构、按钮裁剪、`formatActivityQuote`
240
+ * (⇒ 活性阈值与文案与飞书/企微 task 卡**完全一致**,不会出现同一个
241
+ * session 在两个渠道颜色不同)。
242
+ *
243
+ * ## 主键
244
+ *
245
+ * `task_id = roy-session-<sessionId>[@task-<n>]` —— 回调时
246
+ * `parseRoySessionId` 反解出干净的 sessionId,刷新走 session 主键路径。
247
+ *
248
+ * ## 建群按钮(★ Task #5419 更新)
249
+ *
250
+ * #5360 时企微侧没有建群按钮(当时建群目标是企微群,确实没有)。
251
+ * #5403 之后建群目标改为**飞书群**(独立群 session + 背景事件),
252
+ * 企微卡只是遥控入口 —— 用户 2026-11-13 明令「也有按钮进行飞书
253
+ * 建群哈,功能跟飞书一样」。故 session 卡无条件渲染「建飞书群」。
254
+ */
255
+ export declare function buildWecomSessionCard(input: {
256
+ /** ★ 主键:sub-session id */
257
+ sessionId: string;
258
+ /** session 层生命周期(★ 与有无 task 无关) */
259
+ lifecycle?: WecomSessionLifecycle;
260
+ /** 会话标题(描述 / agent 名);缺省用 sessionId 截断 */
261
+ title?: string;
262
+ /** 所属 agent(subagentType) */
263
+ agentType?: string;
264
+ /** 开始时间(ISO) */
265
+ startedAt?: string;
266
+ /** 已运行时长(人类可读) */
267
+ elapsedText?: string;
268
+ /**
269
+ * ★ 该 session 内创建的 task(可选增强)。
270
+ * 有 → 卡上多一行任务信息;无 → 只显示 session 活性。
271
+ */
272
+ task?: {
273
+ id: number;
274
+ title?: string;
275
+ status?: string;
276
+ progress?: number;
277
+ };
278
+ /** 活性快照。undefined = 不渲染;null = 暂无数据 */
279
+ activity?: WecomActivityLike | null;
280
+ activityNow?: number;
281
+ /** 执行动态(会话级里程碑) */
282
+ milestones?: WecomMilestoneLite[];
283
+ }): WecomButtonInteractionCard;
284
+ /**
285
+ * 构造 aibot_send_msg 直发 template_card 帧。
286
+ *
287
+ * @param input.chatType "single"(chat_type=1,chatid=userid)|
288
+ * "group"(chat_type=2,chatid=群 chatid)
289
+ */
290
+ export declare function buildWecomSendCardFrame(input: {
291
+ chatId: string;
292
+ chatType: "single" | "group";
293
+ card: WecomTextNoticeCard | WecomButtonInteractionCard;
294
+ /** 显式 req_id(缺省自动生成 aibot_send_msg_ 前缀) */
295
+ reqId?: string;
296
+ }): {
297
+ cmd: string;
298
+ headers: {
299
+ req_id: string;
300
+ };
301
+ body: Record<string, unknown>;
302
+ };
303
+ /**
304
+ * 构造 aibot_respond_update_msg 更新帧(按钮点击后 5 秒窗口内)。
305
+ *
306
+ * ★ 协议硬约束:
307
+ * - req_id 必须**原样透传** template_card_event 回调帧的 req_id
308
+ * - template_card.task_id 必须与回调收到的 task_id 一致
309
+ * (回调的 task_id 是发卡时的全量 id,不是 roy-task-<n> 前缀)
310
+ *
311
+ * @param input.taskId 回调解析出的**原始** task_id(原样回填)
312
+ */
313
+ export declare function buildWecomCardUpdateFrame(input: {
314
+ reqId: string;
315
+ /** 回调带回的原始 task_id(原样回填,不做转换) */
316
+ taskId: string;
317
+ statusLabel: string;
318
+ note?: string;
319
+ /** 更新后的按钮列表(如把「标记完成」换成「已确认」) */
320
+ buttonOverrides?: WecomCardButton[];
321
+ /**
322
+ * ★ Task #5203 时间线详情:操作记录(milestones + processSteps)
323
+ * 渲染成 quote_area 引用文本(每行一条,最新在上)。
324
+ */
325
+ timeline?: WecomMilestoneLite[];
326
+ /**
327
+ * ★ Task #5273:任务标题(可选)。
328
+ *
329
+ * 用户反馈更新卡缺任务号/标题 → main_title 从
330
+ * `📋 ${statusLabel}` 升级为
331
+ * `📋 Task #<n> · <title> · ${statusLabel}`(缺省字段自动省略,
332
+ * 向后兼容旧调用方)。
333
+ */
334
+ taskTitle?: string;
335
+ /** ★ Task #5273:roy 任务号(可选,与 taskTitle 配对渲染) */
336
+ taskNumber?: number;
337
+ /**
338
+ * ★ Task #5360:sub-session 活性(用户点「刷新活性」时传入)。
339
+ *
340
+ * - `undefined` → 不渲染活性(普通 view / mark_done,行为与改造前一致)
341
+ * - `null` → 渲染「暂无数据」(用户点过了,必须有反馈)
342
+ * - 快照 → 渲染信号灯 + 消息数 + 最近消息
343
+ */
344
+ activity?: WecomActivityLike | null;
345
+ /** ★ Task #5360:活性时间基准(注入便于测试;缺省 Date.now()) */
346
+ activityNow?: number;
347
+ /** ★ Task #5360:任务是否终态(决定报「已结束」而非「疑似停滞」) */
348
+ activityTerminal?: boolean;
349
+ }): {
350
+ cmd: string;
351
+ headers: {
352
+ req_id: string;
353
+ };
354
+ body: Record<string, unknown>;
355
+ };
356
+ /**
357
+ * ★ Task #5364(用户 2026-11-12 08:34 拍板 B)——
358
+ * 构造 **session 卡的更新帧**(`aibot_respond_update_msg`)。
359
+ *
360
+ * ## 为什么需要它(B 方案的落点)
361
+ *
362
+ * 企微协议:`aibot_respond_update_msg` 只能在 `template_card_event` 回调的
363
+ * 5 秒窗口内、用回调带回的 `req_id` 发。生命周期事件没有 req_id ⇒ **无法主动
364
+ * patch**。所以「一张卡承载整个生命周期」只能靠**用户点按钮把窗口打开**。
365
+ *
366
+ * ⇒ 这张帧必须在**一次渲染里装齐全部信息**(这是用户唯一能看到的最新快照):
367
+ *
368
+ * | 信息 | 来源 | 为什么不能省 |
369
+ * |------|------|--------------|
370
+ * | 生命周期状态 | store.lifecycle | 用户要知道「跑完了没 / 是超时还是失败」 |
371
+ * | 会话详情(id/agent/已运行) | store + startedAt | 首次发卡时的信息,刷新不能擦掉 |
372
+ * | 任务增强(Task #id/title/status) | store.associatedTaskId → task | 有 task 时后端不再发 task 卡,信息必须在这 |
373
+ * | 操作记录(milestones 时间线) | store.milestones | 「这一路发生了什么」 |
374
+ * | 活性(消息数 + 最近 msg) | 实时 probe | 判断 LLM 有没有真在推进 |
375
+ *
376
+ * ## 与 `buildWecomSessionCard`(首发帧)的关系
377
+ *
378
+ * 同一套排版口径(生命周期文案表 / 行裁剪 / `formatActivityQuote`),
379
+ * 但它是**整卡替换**(update 帧的 schema 要求),所以这里重新组装一份,
380
+ * 而不是复用首发卡的返回值 —— 首发卡是 `aibot_send_msg` 的 body 形状。
381
+ *
382
+ * @param input.reqId 回调带回的 req_id(**必须**,缺失直接抛)
383
+ * @param input.cardTaskId 回调带回的原始 `template_card.task_id`(原样回填)
384
+ */
385
+ export declare function buildWecomSessionUpdateFrame(input: {
386
+ reqId: string;
387
+ /** 回调带回的原始 task_id(协议要求原样回填) */
388
+ cardTaskId: string;
389
+ sessionId: string;
390
+ lifecycle: WecomSessionUpdateLifecycle;
391
+ /** 会话标题(缺省用 sessionId 截断) */
392
+ title?: string;
393
+ agentType?: string;
394
+ /** 开始时间(ISO);用于算「已运行」 */
395
+ startedAt?: string;
396
+ /** 已运行时长(优先用调用方算好的;缺省由 startedAt + now 推导) */
397
+ elapsedText?: string;
398
+ /** 关联 roy 任务(可选增强) */
399
+ task?: {
400
+ id: number;
401
+ title?: string;
402
+ status?: string;
403
+ progress?: number;
404
+ };
405
+ /** 累积操作记录(最新在后;渲染时反转成最新在顶部) */
406
+ milestones?: WecomMilestoneLite[];
407
+ /**
408
+ * ★ Task #5419:该 session 已关联的**飞书群** chatId。
409
+ *
410
+ * 有 ⇒ horizontal 加一行「飞书群」(applink 跳转),
411
+ * 建群后按钮翻面语义由 handler 控制(幂等命中不重复建)。
412
+ */
413
+ perTaskChatId?: string;
414
+ /** ★ CV 5419 MAJOR-3:建群失败提示(渲染进 sub_title) */
415
+ errorHint?: string;
416
+ /** 活性快照。undefined = 不渲染;null = 暂无数据(用户点了必须有反馈) */
417
+ activity?: WecomActivityLike | null;
418
+ /** 时间基准(注入便于测试) */
419
+ now?: number;
420
+ }): {
421
+ cmd: string;
422
+ headers: {
423
+ req_id: string;
424
+ };
425
+ body: Record<string, unknown>;
426
+ };