mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-22 14:41:34 +00:00
test: reduce media contract import cost
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
70ecd040dd5815b237eb749db2de98e300fd53630e5b418deea0865b781adf4a plugin-sdk-api-baseline.json
|
||||
7a7b08495662e48d466a1c7cb20d6e81557df05d361de0bebc54369e34dffa35 plugin-sdk-api-baseline.jsonl
|
||||
8a754603a721c3816772a0a4f44b83a19547163ad52ff1b9f18eaaeeaf0de6d4 plugin-sdk-api-baseline.json
|
||||
40539cf99459c77dab1d6e72af2e3f05cafb77f2c49af5fa210c78dc231592b4 plugin-sdk-api-baseline.jsonl
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { mergeInboundPathRoots } from "openclaw/plugin-sdk/channel-inbound";
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime";
|
||||
import { mergeInboundPathRoots } from "openclaw/plugin-sdk/media-runtime";
|
||||
import { resolveIMessageAccount } from "./accounts.js";
|
||||
|
||||
export const DEFAULT_IMESSAGE_ATTACHMENT_ROOTS = ["/Users/*/Library/Messages/Attachments"] as const;
|
||||
|
||||
@@ -50,3 +50,4 @@ export type { NormalizedLocation } from "../channels/location.js";
|
||||
export { formatLocationText, toLocationContext } from "../channels/location.js";
|
||||
export { logInboundDrop } from "../channels/logging.js";
|
||||
export { resolveInboundSessionEnvelopeContext } from "../channels/session-envelope.js";
|
||||
export { mergeInboundPathRoots } from "../media/inbound-path-policy.js";
|
||||
|
||||
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { loadBundledPluginPublicSurfaceModuleSync } from "../plugin-sdk/facade-loader.js";
|
||||
import { resolveBundledPluginsDir } from "../plugins/bundled-dir.js";
|
||||
import {
|
||||
findBundledPluginMetadataById,
|
||||
type BundledPluginMetadata,
|
||||
@@ -15,8 +16,49 @@ const OPENCLAW_PACKAGE_ROOT =
|
||||
moduleUrl: import.meta.url,
|
||||
}) ?? fileURLToPath(new URL("../..", import.meta.url));
|
||||
|
||||
function findBundledPluginMetadata(pluginId: string): BundledPluginMetadata {
|
||||
const metadata = findBundledPluginMetadataById(pluginId);
|
||||
type BundledPluginPublicSurfaceMetadata = Pick<BundledPluginMetadata, "dirName">;
|
||||
|
||||
function isSafeBundledPluginDirName(pluginId: string): boolean {
|
||||
return /^[a-z0-9][a-z0-9._-]*$/u.test(pluginId);
|
||||
}
|
||||
|
||||
function readPluginManifestId(pluginDir: string): string | undefined {
|
||||
try {
|
||||
const manifestPath = path.join(pluginDir, "openclaw.plugin.json");
|
||||
const parsed = JSON.parse(fs.readFileSync(manifestPath, "utf-8")) as { id?: unknown };
|
||||
return typeof parsed.id === "string" ? parsed.id : undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function findBundledPluginMetadataFast(
|
||||
pluginId: string,
|
||||
): BundledPluginPublicSurfaceMetadata | undefined {
|
||||
if (!isSafeBundledPluginDirName(pluginId)) {
|
||||
return undefined;
|
||||
}
|
||||
const roots = [
|
||||
resolveBundledPluginsDir(),
|
||||
path.resolve(OPENCLAW_PACKAGE_ROOT, "extensions"),
|
||||
path.resolve(OPENCLAW_PACKAGE_ROOT, "dist-runtime", "extensions"),
|
||||
path.resolve(OPENCLAW_PACKAGE_ROOT, "dist", "extensions"),
|
||||
].filter(
|
||||
(entry, index, values): entry is string => Boolean(entry) && values.indexOf(entry) === index,
|
||||
);
|
||||
|
||||
for (const root of roots) {
|
||||
const pluginDir = path.join(root, pluginId);
|
||||
if (readPluginManifestId(pluginDir) === pluginId) {
|
||||
return { dirName: pluginId };
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function findBundledPluginMetadata(pluginId: string): BundledPluginPublicSurfaceMetadata {
|
||||
const metadata =
|
||||
findBundledPluginMetadataFast(pluginId) ?? findBundledPluginMetadataById(pluginId);
|
||||
if (!metadata) {
|
||||
throw new Error(`Unknown bundled plugin id: ${pluginId}`);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { loadBundledPluginContractApiSync } from "../../../src/test-utils/bundled-plugin-public-surface.js";
|
||||
import { resolveRelativeBundledPluginPublicModuleId } from "../../../src/test-utils/bundled-plugin-public-surface.js";
|
||||
|
||||
type IMessageContractSurface = typeof import("@openclaw/imessage/contract-api.js");
|
||||
|
||||
@@ -6,7 +6,13 @@ const {
|
||||
DEFAULT_IMESSAGE_ATTACHMENT_ROOTS,
|
||||
resolveIMessageAttachmentRoots,
|
||||
resolveIMessageRemoteAttachmentRoots,
|
||||
} = loadBundledPluginContractApiSync<IMessageContractSurface>("imessage");
|
||||
} = (await import(
|
||||
resolveRelativeBundledPluginPublicModuleId({
|
||||
fromModuleUrl: import.meta.url,
|
||||
pluginId: "imessage",
|
||||
artifactBasename: "contract-api.js",
|
||||
})
|
||||
)) as IMessageContractSurface;
|
||||
|
||||
export {
|
||||
DEFAULT_IMESSAGE_ATTACHMENT_ROOTS,
|
||||
|
||||
Reference in New Issue
Block a user