@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
@@ -0,0 +1,1668 @@
1
+ import { a as parseFeishuTargetId, i as parseFeishuDirectConversationId, n as buildFeishuModelOverrideParentCandidates, r as parseFeishuConversationId, t as buildFeishuConversationId } from "./conversation-id-DWS3Ep2A.js";
2
+ import { n as looksLikeFeishuId, r as normalizeFeishuTarget } from "./targets-JMFJRKSe.js";
3
+ import { a as resolveDefaultFeishuAccountId, f as isRecord$1, i as listFeishuAccountIds, n as inspectFeishuCredentials, o as resolveFeishuAccount, r as listEnabledFeishuAccounts, s as resolveFeishuRuntimeAccount } from "./accounts-Ba3-WP1z.js";
4
+ import "./card-interaction-BfRLgvw_.js";
5
+ import { n as listFeishuDirectoryPeers, t as listFeishuDirectoryGroups } from "./directory.static-f3EeoRJd.js";
6
+ import { t as messageActionTargetAliases } from "./security-audit-DqJdocrN.js";
7
+ import { a as resolveFeishuGroupToolPolicy } from "./policy-D6c-wMPl.js";
8
+ import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-Dm4Z_zQN.js";
9
+ import { t as collectFeishuSecurityAuditFindings } from "./security-audit-shared-ByuMx9cJ.js";
10
+ import { t as resolveFeishuSessionConversation } from "./session-conversation-B4nrW-vo.js";
11
+ import { normalizeLowercaseStringOrEmpty, normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/text-runtime";
12
+ import { getSessionBindingService } from "openclaw/plugin-sdk/conversation-runtime";
13
+ import { describeAccountSnapshot } from "openclaw/plugin-sdk/account-helpers";
14
+ import { formatAllowFromLowercase } from "openclaw/plugin-sdk/allow-from";
15
+ import { adaptScopedAccountAccessor, createHybridChannelConfigAdapter } from "openclaw/plugin-sdk/channel-config-helpers";
16
+ import { buildChannelOutboundSessionRoute, createChatChannelPlugin, stripChannelTargetPrefix } from "openclaw/plugin-sdk/channel-core";
17
+ import { createPairingPrefixStripper } from "openclaw/plugin-sdk/channel-pairing";
18
+ import { createAllowlistProviderGroupPolicyWarningCollector, projectConfigAccountIdWarningCollector } from "openclaw/plugin-sdk/channel-policy";
19
+ import { createChannelDirectoryAdapter, createRuntimeDirectoryLiveAdapter } from "openclaw/plugin-sdk/directory-runtime";
20
+ import { normalizeMessagePresentation, renderMessagePresentationFallbackText } from "openclaw/plugin-sdk/interactive-runtime";
21
+ import { createLazyRuntimeNamedExport } from "openclaw/plugin-sdk/lazy-runtime";
22
+ import { createRuntimeOutboundDelegates } from "openclaw/plugin-sdk/outbound-runtime";
23
+ import { buildProbeChannelStatusSummary, createComputedAccountStatusAdapter, createDefaultChannelRuntimeState } from "openclaw/plugin-sdk/status-helpers";
24
+ import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$2 } from "openclaw/plugin-sdk/account-resolution";
25
+ import { createResolvedApproverActionAuthAdapter, resolveApprovalApprovers } from "openclaw/plugin-sdk/approval-auth-runtime";
26
+ import { createActionGate } from "openclaw/plugin-sdk/channel-actions";
27
+ import { buildChannelConfigSchema } from "openclaw/plugin-sdk/channel-config-primitives";
28
+ import { PAIRING_APPROVED_MESSAGE } from "openclaw/plugin-sdk/channel-status";
29
+ import { chunkTextForOutbound } from "openclaw/plugin-sdk/text-chunking";
30
+ import { normalizeAccountId as normalizeAccountId$1 } from "openclaw/plugin-sdk/account-id";
31
+ import { z } from "openclaw/plugin-sdk/zod";
32
+ import { buildSecretInputSchema, hasConfiguredSecretInput as hasConfiguredSecretInput$2 } from "openclaw/plugin-sdk/secret-input";
33
+ import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$1, formatDocsLink, hasConfiguredSecretInput as hasConfiguredSecretInput$1, mergeAllowFromEntries, patchTopLevelChannelConfigSection, promptSingleChannelSecretInput, splitSetupEntries } from "openclaw/plugin-sdk/setup";
34
+ //#region extensions/feishu/src/approval-auth.ts
35
+ function normalizeFeishuApproverId(value) {
36
+ const trimmed = normalizeOptionalLowercaseString(normalizeFeishuTarget(String(value)));
37
+ return trimmed?.startsWith("ou_") ? trimmed : void 0;
38
+ }
39
+ const feishuApprovalAuth = createResolvedApproverActionAuthAdapter({
40
+ channelLabel: "Feishu",
41
+ resolveApprovers: ({ cfg, accountId }) => {
42
+ const account = resolveFeishuAccount({
43
+ cfg,
44
+ accountId
45
+ }).config;
46
+ return resolveApprovalApprovers({
47
+ allowFrom: account.allowFrom,
48
+ normalizeApprover: normalizeFeishuApproverId
49
+ });
50
+ },
51
+ normalizeSenderId: (value) => normalizeFeishuApproverId(value)
52
+ });
53
+ //#endregion
54
+ //#region extensions/feishu/src/config-schema.ts
55
+ const ChannelActionsSchema = z.object({ reactions: z.boolean().optional() }).strict().optional();
56
+ const DmPolicySchema = z.enum([
57
+ "open",
58
+ "pairing",
59
+ "allowlist"
60
+ ]);
61
+ const GroupPolicySchema = z.union([z.enum([
62
+ "open",
63
+ "allowlist",
64
+ "disabled"
65
+ ]), z.literal("allowall").transform(() => "open")]);
66
+ const FeishuDomainSchema = z.union([z.enum(["feishu", "lark"]), z.string().url().startsWith("https://")]);
67
+ const FeishuConnectionModeSchema = z.enum(["websocket", "webhook"]);
68
+ const TtsOverrideSchema = z.object({
69
+ auto: z.enum([
70
+ "off",
71
+ "always",
72
+ "inbound",
73
+ "tagged"
74
+ ]).optional(),
75
+ enabled: z.boolean().optional(),
76
+ mode: z.enum(["final", "all"]).optional(),
77
+ provider: z.string().optional(),
78
+ persona: z.string().optional(),
79
+ personas: z.record(z.string(), z.record(z.string(), z.unknown())).optional(),
80
+ summaryModel: z.string().optional(),
81
+ modelOverrides: z.record(z.string(), z.unknown()).optional(),
82
+ providers: z.record(z.string(), z.record(z.string(), z.unknown())).optional(),
83
+ prefsPath: z.string().optional(),
84
+ maxTextLength: z.number().int().min(1).optional(),
85
+ timeoutMs: z.number().int().min(1e3).max(12e4).optional()
86
+ }).strict().optional();
87
+ const ToolPolicySchema = z.object({
88
+ allow: z.array(z.string()).optional(),
89
+ deny: z.array(z.string()).optional()
90
+ }).strict().optional();
91
+ const DmConfigSchema = z.object({
92
+ enabled: z.boolean().optional(),
93
+ systemPrompt: z.string().optional()
94
+ }).strict().optional();
95
+ const MarkdownConfigSchema = z.object({
96
+ mode: z.enum([
97
+ "native",
98
+ "escape",
99
+ "strip"
100
+ ]).optional(),
101
+ tableMode: z.enum([
102
+ "native",
103
+ "ascii",
104
+ "simple"
105
+ ]).optional()
106
+ }).strict().optional();
107
+ const RenderModeSchema = z.enum([
108
+ "auto",
109
+ "raw",
110
+ "card"
111
+ ]).optional();
112
+ const StreamingModeSchema = z.boolean().optional();
113
+ const BlockStreamingCoalesceSchema = z.object({
114
+ enabled: z.boolean().optional(),
115
+ minDelayMs: z.number().int().positive().optional(),
116
+ maxDelayMs: z.number().int().positive().optional()
117
+ }).strict().optional();
118
+ const ChannelHeartbeatVisibilitySchema = z.object({
119
+ visibility: z.enum(["visible", "hidden"]).optional(),
120
+ intervalMs: z.number().int().positive().optional()
121
+ }).strict().optional();
122
+ /**
123
+ * Dynamic agent creation configuration.
124
+ * When enabled, a new agent is created for each unique DM user.
125
+ */
126
+ const DynamicAgentCreationSchema = z.object({
127
+ enabled: z.boolean().optional(),
128
+ workspaceTemplate: z.string().optional(),
129
+ agentDirTemplate: z.string().optional(),
130
+ maxAgents: z.number().int().positive().optional()
131
+ }).strict().optional();
132
+ /**
133
+ * Feishu tools configuration.
134
+ * Controls which tool categories are enabled.
135
+ *
136
+ * Dependencies:
137
+ * - wiki requires doc (wiki content is edited via doc tools)
138
+ * - perm can work independently but is typically used with drive
139
+ */
140
+ const FeishuToolsConfigSchema = z.object({
141
+ doc: z.boolean().optional(),
142
+ chat: z.boolean().optional(),
143
+ wiki: z.boolean().optional(),
144
+ drive: z.boolean().optional(),
145
+ perm: z.boolean().optional(),
146
+ scopes: z.boolean().optional()
147
+ }).strict().optional();
148
+ /**
149
+ * Group session scope for routing Feishu group messages.
150
+ * - "group" (default): one session per group chat
151
+ * - "group_sender": one session per (group + sender)
152
+ * - "group_topic": one session per group topic thread (falls back to group if no topic)
153
+ * - "group_topic_sender": one session per (group + topic thread + sender),
154
+ * falls back to (group + sender) if no topic
155
+ */
156
+ const GroupSessionScopeSchema = z.enum([
157
+ "group",
158
+ "group_sender",
159
+ "group_topic",
160
+ "group_topic_sender"
161
+ ]).optional();
162
+ /**
163
+ * @deprecated Use groupSessionScope instead.
164
+ *
165
+ * Topic session isolation mode for group chats.
166
+ * - "disabled" (default): All messages in a group share one session
167
+ * - "enabled": Messages in different topics get separate sessions
168
+ *
169
+ * Topic routing uses Feishu topic-group `thread_id` when the event identifies a
170
+ * native topic group, and keeps `root_id` precedence for normal groups so
171
+ * reply-created threads stay on the initiating message session.
172
+ */
173
+ const TopicSessionModeSchema = z.enum(["disabled", "enabled"]).optional();
174
+ const ReactionNotificationModeSchema = z.enum([
175
+ "off",
176
+ "own",
177
+ "all"
178
+ ]).optional();
179
+ /**
180
+ * Reply-in-thread mode for group chats.
181
+ * - "disabled" (default): Bot replies are normal inline replies
182
+ * - "enabled": Bot replies create or continue a Feishu topic thread
183
+ *
184
+ * When enabled, the Feishu reply API is called with `reply_in_thread: true`,
185
+ * causing the reply to appear as a topic (话题) under the original message.
186
+ */
187
+ const ReplyInThreadSchema = z.enum(["disabled", "enabled"]).optional();
188
+ const FeishuGroupSchema = z.object({
189
+ requireMention: z.boolean().optional(),
190
+ tools: ToolPolicySchema,
191
+ skills: z.array(z.string()).optional(),
192
+ enabled: z.boolean().optional(),
193
+ allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
194
+ systemPrompt: z.string().optional(),
195
+ groupSessionScope: GroupSessionScopeSchema,
196
+ topicSessionMode: TopicSessionModeSchema,
197
+ replyInThread: ReplyInThreadSchema
198
+ }).strict();
199
+ const FeishuSharedConfigShape = {
200
+ webhookHost: z.string().optional(),
201
+ webhookPort: z.number().int().positive().optional(),
202
+ capabilities: z.array(z.string()).optional(),
203
+ markdown: MarkdownConfigSchema,
204
+ configWrites: z.boolean().optional(),
205
+ dmPolicy: DmPolicySchema.optional(),
206
+ allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
207
+ groupPolicy: GroupPolicySchema.optional(),
208
+ groupAllowFrom: z.array(z.union([z.string(), z.number()])).optional(),
209
+ groupSenderAllowFrom: z.array(z.union([z.string(), z.number()])).optional(),
210
+ requireMention: z.boolean().optional(),
211
+ groups: z.record(z.string(), FeishuGroupSchema.optional()).optional(),
212
+ historyLimit: z.number().int().min(0).optional(),
213
+ dmHistoryLimit: z.number().int().min(0).optional(),
214
+ dms: z.record(z.string(), DmConfigSchema).optional(),
215
+ textChunkLimit: z.number().int().positive().optional(),
216
+ chunkMode: z.enum(["length", "newline"]).optional(),
217
+ blockStreamingCoalesce: BlockStreamingCoalesceSchema,
218
+ mediaMaxMb: z.number().positive().optional(),
219
+ httpTimeoutMs: z.number().int().positive().max(3e5).optional(),
220
+ heartbeat: ChannelHeartbeatVisibilitySchema,
221
+ renderMode: RenderModeSchema,
222
+ streaming: StreamingModeSchema,
223
+ tools: FeishuToolsConfigSchema,
224
+ actions: ChannelActionsSchema,
225
+ replyInThread: ReplyInThreadSchema,
226
+ reactionNotifications: ReactionNotificationModeSchema,
227
+ typingIndicator: z.boolean().optional(),
228
+ resolveSenderNames: z.boolean().optional(),
229
+ tts: TtsOverrideSchema
230
+ };
231
+ /**
232
+ * Per-account configuration.
233
+ * All fields are optional - missing fields inherit from top-level config.
234
+ */
235
+ const FeishuAccountConfigSchema = z.object({
236
+ enabled: z.boolean().optional(),
237
+ name: z.string().optional(),
238
+ appId: z.string().optional(),
239
+ appSecret: buildSecretInputSchema().optional(),
240
+ encryptKey: buildSecretInputSchema().optional(),
241
+ verificationToken: buildSecretInputSchema().optional(),
242
+ domain: FeishuDomainSchema.optional(),
243
+ connectionMode: FeishuConnectionModeSchema.optional(),
244
+ webhookPath: z.string().optional(),
245
+ ...FeishuSharedConfigShape,
246
+ groupSessionScope: GroupSessionScopeSchema,
247
+ topicSessionMode: TopicSessionModeSchema
248
+ }).strict();
249
+ const FeishuConfigSchema = z.object({
250
+ enabled: z.boolean().optional(),
251
+ defaultAccount: z.string().optional(),
252
+ appId: z.string().optional(),
253
+ appSecret: buildSecretInputSchema().optional(),
254
+ encryptKey: buildSecretInputSchema().optional(),
255
+ verificationToken: buildSecretInputSchema().optional(),
256
+ domain: FeishuDomainSchema.optional().default("feishu"),
257
+ connectionMode: FeishuConnectionModeSchema.optional().default("websocket"),
258
+ webhookPath: z.string().optional().default("/feishu/events"),
259
+ ...FeishuSharedConfigShape,
260
+ dmPolicy: DmPolicySchema.optional().default("pairing"),
261
+ reactionNotifications: ReactionNotificationModeSchema.optional().default("own"),
262
+ groupPolicy: GroupPolicySchema.optional().default("allowlist"),
263
+ requireMention: z.boolean().optional(),
264
+ groupSessionScope: GroupSessionScopeSchema,
265
+ topicSessionMode: TopicSessionModeSchema,
266
+ dynamicAgentCreation: DynamicAgentCreationSchema,
267
+ typingIndicator: z.boolean().optional().default(true),
268
+ resolveSenderNames: z.boolean().optional().default(true),
269
+ accounts: z.record(z.string(), FeishuAccountConfigSchema.optional()).optional()
270
+ }).strict().superRefine((value, ctx) => {
271
+ const defaultAccount = value.defaultAccount?.trim();
272
+ if (defaultAccount && value.accounts && Object.keys(value.accounts).length > 0) {
273
+ const normalizedDefaultAccount = normalizeAccountId$1(defaultAccount);
274
+ if (!Object.prototype.hasOwnProperty.call(value.accounts, normalizedDefaultAccount)) ctx.addIssue({
275
+ code: z.ZodIssueCode.custom,
276
+ path: ["defaultAccount"],
277
+ message: `channels.feishu.defaultAccount="${defaultAccount}" does not match a configured account key`
278
+ });
279
+ }
280
+ const defaultConnectionMode = value.connectionMode ?? "websocket";
281
+ const defaultVerificationTokenConfigured = hasConfiguredSecretInput$2(value.verificationToken);
282
+ const defaultEncryptKeyConfigured = hasConfiguredSecretInput$2(value.encryptKey);
283
+ if (defaultConnectionMode === "webhook") {
284
+ if (!defaultVerificationTokenConfigured) ctx.addIssue({
285
+ code: z.ZodIssueCode.custom,
286
+ path: ["verificationToken"],
287
+ message: "channels.feishu.connectionMode=\"webhook\" requires channels.feishu.verificationToken"
288
+ });
289
+ if (!defaultEncryptKeyConfigured) ctx.addIssue({
290
+ code: z.ZodIssueCode.custom,
291
+ path: ["encryptKey"],
292
+ message: "channels.feishu.connectionMode=\"webhook\" requires channels.feishu.encryptKey"
293
+ });
294
+ }
295
+ for (const [accountId, account] of Object.entries(value.accounts ?? {})) {
296
+ if (!account) continue;
297
+ if ((account.connectionMode ?? defaultConnectionMode) !== "webhook") continue;
298
+ const accountVerificationTokenConfigured = hasConfiguredSecretInput$2(account.verificationToken) || defaultVerificationTokenConfigured;
299
+ const accountEncryptKeyConfigured = hasConfiguredSecretInput$2(account.encryptKey) || defaultEncryptKeyConfigured;
300
+ if (!accountVerificationTokenConfigured) ctx.addIssue({
301
+ code: z.ZodIssueCode.custom,
302
+ path: [
303
+ "accounts",
304
+ accountId,
305
+ "verificationToken"
306
+ ],
307
+ message: `channels.feishu.accounts.${accountId}.connectionMode="webhook" requires a verificationToken (account-level or top-level)`
308
+ });
309
+ if (!accountEncryptKeyConfigured) ctx.addIssue({
310
+ code: z.ZodIssueCode.custom,
311
+ path: [
312
+ "accounts",
313
+ accountId,
314
+ "encryptKey"
315
+ ],
316
+ message: `channels.feishu.accounts.${accountId}.connectionMode="webhook" requires an encryptKey (account-level or top-level)`
317
+ });
318
+ }
319
+ if (value.dmPolicy === "open") {
320
+ if (!(value.allowFrom ?? []).some((entry) => String(entry).trim() === "*")) ctx.addIssue({
321
+ code: z.ZodIssueCode.custom,
322
+ path: ["allowFrom"],
323
+ message: "channels.feishu.dmPolicy=\"open\" requires channels.feishu.allowFrom to include \"*\""
324
+ });
325
+ }
326
+ });
327
+ //#endregion
328
+ //#region extensions/feishu/src/session-route.ts
329
+ function resolveFeishuOutboundSessionRoute(params) {
330
+ let trimmed = stripChannelTargetPrefix(params.target, "feishu", "lark");
331
+ if (!trimmed) return null;
332
+ const lower = normalizeLowercaseStringOrEmpty(trimmed);
333
+ let isGroup = false;
334
+ let typeExplicit = false;
335
+ if (lower.startsWith("group:") || lower.startsWith("chat:") || lower.startsWith("channel:")) {
336
+ trimmed = trimmed.replace(/^(group|chat|channel):/i, "").trim();
337
+ isGroup = true;
338
+ typeExplicit = true;
339
+ } else if (lower.startsWith("user:") || lower.startsWith("dm:")) {
340
+ trimmed = trimmed.replace(/^(user|dm):/i, "").trim();
341
+ isGroup = false;
342
+ typeExplicit = true;
343
+ }
344
+ if (!typeExplicit) {
345
+ const idLower = normalizeLowercaseStringOrEmpty(trimmed);
346
+ if (idLower.startsWith("ou_") || idLower.startsWith("on_")) isGroup = false;
347
+ }
348
+ return buildChannelOutboundSessionRoute({
349
+ cfg: params.cfg,
350
+ agentId: params.agentId,
351
+ channel: "feishu",
352
+ accountId: params.accountId,
353
+ peer: {
354
+ kind: isGroup ? "group" : "direct",
355
+ id: trimmed
356
+ },
357
+ chatType: isGroup ? "group" : "direct",
358
+ from: isGroup ? `feishu:group:${trimmed}` : `feishu:${trimmed}`,
359
+ to: trimmed
360
+ });
361
+ }
362
+ //#endregion
363
+ //#region extensions/feishu/src/setup-core.ts
364
+ function setFeishuNamedAccountEnabled$1(cfg, accountId, enabled) {
365
+ const feishuCfg = cfg.channels?.feishu;
366
+ return {
367
+ ...cfg,
368
+ channels: {
369
+ ...cfg.channels,
370
+ feishu: {
371
+ ...feishuCfg,
372
+ accounts: {
373
+ ...feishuCfg?.accounts,
374
+ [accountId]: {
375
+ ...feishuCfg?.accounts?.[accountId],
376
+ enabled
377
+ }
378
+ }
379
+ }
380
+ }
381
+ };
382
+ }
383
+ const feishuSetupAdapter = {
384
+ resolveAccountId: ({ cfg, accountId }) => accountId?.trim() || resolveDefaultFeishuAccountId(cfg),
385
+ applyAccountConfig: ({ cfg, accountId }) => {
386
+ if (!accountId || accountId === DEFAULT_ACCOUNT_ID$1) return {
387
+ ...cfg,
388
+ channels: {
389
+ ...cfg.channels,
390
+ feishu: {
391
+ ...cfg.channels?.feishu,
392
+ enabled: true
393
+ }
394
+ }
395
+ };
396
+ return setFeishuNamedAccountEnabled$1(cfg, accountId, true);
397
+ }
398
+ };
399
+ //#endregion
400
+ //#region extensions/feishu/src/setup-surface.ts
401
+ const channel = "feishu";
402
+ function normalizeString(value) {
403
+ if (typeof value !== "string") return;
404
+ return value.trim() || void 0;
405
+ }
406
+ function isFeishuConfigured(cfg) {
407
+ const feishuCfg = cfg.channels?.feishu;
408
+ const isAppIdConfigured = (value) => {
409
+ if (normalizeString(value)) return true;
410
+ if (!value || typeof value !== "object") return false;
411
+ const rec = value;
412
+ const source = normalizeString(rec.source)?.toLowerCase();
413
+ const id = normalizeString(rec.id);
414
+ if (source === "env" && id) return Boolean(normalizeString(process.env[id]));
415
+ return hasConfiguredSecretInput$1(value);
416
+ };
417
+ const topLevelConfigured = isAppIdConfigured(feishuCfg?.appId) && hasConfiguredSecretInput$1(feishuCfg?.appSecret);
418
+ const accountConfigured = Object.values(feishuCfg?.accounts ?? {}).some((account) => {
419
+ if (!account || typeof account !== "object") return false;
420
+ const hasOwnAppId = Object.prototype.hasOwnProperty.call(account, "appId");
421
+ const hasOwnAppSecret = Object.prototype.hasOwnProperty.call(account, "appSecret");
422
+ const accountAppIdConfigured = hasOwnAppId ? isAppIdConfigured(account.appId) : isAppIdConfigured(feishuCfg?.appId);
423
+ const accountSecretConfigured = hasOwnAppSecret ? hasConfiguredSecretInput$1(account.appSecret) : hasConfiguredSecretInput$1(feishuCfg?.appSecret);
424
+ return accountAppIdConfigured && accountSecretConfigured;
425
+ });
426
+ return topLevelConfigured || accountConfigured;
427
+ }
428
+ /**
429
+ * Patch feishu config at the correct location based on accountId.
430
+ * - DEFAULT_ACCOUNT_ID → writes to top-level channels.feishu
431
+ * - named account → writes to channels.feishu.accounts[accountId]
432
+ */
433
+ function patchFeishuConfig(cfg, accountId, patch) {
434
+ const feishuCfg = cfg.channels?.feishu;
435
+ if (accountId === DEFAULT_ACCOUNT_ID$1) return patchTopLevelChannelConfigSection({
436
+ cfg,
437
+ channel,
438
+ enabled: true,
439
+ patch
440
+ });
441
+ const nextAccountPatch = {
442
+ ...feishuCfg?.accounts?.[accountId],
443
+ enabled: true,
444
+ ...patch
445
+ };
446
+ return patchTopLevelChannelConfigSection({
447
+ cfg,
448
+ channel,
449
+ enabled: true,
450
+ patch: { accounts: {
451
+ ...feishuCfg?.accounts,
452
+ [accountId]: nextAccountPatch
453
+ } }
454
+ });
455
+ }
456
+ async function promptFeishuAllowFrom(params) {
457
+ const feishuCfg = params.cfg.channels?.feishu;
458
+ const resolvedAccountId = params.accountId ?? resolveDefaultFeishuAccountId(params.cfg);
459
+ const existingAllowFrom = (resolvedAccountId !== DEFAULT_ACCOUNT_ID$1 ? feishuCfg?.accounts?.[resolvedAccountId] : void 0)?.allowFrom ?? feishuCfg?.allowFrom ?? [];
460
+ await params.prompter.note([
461
+ "Allowlist Feishu DMs by open_id or user_id.",
462
+ "You can find user open_id in Feishu admin console or via API.",
463
+ "Examples:",
464
+ "- ou_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
465
+ "- on_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
466
+ ].join("\n"), "Feishu allowlist");
467
+ const mergedAllowFrom = mergeAllowFromEntries(existingAllowFrom, splitSetupEntries(await params.prompter.text({
468
+ message: "Feishu allowFrom (user open_ids)",
469
+ placeholder: "ou_xxxxx, ou_yyyyy",
470
+ initialValue: existingAllowFrom.length > 0 ? existingAllowFrom.map(String).join(", ") : void 0
471
+ })));
472
+ return patchFeishuConfig(params.cfg, resolvedAccountId, { allowFrom: mergedAllowFrom });
473
+ }
474
+ async function noteFeishuCredentialHelp(prompter) {
475
+ await prompter.note([
476
+ "1) Go to Feishu Open Platform (open.feishu.cn)",
477
+ "2) Create a self-built app",
478
+ "3) Get App ID and App Secret from Credentials page",
479
+ "4) Enable required permissions: im:message, im:chat, contact:user.base:readonly",
480
+ "5) Publish the app or add it to a test group",
481
+ "Tip: you can also set FEISHU_APP_ID / FEISHU_APP_SECRET env vars.",
482
+ `Docs: ${formatDocsLink("/channels/feishu", "feishu")}`
483
+ ].join("\n"), "Feishu credentials");
484
+ }
485
+ async function promptFeishuAppId(params) {
486
+ return (await params.prompter.text({
487
+ message: "Enter Feishu App ID",
488
+ initialValue: params.initialValue,
489
+ validate: (value) => value?.trim() ? void 0 : "Required"
490
+ })).trim();
491
+ }
492
+ const feishuDmPolicy = {
493
+ label: "Feishu",
494
+ channel,
495
+ policyKey: "channels.feishu.dmPolicy",
496
+ allowFromKey: "channels.feishu.allowFrom",
497
+ resolveConfigKeys: (_cfg, accountId) => {
498
+ const resolvedAccountId = accountId ?? resolveDefaultFeishuAccountId(_cfg);
499
+ return resolvedAccountId !== DEFAULT_ACCOUNT_ID$1 ? {
500
+ policyKey: `channels.feishu.accounts.${resolvedAccountId}.dmPolicy`,
501
+ allowFromKey: `channels.feishu.accounts.${resolvedAccountId}.allowFrom`
502
+ } : {
503
+ policyKey: "channels.feishu.dmPolicy",
504
+ allowFromKey: "channels.feishu.allowFrom"
505
+ };
506
+ },
507
+ getCurrent: (cfg, accountId) => {
508
+ const feishuCfg = cfg.channels?.feishu;
509
+ const resolvedAccountId = accountId ?? resolveDefaultFeishuAccountId(cfg);
510
+ if (resolvedAccountId !== DEFAULT_ACCOUNT_ID$1) {
511
+ const account = feishuCfg?.accounts?.[resolvedAccountId];
512
+ if (account?.dmPolicy) return account.dmPolicy;
513
+ }
514
+ return feishuCfg?.dmPolicy ?? "pairing";
515
+ },
516
+ setPolicy: (cfg, policy, accountId) => {
517
+ return patchFeishuConfig(cfg, accountId ?? resolveDefaultFeishuAccountId(cfg), {
518
+ dmPolicy: policy,
519
+ ...policy === "open" ? { allowFrom: mergeAllowFromEntries([], ["*"]) } : {}
520
+ });
521
+ },
522
+ promptAllowFrom: promptFeishuAllowFrom
523
+ };
524
+ function applyNewAppSecurityPolicy(cfg, accountId, openId, groupPolicy) {
525
+ let next = cfg;
526
+ if (openId) next = patchFeishuConfig(next, accountId, {
527
+ dmPolicy: "allowlist",
528
+ allowFrom: [openId]
529
+ });
530
+ const groupPatch = { groupPolicy };
531
+ if (groupPolicy === "open") groupPatch.requireMention = true;
532
+ next = patchFeishuConfig(next, accountId, groupPatch);
533
+ return next;
534
+ }
535
+ async function runScanToCreate(prompter) {
536
+ const { beginAppRegistration, initAppRegistration, pollAppRegistration, printQrCode } = await import("./app-registration-B8qc1MCM.js");
537
+ try {
538
+ await initAppRegistration("feishu");
539
+ } catch {
540
+ await prompter.note("Scan-to-create is not available in this environment. Falling back to manual input.", "Feishu setup");
541
+ return null;
542
+ }
543
+ const begin = await beginAppRegistration("feishu");
544
+ await prompter.note("Scan the QR with Lark/Feishu on your phone.", "Feishu scan-to-create");
545
+ await printQrCode(begin.qrUrl);
546
+ const progress = prompter.progress("Fetching configuration results...");
547
+ const outcome = await pollAppRegistration({
548
+ deviceCode: begin.deviceCode,
549
+ interval: begin.interval,
550
+ expireIn: begin.expireIn,
551
+ initialDomain: "feishu",
552
+ tp: "ob_app"
553
+ });
554
+ switch (outcome.status) {
555
+ case "success":
556
+ progress.stop("Scan completed.");
557
+ return outcome.result;
558
+ case "access_denied":
559
+ progress.stop("User denied authorization. Falling back to manual input.");
560
+ return null;
561
+ case "expired":
562
+ progress.stop("Session expired. Falling back to manual input.");
563
+ return null;
564
+ case "timeout":
565
+ progress.stop("Scan timed out. Falling back to manual input.");
566
+ return null;
567
+ case "error":
568
+ progress.stop(`Registration error: ${outcome.message}. Falling back to manual input.`);
569
+ return null;
570
+ }
571
+ return null;
572
+ }
573
+ async function runNewAppFlow(params) {
574
+ const { prompter, options } = params;
575
+ let next = params.cfg;
576
+ const targetAccountId = resolveDefaultFeishuAccountId(next);
577
+ let appId = null;
578
+ let appSecret = null;
579
+ let appSecretProbeValue = null;
580
+ let scanDomain;
581
+ let scanOpenId;
582
+ const scanResult = await runScanToCreate(prompter);
583
+ if (scanResult) {
584
+ appId = scanResult.appId;
585
+ appSecret = scanResult.appSecret;
586
+ appSecretProbeValue = scanResult.appSecret;
587
+ scanDomain = scanResult.domain;
588
+ scanOpenId = scanResult.openId;
589
+ } else {
590
+ const feishuCfg = next.channels?.feishu;
591
+ await noteFeishuCredentialHelp(prompter);
592
+ const currentDomain = feishuCfg?.domain ?? "feishu";
593
+ scanDomain = await prompter.select({
594
+ message: "Which Feishu domain?",
595
+ options: [{
596
+ value: "feishu",
597
+ label: "Feishu (feishu.cn) - China"
598
+ }, {
599
+ value: "lark",
600
+ label: "Lark (larksuite.com) - International"
601
+ }],
602
+ initialValue: currentDomain
603
+ });
604
+ appId = await promptFeishuAppId({
605
+ prompter,
606
+ initialValue: normalizeString(process.env.FEISHU_APP_ID)
607
+ });
608
+ const appSecretResult = await promptSingleChannelSecretInput({
609
+ cfg: next,
610
+ prompter,
611
+ providerHint: "feishu",
612
+ credentialLabel: "App Secret",
613
+ secretInputMode: options?.secretInputMode,
614
+ accountConfigured: false,
615
+ canUseEnv: false,
616
+ hasConfigToken: false,
617
+ envPrompt: "",
618
+ keepPrompt: "Feishu App Secret already configured. Keep it?",
619
+ inputPrompt: "Enter Feishu App Secret",
620
+ preferredEnvVar: "FEISHU_APP_SECRET"
621
+ });
622
+ if (appSecretResult.action === "set") {
623
+ appSecret = appSecretResult.value;
624
+ appSecretProbeValue = appSecretResult.resolvedValue;
625
+ }
626
+ if (appId && appSecretProbeValue) {
627
+ const { getAppOwnerOpenId } = await import("./app-registration-B8qc1MCM.js");
628
+ scanOpenId = await getAppOwnerOpenId({
629
+ appId,
630
+ appSecret: appSecretProbeValue,
631
+ domain: scanDomain
632
+ });
633
+ }
634
+ }
635
+ const groupPolicy = await prompter.select({
636
+ message: "Group chat policy",
637
+ options: [
638
+ {
639
+ value: "allowlist",
640
+ label: "Allowlist - only respond in specific groups"
641
+ },
642
+ {
643
+ value: "open",
644
+ label: "Open - respond in all groups (requires mention)"
645
+ },
646
+ {
647
+ value: "disabled",
648
+ label: "Disabled - don't respond in groups"
649
+ }
650
+ ],
651
+ initialValue: "allowlist"
652
+ });
653
+ const configProgress = prompter.progress("Configuring...");
654
+ await new Promise((resolve) => setTimeout(resolve, 50));
655
+ if (appId && appSecret) next = patchFeishuConfig(next, targetAccountId, {
656
+ appId,
657
+ appSecret,
658
+ connectionMode: "websocket",
659
+ ...scanDomain ? { domain: scanDomain } : {}
660
+ });
661
+ else if (scanDomain) next = patchFeishuConfig(next, targetAccountId, { domain: scanDomain });
662
+ next = applyNewAppSecurityPolicy(next, targetAccountId, scanOpenId, groupPolicy);
663
+ configProgress.stop("Bot configured.");
664
+ return { cfg: next };
665
+ }
666
+ async function runEditFlow(params) {
667
+ const { prompter, options } = params;
668
+ const next = params.cfg;
669
+ const feishuCfg = next.channels?.feishu;
670
+ const resolveAppIdLabel = (value) => {
671
+ const asString = normalizeString(value);
672
+ if (asString) return asString;
673
+ if (value && typeof value === "object") {
674
+ const rec = value;
675
+ if (normalizeString(rec.source) && normalizeString(rec.id)) return normalizeString(process.env[rec.id]) ?? `env:${String(rec.id)}`;
676
+ if (hasConfiguredSecretInput$1(value)) return "(configured)";
677
+ }
678
+ };
679
+ const existingAppId = resolveAppIdLabel(feishuCfg?.appId) ?? Object.values(feishuCfg?.accounts ?? {}).reduce((found, account) => {
680
+ if (found) return found;
681
+ if (account && typeof account === "object") return resolveAppIdLabel(account.appId);
682
+ }, void 0);
683
+ if (existingAppId) {
684
+ if (!await prompter.confirm({
685
+ message: `We found an existing bot (App ID: ${existingAppId}). Use it for this setup?`,
686
+ initialValue: true
687
+ })) return runNewAppFlow({
688
+ cfg: next,
689
+ prompter,
690
+ options
691
+ });
692
+ } else return runNewAppFlow({
693
+ cfg: next,
694
+ prompter,
695
+ options
696
+ });
697
+ await prompter.note("Bot configured.", "");
698
+ return { cfg: next };
699
+ }
700
+ async function runFeishuLogin(params) {
701
+ const { cfg, prompter } = params;
702
+ const options = {};
703
+ if (isFeishuConfigured(cfg)) {
704
+ const result = await runEditFlow({
705
+ cfg,
706
+ prompter,
707
+ options
708
+ });
709
+ if (result === null) return cfg;
710
+ return result.cfg;
711
+ }
712
+ return (await runNewAppFlow({
713
+ cfg,
714
+ prompter,
715
+ options
716
+ })).cfg;
717
+ }
718
+ const feishuSetupWizard = {
719
+ channel,
720
+ resolveAccountIdForConfigure: ({ accountOverride, defaultAccountId, cfg }) => (typeof accountOverride === "string" && accountOverride.trim() ? accountOverride.trim() : void 0) ?? resolveDefaultFeishuAccountId(cfg) ?? defaultAccountId,
721
+ resolveShouldPromptAccountIds: () => false,
722
+ status: {
723
+ configuredLabel: "configured",
724
+ unconfiguredLabel: "needs app credentials",
725
+ configuredHint: "configured",
726
+ unconfiguredHint: "needs app creds",
727
+ configuredScore: 2,
728
+ unconfiguredScore: 0,
729
+ resolveConfigured: ({ cfg }) => isFeishuConfigured(cfg),
730
+ resolveStatusLines: async ({ cfg, accountId, configured }) => {
731
+ const account = resolveFeishuAccount({
732
+ cfg,
733
+ accountId
734
+ });
735
+ let probeResult = null;
736
+ if (configured && account.configured) try {
737
+ const { probeFeishu } = await import("./probe-BNzzU_uR.js").then((n) => n.n);
738
+ probeResult = await probeFeishu(account);
739
+ } catch {}
740
+ if (!configured) return ["Feishu: needs app credentials"];
741
+ if (probeResult?.ok) return [`Feishu: connected as ${probeResult.botName ?? probeResult.botOpenId ?? "bot"}`];
742
+ return ["Feishu: configured (connection not verified)"];
743
+ }
744
+ },
745
+ prepare: async ({ cfg, credentialValues }) => {
746
+ if (isFeishuConfigured(cfg)) return { credentialValues: {
747
+ ...credentialValues,
748
+ _flow: "edit"
749
+ } };
750
+ return { credentialValues: {
751
+ ...credentialValues,
752
+ _flow: "new"
753
+ } };
754
+ },
755
+ credentials: [],
756
+ finalize: async ({ cfg, prompter, options, credentialValues }) => {
757
+ if ((credentialValues._flow ?? "new") === "edit") {
758
+ const result = await runEditFlow({
759
+ cfg,
760
+ prompter,
761
+ options
762
+ });
763
+ if (result === null) return { cfg };
764
+ return result;
765
+ }
766
+ return runNewAppFlow({
767
+ cfg,
768
+ prompter,
769
+ options
770
+ });
771
+ },
772
+ dmPolicy: feishuDmPolicy,
773
+ disable: (cfg) => patchTopLevelChannelConfigSection({
774
+ cfg,
775
+ channel,
776
+ patch: { enabled: false }
777
+ })
778
+ };
779
+ //#endregion
780
+ //#region extensions/feishu/src/channel.ts
781
+ function readFeishuMediaParam(params) {
782
+ const media = params.media;
783
+ if (typeof media !== "string") return;
784
+ return media.trim() ? media : void 0;
785
+ }
786
+ function readBooleanParam(params, keys) {
787
+ for (const key of keys) {
788
+ const value = params[key];
789
+ if (typeof value === "boolean") return value;
790
+ }
791
+ }
792
+ function hasLegacyFeishuCardCommandValue(actionValue) {
793
+ return isRecord$1(actionValue) && actionValue.oc !== "ocf1" && (Boolean(typeof actionValue.command === "string" && actionValue.command.trim()) || Boolean(typeof actionValue.text === "string" && actionValue.text.trim()));
794
+ }
795
+ function containsLegacyFeishuCardCommandValue(node) {
796
+ if (Array.isArray(node)) return node.some((item) => containsLegacyFeishuCardCommandValue(item));
797
+ if (!isRecord$1(node)) return false;
798
+ if (node.tag === "button" && hasLegacyFeishuCardCommandValue(node.value)) return true;
799
+ return Object.values(node).some((value) => containsLegacyFeishuCardCommandValue(value));
800
+ }
801
+ const meta = {
802
+ id: "feishu",
803
+ label: "Feishu",
804
+ selectionLabel: "Feishu/Lark (飞书)",
805
+ docsPath: "/channels/feishu",
806
+ docsLabel: "feishu",
807
+ blurb: "飞书/Lark enterprise messaging.",
808
+ aliases: ["lark"],
809
+ order: 70
810
+ };
811
+ const loadFeishuChannelRuntime = createLazyRuntimeNamedExport(() => import("./channel.runtime-DYsXcD36.js"), "feishuChannelRuntime");
812
+ function buildFeishuPresentationCard(params) {
813
+ const fallbackPresentation = {
814
+ ...params.presentation.tone ? { tone: params.presentation.tone } : {},
815
+ blocks: params.presentation.blocks
816
+ };
817
+ return {
818
+ schema: "2.0",
819
+ config: { width_mode: "fill" },
820
+ ...params.presentation.title ? { header: {
821
+ title: {
822
+ tag: "plain_text",
823
+ content: params.presentation.title
824
+ },
825
+ template: "blue"
826
+ } } : {},
827
+ body: { elements: [{
828
+ tag: "markdown",
829
+ content: renderMessagePresentationFallbackText({
830
+ text: params.fallbackText,
831
+ presentation: fallbackPresentation
832
+ })
833
+ }] }
834
+ };
835
+ }
836
+ async function createFeishuActionClient(account) {
837
+ const { createFeishuClient } = await import("./client-DBVoQL5w.js").then((n) => n.t);
838
+ return createFeishuClient(account);
839
+ }
840
+ const collectFeishuSecurityWarnings = createAllowlistProviderGroupPolicyWarningCollector({
841
+ providerConfigPresent: (cfg) => cfg.channels?.feishu !== void 0,
842
+ resolveGroupPolicy: ({ cfg, accountId }) => resolveFeishuAccount({
843
+ cfg,
844
+ accountId
845
+ }).config?.groupPolicy,
846
+ collect: ({ cfg, accountId, groupPolicy }) => {
847
+ if (groupPolicy !== "open") return [];
848
+ return [`- Feishu[${resolveFeishuAccount({
849
+ cfg,
850
+ accountId
851
+ }).accountId}] groups: groupPolicy="open" allows any member to trigger (mention-gated). Set channels.feishu.groupPolicy="allowlist" + channels.feishu.groupAllowFrom to restrict senders.`];
852
+ }
853
+ });
854
+ function describeFeishuMessageTool({ cfg, accountId }) {
855
+ const enabledAccounts = accountId ? [resolveFeishuAccount({
856
+ cfg,
857
+ accountId
858
+ })].filter((account) => account.enabled && account.configured) : listEnabledFeishuAccounts(cfg);
859
+ const enabled = enabledAccounts.length > 0 || !accountId && cfg.channels?.feishu?.enabled !== false && Boolean(inspectFeishuCredentials(cfg.channels?.feishu));
860
+ if (enabledAccounts.length === 0) return {
861
+ actions: [],
862
+ capabilities: enabled ? ["presentation"] : []
863
+ };
864
+ const actions = new Set([
865
+ "send",
866
+ "read",
867
+ "edit",
868
+ "thread-reply",
869
+ "pin",
870
+ "list-pins",
871
+ "unpin",
872
+ "member-info",
873
+ "channel-info",
874
+ "channel-list"
875
+ ]);
876
+ if (accountId ? enabledAccounts.some((account) => isFeishuReactionsActionEnabled({
877
+ cfg,
878
+ account
879
+ })) : areAnyFeishuReactionActionsEnabled(cfg)) {
880
+ actions.add("react");
881
+ actions.add("reactions");
882
+ }
883
+ return {
884
+ actions: Array.from(actions),
885
+ capabilities: enabled ? ["presentation"] : []
886
+ };
887
+ }
888
+ function setFeishuNamedAccountEnabled(cfg, accountId, enabled) {
889
+ const feishuCfg = cfg.channels?.feishu;
890
+ return {
891
+ ...cfg,
892
+ channels: {
893
+ ...cfg.channels,
894
+ feishu: {
895
+ ...feishuCfg,
896
+ accounts: {
897
+ ...feishuCfg?.accounts,
898
+ [accountId]: {
899
+ ...feishuCfg?.accounts?.[accountId],
900
+ enabled
901
+ }
902
+ }
903
+ }
904
+ }
905
+ };
906
+ }
907
+ const feishuConfigAdapter = createHybridChannelConfigAdapter({
908
+ sectionKey: "feishu",
909
+ listAccountIds: listFeishuAccountIds,
910
+ resolveAccount: adaptScopedAccountAccessor(resolveFeishuAccount),
911
+ defaultAccountId: resolveDefaultFeishuAccountId,
912
+ clearBaseFields: [],
913
+ resolveAllowFrom: (account) => account.config.allowFrom,
914
+ formatAllowFrom: (allowFrom) => formatAllowFromLowercase({ allowFrom })
915
+ });
916
+ function isFeishuReactionsActionEnabled(params) {
917
+ if (!params.account.enabled || !params.account.configured) return false;
918
+ return createActionGate(params.account.config.actions ?? (params.cfg.channels?.feishu)?.actions)("reactions");
919
+ }
920
+ function areAnyFeishuReactionActionsEnabled(cfg) {
921
+ for (const account of listEnabledFeishuAccounts(cfg)) if (isFeishuReactionsActionEnabled({
922
+ cfg,
923
+ account
924
+ })) return true;
925
+ return false;
926
+ }
927
+ function isSupportedFeishuDirectConversationId(conversationId) {
928
+ const trimmed = conversationId.trim();
929
+ if (!trimmed || trimmed.includes(":")) return false;
930
+ if (trimmed.startsWith("oc_") || trimmed.startsWith("on_")) return false;
931
+ return true;
932
+ }
933
+ function normalizeFeishuAcpConversationId(conversationId) {
934
+ const parsed = parseFeishuConversationId({ conversationId });
935
+ if (!parsed || parsed.scope !== "group_topic" && parsed.scope !== "group_topic_sender" && !isSupportedFeishuDirectConversationId(parsed.canonicalConversationId)) return null;
936
+ return {
937
+ conversationId: parsed.canonicalConversationId,
938
+ parentConversationId: parsed.scope === "group_topic" || parsed.scope === "group_topic_sender" ? parsed.chatId : void 0
939
+ };
940
+ }
941
+ function matchFeishuAcpConversation(params) {
942
+ const binding = normalizeFeishuAcpConversationId(params.bindingConversationId);
943
+ if (!binding) return null;
944
+ const incoming = parseFeishuConversationId({
945
+ conversationId: params.conversationId,
946
+ parentConversationId: params.parentConversationId
947
+ });
948
+ if (!incoming || incoming.scope !== "group_topic" && incoming.scope !== "group_topic_sender" && !isSupportedFeishuDirectConversationId(incoming.canonicalConversationId)) return null;
949
+ const matchesCanonicalConversation = binding.conversationId === incoming.canonicalConversationId;
950
+ const matchesParentTopicForSenderScopedConversation = incoming.scope === "group_topic_sender" && binding.parentConversationId === incoming.chatId && binding.conversationId === `${incoming.chatId}:topic:${incoming.topicId}`;
951
+ if (!matchesCanonicalConversation && !matchesParentTopicForSenderScopedConversation) return null;
952
+ return {
953
+ conversationId: matchesParentTopicForSenderScopedConversation ? binding.conversationId : incoming.canonicalConversationId,
954
+ parentConversationId: incoming.scope === "group_topic" || incoming.scope === "group_topic_sender" ? incoming.chatId : void 0,
955
+ matchPriority: matchesCanonicalConversation ? 2 : 1
956
+ };
957
+ }
958
+ function resolveFeishuSenderScopedCommandConversation(params) {
959
+ const parentConversationId = params.parentConversationId?.trim();
960
+ const threadId = params.threadId?.trim();
961
+ const senderId = params.senderId?.trim();
962
+ if (!parentConversationId || !threadId || !senderId) return;
963
+ const expectedScopePrefix = `feishu:group:${normalizeLowercaseStringOrEmpty(parentConversationId)}:topic:${normalizeLowercaseStringOrEmpty(threadId)}:sender:`;
964
+ const isSenderScopedSession = [params.sessionKey, params.parentSessionKey].some((candidate) => {
965
+ const normalized = normalizeLowercaseStringOrEmpty(candidate ?? "");
966
+ if (!normalized) return false;
967
+ return normalized.replace(/^agent:[^:]+:/, "").startsWith(expectedScopePrefix);
968
+ });
969
+ const senderScopedConversationId = buildFeishuConversationId({
970
+ chatId: parentConversationId,
971
+ scope: "group_topic_sender",
972
+ topicId: threadId,
973
+ senderOpenId: senderId
974
+ });
975
+ if (isSenderScopedSession) return senderScopedConversationId;
976
+ if (!params.sessionKey?.trim()) return;
977
+ return getSessionBindingService().listBySession(params.sessionKey).find((binding) => {
978
+ if (binding.conversation.channel !== "feishu" || binding.conversation.accountId !== params.accountId) return false;
979
+ return binding.conversation.conversationId === senderScopedConversationId;
980
+ })?.conversation.conversationId;
981
+ }
982
+ function resolveFeishuCommandConversation(params) {
983
+ if (params.threadId) {
984
+ const parentConversationId = parseFeishuTargetId(params.originatingTo) ?? parseFeishuTargetId(params.commandTo) ?? parseFeishuTargetId(params.fallbackTo);
985
+ if (!parentConversationId) return null;
986
+ return {
987
+ conversationId: resolveFeishuSenderScopedCommandConversation({
988
+ accountId: params.accountId,
989
+ parentConversationId,
990
+ threadId: params.threadId,
991
+ senderId: params.senderId,
992
+ sessionKey: params.sessionKey,
993
+ parentSessionKey: params.parentSessionKey
994
+ }) ?? buildFeishuConversationId({
995
+ chatId: parentConversationId,
996
+ scope: "group_topic",
997
+ topicId: params.threadId
998
+ }),
999
+ parentConversationId
1000
+ };
1001
+ }
1002
+ const conversationId = parseFeishuDirectConversationId(params.originatingTo) ?? parseFeishuDirectConversationId(params.commandTo) ?? parseFeishuDirectConversationId(params.fallbackTo);
1003
+ return conversationId ? { conversationId } : null;
1004
+ }
1005
+ function jsonActionResult(details) {
1006
+ return {
1007
+ content: [{
1008
+ type: "text",
1009
+ text: JSON.stringify(details)
1010
+ }],
1011
+ details
1012
+ };
1013
+ }
1014
+ function readFirstString(params, keys, fallback) {
1015
+ for (const key of keys) {
1016
+ const value = params[key];
1017
+ if (typeof value === "string" && value.trim()) return value.trim();
1018
+ }
1019
+ if (typeof fallback === "string" && fallback.trim()) return fallback.trim();
1020
+ }
1021
+ function readOptionalNumber(params, keys) {
1022
+ for (const key of keys) {
1023
+ const value = params[key];
1024
+ if (typeof value === "number" && Number.isFinite(value)) return value;
1025
+ if (typeof value === "string" && value.trim()) {
1026
+ const parsed = Number(value);
1027
+ if (Number.isFinite(parsed)) return parsed;
1028
+ }
1029
+ }
1030
+ }
1031
+ function resolveFeishuActionTarget(ctx) {
1032
+ return readFirstString(ctx.params, ["to", "target"], ctx.toolContext?.currentChannelId);
1033
+ }
1034
+ function resolveFeishuChatId(ctx) {
1035
+ const raw = readFirstString(ctx.params, [
1036
+ "chatId",
1037
+ "chat_id",
1038
+ "channelId",
1039
+ "channel_id",
1040
+ "to",
1041
+ "target"
1042
+ ], ctx.toolContext?.currentChannelId);
1043
+ if (!raw) return;
1044
+ if (/^(user|dm|open_id):/i.test(raw)) return;
1045
+ if (/^(chat|group|channel):/i.test(raw)) return normalizeFeishuTarget(raw) ?? void 0;
1046
+ return raw;
1047
+ }
1048
+ function resolveFeishuMessageId(params) {
1049
+ return readFirstString(params, [
1050
+ "messageId",
1051
+ "message_id",
1052
+ "replyTo",
1053
+ "reply_to"
1054
+ ]);
1055
+ }
1056
+ function resolveFeishuMemberId(params) {
1057
+ return readFirstString(params, [
1058
+ "memberId",
1059
+ "member_id",
1060
+ "userId",
1061
+ "user_id",
1062
+ "openId",
1063
+ "open_id",
1064
+ "unionId",
1065
+ "union_id"
1066
+ ]);
1067
+ }
1068
+ function resolveFeishuMemberIdType(params) {
1069
+ const raw = readFirstString(params, [
1070
+ "memberIdType",
1071
+ "member_id_type",
1072
+ "userIdType",
1073
+ "user_id_type"
1074
+ ]);
1075
+ if (raw === "open_id" || raw === "user_id" || raw === "union_id") return raw;
1076
+ if (readFirstString(params, ["userId", "user_id"]) && !readFirstString(params, [
1077
+ "openId",
1078
+ "open_id",
1079
+ "unionId",
1080
+ "union_id"
1081
+ ])) return "user_id";
1082
+ if (readFirstString(params, ["unionId", "union_id"]) && !readFirstString(params, ["openId", "open_id"])) return "union_id";
1083
+ return "open_id";
1084
+ }
1085
+ const feishuPlugin = createChatChannelPlugin({
1086
+ base: {
1087
+ id: "feishu",
1088
+ meta: { ...meta },
1089
+ capabilities: {
1090
+ chatTypes: ["direct", "channel"],
1091
+ polls: false,
1092
+ threads: true,
1093
+ media: true,
1094
+ tts: { voice: {
1095
+ synthesisTarget: "voice-note",
1096
+ transcodesAudio: true
1097
+ } },
1098
+ reactions: true,
1099
+ edit: true,
1100
+ reply: true
1101
+ },
1102
+ agentPrompt: { messageToolHints: () => [
1103
+ "- Feishu targeting: omit `target` to reply to the current conversation (auto-inferred). Explicit targets: `user:open_id` or `chat:chat_id`.",
1104
+ "- Feishu supports interactive cards plus native image, file, audio, and video/media delivery.",
1105
+ "- Feishu supports `send`, `read`, `edit`, `thread-reply`, pins, and channel/member lookup, plus reactions when enabled."
1106
+ ] },
1107
+ groups: { resolveToolPolicy: resolveFeishuGroupToolPolicy },
1108
+ conversationBindings: {
1109
+ defaultTopLevelPlacement: "current",
1110
+ buildModelOverrideParentCandidates: ({ parentConversationId }) => buildFeishuModelOverrideParentCandidates(parentConversationId)
1111
+ },
1112
+ mentions: { stripPatterns: () => ["<at user_id=\"[^\"]*\">[^<]*</at>"] },
1113
+ reload: { configPrefixes: ["channels.feishu"] },
1114
+ configSchema: buildChannelConfigSchema(FeishuConfigSchema),
1115
+ config: {
1116
+ ...feishuConfigAdapter,
1117
+ setAccountEnabled: ({ cfg, accountId, enabled }) => {
1118
+ if (accountId === DEFAULT_ACCOUNT_ID$2) return {
1119
+ ...cfg,
1120
+ channels: {
1121
+ ...cfg.channels,
1122
+ feishu: {
1123
+ ...cfg.channels?.feishu,
1124
+ enabled
1125
+ }
1126
+ }
1127
+ };
1128
+ return setFeishuNamedAccountEnabled(cfg, accountId, enabled);
1129
+ },
1130
+ deleteAccount: ({ cfg, accountId }) => {
1131
+ if (accountId === DEFAULT_ACCOUNT_ID$2) {
1132
+ const next = { ...cfg };
1133
+ const nextChannels = { ...cfg.channels };
1134
+ delete nextChannels.feishu;
1135
+ if (Object.keys(nextChannels).length > 0) next.channels = nextChannels;
1136
+ else delete next.channels;
1137
+ return next;
1138
+ }
1139
+ const feishuCfg = cfg.channels?.feishu;
1140
+ const accounts = { ...feishuCfg?.accounts };
1141
+ delete accounts[accountId];
1142
+ return {
1143
+ ...cfg,
1144
+ channels: {
1145
+ ...cfg.channels,
1146
+ feishu: {
1147
+ ...feishuCfg,
1148
+ accounts: Object.keys(accounts).length > 0 ? accounts : void 0
1149
+ }
1150
+ }
1151
+ };
1152
+ },
1153
+ isConfigured: (account) => account.configured,
1154
+ describeAccount: (account) => describeAccountSnapshot({
1155
+ account,
1156
+ configured: account.configured,
1157
+ extra: {
1158
+ appId: account.appId,
1159
+ domain: account.domain
1160
+ }
1161
+ })
1162
+ },
1163
+ approvalCapability: feishuApprovalAuth,
1164
+ secrets: {
1165
+ secretTargetRegistryEntries,
1166
+ collectRuntimeConfigAssignments
1167
+ },
1168
+ actions: {
1169
+ messageActionTargetAliases,
1170
+ describeMessageTool: describeFeishuMessageTool,
1171
+ handleAction: async (ctx) => {
1172
+ const account = resolveFeishuAccount({
1173
+ cfg: ctx.cfg,
1174
+ accountId: ctx.accountId ?? void 0
1175
+ });
1176
+ if ((ctx.action === "react" || ctx.action === "reactions") && !isFeishuReactionsActionEnabled({
1177
+ cfg: ctx.cfg,
1178
+ account
1179
+ })) throw new Error("Feishu reactions are disabled via actions.reactions.");
1180
+ if (ctx.action === "send" || ctx.action === "thread-reply") {
1181
+ const to = resolveFeishuActionTarget(ctx);
1182
+ if (!to) throw new Error(`Feishu ${ctx.action} requires a target (to).`);
1183
+ const replyToMessageId = ctx.action === "thread-reply" ? resolveFeishuMessageId(ctx.params) : void 0;
1184
+ if (ctx.action === "thread-reply" && !replyToMessageId) throw new Error("Feishu thread-reply requires messageId.");
1185
+ const presentation = normalizeMessagePresentation(ctx.params.presentation);
1186
+ const text = readFirstString(ctx.params, ["text", "message"]);
1187
+ const mediaUrl = readFeishuMediaParam(ctx.params);
1188
+ const audioAsVoice = readBooleanParam(ctx.params, ["asVoice", "audioAsVoice"]);
1189
+ const card = presentation ? buildFeishuPresentationCard({
1190
+ presentation,
1191
+ fallbackText: text
1192
+ }) : void 0;
1193
+ if (card && mediaUrl) throw new Error(`Feishu ${ctx.action} does not support card with media.`);
1194
+ if (!card && !text && !mediaUrl) throw new Error(`Feishu ${ctx.action} requires text/message, media, or card.`);
1195
+ const runtime = await loadFeishuChannelRuntime();
1196
+ const maybeSendMedia = runtime.feishuOutbound.sendMedia;
1197
+ if (mediaUrl && !maybeSendMedia) throw new Error("Feishu media sending is not available.");
1198
+ const sendMedia = maybeSendMedia;
1199
+ let result;
1200
+ if (card) {
1201
+ if (containsLegacyFeishuCardCommandValue(card)) throw new Error("Feishu card buttons that trigger text or commands must use structured interaction envelopes.");
1202
+ result = await runtime.sendCardFeishu({
1203
+ cfg: ctx.cfg,
1204
+ to,
1205
+ card,
1206
+ accountId: ctx.accountId ?? void 0,
1207
+ replyToMessageId,
1208
+ replyInThread: ctx.action === "thread-reply"
1209
+ });
1210
+ } else if (mediaUrl) result = await sendMedia({
1211
+ cfg: ctx.cfg,
1212
+ to,
1213
+ text: text ?? "",
1214
+ mediaUrl,
1215
+ accountId: ctx.accountId ?? void 0,
1216
+ mediaLocalRoots: ctx.mediaLocalRoots,
1217
+ replyToId: replyToMessageId,
1218
+ ...audioAsVoice === true ? { audioAsVoice: true } : {}
1219
+ });
1220
+ else result = await runtime.sendMessageFeishu({
1221
+ cfg: ctx.cfg,
1222
+ to,
1223
+ text,
1224
+ accountId: ctx.accountId ?? void 0,
1225
+ replyToMessageId,
1226
+ replyInThread: ctx.action === "thread-reply"
1227
+ });
1228
+ return jsonActionResult({
1229
+ ok: true,
1230
+ channel: "feishu",
1231
+ action: ctx.action,
1232
+ ...result
1233
+ });
1234
+ }
1235
+ if (ctx.action === "read") {
1236
+ const messageId = resolveFeishuMessageId(ctx.params);
1237
+ if (!messageId) throw new Error("Feishu read requires messageId.");
1238
+ const { getMessageFeishu } = await loadFeishuChannelRuntime();
1239
+ const message = await getMessageFeishu({
1240
+ cfg: ctx.cfg,
1241
+ messageId,
1242
+ accountId: ctx.accountId ?? void 0
1243
+ });
1244
+ if (!message) return {
1245
+ isError: true,
1246
+ content: [{
1247
+ type: "text",
1248
+ text: JSON.stringify({ error: `Feishu read failed or message not found: ${messageId}` })
1249
+ }],
1250
+ details: { error: `Feishu read failed or message not found: ${messageId}` }
1251
+ };
1252
+ return jsonActionResult({
1253
+ ok: true,
1254
+ channel: "feishu",
1255
+ action: "read",
1256
+ message
1257
+ });
1258
+ }
1259
+ if (ctx.action === "edit") {
1260
+ const messageId = resolveFeishuMessageId(ctx.params);
1261
+ if (!messageId) throw new Error("Feishu edit requires messageId.");
1262
+ const text = readFirstString(ctx.params, ["text", "message"]);
1263
+ const card = ctx.params.card && typeof ctx.params.card === "object" ? ctx.params.card : void 0;
1264
+ const { editMessageFeishu } = await loadFeishuChannelRuntime();
1265
+ return jsonActionResult({
1266
+ ok: true,
1267
+ channel: "feishu",
1268
+ action: "edit",
1269
+ ...await editMessageFeishu({
1270
+ cfg: ctx.cfg,
1271
+ messageId,
1272
+ text,
1273
+ card,
1274
+ accountId: ctx.accountId ?? void 0
1275
+ })
1276
+ });
1277
+ }
1278
+ if (ctx.action === "pin") {
1279
+ const messageId = resolveFeishuMessageId(ctx.params);
1280
+ if (!messageId) throw new Error("Feishu pin requires messageId.");
1281
+ const { createPinFeishu } = await loadFeishuChannelRuntime();
1282
+ return jsonActionResult({
1283
+ ok: true,
1284
+ channel: "feishu",
1285
+ action: "pin",
1286
+ pin: await createPinFeishu({
1287
+ cfg: ctx.cfg,
1288
+ messageId,
1289
+ accountId: ctx.accountId ?? void 0
1290
+ })
1291
+ });
1292
+ }
1293
+ if (ctx.action === "unpin") {
1294
+ const messageId = resolveFeishuMessageId(ctx.params);
1295
+ if (!messageId) throw new Error("Feishu unpin requires messageId.");
1296
+ const { removePinFeishu } = await loadFeishuChannelRuntime();
1297
+ await removePinFeishu({
1298
+ cfg: ctx.cfg,
1299
+ messageId,
1300
+ accountId: ctx.accountId ?? void 0
1301
+ });
1302
+ return jsonActionResult({
1303
+ ok: true,
1304
+ channel: "feishu",
1305
+ action: "unpin",
1306
+ messageId
1307
+ });
1308
+ }
1309
+ if (ctx.action === "list-pins") {
1310
+ const chatId = resolveFeishuChatId(ctx);
1311
+ if (!chatId) throw new Error("Feishu list-pins requires chatId or channelId.");
1312
+ const { listPinsFeishu } = await loadFeishuChannelRuntime();
1313
+ return jsonActionResult({
1314
+ ok: true,
1315
+ channel: "feishu",
1316
+ action: "list-pins",
1317
+ ...await listPinsFeishu({
1318
+ cfg: ctx.cfg,
1319
+ chatId,
1320
+ startTime: readFirstString(ctx.params, ["startTime", "start_time"]),
1321
+ endTime: readFirstString(ctx.params, ["endTime", "end_time"]),
1322
+ pageSize: readOptionalNumber(ctx.params, ["pageSize", "page_size"]),
1323
+ pageToken: readFirstString(ctx.params, ["pageToken", "page_token"]),
1324
+ accountId: ctx.accountId ?? void 0
1325
+ })
1326
+ });
1327
+ }
1328
+ if (ctx.action === "channel-info") {
1329
+ const chatId = resolveFeishuChatId(ctx);
1330
+ if (!chatId) throw new Error("Feishu channel-info requires chatId or channelId.");
1331
+ const runtime = await loadFeishuChannelRuntime();
1332
+ const client = await createFeishuActionClient(account);
1333
+ const channel = await runtime.getChatInfo(client, chatId);
1334
+ if (!(ctx.params.includeMembers === true || ctx.params.members === true)) return jsonActionResult({
1335
+ ok: true,
1336
+ provider: "feishu",
1337
+ action: "channel-info",
1338
+ channel
1339
+ });
1340
+ return jsonActionResult({
1341
+ ok: true,
1342
+ provider: "feishu",
1343
+ action: "channel-info",
1344
+ channel,
1345
+ members: await runtime.getChatMembers(client, chatId, readOptionalNumber(ctx.params, ["pageSize", "page_size"]), readFirstString(ctx.params, ["pageToken", "page_token"]), resolveFeishuMemberIdType(ctx.params))
1346
+ });
1347
+ }
1348
+ if (ctx.action === "member-info") {
1349
+ const runtime = await loadFeishuChannelRuntime();
1350
+ const client = await createFeishuActionClient(account);
1351
+ const memberId = resolveFeishuMemberId(ctx.params);
1352
+ if (memberId) return jsonActionResult({
1353
+ ok: true,
1354
+ channel: "feishu",
1355
+ action: "member-info",
1356
+ member: await runtime.getFeishuMemberInfo(client, memberId, resolveFeishuMemberIdType(ctx.params))
1357
+ });
1358
+ const chatId = resolveFeishuChatId(ctx);
1359
+ if (!chatId) throw new Error("Feishu member-info requires memberId or chatId/channelId.");
1360
+ return jsonActionResult({
1361
+ ok: true,
1362
+ channel: "feishu",
1363
+ action: "member-info",
1364
+ ...await runtime.getChatMembers(client, chatId, readOptionalNumber(ctx.params, ["pageSize", "page_size"]), readFirstString(ctx.params, ["pageToken", "page_token"]), resolveFeishuMemberIdType(ctx.params))
1365
+ });
1366
+ }
1367
+ if (ctx.action === "channel-list") {
1368
+ const runtime = await loadFeishuChannelRuntime();
1369
+ const query = readFirstString(ctx.params, ["query"]);
1370
+ const limit = readOptionalNumber(ctx.params, ["limit"]);
1371
+ const scope = readFirstString(ctx.params, ["scope", "kind"]) ?? "all";
1372
+ if (scope === "groups" || scope === "group" || scope === "channels" || scope === "channel") return jsonActionResult({
1373
+ ok: true,
1374
+ channel: "feishu",
1375
+ action: "channel-list",
1376
+ groups: await runtime.listFeishuDirectoryGroupsLive({
1377
+ cfg: ctx.cfg,
1378
+ query,
1379
+ limit,
1380
+ fallbackToStatic: false,
1381
+ accountId: ctx.accountId ?? void 0
1382
+ })
1383
+ });
1384
+ if (scope === "peers" || scope === "peer" || scope === "members" || scope === "member" || scope === "users" || scope === "user") return jsonActionResult({
1385
+ ok: true,
1386
+ channel: "feishu",
1387
+ action: "channel-list",
1388
+ peers: await runtime.listFeishuDirectoryPeersLive({
1389
+ cfg: ctx.cfg,
1390
+ query,
1391
+ limit,
1392
+ fallbackToStatic: false,
1393
+ accountId: ctx.accountId ?? void 0
1394
+ })
1395
+ });
1396
+ const [groups, peers] = await Promise.all([runtime.listFeishuDirectoryGroupsLive({
1397
+ cfg: ctx.cfg,
1398
+ query,
1399
+ limit,
1400
+ fallbackToStatic: false,
1401
+ accountId: ctx.accountId ?? void 0
1402
+ }), runtime.listFeishuDirectoryPeersLive({
1403
+ cfg: ctx.cfg,
1404
+ query,
1405
+ limit,
1406
+ fallbackToStatic: false,
1407
+ accountId: ctx.accountId ?? void 0
1408
+ })]);
1409
+ return jsonActionResult({
1410
+ ok: true,
1411
+ channel: "feishu",
1412
+ action: "channel-list",
1413
+ groups,
1414
+ peers
1415
+ });
1416
+ }
1417
+ if (ctx.action === "react") {
1418
+ const messageId = resolveFeishuMessageId(ctx.params);
1419
+ if (!messageId) throw new Error("Feishu reaction requires messageId.");
1420
+ const emoji = typeof ctx.params.emoji === "string" ? ctx.params.emoji.trim() : "";
1421
+ const remove = ctx.params.remove === true;
1422
+ const clearAll = ctx.params.clearAll === true;
1423
+ if (remove) {
1424
+ if (!emoji) throw new Error("Emoji is required to remove a Feishu reaction.");
1425
+ const { listReactionsFeishu, removeReactionFeishu } = await loadFeishuChannelRuntime();
1426
+ const ownReaction = (await listReactionsFeishu({
1427
+ cfg: ctx.cfg,
1428
+ messageId,
1429
+ emojiType: emoji,
1430
+ accountId: ctx.accountId ?? void 0
1431
+ })).find((entry) => entry.operatorType === "app");
1432
+ if (!ownReaction) return jsonActionResult({
1433
+ ok: true,
1434
+ removed: null
1435
+ });
1436
+ await removeReactionFeishu({
1437
+ cfg: ctx.cfg,
1438
+ messageId,
1439
+ reactionId: ownReaction.reactionId,
1440
+ accountId: ctx.accountId ?? void 0
1441
+ });
1442
+ return jsonActionResult({
1443
+ ok: true,
1444
+ removed: emoji
1445
+ });
1446
+ }
1447
+ if (!emoji) {
1448
+ if (!clearAll) throw new Error("Emoji is required to add a Feishu reaction. Set clearAll=true to remove all bot reactions.");
1449
+ const { listReactionsFeishu, removeReactionFeishu } = await loadFeishuChannelRuntime();
1450
+ const reactions = await listReactionsFeishu({
1451
+ cfg: ctx.cfg,
1452
+ messageId,
1453
+ accountId: ctx.accountId ?? void 0
1454
+ });
1455
+ let removed = 0;
1456
+ for (const reaction of reactions.filter((entry) => entry.operatorType === "app")) {
1457
+ await removeReactionFeishu({
1458
+ cfg: ctx.cfg,
1459
+ messageId,
1460
+ reactionId: reaction.reactionId,
1461
+ accountId: ctx.accountId ?? void 0
1462
+ });
1463
+ removed += 1;
1464
+ }
1465
+ return jsonActionResult({
1466
+ ok: true,
1467
+ removed
1468
+ });
1469
+ }
1470
+ const { addReactionFeishu } = await loadFeishuChannelRuntime();
1471
+ await addReactionFeishu({
1472
+ cfg: ctx.cfg,
1473
+ messageId,
1474
+ emojiType: emoji,
1475
+ accountId: ctx.accountId ?? void 0
1476
+ });
1477
+ return jsonActionResult({
1478
+ ok: true,
1479
+ added: emoji
1480
+ });
1481
+ }
1482
+ if (ctx.action === "reactions") {
1483
+ const messageId = resolveFeishuMessageId(ctx.params);
1484
+ if (!messageId) throw new Error("Feishu reactions lookup requires messageId.");
1485
+ const { listReactionsFeishu } = await loadFeishuChannelRuntime();
1486
+ return jsonActionResult({
1487
+ ok: true,
1488
+ reactions: await listReactionsFeishu({
1489
+ cfg: ctx.cfg,
1490
+ messageId,
1491
+ accountId: ctx.accountId ?? void 0
1492
+ })
1493
+ });
1494
+ }
1495
+ throw new Error(`Unsupported Feishu action: "${ctx.action}"`);
1496
+ }
1497
+ },
1498
+ bindings: {
1499
+ compileConfiguredBinding: ({ conversationId }) => normalizeFeishuAcpConversationId(conversationId),
1500
+ matchInboundConversation: ({ compiledBinding, conversationId, parentConversationId }) => matchFeishuAcpConversation({
1501
+ bindingConversationId: compiledBinding.conversationId,
1502
+ conversationId,
1503
+ parentConversationId
1504
+ }),
1505
+ resolveCommandConversation: ({ accountId, threadId, senderId, sessionKey, parentSessionKey, originatingTo, commandTo, fallbackTo }) => resolveFeishuCommandConversation({
1506
+ accountId,
1507
+ threadId,
1508
+ senderId,
1509
+ sessionKey,
1510
+ parentSessionKey,
1511
+ originatingTo,
1512
+ commandTo,
1513
+ fallbackTo
1514
+ })
1515
+ },
1516
+ auth: { login: async ({ cfg }) => {
1517
+ const { createClackPrompter } = await import("openclaw/plugin-sdk/setup-runtime");
1518
+ const { replaceConfigFile } = await import("openclaw/plugin-sdk/config-mutation");
1519
+ const nextCfg = await runFeishuLogin({
1520
+ cfg,
1521
+ prompter: createClackPrompter()
1522
+ });
1523
+ if (nextCfg !== cfg) await replaceConfigFile({
1524
+ nextConfig: nextCfg,
1525
+ afterWrite: { mode: "auto" }
1526
+ });
1527
+ } },
1528
+ setup: feishuSetupAdapter,
1529
+ setupWizard: feishuSetupWizard,
1530
+ messaging: {
1531
+ targetPrefixes: ["feishu", "lark"],
1532
+ normalizeTarget: (raw) => normalizeFeishuTarget(raw) ?? void 0,
1533
+ resolveDeliveryTarget: ({ conversationId, parentConversationId }) => {
1534
+ const directId = parseFeishuDirectConversationId(conversationId);
1535
+ if (directId) return { to: `user:${directId}` };
1536
+ const parsed = parseFeishuConversationId({
1537
+ conversationId,
1538
+ parentConversationId
1539
+ });
1540
+ if (parsed?.topicId) return {
1541
+ to: `chat:${parentConversationId?.trim() || parsed.chatId}`,
1542
+ threadId: parsed.topicId
1543
+ };
1544
+ return { to: `chat:${parsed?.chatId ?? conversationId.trim()}` };
1545
+ },
1546
+ resolveSessionConversation: ({ kind, rawId }) => resolveFeishuSessionConversation({
1547
+ kind,
1548
+ rawId
1549
+ }),
1550
+ resolveOutboundSessionRoute: (params) => resolveFeishuOutboundSessionRoute(params),
1551
+ targetResolver: {
1552
+ looksLikeId: looksLikeFeishuId,
1553
+ hint: "<chatId|user:openId|chat:chatId>"
1554
+ }
1555
+ },
1556
+ directory: createChannelDirectoryAdapter({
1557
+ listPeers: async ({ cfg, query, limit, accountId }) => listFeishuDirectoryPeers({
1558
+ cfg,
1559
+ query: query ?? void 0,
1560
+ limit: limit ?? void 0,
1561
+ accountId: accountId ?? void 0
1562
+ }),
1563
+ listGroups: async ({ cfg, query, limit, accountId }) => listFeishuDirectoryGroups({
1564
+ cfg,
1565
+ query: query ?? void 0,
1566
+ limit: limit ?? void 0,
1567
+ accountId: accountId ?? void 0
1568
+ }),
1569
+ ...createRuntimeDirectoryLiveAdapter({
1570
+ getRuntime: loadFeishuChannelRuntime,
1571
+ listPeersLive: (runtime) => async ({ cfg, query, limit, accountId }) => await runtime.listFeishuDirectoryPeersLive({
1572
+ cfg,
1573
+ query: query ?? void 0,
1574
+ limit: limit ?? void 0,
1575
+ accountId: accountId ?? void 0
1576
+ }),
1577
+ listGroupsLive: (runtime) => async ({ cfg, query, limit, accountId }) => await runtime.listFeishuDirectoryGroupsLive({
1578
+ cfg,
1579
+ query: query ?? void 0,
1580
+ limit: limit ?? void 0,
1581
+ accountId: accountId ?? void 0
1582
+ })
1583
+ })
1584
+ }),
1585
+ status: createComputedAccountStatusAdapter({
1586
+ defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID$2, { port: null }),
1587
+ buildChannelSummary: ({ snapshot }) => buildProbeChannelStatusSummary(snapshot, { port: snapshot.port ?? null }),
1588
+ probeAccount: async ({ account }) => await (await loadFeishuChannelRuntime()).probeFeishu(account),
1589
+ resolveAccountSnapshot: ({ account, runtime }) => ({
1590
+ accountId: account.accountId,
1591
+ enabled: account.enabled,
1592
+ configured: account.configured,
1593
+ name: account.name,
1594
+ extra: {
1595
+ appId: account.appId,
1596
+ domain: account.domain,
1597
+ port: runtime?.port ?? null
1598
+ }
1599
+ })
1600
+ }),
1601
+ gateway: { startAccount: async (ctx) => {
1602
+ const { monitorFeishuProvider } = await import("./monitor-CT189QfR.js");
1603
+ const account = resolveFeishuRuntimeAccount({
1604
+ cfg: ctx.cfg,
1605
+ accountId: ctx.accountId
1606
+ }, { requireEventSecrets: true });
1607
+ const port = account.config?.webhookPort ?? null;
1608
+ ctx.setStatus({
1609
+ accountId: ctx.accountId,
1610
+ port
1611
+ });
1612
+ ctx.log?.info(`starting feishu[${ctx.accountId}] (mode: ${account.config?.connectionMode ?? "websocket"})`);
1613
+ return monitorFeishuProvider({
1614
+ config: ctx.cfg,
1615
+ runtime: ctx.runtime,
1616
+ abortSignal: ctx.abortSignal,
1617
+ accountId: ctx.accountId
1618
+ });
1619
+ } }
1620
+ },
1621
+ security: {
1622
+ collectWarnings: projectConfigAccountIdWarningCollector(collectFeishuSecurityWarnings),
1623
+ collectAuditFindings: ({ cfg }) => collectFeishuSecurityAuditFindings({ cfg })
1624
+ },
1625
+ pairing: { text: {
1626
+ idLabel: "feishuUserId",
1627
+ message: PAIRING_APPROVED_MESSAGE,
1628
+ normalizeAllowEntry: createPairingPrefixStripper(/^(feishu|user|open_id):/i),
1629
+ notify: async ({ cfg, id, message, accountId }) => {
1630
+ const { sendMessageFeishu } = await loadFeishuChannelRuntime();
1631
+ await sendMessageFeishu({
1632
+ cfg,
1633
+ to: id,
1634
+ text: message,
1635
+ accountId
1636
+ });
1637
+ }
1638
+ } },
1639
+ outbound: {
1640
+ deliveryMode: "direct",
1641
+ chunker: chunkTextForOutbound,
1642
+ chunkerMode: "markdown",
1643
+ textChunkLimit: 4e3,
1644
+ presentationCapabilities: {
1645
+ supported: true,
1646
+ buttons: true,
1647
+ selects: false,
1648
+ context: true,
1649
+ divider: true
1650
+ },
1651
+ renderPresentation: async (ctx) => {
1652
+ const renderPresentation = (await loadFeishuChannelRuntime()).feishuOutbound.renderPresentation;
1653
+ return renderPresentation ? await renderPresentation(ctx) : null;
1654
+ },
1655
+ sendPayload: async (ctx) => {
1656
+ const sendPayload = (await loadFeishuChannelRuntime()).feishuOutbound.sendPayload;
1657
+ if (!sendPayload) throw new Error("Feishu payload sending is not available.");
1658
+ return await sendPayload(ctx);
1659
+ },
1660
+ ...createRuntimeOutboundDelegates({
1661
+ getRuntime: loadFeishuChannelRuntime,
1662
+ sendText: { resolve: (runtime) => runtime.feishuOutbound.sendText },
1663
+ sendMedia: { resolve: (runtime) => runtime.feishuOutbound.sendMedia }
1664
+ })
1665
+ }
1666
+ });
1667
+ //#endregion
1668
+ export { setFeishuNamedAccountEnabled$1 as a, feishuSetupAdapter as i, feishuSetupWizard as n, runFeishuLogin as r, feishuPlugin as t };