mirror of
http://192.168.0.88:13333/lywsvip/openclaw-zero-token.git
synced 2026-05-08 08:08:33 +08:00
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
107 lines
2.7 KiB
TypeScript
107 lines
2.7 KiB
TypeScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { createJiti } from "jiti";
|
|
import { loadConfig } from "../../config/config.js";
|
|
import { loadPluginManifestRegistry } from "../manifest-registry.js";
|
|
import {
|
|
buildPluginLoaderJitiOptions,
|
|
resolvePluginSdkAliasFile,
|
|
resolvePluginSdkScopedAliasMap,
|
|
shouldPreferNativeJiti,
|
|
} from "../sdk-alias.js";
|
|
|
|
type PluginRuntimeRecord = {
|
|
origin?: string;
|
|
rootDir?: string;
|
|
source: string;
|
|
};
|
|
|
|
export function readPluginBoundaryConfigSafely() {
|
|
try {
|
|
return loadConfig();
|
|
} catch {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
export function resolvePluginRuntimeRecord(
|
|
pluginId: string,
|
|
onMissing?: () => never,
|
|
): PluginRuntimeRecord | null {
|
|
const manifestRegistry = loadPluginManifestRegistry({
|
|
config: readPluginBoundaryConfigSafely(),
|
|
cache: true,
|
|
});
|
|
const record = manifestRegistry.plugins.find((plugin) => plugin.id === pluginId);
|
|
if (!record?.source) {
|
|
if (onMissing) {
|
|
onMissing();
|
|
}
|
|
return null;
|
|
}
|
|
return {
|
|
...(record.origin ? { origin: record.origin } : {}),
|
|
rootDir: record.rootDir,
|
|
source: record.source,
|
|
};
|
|
}
|
|
|
|
export function resolvePluginRuntimeModulePath(
|
|
record: Pick<PluginRuntimeRecord, "rootDir" | "source">,
|
|
entryBaseName: string,
|
|
onMissing?: () => never,
|
|
): string | null {
|
|
const candidates = [
|
|
path.join(path.dirname(record.source), `${entryBaseName}.js`),
|
|
path.join(path.dirname(record.source), `${entryBaseName}.ts`),
|
|
...(record.rootDir
|
|
? [
|
|
path.join(record.rootDir, `${entryBaseName}.js`),
|
|
path.join(record.rootDir, `${entryBaseName}.ts`),
|
|
]
|
|
: []),
|
|
];
|
|
for (const candidate of candidates) {
|
|
if (fs.existsSync(candidate)) {
|
|
return candidate;
|
|
}
|
|
}
|
|
if (onMissing) {
|
|
onMissing();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export function getPluginBoundaryJiti(
|
|
modulePath: string,
|
|
loaders: Map<boolean, ReturnType<typeof createJiti>>,
|
|
) {
|
|
const tryNative = shouldPreferNativeJiti(modulePath);
|
|
const cached = loaders.get(tryNative);
|
|
if (cached) {
|
|
return cached;
|
|
}
|
|
const pluginSdkAlias = resolvePluginSdkAliasFile({
|
|
srcFile: "root-alias.cjs",
|
|
distFile: "root-alias.cjs",
|
|
modulePath,
|
|
});
|
|
const aliasMap = {
|
|
...(pluginSdkAlias ? { "openclaw/plugin-sdk": pluginSdkAlias } : {}),
|
|
...resolvePluginSdkScopedAliasMap({ modulePath }),
|
|
};
|
|
const loader = createJiti(import.meta.url, {
|
|
...buildPluginLoaderJitiOptions(aliasMap),
|
|
tryNative,
|
|
});
|
|
loaders.set(tryNative, loader);
|
|
return loader;
|
|
}
|
|
|
|
export function loadPluginBoundaryModuleWithJiti<TModule>(
|
|
modulePath: string,
|
|
loaders: Map<boolean, ReturnType<typeof createJiti>>,
|
|
): TModule {
|
|
return getPluginBoundaryJiti(modulePath, loaders)(modulePath) as TModule;
|
|
}
|