openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
79 lines (78 loc) • 3.28 kB
JavaScript
import { c as normalizeOptionalLowercaseString } from "./string-coerce-CCIiB4H7.mjs";
import { u as normalizePluginsConfig } from "./config-state-B1JlHgba.mjs";
import { n as getCurrentPluginMetadataSnapshotRuntime } from "./plugin-metadata-snapshot.runtime.js";
import { a as resolveManifestOwnerBasePolicyBlock } from "./manifest-owner-policy-B8Brw4Zo.mjs";
import { t as MissingPublicSurfaceError } from "./facade-loader-08DBXZOS.mjs";
import { r as loadPluginPublicArtifactModuleSync, t as loadBundledPluginPublicArtifactModuleFromCandidatesSync } from "./public-surface-loader-DENdCm5a.mjs";
//#region src/media/channel-inbound-roots.ts
const CHANNEL_MEDIA_CONTRACT_ARTIFACT = "media-contract-api.js";
function resolveInstalledChannelMediaContractOwners(e) {
try {
const t = getCurrentPluginMetadataSnapshotRuntime({
config: e.cfg,
allowScopedSnapshot: true,
allowWorkspaceScopedSnapshot: true
});
const n = normalizePluginsConfig(e.cfg.plugins);
return (t?.manifestRegistry.plugins ?? []).filter((t) => t.origin === "global" && t.trustedOfficialInstall === true && t.channels.some((t) => normalizeOptionalLowercaseString(t) === e.channelId) && resolveManifestOwnerBasePolicyBlock({
plugin: t,
normalizedConfig: n
}) === null).toSorted((e, t) => e.id.localeCompare(t.id));
} catch {
return [];
}
}
function findChannelMediaContractApi(e) {
const t = normalizeOptionalLowercaseString(e.channelId);
if (!t) return;
const n = loadBundledPluginPublicArtifactModuleFromCandidatesSync({
dirName: t,
artifactCandidates: [CHANNEL_MEDIA_CONTRACT_ARTIFACT]
});
if (n && typeof n[e.resolver] === "function") return n;
for (const n of resolveInstalledChannelMediaContractOwners({
channelId: t,
cfg: e.cfg
})) try {
const t = loadPluginPublicArtifactModuleSync({
pluginRoot: n.rootDir,
artifactBasename: CHANNEL_MEDIA_CONTRACT_ARTIFACT,
origin: "global"
});
if (typeof t[e.resolver] === "function") return t;
} catch (e) {
if (!(e instanceof MissingPublicSurfaceError)) throw e;
}
}
/** Resolves local inbound attachment roots from the channel named in a message context. */
function resolveChannelInboundAttachmentRoots(e) {
return resolveChannelInboundAttachmentRootsForChannel({
cfg: e.cfg,
channelId: e.ctx.Surface ?? e.ctx.Provider,
accountId: e.ctx.AccountId
});
}
/** Resolves local inbound attachment roots for callers that already know the channel id. */
function resolveChannelInboundAttachmentRootsForChannel(e) {
return findChannelMediaContractApi({
channelId: e.channelId,
cfg: e.cfg,
resolver: "resolveInboundAttachmentRoots"
})?.resolveInboundAttachmentRoots?.({
cfg: e.cfg,
accountId: e.accountId ?? void 0
});
}
/** Resolves remote staging roots for inbound channel attachments without loading full channel code. */
function resolveChannelRemoteInboundAttachmentRoots(e) {
return findChannelMediaContractApi({
channelId: e.ctx.Surface ?? e.ctx.Provider,
cfg: e.cfg,
resolver: "resolveRemoteInboundAttachmentRoots"
})?.resolveRemoteInboundAttachmentRoots?.({
cfg: e.cfg,
accountId: e.ctx.AccountId
});
}
//#endregion
export { resolveChannelInboundAttachmentRootsForChannel as n, resolveChannelRemoteInboundAttachmentRoots as r, resolveChannelInboundAttachmentRoots as t };