@@ -222,8 +222,7 @@ export default function openAIAssistantPage() {
222222 child : tag ( "i" , {
223223 className : "icon edit" ,
224224 } ) ,
225- // TODO: Implement edit functionality
226- //onclick: () => editMessage(message.id),
225+ onclick : ( ) => editMessage ( message . id ) ,
227226 } ) ;
228227 messageActions . appendChild ( editBtn ) ;
229228 }
@@ -248,6 +247,74 @@ export default function openAIAssistantPage() {
248247 scrollToBottom ( ) ;
249248 } ;
250249
250+ const editMessage = ( messageId ) => {
251+ const message = chatHistory . find ( ( msg ) => msg . id === messageId ) ;
252+ if ( ! message ) return ;
253+
254+ const messageEl = messageContainerRef . el . querySelector (
255+ `#message-${ message . id } ` ,
256+ ) ;
257+ const messageContent = messageEl . querySelector ( ".message-content" ) ;
258+
259+ const editContainer = < div className = "edit-container" > </ div > ;
260+
261+ const textarea = (
262+ < textarea
263+ className = "edit-textarea"
264+ defaultValue = { message . content }
265+ placeholder = "Edit your message..."
266+ onkeydown = { ( e ) => {
267+ if ( e . key === "Enter" && e . ctrlKey ) {
268+ e . preventDefault ( ) ;
269+ // TODO: save edit
270+ } else if ( e . key === "Escape" ) {
271+ e . preventDefault ( ) ;
272+ // TODO: cancel edit
273+ }
274+ } }
275+ />
276+ ) ;
277+
278+ const editActions = < div className = "edit-actions" > </ div > ;
279+
280+ const editInfo = (
281+ < div className = "edit-info" >
282+ Press Ctrl+Enter to save, Escape to cancel
283+ </ div >
284+ ) ;
285+
286+ const editButtons = (
287+ < div className = "edit-buttons" >
288+ < button
289+ className = "btn btn-sm btn-outline"
290+ onclick = { ( ) => {
291+ const md = markdownIt ( {
292+ html : true ,
293+ linkify : true ,
294+ typographer : true ,
295+ } ) ;
296+ messageContent . innerHTML = md . render ( message . content ) ;
297+ } }
298+ >
299+ < i className = "icon clearclose" > </ i > { " " }
300+ < span className = "btn-text" > Cancel</ span >
301+ </ button >
302+ < button className = "btn btn-sm btn-primary" >
303+ < i className = "icon check" > </ i > < span className = "btn-text" > Save</ span >
304+ </ button >
305+ </ div >
306+ ) ;
307+
308+ editActions . append ( editInfo , editButtons ) ;
309+ editContainer . append ( textarea , editActions ) ;
310+
311+ messageContent . innerHTML = "" ;
312+ messageContent . appendChild ( editContainer ) ;
313+
314+ textarea . focus ( ) ;
315+ textarea . select ( ) ;
316+ } ;
317+
251318 /**
252319 * Updates the profile button appearance and state
253320 * @param {string } profile - Profile type ("ask" or "write")
@@ -416,6 +483,7 @@ export default function openAIAssistantPage() {
416483 ) ;
417484 }
418485 chatHistory . push ( {
486+ id : msg . id ,
419487 role : msg . role ,
420488 content : msg . content ,
421489 } ) ;
@@ -485,7 +553,10 @@ export default function openAIAssistantPage() {
485553 role : "user" ,
486554 content : userInput ,
487555 } ;
488- chatHistory . push ( userMessageForAgent ) ;
556+ chatHistory . push ( {
557+ ...userMessageForAgent ,
558+ id : userMsgId . id ,
559+ } ) ;
489560
490561 chatInputRef . el . value = "" ;
491562 handleChatInput ( ) ;
@@ -631,6 +702,7 @@ export default function openAIAssistantPage() {
631702
632703 if ( ! wasError ) {
633704 chatHistory . push ( {
705+ id : assistantFinalData . id ,
634706 role : "assistant" ,
635707 content : streamedContent ,
636708 } ) ;
0 commit comments