openclaw/src/plugins/bundled-sources.ts
Vincent Koc cf311978ea
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 commit 6a2b08c47d2636610efbf16fc210d4114b05b4b4.

* Revert "protocol: regenerate macos gateway swift models"

This reverts commit 27c03010c6b9da07b404c93cdb0a1c2a3db671f5.
2026-02-26 08:06:54 -05:00

60 lines
1.5 KiB
TypeScript

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;
}