diff --git a/ui/apps/chat/README.md b/ui/apps/chat/README.md index 49c6fcb4f3c5..5f537803b0b9 100644 --- a/ui/apps/chat/README.md +++ b/ui/apps/chat/README.md @@ -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//` cannot import from that folder. diff --git a/ui/apps/chat/src/app.css b/ui/apps/chat/src/app.css index b5393ec5cfcc..edf87ea6673f 100644 --- a/ui/apps/chat/src/app.css +++ b/ui/apps/chat/src/app.css @@ -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 { diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte index fd1e302ee585..075d2b02e3b6 100644 --- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte @@ -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 { @@ -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; @@ -104,6 +110,7 @@ onStop, onSubmit, onSystemPromptClick, + onSystemPromptWithContent, onUploadedFileRemove, onUploadedFilesChange, onValueChange, @@ -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() { @@ -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 diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionAdd/ChatFormActionAddDrawer.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionAdd/ChatFormActionAddDrawer.svelte index 36cdf4169168..53a5f51bf097 100644 --- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionAdd/ChatFormActionAddDrawer.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionAdd/ChatFormActionAddDrawer.svelte @@ -1,4 +1,5 @@ + + + + + + System message + + + + {#if prompts.hasPrompts} +
+ +
+ {/if} + + onWriteNew?.()}> + + + Write new + + + {#if prompts.libraryPrompts.length > 0} + + + Your prompts + + {#each prompts.libraryPrompts as prompt (prompt.id)} + prompts.selectLibraryPrompt(prompt.id)} + > + {prompt.name} + + {#if prompt.description} + + {prompt.description} + + {/if} + + + {prompt.content} + + + {/each} + {/if} + + {#each prompts.sourceGroups as group (group.source.id)} + + + {group.source.label} + + {#each group.entries as entry (entry.id)} + prompts.selectSourcePrompt(group.source, entry)} + > +
+ {#if entry.iconUrl} + { + (e.currentTarget as HTMLImageElement).style.display = 'none'; + }} + src={entry.iconUrl} + /> + {:else} + + {/if} + + {entry.origin} + + {#if entry.argumentCount > 0} + + {entry.argumentCount} arg{entry.argumentCount > 1 ? 's' : ''} + + {/if} +
+ + + {entry.title} + + + {#if entry.description} + + {entry.description} + + {/if} +
+ {/each} + {/each} + + {#if prompts.hasNoMatches} +
No matches
+ {/if} +
+
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActions.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActions.svelte index 44368c396ca2..004703fe2f39 100644 --- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActions.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActions.svelte @@ -16,6 +16,7 @@ } from '#lib/constants/index.ts'; import { setChatFormActionsContext } from '#lib/contexts/index.ts'; import { FileTypeCategory } from '#lib/enums/index.ts'; + import type { SystemPromptEntry, SystemPromptSource } from '#lib/extensions/index.ts'; import { useChatFormModel } from '#lib/hooks/use-chat-form-model.svelte.ts'; import { useShowContextGauge } from '#lib/hooks/use-context-gauge.svelte.ts'; import { ChatService } from '#lib/services/index.ts'; @@ -55,7 +56,9 @@ /** Why voice mode cannot listen. */ voiceModeUnavailableReason?: string | null; onStop?: () => void; + onPromptArguments?: (source: SystemPromptSource, entry: SystemPromptEntry) => void; onSystemPromptClick?: () => void; + onSystemPromptWithContent?: (content: string, promptId: string, title: string) => void; onWorkingDirectoryClick?: () => void; } @@ -71,8 +74,10 @@ micWarning = null, onFileUpload, onMicClick, + onPromptArguments, onStop, onSystemPromptClick, + onSystemPromptWithContent, onVoiceModeClick, onWorkingDirectoryClick, showAddButton = true, @@ -142,9 +147,15 @@ get onFileUpload() { return onFileUpload; }, + get onPromptArguments() { + return onPromptArguments; + }, get onSystemPromptClick() { return onSystemPromptClick; }, + get onSystemPromptWithContent() { + return onSystemPromptWithContent; + }, get onWorkingDirectoryClick() { return onWorkingDirectoryClick; }, diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessagePrompt/ChatMessagePromptContent.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessagePrompt/ChatMessagePromptContent.svelte new file mode 100644 index 000000000000..8b1e21b9cb28 --- /dev/null +++ b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessagePrompt/ChatMessagePromptContent.svelte @@ -0,0 +1,43 @@ + + + +
+
+
+ + + +
+ + {@render status?.()} +
+ + {#if content.trim()} + +
+ {content} +
+
+ {/if} +
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageSystem/ChatMessageSystem.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageSystem/ChatMessageSystem.svelte index df2097b5a7d9..7988ec4f7bb8 100644 --- a/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageSystem/ChatMessageSystem.svelte +++ b/ui/apps/chat/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageSystem/ChatMessageSystem.svelte @@ -1,13 +1,28 @@ + + + { + event.preventDefault(); + nameInput?.focus(); + nameInput?.select(); + }} + > + + + {prompt ? 'Edit prompt' : contentEditable ? 'New prompt' : 'Add to library'} + + + {#if !prompt && !contentEditable} + + Save this system message as a prompt, to start other chats from it. + + {/if} + + +
+
+
+ + + +
+ +
+ + + +
+ +
+ + + {#if contentEditable} +