diff --git a/.github/workflows/ui.yml b/.github/workflows/ui.yml index bba032416bfb..3547bf4c61e5 100644 --- a/.github/workflows/ui.yml +++ b/.github/workflows/ui.yml @@ -212,6 +212,38 @@ jobs: run: npm run prepack working-directory: ui/lib/harness + chat-only-build: + name: Chat-only build + runs-on: ubuntu-24.04 + steps: + - name: Checkout code + uses: actions/checkout@v6 + with: + ref: ${{ github.event.inputs.sha || github.event.pull_request.head.sha || github.sha || github.head_ref || github.ref_name }} + + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: "24" + package-manager-cache: false + + - name: Install dependencies + run: npm ci + working-directory: ui/apps/chat + + - name: Build without the agentic loop + run: npm run build + working-directory: ui/apps/chat + env: + VITE_PUBLIC_AGENTIC: "false" + + - name: Check the harness loop is not in the bundle + run: | + if grep -rlq "Tool execution was interrupted by a new user message" dist; then + echo "The chat-only bundle contains Llama Harness's loop" && exit 1 + fi + working-directory: ui/apps/chat + e2e-tests: name: E2E Tests needs: ui-build diff --git a/ui/apps/chat/.env.example b/ui/apps/chat/.env.example index 9760b0dd43fb..269e65278648 100644 --- a/ui/apps/chat/.env.example +++ b/ui/apps/chat/.env.example @@ -1,4 +1,6 @@ VITE_PUBLIC_APP_NAME='Llama Chat' +# 'false' builds a chat-only app: no tools, no MCP, no agentic loop +# VITE_PUBLIC_AGENTIC='false' VITE_DEBUG='true' VITE_PUBLIC_SERVER_ORIGIN='http://localhost:8033' diff --git a/ui/apps/chat/.storybook/preview.ts b/ui/apps/chat/.storybook/preview.ts index 22f04dd88609..47c884fd0f99 100644 --- a/ui/apps/chat/.storybook/preview.ts +++ b/ui/apps/chat/.storybook/preview.ts @@ -1,5 +1,6 @@ import '../src/app.css'; import { MEDIA_QUERIES } from '#lib/constants/pwa.constants.ts'; +import { agenticMode } from '#lib/stores/agentic-mode.svelte.ts'; // the docs pages' styles, shared with the library's Storybook import '../../../lib/ui/.storybook/docs.css'; import { applyColorScheme } from './color-scheme'; @@ -7,6 +8,9 @@ import ModeWatcherDecorator from './decorators/ModeWatcherDecorator.svelte'; import TooltipProviderDecorator from './decorators/TooltipProviderDecorator.svelte'; import type { Preview } from '@storybook/sveltekit'; +// the stories show the app as with a llama-server started with --agent +agenticMode.serverHasTools = true; + applyColorScheme(); window.matchMedia(MEDIA_QUERIES.PREFERS_DARK).addEventListener('change', applyColorScheme); diff --git a/ui/apps/chat/README.md b/ui/apps/chat/README.md index 891fe6b2a422..6ba2e8957d10 100644 --- a/ui/apps/chat/README.md +++ b/ui/apps/chat/README.md @@ -154,6 +154,10 @@ llama-server serves the UI with `Cross-Origin-Embedder-Policy: require-corp` and llama-server embeds it: when llama-server is built, `scripts/ui-assets.cmake` takes `ui/apps/chat/dist` if it exists, runs `npm run build` if `LLAMA_BUILD_UI` is on, or downloads the release's prebuilt `dist.tar.gz` from Hugging Face, and compiles every file into the binary. The same `dist` is what `npx @ggml-org/llama-chat` serves. +**Plain chat and agent mode.** Llama Chat is a plain chat, a message and its reply with reasoning when the model gives it, unless llama-server offers the agentic features: its built-in tools or its proxy, which `llama-server --agent` turns on together. The app reads this from `/props` and `/tools`. With them it shows the tools menu, the working folder, MCP and the Tools and Agentic settings, and runs the agentic loop; without them it shows none of these and sends the classic request. Tool calls in earlier conversations still display. + +**Chat-only build.** `VITE_PUBLIC_AGENTIC=false npm run build` builds an app that is a plain chat for every server, and `npm run dev:chat-only` runs the dev server the same way. Llama Harness's loop is left out of its bundle. + ```text ui/apps/chat/ ├── src/ 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/package.json b/ui/apps/chat/package.json index bc3f0d3315d1..76146f41e5b0 100644 --- a/ui/apps/chat/package.json +++ b/ui/apps/chat/package.json @@ -43,6 +43,7 @@ "build": "npm run build-pwa-assets && vite build", "build-pwa-assets": "pwa-assets-generator --root . --config pwa-assets.config.ts && pwa-assets-generator --root . --config pwa-assets-dark.config.ts && node scripts/make-icons-circular.js", "dev": "bash scripts/dev.sh", + "dev:chat-only": "VITE_PUBLIC_AGENTIC=false bash scripts/dev.sh", "preview": "vite preview", "prepare": "svelte-kit sync || echo ''", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionAdd/ChatFormActionAddButton.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionAdd/ChatFormActionAddButton.svelte index e25bcb56f72c..11c8a19544dd 100644 --- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionAdd/ChatFormActionAddButton.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionAdd/ChatFormActionAddButton.svelte @@ -2,7 +2,8 @@ import { Button } from '@ggml-org/llama-ui/ui/button'; import * as Tooltip from '@ggml-org/llama-ui/ui/tooltip'; import { Plus } from '@lucide/svelte'; - import { ATTACHMENT_TOOLTIP_TEXT, ICON_CLASS_DEFAULT } from '#lib/constants/index.ts'; + import { attachmentTooltipText, ICON_CLASS_DEFAULT } from '#lib/constants/index.ts'; + import { agenticMode } from '#lib/stores/agentic-mode.svelte.ts'; interface Props { disabled?: boolean; @@ -21,13 +22,13 @@ type="button" variant="ghost" > - {ATTACHMENT_TOOLTIP_TEXT} + {attachmentTooltipText(agenticMode.enabled)} -

{ATTACHMENT_TOOLTIP_TEXT}

+

{attachmentTooltipText(agenticMode.enabled)}

diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionAdd/ChatFormActionAddDropdown.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionAdd/ChatFormActionAddDropdown.svelte index 78153bfbdfbe..d86d663f3808 100644 --- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionAdd/ChatFormActionAddDropdown.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionAdd/ChatFormActionAddDropdown.svelte @@ -9,13 +9,14 @@ ATTACHMENT_FILE_ITEMS, ATTACHMENT_MENU_TEXT, ATTACHMENT_MODALITY_TEXT, - ATTACHMENT_TOOLTIP_TEXT, + attachmentTooltipText, ICON_CLASS_DEFAULT, MODALITY_ICONS } from '#lib/constants/index.ts'; import { getChatFormActionsContext } from '#lib/contexts/index.ts'; import { AttachmentAction, AttachmentItemEnabledWhen, ModelModality } from '#lib/enums/index.ts'; import { useAttachmentMenu } from '#lib/hooks/use-attachment-menu.svelte.ts'; + import { agenticMode } from '#lib/stores/agentic-mode.svelte.ts'; import type { Component } from 'svelte'; interface Props { @@ -84,7 +85,7 @@ )} disabled={chatFormActions.disabled} > - {ATTACHMENT_TOOLTIP_TEXT} + {attachmentTooltipText(agenticMode.enabled)} @@ -92,7 +93,7 @@ -

{ATTACHMENT_TOOLTIP_TEXT}

+

{attachmentTooltipText(agenticMode.enabled)}

@@ -160,7 +161,9 @@ {/if} - + {#if agenticMode.enabled} + + {/if} 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 efbbde97446a..1a8491d3aa7d 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 @@ -83,7 +83,7 @@ {#if faviconUrl} @@ -108,7 +108,7 @@ {result.title} diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte index 7cf2366e304e..df28b777a86b 100644 --- a/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte @@ -372,7 +372,7 @@ {/if}
- {#if stick.farFromBottom && page.url.hash.includes(ROUTES.CHAT) && page.params.id} + {#if stick.farFromBottom && page.route.id === ROUTES.CHAT && page.params.id} stick.scrollToBottom('smooth')} /> {/if}
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 5a7a6ba4d40a..818bf5779527 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/dialogs/DialogSearch.svelte b/ui/apps/chat/src/lib/components/app/dialogs/DialogSearch.svelte index 9a241af2835b..80d0cb5fdc6f 100644 --- a/ui/apps/chat/src/lib/components/app/dialogs/DialogSearch.svelte +++ b/ui/apps/chat/src/lib/components/app/dialogs/DialogSearch.svelte @@ -22,7 +22,7 @@ ICON_CLASS_SM, ICON_CLASS_XS, SIDEBAR_ACTIONS_ITEMS, - SIDEBAR_FOOTER_ITEMS + sidebarFooterItems } from '#lib/constants/index.ts'; import { KeyboardKey, SidebarAction } from '#lib/enums/index.ts'; import { useDebouncedSearch } from '#lib/hooks/use-debounced-search.svelte.ts'; @@ -32,6 +32,7 @@ HuggingFaceService } from '#lib/services/index.ts'; import { RouterService } from '#lib/services/router.service.ts'; + import { agenticMode } from '#lib/stores/agentic-mode.svelte.ts'; import { conversationsStore, deviceStore, @@ -248,7 +249,7 @@ const actionEntries = $derived.by((): SearchEntry[] => // every sidebar action the sidebar shows but Search itself, which is what opened this // dialog, and the models manager on a phone, which picks its models in the selector - [...SIDEBAR_ACTIONS_ITEMS, ...SIDEBAR_FOOTER_ITEMS] + [...SIDEBAR_ACTIONS_ITEMS, ...sidebarFooterItems(agenticMode.enabled)] .filter( (item) => item.action && 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 c716652b0556..256baa2dd1f4 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 64bdbd5f62ed..26db7f7a9c7f 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 8fcef551be52..5f45697132d6 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, NEW_CHAT_TAB_ID, ROUTES, SETTINGS_KEYS, @@ -173,9 +172,9 @@ untrack(() => { if ( - (page.route.id === '/(chat)' || - page.route.id === '/(chat)/chat/[id]' || - page.route.id === MODELS_ROUTE_ID) && + (page.route.id === ROUTES.START || + page.route.id === ROUTES.CHAT || + page.route.id === ROUTES.MODELS) && page.status !== 401 && page.status !== 403 ) { @@ -384,7 +383,7 @@ - {#if deviceStore.isMobile && !page.url.hash.includes(ROUTES.SEARCH) && !uiStore.isComposerExpanded} + {#if deviceStore.isMobile && page.route.id !== ROUTES.SEARCH && !uiStore.isComposerExpanded}
import { SettingsMcpServers } from '#lib/components/app/settings/index.ts'; - import { APP_NAME } from '#lib/constants/index.ts'; + import { APP_NAME, ROUTES } from '#lib/constants/index.ts'; + import { agenticMode } from '#lib/stores/agentic-mode.svelte.ts'; + import { goto } from '$app/navigation'; + import { resolve } from '$app/paths'; + + // a server without the agentic features has no MCP + $effect(() => { + if (agenticMode.settled && !agenticMode.enabled) void goto(resolve(ROUTES.START)); + }); diff --git a/ui/apps/chat/src/routes/mcp-servers/+page.ts b/ui/apps/chat/src/routes/mcp-servers/+page.ts index 3c3deac5178a..2b6ea49440a6 100644 --- a/ui/apps/chat/src/routes/mcp-servers/+page.ts +++ b/ui/apps/chat/src/routes/mcp-servers/+page.ts @@ -1,4 +1,12 @@ import type { PageLoad } from './$types'; +import { redirect } from '@sveltejs/kit'; +import { AGENTIC_ENABLED, ROUTES } from '#lib/constants/index.ts'; import { loadAppRoute } from '#lib/stores/init.ts'; +import { resolve } from '$app/paths'; -export const load: PageLoad = ({ fetch }) => loadAppRoute(fetch); +export const load: PageLoad = ({ fetch }) => { + // a chat-only build has no MCP + if (!AGENTIC_ENABLED) redirect(307, resolve(ROUTES.START)); + + return loadAppRoute(fetch); +}; diff --git a/ui/apps/chat/src/routes/search/+page.svelte b/ui/apps/chat/src/routes/search/+page.svelte index eafe233910b6..c9bec8db9393 100644 --- a/ui/apps/chat/src/routes/search/+page.svelte +++ b/ui/apps/chat/src/routes/search/+page.svelte @@ -9,6 +9,7 @@ import { chatStore, conversationsStore, deviceStore } from '#lib/stores/index.ts'; import { browser } from '$app/env'; import { goto } from '$app/navigation'; + import { resolve } from '$app/paths'; import { page } from '$app/state'; let searchQuery = $state(''); @@ -28,7 +29,7 @@ // in-place search, so bounce back to a new-chat tab without a history entry. $effect(() => { if (browser && !deviceStore.isMobile) { - goto(ROUTES.START, { replace: true }); + goto(resolve(ROUTES.START), { replace: true }); } }); 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 302c1b6f35fb..dd92bca23d25 100644 --- a/ui/apps/chat/tests/client/nested-surfaces.svelte.test.ts +++ b/ui/apps/chat/tests/client/nested-surfaces.svelte.test.ts @@ -2,7 +2,6 @@ // 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 SidebarNavigationActions from '#lib/components/app/navigation/SidebarNavigation/SidebarNavigationActions.svelte'; import SidebarNavigationFooter from '#lib/components/app/navigation/SidebarNavigation/SidebarNavigationFooter.svelte'; diff --git a/ui/apps/chat/tests/stories/chat/form/ChatScreenForm.a11y.stories.svelte b/ui/apps/chat/tests/stories/chat/form/ChatScreenForm.a11y.stories.svelte index b1058822af45..ad443f61ccdf 100644 --- a/ui/apps/chat/tests/stories/chat/form/ChatScreenForm.a11y.stories.svelte +++ b/ui/apps/chat/tests/stories/chat/form/ChatScreenForm.a11y.stories.svelte @@ -1,7 +1,7 @@