openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
34 lines (33 loc) • 1.56 kB
JavaScript
import { a as resolveGlobalSingleton } from "./global-singleton-D7yf05nR.mjs";
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs";
//#region src/gateway/in-process-session-run.ts
const runs = resolveGlobalSingleton(Symbol.for("openclaw.inProcessSessionRuns"), () => /* @__PURE__ */ new WeakMap());
function bindInProcessSessionRun(e, t) {
if (e.sessionKey !== t.sessionKey || e.idempotencyKey !== t.runId) throw new Error("Session run does not match its prepared target");
const n = {
...e,
expectedExistingSessionId: t.sessionId,
expectedExistingSessionLifecycleRevision: t.lifecycleRevision
};
runs.set(n, { ...t });
return n;
}
/** Only the first host-bound admission consumes creation facts; wire copies cannot. */
function takeInProcessFreshChildSession(e) {
const t = getInProcessSessionRun("agent", e);
if (!t) return;
const { freshChild: n, ...r } = t;
runs.set(e, r);
return n;
}
/** Wire fields cannot grant this alternative; live source and own-session checks still apply. */
function isInProcessSessionRun(e, t) {
return getInProcessSessionRun(e, t) !== void 0;
}
function getInProcessSessionRun(e, t) {
const n = asOptionalRecord(t);
const r = e === "agent" && n ? runs.get(n) : void 0;
return r && n?.sessionKey === r.sessionKey && n.idempotencyKey === r.runId && n.expectedExistingSessionId === r.sessionId && n.expectedExistingSessionLifecycleRevision === r.lifecycleRevision ? r : void 0;
}
//#endregion
export { isInProcessSessionRun as n, takeInProcessFreshChildSession as r, bindInProcessSessionRun as t };