UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

103 lines (102 loc) • 4.2 kB
//#region src/cron/execution-context-registry.ts const contextsByRun = /* @__PURE__ */ new WeakMap(); /** Admission-only: binds an occurrence's context to its admitted run. */ function bindScheduledExecutionContext(e, t) { contextsByRun.set(e, t); return () => { if (contextsByRun.get(e) === t) contextsByRun.delete(e); }; } /** * Targets for the run its owner names (an admitted run context or tool options), * or undefined when that run was not admitted with an execution context. */ function readScheduledToolTargets(e) { const t = e?.operationalRunInstance; const n = t ? contextsByRun.get(t) : void 0; if (!n) return; const r = senderBitOf(n) ? n.assertOwnerCurrent : void 0; const { execTarget: i } = n.toolPolicy; return { boardSessionKey: n.resources.boardSessionKey, assertCurrent: n.assertCurrent, ...r ? { assertOwnerCurrent: r } : {}, ...n.principal.kind === "ingress" ? {} : { placement: n.placement }, ...i ? { execTarget: i } : {} }; } /** * Tool-construction options for a scheduled run on a Gateway-resolved surface: * its targets, plus the grant's tool cap as the run's allowance, matching the * embedded attempt. Empty when the run was not admitted with a context. */ function readScheduledToolOptions(e, t) { const n = readScheduledToolTargets(e); if (!n) return {}; return { scheduledToolTargets: n, ...t ? { runtimeToolAllowlist: [...t] } : {} }; } /** * The automations scope a scheduled occurrence (not an ingress turn) takes from * its admitted context, or undefined when the run has no such context. */ function readScheduledOccurrenceAutomationsScope(e) { const t = e?.operationalRunInstance; const n = t ? contextsByRun.get(t) : void 0; return n && n.principal.kind !== "ingress" ? n.toolPolicy.automations : void 0; } /** * The job a scope restricts the automations tool to, or undefined for no tool. * `self-and-parent-wake` offers the same self actions as `self`: waking the * parent is not offered until the parent-wake action lands (openclaw-0d5.9). */ function readScheduledAutomationsSelfJobId(e) { return e && e.scope !== "none" ? e.jobId : void 0; } /** * The automations scope an ingress turn (hook or channel join introduction) * takes from its admitted context, or undefined when the run is not an ingress * turn admitted with a context. */ function readScheduledIngressAutomationsScope(e) { const t = e?.operationalRunInstance; const n = t ? contextsByRun.get(t) : void 0; return n?.principal.kind === "ingress" ? n.toolPolicy.automations : void 0; } /** The parent whose memory audience a child run inherits, or undefined to resolve from the run row. */ function readScheduledMemoryParent(e) { const t = e ? contextsByRun.get(e)?.resources.memory : void 0; if (t?.source !== "parent") return; const { parent: n, owner: r } = t; return { sessionKey: n.sessionKey, sessionId: n.sessionId, ...n.lifecycleRevision ? { lifecycleRevision: n.lifecycleRevision } : {}, senderIsOwner: r }; } function senderBitOf(e) { if (e.placement === "in-session" || e.principal.kind === "ingress") return; return e.authority.owner ? {} : { senderIsOwner: false }; } /** * The sender bit a scheduled run's tools take from its minted context, or * undefined when the context does not decide it. * * A scheduled run is an internal turn. An owner run carries no sender bit, which * keeps every owner-only tool except standing intents (they need an explicit * sender identity); a run whose requester is not an owner carries `false`. */ function resolveScheduledSenderBit(e) { return e.status === "ready" ? senderBitOf(e.facts) : void 0; } /** The sender bit for the run its owner names, when that run's context decides it. */ function readScheduledSenderBit(e) { const t = e?.operationalRunInstance; const n = t ? contextsByRun.get(t) : void 0; return n ? senderBitOf(n) : void 0; } //#endregion export { readScheduledOccurrenceAutomationsScope as a, readScheduledToolTargets as c, readScheduledMemoryParent as i, resolveScheduledSenderBit as l, readScheduledAutomationsSelfJobId as n, readScheduledSenderBit as o, readScheduledIngressAutomationsScope as r, readScheduledToolOptions as s, bindScheduledExecutionContext as t };