openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
37 lines (36 loc) • 1.75 kB
JavaScript
import { o as captureGatewayStateOwner } from "./gateway-state-owner-eDtEELE9.mjs";
import { u as resolveGatewayLockPaths } from "./gateway-lock-Dw3jf-HK.mjs";
import { t as ErrorCodes } from "./gateway-error-details-gTekQWj2.mjs";
import { d as errorShape } from "./error-codes-D0WRV4Bq.mjs";
import { statSync } from "node:fs";
import path from "node:path";
//#region src/gateway/server-methods/local-state-owner.ts
/** Optional for old clients; new local callers must bind to the physically held owner. */
function captureLocalStateMutationGuard(expectedOwnerId, options, target) {
const { stateDir } = resolveGatewayLockPaths(process.env);
const owner = captureGatewayStateOwner(path.join(stateDir, "state", "openclaw.sqlite"));
const cfg = options.context.getRuntimeConfig();
const assertCurrent = () => {
options.signal?.throwIfAborted();
options.sessionMutationCommitGuard?.();
if (!owner || owner.role !== "gateway" || owner.ownerId !== expectedOwnerId || options.hasCurrentClientAuthority?.() === false || options.context.getRuntimeConfig() !== cfg) throw new Error("Gateway state owner or requester changed; rerun against the current owner.");
owner.assertCurrent();
if (target) {
const current = statSync(target.path, { bigint: true });
if (`${current.dev}:${current.ino}` !== target.identity) throw new Error("Source repository changed; rerun worktrees create.");
}
};
assertCurrent();
return assertCurrent;
}
function localStateOwnerChangedError(error) {
return errorShape(ErrorCodes.UNAVAILABLE, String(error), {
details: {
reason: "STATE_OWNER_CHANGED",
mutationAccepted: false
},
retryable: false
});
}
//#endregion
export { localStateOwnerChangedError as n, captureLocalStateMutationGuard as t };