ui: Restructure repo to use tools/ui folder and ui / UI / llama-ui / LLAMA_UI naming (#23064)

* webui: Move static build output from `tools/server/public` to `build/ui` directory

* refactor: Move to `tools/ui`

* refactor: rename CMake variables and preprocessor defines

- Rename LLAMA_BUILD_WEBUI -> LLAMA_BUILD_UI (old kept as deprecated)
- Rename LLAMA_USE_PREBUILT_WEBUI -> LLAMA_USE_PREBUILT_UI (old kept as deprecated)
- Backward compat: old vars auto-forward to new ones with DEPRECATION warning
- Rename internal vars: WEBUI_SOURCE -> UI_SOURCE, WEBUI_SOURCE_DIR -> UI_SOURCE_DIR, etc.
- Rename HF bucket: LLAMA_WEBUI_HF_BUCKET -> LLAMA_UI_HF_BUCKET
- Emit both LLAMA_BUILD_WEBUI and LLAMA_BUILD_UI preprocessor defines
- Emit both LLAMA_WEBUI_DEFAULT_ENABLED and LLAMA_UI_DEFAULT_ENABLED

* refactor: rename CLI flags (--webui -> --ui) with backward compat

- Add --ui/--no-ui (old --webui/--no-webui kept as deprecated aliases)
- Add --ui-config (old --webui-config kept as deprecated alias)
- Add --ui-config-file (old --webui-config-file kept as deprecated alias)
- Add --ui-mcp-proxy/--no-ui-mcp-proxy (old --webui-mcp-proxy kept as deprecated)
- Add new env vars: LLAMA_ARG_UI, LLAMA_ARG_UI_CONFIG, LLAMA_ARG_UI_CONFIG_FILE, LLAMA_ARG_UI_MCP_PROXY
- C++ struct fields: params.ui, params.ui_config_json, params.ui_mcp_proxy added alongside old fields
- Backward compat: old fields synced to new ones in g_params_to_internals

* refactor: update C++ server internals with backward compat

- Rename json_webui_settings -> json_ui_settings (both kept in server_context_meta)
- Rename params.webui usage -> params.ui (both synced, old still works)
- JSON API emits both "ui"/"ui_settings" and "webui"/"webui_settings" keys
- Server routes use params.ui_mcp_proxy || params.webui_mcp_proxy
- Preprocessor guards use #if defined(LLAMA_BUILD_UI) || defined(LLAMA_BUILD_WEBUI)

* refactor: rename CI/CD workflows, artifacts, and build script

- Rename webui-build.yml -> ui-build.yml; artifact webui-build -> ui-build
- Rename webui-publish.yml -> ui-publish.yml; var HF_BUCKET_WEBUI_STATIC_OUTPUT -> HF_BUCKET_UI_STATIC_OUTPUT
- Rename server-webui.yml -> server-ui.yml; job webui-build/checks -> ui-build/checks
- Update server.yml: job/artifact refs webui-build -> ui-build
- Update release.yml: all webui-build/publish refs -> ui-build/publish; HF_TOKEN_WEBUI_STATIC_OUTPUT -> HF_TOKEN_UI_STATIC_OUTPUT
- Update server-self-hosted.yml: webui-build -> ui-build
- Update build-self-hosted.yml: HF_WEBUI_VERSION -> HF_UI_VERSION
- Rename webui-download.cmake -> ui-download.cmake (internal refs updated)
- Update labeler.yml: server/webui -> server/ui path label

* docs: update CODEOWNERS and server README docs

- Update CODEOWNERS: team ggml-org/llama-webui -> ggml-org/llama-ui, path /tools/server/webui/ -> /tools/ui/
- Update server README.md: CLI tables show --ui flags with deprecated --webui aliases
- Update server README-dev.md: "WebUI" -> "UI", paths updated to tools/ui/

* fix: Small fixes for UI build

* fix: CMake.txt syntax

* chore: Formatting

* fix: `.editorconfig` for llama-ui

* chore: Formatting

* refactor: Use `APP_NAME` in Error route

* refactor: Cleanup

* refactor: Single migration service

* make llama-ui a linkable target

* fix: UI Build output

* fix: Missing change

* fix: separate llama-ui npm build output into build/tools/ui/dist subfolder + use cmake npm build instead of downloading ui-build.yml artifacts in CI

* refactor: UI workflows cleanup

---------

Co-authored-by: Xuan Son Nguyen <son@huggingface.co>
This commit is contained in:
Aleksander Grygier
2026-05-16 02:02:40 +02:00
committed by GitHub
co-authored by Xuan Son Nguyen
parent 49d1701bd2
commit 59778f0196
565 changed files with 1610 additions and 694 deletions
@@ -0,0 +1,394 @@
<script lang="ts">
import { FolderOpen, Plus, Loader2, Braces } from '@lucide/svelte';
import { toast } from 'svelte-sonner';
import * as Dialog from '$lib/components/ui/dialog';
import { Button } from '$lib/components/ui/button';
import { mcpStore } from '$lib/stores/mcp.svelte';
import { conversationsStore } from '$lib/stores/conversations.svelte';
import {
mcpResources,
mcpTotalResourceCount,
mcpResourceStore
} from '$lib/stores/mcp-resources.svelte';
import {
McpResourcesBrowser,
McpResourcePreview,
McpResourceTemplateForm
} from '$lib/components/app';
import { getResourceDisplayName } from '$lib/utils';
import type { MCPResourceInfo, MCPResourceContent, MCPResourceTemplateInfo } from '$lib/types';
import { SvelteSet } from 'svelte/reactivity';
interface Props {
open?: boolean;
onOpenChange?: (open: boolean) => void;
onAttach?: (resource: MCPResourceInfo) => void;
preSelectedUri?: string;
}
let { open = $bindable(false), onOpenChange, onAttach, preSelectedUri }: Props = $props();
let selectedResources = new SvelteSet<string>();
let lastSelectedUri = $state<string | null>(null);
let isAttaching = $state(false);
let selectedTemplate = $state<MCPResourceTemplateInfo | null>(null);
let templatePreviewUri = $state<string | null>(null);
let templatePreviewContent = $state<MCPResourceContent[] | null>(null);
let templatePreviewLoading = $state(false);
let templatePreviewError = $state<string | null>(null);
const totalCount = $derived(mcpTotalResourceCount());
$effect(() => {
if (open) {
loadResources();
if (preSelectedUri) {
selectedResources.clear();
selectedResources.add(preSelectedUri);
lastSelectedUri = preSelectedUri;
}
}
});
async function loadResources() {
const perChatOverrides = conversationsStore.getAllMcpServerOverrides();
const initialized = await mcpStore.ensureInitialized(perChatOverrides);
if (initialized) {
await mcpStore.fetchAllResources();
}
}
function handleOpenChange(newOpen: boolean) {
open = newOpen;
onOpenChange?.(newOpen);
if (!newOpen) {
selectedResources.clear();
lastSelectedUri = null;
clearTemplateState();
}
}
function clearTemplateState() {
selectedTemplate = null;
templatePreviewUri = null;
templatePreviewContent = null;
templatePreviewLoading = false;
templatePreviewError = null;
}
function handleTemplateSelect(template: MCPResourceTemplateInfo) {
selectedResources.clear();
lastSelectedUri = null;
if (
selectedTemplate?.uriTemplate === template.uriTemplate &&
selectedTemplate?.serverName === template.serverName
) {
clearTemplateState();
return;
}
selectedTemplate = template;
templatePreviewUri = null;
templatePreviewContent = null;
templatePreviewLoading = false;
templatePreviewError = null;
}
async function handleTemplateResolve(uri: string, serverName: string) {
templatePreviewUri = uri;
templatePreviewContent = null;
templatePreviewLoading = true;
templatePreviewError = null;
try {
const content = await mcpStore.readResourceByUri(serverName, uri);
if (content) {
templatePreviewContent = content;
} else {
templatePreviewError = 'Failed to read resource';
}
} catch (error) {
templatePreviewError = error instanceof Error ? error.message : 'Unknown error';
} finally {
templatePreviewLoading = false;
}
}
function handleTemplateCancelForm() {
clearTemplateState();
}
async function handleAttachTemplateResource() {
if (!templatePreviewUri || !selectedTemplate || !templatePreviewContent) return;
isAttaching = true;
try {
const knownResource = mcpResourceStore.findResourceByUri(templatePreviewUri);
if (knownResource) {
if (!mcpResourceStore.isAttached(knownResource.uri)) {
await mcpStore.attachResource(knownResource.uri);
}
toast.success(`Resource attached: ${knownResource.title || knownResource.name}`);
} else {
if (mcpResourceStore.isAttached(templatePreviewUri)) {
toast.info('Resource already attached');
handleOpenChange(false);
return;
}
const resourceInfo: MCPResourceInfo = {
uri: templatePreviewUri,
name: templatePreviewUri.split('/').pop() || templatePreviewUri,
serverName: selectedTemplate.serverName
};
const attachment = mcpResourceStore.addAttachment(resourceInfo);
mcpResourceStore.updateAttachmentContent(attachment.id, templatePreviewContent);
toast.success(`Resource attached: ${resourceInfo.name}`);
}
handleOpenChange(false);
} catch (error) {
console.error('Failed to attach template resource:', error);
} finally {
isAttaching = false;
}
}
function handleResourceSelect(resource: MCPResourceInfo, shiftKey: boolean = false) {
clearTemplateState();
if (shiftKey && lastSelectedUri) {
const allResources = getAllResourcesFlatInTreeOrder();
const lastIndex = allResources.findIndex((r) => r.uri === lastSelectedUri);
const currentIndex = allResources.findIndex((r) => r.uri === resource.uri);
if (lastIndex !== -1 && currentIndex !== -1) {
const start = Math.min(lastIndex, currentIndex);
const end = Math.max(lastIndex, currentIndex);
for (let i = start; i <= end; i++) {
selectedResources.add(allResources[i].uri);
}
}
} else {
selectedResources.clear();
selectedResources.add(resource.uri);
lastSelectedUri = resource.uri;
}
}
function handleResourceToggle(resource: MCPResourceInfo, checked: boolean) {
clearTemplateState();
if (checked) {
selectedResources.add(resource.uri);
} else {
selectedResources.delete(resource.uri);
}
lastSelectedUri = resource.uri;
}
function getAllResourcesFlatInTreeOrder(): MCPResourceInfo[] {
const allResources: MCPResourceInfo[] = [];
const resourcesMap = mcpResources();
for (const [serverName, serverRes] of resourcesMap.entries()) {
for (const resource of serverRes.resources) {
allResources.push({ ...resource, serverName });
}
}
return allResources.sort((a, b) => {
const aName = getResourceDisplayName(a);
const bName = getResourceDisplayName(b);
return aName.localeCompare(bName);
});
}
async function handleAttach() {
if (selectedResources.size === 0) return;
isAttaching = true;
try {
const allResources = getAllResourcesFlatInTreeOrder();
const resourcesToAttach = allResources.filter((r) => selectedResources.has(r.uri));
for (const resource of resourcesToAttach) {
await mcpStore.attachResource(resource.uri);
onAttach?.(resource);
}
const count = resourcesToAttach.length;
toast.success(
count === 1
? `Resource attached: ${resourcesToAttach[0].name}`
: `${count} resources attached`
);
handleOpenChange(false);
} catch (error) {
console.error('Failed to attach resources:', error);
} finally {
isAttaching = false;
}
}
const selectedTemplateUri = $derived(selectedTemplate?.uriTemplate ?? null);
const hasTemplateResult = $derived(
!!selectedTemplate && !!templatePreviewContent && !!templatePreviewUri
);
</script>
<Dialog.Root {open} onOpenChange={handleOpenChange}>
<Dialog.Content class="max-h-[80vh] !max-w-4xl overflow-hidden p-0">
<Dialog.Header class="border-b border-border/30 px-6 py-4">
<Dialog.Title class="flex items-center gap-2">
<FolderOpen class="h-5 w-5" />
<span>MCP Resources</span>
{#if totalCount > 0}
<span class="text-sm font-normal text-muted-foreground">({totalCount})</span>
{/if}
</Dialog.Title>
<Dialog.Description>
Browse and attach resources from connected MCP servers to your chat context.
</Dialog.Description>
</Dialog.Header>
<div class="flex h-[500px] min-w-0">
<div class="w-72 shrink-0 overflow-y-auto border-r border-border/30 p-4">
<McpResourcesBrowser
onSelect={handleResourceSelect}
onToggle={handleResourceToggle}
onTemplateSelect={handleTemplateSelect}
selectedUris={selectedResources}
{selectedTemplateUri}
expandToUri={preSelectedUri}
/>
</div>
<div class="min-w-0 flex-1 overflow-auto p-4">
{#if selectedTemplate && !templatePreviewContent}
<div class="flex h-full flex-col">
<div class="mb-3 flex items-center gap-2">
<Braces class="h-4 w-4 text-muted-foreground" />
<span class="text-sm font-medium">
{selectedTemplate.title || selectedTemplate.name}
</span>
</div>
{#if selectedTemplate.description}
<p class="mb-4 text-xs text-muted-foreground">
{selectedTemplate.description}
</p>
{/if}
<div class="mb-4 rounded-md border border-border/50 bg-muted/30 px-3 py-2">
<p class="font-mono text-xs break-all text-muted-foreground">
{selectedTemplate.uriTemplate}
</p>
</div>
{#if templatePreviewLoading}
<div class="flex flex-1 items-center justify-center">
<Loader2 class="h-6 w-6 animate-spin text-muted-foreground" />
</div>
{:else if templatePreviewError}
<div class="flex flex-1 flex-col items-center justify-center gap-2 text-red-500">
<span class="text-sm">{templatePreviewError}</span>
<Button
size="sm"
variant="outline"
onclick={() => {
templatePreviewError = null;
}}
>
Try again
</Button>
</div>
{:else}
<McpResourceTemplateForm
template={selectedTemplate}
onResolve={handleTemplateResolve}
onCancel={handleTemplateCancelForm}
/>
{/if}
</div>
{:else if hasTemplateResult}
<!-- Template resolved: show preview -->
<McpResourcePreview
resource={{
uri: templatePreviewUri ?? '',
name: templatePreviewUri?.split('/').pop() || (templatePreviewUri ?? ''),
serverName: selectedTemplate?.serverName || ''
}}
preloadedContent={templatePreviewContent}
/>
{:else if selectedResources.size === 1}
{@const allResources = getAllResourcesFlatInTreeOrder()}
{@const selectedResource = allResources.find((r) => selectedResources.has(r.uri))}
<McpResourcePreview resource={selectedResource ?? null} />
{:else if selectedResources.size > 1}
<div class="flex flex-col gap-10">
{#each getAllResourcesFlatInTreeOrder() as resource (resource.uri)}
{#if selectedResources.has(resource.uri)}
<McpResourcePreview {resource} />
{/if}
{/each}
</div>
{:else}
<div class="flex h-full items-center justify-center text-sm text-muted-foreground">
Select a resource to preview
</div>
{/if}
</div>
</div>
<Dialog.Footer class="border-t border-border/30 px-6 py-4">
<Button variant="outline" onclick={() => handleOpenChange(false)}>Cancel</Button>
{#if hasTemplateResult}
<Button onclick={handleAttachTemplateResource} disabled={isAttaching}>
{#if isAttaching}
<Loader2 class="mr-2 h-4 w-4 animate-spin" />
{:else}
<Plus class="mr-2 h-4 w-4" />
{/if}
Attach Resource
</Button>
{:else}
<Button onclick={handleAttach} disabled={selectedResources.size === 0 || isAttaching}>
{#if isAttaching}
<Loader2 class="mr-2 h-4 w-4 animate-spin" />
{:else}
<Plus class="mr-2 h-4 w-4" />
{/if}
Attach {selectedResources.size > 0 ? `(${selectedResources.size})` : 'Resource'}
</Button>
{/if}
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>