UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

54 lines (53 loc) • 1.91 kB
import { t as ADMIN_SCOPE } from "./operator-scopes-CULmYfyY.mjs"; //#region src/shared/gateway-method-policy.ts const RESERVED_ADMIN_GATEWAY_METHOD_PREFIXES = [ "exec.approvals.", "config.", "wizard.", "update." ]; const RESERVED_ADMIN_GATEWAY_METHOD_SCOPE = "operator.admin"; /** Resolve the mandatory scope for reserved gateway methods. */ function resolveReservedGatewayMethodScope(e) { if (!RESERVED_ADMIN_GATEWAY_METHOD_PREFIXES.some((t) => e.startsWith(t))) return; return RESERVED_ADMIN_GATEWAY_METHOD_SCOPE; } /** Coerce plugin-declared scopes away from unsafe reserved gateway method scopes. */ function normalizePluginGatewayMethodScope(e, t) { const n = resolveReservedGatewayMethodScope(e); if (!n || !t || t === n) return { scope: t, coercedToReservedAdmin: false }; return { scope: n, coercedToReservedAdmin: true }; } //#endregion //#region src/gateway/methods/descriptor.ts /** Scope marker for methods that only authenticated node clients may call. */ const NODE_GATEWAY_METHOD_SCOPE = "node"; /** Scope marker for methods whose handler derives the required operator scope at runtime. */ const DYNAMIC_GATEWAY_METHOD_SCOPE = "dynamic"; function createPluginGatewayMethodDescriptor(e) { const t = normalizePluginGatewayMethodScope(e.name, e.scope).scope; return { name: e.name, handler: e.handler, owner: { kind: "plugin", pluginId: e.pluginId }, profileAccess: e.profileAccess ?? "required", ...e.sessionAccess ? { sessionAccess: e.sessionAccess } : {}, ...e.shareKey ? { shareKey: e.shareKey, shareInvalidationEvents: e.shareInvalidationEvents, shareMaxAgeMs: e.shareMaxAgeMs } : {}, scope: t ?? "operator.admin" }; } //#endregion export { resolveReservedGatewayMethodScope as a, normalizePluginGatewayMethodScope as i, NODE_GATEWAY_METHOD_SCOPE as n, createPluginGatewayMethodDescriptor as r, DYNAMIC_GATEWAY_METHOD_SCOPE as t };