UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

85 lines (84 loc) • 3.42 kB
import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import { r as getPluginInstance } from "./plugin-instance-scope-oezVdCr2.mjs"; import { d as getActivePluginRegistryVersion } from "./runtime-ezCEpumg.mjs"; import { i as getPluginRuntimeEntrySource } from "./plugin-runtime-artifact-binding-BHK81c8H.mjs"; //#region src/plugins/lifecycle.ts const getPluginRuntimeGeneration = getActivePluginRegistryVersion; /** Carries the install persistence owner’s durable-commit fact, including across RPC. */ 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"; } }; /** Project the published registry's captured-code facts into its application receipt. */ function createPluginRuntimeApplication(e) { const t = /* @__PURE__ */ new Map(); const n = /* @__PURE__ */ new Map(); const r = /* @__PURE__ */ new Set(); for (const i of e.registry.plugins) { if (!e.pluginIds.has(i.id)) continue; const a = getPluginInstance(i); const o = getPluginRuntimeEntrySource(i); if (a && i.status === "loaded" && o) n.set(i.id, o); if (a?.sourceDigest) t.set(i.id, a.sourceDigest); if (e.reloadPluginIds?.has(i.id) && i.enabled && i.status === "loaded" && a && i.origin === "bundled") 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 i = [...r, ...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 } : {}, ...i.length ? { warnings: i } : {} }; } /** Capture publications independently of later management or authority failures. */ 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 } } : {} }; } //#endregion export { getPluginRuntimeGeneration as a, createPluginRuntimeApplication as i, PluginRuntimeApplicationError as n, projectPluginRuntimeFailure as o, capturePluginRuntimeApplications as r, PluginInstallPersistedError as t };