MSTeams: lazy-load runtime-heavy channel paths

This commit is contained in:
Vincent Koc 2026-03-15 17:50:35 -07:00
parent c0e0115b31
commit da4f82503f
2 changed files with 28 additions and 8 deletions

View File

@ -0,0 +1,4 @@
export { listMSTeamsDirectoryGroupsLive, listMSTeamsDirectoryPeersLive } from "./directory-live.js";
export { msteamsOutbound } from "./outbound.js";
export { probeMSTeams } from "./probe.js";
export { sendAdaptiveCardMSTeams, sendMessageMSTeams } from "./send.js";

View File

@ -16,11 +16,8 @@ import {
MSTeamsConfigSchema,
PAIRING_APPROVED_MESSAGE,
} from "openclaw/plugin-sdk/msteams";
import { listMSTeamsDirectoryGroupsLive, listMSTeamsDirectoryPeersLive } from "./directory-live.js";
import { msteamsOnboardingAdapter } from "./onboarding.js";
import { msteamsOutbound } from "./outbound.js";
import { resolveMSTeamsGroupToolPolicy } from "./policy.js";
import { probeMSTeams } from "./probe.js";
import {
normalizeMSTeamsMessagingTarget,
normalizeMSTeamsUserInput,
@ -29,7 +26,7 @@ import {
resolveMSTeamsChannelAllowlist,
resolveMSTeamsUserAllowlist,
} from "./resolve-allowlist.js";
import { sendAdaptiveCardMSTeams, sendMessageMSTeams } from "./send.js";
import { getMSTeamsRuntime } from "./runtime.js";
import { resolveMSTeamsCredentials } from "./token.js";
type ResolvedMSTeamsAccount = {
@ -49,6 +46,10 @@ const meta = {
order: 60,
} as const;
async function loadMSTeamsChannelRuntime() {
return await import("./channel.runtime.js");
}
export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount> = {
id: "msteams",
meta: {
@ -60,6 +61,7 @@ export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount> = {
idLabel: "msteamsUserId",
normalizeAllowEntry: (entry) => entry.replace(/^(msteams|user):/i, ""),
notifyApproval: async ({ cfg, id }) => {
const { sendMessageMSTeams } = await loadMSTeamsChannelRuntime();
await sendMessageMSTeams({
cfg,
to: id,
@ -233,9 +235,9 @@ export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount> = {
.map((id) => ({ kind: "group", id }) as const);
},
listPeersLive: async ({ cfg, query, limit }) =>
listMSTeamsDirectoryPeersLive({ cfg, query, limit }),
(await loadMSTeamsChannelRuntime()).listMSTeamsDirectoryPeersLive({ cfg, query, limit }),
listGroupsLive: async ({ cfg, query, limit }) =>
listMSTeamsDirectoryGroupsLive({ cfg, query, limit }),
(await loadMSTeamsChannelRuntime()).listMSTeamsDirectoryGroupsLive({ cfg, query, limit }),
},
resolver: {
resolveTargets: async ({ cfg, inputs, kind, runtime }) => {
@ -398,6 +400,7 @@ export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount> = {
details: { error: "Card send requires a target (to)." },
};
}
const { sendAdaptiveCardMSTeams } = await loadMSTeamsChannelRuntime();
const result = await sendAdaptiveCardMSTeams({
cfg: ctx.cfg,
to,
@ -422,14 +425,27 @@ export const msteamsPlugin: ChannelPlugin<ResolvedMSTeamsAccount> = {
return null as never;
},
},
outbound: msteamsOutbound,
outbound: {
deliveryMode: "direct",
chunker: (text, limit) => getMSTeamsRuntime().channel.text.chunkMarkdownText(text, limit),
chunkerMode: "markdown",
textChunkLimit: 4000,
pollMaxOptions: 12,
sendText: async (params) =>
(await loadMSTeamsChannelRuntime()).msteamsOutbound.sendText!(params),
sendMedia: async (params) =>
(await loadMSTeamsChannelRuntime()).msteamsOutbound.sendMedia!(params),
sendPoll: async (params) =>
(await loadMSTeamsChannelRuntime()).msteamsOutbound.sendPoll!(params),
},
status: {
defaultRuntime: createDefaultChannelRuntimeState(DEFAULT_ACCOUNT_ID, { port: null }),
buildChannelSummary: ({ snapshot }) =>
buildProbeChannelStatusSummary(snapshot, {
port: snapshot.port ?? null,
}),
probeAccount: async ({ cfg }) => await probeMSTeams(cfg.channels?.msteams),
probeAccount: async ({ cfg }) =>
await (await loadMSTeamsChannelRuntime()).probeMSTeams(cfg.channels?.msteams),
buildAccountSnapshot: ({ account, runtime, probe }) => ({
accountId: account.accountId,
enabled: account.enabled,