feat(chat): add local-first conversation workspace

This commit is contained in:
2026-08-13 15:55:15 +08:00
parent d1d50d722c
commit 8991f78f9f
43 changed files with 5450 additions and 592 deletions
+7 -5
View File
@@ -1,18 +1,20 @@
{
"id": "/chat/",
"name": "Xiteng Chat",
"short_name": "Chat",
"description": "使用个人 Key Vault 凭据的轻量 AI 对话界面",
"start_url": "/",
"scope": "/",
"description": "本地优先、可选登录同步的轻量 AI 对话界面",
"start_url": "/chat/",
"scope": "/chat/",
"display": "standalone",
"launch_handler": {"client_mode": "navigate-existing"},
"background_color": "#f4f4f0",
"theme_color": "#171717",
"orientation": "any",
"lang": "zh-CN",
"categories": ["productivity", "utilities"],
"icons": [
{"src": "/icons/icon-192.png", "sizes": "192x192", "type": "image/png"},
{"src": "/icons/icon-512.png", "sizes": "512x512", "type": "image/png"},
{"src": "/icons/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any"},
{"src": "/icons/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any"},
{"src": "/icons/icon-maskable-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable"}
]
}
+17 -8
View File
@@ -1,8 +1,11 @@
const cacheName = "xiteng-chat-shell-v4";
const cachePrefix = "xiteng-chat-";
const cacheName = `${cachePrefix}shell-v8`;
const basePath = "/chat";
const shellAssets = [
"/",
"/manifest.webmanifest",
`${basePath}/`,
`${basePath}/manifest.webmanifest`,
"/favicon.svg",
"/icons/favicon-32.png",
"/icons/icon-192.png",
"/icons/icon-512.png",
"/icons/icon-maskable-512.png",
@@ -22,7 +25,7 @@ self.addEventListener("install", (event) => {
self.addEventListener("activate", (event) => {
event.waitUntil(caches.keys()
.then((keys) => Promise.all(keys.filter((key) => key !== cacheName).map((key) => caches.delete(key))))
.then((keys) => Promise.all(keys.filter((key) => key.startsWith(cachePrefix) && key !== cacheName).map((key) => caches.delete(key))))
.then(() => self.clients.claim()));
});
@@ -30,19 +33,25 @@ 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 || url.pathname.startsWith("/api/") || url.pathname.startsWith("/outpost.goauthentik.io/")) return;
if (url.origin !== self.location.origin || url.pathname.startsWith(`${basePath}/api/`) || url.pathname.startsWith("/outpost.goauthentik.io/")) return;
if (request.mode === "navigate") {
event.respondWith(fetch(request).then((response) => {
if (response.ok) caches.open(cacheName).then((cache) => cache.put("/", response.clone()));
if (response.ok) {
const cacheable = response.clone();
void caches.open(cacheName).then((cache) => cache.put(`${basePath}/`, cacheable)).catch(() => {});
}
return response;
}).catch(async () => (await caches.match("/")) || Response.error()));
}).catch(async () => (await caches.match(`${basePath}/`)) || Response.error()));
return;
}
if (shellAssets.includes(url.pathname) || /\.(?:js|css|png|svg|ico|webmanifest)$/.test(url.pathname)) {
event.respondWith(caches.match(request).then((cached) => cached || fetch(request).then((response) => {
if (response.ok) caches.open(cacheName).then((cache) => cache.put(request, response.clone()));
if (response.ok) {
const cacheable = response.clone();
void caches.open(cacheName).then((cache) => cache.put(request, cacheable)).catch(() => {});
}
return response;
})));
}