-
Notifications
You must be signed in to change notification settings - Fork 1
Feat/1958 ai left panel UI elements #1971
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
Open
DSanich
wants to merge
9
commits into
feat/1957-ai-left-panel
Choose a base branch
from
feat/1958-ai-left-panel-ui-elements
base: feat/1957-ai-left-panel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
06516cc
feat(#1958): add mock data and types
DSanich 688f81f
feat(#1958): add AiPanelHeader component
DSanich 94d966c
feat(#1958): add AiPanelMessageBubble component
DSanich a7db782
feat(#1958): add AiPanelSuggestions component
DSanich f9fa9ac
feat(#1958): add AiPanelChatBar component
DSanich 49a81c5
feat(#1958): add AiPanelMessages component
DSanich 8f51f03
feat(#1958): add index and refactor AiLeftPanel
DSanich b380b0f
feat(#1958): format fix
DSanich a9e6781
feat(#1958): wrap header and chat bar elements on narrow width
DSanich 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,66 @@ | ||
| 'use client'; | ||
|
|
||
| import { PanelLeftClose } from 'lucide-react'; | ||
| import { useState } from 'react'; | ||
|
|
||
| import { cn } from '@hypha-platform/ui-utils'; | ||
|
|
||
| import { | ||
| AiPanelHeader, | ||
| AiPanelMessages, | ||
| AiPanelChatBar, | ||
| MOCK_MODEL_OPTIONS, | ||
| MOCK_SUGGESTIONS, | ||
| MOCK_WELCOME_MESSAGE, | ||
| } from './ai-panel'; | ||
|
|
||
| type AiLeftPanelProps = { | ||
| onClose: () => void; | ||
| className?: string; | ||
| }; | ||
|
|
||
| export function AiLeftPanel({ onClose, className }: AiLeftPanelProps) { | ||
| const [input, setInput] = useState(''); | ||
| const [selectedModel, setSelectedModel] = useState(MOCK_MODEL_OPTIONS[0]!); | ||
| const [messages, setMessages] = useState([MOCK_WELCOME_MESSAGE]); | ||
| const [showSuggestions, setShowSuggestions] = useState(true); | ||
| const [isStreaming, setIsStreaming] = useState(false); | ||
|
|
||
| const handleSend = () => { | ||
| // Placeholder - no business logic | ||
| }; | ||
|
|
||
| const handleSuggestionSelect = (text: string) => { | ||
| setShowSuggestions(false); | ||
| setInput(text); | ||
| }; | ||
|
|
||
| return ( | ||
| <div | ||
| className={cn( | ||
| 'flex h-full flex-col bg-background-2 border-r border-border', | ||
| 'flex h-full min-w-0 flex-col overflow-hidden border-r border-border bg-background-2', | ||
| className, | ||
| )} | ||
| > | ||
| <div className="flex flex-shrink-0 items-center justify-end border-b border-border px-4 py-3"> | ||
| <button | ||
| type="button" | ||
| onClick={onClose} | ||
| className="flex h-7 w-7 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" | ||
| title="Close panel" | ||
| aria-label="Close panel" | ||
| > | ||
| <PanelLeftClose className="h-3.5 w-3.5" /> | ||
| </button> | ||
| </div> | ||
| <div className="flex-1 overflow-auto" /> | ||
| <AiPanelHeader | ||
| onClose={onClose} | ||
| modelOptions={MOCK_MODEL_OPTIONS} | ||
| selectedModel={selectedModel} | ||
| onModelSelect={setSelectedModel} | ||
| /> | ||
|
|
||
| <AiPanelMessages | ||
| messages={messages} | ||
| suggestions={MOCK_SUGGESTIONS} | ||
| showSuggestions={showSuggestions} | ||
| onSuggestionSelect={handleSuggestionSelect} | ||
| /> | ||
|
|
||
| <AiPanelChatBar | ||
| value={input} | ||
| onChange={setInput} | ||
| onSend={handleSend} | ||
| isStreaming={isStreaming} | ||
| /> | ||
| </div> | ||
| ); | ||
| } |
154 changes: 154 additions & 0 deletions
154
packages/epics/src/common/ai-panel/ai-panel-chat-bar.tsx
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,154 @@ | ||
| 'use client'; | ||
|
|
||
| import { useRef } from 'react'; | ||
| import { | ||
| Code2, | ||
| Image, | ||
| Mic, | ||
| Paperclip, | ||
| Search, | ||
| Send, | ||
| Square, | ||
| } from 'lucide-react'; | ||
|
|
||
| import { cn } from '@hypha-platform/ui-utils'; | ||
|
|
||
| type AiPanelChatBarProps = { | ||
| value: string; | ||
| onChange: (value: string) => void; | ||
| onSend: () => void; | ||
| isStreaming?: boolean; | ||
| placeholder?: string; | ||
| }; | ||
|
|
||
| export function AiPanelChatBar({ | ||
| value, | ||
| onChange, | ||
| onSend, | ||
| isStreaming = false, | ||
| placeholder = 'Ask Hypha AI anything...', | ||
| }: AiPanelChatBarProps) { | ||
| const textareaRef = useRef<HTMLTextAreaElement>(null); | ||
|
|
||
| const autoResize = () => { | ||
| if (textareaRef.current) { | ||
| textareaRef.current.style.height = 'auto'; | ||
| textareaRef.current.style.height = | ||
| Math.min(textareaRef.current.scrollHeight, 160) + 'px'; | ||
| } | ||
| }; | ||
|
|
||
| const handleKeyDown = (e: React.KeyboardEvent) => { | ||
| if (e.key === 'Enter' && !e.shiftKey) { | ||
| e.preventDefault(); | ||
| onSend(); | ||
| } | ||
DSanich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| const canSend = value.trim().length > 0 && !isStreaming; | ||
|
|
||
| return ( | ||
| <div className="flex w-full min-w-0 flex-shrink-0 flex-col border-t border-border bg-background-2 p-3"> | ||
| <div | ||
| className={cn( | ||
| 'flex min-w-0 flex-col rounded-2xl border border-border bg-muted/50', | ||
| 'transition-all duration-200 focus-within:border-primary/50 focus-within:ring-2 focus-within:ring-primary/20', | ||
| )} | ||
| > | ||
| {/* Toolbar */} | ||
| <div className="flex min-w-0 items-center gap-1 px-3 pt-2.5"> | ||
| <button | ||
| type="button" | ||
| className="rounded-lg p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" | ||
| title="Attach file" | ||
| aria-label="Attach file" | ||
| > | ||
| <Paperclip className="h-3.5 w-3.5" /> | ||
| </button> | ||
| <button | ||
| type="button" | ||
| className="rounded-lg p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" | ||
| title="Image" | ||
| aria-label="Add image" | ||
| > | ||
| <Image className="h-3.5 w-3.5" /> | ||
| </button> | ||
| <button | ||
| type="button" | ||
| className="rounded-lg p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" | ||
| title="Code" | ||
| aria-label="Add code snippet" | ||
| > | ||
| <Code2 className="h-3.5 w-3.5" /> | ||
| </button> | ||
| <button | ||
| type="button" | ||
| className="rounded-lg p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" | ||
| title="Search web" | ||
| aria-label="Search" | ||
| > | ||
| <Search className="h-3.5 w-3.5" /> | ||
| </button> | ||
| <div className="min-w-0 flex-1" /> | ||
| <button | ||
| type="button" | ||
| className="rounded-lg p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" | ||
| title="Voice" | ||
| aria-label="Voice input" | ||
| > | ||
| <Mic className="h-3.5 w-3.5" /> | ||
| </button> | ||
| </div> | ||
|
|
||
| {/* Textarea — full width */} | ||
| <textarea | ||
| ref={textareaRef} | ||
| value={value} | ||
| onChange={(e) => { | ||
| onChange(e.target.value); | ||
| autoResize(); | ||
| }} | ||
| onKeyDown={handleKeyDown} | ||
| placeholder={placeholder} | ||
| rows={1} | ||
| className={cn( | ||
| 'min-h-[36px] min-w-0 max-h-[160px] w-full resize-none', | ||
| 'bg-transparent px-3 py-2 text-sm leading-relaxed text-foreground', | ||
| 'placeholder:text-muted-foreground focus:outline-none', | ||
| )} | ||
| style={{ minHeight: '36px', maxHeight: '160px' }} | ||
| /> | ||
|
|
||
| {/* Bottom bar */} | ||
| <div className="flex min-w-0 flex-wrap items-center justify-between gap-x-2 gap-y-1 px-3 pb-2.5"> | ||
| <span className="min-w-0 break-words text-xs text-muted-foreground"> | ||
| Shift+Enter for newline | ||
| </span> | ||
| <button | ||
| type="button" | ||
| onClick={onSend} | ||
| disabled={!canSend} | ||
| className={cn( | ||
| 'flex items-center gap-1.5 rounded-xl px-3 py-1.5 text-xs font-medium transition-all duration-200', | ||
| canSend | ||
| ? 'bg-primary text-primary-foreground hover:opacity-90' | ||
| : 'cursor-not-allowed bg-muted text-muted-foreground', | ||
| )} | ||
| > | ||
| {isStreaming ? ( | ||
| <> | ||
| <Square className="h-3 w-3" /> | ||
| Stop | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <Send className="h-3 w-3" /> | ||
| Send | ||
| </> | ||
| )} | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
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,107 @@ | ||
| 'use client'; | ||
|
|
||
| import { useEffect, useRef, useState } from 'react'; | ||
| import { ChevronDown, PanelLeftClose, RefreshCw, Sparkles } from 'lucide-react'; | ||
|
|
||
| import { cn } from '@hypha-platform/ui-utils'; | ||
|
|
||
| import type { ModelOption } from './mock-data'; | ||
|
|
||
| type AiPanelHeaderProps = { | ||
| onClose: () => void; | ||
| modelOptions: ModelOption[]; | ||
| selectedModel: ModelOption; | ||
| onModelSelect: (model: ModelOption) => void; | ||
| }; | ||
|
|
||
| export function AiPanelHeader({ | ||
| onClose, | ||
| modelOptions, | ||
| selectedModel, | ||
| onModelSelect, | ||
| }: AiPanelHeaderProps) { | ||
| const [showModelMenu, setShowModelMenu] = useState(false); | ||
| const menuRef = useRef<HTMLDivElement>(null); | ||
| const SelectedIcon = selectedModel.icon; | ||
|
|
||
| useEffect(() => { | ||
| const handleClickOutside = (e: MouseEvent) => { | ||
| if ( | ||
| showModelMenu && | ||
| menuRef.current && | ||
| !menuRef.current.contains(e.target as Node) | ||
| ) { | ||
| setShowModelMenu(false); | ||
| } | ||
| }; | ||
| document.addEventListener('mousedown', handleClickOutside); | ||
| return () => document.removeEventListener('mousedown', handleClickOutside); | ||
| }, [showModelMenu]); | ||
|
|
||
| return ( | ||
| <div className="flex min-w-0 flex-shrink-0 flex-wrap items-center justify-between gap-x-2 gap-y-2 border-b border-border bg-background-2 px-4 py-3"> | ||
| <div className="flex min-w-0 shrink-0 items-center gap-2"> | ||
| <div className="flex h-7 w-7 shrink-0 items-center justify-center rounded-xl bg-primary"> | ||
| <Sparkles className="h-3.5 w-3.5 text-primary-foreground" /> | ||
| </div> | ||
| <span className="font-semibold text-sm text-foreground">Hypha AI</span> | ||
| </div> | ||
| <div className="flex min-w-0 flex-wrap items-center justify-end gap-1"> | ||
| <div className="relative" ref={menuRef}> | ||
| <button | ||
| type="button" | ||
| onClick={() => setShowModelMenu(!showModelMenu)} | ||
| className="flex min-w-0 items-center gap-1.5 rounded-lg border border-border bg-secondary px-2.5 py-1.5 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" | ||
| > | ||
| <SelectedIcon className="h-3 w-3 shrink-0" /> | ||
| <span className="min-w-0 truncate">{selectedModel.label}</span> | ||
| <ChevronDown className="h-3 w-3 shrink-0" /> | ||
| </button> | ||
| {showModelMenu && ( | ||
| <div className="absolute left-0 top-full z-50 mt-1 w-44 animate-in fade-in slide-in-from-top-2 rounded-xl border border-border bg-popover py-1 shadow-2xl duration-200"> | ||
| {modelOptions.map((m) => { | ||
| const Icon = m.icon; | ||
| return ( | ||
| <button | ||
| key={m.id} | ||
| type="button" | ||
| onClick={() => { | ||
| onModelSelect(m); | ||
| setShowModelMenu(false); | ||
| }} | ||
| className={cn( | ||
| 'flex w-full items-center gap-2 px-3 py-2 text-xs transition-colors hover:bg-muted', | ||
| m.id === selectedModel.id | ||
| ? 'text-primary' | ||
| : 'text-foreground', | ||
| )} | ||
| > | ||
| <Icon className="h-3 w-3" /> | ||
| {m.label} | ||
| </button> | ||
| ); | ||
| })} | ||
| </div> | ||
| )} | ||
| </div> | ||
| <button | ||
| type="button" | ||
| className="flex h-7 w-7 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" | ||
| title="Refresh" | ||
| aria-label="Refresh" | ||
| > | ||
| <RefreshCw className="h-3.5 w-3.5" /> | ||
| </button> | ||
|
Comment on lines
+87
to
+94
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 90-92 presents an actionable refresh button, but there is no handler. This is confusing UX unless intentionally disabled. Suggested fix type AiPanelHeaderProps = {
onClose: () => void;
+ onRefresh?: () => void;
modelOptions: ModelOption[];
selectedModel: ModelOption;
onModelSelect: (model: ModelOption) => void;
};
export function AiPanelHeader({
onClose,
+ onRefresh,
modelOptions,
selectedModel,
onModelSelect,
}: AiPanelHeaderProps) {
@@
<button
type="button"
+ onClick={onRefresh}
+ disabled={!onRefresh}
className="flex h-7 w-7 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
title="Refresh"
aria-label="Refresh"
>🤖 Prompt for AI Agents |
||
| <button | ||
| type="button" | ||
| onClick={onClose} | ||
| className="flex h-7 w-7 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" | ||
| title="Hide AI panel" | ||
| aria-label="Close panel" | ||
| > | ||
| <PanelLeftClose className="h-3.5 w-3.5" /> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Textarea height can get stale after controlled
valueupdates.autoResize()only runs on local typing. If parent state clears or replacesvalue(e.g., after send), height may not shrink until next keystroke.Proposed fix
Also applies to: 107-110, 119-120
🤖 Prompt for AI Agents