mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 13:48:13 +01:00
The product, its assistant, the repo, the host and every unit on the box now share one name. 638 files, ~3,000 mentions: UI copy, config, env keys (FLEETCROWN_* -> LOKI_*), systemd units (fleetcrown-* -> loki-*), docs, articles, the deploy workflow other repos reuse, and nine file names. - Three article slugs carried the old name and had been shared; permanent redirects keep those links alive (next.config.ts). - test-no-retired-name.sh now also forbids the old product name across the whole repo, so the rename cannot creep back through templates and examples. - ASSISTANT_STACK collapses the product and the assistant into one entry, because they are now the same name. Infra was cut over ahead of this merge: /opt/loki, loki-* units, the `loki` database and role, loki.orangecat.ch (old host 308s to it; /api, /widget, /embed keep proxying), GitHub repos bitbaum/loki and bitbaum/loki-releases. The Resend sending domain stays fleetcrown.orangecat.ch until the new domain is verified in DNS. Claude-Session: https://claude.ai/code/session_016YJVAanfj8keVSXyZnTemh Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
64 lines
1.9 KiB
JavaScript
64 lines
1.9 KiB
JavaScript
/**
|
|
* Loki service worker — handles Web Push events.
|
|
*
|
|
* Scope: root ("/") so notifications fire regardless of which app page is open
|
|
* (or none — that's the point of background push).
|
|
*
|
|
* Two events:
|
|
* - "push" — show the OS notification using the payload body
|
|
* - "notificationclick" — bring an open tab to focus, or open one at the URL
|
|
*/
|
|
|
|
self.addEventListener("install", (event) => {
|
|
event.waitUntil(self.skipWaiting());
|
|
});
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
event.waitUntil(self.clients.claim());
|
|
});
|
|
|
|
self.addEventListener("push", (event) => {
|
|
let data = { title: "Loki", body: "Agent update", url: "/control", tag: "loki" };
|
|
if (event.data) {
|
|
try {
|
|
data = { ...data, ...event.data.json() };
|
|
} catch {
|
|
data.body = event.data.text() || data.body;
|
|
}
|
|
}
|
|
event.waitUntil(
|
|
self.registration.showNotification(data.title, {
|
|
body: data.body,
|
|
tag: data.tag,
|
|
data: { url: data.url },
|
|
// Coalesce same-tag notifications instead of stacking; the user only
|
|
// needs to see the latest state for a given tab.
|
|
renotify: false,
|
|
}),
|
|
);
|
|
});
|
|
|
|
self.addEventListener("notificationclick", (event) => {
|
|
const url = event.notification.data?.url || "/control";
|
|
event.notification.close();
|
|
event.waitUntil(
|
|
(async () => {
|
|
const all = await self.clients.matchAll({ type: "window", includeUncontrolled: true });
|
|
// Focus a Loki tab if one's already open; navigate it to the target.
|
|
for (const client of all) {
|
|
try {
|
|
const u = new URL(client.url);
|
|
if (u.origin === self.location.origin) {
|
|
await client.focus();
|
|
if ("navigate" in client) await client.navigate(url);
|
|
return;
|
|
}
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
}
|
|
await self.clients.openWindow(url);
|
|
})(),
|
|
);
|
|
});
|