Files
pipelines/web/sw.js
T
alan ff36e777c9 web: compose with Enter, share chat titles, reserve the star
Enter inserts a newline and Ctrl/Cmd+Enter sends; slash commands still run on
Enter. Chat renames are stored in the server registry so every device sees the
same title, with a one-time upload of old local titles. The star no longer
covers the row status, and shell frames patch the background bar in place so the
composer stays mounted while streaming.
2026-10-20 03:44:16 +01:00

44 lines
1.5 KiB
JavaScript

// A shell cache for an installed Pipelines app. The API (the WebSocket proxy and
// artifact files) is never cached; static files prefer the network and fall back
// to the last good copy so an installed app still opens when the server is away.
const CACHE = "pipelines-shell-v2";
const SHELL = ["/", "/index.html", "/manifest.webmanifest", "/favicon.svg"];
self.addEventListener("install", (event) => {
event.waitUntil(
caches
.open(CACHE)
.then((cache) => cache.addAll(SHELL))
.catch(() => undefined)
.then(() => self.skipWaiting()),
);
});
self.addEventListener("activate", (event) => {
event.waitUntil(
caches
.keys()
.then((keys) => Promise.all(keys.filter((key) => key !== CACHE).map((key) => caches.delete(key))))
.then(() => self.clients.claim()),
);
});
self.addEventListener("fetch", (event) => {
const request = event.request;
if (request.method !== "GET") return;
const url = new URL(request.url);
if (url.origin !== self.location.origin) return;
if (url.pathname.startsWith("/connect") || url.pathname.startsWith("/artifacts/")) return;
event.respondWith(
fetch(request)
.then((response) => {
if (response.ok) {
const copy = response.clone();
caches.open(CACHE).then((cache) => cache.put(request, copy)).catch(() => undefined);
}
return response;
})
.catch(() => caches.match(request).then((cached) => cached ?? caches.match("/"))),
);
});