perf: reduce feishu monitor import drag

This commit is contained in:
Peter Steinberger
2026-04-24 02:55:07 +01:00
parent 68e2d6f088
commit 3361593442
5 changed files with 27 additions and 17 deletions

View File

@@ -8,8 +8,11 @@ import { createNonExitingTypedRuntimeEnv } from "../../../test/helpers/plugins/r
import type { ClawdbotConfig, PluginRuntime, RuntimeEnv } from "../runtime-api.js";
import { parseFeishuMessageEvent, type FeishuMessageEvent } from "./bot.js";
import * as dedup from "./dedup.js";
import { monitorSingleAccount } from "./monitor.account.js";
import { resolveReactionSyntheticEvent, type FeishuReactionCreatedEvent } from "./monitor.js";
import {
monitorSingleAccount,
resolveReactionSyntheticEvent,
type FeishuReactionCreatedEvent,
} from "./monitor.account.js";
import { setFeishuRuntime } from "./runtime.js";
import type { ResolvedFeishuAccount } from "./types.js";

View File

@@ -40,9 +40,12 @@ function buildMultiAccountWebsocketConfig(accountIds: string[]): ClawdbotConfig
}
async function waitForStartedAccount(started: string[], accountId: string) {
for (let i = 0; i < 10 && !started.includes(accountId); i += 1) {
await Promise.resolve();
}
await vi.waitFor(
() => {
expect(started).toContain(accountId);
},
{ timeout: 10_000 },
);
}
afterEach(() => {
@@ -74,9 +77,7 @@ describe("Feishu monitor startup preflight", () => {
});
try {
await Promise.resolve();
await Promise.resolve();
await waitForStartedAccount(started, "alpha");
expect(started).toEqual(["alpha"]);
expect(maxInFlight).toBe(1);
} finally {
@@ -177,7 +178,7 @@ describe("Feishu monitor startup preflight", () => {
});
try {
await Promise.resolve();
await waitForStartedAccount(started, "alpha");
expect(started).toEqual(["alpha"]);
abortController.abort();

View File

@@ -1,10 +1,5 @@
import type { ClawdbotConfig, RuntimeEnv } from "../runtime-api.js";
import { listEnabledFeishuAccounts, resolveFeishuRuntimeAccount } from "./accounts.js";
import {
monitorSingleAccount,
resolveReactionSyntheticEvent,
type FeishuReactionCreatedEvent,
} from "./monitor.account.js";
import { fetchBotIdentityForMonitor } from "./monitor.startup.js";
import {
clearFeishuWebhookRateLimitStateForTest,
@@ -20,13 +15,18 @@ export type MonitorFeishuOpts = {
accountId?: string;
};
let monitorAccountRuntimePromise: Promise<typeof import("./monitor.account.js")> | undefined;
async function loadMonitorAccountRuntime() {
monitorAccountRuntimePromise ??= import("./monitor.account.js");
return await monitorAccountRuntimePromise;
}
export {
clearFeishuWebhookRateLimitStateForTest,
getFeishuWebhookRateLimitStateSizeForTest,
isWebhookRateLimitedForTest,
resolveReactionSyntheticEvent,
};
export type { FeishuReactionCreatedEvent };
export async function monitorFeishuProvider(opts: MonitorFeishuOpts = {}): Promise<void> {
const cfg = opts.config;
@@ -44,6 +44,7 @@ export async function monitorFeishuProvider(opts: MonitorFeishuOpts = {}): Promi
if (!account.enabled || !account.configured) {
throw new Error(`Feishu account "${opts.accountId}" not configured or disabled`);
}
const { monitorSingleAccount } = await loadMonitorAccountRuntime();
return monitorSingleAccount({
cfg,
account,
@@ -61,6 +62,7 @@ export async function monitorFeishuProvider(opts: MonitorFeishuOpts = {}): Promi
`feishu: starting ${accounts.length} account(s): ${accounts.map((a) => a.accountId).join(", ")}`,
);
const { monitorSingleAccount } = await loadMonitorAccountRuntime();
const monitorPromises: Promise<void>[] = [];
for (const account of accounts) {
if (opts.abortSignal?.aborted) {

View File

@@ -1,4 +1,7 @@
import { isAbortRequestText, isBtwRequestText } from "openclaw/plugin-sdk/reply-runtime";
import {
isAbortRequestText,
isBtwRequestText,
} from "openclaw/plugin-sdk/command-primitives-runtime";
import { parseFeishuMessageEvent, type FeishuMessageEvent } from "./bot.js";
export function getFeishuSequentialKey(params: {

View File

@@ -1 +1,2 @@
export { isAbortRequestText } from "../auto-reply/reply/abort-primitives.js";
export { isBtwRequestText } from "../auto-reply/reply/btw-command.js";