openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
69 lines (68 loc) • 2.84 kB
JavaScript
import { c as isRecord } from "./record-coerce-TIsquoVR.mjs";
import { i as resolveRuntimeWorkerUrl } from "./runtime-worker-url-CFqA9Dvi.mjs";
import { d as readDatabasePathIdentitySync } from "./sqlite-worker-identity-BRNRpRyc.mjs";
import { n as runtimeProcessEntrypoints } from "./runtime-process-entrypoints-De68tE_W.mjs";
import { l as releaseSessionSourceAuthorities, s as prepareSessionSourceAuthority, t as acceptSessionSourceValidation } from "./session-source-authority-h1UO3u0I.mjs";
import { t as executeOpenClawAgentWorkerPublication } from "./openclaw-agent-worker-store-BE9hhRoh.mjs";
import { n as runSessionEntryWorkerOperation } from "./session-entry-patch-fXJDvWHG.mjs";
import { randomUUID } from "node:crypto";
//#region src/config/sessions/goals-management.ts
async function mutateSessionGoalInWorker(database, agentId, execution, input, assertion, native) {
let identity;
let source;
try {
execution.assertCurrent();
identity = readDatabasePathIdentitySync(database.path);
source = await prepareSessionSourceAuthority(assertion);
} catch (error) {
await releaseSessionSourceAuthorities([execution], [error]);
throw error;
}
const release = () => releaseSessionSourceAuthorities([execution, source]);
if (source.nativeSource || source.checks.some(({ predicate }) => typeof predicate.source.databaseIdentity !== "string" || `file:${predicate.source.databaseIdentity}` !== identity.key)) try {
return await native(() => execution.assertCurrent());
} finally {
await release();
}
return runSessionEntryWorkerOperation({
database,
retainedExecution: execution,
agentId,
candidateKind: "session-goal-management",
onTransactionFacts(facts) {
if (isRecord(facts) && facts.kind === "session-entry-patch-validated") {
acceptSessionSourceValidation(source, facts.sourceValidation);
source.assertCurrent();
return true;
}
return false;
},
assertCurrent: source.assertCurrent,
releaseSource: release,
assertCandidate(candidate) {
if (candidate.refusedSource) {
const refused = candidate.refusedSource;
source.checks[refused.index]?.refuse(refused.facts);
throw new Error("Goal source refusal omitted its authority assertion");
}
},
run: (worker, commit) => commit(() => executeOpenClawAgentWorkerPublication(worker, {
id: randomUUID(),
moduleUrl: resolveRuntimeWorkerUrl(runtimeProcessEntrypoints.sessionGoalOperations).href,
input: { agentId: database.agentId },
command: {
type: "session.goal.mutate",
input: {
...input,
sources: source.checks.map(({ predicate }) => predicate)
}
}
})),
onCommitted: (candidate) => {
if (candidate.refusedSource) throw new Error("Refused Goal source reached publication");
return candidate.result;
}
});
}
//#endregion
export { mutateSessionGoalInWorker };