openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
124 lines (123 loc) • 4.2 kB
JavaScript
import { r as truncateUtf16Safe } from "./utf16-slice-CuDyEXgS.mjs";
import { s as redactSensitiveText } from "./redact-Mj7pppxC.mjs";
import { s as executionIdentitySpawnAdmission } from "./execution-identity-admission-EuMO_R29.mjs";
import { isDeepStrictEqual } from "node:util";
//#region src/gateway/local-user-ingress.ts
const ingressByOwner = /* @__PURE__ */ new WeakMap();
const preparedIngress = /* @__PURE__ */ new WeakSet();
function freezeLocalUserIngress(e) {
Object.freeze(e.ingress);
Object.freeze(e.invoker);
Object.freeze(e.representedSubject);
for (const t of e.assurance ?? []) Object.freeze(t);
Object.freeze(e.assurance);
const t = Object.freeze({ facts: Object.freeze(e) });
preparedIngress.add(t);
return t;
}
/** The creation owner supplies these facts only after checking its live agent caller. */
function prepareGatewayAgentToolIngress(e) {
return freezeLocalUserIngress(executionIdentitySpawnAdmission({
operation: "attach",
value: {
ingress: {
kind: "api",
boundary: "gateway.agent-tool",
state: "present"
},
invoker: {
state: "present",
kind: "agent",
rawPrincipalRef: e.agentId
},
...e.representedProfileId ? { representedSubject: {
state: "present",
kind: "person",
rawPrincipalRef: e.representedProfileId
} } : {}
},
extra: e.spawnAdmission
}));
}
/** Only prepared host ingress supplies facts; copied or public lookalikes carry none. */
function readGatewayLocalUserIngressFacts(e) {
return e && preparedIngress.has(e) ? e.facts : void 0;
}
/** Collected turns retain attribution only when every source supplies the same attach facts. */
function combineGatewayLocalUserIngress(e) {
const t = e.find((e) => readGatewayLocalUserIngressFacts(e));
if (!t) return;
if (e.every((e) => isDeepStrictEqual(readGatewayLocalUserIngressFacts(e), t.facts))) return t;
return freezeLocalUserIngress({
ingress: {
kind: "gateway-client",
boundary: "gateway.ws.authenticated-connect",
state: "unknown"
},
invoker: { state: "unknown" }
});
}
function safeDisplayLabel(e) {
const t = e?.trim();
return t ? truncateUtf16Safe(redactSensitiveText(redactSensitiveText(t, { mode: "tools" }), { mode: "tools" }), 128) : void 0;
}
/** Prepare attribution once from authenticated connection facts; credentials never become people. */
function prepareGatewayLocalUserIngress(e) {
const t = e.profile?.profileId.trim();
const n = e.pairedDeviceId?.trim();
const r = safeDisplayLabel(e.profile?.displayName);
const i = [];
if (t) i.push({
kind: "durable-profile",
rawEvidenceRef: t,
strength: "boundary-verified"
});
if (e.authMethod === "trusted-proxy") i.push({
kind: "trusted-proxy",
rawEvidenceRef: t ?? "gateway-auth:trusted-proxy",
strength: "boundary-verified"
});
else if (e.authMethod === "tailscale") i.push({
kind: "tailscale-whois",
rawEvidenceRef: t ?? "gateway-auth:tailscale",
strength: "boundary-verified"
});
if (n) i.push({
kind: "device-proof",
rawEvidenceRef: n,
strength: "cryptographic"
});
if (e.isLocalClient) i.push({
kind: "local-process",
rawEvidenceRef: "gateway-transport:local",
strength: "boundary-verified"
});
const a = t ?? n;
return freezeLocalUserIngress({
ingress: {
kind: "gateway-client",
boundary: "gateway.ws.authenticated-connect",
state: "present",
...a ? { rawSourceRef: a } : {}
},
...t ? { invoker: {
state: "present",
kind: "person",
rawPrincipalRef: t,
...r ? { displayLabel: r } : {}
} } : e.authenticatedUserExpected ? { invoker: { state: "unknown" } } : {},
...i.length > 0 ? { assurance: i } : {}
});
}
function attachGatewayLocalUserIngress(e, t) {
ingressByOwner.set(e, t);
}
function getGatewayLocalUserIngress(e) {
return e ? ingressByOwner.get(e) : void 0;
}
function transferGatewayLocalUserIngress(e, t) {
const n = ingressByOwner.get(e);
if (n) ingressByOwner.set(t, n);
}
//#endregion
export { prepareGatewayLocalUserIngress as a, prepareGatewayAgentToolIngress as i, combineGatewayLocalUserIngress as n, readGatewayLocalUserIngressFacts as o, getGatewayLocalUserIngress as r, transferGatewayLocalUserIngress as s, attachGatewayLocalUserIngress as t };