UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

54 lines (53 loc) • 2.77 kB
import { t as isAbortError } from "./abort-signal-D4Q6SEw7.mjs"; import { o as getPluginRuntimeGatewayRequestScope } from "./gateway-request-scope-BvvDhs5D.mjs"; import { s as captureCronJobSourceAuthority } from "./active-jobs-DAhIn24S.mjs"; import { t as decodeGatewayOperatorRecoverySource } from "./operator-run-recovery-source.codec-qx3kHk7N.mjs"; import { n as isCronOperatorSourceParent } from "./session-target-C-4MLah6.mjs"; import { n as restoreGatewayOperatorSource } from "./operator-run-recovery-DNcb8p2u.mjs"; import { u as resolveCronOperatorExecutionRevision } from "./jobs-tool-policy-zcItpTHY.mjs"; import { t as CronOperatorSourceError } from "./operator-source-error-Da33p_8S.mjs"; import { isDeepStrictEqual } from "node:util"; //#region src/gateway/cron-operator-source.ts /** Re-admit a job's captured parent-conversation source, never a session owner or ambient scheduler. */ async function restoreCronOperatorSource(e) { if (!e.job.operatorSource) return; let t; try { const n = e.job.operatorSource; const r = decodeGatewayOperatorRecoverySource(n.source); const i = getPluginRuntimeGatewayRequestScope()?.resolveGatewayContext?.(); const a = captureCronJobSourceAuthority(e.job.id); if (!i || !a || !e.deliveryAttemptFence) throw new Error("Scheduled operator continuation requires its live Gateway occurrence"); const o = e.deliveryAttemptFence; let s = false; const assertCurrent = () => { e.signal?.throwIfAborted(); a(); o.assertCurrent(); if (s) return; const t = i.cron.getJob(e.job.id); const c = t?.scheduledToolPolicy; if (i.resolveGatewayContext?.() !== i || !t || t.operatorSource?.executionRevision !== resolveCronOperatorExecutionRevision(t) || t.payload.kind !== "agentTurn" || c?.mode !== "account" || c.ownerSessionKey !== r.sessionKey || t.owner?.sessionKey !== r.sessionKey || !isCronOperatorSourceParent(t, r.sessionKey) || e.agentId !== r.agentId || !isDeepStrictEqual(t.operatorSource, n)) throw new Error("Scheduled operator continuation definition or conversation changed; recreate it from an authenticated turn"); }; assertCurrent(); t = await restoreGatewayOperatorSource({ snapshot: r.snapshot, target: { agentId: e.agentId, sessionKey: e.sessionKey }, context: i, assertCurrent }); assertCurrent(); s = true; return t; } catch (n) { t?.release(); if (e.signal?.aborted || isAbortError(n)) throw n; const r = n instanceof Error ? n.message : String(n); throw new CronOperatorSourceError(`The operator authority that created this automation was refused (device, access grant, role or definition changed); recreate it from an authenticated turn. Cause: ${r}`, { cause: n }); } } //#endregion export { restoreCronOperatorSource };