diff --git a/tools/ui/.gitignore b/tools/ui/.gitignore index 7cd35376e199..ad5425313f64 100644 --- a/tools/ui/.gitignore +++ b/tools/ui/.gitignore @@ -35,6 +35,8 @@ static/favicon* # Storybook *storybook.log storybook-static +# Llama design system for Claude (npm run export:design-system) +design-system-export *.code-workspace # Vitest browser mode failure artifacts diff --git a/tools/ui/.storybook/color-scheme.ts b/tools/ui/.storybook/color-scheme.ts new file mode 100644 index 000000000000..3b5feab66f74 --- /dev/null +++ b/tools/ui/.storybook/color-scheme.ts @@ -0,0 +1,12 @@ +/** + * Sets the `dark` class from the saved mode-watcher mode, or the system preference + * when there is none. Docs pages render no story, so preview.ts calls this too. + */ +export function applyColorScheme() { + const mode = localStorage.getItem('mode-watcher-mode') || 'system'; + const isDark = + mode === 'dark' || + (mode === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches); + + document.documentElement.classList.toggle('dark', isDark); +} diff --git a/tools/ui/.storybook/decorators/ModeWatcherDecorator.svelte b/tools/ui/.storybook/decorators/ModeWatcherDecorator.svelte index 8bded8b3f1e6..a20701dd6a20 100644 --- a/tools/ui/.storybook/decorators/ModeWatcherDecorator.svelte +++ b/tools/ui/.storybook/decorators/ModeWatcherDecorator.svelte @@ -1,33 +1,23 @@ - +{#if !forced}{/if} {#if children} {@const Component = children} diff --git a/tools/ui/.storybook/docs.css b/tools/ui/.storybook/docs.css new file mode 100644 index 000000000000..4a2f1facc078 --- /dev/null +++ b/tools/ui/.storybook/docs.css @@ -0,0 +1,91 @@ +@reference '../src/app.css'; + +/* + * MDX pages that wrap their content in
drop + * Storybook's docs theme and take colours, font and type roles from the design system. + */ +.sbdocs-wrapper:has(.ds-docs) { + background: var(--surface-page); +} + +.ds-docs { + @apply mx-auto max-w-3xl font-sans text-body text-fg-default; + + & :where(h1) { + @apply mb-4 text-heading; + } + + & :where(h2) { + @apply mt-10 mb-3 border-b border-line-default pb-2 text-title; + } + + & :where(h3) { + @apply mt-6 mb-2 text-body font-semibold; + } + + & :where(h4, h5, h6) { + @apply mt-4 mb-2 text-label; + } + + & :where(p, ul, ol, blockquote, table, pre) { + @apply my-3; + } + + & :where(ul) { + @apply list-disc pl-6; + } + + & :where(ol) { + @apply list-decimal pl-6; + } + + & :where(li) { + @apply my-1; + } + + & :where(strong) { + @apply font-semibold; + } + + & :where(a) { + @apply underline underline-offset-2 hover:text-fg-muted; + } + + & :where(blockquote) { + @apply border-l-2 border-line-default pl-4 text-fg-muted; + } + + /* a note that stands out from the running text: a quiet panel with the accent on its edge */ + & :where(.callout) { + @apply my-6 rounded-panel border-l-2 border-(--art-cinder) bg-surface-muted px-5 py-4; + + & > :where(p) { + @apply my-0; + } + } + + & :where(hr) { + @apply my-8 border-line-default; + } + + /* inline code only, with a selector that outranks the code the Markdown block renders */ + & :not(pre) > code { + @apply rounded-control border-0 bg-surface-code px-1 py-0.5 font-mono text-[0.875em] text-(--fg-code); + } + + & :where(pre) { + @apply overflow-x-auto rounded-panel bg-surface-code p-4 text-body-sm; + } + + & :where(table) { + @apply w-full border-collapse text-body-sm; + } + + & :where(th, td) { + @apply border-b border-line-default px-3 py-2 text-left align-top; + } + + & :where(th) { + @apply text-label; + } +} diff --git a/tools/ui/.storybook/manager-head.html b/tools/ui/.storybook/manager-head.html new file mode 100644 index 000000000000..e6f22a75ca83 --- /dev/null +++ b/tools/ui/.storybook/manager-head.html @@ -0,0 +1,99 @@ + + diff --git a/tools/ui/.storybook/mockups/MacDock.svelte b/tools/ui/.storybook/mockups/MacDock.svelte new file mode 100644 index 000000000000..0c2fdfad9bcf --- /dev/null +++ b/tools/ui/.storybook/mockups/MacDock.svelte @@ -0,0 +1,174 @@ + + + + + +{#snippet tile(app: DockApp)} + + {#if app.name === labelled}{app.name}{/if} + + {#if app.icon} + {app.name} + {:else} + {@const Glyph = app.glyph ?? Folder} + + + + + + + + + + + {/if} + + + +{/snippet} + + + + diff --git a/tools/ui/.storybook/mockups/MacMenuBar.svelte b/tools/ui/.storybook/mockups/MacMenuBar.svelte new file mode 100644 index 000000000000..5a524adb07ce --- /dev/null +++ b/tools/ui/.storybook/mockups/MacMenuBar.svelte @@ -0,0 +1,119 @@ + + + + + + diff --git a/tools/ui/.storybook/mockups/MacStatusIcon.svelte b/tools/ui/.storybook/mockups/MacStatusIcon.svelte new file mode 100644 index 000000000000..2b857aa5ad37 --- /dev/null +++ b/tools/ui/.storybook/mockups/MacStatusIcon.svelte @@ -0,0 +1,56 @@ + + + + + + + + diff --git a/tools/ui/.storybook/mockups/MockDesktop.svelte b/tools/ui/.storybook/mockups/MockDesktop.svelte new file mode 100644 index 000000000000..51facca5111d --- /dev/null +++ b/tools/ui/.storybook/mockups/MockDesktop.svelte @@ -0,0 +1,76 @@ + + + +
+
+ {@render children()} +
+
+ + diff --git a/tools/ui/.storybook/mockups/WindowsTaskbar.svelte b/tools/ui/.storybook/mockups/WindowsTaskbar.svelte new file mode 100644 index 000000000000..dc2e8afdf8bd --- /dev/null +++ b/tools/ui/.storybook/mockups/WindowsTaskbar.svelte @@ -0,0 +1,234 @@ + + + + + + + + diff --git a/tools/ui/.storybook/mockups/index.ts b/tools/ui/.storybook/mockups/index.ts new file mode 100644 index 000000000000..c4783bde1224 --- /dev/null +++ b/tools/ui/.storybook/mockups/index.ts @@ -0,0 +1,15 @@ +// OS mockups for the stories: a desktop's wallpaper, and on it the macOS Dock and menu bar or the Windows taskbar, +// to picture the brand's icons where the apps put them +export { + default as MacDock, + PLACEHOLDERS as MAC_DOCK_PLACEHOLDERS, + type DockApp +} from './MacDock.svelte'; +export { default as MacMenuBar } from './MacMenuBar.svelte'; +export { default as MacStatusIcon } from './MacStatusIcon.svelte'; +export { default as MockDesktop } from './MockDesktop.svelte'; +export { + default as WindowsTaskbar, + PLACEHOLDERS as WINDOWS_TASKBAR_PLACEHOLDERS, + type TaskbarApp +} from './WindowsTaskbar.svelte'; diff --git a/tools/ui/.storybook/preview.ts b/tools/ui/.storybook/preview.ts index 4610229a681c..ca02559db9d0 100644 --- a/tools/ui/.storybook/preview.ts +++ b/tools/ui/.storybook/preview.ts @@ -1,8 +1,13 @@ import type { Preview } from '@storybook/sveltekit'; import '../src/app.css'; +import './docs.css'; +import { applyColorScheme } from './color-scheme'; import ModeWatcherDecorator from './decorators/ModeWatcherDecorator.svelte'; import TooltipProviderDecorator from './decorators/TooltipProviderDecorator.svelte'; +applyColorScheme(); +window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', applyColorScheme); + const preview: Preview = { parameters: { controls: { @@ -16,6 +21,87 @@ const preview: Preview = { disabled: true }, + options: { + // sidebar sections: the introduction, the philosophy, the brand (logo, type, colour), communications, then the UI: its foundations + // first, the full chat screen leading its folder + storySort: { + order: [ + 'Introduction', + 'Agents', + ['Design guidelines', 'Brand guidelines'], + 'Philosophy', + ['Ideology', 'Product', 'Design'], + 'Architecture', + ['Stack', 'Chat', 'Channels'], + 'Brand', + [ + 'Logo', + ['Overview', 'Icon', 'Usage', 'Assets', ['Logo', 'Social profiles', 'App icons']], + 'Typography', + [ + 'Overview', + 'Tester', + 'Llama Sans', + ['User Interface', 'Running text', 'Display', 'Glyphs'], + 'Llama Mono', + ['Terminal', 'User Interface', 'Logs', 'Diff', 'llama.cpp logo', 'Key visuals'] + ], + 'Colors', + ['Palette'] + ], + 'Communications', + [ + 'Direction', + ['Principles', 'Mood board', 'Specimen boards'], + 'Foundations', + ['Formats and grid', 'Grounds', 'Type'], + 'Elements', + ['Header and footer', 'Chips and labels', 'Figures and commands', 'Motifs', 'The app'], + 'Modules', + ['Headline blocks', 'Model cards', 'Stat cards', 'Product shot'], + 'Key visuals', + ['Statement', 'Product', 'Roster', 'Bulletin', 'Numeral', 'Receipt'], + 'Applications', + [ + 'Model drop', + "What's new", + 'Link previews', + 'Open models poster', + 'Microsoft Store', + 'Mac App Store', + 'Store scenes', + 'Swag' + ] + ], + 'UI', + [ + 'Foundations', + ['Colors', 'Typography', 'Sizing', 'Shapes', 'Elevation', 'Surfaces', 'Brand'], + 'Actions', + 'Forms', + 'Display', + 'Overlays', + 'Navigation', + 'Patterns', + 'Blocks', + [ + 'Chat', + ['ChatScreen', ['ChatScreen', '*']], + 'Content', + 'Models', + 'MCP', + 'Navigation', + 'Settings', + ['DialogSettingsChat', 'Navigation', 'Sections'], + 'App' + ] + ], + 'Scrapbook', + ['About', 'UI', 'Communications', 'Brand'] + ] + } + }, + a11y: { // 'todo' - show a11y violations in the test UI only // 'error' - fail CI on a11y violations @@ -23,11 +109,50 @@ const preview: Preview = { test: 'todo' } }, + // read by tests/stories/pace.ts; the test runner always plays at full speed + globalTypes: { + interactionPace: { + description: 'Speed of the interactions a story plays', + toolbar: { + dynamicTitle: true, + icon: 'timer', + items: [ + { title: 'Human pace', value: 'human' }, + { title: 'Instant', value: 'instant' } + ], + title: 'Interaction pace' + } + }, + // the light surface theme: Paper (white panels on a grey page) or Matte (grey glass on white) + surface: { + description: 'Light surface theme', + toolbar: { + dynamicTitle: true, + icon: 'paintbrush', + items: [ + { title: 'Paper', value: 'paper' }, + { title: 'Matte', value: 'matte' } + ], + title: 'Surface' + } + } + }, + initialGlobals: { + interactionPace: 'human', + surface: 'paper' + }, decorators: [ - (story) => ({ + (story, context) => { + document.documentElement.classList.toggle('theme-matte', context.globals.surface === 'matte'); + + return story(); + }, + // `parameters.colorScheme` fixes a story to light or dark, whatever the viewer chose (a scene in a store screenshot) + (story, context) => ({ Component: ModeWatcherDecorator, props: { - children: story + children: story, + forced: context.parameters.colorScheme } }), (story) => ({ diff --git a/tools/ui/AGENTS.md b/tools/ui/AGENTS.md new file mode 100644 index 000000000000..5f559c22652d --- /dev/null +++ b/tools/ui/AGENTS.md @@ -0,0 +1,31 @@ +# Instructions for tools/ui + +These add to the repository's [AGENTS.md](../../AGENTS.md) for work in `tools/ui`: **Llama UI**, the design system and component library, and **Llama Chat**, the chat client built from it that llama-server bundles. + +- **Design:** [DESIGN.md](DESIGN.md) holds the tokens, roles and rules, written for agents. Follow it for anything visual; when it and the CSS disagree, the CSS wins and DESIGN.md is updated. +- **Why:** Storybook's **Philosophy** section explains the reasons, for people: **Ideology** ([Ideology.svx](tests/stories/philosophy/Ideology.svx)), **Product** ([Product.svx](tests/stories/philosophy/Product.svx)) and **Design** ([Design.svx](tests/stories/philosophy/Design.svx)). +- **Components:** the `SKILL.md` next to a component folder (such as [src/lib/components/app/SKILL.md](src/lib/components/app/SKILL.md)) holds that folder's conventions. + +## Designing: render the options in the Scrapbook + +Whenever a design is being worked out (UI, UX, communications or the brand), offer to render the proposed iterations or variations in Storybook rather than only describing them, so they can be compared on screen. + +- Put them in the **Scrapbook** section, beside Agents, Philosophy, Brand, Communications and UI: `Scrapbook/UI/`, `Scrapbook/Communications/` or `Scrapbook/Brand/`. +- One story per variation, named so they compare: `A · Compact`, `B · Spacious`. +- Build them from the real components, tokens, fonts and files, in both themes, and at a phone width where it matters. +- Once one is chosen, build it in its own section; the others stay in the Scrapbook as a record. [Scrapbook › About](tests/stories/scrapbook/About.svx) says the same for people. + +## Content is Markdown, custom pieces are Svelte: .svx + +Anything that is mostly content (a doc, an overview, a showcase or a Storybook page with prose) is written in Markdown, and whatever Markdown cannot express (a live example, a diagram, a real component) is a Svelte component placed in it. Together that is a `.svx` page, compiled by [mdsvex](https://mdsvex.pngwk.com). + +- Write the prose as plain Markdown, so it reads well as source, for people and for agents alike. +- Put each custom piece in its own `.svelte` file and import it in the page's ` +`; +} + +// the cover: the palette as blocks (ink, cinder, sand, the day sky, the night sky) and a dot grid at the unit, +// the name in Llama Sans +const COVER = ` +
+ +
+

Llama

+

Your AI, on your computer: the brand and communications of Llama and llama.cpp.

+
+
+ + +`; +const MIME = { + '.css': 'text/css', + '.html': 'text/html', + '.js': 'text/javascript', + '.json': 'application/json', + '.mjs': 'text/javascript', + '.png': 'image/png', + '.svg': 'image/svg+xml', + '.woff2': 'font/woff2' +}; + +function serve(dir) { + return new Promise((resolve) => { + const server = http.createServer((req, res) => { + const url = decodeURIComponent(new URL(req.url, 'http://x').pathname); + + let file = path.join(dir, url); + + if (!file.startsWith(dir)) return res.writeHead(403).end(); + + if (fs.existsSync(file) && fs.statSync(file).isDirectory()) + file = path.join(file, 'index.html'); + + if (!fs.existsSync(file)) return res.writeHead(404).end(); + + res.writeHead(200, { + 'content-type': MIME[path.extname(file)] ?? 'application/octet-stream' + }); + fs.createReadStream(file).pipe(res); + }); + + server.listen(0, '127.0.0.1', () => resolve(server)); + }); +} + +async function render(storybook) { + const { chromium } = await import('playwright'); + const server = await serve(storybook); + const base = `http://127.0.0.1:${server.address().port}`; + const browser = await chromium.launch(); + const page = await browser.newPage({ viewport: { height: 1200, width: 1600 } }); + const open = async (id, args = '') => { + await page.goto(`${base}/iframe.html?id=${id}&viewMode=story${args ? `&args=${args}` : ''}`); + await page.waitForSelector('.post'); + await page.evaluate(() => document.fonts.ready); + await page.waitForTimeout(400); + }; + // motifs: each SVG with its computed colours, fonts and strokes written into it, for light and dark grounds; + // the two drawn in CSS (quantised blocks, the dot grid) as images + const motifs = []; + + for (const tone of ['light', 'dark']) { + await open('communications-elements--motifs', `tone:${tone}`); + + const found = await page.evaluate(() => { + const PROPS = [ + 'fill', + 'fill-opacity', + 'stroke', + 'stroke-width', + 'stroke-opacity', + 'stroke-linecap', + 'stroke-linejoin', + 'stroke-dasharray', + 'opacity', + 'font-family', + 'font-size', + 'font-weight', + 'letter-spacing', + 'text-anchor', + 'dominant-baseline' + ]; + + return [...document.querySelectorAll('figure')].map((figure) => { + const label = figure.querySelector('figcaption span')?.textContent?.trim() ?? ''; + const svg = figure.querySelector('.post svg'); + + if (!svg) return { label, svg: null }; + + const clone = svg.cloneNode(true); + const from = [svg, ...svg.querySelectorAll('*')]; + const to = [clone, ...clone.querySelectorAll('*')]; + + from.forEach((el, i) => { + const cs = getComputedStyle(el); + const style = PROPS.map((p) => `${p}:${cs.getPropertyValue(p)}`).join(';'); + + to[i].removeAttribute('class'); + to[i].setAttribute('style', style); + }); + + clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); + clone.setAttribute('width', '800'); + clone.setAttribute('height', '600'); + clone.removeAttribute('aria-hidden'); + + return { label, svg: clone.outerHTML.replace(//g, '') }; + }); + }); + + for (const [i, m] of found.entries()) { + const name = `${slug(m.label)}-${tone}`; + + if (m.svg) { + write(`assets/Motifs/${name}.svg`, `\n${m.svg}\n`); + } else { + const tile = (await page.$$('figure'))[i]; + + await ( + await tile.$('.post') + ).screenshot({ path: path.join(PROJECT, `assets/Motifs/${name}.png`) }); + } + + motifs.push(name); + } + } + + // key visuals and the applications on them, each piece at its real size + await page.addInitScript(() => { + addEventListener('DOMContentLoaded', () => { + const style = document.createElement('style'); + + style.textContent = `.fit{height:auto!important;width:max-content!important;max-width:none!important;overflow:visible!important;box-shadow:none!important;border-radius:0!important} + .post{transform:none!important} + section{width:auto!important} + section > div{display:flex!important;flex-direction:column!important;align-items:flex-start!important}`; + document.head.append(style); + }); + }); + + // each piece is filed under the key visual its label names ("Roster, Square, light"), whichever story it is in + const examples = Object.fromEntries(KEY_VISUALS.map((k) => [k.name, []])); + const stories = [...new Set(KEY_VISUALS.flatMap((k) => k.stories))]; + + for (const id of stories) { + await open(id); + + const posts = await page.$$('.post'); + + console.log(`${id}: ${posts.length} pieces`); + + for (const post of posts) { + const label = await post.getAttribute('aria-label'); + const layout = label.split(',')[0].trim(); + + if (!examples[layout]) continue; + + const prefix = id.includes('applications') ? `${slug(id.split('--')[1])}-` : ''; + const name = `${prefix}${slug(label)}`; + const dir = path.join(PROJECT, `components/${layout}/examples`); + + let file = `${name}.png`; + + fs.mkdirSync(dir, { recursive: true }); + await post.screenshot({ path: path.join(dir, file) }); + + // anything over the system's 512 KB cap for a plain file goes as a JPEG + if (fs.statSync(path.join(dir, file)).size > 500_000) { + fs.rmSync(path.join(dir, file)); + file = `${name}.jpg`; + await post.screenshot({ path: path.join(dir, file), quality: 88, type: 'jpeg' }); + } + + examples[layout].push(file); + } + } + + await browser.close(); + server.close(); + + return { examples, motifs }; +} + +function index(uploads, title) { + const groups = ['Logos', 'Motifs']; + const assetGroups = {}; + + for (const group of groups) { + const files = {}; + const order = []; + + for (const [rel, blob] of Object.entries(uploads).sort()) { + if (!rel.startsWith(`assets/${group}/`)) continue; + + const name = rel.slice(`assets/${group}/`.length); + const file = path.join(PROJECT, rel); + const type = rel.endsWith('.svg') ? 'image/svg+xml' : 'image/png'; + + files[ + name.replace( + /[^A-Za-z0-9_./-]/g, + (c) => `~${c.charCodeAt(0).toString(16).padStart(2, '0')}` + ) + ] = { + blob: blob.replace(/^\/_blob\//, ''), + name, + size: fs.statSync(file).size, + type + }; + order.push(name); + } + + assetGroups[group] = { files, name: group, order, tile: group === 'Logos' ? 'm' : 'l' }; + } + + return { + assetGroups, + blobs: {}, + createdOnFiles: { at: new Date().toISOString(), v: 1 }, + docs: { readme: 'project/README.md', sections: [] }, + groups, + lastChange: { + at: new Date().toISOString(), + by: 'Claude', + note: 'Exported from the Storybook and BRAND.md', + via: 'Claude Code · ggml-org/llama.cpp tools/ui' + }, + layout: 'files', + libraries: [], + namespace: 'Llama', + sections: {}, + title, + v: 3 + }; +} + +if (args[0] === 'index') { + const uploads = JSON.parse( + fs.readFileSync(path.resolve(flag('uploads', 'uploads.json')), 'utf8') + ); + + // the previews show their example images from the uploads: a preview cannot load the system's plain files + for (const k of KEY_VISUALS) { + const file = path.join(PROJECT, `components/${k.name}/preview.html`); + const html = fs + .readFileSync(file, 'utf8') + .replace(/src="\.\.\/\.\.\/([^"]+)"/g, (m, rel) => + uploads[rel] ? `src="${uploads[rel]}"` : m + ); + + fs.writeFileSync(file, html); + } + + write( + 'design-system.json', + `${JSON.stringify(index(uploads, flag('title', 'Llama')), null, '\t')}\n` + ); + console.log(`wrote ${path.relative(ROOT, path.join(PROJECT, 'design-system.json'))}`); +} else { + const storybook = path.resolve(ROOT, flag('storybook', 'storybook-static')); + + if (!fs.existsSync(path.join(storybook, 'iframe.html'))) { + console.log('building Storybook…'); + execSync(`npx storybook build -o '${storybook}' --quiet`, { cwd: ROOT, stdio: 'inherit' }); + } + + fs.rmSync(OUT, { force: true, recursive: true }); + write('tokens.json', `${JSON.stringify(tokens(), null, '\t')}\n`); + + for (const font of ['LlamaSans.woff2', 'LlamaMono.woff2']) + write(`fonts/${font}`, fs.readFileSync(path.join(ROOT, 'src/lib/assets/fonts', font))); + + for (const [dir, file] of LOGO_FILES) + write(`assets/Logos/${file}`, fs.readFileSync(path.join(ROOT, LOGOS, dir, file))); + + for (const [source, file] of APP_ICONS) + write( + `assets/Logos/${file}`, + fs + .readFileSync(path.join(ROOT, LOGOS, source), 'utf8') + .replace( + 'width="1024" height="1024" viewBox="0 0 1024 1024"', + 'width="824" height="824" viewBox="100 100 824 824"' + ) + ); + + write( + 'assets/Logos/README.md', + '# Logos\n\nThe icon and the two lockups, as they are: `-light` is the ink mark for light grounds, `-dark` the light mark for dark grounds, `-bg` with its own ground. Llama goes on any ground; llama.cpp on light and dark only. Never redraw, recolour or outline them.\n\nThe app icon (`app-icon-light.svg`, `app-icon-dark.svg`) is for Llama as a thing in a piece, such as a node in a diagram: the tile as the app ships it, its corners at 22.5% of its side and the icon at 67% of it, optically centred. Use it at about 2.4u with at least 1u clear round it; never draw a square round the icon instead.\n' + ); + write( + 'assets/Motifs/README.md', + '# Motifs\n\nLine drawings for pieces, in the ground’s ink with one cinder detail: `-light` for light grounds (ink #111111), `-dark` for dark ones (ink #fafafa). Models and maths: decision tree, neural network, tensor, gradient descent, vector space. Charts and fields: curve, quantised blocks, dot grid. Machines, isometric or flat: GPU, laptop, small and large workstation, server. A motif fills its area; it is never the accent itself beyond its own cinder detail.\n' + ); + + const { examples } = await render(storybook); + const count = Object.values(examples).reduce((n, f) => n + f.length, 0); + + for (const k of KEY_VISUALS) { + write(`components/${k.name}/README.md`, componentReadme(k, examples[k.name])); + write(`components/${k.name}/preview.html`, componentPreview(k, examples[k.name])); + } + + write('components/Cover/preview.html', COVER); + // the previews need a bundle to run; the key visuals have no code of their own here, so it is empty + write( + 'components/bundle.js', + `/* @ds-bundle: {"format":4,"namespace":"Llama","components":[]} */\nwindow.Llama = {};\n` + ); + // the images the previews show, to upload as assets before the index step + write( + '../preview-images.json', + `${JSON.stringify( + KEY_VISUALS.flatMap((k) => + [...componentPreview(k, examples[k.name]).matchAll(/src="\.\.\/\.\.\/([^"]+)"/g)].map( + (m) => m[1] + ) + ), + null, + '\t' + )}\n` + ); + write('README.md', readme(count)); + + console.log( + `exported to ${path.relative(ROOT, OUT)}: ${count} examples, tokens, fonts, logos and motifs` + ); +} diff --git a/tools/ui/src/app.css b/tools/ui/src/app.css index c1634fca6302..02201d998dd5 100644 --- a/tools/ui/src/app.css +++ b/tools/ui/src/app.css @@ -1,8 +1,38 @@ @import 'tailwindcss'; @source '.'; +/* stories may use classes the app does not, so tailwind scans them too */ +@source '../tests/stories'; @plugin '@tailwindcss/forms'; @plugin '@tailwindcss/typography'; @import 'tw-animate-css'; +@import './lib/styles/tokens/primitives.css'; +@import './lib/styles/tokens/semantic.css'; +@import './lib/styles/tokens/components.css'; +@import './lib/styles/surfaces.css'; +@import './lib/styles/safe-area.css'; + +/* Llama Sans, the sans of the Llama type family (OFL, see lib/assets/fonts/OFL.txt): one variable font for every + weight from 400 to 700 and every optical size from 16 to 40. The browser sets the optical size from font-size + (font-optical-sizing: auto), so text up to 16px is spaced and kerned for interfaces, 40px and up tight for + headlines, with a blend in between. Its line box is centred on the cap height, so labels sit in the middle of + buttons and chips. */ +@font-face { + font-family: 'Llama Sans'; + src: url('./lib/assets/fonts/LlamaSans.woff2') format('woff2'); + font-weight: 400 700; + font-style: normal; + font-display: swap; +} + +/* Llama Mono, the family's monospace (OFL, same file), for code, commands and numbers in columns: every character in + one 600-unit cell, its coding ligatures included, from 400 to 700. */ +@font-face { + font-family: 'Llama Mono'; + src: url('./lib/assets/fonts/LlamaMono.woff2') format('woff2'); + font-weight: 400 700; + font-style: normal; + font-display: swap; +} @custom-variant dark (&:is(.dark *)); @@ -35,50 +65,82 @@ :root { --radius: 0.625rem; + /* the page runs under the status bar and over the home indicator + (viewport-fit=cover); what is pinned to a screen edge keeps clear of them + with the pt-safe / pb-safe utilities (see lib/styles/safe-area.css) */ + --safe-area-top: env(safe-area-inset-top, 0px); + --safe-area-bottom: env(safe-area-inset-bottom, 0px); + /* where the phone's corner controls (menu toggle, context gauge, sidebar logo) sit */ + --corner-control-top: calc(1rem + var(--safe-area-top)); + /* where a phone page's title starts: a row below the corner controls */ + --page-top: calc(var(--corner-control-top) + 3.75rem); /* expanded desktop sidebar width, overridden once the user drags its edge */ --sidebar-width: 18rem; - --background: oklch(1 0 0); - --foreground: oklch(0.145 0 0); - --card: oklch(1 0 0); - --card-foreground: oklch(0.145 0 0); - --popover: oklch(1 0 0); - --popover-foreground: oklch(0.145 0 0); - --primary: oklch(0.205 0 0); - --primary-foreground: oklch(0.985 0 0); - --secondary: oklch(0.95 0 0); - --secondary-foreground: oklch(0.205 0 0); - --muted: oklch(0.97 0 0); - --muted-foreground: oklch(0.556 0 0); - --accent: oklch(0.95 0 0); - --accent-foreground: oklch(0.205 0 0); - --destructive: oklch(0.577 0.245 27.325); - --border: oklch(0.875 0 0); - --input: oklch(0.92 0 0); - --ring: oklch(0.708 0 0); - --chart-1: oklch(0.646 0.222 41.116); - --chart-2: oklch(0.6 0.118 184.704); - --chart-3: oklch(0.398 0.07 227.392); - --chart-4: oklch(0.828 0.189 84.429); - --chart-5: oklch(0.769 0.188 70.08); - --sidebar: oklch(0.985 0 0); - --sidebar-foreground: oklch(0.145 0 0); - --sidebar-primary: oklch(0.205 0 0); - --sidebar-primary-foreground: oklch(0.985 0 0); - --sidebar-accent: oklch(0.97 0 0); - --sidebar-accent-foreground: oklch(0.205 0 0); - --sidebar-border: oklch(0.922 0 0); - --sidebar-ring: oklch(0.708 0 0); - --code-background: oklch(0.985 0 0); - --code-foreground: oklch(0.145 0 0); + /* phone sidebar width, which the page slides aside to reveal */ + --sidebar-reveal: min(80dvw, 20rem); + /* the desktop sidebar's muted/60 over the page, made opaque so the slid page's corners can match it */ + --sidebar-reveal-tint: color-mix(in oklab, var(--muted) 60%, var(--background)); + /* how far the phone sidebar is open, 0 to 1, stepped every frame by useSidebarReveal */ + --sidebar-reveal-progress: 0; + /* the same on a log curve: the sidebar's contents hold on until the page nearly covers them */ + --sidebar-reveal-ease: calc(log(1 + 9 * var(--sidebar-reveal-progress)) / log(10)); + /* the page background, blending into the sidebar tint as the phone sidebar opens */ + --sidebar-reveal-bg: color-mix( + in oklab, + var(--sidebar-reveal-tint) calc(var(--sidebar-reveal-progress) * 100%), + var(--background) + ); --font-mono: - ui-monospace, SFMono-Regular, 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, - 'Liberation Mono', Menlo, monospace; + 'Llama Mono', ui-monospace, SFMono-Regular, 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', + Consolas, 'Liberation Mono', Menlo, monospace; --layer-popover: 1000000; --chat-form-area-height: 8rem; --chat-form-area-offset: 2rem; --chat-form-padding-top: 6rem; + /* the chat form card holding one line of text, as it rests on a new chat */ + --chat-form-collapsed-height: 6.375rem; --max-message-height: max(24rem, min(80dvh, calc(100dvh - var(--chat-form-area-height) - 12rem))); + + /* + * shadcn names, kept so the vendored components and their classes keep working. + * They alias semantic tokens; new code uses the semantic names directly. + */ + --background: var(--surface-page); + --foreground: var(--fg-default); + --card: var(--surface-raised); + --card-foreground: var(--fg-default); + --popover: var(--surface-raised); + --popover-foreground: var(--fg-default); + --primary: var(--action-primary); + --primary-foreground: var(--fg-on-action); + --secondary: var(--surface-emphasis); + --secondary-foreground: var(--fg-default); + --muted: var(--surface-muted); + --muted-foreground: var(--fg-muted); + --accent: var(--surface-selected); + --accent-foreground: var(--fg-default); + --destructive: var(--fg-danger); + --border: var(--line-default); + --input: var(--line-field); + --ring: var(--line-focus); + --code-background: var(--surface-code); + --code-foreground: var(--fg-code); +} + +/* iOS 26 gives an installed app with viewport-fit=cover and a translucent status bar a + viewport short of that bar (WebKit bug 301108), but only while the page is shorter than + the screen. A page that reaches past it gets the full screen, after which this is 100%, + capped at the screen so it never scrolls; elsewhere the inset is 0 and it is 100% too. */ +@media (display-mode: standalone) { + /* the installed app's status bar already sets them apart from the screen's edge */ + :root { + --corner-control-top: calc(0.25rem + var(--safe-area-top)); + } + + html { + min-height: min(100lvh, calc(100% + var(--safe-area-top))); + } } @media (min-width: 640px) { @@ -89,43 +151,10 @@ } } -.dark { - --background: oklch(0.16 0 0); - --foreground: oklch(0.985 0 0); - --card: oklch(0.205 0 0); - --card-foreground: oklch(0.985 0 0); - --popover: oklch(0.205 0 0); - --popover-foreground: oklch(0.985 0 0); - --primary: oklch(0.922 0 0); - --primary-foreground: oklch(0.205 0 0); - --secondary: oklch(0.29 0 0); - --secondary-foreground: oklch(0.985 0 0); - --muted: oklch(0.269 0 0); - --muted-foreground: oklch(0.708 0 0); - --accent: oklch(0.269 0 0); - --accent-foreground: oklch(0.985 0 0); - --destructive: oklch(0.704 0.191 22.216); - --border: oklch(1 0 0 / 30%); - --input: oklch(1 0 0 / 30%); - --ring: oklch(0.556 0 0); - --chart-1: oklch(0.488 0.243 264.376); - --chart-2: oklch(0.696 0.17 162.48); - --chart-3: oklch(0.769 0.188 70.08); - --chart-4: oklch(0.627 0.265 303.9); - --chart-5: oklch(0.645 0.246 16.439); - --sidebar: oklch(0.2 0 0); - --sidebar-foreground: oklch(0.985 0 0); - --sidebar-primary: oklch(0.488 0.243 264.376); - --sidebar-primary-foreground: oklch(0.985 0 0); - --sidebar-accent: oklch(0.269 0 0); - --sidebar-accent-foreground: oklch(0.985 0 0); - --sidebar-border: oklch(1 0 0 / 10%); - --sidebar-ring: oklch(0.556 0 0); - --code-background: oklch(0.225 0 0); - --code-foreground: oklch(0.875 0 0); -} - @theme inline { + /* the sans everywhere, headings included (their size sets the optical size): Llama Sans, then the system stack + while it loads or if it can't */ + --font-sans: 'Llama Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif; --radius-sm: calc(var(--radius) - 4px); --radius-md: calc(var(--radius) - 2px); --radius-lg: var(--radius); @@ -148,19 +177,6 @@ --color-border: var(--border); --color-input: var(--input); --color-ring: var(--ring); - --color-chart-1: var(--chart-1); - --color-chart-2: var(--chart-2); - --color-chart-3: var(--chart-3); - --color-chart-4: var(--chart-4); - --color-chart-5: var(--chart-5); - --color-sidebar: var(--sidebar); - --color-sidebar-foreground: var(--sidebar-foreground); - --color-sidebar-primary: var(--sidebar-primary); - --color-sidebar-primary-foreground: var(--sidebar-primary-foreground); - --color-sidebar-accent: var(--sidebar-accent); - --color-sidebar-accent-foreground: var(--sidebar-accent-foreground); - --color-sidebar-border: var(--sidebar-border); - --color-sidebar-ring: var(--sidebar-ring); } @layer base { @@ -169,11 +185,27 @@ } body { - @apply bg-background text-foreground antialiased; + @apply bg-(--sidebar-reveal-bg) text-foreground antialiased; scrollbar-width: thin; scrollbar-gutter: stable; } + /* While the chat form is a full-screen sheet on a phone, the page around it takes + the sheet's fill (the translucent card over the page, made solid): iOS paints + the installed app's status bar and home indicator areas, and Safari tints its + bars, from this background, so the sheet reaches the screen's edges */ + @media (width < 48rem) { + html[data-chat-form-sheet], + html[data-chat-form-sheet] body { + background-color: color-mix(in oklab, var(--muted) 60%, var(--background)); + } + + html.dark[data-chat-form-sheet], + html.dark[data-chat-form-sheet] body { + background-color: color-mix(in oklab, var(--muted) 75%, var(--background)); + } + } + /* no elastic bounce past the ends of the page: it drags the sticky and fixed bars (tab bar, chat form) along and they jump back on release */ html, @@ -181,6 +213,30 @@ overscroll-behavior: none; } + /* no gray flash over a tapped control, which has its own press state, and + no text inflation when a phone turns to landscape */ + html { + -webkit-tap-highlight-color: transparent; + -webkit-text-size-adjust: 100%; + text-size-adjust: 100%; + } + + /* a tap clicks at once rather than waiting to see if it is a double-tap zoom */ + button, + a, + [role='button'] { + touch-action: manipulation; + } + + /* holding a control does not select its label or pop the link callout; + links stay selectable, as in a message they are content */ + button, + [role='button'] { + -webkit-touch-callout: none; + -webkit-user-select: none; + user-select: none; + } + /* same for dialogs, whose panels and lists scroll on their own with sticky headers and footers. Scroll containers only: Firefox treats an overflow-hidden box (truncated text) as one, and with `none` it would @@ -198,7 +254,7 @@ } *:hover { - scrollbar-color: hsl(var(--muted-foreground) / 0.3) transparent; + scrollbar-color: color-mix(in oklch, var(--fg-muted) 30%, transparent) transparent; } *::-webkit-scrollbar { @@ -217,11 +273,11 @@ } *:hover::-webkit-scrollbar-thumb { - background: hsl(var(--muted-foreground) / 0.3); + background: color-mix(in oklch, var(--fg-muted) 30%, transparent); } *::-webkit-scrollbar-thumb:hover { - background: hsl(var(--muted-foreground) / 0.5); + background: color-mix(in oklch, var(--fg-muted) 50%, transparent); } :where(code, pre, kbd, samp) { @@ -251,6 +307,54 @@ ); } + /* The same fade at the top of a phone's screen: solid behind the status bar and the row of + corner controls under it (the menu key, the chat's header), fading out below them, so the + page scrolls away under them instead of into them. It rides on the page as it slides aside + for the sidebar and stays as it is: the rounded frame over the slid page clips it. */ + .status-bar-fade { + /* down to where a page's content starts (--page-top): solid to the middle of the corner + row, then a long, even fade over its lower half and on to the content */ + height: var(--page-top); + background: linear-gradient( + to bottom, + var(--background) calc(var(--corner-control-top) + 1.25rem), + color-mix(in srgb, var(--background) 55%, transparent) + calc(var(--corner-control-top) + 2.5rem), + transparent 100% + ); + } + + /* iOS Safari colours the screen's top, above the page, from a solid fixed element at the + page's top edge (theme-color no longer), and shows the page through it otherwise. The + fade above is a gradient, which it does not take, so this strip under it carries the + page's colour there, as the installed app has. Safari finds it by hit-testing the top + edge, so it takes taps (pointer-events: none would hide it) and is thicker than the + 10px Safari ignores; what it covers sits under the fade's solid part anyway */ + .status-bar-edge { + height: 0.75rem; + background-color: var(--background); + } + + /* The bottom edge's counterpart, which Safari takes for its bottom toolbar the same way: + without it, it finds the chat form there and takes the form's colour */ + .screen-bottom-edge { + height: 0.75rem; + background-color: var(--background); + } + + /* The same fade at the bottom of a phone's screen: solid behind the home indicator and + fading out above it, so the page ends softly at the screen's edge and under the chat + form instead of running out under it. It stays through the slide as the top one does */ + .screen-bottom-fade { + height: calc(var(--safe-area-bottom) + 3rem); + background: linear-gradient( + to top, + var(--background) var(--safe-area-bottom), + color-mix(in srgb, var(--background) 60%, transparent) calc(var(--safe-area-bottom) + 1.5rem), + transparent 100% + ); + } + /* The sidebar's "Show more" row, stuck to its bottom: an opaque copy of the panel's translucent muted tint, and a fade above it, like the one under the tab bar, so the rows scrolling beneath end softly */ @@ -301,6 +405,27 @@ pointer-events: none; } + /* the phone sidebar's contents zoom out and fade as the page slides back over them */ + .sidebar-reveal-content { + opacity: var(--sidebar-reveal-ease); + scale: calc(0.98 + 0.02 * var(--sidebar-reveal-ease)); + } + + /* the slid page's fixed bars, held where they sit on screen, see useSidebarReveal */ + .sidebar-reveal-pin-top { + translate: 0 var(--sidebar-reveal-pin-top, 0px); + } + + .sidebar-reveal-pin-bottom { + translate: 0 calc(-1 * var(--sidebar-reveal-pin-bottom, 0px)); + } + + @media (prefers-reduced-motion: reduce) { + .sidebar-reveal-content { + scale: none; + } + } + .shimmer-text { background: linear-gradient( 90deg, diff --git a/tools/ui/src/app.html b/tools/ui/src/app.html index ef2787ad1bb4..65a9d92886e9 100644 --- a/tools/ui/src/app.html +++ b/tools/ui/src/app.html @@ -12,7 +12,7 @@ %sveltekit.head% diff --git a/tools/ui/src/lib/assets/fonts/LlamaMono.woff2 b/tools/ui/src/lib/assets/fonts/LlamaMono.woff2 new file mode 100644 index 000000000000..eba0ca6ccb3e Binary files /dev/null and b/tools/ui/src/lib/assets/fonts/LlamaMono.woff2 differ diff --git a/tools/ui/src/lib/assets/fonts/LlamaSans.woff2 b/tools/ui/src/lib/assets/fonts/LlamaSans.woff2 new file mode 100644 index 000000000000..27ee2943b684 Binary files /dev/null and b/tools/ui/src/lib/assets/fonts/LlamaSans.woff2 differ diff --git a/tools/ui/src/lib/assets/fonts/OFL.txt b/tools/ui/src/lib/assets/fonts/OFL.txt new file mode 100644 index 000000000000..04e95fc55085 --- /dev/null +++ b/tools/ui/src/lib/assets/fonts/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2024 The Geist Project Authors (https://github.com/vercel/geist-font) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. \ No newline at end of file diff --git a/tools/ui/src/lib/assets/logo.svg b/tools/ui/src/lib/assets/logo.svg index 05424790afea..b31b5181173c 100644 --- a/tools/ui/src/lib/assets/logo.svg +++ b/tools/ui/src/lib/assets/logo.svg @@ -1,7 +1,4 @@ - - - - - - + + + diff --git a/tools/ui/src/lib/components/app/actions/ActionIcon.svelte b/tools/ui/src/lib/components/app/actions/ActionIcon.svelte index 3116fc530d52..f2bcb59f7fb7 100644 --- a/tools/ui/src/lib/components/app/actions/ActionIcon.svelte +++ b/tools/ui/src/lib/components/app/actions/ActionIcon.svelte @@ -26,7 +26,7 @@ disabled = false, href = '', icon, - iconSize = 'h-3 w-3', + iconSize = 'size-icon-md', onclick, size = 'sm', stopPropagationOnClick = false, @@ -44,7 +44,7 @@

{label}

+ + +{:else} + {@render key()} +{/if} diff --git a/tools/ui/src/lib/components/app/actions/index.ts b/tools/ui/src/lib/components/app/actions/index.ts index 4bb2a58d6672..73ab769135b9 100644 --- a/tools/ui/src/lib/components/app/actions/index.ts +++ b/tools/ui/src/lib/components/app/actions/index.ts @@ -11,3 +11,6 @@ export { default as ActionIcon } from './ActionIcon.svelte'; /** Copy-to-clipboard icon button with clipboard logic. */ export { default as ActionIconCopyToClipboard } from './ActionIconCopyToClipboard.svelte'; + +/** A round matte glass key: a phone's corner keys and the key back to a chat's bottom. */ +export { default as GlassKey } from './GlassKey.svelte'; diff --git a/tools/ui/src/lib/components/app/badges/BadgesModality.svelte b/tools/ui/src/lib/components/app/badges/BadgesModality.svelte index 83b1b46affc6..85cfaa42ded3 100644 --- a/tools/ui/src/lib/components/app/badges/BadgesModality.svelte +++ b/tools/ui/src/lib/components/app/badges/BadgesModality.svelte @@ -22,7 +22,7 @@ className ]} > - + {MODALITY_LABELS[modality]} diff --git a/tools/ui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentsList/ChatAttachmentsListItem/ChatAttachmentsListItemMcpResource.svelte b/tools/ui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentsList/ChatAttachmentsListItem/ChatAttachmentsListItemMcpResource.svelte index 80ef25bbcbe9..2c2021bc2a62 100644 --- a/tools/ui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentsList/ChatAttachmentsListItem/ChatAttachmentsListItemMcpResource.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentsList/ChatAttachmentsListItem/ChatAttachmentsListItemMcpResource.svelte @@ -23,7 +23,7 @@ const favicon = $derived(mcpStore.getServerFavicon(attachment.resource.serverName)); function getStatusClass(attachment: MCPResourceAttachment): string { - if (attachment.error) return 'border-red-500/50 bg-red-500/10'; + if (attachment.error) return 'border-line-danger-soft bg-surface-danger'; if (attachment.loading) return 'border-border/50 bg-muted/30'; @@ -45,11 +45,11 @@ type="button" > {#if attachment.loading} - + {:else if attachment.error} - + {:else} - + {/if} @@ -60,7 +60,7 @@ onRemove?.(attachment.id)} stopPropagationOnClick tooltip="Remove" @@ -74,7 +74,7 @@ {#if favicon} {attachment.resource.serverName} { (e.currentTarget as HTMLImageElement).style.display = 'none'; }} diff --git a/tools/ui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentsList/ChatAttachmentsListItem/ChatAttachmentsListItemThumbnailFile.svelte b/tools/ui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentsList/ChatAttachmentsListItem/ChatAttachmentsListItemThumbnailFile.svelte index 409a3a0f4a35..00050b2377bd 100644 --- a/tools/ui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentsList/ChatAttachmentsListItem/ChatAttachmentsListItemThumbnailFile.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentsList/ChatAttachmentsListItem/ChatAttachmentsListItemThumbnailFile.svelte @@ -107,7 +107,7 @@ {#snippet fileIcon()}
{#if isAudio} @@ -129,7 +129,7 @@ diff --git a/tools/ui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentsPreview/ChatAttachmentsPreviewThumbnailStrip.svelte b/tools/ui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentsPreview/ChatAttachmentsPreviewThumbnailStrip.svelte index e4ecd2357366..c48052da96ff 100644 --- a/tools/ui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentsPreview/ChatAttachmentsPreviewThumbnailStrip.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentsPreview/ChatAttachmentsPreviewThumbnailStrip.svelte @@ -48,10 +48,10 @@ onclick={() => onNavigate(index)} > {#if (item.isImage || item.isPdf) && item.preview} - {item.name} + {item.name} {:else}
{#if item.isAudio} diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatForm.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatForm.svelte index 639577134f7c..5235d7742ded 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatForm.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatForm.svelte @@ -1,5 +1,6 @@ @@ -158,7 +125,8 @@ {/if}
- {#if hasProcessedTokens} + + {#if showContextGauge.current && !deviceStore.isMobile} {/if} @@ -176,7 +144,7 @@ {#if isReasoning && !canSend} {:else if shouldShowRecordButton} diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ChatFormContextGauge.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ChatFormContextGauge.svelte index cb3d07e11a8b..4eb3be329dc1 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ChatFormContextGauge.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ChatFormContextGauge.svelte @@ -7,10 +7,20 @@ gaugeTriggerLeave, gaugeTriggerPointerDown } from './gauge-popup.svelte'; + import GlassKey from '$lib/components/app/actions/GlassKey.svelte'; import { useContextGauge } from '$lib/hooks/use-context-gauge.svelte'; import { chatStore, conversationsStore, deviceStore } from '$lib/stores'; import { untrack } from 'svelte'; + interface Props { + /** Sizes and places the trigger, the inline dial size by default. */ + class?: string; + /** Draws the dial as the icon of a phone's corner key, matching the menu key's glyph. */ + corner?: boolean; + } + + let { class: className = 'h-5 w-5 max-md:h-6 max-md:w-6', corner = false }: Props = $props(); + const gauge = useContextGauge(); $effect(() => { @@ -41,22 +51,38 @@ }); -
- - -
+{#snippet dial(size: 'sm' | 'md' | 'key')} + +{/snippet} + +{#if corner} + + + {@render dial('key')} + +{:else} +
+ + {@render dial(deviceStore.isMobile ? 'md' : 'sm')} +
+{/if} diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugeDial.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugeDial.svelte index ca520862d459..b75af9d07850 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugeDial.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugeDial.svelte @@ -1,44 +1,54 @@ - + diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugeLoadModel.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugeLoadModel.svelte index 4edc72773fbb..31bbcab6d35b 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugeLoadModel.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugeLoadModel.svelte @@ -15,11 +15,11 @@
Available context size is only visible once the model is loaded. - +
{:else if isLoading}
- + Loading model...
diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugePopup.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugePopup.svelte index 8a2cb3c008a3..c36e2b6d0126 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugePopup.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugePopup.svelte @@ -90,13 +90,13 @@ disabled={isCompactDisabled} onclick={handleCompact} size="sm" - variant="tertiary" + variant="secondary" > {#if isCompacting} - + Compacting... {:else} - + Compact conversation {/if} @@ -172,7 +172,7 @@ {:else if gaugePopup.open}
0) return true; + + if (!liveState) return false; + + const livePromptTokens = Math.max( + liveState.promptTokens ?? 0, + liveState.promptProgress?.processed ?? 0 + ); + const liveOutputTokens = liveState.outputTokensUsed ?? 0; + + return livePromptTokens > 0 || liveOutputTokens > 0; +} diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormCurrentWorkingDirectory/ChatFormCurrentWorkingDirectory.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormCurrentWorkingDirectory/ChatFormCurrentWorkingDirectory.svelte index c6b8b3b0c5ec..049370664944 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormCurrentWorkingDirectory/ChatFormCurrentWorkingDirectory.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormCurrentWorkingDirectory/ChatFormCurrentWorkingDirectory.svelte @@ -3,6 +3,7 @@ import ChatFormCurrentWorkingDirectoryResultsList from './ChatFormCurrentWorkingDirectoryResultsList.svelte'; import { FolderOpen } from '@lucide/svelte'; import SearchInput from '$lib/components/app/forms/SearchInput.svelte'; + import * as Drawer from '$lib/components/ui/drawer'; import * as Popover from '$lib/components/ui/popover'; import { DEFAULT_MOBILE_BREAKPOINT, HOME_TILDE, SEARCH, UI_DATA_ATTRS } from '$lib/constants'; import { BuiltInTool, GlobSearchType, KeyboardKey, ToolSource } from '$lib/enums'; @@ -10,7 +11,7 @@ import { usePickerNavigation } from '$lib/hooks/use-picker-navigation.svelte'; import { useScrollActiveRow } from '$lib/hooks/use-scroll-active-row.svelte'; import { ToolsService } from '$lib/services/tools.service'; - import { conversationsStore, toolsStore } from '$lib/stores'; + import { conversationsStore, deviceStore, toolsStore } from '$lib/stores'; import { abbreviateHome, runGlobSearchWithChildren } from '$lib/utils'; // Microtask delay so the popover's focus scope tears down first. @@ -32,6 +33,8 @@ onClose?: () => void; /** Fired when the chip is clicked so the host can open the picker. */ onOpen?: () => void; + /** Renders the chip trigger; off when the host anchors its own trigger. */ + showChip?: boolean; } let { @@ -43,7 +46,8 @@ onChange, onClose, onOpen, - query = $bindable('') + query = $bindable(''), + showChip = true }: Props = $props(); // File System Access API is opt-in (Chrome / Edge / Opera): the popover @@ -297,93 +301,118 @@ const showTooltip = $derived(innerWidth > DEFAULT_MOBILE_BREAKPOINT); - - - - - - event.preventDefault()} - onOpenAutoFocus={(event) => event.preventDefault()} - onkeydown={handleKeydown} - preventScroll={false} - side="top" - sideOffset={12} - > -
- + +{/if} + +{#snippet picker()} +
+ + + {#if !fileSearchEnabled} +
{searchUnavailableMessage}
+ {:else if query.trim() && (search.isSearching || queryResults.length > 0 || searchError)} + nav.setHover(index)} + rawQuery={query} + results={queryResults} /> + {/if} + + {#if pickerSupported && fileSearchEnabled} + + {/if} - {#if !fileSearchEnabled} -
{searchUnavailableMessage}
- {:else if query.trim() && (search.isSearching || queryResults.length > 0 || searchError)} - nav.setHover(index)} - rawQuery={query} - results={queryResults} - /> - {/if} - - {#if pickerSupported && fileSearchEnabled} -
+ + + Searching in: + + {abbreviateHome(searchScope, homeBase)} + + {/if} +
+{/snippet} + + +{#if deviceStore.isMobile} + + + + Working directory + + Choose the directory the chat works in - - - Browse - - {/if} - - {#if homeBase && fileSearchEnabled} - - - - Searching in: - - {abbreviateHome(searchScope, homeBase)} - - {/if} -
- - + + +
+ {@render picker()} +
+ + +{:else} + + + + event.preventDefault()} + onOpenAutoFocus={(event) => event.preventDefault()} + onkeydown={handleKeydown} + preventScroll={false} + side="top" + sideOffset={12} + > + {@render picker()} + + +{/if} diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormCurrentWorkingDirectory/ChatFormCurrentWorkingDirectoryChip.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormCurrentWorkingDirectory/ChatFormCurrentWorkingDirectoryChip.svelte index 5a7b054cec7c..fae93489c4ff 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormCurrentWorkingDirectory/ChatFormCurrentWorkingDirectoryChip.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormCurrentWorkingDirectory/ChatFormCurrentWorkingDirectoryChip.svelte @@ -33,7 +33,7 @@ class="text-muted-foreground inline-flex items-center gap-1 text-xs group" >
- + {#if showTooltip && displayLabelTitle} @@ -58,10 +58,10 @@ > - import ChatFormInputBasic from './ChatFormInputBasic.svelte'; - import ChatFormInputRich from './ChatFormInputRich.svelte'; + import { fileMentionWidgets } from './mention-badge-widget'; + import { EditorView } from '@codemirror/view'; + import { MarkdownEditor } from '$lib/components/app'; + import { deviceStore } from '$lib/stores'; + import { onMount } from 'svelte'; + import type { ClassValue } from 'svelte/elements'; interface Props { - class?: string; + class?: ClassValue; disabled?: boolean; + /** Fill the expanded chat form: the editor takes all its height and scrolls inside. */ + expanded?: boolean; onInput?: () => void; onKeydown?: (event: KeyboardEvent) => void; onPaste?: (event: ClipboardEvent) => void; placeholder?: string; value?: string; - useRichInput?: boolean; } let { class: className = '', disabled = false, + expanded = false, onInput, onKeydown, onPaste, placeholder = 'Ask anything...', - useRichInput = false, value = $bindable('') }: Props = $props(); - let basicRef: ChatFormInputBasic | undefined = $state(); - let richRef: ChatFormInputRich | undefined = $state(); + let editor: MarkdownEditor | undefined = $state(); - // The two renderers share one imperative handle (focus/caret/height), so - // the parent can drive whichever variant is mounted through this one. - export function getElement() { - return useRichInput ? richRef?.getElement() : basicRef?.getElement(); + // CSS can not transition a height that follows its content (an `auto` height never + // changes value), so the editor's content height is mirrored onto this wrapper as a + // length the stylesheet transitions: the form grows and shrinks smoothly as lines + // come and go, and scrolls inside once it reaches its maximum + let contentHeight = $state(null); + + $effect(() => { + const content = editor?.getView()?.contentDOM; + + if (!content) return; + + const observer = new ResizeObserver(() => (contentHeight = content.offsetHeight)); + + observer.observe(content); + + return () => observer.disconnect(); + }); + + // The form gets the keys and pastes first: whatever it handles (submit, pickers, + // pasted files) never reaches the editor + const extensions = [ + EditorView.domEventHandlers({ + keydown: (event) => { + onKeydown?.(event); + + return event.defaultPrevented; + }, + paste: (event) => { + onPaste?.(event); + + return event.defaultPrevented; + } + }) + ]; + + function handleChange(next: string) { + value = next; + onInput?.(); } - export function focus() { - if (useRichInput) richRef?.focus(); - else basicRef?.focus(); + // The expanded editor is taller than its text: a click on the empty room below it + // continues writing at the end, as in a textarea + function handleMouseDown(event: MouseEvent) { + if (!expanded || (event.target as HTMLElement).closest('.cm-content')) return; + + event.preventDefault(); + editor?.focusAt(); } - export function resetHeight() { - if (useRichInput) richRef?.resetHeight(); - else basicRef?.resetHeight(); + onMount(() => { + if (!deviceStore.isMobile) editor?.focus(); + }); + + export function focus() { + if (deviceStore.isMobile) return; + + editor?.focus(); } + /** Cursor offset in the markdown source. */ export function getCaretOffset(): number { - return useRichInput ? (richRef?.getCaretOffset() ?? 0) : (basicRef?.getCaretOffset() ?? 0); + return editor?.getCaretOffset() ?? 0; } export function setCaretOffset(offset: number) { - if (useRichInput) richRef?.setCaretOffset(offset); - else basicRef?.setCaretOffset(offset); + editor?.focusAt(offset); } -{#if useRichInput} - + -{:else} - -{/if} +
+ + diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormInput/ChatFormInputBasic.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormInput/ChatFormInputBasic.svelte deleted file mode 100644 index 0cd4516d87c3..000000000000 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormInput/ChatFormInputBasic.svelte +++ /dev/null @@ -1,82 +0,0 @@ - - -
- -
diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormInput/ChatFormInputRich.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormInput/ChatFormInputRich.svelte deleted file mode 100644 index 70251ea0cbcc..000000000000 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormInput/ChatFormInputRich.svelte +++ /dev/null @@ -1,867 +0,0 @@ - - -
-
-
- - diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormInput/mention-badge-widget.ts b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormInput/mention-badge-widget.ts new file mode 100644 index 000000000000..fa814903e680 --- /dev/null +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormInput/mention-badge-widget.ts @@ -0,0 +1,92 @@ +// File mention badges for the chat form input: in the block being edited, each +// `[name](file://path)` link shows as the same chip the rendered markdown draws. +// The link stays in the source untouched; the badge is an atomic stand-in for it. + +import { type Range } from '@codemirror/state'; +import { Decoration, WidgetType } from '@codemirror/view'; +import { SETTINGS_KEYS } from '$lib/constants'; +import { settingsStore } from '$lib/stores/settings/index.svelte'; +import { toolsStore } from '$lib/stores/tools.svelte'; +import { + decodeFileLinkPath, + fileMentionLinkRe, + getMentionBadgeIconPaths, + getMentionBadgeLabel, + MENTION_BADGE_CLASSNAME, + MENTION_BADGE_ICON_CLASSNAME, + MENTION_BADGE_SVG_ATTRIBUTES +} from '$lib/utils'; + +// Inline code is literal: a mention link inside backticks stays text +const CODE_OR_MENTION_RE = new RegExp( + String.raw`(\`\`\`[\s\S]*?\`\`\`|\`[^\`\n]+\`)|${fileMentionLinkRe().source}`, + 'g' +); + +class MentionBadgeWidget extends WidgetType { + constructor( + readonly name: string, + readonly path: string + ) { + super(); + } + + eq(other: MentionBadgeWidget) { + return other.name === this.name && other.path === this.path; + } + + toDOM() { + const badge = document.createElement('span'); + const decodedPath = decodeFileLinkPath(this.path); + + badge.title = decodedPath; + badge.className = `${MENTION_BADGE_CLASSNAME} align-middle`; + + const svg = document.createElementNS(MENTION_BADGE_SVG_ATTRIBUTES['xmlns'], 'svg'); + + for (const [attr, value] of Object.entries(MENTION_BADGE_SVG_ATTRIBUTES)) { + svg.setAttribute(attr, value); + } + + for (const cls of MENTION_BADGE_ICON_CLASSNAME.split(/\s+/).filter(Boolean)) { + svg.classList.add(cls); + } + + for (const d of getMentionBadgeIconPaths(this.path)) { + const path = document.createElementNS(MENTION_BADGE_SVG_ATTRIBUTES['xmlns'], 'path'); + + path.setAttribute('d', d); + svg.appendChild(path); + } + + const label = document.createElement('span'); + + label.classList.add('shrink-0', 'truncate'); + label.textContent = getMentionBadgeLabel( + this.name, + decodedPath, + settingsStore.getConfig(SETTINGS_KEYS.SHOW_FULL_PATH_IN_MENTIONS), + toolsStore.serverHome + ); + + badge.append(svg, label); + + return badge; + } +} + +/** Badge widgets for the mention links in `source`, which starts at document offset `from`. */ +export function fileMentionWidgets(source: string, from: number): Range[] { + const widgets: Range[] = []; + + for (const match of source.matchAll(CODE_OR_MENTION_RE)) { + if (match[1] !== undefined) continue; + + const start = from + match.index; + const widget = new MentionBadgeWidget(match[2], match[3]); + + widgets.push(Decoration.replace({ widget }).range(start, start + match[0].length)); + } + + return widgets; +} diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPicker/ChatFormPickerItemHeader.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPicker/ChatFormPickerItemHeader.svelte index 67e2790df7e9..9d9a83c3f7f6 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPicker/ChatFormPickerItemHeader.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPicker/ChatFormPickerItemHeader.svelte @@ -22,7 +22,7 @@ {#if faviconUrl} { (e.currentTarget as HTMLImageElement).style.display = 'none'; }} diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPicker/ChatFormPickerListItemSkeleton.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPicker/ChatFormPickerListItemSkeleton.svelte index 36910eda42cc..aee380f14f63 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPicker/ChatFormPickerListItemSkeleton.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPicker/ChatFormPickerListItemSkeleton.svelte @@ -11,7 +11,7 @@
-
+
diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPicker/ChatFormPickerPopover.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPicker/ChatFormPickerPopover.svelte index 2d91ceb5400c..24f92519da50 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPicker/ChatFormPickerPopover.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPicker/ChatFormPickerPopover.svelte @@ -39,7 +39,7 @@ event.preventDefault()} onkeydown={onKeydown} preventScroll={false} diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerCommand.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerCommand.svelte index e3ff9d780a41..b14383326d8f 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerCommand.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerCommand.svelte @@ -121,7 +121,7 @@ if (!command.disabled) nav.setHover(index); }} > - +
/{command.name} diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerMcpPrompts/ChatFormPromptPickerArgumentForm.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerMcpPrompts/ChatFormPromptPickerArgumentForm.svelte index e0eed66006f7..de91a0312048 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerMcpPrompts/ChatFormPromptPickerArgumentForm.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerMcpPrompts/ChatFormPromptPickerArgumentForm.svelte @@ -67,7 +67,7 @@ {/if}
- +
diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerMcpPrompts/ChatFormPromptPickerArgumentInput.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerMcpPrompts/ChatFormPromptPickerArgumentInput.svelte index b20c13cdf68c..5b290871e2ed 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerMcpPrompts/ChatFormPromptPickerArgumentInput.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormPickerMcpPrompts/ChatFormPromptPickerArgumentInput.svelte @@ -66,7 +66,7 @@ {#if isAutocompleteActive && suggestions.length > 0}
{#each suggestions as suggestion, i (suggestion)} + + + + + + + + + + + + Ready + + 3 slots + + Context 92% + + v0.6 +
+ +
+ + + Model settings + + Qwen3.8-27B · Q4_K_M + + + + + + General + + Sampling + + Server + + + +
+ + + + +

+ Tokens the model keeps in view. Up to 131,072 for this model. +

+
+ +
+ + + + F16 + + Q8_0 + + Q4_0 + +
+
+ + + + + + +
+ + + + Server + + llama-server on 127.0.0.1:9931 + + + + {#each server as s (s.id)} +
+
+ + +

{s.hint}

+
+ + +
+ {/each} +
+
+ + + + Loaded models + + Generation speed on this machine, in tokens per second + + + + + + + Model + + Quant + + Context + + Size + + tok/s + + + + + {#each models as m (m.name)} + + {m.name} + + {m.quant} + + {m.context} + + {m.size} + + {m.speed} + + {/each} + + + + +
+
+
diff --git a/tools/ui/tests/stories/chat/form/ChatFormActionReasoning.stories.svelte b/tools/ui/tests/stories/chat/form/ChatFormActionReasoning.stories.svelte new file mode 100644 index 000000000000..e8f652ba51ff --- /dev/null +++ b/tools/ui/tests/stories/chat/form/ChatFormActionReasoning.stories.svelte @@ -0,0 +1,56 @@ + + + + + + + + + { + await userEvent.click(canvas.getByRole('button', { name: 'Reasoning effort' })); + await screen.findByRole('menu'); + }} +/> + + { + await userEvent.click(canvas.getByRole('button', { name: 'Reasoning effort' })); + await screen.findByRole('menu'); + }} +/> diff --git a/tools/ui/tests/stories/chat/form/ChatFormActionRecord.stories.svelte b/tools/ui/tests/stories/chat/form/ChatFormActionRecord.stories.svelte new file mode 100644 index 000000000000..63c60940af16 --- /dev/null +++ b/tools/ui/tests/stories/chat/form/ChatFormActionRecord.stories.svelte @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + // the tooltip trigger wraps the disabled button, hover the trigger + await userEvent.hover(canvas.getAllByRole('button', { name: 'Start recording' })[0]); + }} +/> diff --git a/tools/ui/tests/stories/chat/form/ChatFormActionSubmit.stories.svelte b/tools/ui/tests/stories/chat/form/ChatFormActionSubmit.stories.svelte new file mode 100644 index 000000000000..3f8f3b2a3a5d --- /dev/null +++ b/tools/ui/tests/stories/chat/form/ChatFormActionSubmit.stories.svelte @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/ui/tests/stories/chat/form/ChatFormContextGauge.stories.svelte b/tools/ui/tests/stories/chat/form/ChatFormContextGauge.stories.svelte new file mode 100644 index 000000000000..56cd525be88f --- /dev/null +++ b/tools/ui/tests/stories/chat/form/ChatFormContextGauge.stories.svelte @@ -0,0 +1,110 @@ + + +{#snippet frame()} + +
+ + + + +{/snippet} + + + {@render frame()} + + + + {@render frame()} + + + + {@render frame()} + + + + {@render frame()} + + + + {@render frame()} + + + + {@render frame()} + diff --git a/tools/ui/tests/stories/chat/form/ChatFormCurrentWorkingDirectory.stories.svelte b/tools/ui/tests/stories/chat/form/ChatFormCurrentWorkingDirectory.stories.svelte new file mode 100644 index 000000000000..181baa67dce2 --- /dev/null +++ b/tools/ui/tests/stories/chat/form/ChatFormCurrentWorkingDirectory.stories.svelte @@ -0,0 +1,105 @@ + + +{#snippet template(args: ComponentProps)} + +
+
+ + +
+{/snippet} + + + + + + + + + + + + + + + + ({ error: 'path is outside the allowed roots' }) + })} + name="PickerSearchError" + {template} +/> + + diff --git a/tools/ui/tests/stories/chat/form/ChatFormInput.stories.svelte b/tools/ui/tests/stories/chat/form/ChatFormInput.stories.svelte new file mode 100644 index 000000000000..aee62b811f30 --- /dev/null +++ b/tools/ui/tests/stories/chat/form/ChatFormInput.stories.svelte @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/ui/tests/stories/chat/form/ChatFormPickerCommand.stories.svelte b/tools/ui/tests/stories/chat/form/ChatFormPickerCommand.stories.svelte new file mode 100644 index 000000000000..2f1a2ebbd282 --- /dev/null +++ b/tools/ui/tests/stories/chat/form/ChatFormPickerCommand.stories.svelte @@ -0,0 +1,46 @@ + + + +{#snippet anchored(query: string)} +
+
+ +
+
+{/snippet} + + + + + {@render anchored('')} + + + + {@render anchored('dir')} + + + + {@render anchored('xyz')} + + + diff --git a/tools/ui/tests/stories/chat/form/ChatFormPickerMcpPrompts.stories.svelte b/tools/ui/tests/stories/chat/form/ChatFormPickerMcpPrompts.stories.svelte new file mode 100644 index 000000000000..23ca64de1c3c --- /dev/null +++ b/tools/ui/tests/stories/chat/form/ChatFormPickerMcpPrompts.stories.svelte @@ -0,0 +1,74 @@ + + +{#snippet template(args: ComponentProps)} + +
+ +
+{/snippet} + + seedStores({ mcpPrompts, mcpServers })} name="Default" {template} /> + + seedStores({ mcpPrompts: mcpPrompts.slice(0, 2), mcpServers })} + name="FewPrompts" + {template} +/> + + seedStores({ mcpPrompts, mcpServers })} + name="Filtered" + {template} +/> + + + + seedStores({ mcpPrompts: [], mcpServers })} name="Empty" {template} /> + + seedStores({ mcpPrompts, mcpServers })} + name="ArgumentForm" + play={async ({ userEvent }) => { + await userEvent.click(await screen.findByText('Code review')); + await screen.findByRole('button', { name: 'Use Prompt' }); + }} + {template} +/> diff --git a/tools/ui/tests/stories/chat/form/ChatFormPickerMention.stories.svelte b/tools/ui/tests/stories/chat/form/ChatFormPickerMention.stories.svelte new file mode 100644 index 000000000000..35fe14ff7b37 --- /dev/null +++ b/tools/ui/tests/stories/chat/form/ChatFormPickerMention.stories.svelte @@ -0,0 +1,78 @@ + + +{#snippet template(args: ComponentProps)} + +
+ +
+{/snippet} + + + seedStores({ ...searchTools, globSearch: globSearchResult(toGlobEntries(mentionEntries)) })} + name="Default" + {template} +/> + + seedStores({ ...searchTools, globSearch: pendingGlobSearch() })} + name="Loading" + {template} +/> + + seedStores({ ...searchTools, globSearch: globSearchResult([]) })} + name="NoMatch" + {template} +/> + + + seedStores({ + ...searchTools, + globSearch: async () => ({ error: 'path is outside the allowed roots' }) + })} + name="SearchError" + {template} +/> + + seedStores({ serverHome: SERVER_HOME, serverTools: [] })} + name="SearchUnavailable" + {template} +/> diff --git a/tools/ui/tests/stories/chat/form/ChatScreenForm.stories.svelte b/tools/ui/tests/stories/chat/form/ChatScreenForm.stories.svelte new file mode 100644 index 000000000000..cd197eb1ae44 --- /dev/null +++ b/tools/ui/tests/stories/chat/form/ChatScreenForm.stories.svelte @@ -0,0 +1,208 @@ + + + { + const editor = await canvas.findByRole('textbox'); + const submitButton = await canvas.findByRole('button', { name: 'Send' }); + + // Expect the input to be focused after the component is mounted + await expect(editor).toHaveFocus(); + + // Expect the submit button to be disabled + await expect(submitButton).toBeDisabled(); + + const text = 'What is the meaning of life?'; + + await userEvent.clear(editor); + await userEvent.type(editor, text); + + await expect(editor).toHaveTextContent(text); + + const fileInput = document.querySelector('input[type="file"]'); + + await expect(fileInput).not.toHaveAttribute('accept'); + }} +/> + + seedStores(modelServer)} + name="WithText" + play={async ({ canvas, userEvent }) => { + const editor = await canvas.findByRole('textbox'); + + await userEvent.type(editor, 'Explain how the KV cache works in llama.cpp'); + }} +/> + + seedStores(modelServer)} + name="WithCodeSpan" + play={async ({ canvas, userEvent }) => { + const editor = await canvas.findByRole('textbox'); + + // the live-preview editor renders a complete code span as it is typed + await userEvent.type(editor, 'Why does `npm run check` fail after `npm install`?'); + }} +/> + + + + + + { + const jpgAttachment = canvas.getByAltText('1.jpg'); + const svgAttachment = canvas.getByAltText('hf-logo.svg'); + + await expect(jpgAttachment).toHaveAttribute('src', jpgAsset); + await expect(svgAttachment).toHaveAttribute('src', svgAsset); + await expect(canvas.getByText('example.pdf')).toBeInTheDocument(); + await expect(canvas.getByText('342.82 KB')).toBeInTheDocument(); + }} +/> + + + + + seedStores({ + config: { autoMicOnEmpty: true }, + serverProps: modelServerProps({ modalities: { audio: true, video: false, vision: true } }), + serverRole: ServerRole.MODEL + })} + name="WithRecordButton" +/> + + seedStores({ ...modelServer, reasoningEffort: ReasoningEffort.HIGH })} + name="WithReasoningEffort" +/> + + + seedStores({ + models: routerModels, + selectedModelId: 'removed-model', + serverProps: modelServerProps({ role: ServerRole.ROUTER }), + serverRole: ServerRole.ROUTER + })} + name="ModelNotAvailable" + play={async ({ canvas, userEvent }) => { + const editor = await canvas.findByRole('textbox'); + + await userEvent.type(editor, 'Hello'); + }} +/> + + seedStores({ mcpResources, mcpServers })} + name="WithMcpResources" +/> + + + seedStores({ + ...modelServer, + pendingCwd: `${SERVER_HOME}/llama.cpp/tools/ui`, + serverHome: SERVER_HOME, + serverTools: cwdServerTools + })} + name="WithWorkingDirectory" +/> + + { + await userEvent.click(await canvas.findByRole('button', { name: ATTACHMENT_TOOLTIP_TEXT })); + await screen.findByRole('menu'); + }} +/> + + + seedStores({ + ...modelServer, + mcpServers, + serverHome: SERVER_HOME, + serverTools: cwdServerTools + })} + name="CommandPickerOpen" + play={async ({ canvas, userEvent }) => { + await userEvent.type(await canvas.findByRole('textbox'), '/'); + await screen.findByText('/prompt'); + }} +/> + + + seedStores({ + ...modelServer, + globSearch: globSearchResult(toGlobEntries(mentionEntries)), + serverHome: SERVER_HOME, + serverTools: cwdServerTools + })} + name="MentionPickerOpen" + play={async ({ canvas, userEvent }) => { + await userEvent.type(await canvas.findByRole('textbox'), 'Look at @chat'); + await screen.findByText('ChatForm.svelte'); + }} +/> diff --git a/tools/ui/tests/stories/chat/form/fixtures.ts b/tools/ui/tests/stories/chat/form/fixtures.ts new file mode 100644 index 000000000000..6c63d4129e38 --- /dev/null +++ b/tools/ui/tests/stories/chat/form/fixtures.ts @@ -0,0 +1,457 @@ +import jpgAsset from '../../fixtures/assets/1.jpg?url'; +import pdfAsset from '../../fixtures/assets/example.pdf?raw'; +import svgAsset from '../../fixtures/assets/hf-logo.svg?url'; +import { + BuiltInTool, + ChatFormCommandAction, + FileMentionEntryType, + MessageRole, + MessageType, + MimeTypeText, + ReasoningEffort, + ServerRole, + SpecialFileType, + ToolSource +} from '$lib/enums'; +import { ToolsService } from '$lib/services/tools.service'; +import { + conversationsStore, + mcpStore, + modelsStore, + serverStore, + settingsStore, + toolsStore +} from '$lib/stores'; +import type { + ChatFormCommand, + DatabaseConversation, + DatabaseMessage, + FileMentionEntry, + GlobEntry, + MCPPromptInfo, + MCPResourceInfo, + MCPServerSettingsEntry, + ServerToolInfo +} from '$lib/types'; + +export const FORM_CLASS = 'max-w-[56rem] w-[calc(100vw-2rem)]'; + +export const MODEL_PATH = '/models/Qwen3-8B-Q4_K_M.gguf'; +export const MODEL_NAME = 'Qwen3-8B-Q4_K_M.gguf'; +export const SERVER_HOME = '/home/user'; +export const CONVERSATION_ID = 'story-conversation'; + +export { jpgAsset, svgAsset }; + +export const fileAttachments: ChatUploadedFile[] = [ + { + file: new File([''], '1.jpg', { type: 'image/jpeg' }), + id: '1', + name: '1.jpg', + preview: jpgAsset, + size: 44891, + type: 'image/jpeg' + }, + { + file: new File([''], 'hf-logo.svg', { type: 'image/svg+xml' }), + id: '2', + name: 'hf-logo.svg', + preview: svgAsset, + size: 1234, + type: 'image/svg+xml' + }, + { + file: new File([pdfAsset], 'example.pdf', { type: 'application/pdf' }), + id: '3', + name: 'example.pdf', + size: 351048, + type: 'application/pdf' + }, + { + file: new File(['# Notes\n\nShort text file.'], 'notes.md', { type: MimeTypeText.MARKDOWN }), + id: '4', + name: 'notes.md', + size: 26, + textContent: '# Notes\n\nShort text file.', + type: MimeTypeText.MARKDOWN + } +]; + +export const loadingAttachment: ChatUploadedFile = { + file: new File([], 'loading'), + id: 'loading-prompt', + isLoading: true, + mcpPrompt: { promptName: 'code_review', serverName: 'github' }, + name: 'Code review', + size: 0, + type: SpecialFileType.MCP_PROMPT +}; + +export const mcpServers: MCPServerSettingsEntry[] = [ + { enabled: true, id: 'github', name: 'GitHub', url: 'https://api.githubcopilot.com/mcp/' }, + { enabled: true, id: 'docs', name: 'Docs', url: 'https://docs.example.com/mcp' } +]; + +export const mcpPrompts: MCPPromptInfo[] = [ + { + arguments: [ + { description: 'Repository in owner/name form', name: 'repo', required: true }, + { description: 'Pull request number', name: 'pr', required: true }, + { description: 'Focus area, e.g. security', name: 'focus' } + ], + description: 'Review a pull request and list the main issues', + name: 'code_review', + serverName: 'github', + title: 'Code review' + }, + { + description: 'Summarize open issues by label', + name: 'issue_summary', + serverName: 'github', + title: 'Issue summary' + }, + { + arguments: [{ description: 'Topic to explain', name: 'topic', required: true }], + description: 'Explain a topic from the docs', + name: 'explain', + serverName: 'docs', + title: 'Explain' + }, + { + description: 'Write release notes from the changelog', + name: 'release_notes', + serverName: 'docs' + } +]; + +export const mcpResources: MCPResourceInfo[] = [ + { + mimeType: MimeTypeText.MARKDOWN, + name: 'README.md', + serverName: 'github', + uri: 'repo://ggml-org/llama.cpp/README.md' + }, + { + mimeType: MimeTypeText.PLAIN, + name: 'server-api.txt', + serverName: 'docs', + title: 'Server API', + uri: 'docs://server/api' + } +]; + +export const chatCommands: ChatFormCommand[] = [ + { + action: ChatFormCommandAction.PROMPT, + description: 'Insert an MCP prompt', + disabled: false, + name: 'prompt' + }, + { + action: ChatFormCommandAction.CWD, + description: 'Set working directory', + disabled: false, + keywords: ['current working directory'], + name: 'cwd' + }, + { + action: ChatFormCommandAction.MODEL, + description: 'Select model', + disabled: false, + name: 'model' + }, + { + action: ChatFormCommandAction.COMPACT, + description: 'Summarize the conversation to free up context', + disabled: true, + keywords: ['summarize', 'context'], + name: 'compact' + } +]; + +export const mentionEntries: FileMentionEntry[] = [ + { + name: 'src', + path: `${SERVER_HOME}/llama.cpp/tools/ui/src`, + type: FileMentionEntryType.DIRECTORY + }, + { + name: 'ChatForm.svelte', + path: `${SERVER_HOME}/llama.cpp/tools/ui/src/lib/components/app/chat/ChatForm/ChatForm.svelte`, + type: FileMentionEntryType.FILE + }, + { + name: 'chat.d.ts', + path: `${SERVER_HOME}/llama.cpp/tools/ui/src/lib/types/chat.d.ts`, + type: FileMentionEntryType.FILE + } +]; + +export const directoryResults = [ + `${SERVER_HOME}/llama.cpp`, + `${SERVER_HOME}/llama.cpp/tools`, + `${SERVER_HOME}/llama.cpp/tools/ui`, + `${SERVER_HOME}/llama.cpp/tools/server` +]; + +/** Server tools that make the cwd chip and the mention search available. */ +export const cwdServerTools: ServerToolInfo[] = [ + BuiltInTool.SERVER_FILE_GLOB_SEARCH, + BuiltInTool.SERVER_READ_FILE +].map((tool) => ({ + definition: { function: { name: tool, parameters: {} }, type: 'function' }, + display_name: tool, + permissions: { write: false }, + tool, + type: ToolSource.SERVER, + uses_cwd: true +})); + +export function modelServerProps( + overrides: Partial = {} +): ApiLlamaCppServerProps { + return { + default_generation_settings: { n_ctx: 32768 }, + modalities: { audio: false, video: false, vision: true }, + model_path: MODEL_PATH, + ...overrides + } as unknown as ApiLlamaCppServerProps; +} + +export const routerModels: ModelOption[] = [ + { capabilities: [], id: 'qwen3-8b', model: 'Qwen/Qwen3-8B-GGUF', name: 'Qwen3-8B' }, + { capabilities: [], id: 'gemma-3-4b', model: 'google/gemma-3-4b-it-GGUF', name: 'gemma-3-4b-it' } +]; + +export const conversation: DatabaseConversation = { + currNode: 'a2', + id: CONVERSATION_ID, + lastModified: Date.now(), + name: 'Story conversation' +}; + +/** A short user/assistant exchange whose last turn used `promptTokens` of context. */ +export function conversationMessages(promptTokens: number, outputTokens = 512): DatabaseMessage[] { + const base = { + children: [], + convId: CONVERSATION_ID, + timestamp: Date.now(), + type: MessageType.TEXT + }; + + return [ + { ...base, content: 'Explain the KV cache.', id: 'u1', parent: null, role: MessageRole.USER }, + { + ...base, + content: 'The KV cache stores keys and values of past tokens.', + id: 'a1', + model: MODEL_NAME, + parent: 'u1', + role: MessageRole.ASSISTANT, + timings: { predicted_ms: 4200, predicted_n: 380, prompt_ms: 120, prompt_n: 240 } + }, + { ...base, content: 'And how big can it get?', id: 'u2', parent: 'a1', role: MessageRole.USER }, + { + ...base, + content: 'It grows with the context length.', + id: 'a2', + model: MODEL_NAME, + parent: 'u2', + role: MessageRole.ASSISTANT, + timings: { + cache_n: 620, + predicted_ms: outputTokens * 11, + predicted_n: outputTokens, + prompt_ms: 300, + prompt_n: promptTokens - 620 + } + } + ] as DatabaseMessage[]; +} + +/** Store state a story needs; every field left out keeps the current value. */ +export interface StoreSeed { + activeConversation?: DatabaseConversation | null; + activeMessages?: DatabaseMessage[]; + config?: Record; + globSearch?: (params: Record) => Promise>; + mcpPrompts?: MCPPromptInfo[]; + mcpResources?: MCPResourceInfo[]; + mcpServers?: MCPServerSettingsEntry[]; + modelProps?: Record; + models?: ModelOption[]; + pendingCwd?: string | null; + reasoningEffort?: ReasoningEffort; + routerModels?: ApiModelDataEntry[]; + selectedModelId?: string | null; + selectedModelName?: string | null; + serverHome?: string | null; + serverProps?: ApiLlamaCppServerProps | null; + serverRole?: ServerRole | null; + serverTools?: ServerToolInfo[]; +} + +interface ToolsStoreInternals { + _serverHome: string | null | undefined; + _serverTools: ServerToolInfo['definition'][]; + cwdAwareTools: Set; +} + +interface PropsCache { + cache: { delete(key: string): boolean; set(key: string, value: ApiLlamaCppServerProps): void }; + cacheVersion: number; +} + +type Restore = () => void; + +/** Override an object member; the restore puts back the original. */ +export function override( + target: T, + key: K, + value: T[K] +): Restore { + const hadOwn = Object.prototype.hasOwnProperty.call(target, key); + const previous = target[key]; + + Object.defineProperty(target, key, { configurable: true, value, writable: true }); + + return () => { + if (hadOwn) target[key] = previous; + else delete target[key]; + }; +} + +/** + * Seed the global stores for one story. Nothing is persisted. Return the + * result from `beforeEach` so Storybook restores the stores afterwards. + */ +export function seedStores(seed: StoreSeed): Restore { + const restores: Restore[] = []; + const tools = toolsStore as unknown as ToolsStoreInternals; + const props = modelsStore.props as unknown as PropsCache; + const set = (target: T, key: K, value: T[K]) => { + const previous = target[key]; + + target[key] = value; + restores.push(() => (target[key] = previous)); + }; + + if (seed.serverRole !== undefined) set(serverStore, 'role', seed.serverRole); + + if (seed.serverProps !== undefined) set(serverStore, 'props', seed.serverProps); + + if (seed.models) set(modelsStore, 'models', seed.models); + + if (seed.routerModels) set(modelsStore, 'routerModels', seed.routerModels); + + if (seed.selectedModelId !== undefined) set(modelsStore, 'selectedModelId', seed.selectedModelId); + + if (seed.selectedModelName !== undefined) + set(modelsStore, 'selectedModelName', seed.selectedModelName); + + if (seed.config || seed.mcpServers) { + set(settingsStore, 'config', { + ...settingsStore.config, + ...seed.config, + ...(seed.mcpServers ? { mcpServers: JSON.stringify(seed.mcpServers) } : {}) + }); + } + + if (seed.reasoningEffort !== undefined) + set(conversationsStore.preferences, 'pendingReasoningEffort', seed.reasoningEffort); + + if (seed.pendingCwd !== undefined) + set(conversationsStore.preferences, 'pendingCwd', seed.pendingCwd); + + if (seed.activeConversation !== undefined) + set(conversationsStore, 'activeConversation', seed.activeConversation); + + if (seed.activeMessages) set(conversationsStore, 'activeMessages', seed.activeMessages); + + if (seed.serverTools) { + set( + tools, + '_serverTools', + seed.serverTools.map((t) => t.definition) + ); + set( + tools, + 'cwdAwareTools', + new Set(seed.serverTools.filter((t) => t.uses_cwd).map((t) => t.tool)) + ); + } + + if (seed.serverHome !== undefined) set(tools, '_serverHome', seed.serverHome); + + if (seed.modelProps) { + for (const [id, value] of Object.entries(seed.modelProps)) { + props.cache.set(id, value); + restores.push(() => props.cache.delete(id)); + } + + props.cacheVersion++; + } + + if (seed.globSearch) { + const globSearch = seed.globSearch; + + restores.push( + override(ToolsService, 'executeToolRaw', async (toolName, params) => { + if (toolName !== BuiltInTool.SERVER_FILE_GLOB_SEARCH) return {}; + + return globSearch(params); + }) + ); + } + + if (seed.mcpPrompts) { + const prompts = seed.mcpPrompts; + + restores.push(override(mcpStore, 'ensureInitialized', async () => true)); + restores.push(override(mcpStore, 'getAllPrompts', async () => prompts)); + } + + if (seed.mcpResources) { + for (const resource of seed.mcpResources) { + const attachment = mcpStore.resources.addAttachment(resource); + + mcpStore.resources.updateAttachmentContent(attachment.id, [ + { mimeType: resource.mimeType, text: `Content of ${resource.name}`, uri: resource.uri } + ]); + } + + restores.push(() => mcpStore.resources.clearAttachments()); + } + + return () => { + for (const restore of restores.reverse()) restore(); + }; +} + +/** A `file_glob_search` stand-in that returns `paths` relative to the server home. */ +export function globSearchResult(entries: GlobEntry[], delayMs = 0) { + return async () => { + if (delayMs > 0) await new Promise((resolve) => setTimeout(resolve, delayMs)); + + return { base: SERVER_HOME, entries }; + }; +} + +/** Never resolves: keeps a picker in its loading state. */ +export function pendingGlobSearch() { + return () => new Promise>(() => {}); +} + +export function toGlobEntries(paths: { path: string; type: FileMentionEntryType }[]): GlobEntry[] { + return paths.map(({ path, type }) => ({ + path: path.replace(`${SERVER_HOME}/`, ''), + type: type === FileMentionEntryType.DIRECTORY ? 'dir' : 'file' + })); +} + +export { ReasoningEffort, ServerRole }; + +/** An open menu that unmounts leaves `pointer-events: none` on the body; clear it. */ +export function resetPointerEvents() { + document.body.style.pointerEvents = ''; +} diff --git a/tools/ui/tests/stories/chat/messages/ActionIconsStoryHost.svelte b/tools/ui/tests/stories/chat/messages/ActionIconsStoryHost.svelte new file mode 100644 index 000000000000..28a121782bee --- /dev/null +++ b/tools/ui/tests/stories/chat/messages/ActionIconsStoryHost.svelte @@ -0,0 +1,90 @@ + + + (rawOutputEnabled = enabled)} + {onRegenerate} + {rawOutputEnabled} + {showRawOutputSwitch} +/> diff --git a/tools/ui/tests/stories/chat/messages/ChatMessage.stories.svelte b/tools/ui/tests/stories/chat/messages/ChatMessage.stories.svelte new file mode 100644 index 000000000000..bd77f6ce964c --- /dev/null +++ b/tools/ui/tests/stories/chat/messages/ChatMessage.stories.svelte @@ -0,0 +1,275 @@ + + + seedChatStory()} name="Default" /> + + seedChatStory()} name="User" /> + + seedChatStory()} + name="UserMarkdown" +/> + + seedChatStory({ settings: { renderUserContentAsMarkdown: false } })} + name="UserPlainText" +/> + + seedChatStory()} + name="UserWithAttachments" +/> + + seedChatStory()} + name="UserAttachmentsOnly" +/> + + seedChatStory()} + name="UserWithReadingStats" +/> + + seedChatStory({ loading: true, processing: promptProcessingState })} + name="UserReadingLive" +/> + + seedChatStory()} name="System" /> + + seedChatStory()} name="SystemLong" /> + + seedChatStory({ settings: { enableContinueGeneration: true } })} + name="AssistantWithContinue" +/> + + seedChatStory()} + name="AssistantWithReasoning" +/> + + seedChatStory()} + name="AssistantReasoningCancelled" +/> + + seedChatStory({ loading: true, streamingMessageId: streamingMessage.id })} + name="AssistantReasoningStreaming" + play={async () => { + streamingMessage.timestamp = 0; + streamingMessage.content = ''; + streamingMessage.reasoningContent = ''; + + await streamInto('reasoningContent', REASONING_TEXT); + await streamInto('content', STREAM_ANSWER); + + chatStore.chatStreamingStates.delete(CONV_ID); + chatActivityStore.localEnded(CONV_ID); + streamingMessage.timestamp = Date.now(); + }} +> + + + + seedChatStory({ loading: true, processing: promptProcessingState })} + name="AssistantProcessing" +/> + + + seedChatStory({ + loading: true, + processing: generatingProcessingState, + streamingMessageId: 'assistant-generating' + })} + name="AssistantGenerating" +/> + + seedChatStory()} + name="AssistantWithToolCalls" +/> + + seedChatStory({ settings: { showAgenticTurnStats: true } })} + name="AssistantAgenticMultiTurn" +/> + + seedChatStory()} + name="AssistantWithStatistics" +/> + + seedChatStory({ settings: { showRawOutputSwitch: true } })} + name="RawOutput" + play={async ({ canvas, userEvent }) => { + await userEvent.click(await canvas.findByRole('switch')); + }} +/> + + seedChatStory()} + name="WithBranching" +/> + + + seedChatStory({ activeMessages: [preCompactionAssistantMessage, compactionMessage] })} + name="Compaction" +/> + + + seedChatStory({ + compactingNodeId: compactionPendingMessage.id, + loading: true, + processing: promptProcessingState + })} + name="CompactionPrefill" +/> + + + seedChatStory({ + compactingNodeId: compactionGeneratingMessage.id, + loading: true, + processing: generatingProcessingState + })} + name="CompactionGenerating" +/> + + seedChatStory()} name="CwdChange" /> + + seedChatStory()} name="CwdCleared" /> + + seedChatStory()} name="McpPrompt" /> + + seedChatStory({ pendingEditMessageId: userWithAttachmentsMessage.id })} + name="EditUser" +/> + + seedChatStory({ pendingEditMessageId: assistantWithReasoningMessage.id })} + name="EditAssistant" +/> + + seedChatStory({ pendingEditMessageId: systemMessage.id })} + name="EditSystem" +/> diff --git a/tools/ui/tests/stories/chat/messages/ChatMessageActionCard.stories.svelte b/tools/ui/tests/stories/chat/messages/ChatMessageActionCard.stories.svelte new file mode 100644 index 000000000000..65ece74e8d6e --- /dev/null +++ b/tools/ui/tests/stories/chat/messages/ChatMessageActionCard.stories.svelte @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + diff --git a/tools/ui/tests/stories/chat/messages/ChatMessageActionIcons.stories.svelte b/tools/ui/tests/stories/chat/messages/ChatMessageActionIcons.stories.svelte new file mode 100644 index 000000000000..7b9c480ed195 --- /dev/null +++ b/tools/ui/tests/stories/chat/messages/ChatMessageActionIcons.stories.svelte @@ -0,0 +1,78 @@ + + + + + + {}} + {onRegenerate} + /> + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/ui/tests/stories/chat/messages/ChatMessageReasoningBlock.stories.svelte b/tools/ui/tests/stories/chat/messages/ChatMessageReasoningBlock.stories.svelte new file mode 100644 index 000000000000..522103a8703e --- /dev/null +++ b/tools/ui/tests/stories/chat/messages/ChatMessageReasoningBlock.stories.svelte @@ -0,0 +1,60 @@ + + + seedChatStory()} name="States"> + + + + + + + + + + + + + + + + + + + + + + + + + seedChatStory({ settings: { renderThinkingAsMarkdown: false } })} + name="ExpandedPlainText" +/> diff --git a/tools/ui/tests/stories/chat/messages/ChatMessageStatistics.stories.svelte b/tools/ui/tests/stories/chat/messages/ChatMessageStatistics.stories.svelte new file mode 100644 index 000000000000..395eb9952321 --- /dev/null +++ b/tools/ui/tests/stories/chat/messages/ChatMessageStatistics.stories.svelte @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/ui/tests/stories/chat/messages/ChatMessageToolCallBlock.stories.svelte b/tools/ui/tests/stories/chat/messages/ChatMessageToolCallBlock.stories.svelte new file mode 100644 index 000000000000..b77fbc940fcc --- /dev/null +++ b/tools/ui/tests/stories/chat/messages/ChatMessageToolCallBlock.stories.svelte @@ -0,0 +1,156 @@ + + + seedChatStory()} name="States"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/ui/tests/stories/chat/messages/ChatMessageUserPending.stories.svelte b/tools/ui/tests/stories/chat/messages/ChatMessageUserPending.stories.svelte new file mode 100644 index 000000000000..4a53dfb3bd42 --- /dev/null +++ b/tools/ui/tests/stories/chat/messages/ChatMessageUserPending.stories.svelte @@ -0,0 +1,34 @@ + + + + + + + + + + + + + diff --git a/tools/ui/tests/stories/chat/messages/fixtures.ts b/tools/ui/tests/stories/chat/messages/fixtures.ts new file mode 100644 index 000000000000..bbf7db3bd078 --- /dev/null +++ b/tools/ui/tests/stories/chat/messages/fixtures.ts @@ -0,0 +1,728 @@ +import { + AgenticSectionType, + AttachmentType, + BuiltInTool, + MessageRole, + MessageType +} from '$lib/enums'; +import { chatStore, conversationsStore, settingsStore } from '$lib/stores'; +import { chatActivityStore } from '$lib/stores/chat/activity.svelte'; +import type { + AgenticSection, + ApiChatCompletionToolCall, + ApiProcessingState, + ChatMessageActions, + ChatMessageAgenticTimings, + ChatMessageSiblingInfo, + DatabaseMessage, + DatabaseMessageExtra, + SettingsConfigValue +} from '$lib/types'; + +export const CONV_ID = 'conv-1'; +export const MODEL_NAME = 'ggml-org/gpt-oss-20b-GGUF'; +export const STORY_CLASS = 'max-w-[56rem] w-[calc(100vw-2rem)]'; + +const NOW = Date.now(); + +export const noopChatActions: ChatMessageActions = { + continueAssistantMessage: () => {}, + copy: () => {}, + delete: () => {}, + editUserMessagePreserveResponses: () => {}, + editWithBranching: () => {}, + editWithReplacement: () => {}, + forkConversation: () => {}, + navigateToSibling: () => {}, + regenerateCompaction: () => {}, + regenerateWithBranching: () => {} +}; + +function createMessage( + fields: Pick & Partial +): DatabaseMessage { + return { + children: [], + convId: CONV_ID, + parent: null, + timestamp: NOW - 1000 * 60, + type: MessageType.TEXT, + ...fields + }; +} + +function toolCallsJson(calls: { id: string; name: string; args: unknown }[]): string { + const toolCalls: ApiChatCompletionToolCall[] = calls.map((call) => ({ + function: { arguments: JSON.stringify(call.args), name: call.name }, + id: call.id, + type: 'function' + })); + + return JSON.stringify(toolCalls); +} + +// Small inline images so the stories need no binary assets. +const SVG_IMAGE_URL = `data:image/svg+xml;base64,${btoa( + '' +)}`; +const CHART_IMAGE_URL = `data:image/svg+xml;base64,${btoa( + '' +)}`; + +/* User messages */ + +export const userMessage = createMessage({ + content: 'What is the meaning of life, the universe, and everything?', + id: 'user-1', + role: MessageRole.USER +}); + +export const userMarkdownMessage = createMessage({ + content: + 'Can you review this function?\n\n```ts\nexport function sum(values: number[]): number {\n\treturn values.reduce((acc, v) => acc + v, 0);\n}\n```\n\n- Is it safe for empty arrays?\n- Should it accept `bigint`?', + id: 'user-markdown', + role: MessageRole.USER +}); + +export const userAttachments: DatabaseMessageExtra[] = [ + { + base64Url: SVG_IMAGE_URL, + name: 'sunset.svg', + size: 412, + type: AttachmentType.IMAGE + }, + { + content: 'id,name,score\n1,Ada,98\n2,Linus,91\n3,Grace,95\n', + name: 'scores.csv', + size: 46, + type: AttachmentType.TEXT + }, + { + base64Data: btoa('%PDF-1.4\n%mock\n'), + content: 'Quarterly report. Revenue grew 12 percent quarter over quarter.', + name: 'report.pdf', + processedAsImages: false, + size: 18_432, + type: AttachmentType.PDF + } +]; + +export const userWithAttachmentsMessage = createMessage({ + content: 'Summarize the attached files and describe the image.', + extra: userAttachments, + id: 'user-attachments', + role: MessageRole.USER +}); + +export const userAttachmentsOnlyMessage = createMessage({ + content: '', + extra: [userAttachments[0]], + id: 'user-attachments-only', + role: MessageRole.USER +}); + +/* System messages */ + +export const systemMessage = createMessage({ + content: 'You are a helpful assistant. Answer briefly and use **markdown** when it helps.', + id: 'system-1', + role: MessageRole.SYSTEM, + type: MessageType.SYSTEM +}); + +export const systemLongMessage = createMessage({ + content: [ + 'You are a senior software engineer helping with the llama.cpp web UI.', + '', + '## Rules', + '', + '1. Read the relevant files before you answer.', + '2. Keep answers short and concrete.', + '3. Prefer existing helpers over new abstractions.', + '4. Use ASCII only in code comments.', + '5. Never invent API fields; read the types first.', + '6. Point to file paths when you mention code.', + '', + '## Style', + '', + '- Use simple words.', + '- Avoid long comments.', + '- Show code only when it is needed.' + ].join('\n'), + id: 'system-long', + role: MessageRole.SYSTEM, + type: MessageType.SYSTEM +}); + +/* Assistant messages */ + +export const assistantMessage = createMessage({ + content: + 'The answer to the ultimate question of life, the universe, and everything is **42**.\n\nThis comes from Douglas Adams\' "The Hitchhiker\'s Guide to the Galaxy," where a supercomputer named Deep Thought calculated this answer over 7.5 million years. However, the question itself was never properly formulated, which is why the answer seems meaningless without context.', + id: 'assistant-1', + parent: 'user-1', + role: MessageRole.ASSISTANT +}); + +export const REASONING_TEXT = + "Let's consider the question step by step:\n\n1. Identify the core problem\n2. Evaluate relevant information\n3. Formulate a clear answer\n\nFollowing this process keeps the final response focused and accurate."; + +export const assistantWithReasoningMessage = createMessage({ + content: "Here's the concise answer, now that I've thought it through: **42**.", + id: 'assistant-reasoning', + parent: 'user-1', + reasoningContent: REASONING_TEXT, + role: MessageRole.ASSISTANT +}); + +// Reasoning with no answer after it, on a finished turn: the block shows "Cancelled". +export const assistantInterruptedReasoningMessage = createMessage({ + content: '', + id: 'assistant-reasoning-interrupted', + parent: 'user-1', + reasoningContent: 'The user asks about the meaning of life. I should first check which', + role: MessageRole.ASSISTANT +}); + +export const assistantWithStatsMessage = createMessage({ + content: assistantMessage.content, + id: 'assistant-stats', + model: MODEL_NAME, + parent: 'user-1', + role: MessageRole.ASSISTANT, + timings: { + cache_n: 128, + predicted_ms: 3120, + predicted_n: 164, + prompt_ms: 412, + prompt_n: 1830 + } +}); + +export const rawOutputMessage = createMessage({ + content: 'Hello there! How can I help you today?', + id: 'assistant-raw', + parent: 'user-1', + reasoningContent: + 'User greeted me. Is this a trap? No, just a normal hello. Respond calmly and do not start explaining quantum physics again.', + role: MessageRole.ASSISTANT +}); + +/* Agentic (tool calls) */ + +export const agenticTimings: ChatMessageAgenticTimings = { + llm: { predicted_ms: 5400, predicted_n: 312, prompt_ms: 980, prompt_n: 4210 }, + perTurn: [ + { + llm: { predicted_ms: 1800, predicted_n: 96, prompt_ms: 610, prompt_n: 2400 }, + toolCalls: [ + { duration_ms: 42, name: BuiltInTool.SERVER_GET_INFO, success: true }, + { duration_ms: 318, name: BuiltInTool.SERVER_EXEC_SHELL_COMMAND, success: true } + ], + toolsMs: 360, + turn: 1 + }, + { + llm: { predicted_ms: 3600, predicted_n: 216, prompt_ms: 370, prompt_n: 1810 }, + toolCalls: [], + toolsMs: 0, + turn: 2 + } + ], + toolCalls: [ + { duration_ms: 42, name: BuiltInTool.SERVER_GET_INFO, success: true }, + { duration_ms: 318, name: BuiltInTool.SERVER_EXEC_SHELL_COMMAND, success: true } + ], + toolCallsCount: 2, + toolsMs: 360, + turns: 2 +}; + +export const assistantWithToolCallsMessage = createMessage({ + content: 'Let me check the environment first.', + id: 'assistant-tools', + parent: 'user-1', + reasoningContent: 'I need the working directory and the file list before I answer.', + role: MessageRole.ASSISTANT, + toolCalls: toolCallsJson([ + { args: {}, id: 'call-info', name: BuiltInTool.SERVER_GET_INFO }, + { args: { command: 'ls -la' }, id: 'call-ls', name: BuiltInTool.SERVER_EXEC_SHELL_COMMAND } + ]) +}); + +export const toolResultMessages: DatabaseMessage[] = [ + createMessage({ + content: JSON.stringify({ cwd: '/home/user/projects/llama.cpp', os: 'linux' }), + id: 'tool-info', + parent: 'assistant-tools', + role: MessageRole.TOOL, + toolCallId: 'call-info' + }), + createMessage({ + content: + 'total 24\ndrwxr-xr-x 6 user user 4096 Oct 28 10:12 .\ndrwxr-xr-x 12 user user 4096 Oct 27 09:01 ..\n-rw-r--r-- 1 user user 1067 Oct 20 14:33 LICENSE\n-rw-r--r-- 1 user user 2311 Oct 28 10:12 README.md\ndrwxr-xr-x 4 user user 4096 Oct 28 10:10 src\ndrwxr-xr-x 3 user user 4096 Oct 26 18:40 tools\n[exit code: 0]', + id: 'tool-ls', + parent: 'tool-info', + role: MessageRole.TOOL, + toolCallId: 'call-ls', + toolCwd: '/home/user/projects/llama.cpp' + }) +]; + +// Continuation turn after the tool results; it closes the agentic session. +export const agenticFinalTurnMessage = createMessage({ + content: + 'The project root holds `README.md`, `LICENSE` and two folders: `src` and `tools`. The shell runs on Linux in `~/projects/llama.cpp`.', + id: 'assistant-tools-final', + parent: 'tool-ls', + role: MessageRole.ASSISTANT +}); + +export const agenticToolMessages: DatabaseMessage[] = [ + ...toolResultMessages, + agenticFinalTurnMessage +]; + +export const assistantAgenticWithStatsMessage: DatabaseMessage = { + ...assistantWithToolCallsMessage, + id: 'assistant-tools-stats', + model: MODEL_NAME, + timings: { + agentic: agenticTimings, + predicted_ms: 1800, + predicted_n: 96, + prompt_ms: 610, + prompt_n: 2400 + } +}; + +/* Compaction */ + +export const preCompactionAssistantMessage = createMessage({ + content: 'Deep Thought took 7.5 million years to answer.', + id: 'assistant-pre-compaction', + parent: 'user-1', + role: MessageRole.ASSISTANT, + timestamp: NOW - 1000 * 60 * 31, + timings: { cache_n: 0, predicted_n: 118, prompt_n: 42200 } +}); + +export const compactionMessage = createMessage({ + content: + 'The user asked about the ultimate answer and its origin. Key facts: the answer is **42**, from Douglas Adams\' "The Hitchhiker\'s Guide to the Galaxy", computed by Deep Thought over 7.5 million years.\n\nNothing is left to do unless the user wants the question itself discussed.', + id: 'compaction-1', + model: MODEL_NAME, + parent: 'assistant-pre-compaction', + role: MessageRole.USER, + timestamp: NOW - 1000 * 60 * 30, + // The pre-encode stamps the reduced prompt; `compaction` keeps the summary request timings. + timings: { + cache_n: 0, + compaction: { + cache_n: 0, + predicted_ms: 12000, + predicted_n: 300, + prompt_ms: 18200, + prompt_n: 42200 + }, + predicted_n: 0, + prompt_n: 3204 + }, + type: MessageType.COMPACTION +}); + +export const compactionPendingMessage = createMessage({ + content: '', + id: 'compaction-pending', + parent: 'assistant-pre-compaction', + role: MessageRole.USER, + type: MessageType.COMPACTION +}); + +export const compactionGeneratingMessage = createMessage({ + content: + 'The user asked about the ultimate answer and its origin. Key facts: the answer is **42**', + id: 'compaction-generating', + model: MODEL_NAME, + parent: 'assistant-pre-compaction', + role: MessageRole.USER, + type: MessageType.COMPACTION +}); + +/* Synthetic and MCP prompt */ + +export const cwdChangeMessage = createMessage({ + content: 'Set working directory to [file:///home/user/projects/llama.cpp](~/projects/llama.cpp)', + id: 'cwd-change', + isSynthetic: true, + role: MessageRole.USER +}); + +export const cwdClearedMessage = createMessage({ + content: 'Working directory cleared', + id: 'cwd-cleared', + isSynthetic: true, + role: MessageRole.USER +}); + +export const mcpPromptMessage = createMessage({ + content: '', + extra: [ + { + arguments: { language: 'TypeScript', path: 'src/lib/utils/agentic.ts' }, + content: + 'Review the TypeScript file at src/lib/utils/agentic.ts. Point out bugs first, then style issues.', + name: 'code_review', + promptName: 'code_review', + serverName: 'github', + type: AttachmentType.MCP_PROMPT + } + ], + id: 'mcp-prompt', + role: MessageRole.USER +}); + +/* Branching */ + +export const siblingInfo: ChatMessageSiblingInfo = { + currentIndex: 1, + message: assistantMessage, + siblingIds: ['assistant-0', assistantMessage.id, 'assistant-2'], + totalSiblings: 3 +}; + +/* Tool call sections, as deriveAgenticSections builds them */ + +function toolSection( + toolName: string, + args: unknown, + toolResult?: string, + type: AgenticSectionType = AgenticSectionType.TOOL_CALL +): AgenticSection { + return { + content: toolResult ?? '', + toolArgs: typeof args === 'string' ? args : JSON.stringify(args), + toolCallId: `call-${toolName}`, + toolName, + toolResult, + type + }; +} + +export const defaultToolSection = toolSection( + 'get_weather', + { city: 'Warsaw', units: 'metric' }, + JSON.stringify({ city: 'Warsaw', condition: 'cloudy', humidity: 71, temperature: 9 }) +); + +export const defaultToolPendingSection = toolSection( + 'get_weather', + { city: 'Warsaw', units: 'metric' }, + undefined, + AgenticSectionType.TOOL_CALL_PENDING +); + +export const defaultToolStreamingSection = toolSection( + 'get_weather', + '{"city": "Wars', + undefined, + AgenticSectionType.TOOL_CALL_STREAMING +); + +export const defaultToolMarkdownSection = toolSection( + 'summarize_issue', + { issue: 31273 }, + '## Issue 31273\n\n**Status:** open\n\nThe reasoning menu should list the effort levels the chat template supports.' +); + +export const getDatetimeSection = toolSection( + BuiltInTool.BROWSER_GET_DATETIME, + {}, + JSON.stringify({ result: 'Wednesday, October 28, 2026, 10:15:00 CET' }) +); + +export const getInfoSection = toolSection( + BuiltInTool.SERVER_GET_INFO, + {}, + JSON.stringify({ cwd: '/home/user/projects/llama.cpp', os: 'linux' }) +); + +export const readFileSection = toolSection( + BuiltInTool.SERVER_READ_FILE, + { end_line: 9, path: 'src/lib/utils/sum.ts', start_line: 1 }, + 'export function sum(values: number[]): number {\n\treturn values.reduce((acc, v) => acc + v, 0);\n}\n\nexport function mean(values: number[]): number {\n\tif (values.length === 0) return 0;\n\n\treturn sum(values) / values.length;\n}' +); + +export const editFileSection = toolSection( + BuiltInTool.SERVER_EDIT_FILE, + { + edits: [ + { + new_text: '\tif (values.length === 0) return Number.NaN;', + old_text: '\tif (values.length === 0) return 0;' + } + ], + path: 'src/lib/utils/sum.ts' + }, + JSON.stringify({ edits_applied: 1, result: 'File edited' }) +); + +export const editFileErrorSection = toolSection( + BuiltInTool.SERVER_EDIT_FILE, + { + edits: [{ new_text: 'const b = 2;', old_text: 'const a = 1;' }], + path: 'src/lib/utils/sum.ts' + }, + JSON.stringify({ error: 'old_text not found in file' }) +); + +export const writeFileSection = toolSection( + BuiltInTool.SERVER_WRITE_FILE, + { + content: '# Notes\n\n- Sum is safe for empty arrays.\n- Mean returns NaN for empty input.\n', + path: 'docs/notes.md' + }, + JSON.stringify({ bytes: 79, result: 'File written' }) +); + +export const execShellSection: AgenticSection = { + ...toolSection( + BuiltInTool.SERVER_EXEC_SHELL_COMMAND, + { command: 'npm test -- --run' }, + ' RUN v4.1.12 /home/user/projects/app\n\n src/sum.test.ts (3 tests) 4ms\n src/mean.test.ts (2 tests) 3ms\n\n Test Files 2 passed (2)\n Tests 5 passed (5)\n[exit code: 0]' + ), + toolCwd: '/home/user/projects/app' +}; + +export const execShellFailedSection: AgenticSection = { + ...toolSection( + BuiltInTool.SERVER_EXEC_SHELL_COMMAND, + { command: 'cat missing.txt' }, + 'cat: missing.txt: No such file or directory\n[exit code: 1]' + ), + toolCwd: '/home/user/projects/app' +}; + +export const execShellTimedOutSection: AgenticSection = { + ...toolSection( + BuiltInTool.SERVER_EXEC_SHELL_COMMAND, + { command: 'sleep 600' }, + '[exit code: -1] [exit due to timed out]' + ), + toolCwd: '/home/user/projects/app' +}; + +export const execShellPendingSection: AgenticSection = toolSection( + BuiltInTool.SERVER_EXEC_SHELL_COMMAND, + { command: 'npm run build' }, + undefined, + AgenticSectionType.TOOL_CALL_PENDING +); + +export const fileGlobSearchSection = toolSection( + BuiltInTool.SERVER_FILE_GLOB_SEARCH, + { exclude: '**/node_modules/**', include: '**/*.svelte', path: 'src/lib/components' }, + JSON.stringify({ + plain_text_response: + 'src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessage.svelte\nsrc/lib/components/app/chat/ChatMessages/ChatMessageReasoningBlock.svelte\nsrc/lib/components/app/chat/ChatMessages/ChatMessageEditForm.svelte\n---\nTotal matches: 3' + }) +); + +export const grepSearchSection = toolSection( + BuiltInTool.SERVER_GREP_SEARCH, + { + include: '**/*.ts', + path: 'src/lib', + pattern: 'deriveAgenticSections', + return_line_numbers: true + }, + JSON.stringify({ + plain_text_response: + 'src/lib/utils/agentic.ts:209:export function deriveAgenticSections(\nsrc/lib/utils/index.ts:88:\tderiveAgenticSections,\n---\nTotal matches: 2' + }) +); + +export const runJavascriptSection = toolSection( + BuiltInTool.BROWSER_RUN_JAVASCRIPT, + { + code: 'const values = [3, 1, 2];\nconsole.log(values.sort());\nreturn values.length;', + timeout_ms: 5000 + }, + '[1,2,3]\n3' +); + +export const runJavascriptErrorSection = toolSection( + BuiltInTool.BROWSER_RUN_JAVASCRIPT, + { code: 'undefinedFunction();' }, + JSON.stringify({ error: 'ReferenceError: undefinedFunction is not defined' }) +); + +export const readMediaSection: AgenticSection = { + ...toolSection( + BuiltInTool.BROWSER_READ_MEDIA, + { path: '/home/user/charts/usage.svg' }, + 'File: /home/user/charts/usage.svg\nSize: 512 bytes\nMIME: image/svg+xml\n[Attachment saved: mcp-attachment-usage.svg]' + ), + toolResultExtras: [ + { + base64Url: CHART_IMAGE_URL, + name: 'mcp-attachment-usage.svg', + type: AttachmentType.IMAGE + } + ] +}; + +export const searchResultsSection = toolSection( + 'web_search_exa', + { query: 'llama.cpp speculative decoding' }, + [ + 'Title: Speculative decoding in llama.cpp', + 'URL: https://github.com/ggml-org/llama.cpp/tree/master/examples/speculative', + 'Published: 2025-03-14', + 'Author: N/A', + 'Highlights:', + 'Use a small draft model to propose tokens that the main model verifies in one batch.', + '---', + 'Title: llama-server README', + 'URL: https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md', + 'Published: N/A', + 'Author: ggml-org', + 'Highlights:', + 'The server accepts --model-draft to enable speculative decoding.' + ].join('\n') +); + +/* Reasoning sections */ + +export const reasoningSection: AgenticSection = { + content: REASONING_TEXT, + type: AgenticSectionType.REASONING +}; + +export const reasoningPendingSection: AgenticSection = { + content: REASONING_TEXT, + type: AgenticSectionType.REASONING_PENDING +}; + +export const reasoningInterruptedSection: AgenticSection = { + content: 'The user asks about the meaning of life. I should first check which', + type: AgenticSectionType.REASONING, + wasInterrupted: true +}; + +/* Store seeding */ + +export const promptProcessingState: ApiProcessingState = { + contextTotal: 32768, + contextUsed: 10000, + hasNextToken: false, + outputTokensMax: -1, + outputTokensUsed: 0, + progressPercent: 42, + promptProgress: { cache: 0, processed: 4200, time_ms: 6000, total: 10000 }, + promptTokens: 0, + speculative: false, + status: 'preparing', + temperature: 0.8, + tokensDecoded: 0, + tokensPerSecond: 0, + tokensRemaining: -1, + topP: 0.95 +}; + +export const generatingProcessingState: ApiProcessingState = { + contextTotal: 32768, + contextUsed: 45200, + hasNextToken: true, + outputTokensMax: -1, + outputTokensUsed: 128, + promptTokens: 42200, + speculative: false, + status: 'generating', + temperature: 0.8, + tokensDecoded: 128, + tokensPerSecond: 25, + tokensRemaining: -1, + topP: 0.95 +}; + +export interface ChatStorySeed { + settings?: Record; + /** Branch the compaction toggle reads its "before" size from. */ + activeMessages?: DatabaseMessage[]; + /** Marks the conversation as having a local pipe (chatStore.isLoading). */ + loading?: boolean; + /** Message id of a live stream (chatStore.isStreaming()). */ + streamingMessageId?: string; + processing?: ApiProcessingState; + compactingNodeId?: string; + /** Opens the edit form of this message on mount. */ + pendingEditMessageId?: string; +} + +// Pinned so stories look the same whatever the viewer has in localStorage. +const STORY_SETTINGS_DEFAULTS: Record = { + enableContinueGeneration: false, + renderThinkingAsMarkdown: true, + renderUserContentAsMarkdown: true, + showAgenticTurnStats: false, + showMessageStats: true, + showRawOutputSwitch: false +}; + +/** + * Seed the global stores a chat message reads. Use as a story `beforeEach`: + * it runs before render and the returned cleanup resets the stores, so state + * does not leak into the next story. + */ +export function seedChatStory(seed: ChatStorySeed = {}): () => void { + const settings = { ...STORY_SETTINGS_DEFAULTS, ...seed.settings }; + const previousSettings = Object.fromEntries( + Object.keys(settings).map((key) => [key, settingsStore.config[key]]) + ); + + for (const [key, value] of Object.entries(settings)) { + settingsStore.updateConfig(key, value); + } + + conversationsStore.activeConversation = { + currNode: null, + id: CONV_ID, + lastModified: NOW, + name: 'Storybook conversation' + }; + conversationsStore.activeMessages = seed.activeMessages ?? []; + + if (seed.loading) chatActivityStore.markLocal(CONV_ID); + + if (seed.streamingMessageId) { + chatStore.chatStreamingStates.set(CONV_ID, { + messageId: seed.streamingMessageId, + response: '' + }); + } + + if (seed.processing) { + chatStore.processing.setActiveConversation(CONV_ID); + chatStore.processing.setState(CONV_ID, seed.processing); + } + + if (seed.compactingNodeId) chatActivityStore.markCompacting(CONV_ID, seed.compactingNodeId); + + if (seed.pendingEditMessageId) chatStore.pendingEditMessageId = seed.pendingEditMessageId; + + return () => { + for (const [key, value] of Object.entries(previousSettings)) { + settingsStore.updateConfig(key, value); + } + + chatActivityStore.localEnded(CONV_ID); + chatActivityStore.endCompacting(CONV_ID); + chatStore.chatStreamingStates.delete(CONV_ID); + chatStore.processing.setState(CONV_ID, null); + chatStore.processing.setActiveConversation(null); + chatStore.pendingEditMessageId = null; + conversationsStore.activeMessages = []; + conversationsStore.activeConversation = null; + }; +} diff --git a/tools/ui/tests/stories/chat/screen/ChatScreen.stories.svelte b/tools/ui/tests/stories/chat/screen/ChatScreen.stories.svelte new file mode 100644 index 000000000000..b86d5e2c0945 --- /dev/null +++ b/tools/ui/tests/stories/chat/screen/ChatScreen.stories.svelte @@ -0,0 +1,240 @@ + + + { + const { canvas } = context; + + await expect(await canvas.findByText('Hello there')).toBeInTheDocument(); + await expect(canvas.getByRole('textbox')).toHaveFocus(); + await expect(canvas.getByRole('button', { name: 'Send' })).toBeDisabled(); + }} +/> + + { + const { canvas, step } = context; + + await step('type and send a message', async () => { + await send(context, 'What does quantization do?'); + }); + + await step('the message moves into the chat and the reply streams in', async () => { + await expect(await canvas.findByText('What does quantization do?')).toBeInTheDocument(); + await expect( + await canvas.findByText(REPLY_END, { exact: false }, { timeout: 8000 }) + ).toBeInTheDocument(); + }); + + await step('the form is ready for the next message', async () => { + await waitFor(() => expect(chatStore.isLoading).toBe(false)); + // the editor is empty again: at most its placeholder is left + await expect(canvas.getByRole('textbox')).toHaveTextContent(/^(Type a message\.\.\.)?$/); + await expect(conversationsStore.activeMessages.map((m) => m.role)).toEqual([ + 'user', + 'assistant' + ]); + }); + }} +/> + + { + const { canvas } = context; + + await expect( + await canvas.findByText('What is the difference between Q4_K_M and Q8_0?') + ).toBeInTheDocument(); + await expect(canvas.getByText('How do I run one with llama-server?')).toBeInTheDocument(); + await expect(canvas.getByRole('table')).toBeInTheDocument(); + await expect(canvas.queryByText('Hello there')).not.toBeVisible(); + }} +/> + + { + const { canvas } = context; + + await canvas.findByText('How do I run one with llama-server?'); + + await send(context, 'Which one fits in 8 GB of VRAM?'); + + await expect(await canvas.findByText('Which one fits in 8 GB of VRAM?')).toBeInTheDocument(); + await expect( + await canvas.findByText(REPLY_END, { exact: false }, { timeout: 8000 }) + ).toBeInTheDocument(); + + // the follow-up joins the existing branch: 4 earlier turns plus the new pair + await waitFor(() => expect(conversationsStore.activeMessages).toHaveLength(6)); + }} +/> + + { + const { canvas, step, userEvent } = context; + + await send(context, 'Tell me about quantization'); + + await step('stop the reply while it streams', async () => { + const stop = await canvas.findByRole('button', { name: 'Stop' }, { timeout: 4000 }); + + await canvas.findByText('Sure.', { exact: false }, { timeout: 8000 }); + await getPace(context).pause(); + await userEvent.click(stop); + }); + + await step('the partial reply stays and the form is ready again', async () => { + await waitFor(() => expect(chatStore.isLoading).toBe(false)); + await expect(canvas.getByText('Sure.', { exact: false })).toBeInTheDocument(); + await expect(canvas.queryByText(REPLY_END, { exact: false })).not.toBeInTheDocument(); + await expect(canvas.getByRole('button', { name: 'Send' })).toBeInTheDocument(); + }); + }} +/> + + { + await send(context, 'Summarize this very long document'); + + // the dialog is portalled to the body, outside the canvas + const page = within(document.body); + + await expect(await page.findByRole('alertdialog', {}, { timeout: 4000 })).toBeInTheDocument(); + await expect(page.getByText('Server Error')).toBeInTheDocument(); + await expect( + page.getByText('the request exceeds the available context size', { exact: false }) + ).toBeInTheDocument(); + }} +/> + + { + const restore = await setup()(context); + + serverStore.error = 'Failed to fetch server properties: connection refused'; + serverStore.status = 500; + + return () => { + serverStore.error = null; + serverStore.status = null; + restore(); + }; + }} + name="ServerUnavailable" + parameters={newChatRoute} + play={async (context) => { + const { canvas } = context; + + await expect(await canvas.findByText(/connection refused/)).toBeInTheDocument(); + // the markdown editor is a contenteditable, disabled by turning that off + await expect(canvas.getByRole('textbox')).toHaveAttribute('contenteditable', 'false'); + }} +/> diff --git a/tools/ui/tests/stories/chat/screen/ChatScreenActionScrollDown.stories.svelte b/tools/ui/tests/stories/chat/screen/ChatScreenActionScrollDown.stories.svelte new file mode 100644 index 000000000000..9c52fdd65105 --- /dev/null +++ b/tools/ui/tests/stories/chat/screen/ChatScreenActionScrollDown.stories.svelte @@ -0,0 +1,19 @@ + + + + +
+ console.log('scroll to bottom')} /> +
+
diff --git a/tools/ui/tests/stories/chat/screen/ChatScreenDragOverlay.stories.svelte b/tools/ui/tests/stories/chat/screen/ChatScreenDragOverlay.stories.svelte new file mode 100644 index 000000000000..7e6e8bca9566 --- /dev/null +++ b/tools/ui/tests/stories/chat/screen/ChatScreenDragOverlay.stories.svelte @@ -0,0 +1,20 @@ + + + +
+ Page content behind the overlay +
+ + +
diff --git a/tools/ui/tests/stories/chat/screen/ChatScreenGreeting.stories.svelte b/tools/ui/tests/stories/chat/screen/ChatScreenGreeting.stories.svelte new file mode 100644 index 000000000000..06b41eb32942 --- /dev/null +++ b/tools/ui/tests/stories/chat/screen/ChatScreenGreeting.stories.svelte @@ -0,0 +1,33 @@ + + + + seedAudio(false)} name="Default"> +
+ +
+
+ + seedAudio(true)} name="WithAudioModality"> +
+ +
+
diff --git a/tools/ui/tests/stories/chat/screen/ChatScreenServerError.stories.svelte b/tools/ui/tests/stories/chat/screen/ChatScreenServerError.stories.svelte new file mode 100644 index 000000000000..70fc6cfe78f2 --- /dev/null +++ b/tools/ui/tests/stories/chat/screen/ChatScreenServerError.stories.svelte @@ -0,0 +1,56 @@ + + + + seedServer({ error: 'Failed to fetch server properties: connection refused', status: 500 })} + name="Default" +> +
+ +
+
+ + + seedServer({ + error: 'Failed to fetch server properties: connection refused', + loading: true, + status: 500 + })} + name="Retrying" +> +
+ +
+
+ + + seedServer({ error: 'Loading model', status: 503 })} + name="LoadingModel" +> +
+ +
+
diff --git a/tools/ui/tests/stories/chat/screen/ChatScreenStreamResumeStatus.stories.svelte b/tools/ui/tests/stories/chat/screen/ChatScreenStreamResumeStatus.stories.svelte new file mode 100644 index 000000000000..a74933888160 --- /dev/null +++ b/tools/ui/tests/stories/chat/screen/ChatScreenStreamResumeStatus.stories.svelte @@ -0,0 +1,27 @@ + + + + { + chatStore.streamConnectionState = StreamConnectionState.RESUMING; + }} + name="Default" +> +
+ +
+
diff --git a/tools/ui/tests/stories/chat/screen/attachments/ChatAttachmentsList.stories.svelte b/tools/ui/tests/stories/chat/screen/attachments/ChatAttachmentsList.stories.svelte new file mode 100644 index 000000000000..b71fed624016 --- /dev/null +++ b/tools/ui/tests/stories/chat/screen/attachments/ChatAttachmentsList.stories.svelte @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/ui/tests/stories/chat/screen/attachments/ChatAttachmentsListItemMcpResource.stories.svelte b/tools/ui/tests/stories/chat/screen/attachments/ChatAttachmentsListItemMcpResource.stories.svelte new file mode 100644 index 000000000000..54df23f2743d --- /dev/null +++ b/tools/ui/tests/stories/chat/screen/attachments/ChatAttachmentsListItemMcpResource.stories.svelte @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + console.log('remove', id)} + {onclick} + /> + + + + + + + + + + + diff --git a/tools/ui/tests/stories/chat/screen/attachments/ChatAttachmentsPreview.stories.svelte b/tools/ui/tests/stories/chat/screen/attachments/ChatAttachmentsPreview.stories.svelte index f7f828f33f5c..6416ae908507 100644 --- a/tools/ui/tests/stories/chat/screen/attachments/ChatAttachmentsPreview.stories.svelte +++ b/tools/ui/tests/stories/chat/screen/attachments/ChatAttachmentsPreview.stories.svelte @@ -1,4 +1,14 @@ + + +
+ +
+
+ + +
+ +
+
+ + +
+ +
+
+ + + +
+ +
+
+ + + +
+ +
+
+ + +
+ +
+
+ + + +
+ +
+
+ + +
+ +
+
+ + +
+ +
+
+ + +
+ +
+
+ Date.now() - minutes * 60_000; +const turn = ( + id: string, + parent: string | null, + children: string[], + fields: Partial +): DatabaseMessage => ({ + children, + content: '', + convId: SCREEN_CONVERSATION_ID, + id, + parent, + role: MessageRole.USER, + timestamp: minutesAgo(10), + toolCalls: '', + type: MessageType.TEXT, + ...fields +}); + +/** A finished conversation in the export format, written to IndexedDB as the app would import it. */ +export const screenConversation: ExportedConversation = { + conv: { + currNode: 'a2', + id: SCREEN_CONVERSATION_ID, + lastModified: minutesAgo(2), + name: 'Running GGUF models locally' + }, + messages: [ + turn('root', null, ['u1'], { role: MessageRole.SYSTEM, type: MessageType.ROOT }), + turn('u1', 'root', ['a1'], { + content: 'What is the difference between Q4_K_M and Q8_0?', + timestamp: minutesAgo(9) + }), + turn('a1', 'u1', ['u2'], { + content: + 'Both are GGUF quantization types:\n\n| Type | Bits per weight | Quality |\n| --- | --- | --- |\n| Q4_K_M | ~4.8 | good |\n| Q8_0 | ~8.5 | near lossless |\n\nPick **Q4_K_M** when memory is tight and **Q8_0** when quality matters most.', + model: MODEL_NAME, + reasoningContent: + 'The user compares two quant types. Give bits per weight and the trade-off, keep it short.', + role: MessageRole.ASSISTANT, + timestamp: minutesAgo(8), + timings: { predicted_ms: 3100, predicted_n: 96, prompt_ms: 180, prompt_n: 42 } + }), + turn('u2', 'a1', ['a2'], { + content: 'How do I run one with llama-server?', + timestamp: minutesAgo(3) + }), + turn('a2', 'u2', [], { + content: + 'Point the server at the file and open the web UI:\n\n```sh\nllama-server -m Qwen3-8B-Q4_K_M.gguf --port 9931\n```\n\nThen visit `http://localhost:9931`.', + model: MODEL_NAME, + role: MessageRole.ASSISTANT, + timestamp: minutesAgo(2), + timings: { cache_n: 120, predicted_ms: 2400, predicted_n: 64, prompt_ms: 90, prompt_n: 30 } + }) + ] +}; + +export interface FakeServerOptions { + /** Text streamed back for a chat completion. */ + reply?: string; + /** Delay between streamed chunks, in ms. */ + chunkDelayMs?: number; + /** HTTP status for the completion request; anything but 200 is an error reply. */ + status?: number; + /** Error message sent with a failed completion. */ + errorMessage?: string; +} + +const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); +const json = (body: unknown, status = 200) => + new Response(JSON.stringify(body), { headers: { 'Content-Type': 'application/json' }, status }); + +function streamReply(reply: string, chunkDelayMs: number, signal?: AbortSignal | null): Response { + const encoder = new TextEncoder(); + const words = reply.split(/(?<= )/); + const sse = (data: unknown) => encoder.encode(`data: ${JSON.stringify(data)}\n\n`); + const body = new ReadableStream({ + async start(controller) { + for (const word of words) { + if (signal?.aborted) return controller.error(new DOMException('Aborted', 'AbortError')); + + controller.enqueue( + sse({ choices: [{ delta: { content: word }, index: 0 }], model: MODEL_NAME }) + ); + await sleep(chunkDelayMs); + } + + controller.enqueue( + sse({ + choices: [{ delta: {}, finish_reason: 'stop', index: 0 }], + model: MODEL_NAME, + timings: { + predicted_ms: words.length * chunkDelayMs, + predicted_n: words.length, + prompt_ms: 40, + prompt_n: 24 + } + }) + ); + controller.enqueue(encoder.encode('data: [DONE]\n\n')); + controller.close(); + } + }); + + return new Response(body, { headers: { 'Content-Type': 'text/event-stream' } }); +} + +/** + * Stand-in for llama-server: answers chat completions with a streamed reply and + * every other API call with a harmless empty result. Returns the restore. + */ +export function installFakeServer(options: FakeServerOptions = {}): () => void { + const { chunkDelayMs = 30, errorMessage = 'Internal server error', reply = REPLY_TEXT } = options; + const status = options.status ?? 200; + const realFetch = window.fetch; + + window.fetch = async (input, init) => { + const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url; + + if (url.includes('/v1/chat/completions') && !url.includes('/control')) { + if (status !== 200) return json({ error: { code: status, message: errorMessage } }, status); + + const body = JSON.parse(String(init?.body ?? '{}')); + + if (!body.stream) { + return json({ + choices: [{ message: { content: reply, role: 'assistant' } }], + timings: { cache_n: 0, prompt_n: 24 } + }); + } + + return streamReply(reply, chunkDelayMs, init?.signal); + } + + if (url.includes('/props')) return json(modelServerProps()); + + if (url.includes('/v1/models')) return json({ data: [], object: 'list' }); + + return json({}, 404); + }; + + return () => { + window.fetch = realFetch; + }; +} + +/** Single-model server state plus an empty new-chat screen. */ +export function seedNewChat(): () => void { + const restore = seedStores({ + activeConversation: null, + activeMessages: [], + config: { conversationTabs: false, showMessageStats: true }, + serverProps: modelServerProps(), + serverRole: ServerRole.MODEL + }); + + chatStore.dismissErrorDialog(); + + return restore; +} + +/** Writes the fixture conversation to IndexedDB and opens it like the chat route does. */ +export async function openScreenConversation(): Promise { + await DatabaseService.deleteConversation(SCREEN_CONVERSATION_ID).catch(() => {}); + await DatabaseService.importConversations([structuredClone(screenConversation)]); + await conversationsStore.loadConversations(); + await conversationsStore.loadConversation(SCREEN_CONVERSATION_ID); +} diff --git a/tools/ui/tests/stories/chat/screen/fixtures.ts b/tools/ui/tests/stories/chat/screen/fixtures.ts new file mode 100644 index 000000000000..67336f49904f --- /dev/null +++ b/tools/ui/tests/stories/chat/screen/fixtures.ts @@ -0,0 +1,286 @@ +import photoUrl from '../../fixtures/assets/1.jpg'; +import clipVideoUrl from '../../fixtures/assets/clip.webm'; +import hfLogoUrl from '../../fixtures/assets/hf-logo.svg'; +import toneAudioUrl from '../../fixtures/assets/tone.wav'; +import { AttachmentType, SpecialFileType } from '$lib/enums'; +import type { + DatabaseMessageExtraAudioFile, + DatabaseMessageExtraImageFile, + DatabaseMessageExtraLegacyContext, + DatabaseMessageExtraMcpPrompt, + DatabaseMessageExtraMcpResource, + DatabaseMessageExtraPdfFile, + DatabaseMessageExtraTextFile, + DatabaseMessageExtraVideoFile, + MCPResourceAttachment +} from '$lib/types'; + +export { clipVideoUrl, hfLogoUrl, photoUrl, toneAudioUrl }; + +export const gradientImageUrl = `data:image/svg+xml;utf8,${encodeURIComponent( + '' +)}`; + +export const sampleCode = `import { serverStore } from '$lib/stores'; + +export async function loadProps(): Promise { + await serverStore.fetch(); + + if (serverStore.error) { + console.error('Server unavailable:', serverStore.error); + } +} +`; + +export const sampleNotes = `Meeting notes - release planning + +- Ship the matte glass surfaces behind a flag first. +- Collect feedback from the nightly build users. +- Remove the flag once the dark theme contrast is fixed. +- Follow up on the attachment preview performance numbers from last week.`; + +export const samplePdfText = `Attention Is All You Need + +Abstract. The dominant sequence transduction models are based on complex recurrent or convolutional neural networks that include an encoder and a decoder.`; + +// Stored message attachments (DatabaseMessageExtra) + +export const imageAttachment: DatabaseMessageExtraImageFile = { + base64Url: photoUrl, + name: 'mountain-lake.jpg', + size: 44_891, + type: AttachmentType.IMAGE +}; + +export const logoAttachment: DatabaseMessageExtraImageFile = { + base64Url: hfLogoUrl, + name: 'hf-logo.svg', + size: 35_285, + type: AttachmentType.IMAGE +}; + +export const gradientAttachment: DatabaseMessageExtraImageFile = { + base64Url: gradientImageUrl, + name: 'gradient.svg', + size: 412, + type: AttachmentType.IMAGE +}; + +export const textAttachment: DatabaseMessageExtraTextFile = { + content: sampleCode, + name: 'load-props.ts', + size: sampleCode.length, + type: AttachmentType.TEXT +}; + +export const notesAttachment: DatabaseMessageExtraTextFile = { + content: sampleNotes, + name: 'notes.md', + size: sampleNotes.length, + type: AttachmentType.TEXT +}; + +export const legacyContextAttachment: DatabaseMessageExtraLegacyContext = { + content: 'Pasted context from the old UI.', + name: 'Pasted content', + type: AttachmentType.LEGACY_CONTEXT +}; + +// PDF pages are pre-rendered so the preview does not need pdf.js +export const pdfAttachment: DatabaseMessageExtraPdfFile = { + base64Data: '', + content: samplePdfText, + images: [photoUrl, gradientImageUrl], + name: 'attention-is-all-you-need.pdf', + processedAsImages: false, + size: 2_215_244, + type: AttachmentType.PDF +}; + +export const pdfAsImagesAttachment: DatabaseMessageExtraPdfFile = { + ...pdfAttachment, + name: 'scanned-invoice.pdf', + processedAsImages: true, + size: 351_048 +}; + +export const audioAttachment: DatabaseMessageExtraAudioFile = { + base64Data: '', + mimeType: 'audio/wav', + name: 'voice-memo.wav', + size: 8_078, + type: AttachmentType.AUDIO +}; + +export const videoAttachment: DatabaseMessageExtraVideoFile = { + base64Data: '', + mimeType: 'video/webm', + name: 'screen-recording.webm', + size: 8_101, + type: AttachmentType.VIDEO +}; + +export const mcpPromptAttachment: DatabaseMessageExtraMcpPrompt = { + arguments: { language: 'TypeScript', topic: 'error handling' }, + content: + 'Review the following TypeScript code and suggest improvements for error handling. Focus on edge cases.', + name: 'code-review', + promptName: 'code-review', + serverName: 'github', + type: AttachmentType.MCP_PROMPT +}; + +export const mcpResourceAttachment: DatabaseMessageExtraMcpResource = { + content: '# llama.cpp\n\nInference of LLMs in pure C/C++.', + mimeType: 'text/markdown', + name: 'README.md', + serverName: 'filesystem', + type: AttachmentType.MCP_RESOURCE, + uri: 'file:///workspace/llama.cpp/README.md' +}; + +export const mcpResourceImageAttachment: DatabaseMessageExtraMcpResource = { + content: '', + mimeType: 'image/png', + name: 'architecture.png', + serverName: 'filesystem', + type: AttachmentType.MCP_RESOURCE, + uri: 'file:///workspace/docs/architecture.png' +}; + +export function toMcpResourceAttachment( + extra: DatabaseMessageExtraMcpResource, + overrides: Partial = {} +): MCPResourceAttachment { + return { + id: `resource-${extra.name}`, + resource: { + mimeType: extra.mimeType, + name: extra.name, + serverName: extra.serverName, + title: extra.name, + uri: extra.uri + }, + ...overrides + }; +} + +// Pending uploads (ChatUploadedFile) + +export function createUploadedFile( + name: string, + type: string, + extra: Partial = {} +): ChatUploadedFile { + const content = extra.textContent ?? ''; + + return { + file: new File([content], name, { type }), + id: `upload-${name}`, + name, + size: extra.size ?? content.length, + type, + ...extra + }; +} + +export const uploadedImage = createUploadedFile('mountain-lake.jpg', 'image/jpeg', { + preview: photoUrl, + size: 44_891 +}); + +export const uploadedLogo = createUploadedFile('hf-logo.svg', 'image/svg+xml', { + preview: hfLogoUrl, + size: 35_285 +}); + +export const uploadedGradient = createUploadedFile('gradient.svg', 'image/svg+xml', { + preview: gradientImageUrl, + size: 412 +}); + +export const uploadedText = createUploadedFile('load-props.ts', 'text/typescript', { + textContent: sampleCode +}); + +export const uploadedNotes = createUploadedFile('notes.md', 'text/markdown', { + textContent: sampleNotes +}); + +export const uploadedPdf = createUploadedFile('attention-is-all-you-need.pdf', 'application/pdf', { + size: 2_215_244, + textContent: samplePdfText +}); + +export const uploadedAudio = createUploadedFile('voice-memo.wav', 'audio/wav', { + preview: toneAudioUrl, + size: 8_078 +}); + +export const uploadedVideo = createUploadedFile('screen-recording.webm', 'video/webm', { + preview: clipVideoUrl, + size: 8_101 +}); + +export const uploadedArchive = createUploadedFile('dataset.zip', 'application/zip', { + size: 5_242_880 +}); + +export const uploadedMcpPrompt = createUploadedFile('summarize-issue', SpecialFileType.MCP_PROMPT, { + mcpPrompt: { + arguments: { issue: '#31273' }, + promptName: 'summarize-issue', + serverName: 'github' + }, + textContent: 'Summarize the discussion in issue #31273 and list the open questions.' +}); + +export const uploadedMcpPromptLoading = createUploadedFile( + 'triage-bug', + SpecialFileType.MCP_PROMPT, + { + isLoading: true, + mcpPrompt: { arguments: { label: 'bug' }, promptName: 'triage-bug', serverName: 'github' } + } +); + +export const uploadedMcpPromptError = createUploadedFile( + 'release-notes', + SpecialFileType.MCP_PROMPT, + { + loadError: 'MCP server "github" is not connected', + mcpPrompt: { promptName: 'release-notes', serverName: 'github' } + } +); + +// Conversations for the tab strip + +export const tabConversations: DatabaseConversation[] = [ + { currNode: 'm-1', id: 'conv-1', lastModified: Date.now() - 60_000, name: 'Rust borrow checker' }, + { currNode: 'm-2', id: 'conv-2', lastModified: Date.now() - 120_000, name: 'Trip to Kyoto' }, + { currNode: 'm-3', id: 'conv-3', lastModified: Date.now() - 180_000, name: 'GGUF quantization' }, + { + currNode: 'm-4', + id: 'conv-4', + lastModified: Date.now() - 240_000, + name: 'A very long conversation title that has to be truncated inside the tab' + }, + { currNode: 'm-5', id: 'conv-5', lastModified: Date.now() - 300_000, name: 'Sourdough starter' }, + { + currNode: 'm-6', + id: 'conv-6', + lastModified: Date.now() - 360_000, + name: 'SQL window functions' + }, + { + currNode: 'm-7', + id: 'conv-7', + lastModified: Date.now() - 420_000, + name: 'Weekly report draft' + }, + { currNode: 'm-8', id: 'conv-8', lastModified: Date.now() - 480_000, name: 'Svelte 5 runes' }, + { currNode: 'm-9', id: 'conv-9', lastModified: Date.now() - 540_000, name: 'Bike maintenance' }, + { currNode: 'm-10', id: 'conv-10', lastModified: Date.now() - 600_000, name: 'Tax questions' }, + { currNode: 'm-11', id: 'conv-11', lastModified: Date.now() - 660_000, name: 'Piano practice' }, + { currNode: 'm-12', id: 'conv-12', lastModified: Date.now() - 720_000, name: 'CUDA kernels' } +]; diff --git a/tools/ui/tests/stories/chat/screen/tabs/ChatTabs.stories.svelte b/tools/ui/tests/stories/chat/screen/tabs/ChatTabs.stories.svelte new file mode 100644 index 000000000000..d2ba1458e775 --- /dev/null +++ b/tools/ui/tests/stories/chat/screen/tabs/ChatTabs.stories.svelte @@ -0,0 +1,96 @@ + + + seedTabs(['conv-1', 'conv-2', 'conv-3'])} + name="Default" + parameters={chatRoute('conv-2')} +> +
+ +
+
+ + + seedTabs(['conv-1', 'conv-2', NEW_CHAT_TAB_ID])} + name="NewChatTabActive" + parameters={newChatRoute} +> +
+ +
+
+ + seedTabs(['conv-1', 'conv-2', 'conv-3', 'conv-5'], ['conv-1', 'conv-3'])} + name="WithLoadingTabs" + parameters={chatRoute('conv-1')} +> +
+ +
+
+ + + + seedTabs( + tabConversations.map((c) => c.id), + ['conv-6'] + )} + name="ManyTabsOverflow" + parameters={chatRoute('conv-9')} +> +
+ +
+
+ + + seedTabs(['conv-1', 'conv-missing'])} + name="UnnamedChat" + parameters={chatRoute('conv-missing')} +> +
+ +
+
diff --git a/tools/ui/tests/stories/chat/screen/tabs/ChatTabsItem.stories.svelte b/tools/ui/tests/stories/chat/screen/tabs/ChatTabsItem.stories.svelte new file mode 100644 index 000000000000..e2b9d89888fb --- /dev/null +++ b/tools/ui/tests/stories/chat/screen/tabs/ChatTabsItem.stories.svelte @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/ui/tests/stories/content/CollapsibleTerminalBlock.stories.svelte b/tools/ui/tests/stories/content/CollapsibleTerminalBlock.stories.svelte new file mode 100644 index 000000000000..d54ed8ac0e07 --- /dev/null +++ b/tools/ui/tests/stories/content/CollapsibleTerminalBlock.stories.svelte @@ -0,0 +1,26 @@ + + + +
+ +
running 3 tests
+test borrow::longest ... ok
+test borrow::shorter ... ok
+test borrow::equal ... ok
+
+test result: ok. 3 passed; 0 failed
+
+
+
diff --git a/tools/ui/tests/stories/content/MarkdownContent.stories.svelte b/tools/ui/tests/stories/content/MarkdownContent.stories.svelte new file mode 100644 index 000000000000..c0b0c092b1f1 --- /dev/null +++ b/tools/ui/tests/stories/content/MarkdownContent.stories.svelte @@ -0,0 +1,18 @@ + + + diff --git a/tools/ui/tests/stories/content/SyntaxHighlightedCode.stories.svelte b/tools/ui/tests/stories/content/SyntaxHighlightedCode.stories.svelte new file mode 100644 index 000000000000..22fc0265602a --- /dev/null +++ b/tools/ui/tests/stories/content/SyntaxHighlightedCode.stories.svelte @@ -0,0 +1,23 @@ + + + diff --git a/tools/ui/tests/stories/design-system/actions/Button.stories.svelte b/tools/ui/tests/stories/design-system/actions/Button.stories.svelte new file mode 100644 index 000000000000..bae3dca69ad1 --- /dev/null +++ b/tools/ui/tests/stories/design-system/actions/Button.stories.svelte @@ -0,0 +1,54 @@ + + + + + {#each variants as variant (variant)} + +
+ {#each sizes as size (size)} + + {/each} + + + + +
+
+ {/each} + + +
+ + + +
+
+
+
diff --git a/tools/ui/tests/stories/design-system/actions/ButtonGroup.stories.svelte b/tools/ui/tests/stories/design-system/actions/ButtonGroup.stories.svelte new file mode 100644 index 000000000000..1eb26a689567 --- /dev/null +++ b/tools/ui/tests/stories/design-system/actions/ButtonGroup.stories.svelte @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/ui/tests/stories/design-system/actions/Toggle.stories.svelte b/tools/ui/tests/stories/design-system/actions/Toggle.stories.svelte new file mode 100644 index 000000000000..aef35b598846 --- /dev/null +++ b/tools/ui/tests/stories/design-system/actions/Toggle.stories.svelte @@ -0,0 +1,66 @@ + + + + + + + + + + + + + +
+ + + +
+
+ + +
+ Wrap + + Wrap + + Wrap +
+
+ + + + + + +
+ + + Toggle + + + + Wrap + + + + +
+
+
+
diff --git a/tools/ui/tests/stories/design-system/actions/ToggleGroup.stories.svelte b/tools/ui/tests/stories/design-system/actions/ToggleGroup.stories.svelte new file mode 100644 index 000000000000..e8969469c04e --- /dev/null +++ b/tools/ui/tests/stories/design-system/actions/ToggleGroup.stories.svelte @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + Tools + + Vision + + Audio + + + + + + Tools + + Vision + + Audio + + + + +
+ {#each sizes as size (size)} + + + + + + {/each} +
+
+ + + + + + + + +
+
diff --git a/tools/ui/tests/stories/design-system/display/Alert.stories.svelte b/tools/ui/tests/stories/design-system/display/Alert.stories.svelte new file mode 100644 index 000000000000..01e22f05482d --- /dev/null +++ b/tools/ui/tests/stories/design-system/display/Alert.stories.svelte @@ -0,0 +1,77 @@ + + + + + + + + + Model is loading + + The first reply can take a few seconds. + + + + + + + + Context is full + + Start a new chat or remove some attachments. + + + + + + + + Model loaded + + Qwen 2.5 7B is ready on port 9931. + + + + + + + + Low memory + + Gemma 2 27B needs 16.6 GB; 12 GB is free. + + + + + + + + Update available + + llama.cpp b9726 adds faster prompt processing. + + + + + + + + Saved to this browser + + + + diff --git a/tools/ui/tests/stories/design-system/display/Badge.stories.svelte b/tools/ui/tests/stories/design-system/display/Badge.stories.svelte new file mode 100644 index 000000000000..1d1ba63db059 --- /dev/null +++ b/tools/ui/tests/stories/design-system/display/Badge.stories.svelte @@ -0,0 +1,35 @@ + + + + + {#each variants as variant (variant)} + + Q4_K_M + + {/each} + + diff --git a/tools/ui/tests/stories/design-system/display/Card.stories.svelte b/tools/ui/tests/stories/design-system/display/Card.stories.svelte new file mode 100644 index 000000000000..07458de7edeb --- /dev/null +++ b/tools/ui/tests/stories/design-system/display/Card.stories.svelte @@ -0,0 +1,33 @@ + + + + + + Qwen3.8-27B + + 131k context, vision and tool use + + + + Loaded on the server and ready to answer. + + + + + + + + + diff --git a/tools/ui/tests/stories/design-system/display/Collapsible.stories.svelte b/tools/ui/tests/stories/design-system/display/Collapsible.stories.svelte new file mode 100644 index 000000000000..f86c2c921249 --- /dev/null +++ b/tools/ui/tests/stories/design-system/display/Collapsible.stories.svelte @@ -0,0 +1,52 @@ + + +{#snippet section(open: boolean)} + +
+ Advanced sampling + + + {#snippet child({ props })} + + {/snippet} + +
+ +
temperature 0.8
+ + +
top_p 0.95
+ +
min_p 0.05
+
+
+{/snippet} + + + + + {@render section(false)} + + + + {@render section(true)} + + + diff --git a/tools/ui/tests/stories/design-system/display/Empty.stories.svelte b/tools/ui/tests/stories/design-system/display/Empty.stories.svelte new file mode 100644 index 000000000000..00d9bbecb4bb --- /dev/null +++ b/tools/ui/tests/stories/design-system/display/Empty.stories.svelte @@ -0,0 +1,32 @@ + + + + + + + + + + No conversations yet + + Your chats are saved in this browser and show up here. + + + + + + + diff --git a/tools/ui/tests/stories/design-system/display/ScrollArea.stories.svelte b/tools/ui/tests/stories/design-system/display/ScrollArea.stories.svelte new file mode 100644 index 000000000000..25bf97f838a9 --- /dev/null +++ b/tools/ui/tests/stories/design-system/display/ScrollArea.stories.svelte @@ -0,0 +1,29 @@ + + + + +
+

Conversations

+ + {#each chats as chat (chat)} +
{chat}
+ + + {/each} +
+
+
diff --git a/tools/ui/tests/stories/design-system/display/Separator.stories.svelte b/tools/ui/tests/stories/design-system/display/Separator.stories.svelte new file mode 100644 index 000000000000..f628280c2cde --- /dev/null +++ b/tools/ui/tests/stories/design-system/display/Separator.stories.svelte @@ -0,0 +1,34 @@ + + + +
+

Qwen3.8-27B

+ +

Loaded, 131k context

+ + + +
+ Chat + + + + Models + + + + Settings +
+
+
diff --git a/tools/ui/tests/stories/design-system/display/Skeleton.stories.svelte b/tools/ui/tests/stories/design-system/display/Skeleton.stories.svelte new file mode 100644 index 000000000000..c92823c3b76b --- /dev/null +++ b/tools/ui/tests/stories/design-system/display/Skeleton.stories.svelte @@ -0,0 +1,40 @@ + + + + + +
+ + + + + +
+
+ + +
+ + +
+ + + +
+
+
+
+
diff --git a/tools/ui/tests/stories/design-system/display/Table.stories.svelte b/tools/ui/tests/stories/design-system/display/Table.stories.svelte new file mode 100644 index 000000000000..dafa12ab47b4 --- /dev/null +++ b/tools/ui/tests/stories/design-system/display/Table.stories.svelte @@ -0,0 +1,60 @@ + + + +
+ + Models on this server + + + + Model + + Quant + + Context + + Size + + + + + {#each rows as row (row.model + row.quant)} + + {row.model} + + {row.quant} + + {row.context} + + {row.size} + + {/each} + + + + + Total + + 47.1 GB + + + +
+
diff --git a/tools/ui/tests/stories/design-system/forms/Checkbox.stories.svelte b/tools/ui/tests/stories/design-system/forms/Checkbox.stories.svelte new file mode 100644 index 000000000000..f16068b03801 --- /dev/null +++ b/tools/ui/tests/stories/design-system/forms/Checkbox.stories.svelte @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/ui/tests/stories/design-system/forms/Input.stories.svelte b/tools/ui/tests/stories/design-system/forms/Input.stories.svelte new file mode 100644 index 000000000000..e1af669063bf --- /dev/null +++ b/tools/ui/tests/stories/design-system/forms/Input.stories.svelte @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/ui/tests/stories/design-system/forms/Label.stories.svelte b/tools/ui/tests/stories/design-system/forms/Label.stories.svelte new file mode 100644 index 000000000000..e10be626a1cc --- /dev/null +++ b/tools/ui/tests/stories/design-system/forms/Label.stories.svelte @@ -0,0 +1,21 @@ + + + +
+ + + +
+
diff --git a/tools/ui/tests/stories/design-system/forms/RadioGroup.stories.svelte b/tools/ui/tests/stories/design-system/forms/RadioGroup.stories.svelte new file mode 100644 index 000000000000..05f1aa80bf0f --- /dev/null +++ b/tools/ui/tests/stories/design-system/forms/RadioGroup.stories.svelte @@ -0,0 +1,43 @@ + + + + + + + {#each options as option (option)} + + {/each} + + + + + + {#each options as option (option)} + + {/each} + + + + diff --git a/tools/ui/tests/stories/design-system/forms/Select.stories.svelte b/tools/ui/tests/stories/design-system/forms/Select.stories.svelte new file mode 100644 index 000000000000..70c43507af2f --- /dev/null +++ b/tools/ui/tests/stories/design-system/forms/Select.stories.svelte @@ -0,0 +1,60 @@ + + + + + + + Choose a theme + + + + + + Dark + + + + + + System + + + + +
+ + Light + + + + Theme + + {#each themes as theme (theme.value)} + + {/each} + + + +
+
+
+
diff --git a/tools/ui/tests/stories/design-system/forms/Switch.stories.svelte b/tools/ui/tests/stories/design-system/forms/Switch.stories.svelte new file mode 100644 index 000000000000..119c0745c085 --- /dev/null +++ b/tools/ui/tests/stories/design-system/forms/Switch.stories.svelte @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/ui/tests/stories/design-system/forms/Textarea.stories.svelte b/tools/ui/tests/stories/design-system/forms/Textarea.stories.svelte new file mode 100644 index 000000000000..f1c36ea4420f --- /dev/null +++ b/tools/ui/tests/stories/design-system/forms/Textarea.stories.svelte @@ -0,0 +1,34 @@ + + + + + +