Skip to content

ui: move Llama Chat to SvelteKit 3 and its built-in service worker - #70

Closed
allozaur wants to merge 6 commits into
masterfrom
allozaur/chore/ui-sveltekit-3
Closed

allozaur wants to merge 6 commits into
masterfrom
allozaur/chore/ui-sveltekit-3

Conversation

@allozaur

@allozaur allozaur commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Overview

Llama Chat moves to SvelteKit 3, and its offline support to SvelteKit's own service worker. Nothing changes for the user: the app looks and works as before, installs as a PWA and keeps working offline.

Additional information

Part 1 of 12 of the work-in-progress stack on the fork, based on master, which has the move to ui/ since ggml-org#32032 was merged. Every layer above it, from the design system (#22) up, builds on SvelteKit 3. It also carries the fork-only commit that the move's fork PR (#54) had on top: the dev proxy calls llama-server without the page's Origin, so vite dev passes the server's cross-origin check from a LAN or Tailscale address.

Most of the diff is mechanical: SvelteKit 3 drops $lib, so every import of the app's own code becomes a #lib/... subpath import. The changes that need a review are the configs, the service worker and a handful of base-path and navigation calls, listed below.

What changed

Dependencies

  • SvelteKit 3.2 (the latest), @sveltejs/adapter-static 4, @sveltejs/vite-plugin-svelte 7, Vite 8, TypeScript 6, Svelte 5.57, Tailwind 4.3.5, Storybook 10.6.6 and ESLint 10. Storybook stays on its stable line: 10.6 runs on Vite 8 and SvelteKit 3, so the 11 alpha the first attempt needed is no longer necessary.
  • The lockfile is regenerated: the old one could not resolve the new peer ranges. The repo's min-release-age=7 holds every version to one released at least a week ago, except SvelteKit 3.2.0: it was locked on 17 November, hours before its seventh day, with a one-off --min-release-age=0 that moved only @sveltejs/kit (its new dependency was already in the lockfile). npm ci installs the locked version under the rule.
  • @vite-pwa/sveltekit, workbox-window and the Workbox overrides go.
  • The first commit, on its own, replaces the deprecated mdast stub with @types/mdast, moves the katex override to 0.19.0, overrides the deprecated packages under workbox-build and http-server, and takes the non-breaking npm audit fixes.
  • The last commit overrides minimatch to 11.0.5. 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 through glob patterns) affects below 11.0.1; their own fixed releases are all younger than the repo's 7-day min-release-age. All three only call new Minimatch(), match() and minimatch(), which minimatch 11 keeps. The SvelteKit, adapter and Workbox findings left by the first commit go with the move to SvelteKit 3, so npm audit finds nothing on this branch.

Config

  • svelte.config.js is gone: its options (the static adapter, the single bundle, relative paths, the hash router, mdsvex) move into sveltekit({ ... }) in vite.config.ts, as SvelteKit 3 expects. ESLint reads them through @sveltejs/load-config.
  • tsconfig.json extends $app/tsconfig, which SvelteKit 3 generates.
  • package.json maps #lib/* to ./src/lib/*.
  • npm run lint, storybook and build-storybook run svelte-kit sync first, as check already did: $app/tsconfig only exists after it, and the repo's .npmrc installs without running prepare.

Imports

  • $lib/X becomes #lib/X.ts, #lib/X.svelte.ts for a rune module or #lib/X/index.ts for a folder, in the app, the tests and the stories: the specifier names the file on disk, which the migration guide allows and SvelteKit 3's tsconfig (allowImportingTsExtensions) type-checks. The type declarations in types/*.d.ts keep .js, the module a declaration describes, as TypeScript takes no .d.ts specifier in import { type ... }. $app/environment becomes $app/env. Import order and line wrapping follow from the longer paths.
  • SvelteKit 3 treats modules named server.* and folders named server/ as server-only and refuses to bundle them for the browser. The server status components move to components/app/servers/, where the servers feature (ui: run chat against more llama.cpp servers, added by URL or paired through a tunnel #35) puts its own; the store and enums become stores/llama-server.svelte.ts and enums/llama-server.enums.ts, as ui: run chat against more llama.cpp servers, added by URL or paired through a tunnel #35 has a stores/servers.svelte.ts. Their exports keep their names.

Base path and navigation

  • base from $app/paths is gone in SvelteKit 3. Requests to the server go through a small withBase() helper over asset(), and the Hugging Face icon uses asset() directly.
  • replaceState and goto(..., { replaceState }) are deprecated: the deep-link and ?add cleanups use goto(url, { replace: true, shallow: true }). The models page no longer records those shallow navigations as a page to return to.
  • page.url is read-only now, so the copies are made from page.url.href; the error page reads page from $app/state instead of $app/stores.
  • Two Markdown plugins declare the data they attach to hast and mdast nodes, which TypeScript 6 checks, and links get rel as a list.

Service worker

  • src/service-worker/index.ts, built by SvelteKit, precaches the app shell, the immutable bundle, manifest.webmanifest, _app/version.json and the static files, fetched with cache: 'reload' so a stale index.html from the HTTP cache can't end up next to the new bundle. It serves only those from cache; API requests always go to the network, as they did with Workbox's navigateFallback: ''.
  • usePwa() registers it at service-worker.js (SvelteKit's own registration is off) and keeps the update flow: poll for a new worker, show the refresh prompt when one is waiting, activate it on SKIP_WAITING and reload.
  • A page the worker doesn't control learns of a new build from SvelteKit's updated ($app/state), which checks _app/version.json on navigation, on focus and every hour. It replaces the version Llama Chat kept in localStorage. Reload on the prompt fetches and activates the new worker before reloading, so one click lands on the new build on either path.
  • A small Vite plugin serves and emits manifest.webmanifest, which the PWA plugin used to generate. Its media type, Vite environment and name are constants in pwa.constants.ts, and the header name comes from HEADERS. The manifest gains lang and scope.
  • static/sw.js replaces the old Workbox worker for browsers that installed an earlier build: their update check fetches it, it removes itself and its caches, and the reloaded page registers service-worker.js.
  • llama-server serves service-worker.js with no-cache like sw.js, and answers both paths with the self-removing worker when the built-in UI is off or replaced. The CMake asset check takes either service-worker.js or, from the prebuilt archives of earlier builds that CI downloads, workbox-*.js.
  • The build plugins that post-process index.html run in Vite's buildApp hook, after the adapter has written the output, instead of a setTimeout in closeBundle.

Svelte 5's current patterns (a commit of its own, following the svelte-core-bestpractices guidance on svelte.dev/docs/ai)

  • nearViewport, autoResizeTextarea and the custom CSS injection are attachments ({@attach}) instead of actions (use:)
  • class lists use arrays instead of class: directives
  • the three chat contexts come from createContext, typed, instead of setContext/getContext with string keys
  • usePwa keeps its state in $state instead of a store, and no effect checks browser
  • ActionIconCopyToClipboard, the last legacy-mode component, takes $props()

ESLint 10 (a commit of its own; ESLint 9 now reports itself as unsupported)

  • eslint 10, @eslint/js 10 and @eslint/compat 2; every other plugin already supports it.
  • Its new recommended rules: errors rethrown from a catch keep the original as cause (the MCP service and store, the API fetch helper, PDF processing), and two variables lose an initial value that was always overwritten.
Restacking the layers above

The rest of the stack is rebased onto this branch. To keep the rebase from conflicting on every import, each commit above was first rewritten with the same import codemod (a tree rewrite, no patch replay), then rebased; what was left were real conflicts, resolved per commit. Fixes the upgrade needed in the layers above went into the commits that introduced the code:

On 16 November the move (#54) was merged upstream, so this layer now sits on master, with master's tools-tab fix and its test converted to #lib imports. The npx package (#69) joined the stack in the same restack, between the Storybook (#67) and Llama Harness (#55). Each lockfile that conflicted was regenerated from its commit's package.json; this branch's lockfile also drops 124 lines of extraneous entries the first install left behind.

Typed routes (route ids, navigation through resolve(), svelte/no-navigation-without-resolve back on) are a PR of their own at the top of the stack, #73: every layer adds routes, so doing it here would conflict with each of them.

Testing

Known gaps:

  • Vite 8 warns that the config's extensionless imports won't work with its future native config loader.

Requirements

@github-actions github-actions Bot added documentation Improvements or additions to documentation server labels Nov 16, 2026
@allozaur
allozaur force-pushed the allozaur/chore/ui-sveltekit-3 branch from a14fad0 to 1c5a2a1 Compare November 16, 2026 16:12
@allozaur
allozaur added this pull request to stack #71 November 16, 2026 16:13
llama-server refuses browser requests whose Origin does not match its own
host unless --cors-origins allows it, and the Vite proxy forwarded the
page's Origin (localhost:5173, or a LAN or Tailscale address). Loading a
model, saving tools and /v1 calls failed with 403 under `vite dev`.

The proxy now calls the server with its own Host and no Origin, WebSocket
upgrades included. Sec-Fetch-Site still passes through, so requests from
other sites stay refused.

Assisted-by: Claude (Opus 5.5 Medium)
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)
@allozaur
allozaur removed this pull request from stack #71 November 16, 2026 16:49
@allozaur
allozaur force-pushed the allozaur/chore/ui-sveltekit-3 branch from 1c5a2a1 to 217111c Compare November 16, 2026 16:50
@allozaur
allozaur changed the base branch from allozaur/refactor/ui-folders to master November 16, 2026 16:50
@allozaur
allozaur added this pull request to stack #72 November 16, 2026 16:50
@allozaur
allozaur force-pushed the allozaur/chore/ui-sveltekit-3 branch from 217111c to a6f4a26 Compare November 16, 2026 17:36
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)
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)
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)
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)
Comment thread ui/apps/chat/README.md Outdated
| `DialogConversationRename` | Edit conversation title |

**Server/Model Components** (`app/server/`, `app/models/`):
**Server/Model Components** (`app/llama-server/`, `app/models/`):

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not fully convinced to this rename... probably would be better to have app/servers

Comment on lines +15 to +24
res.setHeader('Content-Type', 'application/manifest+json');
res.end(MANIFEST_SOURCE);
});
},
generateBundle() {
if (this.environment.name !== 'client') return;

this.emitFile({ fileName: MANIFEST_FILE, source: MANIFEST_SOURCE, type: 'asset' });
},
name: 'llama-ui:pwa-manifest'

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's get rid of magic strings

@allozaur
allozaur force-pushed the allozaur/chore/ui-sveltekit-3 branch from 354cae6 to 0c13a21 Compare November 17, 2026 10:31
@allozaur
allozaur removed this pull request from stack #72 November 17, 2026 11:15
@allozaur allozaur closed this Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation server/ui server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant