diff --git a/ui/apps/chat/README.md b/ui/apps/chat/README.md index cd26cdcdace0..e39896f1e0ae 100644 --- a/ui/apps/chat/README.md +++ b/ui/apps/chat/README.md @@ -157,7 +157,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 67c707c312eb..3d402c427f9a 100644 --- a/ui/apps/chat/src/app.css +++ b/ui/apps/chat/src/app.css @@ -362,6 +362,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; + } + } } /* 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 0358140ee282..cc7b95cbf23f 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 @@ -27,7 +27,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 { @@ -84,6 +89,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; @@ -103,6 +109,7 @@ onStop, onSubmit, onSystemPromptClick, + onSystemPromptWithContent, onUploadedFileRemove, onUploadedFilesChange, onValueChange, @@ -527,6 +534,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() { @@ -794,9 +806,11 @@ micWarning={micUnavailableReason ?? micError} onFileUpload={handleFileUpload} onMicClick={handleMicClick} + onPromptArguments={handlePromptArguments} {onStop} onSystemPromptClick={() => onSystemPromptClick?.({ files: uploadedFiles, message: value })} + {onSystemPromptWithContent} onWorkingDirectoryClick={isWorkingDirectoryInAddMenu ? pickers.handleWorkingDirectoryOpen : undefined} 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 aee054e8d8a6..72880998ec41 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 c895ef0c34b7..2639cbf2de10 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 @@ -14,6 +14,7 @@ VOICE_MODE_MESSAGE } from '#lib/constants/index.ts'; import { setChatFormActionsContext } from '#lib/contexts/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'; @@ -52,7 +53,9 @@ onFileUpload?: () => void; onMicClick?: () => void; onStop?: () => void; + onPromptArguments?: (source: SystemPromptSource, entry: SystemPromptEntry) => void; onSystemPromptClick?: () => void; + onSystemPromptWithContent?: (content: string, promptId: string, title: string) => void; onWorkingDirectoryClick?: () => void; } @@ -68,8 +71,10 @@ micWarning = null, onFileUpload, onMicClick, + onPromptArguments, onStop, onSystemPromptClick, + onSystemPromptWithContent, onWorkingDirectoryClick, showAddButton = true, showModelSelector = true, @@ -135,9 +140,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 2770f96d83dc..20611363cc40 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} +