@openclaw/feishu 2026.3.13 → 2026.5.1-beta.1

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 (188) hide show
  1. package/api.ts +31 -0
  2. package/channel-entry.ts +20 -0
  3. package/channel-plugin-api.ts +1 -0
  4. package/contract-api.ts +16 -0
  5. package/index.ts +70 -53
  6. package/openclaw.plugin.json +1653 -4
  7. package/package.json +32 -7
  8. package/runtime-api.ts +55 -0
  9. package/secret-contract-api.ts +5 -0
  10. package/security-contract-api.ts +1 -0
  11. package/session-key-api.ts +1 -0
  12. package/setup-api.ts +3 -0
  13. package/setup-entry.test.ts +14 -0
  14. package/setup-entry.ts +13 -0
  15. package/src/accounts.test.ts +95 -7
  16. package/src/accounts.ts +199 -117
  17. package/src/app-registration.ts +331 -0
  18. package/src/approval-auth.test.ts +24 -0
  19. package/src/approval-auth.ts +25 -0
  20. package/src/async.test.ts +35 -0
  21. package/src/async.ts +43 -1
  22. package/src/audio-preflight.runtime.ts +9 -0
  23. package/src/bitable.test.ts +131 -0
  24. package/src/bitable.ts +59 -22
  25. package/src/bot-content.ts +474 -0
  26. package/src/bot-group-name.test.ts +108 -0
  27. package/src/bot-runtime-api.ts +12 -0
  28. package/src/bot-sender-name.ts +125 -0
  29. package/src/bot.broadcast.test.ts +463 -0
  30. package/src/bot.card-action.test.ts +519 -5
  31. package/src/bot.checkBotMentioned.test.ts +92 -20
  32. package/src/bot.helpers.test.ts +118 -0
  33. package/src/bot.stripBotMention.test.ts +13 -21
  34. package/src/bot.test.ts +1334 -401
  35. package/src/bot.ts +778 -775
  36. package/src/card-action.ts +408 -40
  37. package/src/card-interaction.test.ts +129 -0
  38. package/src/card-interaction.ts +159 -0
  39. package/src/card-test-helpers.ts +47 -0
  40. package/src/card-ux-approval.ts +65 -0
  41. package/src/card-ux-launcher.test.ts +99 -0
  42. package/src/card-ux-launcher.ts +121 -0
  43. package/src/card-ux-shared.ts +33 -0
  44. package/src/channel-runtime-api.ts +16 -0
  45. package/src/channel.runtime.ts +47 -0
  46. package/src/channel.test.ts +914 -3
  47. package/src/channel.ts +1252 -309
  48. package/src/chat-schema.ts +5 -4
  49. package/src/chat.test.ts +84 -28
  50. package/src/chat.ts +68 -10
  51. package/src/client.test.ts +212 -103
  52. package/src/client.ts +115 -21
  53. package/src/comment-dispatcher-runtime-api.ts +6 -0
  54. package/src/comment-dispatcher.test.ts +169 -0
  55. package/src/comment-dispatcher.ts +107 -0
  56. package/src/comment-handler-runtime-api.ts +3 -0
  57. package/src/comment-handler.test.ts +486 -0
  58. package/src/comment-handler.ts +309 -0
  59. package/src/comment-reaction.test.ts +166 -0
  60. package/src/comment-reaction.ts +259 -0
  61. package/src/comment-shared.test.ts +182 -0
  62. package/src/comment-shared.ts +365 -0
  63. package/src/comment-target.ts +44 -0
  64. package/src/config-schema.test.ts +63 -1
  65. package/src/config-schema.ts +31 -4
  66. package/src/conversation-id.test.ts +18 -0
  67. package/src/conversation-id.ts +199 -0
  68. package/src/dedup-runtime-api.ts +1 -0
  69. package/src/dedup.ts +32 -94
  70. package/src/directory.static.ts +61 -0
  71. package/src/directory.test.ts +119 -20
  72. package/src/directory.ts +61 -91
  73. package/src/doc-schema.ts +1 -1
  74. package/src/docx-batch-insert.test.ts +39 -38
  75. package/src/docx-batch-insert.ts +55 -19
  76. package/src/docx-color-text.ts +9 -4
  77. package/src/docx-table-ops.test.ts +53 -0
  78. package/src/docx-table-ops.ts +52 -34
  79. package/src/docx-types.ts +38 -0
  80. package/src/docx.account-selection.test.ts +12 -3
  81. package/src/docx.test.ts +314 -74
  82. package/src/docx.ts +278 -122
  83. package/src/drive-schema.ts +47 -1
  84. package/src/drive.test.ts +1219 -0
  85. package/src/drive.ts +614 -13
  86. package/src/dynamic-agent.ts +10 -4
  87. package/src/event-types.ts +45 -0
  88. package/src/external-keys.ts +1 -1
  89. package/src/lifecycle.test-support.ts +220 -0
  90. package/src/media.test.ts +375 -26
  91. package/src/media.ts +434 -88
  92. package/src/mention-target.types.ts +5 -0
  93. package/src/mention.ts +32 -51
  94. package/src/message-action-contract.ts +13 -0
  95. package/src/monitor-state-runtime-api.ts +7 -0
  96. package/src/monitor-transport-runtime-api.ts +7 -0
  97. package/src/monitor.account.ts +218 -312
  98. package/src/monitor.acp-init-failure.lifecycle.test-support.ts +219 -0
  99. package/src/monitor.bot-identity.ts +86 -0
  100. package/src/monitor.bot-menu-handler.ts +165 -0
  101. package/src/monitor.bot-menu.lifecycle.test-support.ts +224 -0
  102. package/src/monitor.bot-menu.test.ts +178 -0
  103. package/src/monitor.broadcast.reply-once.lifecycle.test-support.ts +264 -0
  104. package/src/monitor.card-action.lifecycle.test-support.ts +373 -0
  105. package/src/monitor.cleanup.test.ts +376 -0
  106. package/src/monitor.comment-notice-handler.ts +105 -0
  107. package/src/monitor.comment.test.ts +937 -0
  108. package/src/monitor.comment.ts +1386 -0
  109. package/src/monitor.lifecycle.test.ts +4 -0
  110. package/src/monitor.message-handler.ts +339 -0
  111. package/src/monitor.reaction.lifecycle.test-support.ts +68 -0
  112. package/src/monitor.reaction.test.ts +108 -48
  113. package/src/monitor.reply-once.lifecycle.test-support.ts +190 -0
  114. package/src/monitor.startup.test.ts +11 -9
  115. package/src/monitor.startup.ts +26 -16
  116. package/src/monitor.state.ts +20 -5
  117. package/src/monitor.synthetic-error.ts +18 -0
  118. package/src/monitor.test-mocks.ts +2 -2
  119. package/src/monitor.transport.ts +220 -60
  120. package/src/monitor.ts +15 -10
  121. package/src/monitor.webhook-e2e.test.ts +65 -7
  122. package/src/monitor.webhook-security.test.ts +122 -0
  123. package/src/monitor.webhook.test-helpers.ts +44 -26
  124. package/src/outbound-runtime-api.ts +1 -0
  125. package/src/outbound.test.ts +616 -37
  126. package/src/outbound.ts +623 -81
  127. package/src/perm-schema.ts +1 -1
  128. package/src/perm.ts +1 -7
  129. package/src/pins.ts +108 -0
  130. package/src/policy.test.ts +297 -117
  131. package/src/policy.ts +142 -29
  132. package/src/post.ts +7 -6
  133. package/src/probe.test.ts +14 -9
  134. package/src/probe.ts +26 -16
  135. package/src/processing-claims.ts +59 -0
  136. package/src/qr-terminal.ts +1 -0
  137. package/src/reactions.ts +4 -34
  138. package/src/reasoning-preview.test.ts +59 -0
  139. package/src/reasoning-preview.ts +20 -0
  140. package/src/reply-dispatcher-runtime-api.ts +7 -0
  141. package/src/reply-dispatcher.test.ts +660 -29
  142. package/src/reply-dispatcher.ts +407 -154
  143. package/src/runtime.ts +6 -3
  144. package/src/secret-contract.ts +145 -0
  145. package/src/secret-input.ts +1 -13
  146. package/src/security-audit-shared.ts +69 -0
  147. package/src/security-audit.test.ts +61 -0
  148. package/src/security-audit.ts +1 -0
  149. package/src/send-result.ts +1 -1
  150. package/src/send-target.test.ts +9 -3
  151. package/src/send-target.ts +10 -4
  152. package/src/send.reply-fallback.test.ts +77 -2
  153. package/src/send.test.ts +386 -4
  154. package/src/send.ts +399 -86
  155. package/src/sequential-key.test.ts +72 -0
  156. package/src/sequential-key.ts +28 -0
  157. package/src/sequential-queue.test.ts +92 -0
  158. package/src/sequential-queue.ts +16 -0
  159. package/src/session-conversation.ts +42 -0
  160. package/src/session-route.ts +48 -0
  161. package/src/setup-core.ts +51 -0
  162. package/src/{onboarding.test.ts → setup-surface.test.ts} +52 -21
  163. package/src/setup-surface.ts +581 -0
  164. package/src/streaming-card.test.ts +138 -2
  165. package/src/streaming-card.ts +134 -18
  166. package/src/subagent-hooks.test.ts +603 -0
  167. package/src/subagent-hooks.ts +397 -0
  168. package/src/targets.ts +3 -13
  169. package/src/test-support/lifecycle-test-support.ts +479 -0
  170. package/src/thread-bindings.test.ts +143 -0
  171. package/src/thread-bindings.ts +330 -0
  172. package/src/tool-account-routing.test.ts +66 -8
  173. package/src/tool-account.test.ts +44 -0
  174. package/src/tool-account.ts +40 -17
  175. package/src/tool-factory-test-harness.ts +11 -8
  176. package/src/tool-result.ts +3 -1
  177. package/src/tools-config.ts +1 -1
  178. package/src/types.ts +16 -15
  179. package/src/typing.ts +10 -6
  180. package/src/wiki-schema.ts +1 -1
  181. package/src/wiki.ts +1 -7
  182. package/subagent-hooks-api.ts +31 -0
  183. package/tsconfig.json +16 -0
  184. package/src/feishu-command-handler.ts +0 -59
  185. package/src/onboarding.status.test.ts +0 -25
  186. package/src/onboarding.ts +0 -489
  187. package/src/send-message.ts +0 -71
  188. package/src/targets.test.ts +0 -70
@@ -0,0 +1,603 @@
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
+ });