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 @@ -148,7 +148,7 @@ 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, sidebar entries, pages, slash commands, pickers, pending attachments, and message and attachment renderers.
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, sidebar entries, pages, slash commands, pickers, pending attachments, message and attachment renderers, and prompts offered as system messages.

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
15 changes: 15 additions & 0 deletions ui/apps/chat/src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,21 @@
animation: none;
}
}

/* A page's entrance, for pages that remount on every navigation into them:
* the whole page fades in at once. A plain ease over 350ms spreads the
* fade evenly instead of front-loading it, so it reads as a calm arrival.
* Opacity only, so it runs on the compositor and stays for reduced motion
* too: a fade does not move anything. */
.page-enter {
animation: page-enter 350ms ease;
}

@keyframes page-enter {
from {
opacity: 0;
}
}
}

.mermaidTooltip {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
MimeTypeText,
SpecialFileType
} from '#lib/enums/index.ts';
import { type ComposerHandle, extensions } from '#lib/extensions/index.ts';
import {
type ComposerHandle,
extensions,
type SystemPromptEntry,
type SystemPromptSource
} from '#lib/extensions/index.ts';
import { useChatFormExpansion } from '#lib/hooks/use-chat-form-expansion.svelte.ts';
import { useChatFormPickers } from '#lib/hooks/use-chat-form-pickers.svelte.ts';
import {
Expand Down Expand Up @@ -83,6 +88,7 @@
onStop?: () => void;
onSubmit?: () => void;
onSystemPromptClick?: (draft: { message: string; files: ChatUploadedFile[] }) => void;
onSystemPromptWithContent?: (content: string, promptId: string, title: string) => void;
onUploadedFileRemove?: (fileId: string) => void;
onUploadedFilesChange?: (files: ChatUploadedFile[]) => void;
onValueChange?: (value: string) => void;
Expand All @@ -104,6 +110,7 @@
onStop,
onSubmit,
onSystemPromptClick,
onSystemPromptWithContent,
onUploadedFileRemove,
onUploadedFilesChange,
onValueChange,
Expand Down Expand Up @@ -518,6 +525,11 @@
}
}

/** A prompt of the System message list that needs arguments: its source asks for them in the form. */
function handlePromptArguments(source: SystemPromptSource, entry: SystemPromptEntry) {
source.openArguments(entry, composer);
}

// Deferred so the closing popover's focus scope tears down first -
// bits-ui yanks a synchronous focus() back into the still-mounted popover.
function refocusInput() {
Expand Down Expand Up @@ -799,9 +811,11 @@
micWarning={micUnavailableReason ?? micError}
onFileUpload={handleFileUpload}
onMicClick={handleMicClick}
onPromptArguments={handlePromptArguments}
{onStop}
onSystemPromptClick={() =>
onSystemPromptClick?.({ files: uploadedFiles, message: value })}
{onSystemPromptWithContent}
onVoiceModeClick={voiceModeAvailable ? handleVoiceModeClick : undefined}
onWorkingDirectoryClick={isWorkingDirectoryInAddMenu
? pickers.handleWorkingDirectoryOpen
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { SearchInput } from '@ggml-org/llama-ui/app/forms';
import { Checkbox } from '@ggml-org/llama-ui/ui/checkbox';
import * as Collapsible from '@ggml-org/llama-ui/ui/collapsible';
import * as Drawer from '@ggml-org/llama-ui/ui/drawer';
Expand All @@ -12,6 +13,7 @@
MessageSquare,
Mic,
PencilRuler,
Plus,
Video
} from '@lucide/svelte';
import {
Expand All @@ -24,6 +26,7 @@
import { getChatFormActionsContext } from '#lib/contexts/index.ts';
import { AttachmentAction, AttachmentItemEnabledWhen } from '#lib/enums/attachment.enums.ts';
import { useAttachmentMenu } from '#lib/hooks/use-attachment-menu.svelte.ts';
import { useSystemMessagePrompts } from '#lib/hooks/use-system-message-prompts.svelte.ts';
import { useToolsPanel } from '#lib/hooks/use-tools-panel.svelte.ts';
import { conversationsStore, projectsStore, uiStore } from '#lib/stores/index.ts';
import type { ToolGroup } from '#lib/types/index.ts';
Expand All @@ -39,6 +42,7 @@
const chatFormActions = getChatFormActionsContext();

let drawerOpen = $state(false);
let promptsExpanded = $state(false);
let toolsExpanded = $state(false);

const attachmentMenu = useAttachmentMenu(
Expand Down Expand Up @@ -79,6 +83,21 @@

const toolsPanel = useToolsPanel();

const systemPrompts = useSystemMessagePrompts({
onPromptArguments: (source, entry) => {
drawerOpen = false;
chatFormActions.onPromptArguments?.(source, entry);
},
onPromptSelect: (content, promptId, title) => {
drawerOpen = false;
chatFormActions.onSystemPromptWithContent?.(content, promptId, title);
}
});

$effect(() => {
if (promptsExpanded) void systemPrompts.loadSourcePrompts();
});

const itemClass =
'flex w-full items-center gap-3 rounded-md px-3 py-2.5 text-left text-sm transition-colors hover:bg-accent active:bg-accent disabled:cursor-not-allowed disabled:opacity-50';

Expand Down Expand Up @@ -149,15 +168,110 @@
<span>{ATTACHMENT_MENU_TEXT.ADD_TO_PROJECT}</span>
</button>

<button
class={itemClass}
onclick={() => attachmentMenu.callbacks[AttachmentAction.SYSTEM_PROMPT_CLICK]()}
type="button"
>
<MessageSquare class="{ICON_CLASS_DEFAULT} shrink-0" />
<Collapsible.Root onOpenChange={(open) => (promptsExpanded = open)} open={promptsExpanded}>
<Collapsible.Trigger class={itemClass}>
{#if promptsExpanded}
<ChevronDown class="{ICON_CLASS_DEFAULT} shrink-0" />
{:else}
<ChevronRight class="{ICON_CLASS_DEFAULT} shrink-0" />
{/if}

<span>{ATTACHMENT_MENU_TEXT.SYSTEM_MESSAGE}</span>
</button>
<MessageSquare class="{ICON_CLASS_DEFAULT} shrink-0" />

<span class="flex-1">{ATTACHMENT_MENU_TEXT.SYSTEM_MESSAGE}</span>
</Collapsible.Trigger>

<Collapsible.Content>
<div class="flex flex-col gap-0.5 pl-4">
{#if systemPrompts.hasPrompts}
<div class="mb-1">
<SearchInput
bind:value={systemPrompts.searchQuery}
placeholder="Search by name, content, or server..."
size="sm"
/>
</div>
{/if}

<button
class={itemClass}
onclick={() => attachmentMenu.callbacks[AttachmentAction.SYSTEM_PROMPT_CLICK]()}
type="button"
>
<Plus class="{ICON_CLASS_DEFAULT} shrink-0" />

<span>Write new</span>
</button>

{#each systemPrompts.libraryPrompts as prompt (prompt.id)}
<button
class="{itemClass} flex-col items-start gap-0.5 py-2"
onclick={() => systemPrompts.selectLibraryPrompt(prompt.id)}
type="button"
>
<span class="line-clamp-1 text-sm font-medium">{prompt.name}</span>

{#if prompt.description}
<span class="line-clamp-1 w-full text-xs text-muted-foreground">
{prompt.description}
</span>
{/if}

<span class="line-clamp-3 w-full text-xs text-muted-foreground">
{prompt.content}
</span>
</button>
{/each}

{#each systemPrompts.sourceGroups as group (group.source.id)}
{#each group.entries as entry (entry.id)}
<button
class="{itemClass} flex-col items-start gap-0.5 py-2"
onclick={() => systemPrompts.selectSourcePrompt(group.source, entry)}
type="button"
>
<span class="flex w-full items-center gap-1.5">
{#if entry.iconUrl}
<img
alt=""
class="{ICON_CLASS_DEFAULT} shrink-0 rounded-sm"
onerror={(e) => {
(e.currentTarget as HTMLImageElement).style.display = 'none';
}}
src={entry.iconUrl}
/>
{:else}
<group.source.icon class="{ICON_CLASS_DEFAULT} shrink-0" />
{/if}

<span class="truncate text-xs text-muted-foreground">{entry.origin}</span>

{#if entry.argumentCount > 0}
<span class="ml-auto shrink-0 text-xs text-muted-foreground">
{entry.argumentCount} arg{entry.argumentCount > 1 ? 's' : ''}
</span>
{/if}
</span>

<span class="line-clamp-1 text-sm font-medium">
{entry.title}
</span>

{#if entry.description}
<span class="line-clamp-2 w-full text-xs text-muted-foreground">
{entry.description}
</span>
{/if}
</button>
{/each}
{/each}

{#if systemPrompts.hasNoMatches}
<div class="px-3 py-2 text-xs text-muted-foreground">No matches</div>
{/if}
</div>
</Collapsible.Content>
</Collapsible.Root>

{#if chatFormActions.onWorkingDirectoryClick}
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
import * as DropdownMenu from '@ggml-org/llama-ui/ui/dropdown-menu';
import * as Tooltip from '@ggml-org/llama-ui/ui/tooltip';
import { cn } from '@ggml-org/llama-ui/utils';
import { File, Folder, Image, MessageSquare, Mic, Plus, Video } from '@lucide/svelte';
import { ChatFormActionAddToolsSubmenu, ProjectSubmenu } from '#lib/components/app/index.ts';
import { File, Folder, Image, Mic, Plus, Video } from '@lucide/svelte';
import {
ChatFormActionAddSystemMessageSubmenu,
ChatFormActionAddToolsSubmenu,
ProjectSubmenu
} from '#lib/components/app/index.ts';
import {
ATTACHMENT_FILE_ITEMS,
ATTACHMENT_MENU_TEXT,
Expand Down Expand Up @@ -143,17 +147,12 @@
)}
/>

<DropdownMenu.Item
class="flex cursor-pointer items-center gap-2"
onclick={() => {
<ChatFormActionAddSystemMessageSubmenu
onWriteNew={() => {
suppressCloseAutoFocus = true;
chatFormActions.onSystemPromptClick?.();
}}
>
<MessageSquare class={ICON_CLASS_DEFAULT} />

<span>{ATTACHMENT_MENU_TEXT.SYSTEM_MESSAGE}</span>
</DropdownMenu.Item>
/>

{#if chatFormActions.onWorkingDirectoryClick}
<DropdownMenu.Item
Expand Down
Loading
Loading