openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
56 lines (55 loc) • 2.29 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { P as consumeSessionEffectHandoff } from "./session-controller.lifecycle-C_Z3sybN.mjs";
//#region src/gateway/server-methods/agent-expected-session.ts
var ExpectedExistingSessionChangedError = class extends Error {
constructor(e) {
super(e);
this.name = "ExpectedExistingSessionChangedError";
}
};
function resolveExpectedExistingSessionConstraint(e) {
const t = normalizeOptionalString(e.expectedExistingSessionId);
if (!t) {
if (e.expectedExistingSessionLifecycleRevision !== void 0) return {
ok: false,
error: "expectedExistingSessionLifecycleRevision requires expectedExistingSessionId."
};
return { ok: true };
}
if (!e.canUseInternalRuntimeHandoff) return {
ok: false,
error: "expectedExistingSessionId is reserved for backend callers."
};
const n = normalizeOptionalString(e.internalRuntimeHandoffId);
return {
ok: true,
constraint: {
sessionId: t,
lifecycleRevision: e.expectedExistingSessionLifecycleRevision,
...n ? { handoffId: n } : {}
}
};
}
function validateExpectedExistingSessionTarget(e) {
if (!e.constraint) return;
if (!e.requestedSessionKey) return "expectedExistingSessionId requires an explicit session key.";
if (e.requestedSessionId && e.requestedSessionId !== e.constraint.sessionId) return "conflicting session identity constraints.";
}
function assertExpectedExistingSession(e) {
if (e.constraint && (e.entry?.sessionId !== e.constraint.sessionId || e.constraint.lifecycleRevision !== void 0 && (e.entry?.lifecycleRevision ?? null) !== e.constraint.lifecycleRevision)) throw new ExpectedExistingSessionChangedError(e.message);
}
function consumeExpectedSessionWorkAdmission(e) {
const t = e.constraint?.handoffId;
if (!t) return;
const n = consumeSessionEffectHandoff({
handoffId: t,
target: e.target,
onInterrupt: e.onInterrupt,
isSettling: e.isSettling,
getAbortReason: e.getAbortReason
});
if (!n) throw new Error("session work admission handoff is unavailable");
return n;
}
//#endregion
export { validateExpectedExistingSessionTarget as a, resolveExpectedExistingSessionConstraint as i, assertExpectedExistingSession as n, consumeExpectedSessionWorkAdmission as r, ExpectedExistingSessionChangedError as t };