diff --git a/ui/apps/chat/eslint.config.js b/ui/apps/chat/eslint.config.js index a731c90d5359..8b03c8098097 100644 --- a/ui/apps/chat/eslint.config.js +++ b/ui/apps/chat/eslint.config.js @@ -350,7 +350,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, @@ -405,6 +404,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 } } + }, { // Tests and stories exercise an extension's code directly files: ['tests/**'], 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 e94ff35e1c82..ffcfada3b83b 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 @@ -21,6 +21,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; @@ -222,7 +223,7 @@ const conversationDeleted = await chatStore.removeSystemPromptPlaceholder(message.id); if (conversationDeleted) { - goto(ROUTES.START); + goto(resolve(ROUTES.START)); } return; @@ -263,7 +264,7 @@ const conversationDeleted = await chatStore.removeSystemPromptPlaceholder(message.id); if (conversationDeleted) { - goto(ROUTES.START); + goto(resolve(ROUTES.START)); } } else { chatActions.delete(message); @@ -343,7 +344,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 dbc0b8ea0522..9f2c601c3dfd 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 @@ -93,7 +93,7 @@ {#if faviconUrl} @@ -118,7 +118,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/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 @@ diff --git a/ui/apps/chat/src/routes/+layout.svelte b/ui/apps/chat/src/routes/+layout.svelte index f3f58fb65816..dc253eed3e94 100644 --- a/ui/apps/chat/src/routes/+layout.svelte +++ b/ui/apps/chat/src/routes/+layout.svelte @@ -9,7 +9,6 @@ FAVICON_PATHS, FAVICON_SELECTORS, HEADERS, - MODELS_ROUTE_ID, ROUTES, SETTINGS_KEYS, TOOLTIP_DELAY_DURATION @@ -199,7 +198,7 @@ untrack(() => { if ( - (page.route.id === '/(chat)' || !!page.params.id || page.route.id === MODELS_ROUTE_ID) && + (page.route.id === ROUTES.START || !!page.params.id || page.route.id === ROUTES.MODELS) && page.status !== 401 && page.status !== 403 ) { @@ -389,7 +388,7 @@ - {#if deviceStore.isMobile && !page.url.hash.includes(ROUTES.SEARCH) && !uiStore.isComposerExpanded} + {#if deviceStore.isMobile && page.route.id !== ROUTES.SEARCH && !uiStore.isComposerExpanded}
{ if (browser && !deviceStore.isMobile) { - goto(ROUTES.START, { replace: true }); + goto(resolve(ROUTES.START), { replace: true }); } }); diff --git a/ui/apps/chat/tests/client/extension-navigation.svelte.test.ts b/ui/apps/chat/tests/client/extension-navigation.svelte.test.ts index 73070b6d572b..b0c8cfe15618 100644 --- a/ui/apps/chat/tests/client/extension-navigation.svelte.test.ts +++ b/ui/apps/chat/tests/client/extension-navigation.svelte.test.ts @@ -3,8 +3,8 @@ // sits right after Models, opens its dialog on a desktop and its page // on a phone, is lit on its page, and is gone, with everything still working, // once its extension is off. - import '../../src/app.css'; +import { RouterService } from '#lib/services/router.service.ts'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; const pageState = vi.hoisted(() => ({ @@ -32,7 +32,7 @@ import { Puzzle } from '@lucide/svelte'; import SidebarNavigationFooter from '#lib/components/app/navigation/SidebarNavigation/SidebarNavigationFooter.svelte'; import { APP_NAME, - EXTENSION_PAGE_ROUTE_ID, + ROUTES, SIDEBAR_ACTIONS_ITEMS, SIDEBAR_FOOTER_ITEMS } from '#lib/constants/index.ts'; @@ -46,7 +46,7 @@ import { render } from 'vitest-browser-svelte'; const ACTIONS = SIDEBAR_ACTIONS_ITEMS.map((item) => item.tooltip); const FOOTER = SIDEBAR_FOOTER_ITEMS.map((item) => item.tooltip); const FIXTURE_ID = 'navigation-fixture'; -const FIXTURE_ROUTE = '#/fixture-page'; +const FIXTURE_ROUTE = RouterService.extensionPage('fixture-page'); const gotoMock = vi.mocked(goto); const refreshAllMock = vi.mocked(refreshAll); @@ -135,7 +135,7 @@ describe('navigation and pages extension points', () => { it('lights a contributed item only while its page is the one shown', async () => { await extensions.setEnabled(FIXTURE_ID, true); - showRoute(EXTENSION_PAGE_ROUTE_ID, { extensionPage: 'fixture-page' }); + showRoute(ROUTES.EXTENSION_PAGE, { extensionPage: 'fixture-page' }); const onPage = render(SidebarNavigationFooter, {}); @@ -146,7 +146,7 @@ describe('navigation and pages extension points', () => { onPage.unmount(); // another extension page, such as a path nothing is contributed for - showRoute(EXTENSION_PAGE_ROUTE_ID, { extensionPage: 'other-page' }); + showRoute(ROUTES.EXTENSION_PAGE, { extensionPage: 'other-page' }); const elsewhere = render(SidebarNavigationFooter, {}); @@ -213,7 +213,7 @@ describe('navigation and pages extension points', () => { it('renders the page contributed for the path, under its title', async () => { await extensions.setEnabled(FIXTURE_ID, true); - showRoute(EXTENSION_PAGE_ROUTE_ID, { extensionPage: 'fixture-page' }); + showRoute(ROUTES.EXTENSION_PAGE, { extensionPage: 'fixture-page' }); const screen = render(ExtensionPage); diff --git a/ui/apps/chat/tests/client/mcp-navigation-glue.svelte.test.ts b/ui/apps/chat/tests/client/mcp-navigation-glue.svelte.test.ts index c1a7ef5047f0..3095660c8e76 100644 --- a/ui/apps/chat/tests/client/mcp-navigation-glue.svelte.test.ts +++ b/ui/apps/chat/tests/client/mcp-navigation-glue.svelte.test.ts @@ -3,7 +3,7 @@ // and the background health checks, which stop when the extension goes off, // when the live connections close too. -import { ROUTES, SETTINGS_KEYS, SIDEBAR_FOOTER_ITEMS } from '#lib/constants/index.ts'; +import { SETTINGS_KEYS, SIDEBAR_FOOTER_ITEMS } from '#lib/constants/index.ts'; import type { ExtensionContext, ExtensionPage, NavigationItem } from '#lib/extensions/index.ts'; import { contributeNavigation } from '#lib/extensions/mcp/navigation.ts'; import { contributePages } from '#lib/extensions/mcp/pages.ts'; @@ -45,7 +45,7 @@ describe('MCP navigation glue', () => { expect(item).toMatchObject({ id: 'mcp', placement: 'footer', - route: ROUTES.MCP_SERVERS, + route: '#/mcp-servers', tooltip: 'MCP' }); expect(item.dialog).toBeDefined(); @@ -70,7 +70,7 @@ describe('MCP navigation glue', () => { expect(mcpPage.title).toBe('MCP Servers'); expect(mcpPage.component).toBeDefined(); - expect(RouterService.extensionPage(mcpPage.path)).toBe(ROUTES.MCP_SERVERS); + expect(RouterService.extensionPage(mcpPage.path)).toBe('#/mcp-servers'); }); it('health-checks every server with a URL, again when the list changes, until deactivated', async () => { diff --git a/ui/apps/chat/tests/client/nested-surfaces.svelte.test.ts b/ui/apps/chat/tests/client/nested-surfaces.svelte.test.ts index 018b744bf061..bbf1c5ea6d4d 100644 --- a/ui/apps/chat/tests/client/nested-surfaces.svelte.test.ts +++ b/ui/apps/chat/tests/client/nested-surfaces.svelte.test.ts @@ -2,13 +2,13 @@ // group inset in the sidebar and a row in the group. This holds the rule app.css states for // them, on what the browser actually renders: a row's corners are concentric with its // group's, so its radius is the group's less the padding between their edges. - import '../../src/app.css'; import { Puzzle } from '@lucide/svelte'; import SidebarNavigationActions from '#lib/components/app/navigation/SidebarNavigation/SidebarNavigationActions.svelte'; import SidebarNavigationFooter from '#lib/components/app/navigation/SidebarNavigation/SidebarNavigationFooter.svelte'; import { SIDEBAR_ACTIONS_ITEMS, SIDEBAR_FOOTER_ITEMS } from '#lib/constants/index.ts'; import { extensions } from '#lib/extensions/index.ts'; +import { RouterService } from '#lib/services/router.service.ts'; import { beforeEach, describe, expect, it, vi } from 'vitest'; import { page } from 'vitest/browser'; import { render } from 'vitest-browser-svelte'; @@ -24,7 +24,7 @@ extensions.register({ icon: Puzzle, id: 'fixture', placement: 'footer', - route: '#/fixture', + route: RouterService.extensionPage('fixture'), tooltip: 'Fixture' }); } diff --git a/ui/apps/chat/tests/stories/chat/tabs/ChatTabsItem.stories.svelte b/ui/apps/chat/tests/stories/chat/tabs/ChatTabsItem.stories.svelte index 969a18d413fb..12cc0ecfbf4d 100644 --- a/ui/apps/chat/tests/stories/chat/tabs/ChatTabsItem.stories.svelte +++ b/ui/apps/chat/tests/stories/chat/tabs/ChatTabsItem.stories.svelte @@ -4,7 +4,9 @@ import { SquarePen } from '@lucide/svelte'; import { defineMeta } from '@storybook/addon-svelte-csf'; import ChatTabsItem from '#lib/components/app/chat/ChatTabs/ChatTabsItem.svelte'; - import { NEW_CHAT_LABEL, NEW_CHAT_TAB_ID } from '#lib/constants/index.ts'; + import { NEW_CHAT_LABEL, NEW_CHAT_TAB_ID, ROUTES } from '#lib/constants/index.ts'; + import { RouterService } from '#lib/services/router.service.ts'; + import { resolve } from '$app/paths'; const { Story } = defineMeta({ component: ChatTabsItem, @@ -14,7 +16,7 @@ title: 'Llama Chat/Chat/ChatTabs/ChatTabsItem' }); - const tab = { href: '#/chat/conv-1', id: 'conv-1', name: 'Rust borrow checker' }; + const tab = { href: RouterService.chat('conv-1'), id: 'conv-1', name: 'Rust borrow checker' }; const handlers = { onActivate: (id: string) => console.log('activate', id), @@ -37,7 +39,12 @@ diff --git a/ui/apps/chat/tests/unit/sidebar-items.test.ts b/ui/apps/chat/tests/unit/sidebar-items.test.ts index 3d9d9685d6b6..687bd933509a 100644 --- a/ui/apps/chat/tests/unit/sidebar-items.test.ts +++ b/ui/apps/chat/tests/unit/sidebar-items.test.ts @@ -1,10 +1,10 @@ // The sidebar's footer is the app's own items plus what extensions contribute: // without a contribution it must be whole, and a contribution must land // right after Models, ahead of the footer's other items. - import { SIDEBAR_FOOTER_ITEMS } from '#lib/constants/index.ts'; import { SidebarAction } from '#lib/enums/index.ts'; import type { NavigationItem } from '#lib/extensions/index.ts'; +import { RouterService } from '#lib/services/router.service.ts'; import { sidebarFooterItems } from '#lib/utils/sidebar-items.ts'; import type { Component } from 'svelte'; import { describe, expect, it } from 'vitest'; @@ -18,7 +18,7 @@ function makeItem(overrides: Partial = {}): NavigationItem { icon: Icon, id: 'fake', placement: 'footer', - route: '#/fake', + route: RouterService.extensionPage('fake'), tooltip: 'Fake', ...overrides };