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
2 changes: 1 addition & 1 deletion ui/apps/chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ An extension is a feature the app is composed with and that can be switched off.

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.
Skills are listed the same way: 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. A chat uses every source the same way: `/skill` attaches a skill to the message, and the model lists and loads skills through the app's own `list_skills` and `load_skill` tools (`SkillToolsService`). A load asks the user for the skill, in the tool permission card, and the source keeps the answer bound to the skill's content: a local skill's SKILL.md digest, an MCP skill's digest set.

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.

Expand Down
10 changes: 10 additions & 0 deletions ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ChatFormInputFileInputInvisible,
ChatFormPickerPrompts,
ChatFormPickers,
ChatFormPickerSkills,
ChatFormSystemMessageAttachment,
ChatFormSystemMessageChip
} from '#lib/components/app/index.ts';
Expand All @@ -23,6 +24,7 @@
OPEN_OVERLAY_SELECTOR,
PROMPTS_PICKER_ID,
SETTING_CONFIG_DEFAULT,
SKILLS_PICKER_ID,
SYSTEM_MESSAGE_PLACEHOLDER,
VOICE_EDITOR_SELECTOR
} from '#lib/constants/index.ts';
Expand Down Expand Up @@ -53,6 +55,7 @@
modelsStore,
serverStore,
settingsStore,
skillsStore,
toolsStore,
uiStore,
voiceTranscriptsStore
Expand Down Expand Up @@ -186,12 +189,18 @@
component: ChatFormPickerPrompts,
id: PROMPTS_PICKER_ID
};
// so is the skill picker, over every source of skills
const SKILLS_PICKER: ComposerPicker = {
component: ChatFormPickerSkills,
id: SKILLS_PICKER_ID
};

// what extensions add to the form: slash commands, the pickers they open, and
// attachments that wait outside the form's files
let contributedCommands = $derived(extensions.contributions('composerCommands'));
let contributedPickers = $derived([
PROMPTS_PICKER,
SKILLS_PICKER,
...extensions.contributions('composerPickers')
]);
let contributedAttachments = $derived(extensions.contributions('composerAttachments'));
Expand Down Expand Up @@ -226,6 +235,7 @@
getShowModelSelector: () => isModelSelectorShown,
getValue: () => value,
hasCwdTools: () => conversationsStore.preferences.hasEnabledCwdTools(),
hasSkills: () => skillsStore.hasAvailableSources,
onCompact: () => chatStore.compactConversation(),
onSystemMessage: () => onSystemPromptClick?.({ files: uploadedFiles, message: value }),
openModelSelector: () => chatFormActionsRef?.openModelSelector(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<script lang="ts">
import type { PromptEntry, PromptSource } from '#lib/extensions/index.ts';
import type { Component } from 'svelte';

/** Where a prompt or a skill comes from, and the mark of its source. */
interface Props {
class?: string;
entry: PromptEntry;
source: PromptSource;
entry: { iconUrl?: string; origin: string };
source: { icon: Component<{ class?: string }> };
}

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

<!-- where a prompt comes from: the library, or the MCP server that offers it -->
<!-- where a prompt or a skill comes from: the library, a folder, or the MCP server that offers it -->
<span class="flex min-w-0 items-center gap-1.5 text-caption text-muted-foreground {className}">
{#if entry.iconUrl}
<img
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<script lang="ts">
import ChatFormPickerPromptOrigin from './ChatFormPickerPromptOrigin.svelte';
import { Badge } from '@ggml-org/llama-ui/ui/badge';
import {
ChatFormPickerList,
ChatFormPickerListItem,
ChatFormPickerListItemSkeleton,
ChatFormPickerPopover
} from '#lib/components/app/chat/index.ts';
import { SKILL_SEARCH_MIN_ITEMS } from '#lib/constants/index.ts';
import type { ComposerPickerProps } from '#lib/extensions/index.ts';
import { usePickerNavigation } from '#lib/hooks/use-picker-navigation.svelte.ts';
import { SkillToolsService, type SourcedSkill } from '#lib/services/skill-tools.service.ts';
import { untrack } from 'svelte';

/**
* The skill picker `/skill` opens: the skills of the machine's folders and the
* ones extensions offer, such as an MCP server's, each with where it comes
* from. Picking one attaches it to the message being written.
*/
let { anchor, composer, isOpen, onClose, query }: ComposerPickerProps = $props();

let skills = $state.raw<SourcedSkill[]>([]);
let isLoading = $state(false);
let searchQuery = $state('');

let items = $derived.by(() => {
const search = searchQuery.trim().toLowerCase();

if (!search) return skills;

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

const nav = usePickerNavigation({
count: () => items.length,
isOpen: () => isOpen,
onClose: () => onClose(),
onSelect: (index) => pick(items[index])
});

// opening the picker is the need for the listings
$effect(() => {
if (!isOpen) return;

untrack(() => {
nav.reset(0);
void load();
});
});

// what is typed after `/skill` searches the list, like its own search field does
$effect(() => {
if (isOpen) searchQuery = query;
});

$effect(() => {
if (nav.hoveredIndex >= items.length) nav.reset(0);
});

async function load() {
isLoading = true;
// in the order of the sources; one that fails to list leaves the others' skills
skills = (await SkillToolsService.listings()).flatMap((listing) => listing.skills);
isLoading = false;
}

function pick({ entry, source }: SourcedSkill) {
onClose();
void source.attach(entry, composer);
}

export function handleKeydown(event: KeyboardEvent): boolean {
return nav.handleKeydown(event);
}
</script>

<ChatFormPickerPopover
bind:isOpen
customAnchor={anchor}
{onClose}
onKeydown={handleKeydown}
srLabel="Open skill picker"
>
<ChatFormPickerList
bind:searchQuery
emptyMessage={skills.length === 0 ? 'No skills available' : 'No matching skill'}
{isLoading}
itemKey={({ entry, source }) => `${source.id}:${entry.id}`}
{items}
scrollTrigger={nav.scrollTrigger}
searchPlaceholder="Search skills..."
selectedIndex={nav.hoveredIndex}
showSearchInput={skills.length >= SKILL_SEARCH_MIN_ITEMS}
>
{#snippet item(skill, index, isSelected)}
<ChatFormPickerListItem
dataIndex={index}
{isSelected}
onclick={() => pick(skill)}
onhover={() => nav.setHover(index)}
>
<div class="min-w-0 flex-1">
<ChatFormPickerPromptOrigin class="mb-0.5" entry={skill.entry} source={skill.source} />

<div class="flex items-center gap-2">
<span class="truncate font-medium">{skill.entry.name}</span>

{#if skill.entry.isUnverified}
<Badge variant="secondary">Cannot be verified</Badge>
{/if}
</div>

{#if skill.entry.description}
<p class="mt-0.5 truncate text-body-sm text-muted-foreground">
{skill.entry.description}
</p>
{/if}
</div>
</ChatFormPickerListItem>
{/snippet}

{#snippet skeleton()}
<ChatFormPickerListItemSkeleton titleWidth="w-32" />
{/snippet}
</ChatFormPickerList>
</ChatFormPickerPopover>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script lang="ts">
/** What the permission card shows about a skill from a folder before the user answers. */
interface Props {
description: string;
/** The user allowed the skill for good before, with another text than it has now. */
hasChanged: boolean;
/** Where its SKILL.md is on the machine. */
path: string;
}

let { description, hasChanged, path }: Props = $props();
</script>

<div class="flex flex-col gap-2 text-caption text-muted-foreground">
{#if hasChanged}
<p class="text-foreground">This skill changed since you allowed it.</p>
{/if}

<p>Its instructions go to the model, which can act on them with the tools you allow.</p>

{#if description}
<p class="line-clamp-4">{description}</p>
{/if}

<p class="truncate font-mono" title={path}>{path}</p>
</div>
8 changes: 7 additions & 1 deletion ui/apps/chat/src/lib/components/app/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export { default as ChatFormPickerMention } from './ChatForm/ChatFormPickers/Cha

/**
* `/`-triggered slash-command picker. Lists the available slash commands
* (`/prompt`, `/cwd`, `/model`) filtered by the typed query; selection
* (`/prompt`, `/skill`, `/cwd`, `/model`) filtered by the typed query; selection
* hands the command to the parent for dispatch.
*/
export { default as ChatFormPickerCommand } from './ChatForm/ChatFormPickers/ChatFormPickerCommand.svelte';
Expand All @@ -310,6 +310,12 @@ export { default as ChatFormPickerCommand } from './ChatForm/ChatFormPickers/Cha
*/
export { default as ChatFormPickerPrompts } from './ChatForm/ChatFormPickers/ChatFormPickerPrompts.svelte';

/**
* The skill picker `/skill` opens: the skills of the machine's folders and the ones
* extensions offer, such as an MCP server's, each with where it comes from.
*/
export { default as ChatFormPickerSkills } from './ChatForm/ChatFormPickers/ChatFormPickerSkills.svelte';

/**
* Where a prompt comes from, on its row in a list: the origin's icon and name.
*/
Expand Down
17 changes: 17 additions & 0 deletions ui/apps/chat/src/lib/constants/skills.constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { STORAGE_APP_NAME } from './storage.constants';

/** The file that names, describes and holds a skill. */
export const SKILL_MANIFEST_NAME = 'SKILL.md';

Expand All @@ -23,3 +25,18 @@ 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';

/** What one of the local source's origins is, in the model's listing of skills. */
export const LOCAL_SKILLS_ORIGIN_KIND = 'folder';

/** Where the local skills the user always allows are remembered, in localStorage. */
export const LOCAL_SKILL_APPROVALS_LOCALSTORAGE_KEY = `${STORAGE_APP_NAME}.localSkillApprovals`;

/** Id of the chat form's skill picker, which `/skill` opens. */
export const SKILLS_PICKER_ID = 'skills';

/** A skill list this long gets a search field. */
export const SKILL_SEARCH_MIN_ITEMS = 4;

/** What the chip of a skill attached to a message reads, before the skill's name. */
export const SKILL_ATTACHMENT_TITLE_PREFIX = 'Skill: ';
11 changes: 11 additions & 0 deletions ui/apps/chat/src/lib/constants/tool-ui.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// (see ChatMessageToolCallBlockGetDatetime and
// ChatMessageToolCallBlockSearchResults for prior art).

import { SKILL_ICON } from './icons.constants';
import Braces from '@lucide/svelte/icons/braces';
import Clock from '@lucide/svelte/icons/clock';
import Eye from '@lucide/svelte/icons/eye';
Expand All @@ -27,6 +28,16 @@ export const TOOL_UI: Readonly<Record<BuiltInTool, ToolUiEntry>> = {
label: 'Current time',
source: ToolSource.BROWSER
},
[BuiltInTool.BROWSER_LIST_SKILLS]: {
icon: SKILL_ICON,
label: 'List skills',
source: ToolSource.BROWSER
},
[BuiltInTool.BROWSER_LOAD_SKILL]: {
icon: SKILL_ICON,
label: 'Load skill',
source: ToolSource.BROWSER
},
[BuiltInTool.BROWSER_READ_MEDIA]: { icon: Eye, label: 'Read media', source: ToolSource.BROWSER },
[BuiltInTool.BROWSER_RUN_JAVASCRIPT]: {
icon: Braces,
Expand Down
1 change: 1 addition & 0 deletions ui/apps/chat/src/lib/enums/chat.enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export enum ChatFormCommandAction {
CWD = 'cwd',
MODEL = 'model',
PROMPT = 'prompt',
SKILL = 'skill',
SYSTEM_MESSAGE = 'system-message'
}

Expand Down
1 change: 1 addition & 0 deletions ui/apps/chat/src/lib/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export {
SearchChatsMessageSelection,
SearchChatsOrder,
ServerToolType,
SkillToolArgument,
ToolSource,
ToolPermissionDecision,
ToolResponseField
Expand Down
9 changes: 9 additions & 0 deletions ui/apps/chat/src/lib/enums/tools.enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export enum GlobSearchType {
*/
export enum BuiltInTool {
BROWSER_GET_DATETIME = 'get_datetime',
BROWSER_LIST_SKILLS = 'list_skills',
BROWSER_LOAD_SKILL = 'load_skill',
BROWSER_READ_MEDIA = 'read_media',
BROWSER_RUN_JAVASCRIPT = 'run_javascript',
BROWSER_SEARCH_CHATS = 'search_chats',
Expand All @@ -62,6 +64,13 @@ export enum BuiltInTool {
SERVER_WRITE_FILE = 'write_file'
}

/** The arguments of {@link BuiltInTool.BROWSER_LOAD_SKILL}. */
export enum SkillToolArgument {
FILE = 'file',
FROM = 'from',
NAME = 'name'
}

/** Wire values of the `search_chats` `message_selection` parameter */
export enum SearchChatsMessageSelection {
EARLIEST = 'earliest',
Expand Down
2 changes: 1 addition & 1 deletion ui/apps/chat/src/lib/extensions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type {
MessageRendererProps
} from './points/renderers';
export type { SettingsAction, SettingsActionDialog } from './points/settings';
export type { SkillEntry, SkillSource } from './points/skills';
export type { SkillEntry, SkillPermission, SkillSource } from './points/skills';
export type {
FlowHook,
FlowInfo,
Expand Down
Loading
Loading