ui: cut Llama Chat's first-load JavaScript by 63%, load diagrams, math and PDFs on demand (#32555)
* ui: import Lucide icons by path in modules that run in Node Assisted-by: Claude (Opus 5.5 Medium) * ui: register highlight.js languages once, from lowlight's modules Assisted-by: Claude (Opus 5.5 Medium) * ui: load the pdf.js worker and nerdamer as files of their own Assisted-by: Claude (Opus 5.5 Medium) * ui: draw Mermaid diagrams with Pele Assisted-by: Claude (Opus 5.5 Medium) * ui: pin dependency versions and use one Svelte across the UI packages Assisted-by: Claude (Opus 5.5 Medium) * ui: build Llama Chat as split chunks Assisted-by: Claude (Opus 5.5 Medium) * ui: load KaTeX and pdf.js on first use Assisted-by: Claude (Opus 5.5 Medium)
This commit is contained in:
1 parent
39039aa27f
commit
80437488a4
35 files changed
+586
-1335
No files matched your search
@@ -41,7 +41,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")
|
||||
@@ -98,9 +98,12 @@ function(ui_validate_assets files in_dir)
|
||||
set(found_build_json TRUE)
|
||||
elseif(base STREQUAL "version.json")
|
||||
set(found_version_json TRUE)
|
||||
elseif(base MATCHES "^bundle.*\\.js$")
|
||||
# the app's entry: bundle[hash].js/.css from a single-bundle build (builds before the
|
||||
# split one, prebuilt archives included), or entry/start[hash].js and the CSS in
|
||||
# _app/immutable/assets from a split build
|
||||
elseif(base MATCHES "^bundle.*\\.js$" OR f MATCHES "(^|/)_app/immutable/entry/start\\.[^/]*\\.js$")
|
||||
set(found_bundle_js TRUE)
|
||||
elseif(base MATCHES "^bundle.*\\.css$")
|
||||
elseif(base MATCHES "^bundle.*\\.css$" OR f MATCHES "(^|/)_app/immutable/assets/[^/]*\\.css$")
|
||||
set(found_bundle_css TRUE)
|
||||
endif()
|
||||
endforeach()
|
||||
@@ -125,10 +128,10 @@ function(ui_validate_assets files in_dir)
|
||||
list(APPEND missing "version.json")
|
||||
endif()
|
||||
if(NOT found_bundle_js)
|
||||
list(APPEND missing "bundle[hash].js")
|
||||
list(APPEND missing "_app/immutable/entry/start[hash].js (or bundle[hash].js)")
|
||||
endif()
|
||||
if(NOT found_bundle_css)
|
||||
list(APPEND missing "bundle[hash].css")
|
||||
list(APPEND missing "_app/immutable/assets/[name][hash].css (or bundle[hash].css)")
|
||||
endif()
|
||||
|
||||
if(missing)
|
||||
|
||||
Generated
+13
-1129
File diff suppressed because it is too large.
Load diff
@@ -110,8 +110,8 @@
|
||||
"dompurify": "3.4.17",
|
||||
"eslint": "10.14.0",
|
||||
"eslint-config-prettier": "10.1.8",
|
||||
"eslint-plugin-perfectionist": "^5.10.1",
|
||||
"eslint-plugin-simple-import-sort": "^14.0.0",
|
||||
"eslint-plugin-perfectionist": "5.13.0",
|
||||
"eslint-plugin-simple-import-sort": "14.0.0",
|
||||
"eslint-plugin-storybook": "10.6.6",
|
||||
"eslint-plugin-svelte": "3.24.1",
|
||||
"fflate": "0.8.3",
|
||||
@@ -120,9 +120,9 @@
|
||||
"http-server": "14.1.1",
|
||||
"@ggml-org/llama-brand": "0.1.0",
|
||||
"mdsvex": "0.12.7",
|
||||
"mermaid": "11.17.2",
|
||||
"mode-watcher": "1.1.0",
|
||||
"pdfjs-dist": "5.4.54",
|
||||
"pele": "1.13.0",
|
||||
"playwright": "1.56.1",
|
||||
"prettier": "3.8.3",
|
||||
"prettier-plugin-svelte": "4.1.0",
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -356,8 +356,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
.mermaidTooltip {
|
||||
display: none !important;
|
||||
/*
|
||||
* Mermaid diagrams are drawn by Pele, which reads its colors from these. They sit on :root
|
||||
* so the svg also inherits them inside the preview dialog's shadow root, and follow the theme.
|
||||
*/
|
||||
:root {
|
||||
--pele-bg: var(--code-background);
|
||||
--pele-fg: var(--code-foreground);
|
||||
--pele-muted: var(--muted-foreground);
|
||||
--pele-line: var(--muted-foreground);
|
||||
--pele-surface: var(--background);
|
||||
--pele-surface-alt: var(--muted);
|
||||
--pele-border: var(--border);
|
||||
--pele-accent: var(--primary);
|
||||
--pele-critical: var(--destructive);
|
||||
--pele-error: var(--destructive);
|
||||
--pele-radius: calc(var(--radius) - 4px);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -625,7 +625,7 @@
|
||||
if ((hasRenderedBlocks || hasUnstableBlock) && containerRef) {
|
||||
setupCodeBlockActions();
|
||||
setupImageErrorHandlers();
|
||||
renderMermaidDiagrams(containerRef, mode.current === ColorMode.DARK);
|
||||
renderMermaidDiagrams(containerRef);
|
||||
renderSvgDiagrams(containerRef);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -626,10 +626,24 @@ div.markdown-user-content :global(.table-wrapper) {
|
||||
|
||||
/* Hide mermaid code text until rendered - prevents flash */
|
||||
.markdown-content :global(pre.mermaid:not([data-mermaid-rendered])),
|
||||
.markdown-content :global(pre.mermaid[data-mermaid-rendered]:not(:has(svg))) {
|
||||
.markdown-content :global(pre.mermaid[data-mermaid-rendered]:not(:has(svg, .mermaid-error))) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* A diagram Pele can't draw shows why, with the line it stopped at */
|
||||
.markdown-content :global(.mermaid-error) {
|
||||
max-width: 100%;
|
||||
padding: 1rem;
|
||||
color: var(--destructive);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.8125rem;
|
||||
/* the caret line under the source must line up character by character */
|
||||
font-variant-ligatures: none;
|
||||
text-align: left;
|
||||
white-space: pre-wrap;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
/* Hide svg source until rendered - prevents flash. A rendered-but-unsanitized
|
||||
block (oversized source) keeps its raw text visible as a safe fallback. */
|
||||
.markdown-content :global(pre.svg-block:not([data-svg-rendered])) {
|
||||
|
||||
@@ -7,9 +7,15 @@ import {
|
||||
DIAGRAM_VIEW_RENDERED,
|
||||
DIAGRAM_VIEW_SOURCE,
|
||||
MERMAID_BLOCK_CLASS,
|
||||
MERMAID_ERROR_CLASS,
|
||||
MERMAID_ID_ATTR,
|
||||
MERMAID_RENDERED_ATTR,
|
||||
MERMAID_SCROLL_CONTAINER_CLASS,
|
||||
MERMAID_SVG_PADDING_X_REM,
|
||||
MERMAID_SYNTAX_ATTR,
|
||||
MERMAID_WRAPPER_CLASS,
|
||||
PELE_SVG_CLASS,
|
||||
PELE_THEME_VARIABLES,
|
||||
SVG,
|
||||
TOGGLE_SOURCE_BTN_CLASS
|
||||
} from '#lib/constants/index.ts';
|
||||
@@ -19,11 +25,30 @@ import { mountSvgShadow } from '#lib/utils/svg-shadow.ts';
|
||||
|
||||
export type DiagramAction = { copy: string } | { previewSvg: string };
|
||||
|
||||
// The width a diagram can take in its block: the scroll container's content box, less the
|
||||
// svg's own horizontal padding. Undefined when the block isn't laid out (detached, hidden).
|
||||
function diagramWidth(node: HTMLElement): number | undefined {
|
||||
const scroll = node.closest<HTMLElement>(`.${MERMAID_SCROLL_CONTAINER_CLASS}`);
|
||||
|
||||
if (!scroll?.clientWidth) return undefined;
|
||||
|
||||
const box = getComputedStyle(scroll);
|
||||
const rem = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
||||
const width =
|
||||
scroll.clientWidth -
|
||||
parseFloat(box.paddingLeft) -
|
||||
parseFloat(box.paddingRight) -
|
||||
MERMAID_SVG_PADDING_X_REM * rem;
|
||||
|
||||
return width > 0 ? width : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the mermaid diagrams in `container` that haven't been rendered yet.
|
||||
* Marks nodes immediately to prevent duplicate renders during streaming.
|
||||
* Renders the mermaid diagrams in `container` that haven't been rendered yet, with Pele.
|
||||
* Marks nodes immediately to prevent duplicate renders during streaming. Colors come
|
||||
* from the `--pele-*` variables in app.css, so a diagram follows the theme without a redraw.
|
||||
*/
|
||||
export async function renderMermaidDiagrams(container: HTMLElement, isDark: boolean) {
|
||||
export async function renderMermaidDiagrams(container: HTMLElement) {
|
||||
const nodes = container.querySelectorAll<HTMLElement>(
|
||||
`pre.${MERMAID_BLOCK_CLASS}:not([${MERMAID_RENDERED_ATTR}])`
|
||||
);
|
||||
@@ -34,32 +59,56 @@ export async function renderMermaidDiagrams(container: HTMLElement, isDark: bool
|
||||
// This avoids needing a guard that would block node discovery.
|
||||
nodes.forEach((node) => node.setAttribute(MERMAID_RENDERED_ATTR, BooleanString.TRUE));
|
||||
|
||||
// lazy load the mermaid dependecy only when needed to reduce bundle size.
|
||||
const { default: mermaid } = await import('mermaid');
|
||||
const { render } = await import('pele');
|
||||
|
||||
mermaid.initialize({
|
||||
flowchart: {
|
||||
htmlLabels: true,
|
||||
useMaxWidth: false
|
||||
},
|
||||
gantt: {
|
||||
useMaxWidth: false
|
||||
},
|
||||
securityLevel: 'strict',
|
||||
sequence: {
|
||||
useMaxWidth: false
|
||||
},
|
||||
startOnLoad: false,
|
||||
theme: isDark ? 'dark' : 'default'
|
||||
});
|
||||
// Pele measures labels with the font it is given, so wait until the page font is in
|
||||
await document.fonts?.ready;
|
||||
|
||||
try {
|
||||
await mermaid.run({ nodes: Array.from(nodes) as unknown as NodeListOf<HTMLElement> });
|
||||
} catch (error) {
|
||||
console.error('Failed to render mermaid diagram:', error);
|
||||
for (const node of nodes) {
|
||||
const source = node.getAttribute(MERMAID_SYNTAX_ATTR) ?? node.textContent ?? '';
|
||||
const id = node.getAttribute(MERMAID_ID_ATTR);
|
||||
|
||||
try {
|
||||
const { svg } = render(source, {
|
||||
fontFamily: getComputedStyle(node).fontFamily,
|
||||
idPrefix: id ? id.replace(/[^\w-]/g, '_') : undefined,
|
||||
// narrow blocks (phones) may turn a left-to-right diagram top-to-bottom
|
||||
maxWidth: diagramWidth(node)
|
||||
});
|
||||
|
||||
node.innerHTML = svg;
|
||||
} catch (error) {
|
||||
// the message quotes the diagram source, so it goes in as text
|
||||
const message = document.createElement('div');
|
||||
|
||||
message.className = MERMAID_ERROR_CLASS;
|
||||
message.textContent = error instanceof Error ? error.message : String(error);
|
||||
node.replaceChildren(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A Pele diagram takes its colors from the page's `--pele-*` variables. Writes their current
|
||||
* values into the svg, so a downloaded file keeps the colors it had on screen. Any other svg
|
||||
* comes back unchanged.
|
||||
*/
|
||||
export function withThemeColors(svgHtml: string): string {
|
||||
const svg = new DOMParser().parseFromString(svgHtml, 'image/svg+xml').documentElement;
|
||||
|
||||
if (!(svg instanceof SVGElement) || !svg.classList.contains(PELE_SVG_CLASS)) return svgHtml;
|
||||
|
||||
const theme = getComputedStyle(document.documentElement);
|
||||
|
||||
for (const name of PELE_THEME_VARIABLES) {
|
||||
const value = theme.getPropertyValue(name).trim();
|
||||
|
||||
if (value) svg.style.setProperty(name, value);
|
||||
}
|
||||
|
||||
return new XMLSerializer().serializeToString(svg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the svg diagrams in `container` that haven't been rendered yet.
|
||||
* Sanitizes the source before injecting and marks each node so it renders once.
|
||||
|
||||
@@ -13,6 +13,7 @@ import { rehypeEnhanceMermaidBlocks } from './plugins/rehype/enhance-mermaid-blo
|
||||
import { rehypeEnhanceSvgBlocks } from './plugins/rehype/enhance-svg-blocks';
|
||||
import { rehypeEnhanceTables } from './plugins/rehype/enhance-tables';
|
||||
import { rehypeFileBadge } from './plugins/rehype/file-badge';
|
||||
import { rehypeLazyKatex } from './plugins/rehype/lazy-katex';
|
||||
import { rehypeMermaidPre } from './plugins/rehype/mermaid-pre';
|
||||
import { rehypeRtlSupport } from './plugins/rehype/rehype-rtl-support';
|
||||
import { rehypeResolveAttachmentImages } from './plugins/rehype/resolve-attachment-images';
|
||||
@@ -25,7 +26,6 @@ import type { Root as HastRoot } from 'hast';
|
||||
import { all as lowlightAll } from 'lowlight';
|
||||
import type { Root as MdastRoot } from 'mdast';
|
||||
import rehypeHighlight from 'rehype-highlight';
|
||||
import rehypeKatex from 'rehype-katex';
|
||||
import rehypeStringify from 'rehype-stringify';
|
||||
import { remark } from 'remark';
|
||||
import remarkBreaks from 'remark-breaks';
|
||||
@@ -71,7 +71,7 @@ function buildPipeline({
|
||||
proc = proc.use(remarkRehype, allowHtml ? { allowDangerousHtml: true } : undefined);
|
||||
|
||||
if (!disableMath) {
|
||||
proc = proc.use(rehypeKatex); // Render math using KaTeX
|
||||
proc = proc.use(rehypeLazyKatex); // Render math using KaTeX, loaded on the first message with math
|
||||
}
|
||||
|
||||
const pipeline = proc
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Rehype plugin that renders math with rehype-katex, loading KaTeX only when a message has math.
|
||||
*
|
||||
* remark-math marks math as elements with a `language-math`, `math-inline` or `math-display`
|
||||
* class; a tree without one is left alone, so a chat without math never downloads KaTeX.
|
||||
*/
|
||||
|
||||
import type { Element, Root } from 'hast';
|
||||
import type { Plugin, Transformer } from 'unified';
|
||||
import { visit } from 'unist-util-visit';
|
||||
|
||||
const MATH_CLASSES = ['language-math', 'math-inline', 'math-display'];
|
||||
|
||||
let katexLoading: Promise<Transformer<Root>> | undefined;
|
||||
let katexTransformer: Transformer<Root> | undefined;
|
||||
|
||||
function hasMath(tree: Root): boolean {
|
||||
let found = false;
|
||||
|
||||
visit(tree, 'element', (node: Element) => {
|
||||
const className = node.properties?.className;
|
||||
|
||||
if (Array.isArray(className) && className.some((c) => MATH_CLASSES.includes(String(c)))) {
|
||||
found = true;
|
||||
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
// synchronous when there is no math or KaTeX has loaded, so only the first message with math
|
||||
// waits for it, and every other one renders in the same pass as before
|
||||
export const rehypeLazyKatex: Plugin<[], Root> = () => {
|
||||
return (tree, file) => {
|
||||
if (!hasMath(tree)) return;
|
||||
|
||||
// rehype-katex changes the tree in place
|
||||
if (katexTransformer) {
|
||||
katexTransformer(tree, file, () => {});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
katexLoading ??= import('rehype-katex').then(({ default: rehypeKatex }) => {
|
||||
katexTransformer = rehypeKatex() as Transformer<Root>;
|
||||
|
||||
return katexTransformer;
|
||||
});
|
||||
|
||||
return katexLoading.then((transform) => {
|
||||
transform(tree, file, () => {});
|
||||
});
|
||||
};
|
||||
};
|
||||
@@ -12,14 +12,12 @@ import {
|
||||
import { getMarkdownProcessor } from '#lib/components/app/content/MarkdownContent/markdown-processor.ts';
|
||||
import { getCodeInfoFromTarget } from '#lib/components/app/content/MarkdownContent/markdown-utils.ts';
|
||||
import { MERMAID_BLOCK_CLASS } from '#lib/constants/index.ts';
|
||||
import { ColorMode } from '#lib/enums/index.ts';
|
||||
import {
|
||||
copyCodeToClipboard,
|
||||
copyToClipboard,
|
||||
preprocessLaTeX,
|
||||
splitGluedClosingCodeFences
|
||||
} from '#lib/utils/index.ts';
|
||||
import { mode } from 'mode-watcher';
|
||||
|
||||
export interface MarkdownBlockWidgetOptions {
|
||||
onPreviewCode?: (code: string, language: string) => void;
|
||||
@@ -311,9 +309,7 @@ export class MarkdownBlockWidget extends WidgetType {
|
||||
|
||||
// mermaid draws asynchronously and changes the block's height when done
|
||||
if (dom.querySelector(`pre.${MERMAID_BLOCK_CLASS}`)) {
|
||||
void renderMermaidDiagrams(dom, mode.current === ColorMode.DARK).then(() =>
|
||||
this.measure(dom, view, key)
|
||||
);
|
||||
void renderMermaidDiagrams(dom).then(() => this.measure(dom, view, key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import RotateCcwIcon from '@lucide/svelte/icons/rotate-ccw';
|
||||
import ZoomInIcon from '@lucide/svelte/icons/zoom-in';
|
||||
import ZoomOutIcon from '@lucide/svelte/icons/zoom-out';
|
||||
import { withThemeColors } from '#lib/components/app/content/MarkdownContent/markdown-diagrams.ts';
|
||||
import { ICON_CLASS_DEFAULT } from '#lib/constants/index.ts';
|
||||
|
||||
interface Props {
|
||||
@@ -18,7 +19,7 @@
|
||||
function downloadSvg() {
|
||||
if (!svgHtml) return;
|
||||
|
||||
const blob = new Blob([svgHtml], { type: 'image/svg+xml' });
|
||||
const blob = new Blob([withThemeColors(svgHtml)], { type: 'image/svg+xml' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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,
|
||||
FolderOpen as CwdCommandIcon,
|
||||
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,
|
||||
Sparkles as PromptCommandIcon,
|
||||
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-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 PromptCommandIcon from '@lucide/svelte/icons/sparkles';
|
||||
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';
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -1,6 +1,25 @@
|
||||
export const MERMAID_WRAPPER_CLASS = 'mermaid-block-wrapper';
|
||||
export const MERMAID_SCROLL_CONTAINER_CLASS = 'mermaid-scroll-container';
|
||||
export const MERMAID_BLOCK_CLASS = 'mermaid';
|
||||
export const MERMAID_ERROR_CLASS = 'mermaid-error';
|
||||
// left plus right padding of a diagram's svg, see `pre.mermaid svg` in markdown-content.css
|
||||
export const MERMAID_SVG_PADDING_X_REM = 2;
|
||||
|
||||
// class Pele puts on the root of every diagram it draws
|
||||
export const PELE_SVG_CLASS = 'pele';
|
||||
// the Pele colors app.css maps to the theme, written into a downloaded diagram
|
||||
export const PELE_THEME_VARIABLES = [
|
||||
'--pele-bg',
|
||||
'--pele-fg',
|
||||
'--pele-muted',
|
||||
'--pele-line',
|
||||
'--pele-surface',
|
||||
'--pele-surface-alt',
|
||||
'--pele-border',
|
||||
'--pele-accent',
|
||||
'--pele-critical',
|
||||
'--pele-radius'
|
||||
] as const;
|
||||
|
||||
export const MERMAID_LANGUAGE = 'mermaid';
|
||||
|
||||
|
||||
@@ -5,19 +5,17 @@ import { DEFAULT_MCP_CONFIG } from './mcp.constants';
|
||||
import { SETTINGS_KEYS } from './settings-keys.constants';
|
||||
import { TITLE_GENERATION } from './title-generation.constants';
|
||||
import { FILE_GLOB_SEARCH_PICKERS } from './working-directory.constants';
|
||||
import {
|
||||
Code,
|
||||
Database,
|
||||
File,
|
||||
Funnel,
|
||||
GlassWater,
|
||||
ListRestart,
|
||||
Monitor,
|
||||
Moon,
|
||||
PencilRuler,
|
||||
SlidersVertical,
|
||||
Sun
|
||||
} from '@lucide/svelte';
|
||||
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 GlassWater from '@lucide/svelte/icons/glass-water';
|
||||
import ListRestart from '@lucide/svelte/icons/list-restart';
|
||||
import Monitor from '@lucide/svelte/icons/monitor';
|
||||
import Moon from '@lucide/svelte/icons/moon';
|
||||
import PencilRuler from '@lucide/svelte/icons/pencil-ruler';
|
||||
import SlidersVertical from '@lucide/svelte/icons/sliders-vertical';
|
||||
import Sun from '@lucide/svelte/icons/sun';
|
||||
import { SurfaceTheme, SyncableParameterType } from '#lib/enums/index.ts';
|
||||
import { SettingsFieldType } from '#lib/enums/settings.enums.ts';
|
||||
import { ColorMode } from '#lib/enums/ui.enums.ts';
|
||||
|
||||
@@ -7,19 +7,17 @@
|
||||
// (see ChatMessageToolCallBlockGetDatetime and
|
||||
// ChatMessageToolCallBlockSearchResults for prior art).
|
||||
|
||||
import {
|
||||
Braces,
|
||||
Clock,
|
||||
Eye,
|
||||
FilePen,
|
||||
FilePlus,
|
||||
FileSearch,
|
||||
FileText,
|
||||
Info,
|
||||
MessagesSquare,
|
||||
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 MessagesSquare from '@lucide/svelte/icons/messages-square';
|
||||
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';
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ import {
|
||||
SHORTCUT_SETTINGS
|
||||
} from './keyboard-shortcuts.constants';
|
||||
import { MCP_SERVERS_ROUTE_ID, MODELS_ROUTE_ID, SETTINGS_ROUTE_ID } from './routes.constants';
|
||||
import { Search, Settings, SquarePen } from '@lucide/svelte';
|
||||
import Search from '@lucide/svelte/icons/search';
|
||||
import Settings from '@lucide/svelte/icons/settings';
|
||||
import SquarePen from '@lucide/svelte/icons/square-pen';
|
||||
import McpLogo from '#lib/components/app/mcp/McpLogo.svelte';
|
||||
import { SidebarAction, ToolSource } from '#lib/enums/index.ts';
|
||||
import type { DesktopIconStripItem } from '#lib/types/index.ts';
|
||||
|
||||
@@ -33,9 +33,9 @@ async function getHarness(): Promise<string> {
|
||||
|
||||
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('');
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -5,23 +5,23 @@
|
||||
|
||||
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' });
|
||||
let pdfjsModule: Promise<typeof import('pdfjs-dist')> | undefined;
|
||||
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(workerBlob);
|
||||
})
|
||||
.catch(() => {
|
||||
console.warn('Failed to load PDF.js worker, PDF processing may not work');
|
||||
});
|
||||
// pdf.js and its worker are files of their own, so the app loads them only when it opens a PDF
|
||||
function loadPdfjs(): Promise<typeof import('pdfjs-dist')> {
|
||||
pdfjsModule ??= import('pdfjs-dist').then((pdfjs) => {
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = pdfWorkerUrl;
|
||||
|
||||
return pdfjs;
|
||||
});
|
||||
|
||||
return pdfjsModule;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +58,7 @@ export async function convertPDFToText(file: File): Promise<string> {
|
||||
}
|
||||
|
||||
try {
|
||||
const buffer = await getFileAsBuffer(file);
|
||||
const [pdfjs, buffer] = await Promise.all([loadPdfjs(), getFileAsBuffer(file)]);
|
||||
const pdf = await pdfjs.getDocument({ data: buffer }).promise;
|
||||
const numPages = pdf.numPages;
|
||||
const textContentPromises: Promise<TextContent>[] = [];
|
||||
@@ -96,7 +96,7 @@ export async function convertPDFToImage(file: File, scale: number = 1.5): Promis
|
||||
}
|
||||
|
||||
try {
|
||||
const buffer = await getFileAsBuffer(file);
|
||||
const [pdfjs, buffer] = await Promise.all([loadPdfjs(), getFileAsBuffer(file)]);
|
||||
const doc = await pdfjs.getDocument({ data: buffer }).promise;
|
||||
const pages: Promise<string>[] = [];
|
||||
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
declare module 'virtual:nerdamer' {
|
||||
const code: string;
|
||||
export default code;
|
||||
const loadNerdamer: () => Promise<string>;
|
||||
export default loadNerdamer;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// pdf.js loads on first use, with its worker as a file of its own: extracting a PDF's text
|
||||
// and drawing its pages go through that load.
|
||||
import { convertPDFToImage, convertPDFToText } from '#lib/utils/pdf-processing.ts';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
/** A one-page PDF that shows `text`, with a correct cross-reference table. */
|
||||
function pdfWithText(text: string): File {
|
||||
const stream = `BT /F1 24 Tf 72 720 Td (${text}) Tj ET`;
|
||||
const objects = [
|
||||
'<< /Type /Catalog /Pages 2 0 R >>',
|
||||
'<< /Type /Pages /Kids [3 0 R] /Count 1 >>',
|
||||
'<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >>',
|
||||
`<< /Length ${stream.length} >>\nstream\n${stream}\nendstream`,
|
||||
'<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>'
|
||||
];
|
||||
|
||||
let body = '%PDF-1.4\n';
|
||||
|
||||
const offsets: number[] = [];
|
||||
|
||||
objects.forEach((object, i) => {
|
||||
offsets.push(body.length);
|
||||
body += `${i + 1} 0 obj\n${object}\nendobj\n`;
|
||||
});
|
||||
|
||||
const xref = body.length;
|
||||
const entries = offsets.map((offset) => `${String(offset).padStart(10, '0')} 00000 n \n`);
|
||||
|
||||
body += `xref\n0 ${objects.length + 1}\n0000000000 65535 f \n${entries.join('')}`;
|
||||
body += `trailer\n<< /Size ${objects.length + 1} /Root 1 0 R >>\nstartxref\n${xref}\n%%EOF\n`;
|
||||
|
||||
return new File([body], 'hello.pdf', { type: 'application/pdf' });
|
||||
}
|
||||
|
||||
describe('pdf-processing', () => {
|
||||
it('extracts the text of a PDF', async () => {
|
||||
const text = await convertPDFToText(pdfWithText('Hello from a PDF'));
|
||||
|
||||
expect(text).toContain('Hello from a PDF');
|
||||
});
|
||||
|
||||
it('draws each page of a PDF as a PNG', async () => {
|
||||
const pages = await convertPDFToImage(pdfWithText('Page one'));
|
||||
|
||||
expect(pages).toHaveLength(1);
|
||||
expect(pages[0]).toMatch(/^data:image\/png;base64,/);
|
||||
});
|
||||
});
|
||||
@@ -40,9 +40,10 @@ test.describe('PWA Service Worker', () => {
|
||||
const swResponse = await page.request.get(swActive!);
|
||||
const swContent = await swResponse.text();
|
||||
|
||||
// Precache contains SvelteKit content-hashed bundle paths
|
||||
expect(swContent).toMatch(/["'`]_app\/immutable\/bundle\.[a-zA-Z0-9_-]+\.js["'`]/);
|
||||
expect(swContent).toMatch(/["'`]_app\/immutable\/assets\/bundle\.[a-zA-Z0-9_-]+\.css["'`]/);
|
||||
// Precache contains SvelteKit's content-hashed entry points and CSS (a split build)
|
||||
expect(swContent).toMatch(/["'`]_app\/immutable\/entry\/start\.[a-zA-Z0-9_-]+\.js["'`]/);
|
||||
expect(swContent).toMatch(/["'`]_app\/immutable\/entry\/app\.[a-zA-Z0-9_-]+\.js["'`]/);
|
||||
expect(swContent).toMatch(/["'`]_app\/immutable\/assets\/[a-zA-Z0-9_.-]+\.css["'`]/);
|
||||
expect(swContent).toMatch(/["'`]manifest\.webmanifest["'`]/);
|
||||
expect(swContent).toMatch(/["'`]_app\/version\.json["'`]/);
|
||||
});
|
||||
@@ -120,16 +121,17 @@ test.describe('PWA Service Worker', () => {
|
||||
expect(manifest.icons.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test('index.html contains content-hashed bundle references', async ({ page }) => {
|
||||
test('index.html contains content-hashed entry references', async ({ page }) => {
|
||||
const response = await page.request.get('/');
|
||||
|
||||
expect(response.ok()).toBeTruthy();
|
||||
|
||||
const html = await response.text();
|
||||
|
||||
// SvelteKit outputs content-hashed bundle names in _app/immutable/
|
||||
expect(html).toMatch(/href="(\.\/|\/)_app\/immutable\/bundle\.[a-zA-Z0-9_-]+\.js"/);
|
||||
expect(html).toMatch(/href="(\.\/|\/)_app\/immutable\/assets\/bundle\.[a-zA-Z0-9_-]+\.css"/);
|
||||
expect(html).toMatch(/import\("(\.\/|\/)_app\/immutable\/bundle\.[a-zA-Z0-9_-]+\.js"\)/);
|
||||
// a split build: SvelteKit's content-hashed entry points in _app/immutable/entry/
|
||||
expect(html).toMatch(/href="(\.\/|\/)_app\/immutable\/entry\/start\.[a-zA-Z0-9_-]+\.js"/);
|
||||
expect(html).toMatch(/href="(\.\/|\/)_app\/immutable\/assets\/[a-zA-Z0-9_.-]+\.css"/);
|
||||
expect(html).toMatch(/import\("(\.\/|\/)_app\/immutable\/entry\/start\.[a-zA-Z0-9_-]+\.js"\)/);
|
||||
expect(html).toMatch(/import\("(\.\/|\/)_app\/immutable\/entry\/app\.[a-zA-Z0-9_-]+\.js"\)/);
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,9 @@
|
||||
<script lang="ts" module>
|
||||
import { AI_TUTORIAL_MD } from '../fixtures/ai-tutorial.js';
|
||||
import { MERMAID_DIAGRAMS_MD } from '../fixtures/mermaid-diagrams.js';
|
||||
import { defineMeta } from '@storybook/addon-svelte-csf';
|
||||
import { MarkdownContent } from '#lib/components/app/index.ts';
|
||||
import { expect, waitFor } from 'storybook/test';
|
||||
|
||||
const { Story } = defineMeta({
|
||||
component: MarkdownContent,
|
||||
@@ -16,3 +18,23 @@
|
||||
args={{ class: 'max-w-[56rem] w-[calc(100vw-2rem)]', content: AI_TUTORIAL_MD }}
|
||||
name="Default"
|
||||
/>
|
||||
|
||||
<Story
|
||||
args={{ class: 'max-w-[56rem] w-[calc(100vw-2rem)]', content: MERMAID_DIAGRAMS_MD }}
|
||||
name="Diagrams"
|
||||
play={async ({ canvasElement }) => {
|
||||
// MarkdownContent renders in batches, so the broken last block can trail the others
|
||||
await waitFor(
|
||||
() => {
|
||||
expect(canvasElement.querySelectorAll('pre.mermaid svg.pele')).toHaveLength(4);
|
||||
expect(canvasElement.querySelector('pre.mermaid .mermaid-error')).not.toBeNull();
|
||||
},
|
||||
{ timeout: 5000 }
|
||||
);
|
||||
|
||||
const error = canvasElement.querySelector('pre.mermaid .mermaid-error');
|
||||
|
||||
await expect(error?.textContent).toContain('line 2');
|
||||
await expect(error?.closest('pre')).toBeVisible();
|
||||
}}
|
||||
/>
|
||||
@@ -0,0 +1,54 @@
|
||||
// Mermaid blocks of several diagram types, and one that can't be drawn
|
||||
const fence = '```';
|
||||
|
||||
export const MERMAID_DIAGRAMS_MD = String.raw`
|
||||
How a request reaches the model:
|
||||
|
||||
${fence}mermaid
|
||||
flowchart LR
|
||||
U[Browser] -->|POST /v1/chat/completions| S(llama-server)
|
||||
S --> Q{Slot free?}
|
||||
Q -->|yes| D[Decode]
|
||||
Q -->|no| W[Queue]
|
||||
W --> D
|
||||
D -->|SSE tokens| U
|
||||
${fence}
|
||||
|
||||
The same exchange over time:
|
||||
|
||||
${fence}mermaid
|
||||
sequenceDiagram
|
||||
participant C as Llama Chat
|
||||
participant S as llama-server
|
||||
C->>S: POST /v1/chat/completions
|
||||
S-->>C: data: {"choices":[...]}
|
||||
S-->>C: data: [DONE]
|
||||
Note over C,S: the stream ends with DONE
|
||||
${fence}
|
||||
|
||||
A slot's life:
|
||||
|
||||
${fence}mermaid
|
||||
stateDiagram-v2
|
||||
[*] --> Idle
|
||||
Idle --> Processing: prompt
|
||||
Processing --> Generating: prompt evaluated
|
||||
Generating --> Idle: stop or limit
|
||||
${fence}
|
||||
|
||||
Where the time goes:
|
||||
|
||||
${fence}mermaid
|
||||
pie title Time per request
|
||||
"Prompt processing" : 35
|
||||
"Token generation" : 60
|
||||
"Sampling" : 5
|
||||
${fence}
|
||||
|
||||
A diagram with a mistake in it:
|
||||
|
||||
${fence}mermaid
|
||||
flowchart LR
|
||||
A -->
|
||||
${fence}
|
||||
`;
|
||||
@@ -0,0 +1,32 @@
|
||||
import { rehypeLazyKatex } from '#lib/components/app/content/MarkdownContent/plugins/rehype/lazy-katex.ts';
|
||||
import type { Root } from 'hast';
|
||||
import rehypeStringify from 'rehype-stringify';
|
||||
import { remark } from 'remark';
|
||||
import remarkMath from 'remark-math';
|
||||
import remarkRehype from 'remark-rehype';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
const processor = remark()
|
||||
.use(remarkMath)
|
||||
.use(remarkRehype)
|
||||
.use(rehypeLazyKatex)
|
||||
.use(rehypeStringify);
|
||||
|
||||
async function render(markdown: string): Promise<string> {
|
||||
return processor.stringify((await processor.run(processor.parse(markdown))) as Root);
|
||||
}
|
||||
|
||||
describe('rehypeLazyKatex', () => {
|
||||
it('renders inline and display math with KaTeX', async () => {
|
||||
const html = await render('Area $\\pi r^2$\n\n$$\nE = mc^2\n$$');
|
||||
|
||||
expect(html.match(/class="katex"/g)).toHaveLength(2);
|
||||
expect(html).toContain('katex-display');
|
||||
});
|
||||
|
||||
it('leaves a message without math as it is, in the same pass', () => {
|
||||
const tree = processor.runSync(processor.parse('Just *text* and `code`')) as Root;
|
||||
|
||||
expect(processor.stringify(tree)).toBe('<p>Just <em>text</em> and <code>code</code></p>');
|
||||
});
|
||||
});
|
||||
@@ -38,24 +38,23 @@ describe('PWA Build Output', () => {
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
it('SvelteKit bundle.js exists in _app/immutable/', () => {
|
||||
// SvelteKit generates hashed bundle names in _app/immutable/
|
||||
const appDir = resolve(DIST_DIR, '_app', 'immutable');
|
||||
it('SvelteKit entry start.js and app.js exist in _app/immutable/entry/', () => {
|
||||
// a split build: hashed entry points in _app/immutable/entry/, the rest in chunks/ and nodes/
|
||||
const entryDir = resolve(DIST_DIR, '_app', 'immutable', 'entry');
|
||||
|
||||
expect(existsSync(appDir), '_app/immutable/ not found').toBeTruthy();
|
||||
const files = readdirSync(appDir).filter((f) => f.startsWith('bundle.') && f.endsWith('.js'));
|
||||
expect(existsSync(entryDir), '_app/immutable/entry/ not found').toBeTruthy();
|
||||
const files = readdirSync(entryDir);
|
||||
|
||||
expect(files.length).toBeGreaterThan(0);
|
||||
expect(files.some((f) => /^start\.[a-zA-Z0-9_-]+\.js$/.test(f))).toBe(true);
|
||||
expect(files.some((f) => /^app\.[a-zA-Z0-9_-]+\.js$/.test(f))).toBe(true);
|
||||
});
|
||||
|
||||
it('SvelteKit bundle.css exists in _app/immutable/assets/', () => {
|
||||
// SvelteKit generates hashed CSS bundles in _app/immutable/assets/
|
||||
it('SvelteKit CSS exists in _app/immutable/assets/', () => {
|
||||
// SvelteKit generates hashed CSS files in _app/immutable/assets/
|
||||
const cssDir = resolve(DIST_DIR, '_app', 'immutable', 'assets');
|
||||
|
||||
expect(existsSync(cssDir), '_app/immutable/assets/ not found').toBeTruthy();
|
||||
const files = readdirSync(cssDir).filter(
|
||||
(f) => f.startsWith('bundle.') && f.endsWith('.css')
|
||||
);
|
||||
const files = readdirSync(cssDir).filter((f) => f.endsWith('.css'));
|
||||
|
||||
expect(files.length).toBeGreaterThan(0);
|
||||
});
|
||||
@@ -81,12 +80,15 @@ describe('PWA Build Output', () => {
|
||||
});
|
||||
|
||||
describe('Service worker content', () => {
|
||||
it('precache contains SvelteKit bundle.js with content hash', () => {
|
||||
expect(swContent).toMatch(/["'`]_app\/immutable\/bundle\.[a-zA-Z0-9_-]+\.js["'`]/);
|
||||
});
|
||||
it('precache contains every file in _app/immutable/, so lazily loaded chunks work offline', () => {
|
||||
const immutableDir = resolve(DIST_DIR, '_app', 'immutable');
|
||||
const files = readdirSync(immutableDir, { recursive: true, withFileTypes: true })
|
||||
.filter((entry) => entry.isFile())
|
||||
.map((entry) => resolve(entry.parentPath, entry.name).slice(resolve(DIST_DIR).length + 1));
|
||||
|
||||
it('precache contains SvelteKit bundle.css with content hash', () => {
|
||||
expect(swContent).toMatch(/["'`]_app\/immutable\/assets\/bundle\.[a-zA-Z0-9_-]+\.css["'`]/);
|
||||
expect(files.length).toBeGreaterThan(0);
|
||||
|
||||
for (const file of files) expect(swContent).toContain(file);
|
||||
});
|
||||
|
||||
it('precache contains the app shell, _app/version.json and manifest.webmanifest', () => {
|
||||
@@ -119,23 +121,27 @@ describe('PWA Build Output', () => {
|
||||
});
|
||||
|
||||
describe('index.html content', () => {
|
||||
it('has modulepreload link for SvelteKit bundle with content hash', () => {
|
||||
expect(indexContent).toBeTruthy();
|
||||
// SvelteKit generates hashed bundle names in _app/immutable/
|
||||
expect(indexContent).toMatch(/href="(\.\/|\/)_app\/immutable\/bundle\.[a-zA-Z0-9_-]+\.js"/);
|
||||
});
|
||||
|
||||
it('has stylesheet link for SvelteKit bundle.css with content hash', () => {
|
||||
it('has modulepreload link for the SvelteKit entry with content hash', () => {
|
||||
expect(indexContent).toBeTruthy();
|
||||
expect(indexContent).toMatch(
|
||||
/href="(\.\/|\/)_app\/immutable\/assets\/bundle\.[a-zA-Z0-9_-]+\.css"/
|
||||
/href="(\.\/|\/)_app\/immutable\/entry\/start\.[a-zA-Z0-9_-]+\.js"/
|
||||
);
|
||||
});
|
||||
|
||||
it('has dynamic import for SvelteKit bundle with content hash', () => {
|
||||
it('has stylesheet link for SvelteKit CSS with content hash', () => {
|
||||
expect(indexContent).toBeTruthy();
|
||||
expect(indexContent).toMatch(
|
||||
/import\("(\.\/|\/)_app\/immutable\/bundle\.[a-zA-Z0-9_-]+\.js"\)/
|
||||
/href="(\.\/|\/)_app\/immutable\/assets\/[a-zA-Z0-9_.-]+\.[a-zA-Z0-9_-]+\.css"/
|
||||
);
|
||||
});
|
||||
|
||||
it('has dynamic imports for the SvelteKit entry with content hash', () => {
|
||||
expect(indexContent).toBeTruthy();
|
||||
expect(indexContent).toMatch(
|
||||
/import\("(\.\/|\/)_app\/immutable\/entry\/start\.[a-zA-Z0-9_-]+\.js"\)/
|
||||
);
|
||||
expect(indexContent).toMatch(
|
||||
/import\("(\.\/|\/)_app\/immutable\/entry\/app\.[a-zA-Z0-9_-]+\.js"\)/
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -28,6 +28,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"],
|
||||
|
||||
@@ -55,7 +55,7 @@ export default defineConfig(({ mode }) => {
|
||||
strict: true
|
||||
}),
|
||||
extensions: ['.svelte', '.svx'],
|
||||
output: { bundleStrategy: 'single' },
|
||||
output: { bundleStrategy: 'split' },
|
||||
paths: { relative: true },
|
||||
// Consult https://svelte.dev/docs/kit/integrations
|
||||
// for more information about preprocessors
|
||||
|
||||
Generated
+60
-23
@@ -10,13 +10,14 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@ggml-org/llama-brand": "0.1.0",
|
||||
"@internationalized/date": "^3.12.4",
|
||||
"@internationalized/date": "3.12.4",
|
||||
"@lucide/svelte": "1.46.0",
|
||||
"bits-ui": "2.18.1",
|
||||
"clsx": "^2.1.1",
|
||||
"highlight.js": "^11.11.1",
|
||||
"tailwind-merge": "^3.7.0",
|
||||
"tailwind-variants": "^3.3.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"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -27,28 +28,28 @@
|
||||
"@storybook/addon-svelte-csf": "5.1.6",
|
||||
"@storybook/addon-vitest": "10.6.6",
|
||||
"@storybook/sveltekit": "10.6.6",
|
||||
"@sveltejs/adapter-auto": "^8.0.0",
|
||||
"@sveltejs/kit": "^3.0.0",
|
||||
"@sveltejs/package": "^2.5.8",
|
||||
"@sveltejs/vite-plugin-svelte": "^7.2.0",
|
||||
"@tailwindcss/vite": "^4.3.3",
|
||||
"@types/node": "^24",
|
||||
"@sveltejs/adapter-auto": "8.0.0",
|
||||
"@sveltejs/kit": "3.2.0",
|
||||
"@sveltejs/package": "2.5.8",
|
||||
"@sveltejs/vite-plugin-svelte": "7.3.1",
|
||||
"@tailwindcss/vite": "4.3.3",
|
||||
"@types/node": "24.19.2",
|
||||
"@vitest/browser-playwright": "5.0.5",
|
||||
"@vitest/coverage-v8": "5.0.5",
|
||||
"mdsvex": "0.12.7",
|
||||
"mode-watcher": "^1.1.0",
|
||||
"playwright": "^1.60.0",
|
||||
"publint": "^0.3.21",
|
||||
"mode-watcher": "1.1.0",
|
||||
"playwright": "1.64.1",
|
||||
"publint": "0.3.25",
|
||||
"storybook": "10.6.6",
|
||||
"svelte": "^5.57.1",
|
||||
"svelte-check": "^4.6.0",
|
||||
"tailwindcss": "^4.3.3",
|
||||
"svelte": "5.57.3",
|
||||
"svelte-check": "4.7.7",
|
||||
"tailwindcss": "4.3.3",
|
||||
"tw-animate-css": "1.4.0",
|
||||
"typescript": "^6.0.3",
|
||||
"typescript": "6.0.3",
|
||||
"vite": "npm:@voidzero-dev/vite-plus-core@1.3.0",
|
||||
"vite-plus": "1.3.0",
|
||||
"vitest": "5.0.5",
|
||||
"vitest-browser-svelte": "^2.1.1"
|
||||
"vitest-browser-svelte": "2.2.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"mode-watcher": "^1.1.0",
|
||||
@@ -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",
|
||||
@@ -6149,9 +6186,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/svelte": {
|
||||
"version": "5.57.2",
|
||||
"resolved": "https://registry.npmjs.org/svelte/-/svelte-5.57.2.tgz",
|
||||
"integrity": "sha512-1YiPCAXT0Ct6g1vOMmSLa0Nsc3QRMvtDF32ihgglGVrugIuIK38RyDiFNXVDhtQ81TJjSO57NdMw6DyYLqSGDQ==",
|
||||
"version": "5.57.3",
|
||||
"resolved": "https://registry.npmjs.org/svelte/-/svelte-5.57.3.tgz",
|
||||
"integrity": "sha512-5mAftM3SoDV9X0zdF386F9p2pv8iKOwi/KfBS1XnBAkVCKFzVOLHUoa8iGWAt4buoicLmyWVRpuuD5wplXOQsg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
+20
-19
@@ -86,28 +86,28 @@
|
||||
"@storybook/addon-svelte-csf": "5.1.6",
|
||||
"@storybook/addon-vitest": "10.6.6",
|
||||
"@storybook/sveltekit": "10.6.6",
|
||||
"@sveltejs/adapter-auto": "^8.0.0",
|
||||
"@sveltejs/kit": "^3.0.0",
|
||||
"@sveltejs/package": "^2.5.8",
|
||||
"@sveltejs/vite-plugin-svelte": "^7.2.0",
|
||||
"@tailwindcss/vite": "^4.3.3",
|
||||
"@types/node": "^24",
|
||||
"@sveltejs/adapter-auto": "8.0.0",
|
||||
"@sveltejs/kit": "3.2.0",
|
||||
"@sveltejs/package": "2.5.8",
|
||||
"@sveltejs/vite-plugin-svelte": "7.3.1",
|
||||
"@tailwindcss/vite": "4.3.3",
|
||||
"@types/node": "24.19.2",
|
||||
"@vitest/browser-playwright": "5.0.5",
|
||||
"@vitest/coverage-v8": "5.0.5",
|
||||
"mdsvex": "0.12.7",
|
||||
"mode-watcher": "^1.1.0",
|
||||
"playwright": "^1.60.0",
|
||||
"publint": "^0.3.21",
|
||||
"mode-watcher": "1.1.0",
|
||||
"playwright": "1.64.1",
|
||||
"publint": "0.3.25",
|
||||
"storybook": "10.6.6",
|
||||
"svelte": "^5.57.1",
|
||||
"svelte-check": "^4.6.0",
|
||||
"tailwindcss": "^4.3.3",
|
||||
"svelte": "5.57.3",
|
||||
"svelte-check": "4.7.7",
|
||||
"tailwindcss": "4.3.3",
|
||||
"tw-animate-css": "1.4.0",
|
||||
"typescript": "^6.0.3",
|
||||
"typescript": "6.0.3",
|
||||
"vite": "npm:@voidzero-dev/vite-plus-core@1.3.0",
|
||||
"vite-plus": "1.3.0",
|
||||
"vitest": "5.0.5",
|
||||
"vitest-browser-svelte": "^2.1.1"
|
||||
"vitest-browser-svelte": "2.2.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"mode-watcher": "^1.1.0",
|
||||
@@ -120,14 +120,15 @@
|
||||
"vitest": "5.0.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@internationalized/date": "^3.12.4",
|
||||
"@internationalized/date": "3.12.4",
|
||||
"@lucide/svelte": "1.46.0",
|
||||
"bits-ui": "2.18.1",
|
||||
"clsx": "^2.1.1",
|
||||
"highlight.js": "^11.11.1",
|
||||
"clsx": "2.1.1",
|
||||
"highlight.js": "11.11.1",
|
||||
"lowlight": "3.3.0",
|
||||
"@ggml-org/llama-brand": "0.1.0",
|
||||
"tailwind-merge": "^3.7.0",
|
||||
"tailwind-variants": "^3.3.1",
|
||||
"tailwind-merge": "3.7.0",
|
||||
"tailwind-variants": "3.3.1",
|
||||
"vaul-svelte": "1.0.0-next.7"
|
||||
}
|
||||
}
|
||||
@@ -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. */
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user