openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
68 lines (67 loc) • 3.49 kB
JavaScript
import { h as SessionGoalOperationError } from "../../openclaw-state-worker-error-C8y1JGQN.mjs";
import { l as ensureSessionGoalOperationsSchema } from "../../openclaw-agent-db-schema-compatibility-DMUbFiMM.mjs";
import { r as mergeSessionEntry } from "../../types-BUko5WqP.mjs";
import { p as readSessionEntryRow } from "../../session-accessor.sqlite-entry-read-csOyyi3K.mjs";
import { r as applySessionGoalOperation } from "../../goals-operation-policy-D3lqf5_y.mjs";
import { c as writeSessionEntry } from "../../session-accessor.sqlite-entry-store-DmqxH0lm.mjs";
import { n as readSessionGoalOperationReceipt, r as writeSessionGoalOperationReceipt } from "../../goals-operation-receipts-DLTLf_KX.mjs";
import { n as prepareSessionEntryReplacementPublication } from "../../session-accessor.sqlite-replacement-publication-7c_4oTwB.mjs";
import { n as readSessionSourceValidation } from "../../session-source-predicate.worker-BkQFgRSR.mjs";
import { i as transferSessionEntryWorkerCandidate, t as bindSessionWorkerBackend } from "../../session-entry-patch.worker-C8AFkROr.mjs";
//#region src/config/sessions/goals-operations.worker.ts
/** Lend the existing executor connection; keep this private command outside the released SDK union. */
function bindSqliteWorkerBackend(e, t) {
return bindSessionWorkerBackend(e, t, "Goal", ({ admit: e, writeTransaction: t }, n) => {
ensureSessionGoalOperationsSchema(n.db);
return ({ input: n }) => {
return t("session.goal.mutate", "Goal transaction", (t) => {
const r = readSessionSourceValidation(t, n.sources);
const { refusedSource: i } = r;
if (i) {
transferSessionEntryWorkerCandidate(t, e, {
kind: "session-goal-management",
refusedSource: i
});
throw new Error("Goal source refusal was not rejected");
}
if (r.conversationMatches.length) e("transaction", {
kind: "session-entry-patch-validated",
sourceValidation: r
});
const { previous: a, ...o } = mutateSessionGoalInDatabase(t, n);
const s = {
kind: "session-goal-management",
result: o,
publication: a && o.sessionEntry ? prepareSessionEntryReplacementPublication({
previous: /* @__PURE__ */ new Map([[n.sessionKey, a]]),
current: /* @__PURE__ */ new Map([[n.sessionKey, o.sessionEntry]]),
pendingArchiveRecovery: false,
membershipInvalidatedKeys: [],
maintenancePlans: []
}, t) : void 0
};
return transferSessionEntryWorkerCandidate(t, e, s);
});
};
}, "Goal management");
}
/** Receipt replay and the reducer share the current row and the caller's synchronous transaction. */
function mutateSessionGoalInDatabase(e, t) {
const n = readSessionEntryRow(e, t.sessionKey);
const r = readSessionGoalOperationReceipt(e.db, t.sessionKey, t.expectedSessionId, t.operation);
if (r && n?.entry.sessionId === t.expectedSessionId) return {
result: r,
replayed: true
};
if (!n || n.entry.sessionId !== t.expectedSessionId) throw new SessionGoalOperationError("session-rebound", "Session changed; refresh before changing its Goal.");
const i = applySessionGoalOperation(n.entry, t.operation, Date.now());
const a = writeSessionEntry(e, t.sessionKey, mergeSessionEntry(n.entry, { goal: i }), { canonicalPreviousEntry: n.entry });
return {
result: writeSessionGoalOperationReceipt(e.db, t.sessionKey, t.expectedSessionId, t.operation, i),
replayed: false,
sessionEntry: a,
previous: n.entry
};
}
//#endregion
export { bindSqliteWorkerBackend };