@@ -2,6 +2,7 @@ import { isAIMessageChunk } from "@langchain/core/messages";
22import { ChatGoogleGenerativeAI } from "@langchain/google-genai" ;
33import { MemorySaver } from "@langchain/langgraph-checkpoint" ;
44import { createReactAgent } from "@langchain/langgraph/prebuilt" ;
5+ import confirm from "dialogs/confirm" ;
56import select from "dialogs/select" ;
67import he from "he" ;
78import Ref from "html-tag-js/ref" ;
@@ -340,26 +341,51 @@ export default function openAIAssistantPage() {
340341 if ( ! historyItemsContainer ) return ;
341342 historyItemsContainer . innerHTML = "" ;
342343 conversations . forEach ( ( conv ) => {
343- const item = document . createElement ( "div" ) ;
344- item . className = `history-item ${ conv . id === currentConversationId ? "active" : "" } ` ;
345- item . onclick = ( ) => {
346- if ( conv . id !== currentConversationId ) {
347- loadOrCreateConversation ( conv . id ) ;
348- toggleHistorySidebar ( ) ;
349- }
350- } ;
344+ const item = (
345+ < div
346+ className = { `history-item ${ conv . id === currentConversationId ? "active" : "" } ` }
347+ onclick = { ( ) => {
348+ if ( conv . id !== currentConversationId ) {
349+ loadOrCreateConversation ( conv . id ) ;
350+ toggleHistorySidebar ( ) ;
351+ }
352+ } }
353+ />
354+ ) ;
355+
356+ const iconWrapper = (
357+ < div className = "history-icon" >
358+ < i
359+ className = { `icon ${ conv . profile === "write" ? "edit" : "chat_bubble" } ` }
360+ > </ i >
361+ </ div >
362+ ) ;
351363
352- const iconWrapper = document . createElement ( "div" ) ;
353- iconWrapper . className = "history-icon" ;
354- const icon = document . createElement ( "i" ) ;
355- icon . className = `icon ${ conv . profile === "write" ? "edit" : "chat_bubble" } ` ;
356- iconWrapper . appendChild ( icon ) ;
364+ const text = (
365+ < div className = "history-text" > { conv . title || "Untitled Chat" } </ div >
366+ ) ;
357367
358- const text = document . createElement ( "div" ) ;
359- text . className = "history-text" ;
360- text . textContent = conv . title || "Untitled Chat" ;
368+ const deleteBtn = (
369+ < button className = "btn btn-icon history-delete" title = "Delete chat" >
370+ < i className = "icon delete" > </ i >
371+ </ button >
372+ ) ;
373+ deleteBtn . onclick = async ( e ) => {
374+ e . stopPropagation ( ) ;
375+ const confirmation = await confirm (
376+ "Delete Chat" ,
377+ `Are you sure you want to delete "<strong>${ conv . title || "Untitled Chat" } </strong>"? This action cannot be undone.` ,
378+ true ,
379+ ) ;
380+ if ( ! confirmation ) return ;
381+ await deleteConversation ( conv . id ) ;
382+ if ( conv . id === currentConversationId ) {
383+ await loadOrCreateConversation ( null ) ;
384+ }
385+ await updateHistorySidebar ( ) ;
386+ } ;
361387
362- item . append ( iconWrapper , text ) ;
388+ item . append ( iconWrapper , text , deleteBtn ) ;
363389 historyItemsContainer . appendChild ( item ) ;
364390 } ) ;
365391 }
@@ -696,9 +722,12 @@ export default function openAIAssistantPage() {
696722 >
697723 < div className = "sidebar-header" >
698724 < h3 className = "sidebar-title" > CHAT HISTORY</ h3 >
699- < button className = "btn btn-icon" title = "New Chat from Sidebar" >
725+ < button
726+ className = "btn btn-icon"
727+ title = "New Chat from Sidebar"
728+ onclick = { ( ) => loadOrCreateConversation ( null ) }
729+ >
700730 < i className = "icon add" > </ i >
701- { /* onclick={() => loadOrCreateConversation(null)} */ }
702731 </ button >
703732 </ div >
704733 < div className = "chat-history" >
0 commit comments