openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
9 lines • 8.44 kB
JavaScript
import{a as normalizeOptionalString,n as normalizeLowercaseStringOrEmpty}from"./string-coerce-BBqv4GXj.mjs";import{d as normalizeUniqueTrimmedStringList}from"./string-normalization-mfgVoo8i.mjs";import{a as parseOpenClawReleaseVersion,r as isOpenClawCorrectionSemver}from"./semver-OLQE-AMj.mjs";import{t as BUNDLED_OFFICIAL_EXTERNAL_PLUGIN_CATALOG_ENTRIES}from"./official-external-plugin-bundled-catalogs-8wb6D0XI.mjs";import{a as getFeedEntryInstallCandidateRecords,h as resolveOfficialExternalPluginId,m as resolveOfficialExternalPluginCatalogProfileConfig,o as getOfficialExternalPluginCatalogManifest,p as resolveOfficialExternalPluginCatalogEntryKey,s as hasKnownCatalogSourceRef,t as DEFAULT_OFFICIAL_EXTERNAL_PLUGIN_CATALOG_PROFILE_CONFIG}from"./official-external-plugin-catalog-source-nSZUCd66.mjs";import{parse,prerelease,valid}from"semver";
//!src/infra/npm-registry-spec.ts
const DIST_TAG_RE=/^[A-Za-z0-9][A-Za-z0-9._-]*$/;function parseRegistryNpmSpecResult(e){const t=e.trim();if(!t)return{ok:false,error:`missing npm spec`};if(/\s/.test(t))return{ok:false,error:`unsupported npm spec: whitespace is not allowed`};if(t.includes(`://`))return{ok:false,error:`unsupported npm spec: URLs are not allowed`};if(t.includes(`#`))return{ok:false,error:`unsupported npm spec: git refs are not allowed`};if(t.includes(`:`))return{ok:false,error:`unsupported npm spec: protocol specs are not allowed`};const n=t.lastIndexOf(`@`);const r=n>0;const i=r?t.slice(0,n):t;const a=r?t.slice(n+1):``;if(!(i.startsWith(`@`)?/^@[a-z0-9][a-z0-9-._~]*\/[a-z0-9][a-z0-9-._~]*$/.test(i):/^[a-z0-9][a-z0-9-._~]*$/.test(i)))return{ok:false,error:`unsupported npm spec: expected <name> or <name>@<version> from the npm registry`};let o=null;if(r){if(!a)return{ok:false,error:`unsupported npm spec: missing version/tag after @`};if(/[\\/]/.test(a))return{ok:false,error:`unsupported npm spec: invalid version/tag`};o=valid(a);if(!o&&!DIST_TAG_RE.test(a))return{ok:false,error:`unsupported npm spec: use an exact version or dist-tag (ranges are not allowed)`}}return{ok:true,parsed:{name:i,raw:t,...r?{selector:a}:{},selectorKind:!r?`none`:o?`exact-version`:`tag`,selectorIsPrerelease:o!==null&&prerelease(o)!==null&&!isOpenClawStableCorrectionVersion(a)}}}function parseRegistryNpmSpec(e){const t=parseRegistryNpmSpecResult(e);return t.ok?t.parsed:null}function isOpenClawStableCorrectionVersion(e){const t=parseOpenClawReleaseVersion(e);return t!==null&&isOpenClawCorrectionSemver(t)}function isPrereleaseSemverVersion(e){const t=e.trim();return prerelease(t)!==null&&!isOpenClawStableCorrectionVersion(t)}function isPrereleaseResolutionAllowed(e){if(!e.resolvedVersion||!isPrereleaseSemverVersion(e.resolvedVersion))return true;if(e.spec.selectorKind===`none`)return false;if(e.spec.selectorKind===`exact-version`)return e.spec.selectorIsPrerelease;return normalizeLowercaseStringOrEmpty(e.spec.selector)!==`latest`}
//!src/infra/clawhub-integrity.ts
function normalizeClawHubSha256Integrity(e){const t=e.trim();if(!t)return null;const n=/^sha256-([A-Za-z0-9+/]+={0,1})$/.exec(t);if(n?.[1]){try{const e=Buffer.from(n[1],`base64`);if(e.length===32)return`sha256-${e.toString(`base64`)}`}catch{return null}return null}const r=/^(?:sha256:)?([A-Fa-f0-9]{64})$/.exec(t)?.[1];return r?`sha256-${Buffer.from(r,`hex`).toString(`base64`)}`:null}
//!src/plugins/plugin-install-default-choice.ts
function normalizePluginInstallDefaultChoice(e){return e===`clawhub`||e===`npm`||e===`local`?e:void 0}
//!src/plugins/official-external-plugin-catalog.ts
function getFeedEntryInstallCandidates(e){return normalizeOptionalString(e.state)===`available`&&normalizeOptionalString(e.publisher?.trust)===`official`?getFeedEntryInstallCandidateRecords(e):[]}const BUNDLED_CATALOG_SOURCE_REFS=new Set(Object.keys(DEFAULT_OFFICIAL_EXTERNAL_PLUGIN_CATALOG_PROFILE_CONFIG.sources??{}));function prepareBundledOfficialExternalPluginCatalog(){const e=/* @__PURE__ */ new Set;const t=[];const n=/* @__PURE__ */ new Map;const r=/* @__PURE__ */ new Map;const i=/* @__PURE__ */ new Set;for(const a of BUNDLED_OFFICIAL_EXTERNAL_PLUGIN_CATALOG_ENTRIES){if(getFeedEntryInstallCandidateRecords(a).some(e=>!hasKnownCatalogSourceRef(e,BUNDLED_CATALOG_SOURCE_REFS)))continue;const o=resolveOfficialExternalPluginCatalogEntryKey(a);if(o&&!e.has(o)){e.add(o);t.push(a);for(const e of resolveOfficialExternalPluginLookupIds(a))if(!n.has(e))n.set(e,a);const s=normalizeOptionalString(a.name);if(s&&!r.has(s))r.set(s,a);const c=resolveOfficialExternalPluginId(a)?.toLowerCase();if(c)i.add(c)}}return{entries:t,byId:n,byPackage:r,canonicalIds:i}}let bundledCatalog;function getBundledOfficialExternalPluginCatalog(){return bundledCatalog??=prepareBundledOfficialExternalPluginCatalog()}function formatFeedInstallCandidateSpec(e){const t=normalizeOptionalString(e.package);if(!t)return;const n=normalizeOptionalString(e.version);if(!n||t.endsWith(`@${n}`))return t;return`${t}@${n}`}function getFeedEntryCandidateSourceType(e,t){const n=normalizeOptionalString(e.sourceRef);if(!n)return;return resolveOfficialExternalPluginCatalogProfileConfig(t).sources[n]?.type}function resolveFeedEntryInstallSources(e){const t=getFeedEntryInstallCandidates(e.entry);return[`npm`,`clawhub`].flatMap(n=>{const r=t.find(t=>getFeedEntryCandidateSourceType(t,e.catalogConfig)===n&&Boolean(normalizeOptionalString(t.package)));const i=r&&formatFeedInstallCandidateSpec(r);if(!r||!i)return[];const a=n===`npm`?normalizeNpmExpectedIntegrity(r.integrity):normalizeClawHubSha256ExpectedIntegrity(r.integrity);return[{source:n,spec:n===`clawhub`?`clawhub:${i}`:i,...a?{expectedIntegrity:a}:{}}]})}function resolveFeedEntryInstallCandidate(e){const t=resolveFeedEntryInstallSources(e)[0];return t?{...t.source===`npm`?{npmSpec:t.spec}:{clawhubSpec:t.spec},defaultChoice:t.source,...t.expectedIntegrity?{expectedIntegrity:t.expectedIntegrity}:{}}:null}function normalizeClawHubSha256ExpectedIntegrity(e){const t=normalizeOptionalString(e);return t?normalizeClawHubSha256Integrity(t)??void 0:void 0}function normalizeNpmExpectedIntegrity(e){const t=normalizeOptionalString(e);if(!t||!/^[a-z0-9]+-[A-Za-z0-9+/=]+$/i.test(t))return;return t}function resolveOfficialExternalPluginLegacyIds(e){return normalizeUniqueTrimmedStringList(getOfficialExternalPluginCatalogManifest(e)?.legacyPluginIds)}function resolveOfficialExternalPluginLookupIds(e){const t=getOfficialExternalPluginCatalogManifest(e);const n=[t?.plugin?.id,t?.channel?.id];for(const e of t?.providers??[])n.push(e.id,...e.aliases??[]);return normalizeUniqueTrimmedStringList(n)}function resolveOfficialExternalPluginInstall(e,t){const n=normalizeOptionalString(e.state);const r=normalizeOptionalString(e.publisher?.trust);if((n||r)&&(n!==`available`||r!==`official`))return null;const i=getOfficialExternalPluginCatalogManifest(e)?.install;const a=normalizeOptionalString(i?.clawhubSpec);const o=normalizeOptionalString(i?.npmSpec);const s=normalizeOptionalString(i?.localPath);const c=resolveFeedEntryInstallCandidate({entry:e,catalogConfig:t?.catalogConfig});if(c)return{...c,...i?.minHostVersion?{minHostVersion:i.minHostVersion}:{},...i?.allowInvalidConfigRecovery===true?{allowInvalidConfigRecovery:true}:{}};const l=getFeedEntryInstallCandidateRecords(e).length>0;const u=o??(l||a?void 0:normalizeOptionalString(e.name));const d=normalizePluginInstallDefaultChoice(i?.defaultChoice)??(u?`npm`:a?`clawhub`:s?`local`:void 0);if(!a&&!u&&!s)return null;return{...a?{clawhubSpec:a}:{},...u?{npmSpec:u}:{},...s?{localPath:s}:{},...d?{defaultChoice:d}:{},...i?.minHostVersion?{minHostVersion:i.minHostVersion}:{},...i?.expectedIntegrity?{expectedIntegrity:i.expectedIntegrity}:{},...i?.allowInvalidConfigRecovery===true?{allowInvalidConfigRecovery:true}:{}}}function listOfficialExternalPluginCatalogEntries(){return[...getBundledOfficialExternalPluginCatalog().entries]}function getOfficialExternalPluginCatalogEntry(e){const t=e.trim();if(!t)return;return getBundledOfficialExternalPluginCatalog().byId.get(t)}function getOfficialExternalPluginCatalogEntryForPackage(e){const t=e?.trim();if(!t)return;return getBundledOfficialExternalPluginCatalog().byPackage.get(t)}export{resolveOfficialExternalPluginLegacyIds as a,resolveOfficialExternalPluginInstall as i,getOfficialExternalPluginCatalogEntryForPackage as n,isPrereleaseResolutionAllowed as o,listOfficialExternalPluginCatalogEntries as r,parseRegistryNpmSpec as s,getOfficialExternalPluginCatalogEntry as t};