openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
33 lines (32 loc) • 1.66 kB
JavaScript
import { n as sha256Hex } from "./node-crypto-BG4u3UnX.mjs";
import { n as parseConversationRouteContext } from "./conversation-route-context-ulGSQNwr.mjs";
//#region src/config/sessions/conversation-route-fingerprint.ts
/** Binds queued authority to the exact route facts admitted by the Gateway. */
function resolveConversationRouteFingerprint(route) {
const context = route.routeContext ? parseConversationRouteContext(route.routeContext) : void 0;
return sha256Hex(JSON.stringify([
route.channel,
route.accountId,
route.kind,
route.peerId,
route.target,
route.parentConversationRef ?? null,
route.threadId ?? null,
route.nativeChannelId ?? null,
route.nativeDirectUserId ?? null,
route.routeContextObserved === true,
context ?? null
]));
}
//#endregion
//#region src/config/sessions/conversation-authority.ts
/** The reader or transaction supplies current rows; captured fingerprints alone grant nothing. */
function assertConversationAuthority(conversation, expected) {
if (!conversation || conversation.conversationRef !== expected.conversationRef || resolveConversationRouteFingerprint(conversation) !== expected.expectedRouteFingerprint || expected.expectedSessionId !== void 0 && conversation.sessionId !== expected.expectedSessionId || expected.expectedSessionKey !== void 0 && conversation.sessionKey !== expected.expectedSessionKey) {
const error = /* @__PURE__ */ new Error(`Conversation is no longer available to this agent: ${expected.conversationRef}`);
error.name = "ConversationAuthorityError";
throw error;
}
}
//#endregion
export { resolveConversationRouteFingerprint as n, assertConversationAuthority as t };