From c98d44718b4404284bee1f671c98c91522e28fb5 Mon Sep 17 00:00:00 2001 From: Aleksander Grygier Date: Mon, 16 Nov 2026 09:17:27 +0100 Subject: [PATCH 01/10] ui: let the dev proxy pass llama-server's cross-origin check 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) --- ui/apps/chat/vite.config.ts | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/ui/apps/chat/vite.config.ts b/ui/apps/chat/vite.config.ts index cf88572a9c2f..5c69a43c078e 100644 --- a/ui/apps/chat/vite.config.ts +++ b/ui/apps/chat/vite.config.ts @@ -13,7 +13,7 @@ import { playwright } from '@vitest/browser-playwright'; import { mdsvex } from 'mdsvex'; import { dirname, resolve } from 'path'; import { fileURLToPath } from 'url'; -import { defineConfig, loadEnv, searchForWorkspaceRoot } from 'vite'; +import { defineConfig, loadEnv, type ProxyOptions, searchForWorkspaceRoot } from 'vite'; const __dirname = dirname(fileURLToPath(import.meta.url)); // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -35,6 +35,18 @@ const outDir = process.env.LLAMA_UI_OUT_DIR ?? './dist'; export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), 'VITE_PUBLIC_'); const SERVER_ORIGIN = env.VITE_PUBLIC_SERVER_ORIGIN || 'http://localhost:9931'; + // llama-server takes cross-origin browser requests only from --cors-origins, so the proxy + // calls it as its own page: the Host of the server and no Origin. Sec-Fetch-Site still + // passes through, so the server keeps refusing requests from other sites. + const toServer = (ws = false): ProxyOptions => ({ + changeOrigin: true, + configure: (proxy) => { + proxy.on('proxyReq', (req) => req.removeHeader('origin')); + proxy.on('proxyReqWs', (req) => req.removeHeader('origin')); + }, + target: SERVER_ORIGIN, + ws + }); return { build: { @@ -90,12 +102,12 @@ export default defineConfig(({ mode }) => { 'Cross-Origin-Opener-Policy': 'same-origin' }, proxy: { - '/cors-proxy': SERVER_ORIGIN, - '/models': SERVER_ORIGIN, - '/props': SERVER_ORIGIN, - '/slots': SERVER_ORIGIN, - '/tools': SERVER_ORIGIN, - '/v1': SERVER_ORIGIN + '/cors-proxy': toServer(), + '/models': toServer(), + '/props': toServer(), + '/slots': toServer(), + '/tools': toServer(), + '/v1': toServer() } }, From 20ec217a1d56d22a7c336cd605b74f7305d560fa Mon Sep 17 00:00:00 2001 From: Aleksander Grygier Date: Mon, 16 Nov 2026 19:30:42 +0100 Subject: [PATCH 02/10] ui: navigate through resolve() with typed route ids ROUTES holds the app's route ids, as page.route.id reports them, in place of hash strings and the separate *_ROUTE_ID constants. Every link and goto() goes through resolve() from $app/paths, which checks the route exists and returns its URL (#/models with the hash router). RouterService resolves the routes that take params: a chat, a project, a project's chat or new chat, and an extension's page. Tab links, sidebar items and extension navigation items carry the resolved URL's type, and checks for the current page compare page.route.id instead of the hash. svelte/no-navigation-without-resolve is on again, with type information for the app's modules so a URL typed as ResolvedPathname passes. Links that leave the app say so with rel="external"; the deep-link cleanups, which change the current page's own query, are marked as such. Assisted-by: Claude (Opus 5.5 Medium) --- ui/apps/chat/eslint.config.js | 7 +++- .../ChatMessage/ChatMessage.svelte | 7 ++-- ...atMessageToolCallBlockSearchResults.svelte | 4 +-- .../app/chat/ChatTabs/ChatTabsItem.svelte | 3 +- .../dialogs/DialogModelNotAvailable.svelte | 1 + .../app/mcp/McpServerIdentity.svelte | 2 +- .../ModelsDiscoverDetailsHeader.svelte | 4 +-- .../SidebarNavigation.svelte | 13 +++++--- .../SidebarNavigationActions.svelte | 6 +--- .../app/servers/ServerErrorSplash.svelte | 3 +- .../app/settings/SettingsMcpServers.svelte | 1 + .../src/lib/constants/routes.constants.ts | 32 +++++++++---------- .../chat/src/lib/constants/ui.constants.ts | 12 ++++--- ui/apps/chat/src/lib/services/index.ts | 2 +- .../chat/src/lib/services/router.service.ts | 11 ++++--- .../lib/stores/conversations/index.svelte.ts | 6 ++-- ui/apps/chat/src/lib/stores/tabs.svelte.ts | 9 +++--- ui/apps/chat/src/lib/stores/ui.svelte.ts | 13 ++++---- ui/apps/chat/src/lib/types/navigation.d.ts | 4 ++- ui/apps/chat/src/lib/utils/chat-tabs.ts | 10 +++--- ui/apps/chat/src/routes/(chat)/+page.svelte | 1 + .../src/routes/(chat)/chat/[id]/+page.svelte | 4 ++- ui/apps/chat/src/routes/+error.svelte | 5 +-- ui/apps/chat/src/routes/+layout.svelte | 9 +++--- ui/apps/chat/src/routes/search/+page.svelte | 3 +- .../client/nested-surfaces.svelte.test.ts | 1 - .../chat/tabs/ChatTabsItem.stories.svelte | 13 ++++++-- 27 files changed, 107 insertions(+), 79 deletions(-) diff --git a/ui/apps/chat/eslint.config.js b/ui/apps/chat/eslint.config.js index 330551d9d8d1..edbc71c487a3 100644 --- a/ui/apps/chat/eslint.config.js +++ b/ui/apps/chat/eslint.config.js @@ -266,7 +266,6 @@ export default ts.config( 'simple-import-sort/imports': ['error', { groups: [['.*']] }], 'svelte/no-at-html-tags': 'off', // This app uses hash-based routing (#/) where resolve() from $app/paths does not apply - 'svelte/no-navigation-without-resolve': 'off', // Sort HTML attributes alphabetically in the markup. The Svelte directives // (bind:/use:/animate:/style:/in:/out:/transition:/class:) sort first, @@ -321,6 +320,12 @@ export default ts.config( } } }, + { + // type information for the app's own modules too, so svelte/no-navigation-without-resolve + // accepts a URL typed as ResolvedPathname, such as RouterService.chat(id) + files: ['src/**/*.ts'], + languageOptions: { parserOptions: { projectService: true } } + }, { // Exclude generated build output and Storybook files from ESLint ignores: [ diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessage.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessage.svelte index 0086107eed80..f4172daaf969 100644 --- a/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessage.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessage.svelte @@ -30,6 +30,7 @@ import { parseFilesToMessageExtras } from '#lib/utils/browser-only.ts'; import { deriveAgenticSections } from '#lib/utils/index.ts'; import { goto } from '$app/navigation'; + import { resolve } from '$app/paths'; interface Props { class?: string; @@ -241,7 +242,7 @@ const conversationDeleted = await chatStore.removeSystemPromptPlaceholder(message.id); if (conversationDeleted) { - goto(ROUTES.START); + goto(resolve(ROUTES.START)); } return; @@ -282,7 +283,7 @@ const conversationDeleted = await chatStore.removeSystemPromptPlaceholder(message.id); if (conversationDeleted) { - goto(ROUTES.START); + goto(resolve(ROUTES.START)); } } else { chatActions.delete(message); @@ -362,7 +363,7 @@ isEditing = false; if (conversationDeleted) { - goto(ROUTES.START); + goto(resolve(ROUTES.START)); } else { focusMainChatForm(); } diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockSearchResults.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockSearchResults.svelte index 2ed631a4f4ae..48f3e7dec3d2 100644 --- a/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockSearchResults.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockSearchResults.svelte @@ -91,7 +91,7 @@ {#if faviconUrl} @@ -116,7 +116,7 @@ {result.title} diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatTabs/ChatTabsItem.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatTabs/ChatTabsItem.svelte index c01af20d6f4b..d5c5509568c2 100644 --- a/ui/apps/chat/src/lib/components/app/chat/ChatTabs/ChatTabsItem.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatTabs/ChatTabsItem.svelte @@ -10,10 +10,11 @@ TAB_SURFACE_IDLE_CLASS, UI_DATA_ATTRS } from '#lib/constants/index.ts'; + import type { ResolvedPathname } from '$app/types'; import type { Component } from 'svelte'; interface Tab { - href: string; + href: ResolvedPathname; /** Marks the new-chat tab. */ icon?: Component; id: string; diff --git a/ui/apps/chat/src/lib/components/app/dialogs/DialogModelNotAvailable.svelte b/ui/apps/chat/src/lib/components/app/dialogs/DialogModelNotAvailable.svelte index 6d5115a6c067..541db9bec157 100644 --- a/ui/apps/chat/src/lib/components/app/dialogs/DialogModelNotAvailable.svelte +++ b/ui/apps/chat/src/lib/components/app/dialogs/DialogModelNotAvailable.svelte @@ -26,6 +26,7 @@ url.searchParams.set(URL_PARAMS.MODEL, model); handleOpenChange(false); + // eslint-disable-next-line svelte/no-navigation-without-resolve -- the current page's own URL with its query changed, not a link to resolve goto(url.toString()); } diff --git a/ui/apps/chat/src/lib/components/app/mcp/McpServerIdentity.svelte b/ui/apps/chat/src/lib/components/app/mcp/McpServerIdentity.svelte index d55235b55afd..7a0630761683 100644 --- a/ui/apps/chat/src/lib/components/app/mcp/McpServerIdentity.svelte +++ b/ui/apps/chat/src/lib/components/app/mcp/McpServerIdentity.svelte @@ -54,7 +54,7 @@ class="shrink-0 text-muted-foreground hover:text-foreground" href={safeWebsiteUrl} onclick={(e) => e.stopPropagation()} - rel="noopener noreferrer" + rel="external noopener noreferrer" target="_blank" > diff --git a/ui/apps/chat/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsHeader.svelte b/ui/apps/chat/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsHeader.svelte index 136acf32e204..ca6b922920fe 100644 --- a/ui/apps/chat/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsHeader.svelte +++ b/ui/apps/chat/src/lib/components/app/models/discover/ModelsDiscoverDetails/ModelsDiscoverDetailsHeader.svelte @@ -73,7 +73,7 @@ aria-label="View base model on HuggingFace" class="shrink-0 text-muted-foreground transition-colors hover:text-foreground" href={HuggingFaceService.getModelUrl(baseModels[0])} - rel="noopener noreferrer" + rel="external noopener noreferrer" target="_blank" > @@ -86,7 +86,7 @@