openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
47 lines (46 loc) • 2.01 kB
JavaScript
import { n as RelayError } from "./protocol-AxVaFy3k.mjs";
//#region extensions/mcp-relay/src/caller.ts
function relayCaller(e, t) {
if (!e || e.connect.role !== "operator") throw new RelayError("unavailable", "Reconnect to the Control UI to manage connected apps.");
const n = e.connect.scopes ?? [];
const r = n.includes("operator.admin");
const i = r || n.includes("operator.write");
const a = [.../* @__PURE__ */ new Set([...n, ...i ? ["operator.read", "operator.write"] : []])];
if (t.gateway?.roles || t.gateway?.auth?.mode === "trusted-proxy") {
const t = e.authenticatedUserProfile;
const n = e.internal?.operatorRoleActor;
if (!t || n?.kind === "system" || n?.kind === "operator" && n.profileId !== t.profileId) throw new RelayError("unavailable", "Sign in as a person and use the Connected apps tab to pair this Gateway.");
return {
principal: {
kind: "person",
profileId: t.profileId
},
principalLabel: t.displayName ?? "Gateway user",
ceiling: a,
canAdmin: r,
canPair: i
};
}
return {
principal: { kind: "owner" },
principalLabel: "Gateway owner",
ceiling: a,
canAdmin: r,
canPair: r
};
}
function ownsGrant(e, t) {
return t.principal.kind === e.principal.kind && (t.principal.kind === "owner" || e.principal.kind === "person" && t.principal.profileId === e.principal.profileId);
}
function consentAuthority(e, t) {
if (!e.canPair) throw new RelayError("unavailable", "Your Gateway role cannot connect apps. Ask your administrator for access.");
const n = t ?? ["operator.read", "operator.write"].filter((t) => e.ceiling.includes(t));
if (!Array.isArray(n) || n.length === 0 || n.length > 64 || !n.every((t) => typeof t === "string" && e.ceiling.includes(t))) throw new RelayError("invalid_params", "Choose access permitted by your current Gateway role.");
return {
principal: e.principal,
principalLabel: e.principalLabel,
ceiling: [...new Set(n)]
};
}
//#endregion
export { ownsGrant as n, relayCaller as r, consentAuthority as t };