openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
102 lines (101 loc) • 3.43 kB
JavaScript
import { S as createOperationalRunInstanceRef, d as prepareAgentRunAdmission, l as getAdmittedRunDelegatedAuthority } from "./admitted-run-context-D3Jvk_f_.mjs";
import { i as consumeChannelAdmissionEvidence, u as recordChannelAdmissionDecision } from "./admission-evidence-q4_t-NFq.mjs";
import { o as readGatewayLocalUserIngressFacts } from "./local-user-ingress-CLpC74uh.mjs";
import { i as prepareChildSessionPublication, n as admitChildSessionPublication, o as ChannelRunAuthorizationError } from "./host-context-builder-BXWPIn7b.mjs";
//#region src/auto-reply/reply/channel-run-admission.ts
/** Adapt reply ingress to admission; authenticated Gateway attach has no plugin-channel decision. */
function consumeChannelRunAdmission(e, t) {
const n = readGatewayLocalUserIngressFacts(t);
if (n) return {
ingressState: n.ingress.state,
facts: n,
onAdmitted: () => void 0
};
const r = consumeChannelAdmissionEvidence(e);
return {
ingressState: r.ingressState,
facts: {
invoker: r.invoker,
...r.assuranceRef ? { assurance: [{
kind: "channel-admission",
rawEvidenceRef: r.assuranceRef,
strength: "boundary-verified"
}] } : {}
},
onAdmitted: (t) => {
const n = t.executionIdentityToken;
if (n && r.decisionCoverage && r.identifierAuthentication) recordChannelAdmissionDecision(e, {
contextId: n.contextId,
executionId: n.executionId,
runId: n.runId,
occurredAt: n.createdAt,
coverageState: r.decisionCoverage,
identifierAuthentication: r.identifierAuthentication
});
}
};
}
/** Defer evidence consumption until the selected runtime actually admits the run. */
function prepareChannelRunAdmission(e) {
const t = createOperationalRunInstanceRef(e.runId);
let n;
let r = false;
const assertSourceCurrent = () => {
if (n) {
n.assertSourceCurrent();
return;
}
e.assertSourceCurrent?.();
e.operatorAuthority?.assertCurrent();
};
return Object.freeze({
operationalRunInstance: t,
assertSourceCurrent,
readOperatorAuthority: () => {
if (r && e.operatorAuthority) throw new Error("prepared operator authority is no longer active");
assertSourceCurrent();
return e.operatorAuthority;
},
admit: (i, a) => {
if (r) return Promise.reject(/* @__PURE__ */ new Error("prepared execution context is already closed"));
if (!n) {
const r = consumeChannelRunAdmission(e.evidence, e.gatewayLocalUserIngress);
n = prepareAgentRunAdmission({
cfg: e.cfg,
assertSourceCurrent: e.assertSourceCurrent,
operationalRunInstance: t,
operatorAuthority: e.operatorAuthority,
facts: {
runId: e.runId,
agentId: e.agentId,
ingress: {
kind: e.ingressKind,
boundary: e.boundary,
state: r.ingressState
},
...r.facts
},
onAdmitted: async (t) => {
if (e.sourceContext) await prepareChildSessionPublication(e.sourceContext);
r.onAdmitted(t);
if (e.sourceContext) try {
admitChildSessionPublication(e.sourceContext, t.operationalRunInstance, () => {
if (!getAdmittedRunDelegatedAuthority(t)) throw new Error("Public ingress run is no longer active.");
});
} catch (e) {
throw new ChannelRunAuthorizationError(e);
}
e.onAdmitted?.(t);
}
});
}
return n.admit(i, a);
},
close: () => {
r = true;
n?.close();
}
});
}
//#endregion
export { prepareChannelRunAdmission as t };