Spaces:
Running
Running
v0.9.2: wipe the Space embed's storage when it opens
Browse files- index.html +1 -0
- js/config.js +1 -1
- js/main.js +46 -0
- sw.js +1 -1
index.html
CHANGED
|
@@ -142,6 +142,7 @@
|
|
| 142 |
<p>LocalWebAgent runs a whole Linux machine and keeps your models and files in your browser. Inside the Hugging Face page it can't save them properly or sign you in, so open it on its own page.</p>
|
| 143 |
<a class="btn primary embed-gate-btn" id="embed-gate-link" href="./" target="_blank" rel="noopener">Open LocalWebAgent</a>
|
| 144 |
<p class="embed-gate-note">Opens in a new tab. Bookmark it for next time.</p>
|
|
|
|
| 145 |
</div>
|
| 146 |
</div>
|
| 147 |
|
|
|
|
| 142 |
<p>LocalWebAgent runs a whole Linux machine and keeps your models and files in your browser. Inside the Hugging Face page it can't save them properly or sign you in, so open it on its own page.</p>
|
| 143 |
<a class="btn primary embed-gate-btn" id="embed-gate-link" href="./" target="_blank" rel="noopener">Open LocalWebAgent</a>
|
| 144 |
<p class="embed-gate-note">Opens in a new tab. Bookmark it for next time.</p>
|
| 145 |
+
<p class="embed-gate-note" id="embed-gate-clean" role="status"></p>
|
| 146 |
</div>
|
| 147 |
</div>
|
| 148 |
|
js/config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
// Central configuration. Everything that pins a version or a location lives here.
|
| 2 |
-
export const APP_VERSION = "0.9.
|
| 3 |
|
| 4 |
// --- Local language models (loaded from the Hugging Face Hub, cached in Cache Storage) ---
|
| 5 |
// Each runs on WebGPU through transformers.js. `chunks` is how many external weight files
|
|
|
|
| 1 |
// Central configuration. Everything that pins a version or a location lives here.
|
| 2 |
+
export const APP_VERSION = "0.9.2";
|
| 3 |
|
| 4 |
// --- Local language models (loaded from the Hugging Face Hub, cached in Cache Storage) ---
|
| 5 |
// Each runs on WebGPU through transformers.js. `chunks` is how many external weight files
|
js/main.js
CHANGED
|
@@ -125,8 +125,12 @@ async function init() {
|
|
| 125 |
if (embedded()) {
|
| 126 |
$("#embed-gate-link").href = standaloneUrl();
|
| 127 |
$("#embed-gate").hidden = false;
|
|
|
|
| 128 |
return;
|
| 129 |
}
|
|
|
|
|
|
|
|
|
|
| 130 |
$("#version").textContent = "v" + APP_VERSION;
|
| 131 |
setBackendLabels();
|
| 132 |
syncToggles();
|
|
@@ -164,6 +168,48 @@ async function init() {
|
|
| 164 |
}
|
| 165 |
|
| 166 |
const UPDATE_FLAG = "lwa-update-linux";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
/** After boot: if the server has a newer Linux image than the installed one, offer it. */
|
| 169 |
async function checkForNewImage() {
|
|
|
|
| 125 |
if (embedded()) {
|
| 126 |
$("#embed-gate-link").href = standaloneUrl();
|
| 127 |
$("#embed-gate").hidden = false;
|
| 128 |
+
wipeEmbeddedStorage();
|
| 129 |
return;
|
| 130 |
}
|
| 131 |
+
// Mark this browser's first-party storage, so an embedded copy can tell whether it sees
|
| 132 |
+
// the same storage (and must not wipe it) or its own partitioned copy.
|
| 133 |
+
try { localStorage.setItem(FIRST_PARTY_MARK, "1"); } catch {}
|
| 134 |
$("#version").textContent = "v" + APP_VERSION;
|
| 135 |
setBackendLabels();
|
| 136 |
syncToggles();
|
|
|
|
| 168 |
}
|
| 169 |
|
| 170 |
const UPDATE_FLAG = "lwa-update-linux";
|
| 171 |
+
const FIRST_PARTY_MARK = "lwa-first-party";
|
| 172 |
+
|
| 173 |
+
/**
|
| 174 |
+
* In the Space embed, deletes everything this app stored there (models, Linux disk and
|
| 175 |
+
* files, settings, keys, service worker) so it only lives on the dedicated page. Browsers
|
| 176 |
+
* partition an iframe's storage by the top-level site, so this is the embed's own copy;
|
| 177 |
+
* if the dedicated page's marker is visible, storage is shared and nothing is deleted.
|
| 178 |
+
*/
|
| 179 |
+
async function wipeEmbeddedStorage() {
|
| 180 |
+
const note = $("#embed-gate-clean");
|
| 181 |
+
let shared = false;
|
| 182 |
+
try { shared = localStorage.getItem(FIRST_PARTY_MARK) === "1"; } catch {}
|
| 183 |
+
if (shared) { note.textContent = ""; return; } // not partitioned: this is the real app's data
|
| 184 |
+
const before = (await navigator.storage?.estimate?.().catch(() => null))?.usage ?? 0;
|
| 185 |
+
note.textContent = "Clearing data stored by this embedded view…";
|
| 186 |
+
const tasks = [];
|
| 187 |
+
tasks.push((async () => {
|
| 188 |
+
for (const r of (await navigator.serviceWorker?.getRegistrations?.()) ?? []) await r.unregister();
|
| 189 |
+
})());
|
| 190 |
+
tasks.push((async () => { for (const k of await caches.keys()) await caches.delete(k); })());
|
| 191 |
+
tasks.push((async () => {
|
| 192 |
+
for (const db of (await indexedDB.databases?.()) ?? []) {
|
| 193 |
+
if (!db.name) continue;
|
| 194 |
+
await new Promise((resolve) => {
|
| 195 |
+
const req = indexedDB.deleteDatabase(db.name);
|
| 196 |
+
req.onsuccess = req.onerror = req.onblocked = () => resolve();
|
| 197 |
+
});
|
| 198 |
+
}
|
| 199 |
+
})());
|
| 200 |
+
tasks.push((async () => {
|
| 201 |
+
const root = await navigator.storage?.getDirectory?.();
|
| 202 |
+
if (root) for await (const name of root.keys()) await root.removeEntry(name, { recursive: true });
|
| 203 |
+
})());
|
| 204 |
+
await Promise.allSettled(tasks);
|
| 205 |
+
try { localStorage.clear(); sessionStorage.clear(); } catch {}
|
| 206 |
+
// An unregistered service worker keeps controlling open pages until they close and can
|
| 207 |
+
// re-cache files they load, so sweep the caches once more shortly after.
|
| 208 |
+
setTimeout(async () => { try { for (const k of await caches.keys()) await caches.delete(k); } catch {} }, 3000);
|
| 209 |
+
const after = (await navigator.storage?.estimate?.().catch(() => null))?.usage ?? 0;
|
| 210 |
+
const freed = Math.max(0, before - after);
|
| 211 |
+
note.textContent = freed > 1e6 ? `Cleared ${fmtBytes(freed)} this embedded view had stored. Your data on LocalWebAgent's own page is untouched.` : "";
|
| 212 |
+
}
|
| 213 |
|
| 214 |
/** After boot: if the server has a newer Linux image than the installed one, offer it. */
|
| 215 |
async function checkForNewImage() {
|
sw.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
| 6 |
// (__vm__/disk.ext2), backed by the chunks the setup screen stored in Cache Storage.
|
| 7 |
// 4. Adds the cross-origin isolation headers (COOP/COEP) that SharedArrayBuffer,
|
| 8 |
// CheerpX and multi-threaded WASM need, even when a host forgets to send them.
|
| 9 |
-
const SHELL_VERSION = "lwa-shell-0.9.
|
| 10 |
const CX_ORIGIN = "https://cxrtnc.leaningtech.com";
|
| 11 |
const CX_CACHE_PREFIX = "lwa-cheerpx-";
|
| 12 |
const DISK_CACHE = "lwa-disk";
|
|
|
|
| 6 |
// (__vm__/disk.ext2), backed by the chunks the setup screen stored in Cache Storage.
|
| 7 |
// 4. Adds the cross-origin isolation headers (COOP/COEP) that SharedArrayBuffer,
|
| 8 |
// CheerpX and multi-threaded WASM need, even when a host forgets to send them.
|
| 9 |
+
const SHELL_VERSION = "lwa-shell-0.9.2";
|
| 10 |
const CX_ORIGIN = "https://cxrtnc.leaningtech.com";
|
| 11 |
const CX_CACHE_PREFIX = "lwa-cheerpx-";
|
| 12 |
const DISK_CACHE = "lwa-disk";
|