Plugin SDK: restore read-only directory inspection seam
This commit is contained in:
parent
e17d10f7cd
commit
c99c4b1e27
@ -1,23 +1,18 @@
|
||||
import {
|
||||
applyDirectoryQueryAndLimit,
|
||||
collectNormalizedDirectoryIds,
|
||||
inspectReadOnlyChannelAccount,
|
||||
toDirectoryEntries,
|
||||
type DirectoryConfigParams,
|
||||
} from "openclaw/plugin-sdk/directory-runtime";
|
||||
import { inspectDiscordAccount } from "../api.js";
|
||||
import type { InspectedDiscordAccount } from "../api.js";
|
||||
|
||||
function inspectDiscordDirectoryAccount(
|
||||
params: DirectoryConfigParams,
|
||||
): InspectedDiscordAccount | null {
|
||||
return inspectDiscordAccount({
|
||||
export async function listDiscordDirectoryPeersFromConfig(params: DirectoryConfigParams) {
|
||||
const account = (await inspectReadOnlyChannelAccount({
|
||||
channelId: "discord",
|
||||
cfg: params.cfg,
|
||||
accountId: params.accountId,
|
||||
});
|
||||
}
|
||||
|
||||
export async function listDiscordDirectoryPeersFromConfig(params: DirectoryConfigParams) {
|
||||
const account = inspectDiscordDirectoryAccount(params);
|
||||
})) as InspectedDiscordAccount | null;
|
||||
if (!account || !("config" in account)) {
|
||||
return [];
|
||||
}
|
||||
@ -39,7 +34,11 @@ export async function listDiscordDirectoryPeersFromConfig(params: DirectoryConfi
|
||||
}
|
||||
|
||||
export async function listDiscordDirectoryGroupsFromConfig(params: DirectoryConfigParams) {
|
||||
const account = inspectDiscordDirectoryAccount(params);
|
||||
const account = (await inspectReadOnlyChannelAccount({
|
||||
channelId: "discord",
|
||||
cfg: params.cfg,
|
||||
accountId: params.accountId,
|
||||
})) as InspectedDiscordAccount | null;
|
||||
if (!account || !("config" in account)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -1,23 +1,20 @@
|
||||
import { normalizeSlackMessagingTarget } from "openclaw/plugin-sdk/channel-runtime";
|
||||
import {
|
||||
applyDirectoryQueryAndLimit,
|
||||
collectNormalizedDirectoryIds,
|
||||
inspectReadOnlyChannelAccount,
|
||||
listDirectoryGroupEntriesFromMapKeys,
|
||||
toDirectoryEntries,
|
||||
type DirectoryConfigParams,
|
||||
} from "openclaw/plugin-sdk/directory-runtime";
|
||||
import { inspectSlackAccount } from "../api.js";
|
||||
import type { InspectedSlackAccount } from "../api.js";
|
||||
|
||||
function inspectSlackDirectoryAccount(params: DirectoryConfigParams): InspectedSlackAccount | null {
|
||||
return inspectSlackAccount({
|
||||
cfg: params.cfg,
|
||||
accountId: params.accountId,
|
||||
});
|
||||
}
|
||||
import { parseSlackTarget } from "./targets.js";
|
||||
|
||||
export async function listSlackDirectoryPeersFromConfig(params: DirectoryConfigParams) {
|
||||
const account = inspectSlackDirectoryAccount(params);
|
||||
const account = (await inspectReadOnlyChannelAccount({
|
||||
channelId: "slack",
|
||||
cfg: params.cfg,
|
||||
accountId: params.accountId,
|
||||
})) as InspectedSlackAccount | null;
|
||||
if (!account || !("config" in account)) {
|
||||
return [];
|
||||
}
|
||||
@ -35,15 +32,19 @@ export async function listSlackDirectoryPeersFromConfig(params: DirectoryConfigP
|
||||
return null;
|
||||
}
|
||||
const target = `user:${normalizedUserId}`;
|
||||
const normalized = normalizeSlackMessagingTarget(target) ?? target.toLowerCase();
|
||||
return normalized.startsWith("user:") ? normalized : null;
|
||||
const normalized = parseSlackTarget(target, { defaultKind: "user" });
|
||||
return normalized?.kind === "user" ? `user:${normalized.id.toLowerCase()}` : null;
|
||||
},
|
||||
});
|
||||
return toDirectoryEntries("user", applyDirectoryQueryAndLimit(ids, params));
|
||||
}
|
||||
|
||||
export async function listSlackDirectoryGroupsFromConfig(params: DirectoryConfigParams) {
|
||||
const account = inspectSlackDirectoryAccount(params);
|
||||
const account = (await inspectReadOnlyChannelAccount({
|
||||
channelId: "slack",
|
||||
cfg: params.cfg,
|
||||
accountId: params.accountId,
|
||||
})) as InspectedSlackAccount | null;
|
||||
if (!account || !("config" in account)) {
|
||||
return [];
|
||||
}
|
||||
@ -52,8 +53,8 @@ export async function listSlackDirectoryGroupsFromConfig(params: DirectoryConfig
|
||||
query: params.query,
|
||||
limit: params.limit,
|
||||
normalizeId: (raw) => {
|
||||
const normalized = normalizeSlackMessagingTarget(raw) ?? raw.toLowerCase();
|
||||
return normalized.startsWith("channel:") ? normalized : null;
|
||||
const normalized = parseSlackTarget(raw, { defaultKind: "channel" });
|
||||
return normalized?.kind === "channel" ? `channel:${normalized.id.toLowerCase()}` : null;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@ -2,24 +2,19 @@ import { mapAllowFromEntries } from "openclaw/plugin-sdk/channel-config-helpers"
|
||||
import {
|
||||
applyDirectoryQueryAndLimit,
|
||||
collectNormalizedDirectoryIds,
|
||||
inspectReadOnlyChannelAccount,
|
||||
listDirectoryGroupEntriesFromMapKeys,
|
||||
toDirectoryEntries,
|
||||
type DirectoryConfigParams,
|
||||
} from "openclaw/plugin-sdk/directory-runtime";
|
||||
import { inspectTelegramAccount } from "../api.js";
|
||||
import type { InspectedTelegramAccount } from "../api.js";
|
||||
|
||||
async function inspectTelegramDirectoryAccount(
|
||||
params: DirectoryConfigParams,
|
||||
): Promise<InspectedTelegramAccount | null> {
|
||||
return inspectTelegramAccount({
|
||||
export async function listTelegramDirectoryPeersFromConfig(params: DirectoryConfigParams) {
|
||||
const account = (await inspectReadOnlyChannelAccount({
|
||||
channelId: "telegram",
|
||||
cfg: params.cfg,
|
||||
accountId: params.accountId,
|
||||
});
|
||||
}
|
||||
|
||||
export async function listTelegramDirectoryPeersFromConfig(params: DirectoryConfigParams) {
|
||||
const account = await inspectTelegramDirectoryAccount(params);
|
||||
})) as InspectedTelegramAccount | null;
|
||||
if (!account || !("config" in account)) {
|
||||
return [];
|
||||
}
|
||||
@ -41,7 +36,11 @@ export async function listTelegramDirectoryPeersFromConfig(params: DirectoryConf
|
||||
}
|
||||
|
||||
export async function listTelegramDirectoryGroupsFromConfig(params: DirectoryConfigParams) {
|
||||
const account = await inspectTelegramDirectoryAccount(params);
|
||||
const account = (await inspectReadOnlyChannelAccount({
|
||||
channelId: "telegram",
|
||||
cfg: params.cfg,
|
||||
accountId: params.accountId,
|
||||
})) as InspectedTelegramAccount | null;
|
||||
if (!account || !("config" in account)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
/** Shared directory listing helpers for plugins that derive users/groups from config maps. */
|
||||
export type { DirectoryConfigParams } from "../channels/plugins/directory-types.js";
|
||||
export type { ReadOnlyInspectedAccount } from "../channels/read-only-account-inspect.js";
|
||||
export {
|
||||
applyDirectoryQueryAndLimit,
|
||||
collectNormalizedDirectoryIds,
|
||||
@ -9,3 +10,4 @@ export {
|
||||
listDirectoryUserEntriesFromAllowFromAndMapKeys,
|
||||
toDirectoryEntries,
|
||||
} from "../channels/plugins/directory-config-helpers.js";
|
||||
export { inspectReadOnlyChannelAccount } from "../channels/read-only-account-inspect.js";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user