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
4 changes: 3 additions & 1 deletion ui/apps/chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ sequenceDiagram

### Extensions (`src/lib/extensions/`)

An extension is a feature the app is composed with and that can be switched off. The registry (`registry.svelte.ts`) knows the built-in extensions (`builtin.ts`), activates the ones that are on at startup, and holds what they add to each extension point (`points/`): tools, flow hooks, settings actions, slash commands, pickers, pending attachments, message and attachment renderers, and sources of prompts.
An extension is a feature the app is composed with and that can be switched off. The registry (`registry.svelte.ts`) knows the built-in extensions (`builtin.ts`), activates the ones that are on at startup, and holds what they add to each extension point (`points/`): tools, flow hooks, settings actions, slash commands, pickers, pending attachments, message and attachment renderers, and sources of prompts and of skills.

A prompt is one kind of item whatever it comes from. The library (`promptsStore`, the Library page) is the app's own source of prompts, and an extension adds another through `promptSources`: MCP lists the prompts of its servers. `/prompt` and the System message list in the chat form's + menu show the prompts of every source together, each with where it comes from, and either sends a prompt with a message or makes it the chat's system message.

Skills are listed the same way, to browse and read: the Library's Skills tab shows the skills found in `~/.agents/skills` and `~/.claude/skills` on the machine llama-server runs on, read through llama-server's file tools (`skillsStore`, `LocalSkillsService`), and an extension adds another source through `skillSources`: MCP lists the skills its servers publish.

The core never imports an extension's own code; an extension may import the core. ESLint enforces this: a file outside `src/lib/extensions/<id>/` cannot import from that folder.

Extensions are switched on and off in Settings, in the Extensions section. A switch takes effect at once: the extension's contributions go away and its cleanups run (MCP closes its connections). The choice is kept in localStorage and read at startup.
Expand Down
79 changes: 79 additions & 0 deletions ui/apps/chat/src/lib/components/app/dialogs/DialogSkill.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<script lang="ts">
import { Badge } from '@ggml-org/llama-ui/ui/badge';
import * as Dialog from '@ggml-org/llama-ui/ui/dialog';
import { Skeleton } from '@ggml-org/llama-ui/ui/skeleton';
import { MarkdownContent } from '#lib/components/app/index.ts';
import { SKILL_MANIFEST_NAME } from '#lib/constants/index.ts';
import type { SkillEntry } from '#lib/extensions/index.ts';
import { skillInstructions } from '#lib/utils/index.ts';
import { untrack } from 'svelte';

interface Props {
open: boolean;
/** The skill to show. */
entry: SkillEntry | null;
/** Reads the skill's SKILL.md. Called each time the dialog opens. */
read: (entry: SkillEntry) => Promise<string>;
}

let { entry, open = $bindable(false), read }: Props = $props();

/** Placeholder lines while the SKILL.md is read. */
const SKELETON_WIDTH_CLASSES = ['w-2/5', 'w-full', 'w-11/12', 'w-4/5'];

let instructions = $state<string | null>(null);
let error = $state<string | null>(null);

// the file is read when the dialog opens: looking at a skill is the need for it
$effect(() => {
if (!open || !entry) return;

const shown = entry;

untrack(() => {
instructions = null;
error = null;

read(shown).then(
(text) => {
if (entry === shown) instructions = skillInstructions(text);
},
(reason) => {
if (entry === shown) error = reason instanceof Error ? reason.message : String(reason);
}
);
});
});
</script>

<Dialog.Root bind:open>
<Dialog.Content
class="grid max-h-[90vh] grid-rows-[auto_minmax(0,1fr)] overflow-hidden sm:max-w-3xl"
>
<Dialog.Header>
<Dialog.Title class="flex items-center gap-2 pr-8">
<span class="truncate">{entry?.name}</span>

{#if entry}
<Badge class="shrink-0" variant="secondary">{entry.origin}</Badge>
{/if}
</Dialog.Title>

<Dialog.Description>{entry?.description}</Dialog.Description>
</Dialog.Header>

<div aria-label={SKILL_MANIFEST_NAME} class="overflow-y-auto pr-1" role="region">
{#if error}
<p class="text-body-sm text-destructive" role="alert">{error}</p>
{:else if instructions === null}
<div aria-busy="true" class="flex flex-col gap-3">
{#each SKELETON_WIDTH_CLASSES as width (width)}
<Skeleton class="h-4 {width}" />
{/each}
</div>
{:else}
<MarkdownContent content={instructions} />
{/if}
</div>
</Dialog.Content>
</Dialog.Root>
8 changes: 8 additions & 0 deletions ui/apps/chat/src/lib/components/app/dialogs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ export { default as DialogConversationRename } from './DialogConversationRename.
*/
export { default as DialogPromptUpdate } from './DialogPromptUpdate.svelte';

/**
* **DialogSkill** - Read a skill's SKILL.md
*
* Opened from a row of the Library's Skills tab: the skill's name, where it comes
* from and its description, then its instructions, read when the dialog opens.
*/
export { default as DialogSkill } from './DialogSkill.svelte';

/**
* **DialogPrompt** - Name, describe and write a library prompt
*
Expand Down
37 changes: 37 additions & 0 deletions ui/apps/chat/src/lib/components/app/library/LibrarySkillRow.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script lang="ts">
import { Badge } from '@ggml-org/llama-ui/ui/badge';
import type { SkillEntry, SkillSource } from '#lib/extensions/index.ts';

interface Props {
entry: SkillEntry;
source: SkillSource;
onOpen: () => void;
}

let { entry, onOpen, source }: Props = $props();
</script>

<!-- one skill: its source's mark on a tile, its name with where it comes from, and what it is for -->
<button
class="flex w-full cursor-pointer items-center gap-3 rounded-lg px-2 py-2.5 text-left transition-colors hover:bg-muted/50 focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-none"
onclick={onOpen}
type="button"
>
<span
class="flex size-10 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground"
>
<source.icon class="size-5" />
</span>

<span class="flex min-w-0 flex-1 flex-col gap-0.5">
<span class="flex min-w-0 items-center gap-2">
<span class="truncate text-label">{entry.name}</span>

<Badge class="shrink-0" variant="secondary">{entry.origin}</Badge>
</span>

{#if entry.description}
<span class="truncate text-body-sm text-muted-foreground">{entry.description}</span>
{/if}
</span>
</button>
146 changes: 146 additions & 0 deletions ui/apps/chat/src/lib/components/app/library/LibrarySkills.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<script lang="ts">
import LibrarySkillRow from './LibrarySkillRow.svelte';
import * as Empty from '@ggml-org/llama-ui/ui/empty';
import { Skeleton } from '@ggml-org/llama-ui/ui/skeleton';
import { SearchX } from '@lucide/svelte';
import { DialogSkill } from '#lib/components/app/index.ts';
import { LOCAL_SKILL_FOLDERS, SKILL_ICON } from '#lib/constants/index.ts';
import type { SkillEntry, SkillSource } from '#lib/extensions/index.ts';
import { skillsStore, toolsStore } from '#lib/stores/index.ts';
import { untrack } from 'svelte';

interface Props {
query?: string;
}

let { query = '' }: Props = $props();

/** A skill with the source that offers it. */
interface SkillItem {
entry: SkillEntry;
source: SkillSource;
}

/** Placeholder rows while the sources are asked. */
const SKILL_ROW_SKELETONS = 5;

let items = $state.raw<SkillItem[]>([]);
let isLoading = $state(true);
let opened = $state.raw<SkillItem | null>(null);
let isDialogOpen = $state(false);
// a list asked for again while one loads makes that one stale
let run = 0;

const shown = $derived.by(() => {
const search = query.trim().toLowerCase();

if (!search) return items;

return items.filter(
({ entry }) =>
entry.name.toLowerCase().includes(search) ||
entry.description.toLowerCase().includes(search) ||
entry.origin.toLowerCase().includes(search)
);
});

/** Asks every source for its skills. A source that fails leaves the others' skills. */
async function load(sources: SkillSource[]) {
const current = ++run;

isLoading = true;

const listings = await Promise.allSettled(sources.map((source) => source.list()));

if (current !== run) return;

items = listings.flatMap((listing, index) => {
if (listing.status === 'rejected') {
console.error(`Failed to list the skills of ${sources[index].id}:`, listing.reason);

return [];
}

return listing.value.map((entry) => ({ entry, source: sources[index] }));
});
isLoading = false;
}

// showing the tab is the need for the lists; they are read again when a source comes or
// goes, or llama-server's file tools arrive
$effect(() => {
const sources = skillsStore.sources;

void skillsStore.canReadLocalSkills;

untrack(() => void load(sources));
});

function open(item: SkillItem) {
opened = item;
isDialogOpen = true;
}
</script>

<!-- llama-server's tools may still be on their way: until they are known, no skills is not an answer -->
{#if (isLoading || toolsStore.loading) && items.length === 0}
<div class="flex flex-col gap-1">
{#each { length: SKILL_ROW_SKELETONS } as _, index (index)}
<div class="flex items-center gap-3 px-2 py-2.5">
<Skeleton class="size-10 shrink-0 rounded-lg" />

<div class="flex flex-1 flex-col gap-1.5">
<Skeleton class="h-4 w-40" />

<Skeleton class="h-4 w-3/5" />
</div>
</div>
{/each}
</div>
{:else if items.length === 0}
<Empty.Root class="border py-16">
<Empty.Header>
<Empty.Media variant="icon">
<SKILL_ICON />
</Empty.Media>

<Empty.Title>No skills found</Empty.Title>

<Empty.Description>
{#if skillsStore.canReadLocalSkills}
Skills are folders with a SKILL.md, looked for in {LOCAL_SKILL_FOLDERS.join(' and ')}. The
skills of MCP servers are listed here too.
{:else}
Skills in {LOCAL_SKILL_FOLDERS.join(' and ')} are listed when llama-server runs with its tools
on, and the skills of MCP servers when MCP is enabled.
{/if}
</Empty.Description>
</Empty.Header>
</Empty.Root>
{:else if shown.length === 0}
<Empty.Root class="border py-16">
<Empty.Header>
<Empty.Media variant="icon">
<SearchX />
</Empty.Media>

<Empty.Title>No skills match</Empty.Title>

<Empty.Description>Try another search.</Empty.Description>
</Empty.Header>
</Empty.Root>
{:else}
<ul class="flex flex-col divide-y divide-border/40">
{#each shown as item (`${item.source.id}:${item.entry.id}`)}
<li class="py-0.5">
<LibrarySkillRow entry={item.entry} onOpen={() => open(item)} source={item.source} />
</li>
{/each}
</ul>
{/if}

<DialogSkill
bind:open={isDialogOpen}
entry={opened?.entry ?? null}
read={(entry) => opened?.source.read(entry) ?? Promise.resolve('')}
/>
7 changes: 5 additions & 2 deletions ui/apps/chat/src/lib/components/app/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
* LIBRARY
*
* The Library page, in tabs: the prompts kept in the app, as cards that are sent
* in a chat or used as its system message, and the files of every conversation
* in a grid, each leading back to the message it was sent in.
* in a chat or used as its system message, the files of every conversation in a
* grid, each leading back to the message it was sent in, and the skills found on
* the machine and on MCP servers.
*/

export { default as LibraryAttachments } from './LibraryAttachments.svelte';
export { default as LibraryAttachmentTile } from './LibraryAttachmentTile.svelte';
export { default as LibraryPromptCard } from './LibraryPromptCard.svelte';
export { default as LibraryPrompts } from './LibraryPrompts.svelte';
export { default as LibrarySkillRow } from './LibrarySkillRow.svelte';
export { default as LibrarySkills } from './LibrarySkills.svelte';
4 changes: 4 additions & 0 deletions ui/apps/chat/src/lib/constants/icons.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import FileIcon from '@lucide/svelte/icons/file';
// not a microphone: that one is for recording and dictation
import AudioIcon from '@lucide/svelte/icons/file-headphone';
import FileTextIcon from '@lucide/svelte/icons/file-text';
import SkillIcon from '@lucide/svelte/icons/graduation-cap';
import ImageIcon from '@lucide/svelte/icons/image';
import LibraryIcon from '@lucide/svelte/icons/library';
import LoadingIcon from '@lucide/svelte/icons/loader-2';
Expand Down Expand Up @@ -63,6 +64,9 @@ export const LIBRARY_ICON = LibraryIcon;
/** A prompt, wherever it comes from. */
export const PROMPT_ICON = PromptIcon;

/** The one icon for skills, wherever the app shows them. */
export const SKILL_ICON = SkillIcon;

/** Boolean flag a modality drives on the ModelModalities type. */
export type ModalityKey = (typeof MODALITY_FLAG_KEYS)[keyof typeof MODALITY_FLAG_KEYS];

Expand Down
1 change: 1 addition & 0 deletions ui/apps/chat/src/lib/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ export * from './get-datetime';
export * from './browser-info';
export * from './search-chats';
export * from './library.constants';
export * from './skills.constants';
export * from './voice.constants';
export * from './sheet.constants';
3 changes: 2 additions & 1 deletion ui/apps/chat/src/lib/constants/library.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import type { Component } from 'svelte';
/** The Library's tabs, in order. */
export const LIBRARY_TABS: { label: string; search: string; value: LibraryTab }[] = [
{ label: 'Prompts', search: 'Search prompts', value: LibraryTab.PROMPTS },
{ label: 'Attachments', search: 'Search attachments', value: LibraryTab.ATTACHMENTS }
{ label: 'Attachments', search: 'Search attachments', value: LibraryTab.ATTACHMENTS },
{ label: 'Skills', search: 'Search skills', value: LibraryTab.SKILLS }
];

/** The mark of a file in the Library's attachments, by its kind. */
Expand Down
25 changes: 25 additions & 0 deletions ui/apps/chat/src/lib/constants/skills.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/** The file that names, describes and holds a skill. */
export const SKILL_MANIFEST_NAME = 'SKILL.md';

/**
* The folders skills are looked for in, on the machine llama-server runs on, in
* order: when two hold a skill of the same name, the first one's is listed.
* `.agents/skills` is the shared folder of agents, `.claude/skills` the one
* Claude Code reads.
*/
export const LOCAL_SKILL_FOLDERS = ['~/.agents/skills', '~/.claude/skills'] as const;

/** Every SKILL.md of a skills folder: a skill is a folder in it, with that file. */
export const LOCAL_SKILLS_GLOB = `**/${SKILL_MANIFEST_NAME}`;

/** A skills folder, a skill's own folder, its SKILL.md. */
export const LOCAL_SKILLS_MAX_DEPTH = 2;

/** Skills listed from one folder at most. */
export const LOCAL_SKILLS_LIMIT = 200;

/** Lines of a SKILL.md read for the list: enough to hold its frontmatter. */
export const LOCAL_SKILL_FRONTMATTER_LINES = 40;

/** Id of the machine's folders as a source of skills. */
export const LOCAL_SKILLS_SOURCE_ID = 'local';
3 changes: 2 additions & 1 deletion ui/apps/chat/src/lib/enums/library.enums.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** The part of the Library a tab shows. */
export enum LibraryTab {
ATTACHMENTS = 'attachments',
PROMPTS = 'prompts'
PROMPTS = 'prompts',
SKILLS = 'skills'
}
1 change: 1 addition & 0 deletions ui/apps/chat/src/lib/extensions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type {
MessageRendererProps
} from './points/renderers';
export type { SettingsAction, SettingsActionDialog } from './points/settings';
export type { SkillEntry, SkillSource } from './points/skills';
export type {
FlowHook,
FlowInfo,
Expand Down
Loading
Loading