@kodelyth/feishu 2026.5.39 → 2026.5.42
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.
- package/api.ts +32 -0
- package/channel-entry.ts +20 -0
- package/channel-plugin-api.ts +1 -0
- package/contract-api.ts +16 -0
- package/dist/accounts-D0ow-lRb.js +429 -0
- package/dist/api.js +2308 -0
- package/dist/app-registration-DBSnysKJ.js +184 -0
- package/dist/audio-preflight.runtime-Dpjbn-7r.js +7 -0
- package/dist/channel-13WQvQ0u.js +2115 -0
- package/dist/channel-entry.js +22 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-JMJonrJ4.js +729 -0
- package/dist/client-D1pzbBGo.js +157 -0
- package/dist/contract-api.js +9 -0
- package/dist/conversation-id-_58ecqlx.js +139 -0
- package/dist/drive-CgHOluXx.js +883 -0
- package/dist/index.js +68 -0
- package/dist/monitor-oWptK0zL.js +60 -0
- package/dist/monitor.account-DHaWlslg.js +5207 -0
- package/dist/monitor.state-C211a4tX.js +100 -0
- package/dist/probe-CF4duEpK.js +149 -0
- package/dist/rolldown-runtime-DUslC3ob.js +14 -0
- package/dist/runtime-DSh5rL_d.js +8 -0
- package/dist/runtime-api.js +14 -0
- package/dist/secret-contract-NSee-WzN.js +119 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/security-audit-DWVC0vSK.js +11 -0
- package/dist/security-audit-shared-Dpcwxeft.js +38 -0
- package/dist/security-contract-api.js +2 -0
- package/dist/send-DfZuV4Fi.js +1212 -0
- package/dist/session-conversation-Duaukbnl.js +27 -0
- package/dist/session-key-api.js +2 -0
- package/dist/setup-api.js +2 -0
- package/dist/setup-entry.js +15 -0
- package/dist/subagent-hooks-Dtegs0kh.js +235 -0
- package/dist/subagent-hooks-api.js +23 -0
- package/dist/targets-DFskxX4p.js +48 -0
- package/dist/thread-bindings-DI7lVSOE.js +222 -0
- package/index.ts +82 -0
- package/klaw.plugin.json +47 -1712
- package/package.json +4 -4
- package/runtime-api.ts +52 -0
- package/secret-contract-api.ts +5 -0
- package/security-contract-api.ts +1 -0
- package/session-key-api.ts +1 -0
- package/setup-api.ts +3 -0
- package/setup-entry.test.ts +19 -0
- package/setup-entry.ts +13 -0
- package/src/accounts.test.ts +480 -0
- package/src/accounts.ts +333 -0
- package/src/agent-config.ts +21 -0
- package/src/app-registration.ts +331 -0
- package/src/approval-auth.test.ts +24 -0
- package/src/approval-auth.ts +25 -0
- package/src/async.test.ts +35 -0
- package/src/async.ts +104 -0
- package/src/audio-preflight.runtime.ts +9 -0
- package/src/bitable.test.ts +136 -0
- package/src/bitable.ts +762 -0
- package/src/bot-content.ts +485 -0
- package/src/bot-group-name.test.ts +116 -0
- package/src/bot-runtime-api.ts +12 -0
- package/src/bot-sender-name.ts +125 -0
- package/src/bot.broadcast.test.ts +523 -0
- package/src/bot.card-action.test.ts +552 -0
- package/src/bot.checkBotMentioned.test.ts +265 -0
- package/src/bot.helpers.test.ts +135 -0
- package/src/bot.stripBotMention.test.ts +126 -0
- package/src/bot.test.ts +3671 -0
- package/src/bot.ts +1703 -0
- package/src/card-action.ts +447 -0
- package/src/card-interaction.test.ts +131 -0
- package/src/card-interaction.ts +159 -0
- package/src/card-test-helpers.ts +54 -0
- package/src/card-ux-approval.ts +65 -0
- package/src/card-ux-launcher.test.ts +106 -0
- package/src/card-ux-launcher.ts +121 -0
- package/src/card-ux-shared.ts +33 -0
- package/src/channel-runtime-api.ts +16 -0
- package/src/channel.runtime.ts +47 -0
- package/src/channel.test.ts +1151 -0
- package/src/channel.ts +1423 -0
- package/src/chat-schema.ts +25 -0
- package/src/chat.test.ts +240 -0
- package/src/chat.ts +188 -0
- package/src/client-timeout.ts +42 -0
- package/src/client.test.ts +447 -0
- package/src/client.ts +262 -0
- package/src/comment-dispatcher-runtime-api.ts +6 -0
- package/src/comment-dispatcher.test.ts +185 -0
- package/src/comment-dispatcher.ts +107 -0
- package/src/comment-handler-runtime-api.ts +3 -0
- package/src/comment-handler.test.ts +592 -0
- package/src/comment-handler.ts +303 -0
- package/src/comment-reaction.test.ts +138 -0
- package/src/comment-reaction.ts +259 -0
- package/src/comment-shared.test.ts +183 -0
- package/src/comment-shared.ts +406 -0
- package/src/comment-target.ts +44 -0
- package/src/config-schema.test.ts +326 -0
- package/src/config-schema.ts +335 -0
- package/src/conversation-id.test.ts +18 -0
- package/src/conversation-id.ts +199 -0
- package/src/dedup-runtime-api.ts +1 -0
- package/src/dedup.ts +141 -0
- package/src/dedupe-key.ts +72 -0
- package/src/directory.static.ts +61 -0
- package/src/directory.test.ts +141 -0
- package/src/directory.ts +124 -0
- package/src/doc-schema.ts +182 -0
- package/src/docx-batch-insert.test.ts +116 -0
- package/src/docx-batch-insert.ts +223 -0
- package/src/docx-color-text.ts +154 -0
- package/src/docx-table-ops.test.ts +53 -0
- package/src/docx-table-ops.ts +316 -0
- package/src/docx-types.ts +38 -0
- package/src/docx.account-selection.test.ts +95 -0
- package/src/docx.test.ts +701 -0
- package/src/docx.ts +1596 -0
- package/src/drive-schema.ts +92 -0
- package/src/drive.test.ts +1237 -0
- package/src/drive.ts +829 -0
- package/src/dynamic-agent.test.ts +155 -0
- package/src/dynamic-agent.ts +143 -0
- package/src/event-types.ts +45 -0
- package/src/external-keys.test.ts +20 -0
- package/src/external-keys.ts +19 -0
- package/src/lifecycle.test-support.ts +220 -0
- package/src/media.test.ts +955 -0
- package/src/media.ts +1105 -0
- package/src/mention-target.types.ts +5 -0
- package/src/mention.ts +114 -0
- package/src/message-action-contract.ts +13 -0
- package/src/monitor-state-runtime-api.ts +7 -0
- package/src/monitor-transport-runtime-api.ts +10 -0
- package/src/monitor.account.ts +492 -0
- package/src/monitor.acp-init-failure.lifecycle.test-support.ts +219 -0
- package/src/monitor.bot-identity.ts +86 -0
- package/src/monitor.bot-menu-handler.ts +165 -0
- package/src/monitor.bot-menu.lifecycle.test-support.ts +224 -0
- package/src/monitor.bot-menu.test.ts +188 -0
- package/src/monitor.broadcast.reply-once.lifecycle.test-support.ts +264 -0
- package/src/monitor.card-action.lifecycle.test-support.ts +421 -0
- package/src/monitor.cleanup.test.ts +383 -0
- package/src/monitor.comment-notice-handler.ts +105 -0
- package/src/monitor.comment.test.ts +967 -0
- package/src/monitor.comment.ts +1386 -0
- package/src/monitor.lifecycle.test.ts +4 -0
- package/src/monitor.message-handler.ts +350 -0
- package/src/monitor.reaction.lifecycle.test-support.ts +68 -0
- package/src/monitor.reaction.test.ts +739 -0
- package/src/monitor.startup.test.ts +213 -0
- package/src/monitor.startup.ts +74 -0
- package/src/monitor.state.defaults.test.ts +46 -0
- package/src/monitor.state.ts +170 -0
- package/src/monitor.synthetic-error.ts +18 -0
- package/src/monitor.test-mocks.ts +46 -0
- package/src/monitor.transport.ts +451 -0
- package/src/monitor.ts +100 -0
- package/src/monitor.webhook-e2e.test.ts +279 -0
- package/src/monitor.webhook-security.test.ts +389 -0
- package/src/monitor.webhook.test-helpers.ts +116 -0
- package/src/outbound-runtime-api.ts +1 -0
- package/src/outbound.test.ts +1118 -0
- package/src/outbound.ts +785 -0
- package/src/perm-schema.ts +52 -0
- package/src/perm.ts +170 -0
- package/src/pins.ts +108 -0
- package/src/policy.test.ts +223 -0
- package/src/policy.ts +318 -0
- package/src/post.test.ts +105 -0
- package/src/post.ts +275 -0
- package/src/probe.test.ts +283 -0
- package/src/probe.ts +166 -0
- package/src/processing-claims.ts +59 -0
- package/src/qr-terminal.ts +1 -0
- package/src/reactions.ts +123 -0
- package/src/reasoning-preview.test.ts +113 -0
- package/src/reasoning-preview.ts +28 -0
- package/src/reply-dispatcher-runtime-api.ts +7 -0
- package/src/reply-dispatcher.test.ts +1513 -0
- package/src/reply-dispatcher.ts +748 -0
- package/src/runtime.ts +9 -0
- package/src/secret-contract.ts +145 -0
- package/src/secret-input.ts +1 -0
- package/src/security-audit-shared.ts +69 -0
- package/src/security-audit.test.ts +59 -0
- package/src/security-audit.ts +1 -0
- package/src/send-result.ts +80 -0
- package/src/send-target.test.ts +86 -0
- package/src/send-target.ts +35 -0
- package/src/send.reply-fallback.test.ts +417 -0
- package/src/send.test.ts +621 -0
- package/src/send.ts +861 -0
- package/src/sequential-key.test.ts +72 -0
- package/src/sequential-key.ts +25 -0
- package/src/sequential-queue.test.ts +165 -0
- package/src/sequential-queue.ts +86 -0
- package/src/session-conversation.ts +42 -0
- package/src/session-route.ts +48 -0
- package/src/setup-core.ts +51 -0
- package/src/setup-surface.test.ts +484 -0
- package/src/setup-surface.ts +618 -0
- package/src/streaming-card.test.ts +397 -0
- package/src/streaming-card.ts +571 -0
- package/src/subagent-hooks.test.ts +627 -0
- package/src/subagent-hooks.ts +413 -0
- package/src/targets.ts +97 -0
- package/src/test-support/lifecycle-test-support.ts +454 -0
- package/src/thread-bindings.test.ts +180 -0
- package/src/thread-bindings.ts +331 -0
- package/src/tool-account-routing.test.ts +250 -0
- package/src/tool-account.test.ts +44 -0
- package/src/tool-account.ts +93 -0
- package/src/tool-factory-test-harness.ts +79 -0
- package/src/tool-result.test.ts +32 -0
- package/src/tool-result.ts +16 -0
- package/src/tools-config.test.ts +21 -0
- package/src/tools-config.ts +22 -0
- package/src/types.ts +106 -0
- package/src/typing.test.ts +144 -0
- package/src/typing.ts +214 -0
- package/src/wiki-schema.ts +69 -0
- package/src/wiki.ts +270 -0
- package/subagent-hooks-api.ts +31 -0
- package/tsconfig.json +16 -0
- package/api.js +0 -7
- package/channel-entry.js +0 -7
- package/channel-plugin-api.js +0 -7
- package/contract-api.js +0 -7
- package/index.js +0 -7
- package/runtime-api.js +0 -7
- package/secret-contract-api.js +0 -7
- package/security-contract-api.js +0 -7
- package/session-key-api.js +0 -7
- package/setup-api.js +0 -7
- package/setup-entry.js +0 -7
- package/subagent-hooks-api.js +0 -7
|
@@ -0,0 +1,2115 @@
|
|
|
1
|
+
import { a as parseFeishuTargetId, i as parseFeishuDirectConversationId, n as buildFeishuModelOverrideParentCandidates, r as parseFeishuConversationId, t as buildFeishuConversationId } from "./conversation-id-_58ecqlx.js";
|
|
2
|
+
import { n as looksLikeFeishuId, r as normalizeFeishuTarget, t as detectIdType } from "./targets-DFskxX4p.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-D0ow-lRb.js";
|
|
4
|
+
import { t as messageActionTargetAliases } from "./security-audit-DWVC0vSK.js";
|
|
5
|
+
import { n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-NSee-WzN.js";
|
|
6
|
+
import { t as collectFeishuSecurityAuditFindings } from "./security-audit-shared-Dpcwxeft.js";
|
|
7
|
+
import { t as resolveFeishuSessionConversation } from "./session-conversation-Duaukbnl.js";
|
|
8
|
+
import { normalizeLowercaseStringOrEmpty, normalizeOptionalLowercaseString } from "klaw/plugin-sdk/string-coerce-runtime";
|
|
9
|
+
import { getSessionBindingService } from "klaw/plugin-sdk/conversation-runtime";
|
|
10
|
+
import { describeAccountSnapshot } from "klaw/plugin-sdk/account-helpers";
|
|
11
|
+
import { formatAllowFromLowercase } from "klaw/plugin-sdk/allow-from";
|
|
12
|
+
import { adaptScopedAccountAccessor, createHybridChannelConfigAdapter } from "klaw/plugin-sdk/channel-config-helpers";
|
|
13
|
+
import { buildChannelOutboundSessionRoute, createChatChannelPlugin, stripChannelTargetPrefix } from "klaw/plugin-sdk/channel-core";
|
|
14
|
+
import { createMessageReceiptFromOutboundResults, defineChannelMessageAdapter } from "klaw/plugin-sdk/channel-message";
|
|
15
|
+
import { createPairingPrefixStripper } from "klaw/plugin-sdk/channel-pairing";
|
|
16
|
+
import { createAllowlistProviderGroupPolicyWarningCollector, projectConfigAccountIdWarningCollector } from "klaw/plugin-sdk/channel-policy";
|
|
17
|
+
import { createChannelDirectoryAdapter, createRuntimeDirectoryLiveAdapter, listDirectoryGroupEntriesFromMapKeysAndAllowFrom, listDirectoryUserEntriesFromAllowFromAndMapKeys } from "klaw/plugin-sdk/directory-runtime";
|
|
18
|
+
import { normalizeMessagePresentation, renderMessagePresentationFallbackText } from "klaw/plugin-sdk/interactive-runtime";
|
|
19
|
+
import { createLazyRuntimeNamedExport } from "klaw/plugin-sdk/lazy-runtime";
|
|
20
|
+
import { createRuntimeOutboundDelegates } from "klaw/plugin-sdk/outbound-runtime";
|
|
21
|
+
import { buildProbeChannelStatusSummary, createComputedAccountStatusAdapter, createDefaultChannelRuntimeState } from "klaw/plugin-sdk/status-helpers";
|
|
22
|
+
import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$2, normalizeAccountId, resolveMergedAccountConfig } from "klaw/plugin-sdk/account-resolution";
|
|
23
|
+
import { createResolvedApproverActionAuthAdapter, resolveApprovalApprovers } from "klaw/plugin-sdk/approval-auth-runtime";
|
|
24
|
+
import { createActionGate } from "klaw/plugin-sdk/channel-actions";
|
|
25
|
+
import { buildChannelConfigSchema } from "klaw/plugin-sdk/channel-config-primitives";
|
|
26
|
+
import { PAIRING_APPROVED_MESSAGE } from "klaw/plugin-sdk/channel-status";
|
|
27
|
+
import { chunkTextForOutbound } from "klaw/plugin-sdk/text-chunking";
|
|
28
|
+
import { normalizeAccountId as normalizeAccountId$1 } from "klaw/plugin-sdk/account-id";
|
|
29
|
+
import { z } from "zod";
|
|
30
|
+
import { buildSecretInputSchema, hasConfiguredSecretInput as hasConfiguredSecretInput$2 } from "klaw/plugin-sdk/secret-input";
|
|
31
|
+
import { createChannelIngressResolver, defineStableChannelIngressIdentity } from "klaw/plugin-sdk/channel-ingress-runtime";
|
|
32
|
+
import { DEFAULT_ACCOUNT_ID as DEFAULT_ACCOUNT_ID$1, createSetupTranslator, formatDocsLink, hasConfiguredSecretInput as hasConfiguredSecretInput$1, mergeAllowFromEntries, patchTopLevelChannelConfigSection, promptSingleChannelSecretInput, splitSetupEntries } from "klaw/plugin-sdk/setup";
|
|
33
|
+
//#region extensions/feishu/src/approval-auth.ts
|
|
34
|
+
function normalizeFeishuApproverId(value) {
|
|
35
|
+
const trimmed = normalizeOptionalLowercaseString(normalizeFeishuTarget(String(value)));
|
|
36
|
+
return trimmed?.startsWith("ou_") ? trimmed : void 0;
|
|
37
|
+
}
|
|
38
|
+
const feishuApprovalAuth = createResolvedApproverActionAuthAdapter({
|
|
39
|
+
channelLabel: "Feishu",
|
|
40
|
+
resolveApprovers: ({ cfg, accountId }) => {
|
|
41
|
+
const account = resolveFeishuAccount({
|
|
42
|
+
cfg,
|
|
43
|
+
accountId
|
|
44
|
+
}).config;
|
|
45
|
+
return resolveApprovalApprovers({
|
|
46
|
+
allowFrom: account.allowFrom,
|
|
47
|
+
normalizeApprover: normalizeFeishuApproverId
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
normalizeSenderId: (value) => normalizeFeishuApproverId(value)
|
|
51
|
+
});
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region extensions/feishu/src/card-interaction.ts
|
|
54
|
+
const FEISHU_CARD_INTERACTION_VERSION = "ocf1";
|
|
55
|
+
function isInteractionKind(value) {
|
|
56
|
+
return value === "button" || value === "quick" || value === "meta";
|
|
57
|
+
}
|
|
58
|
+
function isMetadataValue(value) {
|
|
59
|
+
return value === null || value === void 0 || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
60
|
+
}
|
|
61
|
+
function createFeishuCardInteractionEnvelope(envelope) {
|
|
62
|
+
return {
|
|
63
|
+
oc: FEISHU_CARD_INTERACTION_VERSION,
|
|
64
|
+
...envelope
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function buildFeishuCardActionTextFallback(event) {
|
|
68
|
+
const actionValue = event.action.value;
|
|
69
|
+
if (isRecord$1(actionValue)) {
|
|
70
|
+
if (typeof actionValue.text === "string") return actionValue.text;
|
|
71
|
+
if (typeof actionValue.command === "string") return actionValue.command;
|
|
72
|
+
return JSON.stringify(actionValue);
|
|
73
|
+
}
|
|
74
|
+
return String(actionValue);
|
|
75
|
+
}
|
|
76
|
+
function decodeFeishuCardAction(params) {
|
|
77
|
+
const { event, now = Date.now() } = params;
|
|
78
|
+
const actionValue = event.action.value;
|
|
79
|
+
if (!isRecord$1(actionValue) || actionValue.oc !== "ocf1") return {
|
|
80
|
+
kind: "legacy",
|
|
81
|
+
text: buildFeishuCardActionTextFallback(event)
|
|
82
|
+
};
|
|
83
|
+
if (!isInteractionKind(actionValue.k) || typeof actionValue.a !== "string" || !actionValue.a) return {
|
|
84
|
+
kind: "invalid",
|
|
85
|
+
reason: "malformed"
|
|
86
|
+
};
|
|
87
|
+
if (actionValue.q !== void 0 && typeof actionValue.q !== "string") return {
|
|
88
|
+
kind: "invalid",
|
|
89
|
+
reason: "malformed"
|
|
90
|
+
};
|
|
91
|
+
if (actionValue.m !== void 0) {
|
|
92
|
+
if (!isRecord$1(actionValue.m)) return {
|
|
93
|
+
kind: "invalid",
|
|
94
|
+
reason: "malformed"
|
|
95
|
+
};
|
|
96
|
+
for (const value of Object.values(actionValue.m)) if (!isMetadataValue(value)) return {
|
|
97
|
+
kind: "invalid",
|
|
98
|
+
reason: "malformed"
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (actionValue.c !== void 0) {
|
|
102
|
+
if (!isRecord$1(actionValue.c)) return {
|
|
103
|
+
kind: "invalid",
|
|
104
|
+
reason: "malformed"
|
|
105
|
+
};
|
|
106
|
+
if (actionValue.c.u !== void 0 && typeof actionValue.c.u !== "string") return {
|
|
107
|
+
kind: "invalid",
|
|
108
|
+
reason: "malformed"
|
|
109
|
+
};
|
|
110
|
+
if (actionValue.c.h !== void 0 && typeof actionValue.c.h !== "string") return {
|
|
111
|
+
kind: "invalid",
|
|
112
|
+
reason: "malformed"
|
|
113
|
+
};
|
|
114
|
+
if (actionValue.c.s !== void 0 && typeof actionValue.c.s !== "string") return {
|
|
115
|
+
kind: "invalid",
|
|
116
|
+
reason: "malformed"
|
|
117
|
+
};
|
|
118
|
+
if (actionValue.c.e !== void 0 && !Number.isFinite(actionValue.c.e)) return {
|
|
119
|
+
kind: "invalid",
|
|
120
|
+
reason: "malformed"
|
|
121
|
+
};
|
|
122
|
+
if (actionValue.c.t !== void 0 && actionValue.c.t !== "p2p" && actionValue.c.t !== "group") return {
|
|
123
|
+
kind: "invalid",
|
|
124
|
+
reason: "malformed"
|
|
125
|
+
};
|
|
126
|
+
if (typeof actionValue.c.e === "number" && actionValue.c.e < now) return {
|
|
127
|
+
kind: "invalid",
|
|
128
|
+
reason: "stale"
|
|
129
|
+
};
|
|
130
|
+
const expectedUser = actionValue.c.u?.trim();
|
|
131
|
+
if (expectedUser && expectedUser !== (event.operator.open_id ?? "").trim()) return {
|
|
132
|
+
kind: "invalid",
|
|
133
|
+
reason: "wrong_user"
|
|
134
|
+
};
|
|
135
|
+
const expectedChat = actionValue.c.h?.trim();
|
|
136
|
+
if (expectedChat && expectedChat !== (event.context.chat_id ?? "").trim()) return {
|
|
137
|
+
kind: "invalid",
|
|
138
|
+
reason: "wrong_conversation"
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
kind: "structured",
|
|
143
|
+
envelope: actionValue
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region extensions/feishu/src/config-schema.ts
|
|
148
|
+
const ChannelActionsSchema = z.object({ reactions: z.boolean().optional() }).strict().optional();
|
|
149
|
+
const DmPolicySchema = z.enum([
|
|
150
|
+
"open",
|
|
151
|
+
"pairing",
|
|
152
|
+
"allowlist"
|
|
153
|
+
]);
|
|
154
|
+
const GroupPolicySchema = z.union([z.enum([
|
|
155
|
+
"open",
|
|
156
|
+
"allowlist",
|
|
157
|
+
"disabled"
|
|
158
|
+
]), z.literal("allowall").transform(() => "open")]);
|
|
159
|
+
const FeishuDomainSchema = z.union([z.enum(["feishu", "lark"]), z.string().url().startsWith("https://")]);
|
|
160
|
+
const FeishuConnectionModeSchema = z.enum(["websocket", "webhook"]);
|
|
161
|
+
const TtsOverrideSchema = z.object({
|
|
162
|
+
auto: z.enum([
|
|
163
|
+
"off",
|
|
164
|
+
"always",
|
|
165
|
+
"inbound",
|
|
166
|
+
"tagged"
|
|
167
|
+
]).optional(),
|
|
168
|
+
enabled: z.boolean().optional(),
|
|
169
|
+
mode: z.enum(["final", "all"]).optional(),
|
|
170
|
+
provider: z.string().optional(),
|
|
171
|
+
persona: z.string().optional(),
|
|
172
|
+
personas: z.record(z.string(), z.record(z.string(), z.unknown())).optional(),
|
|
173
|
+
summaryModel: z.string().optional(),
|
|
174
|
+
modelOverrides: z.record(z.string(), z.unknown()).optional(),
|
|
175
|
+
providers: z.record(z.string(), z.record(z.string(), z.unknown())).optional(),
|
|
176
|
+
prefsPath: z.string().optional(),
|
|
177
|
+
maxTextLength: z.number().int().min(1).optional(),
|
|
178
|
+
timeoutMs: z.number().int().min(1e3).max(12e4).optional()
|
|
179
|
+
}).strict().optional();
|
|
180
|
+
const ToolPolicySchema = z.object({
|
|
181
|
+
allow: z.array(z.string()).optional(),
|
|
182
|
+
deny: z.array(z.string()).optional()
|
|
183
|
+
}).strict().optional();
|
|
184
|
+
const DmConfigSchema = z.object({
|
|
185
|
+
enabled: z.boolean().optional(),
|
|
186
|
+
systemPrompt: z.string().optional()
|
|
187
|
+
}).strict().optional();
|
|
188
|
+
const MarkdownConfigSchema = z.object({
|
|
189
|
+
mode: z.enum([
|
|
190
|
+
"native",
|
|
191
|
+
"escape",
|
|
192
|
+
"strip"
|
|
193
|
+
]).optional(),
|
|
194
|
+
tableMode: z.enum([
|
|
195
|
+
"native",
|
|
196
|
+
"ascii",
|
|
197
|
+
"simple"
|
|
198
|
+
]).optional()
|
|
199
|
+
}).strict().optional();
|
|
200
|
+
const RenderModeSchema = z.enum([
|
|
201
|
+
"auto",
|
|
202
|
+
"raw",
|
|
203
|
+
"card"
|
|
204
|
+
]).optional();
|
|
205
|
+
const StreamingModeSchema = z.boolean().optional();
|
|
206
|
+
const BlockStreamingSchema = z.boolean().optional();
|
|
207
|
+
const BlockStreamingCoalesceSchema = z.object({
|
|
208
|
+
enabled: z.boolean().optional(),
|
|
209
|
+
minDelayMs: z.number().int().positive().optional(),
|
|
210
|
+
maxDelayMs: z.number().int().positive().optional()
|
|
211
|
+
}).strict().optional();
|
|
212
|
+
const ChannelHeartbeatVisibilitySchema = z.object({
|
|
213
|
+
visibility: z.enum(["visible", "hidden"]).optional(),
|
|
214
|
+
intervalMs: z.number().int().positive().optional()
|
|
215
|
+
}).strict().optional();
|
|
216
|
+
/**
|
|
217
|
+
* Dynamic agent creation configuration.
|
|
218
|
+
* When enabled, a new agent is created for each unique DM user.
|
|
219
|
+
*/
|
|
220
|
+
const DynamicAgentCreationSchema = z.object({
|
|
221
|
+
enabled: z.boolean().optional(),
|
|
222
|
+
workspaceTemplate: z.string().optional(),
|
|
223
|
+
agentDirTemplate: z.string().optional(),
|
|
224
|
+
maxAgents: z.number().int().positive().optional()
|
|
225
|
+
}).strict().optional();
|
|
226
|
+
/**
|
|
227
|
+
* Feishu tools configuration.
|
|
228
|
+
* Controls which tool categories are enabled.
|
|
229
|
+
*
|
|
230
|
+
* Dependencies:
|
|
231
|
+
* - wiki requires doc (wiki content is edited via doc tools)
|
|
232
|
+
* - perm can work independently but is typically used with drive
|
|
233
|
+
*/
|
|
234
|
+
const FeishuToolsConfigSchema = z.object({
|
|
235
|
+
doc: z.boolean().optional(),
|
|
236
|
+
chat: z.boolean().optional(),
|
|
237
|
+
wiki: z.boolean().optional(),
|
|
238
|
+
drive: z.boolean().optional(),
|
|
239
|
+
perm: z.boolean().optional(),
|
|
240
|
+
scopes: z.boolean().optional()
|
|
241
|
+
}).strict().optional();
|
|
242
|
+
/**
|
|
243
|
+
* Group session scope for routing Feishu group messages.
|
|
244
|
+
* - "group" (default): one session per group chat
|
|
245
|
+
* - "group_sender": one session per (group + sender)
|
|
246
|
+
* - "group_topic": one session per group topic thread (falls back to group if no topic)
|
|
247
|
+
* - "group_topic_sender": one session per (group + topic thread + sender),
|
|
248
|
+
* falls back to (group + sender) if no topic
|
|
249
|
+
*/
|
|
250
|
+
const GroupSessionScopeSchema = z.enum([
|
|
251
|
+
"group",
|
|
252
|
+
"group_sender",
|
|
253
|
+
"group_topic",
|
|
254
|
+
"group_topic_sender"
|
|
255
|
+
]).optional();
|
|
256
|
+
/**
|
|
257
|
+
* @deprecated Use groupSessionScope instead.
|
|
258
|
+
*
|
|
259
|
+
* Topic session isolation mode for group chats.
|
|
260
|
+
* - "disabled" (default): All messages in a group share one session
|
|
261
|
+
* - "enabled": Messages in different topics get separate sessions
|
|
262
|
+
*
|
|
263
|
+
* Topic routing uses Feishu topic-group `thread_id` when the event identifies a
|
|
264
|
+
* native topic group, and keeps `root_id` precedence for normal groups so
|
|
265
|
+
* reply-created threads stay on the initiating message session.
|
|
266
|
+
*/
|
|
267
|
+
const TopicSessionModeSchema = z.enum(["disabled", "enabled"]).optional();
|
|
268
|
+
const ReactionNotificationModeSchema = z.enum([
|
|
269
|
+
"off",
|
|
270
|
+
"own",
|
|
271
|
+
"all"
|
|
272
|
+
]).optional();
|
|
273
|
+
/**
|
|
274
|
+
* Reply-in-thread mode for group chats.
|
|
275
|
+
* - "disabled" (default): Bot replies are normal inline replies
|
|
276
|
+
* - "enabled": Bot replies create or continue a Feishu topic thread
|
|
277
|
+
*
|
|
278
|
+
* When enabled, the Feishu reply API is called with `reply_in_thread: true`,
|
|
279
|
+
* causing the reply to appear as a topic (话题) under the original message.
|
|
280
|
+
*/
|
|
281
|
+
const ReplyInThreadSchema = z.enum(["disabled", "enabled"]).optional();
|
|
282
|
+
const FeishuGroupSchema = z.object({
|
|
283
|
+
requireMention: z.boolean().optional(),
|
|
284
|
+
tools: ToolPolicySchema,
|
|
285
|
+
skills: z.array(z.string()).optional(),
|
|
286
|
+
enabled: z.boolean().optional(),
|
|
287
|
+
allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
|
|
288
|
+
systemPrompt: z.string().optional(),
|
|
289
|
+
groupSessionScope: GroupSessionScopeSchema,
|
|
290
|
+
topicSessionMode: TopicSessionModeSchema,
|
|
291
|
+
replyInThread: ReplyInThreadSchema
|
|
292
|
+
}).strict();
|
|
293
|
+
const FeishuSharedConfigShape = {
|
|
294
|
+
webhookHost: z.string().optional(),
|
|
295
|
+
webhookPort: z.number().int().positive().optional(),
|
|
296
|
+
capabilities: z.array(z.string()).optional(),
|
|
297
|
+
markdown: MarkdownConfigSchema,
|
|
298
|
+
configWrites: z.boolean().optional(),
|
|
299
|
+
dmPolicy: DmPolicySchema.optional(),
|
|
300
|
+
allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
|
|
301
|
+
groupPolicy: GroupPolicySchema.optional(),
|
|
302
|
+
groupAllowFrom: z.array(z.union([z.string(), z.number()])).optional(),
|
|
303
|
+
groupSenderAllowFrom: z.array(z.union([z.string(), z.number()])).optional(),
|
|
304
|
+
requireMention: z.boolean().optional(),
|
|
305
|
+
groups: z.record(z.string(), FeishuGroupSchema.optional()).optional(),
|
|
306
|
+
historyLimit: z.number().int().min(0).optional(),
|
|
307
|
+
dmHistoryLimit: z.number().int().min(0).optional(),
|
|
308
|
+
dms: z.record(z.string(), DmConfigSchema).optional(),
|
|
309
|
+
textChunkLimit: z.number().int().positive().optional(),
|
|
310
|
+
chunkMode: z.enum(["length", "newline"]).optional(),
|
|
311
|
+
blockStreaming: BlockStreamingSchema,
|
|
312
|
+
blockStreamingCoalesce: BlockStreamingCoalesceSchema,
|
|
313
|
+
mediaMaxMb: z.number().positive().optional(),
|
|
314
|
+
httpTimeoutMs: z.number().int().positive().max(3e5).optional(),
|
|
315
|
+
heartbeat: ChannelHeartbeatVisibilitySchema,
|
|
316
|
+
renderMode: RenderModeSchema,
|
|
317
|
+
streaming: StreamingModeSchema,
|
|
318
|
+
tools: FeishuToolsConfigSchema,
|
|
319
|
+
actions: ChannelActionsSchema,
|
|
320
|
+
replyInThread: ReplyInThreadSchema,
|
|
321
|
+
reactionNotifications: ReactionNotificationModeSchema,
|
|
322
|
+
typingIndicator: z.boolean().optional(),
|
|
323
|
+
resolveSenderNames: z.boolean().optional(),
|
|
324
|
+
tts: TtsOverrideSchema
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Per-account configuration.
|
|
328
|
+
* All fields are optional - missing fields inherit from top-level config.
|
|
329
|
+
*/
|
|
330
|
+
const FeishuAccountConfigSchema = z.object({
|
|
331
|
+
enabled: z.boolean().optional(),
|
|
332
|
+
name: z.string().optional(),
|
|
333
|
+
appId: z.string().optional(),
|
|
334
|
+
appSecret: buildSecretInputSchema().optional(),
|
|
335
|
+
encryptKey: buildSecretInputSchema().optional(),
|
|
336
|
+
verificationToken: buildSecretInputSchema().optional(),
|
|
337
|
+
domain: FeishuDomainSchema.optional(),
|
|
338
|
+
connectionMode: FeishuConnectionModeSchema.optional(),
|
|
339
|
+
webhookPath: z.string().optional(),
|
|
340
|
+
...FeishuSharedConfigShape,
|
|
341
|
+
groupSessionScope: GroupSessionScopeSchema,
|
|
342
|
+
topicSessionMode: TopicSessionModeSchema
|
|
343
|
+
}).strict();
|
|
344
|
+
const FeishuConfigSchema = z.object({
|
|
345
|
+
enabled: z.boolean().optional(),
|
|
346
|
+
defaultAccount: z.string().optional(),
|
|
347
|
+
appId: z.string().optional(),
|
|
348
|
+
appSecret: buildSecretInputSchema().optional(),
|
|
349
|
+
encryptKey: buildSecretInputSchema().optional(),
|
|
350
|
+
verificationToken: buildSecretInputSchema().optional(),
|
|
351
|
+
domain: FeishuDomainSchema.optional().default("feishu"),
|
|
352
|
+
connectionMode: FeishuConnectionModeSchema.optional().default("websocket"),
|
|
353
|
+
webhookPath: z.string().optional().default("/feishu/events"),
|
|
354
|
+
...FeishuSharedConfigShape,
|
|
355
|
+
dmPolicy: DmPolicySchema.optional().default("pairing"),
|
|
356
|
+
reactionNotifications: ReactionNotificationModeSchema.optional().default("own"),
|
|
357
|
+
groupPolicy: GroupPolicySchema.optional().default("allowlist"),
|
|
358
|
+
requireMention: z.boolean().optional(),
|
|
359
|
+
groupSessionScope: GroupSessionScopeSchema,
|
|
360
|
+
topicSessionMode: TopicSessionModeSchema,
|
|
361
|
+
dynamicAgentCreation: DynamicAgentCreationSchema,
|
|
362
|
+
typingIndicator: z.boolean().optional().default(true),
|
|
363
|
+
resolveSenderNames: z.boolean().optional().default(true),
|
|
364
|
+
accounts: z.record(z.string(), FeishuAccountConfigSchema.optional()).optional()
|
|
365
|
+
}).strict().superRefine((value, ctx) => {
|
|
366
|
+
const defaultAccount = value.defaultAccount?.trim();
|
|
367
|
+
if (defaultAccount && value.accounts && Object.keys(value.accounts).length > 0) {
|
|
368
|
+
const normalizedDefaultAccount = normalizeAccountId$1(defaultAccount);
|
|
369
|
+
if (!Object.prototype.hasOwnProperty.call(value.accounts, normalizedDefaultAccount)) ctx.addIssue({
|
|
370
|
+
code: z.ZodIssueCode.custom,
|
|
371
|
+
path: ["defaultAccount"],
|
|
372
|
+
message: `channels.feishu.defaultAccount="${defaultAccount}" does not match a configured account key`
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
const defaultConnectionMode = value.connectionMode ?? "websocket";
|
|
376
|
+
const defaultVerificationTokenConfigured = hasConfiguredSecretInput$2(value.verificationToken);
|
|
377
|
+
const defaultEncryptKeyConfigured = hasConfiguredSecretInput$2(value.encryptKey);
|
|
378
|
+
if (defaultConnectionMode === "webhook") {
|
|
379
|
+
if (!defaultVerificationTokenConfigured) ctx.addIssue({
|
|
380
|
+
code: z.ZodIssueCode.custom,
|
|
381
|
+
path: ["verificationToken"],
|
|
382
|
+
message: "channels.feishu.connectionMode=\"webhook\" requires channels.feishu.verificationToken"
|
|
383
|
+
});
|
|
384
|
+
if (!defaultEncryptKeyConfigured) ctx.addIssue({
|
|
385
|
+
code: z.ZodIssueCode.custom,
|
|
386
|
+
path: ["encryptKey"],
|
|
387
|
+
message: "channels.feishu.connectionMode=\"webhook\" requires channels.feishu.encryptKey"
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
for (const [accountId, account] of Object.entries(value.accounts ?? {})) {
|
|
391
|
+
if (!account) continue;
|
|
392
|
+
if ((account.connectionMode ?? defaultConnectionMode) !== "webhook") continue;
|
|
393
|
+
const accountVerificationTokenConfigured = hasConfiguredSecretInput$2(account.verificationToken) || defaultVerificationTokenConfigured;
|
|
394
|
+
const accountEncryptKeyConfigured = hasConfiguredSecretInput$2(account.encryptKey) || defaultEncryptKeyConfigured;
|
|
395
|
+
if (!accountVerificationTokenConfigured) ctx.addIssue({
|
|
396
|
+
code: z.ZodIssueCode.custom,
|
|
397
|
+
path: [
|
|
398
|
+
"accounts",
|
|
399
|
+
accountId,
|
|
400
|
+
"verificationToken"
|
|
401
|
+
],
|
|
402
|
+
message: `channels.feishu.accounts.${accountId}.connectionMode="webhook" requires a verificationToken (account-level or top-level)`
|
|
403
|
+
});
|
|
404
|
+
if (!accountEncryptKeyConfigured) ctx.addIssue({
|
|
405
|
+
code: z.ZodIssueCode.custom,
|
|
406
|
+
path: [
|
|
407
|
+
"accounts",
|
|
408
|
+
accountId,
|
|
409
|
+
"encryptKey"
|
|
410
|
+
],
|
|
411
|
+
message: `channels.feishu.accounts.${accountId}.connectionMode="webhook" requires an encryptKey (account-level or top-level)`
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
if (value.dmPolicy === "open") {
|
|
415
|
+
if (!(value.allowFrom ?? []).some((entry) => String(entry).trim() === "*")) ctx.addIssue({
|
|
416
|
+
code: z.ZodIssueCode.custom,
|
|
417
|
+
path: ["allowFrom"],
|
|
418
|
+
message: "channels.feishu.dmPolicy=\"open\" requires channels.feishu.allowFrom to include \"*\""
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region extensions/feishu/src/directory.static.ts
|
|
424
|
+
function toFeishuDirectoryPeers(ids) {
|
|
425
|
+
return ids.map((id) => ({
|
|
426
|
+
kind: "user",
|
|
427
|
+
id
|
|
428
|
+
}));
|
|
429
|
+
}
|
|
430
|
+
function toFeishuDirectoryGroups(ids) {
|
|
431
|
+
return ids.map((id) => ({
|
|
432
|
+
kind: "group",
|
|
433
|
+
id
|
|
434
|
+
}));
|
|
435
|
+
}
|
|
436
|
+
async function listFeishuDirectoryPeers(params) {
|
|
437
|
+
const account = resolveFeishuAccount({
|
|
438
|
+
cfg: params.cfg,
|
|
439
|
+
accountId: params.accountId
|
|
440
|
+
});
|
|
441
|
+
return toFeishuDirectoryPeers(listDirectoryUserEntriesFromAllowFromAndMapKeys({
|
|
442
|
+
allowFrom: account.config.allowFrom,
|
|
443
|
+
map: account.config.dms,
|
|
444
|
+
query: params.query,
|
|
445
|
+
limit: params.limit,
|
|
446
|
+
normalizeAllowFromId: (entry) => normalizeFeishuTarget(entry) ?? entry,
|
|
447
|
+
normalizeMapKeyId: (entry) => normalizeFeishuTarget(entry) ?? entry
|
|
448
|
+
}).map((entry) => entry.id));
|
|
449
|
+
}
|
|
450
|
+
async function listFeishuDirectoryGroups(params) {
|
|
451
|
+
const account = resolveFeishuAccount({
|
|
452
|
+
cfg: params.cfg,
|
|
453
|
+
accountId: params.accountId
|
|
454
|
+
});
|
|
455
|
+
return toFeishuDirectoryGroups(listDirectoryGroupEntriesFromMapKeysAndAllowFrom({
|
|
456
|
+
groups: account.config.groups,
|
|
457
|
+
allowFrom: account.config.groupAllowFrom,
|
|
458
|
+
query: params.query,
|
|
459
|
+
limit: params.limit
|
|
460
|
+
}).map((entry) => entry.id));
|
|
461
|
+
}
|
|
462
|
+
//#endregion
|
|
463
|
+
//#region extensions/feishu/src/policy.ts
|
|
464
|
+
const FEISHU_PROVIDER_PREFIX_RE = /^(feishu|lark):/i;
|
|
465
|
+
const FEISHU_TYPED_PREFIX_RE = /^(chat|group|channel|user|dm|open_id):/i;
|
|
466
|
+
const FEISHU_ID_KIND = "plugin:feishu-id";
|
|
467
|
+
const feishuIngressIdentity = defineStableChannelIngressIdentity({
|
|
468
|
+
key: "feishu-id",
|
|
469
|
+
kind: FEISHU_ID_KIND,
|
|
470
|
+
normalize: normalizeFeishuAllowEntry,
|
|
471
|
+
sensitivity: "pii",
|
|
472
|
+
aliases: [{
|
|
473
|
+
key: "feishu-alt-id",
|
|
474
|
+
kind: FEISHU_ID_KIND,
|
|
475
|
+
normalizeEntry: () => null,
|
|
476
|
+
normalizeSubject: normalizeFeishuAllowEntry,
|
|
477
|
+
sensitivity: "pii"
|
|
478
|
+
}],
|
|
479
|
+
isWildcardEntry: (entry) => normalizeFeishuAllowEntry(entry) === "*",
|
|
480
|
+
resolveEntryId: ({ entryIndex }) => `feishu-entry-${entryIndex + 1}`
|
|
481
|
+
});
|
|
482
|
+
function normalizeFeishuAllowEntry(raw) {
|
|
483
|
+
const trimmed = raw.trim();
|
|
484
|
+
if (!trimmed) return "";
|
|
485
|
+
if (trimmed === "*") return "*";
|
|
486
|
+
let withoutProviderPrefix = trimmed;
|
|
487
|
+
while (FEISHU_PROVIDER_PREFIX_RE.test(withoutProviderPrefix)) withoutProviderPrefix = withoutProviderPrefix.replace(FEISHU_PROVIDER_PREFIX_RE, "").trim();
|
|
488
|
+
if (withoutProviderPrefix === "*") return "*";
|
|
489
|
+
const lowered = normalizeOptionalLowercaseString(withoutProviderPrefix) ?? "";
|
|
490
|
+
if (!lowered) return "";
|
|
491
|
+
const prefixed = lowered.match(FEISHU_TYPED_PREFIX_RE);
|
|
492
|
+
if (prefixed?.[1]) {
|
|
493
|
+
const kind = [
|
|
494
|
+
"chat",
|
|
495
|
+
"group",
|
|
496
|
+
"channel"
|
|
497
|
+
].includes(prefixed[1]) ? "chat" : "user";
|
|
498
|
+
const value = withoutProviderPrefix.slice(prefixed[0].length).trim();
|
|
499
|
+
return value === "*" ? "*" : value ? `${kind}:${value}` : "";
|
|
500
|
+
}
|
|
501
|
+
const detectedType = detectIdType(withoutProviderPrefix);
|
|
502
|
+
if (detectedType === "chat_id") return `chat:${withoutProviderPrefix}`;
|
|
503
|
+
if (detectedType === "open_id" || detectedType === "user_id") return `user:${withoutProviderPrefix}`;
|
|
504
|
+
return "";
|
|
505
|
+
}
|
|
506
|
+
function normalizeFeishuDmPolicy(policy) {
|
|
507
|
+
return policy === "open" || policy === "pairing" || policy === "allowlist" || policy === "disabled" ? policy : "pairing";
|
|
508
|
+
}
|
|
509
|
+
function normalizeFeishuGroupPolicy(policy) {
|
|
510
|
+
return policy === "allowall" ? "open" : policy;
|
|
511
|
+
}
|
|
512
|
+
function createFeishuIngressSubject(params) {
|
|
513
|
+
const ids = [params.primaryId, ...params.alternateIds ?? []].map((value) => value?.trim()).filter((value) => Boolean(value));
|
|
514
|
+
return {
|
|
515
|
+
stableId: ids[0],
|
|
516
|
+
aliases: { "feishu-alt-id": ids[1] }
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
function createFeishuIngressResolver(params) {
|
|
520
|
+
return createChannelIngressResolver({
|
|
521
|
+
channelId: "feishu",
|
|
522
|
+
accountId: normalizeAccountId(params.accountId) ?? "default",
|
|
523
|
+
identity: feishuIngressIdentity,
|
|
524
|
+
cfg: params.cfg,
|
|
525
|
+
...params.readAllowFromStore ? { readStoreAllowFrom: params.readAllowFromStore } : {}
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
async function resolveFeishuDmIngressAccess(params) {
|
|
529
|
+
return await createFeishuIngressResolver({
|
|
530
|
+
cfg: params.cfg,
|
|
531
|
+
accountId: params.accountId,
|
|
532
|
+
readAllowFromStore: params.readAllowFromStore
|
|
533
|
+
}).message({
|
|
534
|
+
subject: createFeishuIngressSubject({
|
|
535
|
+
primaryId: params.senderOpenId,
|
|
536
|
+
alternateIds: [params.senderUserId]
|
|
537
|
+
}),
|
|
538
|
+
conversation: {
|
|
539
|
+
kind: "direct",
|
|
540
|
+
id: params.conversationId
|
|
541
|
+
},
|
|
542
|
+
event: { mayPair: params.mayPair },
|
|
543
|
+
dmPolicy: normalizeFeishuDmPolicy(params.dmPolicy),
|
|
544
|
+
groupPolicy: "disabled",
|
|
545
|
+
allowFrom: params.allowFrom ?? [],
|
|
546
|
+
...params.command ? { command: params.command } : {}
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
async function resolveFeishuGroupConversationIngressAccess(params) {
|
|
550
|
+
const groupPolicy = normalizeFeishuGroupPolicy(params.groupPolicy);
|
|
551
|
+
const groupAllowFrom = groupPolicy === "allowlist" && params.groupExplicitlyConfigured ? [...params.groupAllowFrom ?? [], params.chatId] : params.groupAllowFrom ?? [];
|
|
552
|
+
return await createFeishuIngressResolver({
|
|
553
|
+
cfg: params.cfg,
|
|
554
|
+
accountId: params.accountId
|
|
555
|
+
}).message({
|
|
556
|
+
subject: createFeishuIngressSubject({ primaryId: params.chatId }),
|
|
557
|
+
conversation: {
|
|
558
|
+
kind: "group",
|
|
559
|
+
id: params.chatId
|
|
560
|
+
},
|
|
561
|
+
dmPolicy: "disabled",
|
|
562
|
+
groupPolicy,
|
|
563
|
+
groupAllowFrom
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
async function resolveFeishuGroupSenderActivationIngressAccess(params) {
|
|
567
|
+
const groupAllowFrom = params.allowFrom ?? [];
|
|
568
|
+
return await createFeishuIngressResolver({
|
|
569
|
+
cfg: params.cfg,
|
|
570
|
+
accountId: params.accountId
|
|
571
|
+
}).message({
|
|
572
|
+
subject: createFeishuIngressSubject({
|
|
573
|
+
primaryId: params.senderOpenId,
|
|
574
|
+
alternateIds: [params.senderUserId]
|
|
575
|
+
}),
|
|
576
|
+
conversation: {
|
|
577
|
+
kind: "group",
|
|
578
|
+
id: params.chatId
|
|
579
|
+
},
|
|
580
|
+
dmPolicy: "disabled",
|
|
581
|
+
groupPolicy: groupAllowFrom.length > 0 ? "allowlist" : "open",
|
|
582
|
+
groupAllowFrom,
|
|
583
|
+
mentionFacts: {
|
|
584
|
+
canDetectMention: true,
|
|
585
|
+
wasMentioned: params.mentionedBot
|
|
586
|
+
},
|
|
587
|
+
policy: { activation: {
|
|
588
|
+
requireMention: params.requireMention,
|
|
589
|
+
allowTextCommands: false
|
|
590
|
+
} },
|
|
591
|
+
...params.command ? { command: params.command } : {}
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
function resolveFeishuGroupConfig(params) {
|
|
595
|
+
const groups = params.cfg?.groups ?? {};
|
|
596
|
+
const wildcard = groups["*"];
|
|
597
|
+
const groupId = params.groupId?.trim();
|
|
598
|
+
if (!groupId) return;
|
|
599
|
+
const direct = groups[groupId];
|
|
600
|
+
if (direct) return direct;
|
|
601
|
+
const lowered = normalizeOptionalLowercaseString(groupId) ?? "";
|
|
602
|
+
const matchKey = Object.keys(groups).find((key) => normalizeOptionalLowercaseString(key) === lowered);
|
|
603
|
+
if (matchKey) return groups[matchKey];
|
|
604
|
+
return wildcard;
|
|
605
|
+
}
|
|
606
|
+
function hasExplicitFeishuGroupConfig(params) {
|
|
607
|
+
const groups = params.cfg?.groups ?? {};
|
|
608
|
+
const groupId = params.groupId?.trim();
|
|
609
|
+
if (!groupId) return false;
|
|
610
|
+
if (Object.prototype.hasOwnProperty.call(groups, groupId) && groupId !== "*") return true;
|
|
611
|
+
const lowered = normalizeOptionalLowercaseString(groupId) ?? "";
|
|
612
|
+
return Object.keys(groups).some((key) => key !== "*" && normalizeOptionalLowercaseString(key) === lowered);
|
|
613
|
+
}
|
|
614
|
+
function resolveFeishuGroupToolPolicy(params) {
|
|
615
|
+
const cfg = params.cfg.channels?.feishu;
|
|
616
|
+
if (!cfg) return;
|
|
617
|
+
return resolveFeishuGroupConfig({
|
|
618
|
+
cfg,
|
|
619
|
+
groupId: params.groupId
|
|
620
|
+
})?.tools;
|
|
621
|
+
}
|
|
622
|
+
function resolveFeishuReplyPolicy(params) {
|
|
623
|
+
if (params.isDirectMessage) return { requireMention: false };
|
|
624
|
+
const feishuCfg = params.cfg.channels?.feishu;
|
|
625
|
+
const resolvedCfg = resolveMergedAccountConfig({
|
|
626
|
+
channelConfig: feishuCfg,
|
|
627
|
+
accounts: feishuCfg?.accounts,
|
|
628
|
+
accountId: normalizeAccountId(params.accountId),
|
|
629
|
+
normalizeAccountId,
|
|
630
|
+
omitKeys: ["defaultAccount"]
|
|
631
|
+
});
|
|
632
|
+
const groupRequireMention = resolveFeishuGroupConfig({
|
|
633
|
+
cfg: resolvedCfg,
|
|
634
|
+
groupId: params.groupId
|
|
635
|
+
})?.requireMention;
|
|
636
|
+
return { requireMention: typeof groupRequireMention === "boolean" ? groupRequireMention : typeof resolvedCfg.requireMention === "boolean" ? resolvedCfg.requireMention : params.groupPolicy !== "open" };
|
|
637
|
+
}
|
|
638
|
+
//#endregion
|
|
639
|
+
//#region extensions/feishu/src/send-result.ts
|
|
640
|
+
function resolveFeishuReceiptKind(msgType) {
|
|
641
|
+
switch (msgType) {
|
|
642
|
+
case "audio": return "voice";
|
|
643
|
+
case "image":
|
|
644
|
+
case "media":
|
|
645
|
+
case "file": return "media";
|
|
646
|
+
case "interactive": return "card";
|
|
647
|
+
case "post":
|
|
648
|
+
case "text": return "text";
|
|
649
|
+
default: return "unknown";
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
function createFeishuSendReceipt(params) {
|
|
653
|
+
const messageId = params.messageId?.trim();
|
|
654
|
+
const chatId = params.chatId.trim();
|
|
655
|
+
return createMessageReceiptFromOutboundResults({
|
|
656
|
+
results: messageId ? [{
|
|
657
|
+
channel: "feishu",
|
|
658
|
+
messageId,
|
|
659
|
+
chatId,
|
|
660
|
+
conversationId: chatId
|
|
661
|
+
}] : [],
|
|
662
|
+
...chatId ? { threadId: chatId } : {},
|
|
663
|
+
kind: params.kind ?? "unknown"
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
function assertFeishuMessageApiSuccess(response, errorPrefix) {
|
|
667
|
+
if (response.code !== 0) throw new Error(`${errorPrefix}: ${response.msg || `code ${response.code}`}`);
|
|
668
|
+
}
|
|
669
|
+
function toFeishuSendResult(response, chatId, kind) {
|
|
670
|
+
const messageId = response.data?.message_id ?? "unknown";
|
|
671
|
+
return {
|
|
672
|
+
messageId,
|
|
673
|
+
chatId,
|
|
674
|
+
receipt: createFeishuSendReceipt({
|
|
675
|
+
messageId,
|
|
676
|
+
chatId,
|
|
677
|
+
kind
|
|
678
|
+
})
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
//#endregion
|
|
682
|
+
//#region extensions/feishu/src/session-route.ts
|
|
683
|
+
function resolveFeishuOutboundSessionRoute(params) {
|
|
684
|
+
let trimmed = stripChannelTargetPrefix(params.target, "feishu", "lark");
|
|
685
|
+
if (!trimmed) return null;
|
|
686
|
+
const lower = normalizeLowercaseStringOrEmpty(trimmed);
|
|
687
|
+
let isGroup = false;
|
|
688
|
+
let typeExplicit = false;
|
|
689
|
+
if (lower.startsWith("group:") || lower.startsWith("chat:") || lower.startsWith("channel:")) {
|
|
690
|
+
trimmed = trimmed.replace(/^(group|chat|channel):/i, "").trim();
|
|
691
|
+
isGroup = true;
|
|
692
|
+
typeExplicit = true;
|
|
693
|
+
} else if (lower.startsWith("user:") || lower.startsWith("dm:")) {
|
|
694
|
+
trimmed = trimmed.replace(/^(user|dm):/i, "").trim();
|
|
695
|
+
isGroup = false;
|
|
696
|
+
typeExplicit = true;
|
|
697
|
+
}
|
|
698
|
+
if (!typeExplicit) {
|
|
699
|
+
const idLower = normalizeLowercaseStringOrEmpty(trimmed);
|
|
700
|
+
if (idLower.startsWith("ou_") || idLower.startsWith("on_")) isGroup = false;
|
|
701
|
+
}
|
|
702
|
+
return buildChannelOutboundSessionRoute({
|
|
703
|
+
cfg: params.cfg,
|
|
704
|
+
agentId: params.agentId,
|
|
705
|
+
channel: "feishu",
|
|
706
|
+
accountId: params.accountId,
|
|
707
|
+
peer: {
|
|
708
|
+
kind: isGroup ? "group" : "direct",
|
|
709
|
+
id: trimmed
|
|
710
|
+
},
|
|
711
|
+
chatType: isGroup ? "group" : "direct",
|
|
712
|
+
from: isGroup ? `feishu:group:${trimmed}` : `feishu:${trimmed}`,
|
|
713
|
+
to: trimmed
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
//#endregion
|
|
717
|
+
//#region extensions/feishu/src/setup-core.ts
|
|
718
|
+
function setFeishuNamedAccountEnabled$1(cfg, accountId, enabled) {
|
|
719
|
+
const feishuCfg = cfg.channels?.feishu;
|
|
720
|
+
return {
|
|
721
|
+
...cfg,
|
|
722
|
+
channels: {
|
|
723
|
+
...cfg.channels,
|
|
724
|
+
feishu: {
|
|
725
|
+
...feishuCfg,
|
|
726
|
+
accounts: {
|
|
727
|
+
...feishuCfg?.accounts,
|
|
728
|
+
[accountId]: {
|
|
729
|
+
...feishuCfg?.accounts?.[accountId],
|
|
730
|
+
enabled
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
const feishuSetupAdapter = {
|
|
738
|
+
resolveAccountId: ({ cfg, accountId }) => accountId?.trim() || resolveDefaultFeishuAccountId(cfg),
|
|
739
|
+
applyAccountConfig: ({ cfg, accountId }) => {
|
|
740
|
+
if (!accountId || accountId === DEFAULT_ACCOUNT_ID$1) return {
|
|
741
|
+
...cfg,
|
|
742
|
+
channels: {
|
|
743
|
+
...cfg.channels,
|
|
744
|
+
feishu: {
|
|
745
|
+
...cfg.channels?.feishu,
|
|
746
|
+
enabled: true
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
return setFeishuNamedAccountEnabled$1(cfg, accountId, true);
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
//#endregion
|
|
754
|
+
//#region extensions/feishu/src/setup-surface.ts
|
|
755
|
+
const t = createSetupTranslator();
|
|
756
|
+
const channel = "feishu";
|
|
757
|
+
const SCAN_TO_CREATE_TP = "ob_cli_app";
|
|
758
|
+
const FEISHU_SETUP_FLOW_KEY = "_flow";
|
|
759
|
+
function normalizeString(value) {
|
|
760
|
+
if (typeof value !== "string") return;
|
|
761
|
+
return value.trim() || void 0;
|
|
762
|
+
}
|
|
763
|
+
function isFeishuConfigured(cfg) {
|
|
764
|
+
const feishuCfg = cfg.channels?.feishu;
|
|
765
|
+
const isAppIdConfigured = (value) => {
|
|
766
|
+
if (normalizeString(value)) return true;
|
|
767
|
+
if (!value || typeof value !== "object") return false;
|
|
768
|
+
const rec = value;
|
|
769
|
+
const source = normalizeString(rec.source)?.toLowerCase();
|
|
770
|
+
const id = normalizeString(rec.id);
|
|
771
|
+
if (source === "env" && id) return Boolean(normalizeString(process.env[id]));
|
|
772
|
+
return hasConfiguredSecretInput$1(value);
|
|
773
|
+
};
|
|
774
|
+
const topLevelConfigured = isAppIdConfigured(feishuCfg?.appId) && hasConfiguredSecretInput$1(feishuCfg?.appSecret);
|
|
775
|
+
const accountConfigured = Object.values(feishuCfg?.accounts ?? {}).some((account) => {
|
|
776
|
+
if (!account || typeof account !== "object") return false;
|
|
777
|
+
const hasOwnAppId = Object.prototype.hasOwnProperty.call(account, "appId");
|
|
778
|
+
const hasOwnAppSecret = Object.prototype.hasOwnProperty.call(account, "appSecret");
|
|
779
|
+
const accountAppIdConfigured = hasOwnAppId ? isAppIdConfigured(account.appId) : isAppIdConfigured(feishuCfg?.appId);
|
|
780
|
+
const accountSecretConfigured = hasOwnAppSecret ? hasConfiguredSecretInput$1(account.appSecret) : hasConfiguredSecretInput$1(feishuCfg?.appSecret);
|
|
781
|
+
return accountAppIdConfigured && accountSecretConfigured;
|
|
782
|
+
});
|
|
783
|
+
return topLevelConfigured || accountConfigured;
|
|
784
|
+
}
|
|
785
|
+
function formatFeishuStatusLine(status) {
|
|
786
|
+
if (status === "needs-credentials") return `Feishu: ${t("wizard.channels.statusNeedsAppCredentials")}`;
|
|
787
|
+
return `Feishu: ${t("wizard.channels.statusConfiguredConnectionNotVerified")}`;
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Patch feishu config at the correct location based on accountId.
|
|
791
|
+
* - DEFAULT_ACCOUNT_ID → writes to top-level channels.feishu
|
|
792
|
+
* - named account → writes to channels.feishu.accounts[accountId]
|
|
793
|
+
*/
|
|
794
|
+
function patchFeishuConfig(cfg, accountId, patch) {
|
|
795
|
+
const feishuCfg = cfg.channels?.feishu;
|
|
796
|
+
if (accountId === DEFAULT_ACCOUNT_ID$1) return patchTopLevelChannelConfigSection({
|
|
797
|
+
cfg,
|
|
798
|
+
channel,
|
|
799
|
+
enabled: true,
|
|
800
|
+
patch
|
|
801
|
+
});
|
|
802
|
+
const nextAccountPatch = {
|
|
803
|
+
...feishuCfg?.accounts?.[accountId],
|
|
804
|
+
enabled: true,
|
|
805
|
+
...patch
|
|
806
|
+
};
|
|
807
|
+
return patchTopLevelChannelConfigSection({
|
|
808
|
+
cfg,
|
|
809
|
+
channel,
|
|
810
|
+
enabled: true,
|
|
811
|
+
patch: { accounts: {
|
|
812
|
+
...feishuCfg?.accounts,
|
|
813
|
+
[accountId]: nextAccountPatch
|
|
814
|
+
} }
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
async function promptFeishuAllowFrom(params) {
|
|
818
|
+
const feishuCfg = params.cfg.channels?.feishu;
|
|
819
|
+
const resolvedAccountId = params.accountId ?? resolveDefaultFeishuAccountId(params.cfg);
|
|
820
|
+
const existingAllowFrom = (resolvedAccountId !== DEFAULT_ACCOUNT_ID$1 ? feishuCfg?.accounts?.[resolvedAccountId] : void 0)?.allowFrom ?? feishuCfg?.allowFrom ?? [];
|
|
821
|
+
await params.prompter.note([
|
|
822
|
+
t("wizard.feishu.allowlistIntro"),
|
|
823
|
+
t("wizard.feishu.allowlistFindUser"),
|
|
824
|
+
t("wizard.feishu.examples"),
|
|
825
|
+
"- ou_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
|
826
|
+
"- on_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
827
|
+
].join("\n"), t("wizard.feishu.allowlistTitle"));
|
|
828
|
+
const mergedAllowFrom = mergeAllowFromEntries(existingAllowFrom, splitSetupEntries(await params.prompter.text({
|
|
829
|
+
message: t("wizard.feishu.allowFromPrompt"),
|
|
830
|
+
placeholder: "ou_xxxxx, ou_yyyyy",
|
|
831
|
+
initialValue: existingAllowFrom.length > 0 ? existingAllowFrom.map(String).join(", ") : void 0
|
|
832
|
+
})));
|
|
833
|
+
return patchFeishuConfig(params.cfg, resolvedAccountId, { allowFrom: mergedAllowFrom });
|
|
834
|
+
}
|
|
835
|
+
async function noteFeishuCredentialHelp(prompter) {
|
|
836
|
+
await prompter.note([
|
|
837
|
+
t("wizard.feishu.credentialsStepOpenPlatform"),
|
|
838
|
+
t("wizard.feishu.credentialsStepCreateApp"),
|
|
839
|
+
t("wizard.feishu.credentialsStepGetCredentials"),
|
|
840
|
+
t("wizard.feishu.credentialsStepPermissions"),
|
|
841
|
+
t("wizard.feishu.credentialsStepPublish"),
|
|
842
|
+
t("wizard.feishu.credentialsEnvTip"),
|
|
843
|
+
t("wizard.channels.docs", { link: formatDocsLink("/channels/feishu", "feishu") })
|
|
844
|
+
].join("\n"), t("wizard.feishu.credentialsTitle"));
|
|
845
|
+
}
|
|
846
|
+
async function promptFeishuAppId(params) {
|
|
847
|
+
return (await params.prompter.text({
|
|
848
|
+
message: t("wizard.feishu.appIdPrompt"),
|
|
849
|
+
initialValue: params.initialValue,
|
|
850
|
+
validate: (value) => value?.trim() ? void 0 : t("common.required")
|
|
851
|
+
})).trim();
|
|
852
|
+
}
|
|
853
|
+
const feishuDmPolicy = {
|
|
854
|
+
label: "Feishu",
|
|
855
|
+
channel,
|
|
856
|
+
policyKey: "channels.feishu.dmPolicy",
|
|
857
|
+
allowFromKey: "channels.feishu.allowFrom",
|
|
858
|
+
resolveConfigKeys: (_cfg, accountId) => {
|
|
859
|
+
const resolvedAccountId = accountId ?? resolveDefaultFeishuAccountId(_cfg);
|
|
860
|
+
return resolvedAccountId !== DEFAULT_ACCOUNT_ID$1 ? {
|
|
861
|
+
policyKey: `channels.feishu.accounts.${resolvedAccountId}.dmPolicy`,
|
|
862
|
+
allowFromKey: `channels.feishu.accounts.${resolvedAccountId}.allowFrom`
|
|
863
|
+
} : {
|
|
864
|
+
policyKey: "channels.feishu.dmPolicy",
|
|
865
|
+
allowFromKey: "channels.feishu.allowFrom"
|
|
866
|
+
};
|
|
867
|
+
},
|
|
868
|
+
getCurrent: (cfg, accountId) => {
|
|
869
|
+
const feishuCfg = cfg.channels?.feishu;
|
|
870
|
+
const resolvedAccountId = accountId ?? resolveDefaultFeishuAccountId(cfg);
|
|
871
|
+
if (resolvedAccountId !== DEFAULT_ACCOUNT_ID$1) {
|
|
872
|
+
const account = feishuCfg?.accounts?.[resolvedAccountId];
|
|
873
|
+
if (account?.dmPolicy) return account.dmPolicy;
|
|
874
|
+
}
|
|
875
|
+
return feishuCfg?.dmPolicy ?? "pairing";
|
|
876
|
+
},
|
|
877
|
+
setPolicy: (cfg, policy, accountId) => {
|
|
878
|
+
return patchFeishuConfig(cfg, accountId ?? resolveDefaultFeishuAccountId(cfg), {
|
|
879
|
+
dmPolicy: policy,
|
|
880
|
+
...policy === "open" ? { allowFrom: mergeAllowFromEntries([], ["*"]) } : {}
|
|
881
|
+
});
|
|
882
|
+
},
|
|
883
|
+
promptAllowFrom: promptFeishuAllowFrom
|
|
884
|
+
};
|
|
885
|
+
function applyNewAppSecurityPolicy(cfg, accountId, openId, groupPolicy) {
|
|
886
|
+
let next = cfg;
|
|
887
|
+
if (openId) next = patchFeishuConfig(next, accountId, {
|
|
888
|
+
dmPolicy: "allowlist",
|
|
889
|
+
allowFrom: [openId]
|
|
890
|
+
});
|
|
891
|
+
const groupPatch = { groupPolicy };
|
|
892
|
+
if (groupPolicy === "open") groupPatch.requireMention = true;
|
|
893
|
+
next = patchFeishuConfig(next, accountId, groupPatch);
|
|
894
|
+
return next;
|
|
895
|
+
}
|
|
896
|
+
async function promptFeishuDomain(params) {
|
|
897
|
+
return await params.prompter.select({
|
|
898
|
+
message: t("wizard.feishu.domainPrompt"),
|
|
899
|
+
options: [{
|
|
900
|
+
value: "feishu",
|
|
901
|
+
label: t("wizard.feishu.domainFeishu")
|
|
902
|
+
}, {
|
|
903
|
+
value: "lark",
|
|
904
|
+
label: t("wizard.feishu.domainLark")
|
|
905
|
+
}],
|
|
906
|
+
initialValue: params.initialValue ?? "feishu"
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
async function promptFeishuSetupMethod(prompter) {
|
|
910
|
+
return await prompter.select({
|
|
911
|
+
message: t("wizard.feishu.setupMethodPrompt"),
|
|
912
|
+
options: [{
|
|
913
|
+
value: "manual",
|
|
914
|
+
label: t("wizard.feishu.setupMethodManual")
|
|
915
|
+
}, {
|
|
916
|
+
value: "scan",
|
|
917
|
+
label: t("wizard.feishu.setupMethodScan")
|
|
918
|
+
}],
|
|
919
|
+
initialValue: "manual"
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
async function runScanToCreate(prompter, domain) {
|
|
923
|
+
const { beginAppRegistration, initAppRegistration, pollAppRegistration, printQrCode } = await import("./app-registration-DBSnysKJ.js");
|
|
924
|
+
try {
|
|
925
|
+
await initAppRegistration(domain);
|
|
926
|
+
} catch {
|
|
927
|
+
await prompter.note(t("wizard.feishu.scanUnavailable"), t("wizard.feishu.setupTitle"));
|
|
928
|
+
return null;
|
|
929
|
+
}
|
|
930
|
+
const begin = await beginAppRegistration(domain);
|
|
931
|
+
await prompter.note(t("wizard.feishu.scanQr"), t("wizard.feishu.scanTitle"));
|
|
932
|
+
await printQrCode(begin.qrUrl);
|
|
933
|
+
const progress = prompter.progress(t("wizard.feishu.fetchingConfig"));
|
|
934
|
+
const outcome = await pollAppRegistration({
|
|
935
|
+
deviceCode: begin.deviceCode,
|
|
936
|
+
interval: begin.interval,
|
|
937
|
+
expireIn: begin.expireIn,
|
|
938
|
+
initialDomain: domain,
|
|
939
|
+
tp: SCAN_TO_CREATE_TP
|
|
940
|
+
});
|
|
941
|
+
switch (outcome.status) {
|
|
942
|
+
case "success":
|
|
943
|
+
progress.stop(t("wizard.feishu.scanCompleted"));
|
|
944
|
+
return outcome.result;
|
|
945
|
+
case "access_denied":
|
|
946
|
+
progress.stop(t("wizard.feishu.scanDenied"));
|
|
947
|
+
return null;
|
|
948
|
+
case "expired":
|
|
949
|
+
progress.stop(t("wizard.feishu.scanExpired"));
|
|
950
|
+
return null;
|
|
951
|
+
case "timeout":
|
|
952
|
+
progress.stop(t("wizard.feishu.scanTimedOut"));
|
|
953
|
+
return null;
|
|
954
|
+
case "error":
|
|
955
|
+
progress.stop(t("wizard.feishu.scanError", { error: outcome.message }));
|
|
956
|
+
return null;
|
|
957
|
+
}
|
|
958
|
+
return null;
|
|
959
|
+
}
|
|
960
|
+
async function runNewAppFlow(params) {
|
|
961
|
+
const { prompter, options } = params;
|
|
962
|
+
let next = params.cfg;
|
|
963
|
+
const targetAccountId = resolveDefaultFeishuAccountId(next);
|
|
964
|
+
let appId = null;
|
|
965
|
+
let appSecret = null;
|
|
966
|
+
let appSecretProbeValue = null;
|
|
967
|
+
let scanDomain;
|
|
968
|
+
let scanOpenId;
|
|
969
|
+
const currentDomain = (next.channels?.feishu)?.domain ?? "feishu";
|
|
970
|
+
const setupMethod = await promptFeishuSetupMethod(prompter);
|
|
971
|
+
const selectedDomain = await promptFeishuDomain({
|
|
972
|
+
prompter,
|
|
973
|
+
initialValue: currentDomain
|
|
974
|
+
});
|
|
975
|
+
scanDomain = selectedDomain;
|
|
976
|
+
const scanResult = setupMethod === "scan" ? await runScanToCreate(prompter, selectedDomain) : null;
|
|
977
|
+
if (scanResult) {
|
|
978
|
+
appId = scanResult.appId;
|
|
979
|
+
appSecret = scanResult.appSecret;
|
|
980
|
+
appSecretProbeValue = scanResult.appSecret;
|
|
981
|
+
scanDomain = scanResult.domain;
|
|
982
|
+
scanOpenId = scanResult.openId;
|
|
983
|
+
} else {
|
|
984
|
+
await noteFeishuCredentialHelp(prompter);
|
|
985
|
+
appId = await promptFeishuAppId({
|
|
986
|
+
prompter,
|
|
987
|
+
initialValue: normalizeString(process.env.FEISHU_APP_ID)
|
|
988
|
+
});
|
|
989
|
+
const appSecretResult = await promptSingleChannelSecretInput({
|
|
990
|
+
cfg: next,
|
|
991
|
+
prompter,
|
|
992
|
+
providerHint: "feishu",
|
|
993
|
+
credentialLabel: "App Secret",
|
|
994
|
+
secretInputMode: options?.secretInputMode,
|
|
995
|
+
accountConfigured: false,
|
|
996
|
+
canUseEnv: false,
|
|
997
|
+
hasConfigToken: false,
|
|
998
|
+
envPrompt: "",
|
|
999
|
+
keepPrompt: t("wizard.feishu.appSecretKeep"),
|
|
1000
|
+
inputPrompt: t("wizard.feishu.appSecretPrompt"),
|
|
1001
|
+
preferredEnvVar: "FEISHU_APP_SECRET"
|
|
1002
|
+
});
|
|
1003
|
+
if (appSecretResult.action === "set") {
|
|
1004
|
+
appSecret = appSecretResult.value;
|
|
1005
|
+
appSecretProbeValue = appSecretResult.resolvedValue;
|
|
1006
|
+
}
|
|
1007
|
+
if (appId && appSecretProbeValue) {
|
|
1008
|
+
const { getAppOwnerOpenId } = await import("./app-registration-DBSnysKJ.js");
|
|
1009
|
+
scanOpenId = await getAppOwnerOpenId({
|
|
1010
|
+
appId,
|
|
1011
|
+
appSecret: appSecretProbeValue,
|
|
1012
|
+
domain: selectedDomain
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
const groupPolicy = await prompter.select({
|
|
1017
|
+
message: t("wizard.feishu.groupPolicyPrompt"),
|
|
1018
|
+
options: [
|
|
1019
|
+
{
|
|
1020
|
+
value: "allowlist",
|
|
1021
|
+
label: t("wizard.feishu.groupPolicyAllowlist")
|
|
1022
|
+
},
|
|
1023
|
+
{
|
|
1024
|
+
value: "open",
|
|
1025
|
+
label: t("wizard.feishu.groupPolicyOpen")
|
|
1026
|
+
},
|
|
1027
|
+
{
|
|
1028
|
+
value: "disabled",
|
|
1029
|
+
label: t("wizard.feishu.groupPolicyDisabled")
|
|
1030
|
+
}
|
|
1031
|
+
],
|
|
1032
|
+
initialValue: "allowlist"
|
|
1033
|
+
});
|
|
1034
|
+
const configProgress = prompter.progress(t("wizard.feishu.configuring"));
|
|
1035
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
1036
|
+
if (appId && appSecret) next = patchFeishuConfig(next, targetAccountId, {
|
|
1037
|
+
appId,
|
|
1038
|
+
appSecret,
|
|
1039
|
+
connectionMode: "websocket",
|
|
1040
|
+
...scanDomain ? { domain: scanDomain } : {}
|
|
1041
|
+
});
|
|
1042
|
+
else if (scanDomain) next = patchFeishuConfig(next, targetAccountId, { domain: scanDomain });
|
|
1043
|
+
next = applyNewAppSecurityPolicy(next, targetAccountId, scanOpenId, groupPolicy);
|
|
1044
|
+
configProgress.stop(t("wizard.feishu.botConfigured"));
|
|
1045
|
+
return { cfg: next };
|
|
1046
|
+
}
|
|
1047
|
+
async function runEditFlow(params) {
|
|
1048
|
+
const { prompter, options } = params;
|
|
1049
|
+
const next = params.cfg;
|
|
1050
|
+
const feishuCfg = next.channels?.feishu;
|
|
1051
|
+
const resolveAppIdLabel = (value) => {
|
|
1052
|
+
const asString = normalizeString(value);
|
|
1053
|
+
if (asString) return asString;
|
|
1054
|
+
if (value && typeof value === "object") {
|
|
1055
|
+
const rec = value;
|
|
1056
|
+
if (normalizeString(rec.source) && normalizeString(rec.id)) return normalizeString(process.env[rec.id]) ?? `env:${String(rec.id)}`;
|
|
1057
|
+
if (hasConfiguredSecretInput$1(value)) return "(configured)";
|
|
1058
|
+
}
|
|
1059
|
+
};
|
|
1060
|
+
const existingAppId = resolveAppIdLabel(feishuCfg?.appId) ?? Object.values(feishuCfg?.accounts ?? {}).reduce((found, account) => {
|
|
1061
|
+
if (found) return found;
|
|
1062
|
+
if (account && typeof account === "object") return resolveAppIdLabel(account.appId);
|
|
1063
|
+
}, void 0);
|
|
1064
|
+
if (existingAppId) {
|
|
1065
|
+
if (!await prompter.confirm({
|
|
1066
|
+
message: t("wizard.feishu.existingBotPrompt", { appId: existingAppId }),
|
|
1067
|
+
initialValue: true
|
|
1068
|
+
})) return runNewAppFlow({
|
|
1069
|
+
cfg: next,
|
|
1070
|
+
prompter,
|
|
1071
|
+
options
|
|
1072
|
+
});
|
|
1073
|
+
} else return runNewAppFlow({
|
|
1074
|
+
cfg: next,
|
|
1075
|
+
prompter,
|
|
1076
|
+
options
|
|
1077
|
+
});
|
|
1078
|
+
await prompter.note(t("wizard.feishu.botConfigured"), "");
|
|
1079
|
+
return { cfg: next };
|
|
1080
|
+
}
|
|
1081
|
+
async function runFeishuLogin(params) {
|
|
1082
|
+
const { cfg, prompter } = params;
|
|
1083
|
+
const options = {};
|
|
1084
|
+
if (isFeishuConfigured(cfg)) {
|
|
1085
|
+
const result = await runEditFlow({
|
|
1086
|
+
cfg,
|
|
1087
|
+
prompter,
|
|
1088
|
+
options
|
|
1089
|
+
});
|
|
1090
|
+
if (result === null) return cfg;
|
|
1091
|
+
return result.cfg;
|
|
1092
|
+
}
|
|
1093
|
+
return (await runNewAppFlow({
|
|
1094
|
+
cfg,
|
|
1095
|
+
prompter,
|
|
1096
|
+
options
|
|
1097
|
+
})).cfg;
|
|
1098
|
+
}
|
|
1099
|
+
const feishuSetupWizard = {
|
|
1100
|
+
channel,
|
|
1101
|
+
resolveAccountIdForConfigure: ({ accountOverride, defaultAccountId, cfg }) => (typeof accountOverride === "string" && accountOverride.trim() ? accountOverride.trim() : void 0) ?? resolveDefaultFeishuAccountId(cfg) ?? defaultAccountId,
|
|
1102
|
+
resolveShouldPromptAccountIds: () => false,
|
|
1103
|
+
status: {
|
|
1104
|
+
configuredLabel: t("wizard.channels.statusConfigured"),
|
|
1105
|
+
unconfiguredLabel: t("wizard.channels.statusNeedsAppCredentials"),
|
|
1106
|
+
configuredHint: t("wizard.channels.statusConfigured"),
|
|
1107
|
+
unconfiguredHint: t("wizard.channels.statusNeedsAppCreds"),
|
|
1108
|
+
configuredScore: 2,
|
|
1109
|
+
unconfiguredScore: 0,
|
|
1110
|
+
resolveConfigured: ({ cfg }) => isFeishuConfigured(cfg),
|
|
1111
|
+
resolveStatusLines: async ({ cfg, accountId, configured }) => {
|
|
1112
|
+
const account = resolveFeishuAccount({
|
|
1113
|
+
cfg,
|
|
1114
|
+
accountId
|
|
1115
|
+
});
|
|
1116
|
+
let probeResult = null;
|
|
1117
|
+
if (configured && account.configured) try {
|
|
1118
|
+
const { probeFeishu } = await import("./probe-CF4duEpK.js").then((n) => n.n);
|
|
1119
|
+
probeResult = await probeFeishu(account);
|
|
1120
|
+
} catch {}
|
|
1121
|
+
if (!configured) return [formatFeishuStatusLine("needs-credentials")];
|
|
1122
|
+
if (probeResult?.ok) return [`Feishu: ${t("wizard.channels.statusConnectedAs", { name: probeResult.botName ?? probeResult.botOpenId ?? "bot" })}`];
|
|
1123
|
+
return [formatFeishuStatusLine("configured-unverified")];
|
|
1124
|
+
}
|
|
1125
|
+
},
|
|
1126
|
+
prepare: async ({ cfg, credentialValues }) => {
|
|
1127
|
+
if (isFeishuConfigured(cfg)) return { credentialValues: {
|
|
1128
|
+
...credentialValues,
|
|
1129
|
+
[FEISHU_SETUP_FLOW_KEY]: "edit"
|
|
1130
|
+
} };
|
|
1131
|
+
return { credentialValues: {
|
|
1132
|
+
...credentialValues,
|
|
1133
|
+
[FEISHU_SETUP_FLOW_KEY]: "new"
|
|
1134
|
+
} };
|
|
1135
|
+
},
|
|
1136
|
+
credentials: [],
|
|
1137
|
+
finalize: async ({ cfg, prompter, options, credentialValues }) => {
|
|
1138
|
+
if ((credentialValues[FEISHU_SETUP_FLOW_KEY] ?? "new") === "edit") {
|
|
1139
|
+
const result = await runEditFlow({
|
|
1140
|
+
cfg,
|
|
1141
|
+
prompter,
|
|
1142
|
+
options
|
|
1143
|
+
});
|
|
1144
|
+
if (result === null) return { cfg };
|
|
1145
|
+
return result;
|
|
1146
|
+
}
|
|
1147
|
+
return runNewAppFlow({
|
|
1148
|
+
cfg,
|
|
1149
|
+
prompter,
|
|
1150
|
+
options
|
|
1151
|
+
});
|
|
1152
|
+
},
|
|
1153
|
+
dmPolicy: feishuDmPolicy,
|
|
1154
|
+
disable: (cfg) => patchTopLevelChannelConfigSection({
|
|
1155
|
+
cfg,
|
|
1156
|
+
channel,
|
|
1157
|
+
patch: { enabled: false }
|
|
1158
|
+
})
|
|
1159
|
+
};
|
|
1160
|
+
//#endregion
|
|
1161
|
+
//#region extensions/feishu/src/channel.ts
|
|
1162
|
+
function readFeishuMediaParam(params) {
|
|
1163
|
+
const media = params.media;
|
|
1164
|
+
if (typeof media !== "string") return;
|
|
1165
|
+
return media.trim() ? media : void 0;
|
|
1166
|
+
}
|
|
1167
|
+
function readBooleanParam(params, keys) {
|
|
1168
|
+
for (const key of keys) {
|
|
1169
|
+
const value = params[key];
|
|
1170
|
+
if (typeof value === "boolean") return value;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
function hasLegacyFeishuCardCommandValue(actionValue) {
|
|
1174
|
+
return isRecord$1(actionValue) && actionValue.oc !== "ocf1" && (Boolean(typeof actionValue.command === "string" && actionValue.command.trim()) || Boolean(typeof actionValue.text === "string" && actionValue.text.trim()));
|
|
1175
|
+
}
|
|
1176
|
+
function containsLegacyFeishuCardCommandValue(node) {
|
|
1177
|
+
if (Array.isArray(node)) return node.some((item) => containsLegacyFeishuCardCommandValue(item));
|
|
1178
|
+
if (!isRecord$1(node)) return false;
|
|
1179
|
+
if (node.tag === "button" && hasLegacyFeishuCardCommandValue(node.value)) return true;
|
|
1180
|
+
return Object.values(node).some((value) => containsLegacyFeishuCardCommandValue(value));
|
|
1181
|
+
}
|
|
1182
|
+
const meta = {
|
|
1183
|
+
id: "feishu",
|
|
1184
|
+
label: "Feishu",
|
|
1185
|
+
selectionLabel: "Feishu/Lark (飞书)",
|
|
1186
|
+
docsPath: "/channels/feishu",
|
|
1187
|
+
docsLabel: "feishu",
|
|
1188
|
+
blurb: "飞书/Lark enterprise messaging.",
|
|
1189
|
+
aliases: ["lark"],
|
|
1190
|
+
order: 70
|
|
1191
|
+
};
|
|
1192
|
+
const loadFeishuChannelRuntime = createLazyRuntimeNamedExport(() => import("./channel.runtime-JMJonrJ4.js"), "feishuChannelRuntime");
|
|
1193
|
+
function toFeishuMessageSendResult(result, kind) {
|
|
1194
|
+
const receipt = result.receipt ?? createFeishuSendReceipt({
|
|
1195
|
+
messageId: result.messageId,
|
|
1196
|
+
chatId: result.chatId ?? "",
|
|
1197
|
+
kind
|
|
1198
|
+
});
|
|
1199
|
+
return {
|
|
1200
|
+
messageId: result.messageId || receipt.primaryPlatformMessageId,
|
|
1201
|
+
receipt
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
const feishuMessageAdapter = defineChannelMessageAdapter({
|
|
1205
|
+
id: "feishu",
|
|
1206
|
+
durableFinal: { capabilities: {
|
|
1207
|
+
text: true,
|
|
1208
|
+
media: true
|
|
1209
|
+
} },
|
|
1210
|
+
send: {
|
|
1211
|
+
text: async (ctx) => {
|
|
1212
|
+
const sendText = (await loadFeishuChannelRuntime()).feishuOutbound.sendText;
|
|
1213
|
+
if (!sendText) throw new Error("Feishu text sending is not available.");
|
|
1214
|
+
return toFeishuMessageSendResult(await sendText(ctx), "text");
|
|
1215
|
+
},
|
|
1216
|
+
media: async (ctx) => {
|
|
1217
|
+
const sendMedia = (await loadFeishuChannelRuntime()).feishuOutbound.sendMedia;
|
|
1218
|
+
if (!sendMedia) throw new Error("Feishu media sending is not available.");
|
|
1219
|
+
return toFeishuMessageSendResult(await sendMedia(ctx), "media");
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
});
|
|
1223
|
+
function buildFeishuPresentationCard(params) {
|
|
1224
|
+
const fallbackPresentation = {
|
|
1225
|
+
...params.presentation.tone ? { tone: params.presentation.tone } : {},
|
|
1226
|
+
blocks: params.presentation.blocks
|
|
1227
|
+
};
|
|
1228
|
+
return {
|
|
1229
|
+
schema: "2.0",
|
|
1230
|
+
config: { width_mode: "fill" },
|
|
1231
|
+
...params.presentation.title ? { header: {
|
|
1232
|
+
title: {
|
|
1233
|
+
tag: "plain_text",
|
|
1234
|
+
content: params.presentation.title
|
|
1235
|
+
},
|
|
1236
|
+
template: "blue"
|
|
1237
|
+
} } : {},
|
|
1238
|
+
body: { elements: [{
|
|
1239
|
+
tag: "markdown",
|
|
1240
|
+
content: renderMessagePresentationFallbackText({
|
|
1241
|
+
text: params.fallbackText,
|
|
1242
|
+
presentation: fallbackPresentation
|
|
1243
|
+
})
|
|
1244
|
+
}] }
|
|
1245
|
+
};
|
|
1246
|
+
}
|
|
1247
|
+
async function createFeishuActionClient(account) {
|
|
1248
|
+
const { createFeishuClient } = await import("./client-D1pzbBGo.js").then((n) => n.t);
|
|
1249
|
+
return createFeishuClient(account);
|
|
1250
|
+
}
|
|
1251
|
+
const collectFeishuSecurityWarnings = createAllowlistProviderGroupPolicyWarningCollector({
|
|
1252
|
+
providerConfigPresent: (cfg) => cfg.channels?.feishu !== void 0,
|
|
1253
|
+
resolveGroupPolicy: ({ cfg, accountId }) => resolveFeishuAccount({
|
|
1254
|
+
cfg,
|
|
1255
|
+
accountId
|
|
1256
|
+
}).config?.groupPolicy,
|
|
1257
|
+
collect: ({ cfg, accountId, groupPolicy }) => {
|
|
1258
|
+
if (groupPolicy !== "open") return [];
|
|
1259
|
+
return [`- Feishu[${resolveFeishuAccount({
|
|
1260
|
+
cfg,
|
|
1261
|
+
accountId
|
|
1262
|
+
}).accountId}] groups: groupPolicy="open" allows any member to trigger (mention-gated). Set channels.feishu.groupPolicy="allowlist" + channels.feishu.groupAllowFrom to restrict senders.`];
|
|
1263
|
+
}
|
|
1264
|
+
});
|
|
1265
|
+
function describeFeishuMessageTool({ cfg, accountId }) {
|
|
1266
|
+
const enabledAccounts = accountId ? [resolveFeishuAccount({
|
|
1267
|
+
cfg,
|
|
1268
|
+
accountId
|
|
1269
|
+
})].filter((account) => account.enabled && account.configured) : listEnabledFeishuAccounts(cfg);
|
|
1270
|
+
const enabled = enabledAccounts.length > 0 || !accountId && cfg.channels?.feishu?.enabled !== false && Boolean(inspectFeishuCredentials(cfg.channels?.feishu));
|
|
1271
|
+
if (enabledAccounts.length === 0) return {
|
|
1272
|
+
actions: [],
|
|
1273
|
+
capabilities: enabled ? ["presentation"] : []
|
|
1274
|
+
};
|
|
1275
|
+
const actions = new Set([
|
|
1276
|
+
"send",
|
|
1277
|
+
"read",
|
|
1278
|
+
"edit",
|
|
1279
|
+
"thread-reply",
|
|
1280
|
+
"pin",
|
|
1281
|
+
"list-pins",
|
|
1282
|
+
"unpin",
|
|
1283
|
+
"member-info",
|
|
1284
|
+
"channel-info",
|
|
1285
|
+
"channel-list"
|
|
1286
|
+
]);
|
|
1287
|
+
if (accountId ? enabledAccounts.some((account) => isFeishuReactionsActionEnabled({
|
|
1288
|
+
cfg,
|
|
1289
|
+
account
|
|
1290
|
+
})) : areAnyFeishuReactionActionsEnabled(cfg)) {
|
|
1291
|
+
actions.add("react");
|
|
1292
|
+
actions.add("reactions");
|
|
1293
|
+
}
|
|
1294
|
+
return {
|
|
1295
|
+
actions: Array.from(actions),
|
|
1296
|
+
capabilities: enabled ? ["presentation"] : []
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
function setFeishuNamedAccountEnabled(cfg, accountId, enabled) {
|
|
1300
|
+
const feishuCfg = cfg.channels?.feishu;
|
|
1301
|
+
return {
|
|
1302
|
+
...cfg,
|
|
1303
|
+
channels: {
|
|
1304
|
+
...cfg.channels,
|
|
1305
|
+
feishu: {
|
|
1306
|
+
...feishuCfg,
|
|
1307
|
+
accounts: {
|
|
1308
|
+
...feishuCfg?.accounts,
|
|
1309
|
+
[accountId]: {
|
|
1310
|
+
...feishuCfg?.accounts?.[accountId],
|
|
1311
|
+
enabled
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
const feishuConfigAdapter = createHybridChannelConfigAdapter({
|
|
1319
|
+
sectionKey: "feishu",
|
|
1320
|
+
listAccountIds: listFeishuAccountIds,
|
|
1321
|
+
resolveAccount: adaptScopedAccountAccessor(resolveFeishuAccount),
|
|
1322
|
+
defaultAccountId: resolveDefaultFeishuAccountId,
|
|
1323
|
+
clearBaseFields: [],
|
|
1324
|
+
resolveAllowFrom: (account) => account.config.allowFrom,
|
|
1325
|
+
formatAllowFrom: (allowFrom) => formatAllowFromLowercase({ allowFrom })
|
|
1326
|
+
});
|
|
1327
|
+
function isFeishuReactionsActionEnabled(params) {
|
|
1328
|
+
if (!params.account.enabled || !params.account.configured) return false;
|
|
1329
|
+
return createActionGate(params.account.config.actions ?? (params.cfg.channels?.feishu)?.actions)("reactions");
|
|
1330
|
+
}
|
|
1331
|
+
function areAnyFeishuReactionActionsEnabled(cfg) {
|
|
1332
|
+
for (const account of listEnabledFeishuAccounts(cfg)) if (isFeishuReactionsActionEnabled({
|
|
1333
|
+
cfg,
|
|
1334
|
+
account
|
|
1335
|
+
})) return true;
|
|
1336
|
+
return false;
|
|
1337
|
+
}
|
|
1338
|
+
function isFeishuGroupTopicSessionKey(sessionKey) {
|
|
1339
|
+
if (typeof sessionKey !== "string" || !sessionKey) return false;
|
|
1340
|
+
const parsed = parseFeishuConversationId({ conversationId: sessionKey });
|
|
1341
|
+
return parsed?.scope === "group_topic" || parsed?.scope === "group_topic_sender";
|
|
1342
|
+
}
|
|
1343
|
+
function resolveFeishuTopicAutoThreadAnchor(ctx) {
|
|
1344
|
+
if (ctx.action !== "send") return;
|
|
1345
|
+
if (!isFeishuGroupTopicSessionKey(ctx.sessionKey)) return;
|
|
1346
|
+
const inbound = ctx.toolContext?.currentMessageId;
|
|
1347
|
+
return typeof inbound === "string" && inbound.length > 0 ? inbound : void 0;
|
|
1348
|
+
}
|
|
1349
|
+
function buildFeishuSendReplyAnchor(ctx) {
|
|
1350
|
+
if (ctx.action === "thread-reply") return {
|
|
1351
|
+
replyToMessageId: resolveFeishuMessageId(ctx.params),
|
|
1352
|
+
replyInThread: true
|
|
1353
|
+
};
|
|
1354
|
+
const autoThreadId = resolveFeishuTopicAutoThreadAnchor(ctx);
|
|
1355
|
+
return {
|
|
1356
|
+
replyToMessageId: autoThreadId,
|
|
1357
|
+
replyInThread: autoThreadId !== void 0
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
function isSupportedFeishuDirectConversationId(conversationId) {
|
|
1361
|
+
const trimmed = conversationId.trim();
|
|
1362
|
+
if (!trimmed || trimmed.includes(":")) return false;
|
|
1363
|
+
if (trimmed.startsWith("oc_") || trimmed.startsWith("on_")) return false;
|
|
1364
|
+
return true;
|
|
1365
|
+
}
|
|
1366
|
+
function normalizeFeishuAcpConversationId(conversationId) {
|
|
1367
|
+
const parsed = parseFeishuConversationId({ conversationId });
|
|
1368
|
+
if (!parsed || parsed.scope !== "group_topic" && parsed.scope !== "group_topic_sender" && !isSupportedFeishuDirectConversationId(parsed.canonicalConversationId)) return null;
|
|
1369
|
+
return {
|
|
1370
|
+
conversationId: parsed.canonicalConversationId,
|
|
1371
|
+
parentConversationId: parsed.scope === "group_topic" || parsed.scope === "group_topic_sender" ? parsed.chatId : void 0
|
|
1372
|
+
};
|
|
1373
|
+
}
|
|
1374
|
+
function matchFeishuAcpConversation(params) {
|
|
1375
|
+
const binding = normalizeFeishuAcpConversationId(params.bindingConversationId);
|
|
1376
|
+
if (!binding) return null;
|
|
1377
|
+
const incoming = parseFeishuConversationId({
|
|
1378
|
+
conversationId: params.conversationId,
|
|
1379
|
+
parentConversationId: params.parentConversationId
|
|
1380
|
+
});
|
|
1381
|
+
if (!incoming || incoming.scope !== "group_topic" && incoming.scope !== "group_topic_sender" && !isSupportedFeishuDirectConversationId(incoming.canonicalConversationId)) return null;
|
|
1382
|
+
const matchesCanonicalConversation = binding.conversationId === incoming.canonicalConversationId;
|
|
1383
|
+
const matchesParentTopicForSenderScopedConversation = incoming.scope === "group_topic_sender" && binding.parentConversationId === incoming.chatId && binding.conversationId === `${incoming.chatId}:topic:${incoming.topicId}`;
|
|
1384
|
+
if (!matchesCanonicalConversation && !matchesParentTopicForSenderScopedConversation) return null;
|
|
1385
|
+
return {
|
|
1386
|
+
conversationId: matchesParentTopicForSenderScopedConversation ? binding.conversationId : incoming.canonicalConversationId,
|
|
1387
|
+
parentConversationId: incoming.scope === "group_topic" || incoming.scope === "group_topic_sender" ? incoming.chatId : void 0,
|
|
1388
|
+
matchPriority: matchesCanonicalConversation ? 2 : 1
|
|
1389
|
+
};
|
|
1390
|
+
}
|
|
1391
|
+
function resolveFeishuSenderScopedCommandConversation(params) {
|
|
1392
|
+
const parentConversationId = params.parentConversationId?.trim();
|
|
1393
|
+
const threadId = params.threadId?.trim();
|
|
1394
|
+
const senderId = params.senderId?.trim();
|
|
1395
|
+
if (!parentConversationId || !threadId || !senderId) return;
|
|
1396
|
+
const expectedScopePrefix = `feishu:group:${normalizeLowercaseStringOrEmpty(parentConversationId)}:topic:${normalizeLowercaseStringOrEmpty(threadId)}:sender:`;
|
|
1397
|
+
const isSenderScopedSession = [params.sessionKey, params.parentSessionKey].some((candidate) => {
|
|
1398
|
+
const normalized = normalizeLowercaseStringOrEmpty(candidate ?? "");
|
|
1399
|
+
if (!normalized) return false;
|
|
1400
|
+
return normalized.replace(/^agent:[^:]+:/, "").startsWith(expectedScopePrefix);
|
|
1401
|
+
});
|
|
1402
|
+
const senderScopedConversationId = buildFeishuConversationId({
|
|
1403
|
+
chatId: parentConversationId,
|
|
1404
|
+
scope: "group_topic_sender",
|
|
1405
|
+
topicId: threadId,
|
|
1406
|
+
senderOpenId: senderId
|
|
1407
|
+
});
|
|
1408
|
+
if (isSenderScopedSession) return senderScopedConversationId;
|
|
1409
|
+
if (!params.sessionKey?.trim()) return;
|
|
1410
|
+
return getSessionBindingService().listBySession(params.sessionKey).find((binding) => {
|
|
1411
|
+
if (binding.conversation.channel !== "feishu" || binding.conversation.accountId !== params.accountId) return false;
|
|
1412
|
+
return binding.conversation.conversationId === senderScopedConversationId;
|
|
1413
|
+
})?.conversation.conversationId;
|
|
1414
|
+
}
|
|
1415
|
+
function resolveFeishuCommandConversation(params) {
|
|
1416
|
+
if (params.threadId) {
|
|
1417
|
+
const parentConversationId = parseFeishuTargetId(params.originatingTo) ?? parseFeishuTargetId(params.commandTo) ?? parseFeishuTargetId(params.fallbackTo);
|
|
1418
|
+
if (!parentConversationId) return null;
|
|
1419
|
+
return {
|
|
1420
|
+
conversationId: resolveFeishuSenderScopedCommandConversation({
|
|
1421
|
+
accountId: params.accountId,
|
|
1422
|
+
parentConversationId,
|
|
1423
|
+
threadId: params.threadId,
|
|
1424
|
+
senderId: params.senderId,
|
|
1425
|
+
sessionKey: params.sessionKey,
|
|
1426
|
+
parentSessionKey: params.parentSessionKey
|
|
1427
|
+
}) ?? buildFeishuConversationId({
|
|
1428
|
+
chatId: parentConversationId,
|
|
1429
|
+
scope: "group_topic",
|
|
1430
|
+
topicId: params.threadId
|
|
1431
|
+
}),
|
|
1432
|
+
parentConversationId
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
const conversationId = parseFeishuDirectConversationId(params.originatingTo) ?? parseFeishuDirectConversationId(params.commandTo) ?? parseFeishuDirectConversationId(params.fallbackTo);
|
|
1436
|
+
return conversationId ? { conversationId } : null;
|
|
1437
|
+
}
|
|
1438
|
+
function jsonActionResult(details) {
|
|
1439
|
+
return {
|
|
1440
|
+
content: [{
|
|
1441
|
+
type: "text",
|
|
1442
|
+
text: JSON.stringify(details)
|
|
1443
|
+
}],
|
|
1444
|
+
details
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
function readFirstString(params, keys, fallback) {
|
|
1448
|
+
for (const key of keys) {
|
|
1449
|
+
const value = params[key];
|
|
1450
|
+
if (typeof value === "string" && value.trim()) return value.trim();
|
|
1451
|
+
}
|
|
1452
|
+
if (typeof fallback === "string" && fallback.trim()) return fallback.trim();
|
|
1453
|
+
}
|
|
1454
|
+
function readOptionalNumber(params, keys) {
|
|
1455
|
+
for (const key of keys) {
|
|
1456
|
+
const value = params[key];
|
|
1457
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
1458
|
+
if (typeof value === "string" && value.trim()) {
|
|
1459
|
+
const parsed = Number(value);
|
|
1460
|
+
if (Number.isFinite(parsed)) return parsed;
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
function resolveFeishuActionTarget(ctx) {
|
|
1465
|
+
return readFirstString(ctx.params, ["to", "target"], ctx.toolContext?.currentChannelId);
|
|
1466
|
+
}
|
|
1467
|
+
function resolveFeishuChatId(ctx) {
|
|
1468
|
+
const raw = readFirstString(ctx.params, [
|
|
1469
|
+
"chatId",
|
|
1470
|
+
"chat_id",
|
|
1471
|
+
"channelId",
|
|
1472
|
+
"channel_id",
|
|
1473
|
+
"to",
|
|
1474
|
+
"target"
|
|
1475
|
+
], ctx.toolContext?.currentChannelId);
|
|
1476
|
+
if (!raw) return;
|
|
1477
|
+
if (/^(user|dm|open_id):/i.test(raw)) return;
|
|
1478
|
+
if (/^(chat|group|channel):/i.test(raw)) return normalizeFeishuTarget(raw) ?? void 0;
|
|
1479
|
+
return raw;
|
|
1480
|
+
}
|
|
1481
|
+
function resolveFeishuMessageId(params) {
|
|
1482
|
+
return readFirstString(params, [
|
|
1483
|
+
"messageId",
|
|
1484
|
+
"message_id",
|
|
1485
|
+
"replyTo",
|
|
1486
|
+
"reply_to"
|
|
1487
|
+
]);
|
|
1488
|
+
}
|
|
1489
|
+
function resolveFeishuMemberId(params) {
|
|
1490
|
+
return readFirstString(params, [
|
|
1491
|
+
"memberId",
|
|
1492
|
+
"member_id",
|
|
1493
|
+
"userId",
|
|
1494
|
+
"user_id",
|
|
1495
|
+
"openId",
|
|
1496
|
+
"open_id",
|
|
1497
|
+
"unionId",
|
|
1498
|
+
"union_id"
|
|
1499
|
+
]);
|
|
1500
|
+
}
|
|
1501
|
+
function resolveFeishuMemberIdType(params) {
|
|
1502
|
+
const raw = readFirstString(params, [
|
|
1503
|
+
"memberIdType",
|
|
1504
|
+
"member_id_type",
|
|
1505
|
+
"userIdType",
|
|
1506
|
+
"user_id_type"
|
|
1507
|
+
]);
|
|
1508
|
+
if (raw === "open_id" || raw === "user_id" || raw === "union_id") return raw;
|
|
1509
|
+
if (readFirstString(params, ["userId", "user_id"]) && !readFirstString(params, [
|
|
1510
|
+
"openId",
|
|
1511
|
+
"open_id",
|
|
1512
|
+
"unionId",
|
|
1513
|
+
"union_id"
|
|
1514
|
+
])) return "user_id";
|
|
1515
|
+
if (readFirstString(params, ["unionId", "union_id"]) && !readFirstString(params, ["openId", "open_id"])) return "union_id";
|
|
1516
|
+
return "open_id";
|
|
1517
|
+
}
|
|
1518
|
+
const feishuPlugin = createChatChannelPlugin({
|
|
1519
|
+
base: {
|
|
1520
|
+
id: "feishu",
|
|
1521
|
+
meta: { ...meta },
|
|
1522
|
+
capabilities: {
|
|
1523
|
+
chatTypes: ["direct", "channel"],
|
|
1524
|
+
polls: false,
|
|
1525
|
+
threads: true,
|
|
1526
|
+
media: true,
|
|
1527
|
+
tts: { voice: {
|
|
1528
|
+
synthesisTarget: "voice-note",
|
|
1529
|
+
transcodesAudio: true
|
|
1530
|
+
} },
|
|
1531
|
+
reactions: true,
|
|
1532
|
+
edit: true,
|
|
1533
|
+
reply: true
|
|
1534
|
+
},
|
|
1535
|
+
agentPrompt: { messageToolHints: () => [
|
|
1536
|
+
"- Feishu targeting: omit `target` to reply to the current conversation (auto-inferred). Explicit targets: `user:open_id` or `chat:chat_id`.",
|
|
1537
|
+
"- Feishu supports interactive cards plus native image, file, audio, and video/media delivery.",
|
|
1538
|
+
"- Feishu supports `send`, `read`, `edit`, `thread-reply`, pins, and channel/member lookup, plus reactions when enabled."
|
|
1539
|
+
] },
|
|
1540
|
+
groups: { resolveToolPolicy: resolveFeishuGroupToolPolicy },
|
|
1541
|
+
conversationBindings: {
|
|
1542
|
+
defaultTopLevelPlacement: "current",
|
|
1543
|
+
buildModelOverrideParentCandidates: ({ parentConversationId }) => buildFeishuModelOverrideParentCandidates(parentConversationId)
|
|
1544
|
+
},
|
|
1545
|
+
mentions: { stripPatterns: () => ["<at user_id=\"[^\"]*\">[^<]*</at>"] },
|
|
1546
|
+
reload: { configPrefixes: ["channels.feishu"] },
|
|
1547
|
+
configSchema: buildChannelConfigSchema(FeishuConfigSchema),
|
|
1548
|
+
config: {
|
|
1549
|
+
...feishuConfigAdapter,
|
|
1550
|
+
setAccountEnabled: ({ cfg, accountId, enabled }) => {
|
|
1551
|
+
if (accountId === DEFAULT_ACCOUNT_ID$2) return {
|
|
1552
|
+
...cfg,
|
|
1553
|
+
channels: {
|
|
1554
|
+
...cfg.channels,
|
|
1555
|
+
feishu: {
|
|
1556
|
+
...cfg.channels?.feishu,
|
|
1557
|
+
enabled
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
};
|
|
1561
|
+
return setFeishuNamedAccountEnabled(cfg, accountId, enabled);
|
|
1562
|
+
},
|
|
1563
|
+
deleteAccount: ({ cfg, accountId }) => {
|
|
1564
|
+
if (accountId === DEFAULT_ACCOUNT_ID$2) {
|
|
1565
|
+
const next = { ...cfg };
|
|
1566
|
+
const nextChannels = { ...cfg.channels };
|
|
1567
|
+
delete nextChannels.feishu;
|
|
1568
|
+
if (Object.keys(nextChannels).length > 0) next.channels = nextChannels;
|
|
1569
|
+
else delete next.channels;
|
|
1570
|
+
return next;
|
|
1571
|
+
}
|
|
1572
|
+
const feishuCfg = cfg.channels?.feishu;
|
|
1573
|
+
const accounts = { ...feishuCfg?.accounts };
|
|
1574
|
+
delete accounts[accountId];
|
|
1575
|
+
return {
|
|
1576
|
+
...cfg,
|
|
1577
|
+
channels: {
|
|
1578
|
+
...cfg.channels,
|
|
1579
|
+
feishu: {
|
|
1580
|
+
...feishuCfg,
|
|
1581
|
+
accounts: Object.keys(accounts).length > 0 ? accounts : void 0
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1585
|
+
},
|
|
1586
|
+
isConfigured: (account) => account.configured,
|
|
1587
|
+
describeAccount: (account) => describeAccountSnapshot({
|
|
1588
|
+
account,
|
|
1589
|
+
configured: account.configured,
|
|
1590
|
+
extra: {
|
|
1591
|
+
appId: account.appId,
|
|
1592
|
+
domain: account.domain
|
|
1593
|
+
}
|
|
1594
|
+
})
|
|
1595
|
+
},
|
|
1596
|
+
approvalCapability: feishuApprovalAuth,
|
|
1597
|
+
secrets: {
|
|
1598
|
+
secretTargetRegistryEntries,
|
|
1599
|
+
collectRuntimeConfigAssignments
|
|
1600
|
+
},
|
|
1601
|
+
actions: {
|
|
1602
|
+
messageActionTargetAliases,
|
|
1603
|
+
describeMessageTool: describeFeishuMessageTool,
|
|
1604
|
+
handleAction: async (ctx) => {
|
|
1605
|
+
const account = resolveFeishuAccount({
|
|
1606
|
+
cfg: ctx.cfg,
|
|
1607
|
+
accountId: ctx.accountId ?? void 0
|
|
1608
|
+
});
|
|
1609
|
+
if ((ctx.action === "react" || ctx.action === "reactions") && !isFeishuReactionsActionEnabled({
|
|
1610
|
+
cfg: ctx.cfg,
|
|
1611
|
+
account
|
|
1612
|
+
})) throw new Error("Feishu reactions are disabled via actions.reactions.");
|
|
1613
|
+
if (ctx.action === "send" || ctx.action === "thread-reply") {
|
|
1614
|
+
const to = resolveFeishuActionTarget(ctx);
|
|
1615
|
+
if (!to) throw new Error(`Feishu ${ctx.action} requires a target (to).`);
|
|
1616
|
+
const { replyToMessageId, replyInThread } = buildFeishuSendReplyAnchor(ctx);
|
|
1617
|
+
if (ctx.action === "thread-reply" && !replyToMessageId) throw new Error("Feishu thread-reply requires messageId.");
|
|
1618
|
+
const presentation = normalizeMessagePresentation(ctx.params.presentation);
|
|
1619
|
+
const text = readFirstString(ctx.params, ["text", "message"]);
|
|
1620
|
+
const mediaUrl = readFeishuMediaParam(ctx.params);
|
|
1621
|
+
const audioAsVoice = readBooleanParam(ctx.params, ["asVoice", "audioAsVoice"]);
|
|
1622
|
+
const card = presentation ? buildFeishuPresentationCard({
|
|
1623
|
+
presentation,
|
|
1624
|
+
fallbackText: text
|
|
1625
|
+
}) : void 0;
|
|
1626
|
+
if (card && mediaUrl) throw new Error(`Feishu ${ctx.action} does not support card with media.`);
|
|
1627
|
+
if (!card && !text && !mediaUrl) throw new Error(`Feishu ${ctx.action} requires text/message, media, or card.`);
|
|
1628
|
+
const runtime = await loadFeishuChannelRuntime();
|
|
1629
|
+
const maybeSendMedia = runtime.feishuOutbound.sendMedia;
|
|
1630
|
+
if (mediaUrl && !maybeSendMedia) throw new Error("Feishu media sending is not available.");
|
|
1631
|
+
const sendMedia = maybeSendMedia;
|
|
1632
|
+
let result;
|
|
1633
|
+
if (card) {
|
|
1634
|
+
if (containsLegacyFeishuCardCommandValue(card)) throw new Error("Feishu card buttons that trigger text or commands must use structured interaction envelopes.");
|
|
1635
|
+
result = await runtime.sendCardFeishu({
|
|
1636
|
+
cfg: ctx.cfg,
|
|
1637
|
+
to,
|
|
1638
|
+
card,
|
|
1639
|
+
accountId: ctx.accountId ?? void 0,
|
|
1640
|
+
replyToMessageId,
|
|
1641
|
+
replyInThread
|
|
1642
|
+
});
|
|
1643
|
+
} else if (mediaUrl) result = await sendMedia({
|
|
1644
|
+
cfg: ctx.cfg,
|
|
1645
|
+
to,
|
|
1646
|
+
text: text ?? "",
|
|
1647
|
+
mediaUrl,
|
|
1648
|
+
accountId: ctx.accountId ?? void 0,
|
|
1649
|
+
mediaLocalRoots: ctx.mediaLocalRoots,
|
|
1650
|
+
...replyInThread ? { threadId: replyToMessageId } : { replyToId: replyToMessageId },
|
|
1651
|
+
...audioAsVoice === true ? { audioAsVoice: true } : {}
|
|
1652
|
+
});
|
|
1653
|
+
else result = await runtime.sendMessageFeishu({
|
|
1654
|
+
cfg: ctx.cfg,
|
|
1655
|
+
to,
|
|
1656
|
+
text,
|
|
1657
|
+
accountId: ctx.accountId ?? void 0,
|
|
1658
|
+
replyToMessageId,
|
|
1659
|
+
replyInThread
|
|
1660
|
+
});
|
|
1661
|
+
return jsonActionResult({
|
|
1662
|
+
ok: true,
|
|
1663
|
+
channel: "feishu",
|
|
1664
|
+
action: ctx.action,
|
|
1665
|
+
...result
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
if (ctx.action === "read") {
|
|
1669
|
+
const messageId = resolveFeishuMessageId(ctx.params);
|
|
1670
|
+
if (!messageId) throw new Error("Feishu read requires messageId.");
|
|
1671
|
+
const { getMessageFeishu } = await loadFeishuChannelRuntime();
|
|
1672
|
+
const message = await getMessageFeishu({
|
|
1673
|
+
cfg: ctx.cfg,
|
|
1674
|
+
messageId,
|
|
1675
|
+
accountId: ctx.accountId ?? void 0
|
|
1676
|
+
});
|
|
1677
|
+
if (!message) return {
|
|
1678
|
+
isError: true,
|
|
1679
|
+
content: [{
|
|
1680
|
+
type: "text",
|
|
1681
|
+
text: JSON.stringify({ error: `Feishu read failed or message not found: ${messageId}` })
|
|
1682
|
+
}],
|
|
1683
|
+
details: { error: `Feishu read failed or message not found: ${messageId}` }
|
|
1684
|
+
};
|
|
1685
|
+
return jsonActionResult({
|
|
1686
|
+
ok: true,
|
|
1687
|
+
channel: "feishu",
|
|
1688
|
+
action: "read",
|
|
1689
|
+
message
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1692
|
+
if (ctx.action === "edit") {
|
|
1693
|
+
const messageId = resolveFeishuMessageId(ctx.params);
|
|
1694
|
+
if (!messageId) throw new Error("Feishu edit requires messageId.");
|
|
1695
|
+
const text = readFirstString(ctx.params, ["text", "message"]);
|
|
1696
|
+
const card = ctx.params.card && typeof ctx.params.card === "object" ? ctx.params.card : void 0;
|
|
1697
|
+
const { editMessageFeishu } = await loadFeishuChannelRuntime();
|
|
1698
|
+
return jsonActionResult({
|
|
1699
|
+
ok: true,
|
|
1700
|
+
channel: "feishu",
|
|
1701
|
+
action: "edit",
|
|
1702
|
+
...await editMessageFeishu({
|
|
1703
|
+
cfg: ctx.cfg,
|
|
1704
|
+
messageId,
|
|
1705
|
+
text,
|
|
1706
|
+
card,
|
|
1707
|
+
accountId: ctx.accountId ?? void 0
|
|
1708
|
+
})
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
if (ctx.action === "pin") {
|
|
1712
|
+
const messageId = resolveFeishuMessageId(ctx.params);
|
|
1713
|
+
if (!messageId) throw new Error("Feishu pin requires messageId.");
|
|
1714
|
+
const { createPinFeishu } = await loadFeishuChannelRuntime();
|
|
1715
|
+
return jsonActionResult({
|
|
1716
|
+
ok: true,
|
|
1717
|
+
channel: "feishu",
|
|
1718
|
+
action: "pin",
|
|
1719
|
+
pin: await createPinFeishu({
|
|
1720
|
+
cfg: ctx.cfg,
|
|
1721
|
+
messageId,
|
|
1722
|
+
accountId: ctx.accountId ?? void 0
|
|
1723
|
+
})
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1726
|
+
if (ctx.action === "unpin") {
|
|
1727
|
+
const messageId = resolveFeishuMessageId(ctx.params);
|
|
1728
|
+
if (!messageId) throw new Error("Feishu unpin requires messageId.");
|
|
1729
|
+
const { removePinFeishu } = await loadFeishuChannelRuntime();
|
|
1730
|
+
await removePinFeishu({
|
|
1731
|
+
cfg: ctx.cfg,
|
|
1732
|
+
messageId,
|
|
1733
|
+
accountId: ctx.accountId ?? void 0
|
|
1734
|
+
});
|
|
1735
|
+
return jsonActionResult({
|
|
1736
|
+
ok: true,
|
|
1737
|
+
channel: "feishu",
|
|
1738
|
+
action: "unpin",
|
|
1739
|
+
messageId
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1742
|
+
if (ctx.action === "list-pins") {
|
|
1743
|
+
const chatId = resolveFeishuChatId(ctx);
|
|
1744
|
+
if (!chatId) throw new Error("Feishu list-pins requires chatId or channelId.");
|
|
1745
|
+
const { listPinsFeishu } = await loadFeishuChannelRuntime();
|
|
1746
|
+
return jsonActionResult({
|
|
1747
|
+
ok: true,
|
|
1748
|
+
channel: "feishu",
|
|
1749
|
+
action: "list-pins",
|
|
1750
|
+
...await listPinsFeishu({
|
|
1751
|
+
cfg: ctx.cfg,
|
|
1752
|
+
chatId,
|
|
1753
|
+
startTime: readFirstString(ctx.params, ["startTime", "start_time"]),
|
|
1754
|
+
endTime: readFirstString(ctx.params, ["endTime", "end_time"]),
|
|
1755
|
+
pageSize: readOptionalNumber(ctx.params, ["pageSize", "page_size"]),
|
|
1756
|
+
pageToken: readFirstString(ctx.params, ["pageToken", "page_token"]),
|
|
1757
|
+
accountId: ctx.accountId ?? void 0
|
|
1758
|
+
})
|
|
1759
|
+
});
|
|
1760
|
+
}
|
|
1761
|
+
if (ctx.action === "channel-info") {
|
|
1762
|
+
const chatId = resolveFeishuChatId(ctx);
|
|
1763
|
+
if (!chatId) throw new Error("Feishu channel-info requires chatId or channelId.");
|
|
1764
|
+
const runtime = await loadFeishuChannelRuntime();
|
|
1765
|
+
const client = await createFeishuActionClient(account);
|
|
1766
|
+
const channel = await runtime.getChatInfo(client, chatId);
|
|
1767
|
+
if (!(ctx.params.includeMembers === true || ctx.params.members === true)) return jsonActionResult({
|
|
1768
|
+
ok: true,
|
|
1769
|
+
provider: "feishu",
|
|
1770
|
+
action: "channel-info",
|
|
1771
|
+
channel
|
|
1772
|
+
});
|
|
1773
|
+
return jsonActionResult({
|
|
1774
|
+
ok: true,
|
|
1775
|
+
provider: "feishu",
|
|
1776
|
+
action: "channel-info",
|
|
1777
|
+
channel,
|
|
1778
|
+
members: await runtime.getChatMembers(client, chatId, readOptionalNumber(ctx.params, ["pageSize", "page_size"]), readFirstString(ctx.params, ["pageToken", "page_token"]), resolveFeishuMemberIdType(ctx.params))
|
|
1779
|
+
});
|
|
1780
|
+
}
|
|
1781
|
+
if (ctx.action === "member-info") {
|
|
1782
|
+
const runtime = await loadFeishuChannelRuntime();
|
|
1783
|
+
const client = await createFeishuActionClient(account);
|
|
1784
|
+
const memberId = resolveFeishuMemberId(ctx.params);
|
|
1785
|
+
if (memberId) return jsonActionResult({
|
|
1786
|
+
ok: true,
|
|
1787
|
+
channel: "feishu",
|
|
1788
|
+
action: "member-info",
|
|
1789
|
+
member: await runtime.getFeishuMemberInfo(client, memberId, resolveFeishuMemberIdType(ctx.params))
|
|
1790
|
+
});
|
|
1791
|
+
const chatId = resolveFeishuChatId(ctx);
|
|
1792
|
+
if (!chatId) throw new Error("Feishu member-info requires memberId or chatId/channelId.");
|
|
1793
|
+
return jsonActionResult({
|
|
1794
|
+
ok: true,
|
|
1795
|
+
channel: "feishu",
|
|
1796
|
+
action: "member-info",
|
|
1797
|
+
...await runtime.getChatMembers(client, chatId, readOptionalNumber(ctx.params, ["pageSize", "page_size"]), readFirstString(ctx.params, ["pageToken", "page_token"]), resolveFeishuMemberIdType(ctx.params))
|
|
1798
|
+
});
|
|
1799
|
+
}
|
|
1800
|
+
if (ctx.action === "channel-list") {
|
|
1801
|
+
const runtime = await loadFeishuChannelRuntime();
|
|
1802
|
+
const query = readFirstString(ctx.params, ["query"]);
|
|
1803
|
+
const limit = readOptionalNumber(ctx.params, ["limit"]);
|
|
1804
|
+
const scope = readFirstString(ctx.params, ["scope", "kind"]) ?? "all";
|
|
1805
|
+
if (scope === "groups" || scope === "group" || scope === "channels" || scope === "channel") return jsonActionResult({
|
|
1806
|
+
ok: true,
|
|
1807
|
+
channel: "feishu",
|
|
1808
|
+
action: "channel-list",
|
|
1809
|
+
groups: await runtime.listFeishuDirectoryGroupsLive({
|
|
1810
|
+
cfg: ctx.cfg,
|
|
1811
|
+
query,
|
|
1812
|
+
limit,
|
|
1813
|
+
fallbackToStatic: false,
|
|
1814
|
+
accountId: ctx.accountId ?? void 0
|
|
1815
|
+
})
|
|
1816
|
+
});
|
|
1817
|
+
if (scope === "peers" || scope === "peer" || scope === "members" || scope === "member" || scope === "users" || scope === "user") return jsonActionResult({
|
|
1818
|
+
ok: true,
|
|
1819
|
+
channel: "feishu",
|
|
1820
|
+
action: "channel-list",
|
|
1821
|
+
peers: await runtime.listFeishuDirectoryPeersLive({
|
|
1822
|
+
cfg: ctx.cfg,
|
|
1823
|
+
query,
|
|
1824
|
+
limit,
|
|
1825
|
+
fallbackToStatic: false,
|
|
1826
|
+
accountId: ctx.accountId ?? void 0
|
|
1827
|
+
})
|
|
1828
|
+
});
|
|
1829
|
+
const [groups, peers] = await Promise.all([runtime.listFeishuDirectoryGroupsLive({
|
|
1830
|
+
cfg: ctx.cfg,
|
|
1831
|
+
query,
|
|
1832
|
+
limit,
|
|
1833
|
+
fallbackToStatic: false,
|
|
1834
|
+
accountId: ctx.accountId ?? void 0
|
|
1835
|
+
}), runtime.listFeishuDirectoryPeersLive({
|
|
1836
|
+
cfg: ctx.cfg,
|
|
1837
|
+
query,
|
|
1838
|
+
limit,
|
|
1839
|
+
fallbackToStatic: false,
|
|
1840
|
+
accountId: ctx.accountId ?? void 0
|
|
1841
|
+
})]);
|
|
1842
|
+
return jsonActionResult({
|
|
1843
|
+
ok: true,
|
|
1844
|
+
channel: "feishu",
|
|
1845
|
+
action: "channel-list",
|
|
1846
|
+
groups,
|
|
1847
|
+
peers
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1850
|
+
if (ctx.action === "react") {
|
|
1851
|
+
const messageId = resolveFeishuMessageId(ctx.params);
|
|
1852
|
+
if (!messageId) throw new Error("Feishu reaction requires messageId.");
|
|
1853
|
+
const emoji = typeof ctx.params.emoji === "string" ? ctx.params.emoji.trim() : "";
|
|
1854
|
+
const remove = ctx.params.remove === true;
|
|
1855
|
+
const clearAll = ctx.params.clearAll === true;
|
|
1856
|
+
if (remove) {
|
|
1857
|
+
if (!emoji) throw new Error("Emoji is required to remove a Feishu reaction.");
|
|
1858
|
+
const { listReactionsFeishu, removeReactionFeishu } = await loadFeishuChannelRuntime();
|
|
1859
|
+
const ownReaction = (await listReactionsFeishu({
|
|
1860
|
+
cfg: ctx.cfg,
|
|
1861
|
+
messageId,
|
|
1862
|
+
emojiType: emoji,
|
|
1863
|
+
accountId: ctx.accountId ?? void 0
|
|
1864
|
+
})).find((entry) => entry.operatorType === "app");
|
|
1865
|
+
if (!ownReaction) return jsonActionResult({
|
|
1866
|
+
ok: true,
|
|
1867
|
+
removed: null
|
|
1868
|
+
});
|
|
1869
|
+
await removeReactionFeishu({
|
|
1870
|
+
cfg: ctx.cfg,
|
|
1871
|
+
messageId,
|
|
1872
|
+
reactionId: ownReaction.reactionId,
|
|
1873
|
+
accountId: ctx.accountId ?? void 0
|
|
1874
|
+
});
|
|
1875
|
+
return jsonActionResult({
|
|
1876
|
+
ok: true,
|
|
1877
|
+
removed: emoji
|
|
1878
|
+
});
|
|
1879
|
+
}
|
|
1880
|
+
if (!emoji) {
|
|
1881
|
+
if (!clearAll) throw new Error("Emoji is required to add a Feishu reaction. Set clearAll=true to remove all bot reactions.");
|
|
1882
|
+
const { listReactionsFeishu, removeReactionFeishu } = await loadFeishuChannelRuntime();
|
|
1883
|
+
const reactions = await listReactionsFeishu({
|
|
1884
|
+
cfg: ctx.cfg,
|
|
1885
|
+
messageId,
|
|
1886
|
+
accountId: ctx.accountId ?? void 0
|
|
1887
|
+
});
|
|
1888
|
+
let removed = 0;
|
|
1889
|
+
for (const reaction of reactions.filter((entry) => entry.operatorType === "app")) {
|
|
1890
|
+
await removeReactionFeishu({
|
|
1891
|
+
cfg: ctx.cfg,
|
|
1892
|
+
messageId,
|
|
1893
|
+
reactionId: reaction.reactionId,
|
|
1894
|
+
accountId: ctx.accountId ?? void 0
|
|
1895
|
+
});
|
|
1896
|
+
removed += 1;
|
|
1897
|
+
}
|
|
1898
|
+
return jsonActionResult({
|
|
1899
|
+
ok: true,
|
|
1900
|
+
removed
|
|
1901
|
+
});
|
|
1902
|
+
}
|
|
1903
|
+
const { addReactionFeishu } = await loadFeishuChannelRuntime();
|
|
1904
|
+
await addReactionFeishu({
|
|
1905
|
+
cfg: ctx.cfg,
|
|
1906
|
+
messageId,
|
|
1907
|
+
emojiType: emoji,
|
|
1908
|
+
accountId: ctx.accountId ?? void 0
|
|
1909
|
+
});
|
|
1910
|
+
return jsonActionResult({
|
|
1911
|
+
ok: true,
|
|
1912
|
+
added: emoji
|
|
1913
|
+
});
|
|
1914
|
+
}
|
|
1915
|
+
if (ctx.action === "reactions") {
|
|
1916
|
+
const messageId = resolveFeishuMessageId(ctx.params);
|
|
1917
|
+
if (!messageId) throw new Error("Feishu reactions lookup requires messageId.");
|
|
1918
|
+
const { listReactionsFeishu } = await loadFeishuChannelRuntime();
|
|
1919
|
+
return jsonActionResult({
|
|
1920
|
+
ok: true,
|
|
1921
|
+
reactions: await listReactionsFeishu({
|
|
1922
|
+
cfg: ctx.cfg,
|
|
1923
|
+
messageId,
|
|
1924
|
+
accountId: ctx.accountId ?? void 0
|
|
1925
|
+
})
|
|
1926
|
+
});
|
|
1927
|
+
}
|
|
1928
|
+
throw new Error(`Unsupported Feishu action: "${ctx.action}"`);
|
|
1929
|
+
}
|
|
1930
|
+
},
|
|
1931
|
+
bindings: {
|
|
1932
|
+
compileConfiguredBinding: ({ conversationId }) => normalizeFeishuAcpConversationId(conversationId),
|
|
1933
|
+
matchInboundConversation: ({ compiledBinding, conversationId, parentConversationId }) => matchFeishuAcpConversation({
|
|
1934
|
+
bindingConversationId: compiledBinding.conversationId,
|
|
1935
|
+
conversationId,
|
|
1936
|
+
parentConversationId
|
|
1937
|
+
}),
|
|
1938
|
+
resolveCommandConversation: ({ accountId, threadId, senderId, sessionKey, parentSessionKey, originatingTo, commandTo, fallbackTo }) => resolveFeishuCommandConversation({
|
|
1939
|
+
accountId,
|
|
1940
|
+
threadId,
|
|
1941
|
+
senderId,
|
|
1942
|
+
sessionKey,
|
|
1943
|
+
parentSessionKey,
|
|
1944
|
+
originatingTo,
|
|
1945
|
+
commandTo,
|
|
1946
|
+
fallbackTo
|
|
1947
|
+
})
|
|
1948
|
+
},
|
|
1949
|
+
auth: { login: async ({ cfg }) => {
|
|
1950
|
+
const { createClackPrompter } = await import("klaw/plugin-sdk/setup-runtime");
|
|
1951
|
+
const { replaceConfigFile } = await import("klaw/plugin-sdk/config-mutation");
|
|
1952
|
+
const nextCfg = await runFeishuLogin({
|
|
1953
|
+
cfg,
|
|
1954
|
+
prompter: createClackPrompter()
|
|
1955
|
+
});
|
|
1956
|
+
if (nextCfg !== cfg) await replaceConfigFile({
|
|
1957
|
+
nextConfig: nextCfg,
|
|
1958
|
+
afterWrite: { mode: "auto" }
|
|
1959
|
+
});
|
|
1960
|
+
} },
|
|
1961
|
+
setup: feishuSetupAdapter,
|
|
1962
|
+
setupWizard: feishuSetupWizard,
|
|
1963
|
+
messaging: {
|
|
1964
|
+
targetPrefixes: ["feishu", "lark"],
|
|
1965
|
+
normalizeTarget: (raw) => normalizeFeishuTarget(raw) ?? void 0,
|
|
1966
|
+
resolveDeliveryTarget: ({ conversationId, parentConversationId }) => {
|
|
1967
|
+
const directId = parseFeishuDirectConversationId(conversationId);
|
|
1968
|
+
if (directId) return { to: `user:${directId}` };
|
|
1969
|
+
const parsed = parseFeishuConversationId({
|
|
1970
|
+
conversationId,
|
|
1971
|
+
parentConversationId
|
|
1972
|
+
});
|
|
1973
|
+
if (parsed?.topicId) return {
|
|
1974
|
+
to: `chat:${parentConversationId?.trim() || parsed.chatId}`,
|
|
1975
|
+
threadId: parsed.topicId
|
|
1976
|
+
};
|
|
1977
|
+
return { to: `chat:${parsed?.chatId ?? conversationId.trim()}` };
|
|
1978
|
+
},
|
|
1979
|
+
resolveSessionConversation: ({ kind, rawId }) => resolveFeishuSessionConversation({
|
|
1980
|
+
kind,
|
|
1981
|
+
rawId
|
|
1982
|
+
}),
|
|
1983
|
+
resolveOutboundSessionRoute: (params) => resolveFeishuOutboundSessionRoute(params),
|
|
1984
|
+
targetResolver: {
|
|
1985
|
+
looksLikeId: looksLikeFeishuId,
|
|
1986
|
+
hint: "<chatId|user:openId|chat:chatId>"
|
|
1987
|
+
}
|
|
1988
|
+
},
|
|
1989
|
+
directory: createChannelDirectoryAdapter({
|
|
1990
|
+
listPeers: async ({ cfg, query, limit, accountId }) => listFeishuDirectoryPeers({
|
|
1991
|
+
cfg,
|
|
1992
|
+
query: query ?? void 0,
|
|
1993
|
+
limit: limit ?? void 0,
|
|
1994
|
+
accountId: accountId ?? void 0
|
|
1995
|
+
}),
|
|
1996
|
+
listGroups: async ({ cfg, query, limit, accountId }) => listFeishuDirectoryGroups({
|
|
1997
|
+
cfg,
|
|
1998
|
+
query: query ?? void 0,
|
|
1999
|
+
limit: limit ?? void 0,
|
|
2000
|
+
accountId: accountId ?? void 0
|
|
2001
|
+
}),
|
|
2002
|
+
...createRuntimeDirectoryLiveAdapter({
|
|
2003
|
+
getRuntime: loadFeishuChannelRuntime,
|
|
2004
|
+
listPeersLive: (runtime) => async ({ cfg, query, limit, accountId }) => await runtime.listFeishuDirectoryPeersLive({
|
|
2005
|
+
cfg,
|
|
2006
|
+
query: query ?? void 0,
|
|
2007
|
+
limit: limit ?? void 0,
|
|
2008
|
+
accountId: accountId ?? void 0
|
|
2009
|
+
}),
|
|
2010
|
+
listGroupsLive: (runtime) => async ({ cfg, query, limit, accountId }) => await runtime.listFeishuDirectoryGroupsLive({
|
|
2011
|
+
cfg,
|
|
2012
|
+
query: query ?? void 0,
|
|
2013
|
+
limit: limit ?? void 0,
|
|
2014
|
+
accountId: accountId ?? void 0
|
|
2015
|
+
})
|
|
2016
|
+
})
|
|
2017
|
+
}),
|
|
2018
|
+
status: createComputedAccountStatusAdapter({
|
|
2019
|
+
defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID$2, { port: null }),
|
|
2020
|
+
buildChannelSummary: ({ snapshot }) => buildProbeChannelStatusSummary(snapshot, { port: snapshot.port ?? null }),
|
|
2021
|
+
probeAccount: async ({ account }) => await (await loadFeishuChannelRuntime()).probeFeishu(account),
|
|
2022
|
+
resolveAccountSnapshot: ({ account, runtime }) => ({
|
|
2023
|
+
accountId: account.accountId,
|
|
2024
|
+
enabled: account.enabled,
|
|
2025
|
+
configured: account.configured,
|
|
2026
|
+
name: account.name,
|
|
2027
|
+
extra: {
|
|
2028
|
+
appId: account.appId,
|
|
2029
|
+
domain: account.domain,
|
|
2030
|
+
port: runtime?.port ?? null
|
|
2031
|
+
}
|
|
2032
|
+
})
|
|
2033
|
+
}),
|
|
2034
|
+
gateway: { startAccount: async (ctx) => {
|
|
2035
|
+
const { monitorFeishuProvider } = await import("./monitor-oWptK0zL.js");
|
|
2036
|
+
const account = resolveFeishuRuntimeAccount({
|
|
2037
|
+
cfg: ctx.cfg,
|
|
2038
|
+
accountId: ctx.accountId
|
|
2039
|
+
}, { requireEventSecrets: true });
|
|
2040
|
+
const port = account.config?.webhookPort ?? null;
|
|
2041
|
+
ctx.setStatus({
|
|
2042
|
+
accountId: ctx.accountId,
|
|
2043
|
+
port
|
|
2044
|
+
});
|
|
2045
|
+
ctx.log?.info(`starting feishu[${ctx.accountId}] (mode: ${account.config?.connectionMode ?? "websocket"})`);
|
|
2046
|
+
return monitorFeishuProvider({
|
|
2047
|
+
config: ctx.cfg,
|
|
2048
|
+
runtime: ctx.runtime,
|
|
2049
|
+
abortSignal: ctx.abortSignal,
|
|
2050
|
+
accountId: ctx.accountId
|
|
2051
|
+
});
|
|
2052
|
+
} },
|
|
2053
|
+
message: feishuMessageAdapter
|
|
2054
|
+
},
|
|
2055
|
+
security: {
|
|
2056
|
+
collectWarnings: projectConfigAccountIdWarningCollector(collectFeishuSecurityWarnings),
|
|
2057
|
+
collectAuditFindings: ({ cfg }) => collectFeishuSecurityAuditFindings({ cfg })
|
|
2058
|
+
},
|
|
2059
|
+
pairing: { text: {
|
|
2060
|
+
idLabel: "feishuUserId",
|
|
2061
|
+
message: PAIRING_APPROVED_MESSAGE,
|
|
2062
|
+
normalizeAllowEntry: createPairingPrefixStripper(/^(feishu|user|open_id):/i),
|
|
2063
|
+
notify: async ({ cfg, id, message, accountId }) => {
|
|
2064
|
+
const { sendMessageFeishu } = await loadFeishuChannelRuntime();
|
|
2065
|
+
await sendMessageFeishu({
|
|
2066
|
+
cfg,
|
|
2067
|
+
to: id,
|
|
2068
|
+
text: message,
|
|
2069
|
+
accountId
|
|
2070
|
+
});
|
|
2071
|
+
}
|
|
2072
|
+
} },
|
|
2073
|
+
outbound: {
|
|
2074
|
+
deliveryMode: "direct",
|
|
2075
|
+
chunker: chunkTextForOutbound,
|
|
2076
|
+
chunkerMode: "markdown",
|
|
2077
|
+
textChunkLimit: 4e3,
|
|
2078
|
+
presentationCapabilities: {
|
|
2079
|
+
supported: true,
|
|
2080
|
+
buttons: true,
|
|
2081
|
+
selects: false,
|
|
2082
|
+
context: true,
|
|
2083
|
+
divider: true,
|
|
2084
|
+
limits: {
|
|
2085
|
+
actions: {
|
|
2086
|
+
maxActions: 20,
|
|
2087
|
+
maxActionsPerRow: 5,
|
|
2088
|
+
maxLabelLength: 40,
|
|
2089
|
+
maxValueBytes: 1024
|
|
2090
|
+
},
|
|
2091
|
+
text: {
|
|
2092
|
+
maxLength: 4e3,
|
|
2093
|
+
encoding: "characters",
|
|
2094
|
+
markdownDialect: "markdown"
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
},
|
|
2098
|
+
renderPresentation: async (ctx) => {
|
|
2099
|
+
const renderPresentation = (await loadFeishuChannelRuntime()).feishuOutbound.renderPresentation;
|
|
2100
|
+
return renderPresentation ? await renderPresentation(ctx) : null;
|
|
2101
|
+
},
|
|
2102
|
+
sendPayload: async (ctx) => {
|
|
2103
|
+
const sendPayload = (await loadFeishuChannelRuntime()).feishuOutbound.sendPayload;
|
|
2104
|
+
if (!sendPayload) throw new Error("Feishu payload sending is not available.");
|
|
2105
|
+
return await sendPayload(ctx);
|
|
2106
|
+
},
|
|
2107
|
+
...createRuntimeOutboundDelegates({
|
|
2108
|
+
getRuntime: loadFeishuChannelRuntime,
|
|
2109
|
+
sendText: { resolve: (runtime) => runtime.feishuOutbound.sendText },
|
|
2110
|
+
sendMedia: { resolve: (runtime) => runtime.feishuOutbound.sendMedia }
|
|
2111
|
+
})
|
|
2112
|
+
}
|
|
2113
|
+
});
|
|
2114
|
+
//#endregion
|
|
2115
|
+
export { listFeishuDirectoryPeers as _, setFeishuNamedAccountEnabled$1 as a, decodeFeishuCardAction as b, toFeishuSendResult as c, resolveFeishuDmIngressAccess as d, resolveFeishuGroupConfig as f, listFeishuDirectoryGroups as g, resolveFeishuReplyPolicy as h, feishuSetupAdapter as i, hasExplicitFeishuGroupConfig as l, resolveFeishuGroupSenderActivationIngressAccess as m, feishuSetupWizard as n, assertFeishuMessageApiSuccess as o, resolveFeishuGroupConversationIngressAccess as p, runFeishuLogin as r, resolveFeishuReceiptKind as s, feishuPlugin as t, normalizeFeishuAllowEntry as u, buildFeishuCardActionTextFallback as v, createFeishuCardInteractionEnvelope as y };
|