-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Toggle history #369
Open
casistack
wants to merge
5
commits into
miurla:main
Choose a base branch
from
casistack:toggle-history
base: main
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
Toggle history #369
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2302266
Intial chat history implementation before testing
casistack 7111005
Local browser storage support
casistack 112280a
Addressing Flagged issues
casistack 2804b5e
Remove browser storage and use Redis None instead
casistack 81fe019
Merge branch 'main' into toggle-history
casistack 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 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 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 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 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 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,12 @@ | ||
export default function LinksPage() { | ||
return ( | ||
<div className="flex min-h-screen flex-col items-center justify-center py-2"> | ||
<div className="text-center"> | ||
<h1 className="text-4xl font-bold mb-4">Links</h1> | ||
<p className="text-muted-foreground"> | ||
Coming soon - Link management and sharing features can be implemented in a future update. | ||
</p> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains 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,12 @@ | ||
export default function LoginPage() { | ||
return ( | ||
<div className="flex min-h-screen flex-col items-center justify-center py-2"> | ||
<div className="text-center"> | ||
<h1 className="text-4xl font-bold mb-4">Login</h1> | ||
<p className="text-muted-foreground"> | ||
Coming soon - User authentication can be implemented in a future update. | ||
</p> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains 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,41 @@ | ||
'use client' | ||
|
||
import React from 'react' | ||
import { Switch } from '@/components/ui/switch' | ||
import { Label } from '@/components/ui/label' | ||
import { useChatHistory } from '@/lib/utils/chat-history-context' | ||
import { updateChatHistorySetting } from '@/lib/actions/chat' | ||
|
||
export function ChatHistoryToggle() { | ||
const { chatHistoryEnabled, setChatHistoryEnabled, isLoading, storageAvailable } = useChatHistory() | ||
|
||
// If storage is not available, show message instead of toggle | ||
if (!storageAvailable) { | ||
return ( | ||
<div className="flex flex-col space-y-2 mb-4 p-4 bg-muted/50 rounded-lg"> | ||
<p className="text-sm text-muted-foreground"> | ||
Chat history is currently unavailable. To enable history functionality, please configure Redis storage in your environment settings. | ||
</p> | ||
</div> | ||
) | ||
} | ||
|
||
const handleToggle = async (checked: boolean) => { | ||
const success = await updateChatHistorySetting('anonymous', checked) | ||
if (success) { | ||
setChatHistoryEnabled(checked) | ||
} | ||
} | ||
|
||
return ( | ||
<div className="flex items-center space-x-2 mb-4"> | ||
<Switch | ||
id="chat-history" | ||
checked={chatHistoryEnabled} | ||
onCheckedChange={handleToggle} | ||
disabled={isLoading} | ||
/> | ||
<Label htmlFor="chat-history">Enable Chat History</Label> | ||
</div> | ||
) | ||
} |
This file contains 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 |
---|---|---|
|
@@ -12,13 +12,15 @@ import { EmptyScreen } from './empty-screen' | |
import Textarea from 'react-textarea-autosize' | ||
import { generateId } from 'ai' | ||
import { useAppState } from '@/lib/utils/app-state' | ||
import { useChatHistory } from '@/lib/utils/chat-history-context' | ||
|
||
interface ChatPanelProps { | ||
messages: UIState | ||
query?: string | ||
} | ||
|
||
export function ChatPanel({ messages, query }: ChatPanelProps) { | ||
const { chatHistoryEnabled } = useChatHistory() | ||
const [input, setInput] = useState('') | ||
const [showEmptyScreen, setShowEmptyScreen] = useState(false) | ||
const [, setMessages] = useUIState<typeof AI>() | ||
|
@@ -46,7 +48,7 @@ export function ChatPanel({ messages, query }: ChatPanelProps) { | |
setInput(query) | ||
setIsGenerating(true) | ||
|
||
// Add user message to UI state | ||
// Always add user message to UI state | ||
setMessages(currentMessages => [ | ||
...currentMessages, | ||
{ | ||
|
@@ -61,6 +63,8 @@ export function ChatPanel({ messages, query }: ChatPanelProps) { | |
data.append('input', query) | ||
} | ||
const responseMessage = await submit(data) | ||
|
||
// Always update UI with response message | ||
setMessages(currentMessages => [...currentMessages, responseMessage]) | ||
} | ||
|
||
|
@@ -89,9 +93,10 @@ export function ChatPanel({ messages, query }: ChatPanelProps) { | |
// Clear messages | ||
const handleClear = () => { | ||
setIsGenerating(false) | ||
setMessages([]) | ||
setAIMessage({ messages: [], chatId: '' }) | ||
// Always clear input and reset UI state when clearing even if chat history is disabled | ||
setInput('') | ||
setMessages([]) | ||
setAIMessage({ messages: [], chatId: generateId() }) // Reset AIState with new chatId | ||
router.push('/') | ||
} | ||
|
||
|
@@ -143,7 +148,7 @@ export function ChatPanel({ messages, query }: ChatPanelProps) { | |
placeholder="Ask a question..." | ||
spellCheck={false} | ||
value={input} | ||
className="resize-none w-full min-h-12 rounded-fill bg-muted border border-input pl-4 pr-10 pt-3 pb-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50'" | ||
className="resize-none w-full min-h-12 rounded-fill bg-muted border border-input pl-4 pr-10 pt-3 pb-1 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50'" | ||
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. 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. ok so no cosmetic changes . cool |
||
onChange={e => { | ||
setInput(e.target.value) | ||
setShowEmptyScreen(e.target.value.length === 0) | ||
|
This file contains 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 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,24 @@ | ||
'use client' | ||
|
||
import React, { Suspense } from 'react' | ||
import { useChatHistory } from '@/lib/utils/chat-history-context' | ||
import { ChatHistoryToggle } from './chat-history-toggle' | ||
import { HistoryList } from './history-list' | ||
|
||
type ClientHistoryListProps = { | ||
userId?: string | ||
} | ||
|
||
export default function ClientHistoryList(props: ClientHistoryListProps) { | ||
const { chatHistoryEnabled } = useChatHistory() | ||
|
||
return ( | ||
<> | ||
<ChatHistoryToggle /> | ||
<Suspense fallback={<div>Loading...</div>}> | ||
|
||
<HistoryList{...props} chatHistoryEnabled={chatHistoryEnabled} /> | ||
</Suspense> | ||
</> | ||
) | ||
} |
This file contains 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,21 @@ | ||
'use client' | ||
|
||
import React from 'react' | ||
import { useChatHistory } from '@/lib/utils/chat-history-context' | ||
import { ChatHistoryToggle } from './chat-history-toggle' | ||
import { HistoryList } from './history-list' | ||
|
||
type ClientHistoryWrapperProps = { | ||
userId?: string | ||
} | ||
|
||
export function ClientHistoryWrapper({ userId }: ClientHistoryWrapperProps) { | ||
const { chatHistoryEnabled } = useChatHistory() | ||
|
||
return ( | ||
<> | ||
<ChatHistoryToggle /> | ||
<HistoryList userId={userId} chatHistoryEnabled={chatHistoryEnabled} /> | ||
</> | ||
) | ||
} |
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.
IMO: Since chatHistoryEnabled is also being checked in saveChat, checking it in either place should be sufficient.
2804b5e#diff-819d2d9016d052cd621d2190deaf60688a87f953233d709b40fdabcf99d83f47R175-R180
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.
yea just put it as additional safety net but see what you mean