openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
72 lines (71 loc) • 2.08 kB
JavaScript
import { a as resolveGlobalSingleton } from "./global-singleton-D7yf05nR.mjs";
import { createHash } from "node:crypto";
//#region src/audit/message-action-decision.ts
/** Exact-execution facts for message-action boundaries without a durable owner record. */
const state = resolveGlobalSingleton(Symbol.for("openclaw.messageActionDecisionSink"), () => ({ sink: void 0 }));
function configureMessageActionDecisionSink(e) {
state.sink = e;
return () => {
if (state.sink === e) state.sink = void 0;
};
}
function decisionId(e) {
const t = [
e.contextId,
e.actionId,
e.reasonCode
];
if (e.receiptDiscriminator) t.push(e.receiptDiscriminator);
return `message-action:${createHash("sha256").update(JSON.stringify(t)).digest("base64url").slice(0, 32)}`;
}
/** Queue one unowned action or policy fact after the exact admission tuple. */
function recordMessageActionDecision(e) {
const t = e.token;
if (!t || !state.sink) return false;
const n = e.channel ? `channel:${e.channel}` : void 0;
const r = decisionId({
contextId: t.contextId,
actionId: e.actionId,
reasonCode: e.reasonCode,
receiptDiscriminator: e.receiptDiscriminator
});
return state.sink({
schemaVersion: 1,
receiptId: r,
contextId: t.contextId,
executionId: t.executionId,
runId: t.runId,
...e.actionId.length <= 256 ? { actionId: e.actionId } : {},
occurredAt: e.occurredAt ?? Date.now(),
action: {
family: "message",
operation: e.action,
...n && n.length <= 256 ? { resourceRef: n } : {},
summary: e.summary
},
decision: {
outcome: e.outcome,
reasonCode: e.reasonCode
},
enforcement: {
coverageState: e.coverageState,
evaluatorRef: "message-action",
policyRefs: e.policyRefs ?? [],
grantRefs: [],
contextFieldsUsed: [
"contextId",
"executionId",
"runId"
]
},
source: {
owner: "message-action",
recordRef: r,
decisionBoundary: "message-tool.action"
},
missingEvidence: [],
remediation: e.remediation
});
}
//#endregion
export { recordMessageActionDecision as n, configureMessageActionDecisionSink as t };