Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ui/apps/chat/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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/**'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -222,7 +223,7 @@
const conversationDeleted = await chatStore.removeSystemPromptPlaceholder(message.id);

if (conversationDeleted) {
goto(ROUTES.START);
goto(resolve(ROUTES.START));
}

return;
Expand Down Expand Up @@ -263,7 +264,7 @@
const conversationDeleted = await chatStore.removeSystemPromptPlaceholder(message.id);

if (conversationDeleted) {
goto(ROUTES.START);
goto(resolve(ROUTES.START));
}
} else {
chatActions.delete(message);
Expand Down Expand Up @@ -343,7 +344,7 @@
isEditing = false;

if (conversationDeleted) {
goto(ROUTES.START);
goto(resolve(ROUTES.START));
} else {
focusMainChatForm();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<HoverCard.Trigger
class="hover:bg-muted/80 focus-visible:ring-ring inline-flex max-w-full items-center gap-1.5 rounded-full border bg-muted px-2.5 py-1 text-xs transition-colors outline-none focus-visible:ring-2"
href={safeUrl}
rel="noopener noreferrer"
rel="external noopener noreferrer"
target="_blank"
>
{#if faviconUrl}
Expand All @@ -118,7 +118,7 @@
<a
class="line-clamp-3 text-sm font-medium leading-snug hover:underline"
href={safeUrl}
rel="noopener noreferrer"
rel="external noopener noreferrer"
target="_blank">{result.title}</a
>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<ExternalLink class="size-icon-xs" />
Expand All @@ -86,7 +86,7 @@
<Button
class="h-auto gap-1.5 px-2.5 py-1.5 text-xs"
href={HuggingFaceService.getModelUrl(modelId)}
rel="noopener noreferrer"
rel="external noopener noreferrer"
size="sm"
target="_blank"
variant="secondary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
} from '#lib/stores/index.ts';
import { buildConversationTree, remToPx, sidebarFooterItems } from '#lib/utils/index.ts';
import { goto } from '$app/navigation';
import { resolve } from '$app/paths';
import { page } from '$app/state';
import { tick } from 'svelte';
import { SvelteSet } from 'svelte/reactivity';
Expand Down Expand Up @@ -157,7 +158,7 @@
});

$effect(() => {
if (deviceStore.isMobile && page.url.hash.includes(ROUTES.SEARCH)) {
if (deviceStore.isMobile && page.route.id === ROUTES.SEARCH) {
uiStore.isSidebarExpanded = false;
}
});
Expand Down Expand Up @@ -544,21 +545,21 @@

break;
case SidebarAction.PROJECTS:
navigateBehind(() => goto(ROUTES.PROJECTS));
navigateBehind(() => goto(resolve(ROUTES.PROJECTS)));

break;
case SidebarAction.MANAGE_MODELS:
openDialog(() => uiStore.openModelsManager());

break;
case SidebarAction.SERVERS:
if (isOnMobile) navigateBehind(() => goto(ROUTES.SERVERS));
if (isOnMobile) navigateBehind(() => goto(resolve(ROUTES.SERVERS)));
else openDialog(() => uiStore.openServers());

break;
// a dialog on a desktop or tablet; on a phone, a page of its own
case SidebarAction.SETTINGS:
if (isOnMobile) navigateBehind(() => goto(ROUTES.SETTINGS));
if (isOnMobile) navigateBehind(() => goto(resolve(ROUTES.SETTINGS)));
else openDialog(() => (settingsDialogOpen = true));

break;
Expand All @@ -583,7 +584,7 @@

<svelte:window bind:innerWidth onkeydown={handleKeydown} />

{#if innerWidth > 768 || !page.url.hash.includes(ROUTES.SEARCH)}
{#if innerWidth > 768 || page.route.id !== ROUTES.SEARCH}
<!-- svelte-ignore a11y_no_static_element_interactions -->
<aside
bind:this={asideEl}
Expand Down Expand Up @@ -646,7 +647,7 @@
class="pointer-events-auto size-10 rounded-full! md:size-9 {isStripHidden
? 'bg-transparent! hover:bg-transparent!'
: 'matte-key bg-surface-raised! hover:bg-surface-raised! dark:bg-muted-foreground/15! dark:hover:bg-muted-foreground/15!'}"
href={uiStore.isSidebarExpanded && !isLogoToggle ? ROUTES.START : undefined}
href={uiStore.isSidebarExpanded && !isLogoToggle ? resolve(ROUTES.START) : undefined}
icon={isLogoToggle && logoHovered
? uiStore.isSidebarExpanded
? PanelLeftClose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import { Button } from '@ggml-org/llama-ui/ui/button';
import { KeyboardShortcutInfo } from '#lib/components/app/index.ts';
import {
EXTENSION_PAGE_ROUTE_ID,
ICON_CLASS_DEFAULT,
ICON_STRIP_TRANSITION_DELAY_MULTIPLIER,
ICON_STRIP_TRANSITION_DURATION,
ROUTES,
SIDEBAR_ACTIONS_ITEMS
} from '#lib/constants/index.ts';
import { SidebarAction } from '#lib/enums/index.ts';
Expand Down Expand Up @@ -84,7 +84,7 @@
// an extension's item is lit while the page it opens is the one shown
if (item.contributed) {
return (
page.route.id === EXTENSION_PAGE_ROUTE_ID &&
page.route.id === ROUTES.EXTENSION_PAGE &&
RouterService.extensionPage(page.params.extensionPage ?? '') === item.contributed.route
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { projectsStore } from '#lib/stores/index.ts';
import type { MenuAction, Project } from '#lib/types/index.ts';
import { goto } from '$app/navigation';
import { resolve } from '$app/paths';

interface Props {
project: Project;
Expand All @@ -18,7 +19,7 @@
if (!confirmed) return;

await projectsStore.remove(project.id);
await goto(ROUTES.PROJECTS);
await goto(resolve(ROUTES.PROJECTS));
}

const actions = $derived<MenuAction[]>([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { ROUTES, TAB_SURFACE_CLASS, TAB_SURFACE_IDLE_CLASS } from '#lib/constants/index.ts';
import { RouterService } from '#lib/services/router.service.ts';
import type { Project } from '#lib/types/index.ts';
import { resolve } from '$app/paths';
import type { ResolvedPathname } from '$app/types';

interface Props {
/** The project page is the current page. */
Expand All @@ -18,7 +20,7 @@
let projectHref = $derived(RouterService.project(project.id));
</script>

{#snippet crumb(href: string, label: string, current: boolean)}
{#snippet crumb(href: ResolvedPathname, label: string, current: boolean)}
<a
aria-current={current ? 'page' : undefined}
class={[
Expand All @@ -35,7 +37,7 @@

<nav aria-label="Breadcrumb" class="flex min-w-0 shrink-0 items-center gap-0.5 text-sm">
{#if root}
{@render crumb(ROUTES.PROJECTS, 'Projects', false)}
{@render crumb(resolve(ROUTES.PROJECTS), 'Projects', false)}

<span class="text-muted-foreground">/</span>
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import { serverStore, settingsStore } from '#lib/stores/index.ts';
import { apiUrl } from '#lib/utils/api-base.ts';
import { goto } from '$app/navigation';
import { resolve } from '$app/paths';
import { fade, fly, scale } from 'svelte/transition';

interface Props {
Expand Down Expand Up @@ -86,7 +87,7 @@

// Show success state briefly, then navigate to home
setTimeout(() => {
goto(ROUTES.START);
goto(resolve(ROUTES.START));
}, 1000);
} else {
// API key is invalid - User Story A
Expand Down
52 changes: 25 additions & 27 deletions ui/apps/chat/src/lib/constants/routes.constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { RouteId } from '$app/types';

/** Query params the chat routes read from the URL. */
export const URL_PARAMS = {
/** Load the selected model instead of waiting for the first message. */
Expand All @@ -8,38 +10,34 @@ export const URL_PARAMS = {
QUERY: 'q'
} as const;

/**
* Route ids of the app's pages, as `page.route.id` reports them. Navigate with
* `resolve(ROUTES.MODELS)` from `$app/paths`, which checks the route exists and returns its URL
* (`#/models` with the hash router); URLs with ids come from RouterService.
*/
export const ROUTES = {
/** Chat base — for dynamic chat URLs use RouterService. */
CHAT: '#/chat',
/** A conversation outside any project. */
CHAT: '/(chat)/chat/[id]',
/** A page an extension contributes, see RouterService.extensionPage(). */
EXTENSION_PAGE: '/[extensionPage]',
/** Library. */
LIBRARY: '#/library',
/** MCP servers - a page on a phone, a dialog elsewhere. */
MCP_SERVERS: '#/mcp-servers',
LIBRARY: '/library',
/** Models manager. */
MODELS: '#/models',
MODELS: '/models',
/** A project's overview. */
PROJECT: '/(chat)/projects/[projectId]',
/** A chat opened inside its project. */
PROJECT_CHAT: '/(chat)/projects/[projectId]/chat/[id]',
/** The new-chat screen of a project. */
PROJECT_NEW_CHAT: '/(chat)/projects/[projectId]/chat/new',
/** Projects list. */
PROJECTS: '#/projects',
PROJECTS: '/projects',
/** Search — mobile-only full-page conversation search. */
SEARCH: '#/search',
SEARCH: '/search',
/** Servers - a page on a phone, a dialog elsewhere. */
SERVERS: '#/servers',
SERVERS: '/servers',
/** Settings - a page on a phone, a dialog elsewhere. */
SETTINGS: '#/settings',
SETTINGS: '/settings',
/** Root — start of the app. */
START: '#/'
} as const;

/** SvelteKit route id of the models manager, as `page.route.id` reports it. */
export const MODELS_ROUTE_ID = '/models';

/** SvelteKit route id of every page an extension contributes, as `page.route.id` reports it. */
export const EXTENSION_PAGE_ROUTE_ID = '/[extensionPage]';

/** SvelteKit route id of the servers page, as `page.route.id` reports it. */
export const SERVERS_ROUTE_ID = '/servers';

/** SvelteKit route id of the settings page, as `page.route.id` reports it. */
export const SETTINGS_ROUTE_ID = '/settings';

/** SvelteKit route id of the projects list, as `page.route.id` reports it. */
export const PROJECTS_ROUTE_ID = '/projects';
START: '/(chat)'
} as const satisfies Record<string, RouteId>;
19 changes: 7 additions & 12 deletions ui/apps/chat/src/lib/constants/ui.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ import {
SHORTCUT_SEARCH,
SHORTCUT_SETTINGS
} from './keyboard-shortcuts.constants';
import {
MODELS_ROUTE_ID,
PROJECTS_ROUTE_ID,
ROUTES,
SERVERS_ROUTE_ID,
SETTINGS_ROUTE_ID
} from './routes.constants';
import { ROUTES } from './routes.constants';
import { Library, Search, Server, Settings, SquarePen } from '@lucide/svelte';
import { SidebarAction, ToolSource } from '#lib/enums/index.ts';
import type { DesktopIconStripItem } from '#lib/types/index.ts';
import { resolve } from '$app/paths';

/** Delay before a copied affordance resets from its check to the copy icon. */
export const COPY_FEEDBACK_RESET_MS = 1500;
Expand Down Expand Up @@ -170,14 +165,14 @@ export const SIDEBAR_ACTIONS_ITEMS: DesktopIconStripItem[] = [
{ action: SidebarAction.SEARCH, icon: Search, keys: SHORTCUT_SEARCH, tooltip: 'Search' },
{
action: SidebarAction.PROJECTS,
activeRouteId: PROJECTS_ROUTE_ID,
activeRouteId: ROUTES.PROJECTS,
icon: PROJECT_ICON,
tooltip: 'Projects'
},
{
activeRoutePrefix: '/library',
icon: Library,
route: ROUTES.LIBRARY,
route: resolve(ROUTES.LIBRARY),
tooltip: 'Library'
}
];
Expand All @@ -189,20 +184,20 @@ export const SIDEBAR_ACTIONS_ITEMS: DesktopIconStripItem[] = [
export const SIDEBAR_FOOTER_ITEMS: DesktopIconStripItem[] = [
{
action: SidebarAction.MANAGE_MODELS,
activeRouteId: MODELS_ROUTE_ID,
activeRouteId: ROUTES.MODELS,
icon: MODEL_ICON,
keys: SHORTCUT_MODELS,
tooltip: 'Models'
},
{
action: SidebarAction.SERVERS,
activeRouteId: SERVERS_ROUTE_ID,
activeRouteId: ROUTES.SERVERS,
icon: Server,
tooltip: 'Servers'
},
{
action: SidebarAction.SETTINGS,
activeRouteId: SETTINGS_ROUTE_ID,
activeRouteId: ROUTES.SETTINGS,
icon: Settings,
keys: SHORTCUT_SETTINGS,
tooltip: 'Settings'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
<ExternalLink class="size-icon-xs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

newUrl.searchParams.delete('add');

// 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(newUrl, { replace: true, shallow: true });
}
});
Expand Down
Loading
Loading