diff --git a/scripts/ui-assets.cmake b/scripts/ui-assets.cmake index 979cfbefb26b..2296c887da4d 100644 --- a/scripts/ui-assets.cmake +++ b/scripts/ui-assets.cmake @@ -43,7 +43,7 @@ function(mime_from_ext name out_var) set(m "text/html; charset=utf-8") elseif(ext_str STREQUAL "css") set(m "text/css") - elseif(ext_str STREQUAL "js") + elseif(ext_str STREQUAL "js" OR ext_str STREQUAL "mjs") set(m "application/javascript") elseif(ext_str STREQUAL "json") set(m "application/json") diff --git a/ui/apps/chat/scripts/vite-plugin-nerdamer.ts b/ui/apps/chat/scripts/vite-plugin-nerdamer.ts index 84e463c6d764..c1551eb5aca8 100644 --- a/ui/apps/chat/scripts/vite-plugin-nerdamer.ts +++ b/ui/apps/chat/scripts/vite-plugin-nerdamer.ts @@ -10,7 +10,9 @@ const RESOLVED_ID = '\0' + VIRTUAL_ID; /** * Bundle the vendored nerdamer-prime source into a minified IIFE string, - * exposed as the `virtual:nerdamer` module. Flags mirror the upstream + * loaded through the `virtual:nerdamer` module. In the client build it is + * its own file, fetched on first use, so it stays out of the app bundle. + * Flags mirror the upstream * build (esbuild --bundle --minify --format=iife --global-name=nerdamer), * so only human readable source lives in the repo and minification is a * build artifact. Vendored under src/lib/vendors/, upstream snapshot: @@ -41,7 +43,13 @@ export function nerdamerPlugin(): Plugin { bundled = result.outputFiles[0].text; } - return `export default ${JSON.stringify(bundled)};`; + if (this.environment.mode === 'build' && this.environment.name === 'client') { + const ref = this.emitFile({ name: 'nerdamer.js', source: bundled, type: 'asset' }); + + return `export default () => fetch(import.meta.ROLLUP_FILE_URL_${ref}).then((res) => res.text());`; + } + + return `export default async () => ${JSON.stringify(bundled)};`; }, name: 'llamacpp:nerdamer', resolveId(id) { diff --git a/ui/apps/chat/src/lib/components/app/library/library-actions.ts b/ui/apps/chat/src/lib/components/app/library/library-actions.ts index e12fbdeeecb7..878ba6c665ee 100644 --- a/ui/apps/chat/src/lib/components/app/library/library-actions.ts +++ b/ui/apps/chat/src/lib/components/app/library/library-actions.ts @@ -1,4 +1,6 @@ -import { Download, Pencil, Trash2 } from '@lucide/svelte'; +import Download from '@lucide/svelte/icons/download'; +import Pencil from '@lucide/svelte/icons/pencil'; +import Trash2 from '@lucide/svelte/icons/trash-2'; import type { MenuAction } from '#lib/types/index.ts'; /** A media item's "more actions" and right-click menu. Placeholders: nothing acts yet. */ diff --git a/ui/apps/chat/src/lib/components/app/models/ModelsManager/row-actions.ts b/ui/apps/chat/src/lib/components/app/models/ModelsManager/row-actions.ts index 160e036aea66..975f94a7fa53 100644 --- a/ui/apps/chat/src/lib/components/app/models/ModelsManager/row-actions.ts +++ b/ui/apps/chat/src/lib/components/app/models/ModelsManager/row-actions.ts @@ -1,4 +1,9 @@ -import { Compass, Eye, EyeOff, Heart, HeartOff, Trash2 } from '@lucide/svelte'; +import Compass from '@lucide/svelte/icons/compass'; +import Eye from '@lucide/svelte/icons/eye'; +import EyeOff from '@lucide/svelte/icons/eye-off'; +import Heart from '@lucide/svelte/icons/heart'; +import HeartOff from '@lucide/svelte/icons/heart-off'; +import Trash2 from '@lucide/svelte/icons/trash-2'; import { MODEL_DOWNLOAD_ICONS } from '#lib/constants/index.ts'; import { ModelRowDownloadState } from '#lib/enums/index.ts'; import { modelsStore, uiStore } from '#lib/stores/index.ts'; diff --git a/ui/apps/chat/src/lib/constants/icons.constants.ts b/ui/apps/chat/src/lib/constants/icons.constants.ts index 61802364cc06..fb413b83e87b 100644 --- a/ui/apps/chat/src/lib/constants/icons.constants.ts +++ b/ui/apps/chat/src/lib/constants/icons.constants.ts @@ -4,25 +4,23 @@ */ import { MODALITY_FLAG_KEYS, MODALITY_ORDER } from '@ggml-org/llama-ui/models'; -import { - CircleAlert as LoadFailedIcon, - Compass as DiscoverIcon, - Eject as UnloadIcon, - File as FileIcon, - FileText as FileTextIcon, - Folder as CwdCommandIcon, - FolderOpen as ProjectIcon, - FoldVertical as CompactCommandIcon, - Image as ImageIcon, - Loader2 as LoadingIcon, - Mic as AudioIcon, - Package as ModelIcon, - Pause as PauseDownloadIcon, - Play as ResumeDownloadIcon, - Power as LoadIcon, - RotateCw as RetryIcon, - Video as VideoIcon -} from '@lucide/svelte'; +import LoadFailedIcon from '@lucide/svelte/icons/circle-alert'; +import DiscoverIcon from '@lucide/svelte/icons/compass'; +import UnloadIcon from '@lucide/svelte/icons/eject'; +import FileIcon from '@lucide/svelte/icons/file'; +import FileTextIcon from '@lucide/svelte/icons/file-text'; +import CompactCommandIcon from '@lucide/svelte/icons/fold-vertical'; +import CwdCommandIcon from '@lucide/svelte/icons/folder'; +import ProjectIcon from '@lucide/svelte/icons/folder-open'; +import ImageIcon from '@lucide/svelte/icons/image'; +import LoadingIcon from '@lucide/svelte/icons/loader-2'; +import AudioIcon from '@lucide/svelte/icons/mic'; +import ModelIcon from '@lucide/svelte/icons/package'; +import PauseDownloadIcon from '@lucide/svelte/icons/pause'; +import ResumeDownloadIcon from '@lucide/svelte/icons/play'; +import LoadIcon from '@lucide/svelte/icons/power'; +import RetryIcon from '@lucide/svelte/icons/rotate-cw'; +import VideoIcon from '@lucide/svelte/icons/video'; import { ChatFormCommandAction, FileTypeCategory, ModelCapability } from '#lib/enums/index.ts'; import type { ModelCapabilities } from '#lib/types/models.js'; import type { Component } from 'svelte'; diff --git a/ui/apps/chat/src/lib/constants/library.constants.ts b/ui/apps/chat/src/lib/constants/library.constants.ts index a1dbe79aea2a..fe23c5153f36 100644 --- a/ui/apps/chat/src/lib/constants/library.constants.ts +++ b/ui/apps/chat/src/lib/constants/library.constants.ts @@ -1,4 +1,6 @@ -import { AudioLines, Film, Image } from '@lucide/svelte'; +import AudioLines from '@lucide/svelte/icons/audio-lines'; +import Film from '@lucide/svelte/icons/film'; +import Image from '@lucide/svelte/icons/image'; import { LibraryItemKind, LibraryTab } from '#lib/enums/index.ts'; import type { Component } from 'svelte'; diff --git a/ui/apps/chat/src/lib/constants/mcp.constants.ts b/ui/apps/chat/src/lib/constants/mcp.constants.ts index daf6772209df..2b9591d65c67 100644 --- a/ui/apps/chat/src/lib/constants/mcp.constants.ts +++ b/ui/apps/chat/src/lib/constants/mcp.constants.ts @@ -1,4 +1,6 @@ -import { Globe, Radio, Zap } from '@lucide/svelte'; +import Globe from '@lucide/svelte/icons/globe'; +import Radio from '@lucide/svelte/icons/radio'; +import Zap from '@lucide/svelte/icons/zap'; import { MimeTypeImage } from '#lib/enums/files.enums.ts'; import { MCPTransportType } from '#lib/enums/index.ts'; import type { ClientCapabilities, Implementation } from '#lib/types/index.ts'; diff --git a/ui/apps/chat/src/lib/constants/settings.constants.ts b/ui/apps/chat/src/lib/constants/settings.constants.ts index 1d0cb6be50cf..a4fbda01f18a 100644 --- a/ui/apps/chat/src/lib/constants/settings.constants.ts +++ b/ui/apps/chat/src/lib/constants/settings.constants.ts @@ -6,24 +6,22 @@ import { SETTINGS_KEYS } from './settings-keys.constants'; import { TITLE_GENERATION } from './title-generation.constants'; import { VOICE_TRANSCRIPTION_MODEL_AUTO } from './voice.constants'; import { FILE_GLOB_SEARCH_PICKERS } from './working-directory.constants'; -import { - AudioLines, - Code, - Database, - File, - Funnel, - Gauge, - GlassWater, - ListRestart, - Mic, - Monitor, - Moon, - PencilRuler, - Puzzle, - SlidersVertical, - Sun, - TextCursorInput -} from '@lucide/svelte'; +import AudioLines from '@lucide/svelte/icons/audio-lines'; +import Code from '@lucide/svelte/icons/code'; +import Database from '@lucide/svelte/icons/database'; +import File from '@lucide/svelte/icons/file'; +import Funnel from '@lucide/svelte/icons/funnel'; +import Gauge from '@lucide/svelte/icons/gauge'; +import GlassWater from '@lucide/svelte/icons/glass-water'; +import ListRestart from '@lucide/svelte/icons/list-restart'; +import Mic from '@lucide/svelte/icons/mic'; +import Monitor from '@lucide/svelte/icons/monitor'; +import Moon from '@lucide/svelte/icons/moon'; +import PencilRuler from '@lucide/svelte/icons/pencil-ruler'; +import Puzzle from '@lucide/svelte/icons/puzzle'; +import SlidersVertical from '@lucide/svelte/icons/sliders-vertical'; +import Sun from '@lucide/svelte/icons/sun'; +import TextCursorInput from '@lucide/svelte/icons/text-cursor-input'; import { SurfaceTheme, SyncableParameterType, VoiceInputMode } from '#lib/enums/index.ts'; import { SettingsFieldType } from '#lib/enums/settings.enums.ts'; import { ColorMode } from '#lib/enums/ui.enums.ts'; diff --git a/ui/apps/chat/src/lib/constants/tool-ui.constants.ts b/ui/apps/chat/src/lib/constants/tool-ui.constants.ts index 15c942bf1b9e..ab7aa6c6cab5 100644 --- a/ui/apps/chat/src/lib/constants/tool-ui.constants.ts +++ b/ui/apps/chat/src/lib/constants/tool-ui.constants.ts @@ -8,21 +8,19 @@ // ChatMessageToolCallBlockSearchResults for prior art). import { PROJECT_ICON } from './icons.constants'; -import { - Braces, - Clock, - Eye, - FilePen, - FilePlus, - FileSearch, - FileText, - Info, - List, - MessagesSquare, - Paperclip, - SearchCode, - Terminal -} from '@lucide/svelte'; +import Braces from '@lucide/svelte/icons/braces'; +import Clock from '@lucide/svelte/icons/clock'; +import Eye from '@lucide/svelte/icons/eye'; +import FilePen from '@lucide/svelte/icons/file-pen'; +import FilePlus from '@lucide/svelte/icons/file-plus'; +import FileSearch from '@lucide/svelte/icons/file-search'; +import FileText from '@lucide/svelte/icons/file-text'; +import Info from '@lucide/svelte/icons/info'; +import List from '@lucide/svelte/icons/list'; +import MessagesSquare from '@lucide/svelte/icons/messages-square'; +import Paperclip from '@lucide/svelte/icons/paperclip'; +import SearchCode from '@lucide/svelte/icons/search-code'; +import Terminal from '@lucide/svelte/icons/terminal'; import { BuiltInTool, ToolSource } from '#lib/enums/index.ts'; import type { ToolUiEntry } from '#lib/types/index.ts'; diff --git a/ui/apps/chat/src/lib/constants/ui.constants.ts b/ui/apps/chat/src/lib/constants/ui.constants.ts index 518962c89284..69dfa221cd54 100644 --- a/ui/apps/chat/src/lib/constants/ui.constants.ts +++ b/ui/apps/chat/src/lib/constants/ui.constants.ts @@ -6,7 +6,11 @@ import { SHORTCUT_SETTINGS } from './keyboard-shortcuts.constants'; import { ROUTES } from './routes.constants'; -import { Library, Search, Server, Settings, SquarePen } from '@lucide/svelte'; +import Library from '@lucide/svelte/icons/library'; +import Search from '@lucide/svelte/icons/search'; +import Server from '@lucide/svelte/icons/server'; +import Settings from '@lucide/svelte/icons/settings'; +import SquarePen from '@lucide/svelte/icons/square-pen'; import { SidebarAction, ToolSource } from '#lib/enums/index.ts'; import type { DesktopIconStripItem } from '#lib/types/index.ts'; import { resolve } from '$app/paths'; diff --git a/ui/apps/chat/src/lib/extensions/mcp/composer.ts b/ui/apps/chat/src/lib/extensions/mcp/composer.ts index 0efd4c69b177..289432dba9d5 100644 --- a/ui/apps/chat/src/lib/extensions/mcp/composer.ts +++ b/ui/apps/chat/src/lib/extensions/mcp/composer.ts @@ -7,7 +7,7 @@ import type { ExtensionContext } from '../types'; import ComposerMcpPrompts from './components/contributions/ComposerMcpPrompts.svelte'; import ComposerMcpResources from './components/contributions/ComposerMcpResources.svelte'; import { mcpStore } from './stores/index.svelte'; -import { Sparkles } from '@lucide/svelte'; +import Sparkles from '@lucide/svelte/icons/sparkles'; import { ToolSource } from '#lib/enums/index.ts'; import { conversationsStore } from '#lib/stores/index.ts'; diff --git a/ui/apps/chat/src/lib/services/sandbox.service.ts b/ui/apps/chat/src/lib/services/sandbox.service.ts index a52e688982a3..223771fc6d4e 100644 --- a/ui/apps/chat/src/lib/services/sandbox.service.ts +++ b/ui/apps/chat/src/lib/services/sandbox.service.ts @@ -33,9 +33,9 @@ async function getHarness(): Promise { if (!harnessCache[key]) { if (enabled) { - const { default: nerdamerJs } = await import('virtual:nerdamer'); + const { default: loadNerdamer } = await import('virtual:nerdamer'); - harnessCache[key] = buildSandboxHarness(nerdamerJs); + harnessCache[key] = buildSandboxHarness(await loadNerdamer()); } else { harnessCache[key] = buildSandboxHarness(''); } diff --git a/ui/apps/chat/src/lib/utils/mcp.ts b/ui/apps/chat/src/lib/utils/mcp.ts index a136ed4ced31..8055cf76e274 100644 --- a/ui/apps/chat/src/lib/utils/mcp.ts +++ b/ui/apps/chat/src/lib/utils/mcp.ts @@ -1,14 +1,12 @@ import { extractRootDomain } from './url'; -import { - AlertTriangle, - Code, - Database, - File, - FileText, - Image, - Info, - XCircle -} from '@lucide/svelte'; +import AlertTriangle from '@lucide/svelte/icons/alert-triangle'; +import Code from '@lucide/svelte/icons/code'; +import Database from '@lucide/svelte/icons/database'; +import File from '@lucide/svelte/icons/file'; +import FileText from '@lucide/svelte/icons/file-text'; +import Image from '@lucide/svelte/icons/image'; +import Info from '@lucide/svelte/icons/info'; +import XCircle from '@lucide/svelte/icons/x-circle'; import { CODE_FILE_EXTENSION_REGEX, DEFAULT_RESOURCE_FILENAME, diff --git a/ui/apps/chat/src/lib/utils/pdf-processing.ts b/ui/apps/chat/src/lib/utils/pdf-processing.ts index a67a117c7ea2..6d856f0b08df 100644 --- a/ui/apps/chat/src/lib/utils/pdf-processing.ts +++ b/ui/apps/chat/src/lib/utils/pdf-processing.ts @@ -6,23 +6,14 @@ import { MimeTypeApplication, MimeTypeImage } from '#lib/enums/index.ts'; import { browser } from '$app/env'; import * as pdfjs from 'pdfjs-dist'; +import pdfWorkerUrl from 'pdfjs-dist/build/pdf.worker.min.mjs?url'; type TextContent = { items: Array<{ str: string }>; }; -if (browser) { - // Import worker as text and create blob URL for inline bundling - import('pdfjs-dist/build/pdf.worker.min.mjs?raw') - .then((workerModule) => { - const workerBlob = new Blob([workerModule.default], { type: 'application/javascript' }); - - pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(workerBlob); - }) - .catch(() => { - console.warn('Failed to load PDF.js worker, PDF processing may not work'); - }); -} +// the worker is its own file, so the app loads it only when it opens a PDF +if (browser) pdfjs.GlobalWorkerOptions.workerSrc = pdfWorkerUrl; /** * Convert a File object to ArrayBuffer for PDF.js processing diff --git a/ui/apps/chat/src/virtual-nerdamer.d.ts b/ui/apps/chat/src/virtual-nerdamer.d.ts index 433fb2b3bd20..19fcd36f6dc7 100644 --- a/ui/apps/chat/src/virtual-nerdamer.d.ts +++ b/ui/apps/chat/src/virtual-nerdamer.d.ts @@ -1,4 +1,4 @@ declare module 'virtual:nerdamer' { - const code: string; - export default code; + const loadNerdamer: () => Promise; + export default loadNerdamer; } diff --git a/ui/apps/chat/tsconfig.json b/ui/apps/chat/tsconfig.json index 289f843bb762..aab815e5fbc4 100644 --- a/ui/apps/chat/tsconfig.json +++ b/ui/apps/chat/tsconfig.json @@ -29,6 +29,8 @@ "highlight.js/*": ["./node_modules/highlight.js/*"], "@ggml-org/llama-brand": ["./node_modules/@ggml-org/llama-brand"], "@ggml-org/llama-brand/*": ["./node_modules/@ggml-org/llama-brand/*"], + "lowlight": ["./node_modules/lowlight"], + "lowlight/*": ["./node_modules/lowlight/*"], "mode-watcher": ["./node_modules/mode-watcher"], "mode-watcher/*": ["./node_modules/mode-watcher/*"], "svelte": ["./node_modules/svelte"], diff --git a/ui/lib/ui/package-lock.json b/ui/lib/ui/package-lock.json index 40a2751d6538..5eb9bab21dfa 100644 --- a/ui/lib/ui/package-lock.json +++ b/ui/lib/ui/package-lock.json @@ -15,6 +15,7 @@ "bits-ui": "2.18.1", "clsx": "^2.1.1", "highlight.js": "^11.11.1", + "lowlight": "^3.3.0", "tailwind-merge": "^3.7.0", "tailwind-variants": "^3.3.1", "vaul-svelte": "1.0.0-next.7" @@ -3578,6 +3579,15 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/hast": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@types/hast/-/hast-3.0.5.tgz", + "integrity": "sha512-rp/ezSWaD1m44dPKICGhiskI13nVr7qTloFwDa/IYkhhf5nzwP+zIQcIJh3WIFSBOy/H1PzB40jPjMDksN4F+g==", + "license": "MIT", + "dependencies": { + "@types/unist": "*" + } + }, "node_modules/@types/json-schema": { "version": "7.0.15", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", @@ -3616,7 +3626,6 @@ "version": "2.0.11", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.11.tgz", "integrity": "sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA==", - "dev": true, "license": "MIT" }, "node_modules/@valibot/to-json-schema": { @@ -4707,6 +4716,19 @@ "dev": true, "license": "MIT" }, + "node_modules/devlop": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/devlop/-/devlop-1.1.0.tgz", + "integrity": "sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==", + "license": "MIT", + "dependencies": { + "dequal": "^2.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/dom-accessibility-api": { "version": "0.5.16", "resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz", @@ -5329,6 +5351,21 @@ "dev": true, "license": "MIT" }, + "node_modules/lowlight": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/lowlight/-/lowlight-3.3.0.tgz", + "integrity": "sha512-0JNhgFoPvP6U6lE/UdVsSq99tn6DhjjpAj5MxG49ewd2mOBVtwWYIT8ClyABhq198aXXODMU6Ox8DrGy/CpTZQ==", + "license": "MIT", + "dependencies": { + "@types/hast": "^3.0.0", + "devlop": "^1.0.0", + "highlight.js": "~11.11.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/lz-string": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz", diff --git a/ui/lib/ui/package.json b/ui/lib/ui/package.json index e8b56071c45d..c9cc21082fe9 100644 --- a/ui/lib/ui/package.json +++ b/ui/lib/ui/package.json @@ -129,6 +129,7 @@ "bits-ui": "2.18.1", "clsx": "^2.1.1", "highlight.js": "^11.11.1", + "lowlight": "^3.3.0", "@ggml-org/llama-brand": "https://codeload.github.com/ggml-org/llama-brand/tar.gz/f05540643c1ca2a18d732ed6491c839686da9a3a", "tailwind-merge": "^3.7.0", "tailwind-variants": "^3.3.1", diff --git a/ui/lib/ui/src/lib/models/constants.ts b/ui/lib/ui/src/lib/models/constants.ts index 2f8899e9c76c..ebfbf84ae727 100644 --- a/ui/lib/ui/src/lib/models/constants.ts +++ b/ui/lib/ui/src/lib/models/constants.ts @@ -2,13 +2,11 @@ // models-discover-download and model-compatibility). import { ModelCapability, ModelModality } from './enums.js'; import type { ModelModalities } from './types.js'; -import { - Eye as VisionIcon, - Lightbulb as ReasoningIcon, - Mic as AudioIcon, - Video as VideoIcon, - Wrench as ToolUseIcon -} from '@lucide/svelte'; +import VisionIcon from '@lucide/svelte/icons/eye'; +import ReasoningIcon from '@lucide/svelte/icons/lightbulb'; +import AudioIcon from '@lucide/svelte/icons/mic'; +import VideoIcon from '@lucide/svelte/icons/video'; +import ToolUseIcon from '@lucide/svelte/icons/wrench'; import type { Component } from 'svelte'; /** Neutral model badge: params, quantization, tags. */ diff --git a/ui/lib/ui/src/lib/utils/code.ts b/ui/lib/ui/src/lib/utils/code.ts index ca368f3527d0..f8c5ba5fc788 100644 --- a/ui/lib/ui/src/lib/utils/code.ts +++ b/ui/lib/ui/src/lib/utils/code.ts @@ -1,7 +1,11 @@ // highlightCode and its helpers, from ui/apps/chat's utils/code.ts (only what SyntaxHighlightedCode uses) import { CODE_BLOCK } from "../constants"; -import hljs from "highlight.js"; +import hljs from "highlight.js/lib/core"; import bash from "highlight.js/lib/languages/bash"; +import { all as languages } from "lowlight"; + +// reuse lowlight's language modules: the full `highlight.js` entry bundles a second, CommonJS copy of every language +for (const [name, language] of Object.entries(languages)) hljs.registerLanguage(name, language); // highlight.js's bash marks strings, variables and keywords but leaves a command's name and its flags plain, so a // command (`curl -H … -d …`) reads as one colour. Mark them too: the name as a built-in, the flags as attributes.