UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

5 lines • 2.65 kB
import{a as classifyMcpAppStandalonePath,i as classifyGatewayProbePath,l as classifyWorkerGatewayPath,s as classifyNodeWorkspaceTransferPath}from"./gateway-http-route-contracts-Dot5G-J1.mjs";import{n as isReadHttpMethod,t as acceptsControlUiHtmlResponse}from"./control-ui-http-utils-M5A3tWWK.mjs";import{s as resolvePluginDiscoveryIdentity}from"./catalog-discovery-BYGBiXZI.mjs"; //!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} //!src/gateway/control-ui-routing.ts const CONTROL_UI_PLUGIN_MANAGER_PATH=`/settings/plugins`;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}/`}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(`/`)}function isControlUiHttpRequest(e,t){const n=e.url?new URL(e.url,`http://localhost`):void 0;return n!==void 0&&classifyControlUiRequest({basePath:t,pathname:n.pathname,search:n.search,method:e.method,accept:e.headers.accept}).kind!==`not-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`,`/oauth`].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}}export{isControlUiPluginManagerRequest as i,isControlUiApprovalDocumentPath as n,isControlUiHttpRequest as r,classifyControlUiRequest as t};