openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.75 kB
JavaScript
import{o as getAsyncWorkSignal}from"./async-work-scope-DBcxYU4O.mjs";import{n as GATEWAY_CLIENT_IDS,r as GATEWAY_CLIENT_MODES}from"./client-info-Dr3-kuD1.mjs";import{t as AgentDatabaseAdmissionError}from"./agent-database-admission-DiJx9iIl.mjs";import{i as PROTOCOL_VERSION}from"./version-CNIg0CD7.mjs";import{d as prepareGatewayRecipientProfile}from"./session-sharing-read-Cm-EAfc6.mjs";import{i as parseControlUiSessionReturnPath}from"./control-ui-session-entry-path-DptIgdbW.mjs";import{t as authorizeControlUiReadRequestOrReply}from"./http-auth-utils-DoyTE-rC.mjs";import{t as resolveControlUiSessionPath}from"./control-ui-session-path-resolve-G8vHfu3m.mjs";
//!src/gateway/control-ui-session-entry.ts
async function serveControlUiSessionEntry(e){const{req:t,res:n,basePath:r,projection:i}=e;n.setHeader(`Cache-Control`,`no-store`);n.setHeader(`X-Robots-Tag`,`noindex, nofollow`);const a=new URL(t.url??`/`,`http://localhost`);const o=a.searchParams.get(`path`)??``;const s=parseControlUiSessionReturnPath(o,r);const c=a.searchParams.get(`probe`)===`1`;if(t.method!==`GET`||!s||a.searchParams.getAll(`path`).length!==1||a.searchParams.getAll(`probe`).length>1||[...a.searchParams.keys()].some(e=>e!==`path`&&e!==`probe`)||a.searchParams.has(`probe`)&&!c){n.statusCode=404;n.end(`Not found`);return true}const l=!c&&(e.auth.mode===`token`||e.auth.mode===`password`);const u=await authorizeControlUiReadRequestOrReply({...e,requiredOperatorMethod:`chat.history`,replyOnFailure:!l});if(!u){if(l)await e.serveApp(o);return true}const d={connect:{minProtocol:4,maxProtocol:4,client:{id:GATEWAY_CLIENT_IDS.CONTROL_UI,version:`internal`,platform:`web`,mode:GATEWAY_CLIENT_MODES.UI},role:`operator`,scopes:u.operatorScopes},authenticatedUserProfile:u.authenticatedUserProfile,internal:{operatorRoleActor:u.operatorRoleActor,operatorAccessAuthority:u.operatorAccessAuthority}};if(i)prepareGatewayRecipientProfile(d);let f=null;if(i)for(;;){let t;try{f=await resolveControlUiSessionPath({target:s,projection:i,client:d,isCurrent:u.hasCurrentClientAuthority});break}catch(n){if(!(n instanceof AgentDatabaseAdmissionError)||n.refusal.code!==`agent-database-inspection-pending`)throw n;t=e.agentDatabaseStartup?.waitForAgentPreparation(n.refusal.agentId,{forWrite:false,signal:getAsyncWorkSignal()});if(!t)throw n}await t;await u.revalidate()}if(!f||!i||!u.hasCurrentClientAuthority()){n.statusCode=403;n.end(c?void 0:`Session unavailable. Reload the conversation or log in again.`);return true}await u.revalidate();const isCurrent=()=>u.hasCurrentClientAuthority()&&f.isCurrent();if(c){n.statusCode=isCurrent()?204:403;n.end()}else{n.setHeader(`X-OpenClaw-Session-Entry`,`1`);await e.serveApp(o,isCurrent)}return true}export{serveControlUiSessionEntry};