UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

135 lines (134 loc) • 5.45 kB
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs"; import { n as describeRootFileOpenFailure, o as openRootFileSync } from "./boundary-file-read-BfaFLDqt.mjs"; import { m as resolvePluginRuntimeExecutionArtifact } from "./bundled-dir-BKvdAqkP.mjs"; import { u as normalizePluginsConfig } from "./config-state-B1JlHgba.mjs"; import { t as shouldRejectHardlinkedPluginFiles } from "./hardlink-policy-Kq1Lxk7_.mjs"; import { t as getCachedPluginModuleLoader } from "./plugin-module-loader-cache-DgNX_BTY.mjs"; import { n as isActivatedManifestOwner, r as isBundledManifestOwner, t as hasExplicitManifestOwnerTrust } from "./manifest-owner-policy-B8Brw4Zo.mjs"; import { f as resolveConfiguredChannelPluginIds } from "./channel-presence-policy-6XNqNGJr.mjs"; import { f as resolvePluginRuntimeArtifact } from "./plugin-setup-module-D_W6TtnO.mjs"; import { t as createEmptyPluginRegistry } from "./registry-empty-Cv4VTWYA.mjs"; import { n as unwrapDefaultModuleExport } from "./module-export-DTZ89pa-.mjs"; import "./channel-plugin-ids-DZDzcpUB.mjs"; import { t as resolvePluginRuntimeLoadContext } from "./load-context.resolve-D0f_6L5E.mjs"; import { t as shouldIncludeChannelSetupFeatureForConfig } from "./bundled-setup-policy-aGGzBRJW.mjs"; import { t as EMPTY_LEGACY_SESSION_SURFACES } from "./legacy-session-surfaces.types-BmAZdMse.mjs"; import fs from "node:fs"; //#region src/plugins/legacy-session-surfaces.ts function formatLoadFailure(e, t) { return `Deferred legacy session-key migration for channel owner "${e}": ${t}. Restore or reinstall the plugin setup entry, then rerun openclaw doctor --fix`; } function resolveLegacySessionSurface(e) { const t = unwrapDefaultModuleExport(e); if (!t || typeof t !== "object") throw new Error("setup entry does not export loadLegacySessionSurface"); const n = t; if (n.kind !== "bundled-channel-setup-entry" || typeof n.loadLegacySessionSurface !== "function") throw new Error("setup entry does not export loadLegacySessionSurface"); const r = n.loadLegacySessionSurface(); if (!isRecord(r)) throw new Error("legacy session surface must be an object"); const i = r.isLegacyGroupSessionKey; const a = r.canonicalizeLegacySessionKey; if (i !== void 0 && typeof i !== "function" || typeof a !== "function") throw new Error("legacy session surface must declare canonicalizeLegacySessionKey"); return r; } function isEnabledLegacySurfaceOwner(e) { if (!shouldIncludeChannelSetupFeatureForConfig({ plugin: e.record, config: e.config, normalizedConfig: e.normalizedConfig })) return false; if (isBundledManifestOwner(e.record)) return true; if (e.record.origin === "global" || e.record.origin === "config") return hasExplicitManifestOwnerTrust({ plugin: e.record, normalizedConfig: e.normalizedConfig }); return isActivatedManifestOwner({ plugin: e.record, normalizedConfig: e.normalizedConfig, rootConfig: e.config }); } function loadLegacySessionSurface(e) { const { source: t, rootDir: n } = resolvePluginRuntimeExecutionArtifact(resolvePluginRuntimeArtifact({ pluginId: e.record.id, entryKind: "setup", source: e.setupSource, rootDir: e.record.rootDir, origin: e.record.origin, preferBuiltPluginArtifacts: false, packageManifest: e.record.packageManifest, registry: e.artifactRegistry })); const r = openRootFileSync({ absolutePath: t, rootPath: n, boundaryLabel: "plugin root", rejectHardlinks: shouldRejectHardlinkedPluginFiles({ origin: e.record.origin, rootDir: e.record.rootDir, env: e.env }), skipLexicalRootCheck: true }); if (!r.ok) throw new Error(describeRootFileOpenFailure({ failure: r, subject: "plugin setup entry path", boundaryLabel: "plugin root", filePath: t })); const i = r.path; fs.closeSync(r.fd); return resolveLegacySessionSurface(getCachedPluginModuleLoader({ modulePath: i, importerUrl: import.meta.url, loaderFilename: import.meta.url })(i)); } /** Resolves immutable session surfaces from the exact configured channel-owner snapshot. */ function prepareLegacySessionSurfaces(e) { const t = resolvePluginRuntimeLoadContext({ config: e.config, env: e.env }); const n = (t.manifestRegistry?.plugins ?? []).filter((e) => e.packageManifest?.setupFeatures?.legacySessionSurfaces === true); const r = normalizePluginsConfig(t.activationSourceConfig.plugins); let i; const a = n.filter((e) => { if (isEnabledLegacySurfaceOwner({ record: e, config: t.activationSourceConfig, normalizedConfig: r })) return true; i ??= new Set(resolveConfiguredChannelPluginIds({ config: t.config, activationSourceConfig: t.activationSourceConfig, workspaceDir: t.workspaceDir, env: t.env, manifestRecords: n })); return i.has(e.id); }); if (a.length === 0) return EMPTY_LEGACY_SESSION_SURFACES; const o = a.flatMap((e) => e.setupSource ? [] : [formatLoadFailure(e.id, "package metadata declares the surface but has no setupEntry")]); const s = []; const c = createEmptyPluginRegistry(); for (const e of a) { if (!e.setupSource) continue; try { s.push(loadLegacySessionSurface({ record: e, setupSource: e.setupSource, env: t.env, artifactRegistry: c })); } catch (t) { const n = t instanceof Error ? t.message : String(t); o.push(formatLoadFailure(e.id, n)); } } return Object.freeze({ surfaces: Object.freeze(s), failures: Object.freeze(o) }); } //#endregion export { prepareLegacySessionSurfaces };