Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .devops/cann.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ COPY ui/apps/chat/package.json ui/apps/chat/package-lock.json ./
RUN npm ci

COPY ui/apps/chat/ ./
# the app compiles Llama UI from its source next to it
# the app compiles Llama UI and the harness from their sources next to it
COPY ui/lib/ui/package.json /app/ui/lib/ui/package.json
COPY ui/lib/ui/src/lib/ /app/ui/lib/ui/src/lib/
COPY ui/lib/harness/src/ /app/ui/lib/harness/src/
RUN LLAMA_BUILD_NUMBER="$APP_VERSION" npm run build

FROM ${CANN_BASE_IMAGE} AS build
Expand Down
3 changes: 2 additions & 1 deletion .devops/cpu.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ COPY ui/apps/chat/package.json ui/apps/chat/package-lock.json ./
RUN npm ci

COPY ui/apps/chat/ ./
# the app compiles Llama UI from its source next to it
# the app compiles Llama UI and the harness from their sources next to it
COPY ui/lib/ui/package.json /app/ui/lib/ui/package.json
COPY ui/lib/ui/src/lib/ /app/ui/lib/ui/src/lib/
COPY ui/lib/harness/src/ /app/ui/lib/harness/src/
RUN LLAMA_BUILD_NUMBER="$APP_VERSION" npm run build

FROM docker.io/ubuntu:$UBUNTU_VERSION AS build
Expand Down
3 changes: 2 additions & 1 deletion .devops/cuda.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ COPY ui/apps/chat/package.json ui/apps/chat/package-lock.json ./
RUN npm ci

COPY ui/apps/chat/ ./
# the app compiles Llama UI from its source next to it
# the app compiles Llama UI and the harness from their sources next to it
COPY ui/lib/ui/package.json /app/ui/lib/ui/package.json
COPY ui/lib/ui/src/lib/ /app/ui/lib/ui/src/lib/
COPY ui/lib/harness/src/ /app/ui/lib/harness/src/
RUN LLAMA_BUILD_NUMBER="$APP_VERSION" npm run build

FROM ${BASE_CUDA_DEV_CONTAINER} AS build
Expand Down
3 changes: 2 additions & 1 deletion .devops/intel.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ COPY ui/apps/chat/package.json ui/apps/chat/package-lock.json ./
RUN npm ci

COPY ui/apps/chat/ ./
# the app compiles Llama UI from its source next to it
# the app compiles Llama UI and the harness from their sources next to it
COPY ui/lib/ui/package.json /app/ui/lib/ui/package.json
COPY ui/lib/ui/src/lib/ /app/ui/lib/ui/src/lib/
COPY ui/lib/harness/src/ /app/ui/lib/harness/src/
RUN LLAMA_BUILD_NUMBER="$APP_VERSION" npm run build

FROM docker.io/intel/deep-learning-essentials:$ONEAPI_VERSION AS build
Expand Down
3 changes: 2 additions & 1 deletion .devops/musa.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ COPY ui/apps/chat/package.json ui/apps/chat/package-lock.json ./
RUN npm ci

COPY ui/apps/chat/ ./
# the app compiles Llama UI from its source next to it
# the app compiles Llama UI and the harness from their sources next to it
COPY ui/lib/ui/package.json /app/ui/lib/ui/package.json
COPY ui/lib/ui/src/lib/ /app/ui/lib/ui/src/lib/
COPY ui/lib/harness/src/ /app/ui/lib/harness/src/
RUN LLAMA_BUILD_NUMBER="$APP_VERSION" npm run build

FROM ${BASE_MUSA_DEV_CONTAINER} AS build
Expand Down
2 changes: 1 addition & 1 deletion .devops/nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ effectiveStdenv.mkDerivation (finalAttrs: {
webui = stdenvNoCC.mkDerivation {
pname = "webui";
version = llamaVersion;
# the app compiles Llama UI from its source in ../../lib/ui, so the source is ui/ as a whole
# the app compiles Llama UI and the harness from their sources in ../../lib, so the source is ui/ as a whole
src = lib.cleanSource ../../ui;
sourceRoot = "source/apps/chat";

Expand Down
3 changes: 2 additions & 1 deletion .devops/openvino.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ COPY ui/apps/chat/package.json ui/apps/chat/package-lock.json ./
RUN npm ci

COPY ui/apps/chat/ ./
# the app compiles Llama UI from its source next to it
# the app compiles Llama UI and the harness from their sources next to it
COPY ui/lib/ui/package.json /app/ui/lib/ui/package.json
COPY ui/lib/ui/src/lib/ /app/ui/lib/ui/src/lib/
COPY ui/lib/harness/src/ /app/ui/lib/harness/src/
RUN LLAMA_BUILD_NUMBER="$APP_VERSION" npm run build

## Build Image
Expand Down
3 changes: 2 additions & 1 deletion .devops/rocm.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ COPY ui/apps/chat/package.json ui/apps/chat/package-lock.json ./
RUN npm ci

COPY ui/apps/chat/ ./
# the app compiles Llama UI from its source next to it
# the app compiles Llama UI and the harness from their sources next to it
COPY ui/lib/ui/package.json /app/ui/lib/ui/package.json
COPY ui/lib/ui/src/lib/ /app/ui/lib/ui/src/lib/
COPY ui/lib/harness/src/ /app/ui/lib/harness/src/
RUN LLAMA_BUILD_NUMBER="$APP_VERSION" npm run build

### Build image
Expand Down
3 changes: 2 additions & 1 deletion .devops/vulkan.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ COPY ui/apps/chat/package.json ui/apps/chat/package-lock.json ./
RUN npm ci

COPY ui/apps/chat/ ./
# the app compiles Llama UI from its source next to it
# the app compiles Llama UI and the harness from their sources next to it
COPY ui/lib/ui/package.json /app/ui/lib/ui/package.json
COPY ui/lib/ui/src/lib/ /app/ui/lib/ui/src/lib/
COPY ui/lib/harness/src/ /app/ui/lib/harness/src/
RUN LLAMA_BUILD_NUMBER="$APP_VERSION" npm run build

FROM docker.io/ubuntu:$UBUNTU_VERSION AS build
Expand Down
3 changes: 2 additions & 1 deletion .devops/zendnn.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ COPY ui/apps/chat/package.json ui/apps/chat/package-lock.json ./
RUN npm ci

COPY ui/apps/chat/ ./
# the app compiles Llama UI from its source next to it
# the app compiles Llama UI and the harness from their sources next to it
COPY ui/lib/ui/package.json /app/ui/lib/ui/package.json
COPY ui/lib/ui/src/lib/ /app/ui/lib/ui/src/lib/
COPY ui/lib/harness/src/ /app/ui/lib/harness/src/
RUN LLAMA_BUILD_NUMBER="$APP_VERSION" npm run build

FROM docker.io/ubuntu:$UBUNTU_VERSION AS build
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ui-self-hosted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on:
'.github/workflows/ui-build-self-hosted.yml',
'ui/apps/chat/**.*',
'ui/lib/ui/**.*',
'ui/lib/harness/**.*',
'tools/server/tests/**.*'
]
pull_request:
Expand All @@ -28,6 +29,7 @@ on:
'.github/workflows/ui-build-self-hosted.yml',
'ui/apps/chat/**.*',
'ui/lib/ui/**.*',
'ui/lib/harness/**.*',
'tools/server/tests/**.*'
]

Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,37 @@ jobs:
run: npm run prepack
working-directory: ui/lib/ui

harness-checks:
name: Harness checks
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.sha || github.event.pull_request.head.sha || github.sha || github.head_ref || github.ref_name }}

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "24"
package-manager-cache: false

- name: Install dependencies
run: npm ci
working-directory: ui/lib/harness

- name: Run type checking
run: npm run check
working-directory: ui/lib/harness

- name: Run tests
run: npm test
working-directory: ui/lib/harness

- name: Build the package
run: npm run prepack
working-directory: ui/lib/harness

e2e-tests:
name: E2E Tests
needs: ui-build
Expand Down
13 changes: 10 additions & 3 deletions scripts/ui-assets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ set(LLAMA_UI_GZIP "" CACHE STRING "Apply gzip compress to assets to save ban
set(DIST_DIR "${UI_BINARY_DIR}/dist")
set(SRC_DIST_DIR "${UI_SOURCE_DIR}/dist")
# The stage keeps the layout of ui/: the app in apps/chat, with the sources of
# Llama UI that it compiles next to it in lib/ui (see ui/apps/chat/scripts/llama-ui.js).
# Llama UI and the harness that it compiles next to it in lib/ (see
# ui/apps/chat/scripts/llama-ui.js and svelte.config.js).
set(STAGE_DIR "${UI_BINARY_DIR}/ui-src")
set(WORK_DIR "${STAGE_DIR}/apps/chat")
set(UI_LIB_DIR "${UI_SOURCE_DIR}/../../lib/ui")
set(HARNESS_DIR "${UI_SOURCE_DIR}/../../lib/harness")
set(STAMP_FILE "${UI_BINARY_DIR}/.ui-stamp")
set(EMBED_STAMP "${UI_BINARY_DIR}/.ui-embed.sha256")
set(UI_CPP "${UI_BINARY_DIR}/ui.cpp")
Expand Down Expand Up @@ -320,7 +322,7 @@ function(npm_build_should_skip out_var)
endfunction()

function(stage_sources)
# everything but the app goes: the library, restaged below, and what a stage
# everything but the app goes: the packages, restaged below, and what a stage
# from before this layout left at the top, its node_modules included
if(EXISTS "${STAGE_DIR}")
file(GLOB staged RELATIVE "${STAGE_DIR}" "${STAGE_DIR}/*")
Expand All @@ -344,7 +346,8 @@ function(stage_sources)
PATTERN "node_modules" EXCLUDE
)

# what the app reads of the library: its sources and the dependency list
# what the app reads of the packages: Llama UI's sources and dependency list,
# and the harness's sources
file(COPY "${UI_LIB_DIR}/package.json"
DESTINATION "${STAGE_DIR}/lib/ui"
NO_SOURCE_PERMISSIONS
Expand All @@ -353,6 +356,10 @@ function(stage_sources)
DESTINATION "${STAGE_DIR}/lib/ui/src"
NO_SOURCE_PERMISSIONS
)
file(COPY "${HARNESS_DIR}/src"
DESTINATION "${STAGE_DIR}/lib/harness"
NO_SOURCE_PERMISSIONS
)
endfunction()

function(npm_build out_var)
Expand Down
19 changes: 13 additions & 6 deletions ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,27 @@ The UI of llama.cpp: the packages in `lib` and the apps built on them.
```text
ui/
├── lib/
│ └── ui/ @ggml-org/llama-ui: design tokens, fonts, surfaces and components
│ ├── ui/ @ggml-org/llama-ui: design tokens, fonts, surfaces and components
│ └── harness/ @ggml-org/llama-harness: the agentic loop, headless
└── apps/
└── chat/ Llama Chat, the chat app that llama-server serves
└── chat/ Llama Chat, the chat app that llama-server serves
```

- [`lib/ui`](lib/ui/README.md) draws the parts and handles interaction, with no business logic. It is built with
`@sveltejs/package` and published to npm as `@ggml-org/llama-ui`. Apps in this repo skip the package: they compile
its sources as part of their own build, so they hold no copy of a component, a token or a font.
- [`apps/chat`](apps/chat/README.md) talks to llama-server, stores conversations and runs the agentic loop. CMake
builds it into llama-server (see `scripts/ui-assets.cmake`), and it is published to npm as `@ggml-org/llama-chat`
(with `llama-chat` as its short name), so `npx llama-chat` runs it against any llama-server.
- [`lib/harness`](lib/harness/README.md) is the agentic loop: plain TypeScript with no UI and no dependencies. An app
gives it an inference client and tools, and reads its events.
- [`apps/chat`](apps/chat/README.md) talks to llama-server, stores conversations and runs the agentic loop through the
harness. CMake builds it into llama-server (see `scripts/ui-assets.cmake`), and it is published to npm as
`@ggml-org/llama-chat` (with `llama-chat` as its short name), so `npx llama-chat` runs it against any llama-server.

Each folder is its own npm package with its own `package-lock.json`: run `npm ci` in the one you work on. Building,
checking and testing `apps/chat` needs no install in `lib/ui`.
checking and testing `apps/chat` needs no install in `lib/ui` or `lib/harness`.

The split between library and app is not finished. Llama Chat takes its tokens, fonts, surfaces and base components
from `lib/ui`, but still has its own versions of what the library holds above those (ActionIcon, SearchInput, Logo,
SyntaxHighlightedCode and the Model UI), and `DESIGN.md`, `BRAND.md` and the full Storybook still sit beside the app.

## Releases

Expand Down
2 changes: 1 addition & 1 deletion ui/apps/chat/AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Instructions for ui/apps/chat

These add to the repository's [AGENTS.md](../../../AGENTS.md) for work in `ui/apps/chat`: **Llama Chat**, the chat client that llama-server bundles. **Llama UI**, the library, is `ui/lib/ui` (`@ggml-org/llama-ui`): Chat imports its tokens, fonts and base components from there (`@ggml-org/llama-ui/ui/<name>`) and keeps no copy of them. `DESIGN.md` and the Storybook live here; the brand book, `BRAND.md`, and the brand and communications pages are in [ggml-org/llama-brand](https://github.com/ggml-org/llama-brand), with their own Storybook.
These add to the repository's [AGENTS.md](../../../AGENTS.md) for work in `ui/apps/chat`: **Llama Chat**, the chat client that llama-server bundles. **Llama UI**, the library, is `ui/lib/ui` (`@ggml-org/llama-ui`): Chat imports its tokens, fonts and base components from there (`@ggml-org/llama-ui/ui/<name>`) and keeps no copy of them. `DESIGN.md` and the Storybook live here; the brand book, `BRAND.md`, and the brand and communications pages are in [ggml-org/llama-brand](https://github.com/ggml-org/llama-brand), with their own Storybook. The agentic loop is `ui/lib/harness` (`@ggml-org/llama-harness`).

- **Design:** [DESIGN.md](DESIGN.md) holds the tokens, roles and rules, written for agents. Follow it for anything visual. Its token sections (`colors`, `typography`, `rounded`) are generated from the CSS with `npm run design:tokens`, and CI checks they are current; the rest is written by hand, and when it and the CSS disagree, the CSS wins and DESIGN.md is updated.
- **Stories:** a story lives with the code it shows. Llama UI's (its foundations, base components, app components and Model UI) are in `ui/lib/ui/tests/stories`, titled `Llama UI/...`, and run as the library's tests; this app's Storybook shows them too. Llama Chat's are in `tests/stories/<area>`, one folder per `src/lib/components/app/<area>` (`chat/` has one per Chat folder), titled `Llama Chat/<Area>/<Component>`. An accessibility story sits next to its component's, as `<Component>.a11y.stories.svelte`, titled `.../<Component>/Accessibility`. The story helpers both Storybooks use (the Editorial the prose pages are set in, `StateGallery`) live with the library's stories and are imported here as `$llama-ui-stories/...`; reuse them rather than copying them here.
Expand Down
19 changes: 10 additions & 9 deletions ui/apps/chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ Llama Chat is the first app on Llama UI, and the reference for the line between

The app imports the library as `@ggml-org/llama-ui/ui/<name>` and compiles its sources in its own build, with no install of the library (see `scripts/vite-plugin-llama-ui.ts`). Data flows one way, through these layers:

| Layer | Lives in | What it holds |
| -------------- | ------------------------- | --------------------------------------------------------------------------------------------------- |
| Routes | `src/routes` | `/`, `/chat/[id]`, `/models`, `/mcp-servers`, `/settings`, `/search` |
| App components | `src/lib/components/app` | Chat, navigation, models, MCP, settings and dialogs, grouped by area |
| UI components | `ui/lib/ui` | shadcn-svelte on bits-ui, from Llama UI |
| Hooks | `src/lib/hooks` | View logic between components and stores: scroll, drag and drop, pickers, keyboard |
| Stores | `src/lib/stores` | Application state as Svelte 5 runes: chat, conversations, the agentic loop, tools, models, settings |
| Services | `src/lib/services` | Stateless I/O: the llama-server API, IndexedDB, MCP, the Hugging Face Hub, the tool sandbox |
| Storage + API | the browser, llama-server | IndexedDB and localStorage; llama-server's `/v1`, `/props`, `/models`, `/tools`, `/slots` |
| Layer | Lives in | What it holds |
| -------------- | ------------------------- | ---------------------------------------------------------------------------------------------------- |
| Routes | `src/routes` | `/`, `/chat/[id]`, `/models`, `/mcp-servers`, `/settings`, `/search` |
| App components | `src/lib/components/app` | Chat, navigation, models, MCP, settings and dialogs, grouped by area |
| UI components | `ui/lib/ui` | shadcn-svelte on bits-ui, from Llama UI |
| Hooks | `src/lib/hooks` | View logic between components and stores: scroll, drag and drop, pickers, keyboard |
| Stores | `src/lib/stores` | Application state as Svelte 5 runes: chat, conversations, the agentic loop, tools, models, settings |
| Agentic loop | `ui/lib/harness` | Llama Harness: streams a turn, runs the tools the model called, repeats until it answers without one |
| Services | `src/lib/services` | Stateless I/O: the llama-server API, IndexedDB, MCP, the Hugging Face Hub, the tool sandbox |
| Storage + API | the browser, llama-server | IndexedDB and localStorage; llama-server's `/v1`, `/props`, `/models`, `/tools`, `/slots` |

```mermaid
flowchart LR
Expand Down
3 changes: 2 additions & 1 deletion ui/apps/chat/sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
set(UI_SOURCE_GLOBS
src/*
static/*
# Llama UI, which the app compiles from source
# Llama UI and the harness, which the app compiles from source
../../lib/ui/src/lib/*
../../lib/harness/src/*
)

set(UI_SOURCE_FILES
Expand Down
32 changes: 32 additions & 0 deletions ui/apps/chat/src/lib/enums/agentic.enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,35 @@ export enum DiffLineKind {
CONTEXT = 'context',
REMOVE = 'remove'
}

/**
* Events of a harness run. The values mirror `HarnessEvent` of `@ggml-org/llama-harness`.
*/
export enum HarnessEventType {
COMPLETION_ID = 'completion_id',
DONE = 'done',
ERROR = 'error',
MESSAGE = 'message',
MODEL = 'model',
REASONING = 'reasoning',
TEXT = 'text',
TIMINGS = 'timings',
TOOL_CALL = 'tool_call',
TOOL_CALL_DELTA = 'tool_call_delta',
TOOL_RESULT = 'tool_result',
TOOL_UPDATE = 'tool_update',
TURN_END = 'turn_end',
TURN_START = 'turn_start'
}

/**
* Events of one streamed completion. The values mirror `InferenceEvent` of `@ggml-org/llama-harness`.
*/
export enum InferenceEventType {
COMPLETION_ID = 'completion_id',
MODEL = 'model',
REASONING = 'reasoning',
TEXT = 'text',
TIMINGS = 'timings',
TOOL_CALLS = 'tool_calls'
}
2 changes: 2 additions & 0 deletions ui/apps/chat/src/lib/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export {
AgenticSectionType,
ContinueIntentKind,
DiffLineKind,
HarnessEventType,
InferenceEventType,
ToolResultKind,
ToolCallType
} from './agentic.enums';
Expand Down
Loading
Loading