@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,288 @@
1
+ // src/env/task/plugins/sub-session-activity.ts
2
+ function flattenInline(text) {
3
+ return text.replace(/\r\n?/g, `
4
+ `).replace(/\n+/g, " · ").replace(/\s{2,}/g, " ").replace(/(?:\s*·\s*){2,}/g, " · ").replace(/^(\s*·\s*)+/, "").replace(/(\s*·\s*)+$/, "").trim();
5
+ }
6
+ var ACTIVITY_ACTIVE_MS = 5 * 60 * 1000;
7
+ var ACTIVITY_SLOW_MS = 20 * 60 * 1000;
8
+ var DEFAULT_ACTIVITY_MESSAGE_MAX = 200;
9
+ function formatAgo(updatedAt, now) {
10
+ if (updatedAt === undefined || !Number.isFinite(updatedAt))
11
+ return;
12
+ const diff = now - updatedAt;
13
+ if (!Number.isFinite(diff) || diff < 60000)
14
+ return "刚刚";
15
+ const minutes = Math.floor(diff / 60000);
16
+ if (minutes < 60)
17
+ return `${minutes} 分钟前`;
18
+ const hours = Math.floor(minutes / 60);
19
+ if (hours < 24)
20
+ return `${hours} 小时前`;
21
+ return `${Math.floor(hours / 24)} 天前`;
22
+ }
23
+ function formatClockTime(ts) {
24
+ if (ts === undefined || !Number.isFinite(ts))
25
+ return;
26
+ const d = new Date(ts);
27
+ if (Number.isNaN(d.getTime()))
28
+ return;
29
+ const pad = (n) => n < 10 ? `0${n}` : String(n);
30
+ return `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;
31
+ }
32
+ function resolveActivityLiveness(activity, now, terminal = false) {
33
+ if (!activity) {
34
+ return { level: "unknown", dot: "❔", label: "未知" };
35
+ }
36
+ const agoText = formatAgo(activity.updatedAt, now);
37
+ if (terminal) {
38
+ return { level: "terminal", dot: "⚪", label: "已结束", agoText };
39
+ }
40
+ const updatedAt = activity.updatedAt;
41
+ if (updatedAt === undefined || !Number.isFinite(updatedAt)) {
42
+ return { level: "unknown", dot: "❔", label: "未知", agoText };
43
+ }
44
+ const age = now - updatedAt;
45
+ if (!Number.isFinite(age) || age < ACTIVITY_ACTIVE_MS) {
46
+ return { level: "active", dot: "\uD83D\uDFE2", label: "活跃", agoText };
47
+ }
48
+ if (age < ACTIVITY_SLOW_MS) {
49
+ return { level: "slow", dot: "\uD83D\uDFE1", label: "缓慢", agoText };
50
+ }
51
+ return { level: "stalled", dot: "\uD83D\uDD34", label: "疑似停滞", agoText };
52
+ }
53
+ function truncateActivityMessage(text, max = DEFAULT_ACTIVITY_MESSAGE_MAX) {
54
+ if (!text)
55
+ return "";
56
+ const flat = flattenInline(text);
57
+ if (!flat)
58
+ return "";
59
+ if (flat.length <= max)
60
+ return flat;
61
+ const cut = flat.slice(0, max - 1);
62
+ const lastSpace = cut.lastIndexOf(" ");
63
+ if (lastSpace > max * 0.6)
64
+ return `${cut.slice(0, lastSpace).trimEnd()}…`;
65
+ return `${cut}…`;
66
+ }
67
+ function formatActivityLines(activity, now, terminal = false) {
68
+ const live = resolveActivityLiveness(activity, now, terminal);
69
+ if (!activity) {
70
+ return ["❔ 暂无数据(子会话已归档或未落盘)"];
71
+ }
72
+ const headParts = [];
73
+ const agoPhrase = live.agoText ? `(${live.agoText}有写入)` : "";
74
+ headParts.push(`${live.dot} ${live.label}${agoPhrase}`);
75
+ headParts.push(`消息数 ${activity.messageCount} 条`);
76
+ const lines = [headParts.join(" · ")];
77
+ const clock = formatClockTime(activity.updatedAt);
78
+ if (clock)
79
+ lines.push(`\uD83D\uDD50 最近写入:${clock}`);
80
+ const last = activity.lastMessage;
81
+ if (last && last.content) {
82
+ const role = last.role ? `[${last.role}] ` : "";
83
+ lines.push(`\uD83D\uDCAC 最近消息:${role}${last.content}`);
84
+ } else {
85
+ lines.push("\uD83D\uDCAC 最近消息:(暂无文本消息)");
86
+ }
87
+ return lines;
88
+ }
89
+ function formatActivityQuote(activity, now, terminal = false) {
90
+ const live = resolveActivityLiveness(activity, now, terminal);
91
+ if (!activity) {
92
+ return {
93
+ title: "⚡ 子会话活性",
94
+ text: "❔ 暂无数据(子会话已归档或未落盘)",
95
+ overflow: false
96
+ };
97
+ }
98
+ const agoPhrase = live.agoText ? `(${live.agoText}有写入)` : "";
99
+ const head = `${live.dot} ${live.label}${agoPhrase} · 消息数 ${activity.messageCount} 条`;
100
+ const last = activity.lastMessage;
101
+ const role = last?.role ? `[${last.role}] ` : "";
102
+ const body = last?.content ? `${role}${truncateActivityMessage(last.content, 80)}` : "(暂无文本消息)";
103
+ const text = `${head}
104
+ \uD83D\uDCAC ${body}`;
105
+ const overflow = text.length > 112;
106
+ return { title: "⚡ 子会话活性", text, overflow };
107
+ }
108
+ function findBackgroundTaskByAssociatedTaskId(tasks, taskId) {
109
+ if (!tasks || tasks.length === 0)
110
+ return;
111
+ if (!Number.isFinite(taskId))
112
+ return;
113
+ let found;
114
+ for (const t of tasks) {
115
+ if (!t || typeof t.subSessionId !== "string" || !t.subSessionId)
116
+ continue;
117
+ if (t.associatedTaskId === taskId)
118
+ found = t;
119
+ }
120
+ return found;
121
+ }
122
+ function createSessionActivityProbe(ports) {
123
+ return async (sessionId) => {
124
+ if (!sessionId)
125
+ return { activity: undefined, terminal: false };
126
+ let session;
127
+ try {
128
+ session = await ports.getSession?.(sessionId);
129
+ } catch {
130
+ session = undefined;
131
+ }
132
+ if (!session)
133
+ return { activity: undefined, terminal: false };
134
+ let lastMessage;
135
+ try {
136
+ lastMessage = await ports.getLastMessage?.(sessionId);
137
+ } catch {
138
+ lastMessage = undefined;
139
+ }
140
+ let lifecycle = "running";
141
+ try {
142
+ lifecycle = await ports.getLifecycle?.(sessionId) ?? "running";
143
+ } catch {
144
+ lifecycle = "running";
145
+ }
146
+ return {
147
+ lifecycle,
148
+ terminal: lifecycle !== "running",
149
+ activity: {
150
+ subSessionId: sessionId,
151
+ messageCount: typeof session.messageCount === "number" ? session.messageCount : 0,
152
+ updatedAt: typeof session.updatedAt === "number" ? session.updatedAt : Number.NaN,
153
+ ...lastMessage ? { lastMessage } : {}
154
+ }
155
+ };
156
+ };
157
+ }
158
+ function createActivityProbe(ports) {
159
+ return async (taskId) => {
160
+ let terminal = false;
161
+ try {
162
+ terminal = await ports.isTerminalTask?.(taskId) ?? false;
163
+ } catch {
164
+ terminal = false;
165
+ }
166
+ let task;
167
+ try {
168
+ task = findBackgroundTaskByAssociatedTaskId(ports.listBackgroundTasks?.(), taskId);
169
+ } catch {
170
+ task = undefined;
171
+ }
172
+ if (!task)
173
+ return { activity: undefined, terminal };
174
+ let stats;
175
+ try {
176
+ stats = await ports.getSubSessionActivity?.(task.id);
177
+ } catch {
178
+ stats = undefined;
179
+ }
180
+ if (!stats)
181
+ return { activity: undefined, terminal };
182
+ let lastMessage;
183
+ try {
184
+ lastMessage = await ports.getLastMessage?.(task.subSessionId);
185
+ } catch {
186
+ lastMessage = undefined;
187
+ }
188
+ return {
189
+ terminal,
190
+ activity: {
191
+ subSessionId: task.subSessionId,
192
+ messageCount: stats.messageCount ?? 0,
193
+ updatedAt: stats.updatedAt,
194
+ ...lastMessage ? { lastMessage } : {}
195
+ }
196
+ };
197
+ };
198
+ }
199
+ function toActivityMessage(msg, max = DEFAULT_ACTIVITY_MESSAGE_MAX) {
200
+ if (!msg)
201
+ return;
202
+ let text = msg.content;
203
+ if (!text || text.length === 0) {
204
+ const textParts = [];
205
+ for (const part of msg.parts ?? []) {
206
+ if (part?.type === "text" && typeof part.content === "string") {
207
+ textParts.push(part.content);
208
+ } else if (part?.type === "tool-result" && typeof part.output === "string") {
209
+ textParts.push(part.output);
210
+ }
211
+ }
212
+ if (textParts.length > 0)
213
+ text = textParts.join(" ");
214
+ }
215
+ const content = truncateActivityMessage(text, max);
216
+ if (!content) {
217
+ if (max === DEFAULT_ACTIVITY_MESSAGE_MAX)
218
+ return;
219
+ return {
220
+ role: typeof msg.role === "string" ? msg.role : "unknown",
221
+ content: "(无文本内容)",
222
+ ...typeof msg.timestamp === "number" ? { timestamp: msg.timestamp } : {}
223
+ };
224
+ }
225
+ return {
226
+ role: typeof msg.role === "string" ? msg.role : "unknown",
227
+ content,
228
+ ...typeof msg.timestamp === "number" ? { timestamp: msg.timestamp } : {}
229
+ };
230
+ }
231
+ function mapBgTaskStatusToSessionLifecycle(status) {
232
+ switch (status) {
233
+ case "completed":
234
+ return "completed";
235
+ case "timeout":
236
+ case "timed_out":
237
+ return "timeout";
238
+ case "failed":
239
+ case "error":
240
+ return "failed";
241
+ case "stopped":
242
+ case "cancelled":
243
+ case "canceled":
244
+ case "aborted":
245
+ return "stopped";
246
+ default:
247
+ return "running";
248
+ }
249
+ }
250
+ var RECENT_MESSAGE_LIMIT = 5;
251
+ var RECENT_MESSAGE_MAX = 100;
252
+ function extractToolCallsFromMessages(messages) {
253
+ const calls = [];
254
+ for (const msg of messages ?? []) {
255
+ for (const part of msg?.parts ?? []) {
256
+ if (part?.type !== "tool-call")
257
+ continue;
258
+ const toolName = typeof part.toolName === "string" ? part.toolName : undefined;
259
+ if (!toolName)
260
+ continue;
261
+ let args;
262
+ if (typeof part.arguments === "string") {
263
+ try {
264
+ const parsed = JSON.parse(part.arguments);
265
+ if (parsed && typeof parsed === "object") {
266
+ args = parsed;
267
+ }
268
+ } catch {}
269
+ } else if (part.arguments && typeof part.arguments === "object") {
270
+ args = part.arguments;
271
+ }
272
+ const reason = typeof args?.reason === "string" && args.reason.trim().length > 0 ? args.reason.trim() : undefined;
273
+ calls.push({ toolName, ...reason ? { reason } : {} });
274
+ }
275
+ }
276
+ return calls;
277
+ }
278
+ function formatRecentToolCallLines(calls, max = RECENT_MESSAGE_MAX) {
279
+ if (!calls || calls.length === 0) {
280
+ return ["暂无工具调用"];
281
+ }
282
+ return calls.map((c) => {
283
+ const reason = truncateActivityMessage(c?.reason, max) || "—";
284
+ return `- ${c?.toolName ?? "未知"}:${reason}`;
285
+ });
286
+ }
287
+
288
+ export { formatActivityLines, formatActivityQuote, createSessionActivityProbe, createActivityProbe, toActivityMessage, mapBgTaskStatusToSessionLifecycle, RECENT_MESSAGE_LIMIT, extractToolCallsFromMessages, formatRecentToolCallLines };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  TagRepository
3
- } from "./roy-agent-core-mcy5apay.js";
3
+ } from "./roy-agent-core-vf9sp6s3.js";
4
4
  import {
5
5
  exports_search_query_parser,
6
6
  init_search_query_parser
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TracedAs,
3
3
  init_decorator
4
- } from "./roy-agent-core-qq96p0tj.js";
4
+ } from "./roy-agent-core-5s2t8z00.js";
5
5
  import {
6
6
  __legacyDecorateClassTS,
7
7
  __require
@@ -6,7 +6,7 @@ import {
6
6
  } from "./roy-agent-core-7hh0brvs.js";
7
7
  import {
8
8
  BaseComponent
9
- } from "./roy-agent-core-pgvcf91v.js";
9
+ } from "./roy-agent-core-m39v7qpx.js";
10
10
  import {
11
11
  createLogger,
12
12
  init_logger
@@ -60,6 +60,24 @@ function safeJsonLen(value) {
60
60
  return 0;
61
61
  }
62
62
  }
63
+ function extractToolNames(tools) {
64
+ if (!Array.isArray(tools))
65
+ return { toolNames: [], toolNamesTruncated: false };
66
+ const names = [];
67
+ let chars = 0;
68
+ for (const t of tools) {
69
+ const raw = t?.name;
70
+ if (typeof raw !== "string" || raw.length === 0)
71
+ continue;
72
+ const name = raw.length > TOOL_NAME_MAX_CHARS ? `${raw.slice(0, TOOL_NAME_MAX_CHARS)}…` : raw;
73
+ if (names.length >= TOOL_NAMES_COUNT_CAP || chars + name.length > TOOL_NAMES_CHAR_BUDGET) {
74
+ return { toolNames: names, toolNamesTruncated: true };
75
+ }
76
+ names.push(name);
77
+ chars += name.length;
78
+ }
79
+ return { toolNames: names, toolNamesTruncated: false };
80
+ }
63
81
  function llmInvokeParamFilter(args) {
64
82
  if (isTraceFullMode()) {
65
83
  return { args };
@@ -67,6 +85,7 @@ function llmInvokeParamFilter(args) {
67
85
  const p = (args ?? [])[0];
68
86
  const ctx = p?.context ?? p?.ctx ?? null;
69
87
  const msgs = Array.isArray(p?.messages) ? p.messages : [];
88
+ const { toolNames, toolNamesTruncated } = extractToolNames(p?.tools);
70
89
  return {
71
90
  model: p?.model ?? p?.modelId ?? ctx?.model ?? null,
72
91
  provider: p?.provider ?? p?.providerId ?? null,
@@ -74,6 +93,8 @@ function llmInvokeParamFilter(args) {
74
93
  messageCount: msgs.length,
75
94
  totalChars: totalMessageChars(msgs),
76
95
  tools: Array.isArray(p?.tools) ? p.tools.length : 0,
96
+ toolNames,
97
+ ...toolNamesTruncated ? { toolNamesTruncated } : {},
77
98
  maxTokens: p?.maxTokens ?? null,
78
99
  temperature: p?.temperature ?? null
79
100
  };
@@ -292,7 +313,7 @@ function recordSessionMessagesParamFilter(args) {
292
313
  totalChars: chars
293
314
  };
294
315
  }
295
- var traceFullModeCache, MAX_COMMAND_CHARS = 2000;
316
+ var traceFullModeCache, TOOL_NAMES_COUNT_CAP = 100, TOOL_NAMES_CHAR_BUDGET = 1024, TOOL_NAME_MAX_CHARS = 120, MAX_COMMAND_CHARS = 2000;
296
317
  var init_trace_filters = () => {};
297
318
 
298
319
  // src/env/log-trace/decorator.ts
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  AgentComponentAdapter,
9
9
  init_agent_component_adapter
10
- } from "./roy-agent-core-dqxec05w.js";
10
+ } from "./roy-agent-core-bjtc9d35.js";
11
11
  import {
12
12
  PythonCallNode,
13
13
  SkillNode,
@@ -17,7 +17,7 @@ import {
17
17
  init_skill_node,
18
18
  init_tool_node,
19
19
  init_workflow_node
20
- } from "./roy-agent-core-efkjyh69.js";
20
+ } from "./roy-agent-core-9710zwwz.js";
21
21
  import {
22
22
  WORKFLOW_SUBMIT_OUTPUT_TOOL_NAME,
23
23
  init_json_schema_to_zod,
@@ -28,20 +28,20 @@ import {
28
28
  } from "./roy-agent-core-1db4vpc6.js";
29
29
  import {
30
30
  init_hooks
31
- } from "./roy-agent-core-dvtg4sn0.js";
31
+ } from "./roy-agent-core-g8yr733d.js";
32
32
  import {
33
33
  WorkflowHookPoints,
34
34
  emitWorkflowNodeHook,
35
35
  emitWorkflowRunHook
36
- } from "./roy-agent-core-c2gbt68e.js";
36
+ } from "./roy-agent-core-h83zdsrq.js";
37
37
  import {
38
38
  TemplateResolver,
39
39
  init_template_resolver
40
- } from "./roy-agent-core-acj8ag08.js";
40
+ } from "./roy-agent-core-tjnabyvq.js";
41
41
  import {
42
42
  DAGManager,
43
43
  init_dag_manager
44
- } from "./roy-agent-core-cgtq6427.js";
44
+ } from "./roy-agent-core-e08bvpaq.js";
45
45
  import {
46
46
  WorkflowError,
47
47
  createWorkflowEvent,
@@ -57,7 +57,7 @@ import {
57
57
  import {
58
58
  TracedAs,
59
59
  init_decorator
60
- } from "./roy-agent-core-qq96p0tj.js";
60
+ } from "./roy-agent-core-5s2t8z00.js";
61
61
  import {
62
62
  createLogger,
63
63
  init_logger
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TracedAs,
3
3
  init_decorator
4
- } from "./roy-agent-core-qq96p0tj.js";
4
+ } from "./roy-agent-core-5s2t8z00.js";
5
5
  import {
6
6
  createLogger,
7
7
  init_logger
@@ -4,7 +4,7 @@ import {
4
4
  } from "./roy-agent-core-7hh0brvs.js";
5
5
  import {
6
6
  BaseComponent
7
- } from "./roy-agent-core-pgvcf91v.js";
7
+ } from "./roy-agent-core-m39v7qpx.js";
8
8
  import {
9
9
  createLogger,
10
10
  init_logger
@@ -0,0 +1,177 @@
1
+ import {
2
+ createCompatibleDatabase,
3
+ init_sqlite_task_store
4
+ } from "./roy-agent-core-6k8mb7zx.js";
5
+ import {
6
+ createLogger,
7
+ init_logger
8
+ } from "./roy-agent-core-7f7t9wwp.js";
9
+
10
+ // src/env/task/plugins/wecom-session-card-store.ts
11
+ init_logger();
12
+ init_sqlite_task_store();
13
+ import { join } from "path";
14
+ var logger = createLogger("wecom:session-card-state");
15
+
16
+ class MemoryWecomSessionCardStore {
17
+ records = new Map;
18
+ upsert(state) {
19
+ this.records.set(state.sessionId, { ...state });
20
+ }
21
+ get(sessionId) {
22
+ const r = this.records.get(sessionId);
23
+ return r ? { ...r } : undefined;
24
+ }
25
+ list() {
26
+ return [...this.records.values()].map((r) => ({ ...r }));
27
+ }
28
+ markClosed(sessionId) {
29
+ const r = this.records.get(sessionId);
30
+ if (!r)
31
+ return;
32
+ const now = Date.now();
33
+ r.lifecycle = r.lifecycle === "running" ? "completed" : r.lifecycle;
34
+ r.closedAt = now;
35
+ r.updatedAt = now;
36
+ }
37
+ delete(sessionId) {
38
+ this.records.delete(sessionId);
39
+ }
40
+ close() {
41
+ this.records.clear();
42
+ }
43
+ }
44
+ function createMemoryWecomSessionCardStore() {
45
+ return new MemoryWecomSessionCardStore;
46
+ }
47
+ function rowToSessionState(row) {
48
+ const state = {
49
+ sessionId: row.session_id,
50
+ chatId: row.chat_id,
51
+ chatType: row.chat_type === "group" ? "group" : "single",
52
+ cardTaskId: row.card_task_id,
53
+ lifecycle: row.lifecycle ?? "running",
54
+ createdAt: row.created_at,
55
+ updatedAt: row.updated_at
56
+ };
57
+ if (row.source_id)
58
+ state.sourceId = row.source_id;
59
+ if (row.title)
60
+ state.title = row.title;
61
+ if (row.agent_type)
62
+ state.agentType = row.agent_type;
63
+ if (row.started_at)
64
+ state.startedAt = row.started_at;
65
+ if (row.associated_task_id !== null && row.associated_task_id !== undefined) {
66
+ state.associatedTaskId = row.associated_task_id;
67
+ }
68
+ if (row.milestones)
69
+ state.milestones = row.milestones;
70
+ if (row.closed_at !== null && row.closed_at !== undefined) {
71
+ state.closedAt = row.closed_at;
72
+ }
73
+ return state;
74
+ }
75
+
76
+ class SqliteWecomSessionCardStore {
77
+ db;
78
+ constructor(dbPath) {
79
+ this.db = createCompatibleDatabase(dbPath);
80
+ try {
81
+ this.db.run("PRAGMA journal_mode = WAL");
82
+ this.db.run("PRAGMA busy_timeout = 5000");
83
+ this.db.run("PRAGMA synchronous = NORMAL");
84
+ } catch {}
85
+ this.db.run(`
86
+ CREATE TABLE IF NOT EXISTS wecom_session_card (
87
+ session_id TEXT PRIMARY KEY,
88
+ chat_id TEXT NOT NULL,
89
+ chat_type TEXT NOT NULL DEFAULT 'single',
90
+ source_id TEXT,
91
+ card_task_id TEXT NOT NULL,
92
+ lifecycle TEXT NOT NULL DEFAULT 'running',
93
+ title TEXT,
94
+ agent_type TEXT,
95
+ started_at TEXT,
96
+ associated_task_id INTEGER,
97
+ milestones TEXT,
98
+ created_at INTEGER NOT NULL,
99
+ updated_at INTEGER NOT NULL,
100
+ closed_at INTEGER
101
+ )
102
+ `);
103
+ this.db.run("CREATE INDEX IF NOT EXISTS idx_wecom_session_card_lifecycle " + "ON wecom_session_card(lifecycle)");
104
+ }
105
+ upsert(state) {
106
+ this.db.prepare(`INSERT INTO wecom_session_card
107
+ (session_id, chat_id, chat_type, source_id, card_task_id, lifecycle,
108
+ title, agent_type, started_at, associated_task_id, milestones,
109
+ created_at, updated_at, closed_at)
110
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
111
+ ON CONFLICT(session_id) DO UPDATE SET
112
+ chat_id = excluded.chat_id,
113
+ chat_type = excluded.chat_type,
114
+ source_id = excluded.source_id,
115
+ card_task_id = excluded.card_task_id,
116
+ lifecycle = excluded.lifecycle,
117
+ title = excluded.title,
118
+ agent_type = excluded.agent_type,
119
+ started_at = excluded.started_at,
120
+ associated_task_id = excluded.associated_task_id,
121
+ milestones = excluded.milestones,
122
+ updated_at = excluded.updated_at,
123
+ closed_at = excluded.closed_at`).run(state.sessionId, state.chatId, state.chatType, state.sourceId ?? null, state.cardTaskId, state.lifecycle, state.title ?? null, state.agentType ?? null, state.startedAt ?? null, state.associatedTaskId ?? null, state.milestones ?? null, state.createdAt, state.updatedAt, state.closedAt ?? null);
124
+ }
125
+ get(sessionId) {
126
+ const row = this.db.prepare("SELECT * FROM wecom_session_card WHERE session_id = ?").get(sessionId);
127
+ return row ? rowToSessionState(row) : undefined;
128
+ }
129
+ list() {
130
+ const rows = this.db.prepare("SELECT * FROM wecom_session_card ORDER BY created_at ASC").all();
131
+ return rows.map(rowToSessionState);
132
+ }
133
+ markClosed(sessionId) {
134
+ const now = Date.now();
135
+ this.db.prepare("UPDATE wecom_session_card SET closed_at = ?, updated_at = ? " + "WHERE session_id = ?").run(now, now, sessionId);
136
+ }
137
+ delete(sessionId) {
138
+ this.db.prepare("DELETE FROM wecom_session_card WHERE session_id = ?").run(sessionId);
139
+ }
140
+ close() {
141
+ try {
142
+ this.db.close?.();
143
+ } catch {}
144
+ }
145
+ }
146
+ function getDefaultWecomSessionCardDbPath() {
147
+ const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
148
+ return join(home, ".local", "share", "roy-agent", "wecom-session-cards.db");
149
+ }
150
+ function createWecomSessionCardStore(dbPath) {
151
+ const isTestEnv = "BUN_TEST_WORKER_ID" in process.env;
152
+ if (!dbPath && !process.env.ROY_AGENT_WECOM_SESSION_CARD_DB && isTestEnv) {
153
+ return new MemoryWecomSessionCardStore;
154
+ }
155
+ const path = dbPath ?? process.env.ROY_AGENT_WECOM_SESSION_CARD_DB ?? getDefaultWecomSessionCardDbPath();
156
+ try {
157
+ return new SqliteWecomSessionCardStore(path);
158
+ } catch (err) {
159
+ logger.warn(`WecomSessionCardStore: sqlite unavailable at ${path} ` + `(${err.message}) —— 降级为内存实现`);
160
+ return new MemoryWecomSessionCardStore;
161
+ }
162
+ }
163
+ var sharedStore = null;
164
+ function getSharedWecomSessionCardStore() {
165
+ if (!sharedStore) {
166
+ sharedStore = createWecomSessionCardStore();
167
+ }
168
+ return sharedStore;
169
+ }
170
+ function __resetSharedWecomSessionCardStoreForTest() {
171
+ try {
172
+ sharedStore?.close?.();
173
+ } catch {}
174
+ sharedStore = null;
175
+ }
176
+
177
+ export { MemoryWecomSessionCardStore, createMemoryWecomSessionCardStore, SqliteWecomSessionCardStore, getDefaultWecomSessionCardDbPath, createWecomSessionCardStore, getSharedWecomSessionCardStore, __resetSharedWecomSessionCardStoreForTest };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  init_decorator,
3
3
  wrapFunction
4
- } from "./roy-agent-core-qq96p0tj.js";
4
+ } from "./roy-agent-core-5s2t8z00.js";
5
5
  import {
6
6
  createLogger,
7
7
  init_logger
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  TracedAs,
3
3
  init_decorator
4
- } from "./roy-agent-core-qq96p0tj.js";
4
+ } from "./roy-agent-core-5s2t8z00.js";
5
5
  import {
6
6
  __esm,
7
7
  __legacyDecorateClassTS