@gakr-gakr/feishu 0.1.0

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 (133) hide show
  1. package/api.ts +32 -0
  2. package/autobot.plugin.json +180 -0
  3. package/channel-entry.ts +20 -0
  4. package/channel-plugin-api.ts +1 -0
  5. package/contract-api.ts +16 -0
  6. package/index.ts +82 -0
  7. package/package.json +62 -0
  8. package/runtime-api.ts +55 -0
  9. package/secret-contract-api.ts +5 -0
  10. package/security-contract-api.ts +1 -0
  11. package/session-key-api.ts +1 -0
  12. package/setup-api.ts +3 -0
  13. package/setup-entry.ts +13 -0
  14. package/skills/feishu-doc/SKILL.md +211 -0
  15. package/skills/feishu-doc/references/block-types.md +103 -0
  16. package/skills/feishu-drive/SKILL.md +97 -0
  17. package/skills/feishu-perm/SKILL.md +119 -0
  18. package/skills/feishu-wiki/SKILL.md +113 -0
  19. package/src/accounts.ts +333 -0
  20. package/src/agent-config.ts +21 -0
  21. package/src/app-registration.ts +331 -0
  22. package/src/approval-auth.ts +25 -0
  23. package/src/async.ts +104 -0
  24. package/src/audio-preflight.runtime.ts +9 -0
  25. package/src/bitable.ts +762 -0
  26. package/src/bot-content.ts +485 -0
  27. package/src/bot-runtime-api.ts +12 -0
  28. package/src/bot-sender-name.ts +125 -0
  29. package/src/bot.ts +1703 -0
  30. package/src/card-action.ts +447 -0
  31. package/src/card-interaction.ts +159 -0
  32. package/src/card-test-helpers.ts +54 -0
  33. package/src/card-ux-approval.ts +65 -0
  34. package/src/card-ux-launcher.ts +121 -0
  35. package/src/card-ux-shared.ts +33 -0
  36. package/src/channel-runtime-api.ts +16 -0
  37. package/src/channel.runtime.ts +47 -0
  38. package/src/channel.ts +1423 -0
  39. package/src/chat-schema.ts +25 -0
  40. package/src/chat.ts +188 -0
  41. package/src/client-timeout.ts +42 -0
  42. package/src/client.ts +262 -0
  43. package/src/comment-dispatcher-runtime-api.ts +6 -0
  44. package/src/comment-dispatcher.ts +107 -0
  45. package/src/comment-handler-runtime-api.ts +3 -0
  46. package/src/comment-handler.ts +303 -0
  47. package/src/comment-reaction.ts +259 -0
  48. package/src/comment-shared.ts +406 -0
  49. package/src/comment-target.ts +44 -0
  50. package/src/config-schema.ts +335 -0
  51. package/src/conversation-id.ts +199 -0
  52. package/src/dedup-runtime-api.ts +1 -0
  53. package/src/dedup.ts +141 -0
  54. package/src/dedupe-key.ts +72 -0
  55. package/src/directory.static.ts +61 -0
  56. package/src/directory.ts +124 -0
  57. package/src/doc-schema.ts +182 -0
  58. package/src/docx-batch-insert.ts +223 -0
  59. package/src/docx-color-text.ts +154 -0
  60. package/src/docx-table-ops.ts +316 -0
  61. package/src/docx-types.ts +38 -0
  62. package/src/docx.ts +1596 -0
  63. package/src/drive-schema.ts +92 -0
  64. package/src/drive.ts +829 -0
  65. package/src/dynamic-agent.ts +143 -0
  66. package/src/event-types.ts +45 -0
  67. package/src/external-keys.ts +19 -0
  68. package/src/lifecycle.test-support.ts +220 -0
  69. package/src/media.ts +1105 -0
  70. package/src/mention-target.types.ts +5 -0
  71. package/src/mention.ts +114 -0
  72. package/src/message-action-contract.ts +13 -0
  73. package/src/monitor-state-runtime-api.ts +7 -0
  74. package/src/monitor-transport-runtime-api.ts +10 -0
  75. package/src/monitor.account.ts +492 -0
  76. package/src/monitor.acp-init-failure.lifecycle.test-support.ts +219 -0
  77. package/src/monitor.bot-identity.ts +86 -0
  78. package/src/monitor.bot-menu-handler.ts +165 -0
  79. package/src/monitor.bot-menu.lifecycle.test-support.ts +224 -0
  80. package/src/monitor.broadcast.reply-once.lifecycle.test-support.ts +264 -0
  81. package/src/monitor.card-action.lifecycle.test-support.ts +421 -0
  82. package/src/monitor.comment-notice-handler.ts +105 -0
  83. package/src/monitor.comment.ts +1386 -0
  84. package/src/monitor.message-handler.ts +350 -0
  85. package/src/monitor.reaction.lifecycle.test-support.ts +68 -0
  86. package/src/monitor.startup.ts +74 -0
  87. package/src/monitor.state.ts +170 -0
  88. package/src/monitor.synthetic-error.ts +18 -0
  89. package/src/monitor.test-mocks.ts +46 -0
  90. package/src/monitor.transport.ts +451 -0
  91. package/src/monitor.ts +100 -0
  92. package/src/outbound-runtime-api.ts +1 -0
  93. package/src/outbound.ts +785 -0
  94. package/src/perm-schema.ts +52 -0
  95. package/src/perm.ts +170 -0
  96. package/src/pins.ts +108 -0
  97. package/src/policy.ts +321 -0
  98. package/src/post.ts +275 -0
  99. package/src/probe.ts +166 -0
  100. package/src/processing-claims.ts +59 -0
  101. package/src/qr-terminal.ts +1 -0
  102. package/src/reactions.ts +123 -0
  103. package/src/reasoning-preview.ts +28 -0
  104. package/src/reply-dispatcher-runtime-api.ts +7 -0
  105. package/src/reply-dispatcher.ts +748 -0
  106. package/src/runtime.ts +9 -0
  107. package/src/secret-contract.ts +145 -0
  108. package/src/secret-input.ts +1 -0
  109. package/src/security-audit-shared.ts +69 -0
  110. package/src/security-audit.ts +1 -0
  111. package/src/send-result.ts +80 -0
  112. package/src/send-target.ts +35 -0
  113. package/src/send.ts +861 -0
  114. package/src/sequential-key.ts +28 -0
  115. package/src/sequential-queue.ts +86 -0
  116. package/src/session-conversation.ts +42 -0
  117. package/src/session-route.ts +48 -0
  118. package/src/setup-core.ts +51 -0
  119. package/src/setup-surface.ts +618 -0
  120. package/src/streaming-card.ts +571 -0
  121. package/src/subagent-hooks.ts +413 -0
  122. package/src/targets.ts +97 -0
  123. package/src/thread-bindings.ts +331 -0
  124. package/src/tool-account.ts +93 -0
  125. package/src/tool-factory-test-harness.ts +79 -0
  126. package/src/tool-result.ts +16 -0
  127. package/src/tools-config.ts +22 -0
  128. package/src/types.ts +106 -0
  129. package/src/typing.ts +214 -0
  130. package/src/wiki-schema.ts +69 -0
  131. package/src/wiki.ts +270 -0
  132. package/subagent-hooks-api.ts +31 -0
  133. package/tsconfig.json +16 -0
@@ -0,0 +1,413 @@
1
+ import {
2
+ normalizeOptionalLowercaseString,
3
+ normalizeOptionalString,
4
+ } from "autobot/plugin-sdk/string-coerce-runtime";
5
+ import { buildFeishuConversationId, parseFeishuConversationId } from "./conversation-id.js";
6
+ import { normalizeFeishuTarget } from "./targets.js";
7
+ import { getFeishuThreadBindingManager } from "./thread-bindings.js";
8
+
9
+ function summarizeError(err: unknown): string {
10
+ if (err instanceof Error) {
11
+ return err.message;
12
+ }
13
+ if (typeof err === "string") {
14
+ return err;
15
+ }
16
+ return "error";
17
+ }
18
+
19
+ function stripProviderPrefix(raw: string): string {
20
+ return raw.replace(/^(feishu|lark):/i, "").trim();
21
+ }
22
+
23
+ function resolveFeishuRequesterConversation(params: {
24
+ accountId?: string;
25
+ to?: string;
26
+ threadId?: string | number;
27
+ requesterSessionKey?: string;
28
+ }): {
29
+ accountId: string;
30
+ conversationId: string;
31
+ parentConversationId?: string;
32
+ } | null {
33
+ const manager = getFeishuThreadBindingManager(params.accountId);
34
+ if (!manager) {
35
+ return null;
36
+ }
37
+ const rawTo = params.to?.trim();
38
+ const withoutProviderPrefix = rawTo ? stripProviderPrefix(rawTo) : "";
39
+ const normalizedTarget = rawTo ? normalizeFeishuTarget(rawTo) : null;
40
+ const threadId =
41
+ params.threadId != null && params.threadId !== "" ? String(params.threadId).trim() : "";
42
+ const isChatTarget = /^(chat|group|channel):/i.test(withoutProviderPrefix);
43
+ const parsedRequesterTopic =
44
+ normalizedTarget && threadId && isChatTarget
45
+ ? parseFeishuConversationId({
46
+ conversationId: buildFeishuConversationId({
47
+ chatId: normalizedTarget,
48
+ scope: "group_topic",
49
+ topicId: threadId,
50
+ }),
51
+ parentConversationId: normalizedTarget,
52
+ })
53
+ : null;
54
+ const requesterSessionKey = params.requesterSessionKey?.trim();
55
+ if (requesterSessionKey) {
56
+ const existingBindings = manager.listBySessionKey(requesterSessionKey);
57
+ if (existingBindings.length === 1) {
58
+ const existing = existingBindings[0];
59
+ return {
60
+ accountId: existing.accountId,
61
+ conversationId: existing.conversationId,
62
+ parentConversationId: existing.parentConversationId,
63
+ };
64
+ }
65
+ if (existingBindings.length > 1) {
66
+ if (rawTo && normalizedTarget && !threadId && !isChatTarget) {
67
+ const directMatches = existingBindings.filter(
68
+ (entry) =>
69
+ entry.accountId === manager.accountId &&
70
+ entry.conversationId === normalizedTarget &&
71
+ !entry.parentConversationId,
72
+ );
73
+ if (directMatches.length === 1) {
74
+ const existing = directMatches[0];
75
+ return {
76
+ accountId: existing.accountId,
77
+ conversationId: existing.conversationId,
78
+ parentConversationId: existing.parentConversationId,
79
+ };
80
+ }
81
+ return null;
82
+ }
83
+ if (parsedRequesterTopic) {
84
+ const matchingTopicBindings = existingBindings.filter((entry) => {
85
+ const parsed = parseFeishuConversationId({
86
+ conversationId: entry.conversationId,
87
+ parentConversationId: entry.parentConversationId,
88
+ });
89
+ return (
90
+ parsed?.chatId === parsedRequesterTopic.chatId &&
91
+ parsed?.topicId === parsedRequesterTopic.topicId
92
+ );
93
+ });
94
+ if (matchingTopicBindings.length === 1) {
95
+ const existing = matchingTopicBindings[0];
96
+ return {
97
+ accountId: existing.accountId,
98
+ conversationId: existing.conversationId,
99
+ parentConversationId: existing.parentConversationId,
100
+ };
101
+ }
102
+ const senderScopedTopicBindings = matchingTopicBindings.filter((entry) => {
103
+ const parsed = parseFeishuConversationId({
104
+ conversationId: entry.conversationId,
105
+ parentConversationId: entry.parentConversationId,
106
+ });
107
+ return parsed?.scope === "group_topic_sender";
108
+ });
109
+ if (
110
+ senderScopedTopicBindings.length === 1 &&
111
+ matchingTopicBindings.length === senderScopedTopicBindings.length
112
+ ) {
113
+ const existing = senderScopedTopicBindings[0];
114
+ return {
115
+ accountId: existing.accountId,
116
+ conversationId: existing.conversationId,
117
+ parentConversationId: existing.parentConversationId,
118
+ };
119
+ }
120
+ return null;
121
+ }
122
+ }
123
+ }
124
+
125
+ if (!rawTo) {
126
+ return null;
127
+ }
128
+ if (!normalizedTarget) {
129
+ return null;
130
+ }
131
+
132
+ if (threadId) {
133
+ if (!isChatTarget) {
134
+ return null;
135
+ }
136
+ return {
137
+ accountId: manager.accountId,
138
+ conversationId: buildFeishuConversationId({
139
+ chatId: normalizedTarget,
140
+ scope: "group_topic",
141
+ topicId: threadId,
142
+ }),
143
+ parentConversationId: normalizedTarget,
144
+ };
145
+ }
146
+
147
+ if (isChatTarget) {
148
+ return null;
149
+ }
150
+
151
+ return {
152
+ accountId: manager.accountId,
153
+ conversationId: normalizedTarget,
154
+ };
155
+ }
156
+
157
+ function resolveFeishuDeliveryOrigin(params: {
158
+ conversationId: string;
159
+ parentConversationId?: string;
160
+ accountId: string;
161
+ deliveryTo?: string;
162
+ deliveryThreadId?: string;
163
+ }): {
164
+ channel: "feishu";
165
+ accountId: string;
166
+ to: string;
167
+ threadId?: string;
168
+ } {
169
+ const deliveryTo = params.deliveryTo?.trim();
170
+ const deliveryThreadId = params.deliveryThreadId?.trim();
171
+ if (deliveryTo) {
172
+ return {
173
+ channel: "feishu",
174
+ accountId: params.accountId,
175
+ to: deliveryTo,
176
+ ...(deliveryThreadId ? { threadId: deliveryThreadId } : {}),
177
+ };
178
+ }
179
+ const parsed = parseFeishuConversationId({
180
+ conversationId: params.conversationId,
181
+ parentConversationId: params.parentConversationId,
182
+ });
183
+ if (parsed?.topicId) {
184
+ return {
185
+ channel: "feishu",
186
+ accountId: params.accountId,
187
+ to: `chat:${params.parentConversationId?.trim() || parsed.chatId}`,
188
+ threadId: parsed.topicId,
189
+ };
190
+ }
191
+ return {
192
+ channel: "feishu",
193
+ accountId: params.accountId,
194
+ to: `user:${params.conversationId}`,
195
+ };
196
+ }
197
+
198
+ function resolveMatchingChildBinding(params: {
199
+ accountId?: string;
200
+ childSessionKey: string;
201
+ requesterSessionKey?: string;
202
+ requesterOrigin?: {
203
+ to?: string;
204
+ threadId?: string | number;
205
+ };
206
+ }) {
207
+ const manager = getFeishuThreadBindingManager(params.accountId);
208
+ if (!manager) {
209
+ return null;
210
+ }
211
+ const childBindings = manager.listBySessionKey(params.childSessionKey.trim());
212
+ if (childBindings.length === 0) {
213
+ return null;
214
+ }
215
+
216
+ const requesterConversation = resolveFeishuRequesterConversation({
217
+ accountId: manager.accountId,
218
+ to: params.requesterOrigin?.to,
219
+ threadId: params.requesterOrigin?.threadId,
220
+ requesterSessionKey: params.requesterSessionKey,
221
+ });
222
+ if (requesterConversation) {
223
+ const matched = childBindings.find(
224
+ (entry) =>
225
+ entry.accountId === requesterConversation.accountId &&
226
+ entry.conversationId === requesterConversation.conversationId &&
227
+ normalizeOptionalString(entry.parentConversationId) ===
228
+ normalizeOptionalString(requesterConversation.parentConversationId),
229
+ );
230
+ if (matched) {
231
+ return matched;
232
+ }
233
+ }
234
+
235
+ return childBindings.length === 1 ? childBindings[0] : null;
236
+ }
237
+
238
+ type FeishuSubagentContext = {
239
+ requesterSessionKey?: string;
240
+ };
241
+
242
+ type FeishuSubagentSpawningEvent = {
243
+ threadRequested?: boolean;
244
+ requester?: {
245
+ channel?: string;
246
+ accountId?: string;
247
+ to?: string;
248
+ threadId?: string | number;
249
+ };
250
+ childSessionKey: string;
251
+ agentId?: string;
252
+ label?: string;
253
+ };
254
+
255
+ type FeishuSubagentDeliveryTargetEvent = {
256
+ expectsCompletionMessage?: boolean;
257
+ requesterOrigin?: {
258
+ channel?: string;
259
+ accountId?: string;
260
+ to?: string;
261
+ threadId?: string | number;
262
+ };
263
+ childSessionKey: string;
264
+ requesterSessionKey?: string;
265
+ };
266
+
267
+ type FeishuSubagentEndedEvent = {
268
+ accountId?: string;
269
+ targetSessionKey: string;
270
+ };
271
+
272
+ type FeishuSubagentSpawningResult =
273
+ | {
274
+ status: "ok";
275
+ threadBindingReady?: boolean;
276
+ deliveryOrigin?: {
277
+ channel: "feishu";
278
+ accountId?: string;
279
+ to?: string;
280
+ threadId?: string | number;
281
+ };
282
+ }
283
+ | { status: "error"; error: string }
284
+ | undefined;
285
+
286
+ type FeishuSubagentDeliveryTargetResult =
287
+ | {
288
+ origin: {
289
+ channel: "feishu";
290
+ accountId?: string;
291
+ to?: string;
292
+ threadId?: string | number;
293
+ };
294
+ }
295
+ | undefined;
296
+
297
+ export async function handleFeishuSubagentSpawning(
298
+ event: FeishuSubagentSpawningEvent,
299
+ ctx: FeishuSubagentContext,
300
+ ): Promise<FeishuSubagentSpawningResult> {
301
+ if (!event.threadRequested) {
302
+ return undefined;
303
+ }
304
+ const requesterChannel = normalizeOptionalLowercaseString(event.requester?.channel);
305
+ if (requesterChannel !== "feishu") {
306
+ return undefined;
307
+ }
308
+
309
+ const manager = getFeishuThreadBindingManager(event.requester?.accountId);
310
+ if (!manager) {
311
+ return {
312
+ status: "error" as const,
313
+ error:
314
+ "Feishu current-conversation binding is unavailable because the Feishu account monitor is not active.",
315
+ };
316
+ }
317
+
318
+ const conversation = resolveFeishuRequesterConversation({
319
+ accountId: event.requester?.accountId,
320
+ to: event.requester?.to,
321
+ threadId: event.requester?.threadId,
322
+ requesterSessionKey: ctx.requesterSessionKey,
323
+ });
324
+ if (!conversation) {
325
+ return {
326
+ status: "error" as const,
327
+ error:
328
+ "Feishu current-conversation binding is only available in direct messages or topic conversations.",
329
+ };
330
+ }
331
+
332
+ try {
333
+ const binding = manager.bindConversation({
334
+ conversationId: conversation.conversationId,
335
+ parentConversationId: conversation.parentConversationId,
336
+ targetKind: "subagent",
337
+ targetSessionKey: event.childSessionKey,
338
+ metadata: {
339
+ agentId: event.agentId,
340
+ label: event.label,
341
+ boundBy: "system",
342
+ deliveryTo: event.requester?.to,
343
+ deliveryThreadId:
344
+ event.requester?.threadId != null && event.requester.threadId !== ""
345
+ ? String(event.requester.threadId)
346
+ : undefined,
347
+ },
348
+ });
349
+ if (!binding) {
350
+ return {
351
+ status: "error" as const,
352
+ error:
353
+ "Unable to bind this Feishu conversation to the spawned subagent session. Session mode is unavailable for this target.",
354
+ };
355
+ }
356
+ return {
357
+ status: "ok" as const,
358
+ threadBindingReady: true,
359
+ deliveryOrigin: resolveFeishuDeliveryOrigin({
360
+ conversationId: binding.conversationId,
361
+ parentConversationId: binding.parentConversationId,
362
+ accountId: binding.accountId,
363
+ deliveryTo: binding.deliveryTo,
364
+ deliveryThreadId: binding.deliveryThreadId,
365
+ }),
366
+ };
367
+ } catch (err) {
368
+ return {
369
+ status: "error" as const,
370
+ error: `Feishu conversation bind failed: ${summarizeError(err)}`,
371
+ };
372
+ }
373
+ }
374
+
375
+ export function handleFeishuSubagentDeliveryTarget(
376
+ event: FeishuSubagentDeliveryTargetEvent,
377
+ ): FeishuSubagentDeliveryTargetResult {
378
+ if (!event.expectsCompletionMessage) {
379
+ return undefined;
380
+ }
381
+ const requesterChannel = normalizeOptionalLowercaseString(event.requesterOrigin?.channel);
382
+ if (requesterChannel !== "feishu") {
383
+ return undefined;
384
+ }
385
+
386
+ const binding = resolveMatchingChildBinding({
387
+ accountId: event.requesterOrigin?.accountId,
388
+ childSessionKey: event.childSessionKey,
389
+ requesterSessionKey: event.requesterSessionKey,
390
+ requesterOrigin: {
391
+ to: event.requesterOrigin?.to,
392
+ threadId: event.requesterOrigin?.threadId,
393
+ },
394
+ });
395
+ if (!binding) {
396
+ return undefined;
397
+ }
398
+
399
+ return {
400
+ origin: resolveFeishuDeliveryOrigin({
401
+ conversationId: binding.conversationId,
402
+ parentConversationId: binding.parentConversationId,
403
+ accountId: binding.accountId,
404
+ deliveryTo: binding.deliveryTo,
405
+ deliveryThreadId: binding.deliveryThreadId,
406
+ }),
407
+ };
408
+ }
409
+
410
+ export function handleFeishuSubagentEnded(event: FeishuSubagentEndedEvent) {
411
+ const manager = getFeishuThreadBindingManager(event.accountId);
412
+ manager?.unbindBySessionKey(event.targetSessionKey);
413
+ }
package/src/targets.ts ADDED
@@ -0,0 +1,97 @@
1
+ import { normalizeLowercaseStringOrEmpty } from "autobot/plugin-sdk/string-coerce-runtime";
2
+ import type { FeishuIdType } from "./types.js";
3
+
4
+ const CHAT_ID_PREFIX = "oc_";
5
+ const OPEN_ID_PREFIX = "ou_";
6
+ const USER_ID_REGEX = /^[a-zA-Z0-9_-]+$/;
7
+
8
+ function stripProviderPrefix(raw: string): string {
9
+ return raw.replace(/^(feishu|lark):/i, "").trim();
10
+ }
11
+
12
+ export function detectIdType(id: string): FeishuIdType | null {
13
+ const trimmed = id.trim();
14
+ if (trimmed.startsWith(CHAT_ID_PREFIX)) {
15
+ return "chat_id";
16
+ }
17
+ if (trimmed.startsWith(OPEN_ID_PREFIX)) {
18
+ return "open_id";
19
+ }
20
+ if (USER_ID_REGEX.test(trimmed)) {
21
+ return "user_id";
22
+ }
23
+ return null;
24
+ }
25
+
26
+ export function normalizeFeishuTarget(raw: string): string | null {
27
+ const trimmed = raw.trim();
28
+ if (!trimmed) {
29
+ return null;
30
+ }
31
+
32
+ const withoutProvider = stripProviderPrefix(trimmed);
33
+ const lowered = normalizeLowercaseStringOrEmpty(withoutProvider);
34
+ if (lowered.startsWith("chat:")) {
35
+ return withoutProvider.slice("chat:".length).trim() || null;
36
+ }
37
+ if (lowered.startsWith("group:")) {
38
+ return withoutProvider.slice("group:".length).trim() || null;
39
+ }
40
+ if (lowered.startsWith("channel:")) {
41
+ return withoutProvider.slice("channel:".length).trim() || null;
42
+ }
43
+ if (lowered.startsWith("user:")) {
44
+ return withoutProvider.slice("user:".length).trim() || null;
45
+ }
46
+ if (lowered.startsWith("dm:")) {
47
+ return withoutProvider.slice("dm:".length).trim() || null;
48
+ }
49
+ if (lowered.startsWith("open_id:")) {
50
+ return withoutProvider.slice("open_id:".length).trim() || null;
51
+ }
52
+
53
+ return withoutProvider;
54
+ }
55
+
56
+ export function resolveReceiveIdType(id: string): "chat_id" | "open_id" | "user_id" {
57
+ const trimmed = id.trim();
58
+ const lowered = normalizeLowercaseStringOrEmpty(trimmed);
59
+ if (
60
+ lowered.startsWith("chat:") ||
61
+ lowered.startsWith("group:") ||
62
+ lowered.startsWith("channel:")
63
+ ) {
64
+ return "chat_id";
65
+ }
66
+ if (lowered.startsWith("open_id:")) {
67
+ return "open_id";
68
+ }
69
+ if (lowered.startsWith("user:") || lowered.startsWith("dm:")) {
70
+ const normalized = trimmed.replace(/^(user|dm):/i, "").trim();
71
+ return normalized.startsWith(OPEN_ID_PREFIX) ? "open_id" : "user_id";
72
+ }
73
+ if (trimmed.startsWith(CHAT_ID_PREFIX)) {
74
+ return "chat_id";
75
+ }
76
+ if (trimmed.startsWith(OPEN_ID_PREFIX)) {
77
+ return "open_id";
78
+ }
79
+ return "user_id";
80
+ }
81
+
82
+ export function looksLikeFeishuId(raw: string): boolean {
83
+ const trimmed = stripProviderPrefix(raw.trim());
84
+ if (!trimmed) {
85
+ return false;
86
+ }
87
+ if (/^(chat|group|channel|user|dm|open_id):/i.test(trimmed)) {
88
+ return true;
89
+ }
90
+ if (trimmed.startsWith(CHAT_ID_PREFIX)) {
91
+ return true;
92
+ }
93
+ if (trimmed.startsWith(OPEN_ID_PREFIX)) {
94
+ return true;
95
+ }
96
+ return false;
97
+ }