mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-26 01:11:37 +00:00
feat!: prefer clawhub plugin installs before npm
This commit is contained in:
@@ -289,6 +289,26 @@ function logSlotWarnings(warnings: string[]) {
|
||||
}
|
||||
}
|
||||
|
||||
function buildPreferredClawHubSpec(raw: string): string | null {
|
||||
const parsed = parseRegistryNpmSpec(raw);
|
||||
if (!parsed) {
|
||||
return null;
|
||||
}
|
||||
return formatClawHubSpecifier({
|
||||
name: parsed.name,
|
||||
version: parsed.selector,
|
||||
});
|
||||
}
|
||||
|
||||
function shouldFallbackFromClawHubToNpm(error: string): boolean {
|
||||
const normalized = error.trim();
|
||||
return (
|
||||
/Package not found on ClawHub/i.test(normalized) ||
|
||||
/ClawHub .* failed \(404\)/i.test(normalized) ||
|
||||
/Version not found/i.test(normalized)
|
||||
);
|
||||
}
|
||||
|
||||
async function installBundledPluginSource(params: {
|
||||
config: OpenClawConfig;
|
||||
rawSpec: string;
|
||||
@@ -545,6 +565,46 @@ async function runPluginInstallCommand(params: {
|
||||
return;
|
||||
}
|
||||
|
||||
const preferredClawHubSpec = buildPreferredClawHubSpec(raw);
|
||||
if (preferredClawHubSpec) {
|
||||
const clawhubResult = await installPluginFromClawHub({
|
||||
spec: preferredClawHubSpec,
|
||||
logger: createPluginInstallLogger(),
|
||||
});
|
||||
if (clawhubResult.ok) {
|
||||
clearPluginManifestRegistryCache();
|
||||
|
||||
let next = enablePluginInConfig(cfg, clawhubResult.pluginId).config;
|
||||
next = recordPluginInstall(next, {
|
||||
pluginId: clawhubResult.pluginId,
|
||||
source: "clawhub",
|
||||
spec: formatClawHubSpecifier({
|
||||
name: clawhubResult.clawhub.clawhubPackage,
|
||||
version: clawhubResult.clawhub.version,
|
||||
}),
|
||||
installPath: clawhubResult.targetDir,
|
||||
version: clawhubResult.version,
|
||||
integrity: clawhubResult.clawhub.integrity,
|
||||
resolvedAt: clawhubResult.clawhub.resolvedAt,
|
||||
clawhubUrl: clawhubResult.clawhub.clawhubUrl,
|
||||
clawhubPackage: clawhubResult.clawhub.clawhubPackage,
|
||||
clawhubFamily: clawhubResult.clawhub.clawhubFamily,
|
||||
clawhubChannel: clawhubResult.clawhub.clawhubChannel,
|
||||
});
|
||||
const slotResult = applySlotSelectionForPlugin(next, clawhubResult.pluginId);
|
||||
next = slotResult.config;
|
||||
await writeConfigFile(next);
|
||||
logSlotWarnings(slotResult.warnings);
|
||||
defaultRuntime.log(`Installed plugin: ${clawhubResult.pluginId}`);
|
||||
defaultRuntime.log(`Restart the gateway to load plugins.`);
|
||||
return;
|
||||
}
|
||||
if (!shouldFallbackFromClawHubToNpm(clawhubResult.error)) {
|
||||
defaultRuntime.error(clawhubResult.error);
|
||||
return defaultRuntime.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
const result = await installPluginFromNpmSpec({
|
||||
spec: raw,
|
||||
logger: createPluginInstallLogger(),
|
||||
|
||||
Reference in New Issue
Block a user