agentacta 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/public/sw.js ADDED
@@ -0,0 +1,42 @@
1
+ const CACHE = 'agentacta-v2';
2
+ const STATIC = ['/', '/icon.svg', '/manifest.json'];
3
+
4
+ self.addEventListener('install', e => {
5
+ e.waitUntil(caches.open(CACHE).then(c => c.addAll(STATIC)));
6
+ self.skipWaiting();
7
+ });
8
+
9
+ self.addEventListener('activate', e => {
10
+ e.waitUntil(caches.keys().then(keys => Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)))));
11
+ self.clients.claim();
12
+ });
13
+
14
+ self.addEventListener('fetch', e => {
15
+ const url = new URL(e.request.url);
16
+ // Don't cache API calls
17
+ if (url.pathname.startsWith('/api/')) return;
18
+
19
+ // Network-first for CSS/JS so deploys are never stale
20
+ if (url.pathname.endsWith('.css') || url.pathname.endsWith('.js')) {
21
+ e.respondWith(
22
+ fetch(e.request).then(r => {
23
+ const clone = r.clone();
24
+ caches.open(CACHE).then(c => c.put(e.request, clone));
25
+ return r;
26
+ }).catch(() => caches.match(e.request))
27
+ );
28
+ return;
29
+ }
30
+
31
+ // Cache-first for other static assets
32
+ e.respondWith(
33
+ caches.match(e.request).then(cached => {
34
+ if (cached) return cached;
35
+ return fetch(e.request).then(r => {
36
+ const clone = r.clone();
37
+ caches.open(CACHE).then(c => c.put(e.request, clone));
38
+ return r;
39
+ });
40
+ })
41
+ );
42
+ });