-
Notifications
You must be signed in to change notification settings - Fork 5
Add dropdown selector for custom prompts near chat input #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8f7a8c8
Initial plan
Copilot 280dafa
Add dropdown selector for custom prompts near chat input
Copilot 7e0f5ea
Add custom prompt dropdown and enhance prompt selection functionality
garland3 f9549ee
feat: update PromptSelector to use removePrompts for clearing selections
garland3 044b349
feat: add easy-start entrypoint scripts for simplified local setup
garland3 09ad3d9
Merge branch 'main' into copilot/add-custom-prompt-dropdown
garland3 7c481bb
feat: add comprehensive tests for ToolsPanel component functionality
garland3 7eb8e5c
Implement feature X to enhance user experience and optimize performance
garland3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| import { useChat } from '../contexts/ChatContext' | ||
| import { ChevronDown, Sparkles } from 'lucide-react' | ||
| import { useState, useRef, useEffect } from 'react' | ||
|
|
||
| const PromptSelector = () => { | ||
| const { prompts, selectedPrompts, togglePrompt, makePromptActive, selectedTools } = useChat() | ||
| const [isOpen, setIsOpen] = useState(false) | ||
| const dropdownRef = useRef(null) | ||
|
|
||
| // Get all selected prompt keys as an array | ||
| const selectedPromptKeys = selectedPrompts && selectedPrompts.size > 0 | ||
| ? Array.from(selectedPrompts) | ||
| : [] | ||
|
|
||
| // Get only the prompts that are actually selected (enabled) | ||
| const allPrompts = [] | ||
| prompts.forEach(server => { | ||
| if (server.prompts && server.prompts.length > 0) { | ||
| server.prompts.forEach(prompt => { | ||
| const promptKey = `${server.server}_${prompt.name}` | ||
| // Only include prompts that are actually selected | ||
| if (selectedPromptKeys.includes(promptKey)) { | ||
| allPrompts.push({ | ||
| key: promptKey, | ||
| server: server.server, | ||
| name: prompt.name, | ||
| description: prompt.description || '', | ||
| compliance_level: server.compliance_level | ||
| }) | ||
| } | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| // The first selected prompt is the active one (used by backend) | ||
| const activePromptKey = selectedPromptKeys.length > 0 ? selectedPromptKeys[0] : null | ||
|
|
||
| // Close dropdown when clicking outside | ||
| useEffect(() => { | ||
| const handleClickOutside = (event) => { | ||
| if (dropdownRef.current && !dropdownRef.current.contains(event.target)) { | ||
| setIsOpen(false) | ||
| } | ||
| } | ||
|
|
||
| if (isOpen) { | ||
| document.addEventListener('mousedown', handleClickOutside) | ||
| return () => document.removeEventListener('mousedown', handleClickOutside) | ||
| } | ||
| }, [isOpen]) | ||
|
|
||
| const handlePromptSelect = (promptKey) => { | ||
| // Just make this prompt active without reordering | ||
| if (makePromptActive) { | ||
| makePromptActive(promptKey) | ||
| } | ||
| } | ||
|
|
||
| // Get display text for the button - show the active (first) prompt name | ||
| const getButtonText = () => { | ||
| if (selectedPromptKeys.length === 0) return 'Default Prompt' | ||
| // Always show the active (first) prompt name | ||
| const key = selectedPromptKeys[0] | ||
| const idx = key.indexOf('_') | ||
| return idx === -1 ? key : key.slice(idx + 1) | ||
| } | ||
|
|
||
| return ( | ||
| <div ref={dropdownRef} className="relative"> | ||
| <button | ||
| type="button" | ||
| onClick={() => setIsOpen(!isOpen)} | ||
| className="flex items-center gap-1 text-xs text-gray-400 hover:text-purple-400 transition-colors" | ||
| title="Select custom prompts" | ||
| > | ||
| <Sparkles className="w-3 h-3" /> | ||
| <span className="underline decoration-dotted"> | ||
| {getButtonText()} | ||
| </span> | ||
| <ChevronDown className={`w-3 h-3 transition-transform ${isOpen ? 'rotate-180' : ''}`} /> | ||
| </button> | ||
|
|
||
| {isOpen && ( | ||
| <div className="absolute bottom-full left-0 mb-1 w-80 bg-gray-800 border border-gray-600 rounded-lg shadow-lg max-h-96 overflow-y-auto z-50"> | ||
| <div className="p-2 border-b border-gray-700 bg-gray-750"> | ||
| <div className="text-xs font-semibold text-gray-300 flex items-center gap-2"> | ||
| <Sparkles className="w-3 h-3 text-purple-400" /> | ||
| Custom Prompts | ||
| </div> | ||
| <div className="text-xs text-gray-400 mt-1"> | ||
| Select prompts to customize AI behavior | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Default Prompt option - always available */} | ||
| <button | ||
| onClick={() => { | ||
| // Clear all selected prompts to use default | ||
| selectedPromptKeys.forEach(key => togglePrompt(key)) | ||
| setIsOpen(false) | ||
| }} | ||
| className={`w-full px-3 py-2 text-left hover:bg-gray-700 transition-colors border-b border-gray-700 ${ | ||
| selectedPromptKeys.length === 0 ? 'bg-blue-900/30' : '' | ||
| }`} | ||
| > | ||
| <div className="flex items-center justify-between gap-2"> | ||
| <div className="flex-1 min-w-0"> | ||
| <div className="font-medium text-gray-200 flex items-center gap-2"> | ||
| {selectedPromptKeys.length === 0 && <span className="text-blue-400">✓</span>} | ||
| <span className="truncate">Default Prompt</span> | ||
| {selectedPromptKeys.length === 0 && <span className="text-xs text-blue-400">(active)</span>} | ||
| </div> | ||
| <div className="text-xs text-gray-400 mt-1"> | ||
| Use the standard system prompt without customization | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </button> | ||
|
|
||
| {/* Clear all selection option - only show if prompts are selected */} | ||
| {selectedPromptKeys.length > 1 && ( | ||
| <button | ||
| onClick={() => { | ||
| selectedPromptKeys.forEach(key => togglePrompt(key)) | ||
| setIsOpen(false) | ||
| }} | ||
| className="w-full px-3 py-2 text-left hover:bg-gray-700 transition-colors border-b border-gray-700 text-sm" | ||
| > | ||
| <div className="font-medium text-gray-400 italic"> | ||
| Clear All ({selectedPromptKeys.length}) | ||
| </div> | ||
| </button> | ||
| )} | ||
|
|
||
| {/* Prompt list */} | ||
| {allPrompts.map((prompt) => { | ||
| const isActive = prompt.key === activePromptKey | ||
| return ( | ||
| <button | ||
| key={prompt.key} | ||
| onClick={() => handlePromptSelect(prompt.key)} | ||
| className={`w-full px-3 py-2 text-left hover:bg-gray-700 transition-colors border-b border-gray-700 last:border-b-0 ${ | ||
| isActive ? 'bg-blue-900/30' : '' | ||
| }`} | ||
| > | ||
| <div className="flex items-center justify-between gap-2"> | ||
| <div className="flex-1 min-w-0"> | ||
| <div className="font-medium text-gray-200 flex items-center gap-2"> | ||
| {isActive && <span className="text-blue-400">✓</span>} | ||
| <span className="truncate">{prompt.name}</span> | ||
| {isActive && <span className="text-xs text-blue-400">(active)</span>} | ||
| </div> | ||
| {prompt.description && ( | ||
| <div className="text-xs text-gray-400 mt-1 line-clamp-2"> | ||
| {prompt.description} | ||
| </div> | ||
| )} | ||
| <div className="text-xs text-gray-500 mt-1"> | ||
| from {prompt.server} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </button> | ||
| ) | ||
| })} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default PromptSelector | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.