@actagent/feishu 2026.6.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 (207) hide show
  1. package/README.md +11 -0
  2. package/actagent.plugin.json +224 -0
  3. package/api.ts +33 -0
  4. package/channel-entry.ts +21 -0
  5. package/channel-plugin-api.ts +2 -0
  6. package/contract-api.ts +17 -0
  7. package/index.ts +83 -0
  8. package/legacy-state-migrations-api.ts +2 -0
  9. package/npm-shrinkwrap.json +539 -0
  10. package/package.json +64 -0
  11. package/runtime-api.ts +58 -0
  12. package/runtime-setter-api.ts +3 -0
  13. package/secret-contract-api.ts +6 -0
  14. package/security-contract-api.ts +2 -0
  15. package/session-key-api.ts +2 -0
  16. package/setup-api.ts +4 -0
  17. package/setup-entry.test.ts +33 -0
  18. package/setup-entry.ts +25 -0
  19. package/skills/feishu-doc/SKILL.md +211 -0
  20. package/skills/feishu-doc/references/block-types.md +103 -0
  21. package/skills/feishu-drive/SKILL.md +97 -0
  22. package/skills/feishu-perm/SKILL.md +119 -0
  23. package/skills/feishu-wiki/SKILL.md +113 -0
  24. package/src/accounts.test.ts +481 -0
  25. package/src/accounts.ts +380 -0
  26. package/src/agent-config.ts +22 -0
  27. package/src/app-registration.test.ts +62 -0
  28. package/src/app-registration.ts +355 -0
  29. package/src/approval-auth.test.ts +25 -0
  30. package/src/approval-auth.ts +26 -0
  31. package/src/async.test.ts +68 -0
  32. package/src/async.ts +109 -0
  33. package/src/audio-preflight.runtime.ts +10 -0
  34. package/src/bitable.test.ts +174 -0
  35. package/src/bitable.ts +781 -0
  36. package/src/bot-content.ts +488 -0
  37. package/src/bot-group-name.test.ts +148 -0
  38. package/src/bot-runtime-api.ts +13 -0
  39. package/src/bot-sender-name.test.ts +68 -0
  40. package/src/bot-sender-name.ts +137 -0
  41. package/src/bot.broadcast.test.ts +643 -0
  42. package/src/bot.card-action.test.ts +647 -0
  43. package/src/bot.checkBotMentioned.test.ts +266 -0
  44. package/src/bot.helpers.test.ts +136 -0
  45. package/src/bot.stripBotMention.test.ts +127 -0
  46. package/src/bot.test.ts +3817 -0
  47. package/src/bot.ts +1788 -0
  48. package/src/card-action.ts +515 -0
  49. package/src/card-interaction.test.ts +132 -0
  50. package/src/card-interaction.ts +160 -0
  51. package/src/card-test-helpers.ts +55 -0
  52. package/src/card-ux-approval.ts +66 -0
  53. package/src/card-ux-launcher.test.ts +126 -0
  54. package/src/card-ux-launcher.ts +136 -0
  55. package/src/card-ux-shared.ts +34 -0
  56. package/src/channel-runtime-api.ts +17 -0
  57. package/src/channel.runtime.ts +48 -0
  58. package/src/channel.test.ts +1337 -0
  59. package/src/channel.ts +1401 -0
  60. package/src/chat-schema.ts +30 -0
  61. package/src/chat.test.ts +295 -0
  62. package/src/chat.ts +198 -0
  63. package/src/client-timeout.ts +44 -0
  64. package/src/client.test.ts +463 -0
  65. package/src/client.ts +263 -0
  66. package/src/comment-dispatcher-runtime-api.ts +7 -0
  67. package/src/comment-dispatcher.test.ts +186 -0
  68. package/src/comment-dispatcher.ts +108 -0
  69. package/src/comment-handler-runtime-api.ts +4 -0
  70. package/src/comment-handler.test.ts +588 -0
  71. package/src/comment-handler.ts +304 -0
  72. package/src/comment-reaction.test.ts +139 -0
  73. package/src/comment-reaction.ts +260 -0
  74. package/src/comment-shared.test.ts +184 -0
  75. package/src/comment-shared.ts +405 -0
  76. package/src/comment-target.ts +45 -0
  77. package/src/config-schema.test.ts +327 -0
  78. package/src/config-schema.ts +338 -0
  79. package/src/conversation-id.test.ts +19 -0
  80. package/src/conversation-id.ts +199 -0
  81. package/src/dedup-migrations.test.ts +90 -0
  82. package/src/dedup-migrations.ts +103 -0
  83. package/src/dedup.test.ts +95 -0
  84. package/src/dedup.ts +304 -0
  85. package/src/dedupe-key.ts +68 -0
  86. package/src/directory.static.ts +62 -0
  87. package/src/directory.test.ts +142 -0
  88. package/src/directory.ts +125 -0
  89. package/src/doc-schema.ts +183 -0
  90. package/src/doctor.test.ts +382 -0
  91. package/src/doctor.ts +876 -0
  92. package/src/docx-batch-insert.test.ts +117 -0
  93. package/src/docx-batch-insert.ts +223 -0
  94. package/src/docx-color-text.ts +154 -0
  95. package/src/docx-table-ops.test.ts +54 -0
  96. package/src/docx-table-ops.ts +316 -0
  97. package/src/docx-types.ts +39 -0
  98. package/src/docx.account-selection.test.ts +96 -0
  99. package/src/docx.test.ts +706 -0
  100. package/src/docx.ts +1598 -0
  101. package/src/drive-schema.ts +93 -0
  102. package/src/drive.test.ts +1240 -0
  103. package/src/drive.ts +830 -0
  104. package/src/dynamic-agent.test.ts +156 -0
  105. package/src/dynamic-agent.ts +144 -0
  106. package/src/event-types.ts +46 -0
  107. package/src/external-keys.test.ts +21 -0
  108. package/src/external-keys.ts +20 -0
  109. package/src/lifecycle.test-support.ts +223 -0
  110. package/src/media.test.ts +956 -0
  111. package/src/media.ts +1106 -0
  112. package/src/mention-target.types.ts +6 -0
  113. package/src/mention.ts +115 -0
  114. package/src/message-action-contract.ts +14 -0
  115. package/src/monitor-state-runtime-api.ts +8 -0
  116. package/src/monitor-transport-runtime-api.ts +11 -0
  117. package/src/monitor.account.ts +501 -0
  118. package/src/monitor.acp-init-failure.lifecycle.test-support.ts +215 -0
  119. package/src/monitor.bot-identity.ts +87 -0
  120. package/src/monitor.bot-menu-handler.ts +164 -0
  121. package/src/monitor.bot-menu.lifecycle.test-support.ts +221 -0
  122. package/src/monitor.bot-menu.test.ts +200 -0
  123. package/src/monitor.broadcast.reply-once.lifecycle.test-support.ts +265 -0
  124. package/src/monitor.card-action.lifecycle.test-support.ts +418 -0
  125. package/src/monitor.cleanup.test.ts +384 -0
  126. package/src/monitor.comment-notice-handler.ts +106 -0
  127. package/src/monitor.comment.test.ts +968 -0
  128. package/src/monitor.comment.ts +1386 -0
  129. package/src/monitor.lifecycle.test.ts +5 -0
  130. package/src/monitor.message-handler.ts +346 -0
  131. package/src/monitor.reaction.test.ts +770 -0
  132. package/src/monitor.startup.test.ts +232 -0
  133. package/src/monitor.startup.ts +76 -0
  134. package/src/monitor.state.defaults.test.ts +47 -0
  135. package/src/monitor.state.ts +171 -0
  136. package/src/monitor.synthetic-error.ts +19 -0
  137. package/src/monitor.test-mocks.ts +47 -0
  138. package/src/monitor.transport.ts +451 -0
  139. package/src/monitor.ts +104 -0
  140. package/src/monitor.webhook-e2e.test.ts +284 -0
  141. package/src/monitor.webhook-security.test.ts +394 -0
  142. package/src/monitor.webhook.test-helpers.ts +138 -0
  143. package/src/outbound-runtime-api.ts +2 -0
  144. package/src/outbound.test.ts +1255 -0
  145. package/src/outbound.ts +742 -0
  146. package/src/perm-schema.ts +53 -0
  147. package/src/perm.ts +171 -0
  148. package/src/pins.ts +109 -0
  149. package/src/policy.test.ts +224 -0
  150. package/src/policy.ts +322 -0
  151. package/src/post.test.ts +106 -0
  152. package/src/post.ts +276 -0
  153. package/src/presentation-card.ts +204 -0
  154. package/src/probe.test.ts +310 -0
  155. package/src/probe.ts +181 -0
  156. package/src/processing-claims.ts +60 -0
  157. package/src/qr-terminal.ts +2 -0
  158. package/src/reactions.ts +124 -0
  159. package/src/reasoning-preview.test.ts +114 -0
  160. package/src/reasoning-preview.ts +29 -0
  161. package/src/reply-dispatcher-runtime-api.ts +8 -0
  162. package/src/reply-dispatcher.test.ts +2009 -0
  163. package/src/reply-dispatcher.ts +865 -0
  164. package/src/runtime.ts +10 -0
  165. package/src/secret-contract.ts +146 -0
  166. package/src/secret-input.ts +2 -0
  167. package/src/security-audit-shared.ts +70 -0
  168. package/src/security-audit.test.ts +60 -0
  169. package/src/security-audit.ts +2 -0
  170. package/src/send-result.ts +81 -0
  171. package/src/send-target.test.ts +87 -0
  172. package/src/send-target.ts +36 -0
  173. package/src/send.reply-fallback.test.ts +418 -0
  174. package/src/send.test.ts +661 -0
  175. package/src/send.ts +860 -0
  176. package/src/sequential-key.test.ts +73 -0
  177. package/src/sequential-key.ts +29 -0
  178. package/src/sequential-queue.test.ts +184 -0
  179. package/src/sequential-queue.ts +90 -0
  180. package/src/session-conversation.ts +42 -0
  181. package/src/session-route.ts +49 -0
  182. package/src/setup-core.ts +52 -0
  183. package/src/setup-surface.test.ts +485 -0
  184. package/src/setup-surface.ts +620 -0
  185. package/src/streaming-card.test.ts +549 -0
  186. package/src/streaming-card.ts +611 -0
  187. package/src/subagent-hooks.test.ts +632 -0
  188. package/src/subagent-hooks.ts +414 -0
  189. package/src/targets.ts +98 -0
  190. package/src/test-support/lifecycle-test-support.ts +459 -0
  191. package/src/thread-bindings.test.ts +181 -0
  192. package/src/thread-bindings.ts +332 -0
  193. package/src/tool-account-routing.test.ts +419 -0
  194. package/src/tool-account.test.ts +45 -0
  195. package/src/tool-account.ts +98 -0
  196. package/src/tool-factory-test-harness.ts +83 -0
  197. package/src/tool-result.test.ts +33 -0
  198. package/src/tool-result.ts +17 -0
  199. package/src/tools-config.test.ts +52 -0
  200. package/src/tools-config.ts +29 -0
  201. package/src/types.ts +111 -0
  202. package/src/typing.test.ts +145 -0
  203. package/src/typing.ts +215 -0
  204. package/src/wiki-schema.ts +70 -0
  205. package/src/wiki.ts +271 -0
  206. package/subagent-hooks-api.ts +22 -0
  207. package/tsconfig.json +16 -0
@@ -0,0 +1,419 @@
1
+ // Feishu tests cover tool account routing plugin behavior.
2
+ import { afterAll, beforeAll, beforeEach, describe, expect, test, vi } from "vitest";
3
+ import type { ACTAgentPluginApi } from "../runtime-api.js";
4
+ import { createToolFactoryHarness } from "./tool-factory-test-harness.js";
5
+
6
+ const createFeishuClientMock = vi.fn((account: { appId?: string } | undefined) => ({
7
+ __appId: account?.appId,
8
+ wiki: {
9
+ spaceNode: {
10
+ list: vi.fn(async () => ({
11
+ code: 0,
12
+ data: { items: [] },
13
+ })),
14
+ },
15
+ },
16
+ }));
17
+
18
+ vi.mock("./client.js", () => ({
19
+ createFeishuClient: (account: { appId?: string } | undefined) => createFeishuClientMock(account),
20
+ }));
21
+
22
+ let registerFeishuBitableTools: typeof import("./bitable.js").registerFeishuBitableTools;
23
+ let registerFeishuDriveTools: typeof import("./drive.js").registerFeishuDriveTools;
24
+ let registerFeishuPermTools: typeof import("./perm.js").registerFeishuPermTools;
25
+ let registerFeishuWikiTools: typeof import("./wiki.js").registerFeishuWikiTools;
26
+
27
+ function createConfig(params: {
28
+ topTools?: {
29
+ wiki?: boolean;
30
+ drive?: boolean;
31
+ perm?: boolean;
32
+ bitable?: boolean;
33
+ base?: boolean;
34
+ };
35
+ toolsA?: {
36
+ wiki?: boolean;
37
+ drive?: boolean;
38
+ perm?: boolean;
39
+ bitable?: boolean;
40
+ base?: boolean;
41
+ };
42
+ toolsB?: {
43
+ wiki?: boolean;
44
+ drive?: boolean;
45
+ perm?: boolean;
46
+ bitable?: boolean;
47
+ base?: boolean;
48
+ };
49
+ defaultAccount?: string;
50
+ }): ACTAgentPluginApi["config"] {
51
+ return {
52
+ channels: {
53
+ feishu: {
54
+ enabled: true,
55
+ defaultAccount: params.defaultAccount,
56
+ tools: params.topTools,
57
+ accounts: {
58
+ a: {
59
+ appId: "app-a",
60
+ appSecret: "sec-a", // pragma: allowlist secret
61
+ tools: params.toolsA,
62
+ },
63
+ b: {
64
+ appId: "app-b",
65
+ appSecret: "sec-b", // pragma: allowlist secret
66
+ tools: params.toolsB,
67
+ },
68
+ },
69
+ },
70
+ },
71
+ } as ACTAgentPluginApi["config"];
72
+ }
73
+
74
+ function clientAppIdAt(index: number): string | undefined {
75
+ const calls = createFeishuClientMock.mock.calls;
76
+ const resolvedIndex = index < 0 ? calls.length + index : index;
77
+ return calls[resolvedIndex]?.[0]?.appId;
78
+ }
79
+
80
+ function lastClientAppId(): string | undefined {
81
+ return clientAppIdAt(-1);
82
+ }
83
+
84
+ describe("feishu tool account routing", () => {
85
+ beforeAll(async () => {
86
+ ({ registerFeishuBitableTools, registerFeishuDriveTools, registerFeishuPermTools } =
87
+ await import("./bitable.js").then(
88
+ async ({ registerFeishuBitableTools: registerFeishuBitableToolsLocal }) => ({
89
+ registerFeishuBitableTools: registerFeishuBitableToolsLocal,
90
+ ...(await import("./drive.js")),
91
+ ...(await import("./perm.js")),
92
+ ...(await import("./wiki.js")),
93
+ }),
94
+ ));
95
+ ({ registerFeishuWikiTools } = await import("./wiki.js"));
96
+ });
97
+
98
+ afterAll(() => {
99
+ vi.doUnmock("./client.js");
100
+ vi.resetModules();
101
+ });
102
+
103
+ beforeEach(() => {
104
+ vi.clearAllMocks();
105
+ });
106
+
107
+ test("wiki tool registers when first account disables it and routes to agentAccountId", async () => {
108
+ const { api, resolveTool } = createToolFactoryHarness(
109
+ createConfig({
110
+ toolsA: { wiki: false },
111
+ toolsB: { wiki: true },
112
+ }),
113
+ );
114
+ registerFeishuWikiTools(api);
115
+
116
+ const tool = resolveTool("feishu_wiki", { agentAccountId: "b" });
117
+ await tool.execute("call", { action: "search" });
118
+
119
+ expect(lastClientAppId()).toBe("app-b");
120
+ });
121
+
122
+ test("wiki tool prefers the active contextual account over configured defaultAccount", async () => {
123
+ const { api, resolveTool } = createToolFactoryHarness(
124
+ createConfig({
125
+ defaultAccount: "b",
126
+ toolsA: { wiki: true },
127
+ toolsB: { wiki: true },
128
+ }),
129
+ );
130
+ registerFeishuWikiTools(api);
131
+
132
+ const tool = resolveTool("feishu_wiki", { agentAccountId: "a" });
133
+ await tool.execute("call", { action: "search" });
134
+
135
+ expect(lastClientAppId()).toBe("app-a");
136
+ });
137
+
138
+ test("wiki tool rejects number-typed space IDs before Lark receives precision-corrupted values", async () => {
139
+ const { api, resolveTool } = createToolFactoryHarness(
140
+ createConfig({
141
+ toolsA: { wiki: true },
142
+ }),
143
+ );
144
+ registerFeishuWikiTools(api);
145
+
146
+ const tool = resolveTool("feishu_wiki", { agentAccountId: "a" });
147
+ const result = await tool.execute("call", {
148
+ action: "nodes",
149
+ space_id: 7616123456789015000,
150
+ });
151
+
152
+ expect(createFeishuClientMock).not.toHaveBeenCalled();
153
+ expect(result.details.error).toContain("space_id must be a string");
154
+ expect(result.details.error).toContain("precision loss");
155
+ });
156
+
157
+ test("wiki tool forwards quoted numeric-looking space IDs unchanged", async () => {
158
+ const { api, resolveTool } = createToolFactoryHarness(
159
+ createConfig({
160
+ toolsA: { wiki: true },
161
+ }),
162
+ );
163
+ registerFeishuWikiTools(api);
164
+
165
+ const tool = resolveTool("feishu_wiki", { agentAccountId: "a" });
166
+ await tool.execute("call", {
167
+ action: "nodes",
168
+ space_id: "7616123456789014828",
169
+ });
170
+
171
+ const client = createFeishuClientMock.mock.results[0]?.value;
172
+ expect(client.wiki.spaceNode.list).toHaveBeenCalledWith({
173
+ path: { space_id: "7616123456789014828" },
174
+ params: { parent_node_token: undefined },
175
+ });
176
+ });
177
+
178
+ test("drive tool registers when first account disables it and routes to agentAccountId", async () => {
179
+ const { api, resolveTool } = createToolFactoryHarness(
180
+ createConfig({
181
+ toolsA: { drive: false },
182
+ toolsB: { drive: true },
183
+ }),
184
+ );
185
+ registerFeishuDriveTools(api);
186
+
187
+ const tool = resolveTool("feishu_drive", { agentAccountId: "b" });
188
+ await tool.execute("call", { action: "unknown_action" });
189
+
190
+ expect(lastClientAppId()).toBe("app-b");
191
+ });
192
+
193
+ test("perm tool registers when only second account enables it and routes to agentAccountId", async () => {
194
+ const { api, resolveTool } = createToolFactoryHarness(
195
+ createConfig({
196
+ toolsA: { perm: false },
197
+ toolsB: { perm: true },
198
+ }),
199
+ );
200
+ registerFeishuPermTools(api);
201
+
202
+ const tool = resolveTool("feishu_perm", { agentAccountId: "b" });
203
+ await tool.execute("call", { action: "unknown_action" });
204
+
205
+ expect(lastClientAppId()).toBe("app-b");
206
+ });
207
+
208
+ test("bitable tool registers when only second account enables it and routes to agentAccountId", async () => {
209
+ const { api, resolveTool } = createToolFactoryHarness(
210
+ createConfig({
211
+ toolsA: { bitable: false },
212
+ toolsB: { bitable: true },
213
+ }),
214
+ );
215
+ registerFeishuBitableTools(api);
216
+
217
+ const tool = resolveTool("feishu_bitable_get_meta", { agentAccountId: "b" });
218
+ await tool.execute("call", { url: "invalid-url" });
219
+
220
+ expect(createFeishuClientMock.mock.calls.at(-1)?.[0]?.appId).toBe("app-b");
221
+ });
222
+
223
+ test("bitable tool rejects a disabled contextual account when another account enables it", async () => {
224
+ const { api, resolveTool } = createToolFactoryHarness(
225
+ createConfig({
226
+ toolsA: { bitable: false },
227
+ toolsB: { bitable: true },
228
+ }),
229
+ );
230
+ registerFeishuBitableTools(api);
231
+
232
+ const tool = resolveTool("feishu_bitable_get_meta", { agentAccountId: "a" });
233
+ const result = await tool.execute("call", { url: "invalid-url" });
234
+
235
+ expect(createFeishuClientMock).not.toHaveBeenCalled();
236
+ expect(result.details.error).toBe('Feishu Bitable tools are disabled for account "a"');
237
+ });
238
+
239
+ test("bitable tool rejects an explicit disabled account override", async () => {
240
+ const { api, resolveTool } = createToolFactoryHarness(
241
+ createConfig({
242
+ toolsA: { bitable: false },
243
+ toolsB: { bitable: true },
244
+ }),
245
+ );
246
+ registerFeishuBitableTools(api);
247
+
248
+ const tool = resolveTool("feishu_bitable_get_meta", { agentAccountId: "b" });
249
+ const result = await tool.execute("call", { url: "invalid-url", accountId: "a" });
250
+
251
+ expect(createFeishuClientMock).not.toHaveBeenCalled();
252
+ expect(result.details.error).toBe('Feishu Bitable tools are disabled for account "a"');
253
+ });
254
+
255
+ test("bitable tool routes to agentAccountId and allows explicit accountId override", async () => {
256
+ const { api, resolveTool } = createToolFactoryHarness(createConfig({}));
257
+ registerFeishuBitableTools(api);
258
+
259
+ const tool = resolveTool("feishu_bitable_get_meta", { agentAccountId: "b" });
260
+ await tool.execute("call-ctx", { url: "invalid-url" });
261
+ await tool.execute("call-override", { url: "invalid-url", accountId: "a" });
262
+
263
+ expect(clientAppIdAt(0)).toBe("app-b");
264
+ expect(clientAppIdAt(1)).toBe("app-a");
265
+ });
266
+
267
+ test("bitable tools are not registered when top-level bitable config disables them", async () => {
268
+ const { api, registered, resolveTool } = createToolFactoryHarness(
269
+ createConfig({
270
+ topTools: { bitable: false },
271
+ }),
272
+ );
273
+ registerFeishuBitableTools(api);
274
+
275
+ expect(
276
+ registered.filter((entry) => entry.opts?.name?.startsWith("feishu_bitable_")).length,
277
+ ).toBe(0);
278
+ expect(() => resolveTool("feishu_bitable_get_meta")).toThrow("Tool not registered");
279
+ });
280
+
281
+ test("top-level bitable disable wins over account-level bitable enable", async () => {
282
+ const { api, registered, resolveTool } = createToolFactoryHarness(
283
+ createConfig({
284
+ topTools: { bitable: false },
285
+ toolsA: { bitable: true },
286
+ toolsB: { bitable: true },
287
+ }),
288
+ );
289
+ registerFeishuBitableTools(api);
290
+
291
+ expect(
292
+ registered.filter((entry) => entry.opts?.name?.startsWith("feishu_bitable_")).length,
293
+ ).toBe(0);
294
+ expect(() => resolveTool("feishu_bitable_get_meta")).toThrow("Tool not registered");
295
+ });
296
+
297
+ test("top-level base alias disable wins over account-level bitable enable", async () => {
298
+ const { api, registered } = createToolFactoryHarness(
299
+ createConfig({
300
+ topTools: { base: false },
301
+ toolsA: { bitable: true },
302
+ toolsB: { bitable: true },
303
+ }),
304
+ );
305
+ registerFeishuBitableTools(api);
306
+
307
+ expect(
308
+ registered.filter((entry) => entry.opts?.name?.startsWith("feishu_bitable_")).length,
309
+ ).toBe(0);
310
+ });
311
+
312
+ test("explicit top-level bitable enable wins over disabled base alias in account merge", async () => {
313
+ const { api, resolveTool } = createToolFactoryHarness(
314
+ createConfig({
315
+ topTools: { bitable: true, base: false },
316
+ toolsA: { bitable: true },
317
+ }),
318
+ );
319
+ registerFeishuBitableTools(api);
320
+
321
+ const tool = resolveTool("feishu_bitable_get_meta", { agentAccountId: "a" });
322
+ await tool.execute("call", { url: "invalid-url" });
323
+
324
+ expect(createFeishuClientMock.mock.calls.at(-1)?.[0]?.appId).toBe("app-a");
325
+ });
326
+
327
+ test("account base alias disable wins over inherited top-level bitable enable", async () => {
328
+ const { api, resolveTool } = createToolFactoryHarness(
329
+ createConfig({
330
+ topTools: { bitable: true },
331
+ toolsA: { base: false },
332
+ toolsB: { bitable: true },
333
+ }),
334
+ );
335
+ registerFeishuBitableTools(api);
336
+
337
+ const tool = resolveTool("feishu_bitable_get_meta", { agentAccountId: "a" });
338
+ const result = await tool.execute("call", { url: "invalid-url" });
339
+
340
+ expect(createFeishuClientMock).not.toHaveBeenCalled();
341
+ expect(result.details.error).toBe('Feishu Bitable tools are disabled for account "a"');
342
+ });
343
+
344
+ test("bitable tools are not registered when account bitable configs disable them", async () => {
345
+ const { api, registered, resolveTool } = createToolFactoryHarness(
346
+ createConfig({
347
+ toolsA: { bitable: false },
348
+ toolsB: { bitable: false },
349
+ }),
350
+ );
351
+ registerFeishuBitableTools(api);
352
+
353
+ expect(
354
+ registered.filter((entry) => entry.opts?.name?.startsWith("feishu_bitable_")).length,
355
+ ).toBe(0);
356
+ expect(() => resolveTool("feishu_bitable_get_meta")).toThrow("Tool not registered");
357
+ });
358
+
359
+ test("base alias disables bitable tool registration", async () => {
360
+ const { api, registered } = createToolFactoryHarness(
361
+ createConfig({
362
+ topTools: { base: false },
363
+ toolsA: { base: false },
364
+ toolsB: { base: false },
365
+ }),
366
+ );
367
+ registerFeishuBitableTools(api);
368
+
369
+ expect(
370
+ registered.filter((entry) => entry.opts?.name?.startsWith("feishu_bitable_")).length,
371
+ ).toBe(0);
372
+ });
373
+
374
+ test("falls back to the configured Feishu default selection when agentAccountId is not a real account", async () => {
375
+ const { api, resolveTool } = createToolFactoryHarness(
376
+ createConfig({
377
+ toolsA: { wiki: true },
378
+ toolsB: { wiki: true },
379
+ }),
380
+ );
381
+ registerFeishuWikiTools(api);
382
+
383
+ const tool = resolveTool("feishu_wiki", { agentAccountId: "agent-spawner" });
384
+ await tool.execute("call", { action: "search" });
385
+
386
+ expect(lastClientAppId()).toBe("app-a");
387
+ });
388
+
389
+ test("does not silently fall back when the contextual account is real but uses non-env SecretRefs", async () => {
390
+ const { api, resolveTool } = createToolFactoryHarness({
391
+ channels: {
392
+ feishu: {
393
+ enabled: true,
394
+ accounts: {
395
+ a: {
396
+ appId: "app-a",
397
+ appSecret: "sec-a", // pragma: allowlist secret
398
+ tools: { wiki: true },
399
+ },
400
+ b: {
401
+ appId: "app-b",
402
+ appSecret: { source: "file", provider: "default", id: "feishu/b-secret" },
403
+ tools: { wiki: true },
404
+ } as never,
405
+ },
406
+ },
407
+ },
408
+ } as ACTAgentPluginApi["config"]);
409
+ registerFeishuWikiTools(api);
410
+
411
+ const tool = resolveTool("feishu_wiki", { agentAccountId: "b" });
412
+ const result = await tool.execute("call", { action: "search" });
413
+
414
+ expect(createFeishuClientMock).not.toHaveBeenCalled();
415
+ expect(typeof result.details.error === "string" ? result.details.error : "").toContain(
416
+ "Resolve this command against an active gateway runtime snapshot before reading it.",
417
+ );
418
+ });
419
+ });
@@ -0,0 +1,45 @@
1
+ // Feishu tests cover tool account plugin behavior.
2
+ import { describe, expect, it } from "vitest";
3
+ import { resolveFeishuToolAccount } from "./tool-account.js";
4
+
5
+ describe("resolveFeishuToolAccount", () => {
6
+ const cfg = {
7
+ channels: {
8
+ feishu: {
9
+ enabled: true,
10
+ defaultAccount: "ops",
11
+ appId: "base-app-id",
12
+ appSecret: "base-app-secret", // pragma: allowlist secret
13
+ accounts: {
14
+ ops: {
15
+ enabled: true,
16
+ appId: "ops-app-id",
17
+ appSecret: "ops-app-secret", // pragma: allowlist secret
18
+ },
19
+ work: {
20
+ enabled: true,
21
+ appId: "work-app-id",
22
+ appSecret: "work-app-secret", // pragma: allowlist secret
23
+ },
24
+ },
25
+ },
26
+ },
27
+ };
28
+
29
+ it("prefers the active contextual account over configured defaultAccount", () => {
30
+ const resolved = resolveFeishuToolAccount({
31
+ api: { config: cfg },
32
+ defaultAccountId: "work",
33
+ });
34
+
35
+ expect(resolved.accountId).toBe("work");
36
+ });
37
+
38
+ it("falls back to configured defaultAccount when there is no contextual account", () => {
39
+ const resolved = resolveFeishuToolAccount({
40
+ api: { config: cfg },
41
+ });
42
+
43
+ expect(resolved.accountId).toBe("ops");
44
+ });
45
+ });
@@ -0,0 +1,98 @@
1
+ // Feishu plugin module implements tool account behavior.
2
+ import type * as Lark from "@larksuiteoapi/node-sdk";
3
+ import { normalizeOptionalString } from "actagent/plugin-sdk/string-coerce-runtime";
4
+ import type { ACTAgentPluginApi } from "../runtime-api.js";
5
+ import {
6
+ listFeishuAccountIds,
7
+ resolveFeishuAccount,
8
+ resolveFeishuRuntimeAccount,
9
+ } from "./accounts.js";
10
+ import { createFeishuClient } from "./client.js";
11
+ import { resolveToolsConfig } from "./tools-config.js";
12
+ import type { FeishuToolsConfig, ResolvedFeishuAccount } from "./types.js";
13
+
14
+ type AccountAwareParams = { accountId?: string };
15
+
16
+ function resolveImplicitToolAccountId(params: {
17
+ api: Pick<ACTAgentPluginApi, "config">;
18
+ executeParams?: AccountAwareParams;
19
+ defaultAccountId?: string;
20
+ }): string | undefined {
21
+ const explicitAccountId = normalizeOptionalString(params.executeParams?.accountId);
22
+ if (explicitAccountId) {
23
+ return explicitAccountId;
24
+ }
25
+
26
+ const contextualAccountId = normalizeOptionalString(params.defaultAccountId);
27
+ if (
28
+ contextualAccountId &&
29
+ listFeishuAccountIds(params.api.config).includes(contextualAccountId)
30
+ ) {
31
+ const contextualAccount = resolveFeishuAccount({
32
+ cfg: params.api.config,
33
+ accountId: contextualAccountId,
34
+ });
35
+ if (contextualAccount.enabled) {
36
+ return contextualAccountId;
37
+ }
38
+ }
39
+
40
+ const configuredDefaultAccountId = normalizeOptionalString(
41
+ (params.api.config?.channels?.feishu as { defaultAccount?: unknown } | undefined)
42
+ ?.defaultAccount,
43
+ );
44
+ if (configuredDefaultAccountId) {
45
+ return configuredDefaultAccountId;
46
+ }
47
+
48
+ return undefined;
49
+ }
50
+
51
+ export function resolveFeishuToolAccount(params: {
52
+ api: Pick<ACTAgentPluginApi, "config">;
53
+ executeParams?: AccountAwareParams;
54
+ defaultAccountId?: string;
55
+ }): ResolvedFeishuAccount {
56
+ if (!params.api.config) {
57
+ throw new Error("Feishu config unavailable");
58
+ }
59
+ return resolveFeishuRuntimeAccount({
60
+ cfg: params.api.config,
61
+ accountId: resolveImplicitToolAccountId(params),
62
+ });
63
+ }
64
+
65
+ export function createFeishuToolClient(params: {
66
+ api: Pick<ACTAgentPluginApi, "config">;
67
+ executeParams?: AccountAwareParams;
68
+ defaultAccountId?: string;
69
+ }): Lark.Client {
70
+ return createFeishuClient(resolveFeishuToolAccount(params));
71
+ }
72
+
73
+ export function resolveAnyEnabledFeishuToolsConfig(
74
+ accounts: ResolvedFeishuAccount[],
75
+ ): Required<FeishuToolsConfig> {
76
+ const merged: Required<FeishuToolsConfig> = {
77
+ doc: false,
78
+ chat: false,
79
+ wiki: false,
80
+ drive: false,
81
+ perm: false,
82
+ scopes: false,
83
+ bitable: false,
84
+ base: false,
85
+ };
86
+ for (const account of accounts) {
87
+ const cfg = resolveToolsConfig(account.config.tools);
88
+ merged.doc = merged.doc || cfg.doc;
89
+ merged.chat = merged.chat || cfg.chat;
90
+ merged.wiki = merged.wiki || cfg.wiki;
91
+ merged.drive = merged.drive || cfg.drive;
92
+ merged.perm = merged.perm || cfg.perm;
93
+ merged.scopes = merged.scopes || cfg.scopes;
94
+ merged.bitable = merged.bitable || cfg.bitable;
95
+ merged.base = merged.base || cfg.base;
96
+ }
97
+ return merged;
98
+ }
@@ -0,0 +1,83 @@
1
+ // Feishu plugin module implements tool factory test harness behavior.
2
+ import type { ACTAgentPluginApi } from "../runtime-api.js";
3
+
4
+ type ToolContextLike = {
5
+ agentAccountId?: string;
6
+ };
7
+
8
+ export type ToolLike = {
9
+ name: string;
10
+ parameters?: unknown;
11
+ execute: (
12
+ toolCallId: string,
13
+ params: unknown,
14
+ ) => Promise<{ details: Record<string, unknown> }> | { details: Record<string, unknown> };
15
+ };
16
+
17
+ type RegisteredTool = {
18
+ tool: unknown;
19
+ opts?: { name?: string };
20
+ };
21
+
22
+ function toToolList(value: unknown): unknown[] {
23
+ if (!value) {
24
+ return [];
25
+ }
26
+ return Array.isArray(value) ? value : [value];
27
+ }
28
+
29
+ function asToolLike(tool: unknown, fallbackName?: string): ToolLike {
30
+ const candidate = tool as Partial<ToolLike>;
31
+ const name = candidate.name ?? fallbackName;
32
+ const execute = candidate.execute;
33
+ if (!name || typeof execute !== "function") {
34
+ throw new Error(`Resolved tool is missing required fields (name=${String(name)})`);
35
+ }
36
+ return {
37
+ name,
38
+ parameters: candidate.parameters,
39
+ execute: (toolCallId, params) => execute(toolCallId, params),
40
+ };
41
+ }
42
+
43
+ export function createToolFactoryHarness(cfg: ACTAgentPluginApi["config"]) {
44
+ const registered: RegisteredTool[] = [];
45
+
46
+ const api: Pick<ACTAgentPluginApi, "config" | "logger" | "registerTool"> = {
47
+ config: cfg,
48
+ logger: {
49
+ info: () => {},
50
+ warn: () => {},
51
+ error: () => {},
52
+ debug: () => {},
53
+ },
54
+ registerTool: (tool, opts) => {
55
+ registered.push({ tool, opts });
56
+ },
57
+ };
58
+
59
+ const resolveTool = (name: string, ctx: ToolContextLike = {}): ToolLike => {
60
+ for (const entry of registered) {
61
+ if (entry.opts?.name === name && typeof entry.tool !== "function") {
62
+ return asToolLike(entry.tool, name);
63
+ }
64
+
65
+ if (typeof entry.tool === "function") {
66
+ const builtTools = toToolList(entry.tool(ctx));
67
+ const hit = builtTools.find((tool) => (tool as { name?: string }).name === name);
68
+ if (hit) {
69
+ return asToolLike(hit, name);
70
+ }
71
+ } else if ((entry.tool as { name?: string }).name === name) {
72
+ return asToolLike(entry.tool, name);
73
+ }
74
+ }
75
+ throw new Error(`Tool not registered: ${name}`);
76
+ };
77
+
78
+ return {
79
+ api: api as ACTAgentPluginApi,
80
+ resolveTool,
81
+ registered,
82
+ };
83
+ }
@@ -0,0 +1,33 @@
1
+ // Feishu tests cover tool result plugin behavior.
2
+ import { describe, expect, it } from "vitest";
3
+ import {
4
+ jsonToolResult,
5
+ toolExecutionErrorResult,
6
+ unknownToolActionResult,
7
+ } from "./tool-result.js";
8
+
9
+ describe("jsonToolResult", () => {
10
+ it("formats tool result with text content and details", () => {
11
+ const payload = { ok: true, id: "abc" };
12
+ expect(jsonToolResult(payload)).toEqual({
13
+ content: [{ type: "text", text: JSON.stringify(payload, null, 2) }],
14
+ details: payload,
15
+ });
16
+ });
17
+
18
+ it("formats unknown action errors", () => {
19
+ expect(unknownToolActionResult("create")).toEqual({
20
+ content: [
21
+ { type: "text", text: JSON.stringify({ error: "Unknown action: create" }, null, 2) },
22
+ ],
23
+ details: { error: "Unknown action: create" },
24
+ });
25
+ });
26
+
27
+ it("formats execution errors", () => {
28
+ expect(toolExecutionErrorResult(new Error("boom"))).toEqual({
29
+ content: [{ type: "text", text: JSON.stringify({ error: "boom" }, null, 2) }],
30
+ details: { error: "boom" },
31
+ });
32
+ });
33
+ });
@@ -0,0 +1,17 @@
1
+ // Feishu plugin module implements tool result behavior.
2
+ import { formatErrorMessage } from "actagent/plugin-sdk/error-runtime";
3
+
4
+ export function jsonToolResult(data: unknown) {
5
+ return {
6
+ content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }],
7
+ details: data,
8
+ };
9
+ }
10
+
11
+ export function unknownToolActionResult(action: unknown) {
12
+ return jsonToolResult({ error: `Unknown action: ${String(action)}` });
13
+ }
14
+
15
+ export function toolExecutionErrorResult(error: unknown) {
16
+ return jsonToolResult({ error: formatErrorMessage(error) });
17
+ }