Repository navigation
feat: add system prompt indicator to chat interface #99
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { useState, useCallback } from "react"; | ||
| import { Bot, Copy, Check } from "lucide-react"; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| DialogTrigger | ||
| } from "@/components/ui/dialog"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { cn } from "@/utils/utils"; | ||
|
|
||
| interface SystemPromptIndicatorProps { | ||
| systemPrompt?: string; | ||
| className?: string; | ||
| } | ||
|
|
||
| export function SystemPromptIndicator({ systemPrompt, className }: SystemPromptIndicatorProps) { | ||
| const [isCopied, setIsCopied] = useState(false); | ||
| const [isOpen, setIsOpen] = useState(false); | ||
|
|
||
| const handleCopy = useCallback(async () => { | ||
| if (!systemPrompt) return; | ||
|
|
||
| try { | ||
| await navigator.clipboard.writeText(systemPrompt); | ||
| setIsCopied(true); | ||
| setTimeout(() => setIsCopied(false), 2000); | ||
| } catch (error) { | ||
| console.error("Failed to copy system prompt:", error); | ||
| } | ||
| }, [systemPrompt]); | ||
|
|
||
| // Don't render if there's no system prompt | ||
| if (!systemPrompt?.trim()) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <Dialog open={isOpen} onOpenChange={setIsOpen}> | ||
| <DialogTrigger asChild> | ||
| <button | ||
| className={cn( | ||
| "inline-flex items-center gap-1 px-2 py-1 rounded-md", | ||
| "text-xs text-muted-foreground/70 hover:text-muted-foreground", | ||
| "bg-muted/30 hover:bg-muted/50 transition-colors", | ||
| "border border-muted-foreground/10", | ||
| className | ||
| )} | ||
| title="View system prompt" | ||
| > | ||
| <Bot className="h-3 w-3" /> | ||
| <span>System</span> | ||
| </button> | ||
| </DialogTrigger> | ||
| <DialogContent className="max-w-2xl max-h-[80vh] overflow-y-auto"> | ||
| <DialogHeader> | ||
| <DialogTitle className="flex items-center gap-2"> | ||
| <Bot className="h-4 w-4" /> | ||
| System Prompt | ||
| </DialogTitle> | ||
| <DialogDescription> | ||
| The system prompt that was used for this conversation | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
| <div className="space-y-4"> | ||
| <div className="bg-muted/50 rounded-lg p-4 font-mono text-sm whitespace-pre-wrap"> | ||
| {systemPrompt} | ||
| </div> | ||
| <div className="flex justify-end"> | ||
| <Button onClick={handleCopy} variant="outline" size="sm" className="gap-2"> | ||
| {isCopied ? ( | ||
| <> | ||
| <Check className="h-4 w-4" /> | ||
| Copied! | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <Copy className="h-4 w-4" /> | ||
| Copy System Prompt | ||
| </> | ||
| )} | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } | ||
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
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.