@openclaw/feishu 2026.5.2 → 2026.5.3-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/thread-bindings.ts
DELETED
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
|
|
2
|
-
import {
|
|
3
|
-
resolveThreadBindingIdleTimeoutMsForChannel,
|
|
4
|
-
resolveThreadBindingMaxAgeMsForChannel,
|
|
5
|
-
registerSessionBindingAdapter,
|
|
6
|
-
resolveThreadBindingConversationIdFromBindingId,
|
|
7
|
-
unregisterSessionBindingAdapter,
|
|
8
|
-
type BindingTargetKind,
|
|
9
|
-
type SessionBindingAdapter,
|
|
10
|
-
type SessionBindingRecord,
|
|
11
|
-
} from "openclaw/plugin-sdk/conversation-runtime";
|
|
12
|
-
import { normalizeAccountId, resolveAgentIdFromSessionKey } from "openclaw/plugin-sdk/routing";
|
|
13
|
-
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
|
14
|
-
|
|
15
|
-
type FeishuBindingTargetKind = "subagent" | "acp";
|
|
16
|
-
|
|
17
|
-
type FeishuThreadBindingRecord = {
|
|
18
|
-
accountId: string;
|
|
19
|
-
conversationId: string;
|
|
20
|
-
parentConversationId?: string;
|
|
21
|
-
deliveryTo?: string;
|
|
22
|
-
deliveryThreadId?: string;
|
|
23
|
-
targetKind: FeishuBindingTargetKind;
|
|
24
|
-
targetSessionKey: string;
|
|
25
|
-
agentId?: string;
|
|
26
|
-
label?: string;
|
|
27
|
-
boundBy?: string;
|
|
28
|
-
boundAt: number;
|
|
29
|
-
lastActivityAt: number;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
type FeishuThreadBindingManager = {
|
|
33
|
-
accountId: string;
|
|
34
|
-
getByConversationId: (conversationId: string) => FeishuThreadBindingRecord | undefined;
|
|
35
|
-
listBySessionKey: (targetSessionKey: string) => FeishuThreadBindingRecord[];
|
|
36
|
-
bindConversation: (params: {
|
|
37
|
-
conversationId: string;
|
|
38
|
-
parentConversationId?: string;
|
|
39
|
-
targetKind: BindingTargetKind;
|
|
40
|
-
targetSessionKey: string;
|
|
41
|
-
metadata?: Record<string, unknown>;
|
|
42
|
-
}) => FeishuThreadBindingRecord | null;
|
|
43
|
-
touchConversation: (conversationId: string, at?: number) => FeishuThreadBindingRecord | null;
|
|
44
|
-
unbindConversation: (conversationId: string) => FeishuThreadBindingRecord | null;
|
|
45
|
-
unbindBySessionKey: (targetSessionKey: string) => FeishuThreadBindingRecord[];
|
|
46
|
-
stop: () => void;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
type FeishuThreadBindingsState = {
|
|
50
|
-
managersByAccountId: Map<string, FeishuThreadBindingManager>;
|
|
51
|
-
bindingsByAccountConversation: Map<string, FeishuThreadBindingRecord>;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const FEISHU_THREAD_BINDINGS_STATE_KEY = Symbol.for("openclaw.feishuThreadBindingsState");
|
|
55
|
-
let state: FeishuThreadBindingsState | undefined;
|
|
56
|
-
|
|
57
|
-
function getState(): FeishuThreadBindingsState {
|
|
58
|
-
if (!state) {
|
|
59
|
-
const globalStore = globalThis as Record<PropertyKey, unknown>;
|
|
60
|
-
state = (globalStore[FEISHU_THREAD_BINDINGS_STATE_KEY] as
|
|
61
|
-
| FeishuThreadBindingsState
|
|
62
|
-
| undefined) ?? {
|
|
63
|
-
managersByAccountId: new Map(),
|
|
64
|
-
bindingsByAccountConversation: new Map(),
|
|
65
|
-
};
|
|
66
|
-
globalStore[FEISHU_THREAD_BINDINGS_STATE_KEY] = state;
|
|
67
|
-
}
|
|
68
|
-
return state;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function resolveBindingKey(params: { accountId: string; conversationId: string }): string {
|
|
72
|
-
return `${params.accountId}:${params.conversationId}`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function toSessionBindingTargetKind(raw: FeishuBindingTargetKind): BindingTargetKind {
|
|
76
|
-
return raw === "subagent" ? "subagent" : "session";
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function toFeishuTargetKind(raw: BindingTargetKind): FeishuBindingTargetKind {
|
|
80
|
-
return raw === "subagent" ? "subagent" : "acp";
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function toSessionBindingRecord(
|
|
84
|
-
record: FeishuThreadBindingRecord,
|
|
85
|
-
defaults: { idleTimeoutMs: number; maxAgeMs: number },
|
|
86
|
-
): SessionBindingRecord {
|
|
87
|
-
const idleExpiresAt =
|
|
88
|
-
defaults.idleTimeoutMs > 0 ? record.lastActivityAt + defaults.idleTimeoutMs : undefined;
|
|
89
|
-
const maxAgeExpiresAt = defaults.maxAgeMs > 0 ? record.boundAt + defaults.maxAgeMs : undefined;
|
|
90
|
-
const expiresAt =
|
|
91
|
-
idleExpiresAt != null && maxAgeExpiresAt != null
|
|
92
|
-
? Math.min(idleExpiresAt, maxAgeExpiresAt)
|
|
93
|
-
: (idleExpiresAt ?? maxAgeExpiresAt);
|
|
94
|
-
return {
|
|
95
|
-
bindingId: resolveBindingKey({
|
|
96
|
-
accountId: record.accountId,
|
|
97
|
-
conversationId: record.conversationId,
|
|
98
|
-
}),
|
|
99
|
-
targetSessionKey: record.targetSessionKey,
|
|
100
|
-
targetKind: toSessionBindingTargetKind(record.targetKind),
|
|
101
|
-
conversation: {
|
|
102
|
-
channel: "feishu",
|
|
103
|
-
accountId: record.accountId,
|
|
104
|
-
conversationId: record.conversationId,
|
|
105
|
-
parentConversationId: record.parentConversationId,
|
|
106
|
-
},
|
|
107
|
-
status: "active",
|
|
108
|
-
boundAt: record.boundAt,
|
|
109
|
-
expiresAt,
|
|
110
|
-
metadata: {
|
|
111
|
-
agentId: record.agentId,
|
|
112
|
-
label: record.label,
|
|
113
|
-
boundBy: record.boundBy,
|
|
114
|
-
deliveryTo: record.deliveryTo,
|
|
115
|
-
deliveryThreadId: record.deliveryThreadId,
|
|
116
|
-
lastActivityAt: record.lastActivityAt,
|
|
117
|
-
idleTimeoutMs: defaults.idleTimeoutMs,
|
|
118
|
-
maxAgeMs: defaults.maxAgeMs,
|
|
119
|
-
},
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export function createFeishuThreadBindingManager(params: {
|
|
124
|
-
accountId?: string;
|
|
125
|
-
cfg: OpenClawConfig;
|
|
126
|
-
}): FeishuThreadBindingManager {
|
|
127
|
-
const accountId = normalizeAccountId(params.accountId);
|
|
128
|
-
const existing = getState().managersByAccountId.get(accountId);
|
|
129
|
-
if (existing) {
|
|
130
|
-
return existing;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const idleTimeoutMs = resolveThreadBindingIdleTimeoutMsForChannel({
|
|
134
|
-
cfg: params.cfg,
|
|
135
|
-
channel: "feishu",
|
|
136
|
-
accountId,
|
|
137
|
-
});
|
|
138
|
-
const maxAgeMs = resolveThreadBindingMaxAgeMsForChannel({
|
|
139
|
-
cfg: params.cfg,
|
|
140
|
-
channel: "feishu",
|
|
141
|
-
accountId,
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const manager: FeishuThreadBindingManager = {
|
|
145
|
-
accountId,
|
|
146
|
-
getByConversationId: (conversationId) =>
|
|
147
|
-
getState().bindingsByAccountConversation.get(
|
|
148
|
-
resolveBindingKey({ accountId, conversationId }),
|
|
149
|
-
),
|
|
150
|
-
listBySessionKey: (targetSessionKey) =>
|
|
151
|
-
[...getState().bindingsByAccountConversation.values()].filter(
|
|
152
|
-
(record) => record.accountId === accountId && record.targetSessionKey === targetSessionKey,
|
|
153
|
-
),
|
|
154
|
-
bindConversation: ({
|
|
155
|
-
conversationId,
|
|
156
|
-
parentConversationId,
|
|
157
|
-
targetKind,
|
|
158
|
-
targetSessionKey,
|
|
159
|
-
metadata,
|
|
160
|
-
}) => {
|
|
161
|
-
const normalizedConversationId = conversationId.trim();
|
|
162
|
-
const normalizedTargetSessionKey = targetSessionKey.trim();
|
|
163
|
-
if (!normalizedConversationId || !normalizedTargetSessionKey) {
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
const existing = getState().bindingsByAccountConversation.get(
|
|
167
|
-
resolveBindingKey({ accountId, conversationId: normalizedConversationId }),
|
|
168
|
-
);
|
|
169
|
-
const now = Date.now();
|
|
170
|
-
const record: FeishuThreadBindingRecord = {
|
|
171
|
-
accountId,
|
|
172
|
-
conversationId: normalizedConversationId,
|
|
173
|
-
parentConversationId:
|
|
174
|
-
normalizeOptionalString(parentConversationId) ?? existing?.parentConversationId,
|
|
175
|
-
deliveryTo:
|
|
176
|
-
typeof metadata?.deliveryTo === "string" && metadata.deliveryTo.trim()
|
|
177
|
-
? metadata.deliveryTo.trim()
|
|
178
|
-
: existing?.deliveryTo,
|
|
179
|
-
deliveryThreadId:
|
|
180
|
-
typeof metadata?.deliveryThreadId === "string" && metadata.deliveryThreadId.trim()
|
|
181
|
-
? metadata.deliveryThreadId.trim()
|
|
182
|
-
: existing?.deliveryThreadId,
|
|
183
|
-
targetKind: toFeishuTargetKind(targetKind),
|
|
184
|
-
targetSessionKey: normalizedTargetSessionKey,
|
|
185
|
-
agentId:
|
|
186
|
-
typeof metadata?.agentId === "string" && metadata.agentId.trim()
|
|
187
|
-
? metadata.agentId.trim()
|
|
188
|
-
: (existing?.agentId ?? resolveAgentIdFromSessionKey(normalizedTargetSessionKey)),
|
|
189
|
-
label:
|
|
190
|
-
typeof metadata?.label === "string" && metadata.label.trim()
|
|
191
|
-
? metadata.label.trim()
|
|
192
|
-
: existing?.label,
|
|
193
|
-
boundBy:
|
|
194
|
-
typeof metadata?.boundBy === "string" && metadata.boundBy.trim()
|
|
195
|
-
? metadata.boundBy.trim()
|
|
196
|
-
: existing?.boundBy,
|
|
197
|
-
boundAt: now,
|
|
198
|
-
lastActivityAt: now,
|
|
199
|
-
};
|
|
200
|
-
getState().bindingsByAccountConversation.set(
|
|
201
|
-
resolveBindingKey({ accountId, conversationId: normalizedConversationId }),
|
|
202
|
-
record,
|
|
203
|
-
);
|
|
204
|
-
return record;
|
|
205
|
-
},
|
|
206
|
-
touchConversation: (conversationId, at = Date.now()) => {
|
|
207
|
-
const key = resolveBindingKey({ accountId, conversationId });
|
|
208
|
-
const existingRecord = getState().bindingsByAccountConversation.get(key);
|
|
209
|
-
if (!existingRecord) {
|
|
210
|
-
return null;
|
|
211
|
-
}
|
|
212
|
-
const updated = { ...existingRecord, lastActivityAt: at };
|
|
213
|
-
getState().bindingsByAccountConversation.set(key, updated);
|
|
214
|
-
return updated;
|
|
215
|
-
},
|
|
216
|
-
unbindConversation: (conversationId) => {
|
|
217
|
-
const key = resolveBindingKey({ accountId, conversationId });
|
|
218
|
-
const existingRecord = getState().bindingsByAccountConversation.get(key);
|
|
219
|
-
if (!existingRecord) {
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
getState().bindingsByAccountConversation.delete(key);
|
|
223
|
-
return existingRecord;
|
|
224
|
-
},
|
|
225
|
-
unbindBySessionKey: (targetSessionKey) => {
|
|
226
|
-
const removed: FeishuThreadBindingRecord[] = [];
|
|
227
|
-
for (const record of getState().bindingsByAccountConversation.values()) {
|
|
228
|
-
if (record.accountId !== accountId || record.targetSessionKey !== targetSessionKey) {
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
getState().bindingsByAccountConversation.delete(
|
|
232
|
-
resolveBindingKey({ accountId, conversationId: record.conversationId }),
|
|
233
|
-
);
|
|
234
|
-
removed.push(record);
|
|
235
|
-
}
|
|
236
|
-
return removed;
|
|
237
|
-
},
|
|
238
|
-
stop: () => {
|
|
239
|
-
for (const key of getState().bindingsByAccountConversation.keys()) {
|
|
240
|
-
if (key.startsWith(`${accountId}:`)) {
|
|
241
|
-
getState().bindingsByAccountConversation.delete(key);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
getState().managersByAccountId.delete(accountId);
|
|
245
|
-
unregisterSessionBindingAdapter({
|
|
246
|
-
channel: "feishu",
|
|
247
|
-
accountId,
|
|
248
|
-
adapter: sessionBindingAdapter,
|
|
249
|
-
});
|
|
250
|
-
},
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
const sessionBindingAdapter: SessionBindingAdapter = {
|
|
254
|
-
channel: "feishu",
|
|
255
|
-
accountId,
|
|
256
|
-
capabilities: {
|
|
257
|
-
placements: ["current"],
|
|
258
|
-
},
|
|
259
|
-
bind: async (input) => {
|
|
260
|
-
if (input.conversation.channel !== "feishu" || input.placement === "child") {
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
const bound = manager.bindConversation({
|
|
264
|
-
conversationId: input.conversation.conversationId,
|
|
265
|
-
parentConversationId: input.conversation.parentConversationId,
|
|
266
|
-
targetKind: input.targetKind,
|
|
267
|
-
targetSessionKey: input.targetSessionKey,
|
|
268
|
-
metadata: input.metadata,
|
|
269
|
-
});
|
|
270
|
-
return bound ? toSessionBindingRecord(bound, { idleTimeoutMs, maxAgeMs }) : null;
|
|
271
|
-
},
|
|
272
|
-
listBySession: (targetSessionKey) =>
|
|
273
|
-
manager
|
|
274
|
-
.listBySessionKey(targetSessionKey)
|
|
275
|
-
.map((entry) => toSessionBindingRecord(entry, { idleTimeoutMs, maxAgeMs })),
|
|
276
|
-
resolveByConversation: (ref) => {
|
|
277
|
-
if (ref.channel !== "feishu") {
|
|
278
|
-
return null;
|
|
279
|
-
}
|
|
280
|
-
const found = manager.getByConversationId(ref.conversationId);
|
|
281
|
-
return found ? toSessionBindingRecord(found, { idleTimeoutMs, maxAgeMs }) : null;
|
|
282
|
-
},
|
|
283
|
-
touch: (bindingId, at) => {
|
|
284
|
-
const conversationId = resolveThreadBindingConversationIdFromBindingId({
|
|
285
|
-
accountId,
|
|
286
|
-
bindingId,
|
|
287
|
-
});
|
|
288
|
-
if (conversationId) {
|
|
289
|
-
manager.touchConversation(conversationId, at);
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
unbind: async (input) => {
|
|
293
|
-
if (input.targetSessionKey?.trim()) {
|
|
294
|
-
return manager
|
|
295
|
-
.unbindBySessionKey(input.targetSessionKey.trim())
|
|
296
|
-
.map((entry) => toSessionBindingRecord(entry, { idleTimeoutMs, maxAgeMs }));
|
|
297
|
-
}
|
|
298
|
-
const conversationId = resolveThreadBindingConversationIdFromBindingId({
|
|
299
|
-
accountId,
|
|
300
|
-
bindingId: input.bindingId,
|
|
301
|
-
});
|
|
302
|
-
if (!conversationId) {
|
|
303
|
-
return [];
|
|
304
|
-
}
|
|
305
|
-
const removed = manager.unbindConversation(conversationId);
|
|
306
|
-
return removed ? [toSessionBindingRecord(removed, { idleTimeoutMs, maxAgeMs })] : [];
|
|
307
|
-
},
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
registerSessionBindingAdapter(sessionBindingAdapter);
|
|
311
|
-
|
|
312
|
-
getState().managersByAccountId.set(accountId, manager);
|
|
313
|
-
return manager;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
export function getFeishuThreadBindingManager(
|
|
317
|
-
accountId?: string,
|
|
318
|
-
): FeishuThreadBindingManager | null {
|
|
319
|
-
return getState().managersByAccountId.get(normalizeAccountId(accountId)) ?? null;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
export const __testing = {
|
|
323
|
-
resetFeishuThreadBindingsForTests() {
|
|
324
|
-
for (const manager of getState().managersByAccountId.values()) {
|
|
325
|
-
manager.stop();
|
|
326
|
-
}
|
|
327
|
-
getState().managersByAccountId.clear();
|
|
328
|
-
getState().bindingsByAccountConversation.clear();
|
|
329
|
-
},
|
|
330
|
-
};
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { beforeAll, beforeEach, describe, expect, test, vi } from "vitest";
|
|
2
|
-
import type { OpenClawPluginApi } from "../runtime-api.js";
|
|
3
|
-
import { createToolFactoryHarness } from "./tool-factory-test-harness.js";
|
|
4
|
-
|
|
5
|
-
const createFeishuClientMock = vi.fn((account: { appId?: string } | undefined) => ({
|
|
6
|
-
__appId: account?.appId,
|
|
7
|
-
}));
|
|
8
|
-
|
|
9
|
-
vi.mock("./client.js", () => ({
|
|
10
|
-
createFeishuClient: (account: { appId?: string } | undefined) => createFeishuClientMock(account),
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
let registerFeishuBitableTools: typeof import("./bitable.js").registerFeishuBitableTools;
|
|
14
|
-
let registerFeishuDriveTools: typeof import("./drive.js").registerFeishuDriveTools;
|
|
15
|
-
let registerFeishuPermTools: typeof import("./perm.js").registerFeishuPermTools;
|
|
16
|
-
let registerFeishuWikiTools: typeof import("./wiki.js").registerFeishuWikiTools;
|
|
17
|
-
|
|
18
|
-
function createConfig(params: {
|
|
19
|
-
toolsA?: {
|
|
20
|
-
wiki?: boolean;
|
|
21
|
-
drive?: boolean;
|
|
22
|
-
perm?: boolean;
|
|
23
|
-
};
|
|
24
|
-
toolsB?: {
|
|
25
|
-
wiki?: boolean;
|
|
26
|
-
drive?: boolean;
|
|
27
|
-
perm?: boolean;
|
|
28
|
-
};
|
|
29
|
-
defaultAccount?: string;
|
|
30
|
-
}): OpenClawPluginApi["config"] {
|
|
31
|
-
return {
|
|
32
|
-
channels: {
|
|
33
|
-
feishu: {
|
|
34
|
-
enabled: true,
|
|
35
|
-
defaultAccount: params.defaultAccount,
|
|
36
|
-
accounts: {
|
|
37
|
-
a: {
|
|
38
|
-
appId: "app-a",
|
|
39
|
-
appSecret: "sec-a", // pragma: allowlist secret
|
|
40
|
-
tools: params.toolsA,
|
|
41
|
-
},
|
|
42
|
-
b: {
|
|
43
|
-
appId: "app-b",
|
|
44
|
-
appSecret: "sec-b", // pragma: allowlist secret
|
|
45
|
-
tools: params.toolsB,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
} as OpenClawPluginApi["config"];
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
describe("feishu tool account routing", () => {
|
|
54
|
-
beforeAll(async () => {
|
|
55
|
-
({ registerFeishuBitableTools, registerFeishuDriveTools, registerFeishuPermTools } =
|
|
56
|
-
await import("./bitable.js").then(async ({ registerFeishuBitableTools }) => ({
|
|
57
|
-
registerFeishuBitableTools,
|
|
58
|
-
...(await import("./drive.js")),
|
|
59
|
-
...(await import("./perm.js")),
|
|
60
|
-
...(await import("./wiki.js")),
|
|
61
|
-
})));
|
|
62
|
-
({ registerFeishuWikiTools } = await import("./wiki.js"));
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
beforeEach(() => {
|
|
66
|
-
vi.clearAllMocks();
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test("wiki tool registers when first account disables it and routes to agentAccountId", async () => {
|
|
70
|
-
const { api, resolveTool } = createToolFactoryHarness(
|
|
71
|
-
createConfig({
|
|
72
|
-
toolsA: { wiki: false },
|
|
73
|
-
toolsB: { wiki: true },
|
|
74
|
-
}),
|
|
75
|
-
);
|
|
76
|
-
registerFeishuWikiTools(api);
|
|
77
|
-
|
|
78
|
-
const tool = resolveTool("feishu_wiki", { agentAccountId: "b" });
|
|
79
|
-
await tool.execute("call", { action: "search" });
|
|
80
|
-
|
|
81
|
-
expect(createFeishuClientMock.mock.calls.at(-1)?.[0]?.appId).toBe("app-b");
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test("wiki tool prefers the active contextual account over configured defaultAccount", async () => {
|
|
85
|
-
const { api, resolveTool } = createToolFactoryHarness(
|
|
86
|
-
createConfig({
|
|
87
|
-
defaultAccount: "b",
|
|
88
|
-
toolsA: { wiki: true },
|
|
89
|
-
toolsB: { wiki: true },
|
|
90
|
-
}),
|
|
91
|
-
);
|
|
92
|
-
registerFeishuWikiTools(api);
|
|
93
|
-
|
|
94
|
-
const tool = resolveTool("feishu_wiki", { agentAccountId: "a" });
|
|
95
|
-
await tool.execute("call", { action: "search" });
|
|
96
|
-
|
|
97
|
-
expect(createFeishuClientMock.mock.calls.at(-1)?.[0]?.appId).toBe("app-a");
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test("drive tool registers when first account disables it and routes to agentAccountId", async () => {
|
|
101
|
-
const { api, resolveTool } = createToolFactoryHarness(
|
|
102
|
-
createConfig({
|
|
103
|
-
toolsA: { drive: false },
|
|
104
|
-
toolsB: { drive: true },
|
|
105
|
-
}),
|
|
106
|
-
);
|
|
107
|
-
registerFeishuDriveTools(api);
|
|
108
|
-
|
|
109
|
-
const tool = resolveTool("feishu_drive", { agentAccountId: "b" });
|
|
110
|
-
await tool.execute("call", { action: "unknown_action" });
|
|
111
|
-
|
|
112
|
-
expect(createFeishuClientMock.mock.calls.at(-1)?.[0]?.appId).toBe("app-b");
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test("perm tool registers when only second account enables it and routes to agentAccountId", async () => {
|
|
116
|
-
const { api, resolveTool } = createToolFactoryHarness(
|
|
117
|
-
createConfig({
|
|
118
|
-
toolsA: { perm: false },
|
|
119
|
-
toolsB: { perm: true },
|
|
120
|
-
}),
|
|
121
|
-
);
|
|
122
|
-
registerFeishuPermTools(api);
|
|
123
|
-
|
|
124
|
-
const tool = resolveTool("feishu_perm", { agentAccountId: "b" });
|
|
125
|
-
await tool.execute("call", { action: "unknown_action" });
|
|
126
|
-
|
|
127
|
-
expect(createFeishuClientMock.mock.calls.at(-1)?.[0]?.appId).toBe("app-b");
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test("bitable tool routes to agentAccountId and allows explicit accountId override", async () => {
|
|
131
|
-
const { api, resolveTool } = createToolFactoryHarness(createConfig({}));
|
|
132
|
-
registerFeishuBitableTools(api);
|
|
133
|
-
|
|
134
|
-
const tool = resolveTool("feishu_bitable_get_meta", { agentAccountId: "b" });
|
|
135
|
-
await tool.execute("call-ctx", { url: "invalid-url" });
|
|
136
|
-
await tool.execute("call-override", { url: "invalid-url", accountId: "a" });
|
|
137
|
-
|
|
138
|
-
expect(createFeishuClientMock.mock.calls[0]?.[0]?.appId).toBe("app-b");
|
|
139
|
-
expect(createFeishuClientMock.mock.calls[1]?.[0]?.appId).toBe("app-a");
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test("falls back to the configured Feishu default selection when agentAccountId is not a real account", async () => {
|
|
143
|
-
const { api, resolveTool } = createToolFactoryHarness(
|
|
144
|
-
createConfig({
|
|
145
|
-
toolsA: { wiki: true },
|
|
146
|
-
toolsB: { wiki: true },
|
|
147
|
-
}),
|
|
148
|
-
);
|
|
149
|
-
registerFeishuWikiTools(api);
|
|
150
|
-
|
|
151
|
-
const tool = resolveTool("feishu_wiki", { agentAccountId: "agent-spawner" });
|
|
152
|
-
await tool.execute("call", { action: "search" });
|
|
153
|
-
|
|
154
|
-
expect(createFeishuClientMock.mock.calls.at(-1)?.[0]?.appId).toBe("app-a");
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test("does not silently fall back when the contextual account is real but uses non-env SecretRefs", async () => {
|
|
158
|
-
const { api, resolveTool } = createToolFactoryHarness({
|
|
159
|
-
channels: {
|
|
160
|
-
feishu: {
|
|
161
|
-
enabled: true,
|
|
162
|
-
accounts: {
|
|
163
|
-
a: {
|
|
164
|
-
appId: "app-a",
|
|
165
|
-
appSecret: "sec-a", // pragma: allowlist secret
|
|
166
|
-
tools: { wiki: true },
|
|
167
|
-
},
|
|
168
|
-
b: {
|
|
169
|
-
appId: "app-b",
|
|
170
|
-
appSecret: { source: "file", provider: "default", id: "feishu/b-secret" },
|
|
171
|
-
tools: { wiki: true },
|
|
172
|
-
} as never,
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
} as OpenClawPluginApi["config"]);
|
|
177
|
-
registerFeishuWikiTools(api);
|
|
178
|
-
|
|
179
|
-
const tool = resolveTool("feishu_wiki", { agentAccountId: "b" });
|
|
180
|
-
const result = await tool.execute("call", { action: "search" });
|
|
181
|
-
|
|
182
|
-
expect(createFeishuClientMock).not.toHaveBeenCalled();
|
|
183
|
-
expect(typeof result.details.error === "string" ? result.details.error : "").toContain(
|
|
184
|
-
"Resolve this command against an active gateway runtime snapshot before reading it.",
|
|
185
|
-
);
|
|
186
|
-
});
|
|
187
|
-
});
|
package/src/tool-account.test.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { resolveFeishuToolAccount } from "./tool-account.js";
|
|
3
|
-
|
|
4
|
-
describe("resolveFeishuToolAccount", () => {
|
|
5
|
-
const cfg = {
|
|
6
|
-
channels: {
|
|
7
|
-
feishu: {
|
|
8
|
-
enabled: true,
|
|
9
|
-
defaultAccount: "ops",
|
|
10
|
-
appId: "base-app-id",
|
|
11
|
-
appSecret: "base-app-secret", // pragma: allowlist secret
|
|
12
|
-
accounts: {
|
|
13
|
-
ops: {
|
|
14
|
-
enabled: true,
|
|
15
|
-
appId: "ops-app-id",
|
|
16
|
-
appSecret: "ops-app-secret", // pragma: allowlist secret
|
|
17
|
-
},
|
|
18
|
-
work: {
|
|
19
|
-
enabled: true,
|
|
20
|
-
appId: "work-app-id",
|
|
21
|
-
appSecret: "work-app-secret", // pragma: allowlist secret
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
it("prefers the active contextual account over configured defaultAccount", () => {
|
|
29
|
-
const resolved = resolveFeishuToolAccount({
|
|
30
|
-
api: { config: cfg },
|
|
31
|
-
defaultAccountId: "work",
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
expect(resolved.accountId).toBe("work");
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("falls back to configured defaultAccount when there is no contextual account", () => {
|
|
38
|
-
const resolved = resolveFeishuToolAccount({
|
|
39
|
-
api: { config: cfg },
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
expect(resolved.accountId).toBe("ops");
|
|
43
|
-
});
|
|
44
|
-
});
|
package/src/tool-account.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import type * as Lark from "@larksuiteoapi/node-sdk";
|
|
2
|
-
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
|
3
|
-
import type { OpenClawPluginApi } from "../runtime-api.js";
|
|
4
|
-
import {
|
|
5
|
-
listFeishuAccountIds,
|
|
6
|
-
resolveFeishuAccount,
|
|
7
|
-
resolveFeishuRuntimeAccount,
|
|
8
|
-
} from "./accounts.js";
|
|
9
|
-
import { createFeishuClient } from "./client.js";
|
|
10
|
-
import { resolveToolsConfig } from "./tools-config.js";
|
|
11
|
-
import type { FeishuToolsConfig, ResolvedFeishuAccount } from "./types.js";
|
|
12
|
-
|
|
13
|
-
type AccountAwareParams = { accountId?: string };
|
|
14
|
-
|
|
15
|
-
function resolveImplicitToolAccountId(params: {
|
|
16
|
-
api: Pick<OpenClawPluginApi, "config">;
|
|
17
|
-
executeParams?: AccountAwareParams;
|
|
18
|
-
defaultAccountId?: string;
|
|
19
|
-
}): string | undefined {
|
|
20
|
-
const explicitAccountId = normalizeOptionalString(params.executeParams?.accountId);
|
|
21
|
-
if (explicitAccountId) {
|
|
22
|
-
return explicitAccountId;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const contextualAccountId = normalizeOptionalString(params.defaultAccountId);
|
|
26
|
-
if (
|
|
27
|
-
contextualAccountId &&
|
|
28
|
-
listFeishuAccountIds(params.api.config).includes(contextualAccountId)
|
|
29
|
-
) {
|
|
30
|
-
const contextualAccount = resolveFeishuAccount({
|
|
31
|
-
cfg: params.api.config,
|
|
32
|
-
accountId: contextualAccountId,
|
|
33
|
-
});
|
|
34
|
-
if (contextualAccount.enabled) {
|
|
35
|
-
return contextualAccountId;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const configuredDefaultAccountId = normalizeOptionalString(
|
|
40
|
-
(params.api.config?.channels?.feishu as { defaultAccount?: unknown } | undefined)
|
|
41
|
-
?.defaultAccount,
|
|
42
|
-
);
|
|
43
|
-
if (configuredDefaultAccountId) {
|
|
44
|
-
return configuredDefaultAccountId;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function resolveFeishuToolAccount(params: {
|
|
51
|
-
api: Pick<OpenClawPluginApi, "config">;
|
|
52
|
-
executeParams?: AccountAwareParams;
|
|
53
|
-
defaultAccountId?: string;
|
|
54
|
-
}): ResolvedFeishuAccount {
|
|
55
|
-
if (!params.api.config) {
|
|
56
|
-
throw new Error("Feishu config unavailable");
|
|
57
|
-
}
|
|
58
|
-
return resolveFeishuRuntimeAccount({
|
|
59
|
-
cfg: params.api.config,
|
|
60
|
-
accountId: resolveImplicitToolAccountId(params),
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function createFeishuToolClient(params: {
|
|
65
|
-
api: Pick<OpenClawPluginApi, "config">;
|
|
66
|
-
executeParams?: AccountAwareParams;
|
|
67
|
-
defaultAccountId?: string;
|
|
68
|
-
}): Lark.Client {
|
|
69
|
-
return createFeishuClient(resolveFeishuToolAccount(params));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function resolveAnyEnabledFeishuToolsConfig(
|
|
73
|
-
accounts: ResolvedFeishuAccount[],
|
|
74
|
-
): Required<FeishuToolsConfig> {
|
|
75
|
-
const merged: Required<FeishuToolsConfig> = {
|
|
76
|
-
doc: false,
|
|
77
|
-
chat: false,
|
|
78
|
-
wiki: false,
|
|
79
|
-
drive: false,
|
|
80
|
-
perm: false,
|
|
81
|
-
scopes: false,
|
|
82
|
-
};
|
|
83
|
-
for (const account of accounts) {
|
|
84
|
-
const cfg = resolveToolsConfig(account.config.tools);
|
|
85
|
-
merged.doc = merged.doc || cfg.doc;
|
|
86
|
-
merged.chat = merged.chat || cfg.chat;
|
|
87
|
-
merged.wiki = merged.wiki || cfg.wiki;
|
|
88
|
-
merged.drive = merged.drive || cfg.drive;
|
|
89
|
-
merged.perm = merged.perm || cfg.perm;
|
|
90
|
-
merged.scopes = merged.scopes || cfg.scopes;
|
|
91
|
-
}
|
|
92
|
-
return merged;
|
|
93
|
-
}
|