openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
61 lines (60 loc) • 2.15 kB
JavaScript
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import { n as runtimeProcessEntrypoints } from "./runtime-process-entrypoints-qiyJvDDT.mjs";
import { a as resolveRuntimeWorkerUrl } from "./runtime-worker-url-DRDkoS4J.mjs";
import { c as prepareSessionSourceAuthority, t as acceptSessionSourceValidation, u as releaseSessionSourceAuthorities } from "./session-source-authority-TlTpfRVE.mjs";
import { t as executeOpenClawAgentWorkerPublication } from "./openclaw-agent-worker-store-Do41NaPe.mjs";
import { n as runSessionEntryWorkerOperation } from "./session-entry-patch-DevVCrdb.mjs";
import { randomUUID } from "node:crypto";
//#region src/config/sessions/goals-management.ts
async function mutateSessionGoalInWorker(e, t, n, r, i) {
let a;
try {
n.assertCurrent();
a = await prepareSessionSourceAuthority(i);
} catch (e) {
await releaseSessionSourceAuthorities([n], [e]);
throw e;
}
const release = () => releaseSessionSourceAuthorities([n, a]);
return runSessionEntryWorkerOperation({
database: e,
retainedExecution: n,
agentId: t,
candidateKind: "session-goal-management",
onTransactionFacts(e) {
if (isRecord(e) && e.kind === "session-entry-patch-validated") {
acceptSessionSourceValidation(a, e.sourceValidation);
a.assertCurrent();
return true;
}
return false;
},
assertCurrent: a.assertCurrent,
releaseSource: release,
assertCandidate(e) {
if (e.refusedSource) {
const t = e.refusedSource;
a.checks[t.index]?.refuse(t.facts);
throw new Error("Goal source refusal omitted its authority assertion");
}
},
run: (t, n) => n(() => executeOpenClawAgentWorkerPublication(t, {
id: randomUUID(),
moduleUrl: resolveRuntimeWorkerUrl(runtimeProcessEntrypoints.sessionGoalOperations).href,
input: { agentId: e.agentId },
command: {
type: "session.goal.mutate",
input: {
...r,
sources: a.checks.map(({ predicate: e }) => e)
}
}
})),
onCommitted: (e) => {
if (e.refusedSource) throw new Error("Refused Goal source reached publication");
return e.result;
}
});
}
//#endregion
export { mutateSessionGoalInWorker };