@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
package/src/send.test.ts DELETED
@@ -1,550 +0,0 @@
1
- import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
2
- import type { ClawdbotConfig } from "../runtime-api.js";
3
- import { buildMarkdownCard } from "./send.js";
4
-
5
- const {
6
- mockConvertMarkdownTables,
7
- mockClientGet,
8
- mockClientList,
9
- mockClientPatch,
10
- mockCreateFeishuClient,
11
- mockResolveMarkdownTableMode,
12
- mockResolveFeishuAccount,
13
- mockRuntimeConvertMarkdownTables,
14
- mockRuntimeResolveMarkdownTableMode,
15
- } = vi.hoisted(() => ({
16
- mockConvertMarkdownTables: vi.fn((text: string) => text),
17
- mockClientGet: vi.fn(),
18
- mockClientList: vi.fn(),
19
- mockClientPatch: vi.fn(),
20
- mockCreateFeishuClient: vi.fn(),
21
- mockResolveMarkdownTableMode: vi.fn(() => "preserve"),
22
- mockResolveFeishuAccount: vi.fn(),
23
- mockRuntimeConvertMarkdownTables: vi.fn((text: string) => text),
24
- mockRuntimeResolveMarkdownTableMode: vi.fn(() => "preserve"),
25
- }));
26
-
27
- vi.mock("openclaw/plugin-sdk/markdown-table-runtime", () => ({
28
- resolveMarkdownTableMode: mockResolveMarkdownTableMode,
29
- }));
30
-
31
- vi.mock("openclaw/plugin-sdk/text-runtime", async (importOriginal) => {
32
- const actual = await importOriginal<typeof import("openclaw/plugin-sdk/text-runtime")>();
33
- return {
34
- ...actual,
35
- convertMarkdownTables: mockConvertMarkdownTables,
36
- };
37
- });
38
-
39
- vi.mock("./client.js", () => ({
40
- createFeishuClient: mockCreateFeishuClient,
41
- }));
42
-
43
- vi.mock("./accounts.js", () => ({
44
- resolveFeishuAccount: mockResolveFeishuAccount,
45
- resolveFeishuRuntimeAccount: mockResolveFeishuAccount,
46
- }));
47
-
48
- vi.mock("./runtime.js", () => ({
49
- getFeishuRuntime: () => ({
50
- channel: {
51
- text: {
52
- resolveMarkdownTableMode: mockRuntimeResolveMarkdownTableMode,
53
- convertMarkdownTables: mockRuntimeConvertMarkdownTables,
54
- },
55
- },
56
- }),
57
- }));
58
-
59
- let buildStructuredCard: typeof import("./send.js").buildStructuredCard;
60
- let editMessageFeishu: typeof import("./send.js").editMessageFeishu;
61
- let getMessageFeishu: typeof import("./send.js").getMessageFeishu;
62
- let listFeishuThreadMessages: typeof import("./send.js").listFeishuThreadMessages;
63
- let resolveFeishuCardTemplate: typeof import("./send.js").resolveFeishuCardTemplate;
64
- let sendMessageFeishu: typeof import("./send.js").sendMessageFeishu;
65
-
66
- describe("getMessageFeishu", () => {
67
- beforeAll(async () => {
68
- ({
69
- buildStructuredCard,
70
- editMessageFeishu,
71
- getMessageFeishu,
72
- listFeishuThreadMessages,
73
- resolveFeishuCardTemplate,
74
- sendMessageFeishu,
75
- } = await import("./send.js"));
76
- });
77
-
78
- beforeEach(() => {
79
- vi.clearAllMocks();
80
- mockResolveMarkdownTableMode.mockReturnValue("preserve");
81
- mockConvertMarkdownTables.mockImplementation((text: string) => text);
82
- mockRuntimeResolveMarkdownTableMode.mockReturnValue("preserve");
83
- mockRuntimeConvertMarkdownTables.mockImplementation((text: string) => text);
84
- mockResolveFeishuAccount.mockReturnValue({
85
- accountId: "default",
86
- configured: true,
87
- });
88
- mockCreateFeishuClient.mockReturnValue({
89
- im: {
90
- message: {
91
- create: vi.fn(),
92
- get: mockClientGet,
93
- list: mockClientList,
94
- patch: mockClientPatch,
95
- },
96
- },
97
- });
98
- });
99
-
100
- it("sends text without requiring Feishu runtime text helpers", async () => {
101
- mockRuntimeResolveMarkdownTableMode.mockImplementation(() => {
102
- throw new Error("Feishu runtime not initialized");
103
- });
104
- mockRuntimeConvertMarkdownTables.mockImplementation(() => {
105
- throw new Error("Feishu runtime not initialized");
106
- });
107
- mockClientPatch.mockResolvedValueOnce({ code: 0 });
108
- mockCreateFeishuClient.mockReturnValue({
109
- im: {
110
- message: {
111
- create: vi.fn().mockResolvedValue({ code: 0, data: { message_id: "om_send" } }),
112
- reply: vi.fn(),
113
- get: mockClientGet,
114
- list: mockClientList,
115
- patch: mockClientPatch,
116
- },
117
- },
118
- });
119
-
120
- const result = await sendMessageFeishu({
121
- cfg: {} as ClawdbotConfig,
122
- to: "oc_send",
123
- text: "hello",
124
- });
125
-
126
- expect(mockResolveMarkdownTableMode).toHaveBeenCalledWith({
127
- cfg: {},
128
- channel: "feishu",
129
- });
130
- expect(mockConvertMarkdownTables).toHaveBeenCalledWith("hello", "preserve");
131
- expect(result).toEqual({ messageId: "om_send", chatId: "oc_send" });
132
- });
133
-
134
- it("extracts text content from interactive card elements", async () => {
135
- mockClientGet.mockResolvedValueOnce({
136
- code: 0,
137
- data: {
138
- items: [
139
- {
140
- message_id: "om_1",
141
- chat_id: "oc_1",
142
- msg_type: "interactive",
143
- body: {
144
- content: JSON.stringify({
145
- elements: [
146
- { tag: "markdown", content: "hello markdown" },
147
- { tag: "div", text: { content: "hello div" } },
148
- ],
149
- }),
150
- },
151
- },
152
- ],
153
- },
154
- });
155
-
156
- const result = await getMessageFeishu({
157
- cfg: {} as ClawdbotConfig,
158
- messageId: "om_1",
159
- });
160
-
161
- expect(result).toEqual(
162
- expect.objectContaining({
163
- messageId: "om_1",
164
- chatId: "oc_1",
165
- contentType: "interactive",
166
- content: "hello markdown\nhello div",
167
- }),
168
- );
169
- });
170
-
171
- it("falls through empty interactive card element arrays and locale variants", async () => {
172
- mockClientGet.mockResolvedValueOnce({
173
- code: 0,
174
- data: {
175
- items: [
176
- {
177
- message_id: "om_i18n_card",
178
- chat_id: "oc_i18n_card",
179
- msg_type: "interactive",
180
- body: {
181
- content: JSON.stringify({
182
- elements: [],
183
- body: { elements: [] },
184
- i18n_elements: {
185
- zh_cn: [],
186
- en_us: [
187
- {
188
- tag: "markdown",
189
- content: "hello ${count} {{label}} {{metadata}}",
190
- },
191
- ],
192
- },
193
- template_variable: {
194
- count: 2,
195
- label: "tasks",
196
- metadata: { ignored: true },
197
- },
198
- }),
199
- },
200
- },
201
- ],
202
- },
203
- });
204
-
205
- const result = await getMessageFeishu({
206
- cfg: {} as ClawdbotConfig,
207
- messageId: "om_i18n_card",
208
- });
209
-
210
- expect(result).toEqual(
211
- expect.objectContaining({
212
- messageId: "om_i18n_card",
213
- chatId: "oc_i18n_card",
214
- contentType: "interactive",
215
- content: "hello 2 tasks {{metadata}}",
216
- }),
217
- );
218
- });
219
-
220
- it("falls back to post-format content when interactive card elements are empty", async () => {
221
- mockClientGet.mockResolvedValueOnce({
222
- code: 0,
223
- data: {
224
- items: [
225
- {
226
- message_id: "om_post_card",
227
- chat_id: "oc_post_card",
228
- msg_type: "interactive",
229
- body: {
230
- content: JSON.stringify({
231
- elements: [],
232
- post: {
233
- zh_cn: {
234
- title: "Card summary",
235
- content: [[{ tag: "md", text: "**fallback** body" }]],
236
- },
237
- },
238
- }),
239
- },
240
- },
241
- ],
242
- },
243
- });
244
-
245
- const result = await getMessageFeishu({
246
- cfg: {} as ClawdbotConfig,
247
- messageId: "om_post_card",
248
- });
249
-
250
- expect(result).toEqual(
251
- expect.objectContaining({
252
- messageId: "om_post_card",
253
- chatId: "oc_post_card",
254
- contentType: "interactive",
255
- content: "Card summary\n\n**fallback** body",
256
- }),
257
- );
258
- });
259
-
260
- it("extracts text content from post messages", async () => {
261
- mockClientGet.mockResolvedValueOnce({
262
- code: 0,
263
- data: {
264
- items: [
265
- {
266
- message_id: "om_post",
267
- chat_id: "oc_post",
268
- msg_type: "post",
269
- body: {
270
- content: JSON.stringify({
271
- zh_cn: {
272
- title: "Summary",
273
- content: [[{ tag: "text", text: "post body" }]],
274
- },
275
- }),
276
- },
277
- },
278
- ],
279
- },
280
- });
281
-
282
- const result = await getMessageFeishu({
283
- cfg: {} as ClawdbotConfig,
284
- messageId: "om_post",
285
- });
286
-
287
- expect(result).toEqual(
288
- expect.objectContaining({
289
- messageId: "om_post",
290
- chatId: "oc_post",
291
- contentType: "post",
292
- content: "Summary\n\npost body",
293
- }),
294
- );
295
- });
296
-
297
- it("returns text placeholder instead of raw JSON for unsupported message types", async () => {
298
- mockClientGet.mockResolvedValueOnce({
299
- code: 0,
300
- data: {
301
- items: [
302
- {
303
- message_id: "om_file",
304
- chat_id: "oc_file",
305
- msg_type: "file",
306
- body: {
307
- content: JSON.stringify({ file_key: "file_v3_123" }),
308
- },
309
- },
310
- ],
311
- },
312
- });
313
-
314
- const result = await getMessageFeishu({
315
- cfg: {} as ClawdbotConfig,
316
- messageId: "om_file",
317
- });
318
-
319
- expect(result).toEqual(
320
- expect.objectContaining({
321
- messageId: "om_file",
322
- chatId: "oc_file",
323
- contentType: "file",
324
- content: "[file message]",
325
- }),
326
- );
327
- });
328
-
329
- it("supports single-object response shape from Feishu API", async () => {
330
- mockClientGet.mockResolvedValueOnce({
331
- code: 0,
332
- data: {
333
- message_id: "om_single",
334
- chat_id: "oc_single",
335
- msg_type: "text",
336
- body: {
337
- content: JSON.stringify({ text: "single payload" }),
338
- },
339
- },
340
- });
341
-
342
- const result = await getMessageFeishu({
343
- cfg: {} as ClawdbotConfig,
344
- messageId: "om_single",
345
- });
346
-
347
- expect(result).toEqual(
348
- expect.objectContaining({
349
- messageId: "om_single",
350
- chatId: "oc_single",
351
- contentType: "text",
352
- content: "single payload",
353
- }),
354
- );
355
- });
356
-
357
- it("reuses the same content parsing for thread history messages", async () => {
358
- mockClientList.mockResolvedValueOnce({
359
- code: 0,
360
- data: {
361
- items: [
362
- {
363
- message_id: "om_root",
364
- msg_type: "text",
365
- body: {
366
- content: JSON.stringify({ text: "root starter" }),
367
- },
368
- },
369
- {
370
- message_id: "om_card",
371
- msg_type: "interactive",
372
- body: {
373
- content: JSON.stringify({
374
- body: {
375
- elements: [{ tag: "markdown", content: "hello from card 2.0" }],
376
- },
377
- }),
378
- },
379
- sender: {
380
- id: "app_1",
381
- sender_type: "app",
382
- },
383
- create_time: "1710000000000",
384
- },
385
- {
386
- message_id: "om_file",
387
- msg_type: "file",
388
- body: {
389
- content: JSON.stringify({ file_key: "file_v3_123" }),
390
- },
391
- sender: {
392
- id: "ou_1",
393
- sender_type: "user",
394
- },
395
- create_time: "1710000001000",
396
- },
397
- ],
398
- },
399
- });
400
-
401
- const result = await listFeishuThreadMessages({
402
- cfg: {} as ClawdbotConfig,
403
- threadId: "omt_1",
404
- rootMessageId: "om_root",
405
- });
406
-
407
- expect(result).toEqual([
408
- expect.objectContaining({
409
- messageId: "om_file",
410
- contentType: "file",
411
- content: "[file message]",
412
- }),
413
- expect.objectContaining({
414
- messageId: "om_card",
415
- contentType: "interactive",
416
- content: "hello from card 2.0",
417
- }),
418
- ]);
419
- });
420
- });
421
-
422
- describe("editMessageFeishu", () => {
423
- beforeEach(() => {
424
- vi.clearAllMocks();
425
- mockResolveFeishuAccount.mockReturnValue({
426
- accountId: "default",
427
- configured: true,
428
- });
429
- mockCreateFeishuClient.mockReturnValue({
430
- im: {
431
- message: {
432
- patch: mockClientPatch,
433
- },
434
- },
435
- });
436
- });
437
-
438
- it("patches post content for text edits", async () => {
439
- mockRuntimeResolveMarkdownTableMode.mockImplementation(() => {
440
- throw new Error("Feishu runtime not initialized");
441
- });
442
- mockRuntimeConvertMarkdownTables.mockImplementation(() => {
443
- throw new Error("Feishu runtime not initialized");
444
- });
445
- mockClientPatch.mockResolvedValueOnce({ code: 0 });
446
-
447
- const result = await editMessageFeishu({
448
- cfg: {} as ClawdbotConfig,
449
- messageId: "om_edit",
450
- text: "updated body",
451
- });
452
-
453
- expect(mockClientPatch).toHaveBeenCalledWith({
454
- path: { message_id: "om_edit" },
455
- data: {
456
- content: JSON.stringify({
457
- zh_cn: {
458
- content: [
459
- [
460
- {
461
- tag: "md",
462
- text: "updated body",
463
- },
464
- ],
465
- ],
466
- },
467
- }),
468
- },
469
- });
470
- expect(result).toEqual({ messageId: "om_edit", contentType: "post" });
471
- });
472
-
473
- it("patches interactive content for card edits", async () => {
474
- mockClientPatch.mockResolvedValueOnce({ code: 0 });
475
-
476
- const result = await editMessageFeishu({
477
- cfg: {} as ClawdbotConfig,
478
- messageId: "om_card",
479
- card: { schema: "2.0" },
480
- });
481
-
482
- expect(mockClientPatch).toHaveBeenCalledWith({
483
- path: { message_id: "om_card" },
484
- data: {
485
- content: JSON.stringify({ schema: "2.0" }),
486
- },
487
- });
488
- expect(result).toEqual({ messageId: "om_card", contentType: "interactive" });
489
- });
490
- });
491
-
492
- describe("resolveFeishuCardTemplate", () => {
493
- it("accepts supported Feishu templates", () => {
494
- expect(resolveFeishuCardTemplate(" purple ")).toBe("purple");
495
- });
496
-
497
- it("drops unsupported free-form identity themes", () => {
498
- expect(resolveFeishuCardTemplate("space lobster")).toBeUndefined();
499
- });
500
- });
501
-
502
- describe("buildStructuredCard", () => {
503
- it("uses schema-2.0 width config instead of legacy wide screen mode", () => {
504
- const card = buildStructuredCard("hello") as {
505
- config: {
506
- width_mode?: string;
507
- enable_forward?: boolean;
508
- wide_screen_mode?: boolean;
509
- };
510
- };
511
-
512
- expect(card.config.width_mode).toBe("fill");
513
- expect(card.config.enable_forward).toBeUndefined();
514
- expect(card.config.wide_screen_mode).toBeUndefined();
515
- });
516
-
517
- it("falls back to blue when the header template is unsupported", () => {
518
- const card = buildStructuredCard("hello", {
519
- header: {
520
- title: "Agent",
521
- template: "space lobster",
522
- },
523
- });
524
-
525
- expect(card).toEqual(
526
- expect.objectContaining({
527
- header: {
528
- title: { tag: "plain_text", content: "Agent" },
529
- template: "blue",
530
- },
531
- }),
532
- );
533
- });
534
- });
535
-
536
- describe("buildMarkdownCard", () => {
537
- it("uses schema-2.0 width config instead of legacy wide screen mode", () => {
538
- const card = buildMarkdownCard("hello") as {
539
- config: {
540
- width_mode?: string;
541
- enable_forward?: boolean;
542
- wide_screen_mode?: boolean;
543
- };
544
- };
545
-
546
- expect(card.config.width_mode).toBe("fill");
547
- expect(card.config.enable_forward).toBeUndefined();
548
- expect(card.config.wide_screen_mode).toBeUndefined();
549
- });
550
- });