openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.55 kB
JavaScript
import{f as shortenHomePath}from"./utils-Dlk0IYAa.mjs";import{fileURLToPath}from"node:url";
//!src/plugins/install-source-spec.ts
function resolveFileNpmSpecToLocalPath(e){const t=e.trim();if(!t.toLowerCase().startsWith(`file:`))return null;const n=t.slice(5);if(!n)return{ok:false,error:`unsupported file: spec: missing path`};if(n.startsWith(`///`)||n.startsWith(`//localhost/`))try{decodeURIComponent(new URL(t).pathname);return{ok:true,path:fileURLToPath(t)}}catch{return{ok:false,error:`unsupported file: URL: invalid local path`}}if(n.startsWith(`//`))return{ok:false,error:`unsupported file: URL host (expected "file:<path>" or "file:///abs/path")`};return{ok:true,path:n}}function parseNpmPrefixSpec(e){const t=e.trim();if(!t.toLowerCase().startsWith(`npm:`))return null;return t.slice(4).trim()}function parseNpmPackPrefixPath(e){const t=e.trim();if(!t.toLowerCase().startsWith(`npm-pack:`))return null;return t.slice(9).trim()}function isBareNpmPackageName(e){return/^[a-z0-9][a-z0-9-._~]*$/.test(e.trim())}function resolveBundledInstallPlanBeforeNpm(e){const t=e.rawSpec.trim();if(!isBareNpmPackageName(t))return null;const n=e.findBundledSource({kind:`pluginId`,value:t});return n?{bundledSource:n,warning:`Using bundled plugin "${n.pluginId}" from ${shortenHomePath(n.localPath)} for bare install spec "${t}". To select a registry explicitly, use clawhub:${t} or npm:${t}.`}:null}export{resolveFileNpmSpecToLocalPath as a,resolveBundledInstallPlanBeforeNpm as i,parseNpmPackPrefixPath as n,parseNpmPrefixSpec as r,isBareNpmPackageName as t};