openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 1.89 kB
JavaScript
import{g as normalizeUniqueStringEntries}from"./string-normalization-D_oBUpO3.mjs";import{N as parseAgentSessionKey}from"./session-key-BPgKfU2m.mjs";import{a as tryLoadActivatedBundledPluginPublicSurfaceModule}from"./facade-runtime-DOjwP1Dh.mjs";import{t as runBestEffortCleanup}from"./non-fatal-cleanup-Zh2ArI4o.mjs";import"./browser-trash-mAYTFZju.mjs";
//!src/plugin-sdk/browser-maintenance.ts
async function closeTrackedBrowserTabsForSessions(e){if(e.sessionEntryCurrent&&typeof e.prepareCurrent!==`function`){e.onWarn?.(`browser cleanup unavailable: sessionEntryCurrent requires prepareCurrent`);return 0}if(e.isCurrent?.()===false||!e.sessionKeys.some(e=>Boolean(e?.trim())))return 0;let t;try{t=await tryLoadActivatedBundledPluginPublicSurfaceModule({dirName:`browser`,artifactBasename:`browser-maintenance.js`})}catch(t){e.onWarn?.(`browser cleanup unavailable: ${String(t)}`);return 0}if(!t||e.isCurrent?.()===false)return 0;if((e.prepareCurrent||e.sessionEntryCurrent)&&t.supportsSessionEntryCurrent!==true){e.onWarn?.(`browser cleanup unavailable: update the Browser plugin to support session-current cleanup`);return 0}if(e.prepareCurrent){if(!await e.prepareCurrent()||e.isCurrent?.()===false)return 0}return await t.closeTrackedBrowserTabsForSessions(e)}
//!src/browser-lifecycle-cleanup.ts
function isBrowserCleanupDisabled(e){return e?.browser?.enabled===false||e?.plugins?.entries?.browser?.enabled===false}async function cleanupBrowserSessionsForLifecycleEnd(e){const{cfg:t,onError:n,...r}=e;if(isBrowserCleanupDisabled(t))return;const i=normalizeUniqueStringEntries(e.sessionKeys.flatMap(e=>{const t=parseAgentSessionKey(e);return t?[`agent:${t.agentId}:${t.rest}`]:[]}));if(i.length===0)return;await runBestEffortCleanup({cleanup:async()=>{await closeTrackedBrowserTabsForSessions({...r,sessionKeys:i})},onError:n})}export{cleanupBrowserSessionsForLifecycleEnd as t};