ltcai 0.1.4 → 0.1.9

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/static/sw.js ADDED
@@ -0,0 +1,51 @@
1
+ // Lattice AI Service Worker — enables PWA install on Android/iOS
2
+ // Strategy: network-first for API, cache-first for static assets.
3
+ const CACHE = "ltcai-v1";
4
+ const STATIC = [
5
+ "/",
6
+ "/manifest.json",
7
+ "/icons/icon-192.png",
8
+ "/icons/icon-512.png",
9
+ "/icons/apple-touch-icon.png",
10
+ ];
11
+
12
+ self.addEventListener("install", e => {
13
+ e.waitUntil(
14
+ caches.open(CACHE).then(c => c.addAll(STATIC)).then(() => self.skipWaiting())
15
+ );
16
+ });
17
+
18
+ self.addEventListener("activate", e => {
19
+ e.waitUntil(
20
+ caches.keys().then(keys =>
21
+ Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)))
22
+ ).then(() => clients.claim())
23
+ );
24
+ });
25
+
26
+ self.addEventListener("fetch", e => {
27
+ const url = new URL(e.request.url);
28
+
29
+ // API calls → always network (never cache)
30
+ if (url.pathname.startsWith("/chat") ||
31
+ url.pathname.startsWith("/agent") ||
32
+ url.pathname.startsWith("/models") ||
33
+ url.pathname.startsWith("/local") ||
34
+ url.pathname.startsWith("/tools") ||
35
+ url.pathname.startsWith("/knowledge") ||
36
+ url.pathname.startsWith("/history")) {
37
+ e.respondWith(fetch(e.request));
38
+ return;
39
+ }
40
+
41
+ // Static HTML → network-first, fall back to cache
42
+ e.respondWith(
43
+ fetch(e.request)
44
+ .then(res => {
45
+ const clone = res.clone();
46
+ caches.open(CACHE).then(c => c.put(e.request, clone));
47
+ return res;
48
+ })
49
+ .catch(() => caches.match(e.request))
50
+ );
51
+ });