@openclaw/feishu 2026.5.2-beta.2 → 2026.5.3-beta.1
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/dist/accounts-Ba3-WP1z.js +423 -0
- package/dist/api.js +2280 -0
- package/dist/app-registration-B8qc1MCM.js +184 -0
- package/dist/audio-preflight.runtime-BPlzkO3l.js +7 -0
- package/dist/card-interaction-BfRLgvw_.js +96 -0
- package/dist/channel-CSD_Jt8I.js +1668 -0
- package/dist/channel-entry.js +22 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.runtime-DYsXcD36.js +700 -0
- package/dist/client-DBVoQL5w.js +157 -0
- package/dist/contract-api.js +9 -0
- package/dist/conversation-id-DWS3Ep2A.js +139 -0
- package/dist/directory.static-f3EeoRJd.js +44 -0
- package/dist/drive-C5eJLJr7.js +883 -0
- package/dist/index.js +68 -0
- package/dist/monitor-CT189QfR.js +60 -0
- package/dist/monitor.account-dJV2jO8C.js +4990 -0
- package/dist/monitor.state-DYM02ipp.js +100 -0
- package/dist/policy-D6c-wMPl.js +118 -0
- package/dist/probe-BNzzU_uR.js +149 -0
- package/dist/rolldown-runtime-DUslC3ob.js +14 -0
- package/dist/runtime-CG0DuRCy.js +8 -0
- package/dist/runtime-api.js +14 -0
- package/dist/secret-contract-Dm4Z_zQN.js +119 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/security-audit-DqJdocrN.js +11 -0
- package/dist/security-audit-shared-ByuMx9cJ.js +38 -0
- package/dist/security-contract-api.js +2 -0
- package/dist/send-DowxxbpH.js +1218 -0
- package/dist/session-conversation-B4nrW-vo.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-C3UhPVLV.js +227 -0
- package/dist/subagent-hooks-api.js +23 -0
- package/dist/targets-JMFJRKSe.js +48 -0
- package/dist/thread-bindings-BmS6TLes.js +222 -0
- package/package.json +15 -6
- package/api.ts +0 -31
- package/channel-entry.ts +0 -20
- package/channel-plugin-api.ts +0 -1
- package/contract-api.ts +0 -16
- package/index.ts +0 -82
- package/runtime-api.ts +0 -55
- package/secret-contract-api.ts +0 -5
- package/security-contract-api.ts +0 -1
- package/session-key-api.ts +0 -1
- package/setup-api.ts +0 -3
- package/setup-entry.test.ts +0 -14
- package/setup-entry.ts +0 -13
- package/src/accounts.test.ts +0 -459
- package/src/accounts.ts +0 -326
- package/src/app-registration.ts +0 -331
- package/src/approval-auth.test.ts +0 -24
- package/src/approval-auth.ts +0 -25
- package/src/async.test.ts +0 -35
- package/src/async.ts +0 -104
- package/src/audio-preflight.runtime.ts +0 -9
- package/src/bitable.test.ts +0 -131
- package/src/bitable.ts +0 -762
- package/src/bot-content.ts +0 -474
- package/src/bot-group-name.test.ts +0 -108
- package/src/bot-runtime-api.ts +0 -12
- package/src/bot-sender-name.ts +0 -125
- package/src/bot.broadcast.test.ts +0 -463
- package/src/bot.card-action.test.ts +0 -577
- package/src/bot.checkBotMentioned.test.ts +0 -265
- package/src/bot.helpers.test.ts +0 -118
- package/src/bot.stripBotMention.test.ts +0 -126
- package/src/bot.test.ts +0 -3040
- package/src/bot.ts +0 -1559
- package/src/card-action.ts +0 -447
- package/src/card-interaction.test.ts +0 -129
- package/src/card-interaction.ts +0 -159
- package/src/card-test-helpers.ts +0 -47
- package/src/card-ux-approval.ts +0 -65
- package/src/card-ux-launcher.test.ts +0 -99
- package/src/card-ux-launcher.ts +0 -121
- package/src/card-ux-shared.ts +0 -33
- package/src/channel-runtime-api.ts +0 -16
- package/src/channel.runtime.ts +0 -47
- package/src/channel.test.ts +0 -959
- package/src/channel.ts +0 -1313
- package/src/chat-schema.ts +0 -25
- package/src/chat.test.ts +0 -196
- package/src/chat.ts +0 -188
- package/src/client.test.ts +0 -433
- package/src/client.ts +0 -290
- package/src/comment-dispatcher-runtime-api.ts +0 -6
- package/src/comment-dispatcher.test.ts +0 -169
- package/src/comment-dispatcher.ts +0 -107
- package/src/comment-handler-runtime-api.ts +0 -3
- package/src/comment-handler.test.ts +0 -486
- package/src/comment-handler.ts +0 -309
- package/src/comment-reaction.test.ts +0 -166
- package/src/comment-reaction.ts +0 -259
- package/src/comment-shared.test.ts +0 -182
- package/src/comment-shared.ts +0 -406
- package/src/comment-target.ts +0 -44
- package/src/config-schema.test.ts +0 -309
- package/src/config-schema.ts +0 -333
- package/src/conversation-id.test.ts +0 -18
- package/src/conversation-id.ts +0 -199
- package/src/dedup-runtime-api.ts +0 -1
- package/src/dedup.ts +0 -141
- package/src/directory.static.ts +0 -61
- package/src/directory.test.ts +0 -136
- package/src/directory.ts +0 -124
- package/src/doc-schema.ts +0 -182
- package/src/docx-batch-insert.test.ts +0 -91
- package/src/docx-batch-insert.ts +0 -223
- package/src/docx-color-text.ts +0 -154
- package/src/docx-table-ops.test.ts +0 -53
- package/src/docx-table-ops.ts +0 -316
- package/src/docx-types.ts +0 -38
- package/src/docx.account-selection.test.ts +0 -79
- package/src/docx.test.ts +0 -685
- package/src/docx.ts +0 -1616
- package/src/drive-schema.ts +0 -92
- package/src/drive.test.ts +0 -1219
- package/src/drive.ts +0 -829
- package/src/dynamic-agent.ts +0 -137
- package/src/event-types.ts +0 -45
- package/src/external-keys.test.ts +0 -20
- package/src/external-keys.ts +0 -19
- package/src/lifecycle.test-support.ts +0 -220
- package/src/media.test.ts +0 -900
- package/src/media.ts +0 -861
- package/src/mention-target.types.ts +0 -5
- package/src/mention.ts +0 -114
- package/src/message-action-contract.ts +0 -13
- package/src/monitor-state-runtime-api.ts +0 -7
- package/src/monitor-transport-runtime-api.ts +0 -7
- package/src/monitor.account.ts +0 -468
- package/src/monitor.acp-init-failure.lifecycle.test-support.ts +0 -219
- package/src/monitor.bot-identity.ts +0 -86
- package/src/monitor.bot-menu-handler.ts +0 -165
- package/src/monitor.bot-menu.lifecycle.test-support.ts +0 -224
- package/src/monitor.bot-menu.test.ts +0 -178
- package/src/monitor.broadcast.reply-once.lifecycle.test-support.ts +0 -264
- package/src/monitor.card-action.lifecycle.test-support.ts +0 -373
- package/src/monitor.cleanup.test.ts +0 -376
- package/src/monitor.comment-notice-handler.ts +0 -105
- package/src/monitor.comment.test.ts +0 -937
- package/src/monitor.comment.ts +0 -1386
- package/src/monitor.lifecycle.test.ts +0 -4
- package/src/monitor.message-handler.ts +0 -339
- package/src/monitor.reaction.lifecycle.test-support.ts +0 -68
- package/src/monitor.reaction.test.ts +0 -713
- package/src/monitor.startup.test.ts +0 -192
- package/src/monitor.startup.ts +0 -74
- package/src/monitor.state.defaults.test.ts +0 -46
- package/src/monitor.state.ts +0 -170
- package/src/monitor.synthetic-error.ts +0 -18
- package/src/monitor.test-mocks.ts +0 -45
- package/src/monitor.transport.ts +0 -424
- package/src/monitor.ts +0 -100
- package/src/monitor.webhook-e2e.test.ts +0 -272
- package/src/monitor.webhook-security.test.ts +0 -264
- package/src/monitor.webhook.test-helpers.ts +0 -116
- package/src/outbound-runtime-api.ts +0 -1
- package/src/outbound.test.ts +0 -935
- package/src/outbound.ts +0 -718
- package/src/perm-schema.ts +0 -52
- package/src/perm.ts +0 -170
- package/src/pins.ts +0 -108
- package/src/policy.test.ts +0 -334
- package/src/policy.ts +0 -236
- package/src/post.test.ts +0 -105
- package/src/post.ts +0 -275
- package/src/probe.test.ts +0 -275
- package/src/probe.ts +0 -166
- package/src/processing-claims.ts +0 -59
- package/src/qr-terminal.ts +0 -1
- package/src/reactions.ts +0 -123
- package/src/reasoning-preview.test.ts +0 -59
- package/src/reasoning-preview.ts +0 -20
- package/src/reply-dispatcher-runtime-api.ts +0 -7
- package/src/reply-dispatcher.test.ts +0 -1144
- package/src/reply-dispatcher.ts +0 -650
- package/src/runtime.ts +0 -9
- package/src/secret-contract.ts +0 -145
- package/src/secret-input.ts +0 -1
- package/src/security-audit-shared.ts +0 -69
- package/src/security-audit.test.ts +0 -61
- package/src/security-audit.ts +0 -1
- package/src/send-result.ts +0 -29
- package/src/send-target.test.ts +0 -80
- package/src/send-target.ts +0 -35
- package/src/send.reply-fallback.test.ts +0 -292
- package/src/send.test.ts +0 -550
- package/src/send.ts +0 -800
- package/src/sequential-key.test.ts +0 -72
- package/src/sequential-key.ts +0 -28
- package/src/sequential-queue.test.ts +0 -92
- package/src/sequential-queue.ts +0 -16
- package/src/session-conversation.ts +0 -42
- package/src/session-route.ts +0 -48
- package/src/setup-core.ts +0 -51
- package/src/setup-surface.test.ts +0 -174
- package/src/setup-surface.ts +0 -581
- package/src/streaming-card.test.ts +0 -190
- package/src/streaming-card.ts +0 -490
- package/src/subagent-hooks.test.ts +0 -603
- package/src/subagent-hooks.ts +0 -397
- package/src/targets.ts +0 -97
- package/src/test-support/lifecycle-test-support.ts +0 -453
- package/src/thread-bindings.test.ts +0 -143
- package/src/thread-bindings.ts +0 -330
- package/src/tool-account-routing.test.ts +0 -187
- package/src/tool-account.test.ts +0 -44
- package/src/tool-account.ts +0 -93
- package/src/tool-factory-test-harness.ts +0 -79
- package/src/tool-result.test.ts +0 -32
- package/src/tool-result.ts +0 -16
- package/src/tools-config.test.ts +0 -21
- package/src/tools-config.ts +0 -22
- package/src/types.ts +0 -104
- package/src/typing.test.ts +0 -144
- package/src/typing.ts +0 -214
- package/src/wiki-schema.ts +0 -55
- package/src/wiki.ts +0 -227
- package/subagent-hooks-api.ts +0 -31
- package/tsconfig.json +0 -16
package/src/conversation-id.ts
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
|
|
2
|
-
|
|
3
|
-
export type FeishuGroupSessionScope =
|
|
4
|
-
| "group"
|
|
5
|
-
| "group_sender"
|
|
6
|
-
| "group_topic"
|
|
7
|
-
| "group_topic_sender";
|
|
8
|
-
|
|
9
|
-
function normalizeText(value: unknown): string | undefined {
|
|
10
|
-
if (typeof value !== "string") {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
const trimmed = value.trim();
|
|
14
|
-
return trimmed || undefined;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function buildFeishuConversationId(params: {
|
|
18
|
-
chatId: string;
|
|
19
|
-
scope: FeishuGroupSessionScope;
|
|
20
|
-
senderOpenId?: string;
|
|
21
|
-
topicId?: string;
|
|
22
|
-
}): string {
|
|
23
|
-
const chatId = normalizeText(params.chatId) ?? "unknown";
|
|
24
|
-
const senderOpenId = normalizeText(params.senderOpenId);
|
|
25
|
-
const topicId = normalizeText(params.topicId);
|
|
26
|
-
|
|
27
|
-
switch (params.scope) {
|
|
28
|
-
case "group_sender":
|
|
29
|
-
return senderOpenId ? `${chatId}:sender:${senderOpenId}` : chatId;
|
|
30
|
-
case "group_topic":
|
|
31
|
-
return topicId ? `${chatId}:topic:${topicId}` : chatId;
|
|
32
|
-
case "group_topic_sender":
|
|
33
|
-
if (topicId && senderOpenId) {
|
|
34
|
-
return `${chatId}:topic:${topicId}:sender:${senderOpenId}`;
|
|
35
|
-
}
|
|
36
|
-
if (topicId) {
|
|
37
|
-
return `${chatId}:topic:${topicId}`;
|
|
38
|
-
}
|
|
39
|
-
return senderOpenId ? `${chatId}:sender:${senderOpenId}` : chatId;
|
|
40
|
-
case "group":
|
|
41
|
-
default:
|
|
42
|
-
return chatId;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function parseFeishuTargetId(raw: unknown): string | undefined {
|
|
47
|
-
const target = normalizeText(raw);
|
|
48
|
-
if (!target) {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
const withoutProvider = target.replace(/^(feishu|lark):/i, "").trim();
|
|
52
|
-
if (!withoutProvider) {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
const lowered = normalizeLowercaseStringOrEmpty(withoutProvider);
|
|
56
|
-
for (const prefix of ["chat:", "group:", "channel:", "user:", "dm:", "open_id:"]) {
|
|
57
|
-
if (lowered.startsWith(prefix)) {
|
|
58
|
-
return normalizeText(withoutProvider.slice(prefix.length));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return withoutProvider;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function parseFeishuDirectConversationId(raw: unknown): string | undefined {
|
|
65
|
-
const target = normalizeText(raw);
|
|
66
|
-
if (!target) {
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
const withoutProvider = target.replace(/^(feishu|lark):/i, "").trim();
|
|
70
|
-
if (!withoutProvider) {
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
const lowered = normalizeLowercaseStringOrEmpty(withoutProvider);
|
|
74
|
-
for (const prefix of ["user:", "dm:", "open_id:"]) {
|
|
75
|
-
if (lowered.startsWith(prefix)) {
|
|
76
|
-
return normalizeText(withoutProvider.slice(prefix.length));
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
const id = parseFeishuTargetId(target);
|
|
80
|
-
if (!id) {
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
if (id.startsWith("ou_") || id.startsWith("on_")) {
|
|
84
|
-
return id;
|
|
85
|
-
}
|
|
86
|
-
return undefined;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function parseFeishuConversationId(params: {
|
|
90
|
-
conversationId: string;
|
|
91
|
-
parentConversationId?: string;
|
|
92
|
-
}): {
|
|
93
|
-
canonicalConversationId: string;
|
|
94
|
-
chatId: string;
|
|
95
|
-
topicId?: string;
|
|
96
|
-
senderOpenId?: string;
|
|
97
|
-
scope: FeishuGroupSessionScope;
|
|
98
|
-
} | null {
|
|
99
|
-
const conversationId = normalizeText(params.conversationId);
|
|
100
|
-
const parentConversationId = normalizeText(params.parentConversationId);
|
|
101
|
-
if (!conversationId) {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const topicSenderMatch = conversationId.match(/^(.+):topic:([^:]+):sender:([^:]+)$/i);
|
|
106
|
-
if (topicSenderMatch) {
|
|
107
|
-
const [, chatId, topicId, senderOpenId] = topicSenderMatch;
|
|
108
|
-
return {
|
|
109
|
-
canonicalConversationId: buildFeishuConversationId({
|
|
110
|
-
chatId,
|
|
111
|
-
scope: "group_topic_sender",
|
|
112
|
-
topicId,
|
|
113
|
-
senderOpenId,
|
|
114
|
-
}),
|
|
115
|
-
chatId,
|
|
116
|
-
topicId,
|
|
117
|
-
senderOpenId,
|
|
118
|
-
scope: "group_topic_sender",
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const topicMatch = conversationId.match(/^(.+):topic:([^:]+)$/i);
|
|
123
|
-
if (topicMatch) {
|
|
124
|
-
const [, chatId, topicId] = topicMatch;
|
|
125
|
-
return {
|
|
126
|
-
canonicalConversationId: buildFeishuConversationId({
|
|
127
|
-
chatId,
|
|
128
|
-
scope: "group_topic",
|
|
129
|
-
topicId,
|
|
130
|
-
}),
|
|
131
|
-
chatId,
|
|
132
|
-
topicId,
|
|
133
|
-
scope: "group_topic",
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const senderMatch = conversationId.match(/^(.+):sender:([^:]+)$/i);
|
|
138
|
-
if (senderMatch) {
|
|
139
|
-
const [, chatId, senderOpenId] = senderMatch;
|
|
140
|
-
return {
|
|
141
|
-
canonicalConversationId: buildFeishuConversationId({
|
|
142
|
-
chatId,
|
|
143
|
-
scope: "group_sender",
|
|
144
|
-
senderOpenId,
|
|
145
|
-
}),
|
|
146
|
-
chatId,
|
|
147
|
-
senderOpenId,
|
|
148
|
-
scope: "group_sender",
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (parentConversationId) {
|
|
153
|
-
return {
|
|
154
|
-
canonicalConversationId: buildFeishuConversationId({
|
|
155
|
-
chatId: parentConversationId,
|
|
156
|
-
scope: "group_topic",
|
|
157
|
-
topicId: conversationId,
|
|
158
|
-
}),
|
|
159
|
-
chatId: parentConversationId,
|
|
160
|
-
topicId: conversationId,
|
|
161
|
-
scope: "group_topic",
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return {
|
|
166
|
-
canonicalConversationId: conversationId,
|
|
167
|
-
chatId: conversationId,
|
|
168
|
-
scope: "group",
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function buildFeishuModelOverrideParentCandidates(
|
|
173
|
-
parentConversationId?: string | null,
|
|
174
|
-
): string[] {
|
|
175
|
-
const rawId = normalizeText(parentConversationId);
|
|
176
|
-
if (!rawId) {
|
|
177
|
-
return [];
|
|
178
|
-
}
|
|
179
|
-
const topicSenderMatch = rawId.match(/^(.+):topic:([^:]+):sender:([^:]+)$/i);
|
|
180
|
-
if (topicSenderMatch) {
|
|
181
|
-
const chatId = normalizeLowercaseStringOrEmpty(topicSenderMatch[1]);
|
|
182
|
-
const topicId = normalizeLowercaseStringOrEmpty(topicSenderMatch[2]);
|
|
183
|
-
if (chatId && topicId) {
|
|
184
|
-
return [`${chatId}:topic:${topicId}`, chatId];
|
|
185
|
-
}
|
|
186
|
-
return [];
|
|
187
|
-
}
|
|
188
|
-
const topicMatch = rawId.match(/^(.+):topic:([^:]+)$/i);
|
|
189
|
-
if (topicMatch) {
|
|
190
|
-
const chatId = normalizeLowercaseStringOrEmpty(topicMatch[1]);
|
|
191
|
-
return chatId ? [chatId] : [];
|
|
192
|
-
}
|
|
193
|
-
const senderMatch = rawId.match(/^(.+):sender:([^:]+)$/i);
|
|
194
|
-
if (senderMatch) {
|
|
195
|
-
const chatId = normalizeLowercaseStringOrEmpty(senderMatch[1]);
|
|
196
|
-
return chatId ? [chatId] : [];
|
|
197
|
-
}
|
|
198
|
-
return [];
|
|
199
|
-
}
|
package/src/dedup-runtime-api.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { createPersistentDedupe } from "openclaw/plugin-sdk/persistent-dedupe";
|
package/src/dedup.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import os from "node:os";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { createPersistentDedupe } from "./dedup-runtime-api.js";
|
|
4
|
-
import {
|
|
5
|
-
releaseFeishuMessageProcessing,
|
|
6
|
-
tryBeginFeishuMessageProcessing,
|
|
7
|
-
} from "./processing-claims.js";
|
|
8
|
-
|
|
9
|
-
// Persistent TTL: 24 hours — survives restarts & WebSocket reconnects.
|
|
10
|
-
const DEDUP_TTL_MS = 24 * 60 * 60 * 1000;
|
|
11
|
-
const MEMORY_MAX_SIZE = 1_000;
|
|
12
|
-
const FILE_MAX_ENTRIES = 10_000;
|
|
13
|
-
|
|
14
|
-
function resolveStateDirFromEnv(env: NodeJS.ProcessEnv = process.env): string {
|
|
15
|
-
const stateOverride = env.OPENCLAW_STATE_DIR?.trim();
|
|
16
|
-
if (stateOverride) {
|
|
17
|
-
return stateOverride;
|
|
18
|
-
}
|
|
19
|
-
if (env.VITEST || env.NODE_ENV === "test") {
|
|
20
|
-
return path.join(os.tmpdir(), ["openclaw-vitest", String(process.pid)].join("-"));
|
|
21
|
-
}
|
|
22
|
-
return path.join(os.homedir(), ".openclaw");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function resolveNamespaceFilePath(namespace: string): string {
|
|
26
|
-
const safe = namespace.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
27
|
-
return path.join(resolveStateDirFromEnv(), "feishu", "dedup", `${safe}.json`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const persistentDedupe = createPersistentDedupe({
|
|
31
|
-
ttlMs: DEDUP_TTL_MS,
|
|
32
|
-
memoryMaxSize: MEMORY_MAX_SIZE,
|
|
33
|
-
fileMaxEntries: FILE_MAX_ENTRIES,
|
|
34
|
-
resolveFilePath: resolveNamespaceFilePath,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
function normalizeMessageId(messageId: string | undefined | null): string | null {
|
|
38
|
-
const trimmed = messageId?.trim();
|
|
39
|
-
return trimmed ? trimmed : null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export { releaseFeishuMessageProcessing, tryBeginFeishuMessageProcessing };
|
|
43
|
-
|
|
44
|
-
export async function claimUnprocessedFeishuMessage(params: {
|
|
45
|
-
messageId: string | undefined | null;
|
|
46
|
-
namespace?: string;
|
|
47
|
-
log?: (...args: unknown[]) => void;
|
|
48
|
-
}): Promise<"claimed" | "duplicate" | "inflight" | "invalid"> {
|
|
49
|
-
const { messageId, namespace = "global", log } = params;
|
|
50
|
-
const normalizedMessageId = normalizeMessageId(messageId);
|
|
51
|
-
if (!normalizedMessageId) {
|
|
52
|
-
return "invalid";
|
|
53
|
-
}
|
|
54
|
-
if (await hasProcessedFeishuMessage(normalizedMessageId, namespace, log)) {
|
|
55
|
-
return "duplicate";
|
|
56
|
-
}
|
|
57
|
-
if (!tryBeginFeishuMessageProcessing(normalizedMessageId, namespace)) {
|
|
58
|
-
return "inflight";
|
|
59
|
-
}
|
|
60
|
-
return "claimed";
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export async function finalizeFeishuMessageProcessing(params: {
|
|
64
|
-
messageId: string | undefined | null;
|
|
65
|
-
namespace?: string;
|
|
66
|
-
log?: (...args: unknown[]) => void;
|
|
67
|
-
claimHeld?: boolean;
|
|
68
|
-
}): Promise<boolean> {
|
|
69
|
-
const { messageId, namespace = "global", log, claimHeld = false } = params;
|
|
70
|
-
const normalizedMessageId = normalizeMessageId(messageId);
|
|
71
|
-
if (!normalizedMessageId) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
if (!claimHeld && !tryBeginFeishuMessageProcessing(normalizedMessageId, namespace)) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
if (!(await tryRecordMessagePersistent(normalizedMessageId, namespace, log))) {
|
|
78
|
-
releaseFeishuMessageProcessing(normalizedMessageId, namespace);
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export async function recordProcessedFeishuMessage(
|
|
85
|
-
messageId: string | undefined | null,
|
|
86
|
-
namespace = "global",
|
|
87
|
-
log?: (...args: unknown[]) => void,
|
|
88
|
-
): Promise<boolean> {
|
|
89
|
-
const normalizedMessageId = normalizeMessageId(messageId);
|
|
90
|
-
if (!normalizedMessageId) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
return await tryRecordMessagePersistent(normalizedMessageId, namespace, log);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export async function hasProcessedFeishuMessage(
|
|
97
|
-
messageId: string | undefined | null,
|
|
98
|
-
namespace = "global",
|
|
99
|
-
log?: (...args: unknown[]) => void,
|
|
100
|
-
): Promise<boolean> {
|
|
101
|
-
const normalizedMessageId = normalizeMessageId(messageId);
|
|
102
|
-
if (!normalizedMessageId) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
return hasRecordedMessagePersistent(normalizedMessageId, namespace, log);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export async function tryRecordMessagePersistent(
|
|
109
|
-
messageId: string,
|
|
110
|
-
namespace = "global",
|
|
111
|
-
log?: (...args: unknown[]) => void,
|
|
112
|
-
): Promise<boolean> {
|
|
113
|
-
return persistentDedupe.checkAndRecord(messageId, {
|
|
114
|
-
namespace,
|
|
115
|
-
onDiskError: (error) => {
|
|
116
|
-
log?.(`feishu-dedup: disk error, falling back to memory: ${String(error)}`);
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async function hasRecordedMessagePersistent(
|
|
122
|
-
messageId: string,
|
|
123
|
-
namespace = "global",
|
|
124
|
-
log?: (...args: unknown[]) => void,
|
|
125
|
-
): Promise<boolean> {
|
|
126
|
-
return persistentDedupe.hasRecent(messageId, {
|
|
127
|
-
namespace,
|
|
128
|
-
onDiskError: (error) => {
|
|
129
|
-
log?.(`feishu-dedup: persistent peek failed: ${String(error)}`);
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export async function warmupDedupFromDisk(
|
|
135
|
-
namespace: string,
|
|
136
|
-
log?: (...args: unknown[]) => void,
|
|
137
|
-
): Promise<number> {
|
|
138
|
-
return persistentDedupe.warmup(namespace, (error) => {
|
|
139
|
-
log?.(`feishu-dedup: warmup disk error: ${String(error)}`);
|
|
140
|
-
});
|
|
141
|
-
}
|
package/src/directory.static.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
listDirectoryGroupEntriesFromMapKeysAndAllowFrom,
|
|
3
|
-
listDirectoryUserEntriesFromAllowFromAndMapKeys,
|
|
4
|
-
} from "openclaw/plugin-sdk/directory-runtime";
|
|
5
|
-
import type { ClawdbotConfig } from "../runtime-api.js";
|
|
6
|
-
import { resolveFeishuAccount } from "./accounts.js";
|
|
7
|
-
import { normalizeFeishuTarget } from "./targets.js";
|
|
8
|
-
|
|
9
|
-
export type FeishuDirectoryPeer = {
|
|
10
|
-
kind: "user";
|
|
11
|
-
id: string;
|
|
12
|
-
name?: string;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export type FeishuDirectoryGroup = {
|
|
16
|
-
kind: "group";
|
|
17
|
-
id: string;
|
|
18
|
-
name?: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
function toFeishuDirectoryPeers(ids: string[]): FeishuDirectoryPeer[] {
|
|
22
|
-
return ids.map((id) => ({ kind: "user", id }));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function toFeishuDirectoryGroups(ids: string[]): FeishuDirectoryGroup[] {
|
|
26
|
-
return ids.map((id) => ({ kind: "group", id }));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export async function listFeishuDirectoryPeers(params: {
|
|
30
|
-
cfg: ClawdbotConfig;
|
|
31
|
-
query?: string;
|
|
32
|
-
limit?: number;
|
|
33
|
-
accountId?: string;
|
|
34
|
-
}): Promise<FeishuDirectoryPeer[]> {
|
|
35
|
-
const account = resolveFeishuAccount({ cfg: params.cfg, accountId: params.accountId });
|
|
36
|
-
const entries = listDirectoryUserEntriesFromAllowFromAndMapKeys({
|
|
37
|
-
allowFrom: account.config.allowFrom,
|
|
38
|
-
map: account.config.dms,
|
|
39
|
-
query: params.query,
|
|
40
|
-
limit: params.limit,
|
|
41
|
-
normalizeAllowFromId: (entry) => normalizeFeishuTarget(entry) ?? entry,
|
|
42
|
-
normalizeMapKeyId: (entry) => normalizeFeishuTarget(entry) ?? entry,
|
|
43
|
-
});
|
|
44
|
-
return toFeishuDirectoryPeers(entries.map((entry) => entry.id));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export async function listFeishuDirectoryGroups(params: {
|
|
48
|
-
cfg: ClawdbotConfig;
|
|
49
|
-
query?: string;
|
|
50
|
-
limit?: number;
|
|
51
|
-
accountId?: string;
|
|
52
|
-
}): Promise<FeishuDirectoryGroup[]> {
|
|
53
|
-
const account = resolveFeishuAccount({ cfg: params.cfg, accountId: params.accountId });
|
|
54
|
-
const entries = listDirectoryGroupEntriesFromMapKeysAndAllowFrom({
|
|
55
|
-
groups: account.config.groups,
|
|
56
|
-
allowFrom: account.config.groupAllowFrom,
|
|
57
|
-
query: params.query,
|
|
58
|
-
limit: params.limit,
|
|
59
|
-
});
|
|
60
|
-
return toFeishuDirectoryGroups(entries.map((entry) => entry.id));
|
|
61
|
-
}
|
package/src/directory.test.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { importFreshModule } from "openclaw/plugin-sdk/test-fixtures";
|
|
2
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import type { ClawdbotConfig } from "../runtime-api.js";
|
|
4
|
-
|
|
5
|
-
const createFeishuClientMock = vi.hoisted(() => vi.fn());
|
|
6
|
-
|
|
7
|
-
vi.mock("./client.js", () => ({
|
|
8
|
-
createFeishuClient: createFeishuClientMock,
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
const { listFeishuDirectoryGroupsLive, listFeishuDirectoryPeersLive } = await importFreshModule<
|
|
12
|
-
typeof import("./directory.js")
|
|
13
|
-
>(import.meta.url, "./directory.js?directory-test");
|
|
14
|
-
const { listFeishuDirectoryGroups, listFeishuDirectoryPeers } = await importFreshModule<
|
|
15
|
-
typeof import("./directory.static.js")
|
|
16
|
-
>(import.meta.url, "./directory.static.js?directory-test");
|
|
17
|
-
|
|
18
|
-
function makeStaticCfg(): ClawdbotConfig {
|
|
19
|
-
return {
|
|
20
|
-
channels: {
|
|
21
|
-
feishu: {
|
|
22
|
-
allowFrom: ["user:alice", "user:bob"],
|
|
23
|
-
dms: {
|
|
24
|
-
"user:carla": {},
|
|
25
|
-
},
|
|
26
|
-
groups: {
|
|
27
|
-
"chat-1": {},
|
|
28
|
-
},
|
|
29
|
-
groupAllowFrom: ["chat-2"],
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
} as ClawdbotConfig;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function makeConfiguredCfg(): ClawdbotConfig {
|
|
36
|
-
return {
|
|
37
|
-
channels: {
|
|
38
|
-
feishu: {
|
|
39
|
-
...makeStaticCfg().channels?.feishu,
|
|
40
|
-
appId: "cli_test_app_id",
|
|
41
|
-
appSecret: "cli_test_app_secret",
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
} as ClawdbotConfig;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
describe("feishu directory (config-backed)", () => {
|
|
48
|
-
beforeEach(() => {
|
|
49
|
-
createFeishuClientMock.mockReset();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("merges allowFrom + dms into peer entries", async () => {
|
|
53
|
-
const peers = await listFeishuDirectoryPeers({ cfg: makeStaticCfg(), query: "a" });
|
|
54
|
-
expect(peers).toEqual([
|
|
55
|
-
{ kind: "user", id: "alice" },
|
|
56
|
-
{ kind: "user", id: "carla" },
|
|
57
|
-
]);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("normalizes spaced provider-prefixed peer entries", async () => {
|
|
61
|
-
const cfg = {
|
|
62
|
-
channels: {
|
|
63
|
-
feishu: {
|
|
64
|
-
allowFrom: [" feishu:user:ou_alice "],
|
|
65
|
-
dms: {
|
|
66
|
-
" lark:dm:ou_carla ": {},
|
|
67
|
-
},
|
|
68
|
-
groups: {},
|
|
69
|
-
groupAllowFrom: [],
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
} as ClawdbotConfig;
|
|
73
|
-
|
|
74
|
-
const peers = await listFeishuDirectoryPeers({ cfg });
|
|
75
|
-
expect(peers).toEqual([
|
|
76
|
-
{ kind: "user", id: "ou_alice" },
|
|
77
|
-
{ kind: "user", id: "ou_carla" },
|
|
78
|
-
]);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("merges groups map + groupAllowFrom into group entries", async () => {
|
|
82
|
-
const groups = await listFeishuDirectoryGroups({ cfg: makeStaticCfg() });
|
|
83
|
-
expect(groups).toEqual([
|
|
84
|
-
{ kind: "group", id: "chat-1" },
|
|
85
|
-
{ kind: "group", id: "chat-2" },
|
|
86
|
-
]);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("falls back to static peers on live lookup failure by default", async () => {
|
|
90
|
-
createFeishuClientMock.mockReturnValueOnce({
|
|
91
|
-
contact: {
|
|
92
|
-
user: {
|
|
93
|
-
list: vi.fn(async () => {
|
|
94
|
-
throw new Error("token expired");
|
|
95
|
-
}),
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const peers = await listFeishuDirectoryPeersLive({ cfg: makeConfiguredCfg(), query: "a" });
|
|
101
|
-
expect(peers).toEqual([
|
|
102
|
-
{ kind: "user", id: "alice" },
|
|
103
|
-
{ kind: "user", id: "carla" },
|
|
104
|
-
]);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("surfaces live peer lookup failures when fallback is disabled", async () => {
|
|
108
|
-
createFeishuClientMock.mockReturnValueOnce({
|
|
109
|
-
contact: {
|
|
110
|
-
user: {
|
|
111
|
-
list: vi.fn(async () => {
|
|
112
|
-
throw new Error("token expired");
|
|
113
|
-
}),
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
await expect(
|
|
119
|
-
listFeishuDirectoryPeersLive({ cfg: makeConfiguredCfg(), fallbackToStatic: false }),
|
|
120
|
-
).rejects.toThrow("token expired");
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("surfaces live group lookup failures when fallback is disabled", async () => {
|
|
124
|
-
createFeishuClientMock.mockReturnValueOnce({
|
|
125
|
-
im: {
|
|
126
|
-
chat: {
|
|
127
|
-
list: vi.fn(async () => ({ code: 999, msg: "forbidden" })),
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
await expect(
|
|
133
|
-
listFeishuDirectoryGroupsLive({ cfg: makeConfiguredCfg(), fallbackToStatic: false }),
|
|
134
|
-
).rejects.toThrow("forbidden");
|
|
135
|
-
});
|
|
136
|
-
});
|
package/src/directory.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
|
|
2
|
-
import type { ClawdbotConfig } from "../runtime-api.js";
|
|
3
|
-
import { resolveFeishuAccount } from "./accounts.js";
|
|
4
|
-
import { createFeishuClient } from "./client.js";
|
|
5
|
-
import {
|
|
6
|
-
listFeishuDirectoryGroups,
|
|
7
|
-
listFeishuDirectoryPeers,
|
|
8
|
-
type FeishuDirectoryGroup,
|
|
9
|
-
type FeishuDirectoryPeer,
|
|
10
|
-
} from "./directory.static.js";
|
|
11
|
-
|
|
12
|
-
export async function listFeishuDirectoryPeersLive(params: {
|
|
13
|
-
cfg: ClawdbotConfig;
|
|
14
|
-
query?: string;
|
|
15
|
-
limit?: number;
|
|
16
|
-
accountId?: string;
|
|
17
|
-
fallbackToStatic?: boolean;
|
|
18
|
-
}): Promise<FeishuDirectoryPeer[]> {
|
|
19
|
-
const account = resolveFeishuAccount({ cfg: params.cfg, accountId: params.accountId });
|
|
20
|
-
if (!account.configured) {
|
|
21
|
-
return listFeishuDirectoryPeers(params);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const client = createFeishuClient(account);
|
|
26
|
-
const peers: FeishuDirectoryPeer[] = [];
|
|
27
|
-
const limit = params.limit ?? 50;
|
|
28
|
-
|
|
29
|
-
const response = await client.contact.user.list({
|
|
30
|
-
params: {
|
|
31
|
-
page_size: Math.min(limit, 50),
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
if (response.code !== 0) {
|
|
36
|
-
throw new Error(response.msg || `code ${response.code}`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const q = normalizeLowercaseStringOrEmpty(params.query);
|
|
40
|
-
for (const user of response.data?.items ?? []) {
|
|
41
|
-
if (user.open_id) {
|
|
42
|
-
const name = user.name || "";
|
|
43
|
-
if (
|
|
44
|
-
!q ||
|
|
45
|
-
normalizeLowercaseStringOrEmpty(user.open_id).includes(q) ||
|
|
46
|
-
normalizeLowercaseStringOrEmpty(name).includes(q)
|
|
47
|
-
) {
|
|
48
|
-
peers.push({
|
|
49
|
-
kind: "user",
|
|
50
|
-
id: user.open_id,
|
|
51
|
-
name: name || undefined,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (peers.length >= limit) {
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return peers;
|
|
61
|
-
} catch (err) {
|
|
62
|
-
if (params.fallbackToStatic === false) {
|
|
63
|
-
throw err instanceof Error ? err : new Error("Feishu live peer lookup failed");
|
|
64
|
-
}
|
|
65
|
-
return listFeishuDirectoryPeers(params);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export async function listFeishuDirectoryGroupsLive(params: {
|
|
70
|
-
cfg: ClawdbotConfig;
|
|
71
|
-
query?: string;
|
|
72
|
-
limit?: number;
|
|
73
|
-
accountId?: string;
|
|
74
|
-
fallbackToStatic?: boolean;
|
|
75
|
-
}): Promise<FeishuDirectoryGroup[]> {
|
|
76
|
-
const account = resolveFeishuAccount({ cfg: params.cfg, accountId: params.accountId });
|
|
77
|
-
if (!account.configured) {
|
|
78
|
-
return listFeishuDirectoryGroups(params);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
try {
|
|
82
|
-
const client = createFeishuClient(account);
|
|
83
|
-
const groups: FeishuDirectoryGroup[] = [];
|
|
84
|
-
const limit = params.limit ?? 50;
|
|
85
|
-
|
|
86
|
-
const response = await client.im.chat.list({
|
|
87
|
-
params: {
|
|
88
|
-
page_size: Math.min(limit, 100),
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
if (response.code !== 0) {
|
|
93
|
-
throw new Error(response.msg || `code ${response.code}`);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const q = normalizeLowercaseStringOrEmpty(params.query);
|
|
97
|
-
for (const chat of response.data?.items ?? []) {
|
|
98
|
-
if (chat.chat_id) {
|
|
99
|
-
const name = chat.name || "";
|
|
100
|
-
if (
|
|
101
|
-
!q ||
|
|
102
|
-
normalizeLowercaseStringOrEmpty(chat.chat_id).includes(q) ||
|
|
103
|
-
normalizeLowercaseStringOrEmpty(name).includes(q)
|
|
104
|
-
) {
|
|
105
|
-
groups.push({
|
|
106
|
-
kind: "group",
|
|
107
|
-
id: chat.chat_id,
|
|
108
|
-
name: name || undefined,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (groups.length >= limit) {
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return groups;
|
|
118
|
-
} catch (err) {
|
|
119
|
-
if (params.fallbackToStatic === false) {
|
|
120
|
-
throw err instanceof Error ? err : new Error("Feishu live group lookup failed");
|
|
121
|
-
}
|
|
122
|
-
return listFeishuDirectoryGroups(params);
|
|
123
|
-
}
|
|
124
|
-
}
|