mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 03:23:42 +00:00
fix(plugins): fallback bundled channel specs when npm install returns 404 (#12849)
* plugins: add bundled source resolver * plugins: add bundled source resolver tests * cli: fallback npm 404 plugin installs to bundled sources * plugins: use bundled source resolver during updates * protocol: regenerate macos gateway swift models * protocol: regenerate shared swift models * Revert "protocol: regenerate shared swift models" This reverts commit6a2b08c47d. * Revert "protocol: regenerate macos gateway swift models" This reverts commit27c03010c6.
This commit is contained in:
59
src/plugins/bundled-sources.ts
Normal file
59
src/plugins/bundled-sources.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { discoverOpenClawPlugins } from "./discovery.js";
|
||||
import { loadPluginManifest } from "./manifest.js";
|
||||
|
||||
export type BundledPluginSource = {
|
||||
pluginId: string;
|
||||
localPath: string;
|
||||
npmSpec?: string;
|
||||
};
|
||||
|
||||
export function resolveBundledPluginSources(params: {
|
||||
workspaceDir?: string;
|
||||
}): Map<string, BundledPluginSource> {
|
||||
const discovery = discoverOpenClawPlugins({ workspaceDir: params.workspaceDir });
|
||||
const bundled = new Map<string, BundledPluginSource>();
|
||||
|
||||
for (const candidate of discovery.candidates) {
|
||||
if (candidate.origin !== "bundled") {
|
||||
continue;
|
||||
}
|
||||
const manifest = loadPluginManifest(candidate.rootDir);
|
||||
if (!manifest.ok) {
|
||||
continue;
|
||||
}
|
||||
const pluginId = manifest.manifest.id;
|
||||
if (bundled.has(pluginId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const npmSpec =
|
||||
candidate.packageManifest?.install?.npmSpec?.trim() ||
|
||||
candidate.packageName?.trim() ||
|
||||
undefined;
|
||||
|
||||
bundled.set(pluginId, {
|
||||
pluginId,
|
||||
localPath: candidate.rootDir,
|
||||
npmSpec,
|
||||
});
|
||||
}
|
||||
|
||||
return bundled;
|
||||
}
|
||||
|
||||
export function findBundledPluginByNpmSpec(params: {
|
||||
spec: string;
|
||||
workspaceDir?: string;
|
||||
}): BundledPluginSource | undefined {
|
||||
const targetSpec = params.spec.trim();
|
||||
if (!targetSpec) {
|
||||
return undefined;
|
||||
}
|
||||
const bundled = resolveBundledPluginSources({ workspaceDir: params.workspaceDir });
|
||||
for (const source of bundled.values()) {
|
||||
if (source.npmSpec === targetSpec) {
|
||||
return source;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user