UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

4 lines • 3.05 kB
import{t as formatErrorMessage}from"./errors-D37BJTfI.mjs";import{i as getPluginInstance}from"./plugin-instance-scope-Bx-frH07.mjs";import{d as getActivePluginRegistryVersion}from"./runtime-Cl6PvJHC.mjs";import{i as getPluginRuntimeEntrySource}from"./plugin-runtime-artifact-binding-_oNTmROe.mjs";import{r as resolveBundledPluginDevReloadMode,t as formatBundledPluginDevReloadWarning}from"./bundled-plugin-dev-reload-2AIcDcus.mjs"; //!src/plugins/lifecycle.ts const getPluginRuntimeGeneration=getActivePluginRegistryVersion;var PluginInstallPersistedError=class extends Error{constructor(e,t){super(`${formatErrorMessage(t)} Plugin "${e}" installation is saved. Fix the reported issue, then run \`openclaw plugins reload ${e}\`.`,{cause:t});this.pluginId=e;this.name=`PluginInstallPersistedError`}};var PluginRuntimeApplicationError=class extends Error{constructor(e,t,n){super(`${e}\nGateway generation ${t.generation}: replacement ${t.committed?`applied`:`not applied`}.`,n);this.details=t;this.name=`PluginRuntimeApplicationError`}};function createPluginRuntimeApplication(e){const t=/* @__PURE__ */ new Map;const n=/* @__PURE__ */ new Map;const r=/* @__PURE__ */ new Set;const i=/* @__PURE__ */ new Set;for(const a of e.registry.plugins){if(!e.pluginIds.has(a.id))continue;const o=getPluginInstance(a);const s=getPluginRuntimeEntrySource(a);if(o&&a.status===`loaded`&&s)n.set(a.id,s);if(o?.sourceDigest)t.set(a.id,o.sourceDigest);if(e.reloadPluginIds?.has(a.id)&&a.enabled&&a.status===`loaded`&&o&&a.origin===`bundled`){if(o.sourceDigest){i.add(formatBundledPluginDevReloadWarning(a.id));continue}r.add(`Bundled plugin code is owned by the running Gateway. Restart the Gateway to load updated code; rebuild first when using compiled output.`);const e=resolveBundledPluginDevReloadMode().ignoredWarning;if(e)r.add(e)}}const a=[...r,...i,...e.warnings];return{operationId:e.operationId,generation:e.generation,pluginIds:[...e.pluginIds].toSorted(),sourceDigests:Object.fromEntries(t),selectedEntries:Object.fromEntries(n),...r.size?{restartRequired:true}:{},...a.length?{warnings:a}:{}}}function capturePluginRuntimeApplications(e){let t;return{get application(){return t},applyRuntime:async n=>{const r=await e(n);const i=[.../* @__PURE__ */ new Set([...t?.warnings??[],...r.warnings??[]])];t=i.length?{...r,warnings:i}:r;return t}}}function projectPluginRuntimeFailure(e,t){const n=e instanceof PluginInstallPersistedError?e:void 0;const r=n?n.cause:e;const i=r instanceof PluginRuntimeApplicationError?r.details:void 0;const a=t&&!i?.committed?t:void 0;return{message:formatErrorMessage(r)+(a?`\nAn earlier runtime change from this operation was applied in Gateway generation ${a.generation}.`:``),runtime:a?{...a,committed:true}:i,...a&&i?{runtimeAttempt:i}:{},...n?{persistence:{operation:`install`,pluginId:n.pluginId}}:{}}}export{getPluginRuntimeGeneration as a,createPluginRuntimeApplication as i,PluginRuntimeApplicationError as n,projectPluginRuntimeFailure as o,capturePluginRuntimeApplications as r,PluginInstallPersistedError as t};