@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/client.ts
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import type { Agent } from "node:https";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import * as Lark from "@larksuiteoapi/node-sdk";
|
|
4
|
-
import {
|
|
5
|
-
readPluginPackageVersion,
|
|
6
|
-
resolveAmbientNodeProxyAgent,
|
|
7
|
-
} from "openclaw/plugin-sdk/extension-shared";
|
|
8
|
-
import type { FeishuConfig, FeishuDomain, ResolvedFeishuAccount } from "./types.js";
|
|
9
|
-
|
|
10
|
-
const require = createRequire(import.meta.url);
|
|
11
|
-
const pluginVersion = readPluginPackageVersion({ require });
|
|
12
|
-
|
|
13
|
-
export { pluginVersion };
|
|
14
|
-
|
|
15
|
-
const FEISHU_USER_AGENT = `openclaw-feishu-builtin/${pluginVersion}/${process.platform}`;
|
|
16
|
-
export { FEISHU_USER_AGENT };
|
|
17
|
-
|
|
18
|
-
const FEISHU_WS_CONFIG = {
|
|
19
|
-
PingInterval: 30,
|
|
20
|
-
PingTimeout: 3,
|
|
21
|
-
} as const;
|
|
22
|
-
|
|
23
|
-
/** User-Agent header value for all Feishu API requests. */
|
|
24
|
-
export function getFeishuUserAgent(): string {
|
|
25
|
-
return FEISHU_USER_AGENT;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
type FeishuClientSdk = Pick<
|
|
29
|
-
typeof Lark,
|
|
30
|
-
| "AppType"
|
|
31
|
-
| "Client"
|
|
32
|
-
| "defaultHttpInstance"
|
|
33
|
-
| "Domain"
|
|
34
|
-
| "EventDispatcher"
|
|
35
|
-
| "LoggerLevel"
|
|
36
|
-
| "WSClient"
|
|
37
|
-
>;
|
|
38
|
-
|
|
39
|
-
const defaultFeishuClientSdk: FeishuClientSdk = {
|
|
40
|
-
AppType: Lark.AppType,
|
|
41
|
-
Client: Lark.Client,
|
|
42
|
-
defaultHttpInstance: Lark.defaultHttpInstance,
|
|
43
|
-
Domain: Lark.Domain,
|
|
44
|
-
EventDispatcher: Lark.EventDispatcher,
|
|
45
|
-
LoggerLevel: Lark.LoggerLevel,
|
|
46
|
-
WSClient: Lark.WSClient,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
let feishuClientSdk: FeishuClientSdk = defaultFeishuClientSdk;
|
|
50
|
-
|
|
51
|
-
// Override the SDK's default User-Agent interceptor.
|
|
52
|
-
// The Lark SDK registers an axios request interceptor that sets
|
|
53
|
-
// 'oapi-node-sdk/1.0.0'. Axios request interceptors execute in LIFO order
|
|
54
|
-
// (last-registered runs first), so simply appending ours doesn't work — the
|
|
55
|
-
// SDK's interceptor would run last and overwrite our UA. We must clear
|
|
56
|
-
// handlers[] first, then register our own as the sole interceptor.
|
|
57
|
-
//
|
|
58
|
-
// Risk is low: the SDK only registers one interceptor (UA) at init time, and
|
|
59
|
-
// we clear it at module load before any other code can register handlers.
|
|
60
|
-
// If a future SDK version adds more interceptors, the upgrade will need
|
|
61
|
-
// compatibility verification regardless.
|
|
62
|
-
{
|
|
63
|
-
const inst = Lark.defaultHttpInstance as {
|
|
64
|
-
interceptors?: {
|
|
65
|
-
request: { handlers: unknown[]; use: (fn: (req: unknown) => unknown) => void };
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
if (inst.interceptors?.request) {
|
|
69
|
-
inst.interceptors.request.handlers = [];
|
|
70
|
-
inst.interceptors.request.use((req: unknown) => {
|
|
71
|
-
const r = req as { headers?: Record<string, string> };
|
|
72
|
-
if (r.headers) {
|
|
73
|
-
r.headers["User-Agent"] = getFeishuUserAgent();
|
|
74
|
-
}
|
|
75
|
-
return req;
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** Default HTTP timeout for Feishu API requests (30 seconds). */
|
|
81
|
-
export const FEISHU_HTTP_TIMEOUT_MS = 30_000;
|
|
82
|
-
export const FEISHU_HTTP_TIMEOUT_MAX_MS = 300_000;
|
|
83
|
-
export const FEISHU_HTTP_TIMEOUT_ENV_VAR = "OPENCLAW_FEISHU_HTTP_TIMEOUT_MS";
|
|
84
|
-
|
|
85
|
-
type FeishuHttpInstanceLike = Pick<
|
|
86
|
-
typeof feishuClientSdk.defaultHttpInstance,
|
|
87
|
-
"request" | "get" | "post" | "put" | "patch" | "delete" | "head" | "options"
|
|
88
|
-
>;
|
|
89
|
-
|
|
90
|
-
async function getWsProxyAgent() {
|
|
91
|
-
return resolveAmbientNodeProxyAgent<Agent>();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Multi-account client cache
|
|
95
|
-
const clientCache = new Map<
|
|
96
|
-
string,
|
|
97
|
-
{
|
|
98
|
-
client: Lark.Client;
|
|
99
|
-
config: { appId: string; appSecret: string; domain?: FeishuDomain; httpTimeoutMs: number };
|
|
100
|
-
}
|
|
101
|
-
>();
|
|
102
|
-
|
|
103
|
-
function resolveDomain(domain: FeishuDomain | undefined): Lark.Domain | string {
|
|
104
|
-
if (domain === "lark") {
|
|
105
|
-
return feishuClientSdk.Domain.Lark;
|
|
106
|
-
}
|
|
107
|
-
if (domain === "feishu" || !domain) {
|
|
108
|
-
return feishuClientSdk.Domain.Feishu;
|
|
109
|
-
}
|
|
110
|
-
return domain.replace(/\/+$/, ""); // Custom URL for private deployment
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Create an HTTP instance that delegates to the Lark SDK's default instance
|
|
115
|
-
* but injects a default request timeout and User-Agent header to prevent
|
|
116
|
-
* indefinite hangs and set a standardized User-Agent per OAPI best practices.
|
|
117
|
-
*/
|
|
118
|
-
function createTimeoutHttpInstance(defaultTimeoutMs: number): Lark.HttpInstance {
|
|
119
|
-
const base: FeishuHttpInstanceLike = feishuClientSdk.defaultHttpInstance;
|
|
120
|
-
|
|
121
|
-
function injectTimeout<D>(opts?: Lark.HttpRequestOptions<D>): Lark.HttpRequestOptions<D> {
|
|
122
|
-
return { timeout: defaultTimeoutMs, ...opts } as Lark.HttpRequestOptions<D>;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
request: (opts) => base.request(injectTimeout(opts)),
|
|
127
|
-
get: (url, opts) => base.get(url, injectTimeout(opts)),
|
|
128
|
-
post: (url, data, opts) => base.post(url, data, injectTimeout(opts)),
|
|
129
|
-
put: (url, data, opts) => base.put(url, data, injectTimeout(opts)),
|
|
130
|
-
patch: (url, data, opts) => base.patch(url, data, injectTimeout(opts)),
|
|
131
|
-
delete: (url, opts) => base.delete(url, injectTimeout(opts)),
|
|
132
|
-
head: (url, opts) => base.head(url, injectTimeout(opts)),
|
|
133
|
-
options: (url, opts) => base.options(url, injectTimeout(opts)),
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Credentials needed to create a Feishu client.
|
|
139
|
-
* Both FeishuConfig and ResolvedFeishuAccount satisfy this interface.
|
|
140
|
-
*/
|
|
141
|
-
export type FeishuClientCredentials = {
|
|
142
|
-
accountId?: string;
|
|
143
|
-
appId?: string;
|
|
144
|
-
appSecret?: string;
|
|
145
|
-
domain?: FeishuDomain;
|
|
146
|
-
httpTimeoutMs?: number;
|
|
147
|
-
config?: Pick<FeishuConfig, "httpTimeoutMs">;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
function resolveConfiguredHttpTimeoutMs(creds: FeishuClientCredentials): number {
|
|
151
|
-
const clampTimeout = (value: number): number => {
|
|
152
|
-
const rounded = Math.floor(value);
|
|
153
|
-
return Math.min(Math.max(rounded, 1), FEISHU_HTTP_TIMEOUT_MAX_MS);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const fromDirectField = creds.httpTimeoutMs;
|
|
157
|
-
if (
|
|
158
|
-
typeof fromDirectField === "number" &&
|
|
159
|
-
Number.isFinite(fromDirectField) &&
|
|
160
|
-
fromDirectField > 0
|
|
161
|
-
) {
|
|
162
|
-
return clampTimeout(fromDirectField);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const envRaw = process.env[FEISHU_HTTP_TIMEOUT_ENV_VAR];
|
|
166
|
-
if (envRaw) {
|
|
167
|
-
const envValue = Number(envRaw);
|
|
168
|
-
if (Number.isFinite(envValue) && envValue > 0) {
|
|
169
|
-
return clampTimeout(envValue);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const fromConfig = creds.config?.httpTimeoutMs;
|
|
174
|
-
const timeout = fromConfig;
|
|
175
|
-
if (typeof timeout !== "number" || !Number.isFinite(timeout) || timeout <= 0) {
|
|
176
|
-
return FEISHU_HTTP_TIMEOUT_MS;
|
|
177
|
-
}
|
|
178
|
-
return clampTimeout(timeout);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Create or get a cached Feishu client for an account.
|
|
183
|
-
* Accepts any object with appId, appSecret, and optional domain/accountId.
|
|
184
|
-
*/
|
|
185
|
-
export function createFeishuClient(creds: FeishuClientCredentials): Lark.Client {
|
|
186
|
-
const { accountId = "default", appId, appSecret, domain } = creds;
|
|
187
|
-
const defaultHttpTimeoutMs = resolveConfiguredHttpTimeoutMs(creds);
|
|
188
|
-
|
|
189
|
-
if (!appId || !appSecret) {
|
|
190
|
-
throw new Error(`Feishu credentials not configured for account "${accountId}"`);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Check cache
|
|
194
|
-
const cached = clientCache.get(accountId);
|
|
195
|
-
if (
|
|
196
|
-
cached &&
|
|
197
|
-
cached.config.appId === appId &&
|
|
198
|
-
cached.config.appSecret === appSecret &&
|
|
199
|
-
cached.config.domain === domain &&
|
|
200
|
-
cached.config.httpTimeoutMs === defaultHttpTimeoutMs
|
|
201
|
-
) {
|
|
202
|
-
return cached.client;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// Create new client with timeout-aware HTTP instance
|
|
206
|
-
const client = new feishuClientSdk.Client({
|
|
207
|
-
appId,
|
|
208
|
-
appSecret,
|
|
209
|
-
appType: feishuClientSdk.AppType.SelfBuild,
|
|
210
|
-
domain: resolveDomain(domain),
|
|
211
|
-
httpInstance: createTimeoutHttpInstance(defaultHttpTimeoutMs),
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
// Cache it
|
|
215
|
-
clientCache.set(accountId, {
|
|
216
|
-
client,
|
|
217
|
-
config: { appId, appSecret, domain, httpTimeoutMs: defaultHttpTimeoutMs },
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
return client;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export type FeishuWsClientCallbacks = Pick<
|
|
224
|
-
ConstructorParameters<typeof feishuClientSdk.WSClient>[0],
|
|
225
|
-
"onError" | "onReady" | "onReconnected" | "onReconnecting"
|
|
226
|
-
>;
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Create a Feishu WebSocket client for an account.
|
|
230
|
-
* Note: WSClient is not cached since each call creates a new connection.
|
|
231
|
-
*/
|
|
232
|
-
export async function createFeishuWSClient(
|
|
233
|
-
account: ResolvedFeishuAccount,
|
|
234
|
-
callbacks: FeishuWsClientCallbacks = {},
|
|
235
|
-
): Promise<Lark.WSClient> {
|
|
236
|
-
const { accountId, appId, appSecret, domain } = account;
|
|
237
|
-
|
|
238
|
-
if (!appId || !appSecret) {
|
|
239
|
-
throw new Error(`Feishu credentials not configured for account "${accountId}"`);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const agent = await getWsProxyAgent();
|
|
243
|
-
return new feishuClientSdk.WSClient({
|
|
244
|
-
appId,
|
|
245
|
-
appSecret,
|
|
246
|
-
domain: resolveDomain(domain),
|
|
247
|
-
...callbacks,
|
|
248
|
-
loggerLevel: feishuClientSdk.LoggerLevel.info,
|
|
249
|
-
wsConfig: FEISHU_WS_CONFIG,
|
|
250
|
-
...(agent ? { agent } : {}),
|
|
251
|
-
} as ConstructorParameters<typeof feishuClientSdk.WSClient>[0] & {
|
|
252
|
-
wsConfig: typeof FEISHU_WS_CONFIG;
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Create an event dispatcher for an account.
|
|
258
|
-
*/
|
|
259
|
-
export function createEventDispatcher(account: ResolvedFeishuAccount): Lark.EventDispatcher {
|
|
260
|
-
return new feishuClientSdk.EventDispatcher({
|
|
261
|
-
encryptKey: account.encryptKey,
|
|
262
|
-
verificationToken: account.verificationToken,
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Get a cached client for an account (if exists).
|
|
268
|
-
*/
|
|
269
|
-
export function getFeishuClient(accountId: string): Lark.Client | null {
|
|
270
|
-
return clientCache.get(accountId)?.client ?? null;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Clear client cache for a specific account or all accounts.
|
|
275
|
-
*/
|
|
276
|
-
export function clearClientCache(accountId?: string): void {
|
|
277
|
-
if (accountId) {
|
|
278
|
-
clientCache.delete(accountId);
|
|
279
|
-
} else {
|
|
280
|
-
clientCache.clear();
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
export function setFeishuClientRuntimeForTest(overrides?: {
|
|
285
|
-
sdk?: Partial<FeishuClientSdk>;
|
|
286
|
-
}): void {
|
|
287
|
-
feishuClientSdk = overrides?.sdk
|
|
288
|
-
? { ...defaultFeishuClientSdk, ...overrides.sdk }
|
|
289
|
-
: defaultFeishuClientSdk;
|
|
290
|
-
}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
|
|
3
|
-
const resolveFeishuRuntimeAccountMock = vi.hoisted(() => vi.fn());
|
|
4
|
-
const createFeishuClientMock = vi.hoisted(() => vi.fn());
|
|
5
|
-
const createReplyPrefixContextMock = vi.hoisted(() => vi.fn());
|
|
6
|
-
const createCommentTypingReactionLifecycleMock = vi.hoisted(() => vi.fn());
|
|
7
|
-
const deliverCommentThreadTextMock = vi.hoisted(() => vi.fn());
|
|
8
|
-
const createReplyDispatcherWithTypingMock = vi.hoisted(() => vi.fn());
|
|
9
|
-
const getFeishuRuntimeMock = vi.hoisted(() => vi.fn());
|
|
10
|
-
|
|
11
|
-
vi.mock("./accounts.js", () => ({
|
|
12
|
-
resolveFeishuRuntimeAccount: resolveFeishuRuntimeAccountMock,
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
|
-
vi.mock("./client.js", () => ({
|
|
16
|
-
createFeishuClient: createFeishuClientMock,
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
vi.mock("./comment-dispatcher-runtime-api.js", () => ({
|
|
20
|
-
createReplyPrefixContext: createReplyPrefixContextMock,
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
vi.mock("./comment-reaction.js", () => ({
|
|
24
|
-
createCommentTypingReactionLifecycle: createCommentTypingReactionLifecycleMock,
|
|
25
|
-
}));
|
|
26
|
-
|
|
27
|
-
vi.mock("./drive.js", () => ({
|
|
28
|
-
deliverCommentThreadText: deliverCommentThreadTextMock,
|
|
29
|
-
}));
|
|
30
|
-
|
|
31
|
-
vi.mock("./runtime.js", () => ({
|
|
32
|
-
getFeishuRuntime: getFeishuRuntimeMock,
|
|
33
|
-
}));
|
|
34
|
-
|
|
35
|
-
import { createFeishuCommentReplyDispatcher } from "./comment-dispatcher.js";
|
|
36
|
-
|
|
37
|
-
describe("createFeishuCommentReplyDispatcher", () => {
|
|
38
|
-
function createTestCommentReplyDispatcher() {
|
|
39
|
-
createFeishuCommentReplyDispatcher({
|
|
40
|
-
cfg: {} as never,
|
|
41
|
-
agentId: "main",
|
|
42
|
-
runtime: { log: vi.fn(), error: vi.fn() } as never,
|
|
43
|
-
accountId: "main",
|
|
44
|
-
fileToken: "doc_token_1",
|
|
45
|
-
fileType: "docx",
|
|
46
|
-
commentId: "comment_1",
|
|
47
|
-
replyId: "reply_1",
|
|
48
|
-
isWholeComment: false,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function latestReplyDispatcherOptions() {
|
|
53
|
-
const options = createReplyDispatcherWithTypingMock.mock.calls.at(-1)?.[0];
|
|
54
|
-
expect(options).toBeDefined();
|
|
55
|
-
if (!options) {
|
|
56
|
-
throw new Error("expected reply dispatcher options");
|
|
57
|
-
}
|
|
58
|
-
return options as {
|
|
59
|
-
deliver: (payload: { text: string }, phase: { kind: string }) => Promise<void> | void;
|
|
60
|
-
onCleanup?: () => Promise<void> | void;
|
|
61
|
-
onReplyStart?: () => Promise<void> | void;
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
beforeEach(() => {
|
|
66
|
-
vi.clearAllMocks();
|
|
67
|
-
resolveFeishuRuntimeAccountMock.mockReturnValue({
|
|
68
|
-
accountId: "main",
|
|
69
|
-
appId: "app_id",
|
|
70
|
-
appSecret: "app_secret",
|
|
71
|
-
domain: "feishu",
|
|
72
|
-
config: {},
|
|
73
|
-
});
|
|
74
|
-
createFeishuClientMock.mockReturnValue({});
|
|
75
|
-
createReplyPrefixContextMock.mockReturnValue({
|
|
76
|
-
responsePrefix: undefined,
|
|
77
|
-
responsePrefixContextProvider: undefined,
|
|
78
|
-
});
|
|
79
|
-
deliverCommentThreadTextMock.mockResolvedValue({
|
|
80
|
-
delivery_mode: "reply_comment",
|
|
81
|
-
reply_id: "reply_1",
|
|
82
|
-
});
|
|
83
|
-
createCommentTypingReactionLifecycleMock.mockReturnValue({
|
|
84
|
-
start: vi.fn(async () => {}),
|
|
85
|
-
cleanup: vi.fn(async () => {}),
|
|
86
|
-
});
|
|
87
|
-
createReplyDispatcherWithTypingMock.mockImplementation(() => ({
|
|
88
|
-
dispatcher: {
|
|
89
|
-
markComplete: vi.fn(),
|
|
90
|
-
waitForIdle: vi.fn(async () => {}),
|
|
91
|
-
},
|
|
92
|
-
replyOptions: {},
|
|
93
|
-
markDispatchIdle: vi.fn(),
|
|
94
|
-
markRunComplete: vi.fn(),
|
|
95
|
-
}));
|
|
96
|
-
getFeishuRuntimeMock.mockReturnValue({
|
|
97
|
-
channel: {
|
|
98
|
-
text: {
|
|
99
|
-
resolveTextChunkLimit: vi.fn(() => 4000),
|
|
100
|
-
resolveChunkMode: vi.fn(() => "line"),
|
|
101
|
-
chunkTextWithMode: vi.fn((text: string) => [text]),
|
|
102
|
-
},
|
|
103
|
-
reply: {
|
|
104
|
-
createReplyDispatcherWithTyping: createReplyDispatcherWithTypingMock,
|
|
105
|
-
resolveHumanDelayConfig: vi.fn(() => undefined),
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("sends final comment text without waiting for typing cleanup", async () => {
|
|
112
|
-
let resolveCleanup: (() => void) | undefined;
|
|
113
|
-
const cleanup = vi.fn(
|
|
114
|
-
() =>
|
|
115
|
-
new Promise<void>((resolve) => {
|
|
116
|
-
resolveCleanup = resolve;
|
|
117
|
-
}),
|
|
118
|
-
);
|
|
119
|
-
createCommentTypingReactionLifecycleMock.mockReturnValue({
|
|
120
|
-
start: vi.fn(async () => {}),
|
|
121
|
-
cleanup,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
createTestCommentReplyDispatcher();
|
|
125
|
-
|
|
126
|
-
const options = latestReplyDispatcherOptions();
|
|
127
|
-
const deliverPromise = Promise.resolve(
|
|
128
|
-
options.deliver({ text: "hello world" }, { kind: "final" }),
|
|
129
|
-
);
|
|
130
|
-
const status = await Promise.race([
|
|
131
|
-
deliverPromise.then(() => "done"),
|
|
132
|
-
new Promise<string>((resolve) => setTimeout(() => resolve("pending"), 0)),
|
|
133
|
-
]);
|
|
134
|
-
|
|
135
|
-
expect(status).toBe("done");
|
|
136
|
-
expect(deliverCommentThreadTextMock).toHaveBeenCalledWith(
|
|
137
|
-
expect.anything(),
|
|
138
|
-
expect.objectContaining({
|
|
139
|
-
file_token: "doc_token_1",
|
|
140
|
-
file_type: "docx",
|
|
141
|
-
comment_id: "comment_1",
|
|
142
|
-
content: "hello world",
|
|
143
|
-
is_whole_comment: false,
|
|
144
|
-
}),
|
|
145
|
-
);
|
|
146
|
-
expect(cleanup).not.toHaveBeenCalled();
|
|
147
|
-
|
|
148
|
-
void options.onCleanup?.();
|
|
149
|
-
expect(cleanup).toHaveBeenCalledTimes(1);
|
|
150
|
-
|
|
151
|
-
resolveCleanup?.();
|
|
152
|
-
await deliverPromise;
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("starts the typing reaction from dispatcher onReplyStart", async () => {
|
|
156
|
-
const start = vi.fn(async () => {});
|
|
157
|
-
createCommentTypingReactionLifecycleMock.mockReturnValue({
|
|
158
|
-
start,
|
|
159
|
-
cleanup: vi.fn(async () => {}),
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
createTestCommentReplyDispatcher();
|
|
163
|
-
|
|
164
|
-
const options = latestReplyDispatcherOptions();
|
|
165
|
-
await options.onReplyStart?.();
|
|
166
|
-
|
|
167
|
-
expect(start).toHaveBeenCalledTimes(1);
|
|
168
|
-
});
|
|
169
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
|
|
2
|
-
import { resolveFeishuRuntimeAccount } from "./accounts.js";
|
|
3
|
-
import { createFeishuClient } from "./client.js";
|
|
4
|
-
import {
|
|
5
|
-
createReplyPrefixContext,
|
|
6
|
-
type ClawdbotConfig,
|
|
7
|
-
type ReplyPayload,
|
|
8
|
-
type RuntimeEnv,
|
|
9
|
-
} from "./comment-dispatcher-runtime-api.js";
|
|
10
|
-
import { createCommentTypingReactionLifecycle } from "./comment-reaction.js";
|
|
11
|
-
import type { CommentFileType } from "./comment-target.js";
|
|
12
|
-
import { deliverCommentThreadText } from "./drive.js";
|
|
13
|
-
import { getFeishuRuntime } from "./runtime.js";
|
|
14
|
-
|
|
15
|
-
type CreateFeishuCommentReplyDispatcherParams = {
|
|
16
|
-
cfg: ClawdbotConfig;
|
|
17
|
-
agentId: string;
|
|
18
|
-
runtime: RuntimeEnv;
|
|
19
|
-
accountId?: string;
|
|
20
|
-
fileToken: string;
|
|
21
|
-
fileType: CommentFileType;
|
|
22
|
-
commentId: string;
|
|
23
|
-
replyId?: string;
|
|
24
|
-
isWholeComment?: boolean;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export function createFeishuCommentReplyDispatcher(
|
|
28
|
-
params: CreateFeishuCommentReplyDispatcherParams,
|
|
29
|
-
) {
|
|
30
|
-
const core = getFeishuRuntime();
|
|
31
|
-
const prefixContext = createReplyPrefixContext({
|
|
32
|
-
cfg: params.cfg,
|
|
33
|
-
agentId: params.agentId,
|
|
34
|
-
channel: "feishu",
|
|
35
|
-
accountId: params.accountId,
|
|
36
|
-
});
|
|
37
|
-
const account = resolveFeishuRuntimeAccount({ cfg: params.cfg, accountId: params.accountId });
|
|
38
|
-
const client = createFeishuClient(account);
|
|
39
|
-
const textChunkLimit = core.channel.text.resolveTextChunkLimit(
|
|
40
|
-
params.cfg,
|
|
41
|
-
"feishu",
|
|
42
|
-
params.accountId,
|
|
43
|
-
{
|
|
44
|
-
fallbackLimit: 4000,
|
|
45
|
-
},
|
|
46
|
-
);
|
|
47
|
-
const chunkMode = core.channel.text.resolveChunkMode(params.cfg, "feishu");
|
|
48
|
-
const typingReaction = createCommentTypingReactionLifecycle({
|
|
49
|
-
cfg: params.cfg,
|
|
50
|
-
fileToken: params.fileToken,
|
|
51
|
-
fileType: params.fileType,
|
|
52
|
-
replyId: params.replyId,
|
|
53
|
-
accountId: params.accountId,
|
|
54
|
-
runtime: params.runtime,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const { dispatcher, replyOptions, markDispatchIdle, markRunComplete } =
|
|
58
|
-
core.channel.reply.createReplyDispatcherWithTyping({
|
|
59
|
-
responsePrefix: prefixContext.responsePrefix,
|
|
60
|
-
responsePrefixContextProvider: prefixContext.responsePrefixContextProvider,
|
|
61
|
-
humanDelay: core.channel.reply.resolveHumanDelayConfig(params.cfg, params.agentId),
|
|
62
|
-
onReplyStart: async () => {
|
|
63
|
-
await typingReaction.start();
|
|
64
|
-
},
|
|
65
|
-
deliver: async (payload: ReplyPayload, info) => {
|
|
66
|
-
if (info.kind !== "final") {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
const reply = resolveSendableOutboundReplyParts(payload);
|
|
70
|
-
if (!reply.hasText) {
|
|
71
|
-
if (reply.hasMedia) {
|
|
72
|
-
params.runtime.log?.(
|
|
73
|
-
`feishu[${params.accountId ?? "default"}]: comment reply ignored media-only payload for comment=${params.commentId}`,
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
const chunks = core.channel.text.chunkTextWithMode(reply.text, textChunkLimit, chunkMode);
|
|
79
|
-
for (const chunk of chunks) {
|
|
80
|
-
await deliverCommentThreadText(client, {
|
|
81
|
-
file_token: params.fileToken,
|
|
82
|
-
file_type: params.fileType,
|
|
83
|
-
comment_id: params.commentId,
|
|
84
|
-
content: chunk,
|
|
85
|
-
is_whole_comment: params.isWholeComment,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
},
|
|
89
|
-
onError: (err, info) => {
|
|
90
|
-
params.runtime.error?.(
|
|
91
|
-
`feishu[${params.accountId ?? "default"}]: comment dispatcher failed kind=${info.kind} comment=${params.commentId}: ${String(err)}`,
|
|
92
|
-
);
|
|
93
|
-
},
|
|
94
|
-
onCleanup: () => {
|
|
95
|
-
void typingReaction.cleanup();
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
dispatcher,
|
|
101
|
-
replyOptions,
|
|
102
|
-
markDispatchIdle,
|
|
103
|
-
markRunComplete,
|
|
104
|
-
startTypingReaction: typingReaction.start,
|
|
105
|
-
cleanupTypingReaction: typingReaction.cleanup,
|
|
106
|
-
};
|
|
107
|
-
}
|