Files
openclaw-zero-token/gateway/control-ui-routing.ts
sjhu 571e14a236 feat: upgrade to upstream v2026.3.28
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
2026-03-30 17:58:12 +08:00

52 lines
1.7 KiB
TypeScript

import { isReadHttpMethod } from "./control-ui-http-utils.js";
export type ControlUiRequestClassification =
| { kind: "not-control-ui" }
| { kind: "not-found" }
| { kind: "redirect"; location: string }
| { kind: "serve" };
const ROOT_MOUNTED_GATEWAY_PROBE_PATHS = new Set(["/health", "/healthz", "/ready", "/readyz"]);
export function classifyControlUiRequest(params: {
basePath: string;
pathname: string;
search: string;
method: string | undefined;
}): ControlUiRequestClassification {
const { basePath, pathname, search, method } = params;
if (!basePath) {
if (pathname === "/ui" || pathname.startsWith("/ui/")) {
return { kind: "not-found" };
}
// Keep core probe routes outside the root-mounted SPA catch-all so the
// gateway probe handler can answer them even when the Control UI owns `/`.
if (ROOT_MOUNTED_GATEWAY_PROBE_PATHS.has(pathname)) {
return { kind: "not-control-ui" };
}
// Keep plugin-owned HTTP routes outside the root-mounted Control UI SPA
// fallback so untrusted plugins cannot claim arbitrary UI paths.
if (pathname === "/plugins" || pathname.startsWith("/plugins/")) {
return { kind: "not-control-ui" };
}
if (pathname === "/api" || pathname.startsWith("/api/")) {
return { kind: "not-control-ui" };
}
if (!isReadHttpMethod(method)) {
return { kind: "not-control-ui" };
}
return { kind: "serve" };
}
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" };
}