Skip to content

Commit 67cf896

Browse files
authored
ui: move Llama Chat to SvelteKit 3 and its built-in service worker (#32463)
* ui: replace deprecated packages and fix npm audit findings Swap the mdast stub for @types/mdast, move the katex override to 0.19.0, and override glob, source-map and html-encoding-sniffer under workbox-build and http-server so installs no longer pull deprecated packages. Apply the non-breaking npm audit fixes to the lockfile. Assisted-by: Claude (Opus 5.5 Medium) * ui: migrate Llama Chat to SvelteKit 3 and its built-in service worker Move to SvelteKit 3, Vite 8, TypeScript 6 and Storybook 10.6. The SvelteKit options move from svelte.config.js into sveltekit() in vite.config.ts, $lib imports become #lib subpath imports from package.json, and $app/environment becomes $app/env. Modules named server.* or living under a server/ folder are server-only in SvelteKit 3, so the llama-server components, store and enums move to llama-server names. @vite-pwa/sveltekit and Workbox give way to SvelteKit's own service worker in src/service-worker, registered by usePwa(), which precaches the app files and leaves API requests to the network. A small plugin emits manifest.webmanifest. static/sw.js removes the worker of older builds, and llama-server serves a self-removing service-worker.js as well as sw.js when the built-in UI is off or replaced. Assisted-by: Claude (Opus 5.5 Medium) * ui: use SvelteKit 3's update detection and Svelte 5's current patterns A page the service worker doesn't control now learns of a new build from SvelteKit itself: `updated` from $app/state checks _app/version.json on navigation, on focus and every hour. It replaces the version Llama Chat kept in localStorage and compared by hand. Reload on the update prompt pulls in the new worker and activates it before reloading, so one click lands on the new build, whether or not a worker controlled the page. Following Svelte's current guidance: - usePwa keeps its state in $state rather than a store, and no effect checks `browser` - nearViewport, autoResizeTextarea and the custom CSS injection are attachments ({@Attach}) rather than actions (use:) - class lists use arrays rather than class: directives - the chat contexts come from createContext, typed, in place of setContext/getContext with string keys - ActionIconCopyToClipboard takes $props() rather than `export let` Assisted-by: Claude (Opus 5.5 Medium) * ui: move to ESLint 10 ESLint 9 is out of support. Every plugin the app uses supports 10: typescript-eslint, eslint-plugin-svelte, perfectionist, simple-import-sort, eslint-plugin-storybook and eslint-config-prettier. @eslint/js and @eslint/compat follow. ESLint 10's recommended rules ask for two things the code now does: errors rethrown from a catch keep the caught error as their `cause`, and no variable starts with a value that every path overwrites. Assisted-by: Claude (Opus 5.5 Medium) * ui: override minimatch to clear npm audit's last finding ESLint 10.14, @eslint/config-array 0.23.5 and typescript-eslint 8.72 depend on minimatch 10, which GHSA-g3hv-75wg-m249 (denial of service via globparts amplification) affects below 11.0.1. Their fixed releases move to minimatch 11 but are all younger than the repo's 7-day min-release-age, so an override pins minimatch 11.0.5, the newest the rule allows. The three only call new Minimatch(), match() and minimatch(), which minimatch 11 keeps. npm audit now finds nothing. Assisted-by: Claude (Opus 5.5 Medium)
1 parent 4df3f29 commit 67cf896

724 files changed

Lines changed: 12417 additions & 16865 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎scripts/ui-assets.cmake‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ function(ui_validate_assets files in_dir)
7272
set(found_index FALSE)
7373
set(found_manifest FALSE)
7474
set(found_sw FALSE)
75+
# the service worker: SvelteKit's service-worker.js, or Workbox's workbox-*.js in the
76+
# prebuilt archives of builds before SvelteKit 3
77+
set(found_service_worker FALSE)
7578
set(found_build_json FALSE)
7679
set(found_version_json FALSE)
7780
set(found_bundle_js FALSE)
7881
set(found_bundle_css FALSE)
79-
set(found_workbox_js FALSE)
8082

8183
foreach(f ${files})
8284
get_filename_component(base "${f}" NAME)
@@ -86,6 +88,8 @@ function(ui_validate_assets files in_dir)
8688
set(found_manifest TRUE)
8789
elseif(base STREQUAL "sw.js")
8890
set(found_sw TRUE)
91+
elseif(base STREQUAL "service-worker.js" OR base MATCHES "^workbox.*\\.js$")
92+
set(found_service_worker TRUE)
8993
elseif(base STREQUAL "build.json")
9094
set(found_build_json TRUE)
9195
elseif(base STREQUAL "version.json")
@@ -94,8 +98,6 @@ function(ui_validate_assets files in_dir)
9498
set(found_bundle_js TRUE)
9599
elseif(base MATCHES "^bundle.*\\.css$")
96100
set(found_bundle_css TRUE)
97-
elseif(base MATCHES "^workbox.*\\.js$")
98-
set(found_workbox_js TRUE)
99101
endif()
100102
endforeach()
101103

@@ -109,6 +111,9 @@ function(ui_validate_assets files in_dir)
109111
if(NOT found_sw)
110112
list(APPEND missing "sw.js")
111113
endif()
114+
if(NOT found_service_worker)
115+
list(APPEND missing "service-worker.js (or workbox[hash].js in an older build)")
116+
endif()
112117
if(NOT found_build_json)
113118
list(APPEND missing "build.json")
114119
endif()
@@ -121,9 +126,6 @@ function(ui_validate_assets files in_dir)
121126
if(NOT found_bundle_css)
122127
list(APPEND missing "bundle[hash].css")
123128
endif()
124-
if(NOT found_workbox_js)
125-
list(APPEND missing "workbox[hash].js")
126-
endif()
127129

128130
if(missing)
129131
set(listing "")

‎tools/server/server-http.cpp‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,10 @@ bool server_http_context::init_listener(const common_params & params) {
564564
srv->Get(params.api_prefix + "/index.html", serve_asset_cached("index.html", true, cache_revalidate));
565565

566566
// All remaining assets registered directly from the embedded asset table.
567-
// PWA revalidation files (sw.js, manifest, version.json) use no-cache;
567+
// PWA revalidation files (service workers, manifest, version.json) use no-cache;
568568
// everything else is immutable.
569569
static const std::unordered_set<std::string> no_cache_names = {
570+
"service-worker.js",
570571
"sw.js",
571572
"manifest.webmanifest",
572573
"_app/version.json",
@@ -588,9 +589,10 @@ bool server_http_context::init_listener(const common_params & params) {
588589
}
589590

590591
// a browser that used the built-in UI keeps its service worker, so it shows the old UI even after the UI is replaced or disabled
591-
// answer the worker's update check with a worker that removes itself; a sw.js in public_path is served first
592+
// answer the worker's update check with a worker that removes itself; a worker file in public_path is served first
593+
// sw.js is the worker path of older UI builds, service-worker.js the current one
592594
if (!params.ui || !params.public_path.empty()) {
593-
srv->Get(params.api_prefix + "/sw.js", [](const httplib::Request &, httplib::Response & res) {
595+
const auto serve_sw_remove = [](const httplib::Request &, httplib::Response & res) {
594596
static constexpr const char * sw_remove_js = R"(
595597
self.addEventListener('install', () => self.skipWaiting());
596598
self.addEventListener('activate', (e) => e.waitUntil((async () => {
@@ -601,7 +603,9 @@ self.addEventListener('activate', (e) => e.waitUntil((async () => {
601603
)";
602604
res.set_header("Cache-Control", "no-cache");
603605
res.set_content(sw_remove_js, "application/javascript");
604-
});
606+
};
607+
srv->Get(params.api_prefix + "/sw.js", serve_sw_remove);
608+
srv->Get(params.api_prefix + "/service-worker.js", serve_sw_remove);
605609
}
606610
return true;
607611
}

‎ui/apps/chat/.storybook/preview.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { Preview } from '@storybook/sveltekit';
21
import '../src/app.css';
32
import ModeWatcherDecorator from './decorators/ModeWatcherDecorator.svelte';
43
import TooltipProviderDecorator from './decorators/TooltipProviderDecorator.svelte';
4+
import type { Preview } from '@storybook/sveltekit';
55

66
const preview: Preview = {
77
parameters: {

‎ui/apps/chat/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ ui/apps/chat/ → build → build/ui/apps/chat/dist/
209209
### SvelteKit Configuration
210210

211211
```javascript
212-
// svelte.config.js
212+
// vite.config.ts - options passed to sveltekit({ ... })
213213
adapter: adapter({
214214
pages: '../../../build/ui/apps/chat/dist', // Output directory
215215
assets: '../../../build/ui/apps/chat/dist', // Static assets
@@ -363,7 +363,7 @@ Components are organized in `app/` (application-specific) and `ui/` (shadcn-svel
363363
| `DialogConfirmation` | Generic confirmation for destructive actions |
364364
| `DialogConversationRename` | Edit conversation title |
365365

366-
**Server/Model Components** (`app/server/`, `app/models/`):
366+
**Server/Model Components** (`app/servers/`, `app/models/`):
367367

368368
| Component | Responsibility |
369369
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------- |

‎ui/apps/chat/eslint.config.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// For more info, see https://github.com/storybookjs/eslint-plugin-storybook#configuration-flat-config-format
2-
import svelteConfig from './svelte.config.js';
32
import { includeIgnoreFile } from '@eslint/compat';
43
import js from '@eslint/js';
4+
import { loadConfig } from '@sveltejs/load-config';
55
import prettier from 'eslint-config-prettier';
66
import perfectionist from 'eslint-plugin-perfectionist';
77
import simpleImportSort from 'eslint-plugin-simple-import-sort';
@@ -11,6 +11,7 @@ import globals from 'globals';
1111
import { fileURLToPath } from 'node:url';
1212
import ts from 'typescript-eslint';
1313

14+
const svelteConfig = (await loadConfig('./', { traverse: false }))?.config;
1415
const gitignorePath = fileURLToPath(new URL('./.gitignore', import.meta.url));
1516
// Require a blank line between sibling element-like nodes in a Svelte template
1617
// (elements, components, and the {#if} / {#each} / {#await} / {#snippet} /

0 commit comments

Comments
 (0)