UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

98 lines (97 loc) • 4.05 kB
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs"; import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import { D as hasKind, r as createPluginActivationSource, u as normalizePluginsConfig } from "./config-state-B1JlHgba.mjs"; import { _ as resolveSubagentMaxConcurrent, g as resolveAgentMaxConcurrent } from "./validation-core-1Fx8ByEb.mjs"; import { l as resolveAuthorizedDreamingSidecar } from "./loader-shared-CQKSwY3n.mjs"; import { s as DEFAULT_MEMORY_DREAMING_PLUGIN_ID } from "./dreaming-C72ZWZJr.mjs"; import { n as enableSessionSuspensionWritesForGatewayStart } from "./session-suspension-DpEUvu5N.mjs"; import { c as publishLaneConfiguration, r as getCommandLaneSnapshot, u as setCommandLaneConcurrency } from "./command-queue-BenRlAaO.mjs"; import { t as resolveCronMaxConcurrentRuns } from "./cron-limits-ek-0PdRl.mjs"; //#region src/gateway/server-cron-memory-dreaming-jobs.ts async function reconcileOrphanedMemoryDreamingJobs(e) { const t = normalizePluginsConfig(e.cfg.plugins); const n = normalizeLowercaseStringOrEmpty(t.slots.memory); if (!n || n === "none" || n === "memory-core") return; const { manifestRegistry: r } = e; if (!r) return; const i = r.plugins.find((e) => e.id === n); if (i && !hasKind(i.kind, "memory") || resolveAuthorizedDreamingSidecar({ cfg: e.cfg, normalized: t, activationSource: createPluginActivationSource({ config: e.cfg, plugins: t }), manifestRegistry: r, memorySlot: n }) !== null || !e.isCurrent()) return; let a; try { a = await e.cron.list({ includeDisabled: true }); } catch (t) { if (e.isCurrent()) e.logger.warn(`Dreaming job inventory failed: ${formatErrorMessage(t)}`); return; } const commitGuard = () => { if (!e.isCurrent()) throw new DOMException("Dreaming cleanup superseded", "AbortError"); }; for (const t of a) { if (t.declarationKey !== "memory-core:memory-dreaming-promotion") continue; if (!e.isCurrent()) return; try { await e.cron.remove(t.id, { commitGuard }); } catch (n) { if (!e.isCurrent()) return; e.logger.warn(`Dreaming job ${t.id} cleanup failed: ${formatErrorMessage(n)}`); } } } //#endregion //#region src/gateway/server-lanes.ts /** Capacity held inside the cron budget so hook dispatch cannot be starved. */ const HOOK_DISPATCH_LANE_RESERVATION = 1; /** Group bounding cron inner work and hook dispatch to one shared budget. */ const CRON_HOOK_LANE_GROUP = "cron-hooks"; function resolveGatewayLaneConcurrency(e) { const t = resolveCronMaxConcurrentRuns(); return { cron: t, hookDispatch: e.hooks?.enabled === true ? t : 0, main: resolveAgentMaxConcurrent(e), subagent: resolveSubagentMaxConcurrent(e) }; } function applyGatewayLaneConcurrency(e, t = {}) { if (t.gatewayStart) enableSessionSuspensionWritesForGatewayStart(); setCommandLaneConcurrency("cron", e.cron); const n = e.hookDispatch > 0; const r = getCommandLaneSnapshot("hook-dispatch"); const i = !n && r.activeCount > 0; publishLaneConfiguration({ lanes: { ["cron-nested"]: e.cron, ["hook-dispatch"]: e.hookDispatch }, groups: n || i ? { [CRON_HOOK_LANE_GROUP]: { budget: e.cron, members: ["cron-nested", "hook-dispatch"], reservations: n ? { ["hook-dispatch"]: HOOK_DISPATCH_LANE_RESERVATION } : void 0 } } : void 0, clearGroups: n || i ? void 0 : [CRON_HOOK_LANE_GROUP] }); setCommandLaneConcurrency("main", e.main); setCommandLaneConcurrency("restart-recovery", e.main); if (t.gatewayStart) setCommandLaneConcurrency("nested", 1); setCommandLaneConcurrency("subagent", e.subagent); setCommandLaneConcurrency("active-memory", e.subagent); } //#endregion //#region src/gateway/server/hook-client-ip-config.ts function resolveHookClientIpConfig(e) { return { trustedProxies: e.gateway?.trustedProxies, allowRealIpFallback: e.gateway?.allowRealIpFallback === true }; } //#endregion export { reconcileOrphanedMemoryDreamingJobs as i, applyGatewayLaneConcurrency as n, resolveGatewayLaneConcurrency as r, resolveHookClientIpConfig as t };