File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,18 @@ import {
2424 PopoverTrigger
2525} from "@flanksource-ui/components/ui/popover" ;
2626
27+ const ACTIVE_CONVERSATION_MAX_AGE_MS = 10 * 60 * 1000 ;
28+
29+ function isConversationRecent (
30+ conversation ?: AIConversationRecord
31+ ) : conversation is AIConversationRecord {
32+ if ( ! conversation ) {
33+ return false ;
34+ }
35+
36+ return Date . now ( ) - conversation . updatedAt <= ACTIVE_CONVERSATION_MAX_AGE_MS ;
37+ }
38+
2739type AiChatPopoverContextValue = {
2840 open : boolean ;
2941 setOpen : ( open : boolean ) => void ;
@@ -125,14 +137,14 @@ export function AiChatPopoverProvider({
125137 )
126138 : undefined ) ?? storedConversations [ 0 ] ;
127139
128- const nextConversationId =
129- activeConversationId ?? storedActiveConversation ?. id ;
140+ if ( isConversationRecent ( storedActiveConversation ) ) {
141+ const nextConversationId =
142+ activeConversationId ?? storedActiveConversation . id ;
130143
131- if ( nextConversationId ) {
132144 replaceChat (
133145 new Chat < UIMessage > ( {
134146 id : nextConversationId ,
135- messages : storedActiveConversation ? .messages ?? [ ]
147+ messages : storedActiveConversation . messages
136148 } ) ,
137149 { userAction : false }
138150 ) ;
You can’t perform that action at this time.
0 commit comments