@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,959 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
- import type { OpenClawConfig } from "../runtime-api.js";
3
- import { feishuPlugin } from "./channel.js";
4
- import { looksLikeFeishuId, normalizeFeishuTarget, resolveReceiveIdType } from "./targets.js";
5
-
6
- const probeFeishuMock = vi.hoisted(() => vi.fn());
7
- const createFeishuClientMock = vi.hoisted(() => vi.fn());
8
- const addReactionFeishuMock = vi.hoisted(() => vi.fn());
9
- const listReactionsFeishuMock = vi.hoisted(() => vi.fn());
10
- const removeReactionFeishuMock = vi.hoisted(() => vi.fn());
11
- const sendCardFeishuMock = vi.hoisted(() => vi.fn());
12
- const sendMessageFeishuMock = vi.hoisted(() => vi.fn());
13
- const getMessageFeishuMock = vi.hoisted(() => vi.fn());
14
- const editMessageFeishuMock = vi.hoisted(() => vi.fn());
15
- const createPinFeishuMock = vi.hoisted(() => vi.fn());
16
- const listPinsFeishuMock = vi.hoisted(() => vi.fn());
17
- const removePinFeishuMock = vi.hoisted(() => vi.fn());
18
- const getChatInfoMock = vi.hoisted(() => vi.fn());
19
- const getChatMembersMock = vi.hoisted(() => vi.fn());
20
- const getFeishuMemberInfoMock = vi.hoisted(() => vi.fn());
21
- const listFeishuDirectoryPeersLiveMock = vi.hoisted(() => vi.fn());
22
- const listFeishuDirectoryGroupsLiveMock = vi.hoisted(() => vi.fn());
23
- const feishuOutboundSendMediaMock = vi.hoisted(() => vi.fn());
24
-
25
- vi.mock("./probe.js", () => ({
26
- probeFeishu: probeFeishuMock,
27
- }));
28
-
29
- vi.mock("./client.js", () => ({
30
- createFeishuClient: createFeishuClientMock,
31
- }));
32
-
33
- vi.mock("./channel.runtime.js", () => ({
34
- feishuChannelRuntime: {
35
- addReactionFeishu: addReactionFeishuMock,
36
- createPinFeishu: createPinFeishuMock,
37
- editMessageFeishu: editMessageFeishuMock,
38
- getChatInfo: getChatInfoMock,
39
- getChatMembers: getChatMembersMock,
40
- getFeishuMemberInfo: getFeishuMemberInfoMock,
41
- getMessageFeishu: getMessageFeishuMock,
42
- listFeishuDirectoryGroupsLive: listFeishuDirectoryGroupsLiveMock,
43
- listFeishuDirectoryPeersLive: listFeishuDirectoryPeersLiveMock,
44
- listPinsFeishu: listPinsFeishuMock,
45
- listReactionsFeishu: listReactionsFeishuMock,
46
- probeFeishu: probeFeishuMock,
47
- removePinFeishu: removePinFeishuMock,
48
- removeReactionFeishu: removeReactionFeishuMock,
49
- sendCardFeishu: sendCardFeishuMock,
50
- sendMessageFeishu: sendMessageFeishuMock,
51
- feishuOutbound: {
52
- sendText: vi.fn(),
53
- sendMedia: feishuOutboundSendMediaMock,
54
- },
55
- },
56
- }));
57
-
58
- function getDescribedActions(cfg: OpenClawConfig, accountId?: string): string[] {
59
- return [...(feishuPlugin.actions?.describeMessageTool?.({ cfg, accountId })?.actions ?? [])];
60
- }
61
-
62
- describe("feishuPlugin.status.probeAccount", () => {
63
- it("uses current account credentials for multi-account config", async () => {
64
- const cfg = {
65
- channels: {
66
- feishu: {
67
- enabled: true,
68
- accounts: {
69
- main: {
70
- appId: "cli_main",
71
- appSecret: "secret_main",
72
- enabled: true,
73
- },
74
- },
75
- },
76
- },
77
- } as OpenClawConfig;
78
-
79
- const account = feishuPlugin.config.resolveAccount(cfg, "main");
80
- probeFeishuMock.mockResolvedValueOnce({ ok: true, appId: "cli_main" });
81
-
82
- const result = await feishuPlugin.status?.probeAccount?.({
83
- account,
84
- timeoutMs: 1_000,
85
- cfg,
86
- });
87
-
88
- expect(probeFeishuMock).toHaveBeenCalledTimes(1);
89
- expect(probeFeishuMock).toHaveBeenCalledWith(
90
- expect.objectContaining({
91
- accountId: "main",
92
- appId: "cli_main",
93
- appSecret: "secret_main",
94
- }),
95
- );
96
- expect(result).toMatchObject({ ok: true, appId: "cli_main" });
97
- });
98
- });
99
-
100
- describe("feishuPlugin.pairing.notifyApproval", () => {
101
- beforeEach(() => {
102
- sendMessageFeishuMock.mockReset();
103
- sendMessageFeishuMock.mockResolvedValue({ messageId: "pairing-msg", chatId: "ou_user" });
104
- });
105
-
106
- it("preserves accountId when sending pairing approvals", async () => {
107
- const cfg = {
108
- channels: {
109
- feishu: {
110
- accounts: {
111
- work: {
112
- appId: "cli_work",
113
- appSecret: "secret_work",
114
- enabled: true,
115
- },
116
- },
117
- },
118
- },
119
- } as OpenClawConfig;
120
-
121
- await feishuPlugin.pairing?.notifyApproval?.({
122
- cfg,
123
- id: "ou_user",
124
- accountId: "work",
125
- });
126
-
127
- expect(sendMessageFeishuMock).toHaveBeenCalledWith(
128
- expect.objectContaining({
129
- cfg,
130
- to: "ou_user",
131
- accountId: "work",
132
- }),
133
- );
134
- });
135
- });
136
-
137
- describe("feishuPlugin messaging", () => {
138
- it("owns sender/topic session inheritance candidates", () => {
139
- expect(
140
- feishuPlugin.messaging?.resolveSessionConversation?.({
141
- kind: "group",
142
- rawId: "oc_group_chat:topic:om_topic_root:sender:ou_topic_user",
143
- }),
144
- ).toEqual({
145
- id: "oc_group_chat:topic:om_topic_root:sender:ou_topic_user",
146
- baseConversationId: "oc_group_chat",
147
- parentConversationCandidates: ["oc_group_chat:topic:om_topic_root", "oc_group_chat"],
148
- });
149
- expect(
150
- feishuPlugin.messaging?.resolveSessionConversation?.({
151
- kind: "group",
152
- rawId: "oc_group_chat:topic:om_topic_root",
153
- }),
154
- ).toEqual({
155
- id: "oc_group_chat:topic:om_topic_root",
156
- baseConversationId: "oc_group_chat",
157
- parentConversationCandidates: ["oc_group_chat"],
158
- });
159
- expect(
160
- feishuPlugin.messaging?.resolveSessionConversation?.({
161
- kind: "group",
162
- rawId: "oc_group_chat:Topic:om_topic_root:Sender:ou_topic_user",
163
- }),
164
- ).toEqual({
165
- id: "oc_group_chat:topic:om_topic_root:sender:ou_topic_user",
166
- baseConversationId: "oc_group_chat",
167
- parentConversationCandidates: ["oc_group_chat:topic:om_topic_root", "oc_group_chat"],
168
- });
169
- });
170
- });
171
-
172
- describe("feishuPlugin actions", () => {
173
- const cfg = {
174
- channels: {
175
- feishu: {
176
- enabled: true,
177
- appId: "cli_main",
178
- appSecret: "secret_main",
179
- actions: {
180
- reactions: true,
181
- },
182
- },
183
- },
184
- } as OpenClawConfig;
185
-
186
- beforeEach(() => {
187
- vi.clearAllMocks();
188
- createFeishuClientMock.mockReturnValue({ tag: "client" });
189
- });
190
-
191
- it("advertises the expanded Feishu action surface", () => {
192
- expect(getDescribedActions(cfg)).toEqual([
193
- "send",
194
- "read",
195
- "edit",
196
- "thread-reply",
197
- "pin",
198
- "list-pins",
199
- "unpin",
200
- "member-info",
201
- "channel-info",
202
- "channel-list",
203
- "react",
204
- "reactions",
205
- ]);
206
- });
207
-
208
- it("does not advertise reactions when disabled via actions config", () => {
209
- const disabledCfg = {
210
- channels: {
211
- feishu: {
212
- enabled: true,
213
- appId: "cli_main",
214
- appSecret: "secret_main",
215
- actions: {
216
- reactions: false,
217
- },
218
- },
219
- },
220
- } as OpenClawConfig;
221
-
222
- expect(getDescribedActions(disabledCfg)).toEqual([
223
- "send",
224
- "read",
225
- "edit",
226
- "thread-reply",
227
- "pin",
228
- "list-pins",
229
- "unpin",
230
- "member-info",
231
- "channel-info",
232
- "channel-list",
233
- ]);
234
- });
235
-
236
- it("honors the selected Feishu account during discovery", () => {
237
- const cfg = {
238
- channels: {
239
- feishu: {
240
- enabled: true,
241
- actions: { reactions: false },
242
- accounts: {
243
- default: {
244
- enabled: true,
245
- appId: "cli_main",
246
- appSecret: "secret_main",
247
- actions: { reactions: false },
248
- },
249
- work: {
250
- enabled: true,
251
- appId: "cli_work",
252
- appSecret: "secret_work",
253
- actions: { reactions: true },
254
- },
255
- },
256
- },
257
- },
258
- } as OpenClawConfig;
259
-
260
- expect(getDescribedActions(cfg, "default")).toEqual([
261
- "send",
262
- "read",
263
- "edit",
264
- "thread-reply",
265
- "pin",
266
- "list-pins",
267
- "unpin",
268
- "member-info",
269
- "channel-info",
270
- "channel-list",
271
- ]);
272
- expect(getDescribedActions(cfg, "work")).toEqual([
273
- "send",
274
- "read",
275
- "edit",
276
- "thread-reply",
277
- "pin",
278
- "list-pins",
279
- "unpin",
280
- "member-info",
281
- "channel-info",
282
- "channel-list",
283
- "react",
284
- "reactions",
285
- ]);
286
- });
287
-
288
- it("sends text messages", async () => {
289
- sendMessageFeishuMock.mockResolvedValueOnce({ messageId: "om_sent", chatId: "oc_group_1" });
290
-
291
- const result = await feishuPlugin.actions?.handleAction?.({
292
- action: "send",
293
- params: { to: "chat:oc_group_1", message: "hello" },
294
- cfg,
295
- accountId: undefined,
296
- toolContext: {},
297
- } as never);
298
-
299
- expect(sendMessageFeishuMock).toHaveBeenCalledWith({
300
- cfg,
301
- to: "chat:oc_group_1",
302
- text: "hello",
303
- accountId: undefined,
304
- replyToMessageId: undefined,
305
- replyInThread: false,
306
- });
307
- expect(result?.details).toMatchObject({ ok: true, messageId: "om_sent", chatId: "oc_group_1" });
308
- });
309
-
310
- it("renders presentation messages as cards", async () => {
311
- sendCardFeishuMock.mockResolvedValueOnce({ messageId: "om_card", chatId: "oc_group_1" });
312
-
313
- const result = await feishuPlugin.actions?.handleAction?.({
314
- action: "send",
315
- params: {
316
- to: "chat:oc_group_1",
317
- presentation: {
318
- title: "Status",
319
- blocks: [{ type: "text", text: "Build completed" }],
320
- },
321
- },
322
- cfg,
323
- accountId: undefined,
324
- toolContext: {},
325
- } as never);
326
-
327
- expect(sendCardFeishuMock).toHaveBeenCalledWith({
328
- cfg,
329
- to: "chat:oc_group_1",
330
- card: expect.objectContaining({
331
- schema: "2.0",
332
- header: {
333
- title: { tag: "plain_text", content: "Status" },
334
- template: "blue",
335
- },
336
- body: {
337
- elements: [
338
- {
339
- tag: "markdown",
340
- content: "Build completed",
341
- },
342
- ],
343
- },
344
- }),
345
- accountId: undefined,
346
- replyToMessageId: undefined,
347
- replyInThread: false,
348
- });
349
- expect(result?.details).toMatchObject({ ok: true, messageId: "om_card", chatId: "oc_group_1" });
350
- });
351
-
352
- it("renders presentation button labels into the card fallback", async () => {
353
- sendCardFeishuMock.mockResolvedValueOnce({ messageId: "om_card", chatId: "oc_group_1" });
354
-
355
- await feishuPlugin.actions?.handleAction?.({
356
- action: "send",
357
- params: {
358
- to: "chat:oc_group_1",
359
- presentation: {
360
- blocks: [
361
- {
362
- type: "buttons",
363
- buttons: [{ label: "Run help", value: "feishu.quick_actions.help" }],
364
- },
365
- ],
366
- },
367
- },
368
- cfg,
369
- accountId: undefined,
370
- toolContext: {},
371
- } as never);
372
-
373
- expect(sendCardFeishuMock).toHaveBeenCalledWith(
374
- expect.objectContaining({
375
- card: expect.objectContaining({
376
- body: {
377
- elements: [
378
- {
379
- tag: "markdown",
380
- content: "- Run help",
381
- },
382
- ],
383
- },
384
- }),
385
- }),
386
- );
387
- });
388
-
389
- it("renders presentation select labels into the card fallback", async () => {
390
- sendCardFeishuMock.mockResolvedValueOnce({ messageId: "om_card", chatId: "oc_group_1" });
391
-
392
- await feishuPlugin.actions?.handleAction?.({
393
- action: "send",
394
- params: {
395
- to: "chat:oc_group_1",
396
- presentation: {
397
- blocks: [
398
- {
399
- type: "select",
400
- placeholder: "Pick one",
401
- options: [{ label: "Option A", value: "a" }],
402
- },
403
- ],
404
- },
405
- },
406
- cfg,
407
- accountId: undefined,
408
- toolContext: {},
409
- } as never);
410
-
411
- expect(sendCardFeishuMock).toHaveBeenCalledWith(
412
- expect.objectContaining({
413
- card: expect.objectContaining({
414
- body: {
415
- elements: [
416
- {
417
- tag: "markdown",
418
- content: "Pick one:\n- Option A",
419
- },
420
- ],
421
- },
422
- }),
423
- }),
424
- );
425
- });
426
-
427
- it("sends media through the outbound adapter", async () => {
428
- feishuOutboundSendMediaMock.mockResolvedValueOnce({
429
- channel: "feishu",
430
- messageId: "om_media",
431
- details: { messageId: "om_media", chatId: "oc_group_1" },
432
- });
433
-
434
- const result = await feishuPlugin.actions?.handleAction?.({
435
- action: "send",
436
- params: {
437
- to: "chat:oc_group_1",
438
- message: "test",
439
- media: "/tmp/image.png",
440
- },
441
- cfg,
442
- accountId: undefined,
443
- toolContext: {},
444
- mediaLocalRoots: ["/tmp"],
445
- } as never);
446
-
447
- expect(feishuOutboundSendMediaMock).toHaveBeenCalledWith({
448
- cfg,
449
- to: "chat:oc_group_1",
450
- text: "test",
451
- mediaUrl: "/tmp/image.png",
452
- accountId: undefined,
453
- mediaLocalRoots: ["/tmp"],
454
- replyToId: undefined,
455
- });
456
- expect(result?.details).toMatchObject({ messageId: "om_media" });
457
- });
458
-
459
- it("passes asVoice through media sends", async () => {
460
- feishuOutboundSendMediaMock.mockResolvedValueOnce({
461
- channel: "feishu",
462
- messageId: "om_voice",
463
- details: { messageId: "om_voice", chatId: "oc_group_1" },
464
- });
465
-
466
- await feishuPlugin.actions?.handleAction?.({
467
- action: "send",
468
- params: {
469
- to: "chat:oc_group_1",
470
- media: "https://example.com/reply.mp3",
471
- asVoice: true,
472
- },
473
- cfg,
474
- accountId: undefined,
475
- toolContext: {},
476
- mediaLocalRoots: [],
477
- } as never);
478
-
479
- expect(feishuOutboundSendMediaMock).toHaveBeenCalledWith(
480
- expect.objectContaining({
481
- mediaUrl: "https://example.com/reply.mp3",
482
- audioAsVoice: true,
483
- }),
484
- );
485
- });
486
-
487
- it("reads messages", async () => {
488
- getMessageFeishuMock.mockResolvedValueOnce({
489
- messageId: "om_1",
490
- content: "hello",
491
- contentType: "text",
492
- });
493
-
494
- const result = await feishuPlugin.actions?.handleAction?.({
495
- action: "read",
496
- params: { messageId: "om_1" },
497
- cfg,
498
- accountId: undefined,
499
- } as never);
500
-
501
- expect(getMessageFeishuMock).toHaveBeenCalledWith({
502
- cfg,
503
- messageId: "om_1",
504
- accountId: undefined,
505
- });
506
- expect(result?.details).toMatchObject({
507
- ok: true,
508
- message: expect.objectContaining({ messageId: "om_1", content: "hello" }),
509
- });
510
- });
511
-
512
- it("returns an error result when message reads fail", async () => {
513
- getMessageFeishuMock.mockResolvedValueOnce(null);
514
-
515
- const result = await feishuPlugin.actions?.handleAction?.({
516
- action: "read",
517
- params: { messageId: "om_missing" },
518
- cfg,
519
- accountId: undefined,
520
- } as never);
521
-
522
- expect((result as { isError?: boolean } | undefined)?.isError).toBe(true);
523
- expect(result?.details).toEqual({
524
- error: "Feishu read failed or message not found: om_missing",
525
- });
526
- });
527
-
528
- it("edits messages", async () => {
529
- editMessageFeishuMock.mockResolvedValueOnce({ messageId: "om_2", contentType: "post" });
530
-
531
- const result = await feishuPlugin.actions?.handleAction?.({
532
- action: "edit",
533
- params: { messageId: "om_2", text: "updated" },
534
- cfg,
535
- accountId: undefined,
536
- } as never);
537
-
538
- expect(editMessageFeishuMock).toHaveBeenCalledWith({
539
- cfg,
540
- messageId: "om_2",
541
- text: "updated",
542
- card: undefined,
543
- accountId: undefined,
544
- });
545
- expect(result?.details).toMatchObject({ ok: true, messageId: "om_2", contentType: "post" });
546
- });
547
-
548
- it("sends explicit thread replies with reply_in_thread semantics", async () => {
549
- sendMessageFeishuMock.mockResolvedValueOnce({ messageId: "om_reply", chatId: "oc_group_1" });
550
-
551
- const result = await feishuPlugin.actions?.handleAction?.({
552
- action: "thread-reply",
553
- params: { to: "chat:oc_group_1", messageId: "om_parent", text: "reply body" },
554
- cfg,
555
- accountId: undefined,
556
- toolContext: {},
557
- } as never);
558
-
559
- expect(sendMessageFeishuMock).toHaveBeenCalledWith({
560
- cfg,
561
- to: "chat:oc_group_1",
562
- text: "reply body",
563
- accountId: undefined,
564
- replyToMessageId: "om_parent",
565
- replyInThread: true,
566
- });
567
- expect(result?.details).toMatchObject({
568
- ok: true,
569
- action: "thread-reply",
570
- messageId: "om_reply",
571
- });
572
- });
573
-
574
- it("creates pins", async () => {
575
- createPinFeishuMock.mockResolvedValueOnce({ messageId: "om_pin", chatId: "oc_group_1" });
576
-
577
- const result = await feishuPlugin.actions?.handleAction?.({
578
- action: "pin",
579
- params: { messageId: "om_pin" },
580
- cfg,
581
- accountId: undefined,
582
- } as never);
583
-
584
- expect(createPinFeishuMock).toHaveBeenCalledWith({
585
- cfg,
586
- messageId: "om_pin",
587
- accountId: undefined,
588
- });
589
- expect(result?.details).toMatchObject({
590
- ok: true,
591
- pin: expect.objectContaining({ messageId: "om_pin" }),
592
- });
593
- });
594
-
595
- it("lists pins", async () => {
596
- listPinsFeishuMock.mockResolvedValueOnce({
597
- chatId: "oc_group_1",
598
- pins: [{ messageId: "om_pin" }],
599
- hasMore: false,
600
- pageToken: undefined,
601
- });
602
-
603
- const result = await feishuPlugin.actions?.handleAction?.({
604
- action: "list-pins",
605
- params: { chatId: "oc_group_1" },
606
- cfg,
607
- accountId: undefined,
608
- toolContext: {},
609
- } as never);
610
-
611
- expect(listPinsFeishuMock).toHaveBeenCalledWith({
612
- cfg,
613
- chatId: "oc_group_1",
614
- startTime: undefined,
615
- endTime: undefined,
616
- pageSize: undefined,
617
- pageToken: undefined,
618
- accountId: undefined,
619
- });
620
- expect(result?.details).toMatchObject({
621
- ok: true,
622
- pins: [expect.objectContaining({ messageId: "om_pin" })],
623
- });
624
- });
625
-
626
- it("removes pins", async () => {
627
- const result = await feishuPlugin.actions?.handleAction?.({
628
- action: "unpin",
629
- params: { messageId: "om_pin" },
630
- cfg,
631
- accountId: undefined,
632
- } as never);
633
-
634
- expect(removePinFeishuMock).toHaveBeenCalledWith({
635
- cfg,
636
- messageId: "om_pin",
637
- accountId: undefined,
638
- });
639
- expect(result?.details).toMatchObject({ ok: true, messageId: "om_pin" });
640
- });
641
-
642
- it("fetches channel info", async () => {
643
- getChatInfoMock.mockResolvedValueOnce({ chat_id: "oc_group_1", name: "Eng" });
644
-
645
- const result = await feishuPlugin.actions?.handleAction?.({
646
- action: "channel-info",
647
- params: { chatId: "oc_group_1" },
648
- cfg,
649
- accountId: undefined,
650
- toolContext: {},
651
- } as never);
652
-
653
- expect(createFeishuClientMock).toHaveBeenCalled();
654
- expect(getChatInfoMock).toHaveBeenCalledWith({ tag: "client" }, "oc_group_1");
655
- expect(result?.details).toMatchObject({
656
- ok: true,
657
- channel: expect.objectContaining({ chat_id: "oc_group_1", name: "Eng" }),
658
- });
659
- });
660
-
661
- it("fetches member lists from a chat", async () => {
662
- getChatMembersMock.mockResolvedValueOnce({
663
- chat_id: "oc_group_1",
664
- members: [{ member_id: "ou_1", name: "Alice" }],
665
- has_more: false,
666
- });
667
-
668
- const result = await feishuPlugin.actions?.handleAction?.({
669
- action: "member-info",
670
- params: { chatId: "oc_group_1" },
671
- cfg,
672
- accountId: undefined,
673
- toolContext: {},
674
- } as never);
675
-
676
- expect(getChatMembersMock).toHaveBeenCalledWith(
677
- { tag: "client" },
678
- "oc_group_1",
679
- undefined,
680
- undefined,
681
- "open_id",
682
- );
683
- expect(result?.details).toMatchObject({
684
- ok: true,
685
- members: [expect.objectContaining({ member_id: "ou_1", name: "Alice" })],
686
- });
687
- });
688
-
689
- it("fetches individual member info", async () => {
690
- getFeishuMemberInfoMock.mockResolvedValueOnce({ member_id: "ou_1", name: "Alice" });
691
-
692
- const result = await feishuPlugin.actions?.handleAction?.({
693
- action: "member-info",
694
- params: { memberId: "ou_1" },
695
- cfg,
696
- accountId: undefined,
697
- toolContext: {},
698
- } as never);
699
-
700
- expect(getFeishuMemberInfoMock).toHaveBeenCalledWith({ tag: "client" }, "ou_1", "open_id");
701
- expect(result?.details).toMatchObject({
702
- ok: true,
703
- member: expect.objectContaining({ member_id: "ou_1", name: "Alice" }),
704
- });
705
- });
706
-
707
- it("infers user_id lookups from the userId alias", async () => {
708
- getFeishuMemberInfoMock.mockResolvedValueOnce({ member_id: "u_1", name: "Alice" });
709
-
710
- await feishuPlugin.actions?.handleAction?.({
711
- action: "member-info",
712
- params: { userId: "u_1" },
713
- cfg,
714
- accountId: undefined,
715
- toolContext: {},
716
- } as never);
717
-
718
- expect(getFeishuMemberInfoMock).toHaveBeenCalledWith({ tag: "client" }, "u_1", "user_id");
719
- });
720
-
721
- it("honors explicit open_id over alias heuristics", async () => {
722
- getFeishuMemberInfoMock.mockResolvedValueOnce({ member_id: "u_1", name: "Alice" });
723
-
724
- await feishuPlugin.actions?.handleAction?.({
725
- action: "member-info",
726
- params: { userId: "u_1", memberIdType: "open_id" },
727
- cfg,
728
- accountId: undefined,
729
- toolContext: {},
730
- } as never);
731
-
732
- expect(getFeishuMemberInfoMock).toHaveBeenCalledWith({ tag: "client" }, "u_1", "open_id");
733
- });
734
-
735
- it("lists directory-backed peers and groups", async () => {
736
- listFeishuDirectoryGroupsLiveMock.mockResolvedValueOnce([{ kind: "group", id: "oc_group_1" }]);
737
- listFeishuDirectoryPeersLiveMock.mockResolvedValueOnce([{ kind: "user", id: "ou_1" }]);
738
-
739
- const result = await feishuPlugin.actions?.handleAction?.({
740
- action: "channel-list",
741
- params: { query: "eng", limit: 5 },
742
- cfg,
743
- accountId: undefined,
744
- } as never);
745
-
746
- expect(listFeishuDirectoryGroupsLiveMock).toHaveBeenCalledWith({
747
- cfg,
748
- query: "eng",
749
- limit: 5,
750
- fallbackToStatic: false,
751
- accountId: undefined,
752
- });
753
- expect(listFeishuDirectoryPeersLiveMock).toHaveBeenCalledWith({
754
- cfg,
755
- query: "eng",
756
- limit: 5,
757
- fallbackToStatic: false,
758
- accountId: undefined,
759
- });
760
- expect(result?.details).toMatchObject({
761
- ok: true,
762
- groups: [expect.objectContaining({ id: "oc_group_1" })],
763
- peers: [expect.objectContaining({ id: "ou_1" })],
764
- });
765
- });
766
-
767
- it("fails channel-list when live discovery fails", async () => {
768
- listFeishuDirectoryGroupsLiveMock.mockRejectedValueOnce(new Error("token expired"));
769
-
770
- await expect(
771
- feishuPlugin.actions?.handleAction?.({
772
- action: "channel-list",
773
- params: { query: "eng", limit: 5, scope: "groups" },
774
- cfg,
775
- accountId: undefined,
776
- } as never),
777
- ).rejects.toThrow("token expired");
778
- });
779
-
780
- it("requires clearAll=true before removing all bot reactions", async () => {
781
- await expect(
782
- feishuPlugin.actions?.handleAction?.({
783
- action: "react",
784
- params: { messageId: "om_msg1" },
785
- cfg,
786
- accountId: undefined,
787
- } as never),
788
- ).rejects.toThrow(
789
- "Emoji is required to add a Feishu reaction. Set clearAll=true to remove all bot reactions.",
790
- );
791
- });
792
-
793
- it("allows explicit clearAll=true when removing all bot reactions", async () => {
794
- listReactionsFeishuMock.mockResolvedValueOnce([
795
- { reactionId: "r1", operatorType: "app" },
796
- { reactionId: "r2", operatorType: "app" },
797
- ]);
798
-
799
- const result = await feishuPlugin.actions?.handleAction?.({
800
- action: "react",
801
- params: { messageId: "om_msg1", clearAll: true },
802
- cfg,
803
- accountId: undefined,
804
- } as never);
805
-
806
- expect(listReactionsFeishuMock).toHaveBeenCalledWith({
807
- cfg,
808
- messageId: "om_msg1",
809
- accountId: undefined,
810
- });
811
- expect(removeReactionFeishuMock).toHaveBeenCalledTimes(2);
812
- expect(result?.details).toMatchObject({ ok: true, removed: 2 });
813
- });
814
-
815
- it("fails for missing params on supported actions", async () => {
816
- await expect(
817
- feishuPlugin.actions?.handleAction?.({
818
- action: "thread-reply",
819
- params: { to: "chat:oc_group_1", message: "reply body" },
820
- cfg,
821
- accountId: undefined,
822
- } as never),
823
- ).rejects.toThrow("Feishu thread-reply requires messageId.");
824
- });
825
-
826
- it("sends media-only messages without requiring card", async () => {
827
- feishuOutboundSendMediaMock.mockResolvedValueOnce({
828
- channel: "feishu",
829
- messageId: "om_media_only",
830
- details: { messageId: "om_media_only", chatId: "oc_group_1" },
831
- });
832
-
833
- const result = await feishuPlugin.actions?.handleAction?.({
834
- action: "send",
835
- params: {
836
- to: "chat:oc_group_1",
837
- media: "https://example.com/image.png",
838
- },
839
- cfg,
840
- accountId: undefined,
841
- toolContext: {},
842
- mediaLocalRoots: [],
843
- } as never);
844
-
845
- expect(feishuOutboundSendMediaMock).toHaveBeenCalledWith(
846
- expect.objectContaining({
847
- to: "chat:oc_group_1",
848
- mediaUrl: "https://example.com/image.png",
849
- }),
850
- );
851
- expect(result?.details).toMatchObject({ messageId: "om_media_only" });
852
- });
853
-
854
- it("fails for unsupported action names", async () => {
855
- await expect(
856
- feishuPlugin.actions?.handleAction?.({
857
- action: "search",
858
- params: {},
859
- cfg,
860
- accountId: undefined,
861
- } as never),
862
- ).rejects.toThrow('Unsupported Feishu action: "search"');
863
- });
864
- });
865
-
866
- describe("resolveReceiveIdType", () => {
867
- it("resolves chat IDs by oc_ prefix", () => {
868
- expect(resolveReceiveIdType("oc_123")).toBe("chat_id");
869
- });
870
-
871
- it("resolves open IDs by ou_ prefix", () => {
872
- expect(resolveReceiveIdType("ou_123")).toBe("open_id");
873
- });
874
-
875
- it("defaults unprefixed IDs to user_id", () => {
876
- expect(resolveReceiveIdType("u_123")).toBe("user_id");
877
- });
878
-
879
- it("treats explicit group targets as chat_id", () => {
880
- expect(resolveReceiveIdType("group:oc_123")).toBe("chat_id");
881
- });
882
-
883
- it("treats explicit channel targets as chat_id", () => {
884
- expect(resolveReceiveIdType("channel:oc_123")).toBe("chat_id");
885
- });
886
-
887
- it("treats dm-prefixed open IDs as open_id", () => {
888
- expect(resolveReceiveIdType("dm:ou_123")).toBe("open_id");
889
- });
890
- });
891
-
892
- describe("normalizeFeishuTarget", () => {
893
- it("strips provider and user prefixes", () => {
894
- expect(normalizeFeishuTarget("feishu:user:ou_123")).toBe("ou_123");
895
- expect(normalizeFeishuTarget("lark:user:ou_123")).toBe("ou_123");
896
- });
897
-
898
- it("strips provider and chat prefixes", () => {
899
- expect(normalizeFeishuTarget("feishu:chat:oc_123")).toBe("oc_123");
900
- });
901
-
902
- it("normalizes group/channel prefixes to chat ids", () => {
903
- expect(normalizeFeishuTarget("group:oc_123")).toBe("oc_123");
904
- expect(normalizeFeishuTarget("feishu:group:oc_123")).toBe("oc_123");
905
- expect(normalizeFeishuTarget("channel:oc_456")).toBe("oc_456");
906
- expect(normalizeFeishuTarget("lark:channel:oc_456")).toBe("oc_456");
907
- });
908
-
909
- it("accepts provider-prefixed raw ids", () => {
910
- expect(normalizeFeishuTarget("feishu:ou_123")).toBe("ou_123");
911
- });
912
-
913
- it("strips provider and dm prefixes", () => {
914
- expect(normalizeFeishuTarget("lark:dm:ou_123")).toBe("ou_123");
915
- });
916
- });
917
-
918
- describe("feishuPlugin.messaging.resolveDeliveryTarget", () => {
919
- it("routes direct conversations to user targets", () => {
920
- expect(
921
- feishuPlugin.messaging?.resolveDeliveryTarget?.({
922
- conversationId: "ou_123",
923
- }),
924
- ).toEqual({ to: "user:ou_123" });
925
- });
926
-
927
- it("routes group conversations to chat targets", () => {
928
- expect(
929
- feishuPlugin.messaging?.resolveDeliveryTarget?.({
930
- conversationId: "oc_123",
931
- }),
932
- ).toEqual({ to: "chat:oc_123" });
933
- });
934
-
935
- it("routes topic conversations to parent chat plus thread id", () => {
936
- expect(
937
- feishuPlugin.messaging?.resolveDeliveryTarget?.({
938
- conversationId: "oc_123:topic:omt_456",
939
- parentConversationId: "oc_123",
940
- }),
941
- ).toEqual({ to: "chat:oc_123", threadId: "omt_456" });
942
- });
943
- });
944
-
945
- describe("looksLikeFeishuId", () => {
946
- it("accepts provider-prefixed user targets", () => {
947
- expect(looksLikeFeishuId("feishu:user:ou_123")).toBe(true);
948
- });
949
-
950
- it("accepts provider-prefixed chat targets", () => {
951
- expect(looksLikeFeishuId("lark:chat:oc_123")).toBe(true);
952
- });
953
-
954
- it("accepts group/channel targets", () => {
955
- expect(looksLikeFeishuId("feishu:group:oc_123")).toBe(true);
956
- expect(looksLikeFeishuId("group:oc_123")).toBe(true);
957
- expect(looksLikeFeishuId("channel:oc_456")).toBe(true);
958
- });
959
- });