@@ -332,6 +332,7 @@ sidebarHideButton[ Dynamic[ nbo_ ] ] := Button[
332332 ],
333333 tr @ "SidebarToolbarButtonTooltipHideSidebar"
334334 ],
335+ CurrentValue [ $FrontEndSession , "ShowNotebookAssistant" ] = False ;
335336 FrontEndToken [nbo , "HideSidebar" ],
336337 Appearance -> "Suppressed" ,
337338 Evaluator -> None
@@ -601,7 +602,7 @@ sidebarChatInputCell // beginDefinition;
601602sidebarChatInputCell [ ] := sidebarChatInputCell [ "" ]
602603
603604sidebarChatInputCell [ initialContent_ ] := Cell [
604- BoxData @ ToBoxes @ DynamicModule [ { thisNB , thisCell , sidebarCell , chatEvalCell , fieldContent = initialContent , returnKeyDownQ , input },
605+ BoxData @ ToBoxes @ DynamicModule [ { thisNB , thisCell , sidebarCell , chatEvalCell , fieldContent = initialContent , returnKeyDownQ , input , kernelWasQuitQ = False , cachedChatInput = "" , cachedSessionID = $SessionID },
605606 EventHandler [
606607 Pane [
607608 Grid [
@@ -620,6 +621,11 @@ sidebarChatInputCell[ initialContent_ ] := Cell[
620621 ,
621622 If [ TrueQ @ returnKeyDownQ ,
622623 returnKeyDownQ = False ;
624+ Needs [ "Wolfram`Chatbook`" -> None ];
625+ If [ kernelWasQuitQ ,
626+ If [ Not @ TrueQ @ $workspaceChatInitialized , initializeWorkspaceChat [ ] ];
627+ If [ fieldContent =!= cachedChatInput , fieldContent = cachedChatInput ];
628+ kernelWasQuitQ = False ];
623629 evaluateSidebarChat [ thisNB , sidebarCell , input , Dynamic @ chatEvalCell ]
624630 ];
625631 (* spooky action at a distance: regenerating a side bar ChatOutput cell *)
@@ -691,7 +697,7 @@ sidebarChatInputCell[ initialContent_ ] := Cell[
691697 Method -> "Preemptive"
692698 ],
693699 (* 15.0: the side bar is a Row of cells: docked cells, scrollable pane cell, footer cell (ChatInput) *)
694- Initialization :> (thisNB = EvaluationNotebook [ ]; thisCell = EvaluationCell [ ]; sidebarCell = ParentCell @ thisCell )
700+ Initialization :> (thisNB = EvaluationNotebook [ ]; thisCell = EvaluationCell [ ]; sidebarCell = ParentCell @ thisCell ; kernelWasQuitQ = cachedSessionID =!= $SessionID ; cachedSessionID = $SessionID )
695701 ],
696702 "ChatInputField" ,
697703 Background -> $inputFieldOuterBackground ,
@@ -747,7 +753,7 @@ attachWorkspaceChatInput // endDefinition;
747753(* :!CodeAnalysis::BeginBlock:: *)
748754(* :!CodeAnalysis::Disable::DynamicImageSize:: *)
749755attachedWorkspaceChatInputCell [ location_ String ] := Cell [
750- BoxData @ ToBoxes @ DynamicModule [ { thisNB },
756+ BoxData @ ToBoxes @ DynamicModule [ { thisNB , cachedSessionID = $SessionID , cachedChatInput = "" , kernelWasQuitQ = False },
751757 EventHandler [
752758 Pane [
753759 Grid [
@@ -756,7 +762,7 @@ attachedWorkspaceChatInputCell[ location_String ] := Cell[
756762 RawBoxes @ TemplateBox [ { }, "ChatIconUser" ],
757763 Framed [
758764 InputField [
759- Dynamic @ $WorkspaceChatInput ,
765+ Dynamic [ $WorkspaceChatInput , Function [ cachedChatInput = $WorkspaceChatInput = # ] ], (* store a local copy of the text in case the kernel was quit *)
760766 Boxes ,
761767 ContinuousAction -> True ,
762768 $inputFieldOptions
@@ -773,6 +779,11 @@ attachedWorkspaceChatInputCell[ location_String ] := Cell[
773779 27
774780 ],
775781 Needs [ "Wolfram`Chatbook`" -> None ];
782+ (* in case kernel was quit and the user hasn't typed something new into the search field, restore it to the cached value *)
783+ If [ kernelWasQuitQ ,
784+ If [ Not @ TrueQ @ $workspaceChatInitialized , initializeWorkspaceChat [ ] ];
785+ If [ $WorkspaceChatInput =!= cachedChatInput , $WorkspaceChatInput = cachedChatInput ];
786+ kernelWasQuitQ = False ];
776787 Symbol [ "Wolfram`Chatbook`ChatbookAction" ][
777788 "EvaluateWorkspaceChat" ,
778789 thisNB ,
@@ -821,6 +832,11 @@ attachedWorkspaceChatInputCell[ location_String ] := Cell[
821832 {
822833 "ReturnKeyDown" :> (
823834 Needs [ "Wolfram`Chatbook`" -> None ];
835+ (* in case kernel was quit and the user hasn't typed something new into the search field, restore it to the cached value *)
836+ If [ kernelWasQuitQ ,
837+ If [ Not @ TrueQ @ $workspaceChatInitialized , initializeWorkspaceChat [ ] ];
838+ If [ $WorkspaceChatInput =!= cachedChatInput , $WorkspaceChatInput = cachedChatInput ];
839+ kernelWasQuitQ = False ];
824840 Symbol [ "Wolfram`Chatbook`ChatbookAction" ][
825841 "EvaluateWorkspaceChat" ,
826842 thisNB ,
@@ -830,7 +846,7 @@ attachedWorkspaceChatInputCell[ location_String ] := Cell[
830846 },
831847 Method -> "Queued"
832848 ],
833- Initialization :> (thisNB = EvaluationNotebook [ ])
849+ Initialization :> (thisNB = EvaluationNotebook [ ]; kernelWasQuitQ = cachedSessionID =!= $SessionID ; cachedSessionID = $SessionID )
834850 ],
835851 "ChatInputField" ,
836852 Background -> $inputFieldOuterBackground ,
@@ -865,7 +881,7 @@ $workspaceChatInitialized = False;
865881(*initializeWorkspaceChat*)
866882initializeWorkspaceChat // beginDefinition ;
867883
868- initializeWorkspaceChat [ ] := initializeWorkspaceChat [ ] = LogChatTiming [
884+ initializeWorkspaceChat [ ] := LogChatTiming [
869885 LogChatTiming [ getEmbeddings [ { "Hello" } ], "InitializeEmbeddings" ];
870886 LogChatTiming [ cachedTokenizer [ "gpt-4o-text" ], "InitializeTokenizer" ];
871887 LogChatTiming [ $llmKitService , "InitializeLLMKitService" ];
@@ -1532,6 +1548,8 @@ assistantMessageButtons[ includeFeedback_, sidebarCellQ_ ] :=
15321548 Tooltip [ assistantCopyAsActionMenu [ Dynamic [ cell ] ], tr [ "WorkspaceOutputRaftCopyAsTooltip" ] ],
15331549 Button [
15341550 Tooltip [ $regenerateLabel , tr [ "WorkspaceOutputRaftRegenerateTooltip" ] ],
1551+ Needs [ "Wolfram`Chatbook`" -> None ];
1552+ If [ Not @ TrueQ @ $workspaceChatInitialized , initializeWorkspaceChat [ ] ]; (* in case kernel was quit *)
15351553 ChatbookAction [ "RegenerateAssistantMessage" , cell , sidebarCellQ ],
15361554 Appearance -> "Suppressed" ,
15371555 Method -> "Queued"
0 commit comments