UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

57 lines (56 loc) • 2.95 kB
import { a as classifyMcpAppStandalonePath, i as classifyGatewayProbePath, l as classifyWorkerGatewayPath, s as classifyNodeWorkspaceTransferPath } from "./gateway-http-route-contracts-DIOh6f_o.mjs"; import { n as isReadHttpMethod, t as acceptsControlUiHtmlResponse } from "./control-ui-http-utils-DH5C3tE0.mjs"; import { s as resolvePluginDiscoveryIdentity } from "./catalog-discovery-q1OWXMsX.mjs"; //#region packages/plugin-package-contract/src/catalog-route.ts const CATALOG_ID = /^[A-Za-z0-9_-]+$/u; const OWNER_AND_NAME = /^[a-z0-9][a-z0-9._-]*\/[a-z0-9][a-z0-9._-]*$/u; function pluginCatalogIdFromRouteSuffix(e) { if (OWNER_AND_NAME.test(e)) return "ch_" + btoa("@" + e).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", ""); return CATALOG_ID.test(e) ? e : null; } //#endregion //#region src/gateway/control-ui-routing.ts const CONTROL_UI_PLUGIN_MANAGER_PATH = "/settings/plugins"; /** Keep the plugin recovery surface ahead of plugin-owned HTTP routes. */ function isControlUiPluginManagerRequest(e) { if (!isReadHttpMethod(e.method)) return false; const t = `${e.basePath}${CONTROL_UI_PLUGIN_MANAGER_PATH}`; return e.pathname === t || e.pathname === `${t}/`; } /** Core-owned standalone approval document namespace, before plugin routing. */ function isControlUiApprovalDocumentPath(e) { const t = `${e.basePath}/approve`; if (e.pathname === t || e.pathname === `${t}/`) return true; const n = `${t}/`; if (!e.pathname.startsWith(n)) return false; const r = e.pathname.slice(n.length); return r.length > 0 && !r.includes("/"); } /** Classify an HTTP request as Control UI serving, redirect, 404, or non-Control-UI. */ function classifyControlUiRequest(e) { const { basePath: t, pathname: n, search: r, method: i } = e; const a = isControlUiPluginManagerRequest(e) || acceptsControlUiHtmlResponse(e.accept); if (!t) { if (n === "/ui" || n.startsWith("/ui/")) return { kind: "not-found" }; if (classifyGatewayProbePath(n) !== "outside" || classifyMcpAppStandalonePath(n) !== "outside" || classifyWorkerGatewayPath(n) !== "outside" || classifyNodeWorkspaceTransferPath(n) !== "outside") return { kind: "not-control-ui" }; if (n === "/plugins" || n.startsWith("/plugins/")) { if (!(n === "/plugins" || n === "/plugins/" || resolvePluginDiscoveryIdentity(pluginCatalogIdFromRouteSuffix(n.slice(9)) ?? "") !== void 0) || !isReadHttpMethod(i) || !a) return { kind: "not-control-ui" }; } if ([ "/api", "/j", "/v1" ].some((e) => n === e || n.startsWith(`${e}/`))) return { kind: "not-control-ui" }; } else if (!n.startsWith(`${t}/`) && n !== t) return { kind: "not-control-ui" }; if (!isReadHttpMethod(i)) return { kind: "not-control-ui" }; if (t && n === t) return { kind: "redirect", location: `${t}/${r}` }; return { kind: "serve", spaFallback: a }; } //#endregion export { isControlUiApprovalDocumentPath as n, isControlUiPluginManagerRequest as r, classifyControlUiRequest as t };