mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-10 00:31:22 +00:00
34 lines
944 B
TypeScript
34 lines
944 B
TypeScript
import { runBestEffortCleanup } from "./infra/non-fatal-cleanup.js";
|
|
import { closeTrackedBrowserTabsForSessions } from "./plugin-sdk/browser-maintenance.js";
|
|
|
|
function normalizeSessionKeys(sessionKeys: string[]): string[] {
|
|
const keys = new Set<string>();
|
|
for (const sessionKey of sessionKeys) {
|
|
const normalized = sessionKey.trim();
|
|
if (normalized) {
|
|
keys.add(normalized);
|
|
}
|
|
}
|
|
return [...keys];
|
|
}
|
|
|
|
export async function cleanupBrowserSessionsForLifecycleEnd(params: {
|
|
sessionKeys: string[];
|
|
onWarn?: (message: string) => void;
|
|
onError?: (error: unknown) => void;
|
|
}): Promise<void> {
|
|
const sessionKeys = normalizeSessionKeys(params.sessionKeys);
|
|
if (sessionKeys.length === 0) {
|
|
return;
|
|
}
|
|
await runBestEffortCleanup({
|
|
cleanup: async () => {
|
|
await closeTrackedBrowserTabsForSessions({
|
|
sessionKeys,
|
|
onWarn: params.onWarn,
|
|
});
|
|
},
|
|
onError: params.onError,
|
|
});
|
|
}
|