openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
95 lines (94 loc) • 5.06 kB
JavaScript
import { t as normalizeControlUiBasePath } from "./control-ui-shared-BiO6QP54.js";
import { a as normalizeControlUiBasePath$1 } from "./share-DPKiewIx.js";
import "./src-DqwLld49.js";
import { _ as isReadHttpMethod, g as acceptsControlUiHtmlResponse } from "./http-common-BaZaosnr.js";
import { a as classifyMcpAppStandalonePath, i as classifyGatewayProbePath, l as classifyWorkerGatewayPath, s as classifyNodeWorkspaceTransferPath } from "./gateway-http-route-contracts-jBtizxKU.js";
//#region packages/session-url-contract/src/focus.ts
const FOCUS_SEGMENT = "/focus";
function normalizePathname(pathname) {
const trimmed = pathname.trim();
const withSlash = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
return withSlash.length > 1 ? withSlash.replace(/\/+$/u, "") : withSlash;
}
function isControlUiFocusPath(pathname, basePath = "") {
const normalizedPath = normalizePathname(pathname);
const root = `${normalizeControlUiBasePath$1(basePath)}${FOCUS_SEGMENT}`;
return normalizedPath === root || normalizedPath.startsWith(`${root}/`);
}
//#endregion
//#region src/gateway/control-ui-root-assets.ts
const CONTROL_UI_BUILD_ID_ATTRIBUTE = "data-openclaw-control-ui-build-id";
/** Root files emitted by the Control UI build and served under any configured mount. */
const CONTROL_UI_ROOT_PUBLIC_ASSETS = [
"apple-touch-icon.png",
"favicon-32.png",
"favicon.ico",
"favicon.svg",
"manifest.webmanifest",
"sw.js"
];
function isControlUiRootPublicAsset(value) {
return CONTROL_UI_ROOT_PUBLIC_ASSETS.some((asset) => asset === value);
}
/** Public build inputs covered by the document's content-bound cache identity. */
function isControlUiVersionedPublicAsset(value) {
return isControlUiRootPublicAsset(value) && value !== "sw.js" || /^(?:fonts\/[^/]+\.(?:css|woff2)|themes\/[^/]+\.css|(?:provider-icons|file-icons(?:\/[^/]+)*)\/[^/]+\.svg|(?:plugin-art|app-art|community-art)\/[^/]+\.webp)$/u.test(value);
}
function buildControlUiRootAssetPath(basePath, asset) {
return `${normalizeControlUiBasePath(basePath)}/${asset}`;
}
//#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(params) {
if (!isReadHttpMethod(params.method)) return false;
const path = `${params.basePath}${CONTROL_UI_PLUGIN_MANAGER_PATH}`;
return params.pathname === path || params.pathname === `${path}/`;
}
/** Core-owned standalone approval document namespace, before plugin routing. */
function isControlUiApprovalDocumentPath(params) {
const root = `${params.basePath}/approve`;
if (params.pathname === root || params.pathname === `${root}/`) return true;
const prefix = `${root}/`;
if (!params.pathname.startsWith(prefix)) return false;
const encodedId = params.pathname.slice(prefix.length);
return encodedId.length > 0 && !encodedId.includes("/");
}
/** Focused presentation namespace used only after plugin routing declines it. */
function isControlUiFocusDocumentPath(params) {
return isControlUiFocusPath(params.pathname, params.basePath);
}
/** Classify an HTTP request as Control UI serving, redirect, 404, or non-Control-UI. */
function classifyControlUiRequest(params) {
const { basePath, pathname, search, method } = params;
const spaFallback = isControlUiPluginManagerRequest(params) || acceptsControlUiHtmlResponse(params.accept);
if (!basePath) {
if (pathname === "/ui" || pathname.startsWith("/ui/")) return { kind: "not-found" };
if (classifyGatewayProbePath(pathname) !== "outside") return { kind: "not-control-ui" };
if (classifyMcpAppStandalonePath(pathname) !== "outside") return { kind: "not-control-ui" };
if (classifyWorkerGatewayPath(pathname) !== "outside") return { kind: "not-control-ui" };
if (classifyNodeWorkspaceTransferPath(pathname) !== "outside") return { kind: "not-control-ui" };
if (pathname === "/plugins" || pathname.startsWith("/plugins/")) return { kind: "not-control-ui" };
if (pathname === "/api" || pathname.startsWith("/api/")) return { kind: "not-control-ui" };
if (pathname === "/j" || pathname.startsWith("/j/")) return { kind: "not-control-ui" };
if (pathname === "/v1" || pathname.startsWith("/v1/")) return { kind: "not-control-ui" };
if (!isReadHttpMethod(method)) return { kind: "not-control-ui" };
return {
kind: "serve",
spaFallback
};
}
if (!pathname.startsWith(`${basePath}/`) && pathname !== basePath) return { kind: "not-control-ui" };
if (!isReadHttpMethod(method)) return { kind: "not-control-ui" };
if (pathname === basePath) return {
kind: "redirect",
location: `${basePath}/${search}`
};
return {
kind: "serve",
spaFallback
};
}
//#endregion
export { CONTROL_UI_BUILD_ID_ATTRIBUTE as a, isControlUiRootPublicAsset as c, isControlUiPluginManagerRequest as i, isControlUiVersionedPublicAsset as l, isControlUiApprovalDocumentPath as n, CONTROL_UI_ROOT_PUBLIC_ASSETS as o, isControlUiFocusDocumentPath as r, buildControlUiRootAssetPath as s, classifyControlUiRequest as t };