@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,935 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import os from "node:os";
3
- import path from "node:path";
4
- import type { MessagePresentation } from "openclaw/plugin-sdk/interactive-runtime";
5
- import { beforeEach, describe, expect, it, vi } from "vitest";
6
- import type { ClawdbotConfig } from "../runtime-api.js";
7
-
8
- const sendMediaFeishuMock = vi.hoisted(() => vi.fn());
9
- const sendMessageFeishuMock = vi.hoisted(() => vi.fn());
10
- const sendCardFeishuMock = vi.hoisted(() => vi.fn());
11
- const sendMarkdownCardFeishuMock = vi.hoisted(() => vi.fn());
12
- const sendStructuredCardFeishuMock = vi.hoisted(() => vi.fn());
13
- const deliverCommentThreadTextMock = vi.hoisted(() => vi.fn());
14
- const cleanupAmbientCommentTypingReactionMock = vi.hoisted(() => vi.fn(async () => false));
15
-
16
- vi.mock("./media.js", () => ({
17
- sendMediaFeishu: sendMediaFeishuMock,
18
- }));
19
-
20
- vi.mock("./send.js", () => ({
21
- sendCardFeishu: sendCardFeishuMock,
22
- sendMessageFeishu: sendMessageFeishuMock,
23
- sendMarkdownCardFeishu: sendMarkdownCardFeishuMock,
24
- sendStructuredCardFeishu: sendStructuredCardFeishuMock,
25
- resolveFeishuCardTemplate: (template?: string) =>
26
- new Set([
27
- "blue",
28
- "green",
29
- "red",
30
- "orange",
31
- "purple",
32
- "indigo",
33
- "wathet",
34
- "turquoise",
35
- "yellow",
36
- "grey",
37
- "carmine",
38
- "violet",
39
- "lime",
40
- ]).has(template ?? "")
41
- ? template
42
- : undefined,
43
- }));
44
-
45
- vi.mock("./runtime.js", () => ({
46
- getFeishuRuntime: () => ({
47
- channel: {
48
- text: {
49
- chunkMarkdownText: (text: string) => [text],
50
- },
51
- },
52
- }),
53
- }));
54
-
55
- vi.mock("./client.js", () => ({
56
- createFeishuClient: vi.fn(() => ({ request: vi.fn() })),
57
- }));
58
-
59
- vi.mock("./drive.js", () => ({
60
- deliverCommentThreadText: deliverCommentThreadTextMock,
61
- }));
62
-
63
- vi.mock("./comment-reaction.js", () => ({
64
- cleanupAmbientCommentTypingReaction: cleanupAmbientCommentTypingReactionMock,
65
- }));
66
-
67
- import { feishuOutbound } from "./outbound.js";
68
- const sendText = feishuOutbound.sendText!;
69
- const emptyConfig: ClawdbotConfig = {};
70
- const cardRenderConfig: ClawdbotConfig = {
71
- channels: {
72
- feishu: {
73
- renderMode: "card",
74
- },
75
- },
76
- };
77
-
78
- function resetOutboundMocks() {
79
- vi.clearAllMocks();
80
- sendMessageFeishuMock.mockResolvedValue({ messageId: "text_msg" });
81
- sendCardFeishuMock.mockResolvedValue({ messageId: "native_card_msg" });
82
- sendMarkdownCardFeishuMock.mockResolvedValue({ messageId: "card_msg" });
83
- sendStructuredCardFeishuMock.mockResolvedValue({ messageId: "card_msg" });
84
- sendMediaFeishuMock.mockResolvedValue({ messageId: "media_msg" });
85
- deliverCommentThreadTextMock.mockResolvedValue({
86
- delivery_mode: "reply_comment",
87
- reply_id: "reply_msg",
88
- });
89
- cleanupAmbientCommentTypingReactionMock.mockResolvedValue(false);
90
- }
91
-
92
- describe("feishuOutbound.sendText local-image auto-convert", () => {
93
- beforeEach(() => {
94
- resetOutboundMocks();
95
- });
96
-
97
- it("chunks outbound text without requiring Feishu runtime initialization", () => {
98
- const chunker = feishuOutbound.chunker;
99
- if (!chunker) {
100
- throw new Error("feishuOutbound.chunker missing");
101
- }
102
-
103
- expect(() => chunker("hello world", 5)).not.toThrow();
104
- expect(chunker("hello world", 5)).toEqual(["hello", "world"]);
105
- });
106
-
107
- async function createTmpImage(ext = ".png"): Promise<{ dir: string; file: string }> {
108
- const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-feishu-outbound-"));
109
- const file = path.join(dir, `sample${ext}`);
110
- await fs.writeFile(file, "image-data");
111
- return { dir, file };
112
- }
113
-
114
- it("sends an absolute existing local image path as media", async () => {
115
- const { dir, file } = await createTmpImage();
116
- try {
117
- const result = await sendText({
118
- cfg: emptyConfig,
119
- to: "chat_1",
120
- text: file,
121
- accountId: "main",
122
- mediaLocalRoots: [dir],
123
- });
124
-
125
- expect(sendMediaFeishuMock).toHaveBeenCalledWith(
126
- expect.objectContaining({
127
- to: "chat_1",
128
- mediaUrl: file,
129
- accountId: "main",
130
- mediaLocalRoots: [dir],
131
- }),
132
- );
133
- expect(sendMessageFeishuMock).not.toHaveBeenCalled();
134
- expect(result).toEqual(
135
- expect.objectContaining({ channel: "feishu", messageId: "media_msg" }),
136
- );
137
- } finally {
138
- await fs.rm(dir, { recursive: true, force: true });
139
- }
140
- });
141
-
142
- it("keeps non-path text on the text-send path", async () => {
143
- await sendText({
144
- cfg: emptyConfig,
145
- to: "chat_1",
146
- text: "please upload /tmp/example.png",
147
- accountId: "main",
148
- });
149
-
150
- expect(sendMediaFeishuMock).not.toHaveBeenCalled();
151
- expect(sendMessageFeishuMock).toHaveBeenCalledWith(
152
- expect.objectContaining({
153
- to: "chat_1",
154
- text: "please upload /tmp/example.png",
155
- accountId: "main",
156
- }),
157
- );
158
- });
159
-
160
- it("falls back to plain text if local-image media send fails", async () => {
161
- const { dir, file } = await createTmpImage();
162
- sendMediaFeishuMock.mockRejectedValueOnce(new Error("upload failed"));
163
- try {
164
- await sendText({
165
- cfg: emptyConfig,
166
- to: "chat_1",
167
- text: file,
168
- accountId: "main",
169
- });
170
-
171
- expect(sendMediaFeishuMock).toHaveBeenCalledTimes(1);
172
- expect(sendMessageFeishuMock).toHaveBeenCalledWith(
173
- expect.objectContaining({
174
- to: "chat_1",
175
- text: file,
176
- accountId: "main",
177
- }),
178
- );
179
- } finally {
180
- await fs.rm(dir, { recursive: true, force: true });
181
- }
182
- });
183
-
184
- it("uses markdown cards when renderMode=card", async () => {
185
- const result = await sendText({
186
- cfg: cardRenderConfig,
187
- to: "chat_1",
188
- text: "| a | b |\n| - | - |",
189
- accountId: "main",
190
- });
191
-
192
- expect(sendStructuredCardFeishuMock).toHaveBeenCalledWith(
193
- expect.objectContaining({
194
- to: "chat_1",
195
- text: "| a | b |\n| - | - |",
196
- accountId: "main",
197
- }),
198
- );
199
- expect(sendMessageFeishuMock).not.toHaveBeenCalled();
200
- expect(result).toEqual(expect.objectContaining({ channel: "feishu", messageId: "card_msg" }));
201
- });
202
-
203
- it("forwards replyToId as replyToMessageId on sendText", async () => {
204
- await sendText({
205
- cfg: emptyConfig,
206
- to: "chat_1",
207
- text: "hello",
208
- replyToId: "om_reply_1",
209
- accountId: "main",
210
- });
211
-
212
- expect(sendMessageFeishuMock).toHaveBeenCalledWith(
213
- expect.objectContaining({
214
- to: "chat_1",
215
- text: "hello",
216
- replyToMessageId: "om_reply_1",
217
- accountId: "main",
218
- }),
219
- );
220
- });
221
-
222
- it("falls back to threadId when replyToId is empty on sendText", async () => {
223
- await sendText({
224
- cfg: emptyConfig,
225
- to: "chat_1",
226
- text: "hello",
227
- replyToId: " ",
228
- threadId: "om_thread_2",
229
- accountId: "main",
230
- });
231
-
232
- expect(sendMessageFeishuMock).toHaveBeenCalledWith(
233
- expect.objectContaining({
234
- to: "chat_1",
235
- text: "hello",
236
- replyToMessageId: "om_thread_2",
237
- accountId: "main",
238
- }),
239
- );
240
- });
241
- });
242
-
243
- describe("feishuOutbound.sendPayload native cards", () => {
244
- beforeEach(() => {
245
- resetOutboundMocks();
246
- });
247
-
248
- async function createTmpImage(ext = ".png"): Promise<{ dir: string; file: string }> {
249
- const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-feishu-payload-"));
250
- const file = path.join(dir, `sample${ext}`);
251
- await fs.writeFile(file, "image-data");
252
- return { dir, file };
253
- }
254
-
255
- it("renders presentation-only payloads into Feishu channelData cards for core delivery", async () => {
256
- const presentation: MessagePresentation = {
257
- title: "Approval",
258
- tone: "success",
259
- blocks: [
260
- { type: "text", text: "Approve the request?" },
261
- {
262
- type: "buttons",
263
- buttons: [
264
- { label: "Approve", value: "/approve req_1 allow-once", style: "success" as const },
265
- ],
266
- },
267
- ],
268
- };
269
- const payload = { presentation };
270
- const rendered = await feishuOutbound.renderPresentation?.({
271
- payload,
272
- presentation,
273
- ctx: {
274
- cfg: emptyConfig,
275
- to: "chat_1",
276
- text: "",
277
- accountId: "main",
278
- payload,
279
- },
280
- });
281
-
282
- expect(rendered).toEqual(
283
- expect.objectContaining({
284
- text: "Approval\n\nApprove the request?\n\n- Approve",
285
- channelData: {
286
- feishu: {
287
- card: expect.objectContaining({
288
- schema: "2.0",
289
- header: {
290
- title: { tag: "plain_text", content: "Approval" },
291
- template: "green",
292
- },
293
- body: {
294
- elements: expect.arrayContaining([
295
- { tag: "markdown", content: "Approve the request?" },
296
- expect.objectContaining({ tag: "action" }),
297
- ]),
298
- },
299
- }),
300
- },
301
- },
302
- }),
303
- );
304
-
305
- if (!rendered) {
306
- throw new Error("expected Feishu presentation renderer to return a payload");
307
- }
308
- const { presentation: _presentation, ...coreRenderedPayload } = rendered;
309
- const result = await feishuOutbound.sendPayload?.({
310
- cfg: emptyConfig,
311
- to: "chat_1",
312
- text: coreRenderedPayload.text ?? "",
313
- accountId: "main",
314
- payload: coreRenderedPayload,
315
- });
316
-
317
- expect(sendCardFeishuMock).toHaveBeenCalledWith(
318
- expect.objectContaining({
319
- to: "chat_1",
320
- card: expect.objectContaining({
321
- header: {
322
- title: { tag: "plain_text", content: "Approval" },
323
- template: "green",
324
- },
325
- }),
326
- }),
327
- );
328
- expect(sendMessageFeishuMock).not.toHaveBeenCalled();
329
- expect(result).toEqual(
330
- expect.objectContaining({ channel: "feishu", messageId: "native_card_msg" }),
331
- );
332
- });
333
-
334
- it("sends interactive button payloads as native Feishu cards", async () => {
335
- const result = await feishuOutbound.sendPayload?.({
336
- cfg: emptyConfig,
337
- to: "chat_1",
338
- text: "Choose an action",
339
- accountId: "main",
340
- payload: {
341
- text: "Choose an action",
342
- interactive: {
343
- blocks: [
344
- { type: "text", text: "Approve the request?" },
345
- {
346
- type: "buttons",
347
- buttons: [
348
- { label: "Approve", value: "/approve req_1 allow-once", style: "success" },
349
- { label: "Deny", value: "/approve req_1 deny", style: "danger" },
350
- ],
351
- },
352
- ],
353
- },
354
- },
355
- });
356
-
357
- expect(sendCardFeishuMock).toHaveBeenCalledWith(
358
- expect.objectContaining({
359
- cfg: emptyConfig,
360
- to: "chat_1",
361
- accountId: "main",
362
- }),
363
- );
364
- const card = sendCardFeishuMock.mock.calls[0][0].card;
365
- expect(card).toEqual(
366
- expect.objectContaining({
367
- schema: "2.0",
368
- body: {
369
- elements: expect.arrayContaining([
370
- { tag: "markdown", content: "Choose an action" },
371
- { tag: "markdown", content: "Approve the request?" },
372
- expect.objectContaining({
373
- tag: "action",
374
- actions: [
375
- expect.objectContaining({
376
- text: { tag: "plain_text", content: "Approve" },
377
- type: "primary",
378
- value: expect.objectContaining({
379
- oc: "ocf1",
380
- k: "quick",
381
- q: "/approve req_1 allow-once",
382
- }),
383
- }),
384
- expect.objectContaining({
385
- text: { tag: "plain_text", content: "Deny" },
386
- type: "danger",
387
- value: expect.objectContaining({
388
- oc: "ocf1",
389
- k: "quick",
390
- q: "/approve req_1 deny",
391
- }),
392
- }),
393
- ],
394
- }),
395
- ]),
396
- },
397
- }),
398
- );
399
- expect(sendMessageFeishuMock).not.toHaveBeenCalled();
400
- expect(result).toEqual(
401
- expect.objectContaining({ channel: "feishu", messageId: "native_card_msg" }),
402
- );
403
- });
404
-
405
- it("escapes generated markdown card text and drops unsafe button URLs", async () => {
406
- await feishuOutbound.sendPayload?.({
407
- cfg: emptyConfig,
408
- to: "chat_1",
409
- text: "Choose <at id=\"ou_1\">",
410
- accountId: "main",
411
- payload: {
412
- text: "Choose <at id=\"ou_1\">",
413
- presentation: {
414
- blocks: [
415
- { type: "context", text: "</font><at id=\"ou_2\">Injected</at>" },
416
- {
417
- type: "buttons",
418
- buttons: [
419
- { label: "Open", url: "https://example.com/path" },
420
- { label: "Bad", url: "javascript:alert(1)" },
421
- ],
422
- },
423
- ],
424
- },
425
- },
426
- });
427
-
428
- const card = sendCardFeishuMock.mock.calls[0][0].card;
429
- expect(card.body.elements).toEqual(
430
- expect.arrayContaining([
431
- { tag: "markdown", content: "Choose &lt;at id=\"ou_1\"&gt;" },
432
- {
433
- tag: "markdown",
434
- content: "<font color='grey'>&lt;/font&gt;&lt;at id=\"ou_2\"&gt;Injected&lt;/at&gt;</font>",
435
- },
436
- {
437
- tag: "action",
438
- actions: [
439
- expect.objectContaining({
440
- text: { tag: "plain_text", content: "Open" },
441
- url: "https://example.com/path",
442
- }),
443
- ],
444
- },
445
- ]),
446
- );
447
- expect(JSON.stringify(card)).not.toContain("javascript:");
448
- });
449
-
450
- it("normalizes caller-supplied native Feishu cards before sending", async () => {
451
- await feishuOutbound.sendPayload?.({
452
- cfg: emptyConfig,
453
- to: "chat_1",
454
- text: "fallback",
455
- accountId: "main",
456
- payload: {
457
- text: "fallback",
458
- channelData: {
459
- feishu: {
460
- card: {
461
- schema: "2.0",
462
- header: {
463
- title: { tag: "plain_text", content: "Unsafe card" },
464
- template: "not-a-template",
465
- },
466
- body: {
467
- elements: [
468
- { tag: "img", img_key: "image-secret" },
469
- { tag: "markdown", content: "<at id=\"ou_1\">ping</at>" },
470
- {
471
- tag: "action",
472
- actions: [
473
- {
474
- tag: "button",
475
- text: { tag: "plain_text", content: "Bad link" },
476
- url: "file:///etc/passwd",
477
- },
478
- {
479
- tag: "button",
480
- text: { tag: "plain_text", content: "Good link" },
481
- url: "https://example.com",
482
- },
483
- ],
484
- },
485
- ],
486
- },
487
- },
488
- },
489
- },
490
- },
491
- });
492
-
493
- const card = sendCardFeishuMock.mock.calls[0][0].card;
494
- expect(card.header.template).toBe("blue");
495
- expect(card.body.elements).toEqual([
496
- { tag: "markdown", content: "&lt;at id=\"ou_1\"&gt;ping&lt;/at&gt;" },
497
- {
498
- tag: "action",
499
- actions: [
500
- expect.objectContaining({
501
- text: { tag: "plain_text", content: "Good link" },
502
- url: "https://example.com",
503
- }),
504
- ],
505
- },
506
- ]);
507
- expect(JSON.stringify(card)).not.toContain("file://");
508
- expect(JSON.stringify(card)).not.toContain("image-secret");
509
- });
510
-
511
- it("sends payload media before final native cards", async () => {
512
- const result = await feishuOutbound.sendPayload?.({
513
- cfg: emptyConfig,
514
- to: "chat_1",
515
- text: "See attached",
516
- accountId: "main",
517
- mediaLocalRoots: ["/tmp"],
518
- payload: {
519
- text: "See attached",
520
- mediaUrl: "/tmp/image.png",
521
- interactive: {
522
- blocks: [{ type: "buttons", buttons: [{ label: "Open", url: "https://example.com" }] }],
523
- },
524
- },
525
- });
526
-
527
- expect(sendMediaFeishuMock).toHaveBeenCalledWith(
528
- expect.objectContaining({
529
- to: "chat_1",
530
- mediaUrl: "/tmp/image.png",
531
- mediaLocalRoots: ["/tmp"],
532
- accountId: "main",
533
- }),
534
- );
535
- expect(sendCardFeishuMock).toHaveBeenCalledWith(
536
- expect.objectContaining({
537
- to: "chat_1",
538
- accountId: "main",
539
- }),
540
- );
541
- expect(result).toEqual(
542
- expect.objectContaining({ channel: "feishu", messageId: "native_card_msg" }),
543
- );
544
- });
545
-
546
- it("keeps text/media fallback behavior for non-card payloads, including local image text", async () => {
547
- const { dir, file } = await createTmpImage();
548
- try {
549
- const result = await feishuOutbound.sendPayload?.({
550
- cfg: emptyConfig,
551
- to: "chat_1",
552
- text: file,
553
- accountId: "main",
554
- mediaLocalRoots: [dir],
555
- payload: { text: file },
556
- });
557
-
558
- expect(sendCardFeishuMock).not.toHaveBeenCalled();
559
- expect(sendMediaFeishuMock).toHaveBeenCalledWith(
560
- expect.objectContaining({
561
- to: "chat_1",
562
- mediaUrl: file,
563
- mediaLocalRoots: [dir],
564
- accountId: "main",
565
- }),
566
- );
567
- expect(sendMessageFeishuMock).not.toHaveBeenCalled();
568
- expect(result).toEqual(
569
- expect.objectContaining({ channel: "feishu", messageId: "media_msg" }),
570
- );
571
- } finally {
572
- await fs.rm(dir, { recursive: true, force: true });
573
- }
574
- });
575
-
576
- it("falls back to comment-thread text instead of sending native cards to document comments", async () => {
577
- const result = await feishuOutbound.sendPayload?.({
578
- cfg: emptyConfig,
579
- to: "comment:docx:doxcn123:7623358762119646411",
580
- text: "Review this",
581
- accountId: "main",
582
- payload: {
583
- text: "Review this",
584
- interactive: {
585
- blocks: [{ type: "buttons", buttons: [{ label: "Approve", value: "/approve req_1" }] }],
586
- },
587
- },
588
- });
589
-
590
- expect(sendCardFeishuMock).not.toHaveBeenCalled();
591
- expect(deliverCommentThreadTextMock).toHaveBeenCalledWith(
592
- expect.anything(),
593
- expect.objectContaining({
594
- content: "Review this\n\n- Approve",
595
- }),
596
- );
597
- expect(result).toEqual(expect.objectContaining({ channel: "feishu", messageId: "reply_msg" }));
598
- });
599
- });
600
-
601
- describe("feishuOutbound comment-thread routing", () => {
602
- beforeEach(() => {
603
- resetOutboundMocks();
604
- });
605
-
606
- it("routes comment-thread text through deliverCommentThreadText", async () => {
607
- const result = await sendText({
608
- cfg: emptyConfig,
609
- to: "comment:docx:doxcn123:7623358762119646411",
610
- text: "handled in thread",
611
- accountId: "main",
612
- });
613
-
614
- expect(deliverCommentThreadTextMock).toHaveBeenCalledWith(
615
- expect.anything(),
616
- expect.objectContaining({
617
- file_token: "doxcn123",
618
- file_type: "docx",
619
- comment_id: "7623358762119646411",
620
- content: "handled in thread",
621
- }),
622
- );
623
- expect(sendMessageFeishuMock).not.toHaveBeenCalled();
624
- expect(result).toEqual(expect.objectContaining({ channel: "feishu", messageId: "reply_msg" }));
625
- });
626
-
627
- it("routes comment-thread code-block replies through deliverCommentThreadText instead of IM cards", async () => {
628
- const result = await sendText({
629
- cfg: emptyConfig,
630
- to: "comment:docx:doxcn123:7623358762119646411",
631
- text: "```ts\nconst x = 1\n```",
632
- accountId: "main",
633
- });
634
-
635
- expect(deliverCommentThreadTextMock).toHaveBeenCalledWith(
636
- expect.anything(),
637
- expect.objectContaining({
638
- file_token: "doxcn123",
639
- file_type: "docx",
640
- comment_id: "7623358762119646411",
641
- content: "```ts\nconst x = 1\n```",
642
- }),
643
- );
644
- expect(sendStructuredCardFeishuMock).not.toHaveBeenCalled();
645
- expect(sendMarkdownCardFeishuMock).not.toHaveBeenCalled();
646
- expect(result).toEqual(expect.objectContaining({ channel: "feishu", messageId: "reply_msg" }));
647
- });
648
-
649
- it("routes comment-thread replies through deliverCommentThreadText even when renderMode=card", async () => {
650
- const result = await sendText({
651
- cfg: cardRenderConfig,
652
- to: "comment:docx:doxcn123:7623358762119646411",
653
- text: "handled in thread",
654
- accountId: "main",
655
- });
656
-
657
- expect(deliverCommentThreadTextMock).toHaveBeenCalledWith(
658
- expect.anything(),
659
- expect.objectContaining({
660
- file_token: "doxcn123",
661
- file_type: "docx",
662
- comment_id: "7623358762119646411",
663
- content: "handled in thread",
664
- }),
665
- );
666
- expect(sendStructuredCardFeishuMock).not.toHaveBeenCalled();
667
- expect(sendMarkdownCardFeishuMock).not.toHaveBeenCalled();
668
- expect(result).toEqual(expect.objectContaining({ channel: "feishu", messageId: "reply_msg" }));
669
- });
670
-
671
- it("falls back to a text-only comment reply for media payloads", async () => {
672
- const result = await feishuOutbound.sendMedia?.({
673
- cfg: emptyConfig,
674
- to: "comment:docx:doxcn123:7623358762119646411",
675
- text: "see attachment",
676
- mediaUrl: "https://example.com/file.png",
677
- accountId: "main",
678
- });
679
-
680
- expect(deliverCommentThreadTextMock).toHaveBeenCalledWith(
681
- expect.anything(),
682
- expect.objectContaining({
683
- content: "see attachment\n\nhttps://example.com/file.png",
684
- }),
685
- );
686
- expect(sendMediaFeishuMock).not.toHaveBeenCalled();
687
- expect(result).toEqual(expect.objectContaining({ channel: "feishu", messageId: "reply_msg" }));
688
- });
689
-
690
- it("preserves comment-thread routing when deliverCommentThreadText falls back to add_comment", async () => {
691
- deliverCommentThreadTextMock.mockResolvedValueOnce({
692
- delivery_mode: "add_comment",
693
- comment_id: "comment_msg",
694
- reply_id: "reply_from_add_comment",
695
- });
696
-
697
- const result = await sendText({
698
- cfg: emptyConfig,
699
- to: "comment:docx:doxcn123:7623358762119646411",
700
- text: "whole-comment follow-up",
701
- accountId: "main",
702
- });
703
-
704
- expect(deliverCommentThreadTextMock).toHaveBeenCalledWith(
705
- expect.anything(),
706
- expect.objectContaining({
707
- file_token: "doxcn123",
708
- file_type: "docx",
709
- comment_id: "7623358762119646411",
710
- content: "whole-comment follow-up",
711
- }),
712
- );
713
- expect(result).toEqual(
714
- expect.objectContaining({
715
- channel: "feishu",
716
- messageId: "reply_from_add_comment",
717
- }),
718
- );
719
- });
720
-
721
- it("does not wait for ambient comment typing cleanup before sending comment-thread replies", async () => {
722
- let resolveCleanup: ((value: boolean) => void) | undefined;
723
- cleanupAmbientCommentTypingReactionMock.mockImplementationOnce(
724
- () =>
725
- new Promise<boolean>((resolve) => {
726
- resolveCleanup = resolve;
727
- }),
728
- );
729
-
730
- const sendPromise = sendText({
731
- cfg: emptyConfig,
732
- to: "comment:docx:doxcn123:7623358762119646411",
733
- text: "handled in thread",
734
- replyToId: "reply_ambient_1",
735
- accountId: "main",
736
- });
737
-
738
- const status = await Promise.race([
739
- sendPromise.then(() => "done"),
740
- new Promise<string>((resolve) => setTimeout(() => resolve("pending"), 0)),
741
- ]);
742
-
743
- expect(status).toBe("done");
744
- expect(deliverCommentThreadTextMock).toHaveBeenCalled();
745
- expect(cleanupAmbientCommentTypingReactionMock).toHaveBeenCalledWith({
746
- client: expect.anything(),
747
- deliveryContext: {
748
- channel: "feishu",
749
- to: "comment:docx:doxcn123:7623358762119646411",
750
- threadId: "reply_ambient_1",
751
- },
752
- });
753
-
754
- resolveCleanup?.(false);
755
- await sendPromise;
756
- });
757
- });
758
-
759
- describe("feishuOutbound.sendText replyToId forwarding", () => {
760
- beforeEach(() => {
761
- resetOutboundMocks();
762
- });
763
-
764
- it("forwards replyToId as replyToMessageId to sendMessageFeishu", async () => {
765
- await sendText({
766
- cfg: emptyConfig,
767
- to: "chat_1",
768
- text: "hello",
769
- replyToId: "om_reply_target",
770
- accountId: "main",
771
- });
772
-
773
- expect(sendMessageFeishuMock).toHaveBeenCalledWith(
774
- expect.objectContaining({
775
- to: "chat_1",
776
- text: "hello",
777
- replyToMessageId: "om_reply_target",
778
- accountId: "main",
779
- }),
780
- );
781
- });
782
-
783
- it("forwards replyToId to sendStructuredCardFeishu when renderMode=card", async () => {
784
- await sendText({
785
- cfg: cardRenderConfig,
786
- to: "chat_1",
787
- text: "```code```",
788
- replyToId: "om_reply_target",
789
- accountId: "main",
790
- });
791
-
792
- expect(sendStructuredCardFeishuMock).toHaveBeenCalledWith(
793
- expect.objectContaining({
794
- replyToMessageId: "om_reply_target",
795
- }),
796
- );
797
- });
798
-
799
- it("does not pass replyToMessageId when replyToId is absent", async () => {
800
- await sendText({
801
- cfg: emptyConfig,
802
- to: "chat_1",
803
- text: "hello",
804
- accountId: "main",
805
- });
806
-
807
- expect(sendMessageFeishuMock).toHaveBeenCalledWith(
808
- expect.objectContaining({
809
- to: "chat_1",
810
- text: "hello",
811
- accountId: "main",
812
- }),
813
- );
814
- expect(sendMessageFeishuMock.mock.calls[0][0].replyToMessageId).toBeUndefined();
815
- });
816
- });
817
-
818
- describe("feishuOutbound.sendMedia replyToId forwarding", () => {
819
- beforeEach(() => {
820
- resetOutboundMocks();
821
- });
822
-
823
- it("forwards replyToId to sendMediaFeishu", async () => {
824
- await feishuOutbound.sendMedia?.({
825
- cfg: emptyConfig,
826
- to: "chat_1",
827
- text: "",
828
- mediaUrl: "https://example.com/image.png",
829
- replyToId: "om_reply_target",
830
- accountId: "main",
831
- });
832
-
833
- expect(sendMediaFeishuMock).toHaveBeenCalledWith(
834
- expect.objectContaining({
835
- replyToMessageId: "om_reply_target",
836
- }),
837
- );
838
- });
839
-
840
- it("forwards audioAsVoice to sendMediaFeishu", async () => {
841
- await feishuOutbound.sendMedia?.({
842
- cfg: emptyConfig,
843
- to: "chat_1",
844
- text: "",
845
- mediaUrl: "https://example.com/reply.mp3",
846
- audioAsVoice: true,
847
- accountId: "main",
848
- });
849
-
850
- expect(sendMediaFeishuMock).toHaveBeenCalledWith(
851
- expect.objectContaining({
852
- mediaUrl: "https://example.com/reply.mp3",
853
- audioAsVoice: true,
854
- }),
855
- );
856
- });
857
-
858
- it("forwards replyToId to text caption send", async () => {
859
- await feishuOutbound.sendMedia?.({
860
- cfg: emptyConfig,
861
- to: "chat_1",
862
- text: "caption text",
863
- mediaUrl: "https://example.com/image.png",
864
- replyToId: "om_reply_target",
865
- accountId: "main",
866
- });
867
-
868
- expect(sendMessageFeishuMock).toHaveBeenCalledWith(
869
- expect.objectContaining({
870
- replyToMessageId: "om_reply_target",
871
- }),
872
- );
873
- });
874
- });
875
-
876
- describe("feishuOutbound.sendMedia renderMode", () => {
877
- beforeEach(() => {
878
- resetOutboundMocks();
879
- });
880
-
881
- it("uses markdown cards for captions when renderMode=card", async () => {
882
- const result = await feishuOutbound.sendMedia?.({
883
- cfg: cardRenderConfig,
884
- to: "chat_1",
885
- text: "| a | b |\n| - | - |",
886
- mediaUrl: "https://example.com/image.png",
887
- accountId: "main",
888
- });
889
-
890
- expect(sendMarkdownCardFeishuMock).toHaveBeenCalledWith(
891
- expect.objectContaining({
892
- to: "chat_1",
893
- text: "| a | b |\n| - | - |",
894
- accountId: "main",
895
- }),
896
- );
897
- expect(sendMediaFeishuMock).toHaveBeenCalledWith(
898
- expect.objectContaining({
899
- to: "chat_1",
900
- mediaUrl: "https://example.com/image.png",
901
- accountId: "main",
902
- }),
903
- );
904
- expect(sendMessageFeishuMock).not.toHaveBeenCalled();
905
- expect(result).toEqual(expect.objectContaining({ channel: "feishu", messageId: "media_msg" }));
906
- });
907
-
908
- it("uses threadId fallback as replyToMessageId on sendMedia", async () => {
909
- await feishuOutbound.sendMedia?.({
910
- cfg: emptyConfig,
911
- to: "chat_1",
912
- text: "caption",
913
- mediaUrl: "https://example.com/image.png",
914
- threadId: "om_thread_1",
915
- accountId: "main",
916
- });
917
-
918
- expect(sendMediaFeishuMock).toHaveBeenCalledWith(
919
- expect.objectContaining({
920
- to: "chat_1",
921
- mediaUrl: "https://example.com/image.png",
922
- replyToMessageId: "om_thread_1",
923
- accountId: "main",
924
- }),
925
- );
926
- expect(sendMessageFeishuMock).toHaveBeenCalledWith(
927
- expect.objectContaining({
928
- to: "chat_1",
929
- text: "caption",
930
- replyToMessageId: "om_thread_1",
931
- accountId: "main",
932
- }),
933
- );
934
- });
935
- });