mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 13:30:22 +00:00
refactor: simplify plugin sdk compatibility aliases
This commit is contained in:
@@ -5,6 +5,7 @@ import { createJiti } from "jiti";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { GatewayRequestHandler } from "../gateway/server-methods/types.js";
|
||||
import { openBoundaryFileSync } from "../infra/boundary-file-read.js";
|
||||
import { resolveOpenClawPackageRootSync } from "../infra/openclaw-root.js";
|
||||
import { createSubsystemLogger } from "../logging/subsystem.js";
|
||||
import { resolveUserPath } from "../utils.js";
|
||||
import { clearPluginCommands } from "./commands.js";
|
||||
@@ -111,105 +112,46 @@ const resolvePluginSdkAliasFile = (params: {
|
||||
const resolvePluginSdkAlias = (): string | null =>
|
||||
resolvePluginSdkAliasFile({ srcFile: "root-alias.cjs", distFile: "root-alias.cjs" });
|
||||
|
||||
const pluginSdkScopedAliasEntries = [
|
||||
{ subpath: "core", srcFile: "core.ts", distFile: "core.js" },
|
||||
{ subpath: "compat", srcFile: "compat.ts", distFile: "compat.js" },
|
||||
{ subpath: "telegram", srcFile: "telegram.ts", distFile: "telegram.js" },
|
||||
{ subpath: "discord", srcFile: "discord.ts", distFile: "discord.js" },
|
||||
{ subpath: "slack", srcFile: "slack.ts", distFile: "slack.js" },
|
||||
{ subpath: "signal", srcFile: "signal.ts", distFile: "signal.js" },
|
||||
{ subpath: "imessage", srcFile: "imessage.ts", distFile: "imessage.js" },
|
||||
{ subpath: "whatsapp", srcFile: "whatsapp.ts", distFile: "whatsapp.js" },
|
||||
{ subpath: "line", srcFile: "line.ts", distFile: "line.js" },
|
||||
{ subpath: "msteams", srcFile: "msteams.ts", distFile: "msteams.js" },
|
||||
{ subpath: "acpx", srcFile: "acpx.ts", distFile: "acpx.js" },
|
||||
{ subpath: "bluebubbles", srcFile: "bluebubbles.ts", distFile: "bluebubbles.js" },
|
||||
{
|
||||
subpath: "copilot-proxy",
|
||||
srcFile: "copilot-proxy.ts",
|
||||
distFile: "copilot-proxy.js",
|
||||
},
|
||||
{ subpath: "device-pair", srcFile: "device-pair.ts", distFile: "device-pair.js" },
|
||||
{
|
||||
subpath: "diagnostics-otel",
|
||||
srcFile: "diagnostics-otel.ts",
|
||||
distFile: "diagnostics-otel.js",
|
||||
},
|
||||
{ subpath: "diffs", srcFile: "diffs.ts", distFile: "diffs.js" },
|
||||
{ subpath: "feishu", srcFile: "feishu.ts", distFile: "feishu.js" },
|
||||
{
|
||||
subpath: "google-gemini-cli-auth",
|
||||
srcFile: "google-gemini-cli-auth.ts",
|
||||
distFile: "google-gemini-cli-auth.js",
|
||||
},
|
||||
{ subpath: "googlechat", srcFile: "googlechat.ts", distFile: "googlechat.js" },
|
||||
{ subpath: "irc", srcFile: "irc.ts", distFile: "irc.js" },
|
||||
{ subpath: "llm-task", srcFile: "llm-task.ts", distFile: "llm-task.js" },
|
||||
{ subpath: "lobster", srcFile: "lobster.ts", distFile: "lobster.js" },
|
||||
{ subpath: "matrix", srcFile: "matrix.ts", distFile: "matrix.js" },
|
||||
{ subpath: "mattermost", srcFile: "mattermost.ts", distFile: "mattermost.js" },
|
||||
{ subpath: "memory-core", srcFile: "memory-core.ts", distFile: "memory-core.js" },
|
||||
{
|
||||
subpath: "memory-lancedb",
|
||||
srcFile: "memory-lancedb.ts",
|
||||
distFile: "memory-lancedb.js",
|
||||
},
|
||||
{
|
||||
subpath: "minimax-portal-auth",
|
||||
srcFile: "minimax-portal-auth.ts",
|
||||
distFile: "minimax-portal-auth.js",
|
||||
},
|
||||
{
|
||||
subpath: "nextcloud-talk",
|
||||
srcFile: "nextcloud-talk.ts",
|
||||
distFile: "nextcloud-talk.js",
|
||||
},
|
||||
{ subpath: "nostr", srcFile: "nostr.ts", distFile: "nostr.js" },
|
||||
{ subpath: "open-prose", srcFile: "open-prose.ts", distFile: "open-prose.js" },
|
||||
{
|
||||
subpath: "phone-control",
|
||||
srcFile: "phone-control.ts",
|
||||
distFile: "phone-control.js",
|
||||
},
|
||||
{
|
||||
subpath: "qwen-portal-auth",
|
||||
srcFile: "qwen-portal-auth.ts",
|
||||
distFile: "qwen-portal-auth.js",
|
||||
},
|
||||
{
|
||||
subpath: "synology-chat",
|
||||
srcFile: "synology-chat.ts",
|
||||
distFile: "synology-chat.js",
|
||||
},
|
||||
{ subpath: "talk-voice", srcFile: "talk-voice.ts", distFile: "talk-voice.js" },
|
||||
{ subpath: "test-utils", srcFile: "test-utils.ts", distFile: "test-utils.js" },
|
||||
{
|
||||
subpath: "thread-ownership",
|
||||
srcFile: "thread-ownership.ts",
|
||||
distFile: "thread-ownership.js",
|
||||
},
|
||||
{ subpath: "tlon", srcFile: "tlon.ts", distFile: "tlon.js" },
|
||||
{ subpath: "twitch", srcFile: "twitch.ts", distFile: "twitch.js" },
|
||||
{ subpath: "voice-call", srcFile: "voice-call.ts", distFile: "voice-call.js" },
|
||||
{ subpath: "zalo", srcFile: "zalo.ts", distFile: "zalo.js" },
|
||||
{ subpath: "zalouser", srcFile: "zalouser.ts", distFile: "zalouser.js" },
|
||||
{ subpath: "account-id", srcFile: "account-id.ts", distFile: "account-id.js" },
|
||||
{
|
||||
subpath: "keyed-async-queue",
|
||||
srcFile: "keyed-async-queue.ts",
|
||||
distFile: "keyed-async-queue.js",
|
||||
},
|
||||
] as const;
|
||||
const cachedPluginSdkExportedSubpaths = new Map<string, string[]>();
|
||||
|
||||
function listPluginSdkExportedSubpaths(params: { modulePath?: string } = {}): string[] {
|
||||
const modulePath = params.modulePath ?? fileURLToPath(import.meta.url);
|
||||
const packageRoot = resolveOpenClawPackageRootSync({
|
||||
cwd: path.dirname(modulePath),
|
||||
});
|
||||
if (!packageRoot) {
|
||||
return [];
|
||||
}
|
||||
const cached = cachedPluginSdkExportedSubpaths.get(packageRoot);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
try {
|
||||
const pkgRaw = fs.readFileSync(path.join(packageRoot, "package.json"), "utf-8");
|
||||
const pkg = JSON.parse(pkgRaw) as {
|
||||
exports?: Record<string, unknown>;
|
||||
};
|
||||
const subpaths = Object.keys(pkg.exports ?? {})
|
||||
.filter((key) => key.startsWith("./plugin-sdk/"))
|
||||
.map((key) => key.slice("./plugin-sdk/".length))
|
||||
.filter((subpath) => Boolean(subpath) && !subpath.includes("/"))
|
||||
.toSorted();
|
||||
cachedPluginSdkExportedSubpaths.set(packageRoot, subpaths);
|
||||
return subpaths;
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
const resolvePluginSdkScopedAliasMap = (): Record<string, string> => {
|
||||
const aliasMap: Record<string, string> = {};
|
||||
for (const entry of pluginSdkScopedAliasEntries) {
|
||||
for (const subpath of listPluginSdkExportedSubpaths()) {
|
||||
const resolved = resolvePluginSdkAliasFile({
|
||||
srcFile: entry.srcFile,
|
||||
distFile: entry.distFile,
|
||||
srcFile: `${subpath}.ts`,
|
||||
distFile: `${subpath}.js`,
|
||||
});
|
||||
if (resolved) {
|
||||
aliasMap[`openclaw/plugin-sdk/${entry.subpath}`] = resolved;
|
||||
aliasMap[`openclaw/plugin-sdk/${subpath}`] = resolved;
|
||||
}
|
||||
}
|
||||
return aliasMap;
|
||||
@@ -217,6 +159,7 @@ const resolvePluginSdkScopedAliasMap = (): Record<string, string> => {
|
||||
|
||||
export const __testing = {
|
||||
listPluginSdkAliasCandidates,
|
||||
listPluginSdkExportedSubpaths,
|
||||
resolvePluginSdkAliasCandidateOrder,
|
||||
resolvePluginSdkAliasFile,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user