@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,327 @@
1
+ // Feishu tests cover config schema plugin behavior.
2
+ import { describe, expect, it } from "vitest";
3
+ import { FeishuConfigSchema, FeishuGroupSchema } from "./config-schema.js";
4
+
5
+ function expectSchemaIssue(
6
+ result: ReturnType<typeof FeishuConfigSchema.safeParse>,
7
+ issuePath: string,
8
+ ) {
9
+ expect(result.success).toBe(false);
10
+ if (!result.success) {
11
+ expect(result.error.issues.map((issue) => issue.path.join("."))).toContain(issuePath);
12
+ }
13
+ }
14
+
15
+ describe("FeishuConfigSchema webhook validation", () => {
16
+ it("applies top-level defaults", () => {
17
+ const result = FeishuConfigSchema.parse({});
18
+ expect(result.domain).toBe("feishu");
19
+ expect(result.connectionMode).toBe("websocket");
20
+ expect(result.webhookPath).toBe("/feishu/events");
21
+ expect(result.dmPolicy).toBe("pairing");
22
+ expect(result.groupPolicy).toBe("allowlist");
23
+ // requireMention has no schema-level default now — it is resolved at runtime
24
+ // through shared channel group-policy resolution, with an open-group override
25
+ // that defaults to false only when requireMention is otherwise unset.
26
+ expect(result.requireMention).toBeUndefined();
27
+ });
28
+
29
+ it("does not force top-level policy defaults into account config", () => {
30
+ const result = FeishuConfigSchema.parse({
31
+ accounts: {
32
+ main: {},
33
+ },
34
+ });
35
+
36
+ expect(result.accounts?.main?.dmPolicy).toBeUndefined();
37
+ expect(result.accounts?.main?.groupPolicy).toBeUndefined();
38
+ expect(result.accounts?.main?.requireMention).toBeUndefined();
39
+ });
40
+
41
+ it("normalizes legacy groupPolicy allowall to open", () => {
42
+ const result = FeishuConfigSchema.parse({
43
+ groupPolicy: "allowall",
44
+ });
45
+
46
+ expect(result.groupPolicy).toBe("open");
47
+ });
48
+
49
+ it("rejects top-level webhook mode without verificationToken", () => {
50
+ const result = FeishuConfigSchema.safeParse({
51
+ connectionMode: "webhook",
52
+ appId: "cli_top",
53
+ appSecret: "secret_top", // pragma: allowlist secret
54
+ });
55
+
56
+ expectSchemaIssue(result, "verificationToken");
57
+ });
58
+
59
+ it("rejects top-level webhook mode without encryptKey", () => {
60
+ const result = FeishuConfigSchema.safeParse({
61
+ connectionMode: "webhook",
62
+ verificationToken: "token_top",
63
+ appId: "cli_top",
64
+ appSecret: "secret_top", // pragma: allowlist secret
65
+ });
66
+
67
+ expectSchemaIssue(result, "encryptKey");
68
+ });
69
+
70
+ it("accepts top-level webhook mode with verificationToken and encryptKey", () => {
71
+ const result = FeishuConfigSchema.safeParse({
72
+ connectionMode: "webhook",
73
+ verificationToken: "token_top",
74
+ encryptKey: "encrypt_top",
75
+ appId: "cli_top",
76
+ appSecret: "secret_top", // pragma: allowlist secret
77
+ });
78
+
79
+ expect(result.success).toBe(true);
80
+ });
81
+
82
+ it("rejects account webhook mode without verificationToken", () => {
83
+ const result = FeishuConfigSchema.safeParse({
84
+ accounts: {
85
+ main: {
86
+ connectionMode: "webhook",
87
+ appId: "cli_main",
88
+ appSecret: "secret_main", // pragma: allowlist secret
89
+ },
90
+ },
91
+ });
92
+
93
+ expectSchemaIssue(result, "accounts.main.verificationToken");
94
+ });
95
+
96
+ it("rejects account webhook mode without encryptKey", () => {
97
+ const result = FeishuConfigSchema.safeParse({
98
+ accounts: {
99
+ main: {
100
+ connectionMode: "webhook",
101
+ verificationToken: "token_main",
102
+ appId: "cli_main",
103
+ appSecret: "secret_main", // pragma: allowlist secret
104
+ },
105
+ },
106
+ });
107
+
108
+ expectSchemaIssue(result, "accounts.main.encryptKey");
109
+ });
110
+
111
+ it("accepts account webhook mode inheriting top-level verificationToken and encryptKey", () => {
112
+ const result = FeishuConfigSchema.safeParse({
113
+ verificationToken: "token_top",
114
+ encryptKey: "encrypt_top",
115
+ accounts: {
116
+ main: {
117
+ connectionMode: "webhook",
118
+ appId: "cli_main",
119
+ appSecret: "secret_main", // pragma: allowlist secret
120
+ },
121
+ },
122
+ });
123
+
124
+ expect(result.success).toBe(true);
125
+ });
126
+
127
+ it("accepts SecretRef verificationToken in webhook mode", () => {
128
+ const result = FeishuConfigSchema.safeParse({
129
+ connectionMode: "webhook",
130
+ verificationToken: {
131
+ source: "env",
132
+ provider: "default",
133
+ id: "FEISHU_VERIFICATION_TOKEN",
134
+ },
135
+ encryptKey: "encrypt_top",
136
+ appId: "cli_top",
137
+ appSecret: {
138
+ source: "env",
139
+ provider: "default",
140
+ id: "FEISHU_APP_SECRET",
141
+ },
142
+ });
143
+
144
+ expect(result.success).toBe(true);
145
+ });
146
+
147
+ it("accepts SecretRef encryptKey in webhook mode", () => {
148
+ const result = FeishuConfigSchema.safeParse({
149
+ connectionMode: "webhook",
150
+ verificationToken: {
151
+ source: "env",
152
+ provider: "default",
153
+ id: "FEISHU_VERIFICATION_TOKEN",
154
+ },
155
+ encryptKey: {
156
+ source: "env",
157
+ provider: "default",
158
+ id: "FEISHU_ENCRYPT_KEY",
159
+ },
160
+ appId: "cli_top",
161
+ appSecret: {
162
+ source: "env",
163
+ provider: "default",
164
+ id: "FEISHU_APP_SECRET",
165
+ },
166
+ });
167
+
168
+ expect(result.success).toBe(true);
169
+ });
170
+ });
171
+
172
+ describe("FeishuConfigSchema replyInThread", () => {
173
+ it("accepts replyInThread at top level", () => {
174
+ const result = FeishuConfigSchema.parse({ replyInThread: "enabled" });
175
+ expect(result.replyInThread).toBe("enabled");
176
+ });
177
+
178
+ it("defaults replyInThread to undefined when not set", () => {
179
+ const result = FeishuConfigSchema.parse({});
180
+ expect(result.replyInThread).toBeUndefined();
181
+ });
182
+
183
+ it("rejects invalid replyInThread value", () => {
184
+ const result = FeishuConfigSchema.safeParse({ replyInThread: "always" });
185
+ expect(result.success).toBe(false);
186
+ });
187
+
188
+ it("accepts replyInThread in group config", () => {
189
+ const result = FeishuGroupSchema.parse({ replyInThread: "enabled" });
190
+ expect(result.replyInThread).toBe("enabled");
191
+ });
192
+
193
+ it("accepts replyInThread in account config", () => {
194
+ const result = FeishuConfigSchema.parse({
195
+ accounts: {
196
+ main: { replyInThread: "enabled" },
197
+ },
198
+ });
199
+ expect(result.accounts?.main?.replyInThread).toBe("enabled");
200
+ });
201
+ });
202
+
203
+ describe("FeishuConfigSchema optimization flags", () => {
204
+ it("defaults top-level typingIndicator and resolveSenderNames to true", () => {
205
+ const result = FeishuConfigSchema.parse({});
206
+ expect(result.typingIndicator).toBe(true);
207
+ expect(result.resolveSenderNames).toBe(true);
208
+ });
209
+
210
+ it("accepts top-level and account-level block streaming", () => {
211
+ const result = FeishuConfigSchema.parse({
212
+ blockStreaming: true,
213
+ accounts: {
214
+ main: {
215
+ blockStreaming: false,
216
+ },
217
+ },
218
+ });
219
+
220
+ expect(result.blockStreaming).toBe(true);
221
+ expect(result.accounts?.main?.blockStreaming).toBe(false);
222
+ });
223
+
224
+ it("accepts account-level optimization flags", () => {
225
+ const result = FeishuConfigSchema.parse({
226
+ accounts: {
227
+ main: {
228
+ typingIndicator: false,
229
+ resolveSenderNames: false,
230
+ },
231
+ },
232
+ });
233
+ expect(result.accounts?.main?.typingIndicator).toBe(false);
234
+ expect(result.accounts?.main?.resolveSenderNames).toBe(false);
235
+ });
236
+ });
237
+
238
+ describe("FeishuConfigSchema TTS overrides", () => {
239
+ it("accepts top-level and account-level TTS overrides", () => {
240
+ const result = FeishuConfigSchema.parse({
241
+ tts: {
242
+ auto: "always",
243
+ provider: "openai",
244
+ providers: {
245
+ openai: {
246
+ voice: "alloy",
247
+ },
248
+ },
249
+ },
250
+ accounts: {
251
+ english: {
252
+ tts: {
253
+ providers: {
254
+ openai: {
255
+ voice: "shimmer",
256
+ },
257
+ },
258
+ },
259
+ },
260
+ },
261
+ });
262
+
263
+ expect(result.tts).toEqual({
264
+ auto: "always",
265
+ provider: "openai",
266
+ providers: {
267
+ openai: {
268
+ voice: "alloy",
269
+ },
270
+ },
271
+ });
272
+ expect(result.accounts?.english?.tts).toEqual({
273
+ providers: {
274
+ openai: {
275
+ voice: "shimmer",
276
+ },
277
+ },
278
+ });
279
+ });
280
+ });
281
+
282
+ describe("FeishuConfigSchema actions", () => {
283
+ it("accepts top-level reactions action gate", () => {
284
+ const result = FeishuConfigSchema.parse({
285
+ actions: { reactions: false },
286
+ });
287
+ expect(result.actions?.reactions).toBe(false);
288
+ });
289
+
290
+ it("accepts account-level reactions action gate", () => {
291
+ const result = FeishuConfigSchema.parse({
292
+ accounts: {
293
+ main: {
294
+ actions: { reactions: false },
295
+ },
296
+ },
297
+ });
298
+ expect(result.accounts?.main?.actions?.reactions).toBe(false);
299
+ });
300
+ });
301
+
302
+ describe("FeishuConfigSchema defaultAccount", () => {
303
+ it("accepts defaultAccount when it matches an account key", () => {
304
+ const result = FeishuConfigSchema.safeParse({
305
+ defaultAccount: "router-d",
306
+ accounts: {
307
+ "router-d": { appId: "cli_router", appSecret: "secret_router" }, // pragma: allowlist secret
308
+ },
309
+ });
310
+
311
+ expect(result.success).toBe(true);
312
+ });
313
+
314
+ it("rejects defaultAccount when it does not match an account key", () => {
315
+ const result = FeishuConfigSchema.safeParse({
316
+ defaultAccount: "router-d",
317
+ accounts: {
318
+ backup: { appId: "cli_backup", appSecret: "secret_backup" }, // pragma: allowlist secret
319
+ },
320
+ });
321
+
322
+ expect(result.success).toBe(false);
323
+ if (!result.success) {
324
+ expect(result.error.issues.map((issue) => issue.path.join("."))).toContain("defaultAccount");
325
+ }
326
+ });
327
+ });
@@ -0,0 +1,338 @@
1
+ // Feishu helper module supports config schema behavior.
2
+ import { normalizeAccountId } from "actagent/plugin-sdk/account-id";
3
+ import { z } from "zod";
4
+ export { z };
5
+ import { buildSecretInputSchema, hasConfiguredSecretInput } from "./secret-input.js";
6
+
7
+ const ChannelActionsSchema = z
8
+ .object({
9
+ reactions: z.boolean().optional(),
10
+ })
11
+ .strict()
12
+ .optional();
13
+
14
+ const DmPolicySchema = z.enum(["open", "pairing", "allowlist"]);
15
+ const GroupPolicySchema = z.union([
16
+ z.enum(["open", "allowlist", "disabled"]),
17
+ z.literal("allowall").transform(() => "open" as const),
18
+ ]);
19
+ const FeishuDomainSchema = z.union([
20
+ z.enum(["feishu", "lark"]),
21
+ z.string().url().startsWith("https://"),
22
+ ]);
23
+ const FeishuConnectionModeSchema = z.enum(["websocket", "webhook"]);
24
+ const TtsOverrideSchema = z
25
+ .object({
26
+ auto: z.enum(["off", "always", "inbound", "tagged"]).optional(),
27
+ enabled: z.boolean().optional(),
28
+ mode: z.enum(["final", "all"]).optional(),
29
+ provider: z.string().optional(),
30
+ persona: z.string().optional(),
31
+ personas: z.record(z.string(), z.record(z.string(), z.unknown())).optional(),
32
+ summaryModel: z.string().optional(),
33
+ modelOverrides: z.record(z.string(), z.unknown()).optional(),
34
+ providers: z.record(z.string(), z.record(z.string(), z.unknown())).optional(),
35
+ prefsPath: z.string().optional(),
36
+ maxTextLength: z.number().int().min(1).optional(),
37
+ timeoutMs: z.number().int().min(1000).max(120000).optional(),
38
+ })
39
+ .strict()
40
+ .optional();
41
+
42
+ const ToolPolicySchema = z
43
+ .object({
44
+ allow: z.array(z.string()).optional(),
45
+ deny: z.array(z.string()).optional(),
46
+ })
47
+ .strict()
48
+ .optional();
49
+
50
+ const DmConfigSchema = z
51
+ .object({
52
+ enabled: z.boolean().optional(),
53
+ systemPrompt: z.string().optional(),
54
+ })
55
+ .strict()
56
+ .optional();
57
+
58
+ const MarkdownConfigSchema = z
59
+ .object({
60
+ mode: z.enum(["native", "escape", "strip"]).optional(),
61
+ tableMode: z.enum(["native", "ascii", "simple"]).optional(),
62
+ })
63
+ .strict()
64
+ .optional();
65
+
66
+ // Message render mode: auto (default) = detect markdown, raw = plain text, card = always card
67
+ const RenderModeSchema = z.enum(["auto", "raw", "card"]).optional();
68
+
69
+ // Streaming card mode: when enabled, card replies use Feishu's Card Kit streaming API
70
+ // for incremental text display with a "Thinking..." placeholder
71
+ const StreamingModeSchema = z.boolean().optional();
72
+ const BlockStreamingSchema = z.boolean().optional();
73
+
74
+ const BlockStreamingCoalesceSchema = z
75
+ .object({
76
+ enabled: z.boolean().optional(),
77
+ minDelayMs: z.number().int().positive().optional(),
78
+ maxDelayMs: z.number().int().positive().optional(),
79
+ })
80
+ .strict()
81
+ .optional();
82
+
83
+ const ChannelHeartbeatVisibilitySchema = z
84
+ .object({
85
+ visibility: z.enum(["visible", "hidden"]).optional(),
86
+ intervalMs: z.number().int().positive().optional(),
87
+ })
88
+ .strict()
89
+ .optional();
90
+
91
+ /**
92
+ * Dynamic agent creation configuration.
93
+ * When enabled, a new agent is created for each unique DM user.
94
+ */
95
+ const DynamicAgentCreationSchema = z
96
+ .object({
97
+ enabled: z.boolean().optional(),
98
+ workspaceTemplate: z.string().optional(),
99
+ agentDirTemplate: z.string().optional(),
100
+ maxAgents: z.number().int().positive().optional(),
101
+ })
102
+ .strict()
103
+ .optional();
104
+
105
+ /**
106
+ * Feishu tools configuration.
107
+ * Controls which tool categories are enabled.
108
+ *
109
+ * Dependencies:
110
+ * - wiki requires doc (wiki content is edited via doc tools)
111
+ * - perm can work independently but is typically used with drive
112
+ */
113
+ const FeishuToolsConfigSchema = z
114
+ .object({
115
+ doc: z.boolean().optional(), // Document operations (default: true)
116
+ chat: z.boolean().optional(), // Chat info + member query operations (default: true)
117
+ wiki: z.boolean().optional(), // Knowledge base operations (default: true, requires doc)
118
+ drive: z.boolean().optional(), // Cloud storage operations (default: true)
119
+ perm: z.boolean().optional(), // Permission management (default: false, sensitive)
120
+ scopes: z.boolean().optional(), // App scopes diagnostic (default: true)
121
+ bitable: z.boolean().optional(), // Bitable/Base operations (default: true)
122
+ base: z.boolean().optional(), // Alias for bitable tools (default: true)
123
+ })
124
+ .strict()
125
+ .optional();
126
+
127
+ /**
128
+ * Group session scope for routing Feishu group messages.
129
+ * - "group" (default): one session per group chat
130
+ * - "group_sender": one session per (group + sender)
131
+ * - "group_topic": one session per group topic thread (falls back to group if no topic)
132
+ * - "group_topic_sender": one session per (group + topic thread + sender),
133
+ * falls back to (group + sender) if no topic
134
+ */
135
+ const GroupSessionScopeSchema = z
136
+ .enum(["group", "group_sender", "group_topic", "group_topic_sender"])
137
+ .optional();
138
+
139
+ /**
140
+ * @deprecated Use groupSessionScope instead.
141
+ *
142
+ * Topic session isolation mode for group chats.
143
+ * - "disabled" (default): All messages in a group share one session
144
+ * - "enabled": Messages in different topics get separate sessions
145
+ *
146
+ * Topic routing uses Feishu topic-group `thread_id` when the event identifies a
147
+ * native topic group, and keeps `root_id` precedence for normal groups so
148
+ * reply-created threads stay on the initiating message session.
149
+ */
150
+ const TopicSessionModeSchema = z.enum(["disabled", "enabled"]).optional();
151
+ const ReactionNotificationModeSchema = z.enum(["off", "own", "all"]).optional();
152
+
153
+ /**
154
+ * Reply-in-thread mode for group chats.
155
+ * - "disabled" (default): Bot replies are normal inline replies
156
+ * - "enabled": Bot replies create or continue a Feishu topic thread
157
+ *
158
+ * When enabled, the Feishu reply API is called with `reply_in_thread: true`,
159
+ * causing the reply to appear as a topic (话题) under the original message.
160
+ */
161
+ const ReplyInThreadSchema = z.enum(["disabled", "enabled"]).optional();
162
+
163
+ export const FeishuGroupSchema = z
164
+ .object({
165
+ requireMention: z.boolean().optional(),
166
+ tools: ToolPolicySchema,
167
+ skills: z.array(z.string()).optional(),
168
+ enabled: z.boolean().optional(),
169
+ allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
170
+ systemPrompt: z.string().optional(),
171
+ groupSessionScope: GroupSessionScopeSchema,
172
+ topicSessionMode: TopicSessionModeSchema,
173
+ replyInThread: ReplyInThreadSchema,
174
+ })
175
+ .strict();
176
+
177
+ const FeishuSharedConfigShape = {
178
+ webhookHost: z.string().optional(),
179
+ webhookPort: z.number().int().positive().optional(),
180
+ capabilities: z.array(z.string()).optional(),
181
+ markdown: MarkdownConfigSchema,
182
+ configWrites: z.boolean().optional(),
183
+ dmPolicy: DmPolicySchema.optional(),
184
+ allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
185
+ groupPolicy: GroupPolicySchema.optional(),
186
+ groupAllowFrom: z.array(z.union([z.string(), z.number()])).optional(),
187
+ groupSenderAllowFrom: z.array(z.union([z.string(), z.number()])).optional(),
188
+ requireMention: z.boolean().optional(),
189
+ groups: z.record(z.string(), FeishuGroupSchema.optional()).optional(),
190
+ historyLimit: z.number().int().min(0).optional(),
191
+ dmHistoryLimit: z.number().int().min(0).optional(),
192
+ dms: z.record(z.string(), DmConfigSchema).optional(),
193
+ textChunkLimit: z.number().int().positive().optional(),
194
+ chunkMode: z.enum(["length", "newline"]).optional(),
195
+ blockStreaming: BlockStreamingSchema,
196
+ blockStreamingCoalesce: BlockStreamingCoalesceSchema,
197
+ mediaMaxMb: z.number().positive().optional(),
198
+ httpTimeoutMs: z.number().int().positive().max(300_000).optional(),
199
+ heartbeat: ChannelHeartbeatVisibilitySchema,
200
+ renderMode: RenderModeSchema,
201
+ streaming: StreamingModeSchema,
202
+ tools: FeishuToolsConfigSchema,
203
+ actions: ChannelActionsSchema,
204
+ replyInThread: ReplyInThreadSchema,
205
+ reactionNotifications: ReactionNotificationModeSchema,
206
+ typingIndicator: z.boolean().optional(),
207
+ resolveSenderNames: z.boolean().optional(),
208
+ tts: TtsOverrideSchema,
209
+ };
210
+
211
+ /**
212
+ * Per-account configuration.
213
+ * All fields are optional - missing fields inherit from top-level config.
214
+ */
215
+ export const FeishuAccountConfigSchema = z
216
+ .object({
217
+ enabled: z.boolean().optional(),
218
+ name: z.string().optional(), // Display name for this account
219
+ appId: z.string().optional(),
220
+ appSecret: buildSecretInputSchema().optional(),
221
+ encryptKey: buildSecretInputSchema().optional(),
222
+ verificationToken: buildSecretInputSchema().optional(),
223
+ domain: FeishuDomainSchema.optional(),
224
+ connectionMode: FeishuConnectionModeSchema.optional(),
225
+ webhookPath: z.string().optional(),
226
+ ...FeishuSharedConfigShape,
227
+ groupSessionScope: GroupSessionScopeSchema,
228
+ topicSessionMode: TopicSessionModeSchema,
229
+ })
230
+ .strict();
231
+
232
+ export const FeishuConfigSchema = z
233
+ .object({
234
+ enabled: z.boolean().optional(),
235
+ defaultAccount: z.string().optional(),
236
+ // Top-level credentials (backward compatible for single-account mode)
237
+ appId: z.string().optional(),
238
+ appSecret: buildSecretInputSchema().optional(),
239
+ encryptKey: buildSecretInputSchema().optional(),
240
+ verificationToken: buildSecretInputSchema().optional(),
241
+ domain: FeishuDomainSchema.optional().default("feishu"),
242
+ connectionMode: FeishuConnectionModeSchema.optional().default("websocket"),
243
+ webhookPath: z.string().optional().default("/feishu/events"),
244
+ ...FeishuSharedConfigShape,
245
+ dmPolicy: DmPolicySchema.optional().default("pairing"),
246
+ reactionNotifications: ReactionNotificationModeSchema.optional().default("own"),
247
+ groupPolicy: GroupPolicySchema.optional().default("allowlist"),
248
+ requireMention: z.boolean().optional(),
249
+ groupSessionScope: GroupSessionScopeSchema,
250
+ topicSessionMode: TopicSessionModeSchema,
251
+ // Dynamic agent creation for DM users
252
+ dynamicAgentCreation: DynamicAgentCreationSchema,
253
+ // Optimization flags
254
+ typingIndicator: z.boolean().optional().default(true),
255
+ resolveSenderNames: z.boolean().optional().default(true),
256
+ // Multi-account configuration
257
+ accounts: z.record(z.string(), FeishuAccountConfigSchema.optional()).optional(),
258
+ })
259
+ .strict()
260
+ .superRefine((value, ctx) => {
261
+ const defaultAccount = value.defaultAccount?.trim();
262
+ if (defaultAccount && value.accounts && Object.keys(value.accounts).length > 0) {
263
+ const normalizedDefaultAccount = normalizeAccountId(defaultAccount);
264
+ if (!Object.hasOwn(value.accounts, normalizedDefaultAccount)) {
265
+ ctx.addIssue({
266
+ code: z.ZodIssueCode.custom,
267
+ path: ["defaultAccount"],
268
+ message: `channels.feishu.defaultAccount="${defaultAccount}" does not match a configured account key`,
269
+ });
270
+ }
271
+ }
272
+
273
+ const defaultConnectionMode = value.connectionMode ?? "websocket";
274
+ const defaultVerificationTokenConfigured = hasConfiguredSecretInput(value.verificationToken);
275
+ const defaultEncryptKeyConfigured = hasConfiguredSecretInput(value.encryptKey);
276
+ if (defaultConnectionMode === "webhook") {
277
+ if (!defaultVerificationTokenConfigured) {
278
+ ctx.addIssue({
279
+ code: z.ZodIssueCode.custom,
280
+ path: ["verificationToken"],
281
+ message:
282
+ 'channels.feishu.connectionMode="webhook" requires channels.feishu.verificationToken',
283
+ });
284
+ }
285
+ if (!defaultEncryptKeyConfigured) {
286
+ ctx.addIssue({
287
+ code: z.ZodIssueCode.custom,
288
+ path: ["encryptKey"],
289
+ message: 'channels.feishu.connectionMode="webhook" requires channels.feishu.encryptKey',
290
+ });
291
+ }
292
+ }
293
+
294
+ for (const [accountId, account] of Object.entries(value.accounts ?? {})) {
295
+ if (!account) {
296
+ continue;
297
+ }
298
+ const accountConnectionMode = account.connectionMode ?? defaultConnectionMode;
299
+ if (accountConnectionMode !== "webhook") {
300
+ continue;
301
+ }
302
+ const accountVerificationTokenConfigured =
303
+ hasConfiguredSecretInput(account.verificationToken) || defaultVerificationTokenConfigured;
304
+ const accountEncryptKeyConfigured =
305
+ hasConfiguredSecretInput(account.encryptKey) || defaultEncryptKeyConfigured;
306
+ if (!accountVerificationTokenConfigured) {
307
+ ctx.addIssue({
308
+ code: z.ZodIssueCode.custom,
309
+ path: ["accounts", accountId, "verificationToken"],
310
+ message:
311
+ `channels.feishu.accounts.${accountId}.connectionMode="webhook" requires ` +
312
+ "a verificationToken (account-level or top-level)",
313
+ });
314
+ }
315
+ if (!accountEncryptKeyConfigured) {
316
+ ctx.addIssue({
317
+ code: z.ZodIssueCode.custom,
318
+ path: ["accounts", accountId, "encryptKey"],
319
+ message:
320
+ `channels.feishu.accounts.${accountId}.connectionMode="webhook" requires ` +
321
+ "an encryptKey (account-level or top-level)",
322
+ });
323
+ }
324
+ }
325
+
326
+ if (value.dmPolicy === "open") {
327
+ const allowFrom = value.allowFrom ?? [];
328
+ const hasWildcard = allowFrom.some((entry) => String(entry).trim() === "*");
329
+ if (!hasWildcard) {
330
+ ctx.addIssue({
331
+ code: z.ZodIssueCode.custom,
332
+ path: ["allowFrom"],
333
+ message:
334
+ 'channels.feishu.dmPolicy="open" requires channels.feishu.allowFrom to include "*"',
335
+ });
336
+ }
337
+ }
338
+ });
@@ -0,0 +1,19 @@
1
+ // Feishu tests cover conversation id plugin behavior.
2
+ import { describe, expect, it } from "vitest";
3
+ import { buildFeishuModelOverrideParentCandidates } from "./conversation-id.js";
4
+
5
+ describe("buildFeishuModelOverrideParentCandidates", () => {
6
+ it("returns topic and chat fallback ids for sender-scoped topics", () => {
7
+ expect(
8
+ buildFeishuModelOverrideParentCandidates(
9
+ "oc_group_chat:Topic:om_topic_root:Sender:ou_topic_user",
10
+ ),
11
+ ).toEqual(["oc_group_chat:topic:om_topic_root", "oc_group_chat"]);
12
+ });
13
+
14
+ it("returns chat fallback ids for sender-scoped chats", () => {
15
+ expect(buildFeishuModelOverrideParentCandidates("oc_group_chat:sender:ou_topic_user")).toEqual([
16
+ "oc_group_chat",
17
+ ]);
18
+ });
19
+ });