@openclaw/feishu 2026.5.2 → 2026.5.3-beta.2

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 (224) hide show
  1. package/dist/accounts-Ba3-WP1z.js +423 -0
  2. package/dist/api.js +2280 -0
  3. package/dist/app-registration-B8qc1MCM.js +184 -0
  4. package/dist/audio-preflight.runtime-BPlzkO3l.js +7 -0
  5. package/dist/card-interaction-BfRLgvw_.js +96 -0
  6. package/dist/channel-CSD_Jt8I.js +1668 -0
  7. package/dist/channel-entry.js +22 -0
  8. package/dist/channel-plugin-api.js +2 -0
  9. package/dist/channel.runtime-DYsXcD36.js +700 -0
  10. package/dist/client-DBVoQL5w.js +157 -0
  11. package/dist/contract-api.js +9 -0
  12. package/dist/conversation-id-DWS3Ep2A.js +139 -0
  13. package/dist/directory.static-f3EeoRJd.js +44 -0
  14. package/dist/drive-C5eJLJr7.js +883 -0
  15. package/dist/index.js +68 -0
  16. package/dist/monitor-CT189QfR.js +60 -0
  17. package/dist/monitor.account-dJV2jO8C.js +4990 -0
  18. package/dist/monitor.state-DYM02ipp.js +100 -0
  19. package/dist/policy-D6c-wMPl.js +118 -0
  20. package/dist/probe-BNzzU_uR.js +149 -0
  21. package/dist/rolldown-runtime-DUslC3ob.js +14 -0
  22. package/dist/runtime-CG0DuRCy.js +8 -0
  23. package/dist/runtime-api.js +14 -0
  24. package/dist/secret-contract-Dm4Z_zQN.js +119 -0
  25. package/dist/secret-contract-api.js +2 -0
  26. package/dist/security-audit-DqJdocrN.js +11 -0
  27. package/dist/security-audit-shared-ByuMx9cJ.js +38 -0
  28. package/dist/security-contract-api.js +2 -0
  29. package/dist/send-DowxxbpH.js +1218 -0
  30. package/dist/session-conversation-B4nrW-vo.js +27 -0
  31. package/dist/session-key-api.js +2 -0
  32. package/dist/setup-api.js +2 -0
  33. package/dist/setup-entry.js +15 -0
  34. package/dist/subagent-hooks-C3UhPVLV.js +227 -0
  35. package/dist/subagent-hooks-api.js +23 -0
  36. package/dist/targets-JMFJRKSe.js +48 -0
  37. package/dist/thread-bindings-BmS6TLes.js +222 -0
  38. package/package.json +15 -6
  39. package/api.ts +0 -31
  40. package/channel-entry.ts +0 -20
  41. package/channel-plugin-api.ts +0 -1
  42. package/contract-api.ts +0 -16
  43. package/index.ts +0 -82
  44. package/runtime-api.ts +0 -55
  45. package/secret-contract-api.ts +0 -5
  46. package/security-contract-api.ts +0 -1
  47. package/session-key-api.ts +0 -1
  48. package/setup-api.ts +0 -3
  49. package/setup-entry.test.ts +0 -14
  50. package/setup-entry.ts +0 -13
  51. package/src/accounts.test.ts +0 -459
  52. package/src/accounts.ts +0 -326
  53. package/src/app-registration.ts +0 -331
  54. package/src/approval-auth.test.ts +0 -24
  55. package/src/approval-auth.ts +0 -25
  56. package/src/async.test.ts +0 -35
  57. package/src/async.ts +0 -104
  58. package/src/audio-preflight.runtime.ts +0 -9
  59. package/src/bitable.test.ts +0 -131
  60. package/src/bitable.ts +0 -762
  61. package/src/bot-content.ts +0 -474
  62. package/src/bot-group-name.test.ts +0 -108
  63. package/src/bot-runtime-api.ts +0 -12
  64. package/src/bot-sender-name.ts +0 -125
  65. package/src/bot.broadcast.test.ts +0 -463
  66. package/src/bot.card-action.test.ts +0 -577
  67. package/src/bot.checkBotMentioned.test.ts +0 -265
  68. package/src/bot.helpers.test.ts +0 -118
  69. package/src/bot.stripBotMention.test.ts +0 -126
  70. package/src/bot.test.ts +0 -3040
  71. package/src/bot.ts +0 -1559
  72. package/src/card-action.ts +0 -447
  73. package/src/card-interaction.test.ts +0 -129
  74. package/src/card-interaction.ts +0 -159
  75. package/src/card-test-helpers.ts +0 -47
  76. package/src/card-ux-approval.ts +0 -65
  77. package/src/card-ux-launcher.test.ts +0 -99
  78. package/src/card-ux-launcher.ts +0 -121
  79. package/src/card-ux-shared.ts +0 -33
  80. package/src/channel-runtime-api.ts +0 -16
  81. package/src/channel.runtime.ts +0 -47
  82. package/src/channel.test.ts +0 -959
  83. package/src/channel.ts +0 -1313
  84. package/src/chat-schema.ts +0 -25
  85. package/src/chat.test.ts +0 -196
  86. package/src/chat.ts +0 -188
  87. package/src/client.test.ts +0 -433
  88. package/src/client.ts +0 -290
  89. package/src/comment-dispatcher-runtime-api.ts +0 -6
  90. package/src/comment-dispatcher.test.ts +0 -169
  91. package/src/comment-dispatcher.ts +0 -107
  92. package/src/comment-handler-runtime-api.ts +0 -3
  93. package/src/comment-handler.test.ts +0 -486
  94. package/src/comment-handler.ts +0 -309
  95. package/src/comment-reaction.test.ts +0 -166
  96. package/src/comment-reaction.ts +0 -259
  97. package/src/comment-shared.test.ts +0 -182
  98. package/src/comment-shared.ts +0 -406
  99. package/src/comment-target.ts +0 -44
  100. package/src/config-schema.test.ts +0 -309
  101. package/src/config-schema.ts +0 -333
  102. package/src/conversation-id.test.ts +0 -18
  103. package/src/conversation-id.ts +0 -199
  104. package/src/dedup-runtime-api.ts +0 -1
  105. package/src/dedup.ts +0 -141
  106. package/src/directory.static.ts +0 -61
  107. package/src/directory.test.ts +0 -136
  108. package/src/directory.ts +0 -124
  109. package/src/doc-schema.ts +0 -182
  110. package/src/docx-batch-insert.test.ts +0 -91
  111. package/src/docx-batch-insert.ts +0 -223
  112. package/src/docx-color-text.ts +0 -154
  113. package/src/docx-table-ops.test.ts +0 -53
  114. package/src/docx-table-ops.ts +0 -316
  115. package/src/docx-types.ts +0 -38
  116. package/src/docx.account-selection.test.ts +0 -79
  117. package/src/docx.test.ts +0 -685
  118. package/src/docx.ts +0 -1616
  119. package/src/drive-schema.ts +0 -92
  120. package/src/drive.test.ts +0 -1219
  121. package/src/drive.ts +0 -829
  122. package/src/dynamic-agent.ts +0 -137
  123. package/src/event-types.ts +0 -45
  124. package/src/external-keys.test.ts +0 -20
  125. package/src/external-keys.ts +0 -19
  126. package/src/lifecycle.test-support.ts +0 -220
  127. package/src/media.test.ts +0 -900
  128. package/src/media.ts +0 -861
  129. package/src/mention-target.types.ts +0 -5
  130. package/src/mention.ts +0 -114
  131. package/src/message-action-contract.ts +0 -13
  132. package/src/monitor-state-runtime-api.ts +0 -7
  133. package/src/monitor-transport-runtime-api.ts +0 -7
  134. package/src/monitor.account.ts +0 -468
  135. package/src/monitor.acp-init-failure.lifecycle.test-support.ts +0 -219
  136. package/src/monitor.bot-identity.ts +0 -86
  137. package/src/monitor.bot-menu-handler.ts +0 -165
  138. package/src/monitor.bot-menu.lifecycle.test-support.ts +0 -224
  139. package/src/monitor.bot-menu.test.ts +0 -178
  140. package/src/monitor.broadcast.reply-once.lifecycle.test-support.ts +0 -264
  141. package/src/monitor.card-action.lifecycle.test-support.ts +0 -373
  142. package/src/monitor.cleanup.test.ts +0 -376
  143. package/src/monitor.comment-notice-handler.ts +0 -105
  144. package/src/monitor.comment.test.ts +0 -937
  145. package/src/monitor.comment.ts +0 -1386
  146. package/src/monitor.lifecycle.test.ts +0 -4
  147. package/src/monitor.message-handler.ts +0 -339
  148. package/src/monitor.reaction.lifecycle.test-support.ts +0 -68
  149. package/src/monitor.reaction.test.ts +0 -713
  150. package/src/monitor.startup.test.ts +0 -192
  151. package/src/monitor.startup.ts +0 -74
  152. package/src/monitor.state.defaults.test.ts +0 -46
  153. package/src/monitor.state.ts +0 -170
  154. package/src/monitor.synthetic-error.ts +0 -18
  155. package/src/monitor.test-mocks.ts +0 -45
  156. package/src/monitor.transport.ts +0 -424
  157. package/src/monitor.ts +0 -100
  158. package/src/monitor.webhook-e2e.test.ts +0 -272
  159. package/src/monitor.webhook-security.test.ts +0 -264
  160. package/src/monitor.webhook.test-helpers.ts +0 -116
  161. package/src/outbound-runtime-api.ts +0 -1
  162. package/src/outbound.test.ts +0 -935
  163. package/src/outbound.ts +0 -718
  164. package/src/perm-schema.ts +0 -52
  165. package/src/perm.ts +0 -170
  166. package/src/pins.ts +0 -108
  167. package/src/policy.test.ts +0 -334
  168. package/src/policy.ts +0 -236
  169. package/src/post.test.ts +0 -105
  170. package/src/post.ts +0 -275
  171. package/src/probe.test.ts +0 -275
  172. package/src/probe.ts +0 -166
  173. package/src/processing-claims.ts +0 -59
  174. package/src/qr-terminal.ts +0 -1
  175. package/src/reactions.ts +0 -123
  176. package/src/reasoning-preview.test.ts +0 -59
  177. package/src/reasoning-preview.ts +0 -20
  178. package/src/reply-dispatcher-runtime-api.ts +0 -7
  179. package/src/reply-dispatcher.test.ts +0 -1144
  180. package/src/reply-dispatcher.ts +0 -650
  181. package/src/runtime.ts +0 -9
  182. package/src/secret-contract.ts +0 -145
  183. package/src/secret-input.ts +0 -1
  184. package/src/security-audit-shared.ts +0 -69
  185. package/src/security-audit.test.ts +0 -61
  186. package/src/security-audit.ts +0 -1
  187. package/src/send-result.ts +0 -29
  188. package/src/send-target.test.ts +0 -80
  189. package/src/send-target.ts +0 -35
  190. package/src/send.reply-fallback.test.ts +0 -292
  191. package/src/send.test.ts +0 -550
  192. package/src/send.ts +0 -800
  193. package/src/sequential-key.test.ts +0 -72
  194. package/src/sequential-key.ts +0 -28
  195. package/src/sequential-queue.test.ts +0 -92
  196. package/src/sequential-queue.ts +0 -16
  197. package/src/session-conversation.ts +0 -42
  198. package/src/session-route.ts +0 -48
  199. package/src/setup-core.ts +0 -51
  200. package/src/setup-surface.test.ts +0 -174
  201. package/src/setup-surface.ts +0 -581
  202. package/src/streaming-card.test.ts +0 -190
  203. package/src/streaming-card.ts +0 -490
  204. package/src/subagent-hooks.test.ts +0 -603
  205. package/src/subagent-hooks.ts +0 -397
  206. package/src/targets.ts +0 -97
  207. package/src/test-support/lifecycle-test-support.ts +0 -453
  208. package/src/thread-bindings.test.ts +0 -143
  209. package/src/thread-bindings.ts +0 -330
  210. package/src/tool-account-routing.test.ts +0 -187
  211. package/src/tool-account.test.ts +0 -44
  212. package/src/tool-account.ts +0 -93
  213. package/src/tool-factory-test-harness.ts +0 -79
  214. package/src/tool-result.test.ts +0 -32
  215. package/src/tool-result.ts +0 -16
  216. package/src/tools-config.test.ts +0 -21
  217. package/src/tools-config.ts +0 -22
  218. package/src/types.ts +0 -104
  219. package/src/typing.test.ts +0 -144
  220. package/src/typing.ts +0 -214
  221. package/src/wiki-schema.ts +0 -55
  222. package/src/wiki.ts +0 -227
  223. package/subagent-hooks-api.ts +0 -31
  224. package/tsconfig.json +0 -16
@@ -1,603 +0,0 @@
1
- import {
2
- getRequiredHookHandler,
3
- registerHookHandlersForTest,
4
- } from "openclaw/plugin-sdk/channel-test-helpers";
5
- import { beforeEach, describe, expect, it } from "vitest";
6
- import type { ClawdbotConfig, OpenClawPluginApi } from "../runtime-api.js";
7
- import { registerFeishuSubagentHooks } from "../subagent-hooks-api.js";
8
- import {
9
- createFeishuThreadBindingManager,
10
- __testing as threadBindingTesting,
11
- } from "./thread-bindings.js";
12
-
13
- const baseConfig: ClawdbotConfig = {
14
- session: { mainKey: "main", scope: "per-sender" },
15
- channels: { feishu: {} },
16
- };
17
-
18
- function registerHandlersForTest(config: Record<string, unknown> = baseConfig) {
19
- return registerHookHandlersForTest<OpenClawPluginApi>({
20
- config,
21
- register: registerFeishuSubagentHooks,
22
- });
23
- }
24
-
25
- describe("feishu subagent hook handlers", () => {
26
- beforeEach(() => {
27
- threadBindingTesting.resetFeishuThreadBindingsForTests();
28
- });
29
-
30
- it("binds a Feishu DM conversation on subagent_spawning", async () => {
31
- const handlers = registerHandlersForTest();
32
- const handler = getRequiredHookHandler(handlers, "subagent_spawning");
33
- createFeishuThreadBindingManager({ cfg: baseConfig, accountId: "work" });
34
-
35
- const result = await handler(
36
- {
37
- childSessionKey: "agent:main:subagent:child",
38
- agentId: "codex",
39
- label: "banana",
40
- mode: "session",
41
- requester: {
42
- channel: "feishu",
43
- accountId: "work",
44
- to: "user:ou_sender_1",
45
- },
46
- threadRequested: true,
47
- },
48
- {},
49
- );
50
-
51
- expect(result).toEqual({ status: "ok", threadBindingReady: true });
52
-
53
- const deliveryTargetHandler = getRequiredHookHandler(handlers, "subagent_delivery_target");
54
- await expect(
55
- deliveryTargetHandler(
56
- {
57
- childSessionKey: "agent:main:subagent:child",
58
- requesterSessionKey: "agent:main:main",
59
- requesterOrigin: {
60
- channel: "feishu",
61
- accountId: "work",
62
- to: "user:ou_sender_1",
63
- },
64
- expectsCompletionMessage: true,
65
- },
66
- {},
67
- ),
68
- ).resolves.toEqual({
69
- origin: {
70
- channel: "feishu",
71
- accountId: "work",
72
- to: "user:ou_sender_1",
73
- },
74
- });
75
- });
76
-
77
- it("preserves the original Feishu DM delivery target", async () => {
78
- const handlers = registerHandlersForTest();
79
- const deliveryHandler = getRequiredHookHandler(handlers, "subagent_delivery_target");
80
- const manager = createFeishuThreadBindingManager({ cfg: baseConfig, accountId: "work" });
81
-
82
- manager.bindConversation({
83
- conversationId: "ou_sender_1",
84
- targetKind: "subagent",
85
- targetSessionKey: "agent:main:subagent:chat-dm-child",
86
- metadata: {
87
- deliveryTo: "chat:oc_dm_chat_1",
88
- boundBy: "system",
89
- },
90
- });
91
-
92
- await expect(
93
- deliveryHandler(
94
- {
95
- childSessionKey: "agent:main:subagent:chat-dm-child",
96
- requesterSessionKey: "agent:main:main",
97
- requesterOrigin: {
98
- channel: "feishu",
99
- accountId: "work",
100
- to: "chat:oc_dm_chat_1",
101
- },
102
- expectsCompletionMessage: true,
103
- },
104
- {},
105
- ),
106
- ).resolves.toEqual({
107
- origin: {
108
- channel: "feishu",
109
- accountId: "work",
110
- to: "chat:oc_dm_chat_1",
111
- },
112
- });
113
- });
114
-
115
- it("binds a Feishu topic conversation and preserves parent context", async () => {
116
- const handlers = registerHandlersForTest();
117
- const spawnHandler = getRequiredHookHandler(handlers, "subagent_spawning");
118
- const deliveryHandler = getRequiredHookHandler(handlers, "subagent_delivery_target");
119
- createFeishuThreadBindingManager({ cfg: baseConfig, accountId: "work" });
120
-
121
- const result = await spawnHandler(
122
- {
123
- childSessionKey: "agent:main:subagent:topic-child",
124
- agentId: "codex",
125
- label: "topic-child",
126
- mode: "session",
127
- requester: {
128
- channel: "feishu",
129
- accountId: "work",
130
- to: "chat:oc_group_chat",
131
- threadId: "om_topic_root",
132
- },
133
- threadRequested: true,
134
- },
135
- {},
136
- );
137
-
138
- expect(result).toEqual({ status: "ok", threadBindingReady: true });
139
- await expect(
140
- deliveryHandler(
141
- {
142
- childSessionKey: "agent:main:subagent:topic-child",
143
- requesterSessionKey: "agent:main:main",
144
- requesterOrigin: {
145
- channel: "feishu",
146
- accountId: "work",
147
- to: "chat:oc_group_chat",
148
- threadId: "om_topic_root",
149
- },
150
- expectsCompletionMessage: true,
151
- },
152
- {},
153
- ),
154
- ).resolves.toEqual({
155
- origin: {
156
- channel: "feishu",
157
- accountId: "work",
158
- to: "chat:oc_group_chat",
159
- threadId: "om_topic_root",
160
- },
161
- });
162
- });
163
-
164
- it("uses the requester session binding to preserve sender-scoped topic conversations", async () => {
165
- const handlers = registerHandlersForTest();
166
- const spawnHandler = getRequiredHookHandler(handlers, "subagent_spawning");
167
- const deliveryHandler = getRequiredHookHandler(handlers, "subagent_delivery_target");
168
- const manager = createFeishuThreadBindingManager({ cfg: baseConfig, accountId: "work" });
169
-
170
- manager.bindConversation({
171
- conversationId: "oc_group_chat:topic:om_topic_root:sender:ou_sender_1",
172
- parentConversationId: "oc_group_chat",
173
- targetKind: "subagent",
174
- targetSessionKey: "agent:main:parent",
175
- metadata: {
176
- agentId: "codex",
177
- label: "parent",
178
- boundBy: "system",
179
- },
180
- });
181
-
182
- const reboundResult = await spawnHandler(
183
- {
184
- childSessionKey: "agent:main:subagent:sender-child",
185
- agentId: "codex",
186
- label: "sender-child",
187
- mode: "session",
188
- requester: {
189
- channel: "feishu",
190
- accountId: "work",
191
- to: "chat:oc_group_chat",
192
- threadId: "om_topic_root",
193
- },
194
- threadRequested: true,
195
- },
196
- {
197
- requesterSessionKey: "agent:main:parent",
198
- },
199
- );
200
-
201
- expect(reboundResult).toEqual({ status: "ok", threadBindingReady: true });
202
- expect(manager.listBySessionKey("agent:main:subagent:sender-child")).toMatchObject([
203
- {
204
- conversationId: "oc_group_chat:topic:om_topic_root:sender:ou_sender_1",
205
- parentConversationId: "oc_group_chat",
206
- },
207
- ]);
208
- await expect(
209
- deliveryHandler(
210
- {
211
- childSessionKey: "agent:main:subagent:sender-child",
212
- requesterSessionKey: "agent:main:parent",
213
- requesterOrigin: {
214
- channel: "feishu",
215
- accountId: "work",
216
- to: "chat:oc_group_chat",
217
- threadId: "om_topic_root",
218
- },
219
- expectsCompletionMessage: true,
220
- },
221
- {},
222
- ),
223
- ).resolves.toEqual({
224
- origin: {
225
- channel: "feishu",
226
- accountId: "work",
227
- to: "chat:oc_group_chat",
228
- threadId: "om_topic_root",
229
- },
230
- });
231
- });
232
-
233
- it("prefers requester-matching bindings when multiple child bindings exist", async () => {
234
- const handlers = registerHandlersForTest();
235
- const spawnHandler = getRequiredHookHandler(handlers, "subagent_spawning");
236
- const deliveryHandler = getRequiredHookHandler(handlers, "subagent_delivery_target");
237
- createFeishuThreadBindingManager({ cfg: baseConfig, accountId: "work" });
238
-
239
- await spawnHandler(
240
- {
241
- childSessionKey: "agent:main:subagent:shared",
242
- agentId: "codex",
243
- label: "shared",
244
- mode: "session",
245
- requester: {
246
- channel: "feishu",
247
- accountId: "work",
248
- to: "user:ou_sender_1",
249
- },
250
- threadRequested: true,
251
- },
252
- {},
253
- );
254
- await spawnHandler(
255
- {
256
- childSessionKey: "agent:main:subagent:shared",
257
- agentId: "codex",
258
- label: "shared",
259
- mode: "session",
260
- requester: {
261
- channel: "feishu",
262
- accountId: "work",
263
- to: "user:ou_sender_2",
264
- },
265
- threadRequested: true,
266
- },
267
- {},
268
- );
269
-
270
- await expect(
271
- deliveryHandler(
272
- {
273
- childSessionKey: "agent:main:subagent:shared",
274
- requesterSessionKey: "agent:main:main",
275
- requesterOrigin: {
276
- channel: "feishu",
277
- accountId: "work",
278
- to: "user:ou_sender_2",
279
- },
280
- expectsCompletionMessage: true,
281
- },
282
- {},
283
- ),
284
- ).resolves.toEqual({
285
- origin: {
286
- channel: "feishu",
287
- accountId: "work",
288
- to: "user:ou_sender_2",
289
- },
290
- });
291
- });
292
-
293
- it("fails closed when requester-session bindings remain ambiguous for the same topic", async () => {
294
- const handlers = registerHandlersForTest();
295
- const spawnHandler = getRequiredHookHandler(handlers, "subagent_spawning");
296
- const deliveryHandler = getRequiredHookHandler(handlers, "subagent_delivery_target");
297
- const manager = createFeishuThreadBindingManager({ cfg: baseConfig, accountId: "work" });
298
-
299
- manager.bindConversation({
300
- conversationId: "oc_group_chat:topic:om_topic_root:sender:ou_sender_1",
301
- parentConversationId: "oc_group_chat",
302
- targetKind: "subagent",
303
- targetSessionKey: "agent:main:parent",
304
- metadata: { boundBy: "system" },
305
- });
306
- manager.bindConversation({
307
- conversationId: "oc_group_chat:topic:om_topic_root:sender:ou_sender_2",
308
- parentConversationId: "oc_group_chat",
309
- targetKind: "subagent",
310
- targetSessionKey: "agent:main:parent",
311
- metadata: { boundBy: "system" },
312
- });
313
-
314
- await expect(
315
- spawnHandler(
316
- {
317
- childSessionKey: "agent:main:subagent:ambiguous-child",
318
- agentId: "codex",
319
- label: "ambiguous-child",
320
- mode: "session",
321
- requester: {
322
- channel: "feishu",
323
- accountId: "work",
324
- to: "chat:oc_group_chat",
325
- threadId: "om_topic_root",
326
- },
327
- threadRequested: true,
328
- },
329
- {
330
- requesterSessionKey: "agent:main:parent",
331
- },
332
- ),
333
- ).resolves.toMatchObject({
334
- status: "error",
335
- error: expect.stringContaining("direct messages or topic conversations"),
336
- });
337
-
338
- await expect(
339
- deliveryHandler(
340
- {
341
- childSessionKey: "agent:main:subagent:ambiguous-child",
342
- requesterSessionKey: "agent:main:parent",
343
- requesterOrigin: {
344
- channel: "feishu",
345
- accountId: "work",
346
- to: "chat:oc_group_chat",
347
- threadId: "om_topic_root",
348
- },
349
- expectsCompletionMessage: true,
350
- },
351
- {},
352
- ),
353
- ).resolves.toBeUndefined();
354
- });
355
-
356
- it("fails closed when both topic-level and sender-scoped requester bindings exist", async () => {
357
- const handlers = registerHandlersForTest();
358
- const spawnHandler = getRequiredHookHandler(handlers, "subagent_spawning");
359
- const deliveryHandler = getRequiredHookHandler(handlers, "subagent_delivery_target");
360
- const manager = createFeishuThreadBindingManager({ cfg: baseConfig, accountId: "work" });
361
-
362
- manager.bindConversation({
363
- conversationId: "oc_group_chat:topic:om_topic_root",
364
- parentConversationId: "oc_group_chat",
365
- targetKind: "subagent",
366
- targetSessionKey: "agent:main:parent",
367
- metadata: { boundBy: "system" },
368
- });
369
- manager.bindConversation({
370
- conversationId: "oc_group_chat:topic:om_topic_root:sender:ou_sender_1",
371
- parentConversationId: "oc_group_chat",
372
- targetKind: "subagent",
373
- targetSessionKey: "agent:main:parent",
374
- metadata: { boundBy: "system" },
375
- });
376
-
377
- await expect(
378
- spawnHandler(
379
- {
380
- childSessionKey: "agent:main:subagent:mixed-topic-child",
381
- agentId: "codex",
382
- label: "mixed-topic-child",
383
- mode: "session",
384
- requester: {
385
- channel: "feishu",
386
- accountId: "work",
387
- to: "chat:oc_group_chat",
388
- threadId: "om_topic_root",
389
- },
390
- threadRequested: true,
391
- },
392
- {
393
- requesterSessionKey: "agent:main:parent",
394
- },
395
- ),
396
- ).resolves.toMatchObject({
397
- status: "error",
398
- error: expect.stringContaining("direct messages or topic conversations"),
399
- });
400
-
401
- await expect(
402
- deliveryHandler(
403
- {
404
- childSessionKey: "agent:main:subagent:mixed-topic-child",
405
- requesterSessionKey: "agent:main:parent",
406
- requesterOrigin: {
407
- channel: "feishu",
408
- accountId: "work",
409
- to: "chat:oc_group_chat",
410
- threadId: "om_topic_root",
411
- },
412
- expectsCompletionMessage: true,
413
- },
414
- {},
415
- ),
416
- ).resolves.toBeUndefined();
417
- });
418
-
419
- it("no-ops for non-Feishu channels and non-threaded spawns", async () => {
420
- const handlers = registerHandlersForTest();
421
- const spawnHandler = getRequiredHookHandler(handlers, "subagent_spawning");
422
- const deliveryHandler = getRequiredHookHandler(handlers, "subagent_delivery_target");
423
- const endedHandler = getRequiredHookHandler(handlers, "subagent_ended");
424
-
425
- await expect(
426
- spawnHandler(
427
- {
428
- childSessionKey: "agent:main:subagent:child",
429
- agentId: "codex",
430
- mode: "run",
431
- requester: {
432
- channel: "discord",
433
- accountId: "work",
434
- to: "channel:123",
435
- },
436
- threadRequested: true,
437
- },
438
- {},
439
- ),
440
- ).resolves.toBeUndefined();
441
-
442
- await expect(
443
- spawnHandler(
444
- {
445
- childSessionKey: "agent:main:subagent:child",
446
- agentId: "codex",
447
- mode: "run",
448
- requester: {
449
- channel: "feishu",
450
- accountId: "work",
451
- to: "user:ou_sender_1",
452
- },
453
- threadRequested: false,
454
- },
455
- {},
456
- ),
457
- ).resolves.toBeUndefined();
458
-
459
- await expect(
460
- deliveryHandler(
461
- {
462
- childSessionKey: "agent:main:subagent:child",
463
- requesterSessionKey: "agent:main:main",
464
- requesterOrigin: {
465
- channel: "discord",
466
- accountId: "work",
467
- to: "channel:123",
468
- },
469
- expectsCompletionMessage: true,
470
- },
471
- {},
472
- ),
473
- ).resolves.toBeUndefined();
474
-
475
- await expect(
476
- endedHandler(
477
- {
478
- targetSessionKey: "agent:main:subagent:child",
479
- targetKind: "subagent",
480
- reason: "done",
481
- accountId: "work",
482
- },
483
- {},
484
- ),
485
- ).resolves.toBeUndefined();
486
- });
487
-
488
- it("returns an error for unsupported non-topic Feishu group conversations", async () => {
489
- const handler = getRequiredHookHandler(registerHandlersForTest(), "subagent_spawning");
490
- createFeishuThreadBindingManager({ cfg: baseConfig, accountId: "work" });
491
-
492
- await expect(
493
- handler(
494
- {
495
- childSessionKey: "agent:main:subagent:child",
496
- agentId: "codex",
497
- mode: "session",
498
- requester: {
499
- channel: "feishu",
500
- accountId: "work",
501
- to: "chat:oc_group_chat",
502
- },
503
- threadRequested: true,
504
- },
505
- {},
506
- ),
507
- ).resolves.toMatchObject({
508
- status: "error",
509
- error: expect.stringContaining("direct messages or topic conversations"),
510
- });
511
- });
512
-
513
- it("unbinds Feishu bindings on subagent_ended", async () => {
514
- const handlers = registerHandlersForTest();
515
- const spawnHandler = getRequiredHookHandler(handlers, "subagent_spawning");
516
- const deliveryHandler = getRequiredHookHandler(handlers, "subagent_delivery_target");
517
- const endedHandler = getRequiredHookHandler(handlers, "subagent_ended");
518
- createFeishuThreadBindingManager({ cfg: baseConfig, accountId: "work" });
519
-
520
- await spawnHandler(
521
- {
522
- childSessionKey: "agent:main:subagent:child",
523
- agentId: "codex",
524
- mode: "session",
525
- requester: {
526
- channel: "feishu",
527
- accountId: "work",
528
- to: "user:ou_sender_1",
529
- },
530
- threadRequested: true,
531
- },
532
- {},
533
- );
534
-
535
- await endedHandler(
536
- {
537
- targetSessionKey: "agent:main:subagent:child",
538
- targetKind: "subagent",
539
- reason: "done",
540
- accountId: "work",
541
- },
542
- {},
543
- );
544
-
545
- await expect(
546
- deliveryHandler(
547
- {
548
- childSessionKey: "agent:main:subagent:child",
549
- requesterSessionKey: "agent:main:main",
550
- requesterOrigin: {
551
- channel: "feishu",
552
- accountId: "work",
553
- to: "user:ou_sender_1",
554
- },
555
- expectsCompletionMessage: true,
556
- },
557
- {},
558
- ),
559
- ).resolves.toBeUndefined();
560
- });
561
-
562
- it("fails closed when the Feishu monitor-owned binding manager is unavailable", async () => {
563
- const handlers = registerHandlersForTest();
564
- const spawnHandler = getRequiredHookHandler(handlers, "subagent_spawning");
565
- const deliveryHandler = getRequiredHookHandler(handlers, "subagent_delivery_target");
566
-
567
- await expect(
568
- spawnHandler(
569
- {
570
- childSessionKey: "agent:main:subagent:no-manager",
571
- agentId: "codex",
572
- mode: "session",
573
- requester: {
574
- channel: "feishu",
575
- accountId: "work",
576
- to: "user:ou_sender_1",
577
- },
578
- threadRequested: true,
579
- },
580
- {},
581
- ),
582
- ).resolves.toMatchObject({
583
- status: "error",
584
- error: expect.stringContaining("monitor is not active"),
585
- });
586
-
587
- await expect(
588
- deliveryHandler(
589
- {
590
- childSessionKey: "agent:main:subagent:no-manager",
591
- requesterSessionKey: "agent:main:main",
592
- requesterOrigin: {
593
- channel: "feishu",
594
- accountId: "work",
595
- to: "user:ou_sender_1",
596
- },
597
- expectsCompletionMessage: true,
598
- },
599
- {},
600
- ),
601
- ).resolves.toBeUndefined();
602
- });
603
- });