mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:20:44 +00:00
test: isolate directory contract fixtures
This commit is contained in:
@@ -59,6 +59,10 @@ import type { MattermostConfig } from "./types.js";
|
||||
|
||||
const loadMattermostChannelRuntime = createLazyRuntimeModule(() => import("./channel.runtime.js"));
|
||||
|
||||
type MattermostDirectoryListParams = Parameters<
|
||||
NonNullable<NonNullable<ChannelPlugin["directory"]>["listGroups"]>
|
||||
>[0];
|
||||
|
||||
const mattermostSecurityAdapter = createRestrictSendersChannelSecurity<ResolvedMattermostAccount>({
|
||||
channelKey: "mattermost",
|
||||
resolveDmPolicy: (account) => account.config.dmPolicy,
|
||||
@@ -110,6 +114,34 @@ function describeMattermostMessageTool({
|
||||
};
|
||||
}
|
||||
|
||||
function hasConfiguredMattermostDirectoryAccount({
|
||||
cfg,
|
||||
accountId,
|
||||
}: Pick<MattermostDirectoryListParams, "cfg" | "accountId">): boolean {
|
||||
const accounts = accountId
|
||||
? [resolveMattermostAccount({ cfg, accountId })]
|
||||
: listMattermostAccountIds(cfg).map((listedAccountId) =>
|
||||
resolveMattermostAccount({ cfg, accountId: listedAccountId }),
|
||||
);
|
||||
return accounts.some((account) =>
|
||||
Boolean(account.enabled && account.botToken?.trim() && account.baseUrl?.trim()),
|
||||
);
|
||||
}
|
||||
|
||||
async function listMattermostDirectoryGroups(params: MattermostDirectoryListParams) {
|
||||
if (!hasConfiguredMattermostDirectoryAccount(params)) {
|
||||
return [];
|
||||
}
|
||||
return (await loadMattermostChannelRuntime()).listMattermostDirectoryGroups(params);
|
||||
}
|
||||
|
||||
async function listMattermostDirectoryPeers(params: MattermostDirectoryListParams) {
|
||||
if (!hasConfiguredMattermostDirectoryAccount(params)) {
|
||||
return [];
|
||||
}
|
||||
return (await loadMattermostChannelRuntime()).listMattermostDirectoryPeers(params);
|
||||
}
|
||||
|
||||
const mattermostMessageActions: ChannelMessageActionAdapter = {
|
||||
describeMessageTool: describeMattermostMessageTool,
|
||||
supportsAction: ({ action }) => {
|
||||
@@ -379,14 +411,10 @@ export const mattermostPlugin: ChannelPlugin<ResolvedMattermostAccount> = create
|
||||
collectRuntimeConfigAssignments,
|
||||
},
|
||||
directory: createChannelDirectoryAdapter({
|
||||
listGroups: async (params) =>
|
||||
(await loadMattermostChannelRuntime()).listMattermostDirectoryGroups(params),
|
||||
listGroupsLive: async (params) =>
|
||||
(await loadMattermostChannelRuntime()).listMattermostDirectoryGroups(params),
|
||||
listPeers: async (params) =>
|
||||
(await loadMattermostChannelRuntime()).listMattermostDirectoryPeers(params),
|
||||
listPeersLive: async (params) =>
|
||||
(await loadMattermostChannelRuntime()).listMattermostDirectoryPeers(params),
|
||||
listGroups: listMattermostDirectoryGroups,
|
||||
listGroupsLive: listMattermostDirectoryGroups,
|
||||
listPeers: listMattermostDirectoryPeers,
|
||||
listPeersLive: listMattermostDirectoryPeers,
|
||||
}),
|
||||
messaging: {
|
||||
targetPrefixes: ["mattermost"],
|
||||
|
||||
Reference in New Issue
Block a user