UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

102 lines (101 loc) • 3.89 kB
import { r as resolveStateDir } from "./state-dir-DiG0gXzD.mjs"; import { o as getPluginRuntimeGatewayRequestScope } from "./gateway-request-scope-BvvDhs5D.mjs"; import { O as tryResolveAmbientOwnerAgentId, f as resolveAgentWorkspaceDir } from "./agent-scope-config-DmXgFGKP.mjs"; import { a as getPluginCache, w as withPluginCache } from "./plugin-cache-B_eRuqTM.mjs"; import { r as cloneEnvWithPlatformSemantics } from "./config-env-vars-ByeGN-9N.mjs"; import { n as prepareBundledDiscoveryMode } from "./bundled-discovery-state-Bb0zCvZZ.mjs"; import { i as preparePersistedInstalledPluginIndexCacheEntry } from "./installed-plugin-index-record-state-euCqi7PU.mjs"; import { h as resolveDiscoverableScopedChannelPluginIds } from "./channel-presence-policy-6XNqNGJr.mjs"; import "./agent-scope-BwB8YH6y.mjs"; import { l as getActivePluginRegistry } from "./runtime-ezCEpumg.mjs"; import "./channel-plugin-ids-DZDzcpUB.mjs"; import { t as applyPluginAutoEnable } from "./plugin-auto-enable-CPcwS2II.mjs"; import { n as withActivatedPluginIds } from "./activation-context-CKtX_5VQ.mjs"; import { n as loadPluginRegistryHandle } from "./loader--j41eir2.mjs"; //#region src/infra/outbound/channel-bootstrap.runtime.ts function resolveSendCapableRegistry(e, t) { const n = e?.channels?.find((e) => e?.plugin?.id === t); return e && (n?.plugin?.outbound?.sendText ?? n?.plugin?.message?.send?.text) ? e : void 0; } function resolveBootstrapPlan(e) { const t = e.cfg; if (!t) return { kind: "resolved", registry: void 0 }; const n = getPluginRuntimeGatewayRequestScope()?.pluginRegistry; const r = resolveSendCapableRegistry(n?.channels?.find((t) => t?.plugin?.id === e.channel) ? n : getActivePluginRegistry(), e.channel); if (r) return { kind: "resolved", registry: r }; return { kind: "cold", cfg: t, agentId: tryResolveAmbientOwnerAgentId(t, e.agentId) }; } function loadBootstrapPlan(e, t, n) { const { cfg: r, agentId: i } = t; const a = n?.env; const o = applyPluginAutoEnable({ config: r, ...a ? { env: a } : {} }); const s = n ? n.workspaceDir : i === void 0 ? void 0 : resolveAgentWorkspaceDir(r, i); const c = resolveDiscoverableScopedChannelPluginIds({ config: o.config, activationSourceConfig: r, channelIds: [e], workspaceDir: s, env: a ?? process.env }); const l = withActivatedPluginIds({ config: o.config, pluginIds: c }) ?? o.config; const u = withActivatedPluginIds({ config: r, pluginIds: c }) ?? r; let d; try { d = resolveSendCapableRegistry(loadPluginRegistryHandle({ config: l, activationSourceConfig: u, autoEnabledReasons: o.autoEnabledReasons, onlyPluginIds: c, workspaceDir: s, ...a ? { env: a } : {}, runtimeOptions: { allowGatewaySubagentBinding: true } }), e); } catch {} return d; } /** Loads runtime plugins on demand when a selected outbound channel has only a setup shell. */ function bootstrapOutboundChannelPlugin(e) { const t = resolveBootstrapPlan(e); return t.kind === "resolved" ? t.registry : loadBootstrapPlan(e.channel, t); } /** Prepares cold SQLite metadata before the shared bootstrap decision and loader. */ async function bootstrapOutboundChannelPluginAsync(e) { e.assertCurrent?.(); const t = resolveBootstrapPlan(e); if (t.kind === "resolved") return t.registry; const n = getPluginCache(); const r = cloneEnvWithPlatformSemantics(process.env); r.OPENCLAW_STATE_DIR = resolveStateDir(r); const i = { env: r, workspaceDir: t.agentId === void 0 ? void 0 : resolveAgentWorkspaceDir(t.cfg, t.agentId, r) }; return withPluginCache(n, async () => { const n = await prepareBundledDiscoveryMode(r); await preparePersistedInstalledPluginIndexCacheEntry({ env: r }); e.assertCurrent?.(); n(); return loadBootstrapPlan(e.channel, t, i); }); } //#endregion export { bootstrapOutboundChannelPluginAsync as n, bootstrapOutboundChannelPlugin as t };